1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "common/bt_target.h"
16 #include <stdlib.h>
17 #include <string.h>
18 #include "btc/btc_common.h"
19 #include "btc/btc_dm.h"
20 #include "btc/btc_main.h"
21 #include "common/bt_trace.h"
22 #include "common/bt_target.h"
23 #include "btc/btc_storage.h"
24 #include "btc/btc_ble_storage.h"
25 #include "btc_gap_ble.h"
26 #include "btm_int.h"
27 #include "bta/bta_api.h"
28 #include "bta/bta_gatt_api.h"
29 #include "osi/allocator.h"
30 #include "btc/btc_manage.h"
31
32
33 #if (BTC_GAP_BT_INCLUDED == 1)
34 #include "btc_gap_bt.h"
35 #endif /* BTC_GAP_BT_INCLUDED == 1 */
36 /******************************************************************************
37 ** Constants & Macros
38 ******************************************************************************/
39 #define BTA_SERVICE_ID_TO_SERVICE_MASK(id) (1 << (id))
40
41 /******************************************************************************
42 ** Static variables
43 ******************************************************************************/
44 #if BTC_DYNAMIC_MEMORY == 0
45 btc_dm_cb_t btc_dm_cb = {0};
46 #else
47 btc_dm_cb_t *btc_dm_cb_ptr;
48 #endif
49
50 /******************************************************************************
51 ** Static functions
52 ******************************************************************************/
53 /******************************************************************************
54 ** Externs
55 ******************************************************************************/
56 #if BTC_AV_INCLUDED
57 extern bt_status_t btc_av_source_execute_service(BOOLEAN b_enable);
58 extern bt_status_t btc_av_sink_execute_service(BOOLEAN b_enable);
59 #endif
60 #if BTC_HF_INCLUDED
61 extern bt_status_t btc_hf_execute_service(BOOLEAN b_enable);
62 #endif
63 #if BTC_HF_CLIENT_INCLUDED
64 extern bt_status_t btc_hf_client_execute_service(BOOLEAN b_enable);
65 #endif
66 /******************************************************************************
67 ** Functions
68 ******************************************************************************/
btc_dm_sec_arg_deep_free(btc_msg_t * msg)69 static void btc_dm_sec_arg_deep_free(btc_msg_t *msg)
70 {
71 btc_dm_sec_args_t *arg = (btc_dm_sec_args_t *)(msg->arg);
72 if (msg->act == BTA_DM_BLE_KEY_EVT) {
73 osi_free(arg->sec.ble_key.p_key_value);
74 }
75 }
76
btc_dm_sec_arg_deep_copy(btc_msg_t * msg,void * dst,void * src)77 void btc_dm_sec_arg_deep_copy(btc_msg_t *msg, void *dst, void *src)
78 {
79 tBTA_DM_SEC *dst_dm_sec = (tBTA_DM_SEC *)dst;
80 tBTA_DM_SEC *src_dm_sec = (tBTA_DM_SEC *)src;
81
82 if (!src_dm_sec) {
83 return;
84 }
85
86 assert(dst_dm_sec);
87 memcpy(dst_dm_sec, src_dm_sec, sizeof(tBTA_DM_SEC));
88
89 if (msg->act == BTA_DM_BLE_KEY_EVT) {
90 dst_dm_sec->ble_key.p_key_value = osi_malloc(sizeof(tBTM_LE_KEY_VALUE));
91 assert(src_dm_sec->ble_key.p_key_value);
92 assert(dst_dm_sec->ble_key.p_key_value);
93 memcpy(dst_dm_sec->ble_key.p_key_value, src_dm_sec->ble_key.p_key_value, sizeof(tBTM_LE_KEY_VALUE));
94 }
95 }
96
97 /*******************************************************************************
98 **
99 ** Function btc_dm_evt
100 **
101 ** Description Switches context from BTE to BTC for all DM events
102 **
103 ** Returns void
104 **
105 *******************************************************************************/
106
btc_dm_sec_evt(tBTA_DM_SEC_EVT event,tBTA_DM_SEC * data)107 void btc_dm_sec_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *data)
108 {
109 btc_msg_t msg;
110
111 msg.sig = BTC_SIG_API_CB;
112 msg.pid = BTC_PID_DM_SEC;
113 msg.act = event;
114
115 btc_transfer_context(&msg, (btc_dm_sec_args_t *)data, sizeof(btc_dm_sec_args_t), btc_dm_sec_arg_deep_copy);
116 }
117
btc_enable_bluetooth_evt(tBTA_STATUS status)118 static void btc_enable_bluetooth_evt(tBTA_STATUS status)
119 {
120 if (status == BTA_SUCCESS) {
121 future_ready(*btc_main_get_future_p(BTC_MAIN_ENABLE_FUTURE), FUTURE_SUCCESS);
122 } else {
123 future_ready(*btc_main_get_future_p(BTC_MAIN_ENABLE_FUTURE), FUTURE_FAIL);
124 }
125 }
126
btc_disable_bluetooth_evt(void)127 static void btc_disable_bluetooth_evt(void)
128 {
129 BTC_TRACE_DEBUG("%s", __FUNCTION__);
130
131 future_ready(*btc_main_get_future_p(BTC_MAIN_DISABLE_FUTURE), FUTURE_SUCCESS);
132 }
133
134 #if (SMP_INCLUDED == 1)
135 #if (BLE_INCLUDED == 1)
btc_dm_load_ble_local_keys(void)136 void btc_dm_load_ble_local_keys(void)
137 {
138 memset(&btc_dm_cb.ble_local_key_cb, 0, sizeof(btc_dm_local_key_cb_t));
139
140 if (btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_ER,(char*)&btc_dm_cb.ble_local_key_cb.er[0],
141 BT_OCTET16_LEN)== BT_STATUS_SUCCESS) {
142 btc_dm_cb.ble_local_key_cb.is_er_rcvd = 1;
143 BTC_TRACE_DEBUG("%s BLE ER key loaded",__func__ );
144 }
145
146 if ((btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_IR,(char*)&btc_dm_cb.ble_local_key_cb.id_keys.ir[0],
147 BT_OCTET16_LEN)== BT_STATUS_SUCCESS )&&
148 (btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_IRK, (char*)&btc_dm_cb.ble_local_key_cb.id_keys.irk[0],
149 BT_OCTET16_LEN)== BT_STATUS_SUCCESS)&&
150 (btc_storage_get_ble_local_key(BTC_LE_LOCAL_KEY_DHK,(char*)&btc_dm_cb.ble_local_key_cb.id_keys.dhk[0],
151 BT_OCTET16_LEN)== BT_STATUS_SUCCESS)) {
152 btc_dm_cb.ble_local_key_cb.is_id_keys_rcvd = 1;
153 BTC_TRACE_DEBUG("%s BLE ID keys loaded", __func__);
154 }
155
156 }
btc_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK * p_key_mask,BT_OCTET16 er,tBTA_BLE_LOCAL_ID_KEYS * p_id_keys)157 void btc_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK *p_key_mask, BT_OCTET16 er,
158 tBTA_BLE_LOCAL_ID_KEYS *p_id_keys)
159 {
160 if (btc_dm_cb.ble_local_key_cb.is_er_rcvd ) {
161 memcpy(&er[0], &btc_dm_cb.ble_local_key_cb.er[0], sizeof(BT_OCTET16));
162 *p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ER;
163 }
164
165 if (btc_dm_cb.ble_local_key_cb.is_id_keys_rcvd) {
166 memcpy(&p_id_keys->ir[0], &btc_dm_cb.ble_local_key_cb.id_keys.ir[0], sizeof(BT_OCTET16));
167 memcpy(&p_id_keys->irk[0], &btc_dm_cb.ble_local_key_cb.id_keys.irk[0], sizeof(BT_OCTET16));
168 memcpy(&p_id_keys->dhk[0], &btc_dm_cb.ble_local_key_cb.id_keys.dhk[0], sizeof(BT_OCTET16));
169 *p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ID;
170 }
171 BTC_TRACE_DEBUG("%s *p_key_mask=0x%02x",__func__, *p_key_mask);
172 }
173
174
btc_dm_remove_ble_bonding_keys(void)175 static void btc_dm_remove_ble_bonding_keys(void)
176 {
177 bt_bdaddr_t bd_addr;
178 BTC_TRACE_DEBUG("%s\n",__func__);
179
180 bdcpy(bd_addr.address, btc_dm_cb.pairing_cb.bd_addr);
181
182 btc_storage_remove_remote_addr_type(&bd_addr, false);
183 btc_storage_remove_ble_dev_auth_mode(&bd_addr, false);
184 btc_storage_remove_ble_dev_type(&bd_addr, false);
185 btc_storage_remove_ble_bonding_keys(&bd_addr);
186 }
187
btc_dm_save_ble_bonding_keys(void)188 static void btc_dm_save_ble_bonding_keys(void)
189 {
190 if (!(btc_dm_cb.pairing_cb.ble.is_penc_key_rcvd || btc_dm_cb.pairing_cb.ble.is_pid_key_rcvd || btc_dm_cb.pairing_cb.ble.is_pcsrk_key_rcvd ||
191 btc_dm_cb.pairing_cb.ble.is_lenc_key_rcvd || btc_dm_cb.pairing_cb.ble.is_lcsrk_key_rcvd || btc_dm_cb.pairing_cb.ble.is_lidk_key_rcvd)) {
192 return ;
193 }
194 bt_bdaddr_t bd_addr;
195
196 bdcpy(bd_addr.address, btc_dm_cb.pairing_cb.bd_addr);
197
198 btc_storage_set_ble_dev_type(&bd_addr, false);
199 BTC_TRACE_DEBUG("%s, penc = %d, pid = %d", __func__, btc_dm_cb.pairing_cb.ble.is_penc_key_rcvd, btc_dm_cb.pairing_cb.ble.is_pid_key_rcvd);
200 if (btc_dm_cb.pairing_cb.ble.is_penc_key_rcvd) {
201 btc_storage_add_ble_bonding_key(&bd_addr,
202 (char *) &btc_dm_cb.pairing_cb.ble.penc_key,
203 BTM_LE_KEY_PENC,
204 sizeof(tBTM_LE_PENC_KEYS));
205 btc_dm_cb.pairing_cb.ble.is_penc_key_rcvd = false;
206 }
207
208 if (btc_dm_cb.pairing_cb.ble.is_pid_key_rcvd) {
209 btc_storage_add_ble_bonding_key(&bd_addr,
210 (char *) &btc_dm_cb.pairing_cb.ble.pid_key,
211 BTM_LE_KEY_PID,
212 sizeof(tBTM_LE_PID_KEYS));
213 btc_dm_cb.pairing_cb.ble.is_pid_key_rcvd = false;
214 }
215
216
217 if (btc_dm_cb.pairing_cb.ble.is_pcsrk_key_rcvd) {
218 btc_storage_add_ble_bonding_key(&bd_addr,
219 (char *) &btc_dm_cb.pairing_cb.ble.pcsrk_key,
220 BTM_LE_KEY_PCSRK,
221 sizeof(tBTM_LE_PCSRK_KEYS));
222 btc_dm_cb.pairing_cb.ble.is_pcsrk_key_rcvd = false;
223 }
224
225
226 if (btc_dm_cb.pairing_cb.ble.is_lenc_key_rcvd) {
227 btc_storage_add_ble_bonding_key(&bd_addr,
228 (char *) &btc_dm_cb.pairing_cb.ble.lenc_key,
229 BTM_LE_KEY_LENC,
230 sizeof(tBTM_LE_LENC_KEYS));
231 btc_dm_cb.pairing_cb.ble.is_lenc_key_rcvd = false;
232 }
233
234 if (btc_dm_cb.pairing_cb.ble.is_lcsrk_key_rcvd) {
235 btc_storage_add_ble_bonding_key(&bd_addr,
236 (char *) &btc_dm_cb.pairing_cb.ble.lcsrk_key,
237 BTM_LE_KEY_LCSRK,
238 sizeof(tBTM_LE_LCSRK_KEYS));
239 btc_dm_cb.pairing_cb.ble.is_lcsrk_key_rcvd = false;
240 }
241
242 if (btc_dm_cb.pairing_cb.ble.is_lidk_key_rcvd) {
243 btc_storage_add_ble_bonding_key(&bd_addr,
244 NULL,
245 BTM_LE_KEY_LID,
246 0);
247 btc_dm_cb.pairing_cb.ble.is_lidk_key_rcvd = false;
248 }
249 }
250
btc_dm_ble_auth_cmpl_evt(tBTA_DM_AUTH_CMPL * p_auth_cmpl)251 static void btc_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
252 {
253 /* Save link key, if not temporary */
254 BTC_TRACE_DEBUG("%s, status = %d", __func__, p_auth_cmpl->success);
255 bt_status_t status = BT_STATUS_FAIL;
256 int addr_type;
257 bt_bdaddr_t bdaddr;
258 bdcpy(bdaddr.address, p_auth_cmpl->bd_addr);
259 bdcpy(btc_dm_cb.pairing_cb.bd_addr, p_auth_cmpl->bd_addr);
260
261 if (p_auth_cmpl->success) {
262 status = BT_STATUS_SUCCESS;
263 BTC_TRACE_DEBUG ("%s, - p_auth_cmpl->bd_addr: %08x%04x", __func__,
264 (p_auth_cmpl->bd_addr[0] << 24) + (p_auth_cmpl->bd_addr[1] << 16) + (p_auth_cmpl->bd_addr[2] << 8) + p_auth_cmpl->bd_addr[3],
265 (p_auth_cmpl->bd_addr[4] << 8) + p_auth_cmpl->bd_addr[5]);
266
267 // Check if need to save BLE keys
268 if((p_auth_cmpl->auth_mode & SMP_AUTH_GEN_BOND) == 0) {
269 return;
270 }
271
272 if (btc_storage_get_remote_addr_type(&bdaddr, &addr_type) != BT_STATUS_SUCCESS) {
273 btc_storage_set_remote_addr_type(&bdaddr, p_auth_cmpl->addr_type, true);
274 }
275 btc_storage_set_ble_dev_auth_mode(&bdaddr, p_auth_cmpl->auth_mode, true);
276 btc_dm_save_ble_bonding_keys();
277 } else {
278 /*Map the HCI fail reason to bt status */
279 switch (p_auth_cmpl->fail_reason) {
280 case BTA_DM_AUTH_SMP_PAIR_AUTH_FAIL:
281 case BTA_DM_AUTH_SMP_CONFIRM_VALUE_FAIL:
282 btc_dm_remove_ble_bonding_keys();
283 status = BT_STATUS_AUTH_FAILURE;
284 break;
285 case BTA_DM_AUTH_SMP_PAIR_NOT_SUPPORT:
286 status = BT_STATUS_AUTH_REJECTED;
287 break;
288 default:
289 btc_dm_remove_ble_bonding_keys();
290 status = BT_STATUS_FAIL;
291 break;
292 }
293
294 }
295
296 #if (CONFIG_BT_STACK_NO_LOG)
297 (void) status;
298 #endif
299 BTC_TRACE_DEBUG("%s, authentication status = %x", __func__, status);
300 return;
301
302 }
303 #endif ///BLE_INCLUDED == 1
304 #endif ///SMP_INCLUDED == 1
305
btc_dm_link_up_evt(tBTA_DM_LINK_UP * p_link_up)306 static void btc_dm_link_up_evt(tBTA_DM_LINK_UP *p_link_up)
307 {
308 BD_ADDR bd_addr;
309 bt_bdaddr_t bt_bdaddr;
310
311
312 if (p_link_up->sc_downgrade == 1) {
313 memcpy(bt_bdaddr.address, p_link_up->bd_addr, sizeof(BD_ADDR));
314 if (btc_storage_remove_bonded_device(&bt_bdaddr) == BT_STATUS_SUCCESS) {
315 memcpy(bd_addr, p_link_up->bd_addr, sizeof(BD_ADDR));
316 if (BTA_DmRemoveDevice(bd_addr, BT_TRANSPORT_BR_EDR) == BTA_SUCCESS) {
317 BTC_TRACE_EVENT(" %s() Bonding information removed.", __FUNCTION__);
318 } else {
319 BTC_TRACE_ERROR(" %s() BTA_DmRemoveDevice error", __FUNCTION__);
320 }
321 } else {
322 BTC_TRACE_ERROR(" %s() btc_storage_remove_bonded_device error", __FUNCTION__);
323 }
324 }
325 }
326
btc_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL * p_auth_cmpl)327 static void btc_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
328 {
329 /* Save link key, if not temporary */
330 bt_bdaddr_t bd_addr;
331 bt_status_t status;
332 BTC_TRACE_DEBUG("%s: bond state success %d, present %d, type%d\n", __func__, p_auth_cmpl->success,
333 p_auth_cmpl->key_present, p_auth_cmpl->key_type);
334
335 bdcpy(bd_addr.address, p_auth_cmpl->bd_addr);
336 if ( (p_auth_cmpl->success == 1) && (p_auth_cmpl->key_present) ) {
337 #if 0
338 if ((p_auth_cmpl->key_type < HCI_LKEY_TYPE_DEBUG_COMB) ||
339 (p_auth_cmpl->key_type == HCI_LKEY_TYPE_AUTH_COMB) ||
340 (p_auth_cmpl->key_type == HCI_LKEY_TYPE_CHANGED_COMB) ||
341 (p_auth_cmpl->key_type == HCI_LKEY_TYPE_AUTH_COMB_P_256)
342 )
343 #endif
344 if (1) {
345 bt_status_t ret;
346 BTC_TRACE_DEBUG("%s: Storing link key. key_type=0x%x",
347 __FUNCTION__, p_auth_cmpl->key_type);
348 ret = btc_storage_add_bonded_device(&bd_addr,
349 p_auth_cmpl->key, p_auth_cmpl->key_type,
350 16, p_auth_cmpl->sc_support);
351 BTC_ASSERTC(ret == BT_STATUS_SUCCESS, "storing link key failed", ret);
352 } else {
353 BTC_TRACE_DEBUG("%s: Temporary key. Not storing. key_type=0x%x",
354 __FUNCTION__, p_auth_cmpl->key_type);
355 }
356 }
357
358 // Skip SDP for certain HID Devices
359 if (p_auth_cmpl->success) {
360 status = BT_STATUS_SUCCESS;
361 } else {
362 // Map the HCI fail reason to bt status
363 switch (p_auth_cmpl->fail_reason) {
364 case HCI_ERR_PAGE_TIMEOUT:
365 BTC_TRACE_WARNING("%s() - Pairing timeout; retrying () ...", __FUNCTION__);
366 return;
367 /* Fall-through */
368 case HCI_ERR_CONNECTION_TOUT:
369 status = BT_STATUS_RMT_DEV_DOWN;
370 break;
371
372 case HCI_ERR_PAIRING_NOT_ALLOWED:
373 status = BT_STATUS_AUTH_REJECTED;
374 break;
375
376 case HCI_ERR_LMP_RESPONSE_TIMEOUT:
377 status = BT_STATUS_AUTH_FAILURE;
378 break;
379
380 /* map the auth failure codes, so we can retry pairing if necessary */
381 case HCI_ERR_AUTH_FAILURE:
382 case HCI_ERR_KEY_MISSING:
383 btc_storage_remove_bonded_device(&bd_addr);
384 case HCI_ERR_HOST_REJECT_SECURITY:
385 case HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE:
386 case HCI_ERR_UNIT_KEY_USED:
387 case HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED:
388 case HCI_ERR_INSUFFCIENT_SECURITY:
389 case HCI_ERR_PEER_USER:
390 case HCI_ERR_UNSPECIFIED:
391 BTC_TRACE_ERROR(" %s() Authentication fail reason %d",
392 __FUNCTION__, p_auth_cmpl->fail_reason);
393 /* if autopair attempts are more than 1, or not attempted */
394 status = BT_STATUS_AUTH_FAILURE;
395 break;
396 default:
397 status = BT_STATUS_FAIL;
398 }
399 }
400 #if (BTC_GAP_BT_INCLUDED == 1)
401 esp_bt_gap_cb_param_t param;
402 bt_status_t ret;
403 btc_msg_t msg;
404 msg.sig = BTC_SIG_API_CB;
405 msg.pid = BTC_PID_GAP_BT;
406 msg.act = BTC_GAP_BT_AUTH_CMPL_EVT;
407 param.auth_cmpl.stat = status;
408 memcpy(param.auth_cmpl.bda, p_auth_cmpl->bd_addr, ESP_BD_ADDR_LEN);
409 memcpy(param.auth_cmpl.device_name, p_auth_cmpl->bd_name, ESP_BT_GAP_MAX_BDNAME_LEN + 1);
410
411 ret = btc_inter_profile_call(&msg, ¶m);
412
413 if (ret != BT_STATUS_SUCCESS) {
414 BTC_TRACE_ERROR("%s btc_inter_profile_call failed\n", __func__);
415 }
416
417 #endif /// BTC_GAP_BT_INCLUDED == 1
418 (void) status;
419 }
420
btc_dm_pin_req_evt(tBTA_DM_PIN_REQ * p_pin_req)421 static void btc_dm_pin_req_evt(tBTA_DM_PIN_REQ *p_pin_req)
422 {
423 #if (BTC_GAP_BT_INCLUDED == 1)
424 esp_bt_gap_cb_param_t param;
425 bt_status_t ret;
426 btc_msg_t msg;
427 msg.sig = BTC_SIG_API_CB;
428 msg.pid = BTC_PID_GAP_BT;
429 msg.act = BTC_GAP_BT_PIN_REQ_EVT;
430 param.pin_req.min_16_digit = p_pin_req->min_16_digit;
431 memcpy(param.pin_req.bda, p_pin_req->bd_addr, ESP_BD_ADDR_LEN);
432
433 ret = btc_inter_profile_call(&msg, ¶m);
434
435 if (ret != BT_STATUS_SUCCESS) {
436 BTC_TRACE_ERROR("%s btc_inter_profile_call failed\n", __func__);
437 }
438 #endif /// BTC_GAP_BT_INCLUDED == 1
439 }
440
441 #if (BT_SSP_INCLUDED == 1)
btc_dm_sp_cfm_req_evt(tBTA_DM_SP_CFM_REQ * p_cfm_req)442 static void btc_dm_sp_cfm_req_evt(tBTA_DM_SP_CFM_REQ *p_cfm_req)
443 {
444 #if (BTC_GAP_BT_INCLUDED == 1)
445 if (p_cfm_req->just_works) {
446 // just work, not show to users.
447 BTA_DmConfirm(p_cfm_req->bd_addr, true);
448 return;
449 }
450
451 esp_bt_gap_cb_param_t param;
452 bt_status_t ret;
453 btc_msg_t msg;
454 msg.sig = BTC_SIG_API_CB;
455 msg.pid = BTC_PID_GAP_BT;
456 msg.act = BTC_GAP_BT_CFM_REQ_EVT;
457 param.cfm_req.num_val = p_cfm_req->num_val;
458 memcpy(param.cfm_req.bda, p_cfm_req->bd_addr, ESP_BD_ADDR_LEN);
459
460 ret = btc_inter_profile_call(&msg, ¶m);
461
462 if (ret != BT_STATUS_SUCCESS) {
463 BTC_TRACE_ERROR("%s btc_inter_profile_call failed\n", __func__);
464 }
465 #endif /// BTC_GAP_BT_INCLUDED == 1
466 }
467
btc_dm_sp_key_notif_evt(tBTA_DM_SP_KEY_NOTIF * p_key_notif)468 static void btc_dm_sp_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_key_notif)
469 {
470 #if (BTC_GAP_BT_INCLUDED == 1)
471 esp_bt_gap_cb_param_t param;
472 bt_status_t ret;
473 btc_msg_t msg;
474 msg.sig = BTC_SIG_API_CB;
475 msg.pid = BTC_PID_GAP_BT;
476 msg.act = BTC_GAP_BT_KEY_NOTIF_EVT;
477 param.key_notif.passkey = p_key_notif->passkey;
478 memcpy(param.key_notif.bda, p_key_notif->bd_addr, ESP_BD_ADDR_LEN);
479
480 ret = btc_inter_profile_call(&msg, ¶m);
481
482 if (ret != BT_STATUS_SUCCESS) {
483 BTC_TRACE_ERROR("%s btc_inter_profile_call failed\n", __func__);
484 }
485 #endif /// BTC_GAP_BT_INCLUDED == 1
486 }
487
btc_dm_sp_key_req_evt(tBTA_DM_SP_KEY_REQ * p_key_req)488 static void btc_dm_sp_key_req_evt(tBTA_DM_SP_KEY_REQ *p_key_req)
489 {
490 #if (BTC_GAP_BT_INCLUDED == 1)
491 esp_bt_gap_cb_param_t param;
492 bt_status_t ret;
493 btc_msg_t msg;
494 msg.sig = BTC_SIG_API_CB;
495 msg.pid = BTC_PID_GAP_BT;
496 msg.act = BTC_GAP_BT_KEY_REQ_EVT;
497 memcpy(param.key_req.bda, p_key_req->bd_addr, ESP_BD_ADDR_LEN);
498
499 ret = btc_inter_profile_call(&msg, ¶m);
500
501 if (ret != BT_STATUS_SUCCESS) {
502 BTC_TRACE_ERROR("%s btc_inter_profile_call failed\n", __func__);
503 }
504 #endif /// BTC_GAP_BT_INCLUDED == 1
505 }
506 #endif /// BT_SSP_INCLUDED == 1
507
btc_dm_dev_unpaired_evt(tBTA_DM_LINK_DOWN * p_link_down)508 static void btc_dm_dev_unpaired_evt(tBTA_DM_LINK_DOWN *p_link_down)
509 {
510 esp_bt_gap_cb_param_t param;
511 BTC_TRACE_DEBUG("%s",__func__);
512 memcpy(param.remove_bond_dev_cmpl.bda, p_link_down->bd_addr, ESP_BD_ADDR_LEN);
513 btm_set_bond_type_dev(p_link_down->bd_addr, BOND_TYPE_UNKNOWN);
514 if (p_link_down->status == HCI_SUCCESS) {
515 //remove the bonded key in the config and nvs flash.
516 param.remove_bond_dev_cmpl.status = btc_storage_remove_bonded_device((bt_bdaddr_t *)param.remove_bond_dev_cmpl.bda);
517 } else {
518 param.remove_bond_dev_cmpl.status = ESP_BT_STATUS_FAIL;
519 }
520
521 #if (BTC_GAP_BT_INCLUDED == 1)
522 bt_status_t ret;
523 btc_msg_t msg;
524 msg.sig = BTC_SIG_API_CB;
525 msg.pid = BTC_PID_GAP_BT;
526 msg.act = BTC_GAP_BT_REMOVE_BOND_DEV_COMPLETE_EVT;
527
528 ret = btc_inter_profile_call(&msg, ¶m);
529
530 if (ret != BT_STATUS_SUCCESS) {
531 BTC_TRACE_ERROR("%s btc_inter_profile_call failed\n", __func__);
532 }
533 #endif /// BTC_GAP_BT_INCLUDED == 1
534 }
535
536
537 #if (BTC_DM_PM_INCLUDED == 1)
btc_dm_pm_mode_chg_evt(tBTA_DM_MODE_CHG * p_mode_chg)538 static void btc_dm_pm_mode_chg_evt(tBTA_DM_MODE_CHG *p_mode_chg)
539 {
540 esp_bt_gap_cb_param_t param;
541 bt_status_t ret;
542 btc_msg_t msg;
543 msg.sig = BTC_SIG_API_CB;
544 msg.pid = BTC_PID_GAP_BT;
545 msg.act = BTC_GAP_BT_MODE_CHG_EVT;
546 memcpy(param.mode_chg.bda, p_mode_chg->bd_addr, ESP_BD_ADDR_LEN);
547 param.mode_chg.mode = p_mode_chg->mode;
548
549 ret = btc_inter_profile_call(&msg, ¶m);
550
551 if (ret != BT_STATUS_SUCCESS) {
552 BTC_TRACE_ERROR("%s btc_inter_profile_call failed\n", __func__);
553 }
554 }
555 #endif /// BTC_DM_PM_INCLUDED == 1
556
btc_get_enabled_services_mask(void)557 tBTA_SERVICE_MASK btc_get_enabled_services_mask(void)
558 {
559 return btc_dm_cb.btc_enabled_services;
560 }
561
btc_clear_services_mask(void)562 void btc_clear_services_mask(void)
563 {
564 btc_dm_cb.btc_enabled_services = 0;
565 }
566
btc_in_execute_service_request(tBTA_SERVICE_ID service_id,BOOLEAN b_enable)567 static bt_status_t btc_in_execute_service_request(tBTA_SERVICE_ID service_id,
568 BOOLEAN b_enable)
569 {
570 BTC_TRACE_DEBUG("%s service_id: %d\n", __FUNCTION__, service_id);
571 /* Check the service_ID and invoke the profile's BT state changed API */
572 switch (service_id) {
573 #if BTC_AV_INCLUDED
574 case BTA_A2DP_SOURCE_SERVICE_ID:
575 btc_av_source_execute_service(b_enable);
576 break;
577 case BTA_A2DP_SINK_SERVICE_ID:
578 btc_av_sink_execute_service(b_enable);
579 break;
580 #endif
581 #if BTC_HF_INCLUDED
582 case BTA_HFP_SERVICE_ID:
583 btc_hf_execute_service(b_enable);
584 break;
585 #endif /* #if BTC_HF_INCLUDED */
586 #if BTC_HF_CLIENT_INCLUDED
587 case BTA_HFP_HS_SERVICE_ID:
588 btc_hf_client_execute_service(b_enable);
589 break;
590 #endif /* #if BTC_HF_CLIENT_INCLUDED */
591 default:
592 BTC_TRACE_ERROR("%s: Unknown service being enabled\n", __FUNCTION__);
593 return BT_STATUS_FAIL;
594 }
595 return BT_STATUS_SUCCESS;
596 }
597
btc_dm_execute_service_request(BOOLEAN enable,char * p_param)598 void btc_dm_execute_service_request(BOOLEAN enable, char *p_param)
599 {
600 btc_in_execute_service_request(*((tBTA_SERVICE_ID *)p_param), enable);
601 }
602
btc_dm_enable_service(tBTA_SERVICE_ID service_id)603 bt_status_t btc_dm_enable_service(tBTA_SERVICE_ID service_id)
604 {
605 tBTA_SERVICE_ID *p_id = &service_id;
606
607 btc_dm_cb.btc_enabled_services |= (1 << service_id);
608
609 BTC_TRACE_DEBUG("%s: current services:0x%x", __FUNCTION__, btc_dm_cb.btc_enabled_services);
610
611 btc_dm_execute_service_request(1, (char *)p_id);
612
613 return BT_STATUS_SUCCESS;
614 }
615
btc_dm_disable_service(tBTA_SERVICE_ID service_id)616 bt_status_t btc_dm_disable_service(tBTA_SERVICE_ID service_id)
617 {
618 tBTA_SERVICE_ID *p_id = &service_id;
619
620 btc_dm_cb.btc_enabled_services &= (tBTA_SERVICE_MASK)(~(1 << service_id));
621
622 BTC_TRACE_DEBUG("%s: Current Services:0x%x", __FUNCTION__, btc_dm_cb.btc_enabled_services);
623
624 btc_dm_execute_service_request(0, (char *)p_id);
625
626 return BT_STATUS_SUCCESS;
627 }
628
btc_dm_sec_cb_handler(btc_msg_t * msg)629 void btc_dm_sec_cb_handler(btc_msg_t *msg)
630 {
631 btc_dm_sec_args_t *arg = (btc_dm_sec_args_t *)(msg->arg);
632 tBTA_DM_SEC *p_data = &(arg->sec);
633 esp_ble_gap_cb_param_t param = {0};
634 btc_msg_t ble_msg = {0};
635 bool rsp_app = false;
636 bt_status_t ret = BT_STATUS_SUCCESS;
637 ble_msg.sig = BTC_SIG_API_CB;
638 ble_msg.pid = BTC_PID_GAP_BLE;
639 // tBTA_SERVICE_MASK service_mask;
640 BTC_TRACE_DEBUG("btc_dm_upstreams_cback ev: %d\n", msg->act);
641
642 switch (msg->act) {
643 case BTA_DM_ENABLE_EVT: {
644 btc_clear_services_mask();
645 #if (SMP_INCLUDED == 1)
646 btc_storage_load_bonded_devices();
647 #if (BLE_INCLUDED == 1)
648 //load the bonding device to the btm layer
649 btc_storage_load_bonded_ble_devices();
650 #endif ///BLE_INCLUDED == 1
651 #endif ///SMP_INCLUDED == 1
652
653 /* Set initial device name, it can be overwritten later */
654 if (p_data->enable.status == BTA_SUCCESS) {
655 const char *initial_device_name = "ESP32";
656 BTA_DmSetDeviceName(initial_device_name);
657 }
658 btc_enable_bluetooth_evt(p_data->enable.status);
659 break;
660 }
661 case BTA_DM_DISABLE_EVT: {
662 tBTA_SERVICE_MASK service_mask = btc_get_enabled_services_mask();
663 for (int i = 0; i <= BTA_MAX_SERVICE_ID; i++) {
664 if (service_mask &
665 (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i))) {
666 btc_in_execute_service_request(i, 0);
667 }
668 }
669 btc_disable_bluetooth_evt();
670 break;
671 }
672 case BTA_DM_PIN_REQ_EVT:
673 BTC_TRACE_DEBUG("BTA_DM_PIN_REQ_EVT");
674 btc_dm_pin_req_evt(&p_data->pin_req);
675 break;
676 case BTA_DM_AUTH_CMPL_EVT:
677 btc_dm_auth_cmpl_evt(&p_data->auth_cmpl);
678 break;
679 case BTA_DM_BOND_CANCEL_CMPL_EVT:
680 BTC_TRACE_DEBUG("BTA_DM_BOND_CANCEL_CMPL_EVT");
681 break;
682 #if (BT_SSP_INCLUDED == 1)
683 case BTA_DM_SP_CFM_REQ_EVT:
684 btc_dm_sp_cfm_req_evt(&p_data->cfm_req);
685 break;
686 case BTA_DM_SP_KEY_NOTIF_EVT:
687 btc_dm_sp_key_notif_evt(&p_data->key_notif);
688 break;
689 case BTA_DM_SP_KEY_REQ_EVT:
690 btc_dm_sp_key_req_evt(&p_data->key_req);
691 break;
692 case BTA_DM_SP_RMT_OOB_EVT:
693 BTC_TRACE_DEBUG("BTA_DM_SP_RMT_OOB_EVT");
694 break;
695 case BTA_DM_SP_KEYPRESS_EVT:
696 BTC_TRACE_DEBUG("BTA_DM_SP_KEYPRESS_EVT");
697 break;
698 #endif ///BT_SSP_INCLUDED == 1
699
700 case BTA_DM_DEV_UNPAIRED_EVT: {
701 btc_dm_dev_unpaired_evt(&p_data->link_down);
702 break;
703 }
704 #if (BLE_INCLUDED == 1)
705 case BTA_DM_BLE_DEV_UNPAIRED_EVT: {
706 #if (SMP_INCLUDED == 1)
707 bt_bdaddr_t bd_addr;
708 rsp_app = true;
709 BTC_TRACE_DEBUG("BTA_DM_BLE_DEV_UNPAIRED_EVT");
710 memcpy(bd_addr.address, p_data->link_down.bd_addr, sizeof(BD_ADDR));
711 btm_set_bond_type_dev(p_data->link_down.bd_addr, BOND_TYPE_UNKNOWN);
712 param.remove_bond_dev_cmpl.status = ESP_BT_STATUS_FAIL;
713
714 if (p_data->link_down.status == HCI_SUCCESS) {
715 //remove the bonded key in the config and nvs flash.
716 btc_storage_remove_ble_dev_type(&bd_addr, false);
717 btc_storage_remove_remote_addr_type(&bd_addr, false);
718 btc_storage_remove_ble_dev_auth_mode(&bd_addr, false);
719 param.remove_bond_dev_cmpl.status = btc_storage_remove_ble_bonding_keys(&bd_addr);
720 }
721 ble_msg.act = ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT;
722 memcpy(param.remove_bond_dev_cmpl.bd_addr, p_data->link_down.bd_addr, sizeof(BD_ADDR));
723 #endif /* #if (SMP_INCLUDED == 1) */
724 break;
725 }
726 #endif ///BLE_INCLUDED == 1
727 case BTA_DM_BUSY_LEVEL_EVT:
728 #if (BTC_GAP_BT_INCLUDED == 1)
729 {
730 if (p_data->busy_level.level_flags & BTM_BL_INQUIRY_PAGING_MASK) {
731 btc_gap_bt_busy_level_updated(p_data->busy_level.level_flags);
732 }
733 break;
734 }
735 #endif /* BTC_GAP_BT_INCLUDED == 1 */
736 case BTA_DM_LINK_DOWN_EVT:
737 case BTA_DM_HW_ERROR_EVT:
738 BTC_TRACE_DEBUG( "btc_dm_sec_cback : unhandled event (%d)\n", msg->act );
739 break;
740 case BTA_DM_LINK_UP_EVT:
741 btc_dm_link_up_evt(&p_data->link_up);
742 break;
743 #if ((BLE_INCLUDED == 1) && (SMP_INCLUDED == 1))
744 case BTA_DM_BLE_AUTH_CMPL_EVT: {
745 rsp_app = true;
746 ble_msg.act = ESP_GAP_BLE_AUTH_CMPL_EVT;
747 param.ble_security.auth_cmpl.addr_type = p_data->auth_cmpl.addr_type;
748 param.ble_security.auth_cmpl.dev_type = p_data->auth_cmpl.dev_type;
749 param.ble_security.auth_cmpl.key_type = p_data->auth_cmpl.key_type;
750 param.ble_security.auth_cmpl.fail_reason = p_data->auth_cmpl.fail_reason;
751 param.ble_security.auth_cmpl.success = p_data->auth_cmpl.success ? true : false;
752 param.ble_security.auth_cmpl.key_present = p_data->auth_cmpl.key_present;
753 memcpy(param.ble_security.auth_cmpl.bd_addr, p_data->auth_cmpl.bd_addr, sizeof(BD_ADDR));
754 memcpy(param.ble_security.auth_cmpl.key, p_data->auth_cmpl.key, sizeof(LINK_KEY));
755 param.ble_security.auth_cmpl.auth_mode = p_data->auth_cmpl.auth_mode;
756 btc_dm_ble_auth_cmpl_evt(&p_data->auth_cmpl);
757 break;
758 }
759 case BTA_DM_BLE_KEY_EVT: {
760 rsp_app = true;
761 ble_msg.act = ESP_GAP_BLE_KEY_EVT;
762 param.ble_security.ble_key.key_type = p_data->ble_key.key_type;
763 memcpy(param.ble_security.ble_key.bd_addr, p_data->ble_key.bd_addr, BD_ADDR_LEN);
764 switch (p_data->ble_key.key_type) {
765 case BTM_LE_KEY_PENC: {
766 BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_PENC");
767 btc_dm_cb.pairing_cb.ble.is_penc_key_rcvd = 1;
768 btc_dm_cb.pairing_cb.ble.penc_key = p_data->ble_key.p_key_value->penc_key;
769 memcpy(&btc_dm_cb.pairing_cb.ble.penc_key, &p_data->ble_key.p_key_value->penc_key,
770 sizeof(tBTM_LE_PENC_KEYS));
771 memcpy(¶m.ble_security.ble_key.p_key_value.penc_key,
772 &p_data->ble_key.p_key_value->penc_key, sizeof(tBTM_LE_PENC_KEYS));
773 break;
774 }
775 case BTM_LE_KEY_PID: {
776 BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_PID");
777 btc_dm_cb.pairing_cb.ble.is_pid_key_rcvd = 1;
778 memcpy(&btc_dm_cb.pairing_cb.ble.pid_key, &p_data->ble_key.p_key_value->pid_key,
779 sizeof(tBTM_LE_PID_KEYS));
780 //Note: The memory size of the addr_type in ble_security.ble_key.p_key_value.pid_key is different from that of p_data->ble_key.p_key_value->pid_key.
781 memcpy(¶m.ble_security.ble_key.p_key_value.pid_key.irk,
782 &p_data->ble_key.p_key_value->pid_key.irk, ESP_BT_OCTET16_LEN);
783 param.ble_security.ble_key.p_key_value.pid_key.addr_type = p_data->ble_key.p_key_value->pid_key.addr_type;
784 memcpy(¶m.ble_security.ble_key.p_key_value.pid_key.static_addr,
785 &p_data->ble_key.p_key_value->pid_key.static_addr, ESP_BD_ADDR_LEN);
786 break;
787 }
788 case BTM_LE_KEY_PCSRK: {
789 BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_PCSRK");
790 btc_dm_cb.pairing_cb.ble.is_pcsrk_key_rcvd = 1;
791 memcpy(&btc_dm_cb.pairing_cb.ble.pcsrk_key, &p_data->ble_key.p_key_value->pcsrk_key,
792 sizeof(tBTM_LE_PCSRK_KEYS));
793 memcpy(¶m.ble_security.ble_key.p_key_value.pcsrk_key,
794 &p_data->ble_key.p_key_value->pcsrk_key, sizeof(tBTM_LE_PCSRK_KEYS));
795 break;
796 }
797 case BTM_LE_KEY_LENC: {
798 BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_LENC");
799 btc_dm_cb.pairing_cb.ble.is_lenc_key_rcvd = 1;
800 memcpy(&btc_dm_cb.pairing_cb.ble.lenc_key, &p_data->ble_key.p_key_value->lenc_key,
801 sizeof(tBTM_LE_LENC_KEYS));
802 memcpy(¶m.ble_security.ble_key.p_key_value.lenc_key,
803 &p_data->ble_key.p_key_value->lenc_key, sizeof(tBTM_LE_LENC_KEYS));
804 break;
805 }
806 case BTM_LE_KEY_LCSRK: {
807 BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_LCSRK");
808 btc_dm_cb.pairing_cb.ble.is_lcsrk_key_rcvd = 1;
809 memcpy(&btc_dm_cb.pairing_cb.ble.lcsrk_key, &p_data->ble_key.p_key_value->lcsrk_key,
810 sizeof(tBTM_LE_LCSRK_KEYS));
811 memcpy(¶m.ble_security.ble_key.p_key_value.lcsrk_key,
812 &p_data->ble_key.p_key_value->lcsrk_key, sizeof(tBTM_LE_LCSRK_KEYS));
813 break;
814 }
815 case BTM_LE_KEY_LID: {
816 BTC_TRACE_DEBUG("Rcv BTA_LE_KEY_LID");
817 btc_dm_cb.pairing_cb.ble.is_lidk_key_rcvd = 1;
818 break;
819 }
820 default:
821 break;
822 }
823
824 break;
825 }
826 case BTA_DM_BLE_SEC_REQ_EVT: {
827 rsp_app = true;
828 ble_msg.act = ESP_GAP_BLE_SEC_REQ_EVT;
829 memcpy(param.ble_security.ble_req.bd_addr, p_data->ble_req.bd_addr, BD_ADDR_LEN);
830 break;
831 }
832 case BTA_DM_BLE_PASSKEY_NOTIF_EVT: {
833 rsp_app = true;
834 ble_msg.act = ESP_GAP_BLE_PASSKEY_NOTIF_EVT;
835 param.ble_security.key_notif.passkey = p_data->key_notif.passkey;
836 memcpy(param.ble_security.key_notif.bd_addr, p_data->ble_req.bd_addr, BD_ADDR_LEN);
837 break;
838 }
839 case BTA_DM_BLE_PASSKEY_REQ_EVT: {
840 rsp_app = true;
841 ble_msg.act = ESP_GAP_BLE_PASSKEY_REQ_EVT;
842 memcpy(param.ble_security.ble_req.bd_addr, p_data->ble_req.bd_addr, BD_ADDR_LEN);
843 break;
844 }
845 case BTA_DM_BLE_OOB_REQ_EVT: {
846 rsp_app = true;
847 ble_msg.act = ESP_GAP_BLE_OOB_REQ_EVT;
848 memcpy(param.ble_security.ble_req.bd_addr, p_data->ble_req.bd_addr, BD_ADDR_LEN);
849 break;
850 }
851 case BTA_DM_BLE_LOCAL_IR_EVT: {
852 rsp_app = true;
853 ble_msg.act = ESP_GAP_BLE_LOCAL_IR_EVT;
854 memcpy(¶m.ble_security.ble_id_keys, &p_data->ble_id_keys, sizeof(tBTA_BLE_LOCAL_ID_KEYS));
855 BTC_TRACE_DEBUG("BTA_DM_BLE_LOCAL_IR_EVT. ");
856 btc_dm_cb.ble_local_key_cb.is_id_keys_rcvd = 1;
857 memcpy(&btc_dm_cb.ble_local_key_cb.id_keys.irk[0],
858 &p_data->ble_id_keys.irk[0], sizeof(BT_OCTET16));
859 memcpy(&btc_dm_cb.ble_local_key_cb.id_keys.ir[0],
860 &p_data->ble_id_keys.ir[0], sizeof(BT_OCTET16));
861 memcpy(&btc_dm_cb.ble_local_key_cb.id_keys.dhk[0],
862 &p_data->ble_id_keys.dhk[0], sizeof(BT_OCTET16));
863 btc_storage_add_ble_local_key( (char *)&btc_dm_cb.ble_local_key_cb.id_keys.irk[0],
864 BTC_LE_LOCAL_KEY_IRK,
865 BT_OCTET16_LEN);
866 btc_storage_add_ble_local_key( (char *)&btc_dm_cb.ble_local_key_cb.id_keys.ir[0],
867 BTC_LE_LOCAL_KEY_IR,
868 BT_OCTET16_LEN);
869 btc_storage_add_ble_local_key( (char *)&btc_dm_cb.ble_local_key_cb.id_keys.dhk[0],
870 BTC_LE_LOCAL_KEY_DHK,
871 BT_OCTET16_LEN);
872 break;
873 }
874 case BTA_DM_BLE_LOCAL_ER_EVT: {
875 rsp_app = true;
876 ble_msg.act = ESP_GAP_BLE_LOCAL_ER_EVT;
877 memcpy(¶m.ble_security.ble_id_keys, &p_data->ble_id_keys, sizeof(tBTA_BLE_LOCAL_ID_KEYS));
878 BTC_TRACE_DEBUG("BTA_DM_BLE_LOCAL_ER_EVT. ");
879 btc_dm_cb.ble_local_key_cb.is_er_rcvd = 1;
880 memcpy(&btc_dm_cb.ble_local_key_cb.er[0], &p_data->ble_er[0], sizeof(BT_OCTET16));
881 btc_storage_add_ble_local_key( (char *)&btc_dm_cb.ble_local_key_cb.er[0],
882 BTC_LE_LOCAL_KEY_ER,
883 BT_OCTET16_LEN);
884 break;
885 }
886 case BTA_DM_BLE_NC_REQ_EVT: {
887 rsp_app = true;
888 ble_msg.act = ESP_GAP_BLE_NC_REQ_EVT;
889 memcpy(param.ble_security.key_notif.bd_addr, p_data->key_notif.bd_addr, BD_ADDR_LEN);
890 param.ble_security.key_notif.passkey = p_data->key_notif.passkey;
891 break;
892 }
893 #endif
894
895 #if (BTC_DM_PM_INCLUDED == 1)
896 case BTA_DM_PM_MODE_CHG_EVT:
897 BTC_TRACE_DEBUG("BTA_DM_PM_MODE_CHG_EVT mode:%d", p_data->mode_chg.mode);
898 btc_dm_pm_mode_chg_evt(&p_data->mode_chg);
899 break;
900 #endif /// BTA_DM_PM_INCLUDED == 1
901
902 case BTA_DM_AUTHORIZE_EVT:
903 case BTA_DM_SIG_STRENGTH_EVT:
904 case BTA_DM_ROLE_CHG_EVT:
905 BTC_TRACE_DEBUG( "btc_dm_sec_cback : unhandled event (%d)\n", msg->act );
906 break;
907 default:
908 BTC_TRACE_DEBUG( "btc_dm_sec_cback : unhandled event (%d)\n", msg->act );
909 break;
910 }
911
912 if (rsp_app) {
913 ret = btc_inter_profile_call(&ble_msg, ¶m);
914
915 if (ret != BT_STATUS_SUCCESS) {
916 BTC_TRACE_ERROR("%s btc_inter_profile_call failed\n", __func__);
917 }
918 }
919 btc_dm_sec_arg_deep_free(msg);
920 }
921