smp_api.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2008-2012 Broadcom Corporation
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at:
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. ******************************************************************************/
  18. /******************************************************************************
  19. *
  20. * This file contains the implementation of the SMP interface used by
  21. * applications that can run over an SMP.
  22. *
  23. ******************************************************************************/
  24. #include <string.h>
  25. #include "common/bt_target.h"
  26. //#include "bt_utils.h"
  27. #if SMP_INCLUDED == TRUE
  28. #include "smp_int.h"
  29. #include "stack/smp_api.h"
  30. #include "stack/l2cdefs.h"
  31. #include "l2c_int.h"
  32. #include "btm_int.h"
  33. #include "stack/hcimsgs.h"
  34. #include "stack/btu.h"
  35. #include "p_256_ecc_pp.h"
  36. #include "osi/allocator.h"
  37. /*******************************************************************************
  38. **
  39. ** Function SMP_Init
  40. **
  41. ** Description This function initializes the SMP unit.
  42. **
  43. ** Returns void
  44. **
  45. *******************************************************************************/
  46. void SMP_Init(void)
  47. {
  48. #if SMP_DYNAMIC_MEMORY
  49. smp_cb_ptr = (tSMP_CB *)osi_malloc(sizeof(tSMP_CB));
  50. #endif
  51. memset(&smp_cb, 0, sizeof(tSMP_CB));
  52. #if defined(SMP_INITIAL_TRACE_LEVEL)
  53. smp_cb.trace_level = SMP_INITIAL_TRACE_LEVEL;
  54. #else
  55. smp_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */
  56. #endif
  57. SMP_TRACE_EVENT ("%s", __FUNCTION__);
  58. smp_l2cap_if_init();
  59. /* initialization of P-256 parameters */
  60. p_256_init_curve(KEY_LENGTH_DWORDS_P256);
  61. }
  62. void SMP_Free(void)
  63. {
  64. memset(&smp_cb, 0, sizeof(tSMP_CB));
  65. #if SMP_DYNAMIC_MEMORY
  66. FREE_AND_RESET(smp_cb_ptr);
  67. #endif /* #if SMP_DYNAMIC_MEMORY */
  68. }
  69. /*******************************************************************************
  70. **
  71. ** Function SMP_SetTraceLevel
  72. **
  73. ** Description This function sets the trace level for SMP. If called with
  74. ** a value of 0xFF, it simply returns the current trace level.
  75. **
  76. ** Input Parameters:
  77. ** level: The level to set the GATT tracing to:
  78. ** 0xff-returns the current setting.
  79. ** 0-turns off tracing.
  80. ** >= 1-Errors.
  81. ** >= 2-Warnings.
  82. ** >= 3-APIs.
  83. ** >= 4-Events.
  84. ** >= 5-Debug.
  85. **
  86. ** Returns The new or current trace level
  87. **
  88. *******************************************************************************/
  89. extern UINT8 SMP_SetTraceLevel (UINT8 new_level)
  90. {
  91. if (new_level != 0xFF) {
  92. smp_cb.trace_level = new_level;
  93. }
  94. return (smp_cb.trace_level);
  95. }
  96. /*******************************************************************************
  97. **
  98. ** Function SMP_Register
  99. **
  100. ** Description This function register for the SMP services callback.
  101. **
  102. ** Returns void
  103. **
  104. *******************************************************************************/
  105. BOOLEAN SMP_Register (tSMP_CALLBACK *p_cback)
  106. {
  107. SMP_TRACE_EVENT ("SMP_Register state=%d", smp_cb.state);
  108. if (smp_cb.p_callback != NULL) {
  109. SMP_TRACE_ERROR ("SMP_Register: duplicate registration, overwrite it");
  110. }
  111. smp_cb.p_callback = p_cback;
  112. return (TRUE);
  113. }
  114. /*******************************************************************************
  115. **
  116. ** Function SMP_Pair
  117. **
  118. ** Description This function call to perform a SMP pairing with peer device.
  119. ** Device support one SMP pairing at one time.
  120. **
  121. ** Parameters bd_addr - peer device bd address.
  122. **
  123. ** Returns None
  124. **
  125. *******************************************************************************/
  126. tSMP_STATUS SMP_Pair (BD_ADDR bd_addr)
  127. {
  128. tSMP_CB *p_cb = &smp_cb;
  129. UINT8 status = SMP_PAIR_INTERNAL_ERR;
  130. SMP_TRACE_EVENT ("%s state=%d br_state=%d flag=0x%x \n",
  131. __FUNCTION__, p_cb->state, p_cb->br_state, p_cb->flags);
  132. if (p_cb->state != SMP_STATE_IDLE || p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD ||
  133. p_cb->smp_over_br) {
  134. /* pending security on going, reject this one */
  135. return SMP_BUSY;
  136. } else {
  137. p_cb->flags = SMP_PAIR_FLAGS_WE_STARTED_DD;
  138. memcpy (p_cb->pairing_bda, bd_addr, BD_ADDR_LEN);
  139. if (!L2CA_ConnectFixedChnl (L2CAP_SMP_CID, bd_addr, BLE_ADDR_UNKNOWN_TYPE)) {
  140. SMP_TRACE_ERROR("%s: L2C connect fixed channel failed.\n", __FUNCTION__);
  141. smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status);
  142. return status;
  143. }
  144. return SMP_STARTED;
  145. }
  146. }
  147. /*******************************************************************************
  148. **
  149. ** Function SMP_BR_PairWith
  150. **
  151. ** Description This function is called to start a SMP pairing over BR/EDR.
  152. ** Device support one SMP pairing at one time.
  153. **
  154. ** Parameters bd_addr - peer device bd address.
  155. **
  156. ** Returns SMP_STARTED if pairing started, otherwise reason for failure.
  157. **
  158. *******************************************************************************/
  159. tSMP_STATUS SMP_BR_PairWith (BD_ADDR bd_addr)
  160. {
  161. tSMP_CB *p_cb = &smp_cb;
  162. UINT8 status = SMP_PAIR_INTERNAL_ERR;
  163. SMP_TRACE_EVENT ("%s state=%d br_state=%d flag=0x%x ",
  164. __func__, p_cb->state, p_cb->br_state, p_cb->flags);
  165. if (p_cb->state != SMP_STATE_IDLE ||
  166. p_cb->smp_over_br ||
  167. p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD) {
  168. /* pending security on going, reject this one */
  169. return SMP_BUSY;
  170. }
  171. p_cb->role = HCI_ROLE_MASTER;
  172. p_cb->flags = SMP_PAIR_FLAGS_WE_STARTED_DD;
  173. p_cb->smp_over_br = TRUE;
  174. memcpy (p_cb->pairing_bda, bd_addr, BD_ADDR_LEN);
  175. if (!L2CA_ConnectFixedChnl (L2CAP_SMP_BR_CID, bd_addr, BLE_ADDR_UNKNOWN_TYPE)) {
  176. SMP_TRACE_ERROR("%s: L2C connect fixed channel failed.", __FUNCTION__);
  177. smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &status);
  178. return status;
  179. }
  180. return SMP_STARTED;
  181. }
  182. /*******************************************************************************
  183. **
  184. ** Function SMP_PairCancel
  185. **
  186. ** Description This function call to cancel a SMP pairing with peer device.
  187. **
  188. ** Parameters bd_addr - peer device bd address.
  189. **
  190. ** Returns TRUE - Pairining is cancelled
  191. **
  192. *******************************************************************************/
  193. BOOLEAN SMP_PairCancel (BD_ADDR bd_addr)
  194. {
  195. tSMP_CB *p_cb = &smp_cb;
  196. UINT8 err_code = SMP_PAIR_FAIL_UNKNOWN;
  197. BOOLEAN status = FALSE;
  198. BTM_TRACE_EVENT ("SMP_CancelPair state=%d flag=0x%x ", p_cb->state, p_cb->flags);
  199. if ( (p_cb->state != SMP_STATE_IDLE) &&
  200. (!memcmp (p_cb->pairing_bda, bd_addr, BD_ADDR_LEN)) ) {
  201. p_cb->is_pair_cancel = TRUE;
  202. SMP_TRACE_DEBUG("Cancel Pairing: set fail reason Unknown");
  203. smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &err_code);
  204. status = TRUE;
  205. }
  206. return status;
  207. }
  208. /*******************************************************************************
  209. **
  210. ** Function SMP_SecurityGrant
  211. **
  212. ** Description This function is called to grant security process.
  213. **
  214. ** Parameters bd_addr - peer device bd address.
  215. ** res - result of the operation SMP_SUCCESS if success.
  216. ** Otherwise, SMP_REPEATED_ATTEMPTS is too many attempts.
  217. **
  218. ** Returns None
  219. **
  220. *******************************************************************************/
  221. void SMP_SecurityGrant(BD_ADDR bd_addr, UINT8 res)
  222. {
  223. SMP_TRACE_EVENT ("SMP_SecurityGrant ");
  224. if (smp_cb.smp_over_br) {
  225. if (smp_cb.br_state != SMP_BR_STATE_WAIT_APP_RSP ||
  226. smp_cb.cb_evt != SMP_SEC_REQUEST_EVT ||
  227. memcmp (smp_cb.pairing_bda, bd_addr, BD_ADDR_LEN)) {
  228. return;
  229. }
  230. /* clear the SMP_SEC_REQUEST_EVT event after get grant */
  231. /* avoid generating duplicate pair request */
  232. smp_cb.cb_evt = 0;
  233. smp_br_state_machine_event(&smp_cb, SMP_BR_API_SEC_GRANT_EVT, &res);
  234. return;
  235. }
  236. if (smp_cb.state != SMP_STATE_WAIT_APP_RSP ||
  237. smp_cb.cb_evt != SMP_SEC_REQUEST_EVT ||
  238. memcmp (smp_cb.pairing_bda, bd_addr, BD_ADDR_LEN)) {
  239. return;
  240. }
  241. /* clear the SMP_SEC_REQUEST_EVT event after get grant */
  242. /* avoid generate duplicate pair request */
  243. smp_cb.cb_evt = 0;
  244. smp_sm_event(&smp_cb, SMP_API_SEC_GRANT_EVT, &res);
  245. }
  246. /*******************************************************************************
  247. **
  248. ** Function SMP_PasskeyReply
  249. **
  250. ** Description This function is called after Security Manager submitted
  251. ** passkey request to the application.
  252. **
  253. ** Parameters: bd_addr - Address of the device for which passkey was requested
  254. ** res - result of the operation SMP_SUCCESS if success
  255. ** passkey - numeric value in the range of
  256. ** BTM_MIN_PASSKEY_VAL(0) - BTM_MAX_PASSKEY_VAL(999999(0xF423F)).
  257. **
  258. *******************************************************************************/
  259. void SMP_PasskeyReply (BD_ADDR bd_addr, UINT8 res, UINT32 passkey)
  260. {
  261. tSMP_CB *p_cb = & smp_cb;
  262. UINT8 failure = SMP_PASSKEY_ENTRY_FAIL;
  263. SMP_TRACE_EVENT ("SMP_PasskeyReply: Key: %d Result:%d",
  264. passkey, res);
  265. /* If timeout already expired or has been canceled, ignore the reply */
  266. if (p_cb->cb_evt != SMP_PASSKEY_REQ_EVT) {
  267. SMP_TRACE_WARNING ("SMP_PasskeyReply() - Wrong State: %d", p_cb->state);
  268. return;
  269. }
  270. if (memcmp (bd_addr, p_cb->pairing_bda, BD_ADDR_LEN) != 0) {
  271. SMP_TRACE_ERROR ("SMP_PasskeyReply() - Wrong BD Addr");
  272. return;
  273. }
  274. if (btm_find_dev (bd_addr) == NULL) {
  275. SMP_TRACE_ERROR ("SMP_PasskeyReply() - no dev CB");
  276. return;
  277. }
  278. if (passkey > BTM_MAX_PASSKEY_VAL || res != SMP_SUCCESS) {
  279. SMP_TRACE_WARNING ("SMP_PasskeyReply() - Wrong key len: %d or passkey entry fail", passkey);
  280. /* send pairing failure */
  281. smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &failure);
  282. } else if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_PASSKEY_ENT) {
  283. smp_sm_event(&smp_cb, SMP_SC_KEY_READY_EVT, &passkey);
  284. } else {
  285. smp_convert_string_to_tk(p_cb->tk, passkey);
  286. }
  287. return;
  288. }
  289. /*******************************************************************************
  290. **
  291. ** Function SMP_SetStaticPasskey
  292. **
  293. ** Description This function is called to set static passkey
  294. **
  295. **
  296. ** Parameters: add - set static passkey when add is TRUE
  297. ** clear static passkey when add is FALSE
  298. ** passkey - static passkey
  299. **
  300. **
  301. *******************************************************************************/
  302. void SMP_SetStaticPasskey (BOOLEAN add, UINT32 passkey)
  303. {
  304. SMP_TRACE_DEBUG("static passkey %6d", passkey);
  305. tSMP_CB *p_cb = & smp_cb;
  306. if(add) {
  307. p_cb->static_passkey = passkey;
  308. p_cb->use_static_passkey = true;
  309. } else {
  310. p_cb->static_passkey = 0;
  311. p_cb->use_static_passkey = false;
  312. }
  313. }
  314. /*******************************************************************************
  315. **
  316. ** Function SMP_ConfirmReply
  317. **
  318. ** Description This function is called after Security Manager submitted
  319. ** numeric comparison request to the application.
  320. **
  321. ** Parameters: bd_addr - Address of the device with which numeric
  322. ** comparison was requested
  323. ** res - comparison result SMP_SUCCESS if success
  324. **
  325. *******************************************************************************/
  326. void SMP_ConfirmReply (BD_ADDR bd_addr, UINT8 res)
  327. {
  328. tSMP_CB *p_cb = & smp_cb;
  329. UINT8 failure = SMP_NUMERIC_COMPAR_FAIL;
  330. SMP_TRACE_EVENT ("%s: Result:%d", __FUNCTION__, res);
  331. /* If timeout already expired or has been canceled, ignore the reply */
  332. if (p_cb->cb_evt != SMP_NC_REQ_EVT) {
  333. SMP_TRACE_WARNING ("%s() - Wrong State: %d", __FUNCTION__, p_cb->state);
  334. return;
  335. }
  336. if (memcmp (bd_addr, p_cb->pairing_bda, BD_ADDR_LEN) != 0) {
  337. SMP_TRACE_ERROR ("%s() - Wrong BD Addr", __FUNCTION__);
  338. return;
  339. }
  340. if (btm_find_dev (bd_addr) == NULL) {
  341. SMP_TRACE_ERROR ("%s() - no dev CB", __FUNCTION__);
  342. return;
  343. }
  344. if (res != SMP_SUCCESS) {
  345. SMP_TRACE_WARNING ("%s() - Numeric Comparison fails", __FUNCTION__);
  346. /* send pairing failure */
  347. smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &failure);
  348. } else {
  349. smp_sm_event(p_cb, SMP_SC_NC_OK_EVT, NULL);
  350. }
  351. }
  352. /*******************************************************************************
  353. **
  354. ** Function SMP_OobDataReply
  355. **
  356. ** Description This function is called to provide the OOB data for
  357. ** SMP in response to SMP_OOB_REQ_EVT
  358. **
  359. ** Parameters: bd_addr - Address of the peer device
  360. ** res - result of the operation SMP_SUCCESS if success
  361. ** p_data - simple pairing Randomizer C.
  362. **
  363. *******************************************************************************/
  364. void SMP_OobDataReply(BD_ADDR bd_addr, tSMP_STATUS res, UINT8 len, UINT8 *p_data)
  365. {
  366. tSMP_CB *p_cb = & smp_cb;
  367. UINT8 failure = SMP_OOB_FAIL;
  368. tSMP_KEY key;
  369. SMP_TRACE_EVENT ("%s State: %d res:%d", __FUNCTION__, smp_cb.state, res);
  370. /* If timeout already expired or has been canceled, ignore the reply */
  371. if (p_cb->state != SMP_STATE_WAIT_APP_RSP || p_cb->cb_evt != SMP_OOB_REQ_EVT) {
  372. return;
  373. }
  374. if (res != SMP_SUCCESS || len == 0 || !p_data) {
  375. smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &failure);
  376. } else {
  377. if (len > BT_OCTET16_LEN) {
  378. len = BT_OCTET16_LEN;
  379. }
  380. memcpy(p_cb->tk, p_data, len);
  381. key.key_type = SMP_KEY_TYPE_TK;
  382. key.p_data = p_cb->tk;
  383. smp_sm_event(&smp_cb, SMP_KEY_READY_EVT, &key);
  384. }
  385. }
  386. /*******************************************************************************
  387. **
  388. ** Function SMP_SecureConnectionOobDataReply
  389. **
  390. ** Description This function is called to provide the SC OOB data for
  391. ** SMP in response to SMP_SC_OOB_REQ_EVT
  392. **
  393. ** Parameters: p_data - pointer to the data
  394. **
  395. *******************************************************************************/
  396. void SMP_SecureConnectionOobDataReply(UINT8 *p_data)
  397. {
  398. tSMP_CB *p_cb = &smp_cb;
  399. UINT8 failure = SMP_OOB_FAIL;
  400. tSMP_SC_OOB_DATA *p_oob = (tSMP_SC_OOB_DATA *) p_data;
  401. if (!p_oob) {
  402. SMP_TRACE_ERROR("%s received no data", __FUNCTION__);
  403. smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &failure);
  404. return;
  405. }
  406. SMP_TRACE_EVENT ("%s req_oob_type: %d, loc_oob_data.present: %d, "
  407. "peer_oob_data.present: %d",
  408. __FUNCTION__, p_cb->req_oob_type, p_oob->loc_oob_data.present,
  409. p_oob->peer_oob_data.present);
  410. if (p_cb->state != SMP_STATE_WAIT_APP_RSP || p_cb->cb_evt != SMP_SC_OOB_REQ_EVT) {
  411. return;
  412. }
  413. BOOLEAN data_missing = FALSE;
  414. switch (p_cb->req_oob_type) {
  415. case SMP_OOB_PEER:
  416. if (!p_oob->peer_oob_data.present) {
  417. data_missing = TRUE;
  418. }
  419. break;
  420. case SMP_OOB_LOCAL:
  421. if (!p_oob->loc_oob_data.present) {
  422. data_missing = TRUE;
  423. }
  424. break;
  425. case SMP_OOB_BOTH:
  426. if (!p_oob->loc_oob_data.present || !p_oob->peer_oob_data.present) {
  427. data_missing = TRUE;
  428. }
  429. break;
  430. default:
  431. SMP_TRACE_EVENT ("Unexpected OOB data type requested. Fail OOB");
  432. data_missing = TRUE;
  433. break;
  434. }
  435. if (data_missing) {
  436. smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &failure);
  437. return;
  438. }
  439. p_cb->sc_oob_data = *p_oob;
  440. smp_sm_event(&smp_cb, SMP_SC_OOB_DATA_EVT, p_data);
  441. }
  442. /*******************************************************************************
  443. **
  444. ** Function SMP_Encrypt
  445. **
  446. ** Description This function is called to encrypt the data with the specified
  447. ** key
  448. **
  449. ** Parameters: key - Pointer to key key[0] conatins the MSB
  450. ** key_len - key length
  451. ** plain_text - Pointer to data to be encrypted
  452. ** plain_text[0] conatins the MSB
  453. ** pt_len - plain text length
  454. ** p_out - output of the encrypted texts
  455. **
  456. ** Returns Boolean - request is successful
  457. *******************************************************************************/
  458. BOOLEAN SMP_Encrypt (UINT8 *key, UINT8 key_len,
  459. UINT8 *plain_text, UINT8 pt_len,
  460. tSMP_ENC *p_out)
  461. {
  462. BOOLEAN status = FALSE;
  463. status = smp_encrypt_data(key, key_len, plain_text, pt_len, p_out);
  464. return status;
  465. }
  466. /*******************************************************************************
  467. **
  468. ** Function SMP_KeypressNotification
  469. **
  470. ** Description This function is called to notify Security Manager about Keypress Notification.
  471. **
  472. ** Parameters: bd_addr Address of the device to send keypress notification to
  473. ** value Keypress notification parameter value
  474. **
  475. *******************************************************************************/
  476. void SMP_KeypressNotification (BD_ADDR bd_addr, UINT8 value)
  477. {
  478. tSMP_CB *p_cb = &smp_cb;
  479. SMP_TRACE_EVENT ("%s: Value: %d", __FUNCTION__, value);
  480. if (memcmp (bd_addr, p_cb->pairing_bda, BD_ADDR_LEN) != 0) {
  481. SMP_TRACE_ERROR ("%s() - Wrong BD Addr", __FUNCTION__);
  482. return;
  483. }
  484. if (btm_find_dev (bd_addr) == NULL) {
  485. SMP_TRACE_ERROR ("%s() - no dev CB", __FUNCTION__);
  486. return;
  487. }
  488. /* Keypress Notification is used by a device with KeyboardOnly IO capabilities */
  489. /* during the passkey entry protocol */
  490. if (p_cb->local_io_capability != SMP_IO_CAP_IN) {
  491. SMP_TRACE_ERROR ("%s() - wrong local IO capabilities %d",
  492. __FUNCTION__, p_cb->local_io_capability);
  493. return;
  494. }
  495. if (p_cb->selected_association_model != SMP_MODEL_SEC_CONN_PASSKEY_ENT) {
  496. SMP_TRACE_ERROR ("%s() - wrong protocol %d", __FUNCTION__,
  497. p_cb->selected_association_model);
  498. return;
  499. }
  500. smp_sm_event(p_cb, SMP_KEYPRESS_NOTIFICATION_EVENT, &value);
  501. }
  502. /*******************************************************************************
  503. **
  504. ** Function SMP_CreateLocalSecureConnectionsOobData
  505. **
  506. ** Description This function is called to start creation of local SC OOB
  507. ** data set (tSMP_LOC_OOB_DATA).
  508. **
  509. ** Parameters: bd_addr - Address of the device to send OOB data block to
  510. **
  511. ** Returns Boolean - TRUE: creation of local SC OOB data set started.
  512. *******************************************************************************/
  513. BOOLEAN SMP_CreateLocalSecureConnectionsOobData (tBLE_BD_ADDR *addr_to_send_to)
  514. {
  515. tSMP_CB *p_cb = &smp_cb;
  516. UINT8 *bd_addr;
  517. if (addr_to_send_to == NULL) {
  518. SMP_TRACE_ERROR ("%s addr_to_send_to is not provided", __FUNCTION__);
  519. return FALSE;
  520. }
  521. bd_addr = addr_to_send_to->bda;
  522. SMP_TRACE_EVENT ("%s addr type: %u, BDA: %08x%04x, state: %u, br_state: %u",
  523. __FUNCTION__, addr_to_send_to->type,
  524. (bd_addr[0] << 24) + (bd_addr[1] << 16) + (bd_addr[2] << 8) + bd_addr[3],
  525. (bd_addr[4] << 8) + bd_addr[5],
  526. p_cb->state,
  527. p_cb->br_state);
  528. if ((p_cb->state != SMP_STATE_IDLE) || (p_cb->smp_over_br)) {
  529. SMP_TRACE_WARNING ("%s creation of local OOB data set "\
  530. "starts only in IDLE state", __FUNCTION__);
  531. return FALSE;
  532. }
  533. p_cb->sc_oob_data.loc_oob_data.addr_sent_to = *addr_to_send_to;
  534. smp_sm_event(p_cb, SMP_CR_LOC_SC_OOB_DATA_EVT, NULL);
  535. return TRUE;
  536. }
  537. #endif /* SMP_INCLUDED */