1 /******************************************************************************
3 * Copyright (C) 1999-2012 Broadcom Corporation
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 ******************************************************************************/
19 /******************************************************************************
21 * This file contains functions that handle BTM interface functions for the
22 * Bluetooth device including Rest, HCI buffer size and others
24 ******************************************************************************/
38 #if BLE_INCLUDED == TRUE
41 #endif /* BLE_INCLUDED */
43 #ifdef BTA_PRM_CHECK_FW_VER
44 extern BOOLEAN BTA_PRM_CHECK_FW_VER(UINT8 *p);
47 #ifndef TT_DEV_RESET_MASK
48 #define TT_DEV_RESET_MASK 0xff
51 /********************************************************************************/
52 /* L O C A L D A T A D E F I N I T I O N S */
53 /********************************************************************************/
55 /* The default class of device. */
56 #ifndef BTM_INIT_CLASS_OF_DEVICE
57 #define BTM_INIT_CLASS_OF_DEVICE "\x00\x1F\x00"
60 #ifndef BTM_DEV_RESET_TIMEOUT
61 #define BTM_DEV_RESET_TIMEOUT 4
64 #define BTM_DEV_REPLY_TIMEOUT 2 /* 1 second expiration time is not good. Timer may start between 0 and 1 second. */
65 /* if it starts at the very end of the 0 second, timer will expire really easily. */
67 #define BTM_INFO_TIMEOUT 5 /* 5 seconds for info response */
69 /* After Reset a timeout can be specified in the target.h for specific targets
70 * that may require additional time to reset
71 * otherwise no timeout is required
73 #ifndef BTM_AFTER_RESET_TIMEOUT
74 #define BTM_AFTER_RESET_TIMEOUT 0
77 /* Internal baseband so the parameters such as local features, version etc. are known
78 so there is no need to issue HCI commands and wait for responses at BTM initialization */
79 #ifndef BTM_INTERNAL_BB
80 #define BTM_INTERNAL_BB FALSE
83 /* The local version information in the format specified in the HCI read local version
85 #ifndef BTM_INTERNAL_LOCAL_VER
86 #define BTM_INTERNAL_LOCAL_VER {0x00, 0x01, 0x05, 0x81, 0x01, 0x30, 0x00, 0x40, 0x8D}
89 /* The local features information in the format specified in the HCI read local features
91 #ifndef BTM_INTERNAL_LOCAL_FEA
92 #define BTM_INTERNAL_LOCAL_FEA {0x00, 0xFF, 0xF9, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00}
95 #ifndef BTM_SET_DEV_NAME_UPON_RESET
96 #define BTM_SET_DEV_NAME_UPON_RESET TRUE
99 /* host SCO buffer size */
100 #ifndef BTM_SCO_HOST_BUF_SIZE
101 #define BTM_SCO_HOST_BUF_SIZE 0xff
104 /********************************************************************************/
105 /* L O C A L F U N C T I O N P R O T O T Y P E S */
106 /********************************************************************************/
107 static void btm_dev_reset (void);
108 static void btm_continue_reset (void);
110 static void btm_get_local_ext_features (UINT8 page_number);
111 static void btm_decode_ext_features_page (UINT8 page_number, const BD_FEATURES p_features);
112 static void btm_read_all_lmp_features_complete (UINT8 max_page_number);
113 static void btm_set_lmp_features_host_may_support (UINT8 max_page_number);
114 static void btm_get_local_features (void);
115 static void btm_issue_host_support_for_lmp_features (void);
116 static void btm_read_local_supported_cmds (UINT8 local_controller_id);
118 #if BLE_INCLUDED == TRUE
119 static void btm_read_ble_local_supported_features (void);
122 /*******************************************************************************
124 ** Function btm_dev_init
126 ** Description This function is on the BTM startup
130 *******************************************************************************/
131 void btm_dev_init (void)
133 #if 0 /* cleared in btm_init; put back in if called from anywhere else! */
134 memset (&btm_cb.devcb, 0, sizeof (tBTM_DEVCB));
137 /* Initialize nonzero defaults */
138 #if (BTM_MAX_LOC_BD_NAME_LEN > 0)
139 memset(btm_cb.cfg.bd_name, 0, sizeof(tBTM_LOC_BD_NAME));
142 btm_cb.devcb.reset_timer.param = (TIMER_PARAM_TYPE)TT_DEV_RESET;
143 btm_cb.devcb.rln_timer.param = (TIMER_PARAM_TYPE)TT_DEV_RLN;
144 btm_cb.devcb.rlinkp_timer.param = (TIMER_PARAM_TYPE)TT_DEV_RLNKP;
146 btm_cb.btm_acl_pkt_types_supported = BTM_ACL_PKT_TYPES_MASK_DH1 + BTM_ACL_PKT_TYPES_MASK_DM1 +
147 BTM_ACL_PKT_TYPES_MASK_DH3 + BTM_ACL_PKT_TYPES_MASK_DM3 +
148 BTM_ACL_PKT_TYPES_MASK_DH5 + BTM_ACL_PKT_TYPES_MASK_DM5;
150 btm_cb.btm_sco_pkt_types_supported = BTM_SCO_PKT_TYPES_MASK_HV1 +
151 BTM_SCO_PKT_TYPES_MASK_HV2 +
152 BTM_SCO_PKT_TYPES_MASK_HV3 +
153 BTM_SCO_PKT_TYPES_MASK_EV3 +
154 BTM_SCO_PKT_TYPES_MASK_EV4 +
155 BTM_SCO_PKT_TYPES_MASK_EV5;
157 btm_cb.first_disabled_channel = 0xff; /* To allow disabling 0th channel alone */
158 btm_cb.last_disabled_channel = 0xff; /* To allow disabling 0th channel alone */
160 #if (BTM_AUTOMATIC_HCI_RESET == TRUE)
162 #if (BTM_FIRST_RESET_DELAY > 0)
163 btm_cb.devcb.state = BTM_DEV_STATE_WAIT_RESET_CMPLT;
164 btu_start_timer (&btm_cb.devcb.reset_timer, BTU_TTYPE_BTM_DEV_CTL, BTM_FIRST_RESET_DELAY);
170 BTM_TRACE_EVENT ("BTM_AUTOMATIC_HCI_RESET is FALSE, so skip btm reset for now");
176 /*******************************************************************************
178 ** Function btm_db_reset
180 ** Description This function is called by BTM_DeviceReset and clears out any
181 ** pending callbacks for inquiries, discoveries, other pending
182 ** functions that may be in progress.
186 *******************************************************************************/
187 static void btm_db_reset (void)
190 tBTM_STATUS status = BTM_DEV_RESET;
194 if (btm_cb.devcb.p_rln_cmpl_cb)
196 p_cb = btm_cb.devcb.p_rln_cmpl_cb;
197 btm_cb.devcb.p_rln_cmpl_cb = NULL;
200 (*p_cb)((void *) NULL);
203 if (btm_cb.devcb.p_rlinkp_cmpl_cb)
205 p_cb = btm_cb.devcb.p_rlinkp_cmpl_cb;
206 btm_cb.devcb.p_rlinkp_cmpl_cb = NULL;
209 (*p_cb)((void *) &status);
212 if (btm_cb.devcb.p_rssi_cmpl_cb)
214 p_cb = btm_cb.devcb.p_rssi_cmpl_cb;
215 btm_cb.devcb.p_rssi_cmpl_cb = NULL;
218 (*p_cb)((tBTM_RSSI_RESULTS *) &status);
224 /*******************************************************************************
226 ** Function btm_dev_absent
228 ** Description This function is called by when it is detected that the
229 ** device is not connected any more.
233 *******************************************************************************/
234 void btm_dev_absent (void)
236 btm_cb.devcb.state = BTM_DEV_STATE_WAIT_RESET_CMPLT;
241 /* If anyone wants device status notifications, give him one */
242 btm_report_device_status (BTM_DEV_STATUS_DOWN);
244 btu_stop_timer (&btm_cb.devcb.reset_timer);
248 /*******************************************************************************
250 ** Function BTM_DeviceReset
252 ** Description This function is called to reset the HCI. Callback function
253 ** if provided is called when startup of the device is
258 *******************************************************************************/
259 void BTM_DeviceReset (tBTM_CMPL_CB *p_cb)
263 /* If device is already resetting, do not allow another */
264 if ((!btm_cb.devcb.p_reset_cmpl_cb) || (btm_cb.devcb.p_reset_cmpl_cb == p_cb))
266 /* Flush all ACL connections */
267 btm_acl_device_down();
269 /* Clear the callback, so application would not hang on reset */
272 /* Save address of the completion routine, if provided */
273 btm_cb.devcb.p_reset_cmpl_cb = p_cb;
279 /* pass an error to the bad callback, another one was already provided */
282 status = BTM_ILLEGAL_VALUE;
289 /*******************************************************************************
291 ** Function BTM_IsDeviceUp
293 ** Description This function is called to check if the device is up.
295 ** Returns TRUE if device is up, else FALSE
297 *******************************************************************************/
298 BOOLEAN BTM_IsDeviceUp (void)
300 return ((BOOLEAN) (btm_cb.devcb.state == BTM_DEV_STATE_READY));
303 /*******************************************************************************
305 ** Function BTM_SetAfhChannels
307 ** Description This function is called disable channels
309 ** Returns tBTM_STATUS
311 *******************************************************************************/
312 tBTM_STATUS BTM_SetAfhChannels (UINT8 first, UINT8 last)
314 BTM_TRACE_API ("BTM_SetAfhChannels first: %d (%d) last: %d (%d)",
315 first, btm_cb.first_disabled_channel, last,
316 btm_cb.last_disabled_channel);
318 /* Make sure the local device supports the feature before sending */
319 if ((!HCI_LMP_AFH_CAP_MASTR_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_0])) &&
320 (!HCI_LMP_AFH_CLASS_SLAVE_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_0])) &&
321 (!HCI_LMP_AFH_CLASS_MASTR_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_0])))
322 return (BTM_MODE_UNSUPPORTED);
324 if (!BTM_IsDeviceUp())
325 return (BTM_WRONG_MODE);
327 if ((btm_cb.first_disabled_channel != first)
328 || (btm_cb.last_disabled_channel != last))
330 if (btsnd_hcic_set_afh_channels (first, last))
332 btm_cb.first_disabled_channel = first;
333 btm_cb.last_disabled_channel = last;
336 return (BTM_NO_RESOURCES);
338 return (BTM_SUCCESS);
341 /*******************************************************************************
343 ** Function BTM_SetAfhChannelAssessment
345 ** Description This function is called to set the channel assessment mode on or off
349 *******************************************************************************/
350 tBTM_STATUS BTM_SetAfhChannelAssessment (BOOLEAN enable_or_disable)
352 /* whatever app wants if device is not 1.2 scan type should be STANDARD */
353 if (!HCI_LMP_AFH_CAP_SLAVE_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
354 return (BTM_MODE_UNSUPPORTED);
356 if (!btsnd_hcic_write_afh_channel_assessment_mode (enable_or_disable))
357 return (BTM_NO_RESOURCES);
359 return (BTM_SUCCESS);
362 /*******************************************************************************
364 ** Function btm_dev_reset
366 ** Description Local function called to send a reset command
370 *******************************************************************************/
371 static void btm_dev_reset (void)
373 btm_cb.devcb.state = BTM_DEV_STATE_WAIT_RESET_CMPLT;
375 /* flush out the command complete queue and command transmit queue */
376 btu_hcif_flush_cmd_queue();
378 /* Start reset timer. When timer expires we will send first command */
379 /* from the setup sequence */
381 btu_start_timer (&btm_cb.devcb.reset_timer, BTU_TTYPE_BTM_DEV_CTL,
382 BTM_DEV_RESET_TIMEOUT);
383 btsnd_hcic_reset (LOCAL_BR_EDR_CONTROLLER_ID);
387 /*******************************************************************************
389 ** Function btm_get_hci_buf_size
391 ** Description Local function called to send a read buffer size command
395 *******************************************************************************/
396 void btm_get_hci_buf_size (void)
399 btu_start_timer (&btm_cb.devcb.reset_timer, BTU_TTYPE_BTM_DEV_CTL, BTM_DEV_REPLY_TIMEOUT);
401 /* Send a Read Buffer Size message to the Host Controller. */
402 btsnd_hcic_read_buffer_size ();
405 #if BLE_INCLUDED == TRUE
406 /*******************************************************************************
408 ** Function btm_read_ble_wl_size
410 ** Description Local function called to send a read BLE buffer size command
414 *******************************************************************************/
415 void btm_read_ble_wl_size(void)
417 BTM_TRACE_DEBUG("btm_read_ble_wl_size ");
418 btu_start_timer (&btm_cb.devcb.reset_timer, BTU_TTYPE_BTM_DEV_CTL, BTM_DEV_REPLY_TIMEOUT);
420 /* Send a Read Buffer Size message to the Host Controller. */
421 btsnd_hcic_ble_read_white_list_size();
423 /*******************************************************************************
425 ** Function btm_get_ble_buffer_size
427 ** Description Local function called to send a read BLE buffer size command
431 *******************************************************************************/
432 void btm_get_ble_buffer_size(void)
434 BTM_TRACE_DEBUG("btm_get_ble_buffer_size ");
435 btu_start_timer (&btm_cb.devcb.reset_timer, BTU_TTYPE_BTM_DEV_CTL, BTM_DEV_REPLY_TIMEOUT);
437 /* Send a Read Buffer Size message to the Host Controller. */
438 btsnd_hcic_ble_read_buffer_size ();
441 /*******************************************************************************
443 ** Function btm_read_ble_local_supported_features
445 ** Description Local function called to send a read BLE local supported
450 *******************************************************************************/
451 static void btm_read_ble_local_supported_features(void)
453 BTM_TRACE_DEBUG("btm_read_ble_local_supported_features ");
454 btu_start_timer (&btm_cb.devcb.reset_timer, BTU_TTYPE_BTM_DEV_CTL, BTM_DEV_REPLY_TIMEOUT);
456 /* Send a Read Local Supported Features message to the Host Controller. */
457 btsnd_hcic_ble_read_local_spt_feat ();
460 /*******************************************************************************
462 ** Function btm_read_ble_local_supported_states
464 ** Description Local function called to send a read BLE local supported
469 *******************************************************************************/
470 static void btm_read_ble_local_supported_states(void)
472 BTM_TRACE_DEBUG("btm_read_ble_local_supported_states ");
473 btu_start_timer (&btm_cb.devcb.reset_timer, BTU_TTYPE_BTM_DEV_CTL, BTM_DEV_REPLY_TIMEOUT);
475 /* Send a Read Local Supported states message to the Host Controller. */
476 btsnd_hcic_ble_read_supported_states ();
479 /*******************************************************************************
481 ** Function btm_get_local_version
483 ** Description Local function called to send a read local version to controller
487 *******************************************************************************/
488 void btm_get_local_version (void)
491 btu_start_timer (&btm_cb.devcb.reset_timer, BTU_TTYPE_BTM_DEV_CTL, BTM_DEV_REPLY_TIMEOUT);
493 /* Send a Read Local Version message to the Host Controller. */
494 btsnd_hcic_read_local_ver (LOCAL_BR_EDR_CONTROLLER_ID);
495 btsnd_hcic_read_bd_addr ();
497 #if BTM_PWR_MGR_INCLUDED == TRUE
503 /*******************************************************************************
505 ** Function btm_read_local_supported_cmds
507 ** Description Local function called to send a read local supported commands
511 *******************************************************************************/
512 static void btm_read_local_supported_cmds (UINT8 local_controller_id)
514 BTM_TRACE_DEBUG("Start reading local supported commands");
516 btu_start_timer (&btm_cb.devcb.reset_timer, BTU_TTYPE_BTM_DEV_CTL, BTM_DEV_REPLY_TIMEOUT);
518 btsnd_hcic_read_local_supported_cmds(local_controller_id);
521 /*******************************************************************************
523 ** Function btm_get_local_features
525 ** Description Local function called to send a read local features
529 *******************************************************************************/
530 static void btm_get_local_features (void)
532 /* If this BT controller supports Read Extended Feature */
533 if (btm_cb.devcb.local_version.hci_version >= HCI_PROTO_VERSION_2_0)
535 btm_get_local_ext_features(HCI_EXT_FEATURES_PAGE_0);
537 /* else, if this is a very old BT controller */
540 btu_start_timer (&btm_cb.devcb.reset_timer, BTU_TTYPE_BTM_DEV_CTL, BTM_DEV_REPLY_TIMEOUT);
542 /* Just read the basic features (legacy HCI command) */
543 btsnd_hcic_read_local_features ();
547 /*******************************************************************************
549 ** Function btm_get_local_ext_features
551 ** Description Local function called to send a read local extended features
555 *******************************************************************************/
556 static void btm_get_local_ext_features (UINT8 page_number)
558 btu_start_timer (&btm_cb.devcb.reset_timer, BTU_TTYPE_BTM_DEV_CTL, BTM_DEV_REPLY_TIMEOUT);
560 btsnd_hcic_read_local_ext_features(page_number);
563 /*******************************************************************************
565 ** Function btm_dev_timeout
567 ** Description This function is called when a timer list entry expires.
571 *******************************************************************************/
572 void btm_dev_timeout (TIMER_LIST_ENT *p_tle)
574 TIMER_PARAM_TYPE timer_type = (TIMER_PARAM_TYPE)p_tle->param;
576 if ((timer_type & TT_DEV_RESET_MASK) == TT_DEV_RESET)
578 /* Call device reset as long as there is timeout*/
581 else if (timer_type == (TIMER_PARAM_TYPE)TT_DEV_RLN)
583 tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rln_cmpl_cb;
585 btm_cb.devcb.p_rln_cmpl_cb = NULL;
588 (*p_cb)((void *) NULL);
592 /*******************************************************************************
594 ** Function btm_reset_complete
596 ** Description This function is called when command complete for HCI_Reset
597 ** is received. It does not make sense to send next command
598 ** because device is resetting after command complete is
599 ** received. Just start timer and set required state.
603 *******************************************************************************/
604 void btm_reset_complete (void)
608 BTM_TRACE_EVENT ("btm_reset_complete");
610 /* Handle if btm initiated the reset */
611 if (btm_cb.devcb.state == BTM_DEV_STATE_WAIT_RESET_CMPLT)
613 /* Tell L2CAP that all connections are gone */
614 l2cu_device_reset ();
616 /* Clear current security state */
617 for (devinx = 0; devinx < BTM_SEC_MAX_DEVICE_RECORDS; devinx++)
619 btm_cb.sec_dev_rec[devinx].sec_state = BTM_SEC_STATE_IDLE;
622 /* After the reset controller should restore all parameters to defaults. */
623 btm_cb.btm_inq_vars.inq_counter = 1;
624 btm_cb.btm_inq_vars.inq_scan_window = HCI_DEF_INQUIRYSCAN_WINDOW;
625 btm_cb.btm_inq_vars.inq_scan_period = HCI_DEF_INQUIRYSCAN_INTERVAL;
626 btm_cb.btm_inq_vars.inq_scan_type = HCI_DEF_SCAN_TYPE;
628 btm_cb.btm_inq_vars.page_scan_window = HCI_DEF_PAGESCAN_WINDOW;
629 btm_cb.btm_inq_vars.page_scan_period = HCI_DEF_PAGESCAN_INTERVAL;
630 btm_cb.btm_inq_vars.page_scan_type = HCI_DEF_SCAN_TYPE;
632 #if (BTM_AFTER_RESET_TIMEOUT > 0)
633 btu_start_timer (&btm_cb.devcb.reset_timer, BTU_TTYPE_BTM_DEV_CTL,
634 BTM_AFTER_RESET_TIMEOUT);
636 btm_cb.devcb.state = BTM_DEV_STATE_WAIT_AFTER_RESET;
637 btu_stop_timer(&btm_cb.devcb.reset_timer);
638 btm_continue_reset();
641 #if (BLE_INCLUDED == TRUE)
642 btm_cb.ble_ctr_cb.conn_state = BLE_CONN_IDLE;
643 btm_cb.ble_ctr_cb.bg_dev_num = 0;
644 btm_cb.ble_ctr_cb.bg_conn_type = BTM_BLE_CONN_NONE;
645 btm_cb.ble_ctr_cb.p_select_cback = NULL;
646 memset(&btm_cb.ble_ctr_cb.bg_dev_list, 0, (sizeof(tBTM_LE_BG_CONN_DEV)*BTM_BLE_MAX_BG_CONN_DEV_NUM));
647 gatt_reset_bgdev_list();
652 /*******************************************************************************
654 ** Function btm_continue_reset
656 ** Description This function is called when wait period expired after
657 ** device reset or called by the application to continue
658 ** initialization after the application has completed its
659 ** vendor specific sequence.
663 *******************************************************************************/
664 void btm_continue_reset (void)
667 /* Reinitialize the default class of device */
668 #if BTM_INTERNAL_BB == TRUE
669 btsnd_hcic_read_bd_addr ();
670 #if BTM_PWR_MGR_INCLUDED == TRUE
675 btm_get_hci_buf_size ();
677 /* default device class */
678 BTM_SetDeviceClass((UINT8 *) BTM_INIT_CLASS_OF_DEVICE);
680 #if (BTM_MAX_LOC_BD_NAME_LEN > 0) && (BTM_SET_DEV_NAME_UPON_RESET == TRUE)
681 BTM_SetLocalDeviceName(btm_cb.cfg.bd_name);
684 BTM_SetPinType (btm_cb.cfg.pin_type, btm_cb.cfg.pin_code, btm_cb.cfg.pin_code_len);
687 /*******************************************************************************
689 ** Function btm_read_hci_buf_size_complete
691 ** Description This function is called when command complete for
692 ** get HCI buffer size is received. Start timer and send
693 ** read local features request
697 *******************************************************************************/
698 void btm_read_hci_buf_size_complete (UINT8 *p, UINT16 evt_len)
701 UINT8 lm_sco_buf_size;
702 UINT16 lm_num_acl_bufs;
703 UINT16 lm_num_sco_bufs;
707 STREAM_TO_UINT8 (status, p);
708 if (status == HCI_SUCCESS)
710 STREAM_TO_UINT16 (btu_cb.hcit_acl_data_size, p);
711 STREAM_TO_UINT8 (lm_sco_buf_size, p);
712 STREAM_TO_UINT16 (lm_num_acl_bufs, p);
713 STREAM_TO_UINT16 (lm_num_sco_bufs, p);
715 btu_cb.hcit_acl_pkt_size = btu_cb.hcit_acl_data_size + HCI_DATA_PREAMBLE_SIZE;
717 l2c_link_processs_num_bufs (lm_num_acl_bufs);
719 #if BTM_ACL_BUF_SIZE > 0
720 acl_buf_size = (BTM_ACL_BUF_SIZE < L2CAP_MTU_SIZE) ? BTM_ACL_BUF_SIZE : L2CAP_MTU_SIZE;
722 acl_buf_size = L2CAP_MTU_SIZE;
724 /* Tell the controller what our buffer sizes are. ?? Need SCO info */
725 btsnd_hcic_set_host_buf_size (acl_buf_size, BTM_SCO_HOST_BUF_SIZE, L2CAP_HOST_FC_ACL_BUFS, 10);
727 #if L2CAP_HOST_FLOW_CTRL == TRUE
728 btsnd_hcic_set_host_flow_ctrl (HCI_HOST_FLOW_CTRL_ACL_ON);
732 /* Set the device into connectable and/or discoverable mode (if configured to do so) */
733 #if BTM_IS_CONNECTABLE == TRUE
734 (void) BTM_SetConnectability (BTM_CONNECTABLE, BTM_DEFAULT_CONN_WINDOW, BTM_DEFAULT_CONN_INTERVAL);
737 #if BTM_IS_DISCOVERABLE == TRUE
738 (void) BTM_SetDiscoverability (BTM_DEFAULT_DISC_MODE, BTM_DEFAULT_DISC_WINDOW, BTM_DEFAULT_DISC_INTERVAL);
741 #if BTM_INTERNAL_BB == TRUE
743 UINT8 buf[9] = BTM_INTERNAL_LOCAL_VER;
744 btm_read_local_version_complete( buf, 9 );
747 btm_get_local_version ();
751 #if (BLE_INCLUDED == TRUE)
752 /*******************************************************************************
754 ** Function btm_read_ble_buf_size_complete
756 ** Description This function is called when command complete for
757 ** get HCI buffer size is received. Start timer and send
758 ** read local supported features request
762 *******************************************************************************/
763 void btm_read_ble_buf_size_complete (UINT8 *p, UINT16 evt_len)
766 UINT16 lm_num_le_bufs;
769 BTM_TRACE_DEBUG("btm_read_ble_buf_size_complete ");
770 STREAM_TO_UINT8 (status, p);
771 if (status == HCI_SUCCESS)
773 STREAM_TO_UINT16 (btu_cb.hcit_ble_acl_data_size, p);
774 STREAM_TO_UINT8 (lm_num_le_bufs, p);
776 if (btu_cb.hcit_ble_acl_data_size == 0)
777 btu_cb.hcit_ble_acl_data_size = btu_cb.hcit_acl_data_size;
779 btu_cb.hcit_ble_acl_pkt_size = btu_cb.hcit_ble_acl_data_size + HCI_DATA_PREAMBLE_SIZE;
781 l2c_link_processs_ble_num_bufs (lm_num_le_bufs);
783 btm_read_ble_local_supported_states();
785 /*******************************************************************************
787 ** Function btm_read_ble_local_supported_states_complete
789 ** Description This function is called when command complete for
790 ** Read LE Local Supported states complete is received.
794 *******************************************************************************/
795 void btm_read_ble_local_supported_states_complete (UINT8 *p, UINT16 evt_len)
800 BTM_TRACE_DEBUG("btm_read_ble_local_supported_states_complete ");
802 btu_stop_timer (&btm_cb.devcb.reset_timer);
804 STREAM_TO_UINT8 (status, p);
805 if (status == HCI_SUCCESS)
807 STREAM_TO_ARRAY(&btm_cb.devcb.le_supported_states, p, BTM_LE_SUPPORT_STATE_SIZE);
811 BTM_TRACE_WARNING ("btm_read_ble_local_supported_features_complete status = %d", status);
814 btm_read_ble_local_supported_features();
817 /*******************************************************************************
819 ** Function btm_read_ble_local_supported_features_complete
821 ** Description This function is called when command complete for
822 ** Read LE Local Supported Features is received. Start timer and send
823 ** read LMP local features request
827 *******************************************************************************/
828 void btm_read_ble_local_supported_features_complete (UINT8 *p, UINT16 evt_len)
833 BTM_TRACE_DEBUG("btm_read_ble_local_supported_features_complete ");
835 btu_stop_timer (&btm_cb.devcb.reset_timer);
837 STREAM_TO_UINT8 (status, p);
838 if (status == HCI_SUCCESS)
840 STREAM_TO_ARRAY(&btm_cb.devcb.local_le_features, p, HCI_FEATURE_BYTES_PER_PAGE);
844 BTM_TRACE_WARNING ("btm_read_ble_local_supported_features_complete status = %d", status);
847 btsnd_hcic_ble_set_evt_mask((UINT8 *)HCI_BLE_EVENT_MASK_DEF);
849 #if BTM_INTERNAL_BB == TRUE
851 UINT8 buf[9] = BTM_INTERNAL_LOCAL_FEA;
852 btm_read_local_features_complete( buf, 9 );
856 /* get local feature if BRCM specific feature is not included */
857 btm_reset_ctrlr_complete();
862 /*******************************************************************************
864 ** Function btm_read_white_list_size_complete
866 ** Description This function read the current white list size.
867 *******************************************************************************/
868 void btm_read_white_list_size_complete(UINT8 *p, UINT16 evt_len)
873 BTM_TRACE_DEBUG("btm_read_white_list_size_complete ");
874 STREAM_TO_UINT8 (status, p);
876 if (status == HCI_SUCCESS)
878 STREAM_TO_UINT8(btm_cb.ble_ctr_cb.max_filter_entries, p);
879 btm_cb.ble_ctr_cb.num_empty_filter = btm_cb.ble_ctr_cb.max_filter_entries;
881 /* write LE host support and simultatunous LE supported */
882 btsnd_hcic_ble_write_host_supported(BTM_BLE_HOST_SUPPORT, BTM_BLE_SIMULTANEOUS_HOST);
884 btm_get_ble_buffer_size();
888 /*******************************************************************************
890 ** Function btm_read_local_version_complete
892 ** Description This function is called when local BD Addr read complete
893 ** message is received from the HCI.
897 *******************************************************************************/
898 void btm_read_local_version_complete (UINT8 *p, UINT16 evt_len)
900 tBTM_VERSION_INFO *p_vi = &btm_cb.devcb.local_version;
904 #ifdef BTA_PRM_CHECK_FW_VER
905 if(BTA_PRM_CHECK_FW_VER(p))
909 STREAM_TO_UINT8 (status, p);
910 if (status == HCI_SUCCESS)
913 STREAM_TO_UINT8 (p_vi->hci_version, p);
914 STREAM_TO_UINT16 (p_vi->hci_revision, p);
915 STREAM_TO_UINT8 (p_vi->lmp_version, p);
916 STREAM_TO_UINT16 (p_vi->manufacturer, p);
917 STREAM_TO_UINT16 (p_vi->lmp_subversion, p);
920 if (p_vi->hci_version >= HCI_PROTO_VERSION_1_2)
922 btm_read_local_supported_cmds(LOCAL_BR_EDR_CONTROLLER_ID);
926 btm_get_local_features ();
930 /*******************************************************************************
932 ** Function btm_decode_ext_features_page
934 ** Description This function is decodes a features page.
938 *******************************************************************************/
939 static void btm_decode_ext_features_page (UINT8 page_number, const UINT8 *p_features)
944 BTM_TRACE_DEBUG ("btm_decode_ext_features_page page: %d", page_number);
947 /* Extended (Legacy) Page 0 */
948 case HCI_EXT_FEATURES_PAGE_0:
950 /* Create ACL supported packet types mask */
951 btm_cb.btm_acl_pkt_types_supported = (BTM_ACL_PKT_TYPES_MASK_DH1 +
952 BTM_ACL_PKT_TYPES_MASK_DM1);
954 if (HCI_3_SLOT_PACKETS_SUPPORTED(p_features))
955 btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_DH3 +
956 BTM_ACL_PKT_TYPES_MASK_DM3);
958 if (HCI_5_SLOT_PACKETS_SUPPORTED(p_features))
959 btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_DH5 +
960 BTM_ACL_PKT_TYPES_MASK_DM5);
962 /* _NO_X_DXX masks are reserved before ver 2.0.
963 Set them only for later versions of controller */
964 if (btm_cb.devcb.local_version.hci_version >= HCI_PROTO_VERSION_2_0)
966 /* Add in EDR related ACL types */
967 if (!HCI_EDR_ACL_2MPS_SUPPORTED(p_features))
969 btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH1 +
970 BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 +
971 BTM_ACL_PKT_TYPES_MASK_NO_2_DH5);
974 if (!HCI_EDR_ACL_3MPS_SUPPORTED(p_features))
976 btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_NO_3_DH1 +
977 BTM_ACL_PKT_TYPES_MASK_NO_3_DH3 +
978 BTM_ACL_PKT_TYPES_MASK_NO_3_DH5);
981 /* Check to see if 3 and 5 slot packets are available */
982 if (HCI_EDR_ACL_2MPS_SUPPORTED(p_features) ||
983 HCI_EDR_ACL_3MPS_SUPPORTED(p_features))
985 if (!HCI_3_SLOT_EDR_ACL_SUPPORTED(p_features))
986 btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 +
987 BTM_ACL_PKT_TYPES_MASK_NO_3_DH3);
989 if (!HCI_5_SLOT_EDR_ACL_SUPPORTED(p_features))
990 btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH5 +
991 BTM_ACL_PKT_TYPES_MASK_NO_3_DH5);
995 BTM_TRACE_DEBUG("Local supported ACL packet types: 0x%04x",
996 btm_cb.btm_acl_pkt_types_supported);
998 /* Create (e)SCO supported packet types mask */
999 btm_cb.btm_sco_pkt_types_supported = 0;
1000 #if BTM_SCO_INCLUDED == TRUE
1001 btm_cb.sco_cb.esco_supported = FALSE;
1003 if (HCI_SCO_LINK_SUPPORTED(p_features))
1005 btm_cb.btm_sco_pkt_types_supported = BTM_SCO_PKT_TYPES_MASK_HV1;
1007 if (HCI_HV2_PACKETS_SUPPORTED(p_features))
1008 btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_HV2;
1010 if (HCI_HV3_PACKETS_SUPPORTED(p_features))
1011 btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_HV3;
1014 if (HCI_ESCO_EV3_SUPPORTED(p_features))
1015 btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_EV3;
1017 if (HCI_ESCO_EV4_SUPPORTED(p_features))
1018 btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_EV4;
1020 if (HCI_ESCO_EV5_SUPPORTED(p_features))
1021 btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_EV5;
1022 #if BTM_SCO_INCLUDED == TRUE
1023 if (btm_cb.btm_sco_pkt_types_supported & BTM_ESCO_LINK_ONLY_MASK)
1025 btm_cb.sco_cb.esco_supported = TRUE;
1027 /* Add in EDR related eSCO types */
1028 if (HCI_EDR_ESCO_2MPS_SUPPORTED(p_features))
1030 if (!HCI_3_SLOT_EDR_ESCO_SUPPORTED(p_features))
1031 btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_NO_2_EV5;
1035 btm_cb.btm_sco_pkt_types_supported |= (BTM_SCO_PKT_TYPES_MASK_NO_2_EV3 +
1036 BTM_SCO_PKT_TYPES_MASK_NO_2_EV5);
1039 if (HCI_EDR_ESCO_3MPS_SUPPORTED(p_features))
1041 if (!HCI_3_SLOT_EDR_ESCO_SUPPORTED(p_features))
1042 btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_NO_3_EV5;
1046 btm_cb.btm_sco_pkt_types_supported |= (BTM_SCO_PKT_TYPES_MASK_NO_3_EV3 +
1047 BTM_SCO_PKT_TYPES_MASK_NO_3_EV5);
1052 BTM_TRACE_DEBUG("Local supported SCO packet types: 0x%04x",
1053 btm_cb.btm_sco_pkt_types_supported);
1055 /* Create Default Policy Settings */
1056 if (HCI_SWITCH_SUPPORTED(p_features))
1057 btm_cb.btm_def_link_policy |= HCI_ENABLE_MASTER_SLAVE_SWITCH;
1059 btm_cb.btm_def_link_policy &= ~HCI_ENABLE_MASTER_SLAVE_SWITCH;
1061 if (HCI_HOLD_MODE_SUPPORTED(p_features))
1062 btm_cb.btm_def_link_policy |= HCI_ENABLE_HOLD_MODE;
1064 btm_cb.btm_def_link_policy &= ~HCI_ENABLE_HOLD_MODE;
1066 if (HCI_SNIFF_MODE_SUPPORTED(p_features))
1067 btm_cb.btm_def_link_policy |= HCI_ENABLE_SNIFF_MODE;
1069 btm_cb.btm_def_link_policy &= ~HCI_ENABLE_SNIFF_MODE;
1071 if (HCI_PARK_MODE_SUPPORTED(p_features))
1072 btm_cb.btm_def_link_policy |= HCI_ENABLE_PARK_MODE;
1074 btm_cb.btm_def_link_policy &= ~HCI_ENABLE_PARK_MODE;
1076 btm_sec_dev_reset ();
1077 #if ((BTM_EIR_SERVER_INCLUDED == TRUE)||(BTM_EIR_CLIENT_INCLUDED == TRUE))
1078 if (HCI_LMP_INQ_RSSI_SUPPORTED(p_features))
1080 if (HCI_EXT_INQ_RSP_SUPPORTED(p_features))
1081 BTM_SetInquiryMode (BTM_INQ_RESULT_EXTENDED);
1083 BTM_SetInquiryMode (BTM_INQ_RESULT_WITH_RSSI);
1086 if (HCI_LMP_INQ_RSSI_SUPPORTED(p_features))
1087 BTM_SetInquiryMode (BTM_INQ_RESULT_WITH_RSSI);
1089 #if L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE
1090 if( HCI_NON_FLUSHABLE_PB_SUPPORTED(p_features))
1091 l2cu_set_non_flushable_pbf(TRUE);
1093 l2cu_set_non_flushable_pbf(FALSE);
1095 BTM_SetPageScanType (BTM_DEFAULT_SCAN_TYPE);
1096 BTM_SetInquiryScanType (BTM_DEFAULT_SCAN_TYPE);
1100 /* Extended Page 1 */
1101 case HCI_EXT_FEATURES_PAGE_1:
1102 /* Nothing to do for page 1 */
1105 /* Extended Page 2 */
1106 case HCI_EXT_FEATURES_PAGE_2:
1107 /* Nothing to do for page 2 */
1111 BTM_TRACE_ERROR("btm_decode_ext_features_page page=%d unknown", page_number);
1116 /*******************************************************************************
1118 ** Function btm_reset_ctrlr_complete
1120 ** Description This is the last step of BR/EDR controller startup sequence.
1124 *******************************************************************************/
1125 void btm_reset_ctrlr_complete ()
1127 tBTM_DEVCB *p_devcb = &btm_cb.devcb;
1128 tBTM_CMPL_CB *p_cb = p_devcb->p_reset_cmpl_cb;
1129 BOOLEAN found = FALSE;
1130 UINT8 i, j, max_page_number;
1132 btu_stop_timer (&btm_cb.devcb.reset_timer);
1134 /* find the highest feature page number which contains non-zero bits */
1135 for (i = HCI_EXT_FEATURES_PAGE_MAX; ; i--)
1137 for (j = 0; j < HCI_FEATURE_BYTES_PER_PAGE; j++)
1139 if (p_devcb->local_lmp_features[i][j] != 0)
1152 BTM_TRACE_WARNING ("btm_reset_ctrlr_complete: NONE of local controller features is set");
1154 max_page_number = i;
1156 BTM_TRACE_DEBUG ("btm_reset_ctrlr_complete: max_page_number: %d", max_page_number);
1159 * Set State to Ready (needs to be done before btm_decode_ext_features_page
1160 * to allow it to send some HCI configuration commands)
1162 p_devcb->state = BTM_DEV_STATE_READY;
1164 /* For every received/saved feature page */
1165 for (i = 0; i <= max_page_number; i++)
1167 /* Decode the saved Feature Page */
1168 btm_decode_ext_features_page(i, p_devcb->local_lmp_features[i]);
1171 /* If there was a callback address for reset complete, reset it */
1172 p_devcb->p_reset_cmpl_cb = NULL;
1174 /* If anyone wants device status notifications, give him one */
1175 btm_report_device_status(BTM_DEV_STATUS_UP);
1177 /* Reset sequence is complete. If this was an application originated */
1178 /* reset, tell him its done. */
1180 (*p_cb)((void *) NULL);
1183 /*******************************************************************************
1185 ** Function btm_issue_host_support_for_lmp_features
1187 ** Description This function:
1188 ** - issues commands to set host supported LMP features (one at
1190 ** - after this is done it issues command to re-read LMP features
1192 ** - after this is done it calls the last step of BR/EDR
1193 ** controller startup sequence.
1197 *******************************************************************************/
1198 static void btm_issue_host_support_for_lmp_features (void)
1200 BTM_TRACE_DEBUG("btm_issue_host_support_for_lmp_features lmp_features_host_may_support: 0x%02x", btm_cb.devcb.lmp_features_host_may_support);
1202 if (btm_cb.devcb.lmp_features_host_may_support & BTM_HOST_MAY_SUPP_SSP)
1204 btsnd_hcic_write_simple_pairing_mode(HCI_SP_MODE_ENABLED);
1208 #if (BLE_INCLUDED == TRUE)
1209 if (btm_cb.devcb.lmp_features_host_may_support & BTM_HOST_MAY_SUPP_LE)
1211 if (btm_cb.devcb.lmp_features_host_may_support & BTM_HOST_MAY_SUPP_SIMULT_BR_LE)
1213 btsnd_hcic_ble_write_host_supported(BTM_BLE_HOST_SUPPORT, BTM_BLE_SIMULTANEOUS_HOST);
1217 btsnd_hcic_ble_write_host_supported(BTM_BLE_HOST_SUPPORT, 0);
1223 if (btm_cb.devcb.lmp_features_host_may_support & BTM_RE_READ_1ST_PAGE)
1225 btm_get_local_ext_features(HCI_EXT_FEATURES_PAGE_1);
1229 if (!btm_cb.devcb.lmp_features_host_may_support)
1231 #if BLE_INCLUDED == TRUE
1232 if (HCI_LE_HOST_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_1]))
1234 btm_read_ble_wl_size();
1237 #elif BTM_INTERNAL_BB == TRUE
1239 UINT8 buf[9] = BTM_INTERNAL_LOCAL_FEA;
1240 btm_read_local_features_complete( buf, 9 );
1244 btm_reset_ctrlr_complete();
1249 BTM_TRACE_ERROR("%s lmp_features_host_may_support: 0x%02x. This is unexpected.",__FUNCTION__,
1250 btm_cb.devcb.lmp_features_host_may_support);
1253 /*******************************************************************************
1255 ** Function btm_set_lmp_features_host_may_support
1257 ** Description This function is called after all LMP features provided by
1258 ** controller are read. It sets the mask that indicates LMP
1259 ** features the host may support based on LMP features supported
1262 ** Host may set SSP (host support) bit only if SSP (controller
1263 ** support) bit is set by controller.
1267 *******************************************************************************/
1268 static void btm_set_lmp_features_host_may_support (UINT8 max_page_number)
1270 btm_cb.devcb.lmp_features_host_may_support = 0;
1272 /* LMP page 0 is always read */
1273 if (HCI_SIMPLE_PAIRING_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
1275 /* host may support SSP */
1276 btm_cb.devcb.lmp_features_host_may_support |= BTM_HOST_MAY_SUPP_SSP;
1279 #if (BLE_INCLUDED == TRUE)
1280 if (HCI_LE_SPT_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
1282 /* host may support LE */
1283 btm_cb.devcb.lmp_features_host_may_support |= BTM_HOST_MAY_SUPP_LE;
1285 if (HCI_SIMUL_LE_BREDR_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
1287 /* host may support BR/EDR and LE simultaneously */
1288 btm_cb.devcb.lmp_features_host_may_support |= BTM_HOST_MAY_SUPP_SIMULT_BR_LE;
1293 if (max_page_number >= HCI_EXT_FEATURES_PAGE_1)
1295 /* nothing yet for HCI_EXT_FEATURES_PAGE_1 */
1298 if (max_page_number >= HCI_EXT_FEATURES_PAGE_1)
1300 /* nothing yet for HCI_EXT_FEATURES_PAGE_2 */
1303 if (btm_cb.devcb.lmp_features_host_may_support)
1304 btm_cb.devcb.lmp_features_host_may_support |= BTM_RE_READ_1ST_PAGE;
1307 /*******************************************************************************
1309 ** Function btm_read_all_lmp_features_complete
1311 ** Description This function is called after all LMP features provided by
1312 ** controller are read.
1313 ** It works with controller supported LMP features which host
1318 *******************************************************************************/
1319 static void btm_read_all_lmp_features_complete (UINT8 max_page_number)
1321 btm_set_lmp_features_host_may_support(max_page_number);
1323 btm_issue_host_support_for_lmp_features();
1326 /*******************************************************************************
1328 ** Function btm_read_local_features_complete
1330 ** Description This function is called when local supported features read
1335 *******************************************************************************/
1336 void btm_read_local_features_complete (UINT8 *p, UINT16 evt_len)
1338 tBTM_DEVCB *p_devcb = &btm_cb.devcb;
1342 btu_stop_timer (&p_devcb->reset_timer);
1344 STREAM_TO_UINT8 (status, p);
1345 if (status == HCI_SUCCESS)
1347 /* Save the Feature Page 0 */
1348 STREAM_TO_ARRAY(p_devcb->local_lmp_features[0],
1349 p, HCI_FEATURE_BYTES_PER_PAGE);
1351 if ((HCI_LMP_EXTENDED_SUPPORTED(p_devcb->local_lmp_features[HCI_EXT_FEATURES_PAGE_0])) &&
1352 (HCI_READ_LOCAL_EXT_FEATURES_SUPPORTED(p_devcb->supported_cmds)))
1354 /* if local controller has extended features and supports
1355 **HCI_Read_Local_Extended_Features command,
1356 ** then start reading these feature starting with extended features page 1 */
1357 BTM_TRACE_DEBUG ("Start reading local extended features");
1358 btm_get_local_ext_features(HCI_EXT_FEATURES_PAGE_1);
1362 btm_read_all_lmp_features_complete (HCI_EXT_FEATURES_PAGE_0);
1367 /*******************************************************************************
1369 ** Function btm_read_local_ext_features_complete
1371 ** Description This function is called when read local extended features
1372 ** command complete message is received from the HCI.
1376 *******************************************************************************/
1377 void btm_read_local_ext_features_complete (UINT8 *p, UINT16 evt_len)
1379 tBTM_DEVCB *p_devcb = &btm_cb.devcb;
1380 tBTM_CMPL_CB *p_cb = p_devcb->p_reset_cmpl_cb;
1383 UINT8 page_number_max;
1386 btu_stop_timer (&btm_cb.devcb.reset_timer);
1388 STREAM_TO_UINT8 (status, p);
1390 if (status != HCI_SUCCESS)
1392 BTM_TRACE_WARNING("btm_read_local_ext_features_complete status = 0x%02X", status);
1393 btm_read_all_lmp_features_complete (HCI_EXT_FEATURES_PAGE_0);
1397 /* Extract Page number */
1398 STREAM_TO_UINT8 (page_number, p);
1400 /* Extract Page number Max */
1401 STREAM_TO_UINT8 (page_number_max, p);
1403 if (page_number > HCI_EXT_FEATURES_PAGE_MAX)
1405 BTM_TRACE_ERROR("btm_read_local_ext_features_complete page=%d unknown",
1410 /* Save the extended features Page received */
1411 STREAM_TO_ARRAY(btm_cb.devcb.local_lmp_features[page_number],
1412 p, HCI_FEATURE_BYTES_PER_PAGE);
1414 /* If this is re-read of the 1-st extended page after host supported LMP features are set */
1415 if ((page_number == HCI_EXT_FEATURES_PAGE_1) &&
1416 (btm_cb.devcb.lmp_features_host_may_support == BTM_RE_READ_1ST_PAGE))
1418 btm_cb.devcb.lmp_features_host_may_support &= ~BTM_RE_READ_1ST_PAGE;
1419 btm_issue_host_support_for_lmp_features();
1423 /* If this is the last page supported by the local BT controller OR */
1424 /* if this is the last page supported by the Host */
1425 if ((page_number == page_number_max) ||
1426 (page_number == HCI_EXT_FEATURES_PAGE_MAX))
1428 BTM_TRACE_DEBUG("BTM reached last extended features page (%d)", page_number);
1429 btm_read_all_lmp_features_complete(page_number);
1431 /* Else (another page must be read) */
1434 /* Read the next features page */
1436 BTM_TRACE_DEBUG("BTM reads next extended features page (%d)", page_number);
1437 btm_get_local_ext_features(page_number);
1441 /*******************************************************************************
1443 ** Function btm_read_local_supported_cmds_complete
1445 ** Description This function is called when local supported commands read
1450 *******************************************************************************/
1451 void btm_read_local_supported_cmds_complete (UINT8 *p)
1453 tBTM_DEVCB *p_devcb = &btm_cb.devcb;
1456 btu_stop_timer (&(p_devcb->reset_timer));
1458 STREAM_TO_UINT8 (status, p);
1459 BTM_TRACE_DEBUG("btm_read_local_supported_cmds_complete status (0x%02x)", status);
1461 if (status == HCI_SUCCESS)
1463 /* Save the supported commands bit mask */
1464 STREAM_TO_ARRAY(p_devcb->supported_cmds, p, HCI_NUM_SUPP_COMMANDS_BYTES);
1467 btm_get_local_features();
1470 /*******************************************************************************
1472 ** Function btm_write_simple_paring_mode_complete
1474 ** Description This function is called when the command complete message
1475 ** is received from the HCI for the write simple pairing mode
1480 *******************************************************************************/
1481 void btm_write_simple_paring_mode_complete (UINT8 *p)
1485 STREAM_TO_UINT8 (status, p);
1487 if (status != HCI_SUCCESS)
1489 BTM_TRACE_WARNING("btm_write_simple_paring_mode_complete status: 0x%02x", status);
1492 if (btm_cb.devcb.lmp_features_host_may_support & BTM_HOST_MAY_SUPP_SSP)
1494 btm_cb.devcb.lmp_features_host_may_support &= ~BTM_HOST_MAY_SUPP_SSP;
1495 btm_issue_host_support_for_lmp_features();
1499 /*******************************************************************************
1501 ** Function btm_write_le_host_supported_complete
1503 ** Description This function is called when the command complete message
1504 ** is received from the HCI for the write LE host supported
1509 *******************************************************************************/
1510 void btm_write_le_host_supported_complete (UINT8 *p)
1514 STREAM_TO_UINT8 (status, p);
1516 if (status != HCI_SUCCESS)
1518 BTM_TRACE_WARNING("btm_write_le_host_supported_complete status: 0x%02x", status);
1521 if (btm_cb.devcb.lmp_features_host_may_support & BTM_HOST_MAY_SUPP_LE)
1523 btm_cb.devcb.lmp_features_host_may_support &= ~BTM_HOST_MAY_SUPP_LE;
1524 if (btm_cb.devcb.lmp_features_host_may_support & BTM_HOST_MAY_SUPP_SIMULT_BR_LE)
1526 btm_cb.devcb.lmp_features_host_may_support &= ~BTM_HOST_MAY_SUPP_SIMULT_BR_LE;
1528 btm_issue_host_support_for_lmp_features();
1532 /*******************************************************************************
1534 ** Function btm_get_voice_coding_support
1536 ** Description This function is provides a way to get the voice coding schemes
1537 ** supported the device.
1539 ** Returns A bit mask - Bit 0 if set indicates CVSD support
1540 ** Bit 1 if set indicates PCM A-law support
1541 ** Bit 2 if set indicates PCM Mu-law support
1543 *******************************************************************************/
1545 UINT8 btm_get_voice_coding_support( void )
1549 if( HCI_LMP_CVSD_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_0]) ) code |= 0x01 ;
1550 if( HCI_LMP_A_LAW_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_0]) ) code |= 0x02 ;
1551 if( HCI_LMP_U_LAW_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_0]) ) code |= 0x04 ;
1556 /*******************************************************************************
1558 ** Function BTM_SetLocalDeviceName
1560 ** Description This function is called to set the local device name.
1562 ** Returns status of the operation
1564 *******************************************************************************/
1565 tBTM_STATUS BTM_SetLocalDeviceName (char *p_name)
1569 if (!p_name || !p_name[0] || (strlen ((char *)p_name) > BD_NAME_LEN))
1570 return (BTM_ILLEGAL_VALUE);
1572 if (btm_cb.devcb.state == BTM_DEV_STATE_WAIT_RESET_CMPLT ||
1573 btm_cb.devcb.state == BTM_DEV_STATE_WAIT_AFTER_RESET)
1574 return (BTM_DEV_RESET);
1576 #if BTM_MAX_LOC_BD_NAME_LEN > 0
1577 /* Save the device name if local storage is enabled */
1578 p = (UINT8 *)btm_cb.cfg.bd_name;
1579 if (p != (UINT8 *)p_name)
1581 BCM_STRNCPY_S(btm_cb.cfg.bd_name, sizeof(btm_cb.cfg.bd_name), p_name, BTM_MAX_LOC_BD_NAME_LEN);
1582 btm_cb.cfg.bd_name[BTM_MAX_LOC_BD_NAME_LEN] = '\0';
1585 p = (UINT8 *)p_name;
1588 if (btsnd_hcic_change_name(p))
1589 return (BTM_CMD_STARTED);
1591 return (BTM_NO_RESOURCES);
1596 /*******************************************************************************
1598 ** Function BTM_ReadLocalDeviceName
1600 ** Description This function is called to read the local device name.
1602 ** Returns status of the operation
1603 ** If success, BTM_SUCCESS is returned and p_name points stored
1604 ** local device name
1605 ** If BTM doesn't store local device name, BTM_NO_RESOURCES is
1606 ** is returned and p_name is set to NULL
1608 *******************************************************************************/
1609 tBTM_STATUS BTM_ReadLocalDeviceName (char **p_name)
1611 #if BTM_MAX_LOC_BD_NAME_LEN > 0
1612 *p_name = btm_cb.cfg.bd_name;
1613 return(BTM_SUCCESS);
1616 return(BTM_NO_RESOURCES);
1621 /*******************************************************************************
1623 ** Function BTM_ReadLocalDeviceNameFromController
1625 ** Description Get local device name from controller. Do not use cached
1626 ** name (used to get chip-id prior to btm reset complete).
1628 ** Returns BTM_CMD_STARTED if successful, otherwise an error
1630 *******************************************************************************/
1631 tBTM_STATUS BTM_ReadLocalDeviceNameFromController (tBTM_CMPL_CB *p_rln_cmpl_cback)
1633 /* Check if rln already in progress */
1634 if (btm_cb.devcb.p_rln_cmpl_cb)
1635 return(BTM_NO_RESOURCES);
1638 btm_cb.devcb.p_rln_cmpl_cb = p_rln_cmpl_cback;
1640 btsnd_hcic_read_name();
1641 btu_start_timer (&btm_cb.devcb.rln_timer, BTU_TTYPE_BTM_DEV_CTL, BTM_DEV_REPLY_TIMEOUT);
1643 return BTM_CMD_STARTED;
1646 /*******************************************************************************
1648 ** Function btm_read_local_name_complete
1650 ** Description This function is called when local name read complete.
1651 ** message is received from the HCI.
1655 *******************************************************************************/
1656 void btm_read_local_name_complete (UINT8 *p, UINT16 evt_len)
1658 tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rln_cmpl_cb;
1662 btu_stop_timer (&btm_cb.devcb.rln_timer);
1664 /* If there was a callback address for read local name, call it */
1665 btm_cb.devcb.p_rln_cmpl_cb = NULL;
1669 STREAM_TO_UINT8 (status, p);
1671 if (status == HCI_SUCCESS)
1679 /*******************************************************************************
1681 ** Function BTM_GetLocalDeviceAddr
1683 ** Description This function is called to read the local device address
1686 ** the local device address is copied into bd_addr
1688 *******************************************************************************/
1689 void BTM_GetLocalDeviceAddr (BD_ADDR bd_addr)
1691 memcpy (bd_addr, btm_cb.devcb.local_addr, BD_ADDR_LEN);
1694 /*******************************************************************************
1696 ** Function BTM_ReadLocalDeviceAddr
1698 ** Description This function is called to read the local device address
1700 ** Returns status of the operation
1702 *******************************************************************************/
1703 tBTM_STATUS BTM_ReadLocalDeviceAddr (tBTM_CMPL_CB *p_cb)
1706 (*p_cb)(btm_cb.devcb.local_addr);
1708 return (BTM_SUCCESS);
1712 /*******************************************************************************
1714 ** Function btm_read_local_addr_complete
1716 ** Description This function is called when local BD Addr read complete
1717 ** message is received from the HCI.
1721 *******************************************************************************/
1722 void btm_read_local_addr_complete (UINT8 *p, UINT16 evt_len)
1727 STREAM_TO_UINT8 (status, p);
1729 if (status == HCI_SUCCESS)
1731 STREAM_TO_BDADDR (btm_cb.devcb.local_addr, p);
1736 /*******************************************************************************
1738 ** Function BTM_ReadLocalVersion
1740 ** Description This function is called to read the local device version
1742 ** Returns status of the operation
1744 *******************************************************************************/
1745 tBTM_STATUS BTM_ReadLocalVersion (tBTM_VERSION_INFO *p_vers)
1747 /* Make sure the device has retrieved the info (not being reset) */
1748 if (btm_cb.devcb.state < BTM_DEV_STATE_READY)
1749 return (BTM_DEV_RESET);
1751 *p_vers = btm_cb.devcb.local_version;
1753 return (BTM_SUCCESS);
1759 /*******************************************************************************
1761 ** Function BTM_SetDeviceClass
1763 ** Description This function is called to set the local device class
1765 ** Returns status of the operation
1767 *******************************************************************************/
1768 tBTM_STATUS BTM_SetDeviceClass (DEV_CLASS dev_class)
1770 if(!memcmp (btm_cb.devcb.dev_class, dev_class, DEV_CLASS_LEN))
1771 return(BTM_SUCCESS);
1773 memcpy (btm_cb.devcb.dev_class, dev_class, DEV_CLASS_LEN);
1775 if (btm_cb.devcb.state == BTM_DEV_STATE_WAIT_RESET_CMPLT ||
1776 btm_cb.devcb.state == BTM_DEV_STATE_WAIT_AFTER_RESET)
1777 return (BTM_DEV_RESET);
1779 if (!btsnd_hcic_write_dev_class (dev_class))
1780 return (BTM_NO_RESOURCES);
1782 return (BTM_SUCCESS);
1786 /*******************************************************************************
1788 ** Function BTM_ReadDeviceClass
1790 ** Description This function is called to read the local device class
1792 ** Returns pointer to the device class
1794 *******************************************************************************/
1795 UINT8 *BTM_ReadDeviceClass (void)
1797 return ((UINT8 *)btm_cb.devcb.dev_class);
1801 /*******************************************************************************
1803 ** Function BTM_ReadLocalFeatures
1805 ** Description This function is called to read the local features
1807 ** Returns pointer to the local features string
1809 *******************************************************************************/
1810 UINT8 *BTM_ReadLocalFeatures (void)
1812 return (btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_0]);
1815 /*******************************************************************************
1817 ** Function BTM_ReadLocalExtendedFeatures
1819 ** Description This function is called to read the local extended features
1821 ** Returns pointer to the local extended features mask or NULL if bad
1824 *******************************************************************************/
1825 UINT8 *BTM_ReadLocalExtendedFeatures (UINT8 page_number)
1827 if (page_number <= HCI_EXT_FEATURES_PAGE_MAX)
1828 return (btm_cb.devcb.local_lmp_features[page_number]);
1830 BTM_TRACE_ERROR("Warning: BTM_ReadLocalExtendedFeatures page %d unknown",
1835 /*******************************************************************************
1837 ** Function BTM_ReadBrcmFeatures
1839 ** Description This function is called to read the Broadcom specific features
1841 ** Returns pointer to the Broadcom features string
1843 *******************************************************************************/
1844 UINT8 *BTM_ReadBrcmFeatures (void)
1846 return (btm_cb.devcb.brcm_features);
1849 /*******************************************************************************
1851 ** Function BTM_RegisterForDeviceStatusNotif
1853 ** Description This function is called to register for device status
1854 ** change notifications.
1856 ** If one registration is already there calling function should
1857 ** save the pointer to the function that is return and
1858 ** call it when processing of the event is complete
1860 ** Returns status of the operation
1862 *******************************************************************************/
1863 tBTM_DEV_STATUS_CB *BTM_RegisterForDeviceStatusNotif (tBTM_DEV_STATUS_CB *p_cb)
1865 tBTM_DEV_STATUS_CB *p_prev = btm_cb.devcb.p_dev_status_cb;
1867 btm_cb.devcb.p_dev_status_cb = p_cb;
1871 /*******************************************************************************
1873 ** Function BTM_VendorSpecificCommand
1875 ** Description Send a vendor specific HCI command to the controller.
1878 ** BTM_SUCCESS Command sent. Does not expect command complete
1879 ** event. (command cmpl callback param is NULL)
1880 ** BTM_CMD_STARTED Command sent. Waiting for command cmpl event.
1883 ** Opcode will be OR'd with HCI_GRP_VENDOR_SPECIFIC.
1885 *******************************************************************************/
1886 tBTM_STATUS BTM_VendorSpecificCommand(UINT16 opcode, UINT8 param_len,
1887 UINT8 *p_param_buf, tBTM_VSC_CMPL_CB *p_cb)
1891 BTM_TRACE_EVENT ("BTM: BTM_VendorSpecificCommand: Opcode: 0x%04X, ParamLen: %i.",
1894 /* Allocate a buffer to hold HCI command plus the callback function */
1895 if ((p_buf = GKI_getbuf((UINT16)(sizeof(BT_HDR) + sizeof (tBTM_CMPL_CB *) +
1896 param_len + HCIC_PREAMBLE_SIZE))) != NULL)
1898 /* Send the HCI command (opcode will be OR'd with HCI_GRP_VENDOR_SPECIFIC) */
1899 btsnd_hcic_vendor_spec_cmd (p_buf, opcode, param_len, p_param_buf, (void *)p_cb);
1903 return (BTM_CMD_STARTED);
1905 return (BTM_SUCCESS);
1908 return (BTM_NO_RESOURCES);
1913 /*******************************************************************************
1915 ** Function btm_vsc_complete
1917 ** Description This function is called when local HCI Vendor Specific
1918 ** Command complete message is received from the HCI.
1922 *******************************************************************************/
1923 void btm_vsc_complete (UINT8 *p, UINT16 opcode, UINT16 evt_len,
1924 tBTM_CMPL_CB *p_vsc_cplt_cback)
1926 tBTM_VSC_CMPL vcs_cplt_params;
1928 /* If there was a callback address for vcs complete, call it */
1929 if (p_vsc_cplt_cback)
1931 /* Pass paramters to the callback function */
1932 vcs_cplt_params.opcode = opcode; /* Number of bytes in return info */
1933 vcs_cplt_params.param_len = evt_len; /* Number of bytes in return info */
1934 vcs_cplt_params.p_param_buf = p;
1935 (*p_vsc_cplt_cback)(&vcs_cplt_params); /* Call the VSC complete callback function */
1939 /*******************************************************************************
1941 ** Function BTM_RegisterForVSEvents
1943 ** Description This function is called to register/deregister for vendor
1944 ** specific HCI events.
1946 ** If is_register=TRUE, then the function will be registered;
1947 ** if is_register=FALSE, then the function will be deregistered.
1949 ** Returns BTM_SUCCESS if successful,
1950 ** BTM_BUSY if maximum number of callbacks have already been
1953 *******************************************************************************/
1954 tBTM_STATUS BTM_RegisterForVSEvents (tBTM_VS_EVT_CB *p_cb, BOOLEAN is_register)
1956 tBTM_STATUS retval = BTM_SUCCESS;
1957 UINT8 i, free_idx = BTM_MAX_VSE_CALLBACKS;
1959 /* See if callback is already registered */
1960 for (i=0; i<BTM_MAX_VSE_CALLBACKS; i++)
1962 if (btm_cb.devcb.p_vend_spec_cb[i] == NULL)
1964 /* Found a free slot. Store index */
1967 else if (btm_cb.devcb.p_vend_spec_cb[i] == p_cb)
1969 /* Found callback in lookup table. If deregistering, clear the entry. */
1970 if (is_register == FALSE)
1972 btm_cb.devcb.p_vend_spec_cb[i] = NULL;
1973 BTM_TRACE_EVENT("BTM Deregister For VSEvents is successfully");
1975 return (BTM_SUCCESS);
1979 /* Didn't find callback. Add callback to free slot if registering */
1982 if (free_idx < BTM_MAX_VSE_CALLBACKS)
1984 btm_cb.devcb.p_vend_spec_cb[free_idx] = p_cb;
1985 BTM_TRACE_EVENT("BTM Register For VSEvents is successfully");
1989 /* No free entries available */
1990 BTM_TRACE_ERROR ("BTM_RegisterForVSEvents: too many callbacks registered");
1992 retval = BTM_NO_RESOURCES;
1999 /*******************************************************************************
2001 ** Function btm_vendor_specific_evt
2003 ** Description Process event HCI_VENDOR_SPECIFIC_EVT
2005 ** Note: Some controllers do not send command complete, so
2006 ** the callback and busy flag are cleared here also.
2010 *******************************************************************************/
2011 void btm_vendor_specific_evt (UINT8 *p, UINT8 evt_len)
2015 BTM_TRACE_DEBUG ("BTM Event: Vendor Specific event from controller");
2017 for (i=0; i<BTM_MAX_VSE_CALLBACKS; i++)
2019 if (btm_cb.devcb.p_vend_spec_cb[i])
2020 (*btm_cb.devcb.p_vend_spec_cb[i])(evt_len, p);
2025 /*******************************************************************************
2027 ** Function BTM_WritePageTimeout
2029 ** Description Send HCI Write Page Timeout.
2032 ** BTM_SUCCESS Command sent.
2033 ** BTM_NO_RESOURCES If out of resources to send the command.
2036 *******************************************************************************/
2037 tBTM_STATUS BTM_WritePageTimeout(UINT16 timeout)
2039 BTM_TRACE_EVENT ("BTM: BTM_WritePageTimeout: Timeout: %d.", timeout);
2041 /* Send the HCI command */
2042 if (btsnd_hcic_write_page_tout (timeout))
2043 return (BTM_SUCCESS);
2045 return (BTM_NO_RESOURCES);
2048 /*******************************************************************************
2050 ** Function BTM_WriteVoiceSettings
2052 ** Description Send HCI Write Voice Settings command.
2053 ** See hcidefs.h for settings bitmask values.
2056 ** BTM_SUCCESS Command sent.
2057 ** BTM_NO_RESOURCES If out of resources to send the command.
2060 *******************************************************************************/
2061 tBTM_STATUS BTM_WriteVoiceSettings(UINT16 settings)
2063 BTM_TRACE_EVENT ("BTM: BTM_WriteVoiceSettings: Settings: 0x%04x.", settings);
2065 /* Send the HCI command */
2066 if (btsnd_hcic_write_voice_settings ((UINT16)(settings & 0x03ff)))
2067 return (BTM_SUCCESS);
2069 return (BTM_NO_RESOURCES);
2072 /*******************************************************************************
2074 ** Function BTM_EnableTestMode
2076 ** Description Send HCI the enable device under test command.
2078 ** Note: Controller can only be taken out of this mode by
2079 ** resetting the controller.
2082 ** BTM_SUCCESS Command sent.
2083 ** BTM_NO_RESOURCES If out of resources to send the command.
2086 *******************************************************************************/
2087 tBTM_STATUS BTM_EnableTestMode(void)
2091 BTM_TRACE_EVENT ("BTM: BTM_EnableTestMode");
2093 /* set auto accept connection as this is needed during test mode */
2094 /* Allocate a buffer to hold HCI command */
2095 cond = HCI_DO_AUTO_ACCEPT_CONNECT;
2096 if (!btsnd_hcic_set_event_filter(HCI_FILTER_CONNECTION_SETUP,
2097 HCI_FILTER_COND_NEW_DEVICE,
2098 &cond, sizeof(cond)))
2100 return (BTM_NO_RESOURCES);
2103 /* put device to connectable mode */
2104 if (!BTM_SetConnectability(BTM_CONNECTABLE, BTM_DEFAULT_CONN_WINDOW,
2105 BTM_DEFAULT_CONN_INTERVAL) == BTM_SUCCESS)
2107 return BTM_NO_RESOURCES;
2110 /* put device to discoverable mode */
2111 if (!BTM_SetDiscoverability(BTM_GENERAL_DISCOVERABLE, BTM_DEFAULT_DISC_WINDOW,
2112 BTM_DEFAULT_DISC_INTERVAL) == BTM_SUCCESS)
2114 return BTM_NO_RESOURCES;
2117 /* mask off all of event from controller */
2118 if (!btsnd_hcic_set_event_mask(LOCAL_BR_EDR_CONTROLLER_ID,
2119 (UINT8 *)"\x00\x00\x00\x00\x00\x00\x00\x00"))
2121 return BTM_NO_RESOURCES;
2124 /* Send the HCI command */
2125 if (btsnd_hcic_enable_test_mode ())
2126 return (BTM_SUCCESS);
2128 return (BTM_NO_RESOURCES);
2131 /*******************************************************************************
2133 ** Function btm_get_hci_version
2135 ** Description Local function called to retrieve the current HCI version
2137 ** Returns Bluetooth HCI Version returned by the controller
2139 *******************************************************************************/
2140 UINT8 btm_get_hci_version (void)
2142 return (btm_cb.devcb.local_version.hci_version);
2147 /*******************************************************************************
2149 ** Function BTM_ReadStoredLinkKey
2151 ** Description This function is called to obtain link key for the specified
2152 ** device from the NVRAM storage attached to the Bluetooth
2155 ** Parameters: bd_addr - Address of the device
2156 ** p_cb - Call back function to be called to return
2159 *******************************************************************************/
2160 tBTM_STATUS BTM_ReadStoredLinkKey (BD_ADDR bd_addr, tBTM_CMPL_CB *p_cb)
2162 BD_ADDR local_bd_addr;
2163 BOOLEAN read_all_flag = FALSE;
2165 /* Check if the previous command is completed */
2166 if (btm_cb.devcb.p_stored_link_key_cmpl_cb)
2171 /* This is to read all the link keys */
2172 read_all_flag = TRUE;
2174 /* We don't care the BD address. Just pass a non zero pointer */
2175 bd_addr = local_bd_addr;
2178 BTM_TRACE_EVENT ("BTM: BTM_ReadStoredLinkKey: Read_All: %s",
2179 read_all_flag ? "TRUE" : "FALSE");
2181 /* Send the HCI command */
2182 btm_cb.devcb.p_stored_link_key_cmpl_cb = p_cb;
2183 if (btsnd_hcic_read_stored_key (bd_addr, read_all_flag))
2184 return (BTM_SUCCESS);
2186 return (BTM_NO_RESOURCES);
2191 /*******************************************************************************
2193 ** Function BTM_WriteStoredLinkKey
2195 ** Description This function is called to write link keys for the specified
2196 ** device addresses to the NVRAM storage attached to the Bluetooth
2199 ** Parameters: num_keys - Number of link keys
2200 ** bd_addr - Addresses of the devices
2201 ** link_key - Link Keys to be stored
2202 ** p_cb - Call back function to be called to return
2205 *******************************************************************************/
2206 tBTM_STATUS BTM_WriteStoredLinkKey (UINT8 num_keys,
2211 /* Check if the previous command is completed */
2212 if (btm_cb.devcb.p_stored_link_key_cmpl_cb)
2215 BTM_TRACE_EVENT ("BTM: BTM_WriteStoredLinkKey: num_keys: %d", num_keys);
2217 /* Check the maximum number of link keys */
2218 if(num_keys > HCI_MAX_NUM_OF_LINK_KEYS_PER_CMMD)
2219 num_keys = HCI_MAX_NUM_OF_LINK_KEYS_PER_CMMD;
2221 /* Send the HCI command */
2222 btm_cb.devcb.p_stored_link_key_cmpl_cb = p_cb;
2223 if (btsnd_hcic_write_stored_key (num_keys, bd_addr, link_key))
2224 return (BTM_SUCCESS);
2226 return (BTM_NO_RESOURCES);
2231 /*******************************************************************************
2233 ** Function BTM_DeleteStoredLinkKey
2235 ** Description This function is called to delete link key for the specified
2236 ** device addresses from the NVRAM storage attached to the Bluetooth
2239 ** Parameters: bd_addr - Addresses of the devices
2240 ** p_cb - Call back function to be called to return
2243 *******************************************************************************/
2244 tBTM_STATUS BTM_DeleteStoredLinkKey(BD_ADDR bd_addr, tBTM_CMPL_CB *p_cb)
2246 BD_ADDR local_bd_addr;
2247 BOOLEAN delete_all_flag = FALSE;
2249 /* Check if the previous command is completed */
2250 if (btm_cb.devcb.p_stored_link_key_cmpl_cb)
2255 /* This is to delete all link keys */
2256 delete_all_flag = TRUE;
2258 /* We don't care the BD address. Just pass a non zero pointer */
2259 bd_addr = local_bd_addr;
2262 BTM_TRACE_EVENT ("BTM: BTM_DeleteStoredLinkKey: delete_all_flag: %s",
2263 delete_all_flag ? "TRUE" : "FALSE");
2265 /* Send the HCI command */
2266 btm_cb.devcb.p_stored_link_key_cmpl_cb = p_cb;
2267 if (!btsnd_hcic_delete_stored_key (bd_addr, delete_all_flag))
2269 return (BTM_NO_RESOURCES);
2272 return (BTM_SUCCESS);
2276 /*******************************************************************************
2278 ** Function btm_read_stored_link_key_complete
2280 ** Description This function is called when the command complete message
2281 ** is received from the HCI for the read stored link key command.
2285 *******************************************************************************/
2286 void btm_read_stored_link_key_complete (UINT8 *p)
2288 tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_stored_link_key_cmpl_cb;
2289 tBTM_READ_STORED_LINK_KEY_COMPLETE result;
2291 /* If there was a callback registered for read stored link key, call it */
2292 btm_cb.devcb.p_stored_link_key_cmpl_cb = NULL;
2296 /* Set the call back event to indicate command complete */
2297 result.event = BTM_CB_EVT_READ_STORED_LINK_KEYS;
2299 /* Extract the result fields from the HCI event if status is success */
2300 STREAM_TO_UINT8 (result.status, p);
2301 if (result.status == HCI_SUCCESS)
2303 STREAM_TO_UINT16 (result.max_keys, p);
2304 STREAM_TO_UINT16 (result.read_keys, p);
2308 BTM_TRACE_WARNING("Read stored link key status %d", result.status);
2309 result.max_keys = 0;
2310 result.read_keys = 0;
2312 /* Call the call back and pass the result */
2318 /*******************************************************************************
2320 ** Function btm_write_stored_link_key_complete
2322 ** Description This function is called when the command complete message
2323 ** is received from the HCI for the write stored link key command.
2327 *******************************************************************************/
2328 void btm_write_stored_link_key_complete (UINT8 *p)
2330 tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_stored_link_key_cmpl_cb;
2331 tBTM_WRITE_STORED_LINK_KEY_COMPLETE result;
2333 /* If there was a callback registered for read stored link key, call it */
2334 btm_cb.devcb.p_stored_link_key_cmpl_cb = NULL;
2338 /* Set the call back event to indicate command complete */
2339 result.event = BTM_CB_EVT_WRITE_STORED_LINK_KEYS;
2341 /* Extract the result fields from the HCI event */
2342 STREAM_TO_UINT8 (result.status, p);
2343 STREAM_TO_UINT8 (result.num_keys, p);
2345 /* Call the call back and pass the result */
2351 /*******************************************************************************
2353 ** Function btm_delete_stored_link_key_complete
2355 ** Description This function is called when the command complete message
2356 ** is received from the HCI for the delete stored link key command.
2360 *******************************************************************************/
2361 void btm_delete_stored_link_key_complete (UINT8 *p)
2363 tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_stored_link_key_cmpl_cb;
2364 tBTM_DELETE_STORED_LINK_KEY_COMPLETE result;
2366 /* If there was a callback registered for read stored link key, call it */
2367 btm_cb.devcb.p_stored_link_key_cmpl_cb = NULL;
2371 /* Set the call back event to indicate command complete */
2372 result.event = BTM_CB_EVT_DELETE_STORED_LINK_KEYS;
2374 /* Extract the result fields from the HCI event */
2375 STREAM_TO_UINT8 (result.status, p);
2376 STREAM_TO_UINT16 (result.num_keys, p);
2378 /* Call the call back and pass the result */
2384 /*******************************************************************************
2386 ** Function btm_return_link_keys_evt
2388 ** Description This function is called when the return link keys event
2389 ** is received from the HCI for the read stored link key command.
2393 *******************************************************************************/
2394 void btm_return_link_keys_evt (tBTM_RETURN_LINK_KEYS_EVT *result)
2396 tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_stored_link_key_cmpl_cb;
2398 UINT8 bd_addr[BD_ADDR_LEN];
2399 UINT8 link_key[LINK_KEY_LEN];
2401 /* Call the call back to pass the link keys to application */
2404 /* Change the BD addr and Link key in to big endian order */
2405 p = (UINT8 *)(result + 1);
2406 for (i=0; i<result->num_keys; i++)
2408 /* Initialize the backup pointer */
2411 /* Extract the BD Addr and Link Key */
2412 REVERSE_STREAM_TO_ARRAY(bd_addr, p1, BD_ADDR_LEN);
2413 REVERSE_STREAM_TO_ARRAY(link_key, p1, LINK_KEY_LEN);
2415 /* Write the BD Addr and Link Key back in big endian format */
2416 ARRAY_TO_STREAM(p, bd_addr, BD_ADDR_LEN);
2417 ARRAY_TO_STREAM(p, link_key, LINK_KEY_LEN);
2426 /*******************************************************************************
2428 ** Function btm_report_device_status
2430 ** Description This function is called when there is a change in the device
2431 ** status. This function will report the new device status to
2436 *******************************************************************************/
2437 void btm_report_device_status (tBTM_DEV_STATUS status)
2439 tBTM_DEV_STATUS_CB *p_cb = btm_cb.devcb.p_dev_status_cb;
2441 /* Call the call back to pass the device status to application */