blob: 86a7db22e9c4c73fc63cb41b1ae81b768ceabbaa [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
2 *
3 * Copyright (C) 2003-2012 Broadcom Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19/******************************************************************************
20 *
21 * This file contains the action functions for device manager state
22 * machine.
23 *
24 ******************************************************************************/
25
Mike J. Chena89616a2014-02-11 16:23:31 -080026#include "bt_target.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080027#include "bt_types.h"
28#include "gki.h"
29#include "bd.h"
30#include "bta_sys.h"
31#include "bta_api.h"
32#include "bta_dm_int.h"
33#include "bta_dm_co.h"
34#include "btm_api.h"
35#include "btm_int.h"
36#include "btu.h"
37#include "sdp_api.h"
38#include "l2c_api.h"
39#include "wbt_api.h"
40#include "utl.h"
41#include <string.h>
42
Mike J. Chena02a48c2014-01-31 17:49:43 -080043#if (GAP_INCLUDED == TRUE)
44#include "gap_api.h"
45#endif
46
The Android Open Source Project5738f832012-12-12 16:00:35 -080047static void bta_dm_inq_results_cb (tBTM_INQ_RESULTS *p_inq, UINT8 *p_eir);
48static void bta_dm_inq_cmpl_cb (void * p_result);
49static void bta_dm_service_search_remname_cback (BD_ADDR bd_addr, DEV_CLASS dc, BD_NAME bd_name);
50static void bta_dm_remname_cback (tBTM_REMOTE_DEV_NAME *p_remote_name);
51static void bta_dm_find_services ( BD_ADDR bd_addr);
52static void bta_dm_discover_next_device(void);
53static void bta_dm_sdp_callback (UINT16 sdp_status);
54static UINT8 bta_dm_authorize_cback (BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name, UINT8 *service_name, UINT8 service_id, BOOLEAN is_originator);
55static UINT8 bta_dm_pin_cback (BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name);
56static UINT8 bta_dm_link_key_request_cback (BD_ADDR bd_addr, LINK_KEY key);
57static UINT8 bta_dm_new_link_key_cback(BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name, LINK_KEY key, UINT8 key_type);
58static UINT8 bta_dm_authentication_complete_cback(BD_ADDR bd_addr, DEV_CLASS dev_class,BD_NAME bd_name, int result);
59static void bta_dm_local_name_cback(BD_ADDR bd_addr);
60static BOOLEAN bta_dm_check_av(UINT16 event);
61#if (BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
62static void bta_dm_bl_change_cback (tBTM_BL_EVENT_DATA *p_data);
63#else
Andre Eisenbach3aa60542013-03-22 18:00:51 -070064static void bta_dm_acl_change_cback (BD_ADDR p_bda, DEV_CLASS p_dc, BD_NAME p_bdn, UINT8 *features, BOOLEAN is_new);
The Android Open Source Project5738f832012-12-12 16:00:35 -080065#endif
66static void bta_dm_policy_cback(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
67
68/* Extended Inquiry Response */
69static UINT8 bta_dm_sp_cback (tBTM_SP_EVT event, tBTM_SP_EVT_DATA *p_data);
70
71#if (BTM_EIR_SERVER_INCLUDED == TRUE)
72static void bta_dm_set_eir (char *local_name);
73#endif /* BTM_EIR_SERVER_INCLUDED */
74
75#if (BTM_EIR_CLIENT_INCLUDED == TRUE)
76static void bta_dm_eir_search_services( tBTM_INQ_RESULTS *p_result,
77 tBTA_SERVICE_MASK *p_services_to_search,
78 tBTA_SERVICE_MASK *p_services_found);
79#endif /* BTM_EIR_CLIENT_INCLUDED */
80
81static void bta_dm_rssi_cback (tBTM_RSSI_RESULTS *p_result);
82static void bta_dm_signal_strength_timer_cback (TIMER_LIST_ENT *p_tle);
83static void bta_dm_link_quality_cback (tBTM_LINK_QUALITY_RESULTS *p_result);
84static void bta_dm_search_timer_cback (TIMER_LIST_ENT *p_tle);
85static void bta_dm_disable_timer_cback (TIMER_LIST_ENT *p_tle);
86static void bta_dm_disable_conn_down_timer_cback (TIMER_LIST_ENT *p_tle);
87static void bta_dm_rm_cback(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
88static void bta_dm_adjust_roles(BOOLEAN delay_role_switch);
89static char *bta_dm_get_remname(void);
90static void bta_dm_bond_cancel_complete_cback(tBTM_STATUS result);
91
92static BOOLEAN bta_dm_read_remote_device_name (BD_ADDR bd_addr);
93static void bta_dm_discover_device(BD_ADDR remote_bd_addr);
94
95static void bta_dm_sys_hw_cback( tBTA_SYS_HW_EVT status );
96
97static BOOLEAN bta_dm_dev_blacklisted_for_switch (BD_ADDR remote_bd_addr);
98static void bta_dm_delay_role_switch_cback (TIMER_LIST_ENT *p_tle);
99
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800100static void bta_dm_disable_search_and_disc(void);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800101#if ((defined BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
102 #if ((defined SMP_INCLUDED) && (SMP_INCLUDED == TRUE))
103static UINT8 bta_dm_ble_smp_cback (tBTM_LE_EVT event, BD_ADDR bda, tBTM_LE_EVT_DATA *p_data);
104 #endif
105static void bta_dm_ble_id_key_cback (UINT8 key_type, tBTM_BLE_LOCAL_KEYS *p_key);
106 #if ((defined BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE))
Andre Eisenbache1202ca2013-05-15 04:55:08 -0700107static void bta_dm_gattc_register(void);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800108static void btm_dm_start_gatt_discovery ( BD_ADDR bd_addr);
109static void bta_dm_cancel_gatt_discovery(BD_ADDR bd_addr);
110static void bta_dm_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC *p_data);
111 #endif
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800112static void bta_dm_observe_results_cb (tBTM_INQ_RESULTS *p_inq, UINT8 *p_eir);
113static void bta_dm_observe_cmpl_cb (void * p_result);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800114
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800115#ifndef BTA_DM_BLE_ADV_CHNL_MAP
116#define BTA_DM_BLE_ADV_CHNL_MAP (BTM_BLE_ADV_CHNL_37|BTM_BLE_ADV_CHNL_38|BTM_BLE_ADV_CHNL_39)
117#endif
118#endif
Matthew Xief751b012013-08-13 20:05:34 -0700119static void bta_dm_remove_sec_dev_entry(BD_ADDR remote_bd_addr);
120
The Android Open Source Project5738f832012-12-12 16:00:35 -0800121extern void sdpu_uuid16_to_uuid128(UINT16 uuid16, UINT8* p_uuid128);
122
123const UINT16 bta_service_id_to_uuid_lkup_tbl [BTA_MAX_SERVICE_ID] =
124{
125 UUID_SERVCLASS_PNP_INFORMATION, /* Reserved */
126 UUID_SERVCLASS_SERIAL_PORT, /* BTA_SPP_SERVICE_ID */
127 UUID_SERVCLASS_DIALUP_NETWORKING, /* BTA_DUN_SERVICE_ID */
128 UUID_SERVCLASS_AUDIO_SOURCE, /* BTA_A2DP_SOURCE_SERVICE_ID */
129 UUID_SERVCLASS_LAN_ACCESS_USING_PPP, /* BTA_LAP_SERVICE_ID */
130 UUID_SERVCLASS_HEADSET, /* BTA_HSP_HS_SERVICE_ID */
131 UUID_SERVCLASS_HF_HANDSFREE, /* BTA_HFP_HS_SERVICE_ID */
132 UUID_SERVCLASS_OBEX_OBJECT_PUSH, /* BTA_OPP_SERVICE_ID */
133 UUID_SERVCLASS_OBEX_FILE_TRANSFER, /* BTA_FTP_SERVICE_ID */
134 UUID_SERVCLASS_CORDLESS_TELEPHONY, /* BTA_CTP_SERVICE_ID */
135 UUID_SERVCLASS_INTERCOM, /* BTA_ICP_SERVICE_ID */
136 UUID_SERVCLASS_IRMC_SYNC, /* BTA_SYNC_SERVICE_ID */
137 UUID_SERVCLASS_DIRECT_PRINTING, /* BTA_BPP_SERVICE_ID */
138 UUID_SERVCLASS_IMAGING_RESPONDER, /* BTA_BIP_SERVICE_ID */
139 UUID_SERVCLASS_PANU, /* BTA_PANU_SERVICE_ID */
140 UUID_SERVCLASS_NAP, /* BTA_NAP_SERVICE_ID */
141 UUID_SERVCLASS_GN, /* BTA_GN_SERVICE_ID */
142 UUID_SERVCLASS_SAP, /* BTA_SAP_SERVICE_ID */
143 UUID_SERVCLASS_AUDIO_SINK, /* BTA_A2DP_SERVICE_ID */
144 UUID_SERVCLASS_AV_REMOTE_CONTROL, /* BTA_AVRCP_SERVICE_ID */
145 UUID_SERVCLASS_HUMAN_INTERFACE, /* BTA_HID_SERVICE_ID */
146 UUID_SERVCLASS_VIDEO_SINK, /* BTA_VDP_SERVICE_ID */
147 UUID_SERVCLASS_PBAP_PSE, /* BTA_PBAP_SERVICE_ID */
148 UUID_SERVCLASS_HEADSET_AUDIO_GATEWAY, /* BTA_HSP_SERVICE_ID */
149 UUID_SERVCLASS_AG_HANDSFREE, /* BTA_HFP_SERVICE_ID */
150 UUID_SERVCLASS_MESSAGE_ACCESS, /* BTA_MAP_SERVICE_ID */
151 UUID_SERVCLASS_MESSAGE_NOTIFICATION, /* BTA_MN_SERVICE_ID */
152 UUID_SERVCLASS_HDP_PROFILE, /* BTA_HDP_SERVICE_ID */
153 UUID_SERVCLASS_PBAP_PCE /* BTA_PCE_SERVICE_ID */
154#if BLE_INCLUDED && BTA_GATT_INCLUDED
155 ,UUID_PROTOCOL_ATT /* BTA_GATT_SERVICE_ID */
156#endif
157};
158
159/*
160 * NOTE : The number of element in bta_service_id_to_btm_srv_id_lkup_tbl should be matching with
161 * the value BTA_MAX_SERVICE_ID in bta_api.h
162 *
163 * i.e., If you add new Service ID for BTA, the correct security ID of the new service
164 * from Security service definitions (btm_api.h) should be added to this lookup table.
165 */
166const UINT32 bta_service_id_to_btm_srv_id_lkup_tbl [BTA_MAX_SERVICE_ID] =
167{
168 0, /* Reserved */
169 BTM_SEC_SERVICE_SERIAL_PORT, /* BTA_SPP_SERVICE_ID */
170 BTM_SEC_SERVICE_DUN, /* BTA_DUN_SERVICE_ID */
171 BTM_SEC_SERVICE_AVDTP, /* BTA_AUDIO_SOURCE_SERVICE_ID */
172 BTM_SEC_SERVICE_LAN_ACCESS, /* BTA_LAP_SERVICE_ID */
173 BTM_SEC_SERVICE_HEADSET_AG, /* BTA_HSP_SERVICE_ID */
174 BTM_SEC_SERVICE_AG_HANDSFREE, /* BTA_HFP_SERVICE_ID */
175 BTM_SEC_SERVICE_OBEX, /* BTA_OPP_SERVICE_ID */
176 BTM_SEC_SERVICE_OBEX_FTP, /* BTA_FTP_SERVICE_ID */
177 BTM_SEC_SERVICE_CORDLESS, /* BTA_CTP_SERVICE_ID */
178 BTM_SEC_SERVICE_INTERCOM, /* BTA_ICP_SERVICE_ID */
179 BTM_SEC_SERVICE_IRMC_SYNC, /* BTA_SYNC_SERVICE_ID */
180 BTM_SEC_SERVICE_BPP_JOB, /* BTA_BPP_SERVICE_ID */
181 BTM_SEC_SERVICE_BIP, /* BTA_BIP_SERVICE_ID */
182 BTM_SEC_SERVICE_BNEP_PANU, /* BTA_PANU_SERVICE_ID */
183 BTM_SEC_SERVICE_BNEP_NAP, /* BTA_NAP_SERVICE_ID */
184 BTM_SEC_SERVICE_BNEP_GN, /* BTA_GN_SERVICE_ID */
185 BTM_SEC_SERVICE_SAP, /* BTA_SAP_SERVICE_ID */
186 BTM_SEC_SERVICE_AVDTP, /* BTA_A2DP_SERVICE_ID */
187 BTM_SEC_SERVICE_AVCTP, /* BTA_AVRCP_SERVICE_ID */
Andre Eisenbach2e7fa682013-08-08 15:42:48 -0700188 BTM_SEC_SERVICE_HIDH_SEC_CTRL, /* BTA_HID_SERVICE_ID */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800189 BTM_SEC_SERVICE_AVDTP, /* BTA_VDP_SERVICE_ID */
190 BTM_SEC_SERVICE_PBAP, /* BTA_PBAP_SERVICE_ID */
191 BTM_SEC_SERVICE_HEADSET, /* BTA_HSP_HS_SERVICE_ID */
192 BTM_SEC_SERVICE_HF_HANDSFREE, /* BTA_HFP_HS_SERVICE_ID */
193 BTM_SEC_SERVICE_MAP, /* BTA_MAP_SERVICE_ID */
194 BTM_SEC_SERVICE_MAP, /* BTA_MN_SERVICE_ID */
195 BTM_SEC_SERVICE_HDP_SNK, /* BTA_HDP_SERVICE_ID */
196 BTM_SEC_SERVICE_PBAP /* BTA_PCE_SERVICE_ID */
197#if BLE_INCLUDED && BTA_GATT_INCLUDED
198 ,BTM_SEC_SERVICE_ATT /* BTA_GATT_SERVICE_ID */
199#endif
Andre Eisenbach6975b4d2013-08-05 16:55:38 -0700200
The Android Open Source Project5738f832012-12-12 16:00:35 -0800201};
202
203/* bta security callback */
204const tBTM_APPL_INFO bta_security =
205{
206 &bta_dm_authorize_cback,
207 &bta_dm_pin_cback,
208 &bta_dm_new_link_key_cback,
209 &bta_dm_link_key_request_cback,
210 &bta_dm_authentication_complete_cback,
211 NULL,
212 &bta_dm_bond_cancel_complete_cback,
213#if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE)
214 &bta_dm_sp_cback
215#else
216 NULL
217#endif
218#if BLE_INCLUDED == TRUE
219#if SMP_INCLUDED == TRUE
220 ,&bta_dm_ble_smp_cback
221#endif
222 ,&bta_dm_ble_id_key_cback
223#endif
224
225};
226
227/* TBD... To be moved to some conf file..? */
228#define BTA_DM_MAX_ROLE_SWITCH_BLACKLIST_COUNT 5
229const tBTA_DM_LMP_VER_INFO bta_role_switch_blacklist[BTA_DM_MAX_ROLE_SWITCH_BLACKLIST_COUNT] =
230{
231 {0x000F,0x2000,0x04},
232 {0x00,0x00,0x00},
233 {0x00,0x00,0x00},
234 {0x00,0x00,0x00},
235 {0x00,0x00,0x00}
236};
237
238#define MAX_DISC_RAW_DATA_BUF (4096)
239UINT8 g_disc_raw_data_buf[MAX_DISC_RAW_DATA_BUF];
240
241/*******************************************************************************
242**
243** Function bta_dm_app_ready_timer_cback
244**
245** Description allow sending EIR to controller
246**
247**
248** Returns void
249**
250*******************************************************************************/
251#if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&(BTA_EIR_CANNED_UUID_LIST != TRUE)
252static void bta_dm_app_ready_timer_cback (TIMER_LIST_ENT *p_tle)
253{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -0800254 UNUSED(p_tle);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800255 bta_dm_set_eir (NULL);
256}
257#else
258#define bta_dm_app_ready_timer_cback (x)
259#endif
260
261/*******************************************************************************
262**
263** Function bta_dm_enable
264**
265** Description Initialises the BT device manager
266**
267**
268** Returns void
269**
270*******************************************************************************/
271void bta_dm_enable(tBTA_DM_MSG *p_data)
272{
273 tBTA_SYS_HW_MSG *sys_enable_event;
274 tBTA_DM_SEC sec_event;
275
The Android Open Source Project5738f832012-12-12 16:00:35 -0800276 /* if already in use, return an error */
277 if( bta_dm_cb.is_bta_dm_active == TRUE )
278 {
279 APPL_TRACE_WARNING0("bta_dm_enable - device already started by another application");
280 memset(&sec_event.enable, 0, sizeof ( tBTA_DM_ENABLE ));
281 sec_event.enable.status = BTA_FAILURE;
282 if( p_data->enable.p_sec_cback != NULL )
283 p_data->enable.p_sec_cback (BTA_DM_ENABLE_EVT, &sec_event);
284 return;
285 }
286
The Android Open Source Project5738f832012-12-12 16:00:35 -0800287 /* first, register our callback to SYS HW manager */
288 bta_sys_hw_register( BTA_SYS_HW_BLUETOOTH, bta_dm_sys_hw_cback );
289
290 /* make sure security callback is saved - if no callback, do not erase the previous one,
291 it could be an error recovery mechanism */
292 if( p_data->enable.p_sec_cback != NULL )
293 bta_dm_cb.p_sec_cback = p_data->enable.p_sec_cback;
294 /* notify BTA DM is now active */
295 bta_dm_cb.is_bta_dm_active = TRUE;
296
297 /* send a message to BTA SYS */
298 if ((sys_enable_event = (tBTA_SYS_HW_MSG *) GKI_getbuf(sizeof(tBTA_SYS_HW_MSG))) != NULL)
299 {
300 sys_enable_event->hdr.event = BTA_SYS_API_ENABLE_EVT;
301 sys_enable_event->hw_module = BTA_SYS_HW_BLUETOOTH;
302
303 bta_sys_sendmsg(sys_enable_event);
304
305 }
306
307
308
309}
310
311
312
313/*******************************************************************************
314**
315** Function bta_dm_sys_hw_cback
316**
317** Description callback register to SYS to get HW status updates
318**
319**
320** Returns void
321**
322*******************************************************************************/
323static void bta_dm_sys_hw_cback( tBTA_SYS_HW_EVT status )
324{
325 DEV_CLASS dev_class;
326 tBTA_DM_SEC_CBACK *temp_cback;
327#if BLE_INCLUDED == TRUE
328 UINT8 key_mask = 0;
329 BT_OCTET16 er;
330 tBTA_BLE_LOCAL_ID_KEYS id_key;
331 tBT_UUID app_uuid = {LEN_UUID_128,{0}};
332#endif
333 APPL_TRACE_DEBUG1(" bta_dm_sys_hw_cback with event: %i" , status );
334
335 /* On H/W error evt, report to the registered DM application callback */
336 if (status == BTA_SYS_HW_ERROR_EVT) {
337 if( bta_dm_cb.p_sec_cback != NULL )
338 bta_dm_cb.p_sec_cback(BTA_DM_HW_ERROR_EVT, NULL);
339 return;
340 }
341 if( status == BTA_SYS_HW_OFF_EVT )
342 {
343 if( bta_dm_cb.p_sec_cback != NULL )
344 bta_dm_cb.p_sec_cback(BTA_DM_DISABLE_EVT, NULL);
345
346 /* reinitialize the control block */
347 memset(&bta_dm_cb, 0, sizeof(bta_dm_cb));
348
349 /* unregister from SYS */
350 bta_sys_hw_unregister( BTA_SYS_HW_BLUETOOTH );
351 /* notify BTA DM is now unactive */
352 bta_dm_cb.is_bta_dm_active = FALSE;
353 }
354 else
355 if( status == BTA_SYS_HW_ON_EVT )
356 {
357 /* FIXME: We should not unregister as the SYS shall invoke this callback on a H/W error.
358 * We need to revisit when this platform has more than one BLuetooth H/W chip */
359 //bta_sys_hw_unregister( BTA_SYS_HW_BLUETOOTH);
360
361 /* save security callback */
362 temp_cback = bta_dm_cb.p_sec_cback;
363 /* make sure the control block is properly initialized */
364 memset(&bta_dm_cb, 0, sizeof(bta_dm_cb));
365 /* and retrieve the callback */
366 bta_dm_cb.p_sec_cback=temp_cback;
367 bta_dm_cb.is_bta_dm_active = TRUE;
368
369 /* hw is ready, go on with BTA DM initialization */
370 memset(&bta_dm_search_cb, 0x00, sizeof(bta_dm_search_cb));
371 memset(&bta_dm_conn_srvcs, 0x00, sizeof(bta_dm_conn_srvcs));
372 memset(&bta_dm_di_cb, 0, sizeof(tBTA_DM_DI_CB));
373
374 memcpy(dev_class, bta_dm_cfg.dev_class, sizeof(dev_class));
375 BTM_SetDeviceClass (dev_class);
376
377#if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
378 /* load BLE local information: ID keys, ER if available */
379 bta_dm_co_ble_load_local_keys(&key_mask, er, &id_key);
380
381 if (key_mask & BTA_BLE_LOCAL_KEY_TYPE_ER)
382 {
383 BTM_BleLoadLocalKeys(BTA_BLE_LOCAL_KEY_TYPE_ER, (tBTM_BLE_LOCAL_KEYS *)&er);
384 }
385 if (key_mask & BTA_BLE_LOCAL_KEY_TYPE_ID)
386 {
387 BTM_BleLoadLocalKeys(BTA_BLE_LOCAL_KEY_TYPE_ID, (tBTM_BLE_LOCAL_KEYS *)&id_key);
388 }
Mike J. Chena89616a2014-02-11 16:23:31 -0800389#if ((defined BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE))
Andre Eisenbach6975b4d2013-08-05 16:55:38 -0700390 bta_dm_search_cb.conn_id = BTA_GATT_INVALID_CONN_ID;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800391#endif
Mike J. Chena89616a2014-02-11 16:23:31 -0800392#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -0800393
394 BTM_SecRegister((tBTM_APPL_INFO*)&bta_security);
395 BTM_SetDefaultLinkSuperTout(bta_dm_cfg.link_timeout);
396 BTM_WritePageTimeout(bta_dm_cfg.page_timeout);
397 bta_dm_cb.cur_policy = bta_dm_cfg.policy_settings;
398 BTM_SetDefaultLinkPolicy(bta_dm_cb.cur_policy);
399#if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
400 BTM_RegBusyLevelNotif (bta_dm_bl_change_cback, NULL, BTM_BL_UPDATE_MASK|BTM_BL_ROLE_CHG_MASK);
401#else
402 BTM_AclRegisterForChanges(bta_dm_acl_change_cback);
403#endif
404 /* Earlier, we used to invoke BTM_ReadLocalAddr which was just copying the bd_addr
405 from the control block and invoking the callback which was sending the DM_ENABLE_EVT.
406 But then we have a few HCI commands being invoked above which were still in progress
407 when the ENABLE_EVT was sent. So modified this to fetch the local name which forces
408 the DM_ENABLE_EVT to be sent only after all the init steps are complete */
409 BTM_ReadLocalDeviceNameFromController((tBTM_CMPL_CB *)bta_dm_local_name_cback);
410
411 bta_sys_rm_register((tBTA_SYS_CONN_CBACK*)bta_dm_rm_cback);
412
413 /* initialize bluetooth low power manager */
414 bta_dm_init_pm();
415
416 bta_sys_policy_register((tBTA_SYS_CONN_CBACK*)bta_dm_policy_cback);
417
418
419 // BLUEDROID REMOVE ??
420#if 0
421#if 1
422 /* Create broadcom primary DI record */
423 if(WBT_ExtCreateRecord())
424 {
425#if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&( BTA_EIR_CANNED_UUID_LIST != TRUE )
426 /* while app_ready_timer is running, BTA DM doesn't send EIR to controller */
427 bta_dm_cb.app_ready_timer.p_cback = (TIMER_CBACK*)&bta_dm_app_ready_timer_cback;
428 bta_sys_start_timer(&bta_dm_cb.app_ready_timer, 0, 100);
429
430 bta_sys_add_uuid(UUID_SERVCLASS_PNP_INFORMATION);
431#endif
432 bta_dm_di_cb.di_handle[bta_dm_di_cb.di_num] = 0; /* primary DI record */
433 bta_dm_di_cb.di_num ++;
434 }
435#else /* Eventually implement pin code */
436 if (WBT_ExtCreateRecord())
437 WBT_ExtAddPinCode();
438#endif
439#endif
Andre Eisenbache1202ca2013-05-15 04:55:08 -0700440#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
441 memset (&app_uuid.uu.uuid128, 0x87, LEN_UUID_128);
442 bta_dm_gattc_register();
443#endif
444
The Android Open Source Project5738f832012-12-12 16:00:35 -0800445 }
446 else
447 APPL_TRACE_DEBUG0(" --- ignored event");
448
449}
450
451
452/*******************************************************************************
453**
454** Function bta_dm_disable
455**
456** Description Disables the BT device manager
457**
458**
459** Returns void
460**
461*******************************************************************************/
462void bta_dm_disable (tBTA_DM_MSG *p_data)
463{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -0800464 UNUSED(p_data);
465
The Android Open Source Project5738f832012-12-12 16:00:35 -0800466 /* Set l2cap idle timeout to 0 (so BTE immediately disconnects ACL link after last channel is closed) */
467 L2CA_SetIdleTimeoutByBdAddr((UINT8 *)BT_BD_ANY, 0);
468
469 /* disable all active subsystems */
470 bta_sys_disable(BTA_SYS_HW_BLUETOOTH);
471
472 BTM_SetDiscoverability(BTM_NON_DISCOVERABLE, 0, 0);
473 BTM_SetConnectability(BTM_NON_CONNECTABLE, 0, 0);
474
475 bta_dm_disable_pm();
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800476 bta_dm_disable_search_and_disc();
The Android Open Source Project5738f832012-12-12 16:00:35 -0800477 bta_dm_cb.disabling = TRUE;
478
The Android Open Source Project5738f832012-12-12 16:00:35 -0800479
480 if(BTM_GetNumAclLinks()==0)
481 {
482#if (defined(BTA_DISABLE_DELAY) && BTA_DISABLE_DELAY > 0)
483 /* If BTA_DISABLE_DELAY is defined and greater than zero, then delay the shutdown by
484 * BTA_DISABLE_DELAY milliseconds
485 */
486 APPL_TRACE_WARNING2("%s BTA_DISABLE_DELAY set to %d ms",
487 __FUNCTION__, BTA_DISABLE_DELAY);
488 bta_sys_stop_timer(&bta_dm_cb.disable_timer);
489 bta_dm_cb.disable_timer.p_cback = (TIMER_CBACK*)&bta_dm_disable_conn_down_timer_cback;
490 bta_sys_start_timer(&bta_dm_cb.disable_timer, 0, BTA_DISABLE_DELAY);
491#else
492 bta_dm_disable_conn_down_timer_cback(NULL);
493#endif
494 }
495 else
496 {
497 bta_dm_cb.disable_timer.p_cback = (TIMER_CBACK*)&bta_dm_disable_timer_cback;
498 bta_sys_start_timer(&bta_dm_cb.disable_timer, 0, 5000);
499 }
500
501}
502
503/*******************************************************************************
504**
505** Function bta_dm_disable_timer_cback
506**
507** Description Called if the disable timer expires
508** Used to close ACL connections which are still active
509**
510**
511**
512** Returns void
513**
514*******************************************************************************/
515static void bta_dm_disable_timer_cback (TIMER_LIST_ENT *p_tle)
516{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -0800517 UNUSED(p_tle);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800518 UINT8 i;
519
520 APPL_TRACE_EVENT0(" bta_dm_disable_timer_cback ");
521
522 if(BTM_GetNumAclLinks())
523 {
524 for(i=0; i<bta_dm_cb.device_list.count; i++)
525 {
526 btm_remove_acl(bta_dm_cb.device_list.peer_device[i].peer_bdaddr);
527
528 }
529
530 }
531 else
532 {
533 bta_dm_cb.disabling = FALSE;
534
535 bta_sys_remove_uuid(UUID_SERVCLASS_PNP_INFORMATION);
536 bta_dm_cb.p_sec_cback(BTA_DM_DISABLE_EVT, NULL);
537 }
538}
539
540
541
542
543/*******************************************************************************
544**
545** Function bta_dm_set_dev_name
546**
547** Description Sets local device name
548**
549**
550** Returns void
551**
552*******************************************************************************/
553void bta_dm_set_dev_name (tBTA_DM_MSG *p_data)
554{
555
556 BTM_SetLocalDeviceName((char*)p_data->set_name.name);
557#if (BTM_EIR_SERVER_INCLUDED == TRUE)
558 bta_dm_set_eir ((char*)p_data->set_name.name);
559#endif
560}
561
562/*******************************************************************************
563**
564** Function bta_dm_set_visibility
565**
566** Description Sets discoverability, connectability and pairability
567**
568**
569** Returns void
570**
571*******************************************************************************/
572void bta_dm_set_visibility (tBTA_DM_MSG *p_data)
573{
574
575
576 /* set modes for Discoverability and connectability if not ignore */
577 if (p_data->set_visibility.disc_mode != BTA_DM_IGNORE)
578 BTM_SetDiscoverability((UINT8)p_data->set_visibility.disc_mode,
579 bta_dm_cb.inquiry_scan_window,
580 bta_dm_cb.inquiry_scan_interval);
581
582 if (p_data->set_visibility.conn_mode != BTA_DM_IGNORE)
583 BTM_SetConnectability((UINT8)p_data->set_visibility.conn_mode,
584 bta_dm_cb.page_scan_window,
585 bta_dm_cb.page_scan_interval);
586
587 /* Send False or True if not ignore */
588 if (p_data->set_visibility.pair_mode != BTA_DM_IGNORE )
589 {
590
591 if (p_data->set_visibility.pair_mode == BTA_DM_NON_PAIRABLE)
592 bta_dm_cb.disable_pair_mode = TRUE;
593 else
594 bta_dm_cb.disable_pair_mode = FALSE;
595
596 }
597
598 /* Send False or True if not ignore */
599 if (p_data->set_visibility.conn_paired_only != BTA_DM_IGNORE)
600 {
601
602 if (p_data->set_visibility.conn_paired_only == BTA_DM_CONN_ALL)
603 bta_dm_cb.conn_paired_only = FALSE;
604 else
605 bta_dm_cb.conn_paired_only = TRUE;
606
607 }
608
609 /* Change mode if either mode is not ignore */
610 if (p_data->set_visibility.pair_mode != BTA_DM_IGNORE || p_data->set_visibility.conn_paired_only != BTA_DM_IGNORE)
611 BTM_SetPairableMode((BOOLEAN)(!(bta_dm_cb.disable_pair_mode)),bta_dm_cb.conn_paired_only);
612
613}
614
615
616/*******************************************************************************
617**
618** Function bta_dm_set_afhchannels
619**
620** Description This function sets the AFH first and
621** last disable channel, so channels within
622** that range are disabled.
623**
624**
625** Returns void
626**
627*******************************************************************************/
628void bta_dm_set_afhchannels (tBTA_DM_MSG *p_data)
629{
630 BTM_SetAfhChannels(p_data->set_afhchannels.first,p_data->set_afhchannels.last);
631
632}
633
634
635/*******************************************************************************
636**
637** Function bta_dm_vendor_spec_command
638**
639** Description Send a vendor specific command to the controller
640**
641**
642** Returns void
643**
644*******************************************************************************/
645void bta_dm_vendor_spec_command (tBTA_DM_MSG *p_data)
646{
647 tBTM_STATUS status;
648
649 status = BTM_VendorSpecificCommand(p_data->vendor_command.opcode,p_data->vendor_command.param_len,p_data->vendor_command.p_param_buf, p_data->vendor_command.p_cback);
650
651}
652
653
654/*******************************************************************************
655**
656** Function bta_dm_tx_inqpower
657**
658** Description write inquiry tx power.
659**
660**
661** Returns void
662**
663*******************************************************************************/
664void bta_dm_tx_inqpower(tBTA_DM_MSG *p_data)
665{
666 if (BTM_WriteInquiryTxPower (p_data->tx_inq_pwr.tx_power) == BTM_ILLEGAL_VALUE)
667 {
668 APPL_TRACE_ERROR1("Invalid Inquiry Tx Power: %d", p_data->tx_inq_pwr.tx_power);
669 }
670 return;
671}
672
673/*******************************************************************************
674**
675** Function bta_dm_remove_device
676**
677** Description Removes device, Disconnects ACL link if required.
678****
679*******************************************************************************/
680void bta_dm_remove_device (tBTA_DM_MSG *p_data)
681{
682 tBTA_DM_API_REMOVE_DEVICE *p_dev = &p_data->remove_dev;
683 int i;
684 tBTA_DM_SEC sec_event;
685
Zhihai Xubd68d682013-11-15 17:55:46 -0800686#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
687 /* need to remove all pending background connection before unpair */
688 BTA_GATTC_CancelOpen(0, p_dev->bd_addr, FALSE);
689#endif
690
The Android Open Source Project5738f832012-12-12 16:00:35 -0800691 if (BTM_IsAclConnectionUp(p_dev->bd_addr))
692 {
693 /* Take the link down first, and mark the device for removal when disconnected */
694 btm_remove_acl( p_dev->bd_addr) ;
695
696 for(i=0; i<bta_dm_cb.device_list.count; i++)
697 {
698 if(!bdcmp( bta_dm_cb.device_list.peer_device[i].peer_bdaddr, p_dev->bd_addr))
699 break;
700 }
701
702 if(i < bta_dm_cb.device_list.count)
703 {
704 bta_dm_cb.device_list.peer_device[i].conn_state = BTA_DM_UNPAIRING;
705 }
706 }
707 else /* Ok to remove the device in application layer */
708 {
709 BTM_SecDeleteDevice(p_dev->bd_addr);
Zhihai Xubd68d682013-11-15 17:55:46 -0800710#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
711 /* remove all cached GATT information */
712 BTA_GATTC_Refresh(p_dev->bd_addr);
713#endif
714
The Android Open Source Project5738f832012-12-12 16:00:35 -0800715 if( bta_dm_cb.p_sec_cback )
716 {
717 bdcpy(sec_event.link_down.bd_addr, p_dev->bd_addr);
718 /* No connection, set status to success (acl disc code not valid) */
719 sec_event.link_down.status = HCI_SUCCESS;
720 bta_dm_cb.p_sec_cback(BTA_DM_DEV_UNPAIRED_EVT, &sec_event);
721 }
722 }
723}
724
725/*******************************************************************************
726**
727** Function bta_dm_add_device
728**
729** Description This function adds a Link Key to an security database entry.
730** It is normally called during host startup to restore all required information
731** stored in the NVRAM.
732****
733*******************************************************************************/
734void bta_dm_add_device (tBTA_DM_MSG *p_data)
735{
736 tBTA_DM_API_ADD_DEVICE *p_dev = &p_data->add_dev;
737 UINT8 *p_dc = NULL;
738 UINT8 *p_lc = NULL;
739 UINT32 trusted_services_mask[BTM_SEC_SERVICE_ARRAY_SIZE];
740 UINT8 index = 0;
741 UINT8 btm_mask_index = 0;
742
743 memset (trusted_services_mask, 0, sizeof(trusted_services_mask));
744
745 /* If not all zeros, the device class has been specified */
746 if (p_dev->dc_known)
747 p_dc = (UINT8 *)p_dev->dc;
748
749 if (p_dev->link_key_known)
750 p_lc = (UINT8 *)p_dev->link_key;
751
752 if (p_dev->is_trusted)
753 {
754 /* covert BTA service mask to BTM mask */
755 while (p_dev->tm && (index < BTA_MAX_SERVICE_ID))
756 {
757 if (p_dev->tm & (UINT32)(1<<index))
758 {
759
760 btm_mask_index = bta_service_id_to_btm_srv_id_lkup_tbl[index] / BTM_SEC_ARRAY_BITS;
761 trusted_services_mask[btm_mask_index] |= (UINT32)(1 << (bta_service_id_to_btm_srv_id_lkup_tbl[index] - (UINT32)(btm_mask_index * 32)));
762
763 p_dev->tm &= (UINT32)(~(1<<index));
764
765 }
766 index++;
767 }
768 }
769
770 if (!BTM_SecAddDevice (p_dev->bd_addr, p_dc, p_dev->bd_name, p_dev->features,
771 trusted_services_mask, p_lc, p_dev->key_type, p_dev->io_cap))
772 {
773 APPL_TRACE_ERROR2 ("BTA_DM: Error adding device %08x%04x",
774 (p_dev->bd_addr[0]<<24)+(p_dev->bd_addr[1]<<16)+(p_dev->bd_addr[2]<<8)+p_dev->bd_addr[3],
775 (p_dev->bd_addr[4]<<8)+p_dev->bd_addr[5]);
776 }
777}
778
779/*******************************************************************************
780**
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800781** Function bta_dm_close_acl
782**
783** Description This function forces to close the connection to a remote device
784** and optionaly remove the device from security database if
785** required.
786****
787*******************************************************************************/
788void bta_dm_close_acl(tBTA_DM_MSG *p_data)
789{
790 tBTA_DM_API_REMOVE_ACL *p_remove_acl = &p_data->remove_acl;
791 UINT8 index;
792
793 APPL_TRACE_DEBUG0("bta_dm_close_acl");
794
795 if (BTM_IsAclConnectionUp(p_remove_acl->bd_addr))
796 {
797 for (index = 0; index < bta_dm_cb.device_list.count; index ++)
798 {
799 if (!bdcmp( bta_dm_cb.device_list.peer_device[index].peer_bdaddr, p_remove_acl->bd_addr))
800 break;
801 }
802 if (index != bta_dm_cb.device_list.count)
803 {
804 if (p_remove_acl->remove_dev)
805 bta_dm_cb.device_list.peer_device[index].remove_dev_pending = TRUE;
806 }
807 else
808 {
809 APPL_TRACE_ERROR0("unknown device, remove ACL failed");
810 }
811 /* Disconnect the ACL link */
812 btm_remove_acl(p_remove_acl->bd_addr);
813 }
814 /* if to remove the device from security database ? do it now */
815 else if (p_remove_acl->remove_dev)
816 {
817 if (!BTM_SecDeleteDevice(p_remove_acl->bd_addr))
818 {
819 APPL_TRACE_ERROR0("delete device from security database failed.");
820 }
821#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
822 /* need to remove all pending background connection if any */
823 BTA_GATTC_CancelOpen(0, p_remove_acl->bd_addr, FALSE);
824 /* remove all cached GATT information */
825 BTA_GATTC_Refresh(p_remove_acl->bd_addr);
826#endif
827 }
828 /* otherwise, no action needed */
829
830}
831/*******************************************************************************
832**
The Android Open Source Project5738f832012-12-12 16:00:35 -0800833** Function bta_dm_bond
834**
835** Description Bonds with peer device
836**
837**
838** Returns void
839**
840*******************************************************************************/
841void bta_dm_bond (tBTA_DM_MSG *p_data)
842{
843 tBTM_STATUS status;
844 tBTA_DM_SEC sec_event;
845 char *p_name;
846
847 status = BTM_SecBond ( p_data->bond.bd_addr, 0, NULL, 0 );
848
849 if (bta_dm_cb.p_sec_cback && (status != BTM_CMD_STARTED))
850 {
851
The Android Open Source Project5738f832012-12-12 16:00:35 -0800852 memset(&sec_event, 0, sizeof(tBTA_DM_SEC));
853 bdcpy(sec_event.auth_cmpl.bd_addr, p_data->bond.bd_addr);
Kim Schulz2a2701c2013-09-16 15:59:33 +0200854 p_name = BTM_SecReadDevName(p_data->bond.bd_addr);
855 if (p_name != NULL)
856 {
857 memcpy(sec_event.auth_cmpl.bd_name, p_name, (BD_NAME_LEN-1));
858 sec_event.auth_cmpl.bd_name[BD_NAME_LEN-1] = 0;
859 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800860
861/* taken care of by memset [above]
862 sec_event.auth_cmpl.key_present = FALSE;
863 sec_event.auth_cmpl.success = FALSE;
864*/
865 sec_event.auth_cmpl.fail_reason = HCI_ERR_ILLEGAL_COMMAND;
866 if (status == BTM_SUCCESS)
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800867 {
The Android Open Source Project5738f832012-12-12 16:00:35 -0800868 sec_event.auth_cmpl.success = TRUE;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800869 }
870 else
871 {
872 /* delete this device entry from Sec Dev DB */
873 bta_dm_remove_sec_dev_entry(p_data->bond.bd_addr);
874 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800875 bta_dm_cb.p_sec_cback(BTA_DM_AUTH_CMPL_EVT, &sec_event);
876 }
877
878}
879
880/*******************************************************************************
881**
882** Function bta_dm_bond_cancel
883**
884** Description Cancels bonding with a peer device
885**
886**
887** Returns void
888**
889*******************************************************************************/
890void bta_dm_bond_cancel (tBTA_DM_MSG *p_data)
891{
892 tBTM_STATUS status;
893 tBTA_DM_SEC sec_event;
894
895 APPL_TRACE_EVENT0(" bta_dm_bond_cancel ");
896 status = BTM_SecBondCancel ( p_data->bond_cancel.bd_addr );
897
898 if (bta_dm_cb.p_sec_cback && (status != BTM_CMD_STARTED && status != BTM_SUCCESS))
899 {
900 sec_event.bond_cancel_cmpl.result = BTA_FAILURE;
901
902 bta_dm_cb.p_sec_cback(BTA_DM_BOND_CANCEL_CMPL_EVT, &sec_event);
903 }
904
905}
906
907/*******************************************************************************
908**
909** Function bta_dm_pin_reply
910**
911** Description Send the pin_reply to a request from BTM
912**
913**
914** Returns void
915**
916*******************************************************************************/
917void bta_dm_pin_reply (tBTA_DM_MSG *p_data)
918{
919 UINT32 trusted_mask[BTM_SEC_SERVICE_ARRAY_SIZE];
920 UINT32 * current_trusted_mask;
921
922 current_trusted_mask = BTM_ReadTrustedMask(p_data->pin_reply.bd_addr);
923
924 if(current_trusted_mask)
925 {
926 memcpy(trusted_mask, current_trusted_mask, sizeof(trusted_mask));
927 }
928 else
929 {
930 memset(trusted_mask, 0, sizeof(trusted_mask));
931 }
932
933 if(p_data->pin_reply.accept)
934 {
935
936 BTM_PINCodeReply(p_data->pin_reply.bd_addr, BTM_SUCCESS, p_data->pin_reply.pin_len, p_data->pin_reply.p_pin, trusted_mask );
937 }
938 else
939 {
940 BTM_PINCodeReply(p_data->pin_reply.bd_addr, BTM_NOT_AUTHORIZED, 0, NULL, trusted_mask );
941 }
942
943}
944
945/*******************************************************************************
946**
947** Function bta_dm_link_policy
948**
949** Description remove/set link policy mask.
950** wake the link, is sniff/park is removed
951**
952** Returns void
953**
954*******************************************************************************/
955void bta_dm_link_policy (tBTA_DM_MSG *p_data)
956{
957 tBTA_DM_PEER_DEVICE *p_dev;
958
959 p_dev = bta_dm_find_peer_device(p_data->link_policy.bd_addr);
960 if(!p_dev)
961 return;
962
963 APPL_TRACE_DEBUG2(" bta_dm_link_policy set:%d, policy:0x%x",
964 p_data->link_policy.set, p_data->link_policy.policy_mask);
965 if(p_data->link_policy.set)
966 {
967 /* restore the default link policy */
968 p_dev->link_policy |= p_data->link_policy.policy_mask;
969 BTM_SetLinkPolicy(p_dev->peer_bdaddr, &(p_dev->link_policy));
970 }
971 else
972 {
973 /* clear the policy from the default link policy */
974 p_dev->link_policy &= (~p_data->link_policy.policy_mask);
975 BTM_SetLinkPolicy(p_dev->peer_bdaddr, &(p_dev->link_policy));
976
977 if(p_data->link_policy.policy_mask & (HCI_ENABLE_SNIFF_MODE | HCI_ENABLE_PARK_MODE))
978 {
979 /* if clearing sniff/park, wake the link */
980 bta_dm_pm_active(p_dev->peer_bdaddr);
981 }
982 }
983}
984
985/*******************************************************************************
986**
987** Function bta_dm_policy_cback
988**
989** Description process the link policy changes
990**
991** Returns void
992**
993*******************************************************************************/
994static void bta_dm_policy_cback(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
995{
996 tBTA_DM_PEER_DEVICE *p_dev = NULL;
997 UINT16 policy = app_id;
998 UINT32 mask = (UINT32)(1 << id);
999
1000 if(peer_addr)
1001 p_dev = bta_dm_find_peer_device(peer_addr);
1002
1003 APPL_TRACE_DEBUG2(" bta_dm_policy_cback cmd:%d, policy:0x%x",
1004 status, policy);
1005 switch(status)
1006 {
1007 case BTA_SYS_PLCY_SET:
1008 if(!p_dev)
1009 return;
1010 /* restore the default link policy */
1011 p_dev->link_policy |= policy;
1012 BTM_SetLinkPolicy(p_dev->peer_bdaddr, &(p_dev->link_policy));
1013 break;
1014
1015 case BTA_SYS_PLCY_CLR:
1016 if(!p_dev)
1017 return;
1018 /* clear the policy from the default link policy */
1019 p_dev->link_policy &= (~policy);
1020 BTM_SetLinkPolicy(p_dev->peer_bdaddr, &(p_dev->link_policy));
1021
1022 if(policy & (HCI_ENABLE_SNIFF_MODE | HCI_ENABLE_PARK_MODE))
1023 {
1024 /* if clearing sniff/park, wake the link */
1025 bta_dm_pm_active(p_dev->peer_bdaddr);
1026 }
1027 break;
1028
1029 case BTA_SYS_PLCY_DEF_SET:
1030 /* want to restore/set the role switch policy */
1031 bta_dm_cb.role_policy_mask &= ~mask;
1032 if(0 == bta_dm_cb.role_policy_mask)
1033 {
1034 /* if nobody wants to insist on the role */
1035 bta_dm_cb.cur_policy |= HCI_ENABLE_MASTER_SLAVE_SWITCH;
1036 BTM_SetDefaultLinkPolicy(bta_dm_cb.cur_policy);
1037 }
1038 break;
1039
1040 case BTA_SYS_PLCY_DEF_CLR:
1041 /* want to remove the role switch policy */
1042 bta_dm_cb.role_policy_mask |= mask;
1043 bta_dm_cb.cur_policy &= ~HCI_ENABLE_MASTER_SLAVE_SWITCH;
1044 BTM_SetDefaultLinkPolicy(bta_dm_cb.cur_policy);
1045 break;
1046 }
1047}
1048
1049
1050/*******************************************************************************
1051**
1052** Function bta_dm_auth_reply
1053**
1054** Description Send the authorization reply to a request from BTM
1055**
1056**
1057** Returns void
1058**
1059*******************************************************************************/
1060void bta_dm_auth_reply (tBTA_DM_MSG *p_data)
1061{
1062
1063 UINT32 trusted_mask[BTM_SEC_SERVICE_ARRAY_SIZE];
1064 UINT8 btm_mask_index = 0;
1065 UINT32 * current_trusted_mask;
1066
1067 current_trusted_mask = BTM_ReadTrustedMask(p_data->auth_reply.bd_addr);
1068
1069 if(current_trusted_mask)
1070 {
1071 memcpy(trusted_mask, current_trusted_mask, sizeof(trusted_mask));
1072 }
1073 else
1074 {
1075 memset(trusted_mask, 0, sizeof(trusted_mask));
1076 }
1077
1078 if(p_data->auth_reply.response != BTA_DM_NOT_AUTH)
1079 {
1080 if(p_data->auth_reply.response == BTA_DM_AUTH_PERM)
1081 {
1082 if(p_data->auth_reply.service < BTA_MAX_SERVICE_ID)
1083 {
1084 /* convert BTA service id to BTM mask */
1085 btm_mask_index = bta_service_id_to_btm_srv_id_lkup_tbl[p_data->auth_reply.service] / 32;
1086 trusted_mask[btm_mask_index] |= (UINT32)(1 << (bta_service_id_to_btm_srv_id_lkup_tbl[p_data->auth_reply.service] - (UINT32)(btm_mask_index * 32)));
1087
1088 }
1089 }
1090 BTM_DeviceAuthorized (p_data->auth_reply.bd_addr, BTM_SUCCESS,trusted_mask);
1091 }
1092 else
1093 {
1094 BTM_DeviceAuthorized (p_data->auth_reply.bd_addr, BTM_NOT_AUTHORIZED,trusted_mask);
1095 }
1096
1097}
1098
1099/*******************************************************************************
1100**
1101** Function bta_dm_confirm
1102**
1103** Description Send the user confirm request reply in response to a
1104** request from BTM
1105**
1106** Returns void
1107**
1108*******************************************************************************/
1109void bta_dm_confirm(tBTA_DM_MSG *p_data)
1110{
1111 tBTM_STATUS res = BTM_NOT_AUTHORIZED;
1112
1113 if(p_data->confirm.accept == TRUE)
1114 res = BTM_SUCCESS;
1115 BTM_ConfirmReqReply(res, p_data->confirm.bd_addr);
1116}
1117
1118/*******************************************************************************
1119**
1120** Function bta_dm_passkey_cancel
1121**
1122** Description Send the passkey cancel from SP initiator by sending a negative
1123** passkey request replyreply.
1124** Returns void
1125**
1126*******************************************************************************/
1127#if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE)
1128void bta_dm_passkey_cancel(tBTA_DM_MSG *p_data)
1129{
1130 BTM_PasskeyReqReply(BTM_NOT_AUTHORIZED, p_data->passkey_cancel.bd_addr, 0);
1131}
1132#endif
1133
1134/*******************************************************************************
1135**
1136** Function bta_dm_loc_oob
1137**
1138** Description Retrieve the OOB data from the local LM
1139**
1140** Returns void
1141**
1142*******************************************************************************/
1143#if (BTM_OOB_INCLUDED == TRUE)
1144void bta_dm_loc_oob(tBTA_DM_MSG *p_data)
1145{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08001146 UNUSED(p_data);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001147 BTM_ReadLocalOobData();
1148}
1149
1150/*******************************************************************************
1151**
1152** Function bta_dm_ci_io_req_act
1153**
1154** Description respond to the IO capabilities request from BTM
1155**
1156** Returns void
1157**
1158*******************************************************************************/
1159void bta_dm_ci_io_req_act(tBTA_DM_MSG *p_data)
1160{
1161 tBTM_AUTH_REQ auth_req = BTM_AUTH_AP_NO;
1162 if(p_data->ci_io_req.auth_req)
1163 auth_req = BTM_AUTH_AP_YES;
1164 BTM_IoCapRsp(p_data->ci_io_req.bd_addr, p_data->ci_io_req.io_cap,
1165 p_data->ci_io_req.oob_data, auth_req);
1166}
1167
1168/*******************************************************************************
1169**
1170** Function bta_dm_ci_rmt_oob_act
1171**
1172** Description respond to the OOB data request for the remote device from BTM
1173**
1174**
1175** Returns void
1176**
1177*******************************************************************************/
1178void bta_dm_ci_rmt_oob_act(tBTA_DM_MSG *p_data)
1179{
1180 tBTM_STATUS res = BTM_NOT_AUTHORIZED;
1181
1182 if(p_data->ci_rmt_oob.accept == TRUE)
1183 res = BTM_SUCCESS;
1184 BTM_RemoteOobDataReply(res, p_data->ci_rmt_oob.bd_addr,
1185 p_data->ci_rmt_oob.c, p_data->ci_rmt_oob.r );
1186}
1187#endif /* BTM_OOB_INCLUDED */
1188
1189/*******************************************************************************
1190**
1191** Function bta_dm_search_start
1192**
1193** Description Starts an inquiry
1194**
1195**
1196** Returns void
1197**
1198*******************************************************************************/
1199void bta_dm_search_start (tBTA_DM_MSG *p_data)
1200{
1201 tBTM_INQUIRY_CMPL result;
1202
Andre Eisenbache1202ca2013-05-15 04:55:08 -07001203#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001204 UINT16 len = (UINT16)(sizeof(tBT_UUID) * p_data->search.num_uuid);
1205#endif
1206
1207 APPL_TRACE_DEBUG1("bta_dm_search_start avoid_scatter=%d", bta_dm_cfg.avoid_scatter);
1208 if (bta_dm_cfg.avoid_scatter &&
1209 (p_data->search.rs_res == BTA_DM_RS_NONE) && bta_dm_check_av(BTA_DM_API_SEARCH_EVT))
1210 {
1211 memcpy(&bta_dm_cb.search_msg, &p_data->search, sizeof(tBTA_DM_API_SEARCH));
1212 return;
1213 }
1214
1215 BTM_ClearInqDb(NULL);
1216 /* save search params */
1217 bta_dm_search_cb.p_search_cback = p_data->search.p_cback;
1218 bta_dm_search_cb.services = p_data->search.services;
1219
1220#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
1221 utl_freebuf((void **)&bta_dm_search_cb.p_srvc_uuid);
1222
1223 if ((bta_dm_search_cb.num_uuid = p_data->search.num_uuid) != 0 &&
1224 p_data->search.p_uuid != NULL)
1225 {
1226 if ((bta_dm_search_cb.p_srvc_uuid = (tBT_UUID *)GKI_getbuf(len)) == NULL)
1227 {
1228 APPL_TRACE_ERROR0("bta_dm_search_start no resources");
1229
1230 result.status = BTA_FAILURE;
1231 result.num_resp = 0;
1232 bta_dm_inq_cmpl_cb ((void *)&result);
1233 return;
1234 }
1235// bta_dm_search_cb.p_srvc_uuid = (tBT_UUID *)GKI_getbuf(len);
1236 memcpy(bta_dm_search_cb.p_srvc_uuid, p_data->search.p_uuid, len);
1237 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001238#endif
1239 result.status = BTM_StartInquiry( (tBTM_INQ_PARMS*)&p_data->search.inq_params,
1240 bta_dm_inq_results_cb,
1241 (tBTM_CMPL_CB*) bta_dm_inq_cmpl_cb);
1242
1243 APPL_TRACE_EVENT1("bta_dm_search_start status=%d", result.status);
1244 if (result.status != BTM_CMD_STARTED)
1245 {
1246 result.num_resp = 0;
1247 bta_dm_inq_cmpl_cb ((void *)&result);
1248 }
1249
1250}
1251
1252/*******************************************************************************
1253**
1254** Function bta_dm_search_cancel
1255**
1256** Description Cancels an ongoing search for devices
1257**
1258**
1259** Returns void
1260**
1261*******************************************************************************/
1262void bta_dm_search_cancel (tBTA_DM_MSG *p_data)
1263{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08001264 UNUSED(p_data);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001265 tBTA_DM_MSG * p_msg;
1266
1267 if(BTM_IsInquiryActive())
1268 {
1269 BTM_CancelInquiry();
1270 bta_dm_search_cancel_notify(NULL);
1271
1272 if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL)
1273 {
1274 p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT;
1275 p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT;
1276 bta_sys_sendmsg(p_msg);
1277
1278 }
1279 }
1280 /* If no Service Search going on then issue cancel remote name in case it is active */
1281 else if (!bta_dm_search_cb.name_discover_done)
1282 {
1283 BTM_CancelRemoteDeviceName();
1284 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001285#if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
The Android Open Source Project5738f832012-12-12 16:00:35 -08001286 if (bta_dm_search_cb.gatt_disc_active)
1287 {
1288 bta_dm_cancel_gatt_discovery(bta_dm_search_cb.peer_bdaddr);
1289 }
1290#endif
1291}
1292
1293/*******************************************************************************
1294**
1295** Function bta_dm_discover
1296**
1297** Description Discovers services on a remote device
1298**
1299**
1300** Returns void
1301**
1302*******************************************************************************/
1303void bta_dm_discover (tBTA_DM_MSG *p_data)
1304{
1305#if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
1306 UINT16 len = (UINT16)(sizeof(tBT_UUID) * p_data->discover.num_uuid);
1307#endif
1308 APPL_TRACE_EVENT2("bta_dm_discover services_to_search=0x%04X, sdp_search=%d",
1309 p_data->discover.services, p_data->discover.sdp_search);
1310
1311 /* save the search condition */
1312 bta_dm_search_cb.services = p_data->discover.services;
1313
1314#if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
1315 utl_freebuf((void **)&bta_dm_search_cb.p_srvc_uuid);
1316 if ((bta_dm_search_cb.num_uuid = p_data->discover.num_uuid) != 0 &&
1317 p_data->discover.p_uuid != NULL)
1318 {
1319 if ((bta_dm_search_cb.p_srvc_uuid = (tBT_UUID *)GKI_getbuf(len)) == NULL)
1320 {
1321 p_data->discover.p_cback(BTA_DM_DISC_CMPL_EVT, NULL);
1322 return;
1323 }
1324 memcpy(bta_dm_search_cb.p_srvc_uuid, p_data->discover.p_uuid, len);
1325 }
1326 bta_dm_search_cb.uuid_to_search = bta_dm_search_cb.num_uuid;
1327#endif
1328
1329 bta_dm_search_cb.p_search_cback = p_data->discover.p_cback;
1330 bta_dm_search_cb.sdp_search = p_data->discover.sdp_search;
1331 bta_dm_search_cb.services_to_search = bta_dm_search_cb.services;
1332 bta_dm_search_cb.service_index = 0;
1333 bta_dm_search_cb.services_found = 0;
1334 bta_dm_search_cb.peer_name[0] = 0;
1335 bta_dm_search_cb.sdp_search = p_data->discover.sdp_search;
1336 bta_dm_search_cb.p_btm_inq_info = BTM_InqDbRead (p_data->discover.bd_addr);
1337
1338 bta_dm_search_cb.name_discover_done = FALSE;
1339 memcpy(&bta_dm_search_cb.uuid, &p_data->discover.uuid, sizeof(tSDP_UUID));
1340 bta_dm_discover_device(p_data->discover.bd_addr);
1341}
1342
1343/*******************************************************************************
1344**
1345** Function bta_dm_di_disc_cmpl
1346**
1347** Description Sends event to application when DI discovery complete
1348**
1349** Returns void
1350**
1351*******************************************************************************/
1352void bta_dm_di_disc_cmpl(tBTA_DM_MSG *p_data)
1353{
1354 tBTA_DM_DI_DISC_CMPL di_disc;
1355
1356 memset(&di_disc, 0, sizeof(tBTA_DM_DI_DISC_CMPL));
1357 bdcpy(di_disc.bd_addr, bta_dm_search_cb.peer_bdaddr);
1358
1359 if((p_data->hdr.offset == SDP_SUCCESS)
1360 || (p_data->hdr.offset == SDP_DB_FULL))
1361 {
1362 di_disc.num_record = SDP_GetNumDiRecords(bta_dm_di_cb.p_di_db);
1363 }
1364 else
1365 di_disc.result = BTA_FAILURE;
1366
1367 bta_dm_di_cb.p_di_db = NULL;
1368 bta_dm_search_cb.p_search_cback(BTA_DM_DI_DISC_CMPL_EVT, (tBTA_DM_SEARCH *) &di_disc);
1369}
1370
1371/*******************************************************************************
1372**
1373** Function bta_dm_di_disc_callback
1374**
1375** Description This function queries a remote device for DI information.
1376**
1377**
1378** Returns void
1379**
1380*******************************************************************************/
1381static void bta_dm_di_disc_callback(UINT16 result)
1382{
1383 tBTA_DM_MSG * p_msg;
1384
1385 if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL)
1386 {
1387 p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT;
1388 p_msg->hdr.layer_specific = BTA_DM_API_DI_DISCOVER_EVT;
1389 p_msg->hdr.offset = result;
1390 bta_sys_sendmsg(p_msg);
1391 }
1392}
1393
1394/*******************************************************************************
1395**
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001396** Function bta_dm_disable_search_and_disc
1397**
1398** Description Cancels an ongoing search or discovery for devices in case of
1399** a Bluetooth disable
1400**
1401**
1402** Returns void
1403**
1404*******************************************************************************/
1405static void bta_dm_disable_search_and_disc (void)
1406{
1407 tBTA_DM_DI_DISC_CMPL di_disc;
1408 tBTA_DM_MSG * p_msg;
1409
1410 if(BTM_IsInquiryActive()||(bta_dm_search_cb.state != BTA_DM_SEARCH_IDLE))
1411 {
1412 BTM_CancelInquiry();
1413 bta_dm_search_cancel_notify(NULL);
1414
1415 if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL)
1416 {
1417 p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT;
1418 p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT;
1419 bta_sys_sendmsg(p_msg);
1420
1421 }
1422 }
1423 /* If no Service Search going on then issue cancel remote name in case it is active */
1424 else if (!bta_dm_search_cb.name_discover_done)
1425 {
1426 BTM_CancelRemoteDeviceName();
1427
1428 if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL)
1429 {
1430 p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT;
1431 p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT;
1432 bta_sys_sendmsg(p_msg);
1433 }
1434 }
1435 else if(bta_dm_di_cb.p_di_db != NULL)
1436 {
1437 memset(&di_disc, 0, sizeof(tBTA_DM_DI_DISC_CMPL));
1438 bdcpy(di_disc.bd_addr, bta_dm_search_cb.peer_bdaddr);
1439 di_disc.result = BTA_FAILURE;
1440
1441 bta_dm_di_cb.p_di_db = NULL;
1442 bta_dm_search_cb.p_search_cback(BTA_DM_DI_DISC_CMPL_EVT, NULL);
1443 }
1444
1445#if (BLE_INCLUDED == TRUE) && (BTA_GATT_INCLUDED == TRUE)
1446 if (bta_dm_search_cb.gatt_disc_active)
1447 {
1448 bta_dm_cancel_gatt_discovery(bta_dm_search_cb.peer_bdaddr);
1449 }
1450#endif
1451}
1452
1453/*******************************************************************************
1454**
The Android Open Source Project5738f832012-12-12 16:00:35 -08001455** Function bta_dm_di_disc
1456**
1457** Description This function queries a remote device for DI information.
1458**
1459**
1460** Returns void
1461**
1462*******************************************************************************/
1463void bta_dm_di_disc (tBTA_DM_MSG *p_data)
1464{
1465 UINT16 result = BTA_FAILURE;
1466 tBTA_DM_MSG *p_msg;
1467
1468 bta_dm_search_cb.p_search_cback = p_data->di_disc.p_cback;
1469 bdcpy(bta_dm_search_cb.peer_bdaddr, p_data->di_disc.bd_addr);
1470 bta_dm_di_cb.p_di_db = p_data->di_disc.p_sdp_db;
1471
1472 if((bta_dm_search_cb.p_sdp_db = (tSDP_DISCOVERY_DB *)GKI_getbuf(BTA_DM_SDP_DB_SIZE)) != NULL)
1473 {
1474 if ( SDP_DiDiscover(bta_dm_search_cb.peer_bdaddr, p_data->di_disc.p_sdp_db,
1475 p_data->di_disc.len, bta_dm_di_disc_callback) == SDP_SUCCESS)
1476 {
1477 result = BTA_SUCCESS;
1478 }
1479 }
1480 else
1481 {
1482 APPL_TRACE_ERROR0("No buffer to start DI discovery");
1483 }
1484
1485 if ( result == BTA_FAILURE &&
1486 (p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL)
1487 {
1488 p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT;
1489 p_msg->hdr.layer_specific = BTA_DM_API_DI_DISCOVER_EVT;
1490 p_data->hdr.offset = result;
1491 bta_sys_sendmsg(p_msg);
1492 }
1493}
1494
1495/*******************************************************************************
1496**
1497** Function bta_dm_read_remote_device_name
1498**
1499** Description Initiate to get remote device name
1500**
1501** Returns TRUE if started to get remote name
1502**
1503*******************************************************************************/
1504static BOOLEAN bta_dm_read_remote_device_name (BD_ADDR bd_addr)
1505{
1506 tBTM_STATUS btm_status;
1507
1508 APPL_TRACE_DEBUG0("bta_dm_read_remote_device_name");
1509
1510 bdcpy(bta_dm_search_cb.peer_bdaddr, bd_addr);
1511 bta_dm_search_cb.peer_name[0] = 0;
1512
1513 btm_status = BTM_ReadRemoteDeviceName (bta_dm_search_cb.peer_bdaddr,
1514 (tBTM_CMPL_CB *) bta_dm_remname_cback);
1515
1516 if ( btm_status == BTM_CMD_STARTED )
1517 {
1518 APPL_TRACE_DEBUG0("bta_dm_read_remote_device_name: BTM_ReadRemoteDeviceName is started");
1519
1520 return (TRUE);
1521 }
1522 else if ( btm_status == BTM_BUSY )
1523 {
1524 APPL_TRACE_DEBUG0("bta_dm_read_remote_device_name: BTM_ReadRemoteDeviceName is busy");
1525
1526 /* Remote name discovery is on going now so BTM cannot notify through "bta_dm_remname_cback" */
1527 /* adding callback to get notified that current reading remore name done */
1528 BTM_SecAddRmtNameNotifyCallback(&bta_dm_service_search_remname_cback);
1529
1530 return (TRUE);
1531 }
1532 else
1533 {
1534 APPL_TRACE_WARNING1("bta_dm_read_remote_device_name: BTM_ReadRemoteDeviceName returns 0x%02X", btm_status);
1535
1536 return (FALSE);
1537 }
1538}
1539
1540/*******************************************************************************
1541**
1542** Function bta_dm_inq_cmpl
1543**
1544** Description Process the inquiry complete event from BTM
1545**
1546** Returns void
1547**
1548*******************************************************************************/
1549void bta_dm_inq_cmpl (tBTA_DM_MSG *p_data)
1550{
1551 tBTA_DM_MSG * p_msg;
1552 tBTA_DM_SEARCH data;
1553
1554 APPL_TRACE_DEBUG0("bta_dm_inq_cmpl");
1555
1556 data.inq_cmpl.num_resps = p_data->inq_cmpl.num;
1557 bta_dm_search_cb.p_search_cback(BTA_DM_INQ_CMPL_EVT, &data);
1558
1559 if((bta_dm_search_cb.p_btm_inq_info = BTM_InqDbFirst()) != NULL)
1560 {
1561 /* start name and service discovery from the first device on inquiry result */
1562 bta_dm_search_cb.name_discover_done = FALSE;
1563 bta_dm_search_cb.peer_name[0] = 0;
1564 bta_dm_discover_device(bta_dm_search_cb.p_btm_inq_info->results.remote_bd_addr);
1565 }
1566 else
1567 {
1568 /* no devices, search complete */
1569 bta_dm_search_cb.services = 0;
1570
1571 if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL)
1572 {
1573 p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT;
1574 p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT;
1575 bta_sys_sendmsg(p_msg);
1576 }
1577 }
1578 }
1579
1580/*******************************************************************************
1581**
1582** Function bta_dm_rmt_name
1583**
1584** Description Process the remote name result from BTM
1585**
1586** Returns void
1587**
1588*******************************************************************************/
1589void bta_dm_rmt_name (tBTA_DM_MSG *p_data)
1590{
1591 APPL_TRACE_DEBUG0("bta_dm_rmt_name");
1592
1593 if( p_data->rem_name.result.disc_res.bd_name[0] && bta_dm_search_cb.p_btm_inq_info)
1594 {
1595 bta_dm_search_cb.p_btm_inq_info->appl_knows_rem_name = TRUE;
1596 }
1597
1598 bta_dm_discover_device(bta_dm_search_cb.peer_bdaddr);
1599}
1600
1601/*******************************************************************************
1602**
1603** Function bta_dm_disc_rmt_name
1604**
1605** Description Process the remote name result from BTM when application
1606** wants to find the name for a bdaddr
1607**
1608** Returns void
1609**
1610*******************************************************************************/
1611void bta_dm_disc_rmt_name (tBTA_DM_MSG *p_data)
1612{
1613 tBTM_INQ_INFO *p_btm_inq_info;
1614
1615 APPL_TRACE_DEBUG0("bta_dm_disc_rmt_name");
1616
1617 p_btm_inq_info = BTM_InqDbRead (p_data->rem_name.result.disc_res.bd_addr);
1618 if( p_btm_inq_info )
1619 {
1620 if( p_data->rem_name.result.disc_res.bd_name[0] )
1621 {
1622 p_btm_inq_info->appl_knows_rem_name = TRUE;
1623 }
1624 }
1625
1626 bta_dm_discover_device(p_data->rem_name.result.disc_res.bd_addr);
1627}
1628
1629/*******************************************************************************
1630**
1631** Function bta_dm_sdp_result
1632**
1633** Description Process the discovery result from sdp
1634**
1635** Returns void
1636**
1637*******************************************************************************/
1638void bta_dm_sdp_result (tBTA_DM_MSG *p_data)
1639{
1640
1641 tSDP_DISC_REC *p_sdp_rec = NULL;
1642 tBTA_DM_MSG *p_msg;
1643 BOOLEAN service_found = FALSE;
1644 BOOLEAN scn_found = FALSE;
1645 UINT16 service = 0xFFFF;
1646 tSDP_PROTOCOL_ELEM pe;
1647
1648#if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
1649 tBT_UUID *p_uuid = bta_dm_search_cb.p_srvc_uuid;
1650 tBTA_DM_SEARCH result;
1651 tBT_UUID service_uuid;
1652#endif
1653
1654 UINT32 num_uuids = 0;
1655 UINT8 uuid_list[32][MAX_UUID_SIZE]; // assuming a max of 32 services
1656
1657 if((p_data->sdp_event.sdp_result == SDP_SUCCESS)
1658 || (p_data->sdp_event.sdp_result == SDP_NO_RECS_MATCH)
1659 || (p_data->sdp_event.sdp_result == SDP_DB_FULL))
1660 {
1661 APPL_TRACE_DEBUG1("sdp_result::0x%x", p_data->sdp_event.sdp_result);
1662 do
1663 {
1664
1665 service_found = FALSE;
1666 p_sdp_rec = NULL;
1667 if( bta_dm_search_cb.service_index == (BTA_USER_SERVICE_ID+1) )
1668 {
1669 p_sdp_rec = SDP_FindServiceUUIDInDb(bta_dm_search_cb.p_sdp_db, &bta_dm_search_cb.uuid, p_sdp_rec);
1670
1671 if (p_sdp_rec && SDP_FindProtocolListElemInRec(p_sdp_rec, UUID_PROTOCOL_RFCOMM, &pe))
1672 {
1673 bta_dm_search_cb.peer_scn = (UINT8) pe.params[0];
1674 scn_found = TRUE;
1675 }
1676 }
1677 else
1678 {
1679 service = bta_service_id_to_uuid_lkup_tbl[bta_dm_search_cb.service_index-1];
1680 p_sdp_rec = SDP_FindServiceInDb(bta_dm_search_cb.p_sdp_db, service, p_sdp_rec);
1681 }
1682#if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
1683 /* finished with BR/EDR services, now we check the result for GATT based service UUID */
1684 if (bta_dm_search_cb.service_index == BTA_MAX_SERVICE_ID)
1685 {
1686 if (bta_dm_search_cb.uuid_to_search != 0 && p_uuid != NULL)
1687 {
1688 p_uuid += (bta_dm_search_cb.num_uuid - bta_dm_search_cb.uuid_to_search);
1689 /* only support 16 bits UUID for now */
1690 service = p_uuid->uu.uuid16;
1691
1692 }
1693 /* all GATT based services */
1694 do
1695 {
1696 /* find a service record, report it */
1697 p_sdp_rec = SDP_FindServiceInDb(bta_dm_search_cb.p_sdp_db,
1698 0, p_sdp_rec);
1699 if (p_sdp_rec)
1700 {
1701 if (SDP_FindServiceUUIDInRec(p_sdp_rec, &service_uuid))
1702 {
1703 /* send result back to app now, one by one */
1704 bdcpy (result.disc_ble_res.bd_addr, bta_dm_search_cb.peer_bdaddr);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001705 BCM_STRNCPY_S((char*)result.disc_ble_res.bd_name, sizeof(BD_NAME), bta_dm_get_remname(), (BD_NAME_LEN));
1706 result.disc_ble_res.bd_name[BD_NAME_LEN] = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001707 result.disc_ble_res.service.len = service_uuid.len;
1708 result.disc_ble_res.service.uu.uuid16 = service_uuid.uu.uuid16;
1709
1710 bta_dm_search_cb.p_search_cback(BTA_DM_DISC_BLE_RES_EVT, &result);
1711 }
1712 }
1713
1714 if (bta_dm_search_cb.uuid_to_search > 0)
1715 break;
1716
1717 } while (p_sdp_rec);
1718 }
1719 else
1720#endif
1721 {
1722 /* SDP_DB_FULL means some records with the
1723 required attributes were received */
1724 if(((p_data->sdp_event.sdp_result == SDP_DB_FULL) &&
1725 bta_dm_search_cb.services != BTA_ALL_SERVICE_MASK) ||
1726 (p_sdp_rec != NULL))
1727 {
1728 /* If Plug and Play service record, check to see if Broadcom stack */
1729 if (service == UUID_SERVCLASS_PNP_INFORMATION)
1730 {
1731 if (p_sdp_rec)
1732 {
1733 if (SDP_FindAttributeInRec (p_sdp_rec, ATTR_ID_EXT_BRCM_VERSION))
1734 {
1735 service_found = TRUE;
1736 }
1737 }
1738 }
1739 else
1740 {
1741 service_found = TRUE;
1742 }
1743
1744 if (service_found)
1745 {
1746 UINT16 tmp_svc = 0xFFFF;
1747 bta_dm_search_cb.services_found |=
1748 (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(bta_dm_search_cb.service_index-1));
1749 tmp_svc = bta_service_id_to_uuid_lkup_tbl[bta_dm_search_cb.service_index-1];
1750 /* Add to the list of UUIDs */
1751 sdpu_uuid16_to_uuid128(tmp_svc, uuid_list[num_uuids]);
1752 num_uuids++;
1753 }
1754 }
1755 }
1756
1757 if(bta_dm_search_cb.services == BTA_ALL_SERVICE_MASK &&
1758 bta_dm_search_cb.services_to_search == 0)
1759 {
1760#if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
1761 if ( bta_dm_search_cb.service_index == BTA_BLE_SERVICE_ID &&
1762 bta_dm_search_cb.uuid_to_search > 0)
1763 bta_dm_search_cb.uuid_to_search --;
1764
1765 if (bta_dm_search_cb.uuid_to_search == 0 ||
1766 bta_dm_search_cb.service_index != BTA_BLE_SERVICE_ID)
1767#endif
1768 bta_dm_search_cb.service_index++;
1769 }
1770 else /* regular one service per search or PNP search */
1771 break;
1772
1773 }
1774 while(bta_dm_search_cb.service_index <= BTA_MAX_SERVICE_ID);
1775
1776// GKI_freebuf(bta_dm_search_cb.p_sdp_db);
1777// bta_dm_search_cb.p_sdp_db = NULL;
1778 APPL_TRACE_DEBUG1("bta_dm_sdp_result services_found = %04x", bta_dm_search_cb.services_found);
1779
1780 /* Collect the 128-bit services here and put them into the list */
1781 if(bta_dm_search_cb.services == BTA_ALL_SERVICE_MASK)
1782 {
1783 p_sdp_rec = NULL;
1784 do
1785 {
1786 tBT_UUID temp_uuid;
1787 /* find a service record, report it */
1788 p_sdp_rec = SDP_FindServiceInDb_128bit(bta_dm_search_cb.p_sdp_db, p_sdp_rec);
1789 if (p_sdp_rec)
1790 {
1791 if (SDP_FindServiceUUIDInRec_128bit(p_sdp_rec, &temp_uuid))
1792 {
1793 memcpy(uuid_list[num_uuids], temp_uuid.uu.uuid128, MAX_UUID_SIZE);
1794 num_uuids++;
1795 }
1796 }
1797 } while (p_sdp_rec);
1798 }
1799 /* if there are more services to search for */
1800 if(bta_dm_search_cb.services_to_search)
1801 {
1802 /* Free up the p_sdp_db before checking the next one */
1803 bta_dm_free_sdp_db(NULL);
1804 bta_dm_find_services(bta_dm_search_cb.peer_bdaddr);
1805 }
1806 else
1807 {
1808 /* callbacks */
1809 /* start next bd_addr if necessary */
1810
1811 BTM_SecDeleteRmtNameNotifyCallback(&bta_dm_service_search_remname_cback);
1812
1813
1814 if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL)
1815 {
1816 p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT;
1817 p_msg->disc_result.result.disc_res.result = BTA_SUCCESS;
1818 p_msg->disc_result.result.disc_res.p_raw_data = NULL;
1819 p_msg->disc_result.result.disc_res.raw_data_size = 0;
1820 p_msg->disc_result.result.disc_res.num_uuids = num_uuids;
1821 p_msg->disc_result.result.disc_res.p_uuid_list = NULL;
1822 if (num_uuids > 0) {
1823 p_msg->disc_result.result.disc_res.p_uuid_list = (UINT8*)GKI_getbuf(num_uuids*MAX_UUID_SIZE);
1824 if (p_msg->disc_result.result.disc_res.p_uuid_list) {
1825 memcpy(p_msg->disc_result.result.disc_res.p_uuid_list, uuid_list,
1826 num_uuids*MAX_UUID_SIZE);
1827 } else {
1828 p_msg->disc_result.result.disc_res.num_uuids = 0;
1829 APPL_TRACE_ERROR1("%s: Unable to allocate memory for uuid_list", __FUNCTION__);
1830 }
1831 }
1832 //copy the raw_data to the discovery result structure
1833 //
1834 APPL_TRACE_DEBUG2("bta_dm_sdp_result (raw_data used = 0x%x raw_data_ptr = 0x%x)\r\n",bta_dm_search_cb.p_sdp_db->raw_used, bta_dm_search_cb.p_sdp_db->raw_data);
1835
1836 if ( bta_dm_search_cb.p_sdp_db != NULL && bta_dm_search_cb.p_sdp_db->raw_used != 0 &&
1837 bta_dm_search_cb.p_sdp_db->raw_data != NULL) {
1838
1839 p_msg->disc_result.result.disc_res.p_raw_data = GKI_getbuf(bta_dm_search_cb.p_sdp_db->raw_used);
1840 if ( NULL != p_msg->disc_result.result.disc_res.p_raw_data ) {
1841 memcpy( p_msg->disc_result.result.disc_res.p_raw_data,
1842 bta_dm_search_cb.p_sdp_db->raw_data,
1843 bta_dm_search_cb.p_sdp_db->raw_used );
1844
1845 p_msg->disc_result.result.disc_res.raw_data_size =
1846 bta_dm_search_cb.p_sdp_db->raw_used;
1847
1848 } else {
1849 APPL_TRACE_DEBUG1("bta_dm_sdp_result GKI Alloc failed to allocate %d bytes !!\r\n",bta_dm_search_cb.p_sdp_db->raw_used);
1850 }
1851
1852 bta_dm_search_cb.p_sdp_db->raw_data = NULL; //no need to free this - it is a global assigned.
1853 bta_dm_search_cb.p_sdp_db->raw_used = 0;
1854 bta_dm_search_cb.p_sdp_db->raw_size = 0;
1855 }
1856 else {
1857 APPL_TRACE_DEBUG0("bta_dm_sdp_result raw data size is 0 or raw_data is null!!\r\n");
1858 }
1859 /* Done with p_sdp_db. Free it */
1860 bta_dm_free_sdp_db(NULL);
1861 p_msg->disc_result.result.disc_res.services = bta_dm_search_cb.services_found;
1862
1863 //Piggy back the SCN over result field
1864 if( scn_found )
1865 {
1866 p_msg->disc_result.result.disc_res.result = (3 + bta_dm_search_cb.peer_scn);
1867 p_msg->disc_result.result.disc_res.services |= BTA_USER_SERVICE_MASK;
1868
1869 APPL_TRACE_EVENT1(" Piggy back the SCN over result field SCN=%d", bta_dm_search_cb.peer_scn);
1870
1871 }
1872 bdcpy (p_msg->disc_result.result.disc_res.bd_addr, bta_dm_search_cb.peer_bdaddr);
1873 BCM_STRNCPY_S((char*)p_msg->disc_result.result.disc_res.bd_name, sizeof(BD_NAME),
1874 bta_dm_get_remname(), (BD_NAME_LEN-1));
1875
1876 /* make sure the string is null terminated */
1877 p_msg->disc_result.result.disc_res.bd_name[BD_NAME_LEN-1] = 0;
1878
1879 bta_sys_sendmsg(p_msg);
1880 }
1881
1882 }
1883
1884 }
1885 else
1886 {
1887 /* conn failed. No need for timer */
1888 if(p_data->sdp_event.sdp_result == SDP_CONN_FAILED || p_data->sdp_event.sdp_result == SDP_CONN_REJECTED
1889 || p_data->sdp_event.sdp_result == SDP_SECURITY_ERR)
1890 bta_dm_search_cb.wait_disc = FALSE;
1891
1892 /* not able to connect go to next device */
1893 GKI_freebuf(bta_dm_search_cb.p_sdp_db);
1894 bta_dm_search_cb.p_sdp_db = NULL;
1895
1896 BTM_SecDeleteRmtNameNotifyCallback(&bta_dm_service_search_remname_cback);
1897
1898 if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL)
1899 {
1900 p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT;
1901 p_msg->disc_result.result.disc_res.result = BTA_FAILURE;
1902 p_msg->disc_result.result.disc_res.services = bta_dm_search_cb.services_found;
1903 bdcpy (p_msg->disc_result.result.disc_res.bd_addr, bta_dm_search_cb.peer_bdaddr);
1904 BCM_STRNCPY_S((char*)p_msg->disc_result.result.disc_res.bd_name, sizeof(BD_NAME),
1905 bta_dm_get_remname(), (BD_NAME_LEN-1));
1906
1907 /* make sure the string is null terminated */
1908 p_msg->disc_result.result.disc_res.bd_name[BD_NAME_LEN-1] = 0;
1909
1910 bta_sys_sendmsg(p_msg);
1911 }
1912 }
1913}
1914
1915/*******************************************************************************
1916**
1917** Function bta_dm_search_cmpl
1918**
1919** Description Sends event to application
1920**
1921** Returns void
1922**
1923*******************************************************************************/
1924void bta_dm_search_cmpl (tBTA_DM_MSG *p_data)
1925{
1926 APPL_TRACE_DEBUG0("bta_dm_search_cmpl");
1927
1928#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
1929 utl_freebuf((void **)&bta_dm_search_cb.p_srvc_uuid);
1930#endif
1931
1932 if (p_data->hdr.layer_specific == BTA_DM_API_DI_DISCOVER_EVT)
1933 bta_dm_di_disc_cmpl(p_data);
1934 else
1935 bta_dm_search_cb.p_search_cback(BTA_DM_DISC_CMPL_EVT, NULL);
1936}
1937
1938/*******************************************************************************
1939**
1940** Function bta_dm_disc_result
1941**
1942** Description Service discovery result when discovering services on a device
1943**
1944** Returns void
1945**
1946*******************************************************************************/
1947void bta_dm_disc_result (tBTA_DM_MSG *p_data)
1948{
1949 tBTA_DM_MSG * p_msg;
1950
1951 APPL_TRACE_DEBUG0("bta_dm_disc_result");
1952
1953#if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
1954 /* if any BR/EDR service discovery has been done, report the event */
1955 if ((bta_dm_search_cb.services & ((BTA_ALL_SERVICE_MASK | BTA_USER_SERVICE_MASK ) & ~BTA_BLE_SERVICE_MASK)))
1956#endif
1957 bta_dm_search_cb.p_search_cback(BTA_DM_DISC_RES_EVT, &p_data->disc_result.result);
1958
1959 /* send a message to change state */
1960 if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL)
1961 {
1962 p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT;
1963 p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT;
1964 bta_sys_sendmsg(p_msg);
1965 }
1966}
1967
1968/*******************************************************************************
1969**
1970** Function bta_dm_search_result
1971**
1972** Description Service discovery result while searching for devices
1973**
1974** Returns void
1975**
1976*******************************************************************************/
1977void bta_dm_search_result (tBTA_DM_MSG *p_data)
1978{
1979 APPL_TRACE_DEBUG2("bta_dm_search_result searching:0x%04x, result:0x%04x",
1980 bta_dm_search_cb.services,
1981 p_data->disc_result.result.disc_res.services);
1982
1983 /* call back if application wants name discovery or found services that application is searching */
1984 if (( !bta_dm_search_cb.services )
1985 ||(( bta_dm_search_cb.services ) && ( p_data->disc_result.result.disc_res.services )))
1986 {
1987 bta_dm_search_cb.p_search_cback(BTA_DM_DISC_RES_EVT, &p_data->disc_result.result);
1988 }
1989
1990 /* if searching did not initiate to create link */
1991 if(!bta_dm_search_cb.wait_disc )
1992 {
1993#if ( BTM_EIR_CLIENT_INCLUDED == TRUE )
1994 /* if service searching is done with EIR, don't search next device */
1995 if( bta_dm_search_cb.p_btm_inq_info )
1996#endif
1997 bta_dm_discover_next_device();
1998 }
1999 else
2000 {
2001 /* wait until link is disconnected or timeout */
2002 bta_dm_search_cb.sdp_results = TRUE;
2003 bta_dm_search_cb.search_timer.p_cback = (TIMER_CBACK*)&bta_dm_search_timer_cback;
2004 bta_sys_start_timer(&bta_dm_search_cb.search_timer, 0, 1000*(L2CAP_LINK_INACTIVITY_TOUT+1) );
2005 }
2006
2007}
2008
2009/*******************************************************************************
2010**
2011** Function bta_dm_search_timer_cback
2012**
2013** Description Called when ACL disconnect time is over
2014**
2015**
2016** Returns void
2017**
2018*******************************************************************************/
2019static void bta_dm_search_timer_cback (TIMER_LIST_ENT *p_tle)
2020{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08002021 UNUSED(p_tle);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002022
2023 APPL_TRACE_EVENT0(" bta_dm_search_timer_cback ");
2024 bta_dm_search_cb.wait_disc = FALSE;
2025
2026 /* proceed with next device */
2027 bta_dm_discover_next_device();
2028
2029}
2030
2031
2032/*******************************************************************************
2033**
2034** Function bta_dm_free_sdp_db
2035**
2036** Description Frees SDP data base
2037**
2038** Returns void
2039**
2040*******************************************************************************/
2041void bta_dm_free_sdp_db (tBTA_DM_MSG *p_data)
2042{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08002043 UNUSED(p_data);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002044 if(bta_dm_search_cb.p_sdp_db)
2045 {
2046 GKI_freebuf(bta_dm_search_cb.p_sdp_db);
2047 bta_dm_search_cb.p_sdp_db = NULL;
2048 }
2049
2050}
2051
2052/*******************************************************************************
2053**
2054** Function bta_dm_queue_search
2055**
2056** Description Queues search command while search is being cancelled
2057**
2058** Returns void
2059**
2060*******************************************************************************/
2061void bta_dm_queue_search (tBTA_DM_MSG *p_data)
2062{
Zhihai Xub69a1752013-11-06 19:23:13 -08002063 if(bta_dm_search_cb.p_search_queue)
2064 {
2065 GKI_freebuf(bta_dm_search_cb.p_search_queue);
2066 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08002067
2068 bta_dm_search_cb.p_search_queue = (tBTA_DM_MSG *)GKI_getbuf(sizeof(tBTA_DM_API_SEARCH));
2069 memcpy(bta_dm_search_cb.p_search_queue, p_data, sizeof(tBTA_DM_API_SEARCH));
2070
2071}
2072
2073/*******************************************************************************
2074**
2075** Function bta_dm_queue_disc
2076**
2077** Description Queues discovery command while search is being cancelled
2078**
2079** Returns void
2080**
2081*******************************************************************************/
2082void bta_dm_queue_disc (tBTA_DM_MSG *p_data)
2083{
Zhihai Xub69a1752013-11-06 19:23:13 -08002084 if(bta_dm_search_cb.p_search_queue)
2085 {
2086 GKI_freebuf(bta_dm_search_cb.p_search_queue);
2087 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08002088
2089 bta_dm_search_cb.p_search_queue = (tBTA_DM_MSG *)GKI_getbuf(sizeof(tBTA_DM_API_DISCOVER));
2090 memcpy(bta_dm_search_cb.p_search_queue, p_data, sizeof(tBTA_DM_API_DISCOVER));
2091
2092}
2093
2094/*******************************************************************************
2095**
2096** Function bta_dm_search_clear_queue
2097**
2098** Description Clears the queue if API search cancel is called
2099**
2100** Returns void
2101**
2102*******************************************************************************/
2103void bta_dm_search_clear_queue (tBTA_DM_MSG *p_data)
2104{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08002105 UNUSED(p_data);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002106 if(bta_dm_search_cb.p_search_queue)
2107 {
2108 GKI_freebuf(bta_dm_search_cb.p_search_queue);
2109 bta_dm_search_cb.p_search_queue = NULL;
2110 }
2111
2112
2113}
2114
2115/*******************************************************************************
2116**
2117** Function bta_dm_search_cancel_cmpl
2118**
2119** Description Search cancel is complete
2120**
2121** Returns void
2122**
2123*******************************************************************************/
2124void bta_dm_search_cancel_cmpl (tBTA_DM_MSG *p_data)
2125{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08002126 UNUSED(p_data);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002127 if(bta_dm_search_cb.p_search_queue)
2128 {
2129 bta_sys_sendmsg(bta_dm_search_cb.p_search_queue);
2130 bta_dm_search_cb.p_search_queue = NULL;
2131 }
2132
2133}
2134
2135/*******************************************************************************
2136**
2137** Function bta_dm_search_cancel_transac_cmpl
2138**
2139** Description Current Service Discovery or remote name procedure is
2140** completed after search cancellation
2141**
2142** Returns void
2143**
2144*******************************************************************************/
2145void bta_dm_search_cancel_transac_cmpl(tBTA_DM_MSG *p_data)
2146{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08002147 UNUSED(p_data);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002148 if(bta_dm_search_cb.p_sdp_db)
2149 {
2150 GKI_freebuf(bta_dm_search_cb.p_sdp_db);
2151 bta_dm_search_cb.p_sdp_db = NULL;
2152 }
2153
2154 bta_dm_search_cancel_notify(NULL);
2155}
2156
2157
2158/*******************************************************************************
2159**
2160** Function bta_dm_search_cancel_notify
2161**
2162** Description Notify application that search has been cancelled
2163**
2164** Returns void
2165**
2166*******************************************************************************/
2167void bta_dm_search_cancel_notify (tBTA_DM_MSG *p_data)
2168{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08002169 UNUSED(p_data);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002170 if (bta_dm_search_cb.p_search_cback)
2171 {
2172 bta_dm_search_cb.p_search_cback(BTA_DM_SEARCH_CANCEL_CMPL_EVT, NULL);
2173 }
2174 if (!bta_dm_search_cb.name_discover_done)
2175 {
2176 BTM_CancelRemoteDeviceName();
2177 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002178#if (BLE_INCLUDED == TRUE) && (BTA_GATT_INCLUDED == TRUE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002179 if (bta_dm_search_cb.gatt_disc_active)
2180 {
2181 bta_dm_cancel_gatt_discovery(bta_dm_search_cb.peer_bdaddr);
2182 }
2183#endif
2184
2185}
2186
2187/*******************************************************************************
2188**
2189** Function bta_dm_find_services
2190**
2191** Description Starts discovery on a device
2192**
2193** Returns void
2194**
2195*******************************************************************************/
2196static void bta_dm_find_services ( BD_ADDR bd_addr)
2197{
2198
2199 tSDP_UUID uuid;
2200 UINT16 attr_list[] = {ATTR_ID_SERVICE_CLASS_ID_LIST, ATTR_ID_EXT_BRCM_VERSION};
2201 UINT16 num_attrs = 1;
2202 tBTA_DM_MSG *p_msg;
2203
2204 memset (&uuid, 0, sizeof(tSDP_UUID));
2205
2206 while(bta_dm_search_cb.service_index < BTA_MAX_SERVICE_ID)
2207 {
2208 if( bta_dm_search_cb.services_to_search
2209 & (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(bta_dm_search_cb.service_index)))
2210 {
2211 if((bta_dm_search_cb.p_sdp_db = (tSDP_DISCOVERY_DB *)GKI_getbuf(BTA_DM_SDP_DB_SIZE)) != NULL)
2212 {
2213 APPL_TRACE_DEBUG1("bta_dm_search_cb.services = %04x***********", bta_dm_search_cb.services);
2214 /* try to search all services by search based on L2CAP UUID */
2215 if(bta_dm_search_cb.services == BTA_ALL_SERVICE_MASK )
2216 {
2217 APPL_TRACE_ERROR1("services_to_search = %08x",bta_dm_search_cb.services_to_search);
2218 if (bta_dm_search_cb.services_to_search & BTA_RES_SERVICE_MASK)
2219 {
2220 uuid.uu.uuid16 = bta_service_id_to_uuid_lkup_tbl[0];
2221 bta_dm_search_cb.services_to_search &= ~BTA_RES_SERVICE_MASK;
2222 }
2223 else
2224 {
2225 uuid.uu.uuid16 = UUID_PROTOCOL_L2CAP;
2226 bta_dm_search_cb.services_to_search = 0;
2227 }
2228 }
2229 else
2230 {
2231#if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
2232 /* for LE only profile */
2233 if (bta_dm_search_cb.service_index == BTA_BLE_SERVICE_ID)
2234 {
2235 if (bta_dm_search_cb.uuid_to_search > 0 && bta_dm_search_cb.p_srvc_uuid)
2236 {
2237 memcpy(&uuid,
2238 (const void *)(bta_dm_search_cb.p_srvc_uuid + \
2239 bta_dm_search_cb.num_uuid - bta_dm_search_cb.uuid_to_search),
2240 sizeof(tBT_UUID));
2241
2242 bta_dm_search_cb.uuid_to_search -- ;
2243 }
2244 else
2245 uuid.uu.uuid16 = bta_service_id_to_uuid_lkup_tbl[bta_dm_search_cb.service_index];
2246
2247 /* last one? clear the BLE service bit if all discovery has been done */
2248 if (bta_dm_search_cb.uuid_to_search == 0)
2249 bta_dm_search_cb.services_to_search &=
2250 (tBTA_SERVICE_MASK)(~(BTA_SERVICE_ID_TO_SERVICE_MASK(bta_dm_search_cb.service_index)));
2251
2252 }
2253 else
2254#endif
2255 {
2256 /* remove the service from services to be searched */
2257 bta_dm_search_cb.services_to_search &=
2258 (tBTA_SERVICE_MASK)(~(BTA_SERVICE_ID_TO_SERVICE_MASK(bta_dm_search_cb.service_index)));
2259 uuid.uu.uuid16 = bta_service_id_to_uuid_lkup_tbl[bta_dm_search_cb.service_index];
2260 }
2261 }
2262
2263 if (uuid.len == 0)
2264 uuid.len = LEN_UUID_16;
2265
2266#if 0
2267 if (uuid.uu.uuid16 == UUID_SERVCLASS_PNP_INFORMATION)
2268 {
2269 num_attrs = 2;
2270 }
2271#endif
2272
2273 if (bta_dm_search_cb.service_index == BTA_USER_SERVICE_ID)
2274 {
2275 memcpy(&uuid, &bta_dm_search_cb.uuid, sizeof(tSDP_UUID));
2276 }
2277
2278
2279 APPL_TRACE_ERROR1("****************search UUID = %04x***********", uuid.uu.uuid16);
2280 //SDP_InitDiscoveryDb (bta_dm_search_cb.p_sdp_db, BTA_DM_SDP_DB_SIZE, 1, &uuid, num_attrs, attr_list);
2281 SDP_InitDiscoveryDb (bta_dm_search_cb.p_sdp_db, BTA_DM_SDP_DB_SIZE, 1, &uuid, 0, NULL);
2282
2283
2284 memset(g_disc_raw_data_buf, 0, sizeof(g_disc_raw_data_buf));
2285 bta_dm_search_cb.p_sdp_db->raw_data = g_disc_raw_data_buf;
2286
2287 bta_dm_search_cb.p_sdp_db->raw_size = MAX_DISC_RAW_DATA_BUF;
2288
2289 if (!SDP_ServiceSearchAttributeRequest (bd_addr, bta_dm_search_cb.p_sdp_db, &bta_dm_sdp_callback))
2290 {
2291 /* if discovery not successful with this device
2292 proceed to next one */
2293 GKI_freebuf(bta_dm_search_cb.p_sdp_db);
2294 bta_dm_search_cb.p_sdp_db = NULL;
2295 bta_dm_search_cb.service_index = BTA_MAX_SERVICE_ID;
2296
2297 }
2298 else
2299 {
2300#if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
2301 if ((bta_dm_search_cb.service_index == BTA_BLE_SERVICE_ID &&
2302 bta_dm_search_cb.uuid_to_search == 0) ||
2303 bta_dm_search_cb.service_index != BTA_BLE_SERVICE_ID)
2304#endif
2305 bta_dm_search_cb.service_index++;
2306 return;
2307 }
2308 }
2309 else
2310 {
2311 APPL_TRACE_ERROR0("#### Failed to allocate SDP DB buffer! ####");
2312 }
2313 }
2314
2315 bta_dm_search_cb.service_index++;
2316 }
2317
2318 /* no more services to be discovered */
2319 if(bta_dm_search_cb.service_index >= BTA_MAX_SERVICE_ID)
2320 {
2321 if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL)
2322 {
2323 p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT;
2324 p_msg->disc_result.result.disc_res.services = bta_dm_search_cb.services_found;
2325 bdcpy (p_msg->disc_result.result.disc_res.bd_addr, bta_dm_search_cb.peer_bdaddr);
2326 BCM_STRNCPY_S((char*)p_msg->disc_result.result.disc_res.bd_name, sizeof(BD_NAME),
2327 bta_dm_get_remname(), (BD_NAME_LEN-1));
2328
2329 /* make sure the string is terminated */
2330 p_msg->disc_result.result.disc_res.bd_name[BD_NAME_LEN-1] = 0;
2331
2332 bta_sys_sendmsg(p_msg);
2333 }
2334 }
2335}
2336
2337/*******************************************************************************
2338**
2339** Function bta_dm_discover_next_device
2340**
2341** Description Starts discovery on the next device in Inquiry data base
2342**
2343** Returns void
2344**
2345*******************************************************************************/
2346static void bta_dm_discover_next_device(void)
2347{
2348
2349 tBTA_DM_MSG * p_msg;
2350
2351 APPL_TRACE_DEBUG0("bta_dm_discover_next_device");
2352
2353 /* searching next device on inquiry result */
2354 if((bta_dm_search_cb.p_btm_inq_info = BTM_InqDbNext(bta_dm_search_cb.p_btm_inq_info)) != NULL)
2355 {
2356 bta_dm_search_cb.name_discover_done = FALSE;
2357 bta_dm_search_cb.peer_name[0] = 0;
2358 bta_dm_discover_device(bta_dm_search_cb.p_btm_inq_info->results.remote_bd_addr);
2359 }
2360 else
2361 {
2362 /* no devices, search complete */
2363 bta_dm_search_cb.services = 0;
2364
2365 if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL)
2366 {
2367 p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT;
2368 p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT;
2369 bta_sys_sendmsg(p_msg);
2370 }
2371 }
2372}
2373
2374/*******************************************************************************
2375**
2376** Function bta_dm_discover_device
2377**
2378** Description Starts name and service discovery on the device
2379**
2380** Returns void
2381**
2382*******************************************************************************/
2383static void bta_dm_discover_device(BD_ADDR remote_bd_addr)
2384{
2385 tBTA_DM_MSG * p_msg;
2386
The Android Open Source Project5738f832012-12-12 16:00:35 -08002387 APPL_TRACE_DEBUG6("bta_dm_discover_device, BDA:0x%02X%02X%02X%02X%02X%02X",
2388 remote_bd_addr[0],remote_bd_addr[1],
2389 remote_bd_addr[2],remote_bd_addr[3],
2390 remote_bd_addr[4],remote_bd_addr[5]);
2391
2392 bdcpy(bta_dm_search_cb.peer_bdaddr, remote_bd_addr);
2393
2394 APPL_TRACE_DEBUG2("bta_dm_discover_device name_discover_done = %d p_btm_inq_info 0x%x ",
2395 bta_dm_search_cb.name_discover_done,
2396 bta_dm_search_cb.p_btm_inq_info
2397 );
2398 if ( bta_dm_search_cb.p_btm_inq_info ) {
2399
2400 APPL_TRACE_DEBUG1("bta_dm_discover_device appl_knows_rem_name %d",
2401 bta_dm_search_cb.p_btm_inq_info->appl_knows_rem_name
2402 );
2403 }
2404
2405 /* if name discovery is not done and application needs remote name */
2406 if ((!bta_dm_search_cb.name_discover_done)
2407 && (( bta_dm_search_cb.p_btm_inq_info == NULL )
2408 ||(bta_dm_search_cb.p_btm_inq_info && (!bta_dm_search_cb.p_btm_inq_info->appl_knows_rem_name))))
2409 {
2410 if( bta_dm_read_remote_device_name(bta_dm_search_cb.peer_bdaddr) == TRUE )
2411 {
2412 return;
2413 }
2414 else
2415 {
2416 /* starting name discovery failed */
2417 bta_dm_search_cb.name_discover_done = TRUE;
2418 }
2419 }
2420
2421 /* if application wants to discover service */
2422 if ( bta_dm_search_cb.services )
2423 {
2424 /* initialize variables */
2425 bta_dm_search_cb.service_index = 0;
2426 bta_dm_search_cb.services_found = 0;
2427 bta_dm_search_cb.services_to_search = bta_dm_search_cb.services;
2428#if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
2429 bta_dm_search_cb.uuid_to_search = bta_dm_search_cb.num_uuid;
2430#endif
2431#if ( BTM_EIR_CLIENT_INCLUDED == TRUE )
2432 if ((bta_dm_search_cb.p_btm_inq_info != NULL) &&
2433 bta_dm_search_cb.services != BTA_USER_SERVICE_MASK
2434 &&(bta_dm_search_cb.sdp_search == FALSE))
2435 {
2436 /* check if EIR provides the information of supported services */
2437 bta_dm_eir_search_services( &bta_dm_search_cb.p_btm_inq_info->results,
2438 &bta_dm_search_cb.services_to_search,
2439 &bta_dm_search_cb.services_found );
2440 }
2441
2442 /* if seaching with EIR is not completed */
2443 if(bta_dm_search_cb.services_to_search)
2444#endif
2445 {
2446 /* check whether connection already exists to the device
2447 if connection exists, we don't have to wait for ACL
2448 link to go down to start search on next device */
2449 if(BTM_IsAclConnectionUp(bta_dm_search_cb.peer_bdaddr))
2450 bta_dm_search_cb.wait_disc = FALSE;
2451 else
2452 bta_dm_search_cb.wait_disc = TRUE;
2453
2454#if (BLE_INCLUDED == TRUE && (defined BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE))
2455 if ( bta_dm_search_cb.p_btm_inq_info )
2456 {
2457 APPL_TRACE_DEBUG3("bta_dm_discover_device p_btm_inq_info 0x%x results.device_type 0x%x services_to_search 0x%x",
2458 bta_dm_search_cb.p_btm_inq_info,
2459 bta_dm_search_cb.p_btm_inq_info->results.device_type,
2460 bta_dm_search_cb.services_to_search
2461 );
2462 }
Andre Eisenbach6975b4d2013-08-05 16:55:38 -07002463 if (BTM_UseLeLink(bta_dm_search_cb.peer_bdaddr))
The Android Open Source Project5738f832012-12-12 16:00:35 -08002464 /*
2465 if ( bta_dm_search_cb.p_btm_inq_info != NULL &&
2466 bta_dm_search_cb.p_btm_inq_info->results.device_type == BT_DEVICE_TYPE_BLE &&
2467 (bta_dm_search_cb.services_to_search & BTA_BLE_SERVICE_MASK))*/
2468 {
2469 if (bta_dm_search_cb.services_to_search & BTA_BLE_SERVICE_MASK)
2470 {
2471 //set the raw data buffer here
2472 memset(g_disc_raw_data_buf, 0, sizeof(g_disc_raw_data_buf));
2473 bta_dm_search_cb.p_ble_rawdata = g_disc_raw_data_buf;
2474
2475 bta_dm_search_cb.ble_raw_size = MAX_DISC_RAW_DATA_BUF;
2476 bta_dm_search_cb.ble_raw_used = 0;
2477
2478 /* start GATT for service discovery */
2479 btm_dm_start_gatt_discovery(bta_dm_search_cb.peer_bdaddr);
2480 return;
2481 }
2482 }
2483 else
2484#endif
2485 {
2486 bta_dm_search_cb.sdp_results = FALSE;
2487 bta_dm_find_services(bta_dm_search_cb.peer_bdaddr);
2488
2489 return;
2490 }
2491 }
2492 }
2493
2494 /* name discovery and service discovery are done for this device */
2495 if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL)
2496 {
2497 p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT;
2498 /* initialize the data structure - includes p_raw_data and raw_data_size */
2499 memset(&(p_msg->disc_result.result), 0, sizeof(tBTA_DM_DISC_RES));
2500 p_msg->disc_result.result.disc_res.result = BTA_SUCCESS;
2501 p_msg->disc_result.result.disc_res.services = bta_dm_search_cb.services_found;
2502 bdcpy (p_msg->disc_result.result.disc_res.bd_addr, bta_dm_search_cb.peer_bdaddr);
2503 BCM_STRNCPY_S((char*)p_msg->disc_result.result.disc_res.bd_name, sizeof(BD_NAME),
2504 (char*)bta_dm_search_cb.peer_name, (BD_NAME_LEN-1));
2505
2506 /* make sure the string is terminated */
2507 p_msg->disc_result.result.disc_res.bd_name[BD_NAME_LEN-1] = 0;
2508
2509 bta_sys_sendmsg(p_msg);
2510 }
2511}
2512
2513/*******************************************************************************
2514**
2515** Function bta_dm_sdp_callback
2516**
2517** Description Callback from sdp with discovery status
2518**
2519** Returns void
2520**
2521*******************************************************************************/
2522static void bta_dm_sdp_callback (UINT16 sdp_status)
2523{
2524
2525 tBTA_DM_SDP_RESULT * p_msg;
2526
2527 if ((p_msg = (tBTA_DM_SDP_RESULT *) GKI_getbuf(sizeof(tBTA_DM_SDP_RESULT))) != NULL)
2528 {
2529 p_msg->hdr.event = BTA_DM_SDP_RESULT_EVT;
2530 p_msg->sdp_result = sdp_status;
2531 bta_sys_sendmsg(p_msg);
2532
2533 }
2534}
2535
2536/*******************************************************************************
2537**
2538** Function bta_dm_inq_results_cb
2539**
2540** Description Inquiry results callback from BTM
2541**
2542** Returns void
2543**
2544*******************************************************************************/
2545static void bta_dm_inq_results_cb (tBTM_INQ_RESULTS *p_inq, UINT8 *p_eir)
2546{
2547
2548 tBTA_DM_SEARCH result;
2549 tBTM_INQ_INFO *p_inq_info;
2550 UINT16 service_class;
2551
2552 bdcpy(result.inq_res.bd_addr, p_inq->remote_bd_addr);
2553 memcpy(result.inq_res.dev_class, p_inq->dev_class, DEV_CLASS_LEN);
2554 BTM_COD_SERVICE_CLASS(service_class, p_inq->dev_class);
2555 result.inq_res.is_limited = (service_class & BTM_COD_SERVICE_LMTD_DISCOVER)?TRUE:FALSE;
2556 result.inq_res.rssi = p_inq->rssi;
2557
2558#if (BLE_INCLUDED == TRUE)
2559 result.inq_res.ble_addr_type = p_inq->ble_addr_type;
2560 result.inq_res.inq_result_type = p_inq->inq_result_type;
2561 result.inq_res.device_type = p_inq->device_type;
2562
2563#endif
2564
2565 /* application will parse EIR to find out remote device name */
2566 result.inq_res.p_eir = p_eir;
2567
2568 if((p_inq_info = BTM_InqDbRead(p_inq->remote_bd_addr)) != NULL)
2569 {
2570 /* initialize remt_name_not_required to FALSE so that we get the name by default */
2571 result.inq_res.remt_name_not_required = FALSE;
2572
2573 }
2574
2575 if(bta_dm_search_cb.p_search_cback)
2576 bta_dm_search_cb.p_search_cback(BTA_DM_INQ_RES_EVT, &result);
2577
2578 if(p_inq_info)
2579 {
2580 /* application indicates if it knows the remote name, inside the callback
2581 copy that to the inquiry data base*/
2582 if(result.inq_res.remt_name_not_required)
2583 p_inq_info->appl_knows_rem_name = TRUE;
2584
2585 }
2586
2587
2588}
2589
2590
2591/*******************************************************************************
2592**
2593** Function bta_dm_inq_cmpl_cb
2594**
2595** Description Inquiry complete callback from BTM
2596**
2597** Returns void
2598**
2599*******************************************************************************/
2600static void bta_dm_inq_cmpl_cb (void * p_result)
2601{
2602
2603 tBTA_DM_MSG * p_msg;
2604
2605 APPL_TRACE_DEBUG0("bta_dm_inq_cmpl_cb");
2606 if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL)
2607 {
2608 p_msg->inq_cmpl.hdr.event = BTA_DM_INQUIRY_CMPL_EVT;
2609 p_msg->inq_cmpl.num = ((tBTM_INQUIRY_CMPL *)p_result)->num_resp;
2610 bta_sys_sendmsg(p_msg);
2611
2612 }
2613
2614
2615}
2616
2617/*******************************************************************************
2618**
2619** Function bta_dm_service_search_remname_cback
2620**
2621** Description Remote name call back from BTM during service discovery
2622**
2623** Returns void
2624**
2625*******************************************************************************/
2626static void bta_dm_service_search_remname_cback (BD_ADDR bd_addr, DEV_CLASS dc, BD_NAME bd_name)
2627{
2628 tBTM_REMOTE_DEV_NAME rem_name;
2629 tBTM_STATUS btm_status;
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08002630 UNUSED(dc);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002631
2632 APPL_TRACE_DEBUG1("bta_dm_service_search_remname_cback name=<%s>", bd_name);
2633
2634 /* if this is what we are looking for */
2635 if (!bdcmp( bta_dm_search_cb.peer_bdaddr, bd_addr))
2636 {
2637 rem_name.length = strlen((char*)bd_name);
2638 if (rem_name.length > (BD_NAME_LEN-1))
2639 {
2640 rem_name.length = (BD_NAME_LEN-1);
2641 rem_name.remote_bd_name[(BD_NAME_LEN-1)] = 0;
2642 }
2643 BCM_STRNCPY_S((char*)rem_name.remote_bd_name, sizeof(BD_NAME), (char*)bd_name, (BD_NAME_LEN-1));
2644 rem_name.status = BTM_SUCCESS;
2645
2646 bta_dm_remname_cback(&rem_name);
2647 }
2648 else
2649 {
2650 /* get name of device */
2651 btm_status = BTM_ReadRemoteDeviceName (bta_dm_search_cb.peer_bdaddr,
2652 (tBTM_CMPL_CB *) bta_dm_remname_cback);
2653 if ( btm_status == BTM_BUSY )
2654 {
2655 /* wait for next chance(notification of remote name discovery done) */
2656 APPL_TRACE_DEBUG0("bta_dm_service_search_remname_cback: BTM_ReadRemoteDeviceName is busy");
2657 }
2658 else if ( btm_status != BTM_CMD_STARTED )
2659 {
2660 /* if failed to start getting remote name then continue */
2661 APPL_TRACE_WARNING1("bta_dm_service_search_remname_cback: BTM_ReadRemoteDeviceName returns 0x%02X", btm_status);
2662
2663 rem_name.length = 0;
2664 rem_name.remote_bd_name[0] = 0;
2665 rem_name.status = btm_status;
2666 bta_dm_remname_cback(&rem_name);
2667 }
2668 }
2669}
2670
2671
2672/*******************************************************************************
2673**
2674** Function bta_dm_remname_cback
2675**
2676** Description Remote name complete call back from BTM
2677**
2678** Returns void
2679**
2680*******************************************************************************/
2681static void bta_dm_remname_cback (tBTM_REMOTE_DEV_NAME *p_remote_name)
2682{
2683 tBTA_DM_REM_NAME * p_msg;
2684
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002685 APPL_TRACE_DEBUG2("bta_dm_remname_cback len = %d name=<%s>", p_remote_name->length,
2686 p_remote_name->remote_bd_name);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002687
2688 /* remote name discovery is done but it could be failed */
2689 bta_dm_search_cb.name_discover_done = TRUE;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002690 BCM_STRNCPY_S((char*)bta_dm_search_cb.peer_name, sizeof(BD_NAME), (char*)p_remote_name->remote_bd_name, (BD_NAME_LEN));
2691 bta_dm_search_cb.peer_name[BD_NAME_LEN]=0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002692
2693 BTM_SecDeleteRmtNameNotifyCallback(&bta_dm_service_search_remname_cback);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002694#if BLE_INCLUDED == TRUE
Andre Eisenbach6975b4d2013-08-05 16:55:38 -07002695 if (BTM_UseLeLink(bta_dm_search_cb.peer_bdaddr))
Andre Eisenbach4c433be2013-04-01 10:27:47 -07002696 GAP_BleReadPeerPrefConnParams (bta_dm_search_cb.peer_bdaddr);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002697#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08002698 if ((p_msg = (tBTA_DM_REM_NAME *) GKI_getbuf(sizeof(tBTA_DM_REM_NAME))) != NULL)
2699 {
2700 bdcpy (p_msg->result.disc_res.bd_addr, bta_dm_search_cb.peer_bdaddr);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002701 BCM_STRNCPY_S((char*)p_msg->result.disc_res.bd_name, sizeof(BD_NAME), (char*)p_remote_name->remote_bd_name, (BD_NAME_LEN));
The Android Open Source Project5738f832012-12-12 16:00:35 -08002702
2703 /* make sure the string is null terminated */
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002704 p_msg->result.disc_res.bd_name[BD_NAME_LEN] = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002705
2706 p_msg->hdr.event = BTA_DM_REMT_NAME_EVT;
2707 bta_sys_sendmsg(p_msg);
2708
2709 }
2710}
2711
2712/*******************************************************************************
2713**
2714** Function bta_dm_authorize_cback
2715**
2716** Description cback requesting authorization
2717**
2718** Returns void
2719**
2720*******************************************************************************/
2721static UINT8 bta_dm_authorize_cback (BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name,
2722 UINT8 *service_name, UINT8 service_id, BOOLEAN is_originator)
2723{
2724 tBTA_DM_SEC sec_event;
2725 UINT8 index = 1;
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08002726 UNUSED(service_name);
2727 UNUSED(is_originator);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002728
2729 bdcpy(sec_event.authorize.bd_addr, bd_addr);
2730 memcpy(sec_event.authorize.dev_class, dev_class, DEV_CLASS_LEN);
2731
2732 BCM_STRNCPY_S((char*)sec_event.authorize.bd_name, sizeof(BD_NAME), (char*)bd_name, (BD_NAME_LEN-1));
2733
2734 /* make sure the string is null terminated */
2735 sec_event.authorize.bd_name[BD_NAME_LEN-1] = 0;
2736
2737#if ( defined(BTA_JV_INCLUDED) && BTA_JV_INCLUDED == TRUE )
2738 sec_event.authorize.service = service_id;
2739#endif
2740
2741 while(index < BTA_MAX_SERVICE_ID)
2742 {
2743 /* get the BTA service id corresponding to BTM id */
2744 if(bta_service_id_to_btm_srv_id_lkup_tbl[index] == service_id)
2745 {
2746 sec_event.authorize.service = index;
2747 break;
2748 }
2749 index++;
2750 }
2751
2752
2753 /* if supported service callback otherwise not authorized */
2754 if(bta_dm_cb.p_sec_cback && (index < BTA_MAX_SERVICE_ID
2755#if ( defined(BTA_JV_INCLUDED) && BTA_JV_INCLUDED == TRUE )
2756 /* pass through JV service ID */
2757 || (service_id >= BTA_FIRST_JV_SERVICE_ID && service_id <= BTA_LAST_JV_SERVICE_ID)
2758#endif
2759 ))
2760 {
2761 bta_dm_cb.p_sec_cback(BTA_DM_AUTHORIZE_EVT, &sec_event);
2762 return BTM_CMD_STARTED;
2763 }
2764 else
2765 {
2766 return BTM_NOT_AUTHORIZED;
2767 }
2768}
2769
2770
2771
2772
2773
2774/*******************************************************************************
2775**
2776** Function bta_dm_pinname_cback
2777**
2778** Description Callback requesting pin_key
2779**
2780** Returns void
2781**
2782*******************************************************************************/
2783static void bta_dm_pinname_cback (void *p_data)
2784{
2785 tBTM_REMOTE_DEV_NAME *p_result = (tBTM_REMOTE_DEV_NAME *)p_data;
2786 tBTA_DM_SEC sec_event;
2787 UINT32 bytes_to_copy;
2788 tBTA_DM_SEC_EVT event = bta_dm_cb.pin_evt;
2789
2790 if (BTA_DM_SP_CFM_REQ_EVT == event)
2791 {
Andre Eisenbach181d0752013-06-11 14:18:21 -07002792 /* Retrieved saved device class and bd_addr */
2793 bdcpy(sec_event.cfm_req.bd_addr, bta_dm_cb.pin_bd_addr);
2794 BTA_COPY_DEVICE_CLASS(sec_event.cfm_req.dev_class, bta_dm_cb.pin_dev_class);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002795
Andre Eisenbach181d0752013-06-11 14:18:21 -07002796 if (p_result && p_result->status == BTM_SUCCESS)
2797 {
2798 bytes_to_copy = (p_result->length < (BD_NAME_LEN-1))
The Android Open Source Project5738f832012-12-12 16:00:35 -08002799 ? p_result->length : (BD_NAME_LEN-1);
Andre Eisenbach181d0752013-06-11 14:18:21 -07002800 memcpy(sec_event.cfm_req.bd_name, p_result->remote_bd_name, bytes_to_copy);
2801 sec_event.pin_req.bd_name[BD_NAME_LEN-1] = 0;
2802 }
2803 else /* No name found */
2804 sec_event.cfm_req.bd_name[0] = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002805
Andre Eisenbach181d0752013-06-11 14:18:21 -07002806 sec_event.key_notif.passkey = bta_dm_cb.num_val; /* get PIN code numeric number */
The Android Open Source Project5738f832012-12-12 16:00:35 -08002807
2808 /* 1 additional event data fields for this event */
2809 sec_event.cfm_req.just_works = bta_dm_cb.just_works;
2810 }
2811 else
2812 {
Andre Eisenbach181d0752013-06-11 14:18:21 -07002813 /* Retrieved saved device class and bd_addr */
2814 bdcpy(sec_event.pin_req.bd_addr, bta_dm_cb.pin_bd_addr);
2815 BTA_COPY_DEVICE_CLASS(sec_event.pin_req.dev_class, bta_dm_cb.pin_dev_class);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002816
Andre Eisenbach181d0752013-06-11 14:18:21 -07002817 if (p_result && p_result->status == BTM_SUCCESS)
2818 {
2819 bytes_to_copy = (p_result->length < (BD_NAME_LEN-1))
The Android Open Source Project5738f832012-12-12 16:00:35 -08002820 ? p_result->length : (BD_NAME_LEN-1);
Andre Eisenbach181d0752013-06-11 14:18:21 -07002821 memcpy(sec_event.pin_req.bd_name, p_result->remote_bd_name, bytes_to_copy);
2822 sec_event.pin_req.bd_name[BD_NAME_LEN-1] = 0;
2823 }
2824 else /* No name found */
2825 sec_event.pin_req.bd_name[0] = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002826
Andre Eisenbach181d0752013-06-11 14:18:21 -07002827 event = bta_dm_cb.pin_evt;
2828 sec_event.key_notif.passkey = bta_dm_cb.num_val; /* get PIN code numeric number */
The Android Open Source Project5738f832012-12-12 16:00:35 -08002829 }
2830
2831 if( bta_dm_cb.p_sec_cback )
2832 bta_dm_cb.p_sec_cback(event, &sec_event);
2833}
2834
2835
2836
2837/*******************************************************************************
2838**
2839** Function bta_dm_pin_cback
2840**
2841** Description Callback requesting pin_key
2842**
2843** Returns void
2844**
2845*******************************************************************************/
2846static UINT8 bta_dm_pin_cback (BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name)
2847{
2848 tBTA_DM_SEC sec_event;
2849
2850 if (!bta_dm_cb.p_sec_cback)
2851 return BTM_NOT_AUTHORIZED;
2852
2853 /* If the device name is not known, save bdaddr and devclass and initiate a name request */
2854 if (bd_name[0] == 0)
2855 {
2856 bta_dm_cb.pin_evt = BTA_DM_PIN_REQ_EVT;
2857 bdcpy(bta_dm_cb.pin_bd_addr, bd_addr);
2858 BTA_COPY_DEVICE_CLASS(bta_dm_cb.pin_dev_class, dev_class);
2859 if ((BTM_ReadRemoteDeviceName(bd_addr, bta_dm_pinname_cback)) == BTM_CMD_STARTED)
2860 return BTM_CMD_STARTED;
2861
2862 APPL_TRACE_WARNING0(" bta_dm_pin_cback() -> Failed to start Remote Name Request ");
2863 }
2864
2865 bdcpy(sec_event.pin_req.bd_addr, bd_addr);
2866 BTA_COPY_DEVICE_CLASS(sec_event.pin_req.dev_class, dev_class);
2867 BCM_STRNCPY_S((char*)sec_event.pin_req.bd_name, sizeof(BD_NAME), (char*)bd_name, (BD_NAME_LEN-1));
2868 sec_event.pin_req.bd_name[BD_NAME_LEN-1] = 0;
2869
2870 bta_dm_cb.p_sec_cback(BTA_DM_PIN_REQ_EVT, &sec_event);
2871 return BTM_CMD_STARTED;
2872}
2873
2874
2875
2876/*******************************************************************************
2877**
2878** Function bta_dm_link_key_request_cback
2879**
2880** Description Callback requesting linkkey
2881**
2882** Returns void
2883**
2884*******************************************************************************/
2885static UINT8 bta_dm_link_key_request_cback (BD_ADDR bd_addr, LINK_KEY key)
2886{
2887 /* Application passes all link key to
2888 BTM during initialization using add_device
2889 API. If BTM doesn't have the link key in it's
2890 data base, that's because application doesn't
2891 it */
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08002892 UNUSED(bd_addr);
2893 UNUSED(key);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002894
2895 return BTM_NOT_AUTHORIZED;
2896}
2897
2898
2899
2900
2901
2902/*******************************************************************************
2903**
2904** Function bta_dm_new_link_key_cback
2905**
2906** Description Callback from BTM to notify new link key
2907**
2908** Returns void
2909**
2910*******************************************************************************/
2911static UINT8 bta_dm_new_link_key_cback(BD_ADDR bd_addr, DEV_CLASS dev_class,
2912 BD_NAME bd_name, LINK_KEY key, UINT8 key_type)
2913{
2914 tBTA_DM_SEC sec_event;
2915 tBTA_DM_AUTH_CMPL *p_auth_cmpl;
2916 UINT8 event;
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08002917 UNUSED(dev_class);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002918
2919 memset (&sec_event, 0, sizeof(tBTA_DM_SEC));
2920
2921 /* Not AMP Key type */
2922 if (key_type != HCI_LKEY_TYPE_AMP_WIFI && key_type != HCI_LKEY_TYPE_AMP_UWB)
2923 {
2924 event = BTA_DM_AUTH_CMPL_EVT;
2925 p_auth_cmpl = &sec_event.auth_cmpl;
2926
2927 bdcpy(p_auth_cmpl->bd_addr, bd_addr);
2928
2929 memcpy(p_auth_cmpl->bd_name, bd_name, (BD_NAME_LEN-1));
2930 p_auth_cmpl->bd_name[BD_NAME_LEN-1] = 0;
2931
2932 p_auth_cmpl->key_present = TRUE;
2933 p_auth_cmpl->key_type = key_type;
2934 p_auth_cmpl->success = TRUE;
2935
2936 memcpy(p_auth_cmpl->key, key, LINK_KEY_LEN);
2937 sec_event.auth_cmpl.fail_reason = HCI_SUCCESS;
2938
2939 if(bta_dm_cb.p_sec_cback)
2940 {
2941 bta_dm_cb.p_sec_cback(event, &sec_event);
2942 }
2943 }
2944 else
2945 {
2946 APPL_TRACE_WARNING0(" bta_dm_new_link_key_cback() Received AMP Key?? ");
2947 }
2948
2949 return BTM_CMD_STARTED;
2950}
2951
2952
2953/*******************************************************************************
2954**
2955** Function bta_dm_authentication_complete_cback
2956**
2957** Description Authentication complete callback from BTM
2958**
2959** Returns void
2960**
2961*******************************************************************************/
2962static UINT8 bta_dm_authentication_complete_cback(BD_ADDR bd_addr, DEV_CLASS dev_class,BD_NAME bd_name, int result)
2963{
The Android Open Source Project5738f832012-12-12 16:00:35 -08002964 tBTA_DM_SEC sec_event;
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08002965 UNUSED(dev_class);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002966
2967 if(result != BTM_SUCCESS)
2968 {
2969 memset(&sec_event, 0, sizeof(tBTA_DM_SEC));
2970 bdcpy(sec_event.auth_cmpl.bd_addr, bd_addr);
2971
2972 memcpy(sec_event.auth_cmpl.bd_name, bd_name, (BD_NAME_LEN-1));
2973 sec_event.auth_cmpl.bd_name[BD_NAME_LEN-1] = 0;
2974
2975/* taken care of by memset [above]
2976 sec_event.auth_cmpl.key_present = FALSE;
2977 sec_event.auth_cmpl.success = FALSE;
2978*/
2979 sec_event.auth_cmpl.fail_reason = (UINT8)result;
2980 if(bta_dm_cb.p_sec_cback)
2981 {
2982 bta_dm_cb.p_sec_cback(BTA_DM_AUTH_CMPL_EVT, &sec_event);
2983 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002984 /* delete this device entry from Sec Dev DB */
2985 bta_dm_remove_sec_dev_entry(bd_addr);
Andre Eisenbach6975b4d2013-08-05 16:55:38 -07002986
The Android Open Source Project5738f832012-12-12 16:00:35 -08002987 }
2988
2989 return BTM_SUCCESS;
2990}
2991
2992/*******************************************************************************
2993**
2994** Function bta_dm_sp_cback
2995**
2996** Description simple pairing callback from BTM
2997**
2998** Returns void
2999**
3000*******************************************************************************/
3001static UINT8 bta_dm_sp_cback (tBTM_SP_EVT event, tBTM_SP_EVT_DATA *p_data)
3002{
3003 tBTM_STATUS status = BTM_CMD_STARTED;
3004 tBTA_DM_SEC sec_event;
3005 tBTA_DM_SEC_EVT pin_evt = BTA_DM_SP_KEY_NOTIF_EVT;
3006
3007 APPL_TRACE_EVENT1("bta_dm_sp_cback: %d", event);
3008 if (!bta_dm_cb.p_sec_cback)
3009 return BTM_NOT_AUTHORIZED;
3010
3011 /* TODO_SP */
3012 switch(event)
3013 {
3014 case BTM_SP_IO_REQ_EVT:
3015#if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE)
3016 /* translate auth_req */
3017 bta_dm_co_io_req(p_data->io_req.bd_addr, &p_data->io_req.io_cap,
3018 &p_data->io_req.oob_data, &p_data->io_req.auth_req, p_data->io_req.is_orig);
3019#endif
3020#if BTM_OOB_INCLUDED == FALSE
3021 status = BTM_SUCCESS;
3022#endif
3023
3024 APPL_TRACE_EVENT2("io mitm: %d oob_data:%d", p_data->io_req.auth_req, p_data->io_req.oob_data);
3025 break;
3026 case BTM_SP_IO_RSP_EVT:
3027#if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE)
3028 bta_dm_co_io_rsp(p_data->io_rsp.bd_addr, p_data->io_rsp.io_cap,
3029 p_data->io_rsp.oob_data, p_data->io_rsp.auth_req );
3030#endif
3031 break;
3032
3033 case BTM_SP_CFM_REQ_EVT:
3034 pin_evt = BTA_DM_SP_CFM_REQ_EVT;
3035 bta_dm_cb.just_works = sec_event.cfm_req.just_works = p_data->cfm_req.just_works;
3036 sec_event.cfm_req.loc_auth_req = p_data->cfm_req.loc_auth_req;
3037 sec_event.cfm_req.rmt_auth_req = p_data->cfm_req.rmt_auth_req;
3038 sec_event.cfm_req.loc_io_caps = p_data->cfm_req.loc_io_caps;
3039 sec_event.cfm_req.rmt_io_caps = p_data->cfm_req.rmt_io_caps;
3040 /* continue to next case */
3041#if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE)
3042 /* Passkey entry mode, mobile device with output capability is very
3043 unlikely to receive key request, so skip this event */
3044 /*case BTM_SP_KEY_REQ_EVT: */
3045 case BTM_SP_KEY_NOTIF_EVT:
3046#endif
3047 bta_dm_cb.num_val = sec_event.key_notif.passkey = p_data->key_notif.passkey;
3048 /* If the device name is not known, save bdaddr and devclass and initiate a name request */
3049 if (p_data->key_notif.bd_name[0] == 0)
3050 {
3051 bta_dm_cb.pin_evt = pin_evt;
3052 bdcpy(bta_dm_cb.pin_bd_addr, p_data->key_notif.bd_addr);
3053 BTA_COPY_DEVICE_CLASS(bta_dm_cb.pin_dev_class, p_data->key_notif.dev_class);
3054 if ((BTM_ReadRemoteDeviceName(p_data->key_notif.bd_addr, bta_dm_pinname_cback)) == BTM_CMD_STARTED)
3055 return BTM_CMD_STARTED;
3056
3057 APPL_TRACE_WARNING0(" bta_dm_sp_cback() -> Failed to start Remote Name Request ");
3058 }
3059 bdcpy(sec_event.key_notif.bd_addr, p_data->key_notif.bd_addr);
3060 BTA_COPY_DEVICE_CLASS(sec_event.key_notif.dev_class, p_data->key_notif.dev_class);
3061 BCM_STRNCPY_S((char*)sec_event.key_notif.bd_name, sizeof(BD_NAME), (char*)p_data->key_notif.bd_name, (BD_NAME_LEN-1));
3062 sec_event.key_notif.bd_name[BD_NAME_LEN-1] = 0;
3063
3064 bta_dm_cb.p_sec_cback(pin_evt, &sec_event);
3065
3066 break;
3067
3068#if BTM_OOB_INCLUDED == TRUE
3069 case BTM_SP_LOC_OOB_EVT:
3070 bta_dm_co_loc_oob((BOOLEAN)(p_data->loc_oob.status == BTM_SUCCESS),
3071 p_data->loc_oob.c, p_data->loc_oob.r);
3072 break;
3073
3074 case BTM_SP_RMT_OOB_EVT:
3075 /* If the device name is not known, save bdaddr and devclass and initiate a name request */
3076 if (p_data->rmt_oob.bd_name[0] == 0)
3077 {
3078 bta_dm_cb.pin_evt = BTA_DM_SP_RMT_OOB_EVT;
3079 bdcpy(bta_dm_cb.pin_bd_addr, p_data->rmt_oob.bd_addr);
3080 BTA_COPY_DEVICE_CLASS(bta_dm_cb.pin_dev_class, p_data->rmt_oob.dev_class);
3081 if ((BTM_ReadRemoteDeviceName(p_data->rmt_oob.bd_addr, bta_dm_pinname_cback)) == BTM_CMD_STARTED)
3082 return BTM_CMD_STARTED;
3083
3084 APPL_TRACE_WARNING0(" bta_dm_sp_cback() -> Failed to start Remote Name Request ");
3085 }
3086 bdcpy(sec_event.rmt_oob.bd_addr, p_data->rmt_oob.bd_addr);
3087 BTA_COPY_DEVICE_CLASS(sec_event.rmt_oob.dev_class, p_data->rmt_oob.dev_class);
3088 BCM_STRNCPY_S((char*)sec_event.rmt_oob.bd_name, sizeof(BD_NAME), (char*)p_data->rmt_oob.bd_name, (BD_NAME_LEN-1));
3089 sec_event.rmt_oob.bd_name[BD_NAME_LEN-1] = 0;
3090
3091 bta_dm_cb.p_sec_cback(BTA_DM_SP_RMT_OOB_EVT, &sec_event);
3092
3093 bta_dm_co_rmt_oob(p_data->rmt_oob.bd_addr);
3094 break;
3095#endif
3096 case BTM_SP_COMPLT_EVT:
3097 /* do not report this event - handled by link_key_callback or auth_complete_callback */
3098 break;
3099
3100 case BTM_SP_KEYPRESS_EVT:
3101 memcpy(&sec_event.key_press, &p_data->key_press, sizeof(tBTM_SP_KEYPRESS));
3102 bta_dm_cb.p_sec_cback(BTA_DM_SP_KEYPRESS_EVT, &sec_event);
3103 break;
3104
3105 case BTM_SP_UPGRADE_EVT:
3106 bta_dm_co_lk_upgrade(p_data->upgrade.bd_addr, &p_data->upgrade.upgrade );
3107 break;
3108
3109 default:
3110 status = BTM_NOT_AUTHORIZED;
3111 break;
3112 }
3113 APPL_TRACE_EVENT1("dm status: %d", status);
3114 return status;
3115}
3116
3117/*******************************************************************************
3118**
3119** Function bta_dm_local_name_cback
3120**
3121** Description Callback from btm after local name is read
3122**
3123**
3124** Returns void
3125**
3126*******************************************************************************/
3127static void bta_dm_local_name_cback(UINT8 *p_name)
3128{
3129 tBTA_DM_SEC sec_event;
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08003130 UNUSED(p_name);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003131
3132 BTM_GetLocalDeviceAddr(sec_event.enable.bd_addr);
3133 sec_event.enable.status = BTA_SUCCESS;
3134
3135 if(bta_dm_cb.p_sec_cback)
3136 bta_dm_cb.p_sec_cback(BTA_DM_ENABLE_EVT, &sec_event);
3137}
3138
3139/*******************************************************************************
3140**
3141** Function bta_dm_signal_strength
3142**
3143** Description Callback from btm after local bdaddr is read
3144**
3145**
3146** Returns void
3147**
3148*******************************************************************************/
3149void bta_dm_signal_strength(tBTA_DM_MSG *p_data)
3150{
3151
3152 if(p_data->sig_strength.start)
3153 {
3154 bta_dm_cb.signal_strength_mask = p_data->sig_strength.mask;
3155 bta_dm_cb.signal_strength_period = p_data->sig_strength.period;
3156 bta_dm_signal_strength_timer_cback(NULL);
3157 }
3158 else
3159 {
3160 bta_sys_stop_timer(&bta_dm_cb.signal_strength_timer);
3161 }
3162
3163}
3164/*******************************************************************************
3165**
3166** Function bta_dm_signal_strength_timer_cback
3167**
3168** Description Periodic timer callback to read signal strength
3169**
3170**
3171** Returns void
3172**
3173*******************************************************************************/
3174static void bta_dm_signal_strength_timer_cback (TIMER_LIST_ENT *p_tle)
3175{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08003176 UNUSED(p_tle);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003177 UINT8 i;
3178
3179 if(bta_dm_cb.signal_strength_mask & BTA_SIG_STRENGTH_RSSI_MASK)
3180 {
3181 for(i=0; i<bta_dm_cb.device_list.count; i++)
3182 {
3183 BTM_ReadRSSI (bta_dm_cb.device_list.peer_device[i].peer_bdaddr, (tBTM_CMPL_CB *)bta_dm_rssi_cback);
3184
3185 }
3186 }
3187 if(bta_dm_cb.signal_strength_mask & BTA_SIG_STRENGTH_LINK_QUALITY_MASK)
3188 {
3189
3190 for(i=0; i<bta_dm_cb.device_list.count; i++)
3191 {
3192 BTM_ReadLinkQuality (bta_dm_cb.device_list.peer_device[i].peer_bdaddr, (tBTM_CMPL_CB *)bta_dm_link_quality_cback);
3193 }
3194
3195 }
3196
3197 if(bta_dm_cb.signal_strength_period)
3198 {
3199 bta_dm_cb.signal_strength_timer.p_cback = (TIMER_CBACK*)&bta_dm_signal_strength_timer_cback;
3200 bta_sys_start_timer(&bta_dm_cb.signal_strength_timer, 0, (UINT32)1000*bta_dm_cb.signal_strength_period);
3201 }
3202}
3203
3204
3205#if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
3206/*******************************************************************************
3207**
3208** Function bta_dm_bl_change_cback
3209**
3210** Description Callback from btm when acl connection goes up or down
3211**
3212**
3213** Returns void
3214**
3215*******************************************************************************/
3216static void bta_dm_bl_change_cback (tBTM_BL_EVENT_DATA *p_data)
3217{
The Android Open Source Project5738f832012-12-12 16:00:35 -08003218 tBTA_DM_ACL_CHANGE * p_msg;
3219
3220 if ((p_msg = (tBTA_DM_ACL_CHANGE *) GKI_getbuf(sizeof(tBTA_DM_ACL_CHANGE))) != NULL)
3221 {
3222 p_msg->event = p_data->event;
3223 p_msg->is_new = FALSE;
3224
3225 switch(p_msg->event)
3226 {
3227 case BTM_BL_CONN_EVT:
3228 p_msg->is_new = TRUE;
3229 bdcpy(p_msg->bd_addr, p_data->conn.p_bda);
3230 break;
3231 case BTM_BL_DISCN_EVT:
3232 bdcpy(p_msg->bd_addr, p_data->discn.p_bda);
3233 break;
3234 case BTM_BL_UPDATE_EVT:
3235 p_msg->busy_level = p_data->update.busy_level;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003236 p_msg->busy_level_flags = p_data->update.busy_level_flags;
The Android Open Source Project5738f832012-12-12 16:00:35 -08003237 break;
3238 case BTM_BL_ROLE_CHG_EVT:
3239 p_msg->new_role = p_data->role_chg.new_role;
3240 p_msg->hci_status = p_data->role_chg.hci_status;
3241 bdcpy(p_msg->bd_addr, p_data->role_chg.p_bda);
3242 break;
3243 case BTM_BL_COLLISION_EVT:
3244 bdcpy(p_msg->bd_addr, p_data->conn.p_bda);
3245 break;;
3246 }
3247
3248 p_msg->hdr.event = BTA_DM_ACL_CHANGE_EVT;
3249 bta_sys_sendmsg(p_msg);
3250
3251 }
3252
3253}
3254#else
3255
3256/*******************************************************************************
3257**
3258** Function bta_dm_acl_change_cback
3259**
3260** Description Callback from btm when acl connection goes up or down
3261**
3262**
3263** Returns void
3264**
3265*******************************************************************************/
3266static void bta_dm_acl_change_cback (BD_ADDR p_bda, DEV_CLASS p_dc, BD_NAME p_bdn,
Andre Eisenbach3aa60542013-03-22 18:00:51 -07003267 UINT8 *features, BOOLEAN is_new)
The Android Open Source Project5738f832012-12-12 16:00:35 -08003268{
3269
3270 tBTA_DM_ACL_CHANGE * p_msg;
3271
3272 if ((p_msg = (tBTA_DM_ACL_CHANGE *) GKI_getbuf(sizeof(tBTA_DM_ACL_CHANGE))) != NULL)
3273 {
3274 bdcpy (p_msg->bd_addr, p_bda);
3275 p_msg->is_new = is_new;
3276
3277 /* This is collision case */
3278 if (features != NULL)
3279 {
3280 if ((features[0] == 0xFF) && !is_new)
3281 p_msg->event = BTM_BL_COLLISION_EVT;
3282 }
3283
3284 p_msg->hdr.event = BTA_DM_ACL_CHANGE_EVT;
3285 bta_sys_sendmsg(p_msg);
3286
3287 }
3288
3289}
3290#endif
3291/*******************************************************************************
3292**
3293** Function bta_dm_rs_cback
3294**
3295** Description Receives the role switch complete event
3296**
3297** Returns
3298**
3299*******************************************************************************/
3300static void bta_dm_rs_cback (tBTM_ROLE_SWITCH_CMPL *p1)
3301{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08003302 UNUSED(p1);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003303 APPL_TRACE_WARNING1("bta_dm_rs_cback:%d", bta_dm_cb.rs_event);
3304 if(bta_dm_cb.rs_event == BTA_DM_API_SEARCH_EVT)
3305 {
3306 bta_dm_cb.search_msg.rs_res = BTA_DM_RS_OK; /* do not care about the result for now */
3307 bta_dm_cb.rs_event = 0;
3308 bta_dm_search_start((tBTA_DM_MSG *)&bta_dm_cb.search_msg);
3309 }
3310}
3311
3312/*******************************************************************************
3313**
3314** Function bta_dm_check_av
3315**
3316** Description This function checks if AV is active
3317** if yes, make sure the AV link is master
3318**
3319** Returns BOOLEAN - TRUE, if switch is in progress
3320**
3321*******************************************************************************/
3322static BOOLEAN bta_dm_check_av(UINT16 event)
3323{
Mattias Agren9647e912013-04-08 12:23:42 +02003324 BOOLEAN avoid_roleswitch = FALSE;
The Android Open Source Project5738f832012-12-12 16:00:35 -08003325 BOOLEAN switching = FALSE;
3326 UINT8 i;
3327 tBTA_DM_PEER_DEVICE *p_dev;
3328
Mattias Agren9647e912013-04-08 12:23:42 +02003329#if defined(BTA_DM_AVOID_A2DP_ROLESWITCH_ON_INQUIRY) && (BTA_DM_AVOID_A2DP_ROLESWITCH_ON_INQUIRY == TRUE)
3330
3331 /* avoid role switch upon inquiry if a2dp is actively streaming as it
3332 introduces an audioglitch due to FW scheduling delays (unavoidable) */
3333 if (event == BTA_DM_API_SEARCH_EVT)
3334 {
3335 avoid_roleswitch = TRUE;
3336 }
3337#endif
3338
The Android Open Source Project5738f832012-12-12 16:00:35 -08003339 APPL_TRACE_WARNING1("bta_dm_check_av:%d", bta_dm_cb.cur_av_count);
3340 if(bta_dm_cb.cur_av_count)
3341 {
3342 for(i=0; i<bta_dm_cb.device_list.count; i++)
3343 {
3344 p_dev = &bta_dm_cb.device_list.peer_device[i];
Mattias Agren9647e912013-04-08 12:23:42 +02003345 APPL_TRACE_WARNING4("[%d]: state:%d, info:x%x, avoid_rs %d",
3346 i, p_dev->conn_state, p_dev->info, avoid_roleswitch);
3347 if((p_dev->conn_state == BTA_DM_CONNECTED) && (p_dev->info & BTA_DM_DI_AV_ACTIVE) &&
3348 (avoid_roleswitch == FALSE))
The Android Open Source Project5738f832012-12-12 16:00:35 -08003349 {
3350 /* make master and take away the role switch policy */
3351 if(BTM_CMD_STARTED == BTM_SwitchRole (p_dev->peer_bdaddr, HCI_ROLE_MASTER, (tBTM_CMPL_CB *)bta_dm_rs_cback))
3352 {
3353 /* the role switch command is actually sent */
3354 bta_dm_cb.rs_event = event;
3355 switching = TRUE;
3356 }
3357 /* else either already master or can not switch for some reasons */
3358 bta_dm_policy_cback(BTA_SYS_PLCY_CLR, 0, HCI_ENABLE_MASTER_SLAVE_SWITCH, p_dev->peer_bdaddr);
3359 break;
3360 }
3361 }
3362 }
3363 return switching;
3364}
3365
3366/*******************************************************************************
3367**
3368** Function bta_dm_acl_change
3369**
3370** Description Process BTA_DM_ACL_CHANGE_EVT
3371**
3372**
3373** Returns void
3374**
3375*******************************************************************************/
3376void bta_dm_acl_change(tBTA_DM_MSG *p_data)
3377{
3378
3379 UINT8 i;
3380 UINT8 *p;
3381 tBTA_DM_SEC conn;
3382 BOOLEAN is_new = p_data->acl_change.is_new;
3383 BD_ADDR_PTR p_bda = p_data->acl_change.bd_addr;
3384 BOOLEAN need_policy_change = FALSE;
3385 BOOLEAN issue_unpair_cb = FALSE;
3386
3387#if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
3388 tBTA_DM_PEER_DEVICE *p_dev;
3389
3390 switch(p_data->acl_change.event)
3391 {
3392 case BTM_BL_UPDATE_EVT: /* busy level update */
3393 if( bta_dm_cb.p_sec_cback )
3394 {
3395 conn.busy_level.level = p_data->acl_change.busy_level;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003396 conn.busy_level.level_flags = p_data->acl_change.busy_level_flags;
The Android Open Source Project5738f832012-12-12 16:00:35 -08003397 bta_dm_cb.p_sec_cback(BTA_DM_BUSY_LEVEL_EVT, &conn);
3398 }
3399 return;
3400
3401 case BTM_BL_ROLE_CHG_EVT: /* role change event */
3402 p_dev = bta_dm_find_peer_device(p_bda);
3403 if(p_dev)
3404 {
3405 APPL_TRACE_DEBUG3("bta_dm_acl_change role chg info:x%x new_role:%d dev count:%d",
3406 p_dev->info, p_data->acl_change.new_role, bta_dm_cb.device_list.count);
3407 if(p_dev->info & BTA_DM_DI_AV_ACTIVE)
3408 {
3409 /* there's AV activity on this link */
3410 if(p_data->acl_change.new_role == HCI_ROLE_SLAVE && bta_dm_cb.device_list.count > 1
3411 && p_data->acl_change.hci_status == HCI_SUCCESS)
3412 {
3413 /* more than one connections and the AV connection is role switched to slave
3414 * switch it back to master and remove the switch policy */
3415 BTM_SwitchRole(p_bda, BTM_ROLE_MASTER, NULL);
3416 need_policy_change = TRUE;
3417 }
3418 else if (bta_dm_cfg.avoid_scatter && (p_data->acl_change.new_role == HCI_ROLE_MASTER))
3419 {
3420 /* if the link updated to be master include AV activities, remove the switch policy */
3421 need_policy_change = TRUE;
3422 }
3423
3424 if(need_policy_change)
3425 {
3426 bta_dm_policy_cback(BTA_SYS_PLCY_CLR, 0, HCI_ENABLE_MASTER_SLAVE_SWITCH, p_dev->peer_bdaddr);
3427 }
3428 }
3429 else
3430 {
3431 /* there's AV no activity on this link and role switch happened
3432 * check if AV is active
3433 * if so, make sure the AV link is master */
3434 bta_dm_check_av(0);
3435 }
3436 bta_sys_notify_role_chg(p_data->acl_change.bd_addr, p_data->acl_change.new_role, p_data->acl_change.hci_status);
3437 bdcpy(conn.role_chg.bd_addr, p_bda);
3438 conn.role_chg.new_role = (UINT8) p_data->acl_change.new_role;
3439 if( bta_dm_cb.p_sec_cback )
3440 bta_dm_cb.p_sec_cback(BTA_DM_ROLE_CHG_EVT, &conn);
3441 }
3442 return;
3443 }
3444#endif
3445
3446 /* Collision report from Stack: Notify profiles */
3447 if (p_data->acl_change.event == BTM_BL_COLLISION_EVT)
3448 {
3449 bta_sys_notify_collision (p_bda);
3450 return;
3451 }
3452
3453 if(is_new)
3454 {
3455 for(i=0; i<bta_dm_cb.device_list.count; i++)
3456 {
3457 if(!bdcmp( bta_dm_cb.device_list.peer_device[i].peer_bdaddr, p_bda))
3458 break;
3459
3460 }
3461
3462 if(i == bta_dm_cb.device_list.count)
3463 {
3464 bdcpy(bta_dm_cb.device_list.peer_device[bta_dm_cb.device_list.count].peer_bdaddr, p_bda);
3465 bta_dm_cb.device_list.peer_device[bta_dm_cb.device_list.count].link_policy = bta_dm_cb.cur_policy;
3466 bta_dm_cb.device_list.count++;
3467 }
3468
3469 bta_dm_cb.device_list.peer_device[i].conn_state = BTA_DM_CONNECTED;
3470 bta_dm_cb.device_list.peer_device[i].pref_role = BTA_ANY_ROLE;
3471 bdcpy(conn.link_up.bd_addr, p_bda);
3472 bta_dm_cb.device_list.peer_device[i].info = BTA_DM_DI_NONE;
3473 if( ((NULL != (p = BTM_ReadLocalFeatures ())) && HCI_SNIFF_SUB_RATE_SUPPORTED(p)) &&
3474 ((NULL != (p = BTM_ReadRemoteFeatures (p_bda))) && HCI_SNIFF_SUB_RATE_SUPPORTED(p)) )
3475 {
3476 /* both local and remote devices support SSR */
3477 bta_dm_cb.device_list.peer_device[i].info = BTA_DM_DI_USE_SSR;
3478 }
3479 APPL_TRACE_WARNING1("info:x%x", bta_dm_cb.device_list.peer_device[i].info);
3480 if( bta_dm_cb.p_sec_cback )
3481 bta_dm_cb.p_sec_cback(BTA_DM_LINK_UP_EVT, &conn);
3482
3483 }
3484 else
3485 {
3486 for(i=0; i<bta_dm_cb.device_list.count; i++)
3487 {
3488 if(bdcmp( bta_dm_cb.device_list.peer_device[i].peer_bdaddr, p_bda))
3489 continue;
3490
3491 if( bta_dm_cb.device_list.peer_device[i].conn_state == BTA_DM_UNPAIRING )
3492 {
3493 BTM_SecDeleteDevice(bta_dm_cb.device_list.peer_device[i].peer_bdaddr);
Zhihai Xubd68d682013-11-15 17:55:46 -08003494#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
3495 /* remove all cached GATT information */
3496 BTA_GATTC_Refresh(p_bda);
3497#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08003498 issue_unpair_cb = TRUE;
3499 }
3500
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003501 conn.link_down.is_removed = bta_dm_cb.device_list.peer_device[i].remove_dev_pending;
3502
The Android Open Source Project5738f832012-12-12 16:00:35 -08003503 for(; i<bta_dm_cb.device_list.count ; i++)
3504 {
3505 memcpy(&bta_dm_cb.device_list.peer_device[i], &bta_dm_cb.device_list.peer_device[i+1], sizeof(bta_dm_cb.device_list.peer_device[i]));
3506 }
3507 break;
3508 }
3509 if(bta_dm_cb.device_list.count)
3510 bta_dm_cb.device_list.count--;
3511
3512 if(bta_dm_search_cb.wait_disc && !bdcmp(bta_dm_search_cb.peer_bdaddr, p_bda))
3513 {
3514 bta_dm_search_cb.wait_disc = FALSE;
3515
3516 if(bta_dm_search_cb.sdp_results)
3517 {
3518 APPL_TRACE_EVENT0(" timer stopped ");
3519 bta_sys_stop_timer(&bta_dm_search_cb.search_timer);
3520 bta_dm_discover_next_device();
3521 }
3522
3523 }
3524
3525 if(bta_dm_cb.disabling)
3526 {
3527 if(!BTM_GetNumAclLinks())
3528 {
3529 bta_sys_stop_timer(&bta_dm_cb.disable_timer);
3530 bta_dm_cb.disable_timer.p_cback = (TIMER_CBACK*)&bta_dm_disable_conn_down_timer_cback;
3531 /* start a timer to make sure that the profiles get the disconnect event */
3532 bta_sys_start_timer(&bta_dm_cb.disable_timer, 0, 1000);
3533 }
3534 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003535 if (conn.link_down.is_removed)
3536 {
3537 BTM_SecDeleteDevice(p_bda);
3538#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
3539 /* need to remove all pending background connection */
3540 BTA_GATTC_CancelOpen(0, p_bda, FALSE);
3541 /* remove all cached GATT information */
3542 BTA_GATTC_Refresh(p_bda);
3543#endif
3544 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08003545
3546 bdcpy(conn.link_down.bd_addr, p_bda);
3547 conn.link_down.status = (UINT8) btm_get_acl_disc_reason_code();
3548 if( bta_dm_cb.p_sec_cback )
3549 {
3550 bta_dm_cb.p_sec_cback(BTA_DM_LINK_DOWN_EVT, &conn);
3551 if( issue_unpair_cb )
3552 bta_dm_cb.p_sec_cback(BTA_DM_DEV_UNPAIRED_EVT, &conn);
3553 }
3554 }
3555
3556 bta_dm_adjust_roles(TRUE);
3557}
3558
3559/*******************************************************************************
3560**
3561** Function bta_dm_disable_conn_down_timer_cback
3562**
3563** Description Sends disable event to application
3564**
3565**
3566** Returns void
3567**
3568*******************************************************************************/
3569static void bta_dm_disable_conn_down_timer_cback (TIMER_LIST_ENT *p_tle)
3570{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08003571 UNUSED(p_tle);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003572 tBTA_SYS_HW_MSG *sys_enable_event;
3573
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003574 /* disable the power managment module */
3575 bta_dm_disable_pm();
3576
The Android Open Source Project5738f832012-12-12 16:00:35 -08003577 /* register our callback to SYS HW manager */
3578 bta_sys_hw_register( BTA_SYS_HW_BLUETOOTH, bta_dm_sys_hw_cback );
3579
3580 /* send a message to BTA SYS */
3581 if ((sys_enable_event = (tBTA_SYS_HW_MSG *) GKI_getbuf(sizeof(tBTA_SYS_HW_MSG))) != NULL)
3582 {
3583 sys_enable_event->hdr.event = BTA_SYS_API_DISABLE_EVT;
3584 sys_enable_event->hw_module = BTA_SYS_HW_BLUETOOTH;
3585 bta_sys_sendmsg(sys_enable_event);
3586 }
3587
3588 bta_dm_cb.disabling = FALSE;
3589
3590}
3591
3592/*******************************************************************************
3593**
3594** Function bta_dm_rssi_cback
3595**
3596** Description Callback from btm with rssi values
3597**
3598**
3599** Returns void
3600**
3601*******************************************************************************/
3602static void bta_dm_rssi_cback (tBTM_RSSI_RESULTS *p_result)
3603{
3604 tBTA_DM_SEC sec_event;
3605
3606 if(p_result->status == BTM_SUCCESS)
3607 {
3608
3609 bdcpy(sec_event.sig_strength.bd_addr, p_result->rem_bda);
3610 sec_event.sig_strength.mask = BTA_SIG_STRENGTH_RSSI_MASK;
3611 sec_event.sig_strength.rssi_value = p_result->rssi;
3612 if( bta_dm_cb.p_sec_cback!= NULL )
3613 bta_dm_cb.p_sec_cback(BTA_DM_SIG_STRENGTH_EVT, &sec_event);
3614
3615 }
3616}
3617
3618/*******************************************************************************
3619**
3620** Function bta_dm_link_quality_cback
3621**
3622** Description Callback from btm with link quality value
3623**
3624**
3625** Returns void
3626**
3627*******************************************************************************/
3628static void bta_dm_link_quality_cback (tBTM_LINK_QUALITY_RESULTS *p_result)
3629{
3630
3631 tBTA_DM_SEC sec_event;
3632
3633 if(p_result->status == BTM_SUCCESS)
3634 {
3635
3636 bdcpy(sec_event.sig_strength.bd_addr, p_result->rem_bda);
3637 sec_event.sig_strength.mask = BTA_SIG_STRENGTH_LINK_QUALITY_MASK;
3638 sec_event.sig_strength.link_quality_value = p_result->link_quality;
3639 if( bta_dm_cb.p_sec_cback!= NULL )
3640 bta_dm_cb.p_sec_cback(BTA_DM_SIG_STRENGTH_EVT, &sec_event);
3641
3642 }
3643}
3644
3645/*******************************************************************************
3646**
3647** Function bta_dm_rm_cback
3648**
3649** Description Role management callback from sys
3650**
3651**
3652** Returns void
3653**
3654*******************************************************************************/
3655static void bta_dm_rm_cback(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
3656{
3657
3658 UINT8 j;
3659 tBTA_PREF_ROLES role;
3660 tBTA_DM_PEER_DEVICE *p_dev;
3661
3662 p_dev = bta_dm_find_peer_device(peer_addr);
3663 if( status == BTA_SYS_CONN_OPEN)
3664 {
3665 if(p_dev)
3666 {
3667 /* Do not set to connected if we are in the middle of unpairing. When AV stream is
3668 * started it fakes out a SYS_CONN_OPEN to potentially trigger a role switch command.
3669 * But this should not be done if we are in the middle of unpairing.
3670 */
3671 if (p_dev->conn_state != BTA_DM_UNPAIRING)
3672 p_dev->conn_state = BTA_DM_CONNECTED;
3673
3674 for(j=1; j<= p_bta_dm_rm_cfg[0].app_id; j++)
3675 {
3676 if(((p_bta_dm_rm_cfg[j].app_id == app_id) || (p_bta_dm_rm_cfg[j].app_id == BTA_ALL_APP_ID))
3677 && (p_bta_dm_rm_cfg[j].id == id))
3678 {
3679 role = p_bta_dm_rm_cfg[j].cfg;
3680
3681 if(role > p_dev->pref_role )
3682 p_dev->pref_role = role;
3683 break;
3684 }
3685 }
3686
3687 }
3688
3689 }
3690
3691 if((BTA_ID_AV == id)||(BTA_ID_AVK ==id))
3692 {
3693 if( status == BTA_SYS_CONN_BUSY)
3694 {
3695 if(p_dev)
3696 p_dev->info |= BTA_DM_DI_AV_ACTIVE;
3697 /* AV calls bta_sys_conn_open with the A2DP stream count as app_id */
3698 if(BTA_ID_AV == id)
3699 bta_dm_cb.cur_av_count = app_id;
3700 }
3701 else if( status == BTA_SYS_CONN_IDLE)
3702 {
3703 if(p_dev)
3704 p_dev->info &= ~BTA_DM_DI_AV_ACTIVE;
3705 /* AV calls bta_sys_conn_open with the A2DP stream count as app_id */
3706 if(BTA_ID_AV == id)
3707 bta_dm_cb.cur_av_count = app_id;
3708 }
3709 APPL_TRACE_WARNING2("bta_dm_rm_cback:%d, status:%d", bta_dm_cb.cur_av_count, status);
3710 }
Ganesh Ganapathi Battaed049d72013-04-12 11:57:50 -07003711 else if ((status == BTA_SYS_CONN_BUSY) || (status == BTA_SYS_CONN_IDLE))
3712 {
3713 /* Do not do role switch management for non-AV profiles when data flow starts/stops */
3714 return;
3715 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08003716
3717 bta_dm_adjust_roles(FALSE);
3718
3719}
3720
3721/*******************************************************************************
3722**
3723** Function bta_dm_dev_blacklisted_for_switch
3724**
3725** Description Checks if the device is blacklisted for immediate role switch after connection.
3726**
3727** Returns TRUE if dev is blacklisted else FALSE
3728**
3729*******************************************************************************/
3730static BOOLEAN bta_dm_dev_blacklisted_for_switch (BD_ADDR remote_bd_addr)
3731{
3732 UINT16 manufacturer = 0;
3733 UINT16 lmp_sub_version = 0;
3734 UINT8 lmp_version = 0;
3735 UINT8 i = 0;
3736
3737 if (BTM_ReadRemoteVersion(remote_bd_addr, &lmp_version,
3738 &manufacturer, &lmp_sub_version) == BTM_SUCCESS)
3739 {
3740 /* Check if this device version info matches with is
3741 blacklisted versions for role switch */
3742 for (i = 0; i < BTA_DM_MAX_ROLE_SWITCH_BLACKLIST_COUNT; i++)
3743 {
3744 if ((bta_role_switch_blacklist[i].lmp_version == lmp_version) &&
3745 (bta_role_switch_blacklist[i].manufacturer == manufacturer)&&
3746 ((bta_role_switch_blacklist[i].lmp_sub_version & lmp_sub_version) ==
3747 bta_role_switch_blacklist[i].lmp_sub_version))
3748 {
3749 APPL_TRACE_EVENT0("Black list F/W version matches.. Delay Role Switch...");
3750 return TRUE;
3751 }
3752
3753 }
3754 }
3755 return FALSE;
3756}
3757
3758/*******************************************************************************
3759**
3760** Function bta_dm_delay_role_switch_cback
3761**
3762** Description Callback from btm to delay a role switch
3763**
3764** Returns void
3765**
3766*******************************************************************************/
3767static void bta_dm_delay_role_switch_cback(TIMER_LIST_ENT *p_tle)
3768{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08003769 UNUSED(p_tle);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003770 APPL_TRACE_EVENT0("bta_dm_delay_role_switch_cback: initiating Delayed RS");
3771 bta_dm_adjust_roles (FALSE);
3772}
3773
3774/*******************************************************************************
3775**
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003776** Function bta_dm_remove_sec_dev_entry
3777**
3778** Description Removes device entry from Security device DB if ACL connection with
3779** remtoe device does not exist, else schedule for dev entry removal upon
3780 ACL close
3781**
3782** Returns void
3783**
3784*******************************************************************************/
3785static void bta_dm_remove_sec_dev_entry(BD_ADDR remote_bd_addr)
3786{
3787 UINT16 index = 0;
3788 if (BTM_IsAclConnectionUp(remote_bd_addr))
3789 {
3790 APPL_TRACE_DEBUG1("%s ACL is not down. Schedule for Dev Removal when ACL closes",
3791 __FUNCTION__);
3792 for (index = 0; index < bta_dm_cb.device_list.count; index ++)
3793 {
3794 if (!bdcmp( bta_dm_cb.device_list.peer_device[index].peer_bdaddr, remote_bd_addr))
3795 break;
3796 }
3797 if (index != bta_dm_cb.device_list.count)
3798 {
3799 bta_dm_cb.device_list.peer_device[index].remove_dev_pending = TRUE;
3800 }
3801 else
3802 {
3803 APPL_TRACE_ERROR1(" %s Device does not exist in DB", __FUNCTION__);
3804 }
3805 }
3806 else
3807 {
3808 BTM_SecDeleteDevice (remote_bd_addr);
Zhihai Xubd68d682013-11-15 17:55:46 -08003809#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE)
3810 /* need to remove all pending background connection */
3811 BTA_GATTC_CancelOpen(0, remote_bd_addr, FALSE);
3812 /* remove all cached GATT information */
3813 BTA_GATTC_Refresh(remote_bd_addr);
3814#endif
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003815 }
3816}
3817
Andre Eisenbach6975b4d2013-08-05 16:55:38 -07003818
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003819/*******************************************************************************
3820**
The Android Open Source Project5738f832012-12-12 16:00:35 -08003821** Function bta_dm_adjust_roles
3822**
3823** Description Adjust roles
3824**
3825**
3826** Returns void
3827**
3828*******************************************************************************/
3829static void bta_dm_adjust_roles(BOOLEAN delay_role_switch)
3830{
3831
3832 UINT8 i;
3833 BOOLEAN set_master_role = FALSE;
3834
3835 if(bta_dm_cb.device_list.count)
3836 {
3837
3838 /* the configuration is no scatternet
3839 * or AV connection exists and there are more than one ACL link */
3840 if( (p_bta_dm_rm_cfg[0].cfg == BTA_DM_NO_SCATTERNET) ||
3841 (bta_dm_cb.cur_av_count && bta_dm_cb.device_list.count > 1) )
3842 {
3843
3844 L2CA_SetDesireRole (HCI_ROLE_MASTER);
3845 set_master_role = TRUE;
3846
3847 }
3848
3849 for(i=0; i<bta_dm_cb.device_list.count; i++)
3850 {
3851 if(bta_dm_cb.device_list.peer_device[i].conn_state == BTA_DM_CONNECTED)
3852 {
3853 if(!set_master_role && (bta_dm_cb.device_list.peer_device[i].pref_role != BTA_ANY_ROLE)
3854 && (p_bta_dm_rm_cfg[0].cfg == BTA_DM_PARTIAL_SCATTERNET))
3855 {
3856 L2CA_SetDesireRole (HCI_ROLE_MASTER);
3857 set_master_role = TRUE;
3858 }
3859
3860 if((bta_dm_cb.device_list.peer_device[i].pref_role == BTA_MASTER_ROLE_ONLY)
3861 || (bta_dm_cb.device_list.count > 1))
3862 {
3863
3864 /* Initiating immediate role switch with certain remote devices
3865 has caused issues due to role switch colliding with link encryption setup and
3866 causing encryption (and in turn the link) to fail . These device . Firmware
3867 versions are stored in a blacklist and role switch with these devices are
3868 delayed to avoid the collision with link encryption setup */
3869
3870 if ((delay_role_switch == FALSE) ||
3871 (bta_dm_dev_blacklisted_for_switch(
3872 bta_dm_cb.device_list.peer_device[i].peer_bdaddr) == FALSE))
3873 {
3874 BTM_SwitchRole (bta_dm_cb.device_list.peer_device[i].peer_bdaddr,
3875 HCI_ROLE_MASTER, NULL);
3876 }
3877 else
3878 {
3879 bta_dm_cb.switch_delay_timer.p_cback =
3880 (TIMER_CBACK*)&bta_dm_delay_role_switch_cback;
3881 bta_sys_start_timer(&bta_dm_cb.switch_delay_timer, 0, 500);
3882 }
3883 }
3884
3885 }
3886 }
3887
3888
3889 if(!set_master_role)
3890 {
3891
3892 L2CA_SetDesireRole (L2CAP_DESIRED_LINK_ROLE);
3893
3894 }
3895
3896 }
3897 else
3898 {
3899 L2CA_SetDesireRole (L2CAP_DESIRED_LINK_ROLE);
3900 }
3901
3902
3903}
3904
3905/*******************************************************************************
3906**
3907** Function bta_dm_get_remname
3908**
3909** Description Returns a pointer to the remote name stored in the DM control
3910** block if it exists, or from the BTM memory.
3911**
3912** Returns char * - Pointer to the remote device name
3913*******************************************************************************/
3914static char *bta_dm_get_remname(void)
3915{
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003916 char *p_name = (char *)bta_dm_search_cb.peer_name;
The Android Open Source Project5738f832012-12-12 16:00:35 -08003917 char *p_temp;
3918
3919 /* If the name isn't already stored, try retrieving from BTM */
3920 if (*p_name == '\0')
3921 if ((p_temp = BTM_SecReadDevName(bta_dm_search_cb.peer_bdaddr)) != NULL)
3922 p_name = p_temp;
3923
3924 return p_name;
3925}
3926
3927/*******************************************************************************
3928**
3929** Function bta_dm_bond_cancel_complete_cback
3930**
3931** Description Authentication complete callback from BTM
3932**
3933** Returns void
3934**
3935*******************************************************************************/
3936static void bta_dm_bond_cancel_complete_cback(tBTM_STATUS result)
3937{
3938
3939 tBTA_DM_SEC sec_event;
3940
3941 if (result == BTM_SUCCESS)
3942 sec_event.bond_cancel_cmpl.result = BTA_SUCCESS;
3943 else
3944 sec_event.bond_cancel_cmpl.result = BTA_FAILURE;
3945
3946 if(bta_dm_cb.p_sec_cback)
3947 {
3948 bta_dm_cb.p_sec_cback(BTA_DM_BOND_CANCEL_CMPL_EVT, &sec_event);
3949 }
3950}
3951
3952#if ( BTM_EIR_SERVER_INCLUDED == TRUE )
3953 #if ( BTA_EIR_CANNED_UUID_LIST != TRUE )&&(BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0)
3954/*******************************************************************************
3955**
3956** Function bta_dm_update_eir_uuid
3957**
3958** Description
3959**
3960**
3961*******************************************************************************/
3962void bta_dm_update_eir_uuid (tBTA_DM_MSG *p_data)
3963{
3964 tBTA_DM_API_UPDATE_EIR_UUID *p_msg = (tBTA_DM_API_UPDATE_EIR_UUID *)p_data;
3965 UINT8 xx;
3966 UINT8 empty_slot = BTA_EIR_SERVER_NUM_CUSTOM_UUID;
3967 UINT8 match_slot = BTA_EIR_SERVER_NUM_CUSTOM_UUID;
3968
3969 for (xx = 0; xx < BTA_EIR_SERVER_NUM_CUSTOM_UUID; xx++)
3970 {
3971 if (bta_dm_cb.custom_uuid[xx].len == 0)
3972 {
3973 if (empty_slot == BTA_EIR_SERVER_NUM_CUSTOM_UUID)
3974 empty_slot = xx;
3975 }
3976 else if (match_slot == BTA_EIR_SERVER_NUM_CUSTOM_UUID)
3977 {
3978 if (!memcmp (bta_dm_cb.custom_uuid[xx].uu.uuid128, p_msg->uuid.uu.uuid128, p_msg->uuid.len))
3979 {
3980 match_slot = xx;;
3981 }
3982 }
3983 }
3984
3985 if (p_msg->is_add)
3986 {
3987 if (match_slot == BTA_EIR_SERVER_NUM_CUSTOM_UUID)
3988 {
3989 if (empty_slot == BTA_EIR_SERVER_NUM_CUSTOM_UUID)
3990 {
3991 APPL_TRACE_ERROR0("No space to add UUID for EIR");
3992 return;
3993 }
3994 else
3995 {
3996 memcpy (&(bta_dm_cb.custom_uuid[empty_slot]), &(p_msg->uuid), sizeof(tBT_UUID));
3997 }
3998 }
3999 else
4000 {
4001 APPL_TRACE_ERROR0("UUID is already added for EIR");
4002 return;
4003 }
4004 }
4005 else
4006 {
4007 if (match_slot == BTA_EIR_SERVER_NUM_CUSTOM_UUID)
4008 {
4009 APPL_TRACE_ERROR0("UUID is not found for EIR");
4010 return;
4011 }
4012 else
4013 {
4014 memset (&(bta_dm_cb.custom_uuid[match_slot]), 0, sizeof(tBT_UUID));
4015 }
4016 }
4017
4018 bta_dm_set_eir (NULL);
4019}
4020 #endif
4021
4022/*******************************************************************************
4023**
4024** Function bta_dm_set_eir_config
4025**
4026** Description
4027**
4028**
4029*******************************************************************************/
4030void bta_dm_set_eir_config (tBTA_DM_MSG *p_data)
4031{
4032 if (p_data->set_eir_cfg.p_eir_cfg)
4033 {
4034 /* User defined config */
4035 p_bta_dm_eir_cfg = p_data->set_eir_cfg.p_eir_cfg;
4036 }
4037 else
4038 {
4039 /* Back to default config */
4040 p_bta_dm_eir_cfg = (tBTA_DM_EIR_CONF*)&bta_dm_eir_cfg;
4041 }
4042
4043 bta_dm_set_eir (NULL);
4044}
4045
4046/*******************************************************************************
4047**
4048** Function bta_dm_set_eir
4049**
4050** Description This function creates EIR tagged data and writes it to controller.
4051**
4052** Returns None
4053**
4054*******************************************************************************/
4055static void bta_dm_set_eir (char *local_name)
4056{
4057 BT_HDR *p_buf;
4058 UINT8 *p;
4059 UINT8 *p_length;
4060#if (BTA_EIR_CANNED_UUID_LIST != TRUE)
4061 UINT8 *p_type;
4062 UINT8 max_num_uuid;
4063#if (BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0)
4064 UINT8 custom_uuid_idx;
4065#endif
4066#endif
4067#if (BTM_EIR_DEFAULT_FEC_REQUIRED == FALSE)
4068 UINT8 free_eir_length = HCI_EXT_INQ_RESPONSE_LEN;
4069#else
4070 UINT8 free_eir_length = HCI_DM5_PACKET_SIZE;
4071#endif
4072 UINT8 num_uuid;
4073 UINT8 data_type;
4074 UINT8 local_name_len;
4075
4076 /* wait until complete to disable */
4077 if (bta_dm_cb.disable_timer.in_use)
4078 return;
4079
4080#if ( BTA_EIR_CANNED_UUID_LIST != TRUE )
4081 /* wait until App is ready */
4082 if (bta_dm_cb.app_ready_timer.in_use)
4083 return;
4084
4085 /* if local name is not provided, get it from controller */
4086 if( local_name == NULL )
4087 {
4088 if( BTM_ReadLocalDeviceName( &local_name ) != BTM_SUCCESS )
4089 {
4090 APPL_TRACE_ERROR0("Fail to read local device name for EIR");
4091 }
4092 }
4093#endif
4094
4095 /* Allocate a buffer to hold HCI command */
4096 if ((p_buf = (BT_HDR *)GKI_getpoolbuf(BTM_CMD_POOL_ID)) == NULL)
4097 {
4098 APPL_TRACE_ERROR0("bta_dm_set_eir couldn't allocate buffer");
4099 return;
4100 }
4101 p = (UINT8 *)p_buf + BTM_HCI_EIR_OFFSET;
4102
4103 memset(p, 0x00, HCI_EXT_INQ_RESPONSE_LEN );
4104
4105 APPL_TRACE_DEBUG0("BTA is generating EIR");
4106
4107 if( local_name )
4108 local_name_len = strlen( local_name );
4109 else
4110 local_name_len = 0;
4111
4112 data_type = BTM_EIR_COMPLETE_LOCAL_NAME_TYPE;
4113 /* if local name is longer than minimum length of shortened name */
4114 /* check whether it needs to be shortened or not */
4115 if( local_name_len > p_bta_dm_eir_cfg->bta_dm_eir_min_name_len )
4116 {
4117 /* get number of UUID 16-bit list */
4118#if (BTA_EIR_CANNED_UUID_LIST == TRUE)
4119 num_uuid = p_bta_dm_eir_cfg->bta_dm_eir_uuid16_len/LEN_UUID_16;
4120#else
4121 max_num_uuid = (free_eir_length - 2)/LEN_UUID_16;
4122 data_type = BTM_GetEirSupportedServices( bta_dm_cb.eir_uuid, &p,
4123 max_num_uuid, &num_uuid );
4124 p = (UINT8 *)p_buf + BTM_HCI_EIR_OFFSET; /* reset p */
4125#endif
4126
4127 /* if UUID doesn't fit remaing space, shorten local name */
4128 if ( local_name_len > (free_eir_length - 4 - num_uuid*LEN_UUID_16))
4129 {
4130 APPL_TRACE_WARNING0("BTA EIR: local name is shortened");
4131 local_name_len = p_bta_dm_eir_cfg->bta_dm_eir_min_name_len;
4132 data_type = BTM_EIR_SHORTENED_LOCAL_NAME_TYPE;
4133 }
4134 else
4135 data_type = BTM_EIR_COMPLETE_LOCAL_NAME_TYPE;
4136 }
4137
4138 UINT8_TO_STREAM(p, local_name_len + 1);
4139 UINT8_TO_STREAM(p, data_type);
Andre Eisenbach3aa60542013-03-22 18:00:51 -07004140
4141 if (local_name != NULL)
4142 {
4143 memcpy(p, local_name, local_name_len);
4144 p += local_name_len;
4145 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08004146 free_eir_length -= local_name_len + 2;
4147
4148#if (BTA_EIR_CANNED_UUID_LIST == TRUE)
4149 /* if UUID list is provided as static data in configuration */
4150 if(( p_bta_dm_eir_cfg->bta_dm_eir_uuid16_len > 0 )
4151 &&(p_bta_dm_eir_cfg->bta_dm_eir_uuid16))
4152 {
4153 if( free_eir_length > LEN_UUID_16 + 2)
4154 {
4155 free_eir_length -= 2;
4156
4157 if( free_eir_length >= p_bta_dm_eir_cfg->bta_dm_eir_uuid16_len)
4158 {
4159 num_uuid = p_bta_dm_eir_cfg->bta_dm_eir_uuid16_len / LEN_UUID_16;
4160 data_type = BTM_EIR_COMPLETE_16BITS_UUID_TYPE;
4161 }
4162 else /* not enough room for all UUIDs */
4163 {
4164 APPL_TRACE_WARNING0("BTA EIR: UUID 16-bit list is truncated");
4165 num_uuid = free_eir_length / LEN_UUID_16;
4166 data_type = BTM_EIR_MORE_16BITS_UUID_TYPE;
4167 }
4168 UINT8_TO_STREAM(p, num_uuid * LEN_UUID_16 + 1);
4169 UINT8_TO_STREAM(p, data_type);
4170 memcpy(p, p_bta_dm_eir_cfg->bta_dm_eir_uuid16, num_uuid * LEN_UUID_16 );
4171 p += num_uuid * LEN_UUID_16;
4172 free_eir_length -= num_uuid * LEN_UUID_16;
4173 }
4174 }
4175#else /* (BTA_EIR_CANNED_UUID_LIST == TRUE) */
4176 /* if UUID list is dynamic */
4177 if ( free_eir_length >= 2)
4178 {
4179 p_length = p++;
4180 p_type = p++;
4181 num_uuid = 0;
4182
4183 max_num_uuid = (free_eir_length - 2)/LEN_UUID_16;
4184 data_type = BTM_GetEirSupportedServices( bta_dm_cb.eir_uuid, &p, max_num_uuid, &num_uuid );
4185
4186 if( data_type == BTM_EIR_MORE_16BITS_UUID_TYPE )
4187 {
4188 APPL_TRACE_WARNING0("BTA EIR: UUID 16-bit list is truncated");
4189 }
4190#if (BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0)
4191 else
4192 {
4193 for (custom_uuid_idx = 0; custom_uuid_idx < BTA_EIR_SERVER_NUM_CUSTOM_UUID; custom_uuid_idx++)
4194 {
4195 if (bta_dm_cb.custom_uuid[custom_uuid_idx].len == LEN_UUID_16)
4196 {
4197 if ( num_uuid < max_num_uuid )
4198 {
4199 UINT16_TO_STREAM(p, bta_dm_cb.custom_uuid[custom_uuid_idx].uu.uuid16);
4200 num_uuid++;
4201 }
4202 else
4203 {
4204 data_type = BTM_EIR_MORE_16BITS_UUID_TYPE;
4205 APPL_TRACE_WARNING0("BTA EIR: UUID 16-bit list is truncated");
4206 break;
4207 }
4208 }
4209 }
4210 }
4211#endif /* (BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0) */
4212
4213 UINT8_TO_STREAM(p_length, num_uuid * LEN_UUID_16 + 1);
4214 UINT8_TO_STREAM(p_type, data_type);
4215 free_eir_length -= num_uuid * LEN_UUID_16 + 2;
4216 }
4217#endif /* (BTA_EIR_CANNED_UUID_LIST == TRUE) */
4218
4219#if ( BTA_EIR_CANNED_UUID_LIST != TRUE )&&(BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0)
4220 /* Adding 32-bit UUID list */
4221 if ( free_eir_length >= 2)
4222 {
4223 p_length = p++;
4224 p_type = p++;
4225 num_uuid = 0;
4226 data_type = BTM_EIR_COMPLETE_32BITS_UUID_TYPE;
4227
4228 max_num_uuid = (free_eir_length - 2)/LEN_UUID_32;
4229
4230 for (custom_uuid_idx = 0; custom_uuid_idx < BTA_EIR_SERVER_NUM_CUSTOM_UUID; custom_uuid_idx++)
4231 {
4232 if (bta_dm_cb.custom_uuid[custom_uuid_idx].len == LEN_UUID_32)
4233 {
4234 if ( num_uuid < max_num_uuid )
4235 {
4236 UINT32_TO_STREAM(p, bta_dm_cb.custom_uuid[custom_uuid_idx].uu.uuid32);
4237 num_uuid++;
4238 }
4239 else
4240 {
4241 data_type = BTM_EIR_MORE_32BITS_UUID_TYPE;
4242 APPL_TRACE_WARNING0("BTA EIR: UUID 32-bit list is truncated");
4243 break;
4244 }
4245 }
4246 }
4247
4248 UINT8_TO_STREAM(p_length, num_uuid * LEN_UUID_32 + 1);
4249 UINT8_TO_STREAM(p_type, data_type);
4250 free_eir_length -= num_uuid * LEN_UUID_32 + 2;
4251 }
4252
4253 /* Adding 128-bit UUID list */
4254 if ( free_eir_length >= 2)
4255 {
4256 p_length = p++;
4257 p_type = p++;
4258 num_uuid = 0;
4259 data_type = BTM_EIR_COMPLETE_128BITS_UUID_TYPE;
4260
4261 max_num_uuid = (free_eir_length - 2)/LEN_UUID_128;
4262
4263 for (custom_uuid_idx = 0; custom_uuid_idx < BTA_EIR_SERVER_NUM_CUSTOM_UUID; custom_uuid_idx++)
4264 {
4265 if (bta_dm_cb.custom_uuid[custom_uuid_idx].len == LEN_UUID_128)
4266 {
4267 if ( num_uuid < max_num_uuid )
4268 {
4269 ARRAY16_TO_STREAM(p, bta_dm_cb.custom_uuid[custom_uuid_idx].uu.uuid128);
4270 num_uuid++;
4271 }
4272 else
4273 {
4274 data_type = BTM_EIR_MORE_128BITS_UUID_TYPE;
4275 APPL_TRACE_WARNING0("BTA EIR: UUID 128-bit list is truncated");
4276 break;
4277 }
4278 }
4279 }
4280
4281 UINT8_TO_STREAM(p_length, num_uuid * LEN_UUID_128 + 1);
4282 UINT8_TO_STREAM(p_type, data_type);
4283 free_eir_length -= num_uuid * LEN_UUID_128 + 2;
4284 }
4285#endif /* ( BTA_EIR_CANNED_UUID_LIST != TRUE )&&(BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0) */
4286
4287 /* if Flags are provided in configuration */
4288 if(( p_bta_dm_eir_cfg->bta_dm_eir_flag_len > 0 )
4289 &&( p_bta_dm_eir_cfg->bta_dm_eir_flags )
4290 &&( free_eir_length >= p_bta_dm_eir_cfg->bta_dm_eir_flag_len + 2 ))
4291 {
4292 UINT8_TO_STREAM(p, p_bta_dm_eir_cfg->bta_dm_eir_flag_len + 1);
4293 UINT8_TO_STREAM(p, BTM_EIR_FLAGS_TYPE);
4294 memcpy(p, p_bta_dm_eir_cfg->bta_dm_eir_flags,
4295 p_bta_dm_eir_cfg->bta_dm_eir_flag_len);
4296 p += p_bta_dm_eir_cfg->bta_dm_eir_flag_len;
4297 free_eir_length -= p_bta_dm_eir_cfg->bta_dm_eir_flag_len + 2;
4298 }
4299
The Android Open Source Project5738f832012-12-12 16:00:35 -08004300 /* if Manufacturer Specific are provided in configuration */
4301 if(( p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec_len > 0 )
4302 &&( p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec )
4303 &&( free_eir_length >= p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec_len + 2 ))
4304 {
4305 p_length = p;
4306
4307 UINT8_TO_STREAM(p, p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec_len + 1);
4308 UINT8_TO_STREAM(p, BTM_EIR_MANUFACTURER_SPECIFIC_TYPE);
4309 memcpy(p, p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec,
4310 p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec_len);
4311 p += p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec_len;
4312 free_eir_length -= p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec_len + 2;
4313
4314 }
4315 else
4316 {
4317 p_length = NULL;
4318 }
4319
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08004320 /* if Inquiry Tx Resp Power compiled */
4321 if ((p_bta_dm_eir_cfg->bta_dm_eir_inq_tx_power) &&
4322 (free_eir_length >= 3))
4323 {
4324 UINT8_TO_STREAM(p, 2); /* Length field */
4325 UINT8_TO_STREAM(p, BTM_EIR_TX_POWER_LEVEL_TYPE);
4326 UINT8_TO_STREAM(p, *(p_bta_dm_eir_cfg->bta_dm_eir_inq_tx_power));
4327 free_eir_length -= 3;
4328 }
4329
The Android Open Source Project5738f832012-12-12 16:00:35 -08004330 if( free_eir_length )
4331 UINT8_TO_STREAM(p, 0); /* terminator of significant part */
4332
4333 BTM_WriteEIR( p_buf );
4334
4335}
4336#endif
4337
4338#if ( BTM_EIR_CLIENT_INCLUDED == TRUE )
4339/*******************************************************************************
4340**
4341** Function bta_dm_eir_search_services
4342**
4343** Description This function searches services in received EIR
4344**
4345** Returns None
4346**
4347*******************************************************************************/
4348static void bta_dm_eir_search_services( tBTM_INQ_RESULTS *p_result,
4349 tBTA_SERVICE_MASK *p_services_to_search,
4350 tBTA_SERVICE_MASK *p_services_found)
4351{
4352 tBTA_SERVICE_MASK service_index = 0;
4353 tBTM_EIR_SEARCH_RESULT result;
4354
4355 APPL_TRACE_DEBUG6("BTA searching services in EIR of BDA:0x%02X%02X%02X%02X%02X%02X",
4356 p_result->remote_bd_addr[0],p_result->remote_bd_addr[1],
4357 p_result->remote_bd_addr[2],p_result->remote_bd_addr[3],
4358 p_result->remote_bd_addr[4],p_result->remote_bd_addr[5]);
4359
4360 APPL_TRACE_DEBUG1(" with services_to_search=0x%08X", *p_services_to_search);
4361
4362#if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
4363 /* always do GATT based service discovery by SDP instead of from EIR */
4364 /* if GATT based service is also to be put in EIR, need to modify this */
4365 while (service_index < (BTA_MAX_SERVICE_ID - 1))
4366#else
4367 while(service_index < BTA_MAX_SERVICE_ID)
4368#endif
4369 {
4370 if( *p_services_to_search
4371 & (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(service_index)))
4372 {
4373 result = BTM_HasInquiryEirService( p_result,
4374 bta_service_id_to_uuid_lkup_tbl[service_index] );
4375
4376 /* Searching for HSP v1.2 only device */
4377 if ((result != BTM_EIR_FOUND) &&
4378 (bta_service_id_to_uuid_lkup_tbl[service_index] == UUID_SERVCLASS_HEADSET))
4379 {
4380 result = BTM_HasInquiryEirService (p_result, UUID_SERVCLASS_HEADSET_HS);
4381 }
4382
4383 if( result == BTM_EIR_FOUND )
4384 {
4385 /* If Plug and Play service record, need to check to see if Broadcom stack */
4386 /* However, EIR data doesn't have EXT_BRCM_VERSION so just skip it */
4387 if( bta_service_id_to_uuid_lkup_tbl[service_index]
4388 != UUID_SERVCLASS_PNP_INFORMATION )
4389 {
4390
4391 *p_services_found |=
4392 (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(service_index));
4393 /* remove the service from services to be searched */
4394 *p_services_to_search &=
4395 (tBTA_SERVICE_MASK)(~(BTA_SERVICE_ID_TO_SERVICE_MASK(service_index)));
4396 }
4397 }
4398 else if( result == BTM_EIR_NOT_FOUND )
4399 {
4400 /* remove the service from services to be searched */
4401 *p_services_to_search &=
4402 (tBTA_SERVICE_MASK)(~(BTA_SERVICE_ID_TO_SERVICE_MASK(service_index)));
4403 }
4404 }
4405
4406 service_index++;
4407 }
4408
4409 APPL_TRACE_ERROR2("BTA EIR search result, services_to_search=0x%08X, services_found=0x%08X",
4410 *p_services_to_search, *p_services_found);
4411}
4412#endif
4413
4414#if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&(BTA_EIR_CANNED_UUID_LIST != TRUE)
4415/*******************************************************************************
4416**
4417** Function bta_dm_eir_update_uuid
4418**
4419** Description This function adds or removes service UUID in EIR database.
4420**
4421** Returns None
4422**
4423*******************************************************************************/
4424void bta_dm_eir_update_uuid(UINT16 uuid16, BOOLEAN adding)
4425{
4426 /* if this UUID is not advertised in EIR */
4427 if( !BTM_HasEirService( p_bta_dm_eir_cfg->uuid_mask, uuid16 ))
4428 return;
4429
4430 if( adding )
4431 {
4432 APPL_TRACE_EVENT1("Adding UUID=0x%04X into EIR", uuid16);
4433
4434 BTM_AddEirService( bta_dm_cb.eir_uuid, uuid16 );
4435 }
4436 else
4437 {
4438 APPL_TRACE_EVENT1("Removing UUID=0x%04X from EIR", uuid16);
4439
4440 BTM_RemoveEirService( bta_dm_cb.eir_uuid, uuid16 );
4441 }
4442
4443 bta_dm_set_eir (NULL);
4444
4445 APPL_TRACE_EVENT2("bta_dm_eir_update_uuid UUID bit mask=0x%08X %08X",
4446 bta_dm_cb.eir_uuid[1], bta_dm_cb.eir_uuid[0] );
4447}
4448#endif
4449
4450/*******************************************************************************
4451**
4452** Function bta_dm_enable_test_mode
4453**
4454** Description enable test mode
4455**
4456**
4457** Returns void
4458**
4459*******************************************************************************/
4460void bta_dm_enable_test_mode(tBTA_DM_MSG *p_data)
4461{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08004462 UNUSED(p_data);
The Android Open Source Project5738f832012-12-12 16:00:35 -08004463 BTM_EnableTestMode();
4464}
4465
4466/*******************************************************************************
4467**
4468** Function bta_dm_disable_test_mode
4469**
4470** Description disable test mode
4471**
4472**
4473** Returns void
4474**
4475*******************************************************************************/
4476void bta_dm_disable_test_mode(tBTA_DM_MSG *p_data)
4477{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08004478 UNUSED(p_data);
The Android Open Source Project5738f832012-12-12 16:00:35 -08004479 BTM_DeviceReset(NULL);
4480}
4481
4482/*******************************************************************************
4483**
4484** Function bta_dm_execute_callback
4485**
4486** Description Just execute a generic call back in the context of the BTU/BTA tack
4487**
4488**
4489** Returns void
4490**
4491*******************************************************************************/
4492void bta_dm_execute_callback(tBTA_DM_MSG *p_data)
4493{
4494 /* sanity check */
4495 if(p_data->exec_cback.p_exec_cback == NULL)
4496 {
4497 return;
4498 }
4499
4500 p_data->exec_cback.p_exec_cback(p_data->exec_cback.p_param);
4501}
4502/*******************************************************************************
4503**
4504** Function bta_dm_encrypt_cback
4505**
4506** Description link encryption complete callback.
4507**
4508** Returns None
4509**
4510*******************************************************************************/
4511void bta_dm_encrypt_cback(BD_ADDR bd_addr, void *p_ref_data, tBTM_STATUS result)
4512{
4513 tBTA_STATUS bta_status = BTA_SUCCESS;
4514 tBTA_DM_ENCRYPT_CBACK *p_callback = bta_dm_cb.p_encrypt_cback;
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08004515 UNUSED(p_ref_data);
The Android Open Source Project5738f832012-12-12 16:00:35 -08004516
4517 bta_dm_cb.p_encrypt_cback = NULL;
4518 switch (result)
4519 {
4520 case BTM_SUCCESS:
4521 break;
4522 case BTM_WRONG_MODE:
4523 bta_status = BTA_WRONG_MODE;
4524 break;
4525 case BTM_NO_RESOURCES:
4526 bta_status = BTA_NO_RESOURCES;
4527 break;
4528 case BTM_BUSY:
4529 bta_status = BTA_BUSY;
4530 break;
4531 default:
4532 bta_status = BTA_FAILURE;
4533 break;
4534 }
4535
4536 APPL_TRACE_DEBUG2("bta_dm_encrypt_cback status =%d p_callback=0x%x", bta_status, p_callback);
4537
4538 if (p_callback)
4539 {
4540 (*p_callback)(bd_addr, bta_status);
4541 }
4542}
4543/*******************************************************************************
4544**
4545** Function bta_dm_set_encryption
4546**
4547** Description This function to encrypt the link
4548**
4549** Returns None
4550**
4551*******************************************************************************/
4552void bta_dm_set_encryption (tBTA_DM_MSG *p_data)
4553{
4554
4555 APPL_TRACE_DEBUG0("bta_dm_set_encryption"); //todo
4556 if (!p_data->set_encryption.p_callback)
4557 {
4558 APPL_TRACE_ERROR0("bta_dm_set_encryption callback is not provided");
4559 return;
4560 }
4561
4562 if (bta_dm_cb.p_encrypt_cback)
4563 {
4564 (*p_data->set_encryption.p_callback)(p_data->set_encryption.bd_addr, BTA_BUSY);
4565 return;
4566 }
4567
4568
4569 bta_dm_cb.p_encrypt_cback = p_data->set_encryption.p_callback;
4570 bta_dm_cb.sec_act = p_data->set_encryption.sec_act;
4571 BTM_SetEncryption(p_data->set_encryption.bd_addr, bta_dm_encrypt_cback, &bta_dm_cb.sec_act);
4572}
4573
4574/*******************************************************************************
4575**
4576** Function bta_dm_set_afh_channels
4577**
4578** Description set afh channels
4579**
4580**
4581** Returns void
4582**
4583*******************************************************************************/
4584void bta_dm_set_afh_channels(tBTA_DM_MSG * p_data)
4585{
4586
4587 BTM_SetAfhChannels(p_data->set_afhchannels.first,p_data->set_afhchannels.last);
4588}
4589
4590/*******************************************************************************
4591**
4592** Function bta_dm_set_afh_channel_assesment
4593**
4594** Description set afh channel assesment
4595**
4596**
4597** Returns void
4598**
4599*******************************************************************************/
4600
4601void bta_dm_set_afh_channel_assesment (tBTA_DM_MSG * p_data)
4602{
4603 BTM_SetAfhChannelAssessment(p_data->set_afh_channel_assessment.enable_or_disable);
4604}
4605
4606#if (BLE_INCLUDED == TRUE)
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08004607/*******************************************************************************
4608**
4609** Function bta_dm_observe_results_cb
4610**
4611** Description Callback for BLE Observe result
4612**
4613**
4614** Returns void
4615**
4616*******************************************************************************/
4617static void bta_dm_observe_results_cb (tBTM_INQ_RESULTS *p_inq, UINT8 *p_eir)
4618{
4619;
4620 tBTA_DM_SEARCH result;
4621 tBTM_INQ_INFO *p_inq_info;
4622 UINT16 service_class;
4623 APPL_TRACE_DEBUG0("bta_dm_observe_results_cb")
4624
4625 bdcpy(result.inq_res.bd_addr, p_inq->remote_bd_addr);
4626 result.inq_res.rssi = p_inq->rssi;
4627 result.inq_res.ble_addr_type = p_inq->ble_addr_type;
4628 result.inq_res.inq_result_type = p_inq->inq_result_type;
4629 result.inq_res.device_type = p_inq->device_type;
4630
4631 /* application will parse EIR to find out remote device name */
4632 result.inq_res.p_eir = p_eir;
4633
4634 if((p_inq_info = BTM_InqDbRead(p_inq->remote_bd_addr)) != NULL)
4635 {
4636 /* initialize remt_name_not_required to FALSE so that we get the name by default */
4637 result.inq_res.remt_name_not_required = FALSE;
4638 }
4639
4640 if(bta_dm_search_cb.p_scan_cback)
4641 bta_dm_search_cb.p_scan_cback(BTA_DM_INQ_RES_EVT, &result);
4642
4643 if(p_inq_info)
4644 {
4645 /* application indicates if it knows the remote name, inside the callback
4646 copy that to the inquiry data base*/
4647 if(result.inq_res.remt_name_not_required)
4648 p_inq_info->appl_knows_rem_name = TRUE;
4649 }
4650}
4651
4652/*******************************************************************************
4653**
4654** Function bta_dm_observe_cmpl_cb
4655**
4656** Description Callback for BLE Observe complete
4657**
4658**
4659** Returns void
4660**
4661*******************************************************************************/
4662static void bta_dm_observe_cmpl_cb (void * p_result)
4663{
4664 tBTA_DM_SEARCH data;
4665
4666 APPL_TRACE_DEBUG0("bta_dm_observe_cmpl_cb");
4667
4668 data.inq_cmpl.num_resps = ((tBTM_INQUIRY_CMPL *)p_result)->num_resp;
4669 if (bta_dm_search_cb.p_scan_cback)
4670 {
4671 bta_dm_search_cb.p_scan_cback(BTA_DM_INQ_CMPL_EVT, &data);
4672 }
4673}
4674
The Android Open Source Project5738f832012-12-12 16:00:35 -08004675#if (SMP_INCLUDED == TRUE)
4676/*******************************************************************************
4677**
4678** Function bta_dm_ble_smp_cback
4679**
4680** Description Callback for BLE SMP
4681**
4682**
4683** Returns void
4684**
4685*******************************************************************************/
4686static UINT8 bta_dm_ble_smp_cback (tBTM_LE_EVT event, BD_ADDR bda, tBTM_LE_EVT_DATA *p_data)
4687{
4688 tBTM_STATUS status = BTM_SUCCESS;
4689 tBTA_DM_SEC sec_event;
Andre Eisenbach181d0752013-06-11 14:18:21 -07004690 char* p_name = NULL;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08004691 UINT8 i;
4692
4693 APPL_TRACE_DEBUG0("bta_dm_ble_smp_cback");
The Android Open Source Project5738f832012-12-12 16:00:35 -08004694
4695 if (!bta_dm_cb.p_sec_cback)
4696 return BTM_NOT_AUTHORIZED;
4697
4698 memset(&sec_event, 0, sizeof(tBTA_DM_SEC));
4699 switch (event)
4700 {
4701 case BTM_LE_IO_REQ_EVT:
4702#if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE)
4703
4704 bta_dm_co_ble_io_req(bda,
4705 &p_data->io_req.io_cap,
4706 &p_data->io_req.oob_data,
4707 &p_data->io_req.auth_req,
4708 &p_data->io_req.max_key_size,
4709 &p_data->io_req.init_keys,
4710 &p_data->io_req.resp_keys);
4711#endif
4712#if BTM_OOB_INCLUDED == FALSE
4713 status = BTM_SUCCESS;
4714#endif
4715 APPL_TRACE_EVENT2("io mitm: %d oob_data:%d", p_data->io_req.auth_req, p_data->io_req.oob_data);
4716
4717 break;
4718
4719 case BTM_LE_SEC_REQUEST_EVT:
4720 bdcpy(sec_event.ble_req.bd_addr, bda);
Andre Eisenbach181d0752013-06-11 14:18:21 -07004721 p_name = BTM_SecReadDevName(bda);
4722 if (p_name != NULL)
4723 {
4724 BCM_STRNCPY_S((char*)sec_event.ble_req.bd_name,
4725 sizeof(BD_NAME), p_name, (BD_NAME_LEN));
4726 }
4727 else
4728 {
4729 sec_event.ble_req.bd_name[0] = 0;
4730 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08004731 bta_dm_cb.p_sec_cback(BTA_DM_BLE_SEC_REQ_EVT, &sec_event);
4732 break;
4733
4734 case BTM_LE_KEY_NOTIF_EVT:
4735 bdcpy(sec_event.key_notif.bd_addr, bda);
Andre Eisenbach181d0752013-06-11 14:18:21 -07004736 p_name = BTM_SecReadDevName(bda);
4737 if (p_name != NULL)
4738 {
4739 BCM_STRNCPY_S((char*)sec_event.key_notif.bd_name,
4740 sizeof(BD_NAME), p_name, (BD_NAME_LEN));
4741 }
4742 else
4743 {
4744 sec_event.key_notif.bd_name[0] = 0;
4745 }
4746 sec_event.key_notif.passkey = p_data->key_notif;
4747 bta_dm_cb.p_sec_cback(BTA_DM_BLE_PASSKEY_NOTIF_EVT, &sec_event);
4748 break;
The Android Open Source Project5738f832012-12-12 16:00:35 -08004749
4750 case BTM_LE_KEY_REQ_EVT:
4751 bdcpy(sec_event.ble_req.bd_addr, bda);
4752 bta_dm_cb.p_sec_cback(BTA_DM_BLE_PASSKEY_REQ_EVT, &sec_event);
4753 break;
4754
4755 case BTM_LE_OOB_REQ_EVT:
4756 bdcpy(sec_event.ble_req.bd_addr, bda);
4757 bta_dm_cb.p_sec_cback(BTA_DM_BLE_OOB_REQ_EVT, &sec_event);
4758 break;
4759
4760 case BTM_LE_KEY_EVT:
4761 bdcpy(sec_event.ble_key.bd_addr, bda);
4762 sec_event.ble_key.key_type = p_data->key.key_type;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08004763
4764 if (p_data->key.key_type == BTM_LE_KEY_PID)
4765 {
4766 for (i=0; i<BT_OCTET16_LEN; i++ )
4767 {
4768 sec_event.ble_key.key_value.pid_key.irk[i] = p_data->key.p_key_value->pid_key.irk[i];
4769 }
4770 sec_event.ble_key.key_value.pid_key.addr_type = p_data->key.p_key_value->pid_key.addr_type;
4771 memcpy( &(sec_event.ble_key.key_value.pid_key.static_addr),
4772 &(p_data->key.p_key_value->pid_key.static_addr),
4773 sizeof (BD_ADDR));
4774 }
4775 else
4776 {
4777 memcpy(&sec_event.ble_key.key_value, p_data->key.p_key_value, sizeof(tBTM_LE_KEY_VALUE));
4778 }
4779 // memcpy(&sec_event.ble_key.key_value, p_data->key.p_key_value, sizeof(tBTM_LE_KEY_VALUE)); todo will crash
The Android Open Source Project5738f832012-12-12 16:00:35 -08004780 bta_dm_cb.p_sec_cback(BTA_DM_BLE_KEY_EVT, &sec_event);
4781 break;
4782
4783 case BTM_LE_COMPLT_EVT:
4784 bdcpy(sec_event.auth_cmpl.bd_addr, bda);
Andre Eisenbach181d0752013-06-11 14:18:21 -07004785 p_name = BTM_SecReadDevName(bda);
4786 if (p_name != NULL)
4787 {
4788 BCM_STRNCPY_S((char*)sec_event.auth_cmpl.bd_name,
4789 sizeof(BD_NAME), p_name, (BD_NAME_LEN));
4790 }
4791 else
4792 {
4793 sec_event.auth_cmpl.bd_name[0] = 0;
4794 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08004795 if (p_data->complt.reason != 0)
4796 {
4797 sec_event.auth_cmpl.fail_reason = BTA_DM_AUTH_CONVERT_SMP_CODE(((UINT8)p_data->complt.reason));
4798 /* delete this device entry from Sec Dev DB */
4799 bta_dm_remove_sec_dev_entry (bda);
4800 }
4801 else
4802 {
4803 sec_event.auth_cmpl.success = TRUE;
4804 }
4805 sec_event.auth_cmpl.privacy_enabled = p_data->complt.privacy_supported;
The Android Open Source Project5738f832012-12-12 16:00:35 -08004806 if (bta_dm_cb.p_sec_cback)
4807 {
4808 //bta_dm_cb.p_sec_cback(BTA_DM_AUTH_CMPL_EVT, &sec_event);
4809 bta_dm_cb.p_sec_cback(BTA_DM_BLE_AUTH_CMPL_EVT, &sec_event);
4810 }
4811
4812 break;
4813
4814 default:
4815 status = BTM_NOT_AUTHORIZED;
4816 break;
4817 }
4818 return status;
4819}
4820#endif /* SMP_INCLUDED == TRUE */
4821
4822/*******************************************************************************
4823**
4824** Function bta_dm_ble_id_key_cback
4825**
4826** Description Callback for BLE local ID keys
4827**
4828**
4829** Returns void
4830**
4831*******************************************************************************/
4832static void bta_dm_ble_id_key_cback (UINT8 key_type, tBTM_BLE_LOCAL_KEYS *p_key)
4833{
4834 UINT8 evt;
4835 tBTA_DM_SEC dm_key;
4836
4837 switch (key_type)
4838 {
4839 case BTM_BLE_KEY_TYPE_ID:
4840 case BTM_BLE_KEY_TYPE_ER:
4841 if (bta_dm_cb.p_sec_cback)
4842 {
4843 memcpy(&dm_key.ble_id_keys, p_key, sizeof(tBTM_BLE_LOCAL_KEYS));
4844
4845 evt = (key_type == BTM_BLE_KEY_TYPE_ID) ? BTA_DM_BLE_LOCAL_IR_EVT :\
4846 BTA_DM_BLE_LOCAL_ER_EVT;
4847 bta_dm_cb.p_sec_cback(evt, &dm_key);
4848 }
4849 break;
4850
4851 default:
4852 APPL_TRACE_DEBUG1("Unknown key type %d", key_type);
4853 break;
4854 }
4855 return;
4856
4857}
4858
4859/*******************************************************************************
4860**
4861** Function bta_dm_add_blekey
4862**
4863** Description This function adds an BLE Key to an security database entry.
4864** This function shall only be called AFTER BTA_DmAddBleDevice has been called.
4865** It is normally called during host startup to restore all required information
4866** stored in the NVRAM.
4867**
4868** Parameters:
4869**
4870*******************************************************************************/
4871void bta_dm_add_blekey (tBTA_DM_MSG *p_data)
4872{
4873 if (!BTM_SecAddBleKey (p_data->add_ble_key.bd_addr,
4874 (tBTM_LE_KEY_VALUE *)&p_data->add_ble_key.blekey,
4875 p_data->add_ble_key.key_type))
4876 {
4877 APPL_TRACE_ERROR2 ("BTA_DM: Error adding BLE Key for device %08x%04x",
4878 (p_data->add_ble_key.bd_addr[0]<<24)+(p_data->add_ble_key.bd_addr[1]<<16)+\
4879 (p_data->add_ble_key.bd_addr[2]<<8)+p_data->add_ble_key.bd_addr[3],
4880 (p_data->add_ble_key.bd_addr[4]<<8)+p_data->add_ble_key.bd_addr[5]);
4881 }
4882}
4883
4884/*******************************************************************************
4885**
4886** Function bta_dm_add_ble_device
4887**
4888** Description This function adds an BLE device to an security database entry.
4889** It is normally called during host startup to restore all required information
4890** stored in the NVRAM.
4891**
4892** Parameters:
4893**
4894*******************************************************************************/
4895void bta_dm_add_ble_device (tBTA_DM_MSG *p_data)
4896{
4897 if (!BTM_SecAddBleDevice (p_data->add_ble_device.bd_addr, NULL,
4898 p_data->add_ble_device.dev_type ,
4899 p_data->add_ble_device.addr_type))
4900 {
4901 APPL_TRACE_ERROR2 ("BTA_DM: Error adding BLE Device for device %08x%04x",
4902 (p_data->add_ble_device.bd_addr[0]<<24)+(p_data->add_ble_device.bd_addr[1]<<16)+ \
4903 (p_data->add_ble_device.bd_addr[2]<<8)+p_data->add_ble_device.bd_addr[3],
4904 (p_data->add_ble_device.bd_addr[4]<<8)+p_data->add_ble_device.bd_addr[5]);
4905 }
4906}
4907
4908/*******************************************************************************
4909**
4910** Function bta_dm_add_ble_device
4911**
4912** Description This function adds an BLE device to an security database entry.
4913** It is normally called during host startup to restore all required information
4914** stored in the NVRAM.
4915**
4916** Parameters:
4917**
4918*******************************************************************************/
4919void bta_dm_ble_passkey_reply (tBTA_DM_MSG *p_data)
4920{
4921 if (p_data->pin_reply.accept)
4922 {
4923
4924 BTM_BlePasskeyReply(p_data->ble_passkey_reply.bd_addr, BTM_SUCCESS, p_data->ble_passkey_reply.passkey);
4925 }
4926 else
4927 {
4928 BTM_BlePasskeyReply(p_data->ble_passkey_reply.bd_addr, BTM_NOT_AUTHORIZED, p_data->ble_passkey_reply.passkey);
4929 }
4930
4931}
4932
4933/*******************************************************************************
4934**
4935** Function bta_dm_security_grant
4936**
4937** Description This function grant SMP security request access.
4938**
4939** Parameters:
4940**
4941*******************************************************************************/
4942void bta_dm_security_grant (tBTA_DM_MSG *p_data)
4943{
4944 BTM_SecurityGrant(p_data->ble_sec_grant.bd_addr, p_data->ble_sec_grant.res);
4945}
4946
4947/*******************************************************************************
4948**
4949** Function bta_dm_ble_set_bg_conn_type
4950**
4951** Description This function set the BLE background connection type
4952**
4953** Parameters:
4954**
4955*******************************************************************************/
4956void bta_dm_ble_set_bg_conn_type (tBTA_DM_MSG *p_data)
4957{
4958 BTM_BleSetBgConnType(p_data->ble_set_bd_conn_type.bg_conn_type,
4959 p_data->ble_set_bd_conn_type.p_select_cback);
4960}
4961
4962/*******************************************************************************
4963**
4964** Function bta_dm_ble_set_conn_params
4965**
4966** Description This function set the preferred connection parameters.
4967**
4968** Parameters:
4969**
4970*******************************************************************************/
4971void bta_dm_ble_set_conn_params (tBTA_DM_MSG *p_data)
4972{
4973 BTM_BleSetPrefConnParams(p_data->ble_set_conn_params.peer_bda,
4974 p_data->ble_set_conn_params.conn_int_min,
4975 p_data->ble_set_conn_params.conn_int_max,
4976 p_data->ble_set_conn_params.slave_latency,
4977 p_data->ble_set_conn_params.supervision_tout);
4978}
4979
4980/*******************************************************************************
4981**
4982** Function bta_dm_ble_set_scan_params
4983**
4984** Description This function set the preferred connection scan parameters.
4985**
4986** Parameters:
4987**
4988*******************************************************************************/
4989void bta_dm_ble_set_scan_params (tBTA_DM_MSG *p_data)
4990{
4991 BTM_BleSetConnScanParams(p_data->ble_set_scan_params.scan_int,
4992 p_data->ble_set_scan_params.scan_window);
4993}
4994
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08004995
4996/*******************************************************************************
4997**
4998** Function bta_dm_ble_observe
4999**
5000** Description This function set the preferred connection scan parameters.
5001**
5002** Parameters:
5003**
5004*******************************************************************************/
5005void bta_dm_ble_observe (tBTA_DM_MSG *p_data)
5006{
5007
5008 tBTM_STATUS status;
5009 if (p_data->ble_observe.start)
5010 {
5011 /*Save the callback to be called when a scan results are available */
5012 bta_dm_search_cb.p_scan_cback = p_data->ble_observe.p_cback;
5013 if ((status = BTM_BleObserve(TRUE, p_data->ble_observe.duration,
5014 bta_dm_observe_results_cb, bta_dm_observe_cmpl_cb))!= BTM_SUCCESS)
5015 {
5016 tBTA_DM_SEARCH data;
5017 APPL_TRACE_WARNING2(" %s BTM_BleObserve failed. status %d",__FUNCTION__,status);
5018 data.inq_cmpl.num_resps = 0;
5019 if (bta_dm_search_cb.p_scan_cback)
5020 {
5021 bta_dm_search_cb.p_scan_cback(BTA_DM_INQ_CMPL_EVT, &data);
5022 }
5023 }
5024 }
5025 else
5026 {
5027 bta_dm_search_cb.p_scan_cback = NULL;
5028 BTM_BleObserve(FALSE, 0, NULL,NULL );
5029 }
5030}
Andre Eisenbach5c44e452013-08-06 18:19:37 -07005031/*******************************************************************************
5032**
5033** Function bta_dm_ble_set_scan_params
5034**
5035** Description This function set the adv parameters.
5036**
5037** Parameters:
5038**
5039*******************************************************************************/
5040void bta_dm_ble_set_adv_params (tBTA_DM_MSG *p_data)
5041{
5042 BTM_BleSetAdvParams(p_data->ble_set_adv_params.adv_int_min,
5043 p_data->ble_set_adv_params.adv_int_max,
5044 p_data->ble_set_adv_params.p_dir_bda,
5045 BTA_DM_BLE_ADV_CHNL_MAP);
5046}
Andre Eisenbacheeeac992013-11-08 10:23:52 -08005047
Andre Eisenbach5c44e452013-08-06 18:19:37 -07005048/*******************************************************************************
5049**
5050** Function bta_dm_ble_set_adv_config
5051**
5052** Description This function set the customized ADV data configuration
5053**
5054** Parameters:
5055**
5056*******************************************************************************/
5057void bta_dm_ble_set_adv_config (tBTA_DM_MSG *p_data)
5058{
5059 BTM_BleWriteAdvData(p_data->ble_set_adv_data.data_mask,
5060 (tBTM_BLE_ADV_DATA *)p_data->ble_set_adv_data.p_adv_cfg);
5061}
5062
Andre Eisenbacheeeac992013-11-08 10:23:52 -08005063/*******************************************************************************
5064**
5065** Function bta_dm_ble_set_scan_rsp
5066**
5067** Description This function set the customized ADV scan resp. configuration
5068**
5069** Parameters:
5070**
5071*******************************************************************************/
5072void bta_dm_ble_set_scan_rsp (tBTA_DM_MSG *p_data)
5073{
5074 BTM_BleWriteScanRsp(p_data->ble_set_adv_data.data_mask,
5075 (tBTM_BLE_ADV_DATA *)p_data->ble_set_adv_data.p_adv_cfg);
5076}
5077
5078/*******************************************************************************
5079**
5080** Function bta_dm_ble_broadcast
5081**
5082** Description Starts or stops LE broadcasts
5083**
5084** Parameters:
5085**
5086*******************************************************************************/
5087void bta_dm_ble_broadcast (tBTA_DM_MSG *p_data)
5088{
5089 BTM_BleBroadcast(p_data->ble_observe.start);
5090}
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08005091
The Android Open Source Project5738f832012-12-12 16:00:35 -08005092#if ((defined BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE))
Andre Eisenbach6975b4d2013-08-05 16:55:38 -07005093#ifndef BTA_DM_GATT_CLOSE_DELAY_TOUT
5094#define BTA_DM_GATT_CLOSE_DELAY_TOUT 1000
5095#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08005096
5097/*******************************************************************************
5098**
Andre Eisenbache1202ca2013-05-15 04:55:08 -07005099** Function bta_dm_gattc_register
5100**
5101** Description Register with GATTC in DM if BLE is needed.
5102**
5103**
5104** Returns void
5105**
5106*******************************************************************************/
5107static void bta_dm_gattc_register(void)
5108{
5109 tBT_UUID app_uuid = {LEN_UUID_128,{0}};
5110
5111 if (bta_dm_search_cb.client_if == BTA_GATTS_INVALID_IF)
5112 {
5113 memset (&app_uuid.uu.uuid128, 0x87, LEN_UUID_128);
5114 BTA_GATTC_AppRegister(&app_uuid, bta_dm_gattc_callback);
5115 }
5116}
5117
5118/*******************************************************************************
5119**
The Android Open Source Project5738f832012-12-12 16:00:35 -08005120** Function btm_dm_start_disc_gatt_services
5121**
5122** Description This function starts a GATT service search request.
5123**
5124** Parameters:
5125**
5126*******************************************************************************/
5127static void btm_dm_start_disc_gatt_services (UINT16 conn_id)
5128{
5129 tBT_UUID *p_uuid = bta_dm_search_cb.p_srvc_uuid +
5130 bta_dm_search_cb.num_uuid - bta_dm_search_cb.uuid_to_search;
5131
5132 p_uuid = bta_dm_search_cb.p_srvc_uuid +
5133 bta_dm_search_cb.num_uuid - bta_dm_search_cb.uuid_to_search;
5134
5135 /* always search for all services */
5136 BTA_GATTC_ServiceSearchRequest(conn_id, p_uuid);
5137}
5138
5139/*******************************************************************************
5140**
5141** Function bta_dm_gatt_disc_result
5142**
5143** Description This function process the GATT service search result.
5144**
5145** Parameters:
5146**
5147*******************************************************************************/
5148static void bta_dm_gatt_disc_result(tBTA_GATT_ID service_id)
5149{
5150 tBTA_DM_SEARCH result;
5151
5152 /*
5153 * This logic will not work for gatt case. We are checking against the bluetooth profiles here
5154 * just copy the GATTID in raw data field and send it across.
5155 */
5156
5157
5158 if ( bta_dm_search_cb.ble_raw_used + sizeof(tBTA_GATT_ID) < bta_dm_search_cb.ble_raw_size )
5159 {
5160 APPL_TRACE_DEBUG3("ADDING BLE SERVICE uuid=0x%x, ble_ptr = 0x%x, ble_raw_used = 0x%x", service_id.uuid.uu.uuid16,bta_dm_search_cb.p_ble_rawdata,bta_dm_search_cb.ble_raw_used);
5161
Andre Eisenbachca22ac42013-02-13 17:02:11 +09005162 if(bta_dm_search_cb.p_ble_rawdata)
5163 {
5164 memcpy((bta_dm_search_cb.p_ble_rawdata + bta_dm_search_cb.ble_raw_used), &service_id,
5165 sizeof(service_id) );
The Android Open Source Project5738f832012-12-12 16:00:35 -08005166
Andre Eisenbachca22ac42013-02-13 17:02:11 +09005167 bta_dm_search_cb.ble_raw_used += sizeof(service_id);
5168 }
5169 else
5170 {
5171 APPL_TRACE_ERROR0("p_ble_rawdata is NULL");
5172 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08005173
5174 }
5175 else
5176 {
5177 APPL_TRACE_ERROR3("%s out of room to accomodate more service ids ble_raw_size = %d ble_raw_used = %d", __FUNCTION__,bta_dm_search_cb.ble_raw_size, bta_dm_search_cb.ble_raw_used );
5178 }
5179
5180 APPL_TRACE_ERROR1("bta_dm_gatt_disc_result serivce_id len=%d ", service_id.uuid.len);
5181 if ( bta_dm_search_cb.state != BTA_DM_SEARCH_IDLE)
5182 {
5183
5184 /* send result back to app now, one by one */
5185 bdcpy (result.disc_ble_res.bd_addr, bta_dm_search_cb.peer_bdaddr);
5186 BCM_STRNCPY_S((char*)result.disc_ble_res.bd_name, sizeof(BD_NAME), bta_dm_get_remname(), (BD_NAME_LEN-1));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08005187 result.disc_ble_res.bd_name[BD_NAME_LEN] = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08005188 memcpy(&result.disc_ble_res.service, &service_id.uuid, sizeof(tBT_UUID));
5189
5190 bta_dm_search_cb.p_search_cback(BTA_DM_DISC_BLE_RES_EVT, &result);
5191 }
5192}
5193
5194/*******************************************************************************
5195**
5196** Function bta_dm_gatt_disc_complete
5197**
5198** Description This function process the GATT service search complete.
5199**
5200** Parameters:
5201**
5202*******************************************************************************/
5203static void bta_dm_gatt_disc_complete(UINT16 conn_id, tBTA_GATT_STATUS status)
5204{
5205 tBTA_DM_MSG *p_msg;
5206
5207 APPL_TRACE_DEBUG1("bta_dm_gatt_disc_complete conn_id = %d",conn_id);
5208
5209 if (bta_dm_search_cb.uuid_to_search > 0) bta_dm_search_cb.uuid_to_search --;
5210
5211 if (status == BTA_GATT_OK && bta_dm_search_cb.uuid_to_search > 0)
5212 {
5213 btm_dm_start_disc_gatt_services(conn_id);
5214 }
5215 else
5216 {
5217 bta_dm_search_cb.uuid_to_search = 0;
5218
5219 /* no more services to be discovered */
5220 if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL)
5221 {
5222 p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT;
5223 p_msg->disc_result.result.disc_res.result = (status == BTA_GATT_OK) ? BTA_SUCCESS :BTA_FAILURE;
5224 p_msg->disc_result.result.disc_res.services = bta_dm_search_cb.services_found;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08005225 p_msg->disc_result.result.disc_res.num_uuids = 0;
5226 p_msg->disc_result.result.disc_res.p_uuid_list = NULL;
The Android Open Source Project5738f832012-12-12 16:00:35 -08005227 bdcpy (p_msg->disc_result.result.disc_res.bd_addr, bta_dm_search_cb.peer_bdaddr);
5228 BCM_STRNCPY_S((char*)p_msg->disc_result.result.disc_res.bd_name, sizeof(BD_NAME),
5229 bta_dm_get_remname(), (BD_NAME_LEN-1));
5230
5231 /* make sure the string is terminated */
5232 p_msg->disc_result.result.disc_res.bd_name[BD_NAME_LEN-1] = 0;
5233
5234 p_msg->disc_result.result.disc_res.device_type = BT_DEVICE_TYPE_BLE;
5235 if ( bta_dm_search_cb.ble_raw_used > 0 )
5236 {
5237 p_msg->disc_result.result.disc_res.p_raw_data = GKI_getbuf(bta_dm_search_cb.ble_raw_used);
5238
5239 memcpy( p_msg->disc_result.result.disc_res.p_raw_data,
5240 bta_dm_search_cb.p_ble_rawdata,
5241 bta_dm_search_cb.ble_raw_used );
5242
5243 p_msg->disc_result.result.disc_res.raw_data_size = bta_dm_search_cb.ble_raw_used;
5244 }
5245 else
5246 {
5247 p_msg->disc_result.result.disc_res.p_raw_data = NULL;
5248 bta_dm_search_cb.p_ble_rawdata = 0;
5249 }
5250
5251 bta_sys_sendmsg(p_msg);
5252 }
5253 if (conn_id != BTA_GATT_INVALID_CONN_ID)
5254 {
Andre Eisenbach6975b4d2013-08-05 16:55:38 -07005255 if (BTA_DM_GATT_CLOSE_DELAY_TOUT != 0)
5256 {
5257 bta_sys_start_timer(&bta_dm_search_cb.gatt_close_timer, BTA_DM_DISC_CLOSE_TOUT_EVT,
5258 BTA_DM_GATT_CLOSE_DELAY_TOUT);
5259 }
5260 else
5261 {
5262 BTA_GATTC_Close(conn_id);
5263 bta_dm_search_cb.conn_id = BTA_GATT_INVALID_CONN_ID;
5264 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08005265 }
Andre Eisenbach6975b4d2013-08-05 16:55:38 -07005266
The Android Open Source Project5738f832012-12-12 16:00:35 -08005267 bta_dm_search_cb.gatt_disc_active = FALSE;
5268 }
5269}
5270
5271/*******************************************************************************
5272**
Andre Eisenbach6975b4d2013-08-05 16:55:38 -07005273** Function bta_dm_close_gatt_conn
5274**
5275** Description This function close the GATT connection after delay timeout.
5276**
5277** Parameters:
5278**
5279*******************************************************************************/
5280void bta_dm_close_gatt_conn(tBTA_DM_MSG *p_data)
5281{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08005282 UNUSED(p_data);
5283
Andre Eisenbach6975b4d2013-08-05 16:55:38 -07005284 if (bta_dm_search_cb.conn_id != BTA_GATT_INVALID_CONN_ID)
5285 BTA_GATTC_Close(bta_dm_search_cb.conn_id);
5286
5287 bta_dm_search_cb.conn_id = BTA_GATT_INVALID_CONN_ID;
5288}
5289
5290/*******************************************************************************
5291**
The Android Open Source Project5738f832012-12-12 16:00:35 -08005292** Function btm_dm_start_gatt_discovery
5293**
5294** Description This is GATT initiate the service search by open a GATT connection
5295** first.
5296**
5297** Parameters:
5298**
5299*******************************************************************************/
5300void btm_dm_start_gatt_discovery (BD_ADDR bd_addr)
5301{
5302 bta_dm_search_cb.gatt_disc_active = TRUE;
Andre Eisenbach6975b4d2013-08-05 16:55:38 -07005303
5304 /* connection is already open */
5305 if (bdcmp(bta_dm_search_cb.pending_close_bda, bd_addr) == 0 &&
5306 bta_dm_search_cb.conn_id != BTA_GATT_INVALID_CONN_ID)
5307 {
5308 memset(bta_dm_search_cb.pending_close_bda, 0, BD_ADDR_LEN);
5309 bta_sys_stop_timer(&bta_dm_search_cb.gatt_close_timer);
5310 btm_dm_start_disc_gatt_services(bta_dm_search_cb.conn_id);
5311 }
5312 else
5313 BTA_GATTC_Open(bta_dm_search_cb.client_if, bd_addr, TRUE);
The Android Open Source Project5738f832012-12-12 16:00:35 -08005314}
5315
5316/*******************************************************************************
5317**
5318** Function bta_dm_cancel_gatt_discovery
5319**
5320** Description This is GATT cancel the GATT service search.
5321**
5322** Parameters:
5323**
5324*******************************************************************************/
5325static void bta_dm_cancel_gatt_discovery(BD_ADDR bd_addr)
5326{
5327 if (bta_dm_search_cb.conn_id == BTA_GATT_INVALID_CONN_ID)
5328 {
5329 BTA_GATTC_CancelOpen(bta_dm_search_cb.client_if, bd_addr, TRUE);
5330 }
5331
5332 bta_dm_gatt_disc_complete(bta_dm_search_cb.conn_id, (tBTA_GATT_STATUS) BTA_GATT_ERROR);
5333}
5334
5335/*******************************************************************************
5336**
5337** Function bta_dm_proc_open_evt
5338**
5339** Description process BTA_GATTC_OPEN_EVT in DM.
5340**
5341** Parameters:
5342**
5343*******************************************************************************/
5344void bta_dm_proc_open_evt(tBTA_GATTC_OPEN *p_data)
5345{
5346 UINT8 *p1;
5347 UINT8 *p2;
5348
5349 p1 = bta_dm_search_cb.peer_bdaddr;
5350 p2 = p_data->remote_bda;
5351
5352 APPL_TRACE_DEBUG5("DM Search state= %d search_cb.peer_dbaddr: [%08x%04x] connected_bda= [%08x%04x] ",
5353 bta_dm_search_cb.state,
5354 ((p1[0])<<24)+((p1[1])<<16)+((p1[2])<<8)+(p1[3]),
5355 ((p1[4])<<8)+ p1[5],
5356 ((p2[0])<<24)+((p2[1])<<16)+((p2[2])<<8)+(p2[3]),
5357 ((p2[4])<<8)+ p2[5]);
5358
5359 APPL_TRACE_DEBUG3("BTA_GATTC_OPEN_EVT conn_id = %d client_if=%d status = %d" ,
5360 p_data->conn_id,
5361 p_data->client_if,
5362 p_data->status);
5363
5364 bta_dm_search_cb.conn_id = p_data->conn_id;
5365
5366 if (p_data->status == BTA_GATT_OK)
5367 {
5368 btm_dm_start_disc_gatt_services(p_data->conn_id);
5369 }
5370 else
5371 {
5372 bta_dm_gatt_disc_complete(BTA_GATT_INVALID_CONN_ID, p_data->status);
5373 }
5374}
5375
5376/*******************************************************************************
5377**
5378** Function bta_dm_gattc_callback
5379**
5380** Description This is GATT client callback function used in DM.
5381**
5382** Parameters:
5383**
5384*******************************************************************************/
5385static void bta_dm_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
5386{
5387 APPL_TRACE_DEBUG1("bta_dm_gattc_callback event = %d", event);
5388
5389 switch (event)
5390 {
5391 case BTA_GATTC_REG_EVT:
5392 APPL_TRACE_DEBUG1("BTA_GATTC_REG_EVT client_if = %d", p_data->reg_oper.client_if);
5393 if (p_data->reg_oper.status == BTA_GATT_OK)
5394 bta_dm_search_cb.client_if = p_data->reg_oper.client_if;
5395 else
5396 bta_dm_search_cb.client_if = BTA_GATTS_INVALID_IF;
5397 break;
5398
5399 case BTA_GATTC_OPEN_EVT:
5400 bta_dm_proc_open_evt(&p_data->open);
5401 break;
5402
5403 case BTA_GATTC_SEARCH_RES_EVT:
5404 bta_dm_gatt_disc_result(p_data->srvc_res.service_uuid.id);
5405 break;
5406
5407 case BTA_GATTC_SEARCH_CMPL_EVT:
5408 if ( bta_dm_search_cb.state != BTA_DM_SEARCH_IDLE)
5409 bta_dm_gatt_disc_complete(p_data->search_cmpl.conn_id, p_data->search_cmpl.status);
5410 break;
5411
5412 case BTA_GATTC_CLOSE_EVT:
5413 APPL_TRACE_DEBUG1("BTA_GATTC_CLOSE_EVT reason = %d", p_data->close.reason);
5414 /* in case of disconnect before search is completed */
5415 if ( (bta_dm_search_cb.state != BTA_DM_SEARCH_IDLE) &&
5416 !memcmp(p_data->close.remote_bda, bta_dm_search_cb.peer_bdaddr, BD_ADDR_LEN))
5417 {
5418 bta_dm_gatt_disc_complete((UINT16)BTA_GATT_INVALID_CONN_ID, (tBTA_GATT_STATUS) BTA_GATT_ERROR);
5419 }
5420 break;
5421
5422 default:
5423 break;
5424 }
5425}
The Android Open Source Project5738f832012-12-12 16:00:35 -08005426#endif /* BTA_GATT_INCLUDED */
Andre Eisenbach2d754412013-11-20 17:23:06 -08005427
5428#if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE
5429/*******************************************************************************
5430**
5431** Function bta_dm_enable_scan_filter
5432**
5433** Description This function enable/disable adv payload filtering condition
5434**
5435** Parameters:
5436**
5437*******************************************************************************/
5438void bta_dm_enable_scan_filter (tBTA_DM_MSG *p_data)
5439{
5440 tBTA_SYS_VS_BLE_SCAN_PF_ENABLE param;
5441
5442 param.enable = p_data->ble_enable_scan_filter.enable;
5443 param.p_target = p_data->ble_enable_scan_filter.p_target;
5444 param.p_cmpl_cback = p_data->ble_enable_scan_filter.p_cmpl_cback;
5445
5446 bta_sys_vs_hdl(BTA_VS_BLE_SCAN_PF_ENABLE_EVT, (void *)&param);
5447}
5448
5449/*******************************************************************************
5450**
5451** Function bta_dm_cfg_filter_cond
5452**
5453** Description This function configure adv payload filtering condition
5454**
5455** Parameters:
5456**
5457*******************************************************************************/
5458void bta_dm_cfg_filter_cond (tBTA_DM_MSG *p_data)
5459{
5460 tBTA_SYS_VS_BLE_SCAN_PF_COND param;
5461
5462 param.action = p_data->ble_cfg_filter_cond.action;
5463 param.cond_type = p_data->ble_cfg_filter_cond.cond_type;
5464 param.p_cond = (void *)p_data->ble_cfg_filter_cond.p_cond_param;
5465 param.p_cmpl_cback = p_data->ble_cfg_filter_cond.p_cmpl_cback;
5466
5467 bta_sys_vs_hdl(BTA_VS_BLE_SCAN_PF_COND_EVT, (void *)&param);
5468}
5469#endif /* BLE_ANDROID_CONTROLLER_SCAN_FILTER */
The Android Open Source Project5738f832012-12-12 16:00:35 -08005470#endif /* BLE_INCLUDED */