btm_devctl.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166
  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. BT_HDR *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 = HCI_GET_CMD_BUF(param_len)) != NULL) {
  573. /* Send the HCI command (opcode will be OR'd with HCI_GRP_VENDOR_SPECIFIC) */
  574. btsnd_hcic_vendor_spec_cmd (p_buf, opcode, param_len, p_param_buf, (void *)p_cb);
  575. /* Return value */
  576. if (p_cb != NULL) {
  577. return (BTM_CMD_STARTED);
  578. } else {
  579. return (BTM_SUCCESS);
  580. }
  581. } else {
  582. return (BTM_NO_RESOURCES);
  583. }
  584. }
  585. /*******************************************************************************
  586. **
  587. ** Function btm_vsc_complete
  588. **
  589. ** Description This function is called when local HCI Vendor Specific
  590. ** Command complete message is received from the HCI.
  591. **
  592. ** Returns void
  593. **
  594. *******************************************************************************/
  595. void btm_vsc_complete (UINT8 *p, UINT16 opcode, UINT16 evt_len,
  596. tBTM_CMPL_CB *p_vsc_cplt_cback)
  597. {
  598. #if (BLE_INCLUDED == TRUE)
  599. tBTM_BLE_CB *ble_cb = &btm_cb.ble_ctr_cb;
  600. switch(opcode) {
  601. case HCI_VENDOR_BLE_LONG_ADV_DATA:
  602. BTM_TRACE_EVENT("Set long adv data complete\n");
  603. break;
  604. case HCI_VENDOR_BLE_UPDATE_DUPLICATE_EXCEPTIONAL_LIST: {
  605. uint8_t subcode, status; uint32_t length;
  606. STREAM_TO_UINT8(status, p);
  607. STREAM_TO_UINT8(subcode, p);
  608. STREAM_TO_UINT32(length, p);
  609. if(ble_cb && ble_cb->update_exceptional_list_cmp_cb) {
  610. (*ble_cb->update_exceptional_list_cmp_cb)(status, subcode, length, p);
  611. }
  612. break;
  613. }
  614. default:
  615. break;
  616. }
  617. tBTM_VSC_CMPL vcs_cplt_params;
  618. /* If there was a callback address for vcs complete, call it */
  619. if (p_vsc_cplt_cback) {
  620. /* Pass paramters to the callback function */
  621. vcs_cplt_params.opcode = opcode; /* Number of bytes in return info */
  622. vcs_cplt_params.param_len = evt_len; /* Number of bytes in return info */
  623. vcs_cplt_params.p_param_buf = p;
  624. (*p_vsc_cplt_cback)(&vcs_cplt_params); /* Call the VSC complete callback function */
  625. }
  626. #endif
  627. }
  628. /*******************************************************************************
  629. **
  630. ** Function BTM_RegisterForVSEvents
  631. **
  632. ** Description This function is called to register/deregister for vendor
  633. ** specific HCI events.
  634. **
  635. ** If is_register=TRUE, then the function will be registered;
  636. ** if is_register=FALSE, then the function will be deregistered.
  637. **
  638. ** Returns BTM_SUCCESS if successful,
  639. ** BTM_BUSY if maximum number of callbacks have already been
  640. ** registered.
  641. **
  642. *******************************************************************************/
  643. tBTM_STATUS BTM_RegisterForVSEvents (tBTM_VS_EVT_CB *p_cb, BOOLEAN is_register)
  644. {
  645. tBTM_STATUS retval = BTM_SUCCESS;
  646. UINT8 i, free_idx = BTM_MAX_VSE_CALLBACKS;
  647. /* See if callback is already registered */
  648. for (i = 0; i < BTM_MAX_VSE_CALLBACKS; i++) {
  649. if (btm_cb.devcb.p_vend_spec_cb[i] == NULL) {
  650. /* Found a free slot. Store index */
  651. free_idx = i;
  652. } else if (btm_cb.devcb.p_vend_spec_cb[i] == p_cb) {
  653. /* Found callback in lookup table. If deregistering, clear the entry. */
  654. if (is_register == FALSE) {
  655. btm_cb.devcb.p_vend_spec_cb[i] = NULL;
  656. BTM_TRACE_EVENT("BTM Deregister For VSEvents is successfully");
  657. }
  658. return (BTM_SUCCESS);
  659. }
  660. }
  661. /* Didn't find callback. Add callback to free slot if registering */
  662. if (is_register) {
  663. if (free_idx < BTM_MAX_VSE_CALLBACKS) {
  664. btm_cb.devcb.p_vend_spec_cb[free_idx] = p_cb;
  665. BTM_TRACE_EVENT("BTM Register For VSEvents is successfully");
  666. } else {
  667. /* No free entries available */
  668. BTM_TRACE_ERROR ("BTM_RegisterForVSEvents: too many callbacks registered");
  669. retval = BTM_NO_RESOURCES;
  670. }
  671. }
  672. return (retval);
  673. }
  674. /*******************************************************************************
  675. **
  676. ** Function btm_vendor_specific_evt
  677. **
  678. ** Description Process event HCI_VENDOR_SPECIFIC_EVT
  679. **
  680. ** Note: Some controllers do not send command complete, so
  681. ** the callback and busy flag are cleared here also.
  682. **
  683. ** Returns void
  684. **
  685. *******************************************************************************/
  686. void btm_vendor_specific_evt (UINT8 *p, UINT8 evt_len)
  687. {
  688. UINT8 i;
  689. #if (CLASSIC_BT_INCLUDED == TRUE)
  690. UINT8 sub_event;
  691. UINT8 *p_evt = p;
  692. STREAM_TO_UINT8(sub_event, p_evt);
  693. /* Check in subevent if authentication is through Legacy Authentication. */
  694. if (sub_event == ESP_VS_REM_LEGACY_AUTH_CMP) {
  695. UINT16 hci_handle;
  696. STREAM_TO_UINT16(hci_handle, p_evt);
  697. btm_sec_handle_remote_legacy_auth_cmp(hci_handle);
  698. }
  699. #endif /// (CLASSIC_BT_INCLUDED == TRUE)
  700. for (i = 0; i < BTM_MAX_VSE_CALLBACKS; i++) {
  701. if (btm_cb.devcb.p_vend_spec_cb[i]) {
  702. (*btm_cb.devcb.p_vend_spec_cb[i])(evt_len, p);
  703. }
  704. }
  705. BTM_TRACE_DEBUG ("BTM Event: Vendor Specific event from controller");
  706. }
  707. /*******************************************************************************
  708. **
  709. ** Function BTM_WritePageTimeout
  710. **
  711. ** Description Send HCI Write Page Timeout.
  712. **
  713. ** Returns
  714. ** BTM_SUCCESS Command sent.
  715. ** BTM_NO_RESOURCES If out of resources to send the command.
  716. **
  717. **
  718. *******************************************************************************/
  719. tBTM_STATUS BTM_WritePageTimeout(UINT16 timeout)
  720. {
  721. BTM_TRACE_EVENT ("BTM: BTM_WritePageTimeout: Timeout: %d.", timeout);
  722. /* Send the HCI command */
  723. if (btsnd_hcic_write_page_tout (timeout)) {
  724. return (BTM_SUCCESS);
  725. } else {
  726. return (BTM_NO_RESOURCES);
  727. }
  728. }
  729. /*******************************************************************************
  730. **
  731. ** Function BTM_WriteVoiceSettings
  732. **
  733. ** Description Send HCI Write Voice Settings command.
  734. ** See stack/hcidefs.h for settings bitmask values.
  735. **
  736. ** Returns
  737. ** BTM_SUCCESS Command sent.
  738. ** BTM_NO_RESOURCES If out of resources to send the command.
  739. **
  740. **
  741. *******************************************************************************/
  742. tBTM_STATUS BTM_WriteVoiceSettings(UINT16 settings)
  743. {
  744. BTM_TRACE_EVENT ("BTM: BTM_WriteVoiceSettings: Settings: 0x%04x.", settings);
  745. /* Send the HCI command */
  746. if (btsnd_hcic_write_voice_settings ((UINT16)(settings & 0x03ff))) {
  747. return (BTM_SUCCESS);
  748. }
  749. return (BTM_NO_RESOURCES);
  750. }
  751. /*******************************************************************************
  752. **
  753. ** Function BTM_EnableTestMode
  754. **
  755. ** Description Send HCI the enable device under test command.
  756. **
  757. ** Note: Controller can only be taken out of this mode by
  758. ** resetting the controller.
  759. **
  760. ** Returns
  761. ** BTM_SUCCESS Command sent.
  762. ** BTM_NO_RESOURCES If out of resources to send the command.
  763. **
  764. **
  765. *******************************************************************************/
  766. tBTM_STATUS BTM_EnableTestMode(void)
  767. {
  768. UINT8 cond;
  769. BTM_TRACE_EVENT ("BTM: BTM_EnableTestMode");
  770. /* set auto accept connection as this is needed during test mode */
  771. /* Allocate a buffer to hold HCI command */
  772. cond = HCI_DO_AUTO_ACCEPT_CONNECT;
  773. if (!btsnd_hcic_set_event_filter(HCI_FILTER_CONNECTION_SETUP,
  774. HCI_FILTER_COND_NEW_DEVICE,
  775. &cond, sizeof(cond))) {
  776. return (BTM_NO_RESOURCES);
  777. }
  778. /* put device to connectable mode */
  779. if (!BTM_SetConnectability(BTM_CONNECTABLE, BTM_DEFAULT_CONN_WINDOW,
  780. BTM_DEFAULT_CONN_INTERVAL) == BTM_SUCCESS) {
  781. return BTM_NO_RESOURCES;
  782. }
  783. /* put device to discoverable mode */
  784. if (!BTM_SetDiscoverability(BTM_GENERAL_DISCOVERABLE, BTM_DEFAULT_DISC_WINDOW,
  785. BTM_DEFAULT_DISC_INTERVAL) == BTM_SUCCESS) {
  786. return BTM_NO_RESOURCES;
  787. }
  788. /* mask off all of event from controller */
  789. hci_layer_get_interface()->transmit_command(
  790. hci_packet_factory_get_interface()->make_set_event_mask((const bt_event_mask_t *)("\x00\x00\x00\x00\x00\x00\x00\x00")),
  791. NULL,
  792. NULL,
  793. NULL);
  794. /* Send the HCI command */
  795. if (btsnd_hcic_enable_test_mode ()) {
  796. return (BTM_SUCCESS);
  797. } else {
  798. return (BTM_NO_RESOURCES);
  799. }
  800. }
  801. /*******************************************************************************
  802. **
  803. ** Function BTM_DeleteStoredLinkKey
  804. **
  805. ** Description This function is called to delete link key for the specified
  806. ** device addresses from the NVRAM storage attached to the Bluetooth
  807. ** controller.
  808. **
  809. ** Parameters: bd_addr - Addresses of the devices
  810. ** p_cb - Call back function to be called to return
  811. ** the results
  812. **
  813. *******************************************************************************/
  814. tBTM_STATUS BTM_DeleteStoredLinkKey(BD_ADDR bd_addr, tBTM_CMPL_CB *p_cb)
  815. {
  816. BD_ADDR local_bd_addr = {0};
  817. BOOLEAN delete_all_flag = FALSE;
  818. /* Check if the previous command is completed */
  819. if (btm_cb.devcb.p_stored_link_key_cmpl_cb) {
  820. return (BTM_BUSY);
  821. }
  822. if (!bd_addr) {
  823. /* This is to delete all link keys */
  824. delete_all_flag = TRUE;
  825. /* We don't care the BD address. Just pass a non zero pointer */
  826. bd_addr = local_bd_addr;
  827. }
  828. BTM_TRACE_EVENT ("BTM: BTM_DeleteStoredLinkKey: delete_all_flag: %s",
  829. delete_all_flag ? "TRUE" : "FALSE");
  830. /* Send the HCI command */
  831. btm_cb.devcb.p_stored_link_key_cmpl_cb = p_cb;
  832. if (!btsnd_hcic_delete_stored_key (bd_addr, delete_all_flag)) {
  833. return (BTM_NO_RESOURCES);
  834. } else {
  835. return (BTM_SUCCESS);
  836. }
  837. }
  838. /*******************************************************************************
  839. **
  840. ** Function btm_delete_stored_link_key_complete
  841. **
  842. ** Description This function is called when the command complete message
  843. ** is received from the HCI for the delete stored link key command.
  844. **
  845. ** Returns void
  846. **
  847. *******************************************************************************/
  848. void btm_delete_stored_link_key_complete (UINT8 *p)
  849. {
  850. tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_stored_link_key_cmpl_cb;
  851. tBTM_DELETE_STORED_LINK_KEY_COMPLETE result;
  852. /* If there was a callback registered for read stored link key, call it */
  853. btm_cb.devcb.p_stored_link_key_cmpl_cb = NULL;
  854. if (p_cb) {
  855. /* Set the call back event to indicate command complete */
  856. result.event = BTM_CB_EVT_DELETE_STORED_LINK_KEYS;
  857. /* Extract the result fields from the HCI event */
  858. STREAM_TO_UINT8 (result.status, p);
  859. STREAM_TO_UINT16 (result.num_keys, p);
  860. /* Call the call back and pass the result */
  861. (*p_cb)(&result);
  862. }
  863. }
  864. /*******************************************************************************
  865. **
  866. ** Function btm_report_device_status
  867. **
  868. ** Description This function is called when there is a change in the device
  869. ** status. This function will report the new device status to
  870. ** the application
  871. **
  872. ** Returns void
  873. **
  874. *******************************************************************************/
  875. void btm_report_device_status (tBTM_DEV_STATUS status)
  876. {
  877. tBTM_DEV_STATUS_CB *p_cb = btm_cb.devcb.p_dev_status_cb;
  878. /* Call the call back to pass the device status to application */
  879. if (p_cb) {
  880. (*p_cb)(status);
  881. }
  882. }
  883. #if (CLASSIC_BT_INCLUDED == TRUE)
  884. /*******************************************************************************
  885. **
  886. ** Function BTM_SetAfhChannels
  887. **
  888. ** Description This function is called to set AFH channels
  889. **
  890. ** Returns status of the operation
  891. **
  892. *******************************************************************************/
  893. tBTM_STATUS BTM_SetAfhChannels (AFH_CHANNELS channels, tBTM_CMPL_CB *p_afh_channels_cmpl_cback)
  894. {
  895. if (!controller_get_interface()->get_is_ready()) {
  896. return (BTM_DEV_RESET);
  897. }
  898. /* Check if set afh already in progress */
  899. if (btm_cb.devcb.p_afh_channels_cmpl_cb) {
  900. return (BTM_NO_RESOURCES);
  901. }
  902. /* Save callback */
  903. btm_cb.devcb.p_afh_channels_cmpl_cb = p_afh_channels_cmpl_cback;
  904. if (!btsnd_hcic_set_afh_channels (channels)) {
  905. return (BTM_NO_RESOURCES);
  906. }
  907. btu_start_timer (&btm_cb.devcb.afh_channels_timer, BTU_TTYPE_BTM_ACL, BTM_DEV_REPLY_TIMEOUT);
  908. return BTM_CMD_STARTED;
  909. }
  910. /*******************************************************************************
  911. **
  912. ** Function btm_set_afh_channels_complete
  913. **
  914. ** Description This function is called when setting AFH channels complete.
  915. ** message is received from the HCI.
  916. **
  917. ** Returns void
  918. **
  919. *******************************************************************************/
  920. void btm_set_afh_channels_complete (UINT8 *p)
  921. {
  922. tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_afh_channels_cmpl_cb;
  923. tBTM_SET_AFH_CHANNELS_RESULTS results;
  924. btu_free_timer (&btm_cb.devcb.afh_channels_timer);
  925. /* If there is a callback address for setting AFH channels, call it */
  926. btm_cb.devcb.p_afh_channels_cmpl_cb = NULL;
  927. if (p_cb) {
  928. STREAM_TO_UINT8 (results.hci_status, p);
  929. switch (results.hci_status){
  930. case HCI_SUCCESS:
  931. results.status = BTM_SUCCESS;
  932. break;
  933. case HCI_ERR_UNSUPPORTED_VALUE:
  934. case HCI_ERR_ILLEGAL_PARAMETER_FMT:
  935. results.status = BTM_ILLEGAL_VALUE;
  936. break;
  937. default:
  938. results.status = BTM_ERR_PROCESSING;
  939. break;
  940. }
  941. (*p_cb)(&results);
  942. }
  943. }
  944. #endif /// CLASSIC_BT_INCLUDED == TRUE
  945. #if (BLE_INCLUDED == TRUE)
  946. /*******************************************************************************
  947. **
  948. ** Function BTM_BleSetChannels
  949. **
  950. ** Description This function is called to set BLE channels
  951. **
  952. ** Returns status of the operation
  953. **
  954. *******************************************************************************/
  955. tBTM_STATUS BTM_BleSetChannels (BLE_CHANNELS channels, tBTM_CMPL_CB *p_ble_channels_cmpl_cback)
  956. {
  957. if (!controller_get_interface()->get_is_ready()) {
  958. return (BTM_DEV_RESET);
  959. }
  960. /* Check if set afh already in progress */
  961. if (btm_cb.devcb.p_ble_channels_cmpl_cb) {
  962. return (BTM_NO_RESOURCES);
  963. }
  964. /* Save callback */
  965. btm_cb.devcb.p_ble_channels_cmpl_cb = p_ble_channels_cmpl_cback;
  966. if (!btsnd_hcic_ble_set_channels (channels)) {
  967. return (BTM_NO_RESOURCES);
  968. }
  969. btu_start_timer (&btm_cb.devcb.ble_channels_timer, BTU_TTYPE_BTM_ACL, BTM_DEV_REPLY_TIMEOUT);
  970. return BTM_CMD_STARTED;
  971. }
  972. /*******************************************************************************
  973. **
  974. ** Function btm_ble_set_channels_complete
  975. **
  976. ** Description This function is called when setting AFH channels complete.
  977. ** message is received from the HCI.
  978. **
  979. ** Returns void
  980. **
  981. *******************************************************************************/
  982. void btm_ble_set_channels_complete (UINT8 *p)
  983. {
  984. tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_ble_channels_cmpl_cb;
  985. tBTM_BLE_SET_CHANNELS_RESULTS results;
  986. btu_free_timer (&btm_cb.devcb.ble_channels_timer);
  987. /* If there is a callback address for setting AFH channels, call it */
  988. btm_cb.devcb.p_ble_channels_cmpl_cb = NULL;
  989. if (p_cb) {
  990. STREAM_TO_UINT8 (results.hci_status, p);
  991. switch (results.hci_status){
  992. case HCI_SUCCESS:
  993. results.status = BTM_SUCCESS;
  994. break;
  995. case HCI_ERR_UNSUPPORTED_VALUE:
  996. case HCI_ERR_ILLEGAL_PARAMETER_FMT:
  997. results.status = BTM_ILLEGAL_VALUE;
  998. break;
  999. default:
  1000. results.status = BTM_ERR_PROCESSING;
  1001. break;
  1002. }
  1003. (*p_cb)(&results);
  1004. }
  1005. }
  1006. #endif /// BLE_INCLUDED == TRUE