The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 3 | * Copyright (C) 2008-2014 Broadcom Corporation |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 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 | * |
| 21 | * This file contains functions for BLE GAP. |
| 22 | * |
| 23 | ******************************************************************************/ |
| 24 | |
| 25 | #include <string.h> |
| 26 | #include <stdio.h> |
| 27 | #include <stddef.h> |
| 28 | |
| 29 | #include "bt_types.h" |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 30 | #include "bt_utils.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 31 | #include "btm_int.h" |
Wei Wang | 21015a4 | 2014-10-03 10:58:03 -0700 | [diff] [blame] | 32 | #include "btm_ble_api.h" |
| 33 | #include "btu.h" |
Chris Manton | 79ecab5 | 2014-10-31 14:54:51 -0700 | [diff] [blame] | 34 | #include "device/include/controller.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 35 | #include "hcimsgs.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 36 | #include "gap_api.h" |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 37 | |
| 38 | #if BLE_INCLUDED == TRUE |
Priti Aghera | 9c29d08 | 2014-09-02 15:41:56 -0700 | [diff] [blame] | 39 | #include "l2c_int.h" |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 40 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 41 | #include "gattdefs.h" |
Nitin Arora | 021e17a | 2014-01-29 19:18:39 -0800 | [diff] [blame] | 42 | #include "gatt_int.h" |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 43 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 44 | #include "btm_ble_int.h" |
Chris Manton | f802700 | 2015-03-12 09:22:48 -0700 | [diff] [blame] | 45 | #define LOG_TAG "bt_btm_ble" |
Sharvil Nanavati | 4480276 | 2014-12-23 23:08:58 -0800 | [diff] [blame] | 46 | #include "osi/include/log.h" |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 47 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 48 | #define BTM_BLE_NAME_SHORT 0x01 |
| 49 | #define BTM_BLE_NAME_CMPL 0x02 |
| 50 | |
| 51 | #define BTM_BLE_FILTER_TARGET_UNKNOWN 0xff |
| 52 | #define BTM_BLE_POLICY_UNKNOWN 0xff |
| 53 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 54 | #define BTM_EXT_BLE_RMT_NAME_TIMEOUT 30 |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 55 | #define MIN_ADV_LENGTH 2 |
Satya Calloji | 5725fc6 | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 56 | #define BTM_VSC_CHIP_CAPABILITY_RSP_LEN_L_RELEASE 9 |
| 57 | |
| 58 | static tBTM_BLE_VSC_CB cmn_ble_vsc_cb; |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 59 | |
Bernhard Rosenkränzer | 104e3f2 | 2014-11-12 21:53:08 +0100 | [diff] [blame] | 60 | #if BLE_VND_INCLUDED == TRUE |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 61 | static tBTM_BLE_CTRL_FEATURES_CBACK *p_ctrl_le_feature_rd_cmpl_cback = NULL; |
Bernhard Rosenkränzer | 104e3f2 | 2014-11-12 21:53:08 +0100 | [diff] [blame] | 62 | #endif |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 63 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 64 | /******************************************************************************* |
| 65 | ** Local functions |
| 66 | *******************************************************************************/ |
| 67 | static void btm_ble_update_adv_flag(UINT8 flag); |
| 68 | static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, UINT8 addr_type, UINT8 evt_type, UINT8 *p); |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 69 | UINT8 *btm_ble_build_adv_data(tBTM_BLE_AD_MASK *p_data_mask, UINT8 **p_dst, |
| 70 | tBTM_BLE_ADV_DATA *p_data); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 71 | static UINT8 btm_set_conn_mode_adv_init_addr(tBTM_BLE_INQ_CB *p_cb, |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 72 | BD_ADDR_PTR p_peer_addr_ptr, |
| 73 | tBLE_ADDR_TYPE *p_peer_addr_type, |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 74 | tBLE_ADDR_TYPE *p_own_addr_type); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 75 | static void btm_ble_stop_observe(void); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 76 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 77 | #define BTM_BLE_INQ_RESULT 0x01 |
| 78 | #define BTM_BLE_OBS_RESULT 0x02 |
| 79 | #define BTM_BLE_SEL_CONN_RESULT 0x04 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 80 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 81 | /* LE states combo bit to check */ |
| 82 | const UINT8 btm_le_state_combo_tbl[BTM_BLE_STATE_MAX][BTM_BLE_STATE_MAX][2] = |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 83 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 84 | {/* single state support */ |
| 85 | {HCI_SUPP_LE_STATES_CONN_ADV_MASK, HCI_SUPP_LE_STATES_CONN_ADV_OFF}, /* conn_adv */ |
| 86 | {HCI_SUPP_LE_STATES_INIT_MASK, HCI_SUPP_LE_STATES_INIT_OFF}, /* init */ |
| 87 | {HCI_SUPP_LE_STATES_INIT_MASK, HCI_SUPP_LE_STATES_INIT_OFF}, /* master */ |
| 88 | {HCI_SUPP_LE_STATES_SLAVE_MASK, HCI_SUPP_LE_STATES_SLAVE_OFF}, /* slave */ |
| 89 | {0, 0}, /* todo: lo du dir adv, not covered ? */ |
| 90 | {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_OFF}, /* hi duty dir adv */ |
| 91 | {HCI_SUPP_LE_STATES_NON_CONN_ADV_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_OFF}, /* non connectable adv */ |
| 92 | {HCI_SUPP_LE_STATES_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_PASS_SCAN_OFF}, /* passive scan */ |
| 93 | {HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_ACTIVE_SCAN_OFF}, /* active scan */ |
| 94 | {HCI_SUPP_LE_STATES_SCAN_ADV_MASK, HCI_SUPP_LE_STATESSCAN_ADV_OFF} /* scanable adv */ |
| 95 | }, |
| 96 | { /* conn_adv =0 */ |
| 97 | {0, 0}, /* conn_adv */ |
| 98 | {HCI_SUPP_LE_STATES_CONN_ADV_INIT_MASK, HCI_SUPP_LE_STATES_CONN_ADV_INIT_OFF}, /* init: 32 */ |
| 99 | {HCI_SUPP_LE_STATES_CONN_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_CONN_ADV_MASTER_OFF}, /* master: 35 */ |
| 100 | {HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_OFF}, /* slave: 38,*/ |
| 101 | {0, 0}, /* lo du dir adv */ |
| 102 | {0, 0}, /* hi duty dir adv */ |
| 103 | {0, 0}, /* non connectable adv */ |
| 104 | {HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_OFF}, /* passive scan */ |
| 105 | {HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_OFF}, /* active scan */ |
| 106 | {0, 0} /* scanable adv */ |
| 107 | }, |
| 108 | { /* init */ |
| 109 | {HCI_SUPP_LE_STATES_CONN_ADV_INIT_MASK, HCI_SUPP_LE_STATES_CONN_ADV_INIT_OFF}, /* conn_adv: 32 */ |
| 110 | {0, 0}, /* init */ |
| 111 | {HCI_SUPP_LE_STATES_INIT_MASTER_MASK, HCI_SUPP_LE_STATES_INIT_MASTER_OFF}, /* master 28 */ |
| 112 | {HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_MASK, HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_OFF}, /* slave 41 */ |
| 113 | {HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_MASK, HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_OFF} ,/* lo du dir adv 34 */ |
| 114 | {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_OFF}, /* hi duty dir adv 33 */ |
| 115 | {HCI_SUPP_LE_STATES_NON_CONN_INIT_MASK, HCI_SUPP_LE_STATES_NON_CONN_INIT_OFF}, /* non connectable adv */ |
| 116 | {HCI_SUPP_LE_STATES_PASS_SCAN_INIT_MASK, HCI_SUPP_LE_STATES_PASS_SCAN_INIT_OFF}, /* passive scan */ |
| 117 | {HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_MASK, HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_OFF}, /* active scan */ |
| 118 | {HCI_SUPP_LE_STATES_SCAN_ADV_INIT_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_INIT_OFF} /* scanable adv */ |
| 119 | |
| 120 | }, |
| 121 | { /* master */ |
| 122 | {HCI_SUPP_LE_STATES_CONN_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_CONN_ADV_MASTER_OFF}, /* conn_adv: 35 */ |
| 123 | {HCI_SUPP_LE_STATES_INIT_MASTER_MASK, HCI_SUPP_LE_STATES_INIT_MASTER_OFF}, /* init 28 */ |
| 124 | {HCI_SUPP_LE_STATES_INIT_MASTER_MASK, HCI_SUPP_LE_STATES_INIT_MASTER_OFF}, /* master 28 */ |
| 125 | {HCI_SUPP_LE_STATES_CONN_ADV_INIT_MASK, HCI_SUPP_LE_STATES_CONN_ADV_INIT_OFF}, /* slave: 32 */ |
| 126 | {HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_OFF}, /* lo duty cycle adv 37 */ |
| 127 | {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_OFF}, /* hi duty cycle adv 36 */ |
| 128 | {HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_OFF}, /* non connectable adv */ |
| 129 | {HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_MASK, HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_OFF}, /* passive scan */ |
| 130 | {HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_MASK, HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_OFF}, /* active scan */ |
| 131 | {HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_OFF} /* scanable adv */ |
| 132 | |
| 133 | }, |
| 134 | { /* slave */ |
| 135 | {HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_OFF}, /* conn_adv: 38,*/ |
| 136 | {HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_MASK, HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_OFF}, /* init 41 */ |
| 137 | {HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_MASK, HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_OFF}, /* master 41 */ |
| 138 | {HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_OFF}, /* slave: 38,*/ |
| 139 | {HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_OFF}, /* lo duty cycle adv 40 */ |
| 140 | {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_OFF}, /* hi duty cycle adv 39 */ |
| 141 | {HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_OFF}, /* non connectable adv */ |
| 142 | {HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_MASK, HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_OFF}, /* passive scan */ |
| 143 | {HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_MASK, HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_OFF}, /* active scan */ |
| 144 | {HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_OFF} /* scanable adv */ |
| 145 | |
| 146 | }, |
| 147 | { /* lo duty cycle adv */ |
| 148 | {0, 0}, /* conn_adv: 38,*/ |
| 149 | {HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_MASK, HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_OFF} ,/* init 34 */ |
| 150 | {HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_OFF}, /* master 37 */ |
| 151 | {HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_OFF}, /* slave: 40 */ |
| 152 | {0, 0}, /* lo duty cycle adv 40 */ |
| 153 | {0, 0}, /* hi duty cycle adv 39 */ |
| 154 | {0, 0}, /* non connectable adv */ |
| 155 | {0, 0}, /* TODO: passive scan, not covered? */ |
| 156 | {0, 0}, /* TODO: active scan, not covered? */ |
| 157 | {0, 0} /* scanable adv */ |
| 158 | }, |
| 159 | { /* hi duty cycle adv */ |
| 160 | {0, 0}, /* conn_adv: 38,*/ |
| 161 | {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_OFF}, /* init 33 */ |
| 162 | {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_OFF}, /* master 36 */ |
| 163 | {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_OFF}, /* slave: 39*/ |
| 164 | {0, 0}, /* lo duty cycle adv 40 */ |
| 165 | {0, 0}, /* hi duty cycle adv 39 */ |
| 166 | {0, 0}, /* non connectable adv */ |
| 167 | {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_OFF}, /* passive scan */ |
| 168 | {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_OFF}, /* active scan */ |
| 169 | {0, 0} /* scanable adv */ |
| 170 | }, |
| 171 | { /* non connectable adv */ |
| 172 | {0, 0}, /* conn_adv: */ |
| 173 | {HCI_SUPP_LE_STATES_NON_CONN_INIT_MASK, HCI_SUPP_LE_STATES_NON_CONN_INIT_OFF}, /* init */ |
| 174 | {HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_OFF}, /* master */ |
| 175 | {HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_OFF}, /* slave: */ |
| 176 | {0, 0}, /* lo duty cycle adv */ |
| 177 | {0, 0}, /* hi duty cycle adv */ |
| 178 | {0, 0}, /* non connectable adv */ |
| 179 | {HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_OFF}, /* passive scan */ |
| 180 | {HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_OFF}, /* active scan */ |
| 181 | {0, 0} /* scanable adv */ |
| 182 | }, |
| 183 | { /* passive scan */ |
| 184 | {HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_OFF}, /* conn_adv: */ |
| 185 | {HCI_SUPP_LE_STATES_PASS_SCAN_INIT_MASK, HCI_SUPP_LE_STATES_PASS_SCAN_INIT_OFF}, /* init */ |
| 186 | {HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_MASK, HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_OFF}, /* master */ |
| 187 | {HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_MASK, HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_OFF}, /* slave: */ |
| 188 | {0, 0}, /* lo duty cycle adv */ |
| 189 | {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_OFF}, /* hi duty cycle adv */ |
| 190 | {HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_OFF}, /* non connectable adv */ |
| 191 | {0, 0}, /* passive scan */ |
| 192 | {0, 0}, /* active scan */ |
| 193 | {HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_OFF} /* scanable adv */ |
| 194 | }, |
| 195 | { /* active scan */ |
| 196 | {HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_OFF}, /* conn_adv: */ |
| 197 | {HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_MASK, HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_OFF}, /* init */ |
| 198 | {HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_MASK, HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_OFF}, /* master */ |
| 199 | {HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_MASK, HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_OFF}, /* slave: */ |
| 200 | {0, 0}, /* lo duty cycle adv */ |
| 201 | {HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_OFF}, /* hi duty cycle adv */ |
| 202 | {HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_OFF}, /* non connectable adv */ |
| 203 | {0, 0}, /* TODO: passive scan */ |
| 204 | {0, 0}, /* TODO: active scan */ |
| 205 | {HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_OFF} /* scanable adv */ |
| 206 | }, |
| 207 | { /* scanable adv */ |
| 208 | {0, 0}, /* conn_adv: */ |
| 209 | {HCI_SUPP_LE_STATES_SCAN_ADV_INIT_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_INIT_OFF}, /* init */ |
| 210 | {HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_OFF}, /* master */ |
| 211 | {HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_OFF}, /* slave: */ |
| 212 | {0, 0}, /* lo duty cycle adv */ |
| 213 | {0, 0}, /* hi duty cycle adv */ |
| 214 | {0, 0}, /* non connectable adv */ |
| 215 | {HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_OFF}, /* passive scan */ |
| 216 | {HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_MASK, HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_OFF}, /* active scan */ |
| 217 | {0, 0} /* scanable adv */ |
| 218 | } |
| 219 | |
| 220 | }; |
| 221 | /* check LE combo state supported */ |
| 222 | #define BTM_LE_STATES_SUPPORTED(x, y, z) ((x)[(z)] & (y)) |
| 223 | |
| 224 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 225 | /******************************************************************************* |
| 226 | ** |
| 227 | ** Function BTM_BleUpdateAdvWhitelist |
| 228 | ** |
| 229 | ** Description Add or remove device from advertising white list |
| 230 | ** |
| 231 | ** Returns void |
| 232 | ** |
| 233 | *******************************************************************************/ |
| 234 | BOOLEAN BTM_BleUpdateAdvWhitelist(BOOLEAN add_remove, BD_ADDR remote_bda) |
| 235 | { |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 236 | UNUSED(add_remove); |
| 237 | UNUSED(remote_bda); |
| 238 | |
| 239 | return FALSE; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 240 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 241 | |
| 242 | /******************************************************************************* |
| 243 | ** |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 244 | ** Function BTM_BleUpdateAdvFilterPolicy |
| 245 | ** |
| 246 | ** Description This function update the filter policy of advertiser. |
| 247 | ** |
| 248 | ** Parameter adv_policy: advertising filter policy |
| 249 | ** |
| 250 | ** Return void |
| 251 | *******************************************************************************/ |
| 252 | void BTM_BleUpdateAdvFilterPolicy(tBTM_BLE_AFP adv_policy) |
| 253 | { |
| 254 | tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 255 | tBLE_ADDR_TYPE init_addr_type = BLE_ADDR_PUBLIC; |
| 256 | BD_ADDR p_addr_ptr= {0}; |
| 257 | UINT8 adv_mode = p_cb->adv_mode; |
| 258 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 259 | BTM_TRACE_EVENT ("BTM_BleUpdateAdvFilterPolicy"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 260 | |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 261 | if (!controller_get_interface()->supports_ble()) |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 262 | return; |
| 263 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 264 | if (p_cb->afp != adv_policy) |
| 265 | { |
| 266 | p_cb->afp = adv_policy; |
| 267 | |
| 268 | /* if adv active, stop and restart */ |
| 269 | btm_ble_stop_adv (); |
| 270 | |
| 271 | if (p_cb->connectable_mode & BTM_BLE_CONNECTABLE) |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 272 | p_cb->evt_type = btm_set_conn_mode_adv_init_addr(p_cb, p_addr_ptr, &init_addr_type, |
| 273 | &p_cb->adv_addr_type); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 274 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 275 | btsnd_hcic_ble_write_adv_params ((UINT16)(p_cb->adv_interval_min ? p_cb->adv_interval_min : |
| 276 | BTM_BLE_GAP_ADV_SLOW_INT), |
| 277 | (UINT16)(p_cb->adv_interval_max ? p_cb->adv_interval_max : |
| 278 | BTM_BLE_GAP_ADV_SLOW_INT), |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 279 | p_cb->evt_type, |
| 280 | p_cb->adv_addr_type, |
| 281 | init_addr_type, |
| 282 | p_addr_ptr, |
| 283 | p_cb->adv_chnl_map, |
| 284 | p_cb->afp); |
| 285 | |
| 286 | if (adv_mode == BTM_BLE_ADV_ENABLE) |
| 287 | btm_ble_start_adv (); |
| 288 | |
| 289 | } |
| 290 | } |
Satya Calloji | 5725fc6 | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 291 | |
| 292 | /******************************************************************************* |
| 293 | ** |
| 294 | ** Function btm_ble_send_extended_scan_params |
| 295 | ** |
| 296 | ** Description This function sends out the extended scan parameters command to the controller |
| 297 | ** |
| 298 | ** Parameters scan_type - Scan type |
| 299 | ** scan_int - Scan interval |
| 300 | ** scan_win - Scan window |
| 301 | ** addr_type_own - Own address type |
| 302 | ** scan_filter_policy - Scan filter policy |
| 303 | ** |
| 304 | ** Returns TRUE or FALSE |
| 305 | ** |
| 306 | *******************************************************************************/ |
| 307 | BOOLEAN btm_ble_send_extended_scan_params(UINT8 scan_type, UINT32 scan_int, |
| 308 | UINT32 scan_win, UINT8 addr_type_own, |
| 309 | UINT8 scan_filter_policy) |
| 310 | { |
| 311 | UINT8 scan_param[HCIC_PARAM_SIZE_BLE_WRITE_EXTENDED_SCAN_PARAM]; |
| 312 | UINT8 *pp_scan = scan_param; |
| 313 | |
| 314 | memset(scan_param, 0, HCIC_PARAM_SIZE_BLE_WRITE_EXTENDED_SCAN_PARAM); |
| 315 | |
| 316 | UINT8_TO_STREAM(pp_scan, scan_type); |
| 317 | UINT32_TO_STREAM(pp_scan, scan_int); |
| 318 | UINT32_TO_STREAM(pp_scan, scan_win); |
| 319 | UINT8_TO_STREAM(pp_scan, addr_type_own); |
| 320 | UINT8_TO_STREAM(pp_scan, scan_filter_policy); |
| 321 | |
| 322 | BTM_TRACE_DEBUG("%s, %d, %d", __func__, scan_int, scan_win); |
| 323 | if ((BTM_VendorSpecificCommand(HCI_BLE_EXTENDED_SCAN_PARAMS_OCF, |
| 324 | HCIC_PARAM_SIZE_BLE_WRITE_EXTENDED_SCAN_PARAM, scan_param, NULL)) != BTM_SUCCESS) |
| 325 | { |
| 326 | BTM_TRACE_ERROR("%s error sending extended scan parameters", __func__); |
| 327 | return FALSE; |
| 328 | } |
| 329 | return TRUE; |
| 330 | } |
| 331 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 332 | /******************************************************************************* |
| 333 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 334 | ** Function BTM_BleObserve |
| 335 | ** |
| 336 | ** Description This procedure keep the device listening for advertising |
| 337 | ** events from a broadcast device. |
| 338 | ** |
| 339 | ** Parameters start: start or stop observe. |
| 340 | ** white_list: use white list in observer mode or not. |
| 341 | ** |
| 342 | ** Returns void |
| 343 | ** |
| 344 | *******************************************************************************/ |
| 345 | tBTM_STATUS BTM_BleObserve(BOOLEAN start, UINT8 duration, |
| 346 | tBTM_INQ_RESULTS_CB *p_results_cb, tBTM_CMPL_CB *p_cmpl_cb) |
| 347 | { |
| 348 | tBTM_BLE_INQ_CB *p_inq = &btm_cb.ble_ctr_cb.inq_var; |
Satya Calloji | 877123f | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 349 | tBTM_STATUS status = BTM_WRONG_MODE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 350 | |
Satya Calloji | 5725fc6 | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 351 | UINT32 scan_interval = !p_inq->scan_interval ? BTM_BLE_GAP_DISC_SCAN_INT : p_inq->scan_interval; |
| 352 | UINT32 scan_window = !p_inq->scan_window ? BTM_BLE_GAP_DISC_SCAN_WIN : p_inq->scan_window; |
| 353 | |
Satya Calloji | 877123f | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 354 | BTM_TRACE_EVENT ("%s : scan_type:%d, %d, %d", __func__, btm_cb.btm_inq_vars.scan_type, |
| 355 | p_inq->scan_interval, p_inq->scan_window); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 356 | |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 357 | if (!controller_get_interface()->supports_ble()) |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 358 | return BTM_ILLEGAL_VALUE; |
| 359 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 360 | if (start) |
| 361 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 362 | /* shared inquiry database, do not allow observe if any inquiry is active */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 363 | if (BTM_BLE_IS_OBS_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) |
Nitin Arora | 0830ad4 | 2014-02-21 18:20:37 -0800 | [diff] [blame] | 364 | { |
Satya Calloji | 877123f | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 365 | BTM_TRACE_ERROR("%s Observe Already Active", __func__); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 366 | return status; |
Nitin Arora | 0830ad4 | 2014-02-21 18:20:37 -0800 | [diff] [blame] | 367 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 368 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 369 | btm_cb.ble_ctr_cb.p_obs_results_cb = p_results_cb; |
| 370 | btm_cb.ble_ctr_cb.p_obs_cmpl_cb = p_cmpl_cb; |
| 371 | status = BTM_CMD_STARTED; |
| 372 | |
| 373 | /* scan is not started */ |
| 374 | if (!BTM_BLE_IS_SCAN_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) |
| 375 | { |
Satya Calloji | 5725fc6 | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 376 | /* allow config of scan type */ |
| 377 | p_inq->scan_type = (p_inq->scan_type == BTM_BLE_SCAN_MODE_NONE) ? |
| 378 | BTM_BLE_SCAN_MODE_ACTI: p_inq->scan_type; |
| 379 | /* assume observe always not using white list */ |
Satya Calloji | 877123f | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 380 | #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE) |
| 381 | /* enable resolving list */ |
| 382 | btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_SCAN); |
| 383 | #endif |
| 384 | |
Satya Calloji | 5725fc6 | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 385 | if (cmn_ble_vsc_cb.extended_scan_support == 0) |
| 386 | { |
| 387 | btsnd_hcic_ble_set_scan_params(p_inq->scan_type, (UINT16)scan_interval, |
| 388 | (UINT16)scan_window, |
| 389 | btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, |
| 390 | BTM_BLE_DEFAULT_SFP); |
| 391 | } |
| 392 | else |
| 393 | { |
| 394 | btm_ble_send_extended_scan_params(p_inq->scan_type, scan_interval, scan_window, |
| 395 | btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, |
| 396 | BTM_BLE_DEFAULT_SFP); |
| 397 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 398 | |
Satya Calloji | 877123f | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 399 | p_inq->scan_duplicate_filter = BTM_BLE_DUPLICATE_DISABLE; |
| 400 | status = btm_ble_start_scan(); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 401 | } |
Satya Calloji | 877123f | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 402 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 403 | if (status == BTM_CMD_STARTED) |
| 404 | { |
| 405 | btm_cb.ble_ctr_cb.scan_activity |= BTM_LE_OBSERVE_ACTIVE; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 406 | if (duration != 0) |
| 407 | /* start observer timer */ |
| 408 | btu_start_timer (&btm_cb.ble_ctr_cb.obs_timer_ent, BTU_TTYPE_BLE_OBSERVE, duration); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 409 | } |
| 410 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 411 | else if (BTM_BLE_IS_OBS_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 412 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 413 | status = BTM_CMD_STARTED; |
| 414 | btm_ble_stop_observe(); |
| 415 | } |
| 416 | else |
| 417 | { |
Satya Calloji | 877123f | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 418 | BTM_TRACE_ERROR("%s Observe not active", __func__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | return status; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 422 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | /******************************************************************************* |
| 426 | ** |
| 427 | ** Function BTM_BleBroadcast |
| 428 | ** |
| 429 | ** Description This function is to start or stop broadcasting. |
| 430 | ** |
| 431 | ** Parameters start: start or stop broadcasting. |
| 432 | ** |
| 433 | ** Returns status. |
| 434 | ** |
| 435 | *******************************************************************************/ |
| 436 | tBTM_STATUS BTM_BleBroadcast(BOOLEAN start) |
| 437 | { |
| 438 | tBTM_STATUS status = BTM_NO_RESOURCES; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 439 | tBTM_LE_RANDOM_CB *p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 440 | tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 441 | UINT8 evt_type = p_cb->scan_rsp ? BTM_BLE_DISCOVER_EVT: BTM_BLE_NON_CONNECT_EVT; |
| 442 | |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 443 | if (!controller_get_interface()->supports_ble()) |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 444 | return BTM_ILLEGAL_VALUE; |
| 445 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 446 | #ifdef BTM_BLE_PC_ADV_TEST_MODE |
| 447 | if (BTM_BLE_PC_ADV_TEST_MODE) |
| 448 | { |
| 449 | evt_type = p_cb->scan_rsp ? BTM_BLE_CONNECT_EVT: BTM_BLE_NON_CONNECT_EVT; |
| 450 | } |
| 451 | #endif |
| 452 | |
| 453 | if (start && p_cb->adv_mode == BTM_BLE_ADV_DISABLE) |
| 454 | { |
| 455 | /* update adv params */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 456 | if (!btsnd_hcic_ble_write_adv_params ((UINT16)(p_cb->adv_interval_min ? p_cb->adv_interval_min : |
| 457 | BTM_BLE_GAP_ADV_INT), |
| 458 | (UINT16)(p_cb->adv_interval_max ? p_cb->adv_interval_max : |
| 459 | BTM_BLE_GAP_ADV_INT), |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 460 | evt_type, |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 461 | p_addr_cb->own_addr_type, |
| 462 | p_cb->direct_bda.type, |
| 463 | p_cb->direct_bda.bda, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 464 | p_cb->adv_chnl_map, |
| 465 | p_cb->afp)) |
| 466 | |
| 467 | status = BTM_NO_RESOURCES; |
| 468 | else |
| 469 | p_cb->evt_type = evt_type; |
| 470 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 471 | status = btm_ble_start_adv (); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 472 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 473 | else if (!start) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 474 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 475 | status = btm_ble_stop_adv(); |
Andre Eisenbach | a9c5301 | 2015-05-20 23:55:13 -0700 | [diff] [blame] | 476 | #if BLE_PRIVACY_SPT == TRUE |
Satya Calloji | 877123f | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 477 | btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, TRUE); |
Andre Eisenbach | a9c5301 | 2015-05-20 23:55:13 -0700 | [diff] [blame] | 478 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 479 | } |
| 480 | else |
| 481 | { |
| 482 | status = BTM_WRONG_MODE; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 483 | BTM_TRACE_ERROR("Can not %s Broadcast, device %s in Broadcast mode", |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 484 | (start ? "Start" : "Stop"), (start ? "already" :"not")); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 485 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 486 | return status; |
| 487 | } |
| 488 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 489 | /******************************************************************************* |
| 490 | ** |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 491 | ** Function btm_vsc_brcm_features_complete |
| 492 | ** |
| 493 | ** Description Command Complete callback for HCI_BLE_VENDOR_CAP_OCF |
| 494 | ** |
| 495 | ** Returns void |
| 496 | ** |
| 497 | *******************************************************************************/ |
| 498 | static void btm_ble_vendor_capability_vsc_cmpl_cback (tBTM_VSC_CMPL *p_vcs_cplt_params) |
| 499 | { |
Satya Calloji | 5725fc6 | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 500 | #if BLE_VND_INCLUDED == TRUE |
| 501 | UINT8 status = 0xFF; |
| 502 | UINT8 *p; |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 503 | |
Satya Calloji | 5725fc6 | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 504 | BTM_TRACE_DEBUG("%s", __func__); |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 505 | |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 506 | /* Check status of command complete event */ |
Satya Calloji | 5725fc6 | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 507 | if ((p_vcs_cplt_params->opcode == HCI_BLE_VENDOR_CAP_OCF) && |
| 508 | (p_vcs_cplt_params->param_len > 0)) |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 509 | { |
| 510 | p = p_vcs_cplt_params->p_param_buf; |
Satya Calloji | 5725fc6 | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 511 | STREAM_TO_UINT8(status, p); |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 512 | } |
| 513 | |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 514 | if (status == HCI_SUCCESS) |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 515 | { |
Satya Calloji | 5725fc6 | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 516 | STREAM_TO_UINT8(btm_cb.cmn_ble_vsc_cb.adv_inst_max, p); |
| 517 | STREAM_TO_UINT8(btm_cb.cmn_ble_vsc_cb.rpa_offloading, p); |
| 518 | STREAM_TO_UINT16(btm_cb.cmn_ble_vsc_cb.tot_scan_results_strg, p); |
| 519 | STREAM_TO_UINT8(btm_cb.cmn_ble_vsc_cb.max_irk_list_sz, p); |
| 520 | STREAM_TO_UINT8(btm_cb.cmn_ble_vsc_cb.filter_support, p); |
| 521 | STREAM_TO_UINT8(btm_cb.cmn_ble_vsc_cb.max_filter, p); |
| 522 | STREAM_TO_UINT8(btm_cb.cmn_ble_vsc_cb.energy_support, p); |
Satya Calloji | f538707 | 2015-02-09 17:40:52 -0800 | [diff] [blame] | 523 | |
Satya Calloji | 5725fc6 | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 524 | if (p_vcs_cplt_params->param_len > BTM_VSC_CHIP_CAPABILITY_RSP_LEN_L_RELEASE) |
Satya Calloji | f538707 | 2015-02-09 17:40:52 -0800 | [diff] [blame] | 525 | { |
Satya Calloji | 5725fc6 | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 526 | STREAM_TO_UINT16(btm_cb.cmn_ble_vsc_cb.version_supported, p); |
| 527 | } |
| 528 | else |
| 529 | { |
| 530 | btm_cb.cmn_ble_vsc_cb.version_supported = BTM_VSC_CHIP_CAPABILITY_L_VERSION; |
| 531 | } |
| 532 | |
Satya Calloji | b151a43 | 2015-05-07 14:06:37 -0700 | [diff] [blame] | 533 | if (btm_cb.cmn_ble_vsc_cb.version_supported == BTM_VSC_CHIP_CAPABILITY_M_VERSION) |
Satya Calloji | 5725fc6 | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 534 | { |
| 535 | STREAM_TO_UINT16(btm_cb.cmn_ble_vsc_cb.total_trackable_advertisers, p); |
| 536 | STREAM_TO_UINT16(btm_cb.cmn_ble_vsc_cb.extended_scan_support, p); |
| 537 | STREAM_TO_UINT16(btm_cb.cmn_ble_vsc_cb.debug_logging_supported, p); |
Satya Calloji | f538707 | 2015-02-09 17:40:52 -0800 | [diff] [blame] | 538 | } |
Satya Calloji | 3f24f46 | 2014-09-16 22:44:43 -0700 | [diff] [blame] | 539 | btm_cb.cmn_ble_vsc_cb.values_read = TRUE; |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 540 | } |
Satya Calloji | c4e2596 | 2014-05-10 23:46:24 -0700 | [diff] [blame] | 541 | |
Satya Calloji | b151a43 | 2015-05-07 14:06:37 -0700 | [diff] [blame] | 542 | BTM_TRACE_DEBUG("%s: stat=%d, irk=%d, ADV ins:%d, rpa=%d, ener=%d, ext_scan=%d", |
Satya Calloji | 5725fc6 | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 543 | __func__, status, btm_cb.cmn_ble_vsc_cb.max_irk_list_sz, |
| 544 | btm_cb.cmn_ble_vsc_cb.adv_inst_max, btm_cb.cmn_ble_vsc_cb.rpa_offloading, |
Satya Calloji | b151a43 | 2015-05-07 14:06:37 -0700 | [diff] [blame] | 545 | btm_cb.cmn_ble_vsc_cb.energy_support, btm_cb.cmn_ble_vsc_cb.extended_scan_support); |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 546 | |
| 547 | if (BTM_BleMaxMultiAdvInstanceCount() > 0) |
| 548 | btm_ble_multi_adv_init(); |
| 549 | |
| 550 | if (btm_cb.cmn_ble_vsc_cb.max_filter > 0) |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 551 | btm_ble_adv_filter_init(); |
Satya Calloji | d5aa247 | 2014-09-23 18:27:09 -0700 | [diff] [blame] | 552 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 553 | #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE) |
| 554 | /* VS capability included and non-4.2 device */ |
| 555 | if (btm_cb.cmn_ble_vsc_cb.max_irk_list_sz > 0 && |
| 556 | controller_get_interface()->get_ble_resolving_list_max_size() == 0) |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 557 | btm_ble_resolving_list_init(btm_cb.cmn_ble_vsc_cb.max_irk_list_sz); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 558 | #endif |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 559 | |
| 560 | if (btm_cb.cmn_ble_vsc_cb.tot_scan_results_strg > 0) |
| 561 | btm_ble_batchscan_init(); |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 562 | |
| 563 | if (p_ctrl_le_feature_rd_cmpl_cback != NULL) |
| 564 | p_ctrl_le_feature_rd_cmpl_cback(status); |
Bernhard Rosenkränzer | 104e3f2 | 2014-11-12 21:53:08 +0100 | [diff] [blame] | 565 | #endif |
Satya Calloji | 5725fc6 | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 566 | } |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 567 | |
| 568 | /******************************************************************************* |
| 569 | ** |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 570 | ** Function BTM_BleGetVendorCapabilities |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 571 | ** |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 572 | ** Description This function reads local LE features |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 573 | ** |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 574 | ** Parameters p_cmn_vsc_cb : Locala LE capability structure |
| 575 | ** |
| 576 | ** Returns void |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 577 | ** |
| 578 | *******************************************************************************/ |
June R. Tate-Gans | 24933b5 | 2014-09-24 15:25:02 -0700 | [diff] [blame] | 579 | extern void BTM_BleGetVendorCapabilities(tBTM_BLE_VSC_CB *p_cmn_vsc_cb) |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 580 | { |
Satya Calloji | 1a9247a | 2014-06-05 13:15:15 -0700 | [diff] [blame] | 581 | BTM_TRACE_DEBUG("BTM_BleGetVendorCapabilities"); |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 582 | |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 583 | if (NULL != p_cmn_vsc_cb) |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 584 | { |
| 585 | *p_cmn_vsc_cb = btm_cb.cmn_ble_vsc_cb; |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | /****************************************************************************** |
| 590 | ** |
| 591 | ** Function BTM_BleReadControllerFeatures |
| 592 | ** |
| 593 | ** Description Reads BLE specific controller features |
| 594 | ** |
| 595 | ** Parameters: tBTM_BLE_CTRL_FEATURES_CBACK : Callback to notify when features are read |
| 596 | ** |
| 597 | ** Returns void |
| 598 | ** |
| 599 | *******************************************************************************/ |
June R. Tate-Gans | 24933b5 | 2014-09-24 15:25:02 -0700 | [diff] [blame] | 600 | extern void BTM_BleReadControllerFeatures(tBTM_BLE_CTRL_FEATURES_CBACK *p_vsc_cback) |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 601 | { |
Satya Calloji | 3f24f46 | 2014-09-16 22:44:43 -0700 | [diff] [blame] | 602 | if (TRUE == btm_cb.cmn_ble_vsc_cb.values_read) |
| 603 | return; |
| 604 | |
Satya Calloji | c4e2596 | 2014-05-10 23:46:24 -0700 | [diff] [blame] | 605 | #if BLE_VND_INCLUDED == TRUE |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 606 | BTM_TRACE_DEBUG("BTM_BleReadControllerFeatures"); |
| 607 | |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 608 | p_ctrl_le_feature_rd_cmpl_cback = p_vsc_cback; |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 609 | if ( BTM_VendorSpecificCommand (HCI_BLE_VENDOR_CAP_OCF, |
| 610 | 0, |
| 611 | NULL, |
| 612 | btm_ble_vendor_capability_vsc_cmpl_cback) |
| 613 | != BTM_CMD_STARTED) |
| 614 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 615 | BTM_TRACE_ERROR("LE Get_Vendor Capabilities Command Failed."); |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 616 | } |
Satya Calloji | c4e2596 | 2014-05-10 23:46:24 -0700 | [diff] [blame] | 617 | #else |
| 618 | UNUSED(p_vsc_cback); |
| 619 | #endif |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 620 | return ; |
| 621 | } |
| 622 | |
| 623 | /******************************************************************************* |
| 624 | ** |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 625 | ** Function BTM_BleEnableMixedPrivacyMode |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 626 | ** |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 627 | ** Description This function is called to enabled Mixed mode if privacy 1.2 |
| 628 | ** is applicable in controller. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 629 | ** |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 630 | ** Parameters mixed_on: mixed mode to be used or not. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 631 | ** |
| 632 | ** Returns void |
| 633 | ** |
| 634 | *******************************************************************************/ |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 635 | void BTM_BleEnableMixedPrivacyMode(BOOLEAN mixed_on) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 636 | { |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 637 | |
| 638 | #if BLE_PRIVACY_SPT == TRUE |
| 639 | btm_cb.ble_ctr_cb.mixed_mode = mixed_on; |
| 640 | |
| 641 | /* TODO: send VSC to enabled mixed mode */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 642 | #endif |
| 643 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 644 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 645 | /******************************************************************************* |
| 646 | ** |
| 647 | ** Function BTM_BleConfigPrivacy |
| 648 | ** |
| 649 | ** Description This function is called to enable or disable the privacy in |
| 650 | ** LE channel of the local device. |
| 651 | ** |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 652 | ** Parameters privacy_mode: privacy mode on or off. |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 653 | ** |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 654 | ** Returns BOOLEAN privacy mode set success; otherwise failed. |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 655 | ** |
| 656 | *******************************************************************************/ |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 657 | BOOLEAN BTM_BleConfigPrivacy(BOOLEAN privacy_mode) |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 658 | { |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 659 | #if BLE_PRIVACY_SPT == TRUE |
| 660 | tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 661 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 662 | BTM_TRACE_EVENT ("%s", __func__); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 663 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 664 | /* if LE is not supported, return error */ |
| 665 | if (!controller_get_interface()->supports_ble()) |
| 666 | return FALSE; |
| 667 | |
| 668 | uint8_t addr_resolution = 0; |
| 669 | if(!privacy_mode)/* if privacy disabled, always use public address */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 670 | { |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 671 | p_cb->addr_mgnt_cb.own_addr_type = BLE_ADDR_PUBLIC; |
| 672 | p_cb->privacy_mode = BTM_PRIVACY_NONE; |
| 673 | } |
| 674 | else /* privacy is turned on*/ |
| 675 | { |
| 676 | /* always set host random address, used when privacy 1.1 or priavcy 1.2 is disabled */ |
| 677 | p_cb->addr_mgnt_cb.own_addr_type = BLE_ADDR_RANDOM; |
| 678 | btm_gen_resolvable_private_addr((void *)btm_gen_resolve_paddr_low); |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 679 | |
| 680 | if (BTM_BleMaxMultiAdvInstanceCount() > 0) |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 681 | btm_ble_multi_adv_enb_privacy(privacy_mode); |
| 682 | |
| 683 | /* 4.2 controller only allow privacy 1.2 or mixed mode, resolvable private address in controller */ |
| 684 | if (controller_get_interface()->supports_ble_privacy()) |
| 685 | { |
| 686 | addr_resolution = 1; |
| 687 | /* check vendor specific capability */ |
| 688 | p_cb->privacy_mode = btm_cb.ble_ctr_cb.mixed_mode ? BTM_PRIVACY_MIXED : BTM_PRIVACY_1_2; |
| 689 | } |
| 690 | else /* 4.1/4.0 controller */ |
| 691 | p_cb->privacy_mode = BTM_PRIVACY_1_1; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 692 | } |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 693 | |
| 694 | GAP_BleAttrDBUpdate (GATT_UUID_GAP_CENTRAL_ADDR_RESOL, (tGAP_BLE_ATTR_VALUE *)&addr_resolution); |
| 695 | |
| 696 | return TRUE; |
| 697 | #else |
| 698 | return FALSE; |
| 699 | #endif |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 700 | } |
| 701 | |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 702 | /******************************************************************************* |
| 703 | ** |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 704 | ** Function BTM_BleMaxMultiAdvInstanceCount |
| 705 | ** |
| 706 | ** Description Returns max number of multi adv instances supported by controller |
| 707 | ** |
| 708 | ** Returns Max multi adv instance count |
| 709 | ** |
| 710 | *******************************************************************************/ |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 711 | extern UINT8 BTM_BleMaxMultiAdvInstanceCount(void) |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 712 | { |
Wei Wang | 21015a4 | 2014-10-03 10:58:03 -0700 | [diff] [blame] | 713 | return btm_cb.cmn_ble_vsc_cb.adv_inst_max < BTM_BLE_MULTI_ADV_MAX ? |
| 714 | btm_cb.cmn_ble_vsc_cb.adv_inst_max : BTM_BLE_MULTI_ADV_MAX; |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | #if BLE_PRIVACY_SPT == TRUE |
| 718 | /******************************************************************************* |
| 719 | ** |
Zhihai Xu | 8b35b3f | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 720 | ** Function btm_ble_resolve_random_addr_on_adv |
| 721 | ** |
| 722 | ** Description resolve random address complete callback. |
| 723 | ** |
| 724 | ** Returns void |
| 725 | ** |
| 726 | *******************************************************************************/ |
| 727 | static void btm_ble_resolve_random_addr_on_adv(void * p_rec, void *p) |
| 728 | { |
| 729 | tBTM_SEC_DEV_REC *match_rec = (tBTM_SEC_DEV_REC *) p_rec; |
| 730 | UINT8 addr_type = BLE_ADDR_RANDOM; |
| 731 | BD_ADDR bda; |
| 732 | UINT8 *pp = (UINT8 *)p + 1; |
| 733 | UINT8 evt_type; |
| 734 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 735 | BTM_TRACE_EVENT ("btm_ble_resolve_random_addr_on_adv "); |
Zhihai Xu | 8b35b3f | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 736 | |
| 737 | STREAM_TO_UINT8 (evt_type, pp); |
| 738 | STREAM_TO_UINT8 (addr_type, pp); |
| 739 | STREAM_TO_BDADDR (bda, pp); |
| 740 | |
| 741 | if (match_rec) |
| 742 | { |
Wei Wang | 72833a1 | 2014-10-16 20:26:44 -0700 | [diff] [blame] | 743 | BTM_TRACE_DEBUG("Random match"); |
Zhihai Xu | 8b35b3f | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 744 | match_rec->ble.active_addr_type = BTM_BLE_ADDR_RRA; |
| 745 | memcpy(match_rec->ble.cur_rand_addr, bda, BD_ADDR_LEN); |
| 746 | memcpy(bda, match_rec->bd_addr, BD_ADDR_LEN); |
| 747 | addr_type = match_rec->ble.ble_addr_type; |
| 748 | } |
Zhihai Xu | 8b35b3f | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 749 | |
| 750 | btm_ble_process_adv_pkt_cont(bda, addr_type, evt_type, pp); |
| 751 | |
| 752 | return; |
| 753 | } |
| 754 | #endif |
| 755 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 756 | /******************************************************************************* |
| 757 | ** |
Sharvil Nanavati | 2611263 | 2014-06-07 00:56:14 -0700 | [diff] [blame] | 758 | ** Function BTM_BleLocalPrivacyEnabled |
| 759 | ** |
| 760 | ** Description Checks if local device supports private address |
| 761 | ** |
| 762 | ** Returns Return TRUE if local privacy is enabled else FALSE |
| 763 | ** |
| 764 | *******************************************************************************/ |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 765 | BOOLEAN BTM_BleLocalPrivacyEnabled(void) |
Sharvil Nanavati | 2611263 | 2014-06-07 00:56:14 -0700 | [diff] [blame] | 766 | { |
| 767 | #if BLE_PRIVACY_SPT == TRUE |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 768 | return (btm_cb.ble_ctr_cb.privacy_mode != BTM_PRIVACY_NONE); |
Sharvil Nanavati | 2611263 | 2014-06-07 00:56:14 -0700 | [diff] [blame] | 769 | #else |
| 770 | return false; |
| 771 | #endif |
| 772 | } |
| 773 | |
| 774 | /******************************************************************************* |
| 775 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 776 | ** Function BTM_BleSetBgConnType |
| 777 | ** |
| 778 | ** Description This function is called to set BLE connectable mode for a |
| 779 | ** peripheral device. |
| 780 | ** |
| 781 | ** Parameters bg_conn_type: it can be auto connection, or selective connection. |
| 782 | ** p_select_cback: callback function when selective connection procedure |
| 783 | ** is being used. |
| 784 | ** |
| 785 | ** Returns void |
| 786 | ** |
| 787 | *******************************************************************************/ |
| 788 | BOOLEAN BTM_BleSetBgConnType(tBTM_BLE_CONN_TYPE bg_conn_type, |
| 789 | tBTM_BLE_SEL_CBACK *p_select_cback) |
| 790 | { |
| 791 | BOOLEAN started = TRUE; |
| 792 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 793 | BTM_TRACE_EVENT ("BTM_BleSetBgConnType "); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 794 | if (!controller_get_interface()->supports_ble()) |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 795 | return FALSE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 796 | |
| 797 | if (btm_cb.ble_ctr_cb.bg_conn_type != bg_conn_type) |
| 798 | { |
| 799 | switch (bg_conn_type) |
| 800 | { |
| 801 | case BTM_BLE_CONN_AUTO: |
| 802 | btm_ble_start_auto_conn(TRUE); |
| 803 | break; |
| 804 | |
| 805 | case BTM_BLE_CONN_SELECTIVE: |
| 806 | if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_AUTO) |
| 807 | { |
| 808 | btm_ble_start_auto_conn(FALSE); |
| 809 | } |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 810 | btm_ble_start_select_conn(TRUE, p_select_cback); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 811 | break; |
| 812 | |
| 813 | case BTM_BLE_CONN_NONE: |
| 814 | if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_AUTO) |
| 815 | { |
| 816 | btm_ble_start_auto_conn(FALSE); |
| 817 | } |
| 818 | else if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_SELECTIVE) |
| 819 | { |
| 820 | btm_ble_start_select_conn(FALSE, NULL); |
| 821 | } |
| 822 | started = TRUE; |
| 823 | break; |
| 824 | |
| 825 | default: |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 826 | BTM_TRACE_ERROR("invalid bg connection type : %d ", bg_conn_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 827 | started = FALSE; |
| 828 | break; |
| 829 | } |
| 830 | |
| 831 | if (started) |
| 832 | btm_cb.ble_ctr_cb.bg_conn_type = bg_conn_type; |
| 833 | } |
| 834 | return started; |
| 835 | } |
| 836 | |
| 837 | /******************************************************************************* |
| 838 | ** |
Nitin Arora | 021e17a | 2014-01-29 19:18:39 -0800 | [diff] [blame] | 839 | ** Function BTM_BleClearBgConnDev |
| 840 | ** |
| 841 | ** Description This function is called to clear the whitelist, |
| 842 | ** end any pending whitelist connections, |
| 843 | * and reset the local bg device list. |
| 844 | ** |
| 845 | ** Parameters void |
| 846 | ** |
| 847 | ** Returns void |
| 848 | ** |
| 849 | *******************************************************************************/ |
| 850 | void BTM_BleClearBgConnDev(void) |
| 851 | { |
| 852 | btm_ble_start_auto_conn(FALSE); |
| 853 | btm_ble_clear_white_list(); |
| 854 | gatt_reset_bgdev_list(); |
| 855 | } |
| 856 | |
| 857 | /******************************************************************************* |
| 858 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 859 | ** Function BTM_BleUpdateBgConnDev |
| 860 | ** |
| 861 | ** Description This function is called to add or remove a device into/from |
| 862 | ** background connection procedure. The background connection |
| 863 | * procedure is decided by the background connection type, it can be |
| 864 | * auto connection, or selective connection. |
| 865 | ** |
| 866 | ** Parameters add_remove: TRUE to add; FALSE to remove. |
| 867 | ** remote_bda: device address to add/remove. |
| 868 | ** |
| 869 | ** Returns void |
| 870 | ** |
| 871 | *******************************************************************************/ |
| 872 | BOOLEAN BTM_BleUpdateBgConnDev(BOOLEAN add_remove, BD_ADDR remote_bda) |
| 873 | { |
Priti Aghera | b8b3e80 | 2015-04-17 18:11:24 -0700 | [diff] [blame] | 874 | BTM_TRACE_EVENT("%s() add=%d", __func__, add_remove); |
| 875 | return btm_update_dev_to_white_list(add_remove, remote_bda); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | /******************************************************************************* |
| 879 | ** |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 880 | ** Function BTM_BleSetConnectableMode |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 881 | ** |
| 882 | ** Description This function is called to set BLE connectable mode for a |
| 883 | ** peripheral device. |
| 884 | ** |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 885 | ** Parameters conn_mode: directed connectable mode, or non-directed.It can |
| 886 | ** be BTM_BLE_CONNECT_EVT, BTM_BLE_CONNECT_DIR_EVT or |
| 887 | ** BTM_BLE_CONNECT_LO_DUTY_DIR_EVT |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 888 | ** |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 889 | ** Returns BTM_ILLEGAL_VALUE if controller does not support BLE. |
| 890 | ** BTM_SUCCESS is status set successfully; otherwise failure. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 891 | ** |
| 892 | *******************************************************************************/ |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 893 | tBTM_STATUS BTM_BleSetConnectableMode(tBTM_BLE_CONN_MODE connectable_mode) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 894 | { |
| 895 | tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 896 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 897 | BTM_TRACE_EVENT ("%s connectable_mode = %d ", __func__, connectable_mode); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 898 | if (!controller_get_interface()->supports_ble()) |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 899 | return BTM_ILLEGAL_VALUE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 900 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 901 | p_cb->directed_conn = connectable_mode; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 902 | return btm_ble_set_connectability( p_cb->connectable_mode); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | /******************************************************************************* |
| 906 | ** |
| 907 | ** Function btm_set_conn_mode_adv_init_addr |
| 908 | ** |
| 909 | ** Description set initator address type and local address type based on adv |
| 910 | ** mode. |
| 911 | ** |
| 912 | ** |
| 913 | *******************************************************************************/ |
| 914 | static UINT8 btm_set_conn_mode_adv_init_addr(tBTM_BLE_INQ_CB *p_cb, |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 915 | BD_ADDR_PTR p_peer_addr_ptr, |
| 916 | tBLE_ADDR_TYPE *p_peer_addr_type, |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 917 | tBLE_ADDR_TYPE *p_own_addr_type) |
| 918 | { |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 919 | UINT8 evt_type, i = BTM_SEC_MAX_DEVICE_RECORDS; |
| 920 | tBTM_SEC_DEV_REC *p_dev_rec; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 921 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 922 | evt_type = (p_cb->connectable_mode == BTM_BLE_NON_CONNECTABLE) ? \ |
| 923 | ((p_cb->scan_rsp) ? BTM_BLE_DISCOVER_EVT : BTM_BLE_NON_CONNECT_EVT )\ |
| 924 | : BTM_BLE_CONNECT_EVT; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 925 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 926 | if (evt_type == BTM_BLE_CONNECT_EVT) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 927 | { |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 928 | evt_type = p_cb->directed_conn; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 929 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 930 | if ( p_cb->directed_conn == BTM_BLE_CONNECT_DIR_EVT || |
| 931 | p_cb->directed_conn == BTM_BLE_CONNECT_LO_DUTY_DIR_EVT) |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 932 | { |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 933 | |
| 934 | #if BLE_PRIVACY_SPT == TRUE |
| 935 | /* for privacy 1.2, convert peer address as static, own address set as ID addr */ |
| 936 | if (btm_cb.ble_ctr_cb.privacy_mode == BTM_PRIVACY_1_2 || |
| 937 | btm_cb.ble_ctr_cb.privacy_mode == BTM_PRIVACY_MIXED) |
| 938 | { |
| 939 | /* only do so for bonded device */ |
| 940 | if ((p_dev_rec = btm_find_or_alloc_dev (p_cb->direct_bda.bda)) != NULL && |
| 941 | p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) |
| 942 | { |
Satya Calloji | 877123f | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 943 | btm_ble_enable_resolving_list(BTM_BLE_RL_ADV); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 944 | memcpy(p_peer_addr_ptr, p_dev_rec->ble.static_addr, BD_ADDR_LEN); |
| 945 | *p_peer_addr_type = p_dev_rec->ble.static_addr_type; |
| 946 | *p_own_addr_type = BLE_ADDR_RANDOM_ID; |
| 947 | return evt_type; |
| 948 | } |
| 949 | /* otherwise fall though as normal directed adv */ |
Satya Calloji | 877123f | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 950 | else |
| 951 | { |
| 952 | btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, TRUE); |
| 953 | } |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 954 | } |
| 955 | #endif |
| 956 | /* direct adv mode does not have privacy, if privacy is not enabled */ |
| 957 | *p_peer_addr_type = p_cb->direct_bda.type; |
| 958 | memcpy(p_peer_addr_ptr, p_cb->direct_bda.bda, BD_ADDR_LEN); |
| 959 | return evt_type; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 960 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 961 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 962 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 963 | /* undirect adv mode or non-connectable mode*/ |
| 964 | #if BLE_PRIVACY_SPT == TRUE |
| 965 | /* when privacy 1.2 privacy only mode is used, or mixed mode */ |
| 966 | if ((btm_cb.ble_ctr_cb.privacy_mode == BTM_PRIVACY_1_2 && p_cb->afp != AP_SCAN_CONN_ALL) || |
| 967 | btm_cb.ble_ctr_cb.privacy_mode == BTM_PRIVACY_MIXED) |
| 968 | { |
| 969 | /* if enhanced privacy is required, set Identity address and matching IRK peer */ |
| 970 | for (i = 0; i < BTM_SEC_MAX_DEVICE_RECORDS; i ++) |
| 971 | { |
| 972 | if ((btm_cb.sec_dev_rec[i].sec_flags & BTM_SEC_IN_USE) != 0 && |
| 973 | (btm_cb.sec_dev_rec[i].ble.in_controller_list & BTM_RESOLVING_LIST_BIT) != 0) |
| 974 | { |
| 975 | memcpy(p_peer_addr_ptr, btm_cb.sec_dev_rec[i].ble.static_addr, BD_ADDR_LEN); |
| 976 | *p_peer_addr_type = btm_cb.sec_dev_rec[i].ble.static_addr_type; |
| 977 | break; |
| 978 | } |
| 979 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 980 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 981 | if (i != BTM_SEC_MAX_DEVICE_RECORDS) |
| 982 | *p_own_addr_type = BLE_ADDR_RANDOM_ID; |
| 983 | else |
| 984 | /* resolving list is empty, not enabled */ |
| 985 | *p_own_addr_type = BLE_ADDR_RANDOM; |
| 986 | } |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 987 | /* privacy 1.1, or privacy 1.2, general discoverable/connectable mode, disable privacy in */ |
| 988 | /* controller fall back to host based privacy */ |
| 989 | else if (btm_cb.ble_ctr_cb.privacy_mode != BTM_PRIVACY_NONE) |
| 990 | { |
| 991 | *p_own_addr_type = BLE_ADDR_RANDOM; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 992 | } |
| 993 | #endif |
| 994 | |
| 995 | /* if no privacy,do not set any peer address,*/ |
| 996 | /* local address type go by global privacy setting */ |
| 997 | return evt_type; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | /******************************************************************************* |
| 1001 | ** |
| 1002 | ** Function BTM_BleSetAdvParams |
| 1003 | ** |
| 1004 | ** Description This function is called to set advertising parameters. |
| 1005 | ** |
| 1006 | ** Parameters adv_int_min: minimum advertising interval |
| 1007 | ** adv_int_max: maximum advertising interval |
| 1008 | ** p_dir_bda: connectable direct initiator's LE device address |
| 1009 | ** chnl_map: advertising channel map. |
| 1010 | ** |
| 1011 | ** Returns void |
| 1012 | ** |
| 1013 | *******************************************************************************/ |
| 1014 | tBTM_STATUS BTM_BleSetAdvParams(UINT16 adv_int_min, UINT16 adv_int_max, |
| 1015 | tBLE_BD_ADDR *p_dir_bda, |
| 1016 | tBTM_BLE_ADV_CHNL_MAP chnl_map) |
| 1017 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1018 | tBTM_LE_RANDOM_CB *p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1019 | tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 1020 | tBTM_STATUS status = BTM_SUCCESS; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1021 | BD_ADDR p_addr_ptr = {0}; |
| 1022 | tBLE_ADDR_TYPE init_addr_type = BLE_ADDR_PUBLIC; |
| 1023 | tBLE_ADDR_TYPE own_addr_type = p_addr_cb->own_addr_type; |
| 1024 | UINT8 adv_mode = p_cb->adv_mode; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1025 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1026 | BTM_TRACE_EVENT ("BTM_BleSetAdvParams"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1027 | |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 1028 | if (!controller_get_interface()->supports_ble()) |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1029 | return BTM_ILLEGAL_VALUE; |
| 1030 | |
Satya Calloji | 5725fc6 | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 1031 | if (!BTM_BLE_ISVALID_PARAM(adv_int_min, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX) || |
| 1032 | !BTM_BLE_ISVALID_PARAM(adv_int_max, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1033 | { |
| 1034 | return BTM_ILLEGAL_VALUE; |
| 1035 | } |
| 1036 | |
| 1037 | p_cb->adv_interval_min = adv_int_min; |
| 1038 | p_cb->adv_interval_max = adv_int_max; |
| 1039 | p_cb->adv_chnl_map = chnl_map; |
| 1040 | |
| 1041 | if (p_dir_bda) |
| 1042 | { |
| 1043 | memcpy(&p_cb->direct_bda, p_dir_bda, sizeof(tBLE_BD_ADDR)); |
| 1044 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1045 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1046 | BTM_TRACE_EVENT ("update params for an active adv"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1047 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1048 | btm_ble_stop_adv(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1049 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1050 | p_cb->evt_type = btm_set_conn_mode_adv_init_addr(p_cb, p_addr_ptr, &init_addr_type, |
| 1051 | &own_addr_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1052 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1053 | /* update adv params */ |
| 1054 | btsnd_hcic_ble_write_adv_params (p_cb->adv_interval_min, |
| 1055 | p_cb->adv_interval_max, |
| 1056 | p_cb->evt_type, |
| 1057 | own_addr_type, |
| 1058 | init_addr_type, |
| 1059 | p_addr_ptr, |
| 1060 | p_cb->adv_chnl_map, |
| 1061 | p_cb->afp); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1062 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1063 | if (adv_mode == BTM_BLE_ADV_ENABLE) |
| 1064 | btm_ble_start_adv(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1065 | |
| 1066 | return status; |
| 1067 | } |
| 1068 | |
| 1069 | /******************************************************************************* |
| 1070 | ** |
| 1071 | ** Function BTM_BleReadAdvParams |
| 1072 | ** |
| 1073 | ** Description This function is called to set advertising parameters. |
| 1074 | ** |
| 1075 | ** Parameters adv_int_min: minimum advertising interval |
| 1076 | ** adv_int_max: maximum advertising interval |
| 1077 | ** p_dir_bda: connectable direct initiator's LE device address |
| 1078 | ** chnl_map: advertising channel map. |
| 1079 | ** |
| 1080 | ** Returns void |
| 1081 | ** |
| 1082 | *******************************************************************************/ |
| 1083 | void BTM_BleReadAdvParams (UINT16 *adv_int_min, UINT16 *adv_int_max, |
| 1084 | tBLE_BD_ADDR *p_dir_bda, tBTM_BLE_ADV_CHNL_MAP *p_chnl_map) |
| 1085 | { |
| 1086 | tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 1087 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1088 | BTM_TRACE_EVENT ("BTM_BleReadAdvParams "); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 1089 | if (!controller_get_interface()->supports_ble()) |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1090 | return ; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1091 | |
| 1092 | *adv_int_min = p_cb->adv_interval_min; |
| 1093 | *adv_int_max = p_cb->adv_interval_max; |
| 1094 | *p_chnl_map = p_cb->adv_chnl_map; |
| 1095 | |
| 1096 | if (p_dir_bda != NULL) |
| 1097 | { |
| 1098 | memcpy(p_dir_bda, &p_cb->direct_bda, sizeof(tBLE_BD_ADDR)); |
| 1099 | } |
| 1100 | } |
| 1101 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1102 | /******************************************************************************* |
| 1103 | ** |
| 1104 | ** Function BTM_BleSetScanParams |
| 1105 | ** |
Satya Calloji | 5725fc6 | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 1106 | ** Description This function is called to set scan parameters. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1107 | ** |
Satya Calloji | 5725fc6 | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 1108 | ** Parameters client_if - Client IF |
| 1109 | ** scan_interval - Scan interval |
| 1110 | ** scan_window - Scan window |
| 1111 | ** scan_mode - Scan mode |
| 1112 | ** scan_setup_status_cback - Scan param setup status callback |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1113 | ** |
| 1114 | ** Returns void |
| 1115 | ** |
| 1116 | *******************************************************************************/ |
Satya Calloji | 5725fc6 | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 1117 | void BTM_BleSetScanParams(tGATT_IF client_if, UINT32 scan_interval, UINT32 scan_window, |
| 1118 | tBLE_SCAN_MODE scan_mode, |
| 1119 | tBLE_SCAN_PARAM_SETUP_CBACK scan_setup_status_cback) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1120 | { |
| 1121 | tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; |
Satya Calloji | 5725fc6 | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 1122 | UINT32 max_scan_interval; |
| 1123 | UINT32 max_scan_window; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1124 | |
Satya Calloji | 5725fc6 | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 1125 | BTM_TRACE_EVENT ("%s", __func__); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 1126 | if (!controller_get_interface()->supports_ble()) |
Satya Calloji | 5725fc6 | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 1127 | return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1128 | |
Satya Calloji | 5725fc6 | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 1129 | /* If not supporting extended scan support, use the older range for checking */ |
| 1130 | if (btm_cb.cmn_ble_vsc_cb.extended_scan_support == 0) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1131 | { |
Satya Calloji | 5725fc6 | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 1132 | max_scan_interval = BTM_BLE_SCAN_INT_MAX; |
| 1133 | max_scan_window = BTM_BLE_SCAN_WIN_MAX; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1134 | } |
| 1135 | else |
| 1136 | { |
Satya Calloji | 5725fc6 | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 1137 | /* If supporting extended scan support, use the new extended range for checking */ |
| 1138 | max_scan_interval = BTM_BLE_EXT_SCAN_INT_MAX; |
| 1139 | max_scan_window = BTM_BLE_EXT_SCAN_WIN_MAX; |
| 1140 | } |
| 1141 | |
| 1142 | if (BTM_BLE_ISVALID_PARAM(scan_interval, BTM_BLE_SCAN_INT_MIN, max_scan_interval) && |
| 1143 | BTM_BLE_ISVALID_PARAM(scan_window, BTM_BLE_SCAN_WIN_MIN, max_scan_window) && |
| 1144 | (scan_mode == BTM_BLE_SCAN_MODE_ACTI || scan_mode == BTM_BLE_SCAN_MODE_PASS)) |
| 1145 | { |
| 1146 | p_cb->scan_type = scan_mode; |
| 1147 | p_cb->scan_interval = scan_interval; |
| 1148 | p_cb->scan_window = scan_window; |
| 1149 | |
| 1150 | if (scan_setup_status_cback != NULL) |
| 1151 | scan_setup_status_cback(client_if, BTM_SUCCESS); |
| 1152 | } |
| 1153 | else |
| 1154 | { |
| 1155 | if (scan_setup_status_cback != NULL) |
| 1156 | scan_setup_status_cback(client_if, BTM_ILLEGAL_VALUE); |
| 1157 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1158 | BTM_TRACE_ERROR("Illegal params: scan_interval = %d scan_window = %d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1159 | scan_interval, scan_window); |
| 1160 | } |
| 1161 | |
| 1162 | } |
| 1163 | |
| 1164 | /******************************************************************************* |
| 1165 | ** |
| 1166 | ** Function BTM_BleWriteScanRsp |
| 1167 | ** |
| 1168 | ** Description This function is called to write LE scan response. |
| 1169 | ** |
| 1170 | ** Parameters: p_scan_rsp: scan response information. |
| 1171 | ** |
| 1172 | ** Returns void |
| 1173 | ** |
| 1174 | *******************************************************************************/ |
| 1175 | tBTM_STATUS BTM_BleWriteScanRsp(tBTM_BLE_AD_MASK data_mask, tBTM_BLE_ADV_DATA *p_data) |
| 1176 | { |
| 1177 | tBTM_STATUS status = BTM_NO_RESOURCES; |
| 1178 | UINT8 rsp_data[BTM_BLE_AD_DATA_LEN], |
| 1179 | *p = rsp_data; |
| 1180 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1181 | BTM_TRACE_EVENT (" BTM_BleWriteScanRsp"); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1182 | |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 1183 | if (!controller_get_interface()->supports_ble()) |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1184 | return BTM_ILLEGAL_VALUE; |
| 1185 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1186 | memset(rsp_data, 0, BTM_BLE_AD_DATA_LEN); |
| 1187 | btm_ble_build_adv_data(&data_mask, &p, p_data); |
| 1188 | |
| 1189 | if (btsnd_hcic_ble_set_scan_rsp_data((UINT8)(p - rsp_data), rsp_data)) |
| 1190 | { |
| 1191 | status = BTM_SUCCESS; |
| 1192 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1193 | if (data_mask != 0) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1194 | btm_cb.ble_ctr_cb.inq_var.scan_rsp = TRUE; |
| 1195 | else |
| 1196 | btm_cb.ble_ctr_cb.inq_var.scan_rsp = FALSE; |
| 1197 | } |
| 1198 | else |
| 1199 | status = BTM_ILLEGAL_VALUE; |
| 1200 | |
| 1201 | return status; |
| 1202 | } |
| 1203 | |
| 1204 | /******************************************************************************* |
| 1205 | ** |
| 1206 | ** Function BTM_BleWriteAdvData |
| 1207 | ** |
| 1208 | ** Description This function is called to write advertising data. |
| 1209 | ** |
| 1210 | ** Parameters: None. |
| 1211 | ** |
| 1212 | ** Returns void |
| 1213 | ** |
| 1214 | *******************************************************************************/ |
| 1215 | tBTM_STATUS BTM_BleWriteAdvData(tBTM_BLE_AD_MASK data_mask, tBTM_BLE_ADV_DATA *p_data) |
| 1216 | { |
| 1217 | tBTM_BLE_LOCAL_ADV_DATA *p_cb_data = &btm_cb.ble_ctr_cb.inq_var.adv_data; |
| 1218 | UINT8 *p; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1219 | tBTM_BLE_AD_MASK mask = data_mask; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1220 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1221 | BTM_TRACE_EVENT ("BTM_BleWriteAdvData "); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1222 | |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 1223 | if (!controller_get_interface()->supports_ble()) |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1224 | return BTM_ILLEGAL_VALUE; |
| 1225 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1226 | memset(p_cb_data, 0, sizeof(tBTM_BLE_LOCAL_ADV_DATA)); |
| 1227 | p = p_cb_data->ad_data; |
| 1228 | p_cb_data->data_mask = data_mask; |
| 1229 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1230 | p_cb_data->p_flags = btm_ble_build_adv_data(&mask, &p, p_data); |
| 1231 | |
| 1232 | p_cb_data->p_pad = p; |
| 1233 | |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1234 | if (mask != 0) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1235 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1236 | BTM_TRACE_ERROR("Partial data write into ADV"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1237 | } |
| 1238 | |
| 1239 | p_cb_data->data_mask &= ~mask; |
| 1240 | |
| 1241 | if (btsnd_hcic_ble_set_adv_data((UINT8)(p_cb_data->p_pad - p_cb_data->ad_data), |
| 1242 | p_cb_data->ad_data)) |
| 1243 | return BTM_SUCCESS; |
| 1244 | else |
| 1245 | return BTM_NO_RESOURCES; |
| 1246 | |
| 1247 | } |
| 1248 | |
| 1249 | /******************************************************************************* |
| 1250 | ** |
| 1251 | ** Function BTM_CheckAdvData |
| 1252 | ** |
| 1253 | ** Description This function is called to get ADV data for a specific type. |
| 1254 | ** |
| 1255 | ** Parameters p_adv - pointer of ADV data |
| 1256 | ** type - finding ADV data type |
| 1257 | ** p_length - return the length of ADV data not including type |
| 1258 | ** |
| 1259 | ** Returns pointer of ADV data |
| 1260 | ** |
| 1261 | *******************************************************************************/ |
| 1262 | UINT8 *BTM_CheckAdvData( UINT8 *p_adv, UINT8 type, UINT8 *p_length) |
| 1263 | { |
| 1264 | UINT8 *p = p_adv; |
| 1265 | UINT8 length; |
| 1266 | UINT8 adv_type; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1267 | BTM_TRACE_API("BTM_CheckAdvData type=0x%02X", type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1268 | |
| 1269 | STREAM_TO_UINT8(length, p); |
| 1270 | |
| 1271 | while ( length && (p - p_adv <= BTM_BLE_CACHE_ADV_DATA_MAX)) |
| 1272 | { |
| 1273 | STREAM_TO_UINT8(adv_type, p); |
| 1274 | |
| 1275 | if ( adv_type == type ) |
| 1276 | { |
| 1277 | /* length doesn't include itself */ |
| 1278 | *p_length = length - 1; /* minus the length of type */ |
| 1279 | return p; |
| 1280 | } |
| 1281 | p += length - 1; /* skip the length of data */ |
| 1282 | STREAM_TO_UINT8(length, p); |
| 1283 | } |
| 1284 | |
| 1285 | *p_length = 0; |
| 1286 | return NULL; |
| 1287 | } |
| 1288 | |
| 1289 | /******************************************************************************* |
| 1290 | ** |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame^] | 1291 | ** Function BTM__BLEReadDiscoverability |
| 1292 | ** |
| 1293 | ** Description This function is called to read the current LE discoverability |
| 1294 | ** mode of the device. |
| 1295 | ** |
| 1296 | ** Returns BTM_BLE_NON_DISCOVERABLE ,BTM_BLE_LIMITED_DISCOVERABLE or |
| 1297 | ** BTM_BLE_GENRAL_DISCOVERABLE |
| 1298 | ** |
| 1299 | *******************************************************************************/ |
| 1300 | UINT16 BTM_BleReadDiscoverability() |
| 1301 | { |
| 1302 | BTM_TRACE_API("%s", __FUNCTION__); |
| 1303 | |
| 1304 | return (btm_cb.ble_ctr_cb.inq_var.discoverable_mode); |
| 1305 | } |
| 1306 | |
| 1307 | /******************************************************************************* |
| 1308 | ** |
| 1309 | ** Function BTM__BLEReadConnectability |
| 1310 | ** |
| 1311 | ** Description This function is called to read the current LE connectibility |
| 1312 | ** mode of the device. |
| 1313 | ** |
| 1314 | ** Returns BTM_BLE_NON_CONNECTABLE or BTM_BLE_CONNECTABLE |
| 1315 | ** |
| 1316 | *******************************************************************************/ |
| 1317 | UINT16 BTM_BleReadConnectability() |
| 1318 | { |
| 1319 | BTM_TRACE_API ("%s", __FUNCTION__); |
| 1320 | |
| 1321 | return (btm_cb.ble_ctr_cb.inq_var.connectable_mode); |
| 1322 | } |
| 1323 | |
| 1324 | /******************************************************************************* |
| 1325 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1326 | ** Function btm_ble_build_adv_data |
| 1327 | ** |
| 1328 | ** Description This function is called build the adv data and rsp data. |
| 1329 | *******************************************************************************/ |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1330 | UINT8 *btm_ble_build_adv_data(tBTM_BLE_AD_MASK *p_data_mask, UINT8 **p_dst, |
| 1331 | tBTM_BLE_ADV_DATA *p_data) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1332 | { |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1333 | UINT32 data_mask = *p_data_mask; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1334 | UINT8 *p = *p_dst, |
| 1335 | *p_flag = NULL; |
| 1336 | UINT16 len = BTM_BLE_AD_DATA_LEN, cp_len = 0; |
| 1337 | UINT8 i = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1338 | tBTM_BLE_PROP_ELEM *p_elem; |
| 1339 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1340 | BTM_TRACE_EVENT (" btm_ble_build_adv_data"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1341 | |
| 1342 | /* build the adv data structure and build the data string */ |
| 1343 | if (data_mask) |
| 1344 | { |
| 1345 | /* flags */ |
| 1346 | if (data_mask & BTM_BLE_AD_BIT_FLAGS) |
| 1347 | { |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1348 | *p++ = MIN_ADV_LENGTH; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1349 | *p++ = BTM_BLE_AD_TYPE_FLAG; |
| 1350 | p_flag = p; |
| 1351 | if (p_data) |
| 1352 | *p++ = p_data->flag; |
| 1353 | else |
| 1354 | *p++ = 0; |
| 1355 | |
| 1356 | len -= 3; |
| 1357 | |
| 1358 | data_mask &= ~BTM_BLE_AD_BIT_FLAGS; |
| 1359 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1360 | /* appearance data */ |
| 1361 | if (len > 3 && data_mask & BTM_BLE_AD_BIT_APPEARANCE) |
| 1362 | { |
| 1363 | *p++ = 3; /* length */ |
| 1364 | *p++ = BTM_BLE_AD_TYPE_APPEARANCE; |
| 1365 | UINT16_TO_STREAM(p, p_data->appearance); |
| 1366 | len -= 4; |
| 1367 | |
| 1368 | data_mask &= ~BTM_BLE_AD_BIT_APPEARANCE; |
| 1369 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1370 | /* device name */ |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1371 | #if BTM_MAX_LOC_BD_NAME_LEN > 0 |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1372 | if (len > MIN_ADV_LENGTH && data_mask & BTM_BLE_AD_BIT_DEV_NAME) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1373 | { |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1374 | if (strlen(btm_cb.cfg.bd_name) > (UINT16)(len - MIN_ADV_LENGTH)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1375 | { |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1376 | *p++ = len - MIN_ADV_LENGTH + 1; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1377 | *p++ = BTM_BLE_AD_TYPE_NAME_SHORT; |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1378 | ARRAY_TO_STREAM(p, btm_cb.cfg.bd_name, len - MIN_ADV_LENGTH); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1379 | } |
| 1380 | else |
| 1381 | { |
| 1382 | cp_len = (UINT16)strlen(btm_cb.cfg.bd_name); |
| 1383 | *p++ = cp_len + 1; |
| 1384 | *p++ = BTM_BLE_AD_TYPE_NAME_CMPL; |
| 1385 | ARRAY_TO_STREAM(p, btm_cb.cfg.bd_name, cp_len); |
| 1386 | } |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1387 | len -= (cp_len + MIN_ADV_LENGTH); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1388 | data_mask &= ~BTM_BLE_AD_BIT_DEV_NAME; |
| 1389 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1390 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1391 | /* manufacturer data */ |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1392 | if (len > MIN_ADV_LENGTH && data_mask & BTM_BLE_AD_BIT_MANU && |
| 1393 | p_data && p_data->p_manu && |
| 1394 | p_data->p_manu->len != 0 && p_data->p_manu->p_val) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1395 | { |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1396 | if (p_data->p_manu->len > (len - MIN_ADV_LENGTH)) |
| 1397 | cp_len = len - MIN_ADV_LENGTH; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1398 | else |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1399 | cp_len = p_data->p_manu->len; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1400 | |
| 1401 | *p++ = cp_len + 1; |
| 1402 | *p++ = BTM_BLE_AD_TYPE_MANU; |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1403 | ARRAY_TO_STREAM(p, p_data->p_manu->p_val, cp_len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1404 | |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1405 | len -= (cp_len + MIN_ADV_LENGTH); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1406 | data_mask &= ~BTM_BLE_AD_BIT_MANU; |
| 1407 | } |
| 1408 | /* TX power */ |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1409 | if (len > MIN_ADV_LENGTH && data_mask & BTM_BLE_AD_BIT_TX_PWR) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1410 | { |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1411 | *p++ = MIN_ADV_LENGTH; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1412 | *p++ = BTM_BLE_AD_TYPE_TX_PWR; |
Satya Calloji | 4a7ad9b | 2014-07-29 15:32:51 -0700 | [diff] [blame] | 1413 | if (p_data->tx_power > BTM_BLE_ADV_TX_POWER_MAX) |
| 1414 | p_data->tx_power = BTM_BLE_ADV_TX_POWER_MAX; |
| 1415 | *p++ = btm_ble_map_adv_tx_power(p_data->tx_power); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1416 | len -= 3; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1417 | data_mask &= ~BTM_BLE_AD_BIT_TX_PWR; |
| 1418 | } |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1419 | /* 16 bits services */ |
| 1420 | if (len > MIN_ADV_LENGTH && data_mask & BTM_BLE_AD_BIT_SERVICE && |
| 1421 | p_data && p_data->p_services && |
| 1422 | p_data->p_services->num_service != 0 && |
| 1423 | p_data->p_services->p_uuid) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1424 | { |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1425 | if (p_data->p_services->num_service * LEN_UUID_16 > (len - MIN_ADV_LENGTH)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1426 | { |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1427 | cp_len = (len - MIN_ADV_LENGTH)/LEN_UUID_16; |
| 1428 | *p ++ = 1 + cp_len * LEN_UUID_16; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1429 | *p++ = BTM_BLE_AD_TYPE_16SRV_PART; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1430 | } |
| 1431 | else |
| 1432 | { |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1433 | cp_len = p_data->p_services->num_service; |
| 1434 | *p++ = 1 + cp_len * LEN_UUID_16; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1435 | *p++ = BTM_BLE_AD_TYPE_16SRV_CMPL; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1436 | } |
| 1437 | for (i = 0; i < cp_len; i ++) |
| 1438 | { |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1439 | UINT16_TO_STREAM(p, *(p_data->p_services->p_uuid + i)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1440 | } |
| 1441 | |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1442 | len -= (cp_len * MIN_ADV_LENGTH + MIN_ADV_LENGTH); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1443 | data_mask &= ~BTM_BLE_AD_BIT_SERVICE; |
| 1444 | } |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1445 | /* 32 bits service uuid */ |
| 1446 | if (len > MIN_ADV_LENGTH && data_mask & BTM_BLE_AD_BIT_SERVICE_32 && |
| 1447 | p_data && p_data->p_service_32b && |
| 1448 | p_data->p_service_32b->num_service != 0 && |
| 1449 | p_data->p_service_32b->p_uuid) |
| 1450 | { |
| 1451 | if ((p_data->p_service_32b->num_service * LEN_UUID_32) > (len - MIN_ADV_LENGTH)) |
| 1452 | { |
| 1453 | cp_len = (len - MIN_ADV_LENGTH)/LEN_UUID_32; |
| 1454 | *p ++ = 1 + cp_len * LEN_UUID_32; |
| 1455 | *p++ = BTM_BLE_AD_TYPE_32SRV_PART; |
| 1456 | } |
| 1457 | else |
| 1458 | { |
| 1459 | cp_len = p_data->p_service_32b->num_service; |
| 1460 | *p++ = 1 + cp_len * LEN_UUID_32; |
| 1461 | *p++ = BTM_BLE_AD_TYPE_32SRV_CMPL; |
| 1462 | } |
| 1463 | for (i = 0; i < cp_len; i ++) |
| 1464 | { |
| 1465 | UINT32_TO_STREAM(p, *(p_data->p_service_32b->p_uuid + i)); |
| 1466 | } |
| 1467 | |
| 1468 | len -= (cp_len * LEN_UUID_32 + MIN_ADV_LENGTH); |
| 1469 | data_mask &= ~BTM_BLE_AD_BIT_SERVICE_32; |
| 1470 | } |
| 1471 | /* 128 bits services */ |
| 1472 | if (len >= (MAX_UUID_SIZE + 2) && data_mask & BTM_BLE_AD_BIT_SERVICE_128 && |
| 1473 | p_data && p_data->p_services_128b) |
| 1474 | { |
| 1475 | *p ++ = 1 + MAX_UUID_SIZE; |
| 1476 | if (!p_data->p_services_128b->list_cmpl) |
| 1477 | *p++ = BTM_BLE_AD_TYPE_128SRV_PART; |
| 1478 | else |
| 1479 | *p++ = BTM_BLE_AD_TYPE_128SRV_CMPL; |
| 1480 | |
| 1481 | ARRAY_TO_STREAM(p, p_data->p_services_128b->uuid128, MAX_UUID_SIZE); |
| 1482 | |
| 1483 | len -= (MAX_UUID_SIZE + MIN_ADV_LENGTH); |
| 1484 | data_mask &= ~BTM_BLE_AD_BIT_SERVICE_128; |
| 1485 | } |
| 1486 | /* 32 bits Service Solicitation UUIDs */ |
| 1487 | if (len > MIN_ADV_LENGTH && data_mask & BTM_BLE_AD_BIT_SERVICE_32SOL && |
| 1488 | p_data && p_data->p_sol_service_32b && |
| 1489 | p_data->p_sol_service_32b->num_service != 0 && |
| 1490 | p_data->p_sol_service_32b->p_uuid) |
| 1491 | { |
| 1492 | if ((p_data->p_sol_service_32b->num_service * LEN_UUID_32) > (len - MIN_ADV_LENGTH)) |
| 1493 | { |
| 1494 | cp_len = (len - MIN_ADV_LENGTH)/LEN_UUID_32; |
| 1495 | *p ++ = 1 + cp_len * LEN_UUID_32; |
| 1496 | } |
| 1497 | else |
| 1498 | { |
| 1499 | cp_len = p_data->p_sol_service_32b->num_service; |
| 1500 | *p++ = 1 + cp_len * LEN_UUID_32; |
| 1501 | } |
| 1502 | |
| 1503 | *p++ = BTM_BLE_AD_TYPE_32SOL_SRV_UUID; |
| 1504 | for (i = 0; i < cp_len; i ++) |
| 1505 | { |
| 1506 | UINT32_TO_STREAM(p, *(p_data->p_sol_service_32b->p_uuid + i)); |
| 1507 | } |
| 1508 | |
| 1509 | len -= (cp_len * LEN_UUID_32 + MIN_ADV_LENGTH); |
| 1510 | data_mask &= ~BTM_BLE_AD_BIT_SERVICE_32SOL; |
| 1511 | } |
| 1512 | /* 128 bits Solicitation services UUID */ |
| 1513 | if (len >= (MAX_UUID_SIZE + MIN_ADV_LENGTH) && data_mask & BTM_BLE_AD_BIT_SERVICE_128SOL && |
| 1514 | p_data && p_data->p_sol_service_128b) |
| 1515 | { |
| 1516 | *p ++ = 1 + MAX_UUID_SIZE; |
| 1517 | *p++ = BTM_BLE_AD_TYPE_128SOL_SRV_UUID; |
| 1518 | ARRAY_TO_STREAM(p, p_data->p_sol_service_128b->uuid128, MAX_UUID_SIZE); |
| 1519 | len -= (MAX_UUID_SIZE + MIN_ADV_LENGTH); |
| 1520 | data_mask &= ~BTM_BLE_AD_BIT_SERVICE_128SOL; |
| 1521 | } |
| 1522 | /* 16bits/32bits/128bits Service Data */ |
| 1523 | if (len > MIN_ADV_LENGTH && data_mask & BTM_BLE_AD_BIT_SERVICE_DATA && |
| 1524 | p_data && p_data->p_service_data->len != 0 && p_data->p_service_data->p_val) |
| 1525 | { |
| 1526 | if (len > (p_data->p_service_data->service_uuid.len + MIN_ADV_LENGTH)) |
| 1527 | { |
| 1528 | if (p_data->p_service_data->len > (len - MIN_ADV_LENGTH)) |
| 1529 | cp_len = len - MIN_ADV_LENGTH- p_data->p_service_data->service_uuid.len; |
| 1530 | else |
| 1531 | cp_len = p_data->p_service_data->len; |
| 1532 | |
| 1533 | *p++ = cp_len + 1 + p_data->p_service_data->service_uuid.len; |
| 1534 | if (p_data->p_service_data->service_uuid.len == LEN_UUID_16) |
| 1535 | { |
| 1536 | *p++ = BTM_BLE_AD_TYPE_SERVICE_DATA; |
| 1537 | UINT16_TO_STREAM(p, p_data->p_service_data->service_uuid.uu.uuid16); |
| 1538 | } |
| 1539 | else if (p_data->p_service_data->service_uuid.len == LEN_UUID_32) |
| 1540 | { |
| 1541 | *p++ = BTM_BLE_AD_TYPE_32SERVICE_DATA; |
| 1542 | UINT32_TO_STREAM(p, p_data->p_service_data->service_uuid.uu.uuid32); |
| 1543 | } |
| 1544 | else |
| 1545 | { |
| 1546 | *p++ = BTM_BLE_AD_TYPE_128SERVICE_DATA; |
| 1547 | ARRAY_TO_STREAM(p, p_data->p_service_data->service_uuid.uu.uuid128, |
| 1548 | LEN_UUID_128); |
| 1549 | } |
| 1550 | |
| 1551 | ARRAY_TO_STREAM(p, p_data->p_service_data->p_val, cp_len); |
| 1552 | |
| 1553 | len -= (cp_len + MIN_ADV_LENGTH + p_data->p_service_data->service_uuid.len); |
| 1554 | data_mask &= ~BTM_BLE_AD_BIT_SERVICE_DATA; |
| 1555 | } |
| 1556 | else |
| 1557 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1558 | BTM_TRACE_WARNING("service data does not fit"); |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1559 | } |
| 1560 | } |
| 1561 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1562 | if (len >= 6 && data_mask & BTM_BLE_AD_BIT_INT_RANGE && |
| 1563 | p_data) |
| 1564 | { |
| 1565 | *p++ = 5; |
| 1566 | *p++ = BTM_BLE_AD_TYPE_INT_RANGE; |
| 1567 | UINT16_TO_STREAM(p, p_data->int_range.low); |
| 1568 | UINT16_TO_STREAM(p, p_data->int_range.hi); |
| 1569 | len -= 6; |
| 1570 | data_mask &= ~BTM_BLE_AD_BIT_INT_RANGE; |
| 1571 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1572 | if (data_mask & BTM_BLE_AD_BIT_PROPRIETARY && p_data && p_data->p_proprietary) |
| 1573 | { |
| 1574 | for (i = 0; i < p_data->p_proprietary->num_elem ; i ++) |
| 1575 | { |
| 1576 | p_elem = p_data->p_proprietary->p_elem + i; |
| 1577 | |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1578 | if (len >= (MIN_ADV_LENGTH + p_elem->len))/* len byte(1) + ATTR type(1) + Uuid len(2) |
| 1579 | + value length */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1580 | { |
| 1581 | *p ++ = p_elem->len + 1; /* Uuid len + value length */ |
| 1582 | *p ++ = p_elem->adv_type; |
| 1583 | ARRAY_TO_STREAM(p, p_elem->p_val, p_elem->len); |
| 1584 | |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1585 | len -= (MIN_ADV_LENGTH + p_elem->len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1586 | } |
| 1587 | else |
| 1588 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1589 | BTM_TRACE_WARNING("data exceed max adv packet length"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1590 | break; |
| 1591 | } |
| 1592 | } |
| 1593 | data_mask &= ~BTM_BLE_AD_BIT_PROPRIETARY; |
| 1594 | } |
| 1595 | } |
| 1596 | |
| 1597 | *p_data_mask = data_mask; |
| 1598 | *p_dst = p; |
| 1599 | |
| 1600 | return p_flag; |
| 1601 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1602 | /******************************************************************************* |
| 1603 | ** |
| 1604 | ** Function btm_ble_select_adv_interval |
| 1605 | ** |
| 1606 | ** Description select adv interval based on device mode |
| 1607 | ** |
| 1608 | ** Returns void |
| 1609 | ** |
| 1610 | *******************************************************************************/ |
| 1611 | void btm_ble_select_adv_interval(tBTM_BLE_INQ_CB *p_cb, UINT8 evt_type, UINT16 *p_adv_int_min, UINT16 *p_adv_int_max) |
| 1612 | { |
| 1613 | if (p_cb->adv_interval_min && p_cb->adv_interval_max) |
| 1614 | { |
| 1615 | *p_adv_int_min = p_cb->adv_interval_min; |
| 1616 | *p_adv_int_max = p_cb->adv_interval_max; |
| 1617 | } |
| 1618 | else |
| 1619 | { |
| 1620 | switch (evt_type) |
| 1621 | { |
| 1622 | case BTM_BLE_CONNECT_EVT: |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1623 | case BTM_BLE_CONNECT_LO_DUTY_DIR_EVT: |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1624 | *p_adv_int_min = *p_adv_int_max = BTM_BLE_GAP_ADV_FAST_INT_1; |
| 1625 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1626 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1627 | case BTM_BLE_NON_CONNECT_EVT: |
| 1628 | case BTM_BLE_DISCOVER_EVT: |
| 1629 | *p_adv_int_min = *p_adv_int_max = BTM_BLE_GAP_ADV_FAST_INT_2; |
| 1630 | break; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1631 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1632 | /* connectable directed event */ |
| 1633 | case BTM_BLE_CONNECT_DIR_EVT: |
| 1634 | *p_adv_int_min = BTM_BLE_GAP_ADV_DIR_MIN_INT; |
| 1635 | *p_adv_int_max = BTM_BLE_GAP_ADV_DIR_MAX_INT; |
| 1636 | break; |
| 1637 | |
| 1638 | default: |
| 1639 | *p_adv_int_min = *p_adv_int_max = BTM_BLE_GAP_ADV_SLOW_INT; |
| 1640 | break; |
| 1641 | } |
| 1642 | } |
| 1643 | return; |
| 1644 | } |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1645 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1646 | /******************************************************************************* |
| 1647 | ** |
Satya Calloji | 7cf7da9 | 2015-02-05 13:12:15 -0800 | [diff] [blame] | 1648 | ** Function btm_ble_update_dmt_flag_bits |
| 1649 | ** |
| 1650 | ** Description Obtain updated adv flag value based on connect and discoverability mode. |
| 1651 | ** Also, setup DMT support value in the flag based on whether the controller |
| 1652 | ** supports both LE and BR/EDR. |
| 1653 | ** |
| 1654 | ** Parameters: flag_value (Input / Output) - flag value |
| 1655 | ** connect_mode (Input) - Connect mode value |
| 1656 | ** disc_mode (Input) - discoverability mode |
| 1657 | ** |
| 1658 | ** Returns void |
| 1659 | ** |
| 1660 | *******************************************************************************/ |
| 1661 | void btm_ble_update_dmt_flag_bits(UINT8 *adv_flag_value, const UINT16 connect_mode, |
| 1662 | const UINT16 disc_mode) |
| 1663 | { |
| 1664 | /* BR/EDR non-discoverable , non-connectable */ |
| 1665 | if ((disc_mode & BTM_DISCOVERABLE_MASK) == 0 && |
| 1666 | (connect_mode & BTM_CONNECTABLE_MASK) == 0) |
| 1667 | *adv_flag_value |= BTM_BLE_BREDR_NOT_SPT; |
| 1668 | else |
| 1669 | *adv_flag_value &= ~BTM_BLE_BREDR_NOT_SPT; |
| 1670 | |
| 1671 | /* if local controller support, mark both controller and host support in flag */ |
| 1672 | if (controller_get_interface()->supports_simultaneous_le_bredr()) |
| 1673 | *adv_flag_value |= (BTM_BLE_DMT_CONTROLLER_SPT|BTM_BLE_DMT_HOST_SPT); |
| 1674 | else |
| 1675 | *adv_flag_value &= ~(BTM_BLE_DMT_CONTROLLER_SPT|BTM_BLE_DMT_HOST_SPT); |
| 1676 | } |
| 1677 | |
| 1678 | /******************************************************************************* |
| 1679 | ** |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1680 | ** Function btm_ble_set_adv_flag |
| 1681 | ** |
| 1682 | ** Description Set adv flag in adv data. |
| 1683 | ** |
Satya Calloji | 7cf7da9 | 2015-02-05 13:12:15 -0800 | [diff] [blame] | 1684 | ** Parameters: connect_mode (Input)- Connect mode value |
| 1685 | ** disc_mode (Input) - discoverability mode |
| 1686 | ** |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1687 | ** Returns void |
| 1688 | ** |
| 1689 | *******************************************************************************/ |
| 1690 | void btm_ble_set_adv_flag(UINT16 connect_mode, UINT16 disc_mode) |
| 1691 | { |
| 1692 | UINT8 flag = 0, old_flag = 0; |
| 1693 | tBTM_BLE_LOCAL_ADV_DATA *p_adv_data = &btm_cb.ble_ctr_cb.inq_var.adv_data; |
| 1694 | |
| 1695 | if (p_adv_data->p_flags != NULL) |
| 1696 | flag = old_flag = *(p_adv_data->p_flags); |
| 1697 | |
Satya Calloji | 7cf7da9 | 2015-02-05 13:12:15 -0800 | [diff] [blame] | 1698 | btm_ble_update_dmt_flag_bits (&flag, connect_mode, disc_mode); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1699 | |
Sharvil Nanavati | 4480276 | 2014-12-23 23:08:58 -0800 | [diff] [blame] | 1700 | LOG_DEBUG("disc_mode %04x", disc_mode); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1701 | /* update discoverable flag */ |
| 1702 | if (disc_mode & BTM_BLE_LIMITED_DISCOVERABLE) |
| 1703 | { |
| 1704 | flag &= ~BTM_BLE_GEN_DISC_FLAG; |
Satya Calloji | 7cf7da9 | 2015-02-05 13:12:15 -0800 | [diff] [blame] | 1705 | flag |= BTM_BLE_LIMIT_DISC_FLAG; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1706 | } |
| 1707 | else if (disc_mode & BTM_BLE_GENERAL_DISCOVERABLE) |
| 1708 | { |
| 1709 | flag |= BTM_BLE_GEN_DISC_FLAG; |
| 1710 | flag &= ~BTM_BLE_LIMIT_DISC_FLAG; |
| 1711 | } |
| 1712 | else /* remove all discoverable flags */ |
| 1713 | { |
| 1714 | flag &= ~(BTM_BLE_LIMIT_DISC_FLAG|BTM_BLE_GEN_DISC_FLAG); |
| 1715 | } |
| 1716 | |
| 1717 | if (flag != old_flag) |
| 1718 | { |
| 1719 | btm_ble_update_adv_flag(flag); |
| 1720 | } |
| 1721 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1722 | /******************************************************************************* |
| 1723 | ** |
| 1724 | ** Function btm_ble_set_discoverability |
| 1725 | ** |
| 1726 | ** Description This function is called to set BLE discoverable mode. |
| 1727 | ** |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1728 | ** Parameters: combined_mode: discoverability mode. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1729 | ** |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1730 | ** Returns BTM_SUCCESS is status set successfully; otherwise failure. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1731 | ** |
| 1732 | *******************************************************************************/ |
| 1733 | tBTM_STATUS btm_ble_set_discoverability(UINT16 combined_mode) |
| 1734 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1735 | tBTM_LE_RANDOM_CB *p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1736 | tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 1737 | UINT16 mode = (combined_mode & BTM_BLE_DISCOVERABLE_MASK); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1738 | UINT8 new_mode = BTM_BLE_ADV_ENABLE; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1739 | UINT8 evt_type; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1740 | tBTM_STATUS status = BTM_SUCCESS; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1741 | BD_ADDR p_addr_ptr= {0}; |
| 1742 | tBLE_ADDR_TYPE init_addr_type = BLE_ADDR_PUBLIC, |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1743 | own_addr_type = p_addr_cb->own_addr_type; |
| 1744 | UINT16 adv_int_min, adv_int_max; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1745 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1746 | BTM_TRACE_EVENT ("%s mode=0x%0x combined_mode=0x%x", __FUNCTION__, mode, combined_mode); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1747 | |
| 1748 | /*** Check mode parameter ***/ |
| 1749 | if (mode > BTM_BLE_MAX_DISCOVERABLE) |
| 1750 | return(BTM_ILLEGAL_VALUE); |
| 1751 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1752 | p_cb->discoverable_mode = mode; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1753 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1754 | evt_type = btm_set_conn_mode_adv_init_addr(p_cb, p_addr_ptr, &init_addr_type, &own_addr_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1755 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1756 | if (p_cb->connectable_mode == BTM_BLE_NON_CONNECTABLE && mode == BTM_BLE_NON_DISCOVERABLE) |
| 1757 | new_mode = BTM_BLE_ADV_DISABLE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1758 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1759 | btm_ble_select_adv_interval(p_cb, evt_type, &adv_int_min, &adv_int_max); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1760 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1761 | btu_stop_timer(&p_cb->fast_adv_timer); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1762 | |
| 1763 | /* update adv params if start advertising */ |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1764 | BTM_TRACE_EVENT ("evt_type=0x%x p-cb->evt_type=0x%x ", evt_type, p_cb->evt_type); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1765 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1766 | if (new_mode == BTM_BLE_ADV_ENABLE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1767 | { |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1768 | btm_ble_set_adv_flag (btm_cb.btm_inq_vars.connectable_mode, combined_mode); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1769 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1770 | if (evt_type != p_cb->evt_type ||p_cb->adv_addr_type != own_addr_type |
| 1771 | || !p_cb->fast_adv_on) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1772 | { |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1773 | btm_ble_stop_adv(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1774 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1775 | /* update adv params */ |
| 1776 | if (!btsnd_hcic_ble_write_adv_params (adv_int_min, |
| 1777 | adv_int_max, |
| 1778 | evt_type, |
| 1779 | own_addr_type, |
| 1780 | init_addr_type, |
| 1781 | p_addr_ptr, |
| 1782 | p_cb->adv_chnl_map, |
| 1783 | p_cb->afp)) |
| 1784 | { |
| 1785 | status = BTM_NO_RESOURCES; |
| 1786 | } |
| 1787 | else |
| 1788 | { |
| 1789 | p_cb->evt_type = evt_type; |
| 1790 | p_cb->adv_addr_type = own_addr_type; |
| 1791 | } |
| 1792 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1793 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1794 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1795 | if (status == BTM_SUCCESS && p_cb->adv_mode != new_mode) |
| 1796 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1797 | if (new_mode == BTM_BLE_ADV_ENABLE) |
| 1798 | status = btm_ble_start_adv(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1799 | else |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1800 | status = btm_ble_stop_adv(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1801 | } |
Satya Calloji | 877123f | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 1802 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1803 | if (p_cb->adv_mode == BTM_BLE_ADV_ENABLE) |
| 1804 | { |
| 1805 | p_cb->fast_adv_on = TRUE; |
| 1806 | /* start initial GAP mode adv timer */ |
| 1807 | btu_start_timer (&p_cb->fast_adv_timer, BTU_TTYPE_BLE_GAP_FAST_ADV, |
| 1808 | BTM_BLE_GAP_FAST_ADV_TOUT); |
| 1809 | } |
Satya Calloji | 877123f | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 1810 | else |
| 1811 | { |
Andre Eisenbach | a9c5301 | 2015-05-20 23:55:13 -0700 | [diff] [blame] | 1812 | #if BLE_PRIVACY_SPT == TRUE |
Satya Calloji | 877123f | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 1813 | btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, TRUE); |
Andre Eisenbach | a9c5301 | 2015-05-20 23:55:13 -0700 | [diff] [blame] | 1814 | #endif |
Satya Calloji | 877123f | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 1815 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1816 | |
| 1817 | /* set up stop advertising timer */ |
| 1818 | if (status == BTM_SUCCESS && mode == BTM_BLE_LIMITED_DISCOVERABLE) |
| 1819 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1820 | BTM_TRACE_EVENT ("start timer for limited disc mode duration=%d (180 secs)", BTM_BLE_GAP_LIM_TOUT); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1821 | /* start Tgap(lim_timeout) */ |
| 1822 | btu_start_timer (&p_cb->inq_timer_ent, BTU_TTYPE_BLE_GAP_LIM_DISC, |
| 1823 | BTM_BLE_GAP_LIM_TOUT); |
| 1824 | } |
| 1825 | return status; |
| 1826 | } |
| 1827 | |
| 1828 | /******************************************************************************* |
| 1829 | ** |
| 1830 | ** Function btm_ble_set_connectability |
| 1831 | ** |
| 1832 | ** Description This function is called to set BLE connectability mode. |
| 1833 | ** |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1834 | ** Parameters: combined_mode: connectability mode. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1835 | ** |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 1836 | ** Returns BTM_SUCCESS is status set successfully; otherwise failure. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1837 | ** |
| 1838 | *******************************************************************************/ |
| 1839 | tBTM_STATUS btm_ble_set_connectability(UINT16 combined_mode) |
| 1840 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1841 | tBTM_LE_RANDOM_CB *p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1842 | tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 1843 | UINT16 mode = (combined_mode & BTM_BLE_CONNECTABLE_MASK); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1844 | UINT8 new_mode = BTM_BLE_ADV_ENABLE; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1845 | UINT8 evt_type; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1846 | tBTM_STATUS status = BTM_SUCCESS; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1847 | BD_ADDR p_addr_ptr = {0}; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1848 | tBLE_ADDR_TYPE peer_addr_type = BLE_ADDR_PUBLIC, |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1849 | own_addr_type = p_addr_cb->own_addr_type; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1850 | UINT16 adv_int_min, adv_int_max; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1851 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1852 | BTM_TRACE_EVENT ("%s mode=0x%0x combined_mode=0x%x", __FUNCTION__, mode, combined_mode); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1853 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1854 | /*** Check mode parameter ***/ |
| 1855 | if (mode > BTM_BLE_MAX_CONNECTABLE) |
| 1856 | return(BTM_ILLEGAL_VALUE); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1857 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1858 | p_cb->connectable_mode = mode; |
| 1859 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1860 | evt_type = btm_set_conn_mode_adv_init_addr(p_cb, p_addr_ptr, &peer_addr_type, &own_addr_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1861 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1862 | if (mode == BTM_BLE_NON_CONNECTABLE && p_cb->discoverable_mode == BTM_BLE_NON_DISCOVERABLE) |
| 1863 | new_mode = BTM_BLE_ADV_DISABLE; |
| 1864 | |
| 1865 | btm_ble_select_adv_interval(p_cb, evt_type, &adv_int_min, &adv_int_max); |
| 1866 | |
| 1867 | btu_stop_timer(&p_cb->fast_adv_timer); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1868 | /* update adv params if needed */ |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1869 | if (new_mode == BTM_BLE_ADV_ENABLE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1870 | { |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1871 | btm_ble_set_adv_flag (combined_mode, btm_cb.btm_inq_vars.discoverable_mode); |
| 1872 | if (p_cb->evt_type != evt_type || p_cb->adv_addr_type != p_addr_cb->own_addr_type |
| 1873 | || !p_cb->fast_adv_on) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1874 | { |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1875 | btm_ble_stop_adv(); |
| 1876 | |
| 1877 | if (!btsnd_hcic_ble_write_adv_params (adv_int_min, |
| 1878 | adv_int_max, |
| 1879 | evt_type, |
| 1880 | own_addr_type, |
| 1881 | peer_addr_type, |
| 1882 | p_addr_ptr, |
| 1883 | p_cb->adv_chnl_map, |
| 1884 | p_cb->afp)) |
| 1885 | { |
| 1886 | status = BTM_NO_RESOURCES; |
| 1887 | } |
| 1888 | else |
| 1889 | { |
| 1890 | p_cb->evt_type = evt_type; |
| 1891 | p_cb->adv_addr_type = own_addr_type; |
| 1892 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1893 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1894 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1895 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1896 | /* update advertising mode */ |
| 1897 | if (status == BTM_SUCCESS && new_mode != p_cb->adv_mode) |
| 1898 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1899 | if (new_mode == BTM_BLE_ADV_ENABLE) |
| 1900 | status = btm_ble_start_adv(); |
| 1901 | else |
| 1902 | status = btm_ble_stop_adv(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1903 | } |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1904 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1905 | if (p_cb->adv_mode == BTM_BLE_ADV_ENABLE) |
| 1906 | { |
| 1907 | p_cb->fast_adv_on = TRUE; |
| 1908 | /* start initial GAP mode adv timer */ |
| 1909 | btu_start_timer (&p_cb->fast_adv_timer, BTU_TTYPE_BLE_GAP_FAST_ADV, |
| 1910 | BTM_BLE_GAP_FAST_ADV_TOUT); |
| 1911 | } |
Satya Calloji | 877123f | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 1912 | else |
| 1913 | { |
Andre Eisenbach | a9c5301 | 2015-05-20 23:55:13 -0700 | [diff] [blame] | 1914 | #if BLE_PRIVACY_SPT == TRUE |
Satya Calloji | 877123f | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 1915 | btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, TRUE); |
Andre Eisenbach | a9c5301 | 2015-05-20 23:55:13 -0700 | [diff] [blame] | 1916 | #endif |
Satya Calloji | 877123f | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 1917 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1918 | return status; |
| 1919 | } |
| 1920 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1921 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1922 | /******************************************************************************* |
| 1923 | ** |
| 1924 | ** Function btm_ble_start_inquiry |
| 1925 | ** |
| 1926 | ** Description This function is called to start BLE inquiry procedure. |
| 1927 | ** If the duration is zero, the periodic inquiry mode is cancelled. |
| 1928 | ** |
| 1929 | ** Parameters: mode - GENERAL or LIMITED inquiry |
| 1930 | ** p_inq_params - pointer to the BLE inquiry parameter. |
| 1931 | ** p_results_cb - callback returning pointer to results (tBTM_INQ_RESULTS) |
| 1932 | ** p_cmpl_cb - callback indicating the end of an inquiry |
| 1933 | ** |
| 1934 | ** |
| 1935 | ** |
| 1936 | ** Returns BTM_CMD_STARTED if successfully started |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1937 | ** BTM_NO_RESOURCES if could not allocate a message buffer |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1938 | ** BTM_BUSY - if an inquiry is already active |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1939 | ** |
| 1940 | *******************************************************************************/ |
| 1941 | tBTM_STATUS btm_ble_start_inquiry (UINT8 mode, UINT8 duration) |
| 1942 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1943 | tBTM_STATUS status = BTM_CMD_STARTED; |
| 1944 | tBTM_BLE_CB *p_ble_cb = &btm_cb.ble_ctr_cb; |
| 1945 | tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1946 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1947 | BTM_TRACE_DEBUG("btm_ble_start_inquiry: mode = %02x inq_active = 0x%02x", mode, btm_cb.btm_inq_vars.inq_active); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1948 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1949 | /* if selective connection is active, or inquiry is already active, reject it */ |
| 1950 | if (BTM_BLE_IS_INQ_ACTIVE(p_ble_cb->scan_activity) || |
| 1951 | BTM_BLE_IS_SEL_CONN_ACTIVE (p_ble_cb->scan_activity)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1952 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1953 | BTM_TRACE_ERROR("LE Inquiry is active, can not start inquiry"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1954 | return(BTM_BUSY); |
| 1955 | } |
| 1956 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1957 | if (!BTM_BLE_IS_SCAN_ACTIVE(p_ble_cb->scan_activity)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1958 | { |
Nitin Arora | 11e6c29 | 2014-09-29 18:43:27 -0700 | [diff] [blame] | 1959 | btsnd_hcic_ble_set_scan_params(BTM_BLE_SCAN_MODE_ACTI, |
| 1960 | BTM_BLE_LOW_LATENCY_SCAN_INT, |
| 1961 | BTM_BLE_LOW_LATENCY_SCAN_WIN, |
| 1962 | btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, |
| 1963 | SP_ADV_ALL); |
Wei Wang | ed534e3 | 2014-05-20 06:30:13 +0000 | [diff] [blame] | 1964 | #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE) |
Wei Wang | ed534e3 | 2014-05-20 06:30:13 +0000 | [diff] [blame] | 1965 | /* enable IRK list */ |
Satya Calloji | 877123f | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 1966 | btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_SCAN); |
Wei Wang | ed534e3 | 2014-05-20 06:30:13 +0000 | [diff] [blame] | 1967 | #endif |
Satya Calloji | 877123f | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 1968 | p_ble_cb->inq_var.scan_duplicate_filter = BTM_BLE_DUPLICATE_DISABLE; |
| 1969 | status = btm_ble_start_scan(); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1970 | } |
Nitin Arora | 11e6c29 | 2014-09-29 18:43:27 -0700 | [diff] [blame] | 1971 | else if ((p_ble_cb->inq_var.scan_interval != BTM_BLE_LOW_LATENCY_SCAN_INT) || |
| 1972 | (p_ble_cb->inq_var.scan_window != BTM_BLE_LOW_LATENCY_SCAN_WIN)) { |
| 1973 | BTM_TRACE_DEBUG("%s, restart LE scan with low latency scan params", __FUNCTION__); |
| 1974 | btsnd_hcic_ble_set_scan_enable(BTM_BLE_SCAN_DISABLE, BTM_BLE_DUPLICATE_ENABLE); |
| 1975 | btsnd_hcic_ble_set_scan_params(BTM_BLE_SCAN_MODE_ACTI, |
| 1976 | BTM_BLE_LOW_LATENCY_SCAN_INT, |
| 1977 | BTM_BLE_LOW_LATENCY_SCAN_WIN, |
| 1978 | btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, |
| 1979 | SP_ADV_ALL); |
| 1980 | btsnd_hcic_ble_set_scan_enable(BTM_BLE_SCAN_ENABLE, BTM_BLE_DUPLICATE_DISABLE); |
| 1981 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1982 | |
| 1983 | if (status == BTM_CMD_STARTED) |
| 1984 | { |
| 1985 | p_inq->inq_active |= mode; |
| 1986 | p_ble_cb->scan_activity |= mode; |
| 1987 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1988 | BTM_TRACE_DEBUG("btm_ble_start_inquiry inq_active = 0x%02x", p_inq->inq_active); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1989 | |
| 1990 | if (duration != 0) |
| 1991 | { |
| 1992 | /* start inquiry timer */ |
Nitin Arora | 11e6c29 | 2014-09-29 18:43:27 -0700 | [diff] [blame] | 1993 | btu_start_timer (&p_ble_cb->inq_var.inq_timer_ent, BTU_TTYPE_BLE_INQUIRY, duration); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1994 | } |
| 1995 | } |
| 1996 | |
| 1997 | return status; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1998 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | /******************************************************************************* |
| 2002 | ** |
| 2003 | ** Function btm_ble_read_remote_name_cmpl |
| 2004 | ** |
| 2005 | ** Description This function is called when BLE remote name is received. |
| 2006 | ** |
| 2007 | ** Returns void |
| 2008 | ** |
| 2009 | *******************************************************************************/ |
| 2010 | void btm_ble_read_remote_name_cmpl(BOOLEAN status, BD_ADDR bda, UINT16 length, char *p_name) |
| 2011 | { |
| 2012 | UINT8 hci_status = HCI_SUCCESS; |
| 2013 | BD_NAME bd_name; |
| 2014 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2015 | memset(bd_name, 0, (BD_NAME_LEN + 1)); |
Zhihai Xu | 7f9bcf8 | 2014-01-15 15:49:21 -0800 | [diff] [blame] | 2016 | if (length > BD_NAME_LEN) |
| 2017 | { |
| 2018 | length = BD_NAME_LEN; |
| 2019 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2020 | memcpy((UINT8*)bd_name, p_name, length); |
| 2021 | |
| 2022 | if ((!status) || (length==0)) |
| 2023 | { |
| 2024 | hci_status = HCI_ERR_HOST_TIMEOUT; |
| 2025 | } |
| 2026 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2027 | btm_process_remote_name(bda, bd_name, length +1, hci_status); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2028 | btm_sec_rmt_name_request_complete (bda, (UINT8 *)p_name, hci_status); |
| 2029 | } |
| 2030 | |
| 2031 | /******************************************************************************* |
| 2032 | ** |
| 2033 | ** Function btm_ble_read_remote_name |
| 2034 | ** |
| 2035 | ** Description This function read remote LE device name using GATT read |
| 2036 | ** procedure. |
| 2037 | ** |
| 2038 | ** Parameters: None. |
| 2039 | ** |
| 2040 | ** Returns void |
| 2041 | ** |
| 2042 | *******************************************************************************/ |
| 2043 | tBTM_STATUS btm_ble_read_remote_name(BD_ADDR remote_bda, tBTM_INQ_INFO *p_cur, tBTM_CMPL_CB *p_cb) |
| 2044 | { |
| 2045 | tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; |
| 2046 | |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 2047 | if (!controller_get_interface()->supports_ble()) |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 2048 | return BTM_ERR_PROCESSING; |
| 2049 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2050 | if (p_cur && |
| 2051 | p_cur->results.ble_evt_type != BTM_BLE_EVT_CONN_ADV && |
| 2052 | p_cur->results.ble_evt_type != BTM_BLE_EVT_CONN_DIR_ADV) |
| 2053 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2054 | BTM_TRACE_DEBUG("name request to non-connectable device failed."); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2055 | return BTM_ERR_PROCESSING; |
| 2056 | } |
| 2057 | |
| 2058 | /* read remote device name using GATT procedure */ |
| 2059 | if (p_inq->remname_active) |
| 2060 | return BTM_BUSY; |
| 2061 | |
| 2062 | if (!GAP_BleReadPeerDevName(remote_bda, btm_ble_read_remote_name_cmpl)) |
| 2063 | return BTM_BUSY; |
| 2064 | |
| 2065 | p_inq->p_remname_cmpl_cb = p_cb; |
| 2066 | p_inq->remname_active = TRUE; |
| 2067 | |
| 2068 | memcpy(p_inq->remname_bda, remote_bda, BD_ADDR_LEN); |
| 2069 | |
| 2070 | btu_start_timer (&p_inq->rmt_name_timer_ent, |
| 2071 | BTU_TTYPE_BTM_RMT_NAME, |
| 2072 | BTM_EXT_BLE_RMT_NAME_TIMEOUT); |
| 2073 | |
| 2074 | return BTM_CMD_STARTED; |
| 2075 | } |
| 2076 | |
| 2077 | /******************************************************************************* |
| 2078 | ** |
| 2079 | ** Function btm_ble_cancel_remote_name |
| 2080 | ** |
| 2081 | ** Description This function cancel read remote LE device name. |
| 2082 | ** |
| 2083 | ** Parameters: None. |
| 2084 | ** |
| 2085 | ** Returns void |
| 2086 | ** |
| 2087 | *******************************************************************************/ |
| 2088 | BOOLEAN btm_ble_cancel_remote_name(BD_ADDR remote_bda) |
| 2089 | { |
| 2090 | tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; |
| 2091 | BOOLEAN status; |
| 2092 | |
| 2093 | status = GAP_BleCancelReadPeerDevName(remote_bda); |
| 2094 | |
| 2095 | p_inq->remname_active = FALSE; |
| 2096 | memset(p_inq->remname_bda, 0, BD_ADDR_LEN); |
| 2097 | btu_stop_timer(&p_inq->rmt_name_timer_ent); |
| 2098 | |
| 2099 | return status; |
| 2100 | } |
| 2101 | |
| 2102 | /******************************************************************************* |
| 2103 | ** |
| 2104 | ** Function btm_ble_update_adv_flag |
| 2105 | ** |
| 2106 | ** Description This function update the limited discoverable flag in the adv |
| 2107 | ** data. |
| 2108 | ** |
| 2109 | ** Parameters: None. |
| 2110 | ** |
| 2111 | ** Returns void |
| 2112 | ** |
| 2113 | *******************************************************************************/ |
| 2114 | static void btm_ble_update_adv_flag(UINT8 flag) |
| 2115 | { |
| 2116 | tBTM_BLE_LOCAL_ADV_DATA *p_adv_data = &btm_cb.ble_ctr_cb.inq_var.adv_data; |
| 2117 | UINT8 *p; |
| 2118 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2119 | BTM_TRACE_DEBUG ("btm_ble_update_adv_flag new=0x%x", flag); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2120 | |
| 2121 | if (p_adv_data->p_flags != NULL) |
| 2122 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2123 | BTM_TRACE_DEBUG ("btm_ble_update_adv_flag old=0x%x", *p_adv_data->p_flags); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2124 | *p_adv_data->p_flags = flag; |
| 2125 | } |
| 2126 | else /* no FLAGS in ADV data*/ |
| 2127 | { |
| 2128 | p = (p_adv_data->p_pad == NULL) ? p_adv_data->ad_data : p_adv_data->p_pad; |
| 2129 | /* need 3 bytes space to stuff in the flags, if not */ |
| 2130 | /* erase all written data, just for flags */ |
| 2131 | if ((BTM_BLE_AD_DATA_LEN - (p - p_adv_data->ad_data)) < 3) |
| 2132 | { |
| 2133 | p = p_adv_data->p_pad = p_adv_data->ad_data; |
| 2134 | memset(p_adv_data->ad_data, 0, BTM_BLE_AD_DATA_LEN); |
| 2135 | } |
| 2136 | |
| 2137 | *p++ = 2; |
| 2138 | *p++ = BTM_BLE_AD_TYPE_FLAG; |
| 2139 | p_adv_data->p_flags = p; |
| 2140 | *p++ = flag; |
| 2141 | p_adv_data->p_pad = p; |
| 2142 | } |
| 2143 | |
| 2144 | if (btsnd_hcic_ble_set_adv_data((UINT8)(p_adv_data->p_pad - p_adv_data->ad_data), |
| 2145 | p_adv_data->ad_data)) |
| 2146 | p_adv_data->data_mask |= BTM_BLE_AD_BIT_FLAGS; |
| 2147 | |
| 2148 | } |
| 2149 | |
| 2150 | #if 0 |
| 2151 | /******************************************************************************* |
| 2152 | ** |
| 2153 | ** Function btm_ble_parse_adv_data |
| 2154 | ** |
| 2155 | ** Description This function parse the adv data into a structure. |
| 2156 | ** |
| 2157 | ** Returns pointer to entry, or NULL if not found |
| 2158 | ** |
| 2159 | *******************************************************************************/ |
| 2160 | static void btm_ble_parse_adv_data(tBTM_INQ_INFO *p_info, UINT8 *p_data, |
| 2161 | UINT8 len, tBTM_BLE_INQ_DATA *p_adv_data, UINT8 *p_buf) |
| 2162 | { |
| 2163 | UINT8 *p_cur = p_data; |
| 2164 | UINT8 ad_len, ad_type, ad_flag; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2165 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2166 | BTM_TRACE_EVENT (" btm_ble_parse_adv_data"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2167 | |
| 2168 | while (len > 0) |
| 2169 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2170 | BTM_TRACE_DEBUG("btm_ble_parse_adv_data: len = %d", len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2171 | if ((ad_len = *p_cur ++) == 0) |
| 2172 | break; |
| 2173 | |
| 2174 | ad_type = *p_cur ++; |
| 2175 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2176 | BTM_TRACE_DEBUG(" ad_type = %02x ad_len = %d", ad_type, ad_len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2177 | |
| 2178 | switch (ad_type) |
| 2179 | { |
| 2180 | case BTM_BLE_AD_TYPE_NAME_SHORT: |
| 2181 | |
| 2182 | case BTM_BLE_AD_TYPE_NAME_CMPL: |
| 2183 | p_adv_data->ad_mask |= BTM_BLE_AD_BIT_DEV_NAME; |
| 2184 | if (p_info) |
| 2185 | { |
| 2186 | p_info->remote_name_type =(ad_type == BTM_BLE_AD_TYPE_NAME_SHORT) ? |
| 2187 | BTM_BLE_NAME_SHORT: BTM_BLE_NAME_CMPL; |
| 2188 | memcpy(p_info->remote_name, p_cur, ad_len -1); |
| 2189 | p_info->remote_name[ad_len] = 0; |
| 2190 | p_adv_data->p_remote_name = p_info->remote_name; |
| 2191 | p_info->remote_name_len = p_adv_data->remote_name_len = ad_len - 1; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2192 | BTM_TRACE_DEBUG("BTM_BLE_AD_TYPE_NAME name = %s",p_adv_data->p_remote_name); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2193 | } |
| 2194 | p_cur += (ad_len -1); |
| 2195 | |
| 2196 | break; |
| 2197 | |
| 2198 | case BTM_BLE_AD_TYPE_FLAG: |
| 2199 | p_adv_data->ad_mask |= BTM_BLE_AD_BIT_FLAGS; |
| 2200 | ad_flag = *p_cur ++; |
| 2201 | p_adv_data->flag = (UINT8)(ad_flag & BTM_BLE_ADV_FLAG_MASK) ; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2202 | BTM_TRACE_DEBUG("BTM_BLE_AD_TYPE_FLAG flag = %s | %s | %s", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2203 | (p_adv_data->flag & BTM_BLE_LIMIT_DISC_FLAG)? "LE_LIMIT_DISC" : "", |
| 2204 | (p_adv_data->flag & BTM_BLE_GEN_DISC_FLAG)? "LE_GENERAL_DISC" : "", |
| 2205 | (p_adv_data->flag & BTM_BLE_BREDR_NOT_SPT)? "LE Only device" : ""); |
| 2206 | break; |
| 2207 | |
| 2208 | case BTM_BLE_AD_TYPE_TX_PWR: |
| 2209 | p_adv_data->ad_mask |= BTM_BLE_AD_BIT_TX_PWR; |
| 2210 | p_adv_data->tx_power_level = (INT8)*p_cur ++; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2211 | BTM_TRACE_DEBUG("BTM_BLE_AD_TYPE_TX_PWR tx_level = %d", p_adv_data->tx_power_level); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2212 | break; |
| 2213 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2214 | case BTM_BLE_AD_TYPE_MANU: |
| 2215 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2216 | case BTM_BLE_AD_TYPE_16SRV_PART: |
| 2217 | case BTM_BLE_AD_TYPE_16SRV_CMPL: |
| 2218 | p_adv_data->ad_mask |= BTM_BLE_AD_BIT_SERVICE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2219 | /* need allocate memory to store UUID list */ |
| 2220 | p_adv_data->service.num_service = (ad_len - 1)/2; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2221 | BTM_TRACE_DEBUG("service UUID list, num = %d", p_adv_data->service.num_service); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2222 | p_cur += (ad_len - 1); |
| 2223 | break; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2224 | |
| 2225 | case BTM_BLE_AD_TYPE_SOL_SRV_UUID: |
| 2226 | p_adv_data->ad_mask |= BTM_BLE_AD_BIT_SERVICE_SOL; |
| 2227 | /* need allocate memory to store UUID list */ |
| 2228 | p_adv_data->service.num_service = (ad_len - 1)/2; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2229 | BTM_TRACE_DEBUG("service UUID list, num = %d", p_adv_data->service.num_service); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2230 | p_cur += (ad_len - 1); |
| 2231 | break; |
| 2232 | |
| 2233 | case BTM_BLE_AD_TYPE_128SOL_SRV_UUID: |
| 2234 | p_adv_data->ad_mask |= BTM_BLE_AD_BIT_SERVICE_128SOL; |
| 2235 | /* need allocate memory to store UUID list */ |
| 2236 | p_adv_data->service.num_service = (ad_len - 1)/16; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2237 | BTM_TRACE_DEBUG("service UUID list, num = %d", p_adv_data->service.num_service); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2238 | p_cur += (ad_len - 1); |
| 2239 | break; |
| 2240 | |
| 2241 | case BTM_BLE_AD_TYPE_APPEARANCE: |
| 2242 | case BTM_BLE_AD_TYPE_PUBLIC_TARGET: |
| 2243 | case BTM_BLE_AD_TYPE_RANDOM_TARGET: |
| 2244 | default: |
| 2245 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2246 | } |
| 2247 | len -= (ad_len + 1); |
| 2248 | } |
| 2249 | } |
| 2250 | #endif |
| 2251 | |
| 2252 | /******************************************************************************* |
| 2253 | ** |
| 2254 | ** Function btm_ble_cache_adv_data |
| 2255 | ** |
| 2256 | ** Description Update advertising cache data. |
| 2257 | ** |
| 2258 | ** Returns void |
| 2259 | ** |
| 2260 | *******************************************************************************/ |
| 2261 | void btm_ble_cache_adv_data(tBTM_INQ_RESULTS *p_cur, UINT8 data_len, UINT8 *p, UINT8 evt_type) |
| 2262 | { |
| 2263 | tBTM_BLE_INQ_CB *p_le_inq_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 2264 | UINT8 *p_cache; |
| 2265 | UINT8 length; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 2266 | UNUSED(p_cur); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2267 | |
| 2268 | /* cache adv report/scan response data */ |
| 2269 | if (evt_type != BTM_BLE_SCAN_RSP_EVT) |
| 2270 | { |
| 2271 | p_le_inq_cb->adv_len = 0; |
| 2272 | memset(p_le_inq_cb->adv_data_cache, 0, BTM_BLE_CACHE_ADV_DATA_MAX); |
| 2273 | } |
| 2274 | |
| 2275 | if (data_len > 0) |
| 2276 | { |
| 2277 | p_cache = &p_le_inq_cb->adv_data_cache[p_le_inq_cb->adv_len]; |
| 2278 | STREAM_TO_UINT8(length, p); |
| 2279 | while ( length && ((p_le_inq_cb->adv_len + length + 1) <= BTM_BLE_CACHE_ADV_DATA_MAX)) |
| 2280 | { |
| 2281 | /* copy from the length byte & data into cache */ |
| 2282 | memcpy(p_cache, p-1, length+1); |
| 2283 | /* advance the cache pointer past data */ |
| 2284 | p_cache += length+1; |
| 2285 | /* increment cache length */ |
| 2286 | p_le_inq_cb->adv_len += length+1; |
| 2287 | /* skip the length of data */ |
| 2288 | p += length; |
| 2289 | STREAM_TO_UINT8(length, p); |
| 2290 | } |
| 2291 | } |
| 2292 | |
| 2293 | /* parse service UUID from adv packet and save it in inq db eir_uuid */ |
| 2294 | /* TODO */ |
| 2295 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2296 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2297 | /******************************************************************************* |
| 2298 | ** |
| 2299 | ** Function btm_ble_is_discoverable |
| 2300 | ** |
| 2301 | ** Description check ADV flag to make sure device is discoverable and match |
| 2302 | ** the search condition |
| 2303 | ** |
| 2304 | ** Parameters |
| 2305 | ** |
| 2306 | ** Returns void |
| 2307 | ** |
| 2308 | *******************************************************************************/ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2309 | UINT8 btm_ble_is_discoverable(BD_ADDR bda, UINT8 evt_type, UINT8 *p) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2310 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2311 | UINT8 *p_flag, flag = 0, rt = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2312 | UINT8 data_len; |
| 2313 | tBTM_INQ_PARMS *p_cond = &btm_cb.btm_inq_vars.inqparms; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2314 | tBTM_BLE_INQ_CB *p_le_inq_cb = &btm_cb.ble_ctr_cb.inq_var; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2315 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2316 | UNUSED(p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2317 | |
| 2318 | /* for observer, always "discoverable */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2319 | if (BTM_BLE_IS_OBS_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) |
| 2320 | rt |= BTM_BLE_OBS_RESULT; |
| 2321 | |
| 2322 | if (BTM_BLE_IS_SEL_CONN_ACTIVE(btm_cb.ble_ctr_cb.scan_activity) && |
| 2323 | (evt_type == BTM_BLE_CONNECT_EVT || evt_type == BTM_BLE_CONNECT_DIR_EVT)) |
| 2324 | rt |= BTM_BLE_SEL_CONN_RESULT; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2325 | |
| 2326 | /* does not match filter condition */ |
| 2327 | if (p_cond->filter_cond_type == BTM_FILTER_COND_BD_ADDR && |
| 2328 | memcmp(bda, p_cond->filter_cond.bdaddr_cond, BD_ADDR_LEN) != 0) |
| 2329 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2330 | BTM_TRACE_DEBUG("BD ADDR does not meet filter condition"); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2331 | return rt; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2332 | } |
| 2333 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2334 | if (p_le_inq_cb->adv_len != 0) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2335 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2336 | if ((p_flag = BTM_CheckAdvData(p_le_inq_cb->adv_data_cache, |
| 2337 | BTM_BLE_AD_TYPE_FLAG, &data_len)) != NULL) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2338 | { |
| 2339 | flag = * p_flag; |
| 2340 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2341 | if ((btm_cb.btm_inq_vars.inq_active & BTM_BLE_GENERAL_INQUIRY) && |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2342 | (flag & (BTM_BLE_LIMIT_DISC_FLAG|BTM_BLE_GEN_DISC_FLAG)) != 0) |
| 2343 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2344 | BTM_TRACE_DEBUG("Find Generable Discoverable device"); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2345 | rt |= BTM_BLE_INQ_RESULT; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2346 | } |
| 2347 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2348 | else if (btm_cb.btm_inq_vars.inq_active & BTM_BLE_LIMITED_INQUIRY && |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2349 | (flag & BTM_BLE_LIMIT_DISC_FLAG) != 0) |
| 2350 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2351 | BTM_TRACE_DEBUG("Find limited discoverable device"); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2352 | rt |= BTM_BLE_INQ_RESULT; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2353 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2354 | } |
| 2355 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2356 | return rt; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2357 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2358 | |
Adam Hampson | e6c7450 | 2014-05-30 15:07:08 -0700 | [diff] [blame] | 2359 | static void btm_ble_appearance_to_cod(UINT16 appearance, UINT8 *dev_class) |
| 2360 | { |
| 2361 | dev_class[0] = 0; |
| 2362 | |
| 2363 | switch (appearance) |
| 2364 | { |
| 2365 | case BTM_BLE_APPEARANCE_GENERIC_PHONE: |
| 2366 | dev_class[1] = BTM_COD_MAJOR_PHONE; |
| 2367 | dev_class[2] = BTM_COD_MINOR_UNCLASSIFIED; |
| 2368 | break; |
| 2369 | case BTM_BLE_APPEARANCE_GENERIC_COMPUTER: |
| 2370 | dev_class[1] = BTM_COD_MAJOR_COMPUTER; |
| 2371 | dev_class[2] = BTM_COD_MINOR_UNCLASSIFIED; |
| 2372 | break; |
| 2373 | case BTM_BLE_APPEARANCE_GENERIC_REMOTE: |
| 2374 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 2375 | dev_class[2] = BTM_COD_MINOR_REMOTE_CONTROL; |
| 2376 | break; |
| 2377 | case BTM_BLE_APPEARANCE_GENERIC_THERMOMETER: |
| 2378 | case BTM_BLE_APPEARANCE_THERMOMETER_EAR: |
| 2379 | dev_class[1] = BTM_COD_MAJOR_HEALTH; |
| 2380 | dev_class[2] = BTM_COD_MINOR_THERMOMETER; |
| 2381 | break; |
| 2382 | case BTM_BLE_APPEARANCE_GENERIC_HEART_RATE: |
| 2383 | case BTM_BLE_APPEARANCE_HEART_RATE_BELT: |
| 2384 | dev_class[1] = BTM_COD_MAJOR_HEALTH; |
| 2385 | dev_class[2] = BTM_COD_MINOR_HEART_PULSE_MONITOR; |
| 2386 | break; |
| 2387 | case BTM_BLE_APPEARANCE_GENERIC_BLOOD_PRESSURE: |
| 2388 | case BTM_BLE_APPEARANCE_BLOOD_PRESSURE_ARM: |
| 2389 | case BTM_BLE_APPEARANCE_BLOOD_PRESSURE_WRIST: |
| 2390 | dev_class[1] = BTM_COD_MAJOR_HEALTH; |
| 2391 | dev_class[2] = BTM_COD_MINOR_BLOOD_MONITOR; |
| 2392 | break; |
| 2393 | case BTM_BLE_APPEARANCE_GENERIC_PULSE_OXIMETER: |
| 2394 | case BTM_BLE_APPEARANCE_PULSE_OXIMETER_FINGERTIP: |
| 2395 | case BTM_BLE_APPEARANCE_PULSE_OXIMETER_WRIST: |
| 2396 | dev_class[1] = BTM_COD_MAJOR_HEALTH; |
| 2397 | dev_class[2] = BTM_COD_MINOR_PULSE_OXIMETER; |
| 2398 | break; |
| 2399 | case BTM_BLE_APPEARANCE_GENERIC_GLUCOSE: |
| 2400 | dev_class[1] = BTM_COD_MAJOR_HEALTH; |
| 2401 | dev_class[2] = BTM_COD_MINOR_GLUCOSE_METER; |
| 2402 | break; |
| 2403 | case BTM_BLE_APPEARANCE_GENERIC_WEIGHT: |
| 2404 | dev_class[1] = BTM_COD_MAJOR_HEALTH; |
| 2405 | dev_class[2] = BTM_COD_MINOR_WEIGHING_SCALE; |
| 2406 | break; |
| 2407 | case BTM_BLE_APPEARANCE_GENERIC_WALKING: |
| 2408 | case BTM_BLE_APPEARANCE_WALKING_IN_SHOE: |
| 2409 | case BTM_BLE_APPEARANCE_WALKING_ON_SHOE: |
| 2410 | case BTM_BLE_APPEARANCE_WALKING_ON_HIP: |
| 2411 | dev_class[1] = BTM_COD_MAJOR_HEALTH; |
| 2412 | dev_class[2] = BTM_COD_MINOR_STEP_COUNTER; |
| 2413 | break; |
| 2414 | case BTM_BLE_APPEARANCE_GENERIC_WATCH: |
| 2415 | case BTM_BLE_APPEARANCE_SPORTS_WATCH: |
| 2416 | dev_class[1] = BTM_COD_MAJOR_WEARABLE; |
| 2417 | dev_class[2] = BTM_COD_MINOR_WRIST_WATCH; |
| 2418 | break; |
| 2419 | case BTM_BLE_APPEARANCE_GENERIC_EYEGLASSES: |
| 2420 | dev_class[1] = BTM_COD_MAJOR_WEARABLE; |
| 2421 | dev_class[2] = BTM_COD_MINOR_GLASSES; |
| 2422 | break; |
| 2423 | case BTM_BLE_APPEARANCE_GENERIC_DISPLAY: |
| 2424 | dev_class[1] = BTM_COD_MAJOR_IMAGING; |
| 2425 | dev_class[2] = BTM_COD_MINOR_DISPLAY; |
| 2426 | break; |
| 2427 | case BTM_BLE_APPEARANCE_GENERIC_MEDIA_PLAYER: |
| 2428 | dev_class[1] = BTM_COD_MAJOR_AUDIO; |
| 2429 | dev_class[2] = BTM_COD_MINOR_UNCLASSIFIED; |
| 2430 | break; |
| 2431 | case BTM_BLE_APPEARANCE_GENERIC_BARCODE_SCANNER: |
| 2432 | case BTM_BLE_APPEARANCE_HID_BARCODE_SCANNER: |
| 2433 | case BTM_BLE_APPEARANCE_GENERIC_HID: |
| 2434 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 2435 | dev_class[2] = BTM_COD_MINOR_UNCLASSIFIED; |
| 2436 | break; |
| 2437 | case BTM_BLE_APPEARANCE_HID_KEYBOARD: |
| 2438 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 2439 | dev_class[2] = BTM_COD_MINOR_KEYBOARD; |
| 2440 | break; |
| 2441 | case BTM_BLE_APPEARANCE_HID_MOUSE: |
| 2442 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 2443 | dev_class[2] = BTM_COD_MINOR_POINTING; |
| 2444 | break; |
| 2445 | case BTM_BLE_APPEARANCE_HID_JOYSTICK: |
| 2446 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 2447 | dev_class[2] = BTM_COD_MINOR_JOYSTICK; |
| 2448 | break; |
| 2449 | case BTM_BLE_APPEARANCE_HID_GAMEPAD: |
| 2450 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 2451 | dev_class[2] = BTM_COD_MINOR_GAMEPAD; |
| 2452 | break; |
| 2453 | case BTM_BLE_APPEARANCE_HID_DIGITIZER_TABLET: |
| 2454 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 2455 | dev_class[2] = BTM_COD_MINOR_DIGITIZING_TABLET; |
| 2456 | break; |
| 2457 | case BTM_BLE_APPEARANCE_HID_CARD_READER: |
| 2458 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 2459 | dev_class[2] = BTM_COD_MINOR_CARD_READER; |
| 2460 | break; |
| 2461 | case BTM_BLE_APPEARANCE_HID_DIGITAL_PEN: |
| 2462 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 2463 | dev_class[2] = BTM_COD_MINOR_DIGITAL_PAN; |
| 2464 | break; |
| 2465 | case BTM_BLE_APPEARANCE_UKNOWN: |
| 2466 | case BTM_BLE_APPEARANCE_GENERIC_CLOCK: |
| 2467 | case BTM_BLE_APPEARANCE_GENERIC_TAG: |
| 2468 | case BTM_BLE_APPEARANCE_GENERIC_KEYRING: |
| 2469 | case BTM_BLE_APPEARANCE_GENERIC_CYCLING: |
| 2470 | case BTM_BLE_APPEARANCE_CYCLING_COMPUTER: |
| 2471 | case BTM_BLE_APPEARANCE_CYCLING_SPEED: |
| 2472 | case BTM_BLE_APPEARANCE_CYCLING_CADENCE: |
| 2473 | case BTM_BLE_APPEARANCE_CYCLING_POWER: |
| 2474 | case BTM_BLE_APPEARANCE_CYCLING_SPEED_CADENCE: |
| 2475 | case BTM_BLE_APPEARANCE_GENERIC_OUTDOOR_SPORTS: |
| 2476 | case BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION: |
| 2477 | case BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_AND_NAV: |
| 2478 | case BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD: |
| 2479 | case BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD_AND_NAV: |
| 2480 | default: |
| 2481 | dev_class[1] = BTM_COD_MAJOR_UNCLASSIFIED; |
| 2482 | dev_class[2] = BTM_COD_MINOR_UNCLASSIFIED; |
| 2483 | }; |
| 2484 | } |
| 2485 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2486 | /******************************************************************************* |
| 2487 | ** |
| 2488 | ** Function btm_ble_update_inq_result |
| 2489 | ** |
| 2490 | ** Description Update adv packet information into inquiry result. |
| 2491 | ** |
| 2492 | ** Parameters |
| 2493 | ** |
| 2494 | ** Returns void |
| 2495 | ** |
| 2496 | *******************************************************************************/ |
| 2497 | BOOLEAN btm_ble_update_inq_result(tINQ_DB_ENT *p_i, UINT8 addr_type, UINT8 evt_type, UINT8 *p) |
| 2498 | { |
| 2499 | BOOLEAN to_report = TRUE; |
| 2500 | tBTM_INQ_RESULTS *p_cur = &p_i->inq_info.results; |
| 2501 | UINT8 len; |
| 2502 | UINT8 *p_flag; |
| 2503 | tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; |
| 2504 | UINT8 data_len, rssi; |
| 2505 | tBTM_BLE_INQ_CB *p_le_inq_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 2506 | UINT8 *p1; |
Zhihai Xu | 1237ee3 | 2013-11-26 18:18:29 -0800 | [diff] [blame] | 2507 | UINT8 *p_uuid16; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2508 | |
| 2509 | STREAM_TO_UINT8 (data_len, p); |
| 2510 | |
| 2511 | if (data_len > BTM_BLE_ADV_DATA_LEN_MAX) |
| 2512 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2513 | BTM_TRACE_WARNING("EIR data too long %d. discard", data_len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2514 | return FALSE; |
| 2515 | } |
| 2516 | btm_ble_cache_adv_data(p_cur, data_len, p, evt_type); |
| 2517 | |
| 2518 | p1 = (p + data_len); |
| 2519 | STREAM_TO_UINT8 (rssi, p1); |
| 2520 | |
| 2521 | /* Save the info */ |
| 2522 | p_cur->inq_result_type = BTM_INQ_RESULT_BLE; |
| 2523 | p_cur->ble_addr_type = addr_type; |
| 2524 | p_cur->rssi = rssi; |
| 2525 | |
| 2526 | /* active scan, always wait until get scan_rsp to report the result */ |
| 2527 | if ((btm_cb.ble_ctr_cb.inq_var.scan_type == BTM_BLE_SCAN_MODE_ACTI && |
| 2528 | (evt_type == BTM_BLE_CONNECT_EVT || evt_type == BTM_BLE_DISCOVER_EVT))) |
| 2529 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2530 | BTM_TRACE_DEBUG("btm_ble_update_inq_result scan_rsp=false, to_report=false,\ |
Nitin Arora | 0830ad4 | 2014-02-21 18:20:37 -0800 | [diff] [blame] | 2531 | scan_type_active=%d", btm_cb.ble_ctr_cb.inq_var.scan_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2532 | p_i->scan_rsp = FALSE; |
| 2533 | to_report = FALSE; |
| 2534 | } |
| 2535 | else |
| 2536 | p_i->scan_rsp = TRUE; |
| 2537 | |
| 2538 | if (p_i->inq_count != p_inq->inq_counter) |
| 2539 | p_cur->device_type = BT_DEVICE_TYPE_BLE; |
| 2540 | else |
| 2541 | p_cur->device_type |= BT_DEVICE_TYPE_BLE; |
| 2542 | |
| 2543 | if (evt_type != BTM_BLE_SCAN_RSP_EVT) |
| 2544 | p_cur->ble_evt_type = evt_type; |
| 2545 | |
| 2546 | p_i->inq_count = p_inq->inq_counter; /* Mark entry for current inquiry */ |
| 2547 | |
| 2548 | if (p_le_inq_cb->adv_len != 0) |
| 2549 | { |
| 2550 | if ((p_flag = BTM_CheckAdvData(p_le_inq_cb->adv_data_cache, BTM_BLE_AD_TYPE_FLAG, &len)) != NULL) |
| 2551 | p_cur->flag = * p_flag; |
| 2552 | } |
| 2553 | |
Zhihai Xu | 1237ee3 | 2013-11-26 18:18:29 -0800 | [diff] [blame] | 2554 | if (p_le_inq_cb->adv_len != 0) |
| 2555 | { |
Adam Hampson | e6c7450 | 2014-05-30 15:07:08 -0700 | [diff] [blame] | 2556 | /* Check to see the BLE device has the Appearance UUID in the advertising data. If it does |
| 2557 | * then try to convert the appearance value to a class of device value Bluedroid can use. |
| 2558 | * Otherwise fall back to trying to infer if it is a HID device based on the service class. |
| 2559 | */ |
| 2560 | p_uuid16 = BTM_CheckAdvData(p_le_inq_cb->adv_data_cache, BTM_BLE_AD_TYPE_APPEARANCE, &len); |
| 2561 | if (p_uuid16 && len == 2) |
Zhihai Xu | 1237ee3 | 2013-11-26 18:18:29 -0800 | [diff] [blame] | 2562 | { |
Adam Hampson | e6c7450 | 2014-05-30 15:07:08 -0700 | [diff] [blame] | 2563 | btm_ble_appearance_to_cod((UINT16)p_uuid16[0] | (p_uuid16[1] << 8), p_cur->dev_class); |
| 2564 | } |
| 2565 | else |
| 2566 | { |
| 2567 | if ((p_uuid16 = BTM_CheckAdvData(p_le_inq_cb->adv_data_cache, |
| 2568 | BTM_BLE_AD_TYPE_16SRV_CMPL, &len)) != NULL) |
Zhihai Xu | 1237ee3 | 2013-11-26 18:18:29 -0800 | [diff] [blame] | 2569 | { |
Adam Hampson | e6c7450 | 2014-05-30 15:07:08 -0700 | [diff] [blame] | 2570 | UINT8 i; |
| 2571 | for (i = 0; i + 2 <= len; i = i + 2) |
Zhihai Xu | 1237ee3 | 2013-11-26 18:18:29 -0800 | [diff] [blame] | 2572 | { |
Adam Hampson | e6c7450 | 2014-05-30 15:07:08 -0700 | [diff] [blame] | 2573 | /* if this BLE device support HID over LE, set HID Major in class of device */ |
| 2574 | if ((p_uuid16[i] | (p_uuid16[i+1] << 8)) == UUID_SERVCLASS_LE_HID) |
| 2575 | { |
| 2576 | p_cur->dev_class[0] = 0; |
| 2577 | p_cur->dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 2578 | p_cur->dev_class[2] = 0; |
| 2579 | break; |
| 2580 | } |
Zhihai Xu | 1237ee3 | 2013-11-26 18:18:29 -0800 | [diff] [blame] | 2581 | } |
| 2582 | } |
| 2583 | } |
| 2584 | } |
| 2585 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2586 | /* if BR/EDR not supported is not set, assume is a DUMO device */ |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2587 | if ((p_cur->flag & BTM_BLE_BREDR_NOT_SPT) == 0 && |
| 2588 | evt_type != BTM_BLE_CONNECT_DIR_EVT) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2589 | { |
Andre Eisenbach | bf68ac7 | 2013-10-25 16:17:45 -0700 | [diff] [blame] | 2590 | if (p_cur->ble_addr_type != BLE_ADDR_RANDOM) |
| 2591 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2592 | BTM_TRACE_DEBUG("BR/EDR NOT support bit not set, treat as DUMO"); |
Andre Eisenbach | bf68ac7 | 2013-10-25 16:17:45 -0700 | [diff] [blame] | 2593 | p_cur->device_type |= BT_DEVICE_TYPE_DUMO; |
| 2594 | } else { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2595 | BTM_TRACE_DEBUG("Random address, treating device as LE only"); |
Andre Eisenbach | bf68ac7 | 2013-10-25 16:17:45 -0700 | [diff] [blame] | 2596 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2597 | } |
| 2598 | else |
| 2599 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2600 | BTM_TRACE_DEBUG("BR/EDR NOT SUPPORT bit set, LE only device"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2601 | } |
| 2602 | |
| 2603 | return to_report; |
| 2604 | |
| 2605 | } |
| 2606 | |
| 2607 | /******************************************************************************* |
| 2608 | ** |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 2609 | ** Function btm_clear_all_pending_le_entry |
| 2610 | ** |
| 2611 | ** Description This function is called to clear all LE pending entry in |
| 2612 | ** inquiry database. |
| 2613 | ** |
| 2614 | ** Returns void |
| 2615 | ** |
| 2616 | *******************************************************************************/ |
| 2617 | void btm_clear_all_pending_le_entry(void) |
| 2618 | { |
| 2619 | UINT16 xx; |
| 2620 | tINQ_DB_ENT *p_ent = btm_cb.btm_inq_vars.inq_db; |
| 2621 | |
| 2622 | for (xx = 0; xx < BTM_INQ_DB_SIZE; xx++, p_ent++) |
| 2623 | { |
| 2624 | /* mark all pending LE entry as unused if an LE only device has scan response outstanding */ |
| 2625 | if ((p_ent->in_use) && |
| 2626 | (p_ent->inq_info.results.device_type == BT_DEVICE_TYPE_BLE) && |
| 2627 | !p_ent->scan_rsp) |
| 2628 | p_ent->in_use = FALSE; |
| 2629 | } |
| 2630 | } |
| 2631 | |
| 2632 | /******************************************************************************* |
| 2633 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2634 | ** Function btm_send_sel_conn_callback |
| 2635 | ** |
| 2636 | ** Description send selection connection request callback. |
| 2637 | ** |
| 2638 | ** Parameters |
| 2639 | ** |
| 2640 | ** Returns void |
| 2641 | ** |
| 2642 | *******************************************************************************/ |
| 2643 | void btm_send_sel_conn_callback(BD_ADDR remote_bda, UINT8 evt_type, UINT8 *p_data, UINT8 addr_type) |
| 2644 | { |
| 2645 | UINT8 data_len, len; |
| 2646 | UINT8 *p_dev_name, remname[31] = {0}; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 2647 | UNUSED(addr_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2648 | |
| 2649 | if (btm_cb.ble_ctr_cb.p_select_cback == NULL || |
| 2650 | /* non-connectable device */ |
| 2651 | (evt_type != BTM_BLE_EVT_CONN_ADV && evt_type != BTM_BLE_EVT_CONN_DIR_ADV)) |
| 2652 | return; |
| 2653 | |
| 2654 | STREAM_TO_UINT8 (data_len, p_data); |
| 2655 | |
| 2656 | /* get the device name if exist in ADV data */ |
| 2657 | if (data_len != 0) |
| 2658 | { |
| 2659 | p_dev_name = BTM_CheckAdvData(p_data, BTM_BLE_AD_TYPE_NAME_CMPL, &len); |
| 2660 | |
| 2661 | if (p_dev_name == NULL) |
| 2662 | p_dev_name = BTM_CheckAdvData(p_data, BTM_BLE_AD_TYPE_NAME_SHORT, &len); |
| 2663 | |
| 2664 | if (p_dev_name) |
| 2665 | memcpy(remname, p_dev_name, len); |
| 2666 | } |
| 2667 | /* allow connection */ |
| 2668 | if ((* btm_cb.ble_ctr_cb.p_select_cback)(remote_bda, remname)) |
| 2669 | { |
| 2670 | /* terminate selective connection, initiate connection */ |
| 2671 | btm_ble_initiate_select_conn(remote_bda); |
| 2672 | } |
| 2673 | } |
| 2674 | |
| 2675 | /******************************************************************************* |
| 2676 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2677 | ** Function btm_ble_process_adv_pkt |
| 2678 | ** |
| 2679 | ** Description This function is called when adv packet report events are |
| 2680 | ** received from the device. It updates the inquiry database. |
| 2681 | ** If the inquiry database is full, the oldest entry is discarded. |
| 2682 | ** |
| 2683 | ** Parameters |
| 2684 | ** |
| 2685 | ** Returns void |
| 2686 | ** |
| 2687 | *******************************************************************************/ |
| 2688 | void btm_ble_process_adv_pkt (UINT8 *p_data) |
| 2689 | { |
| 2690 | BD_ADDR bda; |
| 2691 | UINT8 evt_type = 0, *p = p_data; |
| 2692 | UINT8 addr_type = 0; |
Adam Hampson | 186cddb | 2014-05-27 10:48:19 -0700 | [diff] [blame] | 2693 | UINT8 num_reports; |
| 2694 | UINT8 data_len; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2695 | #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE) |
Zhihai Xu | 8b35b3f | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 2696 | BOOLEAN match = FALSE; |
| 2697 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2698 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 2699 | /* Only process the results if the inquiry is still active */ |
| 2700 | if (!BTM_BLE_IS_SCAN_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) |
| 2701 | return; |
| 2702 | |
Adam Hampson | 186cddb | 2014-05-27 10:48:19 -0700 | [diff] [blame] | 2703 | /* Extract the number of reports in this event. */ |
| 2704 | STREAM_TO_UINT8(num_reports, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2705 | |
Adam Hampson | 186cddb | 2014-05-27 10:48:19 -0700 | [diff] [blame] | 2706 | while (num_reports--) |
| 2707 | { |
| 2708 | /* Extract inquiry results */ |
| 2709 | STREAM_TO_UINT8 (evt_type, p); |
| 2710 | STREAM_TO_UINT8 (addr_type, p); |
| 2711 | STREAM_TO_BDADDR (bda, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2712 | |
Wei Wang | ed534e3 | 2014-05-20 06:30:13 +0000 | [diff] [blame] | 2713 | #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE) |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 2714 | /* map address to security record */ |
| 2715 | match = btm_identity_addr_to_random_pseudo(bda, &addr_type, FALSE); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2716 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 2717 | BTM_TRACE_DEBUG("btm_ble_process_adv_pkt:bda= %0x:%0x:%0x:%0x:%0x:%0x", |
Nitin Arora | 0830ad4 | 2014-02-21 18:20:37 -0800 | [diff] [blame] | 2718 | bda[0],bda[1],bda[2],bda[3],bda[4],bda[5]); |
Adam Hampson | 186cddb | 2014-05-27 10:48:19 -0700 | [diff] [blame] | 2719 | /* always do RRA resolution on host */ |
| 2720 | if (!match && BTM_BLE_IS_RESOLVE_BDA(bda)) |
| 2721 | { |
| 2722 | btm_ble_resolve_random_addr(bda, btm_ble_resolve_random_addr_on_adv, p_data); |
| 2723 | } |
| 2724 | else |
Zhihai Xu | 8b35b3f | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 2725 | #endif |
Adam Hampson | 186cddb | 2014-05-27 10:48:19 -0700 | [diff] [blame] | 2726 | btm_ble_process_adv_pkt_cont(bda, addr_type, evt_type, p); |
Adam Hampson | 186cddb | 2014-05-27 10:48:19 -0700 | [diff] [blame] | 2727 | |
| 2728 | STREAM_TO_UINT8(data_len, p); |
| 2729 | |
| 2730 | /* Advance to the next event data_len + rssi byte */ |
| 2731 | p += data_len + 1; |
Zhihai Xu | 8b35b3f | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 2732 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2733 | } |
| 2734 | |
| 2735 | /******************************************************************************* |
| 2736 | ** |
| 2737 | ** Function btm_ble_process_adv_pkt_cont |
| 2738 | ** |
| 2739 | ** Description This function is called after random address resolution is |
| 2740 | ** done, and proceed to process adv packet. |
| 2741 | ** |
| 2742 | ** Parameters |
| 2743 | ** |
| 2744 | ** Returns void |
| 2745 | ** |
| 2746 | *******************************************************************************/ |
| 2747 | static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, UINT8 addr_type, UINT8 evt_type, UINT8 *p) |
| 2748 | { |
| 2749 | tINQ_DB_ENT *p_i; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2750 | tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; |
| 2751 | tBTM_INQ_RESULTS_CB *p_inq_results_cb = p_inq->p_inq_results_cb; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2752 | tBTM_INQ_RESULTS_CB *p_obs_results_cb = btm_cb.ble_ctr_cb.p_obs_results_cb; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2753 | tBTM_BLE_INQ_CB *p_le_inq_cb = &btm_cb.ble_ctr_cb.inq_var; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2754 | BOOLEAN update = TRUE; |
| 2755 | UINT8 result = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2756 | |
| 2757 | p_i = btm_inq_db_find (bda); |
| 2758 | |
| 2759 | /* Check if this address has already been processed for this inquiry */ |
| 2760 | if (btm_inq_find_bdaddr(bda)) |
| 2761 | { |
| 2762 | /* never been report as an LE device */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2763 | if (p_i && |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2764 | (!(p_i->inq_info.results.device_type & BT_DEVICE_TYPE_BLE) || |
| 2765 | /* scan repsonse to be updated */ |
| 2766 | (!p_i->scan_rsp))) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2767 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2768 | update = TRUE; |
| 2769 | } |
| 2770 | else if (BTM_BLE_IS_OBS_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) |
| 2771 | { |
| 2772 | update = FALSE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2773 | } |
| 2774 | else |
| 2775 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2776 | /* if yes, skip it */ |
| 2777 | return; /* assumption: one result per event */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2778 | } |
| 2779 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2780 | /* If existing entry, use that, else get a new one (possibly reusing the oldest) */ |
| 2781 | if (p_i == NULL) |
| 2782 | { |
Nitin Arora | 0830ad4 | 2014-02-21 18:20:37 -0800 | [diff] [blame] | 2783 | if ((p_i = btm_inq_db_new (bda)) != NULL) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2784 | { |
Nitin Arora | 0830ad4 | 2014-02-21 18:20:37 -0800 | [diff] [blame] | 2785 | p_inq->inq_cmpl_info.num_resp++; |
| 2786 | } |
| 2787 | else |
| 2788 | return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2789 | } |
| 2790 | else if (p_i->inq_count != p_inq->inq_counter) /* first time seen in this inquiry */ |
| 2791 | { |
| 2792 | p_inq->inq_cmpl_info.num_resp++; |
| 2793 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2794 | /* update the LE device information in inquiry database */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2795 | if (!btm_ble_update_inq_result(p_i, addr_type, evt_type, p)) |
| 2796 | return; |
| 2797 | |
| 2798 | if ((result = btm_ble_is_discoverable(bda, evt_type, p)) == 0) |
| 2799 | { |
Chris Manton | f802700 | 2015-03-12 09:22:48 -0700 | [diff] [blame] | 2800 | LOG_WARN("%s device is no longer discoverable so discarding advertising packet pkt", |
| 2801 | __func__); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2802 | return; |
| 2803 | } |
| 2804 | if (!update) |
| 2805 | result &= ~BTM_BLE_INQ_RESULT; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2806 | /* If the number of responses found and limited, issue a cancel inquiry */ |
| 2807 | if (p_inq->inqparms.max_resps && |
| 2808 | p_inq->inq_cmpl_info.num_resp == p_inq->inqparms.max_resps) |
| 2809 | { |
| 2810 | /* new device */ |
| 2811 | if (p_i == NULL || |
Chaojing Sun | e280553 | 2015-04-22 13:40:21 -0700 | [diff] [blame] | 2812 | /* assume a DUMO device, BR/EDR inquiry is always active */ |
| 2813 | (p_i && |
| 2814 | (p_i->inq_info.results.device_type & BT_DEVICE_TYPE_BLE) == BT_DEVICE_TYPE_BLE && |
| 2815 | p_i->scan_rsp)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2816 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2817 | BTM_TRACE_WARNING("INQ RES: Extra Response Received...cancelling inquiry.."); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2818 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2819 | /* if is non-periodic inquiry active, cancel now */ |
| 2820 | if ((p_inq->inq_active & BTM_BR_INQ_ACTIVE_MASK) != 0 && |
| 2821 | (p_inq->inq_active & BTM_PERIODIC_INQUIRY_ACTIVE) == 0) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2822 | btsnd_hcic_inq_cancel(); |
| 2823 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2824 | btm_ble_stop_inquiry(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2825 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2826 | btm_acl_update_busy_level (BTM_BLI_INQ_DONE_EVT); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2827 | } |
| 2828 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2829 | /* background connection in selective connection mode */ |
| 2830 | if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_SELECTIVE) |
| 2831 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2832 | if (result & BTM_BLE_SEL_CONN_RESULT) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2833 | btm_send_sel_conn_callback(bda, evt_type, p, addr_type); |
| 2834 | else |
| 2835 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2836 | BTM_TRACE_DEBUG("None LE device, can not initiate selective connection"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2837 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2838 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2839 | else |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2840 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2841 | if (p_inq_results_cb && (result & BTM_BLE_INQ_RESULT)) |
| 2842 | { |
Nitin Arora | 0830ad4 | 2014-02-21 18:20:37 -0800 | [diff] [blame] | 2843 | (p_inq_results_cb)((tBTM_INQ_RESULTS *) &p_i->inq_info.results, p_le_inq_cb->adv_data_cache); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2844 | } |
| 2845 | if (p_obs_results_cb && (result & BTM_BLE_OBS_RESULT)) |
| 2846 | { |
| 2847 | (p_obs_results_cb)((tBTM_INQ_RESULTS *) &p_i->inq_info.results, p_le_inq_cb->adv_data_cache); |
| 2848 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2849 | } |
| 2850 | } |
| 2851 | |
| 2852 | /******************************************************************************* |
| 2853 | ** |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2854 | ** Function btm_ble_start_scan |
| 2855 | ** |
| 2856 | ** Description Start the BLE scan. |
| 2857 | ** |
| 2858 | ** Returns void |
| 2859 | ** |
| 2860 | *******************************************************************************/ |
Satya Calloji | 877123f | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 2861 | tBTM_STATUS btm_ble_start_scan(void) |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2862 | { |
| 2863 | tBTM_BLE_INQ_CB *p_inq = &btm_cb.ble_ctr_cb.inq_var; |
| 2864 | tBTM_STATUS status = BTM_CMD_STARTED; |
| 2865 | |
| 2866 | /* start scan, disable duplicate filtering */ |
Satya Calloji | 877123f | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 2867 | if (!btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_ENABLE, p_inq->scan_duplicate_filter)) |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 2868 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2869 | status = BTM_NO_RESOURCES; |
Mike J. Chen | dab8714 | 2014-07-18 17:40:12 -0700 | [diff] [blame] | 2870 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2871 | else |
| 2872 | { |
| 2873 | if (p_inq->scan_type == BTM_BLE_SCAN_MODE_ACTI) |
| 2874 | btm_ble_set_topology_mask(BTM_BLE_STATE_ACTIVE_SCAN_BIT); |
| 2875 | else |
| 2876 | btm_ble_set_topology_mask(BTM_BLE_STATE_PASSIVE_SCAN_BIT); |
| 2877 | } |
| 2878 | return status; |
| 2879 | } |
| 2880 | |
| 2881 | /******************************************************************************* |
| 2882 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2883 | ** Function btm_ble_stop_scan |
| 2884 | ** |
| 2885 | ** Description Stop the BLE scan. |
| 2886 | ** |
| 2887 | ** Returns void |
| 2888 | ** |
| 2889 | *******************************************************************************/ |
| 2890 | void btm_ble_stop_scan(void) |
| 2891 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2892 | BTM_TRACE_EVENT ("btm_ble_stop_scan "); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2893 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2894 | /* Clear the inquiry callback if set */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2895 | btm_cb.ble_ctr_cb.inq_var.scan_type = BTM_BLE_SCAN_MODE_NONE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2896 | |
| 2897 | /* stop discovery now */ |
| 2898 | btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_DISABLE, BTM_BLE_DUPLICATE_ENABLE); |
| 2899 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2900 | btm_update_scanner_filter_policy(SP_ADV_ALL); |
Mike J. Chen | dab8714 | 2014-07-18 17:40:12 -0700 | [diff] [blame] | 2901 | |
| 2902 | btm_cb.ble_ctr_cb.wl_state &= ~BTM_BLE_WL_SCAN; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2903 | } |
| 2904 | /******************************************************************************* |
| 2905 | ** |
| 2906 | ** Function btm_ble_stop_inquiry |
| 2907 | ** |
| 2908 | ** Description Stop the BLE Inquiry. |
| 2909 | ** |
| 2910 | ** Returns void |
| 2911 | ** |
| 2912 | *******************************************************************************/ |
| 2913 | void btm_ble_stop_inquiry(void) |
| 2914 | { |
| 2915 | tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; |
| 2916 | tBTM_BLE_CB *p_ble_cb = &btm_cb.ble_ctr_cb; |
| 2917 | |
| 2918 | btu_stop_timer (&p_ble_cb->inq_var.inq_timer_ent); |
| 2919 | |
| 2920 | p_ble_cb->scan_activity &= ~BTM_BLE_INQUIRY_MASK; |
| 2921 | |
| 2922 | /* If no more scan activity, stop LE scan now */ |
| 2923 | if (!BTM_BLE_IS_SCAN_ACTIVE(p_ble_cb->scan_activity)) |
| 2924 | btm_ble_stop_scan(); |
Nitin Arora | 11e6c29 | 2014-09-29 18:43:27 -0700 | [diff] [blame] | 2925 | else if((p_ble_cb->inq_var.scan_interval != BTM_BLE_LOW_LATENCY_SCAN_INT) || |
| 2926 | (p_ble_cb->inq_var.scan_window != BTM_BLE_LOW_LATENCY_SCAN_WIN)) |
| 2927 | { |
| 2928 | BTM_TRACE_DEBUG("%s: setting default params for ongoing observe", __FUNCTION__); |
| 2929 | btm_ble_stop_scan(); |
| 2930 | btm_ble_start_scan(); |
| 2931 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2932 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2933 | /* If we have a callback registered for inquiry complete, call it */ |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2934 | BTM_TRACE_DEBUG ("BTM Inq Compl Callback: status 0x%02x, num results %d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2935 | p_inq->inq_cmpl_info.status, p_inq->inq_cmpl_info.num_resp); |
| 2936 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2937 | btm_process_inq_complete(HCI_SUCCESS, (UINT8)(p_inq->inqparms.mode & BTM_BLE_INQUIRY_MASK)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2938 | } |
| 2939 | |
| 2940 | /******************************************************************************* |
| 2941 | ** |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2942 | ** Function btm_ble_stop_observe |
| 2943 | ** |
| 2944 | ** Description Stop the BLE Observe. |
| 2945 | ** |
| 2946 | ** Returns void |
| 2947 | ** |
| 2948 | *******************************************************************************/ |
| 2949 | static void btm_ble_stop_observe(void) |
| 2950 | { |
| 2951 | tBTM_BLE_CB *p_ble_cb = & btm_cb.ble_ctr_cb; |
| 2952 | tBTM_CMPL_CB *p_obs_cb = p_ble_cb->p_obs_cmpl_cb; |
| 2953 | |
| 2954 | btu_stop_timer (&p_ble_cb->obs_timer_ent); |
| 2955 | |
| 2956 | p_ble_cb->scan_activity &= ~BTM_LE_OBSERVE_ACTIVE; |
| 2957 | |
| 2958 | p_ble_cb->p_obs_results_cb = NULL; |
| 2959 | p_ble_cb->p_obs_cmpl_cb = NULL; |
| 2960 | |
| 2961 | if (!BTM_BLE_IS_SCAN_ACTIVE(p_ble_cb->scan_activity)) |
| 2962 | btm_ble_stop_scan(); |
| 2963 | |
| 2964 | if (p_obs_cb) |
| 2965 | (p_obs_cb)((tBTM_INQUIRY_CMPL *) &btm_cb.btm_inq_vars.inq_cmpl_info); |
| 2966 | } |
| 2967 | /******************************************************************************* |
| 2968 | ** |
| 2969 | ** Function btm_ble_adv_states_operation |
| 2970 | ** |
| 2971 | ** Description Set or clear adv states in topology mask |
| 2972 | ** |
| 2973 | ** Returns operation status. TRUE if sucessful, FALSE otherwise. |
| 2974 | ** |
| 2975 | *******************************************************************************/ |
| 2976 | typedef BOOLEAN (BTM_TOPOLOGY_FUNC_PTR)(tBTM_BLE_STATE_MASK); |
| 2977 | static BOOLEAN btm_ble_adv_states_operation(BTM_TOPOLOGY_FUNC_PTR *p_handler, UINT8 adv_evt) |
| 2978 | { |
| 2979 | BOOLEAN rt = FALSE; |
| 2980 | |
| 2981 | switch (adv_evt) |
| 2982 | { |
| 2983 | case BTM_BLE_CONNECT_EVT: |
| 2984 | rt = (*p_handler)(BTM_BLE_STATE_CONN_ADV_BIT); |
| 2985 | break; |
| 2986 | |
| 2987 | case BTM_BLE_NON_CONNECT_EVT: |
| 2988 | rt = (*p_handler) (BTM_BLE_STATE_NON_CONN_ADV_BIT); |
| 2989 | break; |
| 2990 | case BTM_BLE_CONNECT_DIR_EVT: |
| 2991 | rt = (*p_handler) (BTM_BLE_STATE_HI_DUTY_DIR_ADV_BIT); |
| 2992 | break; |
| 2993 | |
| 2994 | case BTM_BLE_DISCOVER_EVT: |
| 2995 | rt = (*p_handler) (BTM_BLE_STATE_SCAN_ADV_BIT); |
| 2996 | break; |
| 2997 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 2998 | case BTM_BLE_CONNECT_LO_DUTY_DIR_EVT: |
| 2999 | rt = (*p_handler) (BTM_BLE_STATE_LO_DUTY_DIR_ADV_BIT); |
| 3000 | break; |
| 3001 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3002 | default: |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 3003 | BTM_TRACE_ERROR("unknown adv event : %d", adv_evt); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3004 | break; |
| 3005 | } |
| 3006 | |
| 3007 | return rt; |
| 3008 | } |
| 3009 | |
| 3010 | |
| 3011 | /******************************************************************************* |
| 3012 | ** |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3013 | ** Function btm_ble_start_adv |
| 3014 | ** |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3015 | ** Description start the BLE advertising. |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3016 | ** |
| 3017 | ** Returns void |
| 3018 | ** |
| 3019 | *******************************************************************************/ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3020 | tBTM_STATUS btm_ble_start_adv(void) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3021 | { |
| 3022 | tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 3023 | tBTM_STATUS rt = BTM_NO_RESOURCES; |
| 3024 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3025 | if (!btm_ble_adv_states_operation (btm_ble_topology_check, p_cb->evt_type)) |
| 3026 | return BTM_WRONG_MODE; |
| 3027 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 3028 | #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE) |
Satya Calloji | 877123f | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 3029 | /* To relax resolving list, always have resolving list enabled, unless directed adv */ |
| 3030 | if (p_cb->evt_type != BTM_BLE_CONNECT_LO_DUTY_DIR_EVT && |
| 3031 | p_cb->evt_type != BTM_BLE_CONNECT_DIR_EVT) |
| 3032 | /* enable resolving list is desired */ |
| 3033 | btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_ADV); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 3034 | #endif |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3035 | if (p_cb->afp != AP_SCAN_CONN_ALL) |
| 3036 | { |
| 3037 | btm_execute_wl_dev_operation(); |
| 3038 | btm_cb.ble_ctr_cb.wl_state |= BTM_BLE_WL_ADV; |
| 3039 | } |
| 3040 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3041 | if (btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_ENABLE)) |
| 3042 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3043 | p_cb->adv_mode = BTM_BLE_ADV_ENABLE; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 3044 | btm_ble_adv_states_operation(btm_ble_set_topology_mask, p_cb->evt_type); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3045 | rt = BTM_SUCCESS; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3046 | } |
| 3047 | else |
| 3048 | { |
| 3049 | p_cb->adv_mode = BTM_BLE_ADV_DISABLE; |
| 3050 | btm_cb.ble_ctr_cb.wl_state &= ~BTM_BLE_WL_ADV; |
| 3051 | } |
| 3052 | return rt; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3053 | } |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 3054 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3055 | /******************************************************************************* |
| 3056 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3057 | ** Function btm_ble_stop_adv |
| 3058 | ** |
| 3059 | ** Description Stop the BLE advertising. |
| 3060 | ** |
| 3061 | ** Returns void |
| 3062 | ** |
| 3063 | *******************************************************************************/ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3064 | tBTM_STATUS btm_ble_stop_adv(void) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3065 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3066 | tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 3067 | tBTM_STATUS rt = BTM_SUCCESS; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3068 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3069 | if (p_cb->adv_mode == BTM_BLE_ADV_ENABLE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3070 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3071 | if (btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_DISABLE)) |
| 3072 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3073 | p_cb->fast_adv_on = FALSE; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3074 | p_cb->adv_mode = BTM_BLE_ADV_DISABLE; |
| 3075 | btm_cb.ble_ctr_cb.wl_state &= ~BTM_BLE_WL_ADV; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3076 | |
| 3077 | /* clear all adv states */ |
| 3078 | btm_ble_clear_topology_mask (BTM_BLE_STATE_ALL_ADV_MASK); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3079 | } |
| 3080 | else |
| 3081 | rt = BTM_NO_RESOURCES; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3082 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3083 | return rt; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3084 | } |
| 3085 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3086 | |
| 3087 | /******************************************************************************* |
| 3088 | ** |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3089 | ** Function btm_ble_start_slow_adv |
| 3090 | ** |
| 3091 | ** Description Restart adv with slow adv interval |
| 3092 | ** |
| 3093 | ** Returns void |
| 3094 | ** |
| 3095 | *******************************************************************************/ |
| 3096 | static void btm_ble_start_slow_adv (void) |
| 3097 | { |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 3098 | tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3099 | |
| 3100 | if (p_cb->adv_mode == BTM_BLE_ADV_ENABLE) |
| 3101 | { |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 3102 | tBTM_LE_RANDOM_CB *p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; |
| 3103 | BD_ADDR p_addr_ptr = {0}; |
| 3104 | tBLE_ADDR_TYPE init_addr_type = BLE_ADDR_PUBLIC; |
| 3105 | tBLE_ADDR_TYPE own_addr_type = p_addr_cb->own_addr_type; |
| 3106 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3107 | btm_ble_stop_adv(); |
| 3108 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 3109 | p_cb->evt_type = btm_set_conn_mode_adv_init_addr(p_cb, p_addr_ptr, &init_addr_type, |
| 3110 | &own_addr_type); |
| 3111 | |
| 3112 | /* slow adv mode never goes into directed adv */ |
| 3113 | btsnd_hcic_ble_write_adv_params (BTM_BLE_GAP_ADV_SLOW_INT, BTM_BLE_GAP_ADV_SLOW_INT, |
| 3114 | p_cb->evt_type, own_addr_type, |
| 3115 | init_addr_type, p_addr_ptr, |
| 3116 | p_cb->adv_chnl_map, p_cb->afp); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3117 | |
| 3118 | btm_ble_start_adv(); |
| 3119 | } |
| 3120 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3121 | /******************************************************************************* |
| 3122 | ** |
| 3123 | ** Function btm_ble_timeout |
| 3124 | ** |
| 3125 | ** Description Called when BTM BLE inquiry timer expires |
| 3126 | ** |
| 3127 | ** Returns void |
| 3128 | ** |
| 3129 | *******************************************************************************/ |
| 3130 | void btm_ble_timeout(TIMER_LIST_ENT *p_tle) |
| 3131 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 3132 | BTM_TRACE_EVENT ("btm_ble_timeout"); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3133 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3134 | switch (p_tle->event) |
| 3135 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3136 | case BTU_TTYPE_BLE_OBSERVE: |
| 3137 | btm_ble_stop_observe(); |
| 3138 | break; |
| 3139 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3140 | case BTU_TTYPE_BLE_INQUIRY: |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3141 | btm_ble_stop_inquiry(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3142 | break; |
| 3143 | |
| 3144 | case BTU_TTYPE_BLE_GAP_LIM_DISC: |
| 3145 | /* lim_timeout expiried, limited discovery should exit now */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3146 | btm_cb.btm_inq_vars.discoverable_mode &= ~BTM_BLE_LIMITED_DISCOVERABLE; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3147 | btm_ble_set_adv_flag(btm_cb.btm_inq_vars.connectable_mode, btm_cb.btm_inq_vars.discoverable_mode); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3148 | break; |
| 3149 | |
| 3150 | case BTU_TTYPE_BLE_RANDOM_ADDR: |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3151 | if (btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type == BLE_ADDR_RANDOM) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3152 | { |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 3153 | if (NULL == (void *)(p_tle->param)) |
| 3154 | { |
| 3155 | /* refresh the random addr */ |
| 3156 | btm_gen_resolvable_private_addr((void *)btm_gen_resolve_paddr_low); |
| 3157 | } |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 3158 | else |
| 3159 | { |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 3160 | if (BTM_BleMaxMultiAdvInstanceCount() > 0) |
| 3161 | btm_ble_multi_adv_configure_rpa((tBTM_BLE_MULTI_ADV_INST*)p_tle->param); |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 3162 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3163 | } |
| 3164 | break; |
| 3165 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3166 | case BTU_TTYPE_BLE_GAP_FAST_ADV: |
| 3167 | /* fast adv is completed, fall back to slow adv interval */ |
| 3168 | btm_ble_start_slow_adv(); |
| 3169 | break; |
| 3170 | |
| 3171 | default: |
| 3172 | break; |
| 3173 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3174 | } |
| 3175 | } |
| 3176 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3177 | |
| 3178 | /******************************************************************************* |
| 3179 | ** |
| 3180 | ** Function btm_ble_read_remote_features_complete |
| 3181 | ** |
| 3182 | ** Description This function is called when the command complete message |
| 3183 | ** is received from the HCI for the read LE remote feature supported |
| 3184 | ** complete event. |
| 3185 | ** |
| 3186 | ** Returns void |
| 3187 | ** |
| 3188 | *******************************************************************************/ |
| 3189 | void btm_ble_read_remote_features_complete(UINT8 *p) |
| 3190 | { |
| 3191 | tACL_CONN *p_acl_cb = &btm_cb.acl_db[0]; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3192 | UINT16 handle; |
Priti Aghera | 9c29d08 | 2014-09-02 15:41:56 -0700 | [diff] [blame] | 3193 | UINT8 status; |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 3194 | int xx; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3195 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 3196 | BTM_TRACE_EVENT ("btm_ble_read_remote_features_complete "); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3197 | |
Priti Aghera | 9c29d08 | 2014-09-02 15:41:56 -0700 | [diff] [blame] | 3198 | STREAM_TO_UINT8(status, p); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 3199 | |
| 3200 | // if LE read remote feature failed for HCI_ERR_CONN_FAILED_ESTABLISHMENT, |
| 3201 | // expect disconnect complete to be received |
| 3202 | if (status != HCI_ERR_CONN_FAILED_ESTABLISHMENT) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3203 | { |
Priti Aghera | 9c29d08 | 2014-09-02 15:41:56 -0700 | [diff] [blame] | 3204 | STREAM_TO_UINT16 (handle, p); |
| 3205 | |
| 3206 | /* Look up the connection by handle and copy features */ |
| 3207 | for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_acl_cb++) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3208 | { |
Priti Aghera | 9c29d08 | 2014-09-02 15:41:56 -0700 | [diff] [blame] | 3209 | if ((p_acl_cb->in_use) && (p_acl_cb->hci_handle == handle)) |
| 3210 | { |
| 3211 | STREAM_TO_ARRAY(p_acl_cb->peer_le_features, p, BD_FEATURES_LEN); |
Prerepa Viswanadham | 7ae2515 | 2014-09-10 17:08:11 -0700 | [diff] [blame] | 3212 | /*notify link up here */ |
Priti Aghera | 9c29d08 | 2014-09-02 15:41:56 -0700 | [diff] [blame] | 3213 | l2cble_notify_le_connection (p_acl_cb->remote_addr); |
| 3214 | break; |
| 3215 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3216 | } |
| 3217 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3218 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3219 | } |
| 3220 | |
| 3221 | /******************************************************************************* |
| 3222 | ** |
| 3223 | ** Function btm_ble_write_adv_enable_complete |
| 3224 | ** |
| 3225 | ** Description This function process the write adv enable command complete. |
| 3226 | ** |
| 3227 | ** Returns void |
| 3228 | ** |
| 3229 | *******************************************************************************/ |
| 3230 | void btm_ble_write_adv_enable_complete(UINT8 * p) |
| 3231 | { |
| 3232 | tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 3233 | |
| 3234 | /* if write adv enable/disbale not succeed */ |
| 3235 | if (*p != HCI_SUCCESS) |
| 3236 | { |
| 3237 | /* toggle back the adv mode */ |
| 3238 | p_cb->adv_mode = !p_cb->adv_mode; |
| 3239 | } |
| 3240 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3241 | |
| 3242 | /******************************************************************************* |
| 3243 | ** |
| 3244 | ** Function btm_ble_dir_adv_tout |
| 3245 | ** |
| 3246 | ** Description when directed adv time out |
| 3247 | ** |
| 3248 | ** Returns void |
| 3249 | ** |
| 3250 | *******************************************************************************/ |
| 3251 | void btm_ble_dir_adv_tout(void) |
| 3252 | { |
| 3253 | btm_cb.ble_ctr_cb.inq_var.adv_mode = BTM_BLE_ADV_DISABLE; |
| 3254 | |
| 3255 | /* make device fall back into undirected adv mode by default */ |
| 3256 | btm_cb.ble_ctr_cb.inq_var.directed_conn = FALSE; |
| 3257 | } |
| 3258 | |
| 3259 | /******************************************************************************* |
| 3260 | ** |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 3261 | ** Function btm_ble_set_topology_mask |
| 3262 | ** |
| 3263 | ** Description set BLE topology mask |
| 3264 | ** |
| 3265 | ** Returns TRUE is request is allowed, FALSE otherwise. |
| 3266 | ** |
| 3267 | *******************************************************************************/ |
| 3268 | BOOLEAN btm_ble_set_topology_mask(tBTM_BLE_STATE_MASK request_state_mask) |
| 3269 | { |
| 3270 | request_state_mask &= BTM_BLE_STATE_ALL_MASK; |
| 3271 | btm_cb.ble_ctr_cb.cur_states |= (request_state_mask & BTM_BLE_STATE_ALL_MASK); |
| 3272 | return TRUE; |
| 3273 | } |
| 3274 | |
| 3275 | /******************************************************************************* |
| 3276 | ** |
| 3277 | ** Function btm_ble_clear_topology_mask |
| 3278 | ** |
| 3279 | ** Description Clear BLE topology bit mask |
| 3280 | ** |
| 3281 | ** Returns TRUE is request is allowed, FALSE otherwise. |
| 3282 | ** |
| 3283 | *******************************************************************************/ |
| 3284 | BOOLEAN btm_ble_clear_topology_mask (tBTM_BLE_STATE_MASK request_state_mask) |
| 3285 | { |
| 3286 | request_state_mask &= BTM_BLE_STATE_ALL_MASK; |
| 3287 | btm_cb.ble_ctr_cb.cur_states &= ~request_state_mask; |
| 3288 | return TRUE; |
| 3289 | } |
| 3290 | |
| 3291 | /******************************************************************************* |
| 3292 | ** |
| 3293 | ** Function btm_ble_update_link_topology_mask |
| 3294 | ** |
| 3295 | ** Description This function update the link topology mask |
| 3296 | ** |
| 3297 | ** Returns void |
| 3298 | ** |
| 3299 | *******************************************************************************/ |
| 3300 | void btm_ble_update_link_topology_mask(UINT8 link_role, BOOLEAN increase) |
| 3301 | { |
| 3302 | btm_ble_clear_topology_mask (BTM_BLE_STATE_ALL_CONN_MASK); |
| 3303 | |
| 3304 | if (increase) |
| 3305 | btm_cb.ble_ctr_cb.link_count[link_role]++; |
| 3306 | else if (btm_cb.ble_ctr_cb.link_count[link_role] > 0) |
| 3307 | btm_cb.ble_ctr_cb.link_count[link_role]--; |
| 3308 | |
| 3309 | if (btm_cb.ble_ctr_cb.link_count[HCI_ROLE_MASTER]) |
| 3310 | btm_ble_set_topology_mask (BTM_BLE_STATE_MASTER_BIT); |
| 3311 | |
| 3312 | if (btm_cb.ble_ctr_cb.link_count[HCI_ROLE_SLAVE]) |
| 3313 | btm_ble_set_topology_mask(BTM_BLE_STATE_SLAVE_BIT); |
| 3314 | |
| 3315 | if (link_role == HCI_ROLE_SLAVE && increase) |
| 3316 | { |
| 3317 | btm_cb.ble_ctr_cb.inq_var.adv_mode = BTM_BLE_ADV_DISABLE; |
| 3318 | /* make device fall back into undirected adv mode by default */ |
| 3319 | btm_cb.ble_ctr_cb.inq_var.directed_conn = BTM_BLE_CONNECT_EVT; |
| 3320 | /* clear all adv states */ |
| 3321 | btm_ble_clear_topology_mask(BTM_BLE_STATE_ALL_ADV_MASK); |
| 3322 | } |
| 3323 | } |
| 3324 | |
| 3325 | /******************************************************************************* |
| 3326 | ** |
| 3327 | ** Function btm_ble_update_mode_operation |
| 3328 | ** |
| 3329 | ** Description This function update the GAP role operation when a link status |
| 3330 | ** is updated. |
| 3331 | ** |
| 3332 | ** Returns void |
| 3333 | ** |
| 3334 | *******************************************************************************/ |
| 3335 | void btm_ble_update_mode_operation(UINT8 link_role, BD_ADDR bd_addr, UINT8 status) |
| 3336 | { |
| 3337 | if (status == HCI_ERR_DIRECTED_ADVERTISING_TIMEOUT) |
| 3338 | { |
| 3339 | btm_cb.ble_ctr_cb.inq_var.adv_mode = BTM_BLE_ADV_DISABLE; |
| 3340 | /* make device fall back into undirected adv mode by default */ |
| 3341 | btm_cb.ble_ctr_cb.inq_var.directed_conn = BTM_BLE_CONNECT_EVT; |
| 3342 | /* clear all adv states */ |
| 3343 | btm_ble_clear_topology_mask (BTM_BLE_STATE_ALL_ADV_MASK); |
| 3344 | } |
| 3345 | |
| 3346 | if (btm_cb.ble_ctr_cb.inq_var.connectable_mode == BTM_BLE_CONNECTABLE) |
| 3347 | { |
| 3348 | btm_ble_set_connectability(btm_cb.btm_inq_vars.connectable_mode | |
| 3349 | btm_cb.ble_ctr_cb.inq_var.connectable_mode); |
| 3350 | } |
| 3351 | |
| 3352 | /* when no connection is attempted, and controller is not rejecting last request |
| 3353 | due to resource limitation, start next direct connection or background connection |
| 3354 | now in order */ |
| 3355 | if (btm_ble_get_conn_st() == BLE_CONN_IDLE && status != HCI_ERR_HOST_REJECT_RESOURCES && |
| 3356 | !btm_send_pending_direct_conn()) |
| 3357 | { |
| 3358 | btm_ble_resume_bg_conn(); |
| 3359 | } |
| 3360 | } |
| 3361 | |
| 3362 | /******************************************************************************* |
| 3363 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3364 | ** Function btm_ble_init |
| 3365 | ** |
| 3366 | ** Description Initialize the control block variable values. |
| 3367 | ** |
| 3368 | ** Returns void |
| 3369 | ** |
| 3370 | *******************************************************************************/ |
| 3371 | void btm_ble_init (void) |
| 3372 | { |
| 3373 | tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; |
| 3374 | |
Satya Calloji | b151a43 | 2015-05-07 14:06:37 -0700 | [diff] [blame] | 3375 | BTM_TRACE_DEBUG("%s", __func__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3376 | |
| 3377 | memset(p_cb, 0, sizeof(tBTM_BLE_CB)); |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 3378 | memset(&(btm_cb.cmn_ble_vsc_cb), 0 , sizeof(tBTM_BLE_VSC_CB)); |
Satya Calloji | 3f24f46 | 2014-09-16 22:44:43 -0700 | [diff] [blame] | 3379 | btm_cb.cmn_ble_vsc_cb.values_read = FALSE; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3380 | p_cb->cur_states = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3381 | |
| 3382 | p_cb->inq_var.adv_mode = BTM_BLE_ADV_DISABLE; |
| 3383 | p_cb->inq_var.scan_type = BTM_BLE_SCAN_MODE_NONE; |
| 3384 | p_cb->inq_var.adv_chnl_map = BTM_BLE_DEFAULT_ADV_CHNL_MAP; |
| 3385 | p_cb->inq_var.afp = BTM_BLE_DEFAULT_AFP; |
| 3386 | p_cb->inq_var.sfp = BTM_BLE_DEFAULT_SFP; |
| 3387 | p_cb->inq_var.connectable_mode = BTM_BLE_NON_CONNECTABLE; |
| 3388 | p_cb->inq_var.discoverable_mode = BTM_BLE_NON_DISCOVERABLE; |
| 3389 | |
| 3390 | /* for background connection, reset connection params to be undefined */ |
Satya Calloji | 877123f | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 3391 | p_cb->scan_int = p_cb->scan_win = BTM_BLE_SCAN_PARAM_UNDEF; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3392 | |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 3393 | p_cb->inq_var.evt_type = BTM_BLE_NON_CONNECT_EVT; |
Satya Calloji | c4e2596 | 2014-05-10 23:46:24 -0700 | [diff] [blame] | 3394 | |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 3395 | #if BLE_VND_INCLUDED == FALSE |
Satya Calloji | 1a9247a | 2014-06-05 13:15:15 -0700 | [diff] [blame] | 3396 | btm_ble_adv_filter_init(); |
| 3397 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3398 | } |
| 3399 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3400 | /******************************************************************************* |
| 3401 | ** |
| 3402 | ** Function btm_ble_topology_check |
| 3403 | ** |
| 3404 | ** Description check to see requested state is supported. One state check at |
| 3405 | ** a time is supported |
| 3406 | ** |
| 3407 | ** Returns TRUE is request is allowed, FALSE otherwise. |
| 3408 | ** |
| 3409 | *******************************************************************************/ |
| 3410 | BOOLEAN btm_ble_topology_check(tBTM_BLE_STATE_MASK request_state_mask) |
| 3411 | { |
| 3412 | BOOLEAN rt = FALSE; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3413 | |
| 3414 | UINT8 state_offset = 0; |
| 3415 | UINT16 cur_states = btm_cb.ble_ctr_cb.cur_states; |
| 3416 | UINT8 mask, offset; |
| 3417 | UINT8 request_state = 0; |
| 3418 | |
| 3419 | /* check only one bit is set and within valid range */ |
| 3420 | if (request_state_mask == BTM_BLE_STATE_INVALID || |
| 3421 | request_state_mask > BTM_BLE_STATE_SCAN_ADV_BIT || |
| 3422 | (request_state_mask & (request_state_mask -1 )) != 0) |
| 3423 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 3424 | BTM_TRACE_ERROR("illegal state requested: %d", request_state_mask); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3425 | return rt; |
| 3426 | } |
| 3427 | |
| 3428 | while (request_state_mask) |
| 3429 | { |
| 3430 | request_state_mask >>= 1; |
| 3431 | request_state ++; |
| 3432 | } |
| 3433 | |
| 3434 | /* check if the requested state is supported or not */ |
| 3435 | mask = btm_le_state_combo_tbl[0][request_state - 1][0]; |
| 3436 | offset = btm_le_state_combo_tbl[0][request_state-1][1]; |
| 3437 | |
Zach Johnson | a87c821 | 2014-10-28 17:59:13 -0700 | [diff] [blame] | 3438 | const uint8_t *ble_supported_states = controller_get_interface()->get_ble_supported_states(); |
| 3439 | |
| 3440 | if (!BTM_LE_STATES_SUPPORTED(ble_supported_states, mask, offset)) |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3441 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 3442 | BTM_TRACE_ERROR("state requested not supported: %d", request_state); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3443 | return rt; |
| 3444 | } |
| 3445 | |
| 3446 | rt = TRUE; |
| 3447 | /* make sure currently active states are all supported in conjunction with the requested |
| 3448 | state. If the bit in table is not set, the combination is not supported */ |
| 3449 | while (cur_states != 0) |
| 3450 | { |
| 3451 | if (cur_states & 0x01) |
| 3452 | { |
| 3453 | mask = btm_le_state_combo_tbl[request_state][state_offset][0]; |
| 3454 | offset = btm_le_state_combo_tbl[request_state][state_offset][1]; |
| 3455 | |
| 3456 | if (mask != 0 && offset != 0) |
| 3457 | { |
Zach Johnson | a87c821 | 2014-10-28 17:59:13 -0700 | [diff] [blame] | 3458 | if (!BTM_LE_STATES_SUPPORTED(ble_supported_states, mask, offset)) |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3459 | { |
| 3460 | rt = FALSE; |
| 3461 | break; |
| 3462 | } |
| 3463 | } |
| 3464 | } |
| 3465 | cur_states >>= 1; |
| 3466 | state_offset ++; |
| 3467 | } |
| 3468 | return rt; |
| 3469 | } |
| 3470 | |
| 3471 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3472 | #endif /* BLE_INCLUDED */ |