blob: 4a1674f0507b271d55c3d5e03ad54fa920d285e0 [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
2 *
Wei Wanga6ce7752014-05-20 06:30:32 +00003 * Copyright (C) 2008-2014 Broadcom Corporation
The Android Open Source Project5738f832012-12-12 16:00:35 -08004 *
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. Chen5cd8bff2014-01-31 18:16:59 -080030#include "bt_utils.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080031#include "btm_int.h"
Wei Wang21015a42014-10-03 10:58:03 -070032#include "btm_ble_api.h"
33#include "btu.h"
Chris Manton79ecab52014-10-31 14:54:51 -070034#include "device/include/controller.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080035#include "hcimsgs.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080036#include "gap_api.h"
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -070037
38#if BLE_INCLUDED == TRUE
Priti Aghera9c29d082014-09-02 15:41:56 -070039#include "l2c_int.h"
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -070040
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080041#include "gattdefs.h"
Nitin Arora021e17a2014-01-29 19:18:39 -080042#include "gatt_int.h"
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080043
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -070044#include "btm_ble_int.h"
Chris Mantonf8027002015-03-12 09:22:48 -070045#define LOG_TAG "bt_btm_ble"
Sharvil Nanavati44802762014-12-23 23:08:58 -080046#include "osi/include/log.h"
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -070047
The Android Open Source Project5738f832012-12-12 16:00:35 -080048#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 Project5738f832012-12-12 16:00:35 -080054#define BTM_EXT_BLE_RMT_NAME_TIMEOUT 30
Wei Wanga6ce7752014-05-20 06:30:32 +000055#define MIN_ADV_LENGTH 2
Satya Calloji5725fc62015-03-31 13:24:32 -070056#define BTM_VSC_CHIP_CAPABILITY_RSP_LEN_L_RELEASE 9
57
58static tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
Wei Wanga6ce7752014-05-20 06:30:32 +000059
Bernhard Rosenkränzer104e3f22014-11-12 21:53:08 +010060#if BLE_VND_INCLUDED == TRUE
Ganesh Ganapathi Batta8d416912014-05-30 16:28:00 -070061static tBTM_BLE_CTRL_FEATURES_CBACK *p_ctrl_le_feature_rd_cmpl_cback = NULL;
Bernhard Rosenkränzer104e3f22014-11-12 21:53:08 +010062#endif
Ganesh Ganapathi Batta8d416912014-05-30 16:28:00 -070063
The Android Open Source Project5738f832012-12-12 16:00:35 -080064/*******************************************************************************
65** Local functions
66*******************************************************************************/
67static void btm_ble_update_adv_flag(UINT8 flag);
68static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, UINT8 addr_type, UINT8 evt_type, UINT8 *p);
Wei Wanga6ce7752014-05-20 06:30:32 +000069UINT8 *btm_ble_build_adv_data(tBTM_BLE_AD_MASK *p_data_mask, UINT8 **p_dst,
70 tBTM_BLE_ADV_DATA *p_data);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080071static UINT8 btm_set_conn_mode_adv_init_addr(tBTM_BLE_INQ_CB *p_cb,
Satya Calloji444a8da2015-03-06 10:38:22 -080072 BD_ADDR_PTR p_peer_addr_ptr,
73 tBLE_ADDR_TYPE *p_peer_addr_type,
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080074 tBLE_ADDR_TYPE *p_own_addr_type);
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -070075static void btm_ble_stop_observe(void);
The Android Open Source Project5738f832012-12-12 16:00:35 -080076
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -070077#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 Project5738f832012-12-12 16:00:35 -080080
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -070081/* LE states combo bit to check */
82const UINT8 btm_le_state_combo_tbl[BTM_BLE_STATE_MAX][BTM_BLE_STATE_MAX][2] =
The Android Open Source Project5738f832012-12-12 16:00:35 -080083{
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -070084 {/* 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 Battaead3cde2013-02-05 15:22:31 -0800225/*******************************************************************************
226**
227** Function BTM_BleUpdateAdvWhitelist
228**
229** Description Add or remove device from advertising white list
230**
231** Returns void
232**
233*******************************************************************************/
234BOOLEAN BTM_BleUpdateAdvWhitelist(BOOLEAN add_remove, BD_ADDR remote_bda)
235{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -0800236 UNUSED(add_remove);
237 UNUSED(remote_bda);
238
239 return FALSE;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800240}
The Android Open Source Project5738f832012-12-12 16:00:35 -0800241
242/*******************************************************************************
243**
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800244** 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*******************************************************************************/
252void 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 Nanavati5344d6d2014-05-04 00:46:57 -0700259 BTM_TRACE_EVENT ("BTM_BleUpdateAdvFilterPolicy");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800260
Zach Johnson30e58062014-09-26 21:14:34 -0700261 if (!controller_get_interface()->supports_ble())
Andre Eisenbach3aa60542013-03-22 18:00:51 -0700262 return;
263
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800264 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 Batta7fa4fba2014-04-16 16:50:09 -0700272 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 Battaead3cde2013-02-05 15:22:31 -0800274
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700275 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 Battaead3cde2013-02-05 15:22:31 -0800279 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 Calloji5725fc62015-03-31 13:24:32 -0700291
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*******************************************************************************/
307BOOLEAN 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 Battaead3cde2013-02-05 15:22:31 -0800332/*******************************************************************************
333**
The Android Open Source Project5738f832012-12-12 16:00:35 -0800334** 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*******************************************************************************/
345tBTM_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 Calloji877123f2015-04-23 23:39:49 -0700349 tBTM_STATUS status = BTM_WRONG_MODE;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800350
Satya Calloji5725fc62015-03-31 13:24:32 -0700351 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 Calloji877123f2015-04-23 23:39:49 -0700354 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 Project5738f832012-12-12 16:00:35 -0800356
Zach Johnson30e58062014-09-26 21:14:34 -0700357 if (!controller_get_interface()->supports_ble())
Andre Eisenbach3aa60542013-03-22 18:00:51 -0700358 return BTM_ILLEGAL_VALUE;
359
The Android Open Source Project5738f832012-12-12 16:00:35 -0800360 if (start)
361 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800362 /* shared inquiry database, do not allow observe if any inquiry is active */
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700363 if (BTM_BLE_IS_OBS_ACTIVE(btm_cb.ble_ctr_cb.scan_activity))
Nitin Arora0830ad42014-02-21 18:20:37 -0800364 {
Satya Calloji877123f2015-04-23 23:39:49 -0700365 BTM_TRACE_ERROR("%s Observe Already Active", __func__);
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700366 return status;
Nitin Arora0830ad42014-02-21 18:20:37 -0800367 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800368
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700369 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 Calloji5725fc62015-03-31 13:24:32 -0700376 /* 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 Calloji877123f2015-04-23 23:39:49 -0700380 #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 Calloji5725fc62015-03-31 13:24:32 -0700385 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 Project5738f832012-12-12 16:00:35 -0800398
Satya Calloji877123f2015-04-23 23:39:49 -0700399 p_inq->scan_duplicate_filter = BTM_BLE_DUPLICATE_DISABLE;
400 status = btm_ble_start_scan();
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700401 }
Satya Calloji877123f2015-04-23 23:39:49 -0700402
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700403 if (status == BTM_CMD_STARTED)
404 {
405 btm_cb.ble_ctr_cb.scan_activity |= BTM_LE_OBSERVE_ACTIVE;
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700406 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 Project5738f832012-12-12 16:00:35 -0800409 }
410 }
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700411 else if (BTM_BLE_IS_OBS_ACTIVE(btm_cb.ble_ctr_cb.scan_activity))
The Android Open Source Project5738f832012-12-12 16:00:35 -0800412 {
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700413 status = BTM_CMD_STARTED;
414 btm_ble_stop_observe();
415 }
416 else
417 {
Satya Calloji877123f2015-04-23 23:39:49 -0700418 BTM_TRACE_ERROR("%s Observe not active", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800419 }
420
421 return status;
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700422
The Android Open Source Project5738f832012-12-12 16:00:35 -0800423}
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*******************************************************************************/
436tBTM_STATUS BTM_BleBroadcast(BOOLEAN start)
437{
438 tBTM_STATUS status = BTM_NO_RESOURCES;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800439 tBTM_LE_RANDOM_CB *p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800440 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 Johnson30e58062014-09-26 21:14:34 -0700443 if (!controller_get_interface()->supports_ble())
Andre Eisenbach3aa60542013-03-22 18:00:51 -0700444 return BTM_ILLEGAL_VALUE;
445
The Android Open Source Project5738f832012-12-12 16:00:35 -0800446#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 Batta7fa4fba2014-04-16 16:50:09 -0700456 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 Project5738f832012-12-12 16:00:35 -0800460 evt_type,
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800461 p_addr_cb->own_addr_type,
462 p_cb->direct_bda.type,
463 p_cb->direct_bda.bda,
The Android Open Source Project5738f832012-12-12 16:00:35 -0800464 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 Battaead3cde2013-02-05 15:22:31 -0800471 status = btm_ble_start_adv ();
The Android Open Source Project5738f832012-12-12 16:00:35 -0800472 }
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700473 else if (!start)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800474 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800475 status = btm_ble_stop_adv();
Andre Eisenbacha9c53012015-05-20 23:55:13 -0700476#if BLE_PRIVACY_SPT == TRUE
Satya Calloji877123f2015-04-23 23:39:49 -0700477 btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, TRUE);
Andre Eisenbacha9c53012015-05-20 23:55:13 -0700478#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -0800479 }
480 else
481 {
482 status = BTM_WRONG_MODE;
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -0700483 BTM_TRACE_ERROR("Can not %s Broadcast, device %s in Broadcast mode",
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700484 (start ? "Start" : "Stop"), (start ? "already" :"not"));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800485 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800486 return status;
487}
488
The Android Open Source Project5738f832012-12-12 16:00:35 -0800489/*******************************************************************************
490**
Wei Wanga6ce7752014-05-20 06:30:32 +0000491** Function btm_vsc_brcm_features_complete
492**
493** Description Command Complete callback for HCI_BLE_VENDOR_CAP_OCF
494**
495** Returns void
496**
497*******************************************************************************/
498static void btm_ble_vendor_capability_vsc_cmpl_cback (tBTM_VSC_CMPL *p_vcs_cplt_params)
499{
Satya Calloji5725fc62015-03-31 13:24:32 -0700500#if BLE_VND_INCLUDED == TRUE
501 UINT8 status = 0xFF;
502 UINT8 *p;
Ganesh Ganapathi Batta8d416912014-05-30 16:28:00 -0700503
Satya Calloji5725fc62015-03-31 13:24:32 -0700504 BTM_TRACE_DEBUG("%s", __func__);
Ganesh Ganapathi Batta8d416912014-05-30 16:28:00 -0700505
Wei Wanga6ce7752014-05-20 06:30:32 +0000506 /* Check status of command complete event */
Satya Calloji5725fc62015-03-31 13:24:32 -0700507 if ((p_vcs_cplt_params->opcode == HCI_BLE_VENDOR_CAP_OCF) &&
508 (p_vcs_cplt_params->param_len > 0))
Wei Wanga6ce7752014-05-20 06:30:32 +0000509 {
510 p = p_vcs_cplt_params->p_param_buf;
Satya Calloji5725fc62015-03-31 13:24:32 -0700511 STREAM_TO_UINT8(status, p);
Wei Wanga6ce7752014-05-20 06:30:32 +0000512 }
513
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -0700514 if (status == HCI_SUCCESS)
Wei Wanga6ce7752014-05-20 06:30:32 +0000515 {
Satya Calloji5725fc62015-03-31 13:24:32 -0700516 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 Callojif5387072015-02-09 17:40:52 -0800523
Satya Calloji5725fc62015-03-31 13:24:32 -0700524 if (p_vcs_cplt_params->param_len > BTM_VSC_CHIP_CAPABILITY_RSP_LEN_L_RELEASE)
Satya Callojif5387072015-02-09 17:40:52 -0800525 {
Satya Calloji5725fc62015-03-31 13:24:32 -0700526 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 Callojib151a432015-05-07 14:06:37 -0700533 if (btm_cb.cmn_ble_vsc_cb.version_supported == BTM_VSC_CHIP_CAPABILITY_M_VERSION)
Satya Calloji5725fc62015-03-31 13:24:32 -0700534 {
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 Callojif5387072015-02-09 17:40:52 -0800538 }
Satya Calloji3f24f462014-09-16 22:44:43 -0700539 btm_cb.cmn_ble_vsc_cb.values_read = TRUE;
Wei Wanga6ce7752014-05-20 06:30:32 +0000540 }
Satya Callojic4e25962014-05-10 23:46:24 -0700541
Satya Callojib151a432015-05-07 14:06:37 -0700542 BTM_TRACE_DEBUG("%s: stat=%d, irk=%d, ADV ins:%d, rpa=%d, ener=%d, ext_scan=%d",
Satya Calloji5725fc62015-03-31 13:24:32 -0700543 __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 Callojib151a432015-05-07 14:06:37 -0700545 btm_cb.cmn_ble_vsc_cb.energy_support, btm_cb.cmn_ble_vsc_cb.extended_scan_support);
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -0700546
547 if (BTM_BleMaxMultiAdvInstanceCount() > 0)
548 btm_ble_multi_adv_init();
549
550 if (btm_cb.cmn_ble_vsc_cb.max_filter > 0)
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -0700551 btm_ble_adv_filter_init();
Satya Callojid5aa2472014-09-23 18:27:09 -0700552
Satya Calloji444a8da2015-03-06 10:38:22 -0800553#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 Calloji444a8da2015-03-06 10:38:22 -0800557 btm_ble_resolving_list_init(btm_cb.cmn_ble_vsc_cb.max_irk_list_sz);
Satya Calloji444a8da2015-03-06 10:38:22 -0800558#endif
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -0700559
560 if (btm_cb.cmn_ble_vsc_cb.tot_scan_results_strg > 0)
561 btm_ble_batchscan_init();
Ganesh Ganapathi Batta8d416912014-05-30 16:28:00 -0700562
563 if (p_ctrl_le_feature_rd_cmpl_cback != NULL)
564 p_ctrl_le_feature_rd_cmpl_cback(status);
Bernhard Rosenkränzer104e3f22014-11-12 21:53:08 +0100565#endif
Satya Calloji5725fc62015-03-31 13:24:32 -0700566}
Wei Wanga6ce7752014-05-20 06:30:32 +0000567
568/*******************************************************************************
569**
Ganesh Ganapathi Batta8d416912014-05-30 16:28:00 -0700570** Function BTM_BleGetVendorCapabilities
Wei Wanga6ce7752014-05-20 06:30:32 +0000571**
Ganesh Ganapathi Batta8d416912014-05-30 16:28:00 -0700572** Description This function reads local LE features
Wei Wanga6ce7752014-05-20 06:30:32 +0000573**
Ganesh Ganapathi Batta8d416912014-05-30 16:28:00 -0700574** Parameters p_cmn_vsc_cb : Locala LE capability structure
575**
576** Returns void
Wei Wanga6ce7752014-05-20 06:30:32 +0000577**
578*******************************************************************************/
June R. Tate-Gans24933b52014-09-24 15:25:02 -0700579extern void BTM_BleGetVendorCapabilities(tBTM_BLE_VSC_CB *p_cmn_vsc_cb)
Wei Wanga6ce7752014-05-20 06:30:32 +0000580{
Satya Calloji1a9247a2014-06-05 13:15:15 -0700581 BTM_TRACE_DEBUG("BTM_BleGetVendorCapabilities");
Ganesh Ganapathi Batta8d416912014-05-30 16:28:00 -0700582
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -0700583 if (NULL != p_cmn_vsc_cb)
Ganesh Ganapathi Batta8d416912014-05-30 16:28:00 -0700584 {
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-Gans24933b52014-09-24 15:25:02 -0700600extern void BTM_BleReadControllerFeatures(tBTM_BLE_CTRL_FEATURES_CBACK *p_vsc_cback)
Ganesh Ganapathi Batta8d416912014-05-30 16:28:00 -0700601{
Satya Calloji3f24f462014-09-16 22:44:43 -0700602 if (TRUE == btm_cb.cmn_ble_vsc_cb.values_read)
603 return;
604
Satya Callojic4e25962014-05-10 23:46:24 -0700605#if BLE_VND_INCLUDED == TRUE
Ganesh Ganapathi Batta8d416912014-05-30 16:28:00 -0700606 BTM_TRACE_DEBUG("BTM_BleReadControllerFeatures");
607
Ganesh Ganapathi Batta8d416912014-05-30 16:28:00 -0700608 p_ctrl_le_feature_rd_cmpl_cback = p_vsc_cback;
Wei Wanga6ce7752014-05-20 06:30:32 +0000609 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 Nanavati5344d6d2014-05-04 00:46:57 -0700615 BTM_TRACE_ERROR("LE Get_Vendor Capabilities Command Failed.");
Wei Wanga6ce7752014-05-20 06:30:32 +0000616 }
Satya Callojic4e25962014-05-10 23:46:24 -0700617#else
618 UNUSED(p_vsc_cback);
619#endif
Wei Wanga6ce7752014-05-20 06:30:32 +0000620 return ;
621}
622
623/*******************************************************************************
624**
Satya Calloji444a8da2015-03-06 10:38:22 -0800625** Function BTM_BleEnableMixedPrivacyMode
The Android Open Source Project5738f832012-12-12 16:00:35 -0800626**
Satya Calloji444a8da2015-03-06 10:38:22 -0800627** Description This function is called to enabled Mixed mode if privacy 1.2
628** is applicable in controller.
The Android Open Source Project5738f832012-12-12 16:00:35 -0800629**
Satya Calloji444a8da2015-03-06 10:38:22 -0800630** Parameters mixed_on: mixed mode to be used or not.
The Android Open Source Project5738f832012-12-12 16:00:35 -0800631**
632** Returns void
633**
634*******************************************************************************/
Satya Calloji444a8da2015-03-06 10:38:22 -0800635void BTM_BleEnableMixedPrivacyMode(BOOLEAN mixed_on)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800636{
Satya Calloji444a8da2015-03-06 10:38:22 -0800637
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 Project5738f832012-12-12 16:00:35 -0800642#endif
643}
The Android Open Source Project5738f832012-12-12 16:00:35 -0800644
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700645/*******************************************************************************
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 Calloji444a8da2015-03-06 10:38:22 -0800652** Parameters privacy_mode: privacy mode on or off.
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700653**
Satya Calloji444a8da2015-03-06 10:38:22 -0800654** Returns BOOLEAN privacy mode set success; otherwise failed.
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700655**
656*******************************************************************************/
Satya Calloji444a8da2015-03-06 10:38:22 -0800657BOOLEAN BTM_BleConfigPrivacy(BOOLEAN privacy_mode)
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700658{
Satya Calloji444a8da2015-03-06 10:38:22 -0800659#if BLE_PRIVACY_SPT == TRUE
660 tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700661
Satya Calloji444a8da2015-03-06 10:38:22 -0800662 BTM_TRACE_EVENT ("%s", __func__);
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700663
Satya Calloji444a8da2015-03-06 10:38:22 -0800664 /* 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 Batta7fa4fba2014-04-16 16:50:09 -0700670 {
Satya Calloji444a8da2015-03-06 10:38:22 -0800671 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 Viswanadham16fe0822014-08-07 11:38:06 -0700679
680 if (BTM_BleMaxMultiAdvInstanceCount() > 0)
Satya Calloji444a8da2015-03-06 10:38:22 -0800681 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 Batta7fa4fba2014-04-16 16:50:09 -0700692 }
Satya Calloji444a8da2015-03-06 10:38:22 -0800693
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 Batta7fa4fba2014-04-16 16:50:09 -0700700}
701
Ganesh Ganapathi Batta8d416912014-05-30 16:28:00 -0700702/*******************************************************************************
703**
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -0700704** 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 Calloji444a8da2015-03-06 10:38:22 -0800711extern UINT8 BTM_BleMaxMultiAdvInstanceCount(void)
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -0700712{
Wei Wang21015a42014-10-03 10:58:03 -0700713 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 Viswanadham16fe0822014-08-07 11:38:06 -0700715}
716
717#if BLE_PRIVACY_SPT == TRUE
718/*******************************************************************************
719**
Zhihai Xu8b35b3f2014-03-11 15:01:45 -0700720** Function btm_ble_resolve_random_addr_on_adv
721**
722** Description resolve random address complete callback.
723**
724** Returns void
725**
726*******************************************************************************/
727static 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 Nanavati5344d6d2014-05-04 00:46:57 -0700735 BTM_TRACE_EVENT ("btm_ble_resolve_random_addr_on_adv ");
Zhihai Xu8b35b3f2014-03-11 15:01:45 -0700736
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 Wang72833a12014-10-16 20:26:44 -0700743 BTM_TRACE_DEBUG("Random match");
Zhihai Xu8b35b3f2014-03-11 15:01:45 -0700744 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 Xu8b35b3f2014-03-11 15:01:45 -0700749
750 btm_ble_process_adv_pkt_cont(bda, addr_type, evt_type, pp);
751
752 return;
753}
754#endif
755
The Android Open Source Project5738f832012-12-12 16:00:35 -0800756/*******************************************************************************
757**
Sharvil Nanavati26112632014-06-07 00:56:14 -0700758** 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 Calloji444a8da2015-03-06 10:38:22 -0800765BOOLEAN BTM_BleLocalPrivacyEnabled(void)
Sharvil Nanavati26112632014-06-07 00:56:14 -0700766{
767#if BLE_PRIVACY_SPT == TRUE
Satya Calloji444a8da2015-03-06 10:38:22 -0800768 return (btm_cb.ble_ctr_cb.privacy_mode != BTM_PRIVACY_NONE);
Sharvil Nanavati26112632014-06-07 00:56:14 -0700769#else
770 return false;
771#endif
772}
773
774/*******************************************************************************
775**
The Android Open Source Project5738f832012-12-12 16:00:35 -0800776** 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*******************************************************************************/
788BOOLEAN BTM_BleSetBgConnType(tBTM_BLE_CONN_TYPE bg_conn_type,
789 tBTM_BLE_SEL_CBACK *p_select_cback)
790{
791 BOOLEAN started = TRUE;
792
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -0700793 BTM_TRACE_EVENT ("BTM_BleSetBgConnType ");
Zach Johnson30e58062014-09-26 21:14:34 -0700794 if (!controller_get_interface()->supports_ble())
Andre Eisenbach3aa60542013-03-22 18:00:51 -0700795 return FALSE;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800796
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 Calloji444a8da2015-03-06 10:38:22 -0800810 btm_ble_start_select_conn(TRUE, p_select_cback);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800811 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 Nanavati5344d6d2014-05-04 00:46:57 -0700826 BTM_TRACE_ERROR("invalid bg connection type : %d ", bg_conn_type);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800827 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 Arora021e17a2014-01-29 19:18:39 -0800839** 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*******************************************************************************/
850void 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 Project5738f832012-12-12 16:00:35 -0800859** 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*******************************************************************************/
872BOOLEAN BTM_BleUpdateBgConnDev(BOOLEAN add_remove, BD_ADDR remote_bda)
873{
Priti Agherab8b3e802015-04-17 18:11:24 -0700874 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 Project5738f832012-12-12 16:00:35 -0800876}
877
878/*******************************************************************************
879**
Satya Calloji444a8da2015-03-06 10:38:22 -0800880** Function BTM_BleSetConnectableMode
The Android Open Source Project5738f832012-12-12 16:00:35 -0800881**
882** Description This function is called to set BLE connectable mode for a
883** peripheral device.
884**
Satya Calloji444a8da2015-03-06 10:38:22 -0800885** 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 Project5738f832012-12-12 16:00:35 -0800888**
Satya Calloji444a8da2015-03-06 10:38:22 -0800889** Returns BTM_ILLEGAL_VALUE if controller does not support BLE.
890** BTM_SUCCESS is status set successfully; otherwise failure.
The Android Open Source Project5738f832012-12-12 16:00:35 -0800891**
892*******************************************************************************/
Satya Calloji444a8da2015-03-06 10:38:22 -0800893tBTM_STATUS BTM_BleSetConnectableMode(tBTM_BLE_CONN_MODE connectable_mode)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800894{
895 tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800896
Satya Calloji444a8da2015-03-06 10:38:22 -0800897 BTM_TRACE_EVENT ("%s connectable_mode = %d ", __func__, connectable_mode);
Zach Johnson30e58062014-09-26 21:14:34 -0700898 if (!controller_get_interface()->supports_ble())
Andre Eisenbach3aa60542013-03-22 18:00:51 -0700899 return BTM_ILLEGAL_VALUE;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800900
Satya Calloji444a8da2015-03-06 10:38:22 -0800901 p_cb->directed_conn = connectable_mode;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800902 return btm_ble_set_connectability( p_cb->connectable_mode);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800903}
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*******************************************************************************/
914static UINT8 btm_set_conn_mode_adv_init_addr(tBTM_BLE_INQ_CB *p_cb,
Satya Calloji444a8da2015-03-06 10:38:22 -0800915 BD_ADDR_PTR p_peer_addr_ptr,
916 tBLE_ADDR_TYPE *p_peer_addr_type,
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800917 tBLE_ADDR_TYPE *p_own_addr_type)
918{
Satya Calloji444a8da2015-03-06 10:38:22 -0800919 UINT8 evt_type, i = BTM_SEC_MAX_DEVICE_RECORDS;
920 tBTM_SEC_DEV_REC *p_dev_rec;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800921
Satya Calloji444a8da2015-03-06 10:38:22 -0800922 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 Batta7fa4fba2014-04-16 16:50:09 -0700925
Satya Calloji444a8da2015-03-06 10:38:22 -0800926 if (evt_type == BTM_BLE_CONNECT_EVT)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800927 {
Satya Calloji444a8da2015-03-06 10:38:22 -0800928 evt_type = p_cb->directed_conn;
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700929
Satya Calloji444a8da2015-03-06 10:38:22 -0800930 if ( p_cb->directed_conn == BTM_BLE_CONNECT_DIR_EVT ||
931 p_cb->directed_conn == BTM_BLE_CONNECT_LO_DUTY_DIR_EVT)
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700932 {
Satya Calloji444a8da2015-03-06 10:38:22 -0800933
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 Calloji877123f2015-04-23 23:39:49 -0700943 btm_ble_enable_resolving_list(BTM_BLE_RL_ADV);
Satya Calloji444a8da2015-03-06 10:38:22 -0800944 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 Calloji877123f2015-04-23 23:39:49 -0700950 else
951 {
952 btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, TRUE);
953 }
Satya Calloji444a8da2015-03-06 10:38:22 -0800954 }
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 Batta7fa4fba2014-04-16 16:50:09 -0700960 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800961 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800962
Satya Calloji444a8da2015-03-06 10:38:22 -0800963 /* 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 Battaead3cde2013-02-05 15:22:31 -0800980
Satya Calloji444a8da2015-03-06 10:38:22 -0800981 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 Calloji444a8da2015-03-06 10:38:22 -0800987 /* 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 Calloji444a8da2015-03-06 10:38:22 -0800992 }
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 Project5738f832012-12-12 16:00:35 -0800998}
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*******************************************************************************/
1014tBTM_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 Battaead3cde2013-02-05 15:22:31 -08001018 tBTM_LE_RANDOM_CB *p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001019 tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var;
1020 tBTM_STATUS status = BTM_SUCCESS;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001021 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 Project5738f832012-12-12 16:00:35 -08001025
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07001026 BTM_TRACE_EVENT ("BTM_BleSetAdvParams");
The Android Open Source Project5738f832012-12-12 16:00:35 -08001027
Zach Johnson30e58062014-09-26 21:14:34 -07001028 if (!controller_get_interface()->supports_ble())
Andre Eisenbach3aa60542013-03-22 18:00:51 -07001029 return BTM_ILLEGAL_VALUE;
1030
Satya Calloji5725fc62015-03-31 13:24:32 -07001031 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 Project5738f832012-12-12 16:00:35 -08001033 {
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 Project5738f832012-12-12 16:00:35 -08001045
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07001046 BTM_TRACE_EVENT ("update params for an active adv");
The Android Open Source Project5738f832012-12-12 16:00:35 -08001047
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001048 btm_ble_stop_adv();
The Android Open Source Project5738f832012-12-12 16:00:35 -08001049
Satya Calloji444a8da2015-03-06 10:38:22 -08001050 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 Project5738f832012-12-12 16:00:35 -08001052
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001053 /* 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 Project5738f832012-12-12 16:00:35 -08001062
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001063 if (adv_mode == BTM_BLE_ADV_ENABLE)
1064 btm_ble_start_adv();
The Android Open Source Project5738f832012-12-12 16:00:35 -08001065
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*******************************************************************************/
1083void 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 Nanavati5344d6d2014-05-04 00:46:57 -07001088 BTM_TRACE_EVENT ("BTM_BleReadAdvParams ");
Zach Johnson30e58062014-09-26 21:14:34 -07001089 if (!controller_get_interface()->supports_ble())
Andre Eisenbach3aa60542013-03-22 18:00:51 -07001090 return ;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001091
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 Project5738f832012-12-12 16:00:35 -08001102/*******************************************************************************
1103**
1104** Function BTM_BleSetScanParams
1105**
Satya Calloji5725fc62015-03-31 13:24:32 -07001106** Description This function is called to set scan parameters.
The Android Open Source Project5738f832012-12-12 16:00:35 -08001107**
Satya Calloji5725fc62015-03-31 13:24:32 -07001108** 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 Project5738f832012-12-12 16:00:35 -08001113**
1114** Returns void
1115**
1116*******************************************************************************/
Satya Calloji5725fc62015-03-31 13:24:32 -07001117void 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 Project5738f832012-12-12 16:00:35 -08001120{
1121 tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var;
Satya Calloji5725fc62015-03-31 13:24:32 -07001122 UINT32 max_scan_interval;
1123 UINT32 max_scan_window;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001124
Satya Calloji5725fc62015-03-31 13:24:32 -07001125 BTM_TRACE_EVENT ("%s", __func__);
Zach Johnson30e58062014-09-26 21:14:34 -07001126 if (!controller_get_interface()->supports_ble())
Satya Calloji5725fc62015-03-31 13:24:32 -07001127 return;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001128
Satya Calloji5725fc62015-03-31 13:24:32 -07001129 /* 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 Project5738f832012-12-12 16:00:35 -08001131 {
Satya Calloji5725fc62015-03-31 13:24:32 -07001132 max_scan_interval = BTM_BLE_SCAN_INT_MAX;
1133 max_scan_window = BTM_BLE_SCAN_WIN_MAX;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001134 }
1135 else
1136 {
Satya Calloji5725fc62015-03-31 13:24:32 -07001137 /* 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 Nanavati5344d6d2014-05-04 00:46:57 -07001158 BTM_TRACE_ERROR("Illegal params: scan_interval = %d scan_window = %d",
The Android Open Source Project5738f832012-12-12 16:00:35 -08001159 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*******************************************************************************/
1175tBTM_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 Nanavati5344d6d2014-05-04 00:46:57 -07001181 BTM_TRACE_EVENT (" BTM_BleWriteScanRsp");
Andre Eisenbach3aa60542013-03-22 18:00:51 -07001182
Zach Johnson30e58062014-09-26 21:14:34 -07001183 if (!controller_get_interface()->supports_ble())
Andre Eisenbach3aa60542013-03-22 18:00:51 -07001184 return BTM_ILLEGAL_VALUE;
1185
The Android Open Source Project5738f832012-12-12 16:00:35 -08001186 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 Battaead3cde2013-02-05 15:22:31 -08001193 if (data_mask != 0)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001194 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*******************************************************************************/
1215tBTM_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 Batta7fa4fba2014-04-16 16:50:09 -07001219 tBTM_BLE_AD_MASK mask = data_mask;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001220
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07001221 BTM_TRACE_EVENT ("BTM_BleWriteAdvData ");
Andre Eisenbach3aa60542013-03-22 18:00:51 -07001222
Zach Johnson30e58062014-09-26 21:14:34 -07001223 if (!controller_get_interface()->supports_ble())
Andre Eisenbach3aa60542013-03-22 18:00:51 -07001224 return BTM_ILLEGAL_VALUE;
1225
The Android Open Source Project5738f832012-12-12 16:00:35 -08001226 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 Project5738f832012-12-12 16:00:35 -08001230 p_cb_data->p_flags = btm_ble_build_adv_data(&mask, &p, p_data);
1231
1232 p_cb_data->p_pad = p;
1233
Wei Wanga6ce7752014-05-20 06:30:32 +00001234 if (mask != 0)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001235 {
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07001236 BTM_TRACE_ERROR("Partial data write into ADV");
The Android Open Source Project5738f832012-12-12 16:00:35 -08001237 }
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*******************************************************************************/
1262UINT8 *BTM_CheckAdvData( UINT8 *p_adv, UINT8 type, UINT8 *p_length)
1263{
1264 UINT8 *p = p_adv;
1265 UINT8 length;
1266 UINT8 adv_type;
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07001267 BTM_TRACE_API("BTM_CheckAdvData type=0x%02X", type);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001268
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 VijayaRaghavan76356ae2015-04-21 11:32:29 -07001291** 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*******************************************************************************/
1300UINT16 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*******************************************************************************/
1317UINT16 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 Project5738f832012-12-12 16:00:35 -08001326** Function btm_ble_build_adv_data
1327**
1328** Description This function is called build the adv data and rsp data.
1329*******************************************************************************/
Wei Wanga6ce7752014-05-20 06:30:32 +00001330UINT8 *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 Project5738f832012-12-12 16:00:35 -08001332{
Wei Wanga6ce7752014-05-20 06:30:32 +00001333 UINT32 data_mask = *p_data_mask;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001334 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 Project5738f832012-12-12 16:00:35 -08001338 tBTM_BLE_PROP_ELEM *p_elem;
1339
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07001340 BTM_TRACE_EVENT (" btm_ble_build_adv_data");
The Android Open Source Project5738f832012-12-12 16:00:35 -08001341
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 Wanga6ce7752014-05-20 06:30:32 +00001348 *p++ = MIN_ADV_LENGTH;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001349 *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 Battaead3cde2013-02-05 15:22:31 -08001360 /* 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 Project5738f832012-12-12 16:00:35 -08001370 /* device name */
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001371#if BTM_MAX_LOC_BD_NAME_LEN > 0
Wei Wanga6ce7752014-05-20 06:30:32 +00001372 if (len > MIN_ADV_LENGTH && data_mask & BTM_BLE_AD_BIT_DEV_NAME)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001373 {
Wei Wanga6ce7752014-05-20 06:30:32 +00001374 if (strlen(btm_cb.cfg.bd_name) > (UINT16)(len - MIN_ADV_LENGTH))
The Android Open Source Project5738f832012-12-12 16:00:35 -08001375 {
Wei Wanga6ce7752014-05-20 06:30:32 +00001376 *p++ = len - MIN_ADV_LENGTH + 1;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001377 *p++ = BTM_BLE_AD_TYPE_NAME_SHORT;
Wei Wanga6ce7752014-05-20 06:30:32 +00001378 ARRAY_TO_STREAM(p, btm_cb.cfg.bd_name, len - MIN_ADV_LENGTH);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001379 }
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 Wanga6ce7752014-05-20 06:30:32 +00001387 len -= (cp_len + MIN_ADV_LENGTH);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001388 data_mask &= ~BTM_BLE_AD_BIT_DEV_NAME;
1389 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001390#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001391 /* manufacturer data */
Wei Wanga6ce7752014-05-20 06:30:32 +00001392 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 Project5738f832012-12-12 16:00:35 -08001395 {
Wei Wanga6ce7752014-05-20 06:30:32 +00001396 if (p_data->p_manu->len > (len - MIN_ADV_LENGTH))
1397 cp_len = len - MIN_ADV_LENGTH;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001398 else
Wei Wanga6ce7752014-05-20 06:30:32 +00001399 cp_len = p_data->p_manu->len;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001400
1401 *p++ = cp_len + 1;
1402 *p++ = BTM_BLE_AD_TYPE_MANU;
Wei Wanga6ce7752014-05-20 06:30:32 +00001403 ARRAY_TO_STREAM(p, p_data->p_manu->p_val, cp_len);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001404
Wei Wanga6ce7752014-05-20 06:30:32 +00001405 len -= (cp_len + MIN_ADV_LENGTH);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001406 data_mask &= ~BTM_BLE_AD_BIT_MANU;
1407 }
1408 /* TX power */
Wei Wanga6ce7752014-05-20 06:30:32 +00001409 if (len > MIN_ADV_LENGTH && data_mask & BTM_BLE_AD_BIT_TX_PWR)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001410 {
Wei Wanga6ce7752014-05-20 06:30:32 +00001411 *p++ = MIN_ADV_LENGTH;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001412 *p++ = BTM_BLE_AD_TYPE_TX_PWR;
Satya Calloji4a7ad9b2014-07-29 15:32:51 -07001413 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 Project5738f832012-12-12 16:00:35 -08001416 len -= 3;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001417 data_mask &= ~BTM_BLE_AD_BIT_TX_PWR;
1418 }
Wei Wanga6ce7752014-05-20 06:30:32 +00001419 /* 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 Project5738f832012-12-12 16:00:35 -08001424 {
Wei Wanga6ce7752014-05-20 06:30:32 +00001425 if (p_data->p_services->num_service * LEN_UUID_16 > (len - MIN_ADV_LENGTH))
The Android Open Source Project5738f832012-12-12 16:00:35 -08001426 {
Wei Wanga6ce7752014-05-20 06:30:32 +00001427 cp_len = (len - MIN_ADV_LENGTH)/LEN_UUID_16;
1428 *p ++ = 1 + cp_len * LEN_UUID_16;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001429 *p++ = BTM_BLE_AD_TYPE_16SRV_PART;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001430 }
1431 else
1432 {
Wei Wanga6ce7752014-05-20 06:30:32 +00001433 cp_len = p_data->p_services->num_service;
1434 *p++ = 1 + cp_len * LEN_UUID_16;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001435 *p++ = BTM_BLE_AD_TYPE_16SRV_CMPL;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001436 }
1437 for (i = 0; i < cp_len; i ++)
1438 {
Wei Wanga6ce7752014-05-20 06:30:32 +00001439 UINT16_TO_STREAM(p, *(p_data->p_services->p_uuid + i));
The Android Open Source Project5738f832012-12-12 16:00:35 -08001440 }
1441
Wei Wanga6ce7752014-05-20 06:30:32 +00001442 len -= (cp_len * MIN_ADV_LENGTH + MIN_ADV_LENGTH);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001443 data_mask &= ~BTM_BLE_AD_BIT_SERVICE;
1444 }
Wei Wanga6ce7752014-05-20 06:30:32 +00001445 /* 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 Nanavati5344d6d2014-05-04 00:46:57 -07001558 BTM_TRACE_WARNING("service data does not fit");
Wei Wanga6ce7752014-05-20 06:30:32 +00001559 }
1560 }
1561
The Android Open Source Project5738f832012-12-12 16:00:35 -08001562 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 Project5738f832012-12-12 16:00:35 -08001572 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 Wanga6ce7752014-05-20 06:30:32 +00001578 if (len >= (MIN_ADV_LENGTH + p_elem->len))/* len byte(1) + ATTR type(1) + Uuid len(2)
1579 + value length */
The Android Open Source Project5738f832012-12-12 16:00:35 -08001580 {
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 Wanga6ce7752014-05-20 06:30:32 +00001585 len -= (MIN_ADV_LENGTH + p_elem->len);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001586 }
1587 else
1588 {
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07001589 BTM_TRACE_WARNING("data exceed max adv packet length");
The Android Open Source Project5738f832012-12-12 16:00:35 -08001590 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 Batta7fa4fba2014-04-16 16:50:09 -07001602/*******************************************************************************
1603**
1604** Function btm_ble_select_adv_interval
1605**
1606** Description select adv interval based on device mode
1607**
1608** Returns void
1609**
1610*******************************************************************************/
1611void 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 Calloji444a8da2015-03-06 10:38:22 -08001623 case BTM_BLE_CONNECT_LO_DUTY_DIR_EVT:
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001624 *p_adv_int_min = *p_adv_int_max = BTM_BLE_GAP_ADV_FAST_INT_1;
1625 break;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001626
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001627 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 Calloji444a8da2015-03-06 10:38:22 -08001631
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001632 /* 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 Calloji444a8da2015-03-06 10:38:22 -08001645
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001646/*******************************************************************************
1647**
Satya Calloji7cf7da92015-02-05 13:12:15 -08001648** 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*******************************************************************************/
1661void 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 Batta7fa4fba2014-04-16 16:50:09 -07001680** Function btm_ble_set_adv_flag
1681**
1682** Description Set adv flag in adv data.
1683**
Satya Calloji7cf7da92015-02-05 13:12:15 -08001684** Parameters: connect_mode (Input)- Connect mode value
1685** disc_mode (Input) - discoverability mode
1686**
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001687** Returns void
1688**
1689*******************************************************************************/
1690void 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 Calloji7cf7da92015-02-05 13:12:15 -08001698 btm_ble_update_dmt_flag_bits (&flag, connect_mode, disc_mode);
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001699
Sharvil Nanavati44802762014-12-23 23:08:58 -08001700 LOG_DEBUG("disc_mode %04x", disc_mode);
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001701 /* update discoverable flag */
1702 if (disc_mode & BTM_BLE_LIMITED_DISCOVERABLE)
1703 {
1704 flag &= ~BTM_BLE_GEN_DISC_FLAG;
Satya Calloji7cf7da92015-02-05 13:12:15 -08001705 flag |= BTM_BLE_LIMIT_DISC_FLAG;
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001706 }
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 Project5738f832012-12-12 16:00:35 -08001722/*******************************************************************************
1723**
1724** Function btm_ble_set_discoverability
1725**
1726** Description This function is called to set BLE discoverable mode.
1727**
Wei Wanga6ce7752014-05-20 06:30:32 +00001728** Parameters: combined_mode: discoverability mode.
The Android Open Source Project5738f832012-12-12 16:00:35 -08001729**
Wei Wanga6ce7752014-05-20 06:30:32 +00001730** Returns BTM_SUCCESS is status set successfully; otherwise failure.
The Android Open Source Project5738f832012-12-12 16:00:35 -08001731**
1732*******************************************************************************/
1733tBTM_STATUS btm_ble_set_discoverability(UINT16 combined_mode)
1734{
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001735 tBTM_LE_RANDOM_CB *p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001736 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 Project5738f832012-12-12 16:00:35 -08001738 UINT8 new_mode = BTM_BLE_ADV_ENABLE;
Satya Calloji444a8da2015-03-06 10:38:22 -08001739 UINT8 evt_type;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001740 tBTM_STATUS status = BTM_SUCCESS;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001741 BD_ADDR p_addr_ptr= {0};
1742 tBLE_ADDR_TYPE init_addr_type = BLE_ADDR_PUBLIC,
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001743 own_addr_type = p_addr_cb->own_addr_type;
1744 UINT16 adv_int_min, adv_int_max;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001745
Satya Calloji444a8da2015-03-06 10:38:22 -08001746 BTM_TRACE_EVENT ("%s mode=0x%0x combined_mode=0x%x", __FUNCTION__, mode, combined_mode);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001747
1748 /*** Check mode parameter ***/
1749 if (mode > BTM_BLE_MAX_DISCOVERABLE)
1750 return(BTM_ILLEGAL_VALUE);
1751
Satya Calloji444a8da2015-03-06 10:38:22 -08001752 p_cb->discoverable_mode = mode;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001753
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001754 evt_type = btm_set_conn_mode_adv_init_addr(p_cb, p_addr_ptr, &init_addr_type, &own_addr_type);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001755
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001756 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 Project5738f832012-12-12 16:00:35 -08001758
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001759 btm_ble_select_adv_interval(p_cb, evt_type, &adv_int_min, &adv_int_max);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001760
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001761 btu_stop_timer(&p_cb->fast_adv_timer);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001762
1763 /* update adv params if start advertising */
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07001764 BTM_TRACE_EVENT ("evt_type=0x%x p-cb->evt_type=0x%x ", evt_type, p_cb->evt_type);
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001765
Satya Calloji444a8da2015-03-06 10:38:22 -08001766 if (new_mode == BTM_BLE_ADV_ENABLE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001767 {
Satya Calloji444a8da2015-03-06 10:38:22 -08001768 btm_ble_set_adv_flag (btm_cb.btm_inq_vars.connectable_mode, combined_mode);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001769
Satya Calloji444a8da2015-03-06 10:38:22 -08001770 if (evt_type != p_cb->evt_type ||p_cb->adv_addr_type != own_addr_type
1771 || !p_cb->fast_adv_on)
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001772 {
Satya Calloji444a8da2015-03-06 10:38:22 -08001773 btm_ble_stop_adv();
The Android Open Source Project5738f832012-12-12 16:00:35 -08001774
Satya Calloji444a8da2015-03-06 10:38:22 -08001775 /* 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 Project5738f832012-12-12 16:00:35 -08001793 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001794
The Android Open Source Project5738f832012-12-12 16:00:35 -08001795 if (status == BTM_SUCCESS && p_cb->adv_mode != new_mode)
1796 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001797 if (new_mode == BTM_BLE_ADV_ENABLE)
1798 status = btm_ble_start_adv();
The Android Open Source Project5738f832012-12-12 16:00:35 -08001799 else
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001800 status = btm_ble_stop_adv();
The Android Open Source Project5738f832012-12-12 16:00:35 -08001801 }
Satya Calloji877123f2015-04-23 23:39:49 -07001802
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001803 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 Calloji877123f2015-04-23 23:39:49 -07001810 else
1811 {
Andre Eisenbacha9c53012015-05-20 23:55:13 -07001812#if BLE_PRIVACY_SPT == TRUE
Satya Calloji877123f2015-04-23 23:39:49 -07001813 btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, TRUE);
Andre Eisenbacha9c53012015-05-20 23:55:13 -07001814#endif
Satya Calloji877123f2015-04-23 23:39:49 -07001815 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001816
1817 /* set up stop advertising timer */
1818 if (status == BTM_SUCCESS && mode == BTM_BLE_LIMITED_DISCOVERABLE)
1819 {
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07001820 BTM_TRACE_EVENT ("start timer for limited disc mode duration=%d (180 secs)", BTM_BLE_GAP_LIM_TOUT);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001821 /* 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 Wanga6ce7752014-05-20 06:30:32 +00001834** Parameters: combined_mode: connectability mode.
The Android Open Source Project5738f832012-12-12 16:00:35 -08001835**
Wei Wanga6ce7752014-05-20 06:30:32 +00001836** Returns BTM_SUCCESS is status set successfully; otherwise failure.
The Android Open Source Project5738f832012-12-12 16:00:35 -08001837**
1838*******************************************************************************/
1839tBTM_STATUS btm_ble_set_connectability(UINT16 combined_mode)
1840{
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001841 tBTM_LE_RANDOM_CB *p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001842 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 Project5738f832012-12-12 16:00:35 -08001844 UINT8 new_mode = BTM_BLE_ADV_ENABLE;
Satya Calloji444a8da2015-03-06 10:38:22 -08001845 UINT8 evt_type;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001846 tBTM_STATUS status = BTM_SUCCESS;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001847 BD_ADDR p_addr_ptr = {0};
Satya Calloji444a8da2015-03-06 10:38:22 -08001848 tBLE_ADDR_TYPE peer_addr_type = BLE_ADDR_PUBLIC,
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001849 own_addr_type = p_addr_cb->own_addr_type;
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001850 UINT16 adv_int_min, adv_int_max;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001851
Satya Calloji444a8da2015-03-06 10:38:22 -08001852 BTM_TRACE_EVENT ("%s mode=0x%0x combined_mode=0x%x", __FUNCTION__, mode, combined_mode);
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001853
The Android Open Source Project5738f832012-12-12 16:00:35 -08001854 /*** Check mode parameter ***/
1855 if (mode > BTM_BLE_MAX_CONNECTABLE)
1856 return(BTM_ILLEGAL_VALUE);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001857
The Android Open Source Project5738f832012-12-12 16:00:35 -08001858 p_cb->connectable_mode = mode;
1859
Satya Calloji444a8da2015-03-06 10:38:22 -08001860 evt_type = btm_set_conn_mode_adv_init_addr(p_cb, p_addr_ptr, &peer_addr_type, &own_addr_type);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001861
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001862 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 Project5738f832012-12-12 16:00:35 -08001868 /* update adv params if needed */
Satya Calloji444a8da2015-03-06 10:38:22 -08001869 if (new_mode == BTM_BLE_ADV_ENABLE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001870 {
Satya Calloji444a8da2015-03-06 10:38:22 -08001871 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 Battaead3cde2013-02-05 15:22:31 -08001874 {
Satya Calloji444a8da2015-03-06 10:38:22 -08001875 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 Battaead3cde2013-02-05 15:22:31 -08001893 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001894 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001895
The Android Open Source Project5738f832012-12-12 16:00:35 -08001896 /* update advertising mode */
1897 if (status == BTM_SUCCESS && new_mode != p_cb->adv_mode)
1898 {
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001899 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 Project5738f832012-12-12 16:00:35 -08001903 }
Satya Calloji444a8da2015-03-06 10:38:22 -08001904
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001905 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 Calloji877123f2015-04-23 23:39:49 -07001912 else
1913 {
Andre Eisenbacha9c53012015-05-20 23:55:13 -07001914#if BLE_PRIVACY_SPT == TRUE
Satya Calloji877123f2015-04-23 23:39:49 -07001915 btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, TRUE);
Andre Eisenbacha9c53012015-05-20 23:55:13 -07001916#endif
Satya Calloji877123f2015-04-23 23:39:49 -07001917 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001918 return status;
1919}
1920
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001921
The Android Open Source Project5738f832012-12-12 16:00:35 -08001922/*******************************************************************************
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 Project5738f832012-12-12 16:00:35 -08001937** BTM_NO_RESOURCES if could not allocate a message buffer
The Android Open Source Project5738f832012-12-12 16:00:35 -08001938** BTM_BUSY - if an inquiry is already active
The Android Open Source Project5738f832012-12-12 16:00:35 -08001939**
1940*******************************************************************************/
1941tBTM_STATUS btm_ble_start_inquiry (UINT8 mode, UINT8 duration)
1942{
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001943 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 Project5738f832012-12-12 16:00:35 -08001946
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07001947 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 Project5738f832012-12-12 16:00:35 -08001948
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001949 /* 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 Project5738f832012-12-12 16:00:35 -08001952 {
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07001953 BTM_TRACE_ERROR("LE Inquiry is active, can not start inquiry");
The Android Open Source Project5738f832012-12-12 16:00:35 -08001954 return(BTM_BUSY);
1955 }
1956
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001957 if (!BTM_BLE_IS_SCAN_ACTIVE(p_ble_cb->scan_activity))
The Android Open Source Project5738f832012-12-12 16:00:35 -08001958 {
Nitin Arora11e6c292014-09-29 18:43:27 -07001959 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 Wanged534e32014-05-20 06:30:13 +00001964#if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE)
Wei Wanged534e32014-05-20 06:30:13 +00001965 /* enable IRK list */
Satya Calloji877123f2015-04-23 23:39:49 -07001966 btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_SCAN);
Wei Wanged534e32014-05-20 06:30:13 +00001967#endif
Satya Calloji877123f2015-04-23 23:39:49 -07001968 p_ble_cb->inq_var.scan_duplicate_filter = BTM_BLE_DUPLICATE_DISABLE;
1969 status = btm_ble_start_scan();
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001970 }
Nitin Arora11e6c292014-09-29 18:43:27 -07001971 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 Batta7fa4fba2014-04-16 16:50:09 -07001982
1983 if (status == BTM_CMD_STARTED)
1984 {
1985 p_inq->inq_active |= mode;
1986 p_ble_cb->scan_activity |= mode;
1987
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07001988 BTM_TRACE_DEBUG("btm_ble_start_inquiry inq_active = 0x%02x", p_inq->inq_active);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001989
1990 if (duration != 0)
1991 {
1992 /* start inquiry timer */
Nitin Arora11e6c292014-09-29 18:43:27 -07001993 btu_start_timer (&p_ble_cb->inq_var.inq_timer_ent, BTU_TTYPE_BLE_INQUIRY, duration);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001994 }
1995 }
1996
1997 return status;
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001998
The Android Open Source Project5738f832012-12-12 16:00:35 -08001999}
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*******************************************************************************/
2010void 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 Battaead3cde2013-02-05 15:22:31 -08002015 memset(bd_name, 0, (BD_NAME_LEN + 1));
Zhihai Xu7f9bcf82014-01-15 15:49:21 -08002016 if (length > BD_NAME_LEN)
2017 {
2018 length = BD_NAME_LEN;
2019 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08002020 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 Battaead3cde2013-02-05 15:22:31 -08002027 btm_process_remote_name(bda, bd_name, length +1, hci_status);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002028 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*******************************************************************************/
2043tBTM_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 Johnson30e58062014-09-26 21:14:34 -07002047 if (!controller_get_interface()->supports_ble())
Andre Eisenbach3aa60542013-03-22 18:00:51 -07002048 return BTM_ERR_PROCESSING;
2049
The Android Open Source Project5738f832012-12-12 16:00:35 -08002050 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 Nanavati5344d6d2014-05-04 00:46:57 -07002054 BTM_TRACE_DEBUG("name request to non-connectable device failed.");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002055 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*******************************************************************************/
2088BOOLEAN 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*******************************************************************************/
2114static 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 Nanavati5344d6d2014-05-04 00:46:57 -07002119 BTM_TRACE_DEBUG ("btm_ble_update_adv_flag new=0x%x", flag);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002120
2121 if (p_adv_data->p_flags != NULL)
2122 {
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07002123 BTM_TRACE_DEBUG ("btm_ble_update_adv_flag old=0x%x", *p_adv_data->p_flags);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002124 *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*******************************************************************************/
2160static 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 Project5738f832012-12-12 16:00:35 -08002165
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07002166 BTM_TRACE_EVENT (" btm_ble_parse_adv_data");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002167
2168 while (len > 0)
2169 {
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07002170 BTM_TRACE_DEBUG("btm_ble_parse_adv_data: len = %d", len);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002171 if ((ad_len = *p_cur ++) == 0)
2172 break;
2173
2174 ad_type = *p_cur ++;
2175
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07002176 BTM_TRACE_DEBUG(" ad_type = %02x ad_len = %d", ad_type, ad_len);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002177
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 Nanavati5344d6d2014-05-04 00:46:57 -07002192 BTM_TRACE_DEBUG("BTM_BLE_AD_TYPE_NAME name = %s",p_adv_data->p_remote_name);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002193 }
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 Nanavati5344d6d2014-05-04 00:46:57 -07002202 BTM_TRACE_DEBUG("BTM_BLE_AD_TYPE_FLAG flag = %s | %s | %s",
The Android Open Source Project5738f832012-12-12 16:00:35 -08002203 (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 Nanavati5344d6d2014-05-04 00:46:57 -07002211 BTM_TRACE_DEBUG("BTM_BLE_AD_TYPE_TX_PWR tx_level = %d", p_adv_data->tx_power_level);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002212 break;
2213
The Android Open Source Project5738f832012-12-12 16:00:35 -08002214 case BTM_BLE_AD_TYPE_MANU:
2215
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002216 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 Project5738f832012-12-12 16:00:35 -08002219 /* need allocate memory to store UUID list */
2220 p_adv_data->service.num_service = (ad_len - 1)/2;
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07002221 BTM_TRACE_DEBUG("service UUID list, num = %d", p_adv_data->service.num_service);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002222 p_cur += (ad_len - 1);
2223 break;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002224
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 Nanavati5344d6d2014-05-04 00:46:57 -07002229 BTM_TRACE_DEBUG("service UUID list, num = %d", p_adv_data->service.num_service);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002230 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 Nanavati5344d6d2014-05-04 00:46:57 -07002237 BTM_TRACE_DEBUG("service UUID list, num = %d", p_adv_data->service.num_service);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002238 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 Project5738f832012-12-12 16:00:35 -08002246 }
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*******************************************************************************/
2261void 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. Chen5cd8bff2014-01-31 18:16:59 -08002266 UNUSED(p_cur);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002267
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 Battaead3cde2013-02-05 15:22:31 -08002296
The Android Open Source Project5738f832012-12-12 16:00:35 -08002297/*******************************************************************************
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 Batta7fa4fba2014-04-16 16:50:09 -07002309UINT8 btm_ble_is_discoverable(BD_ADDR bda, UINT8 evt_type, UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002310{
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002311 UINT8 *p_flag, flag = 0, rt = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002312 UINT8 data_len;
2313 tBTM_INQ_PARMS *p_cond = &btm_cb.btm_inq_vars.inqparms;
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002314 tBTM_BLE_INQ_CB *p_le_inq_cb = &btm_cb.ble_ctr_cb.inq_var;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002315
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002316 UNUSED(p);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002317
2318 /* for observer, always "discoverable */
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002319 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 Project5738f832012-12-12 16:00:35 -08002325
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 Nanavati5344d6d2014-05-04 00:46:57 -07002330 BTM_TRACE_DEBUG("BD ADDR does not meet filter condition");
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002331 return rt;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002332 }
2333
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002334 if (p_le_inq_cb->adv_len != 0)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002335 {
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002336 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 Project5738f832012-12-12 16:00:35 -08002338 {
2339 flag = * p_flag;
2340
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002341 if ((btm_cb.btm_inq_vars.inq_active & BTM_BLE_GENERAL_INQUIRY) &&
The Android Open Source Project5738f832012-12-12 16:00:35 -08002342 (flag & (BTM_BLE_LIMIT_DISC_FLAG|BTM_BLE_GEN_DISC_FLAG)) != 0)
2343 {
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07002344 BTM_TRACE_DEBUG("Find Generable Discoverable device");
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002345 rt |= BTM_BLE_INQ_RESULT;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002346 }
2347
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002348 else if (btm_cb.btm_inq_vars.inq_active & BTM_BLE_LIMITED_INQUIRY &&
The Android Open Source Project5738f832012-12-12 16:00:35 -08002349 (flag & BTM_BLE_LIMIT_DISC_FLAG) != 0)
2350 {
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07002351 BTM_TRACE_DEBUG("Find limited discoverable device");
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002352 rt |= BTM_BLE_INQ_RESULT;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002353 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08002354 }
2355 }
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002356 return rt;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002357}
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002358
Adam Hampsone6c74502014-05-30 15:07:08 -07002359static 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 Project5738f832012-12-12 16:00:35 -08002486/*******************************************************************************
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*******************************************************************************/
2497BOOLEAN 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 Xu1237ee32013-11-26 18:18:29 -08002507 UINT8 *p_uuid16;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002508
2509 STREAM_TO_UINT8 (data_len, p);
2510
2511 if (data_len > BTM_BLE_ADV_DATA_LEN_MAX)
2512 {
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07002513 BTM_TRACE_WARNING("EIR data too long %d. discard", data_len);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002514 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 Nanavati5344d6d2014-05-04 00:46:57 -07002530 BTM_TRACE_DEBUG("btm_ble_update_inq_result scan_rsp=false, to_report=false,\
Nitin Arora0830ad42014-02-21 18:20:37 -08002531 scan_type_active=%d", btm_cb.ble_ctr_cb.inq_var.scan_type);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002532 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 Xu1237ee32013-11-26 18:18:29 -08002554 if (p_le_inq_cb->adv_len != 0)
2555 {
Adam Hampsone6c74502014-05-30 15:07:08 -07002556 /* 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 Xu1237ee32013-11-26 18:18:29 -08002562 {
Adam Hampsone6c74502014-05-30 15:07:08 -07002563 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 Xu1237ee32013-11-26 18:18:29 -08002569 {
Adam Hampsone6c74502014-05-30 15:07:08 -07002570 UINT8 i;
2571 for (i = 0; i + 2 <= len; i = i + 2)
Zhihai Xu1237ee32013-11-26 18:18:29 -08002572 {
Adam Hampsone6c74502014-05-30 15:07:08 -07002573 /* 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 Xu1237ee32013-11-26 18:18:29 -08002581 }
2582 }
2583 }
2584 }
2585
The Android Open Source Project5738f832012-12-12 16:00:35 -08002586 /* if BR/EDR not supported is not set, assume is a DUMO device */
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002587 if ((p_cur->flag & BTM_BLE_BREDR_NOT_SPT) == 0 &&
2588 evt_type != BTM_BLE_CONNECT_DIR_EVT)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002589 {
Andre Eisenbachbf68ac72013-10-25 16:17:45 -07002590 if (p_cur->ble_addr_type != BLE_ADDR_RANDOM)
2591 {
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07002592 BTM_TRACE_DEBUG("BR/EDR NOT support bit not set, treat as DUMO");
Andre Eisenbachbf68ac72013-10-25 16:17:45 -07002593 p_cur->device_type |= BT_DEVICE_TYPE_DUMO;
2594 } else {
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07002595 BTM_TRACE_DEBUG("Random address, treating device as LE only");
Andre Eisenbachbf68ac72013-10-25 16:17:45 -07002596 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08002597 }
2598 else
2599 {
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07002600 BTM_TRACE_DEBUG("BR/EDR NOT SUPPORT bit set, LE only device");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002601 }
2602
2603 return to_report;
2604
2605}
2606
2607/*******************************************************************************
2608**
Satya Calloji444a8da2015-03-06 10:38:22 -08002609** 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*******************************************************************************/
2617void 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 Project5738f832012-12-12 16:00:35 -08002634** Function btm_send_sel_conn_callback
2635**
2636** Description send selection connection request callback.
2637**
2638** Parameters
2639**
2640** Returns void
2641**
2642*******************************************************************************/
2643void 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. Chen5cd8bff2014-01-31 18:16:59 -08002647 UNUSED(addr_type);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002648
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 Project5738f832012-12-12 16:00:35 -08002677** 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*******************************************************************************/
2688void 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 Hampson186cddb2014-05-27 10:48:19 -07002693 UINT8 num_reports;
2694 UINT8 data_len;
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002695#if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE)
Zhihai Xu8b35b3f2014-03-11 15:01:45 -07002696 BOOLEAN match = FALSE;
2697#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08002698
Satya Calloji444a8da2015-03-06 10:38:22 -08002699 /* 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 Hampson186cddb2014-05-27 10:48:19 -07002703 /* Extract the number of reports in this event. */
2704 STREAM_TO_UINT8(num_reports, p);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002705
Adam Hampson186cddb2014-05-27 10:48:19 -07002706 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 Project5738f832012-12-12 16:00:35 -08002712
Wei Wanged534e32014-05-20 06:30:13 +00002713#if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE)
Satya Calloji444a8da2015-03-06 10:38:22 -08002714 /* map address to security record */
2715 match = btm_identity_addr_to_random_pseudo(bda, &addr_type, FALSE);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002716
Satya Calloji444a8da2015-03-06 10:38:22 -08002717 BTM_TRACE_DEBUG("btm_ble_process_adv_pkt:bda= %0x:%0x:%0x:%0x:%0x:%0x",
Nitin Arora0830ad42014-02-21 18:20:37 -08002718 bda[0],bda[1],bda[2],bda[3],bda[4],bda[5]);
Adam Hampson186cddb2014-05-27 10:48:19 -07002719 /* 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 Xu8b35b3f2014-03-11 15:01:45 -07002725#endif
Adam Hampson186cddb2014-05-27 10:48:19 -07002726 btm_ble_process_adv_pkt_cont(bda, addr_type, evt_type, p);
Adam Hampson186cddb2014-05-27 10:48:19 -07002727
2728 STREAM_TO_UINT8(data_len, p);
2729
2730 /* Advance to the next event data_len + rssi byte */
2731 p += data_len + 1;
Zhihai Xu8b35b3f2014-03-11 15:01:45 -07002732 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08002733}
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*******************************************************************************/
2747static 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 Project5738f832012-12-12 16:00:35 -08002750 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 Batta7fa4fba2014-04-16 16:50:09 -07002752 tBTM_INQ_RESULTS_CB *p_obs_results_cb = btm_cb.ble_ctr_cb.p_obs_results_cb;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002753 tBTM_BLE_INQ_CB *p_le_inq_cb = &btm_cb.ble_ctr_cb.inq_var;
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002754 BOOLEAN update = TRUE;
2755 UINT8 result = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002756
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 Batta7fa4fba2014-04-16 16:50:09 -07002763 if (p_i &&
The Android Open Source Project5738f832012-12-12 16:00:35 -08002764 (!(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 Project5738f832012-12-12 16:00:35 -08002767 {
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002768 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 Project5738f832012-12-12 16:00:35 -08002773 }
2774 else
2775 {
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002776 /* if yes, skip it */
2777 return; /* assumption: one result per event */
The Android Open Source Project5738f832012-12-12 16:00:35 -08002778 }
2779 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08002780 /* If existing entry, use that, else get a new one (possibly reusing the oldest) */
2781 if (p_i == NULL)
2782 {
Nitin Arora0830ad42014-02-21 18:20:37 -08002783 if ((p_i = btm_inq_db_new (bda)) != NULL)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002784 {
Nitin Arora0830ad42014-02-21 18:20:37 -08002785 p_inq->inq_cmpl_info.num_resp++;
2786 }
2787 else
2788 return;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002789 }
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 Project5738f832012-12-12 16:00:35 -08002794 /* update the LE device information in inquiry database */
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002795 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 Mantonf8027002015-03-12 09:22:48 -07002800 LOG_WARN("%s device is no longer discoverable so discarding advertising packet pkt",
2801 __func__);
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002802 return;
2803 }
2804 if (!update)
2805 result &= ~BTM_BLE_INQ_RESULT;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002806 /* 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 Sune2805532015-04-22 13:40:21 -07002812 /* 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 Project5738f832012-12-12 16:00:35 -08002816 {
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07002817 BTM_TRACE_WARNING("INQ RES: Extra Response Received...cancelling inquiry..");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002818
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002819 /* 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 Project5738f832012-12-12 16:00:35 -08002822 btsnd_hcic_inq_cancel();
2823
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002824 btm_ble_stop_inquiry();
The Android Open Source Project5738f832012-12-12 16:00:35 -08002825
The Android Open Source Project5738f832012-12-12 16:00:35 -08002826 btm_acl_update_busy_level (BTM_BLI_INQ_DONE_EVT);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002827 }
2828 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08002829 /* background connection in selective connection mode */
2830 if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_SELECTIVE)
2831 {
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002832 if (result & BTM_BLE_SEL_CONN_RESULT)
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002833 btm_send_sel_conn_callback(bda, evt_type, p, addr_type);
2834 else
2835 {
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07002836 BTM_TRACE_DEBUG("None LE device, can not initiate selective connection");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002837 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08002838 }
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002839 else
The Android Open Source Project5738f832012-12-12 16:00:35 -08002840 {
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002841 if (p_inq_results_cb && (result & BTM_BLE_INQ_RESULT))
2842 {
Nitin Arora0830ad42014-02-21 18:20:37 -08002843 (p_inq_results_cb)((tBTM_INQ_RESULTS *) &p_i->inq_info.results, p_le_inq_cb->adv_data_cache);
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002844 }
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 Project5738f832012-12-12 16:00:35 -08002849 }
2850}
2851
2852/*******************************************************************************
2853**
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002854** Function btm_ble_start_scan
2855**
2856** Description Start the BLE scan.
2857**
2858** Returns void
2859**
2860*******************************************************************************/
Satya Calloji877123f2015-04-23 23:39:49 -07002861tBTM_STATUS btm_ble_start_scan(void)
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002862{
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 Calloji877123f2015-04-23 23:39:49 -07002867 if (!btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_ENABLE, p_inq->scan_duplicate_filter))
Satya Calloji444a8da2015-03-06 10:38:22 -08002868 {
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002869 status = BTM_NO_RESOURCES;
Mike J. Chendab87142014-07-18 17:40:12 -07002870 }
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002871 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 Project5738f832012-12-12 16:00:35 -08002883** Function btm_ble_stop_scan
2884**
2885** Description Stop the BLE scan.
2886**
2887** Returns void
2888**
2889*******************************************************************************/
2890void btm_ble_stop_scan(void)
2891{
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07002892 BTM_TRACE_EVENT ("btm_ble_stop_scan ");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002893
The Android Open Source Project5738f832012-12-12 16:00:35 -08002894 /* Clear the inquiry callback if set */
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002895 btm_cb.ble_ctr_cb.inq_var.scan_type = BTM_BLE_SCAN_MODE_NONE;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002896
2897 /* stop discovery now */
2898 btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_DISABLE, BTM_BLE_DUPLICATE_ENABLE);
2899
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002900 btm_update_scanner_filter_policy(SP_ADV_ALL);
Mike J. Chendab87142014-07-18 17:40:12 -07002901
2902 btm_cb.ble_ctr_cb.wl_state &= ~BTM_BLE_WL_SCAN;
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002903}
2904/*******************************************************************************
2905**
2906** Function btm_ble_stop_inquiry
2907**
2908** Description Stop the BLE Inquiry.
2909**
2910** Returns void
2911**
2912*******************************************************************************/
2913void 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 Arora11e6c292014-09-29 18:43:27 -07002925 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 Batta7fa4fba2014-04-16 16:50:09 -07002932
The Android Open Source Project5738f832012-12-12 16:00:35 -08002933 /* If we have a callback registered for inquiry complete, call it */
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07002934 BTM_TRACE_DEBUG ("BTM Inq Compl Callback: status 0x%02x, num results %d",
The Android Open Source Project5738f832012-12-12 16:00:35 -08002935 p_inq->inq_cmpl_info.status, p_inq->inq_cmpl_info.num_resp);
2936
The Android Open Source Project5738f832012-12-12 16:00:35 -08002937 btm_process_inq_complete(HCI_SUCCESS, (UINT8)(p_inq->inqparms.mode & BTM_BLE_INQUIRY_MASK));
The Android Open Source Project5738f832012-12-12 16:00:35 -08002938}
2939
2940/*******************************************************************************
2941**
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002942** Function btm_ble_stop_observe
2943**
2944** Description Stop the BLE Observe.
2945**
2946** Returns void
2947**
2948*******************************************************************************/
2949static 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*******************************************************************************/
2976typedef BOOLEAN (BTM_TOPOLOGY_FUNC_PTR)(tBTM_BLE_STATE_MASK);
2977static 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 Calloji444a8da2015-03-06 10:38:22 -08002998 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 Batta7fa4fba2014-04-16 16:50:09 -07003002 default:
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07003003 BTM_TRACE_ERROR("unknown adv event : %d", adv_evt);
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07003004 break;
3005 }
3006
3007 return rt;
3008}
3009
3010
3011/*******************************************************************************
3012**
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003013** Function btm_ble_start_adv
3014**
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07003015** Description start the BLE advertising.
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003016**
3017** Returns void
3018**
3019*******************************************************************************/
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07003020tBTM_STATUS btm_ble_start_adv(void)
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003021{
3022 tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var;
3023 tBTM_STATUS rt = BTM_NO_RESOURCES;
3024
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07003025 if (!btm_ble_adv_states_operation (btm_ble_topology_check, p_cb->evt_type))
3026 return BTM_WRONG_MODE;
3027
Satya Calloji444a8da2015-03-06 10:38:22 -08003028#if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE)
Satya Calloji877123f2015-04-23 23:39:49 -07003029 /* 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 Calloji444a8da2015-03-06 10:38:22 -08003034#endif
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07003035 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 Battaead3cde2013-02-05 15:22:31 -08003041 if (btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_ENABLE))
3042 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003043 p_cb->adv_mode = BTM_BLE_ADV_ENABLE;
Satya Calloji444a8da2015-03-06 10:38:22 -08003044 btm_ble_adv_states_operation(btm_ble_set_topology_mask, p_cb->evt_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003045 rt = BTM_SUCCESS;
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07003046 }
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 Battaead3cde2013-02-05 15:22:31 -08003053}
Satya Calloji444a8da2015-03-06 10:38:22 -08003054
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003055/*******************************************************************************
3056**
The Android Open Source Project5738f832012-12-12 16:00:35 -08003057** Function btm_ble_stop_adv
3058**
3059** Description Stop the BLE advertising.
3060**
3061** Returns void
3062**
3063*******************************************************************************/
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07003064tBTM_STATUS btm_ble_stop_adv(void)
The Android Open Source Project5738f832012-12-12 16:00:35 -08003065{
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003066 tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var;
3067 tBTM_STATUS rt = BTM_SUCCESS;
The Android Open Source Project5738f832012-12-12 16:00:35 -08003068
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003069 if (p_cb->adv_mode == BTM_BLE_ADV_ENABLE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08003070 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003071 if (btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_DISABLE))
3072 {
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07003073 p_cb->fast_adv_on = FALSE;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003074 p_cb->adv_mode = BTM_BLE_ADV_DISABLE;
3075 btm_cb.ble_ctr_cb.wl_state &= ~BTM_BLE_WL_ADV;
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07003076
3077 /* clear all adv states */
3078 btm_ble_clear_topology_mask (BTM_BLE_STATE_ALL_ADV_MASK);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003079 }
3080 else
3081 rt = BTM_NO_RESOURCES;
The Android Open Source Project5738f832012-12-12 16:00:35 -08003082 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003083 return rt;
The Android Open Source Project5738f832012-12-12 16:00:35 -08003084}
3085
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07003086
3087/*******************************************************************************
3088**
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07003089** Function btm_ble_start_slow_adv
3090**
3091** Description Restart adv with slow adv interval
3092**
3093** Returns void
3094**
3095*******************************************************************************/
3096static void btm_ble_start_slow_adv (void)
3097{
Satya Calloji444a8da2015-03-06 10:38:22 -08003098 tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var;
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07003099
3100 if (p_cb->adv_mode == BTM_BLE_ADV_ENABLE)
3101 {
Satya Calloji444a8da2015-03-06 10:38:22 -08003102 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 Batta7fa4fba2014-04-16 16:50:09 -07003107 btm_ble_stop_adv();
3108
Satya Calloji444a8da2015-03-06 10:38:22 -08003109 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 Batta7fa4fba2014-04-16 16:50:09 -07003117
3118 btm_ble_start_adv();
3119 }
3120}
The Android Open Source Project5738f832012-12-12 16:00:35 -08003121/*******************************************************************************
3122**
3123** Function btm_ble_timeout
3124**
3125** Description Called when BTM BLE inquiry timer expires
3126**
3127** Returns void
3128**
3129*******************************************************************************/
3130void btm_ble_timeout(TIMER_LIST_ENT *p_tle)
3131{
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07003132 BTM_TRACE_EVENT ("btm_ble_timeout");
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07003133
The Android Open Source Project5738f832012-12-12 16:00:35 -08003134 switch (p_tle->event)
3135 {
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07003136 case BTU_TTYPE_BLE_OBSERVE:
3137 btm_ble_stop_observe();
3138 break;
3139
The Android Open Source Project5738f832012-12-12 16:00:35 -08003140 case BTU_TTYPE_BLE_INQUIRY:
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07003141 btm_ble_stop_inquiry();
The Android Open Source Project5738f832012-12-12 16:00:35 -08003142 break;
3143
3144 case BTU_TTYPE_BLE_GAP_LIM_DISC:
3145 /* lim_timeout expiried, limited discovery should exit now */
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07003146 btm_cb.btm_inq_vars.discoverable_mode &= ~BTM_BLE_LIMITED_DISCOVERABLE;
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07003147 btm_ble_set_adv_flag(btm_cb.btm_inq_vars.connectable_mode, btm_cb.btm_inq_vars.discoverable_mode);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003148 break;
3149
3150 case BTU_TTYPE_BLE_RANDOM_ADDR:
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003151 if (btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type == BLE_ADDR_RANDOM)
The Android Open Source Project5738f832012-12-12 16:00:35 -08003152 {
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -07003153 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 Wanga6ce7752014-05-20 06:30:32 +00003158 else
3159 {
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -07003160 if (BTM_BleMaxMultiAdvInstanceCount() > 0)
3161 btm_ble_multi_adv_configure_rpa((tBTM_BLE_MULTI_ADV_INST*)p_tle->param);
Wei Wanga6ce7752014-05-20 06:30:32 +00003162 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08003163 }
3164 break;
3165
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07003166 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 Project5738f832012-12-12 16:00:35 -08003174 }
3175}
3176
The Android Open Source Project5738f832012-12-12 16:00:35 -08003177
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*******************************************************************************/
3189void btm_ble_read_remote_features_complete(UINT8 *p)
3190{
3191 tACL_CONN *p_acl_cb = &btm_cb.acl_db[0];
The Android Open Source Project5738f832012-12-12 16:00:35 -08003192 UINT16 handle;
Priti Aghera9c29d082014-09-02 15:41:56 -07003193 UINT8 status;
Andre Eisenbach3aa60542013-03-22 18:00:51 -07003194 int xx;
The Android Open Source Project5738f832012-12-12 16:00:35 -08003195
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07003196 BTM_TRACE_EVENT ("btm_ble_read_remote_features_complete ");
The Android Open Source Project5738f832012-12-12 16:00:35 -08003197
Priti Aghera9c29d082014-09-02 15:41:56 -07003198 STREAM_TO_UINT8(status, p);
Satya Calloji444a8da2015-03-06 10:38:22 -08003199
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 Project5738f832012-12-12 16:00:35 -08003203 {
Priti Aghera9c29d082014-09-02 15:41:56 -07003204 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 Project5738f832012-12-12 16:00:35 -08003208 {
Priti Aghera9c29d082014-09-02 15:41:56 -07003209 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 Viswanadham7ae25152014-09-10 17:08:11 -07003212 /*notify link up here */
Priti Aghera9c29d082014-09-02 15:41:56 -07003213 l2cble_notify_le_connection (p_acl_cb->remote_addr);
3214 break;
3215 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08003216 }
3217 }
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07003218
The Android Open Source Project5738f832012-12-12 16:00:35 -08003219}
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*******************************************************************************/
3230void 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 Battaead3cde2013-02-05 15:22:31 -08003241
3242/*******************************************************************************
3243**
3244** Function btm_ble_dir_adv_tout
3245**
3246** Description when directed adv time out
3247**
3248** Returns void
3249**
3250*******************************************************************************/
3251void 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 Calloji444a8da2015-03-06 10:38:22 -08003261** 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*******************************************************************************/
3268BOOLEAN 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*******************************************************************************/
3284BOOLEAN 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*******************************************************************************/
3300void 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*******************************************************************************/
3335void 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 Project5738f832012-12-12 16:00:35 -08003364** Function btm_ble_init
3365**
3366** Description Initialize the control block variable values.
3367**
3368** Returns void
3369**
3370*******************************************************************************/
3371void btm_ble_init (void)
3372{
3373 tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
3374
Satya Callojib151a432015-05-07 14:06:37 -07003375 BTM_TRACE_DEBUG("%s", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003376
3377 memset(p_cb, 0, sizeof(tBTM_BLE_CB));
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -07003378 memset(&(btm_cb.cmn_ble_vsc_cb), 0 , sizeof(tBTM_BLE_VSC_CB));
Satya Calloji3f24f462014-09-16 22:44:43 -07003379 btm_cb.cmn_ble_vsc_cb.values_read = FALSE;
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07003380 p_cb->cur_states = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08003381
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 Calloji877123f2015-04-23 23:39:49 -07003391 p_cb->scan_int = p_cb->scan_win = BTM_BLE_SCAN_PARAM_UNDEF;
The Android Open Source Project5738f832012-12-12 16:00:35 -08003392
Andre Eisenbach6975b4d2013-08-05 16:55:38 -07003393 p_cb->inq_var.evt_type = BTM_BLE_NON_CONNECT_EVT;
Satya Callojic4e25962014-05-10 23:46:24 -07003394
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -07003395#if BLE_VND_INCLUDED == FALSE
Satya Calloji1a9247a2014-06-05 13:15:15 -07003396 btm_ble_adv_filter_init();
3397#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08003398}
3399
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07003400/*******************************************************************************
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*******************************************************************************/
3410BOOLEAN btm_ble_topology_check(tBTM_BLE_STATE_MASK request_state_mask)
3411{
3412 BOOLEAN rt = FALSE;
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07003413
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 Nanavati5344d6d2014-05-04 00:46:57 -07003424 BTM_TRACE_ERROR("illegal state requested: %d", request_state_mask);
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07003425 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 Johnsona87c8212014-10-28 17:59:13 -07003438 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 Batta7fa4fba2014-04-16 16:50:09 -07003441 {
Sharvil Nanavati5344d6d2014-05-04 00:46:57 -07003442 BTM_TRACE_ERROR("state requested not supported: %d", request_state);
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07003443 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 Johnsona87c8212014-10-28 17:59:13 -07003458 if (!BTM_LE_STATES_SUPPORTED(ble_supported_states, mask, offset))
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07003459 {
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 Project5738f832012-12-12 16:00:35 -08003472#endif /* BLE_INCLUDED */