btm_devctl.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 1999-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 functions that handle BTM interface functions for the
  21. * Bluetooth device including Rest, HCI buffer size and others
  22. *
  23. ******************************************************************************/
  24. #include <stdlib.h>
  25. #include <string.h>
  26. //#include <stdio.h>
  27. #include <stddef.h>
  28. #include "common/bt_trace.h"
  29. #include "stack/bt_types.h"
  30. //#include "bt_utils.h"
  31. #include "btm_int.h"
  32. #include "stack/btu.h"
  33. #include "device/controller.h"
  34. #include "hci/hci_layer.h"
  35. #include "stack/hcimsgs.h"
  36. #include "l2c_int.h"
  37. //#include "btcore/include/module.h"
  38. //#include "osi/include/osi/thread.h"
  39. #if BLE_INCLUDED == TRUE
  40. #include "gatt_int.h"
  41. #endif /* BLE_INCLUDED */
  42. //extern thread_t *bt_workqueue_thread;
  43. /********************************************************************************/
  44. /* L O C A L D A T A D E F I N I T I O N S */
  45. /********************************************************************************/
  46. #ifndef BTM_DEV_RESET_TIMEOUT
  47. #define BTM_DEV_RESET_TIMEOUT 4
  48. #endif
  49. #define BTM_DEV_REPLY_TIMEOUT 2 /* 1 second expiration time is not good. Timer may start between 0 and 1 second. */
  50. /* if it starts at the very end of the 0 second, timer will expire really easily. */
  51. #define BTM_INFO_TIMEOUT 5 /* 5 seconds for info response */
  52. /********************************************************************************/
  53. /* L O C A L F U N C T I O N P R O T O T Y P E S */
  54. /********************************************************************************/
  55. static void btm_decode_ext_features_page (UINT8 page_number, const BD_FEATURES p_features);
  56. /*******************************************************************************
  57. **
  58. ** Function btm_dev_init
  59. **
  60. ** Description This function is on the BTM startup
  61. **
  62. ** Returns void
  63. **
  64. *******************************************************************************/
  65. void btm_dev_init (void)
  66. {
  67. #if 0 /* cleared in btm_init; put back in if called from anywhere else! */
  68. memset (&btm_cb.devcb, 0, sizeof (tBTM_DEVCB));
  69. #endif
  70. /* Initialize nonzero defaults */
  71. #if (BTM_MAX_LOC_BD_NAME_LEN > 0)
  72. memset(btm_cb.cfg.bd_name, 0, sizeof(tBTM_LOC_BD_NAME));
  73. #endif
  74. btm_cb.devcb.reset_timer.param = (TIMER_PARAM_TYPE)TT_DEV_RESET;
  75. btm_cb.devcb.rln_timer.param = (TIMER_PARAM_TYPE)TT_DEV_RLN;
  76. btm_cb.btm_acl_pkt_types_supported = BTM_ACL_PKT_TYPES_MASK_DH1 + BTM_ACL_PKT_TYPES_MASK_DM1 +
  77. BTM_ACL_PKT_TYPES_MASK_DH3 + BTM_ACL_PKT_TYPES_MASK_DM3 +
  78. BTM_ACL_PKT_TYPES_MASK_DH5 + BTM_ACL_PKT_TYPES_MASK_DM5;
  79. btm_cb.btm_sco_pkt_types_supported = BTM_SCO_PKT_TYPES_MASK_HV1 +
  80. BTM_SCO_PKT_TYPES_MASK_HV2 +
  81. BTM_SCO_PKT_TYPES_MASK_HV3 +
  82. BTM_SCO_PKT_TYPES_MASK_EV3 +
  83. BTM_SCO_PKT_TYPES_MASK_EV4 +
  84. BTM_SCO_PKT_TYPES_MASK_EV5;
  85. }
  86. /*******************************************************************************
  87. **
  88. ** Function btm_db_reset
  89. **
  90. ** Description This function is called by BTM_DeviceReset and clears out any
  91. ** pending callbacks for inquiries, discoveries, other pending
  92. ** functions that may be in progress.
  93. **
  94. ** Returns void
  95. **
  96. *******************************************************************************/
  97. static void btm_db_reset (void)
  98. {
  99. tBTM_CMPL_CB *p_cb;
  100. tBTM_STATUS status = BTM_DEV_RESET;
  101. btm_inq_db_reset();
  102. if (btm_cb.devcb.p_rln_cmpl_cb) {
  103. p_cb = btm_cb.devcb.p_rln_cmpl_cb;
  104. btm_cb.devcb.p_rln_cmpl_cb = NULL;
  105. if (p_cb) {
  106. (*p_cb)((void *) NULL);
  107. }
  108. }
  109. if (btm_cb.devcb.p_rssi_cmpl_cb) {
  110. p_cb = btm_cb.devcb.p_rssi_cmpl_cb;
  111. btm_cb.devcb.p_rssi_cmpl_cb = NULL;
  112. if (p_cb) {
  113. (*p_cb)((tBTM_RSSI_RESULTS *) &status);
  114. }
  115. }
  116. }
  117. static void reset_complete(void)
  118. {
  119. const controller_t *controller = controller_get_interface();
  120. /* Tell L2CAP that all connections are gone */
  121. l2cu_device_reset ();
  122. #if (SMP_INCLUDED == TRUE)
  123. /* Clear current security state */
  124. {
  125. list_node_t *p_node = NULL;
  126. for (p_node = list_begin(btm_cb.p_sec_dev_rec_list); p_node; p_node = list_next(p_node)) {
  127. tBTM_SEC_DEV_REC *p_dev_rec = (tBTM_SEC_DEV_REC *) list_node(p_node);
  128. p_dev_rec->sec_state = BTM_SEC_STATE_IDLE;
  129. }
  130. }
  131. #endif ///SMP_INCLUDED == TRUE
  132. /* After the reset controller should restore all parameters to defaults. */
  133. btm_cb.btm_inq_vars.inq_counter = 1;
  134. btm_cb.btm_inq_vars.inq_scan_window = HCI_DEF_INQUIRYSCAN_WINDOW;
  135. btm_cb.btm_inq_vars.inq_scan_period = HCI_DEF_INQUIRYSCAN_INTERVAL;
  136. btm_cb.btm_inq_vars.inq_scan_type = HCI_DEF_SCAN_TYPE;
  137. btm_cb.btm_inq_vars.page_scan_window = HCI_DEF_PAGESCAN_WINDOW;
  138. btm_cb.btm_inq_vars.page_scan_period = HCI_DEF_PAGESCAN_INTERVAL;
  139. btm_cb.btm_inq_vars.page_scan_type = HCI_DEF_SCAN_TYPE;
  140. #if (BLE_INCLUDED == TRUE)
  141. btm_cb.ble_ctr_cb.conn_state = BLE_CONN_IDLE;
  142. btm_cb.ble_ctr_cb.bg_conn_type = BTM_BLE_CONN_NONE;
  143. btm_cb.ble_ctr_cb.p_select_cback = NULL;
  144. gatt_reset_bgdev_list();
  145. btm_ble_multi_adv_init();
  146. #endif
  147. btm_pm_reset();
  148. l2c_link_processs_num_bufs(controller->get_acl_buffer_count_classic());
  149. #if BTM_SCO_HCI_INCLUDED == TRUE
  150. btm_sco_process_num_bufs(controller->get_sco_buffer_count());
  151. #endif
  152. #if (BLE_INCLUDED == TRUE)
  153. #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE)
  154. /* Set up the BLE privacy settings */
  155. if (controller->supports_ble() && controller->supports_ble_privacy() &&
  156. controller->get_ble_resolving_list_max_size() > 0) {
  157. btm_ble_resolving_list_init(controller->get_ble_resolving_list_max_size());
  158. /* set the default random private address timeout */
  159. btsnd_hcic_ble_set_rand_priv_addr_timeout(BTM_BLE_PRIVATE_ADDR_INT);
  160. }
  161. #endif
  162. if (controller->supports_ble()) {
  163. btm_ble_white_list_init(controller->get_ble_white_list_size());
  164. l2c_link_processs_ble_num_bufs(controller->get_acl_buffer_count_ble());
  165. }
  166. #endif
  167. #if (SMP_INCLUDED == TRUE && CLASSIC_BT_INCLUDED == TRUE)
  168. BTM_SetPinType (btm_cb.cfg.pin_type, btm_cb.cfg.pin_code, btm_cb.cfg.pin_code_len);
  169. #endif ///SMP_INCLUDED == TRUE && CLASSIC_BT_INCLUDED == TRUE
  170. for (int i = 0; i <= controller->get_last_features_classic_index(); i++) {
  171. btm_decode_ext_features_page(i, controller->get_features_classic(i)->as_array);
  172. }
  173. btm_report_device_status(BTM_DEV_STATUS_UP);
  174. }
  175. // TODO(zachoverflow): remove this function
  176. void BTM_DeviceReset (UNUSED_ATTR tBTM_CMPL_CB *p_cb)
  177. {
  178. /* Flush all ACL connections */
  179. btm_acl_device_down();
  180. /* Clear the callback, so application would not hang on reset */
  181. btm_db_reset();
  182. /* todo: review the below logic; start_up executes under another task context
  183. * reset_complete runs in btu task */
  184. controller_get_interface()->start_up();
  185. reset_complete();
  186. }
  187. /*******************************************************************************
  188. **
  189. ** Function BTM_IsDeviceUp
  190. **
  191. ** Description This function is called to check if the device is up.
  192. **
  193. ** Returns TRUE if device is up, else FALSE
  194. **
  195. *******************************************************************************/
  196. BOOLEAN BTM_IsDeviceUp (void)
  197. {
  198. return controller_get_interface()->get_is_ready();
  199. }
  200. /*******************************************************************************
  201. **
  202. ** Function btm_dev_timeout
  203. **
  204. ** Description This function is called when a timer list entry expires.
  205. **
  206. ** Returns void
  207. **
  208. *******************************************************************************/
  209. void btm_dev_timeout (TIMER_LIST_ENT *p_tle)
  210. {
  211. TIMER_PARAM_TYPE timer_type = (TIMER_PARAM_TYPE)p_tle->param;
  212. if (timer_type == (TIMER_PARAM_TYPE)TT_DEV_RLN) {
  213. tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rln_cmpl_cb;
  214. btm_cb.devcb.p_rln_cmpl_cb = NULL;
  215. if (p_cb) {
  216. (*p_cb)((void *) NULL);
  217. }
  218. }
  219. }
  220. /*******************************************************************************
  221. **
  222. ** Function btm_decode_ext_features_page
  223. **
  224. ** Description This function is decodes a features page.
  225. **
  226. ** Returns void
  227. **
  228. *******************************************************************************/
  229. static void btm_decode_ext_features_page (UINT8 page_number, const BD_FEATURES p_features)
  230. {
  231. BTM_TRACE_DEBUG ("btm_decode_ext_features_page page: %d", page_number);
  232. switch (page_number) {
  233. /* Extended (Legacy) Page 0 */
  234. case HCI_EXT_FEATURES_PAGE_0:
  235. /* Create ACL supported packet types mask */
  236. btm_cb.btm_acl_pkt_types_supported = (BTM_ACL_PKT_TYPES_MASK_DH1 +
  237. BTM_ACL_PKT_TYPES_MASK_DM1);
  238. if (HCI_3_SLOT_PACKETS_SUPPORTED(p_features)) {
  239. btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_DH3 +
  240. BTM_ACL_PKT_TYPES_MASK_DM3);
  241. }
  242. if (HCI_5_SLOT_PACKETS_SUPPORTED(p_features)) {
  243. btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_DH5 +
  244. BTM_ACL_PKT_TYPES_MASK_DM5);
  245. }
  246. /* Add in EDR related ACL types */
  247. if (!HCI_EDR_ACL_2MPS_SUPPORTED(p_features)) {
  248. btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH1 +
  249. BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 +
  250. BTM_ACL_PKT_TYPES_MASK_NO_2_DH5);
  251. }
  252. if (!HCI_EDR_ACL_3MPS_SUPPORTED(p_features)) {
  253. btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_NO_3_DH1 +
  254. BTM_ACL_PKT_TYPES_MASK_NO_3_DH3 +
  255. BTM_ACL_PKT_TYPES_MASK_NO_3_DH5);
  256. }
  257. /* Check to see if 3 and 5 slot packets are available */
  258. if (HCI_EDR_ACL_2MPS_SUPPORTED(p_features) ||
  259. HCI_EDR_ACL_3MPS_SUPPORTED(p_features)) {
  260. if (!HCI_3_SLOT_EDR_ACL_SUPPORTED(p_features)) {
  261. btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 +
  262. BTM_ACL_PKT_TYPES_MASK_NO_3_DH3);
  263. }
  264. if (!HCI_5_SLOT_EDR_ACL_SUPPORTED(p_features)) {
  265. btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH5 +
  266. BTM_ACL_PKT_TYPES_MASK_NO_3_DH5);
  267. }
  268. }
  269. BTM_TRACE_DEBUG("Local supported ACL packet types: 0x%04x",
  270. btm_cb.btm_acl_pkt_types_supported);
  271. /* Create (e)SCO supported packet types mask */
  272. btm_cb.btm_sco_pkt_types_supported = 0;
  273. #if BTM_SCO_INCLUDED == TRUE
  274. btm_cb.sco_cb.esco_supported = FALSE;
  275. #endif
  276. if (HCI_SCO_LINK_SUPPORTED(p_features)) {
  277. btm_cb.btm_sco_pkt_types_supported = BTM_SCO_PKT_TYPES_MASK_HV1;
  278. if (HCI_HV2_PACKETS_SUPPORTED(p_features)) {
  279. btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_HV2;
  280. }
  281. if (HCI_HV3_PACKETS_SUPPORTED(p_features)) {
  282. btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_HV3;
  283. }
  284. }
  285. if (HCI_ESCO_EV3_SUPPORTED(p_features)) {
  286. btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_EV3;
  287. }
  288. if (HCI_ESCO_EV4_SUPPORTED(p_features)) {
  289. btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_EV4;
  290. }
  291. if (HCI_ESCO_EV5_SUPPORTED(p_features)) {
  292. btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_EV5;
  293. }
  294. #if BTM_SCO_INCLUDED == TRUE
  295. if (btm_cb.btm_sco_pkt_types_supported & BTM_ESCO_LINK_ONLY_MASK) {
  296. btm_cb.sco_cb.esco_supported = TRUE;
  297. /* Add in EDR related eSCO types */
  298. if (HCI_EDR_ESCO_2MPS_SUPPORTED(p_features)) {
  299. if (!HCI_3_SLOT_EDR_ESCO_SUPPORTED(p_features)) {
  300. btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_NO_2_EV5;
  301. }
  302. } else {
  303. btm_cb.btm_sco_pkt_types_supported |= (BTM_SCO_PKT_TYPES_MASK_NO_2_EV3 +
  304. BTM_SCO_PKT_TYPES_MASK_NO_2_EV5);
  305. }
  306. if (HCI_EDR_ESCO_3MPS_SUPPORTED(p_features)) {
  307. if (!HCI_3_SLOT_EDR_ESCO_SUPPORTED(p_features)) {
  308. btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_NO_3_EV5;
  309. }
  310. } else {
  311. btm_cb.btm_sco_pkt_types_supported |= (BTM_SCO_PKT_TYPES_MASK_NO_3_EV3 +
  312. BTM_SCO_PKT_TYPES_MASK_NO_3_EV5);
  313. }
  314. }
  315. #endif
  316. BTM_TRACE_DEBUG("Local supported SCO packet types: 0x%04x",
  317. btm_cb.btm_sco_pkt_types_supported);
  318. /* Create Default Policy Settings */
  319. if (HCI_SWITCH_SUPPORTED(p_features)) {
  320. btm_cb.btm_def_link_policy |= HCI_ENABLE_MASTER_SLAVE_SWITCH;
  321. } else {
  322. btm_cb.btm_def_link_policy &= ~HCI_ENABLE_MASTER_SLAVE_SWITCH;
  323. }
  324. if (HCI_HOLD_MODE_SUPPORTED(p_features)) {
  325. btm_cb.btm_def_link_policy |= HCI_ENABLE_HOLD_MODE;
  326. } else {
  327. btm_cb.btm_def_link_policy &= ~HCI_ENABLE_HOLD_MODE;
  328. }
  329. if (HCI_SNIFF_MODE_SUPPORTED(p_features)) {
  330. btm_cb.btm_def_link_policy |= HCI_ENABLE_SNIFF_MODE;
  331. } else {
  332. btm_cb.btm_def_link_policy &= ~HCI_ENABLE_SNIFF_MODE;
  333. }
  334. if (HCI_PARK_MODE_SUPPORTED(p_features)) {
  335. btm_cb.btm_def_link_policy |= HCI_ENABLE_PARK_MODE;
  336. } else {
  337. btm_cb.btm_def_link_policy &= ~HCI_ENABLE_PARK_MODE;
  338. }
  339. btm_sec_dev_reset ();
  340. if (HCI_LMP_INQ_RSSI_SUPPORTED(p_features)) {
  341. if (HCI_EXT_INQ_RSP_SUPPORTED(p_features)) {
  342. BTM_SetInquiryMode (BTM_INQ_RESULT_EXTENDED);
  343. } else {
  344. BTM_SetInquiryMode (BTM_INQ_RESULT_WITH_RSSI);
  345. }
  346. }
  347. #if L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE
  348. if ( HCI_NON_FLUSHABLE_PB_SUPPORTED(p_features)) {
  349. l2cu_set_non_flushable_pbf(TRUE);
  350. } else {
  351. l2cu_set_non_flushable_pbf(FALSE);
  352. }
  353. #endif
  354. BTM_SetPageScanType (BTM_DEFAULT_SCAN_TYPE);
  355. BTM_SetInquiryScanType (BTM_DEFAULT_SCAN_TYPE);
  356. break;
  357. /* Extended Page 1 */
  358. case HCI_EXT_FEATURES_PAGE_1:
  359. /* Nothing to do for page 1 */
  360. break;
  361. /* Extended Page 2 */
  362. case HCI_EXT_FEATURES_PAGE_2:
  363. /* Nothing to do for page 2 */
  364. break;
  365. default:
  366. BTM_TRACE_ERROR("btm_decode_ext_features_page page=%d unknown", page_number);
  367. break;
  368. }
  369. }
  370. /*******************************************************************************
  371. **
  372. ** Function BTM_SetLocalDeviceName
  373. **
  374. ** Description This function is called to set the local device name.
  375. **
  376. ** Returns status of the operation
  377. **
  378. *******************************************************************************/
  379. tBTM_STATUS BTM_SetLocalDeviceName (char *p_name)
  380. {
  381. UINT8 *p;
  382. if (!p_name || !p_name[0] || (strlen ((char *)p_name) > BD_NAME_LEN)) {
  383. return (BTM_ILLEGAL_VALUE);
  384. }
  385. if (!controller_get_interface()->get_is_ready()) {
  386. return (BTM_DEV_RESET);
  387. }
  388. #if BTM_MAX_LOC_BD_NAME_LEN > 0
  389. /* Save the device name if local storage is enabled */
  390. p = (UINT8 *)btm_cb.cfg.bd_name;
  391. if (p != (UINT8 *)p_name) {
  392. BCM_STRNCPY_S(btm_cb.cfg.bd_name, p_name, BTM_MAX_LOC_BD_NAME_LEN);
  393. btm_cb.cfg.bd_name[BTM_MAX_LOC_BD_NAME_LEN] = '\0';
  394. }
  395. #else
  396. p = (UINT8 *)p_name;
  397. #endif
  398. #if CLASSIC_BT_INCLUDED
  399. if (btsnd_hcic_change_name(p)) {
  400. return (BTM_CMD_STARTED);
  401. } else
  402. #endif
  403. {
  404. return (BTM_NO_RESOURCES);
  405. }
  406. }
  407. /*******************************************************************************
  408. **
  409. ** Function BTM_ReadLocalDeviceName
  410. **
  411. ** Description This function is called to read the local device name.
  412. **
  413. ** Returns status of the operation
  414. ** If success, BTM_SUCCESS is returned and p_name points stored
  415. ** local device name
  416. ** If BTM doesn't store local device name, BTM_NO_RESOURCES is
  417. ** is returned and p_name is set to NULL
  418. **
  419. *******************************************************************************/
  420. tBTM_STATUS BTM_ReadLocalDeviceName (char **p_name)
  421. {
  422. #if BTM_MAX_LOC_BD_NAME_LEN > 0
  423. *p_name = btm_cb.cfg.bd_name;
  424. return (BTM_SUCCESS);
  425. #else
  426. *p_name = NULL;
  427. return (BTM_NO_RESOURCES);
  428. #endif
  429. }
  430. /*******************************************************************************
  431. **
  432. ** Function BTM_ReadLocalDeviceNameFromController
  433. **
  434. ** Description Get local device name from controller. Do not use cached
  435. ** name (used to get chip-id prior to btm reset complete).
  436. **
  437. ** Returns BTM_CMD_STARTED if successful, otherwise an error
  438. **
  439. *******************************************************************************/
  440. tBTM_STATUS BTM_ReadLocalDeviceNameFromController (tBTM_CMPL_CB *p_rln_cmpl_cback)
  441. {
  442. /* Check if rln already in progress */
  443. if (btm_cb.devcb.p_rln_cmpl_cb) {
  444. return (BTM_NO_RESOURCES);
  445. }
  446. /* Save callback */
  447. btm_cb.devcb.p_rln_cmpl_cb = p_rln_cmpl_cback;
  448. btsnd_hcic_read_name();
  449. btu_start_timer (&btm_cb.devcb.rln_timer, BTU_TTYPE_BTM_DEV_CTL, BTM_DEV_REPLY_TIMEOUT);
  450. return BTM_CMD_STARTED;
  451. }
  452. /*******************************************************************************
  453. **
  454. ** Function btm_read_local_name_complete
  455. **
  456. ** Description This function is called when local name read complete.
  457. ** message is received from the HCI.
  458. **
  459. ** Returns void
  460. **
  461. *******************************************************************************/
  462. void btm_read_local_name_complete (UINT8 *p, UINT16 evt_len)
  463. {
  464. tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rln_cmpl_cb;
  465. UINT8 status;
  466. UNUSED(evt_len);
  467. btu_free_timer (&btm_cb.devcb.rln_timer);
  468. /* If there was a callback address for read local name, call it */
  469. btm_cb.devcb.p_rln_cmpl_cb = NULL;
  470. if (p_cb) {
  471. STREAM_TO_UINT8 (status, p);
  472. if (status == HCI_SUCCESS) {
  473. (*p_cb)(p);
  474. } else {
  475. (*p_cb)(NULL);
  476. }
  477. }
  478. }
  479. /*******************************************************************************
  480. **
  481. ** Function BTM_SetDeviceClass
  482. **
  483. ** Description This function is called to set the local device class
  484. **
  485. ** Returns status of the operation
  486. **
  487. *******************************************************************************/
  488. tBTM_STATUS BTM_SetDeviceClass (DEV_CLASS dev_class)
  489. {
  490. if (!memcmp (btm_cb.devcb.dev_class, dev_class, DEV_CLASS_LEN)) {
  491. return (BTM_SUCCESS);
  492. }
  493. memcpy (btm_cb.devcb.dev_class, dev_class, DEV_CLASS_LEN);
  494. if (!controller_get_interface()->get_is_ready()) {
  495. return (BTM_DEV_RESET);
  496. }
  497. if (!btsnd_hcic_write_dev_class (dev_class)) {
  498. return (BTM_NO_RESOURCES);
  499. }
  500. return (BTM_SUCCESS);
  501. }
  502. /*******************************************************************************
  503. **
  504. ** Function BTM_ReadDeviceClass
  505. **
  506. ** Description This function is called to read the local device class
  507. **
  508. ** Returns pointer to the device class
  509. **
  510. *******************************************************************************/
  511. UINT8 *BTM_ReadDeviceClass (void)
  512. {
  513. return ((UINT8 *)btm_cb.devcb.dev_class);
  514. }
  515. /*******************************************************************************
  516. **
  517. ** Function BTM_ReadLocalFeatures
  518. **
  519. ** Description This function is called to read the local features
  520. **
  521. ** Returns pointer to the local features string
  522. **
  523. *******************************************************************************/
  524. // TODO(zachoverflow): get rid of this function
  525. UINT8 *BTM_ReadLocalFeatures (void)
  526. {
  527. // Discarding const modifier for now, until this function dies
  528. return (UINT8 *)controller_get_interface()->get_features_classic(0)->as_array;
  529. }
  530. /*******************************************************************************
  531. **
  532. ** Function BTM_RegisterForDeviceStatusNotif
  533. **
  534. ** Description This function is called to register for device status
  535. ** change notifications.
  536. **
  537. ** If one registration is already there calling function should
  538. ** save the pointer to the function that is return and
  539. ** call it when processing of the event is complete
  540. **
  541. ** Returns status of the operation
  542. **
  543. *******************************************************************************/
  544. tBTM_DEV_STATUS_CB *BTM_RegisterForDeviceStatusNotif (tBTM_DEV_STATUS_CB *p_cb)
  545. {
  546. tBTM_DEV_STATUS_CB *p_prev = btm_cb.devcb.p_dev_status_cb;
  547. btm_cb.devcb.p_dev_status_cb = p_cb;
  548. return (p_prev);
  549. }
  550. /*******************************************************************************
  551. **
  552. ** Function BTM_VendorSpecificCommand
  553. **
  554. ** Description Send a vendor specific HCI command to the controller.
  555. **
  556. ** Returns
  557. ** BTM_SUCCESS Command sent. Does not expect command complete
  558. ** event. (command cmpl callback param is NULL)
  559. ** BTM_CMD_STARTED Command sent. Waiting for command cmpl event.
  560. **
  561. ** Notes
  562. ** Opcode will be OR'd with HCI_GRP_VENDOR_SPECIFIC.
  563. **
  564. *******************************************************************************/
  565. tBTM_STATUS BTM_VendorSpecificCommand(UINT16 opcode, UINT8 param_len,
  566. UINT8 *p_param_buf, tBTM_VSC_CMPL_CB *p_cb)
  567. {
  568. void *p_buf;
  569. BTM_TRACE_EVENT ("BTM: BTM_VendorSpecificCommand: Opcode: 0x%04X, ParamLen: %i.",
  570. opcode, param_len);
  571. /* Allocate a buffer to hold HCI command plus the callback function */
  572. if ((p_buf = osi_malloc((UINT16)(sizeof(BT_HDR) + sizeof (tBTM_CMPL_CB *) +
  573. param_len + HCIC_PREAMBLE_SIZE))) != NULL) {
  574. /* Send the HCI command (opcode will be OR'd with HCI_GRP_VENDOR_SPECIFIC) */
  575. btsnd_hcic_vendor_spec_cmd (p_buf, opcode, param_len, p_param_buf, (void *)p_cb);
  576. /* Return value */
  577. if (p_cb != NULL) {
  578. return (BTM_CMD_STARTED);
  579. } else {
  580. return (BTM_SUCCESS);
  581. }
  582. } else {
  583. return (BTM_NO_RESOURCES);
  584. }
  585. }
  586. /*******************************************************************************
  587. **
  588. ** Function btm_vsc_complete
  589. **
  590. ** Description This function is called when local HCI Vendor Specific
  591. ** Command complete message is received from the HCI.
  592. **
  593. ** Returns void
  594. **
  595. *******************************************************************************/
  596. void btm_vsc_complete (UINT8 *p, UINT16 opcode, UINT16 evt_len,
  597. tBTM_CMPL_CB *p_vsc_cplt_cback)
  598. {
  599. #if (BLE_INCLUDED == TRUE)
  600. tBTM_BLE_CB *ble_cb = &btm_cb.ble_ctr_cb;
  601. switch(opcode) {
  602. case HCI_VENDOR_BLE_LONG_ADV_DATA:
  603. BTM_TRACE_EVENT("Set long adv data complete\n");
  604. break;
  605. case HCI_VENDOR_BLE_UPDATE_DUPLICATE_EXCEPTIONAL_LIST: {
  606. uint8_t subcode, status; uint32_t length;
  607. STREAM_TO_UINT8(status, p);
  608. STREAM_TO_UINT8(subcode, p);
  609. STREAM_TO_UINT32(length, p);
  610. if(ble_cb && ble_cb->update_exceptional_list_cmp_cb) {
  611. (*ble_cb->update_exceptional_list_cmp_cb)(status, subcode, length, p);
  612. }
  613. break;
  614. }
  615. default:
  616. break;
  617. }
  618. tBTM_VSC_CMPL vcs_cplt_params;
  619. /* If there was a callback address for vcs complete, call it */
  620. if (p_vsc_cplt_cback) {
  621. /* Pass paramters to the callback function */
  622. vcs_cplt_params.opcode = opcode; /* Number of bytes in return info */
  623. vcs_cplt_params.param_len = evt_len; /* Number of bytes in return info */
  624. vcs_cplt_params.p_param_buf = p;
  625. (*p_vsc_cplt_cback)(&vcs_cplt_params); /* Call the VSC complete callback function */
  626. }
  627. #endif
  628. }
  629. /*******************************************************************************
  630. **
  631. ** Function BTM_RegisterForVSEvents
  632. **
  633. ** Description This function is called to register/deregister for vendor
  634. ** specific HCI events.
  635. **
  636. ** If is_register=TRUE, then the function will be registered;
  637. ** if is_register=FALSE, then the function will be deregistered.
  638. **
  639. ** Returns BTM_SUCCESS if successful,
  640. ** BTM_BUSY if maximum number of callbacks have already been
  641. ** registered.
  642. **
  643. *******************************************************************************/
  644. tBTM_STATUS BTM_RegisterForVSEvents (tBTM_VS_EVT_CB *p_cb, BOOLEAN is_register)
  645. {
  646. tBTM_STATUS retval = BTM_SUCCESS;
  647. UINT8 i, free_idx = BTM_MAX_VSE_CALLBACKS;
  648. /* See if callback is already registered */
  649. for (i = 0; i < BTM_MAX_VSE_CALLBACKS; i++) {
  650. if (btm_cb.devcb.p_vend_spec_cb[i] == NULL) {
  651. /* Found a free slot. Store index */
  652. free_idx = i;
  653. } else if (btm_cb.devcb.p_vend_spec_cb[i] == p_cb) {
  654. /* Found callback in lookup table. If deregistering, clear the entry. */
  655. if (is_register == FALSE) {
  656. btm_cb.devcb.p_vend_spec_cb[i] = NULL;
  657. BTM_TRACE_EVENT("BTM Deregister For VSEvents is successfully");
  658. }
  659. return (BTM_SUCCESS);
  660. }
  661. }
  662. /* Didn't find callback. Add callback to free slot if registering */
  663. if (is_register) {
  664. if (free_idx < BTM_MAX_VSE_CALLBACKS) {
  665. btm_cb.devcb.p_vend_spec_cb[free_idx] = p_cb;
  666. BTM_TRACE_EVENT("BTM Register For VSEvents is successfully");
  667. } else {
  668. /* No free entries available */
  669. BTM_TRACE_ERROR ("BTM_RegisterForVSEvents: too many callbacks registered");
  670. retval = BTM_NO_RESOURCES;
  671. }
  672. }
  673. return (retval);
  674. }
  675. /*******************************************************************************
  676. **
  677. ** Function btm_vendor_specific_evt
  678. **
  679. ** Description Process event HCI_VENDOR_SPECIFIC_EVT
  680. **
  681. ** Note: Some controllers do not send command complete, so
  682. ** the callback and busy flag are cleared here also.
  683. **
  684. ** Returns void
  685. **
  686. *******************************************************************************/
  687. void btm_vendor_specific_evt (UINT8 *p, UINT8 evt_len)
  688. {
  689. UINT8 i;
  690. #if (CLASSIC_BT_INCLUDED == TRUE)
  691. UINT8 sub_event;
  692. UINT8 *p_evt = p;
  693. STREAM_TO_UINT8(sub_event, p_evt);
  694. /* Check in subevent if authentication is through Legacy Authentication. */
  695. if (sub_event == ESP_VS_REM_LEGACY_AUTH_CMP) {
  696. UINT16 hci_handle;
  697. STREAM_TO_UINT16(hci_handle, p_evt);
  698. btm_sec_handle_remote_legacy_auth_cmp(hci_handle);
  699. }
  700. #endif /// (CLASSIC_BT_INCLUDED == TRUE)
  701. for (i = 0; i < BTM_MAX_VSE_CALLBACKS; i++) {
  702. if (btm_cb.devcb.p_vend_spec_cb[i]) {
  703. (*btm_cb.devcb.p_vend_spec_cb[i])(evt_len, p);
  704. }
  705. }
  706. BTM_TRACE_DEBUG ("BTM Event: Vendor Specific event from controller");
  707. }
  708. /*******************************************************************************
  709. **
  710. ** Function BTM_WritePageTimeout
  711. **
  712. ** Description Send HCI Write Page Timeout.
  713. **
  714. ** Returns
  715. ** BTM_SUCCESS Command sent.
  716. ** BTM_NO_RESOURCES If out of resources to send the command.
  717. **
  718. **
  719. *******************************************************************************/
  720. tBTM_STATUS BTM_WritePageTimeout(UINT16 timeout)
  721. {
  722. BTM_TRACE_EVENT ("BTM: BTM_WritePageTimeout: Timeout: %d.", timeout);
  723. /* Send the HCI command */
  724. if (btsnd_hcic_write_page_tout (timeout)) {
  725. return (BTM_SUCCESS);
  726. } else {
  727. return (BTM_NO_RESOURCES);
  728. }
  729. }
  730. /*******************************************************************************
  731. **
  732. ** Function BTM_WriteVoiceSettings
  733. **
  734. ** Description Send HCI Write Voice Settings command.
  735. ** See stack/hcidefs.h for settings bitmask values.
  736. **
  737. ** Returns
  738. ** BTM_SUCCESS Command sent.
  739. ** BTM_NO_RESOURCES If out of resources to send the command.
  740. **
  741. **
  742. *******************************************************************************/
  743. tBTM_STATUS BTM_WriteVoiceSettings(UINT16 settings)
  744. {
  745. BTM_TRACE_EVENT ("BTM: BTM_WriteVoiceSettings: Settings: 0x%04x.", settings);
  746. /* Send the HCI command */
  747. if (btsnd_hcic_write_voice_settings ((UINT16)(settings & 0x03ff))) {
  748. return (BTM_SUCCESS);
  749. }
  750. return (BTM_NO_RESOURCES);
  751. }
  752. /*******************************************************************************
  753. **
  754. ** Function BTM_EnableTestMode
  755. **
  756. ** Description Send HCI the enable device under test command.
  757. **
  758. ** Note: Controller can only be taken out of this mode by
  759. ** resetting the controller.
  760. **
  761. ** Returns
  762. ** BTM_SUCCESS Command sent.
  763. ** BTM_NO_RESOURCES If out of resources to send the command.
  764. **
  765. **
  766. *******************************************************************************/
  767. tBTM_STATUS BTM_EnableTestMode(void)
  768. {
  769. UINT8 cond;
  770. BTM_TRACE_EVENT ("BTM: BTM_EnableTestMode");
  771. /* set auto accept connection as this is needed during test mode */
  772. /* Allocate a buffer to hold HCI command */
  773. cond = HCI_DO_AUTO_ACCEPT_CONNECT;
  774. if (!btsnd_hcic_set_event_filter(HCI_FILTER_CONNECTION_SETUP,
  775. HCI_FILTER_COND_NEW_DEVICE,
  776. &cond, sizeof(cond))) {
  777. return (BTM_NO_RESOURCES);
  778. }
  779. /* put device to connectable mode */
  780. if (!BTM_SetConnectability(BTM_CONNECTABLE, BTM_DEFAULT_CONN_WINDOW,
  781. BTM_DEFAULT_CONN_INTERVAL) == BTM_SUCCESS) {
  782. return BTM_NO_RESOURCES;
  783. }
  784. /* put device to discoverable mode */
  785. if (!BTM_SetDiscoverability(BTM_GENERAL_DISCOVERABLE, BTM_DEFAULT_DISC_WINDOW,
  786. BTM_DEFAULT_DISC_INTERVAL) == BTM_SUCCESS) {
  787. return BTM_NO_RESOURCES;
  788. }
  789. /* mask off all of event from controller */
  790. hci_layer_get_interface()->transmit_command(
  791. hci_packet_factory_get_interface()->make_set_event_mask((const bt_event_mask_t *)("\x00\x00\x00\x00\x00\x00\x00\x00")),
  792. NULL,
  793. NULL,
  794. NULL);
  795. /* Send the HCI command */
  796. if (btsnd_hcic_enable_test_mode ()) {
  797. return (BTM_SUCCESS);
  798. } else {
  799. return (BTM_NO_RESOURCES);
  800. }
  801. }
  802. /*******************************************************************************
  803. **
  804. ** Function BTM_DeleteStoredLinkKey
  805. **
  806. ** Description This function is called to delete link key for the specified
  807. ** device addresses from the NVRAM storage attached to the Bluetooth
  808. ** controller.
  809. **
  810. ** Parameters: bd_addr - Addresses of the devices
  811. ** p_cb - Call back function to be called to return
  812. ** the results
  813. **
  814. *******************************************************************************/
  815. tBTM_STATUS BTM_DeleteStoredLinkKey(BD_ADDR bd_addr, tBTM_CMPL_CB *p_cb)
  816. {
  817. BD_ADDR local_bd_addr = {0};
  818. BOOLEAN delete_all_flag = FALSE;
  819. /* Check if the previous command is completed */
  820. if (btm_cb.devcb.p_stored_link_key_cmpl_cb) {
  821. return (BTM_BUSY);
  822. }
  823. if (!bd_addr) {
  824. /* This is to delete all link keys */
  825. delete_all_flag = TRUE;
  826. /* We don't care the BD address. Just pass a non zero pointer */
  827. bd_addr = local_bd_addr;
  828. }
  829. BTM_TRACE_EVENT ("BTM: BTM_DeleteStoredLinkKey: delete_all_flag: %s",
  830. delete_all_flag ? "TRUE" : "FALSE");
  831. /* Send the HCI command */
  832. btm_cb.devcb.p_stored_link_key_cmpl_cb = p_cb;
  833. if (!btsnd_hcic_delete_stored_key (bd_addr, delete_all_flag)) {
  834. return (BTM_NO_RESOURCES);
  835. } else {
  836. return (BTM_SUCCESS);
  837. }
  838. }
  839. /*******************************************************************************
  840. **
  841. ** Function btm_delete_stored_link_key_complete
  842. **
  843. ** Description This function is called when the command complete message
  844. ** is received from the HCI for the delete stored link key command.
  845. **
  846. ** Returns void
  847. **
  848. *******************************************************************************/
  849. void btm_delete_stored_link_key_complete (UINT8 *p)
  850. {
  851. tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_stored_link_key_cmpl_cb;
  852. tBTM_DELETE_STORED_LINK_KEY_COMPLETE result;
  853. /* If there was a callback registered for read stored link key, call it */
  854. btm_cb.devcb.p_stored_link_key_cmpl_cb = NULL;
  855. if (p_cb) {
  856. /* Set the call back event to indicate command complete */
  857. result.event = BTM_CB_EVT_DELETE_STORED_LINK_KEYS;
  858. /* Extract the result fields from the HCI event */
  859. STREAM_TO_UINT8 (result.status, p);
  860. STREAM_TO_UINT16 (result.num_keys, p);
  861. /* Call the call back and pass the result */
  862. (*p_cb)(&result);
  863. }
  864. }
  865. /*******************************************************************************
  866. **
  867. ** Function btm_report_device_status
  868. **
  869. ** Description This function is called when there is a change in the device
  870. ** status. This function will report the new device status to
  871. ** the application
  872. **
  873. ** Returns void
  874. **
  875. *******************************************************************************/
  876. void btm_report_device_status (tBTM_DEV_STATUS status)
  877. {
  878. tBTM_DEV_STATUS_CB *p_cb = btm_cb.devcb.p_dev_status_cb;
  879. /* Call the call back to pass the device status to application */
  880. if (p_cb) {
  881. (*p_cb)(status);
  882. }
  883. }
  884. #if (CLASSIC_BT_INCLUDED == TRUE)
  885. /*******************************************************************************
  886. **
  887. ** Function BTM_SetAfhChannels
  888. **
  889. ** Description This function is called to set AFH channels
  890. **
  891. ** Returns status of the operation
  892. **
  893. *******************************************************************************/
  894. tBTM_STATUS BTM_SetAfhChannels (AFH_CHANNELS channels, tBTM_CMPL_CB *p_afh_channels_cmpl_cback)
  895. {
  896. if (!controller_get_interface()->get_is_ready()) {
  897. return (BTM_DEV_RESET);
  898. }
  899. /* Check if set afh already in progress */
  900. if (btm_cb.devcb.p_afh_channels_cmpl_cb) {
  901. return (BTM_NO_RESOURCES);
  902. }
  903. /* Save callback */
  904. btm_cb.devcb.p_afh_channels_cmpl_cb = p_afh_channels_cmpl_cback;
  905. if (!btsnd_hcic_set_afh_channels (channels)) {
  906. return (BTM_NO_RESOURCES);
  907. }
  908. btu_start_timer (&btm_cb.devcb.afh_channels_timer, BTU_TTYPE_BTM_ACL, BTM_DEV_REPLY_TIMEOUT);
  909. return BTM_CMD_STARTED;
  910. }
  911. /*******************************************************************************
  912. **
  913. ** Function btm_set_afh_channels_complete
  914. **
  915. ** Description This function is called when setting AFH channels complete.
  916. ** message is received from the HCI.
  917. **
  918. ** Returns void
  919. **
  920. *******************************************************************************/
  921. void btm_set_afh_channels_complete (UINT8 *p)
  922. {
  923. tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_afh_channels_cmpl_cb;
  924. tBTM_SET_AFH_CHANNELS_RESULTS results;
  925. btu_free_timer (&btm_cb.devcb.afh_channels_timer);
  926. /* If there is a callback address for setting AFH channels, call it */
  927. btm_cb.devcb.p_afh_channels_cmpl_cb = NULL;
  928. if (p_cb) {
  929. STREAM_TO_UINT8 (results.hci_status, p);
  930. switch (results.hci_status){
  931. case HCI_SUCCESS:
  932. results.status = BTM_SUCCESS;
  933. break;
  934. case HCI_ERR_UNSUPPORTED_VALUE:
  935. case HCI_ERR_ILLEGAL_PARAMETER_FMT:
  936. results.status = BTM_ILLEGAL_VALUE;
  937. break;
  938. default:
  939. results.status = BTM_ERR_PROCESSING;
  940. break;
  941. }
  942. (*p_cb)(&results);
  943. }
  944. }
  945. #endif /// CLASSIC_BT_INCLUDED == TRUE
  946. #if (BLE_INCLUDED == TRUE)
  947. /*******************************************************************************
  948. **
  949. ** Function BTM_BleSetChannels
  950. **
  951. ** Description This function is called to set BLE channels
  952. **
  953. ** Returns status of the operation
  954. **
  955. *******************************************************************************/
  956. tBTM_STATUS BTM_BleSetChannels (BLE_CHANNELS channels, tBTM_CMPL_CB *p_ble_channels_cmpl_cback)
  957. {
  958. if (!controller_get_interface()->get_is_ready()) {
  959. return (BTM_DEV_RESET);
  960. }
  961. /* Check if set afh already in progress */
  962. if (btm_cb.devcb.p_ble_channels_cmpl_cb) {
  963. return (BTM_NO_RESOURCES);
  964. }
  965. /* Save callback */
  966. btm_cb.devcb.p_ble_channels_cmpl_cb = p_ble_channels_cmpl_cback;
  967. if (!btsnd_hcic_ble_set_channels (channels)) {
  968. return (BTM_NO_RESOURCES);
  969. }
  970. btu_start_timer (&btm_cb.devcb.ble_channels_timer, BTU_TTYPE_BTM_ACL, BTM_DEV_REPLY_TIMEOUT);
  971. return BTM_CMD_STARTED;
  972. }
  973. /*******************************************************************************
  974. **
  975. ** Function btm_ble_set_channels_complete
  976. **
  977. ** Description This function is called when setting AFH channels complete.
  978. ** message is received from the HCI.
  979. **
  980. ** Returns void
  981. **
  982. *******************************************************************************/
  983. void btm_ble_set_channels_complete (UINT8 *p)
  984. {
  985. tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_ble_channels_cmpl_cb;
  986. tBTM_BLE_SET_CHANNELS_RESULTS results;
  987. btu_free_timer (&btm_cb.devcb.ble_channels_timer);
  988. /* If there is a callback address for setting AFH channels, call it */
  989. btm_cb.devcb.p_ble_channels_cmpl_cb = NULL;
  990. if (p_cb) {
  991. STREAM_TO_UINT8 (results.hci_status, p);
  992. switch (results.hci_status){
  993. case HCI_SUCCESS:
  994. results.status = BTM_SUCCESS;
  995. break;
  996. case HCI_ERR_UNSUPPORTED_VALUE:
  997. case HCI_ERR_ILLEGAL_PARAMETER_FMT:
  998. results.status = BTM_ILLEGAL_VALUE;
  999. break;
  1000. default:
  1001. results.status = BTM_ERR_PROCESSING;
  1002. break;
  1003. }
  1004. (*p_cb)(&results);
  1005. }
  1006. }
  1007. #endif /// BLE_INCLUDED == TRUE