btm_devctl.c 39 KB

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