external/bluetooth/bluedroid
リビジョン | 3014db38dfd3ce589ce041d96771a7cae793edef (tree) |
---|---|
日時 | 2014-08-27 19:27:53 |
作者 | Chih-Wei Huang <cwhuang@linu...> |
コミッター | Chih-Wei Huang |
Merge tag 'android-4.4.4_r2' into kitkat-x86
Android 4.4.4 Release 2
@@ -673,6 +673,11 @@ void bta_dm_remove_device (tBTA_DM_MSG *p_data) | ||
673 | 673 | int i; |
674 | 674 | tBTA_DM_SEC sec_event; |
675 | 675 | |
676 | +#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE) | |
677 | + /* need to remove all pending background connection before unpair */ | |
678 | + BTA_GATTC_CancelOpen(0, p_dev->bd_addr, FALSE); | |
679 | +#endif | |
680 | + | |
676 | 681 | if (BTM_IsAclConnectionUp(p_dev->bd_addr)) |
677 | 682 | { |
678 | 683 | /* Take the link down first, and mark the device for removal when disconnected */ |
@@ -692,6 +697,11 @@ void bta_dm_remove_device (tBTA_DM_MSG *p_data) | ||
692 | 697 | else /* Ok to remove the device in application layer */ |
693 | 698 | { |
694 | 699 | BTM_SecDeleteDevice(p_dev->bd_addr); |
700 | +#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE) | |
701 | + /* remove all cached GATT information */ | |
702 | + BTA_GATTC_Refresh(p_dev->bd_addr); | |
703 | +#endif | |
704 | + | |
695 | 705 | if( bta_dm_cb.p_sec_cback ) |
696 | 706 | { |
697 | 707 | bdcpy(sec_event.link_down.bd_addr, p_dev->bd_addr); |
@@ -3459,6 +3469,10 @@ void bta_dm_acl_change(tBTA_DM_MSG *p_data) | ||
3459 | 3469 | if( bta_dm_cb.device_list.peer_device[i].conn_state == BTA_DM_UNPAIRING ) |
3460 | 3470 | { |
3461 | 3471 | BTM_SecDeleteDevice(bta_dm_cb.device_list.peer_device[i].peer_bdaddr); |
3472 | +#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE) | |
3473 | + /* remove all cached GATT information */ | |
3474 | + BTA_GATTC_Refresh(p_bda); | |
3475 | +#endif | |
3462 | 3476 | issue_unpair_cb = TRUE; |
3463 | 3477 | } |
3464 | 3478 |
@@ -3768,6 +3782,12 @@ static void bta_dm_remove_sec_dev_entry(BD_ADDR remote_bd_addr) | ||
3768 | 3782 | else |
3769 | 3783 | { |
3770 | 3784 | BTM_SecDeleteDevice (remote_bd_addr); |
3785 | +#if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE) | |
3786 | + /* need to remove all pending background connection */ | |
3787 | + BTA_GATTC_CancelOpen(0, remote_bd_addr, FALSE); | |
3788 | + /* remove all cached GATT information */ | |
3789 | + BTA_GATTC_Refresh(remote_bd_addr); | |
3790 | +#endif | |
3771 | 3791 | } |
3772 | 3792 | } |
3773 | 3793 |
@@ -4997,6 +5017,7 @@ void bta_dm_ble_set_adv_params (tBTA_DM_MSG *p_data) | ||
4997 | 5017 | p_data->ble_set_adv_params.p_dir_bda, |
4998 | 5018 | BTA_DM_BLE_ADV_CHNL_MAP); |
4999 | 5019 | } |
5020 | + | |
5000 | 5021 | /******************************************************************************* |
5001 | 5022 | ** |
5002 | 5023 | ** Function bta_dm_ble_set_adv_config |
@@ -5012,6 +5033,34 @@ void bta_dm_ble_set_adv_config (tBTA_DM_MSG *p_data) | ||
5012 | 5033 | (tBTM_BLE_ADV_DATA *)p_data->ble_set_adv_data.p_adv_cfg); |
5013 | 5034 | } |
5014 | 5035 | |
5036 | +/******************************************************************************* | |
5037 | +** | |
5038 | +** Function bta_dm_ble_set_scan_rsp | |
5039 | +** | |
5040 | +** Description This function set the customized ADV scan resp. configuration | |
5041 | +** | |
5042 | +** Parameters: | |
5043 | +** | |
5044 | +*******************************************************************************/ | |
5045 | +void bta_dm_ble_set_scan_rsp (tBTA_DM_MSG *p_data) | |
5046 | +{ | |
5047 | + BTM_BleWriteScanRsp(p_data->ble_set_adv_data.data_mask, | |
5048 | + (tBTM_BLE_ADV_DATA *)p_data->ble_set_adv_data.p_adv_cfg); | |
5049 | +} | |
5050 | + | |
5051 | +/******************************************************************************* | |
5052 | +** | |
5053 | +** Function bta_dm_ble_broadcast | |
5054 | +** | |
5055 | +** Description Starts or stops LE broadcasts | |
5056 | +** | |
5057 | +** Parameters: | |
5058 | +** | |
5059 | +*******************************************************************************/ | |
5060 | +void bta_dm_ble_broadcast (tBTA_DM_MSG *p_data) | |
5061 | +{ | |
5062 | + BTM_BleBroadcast(p_data->ble_observe.start); | |
5063 | +} | |
5015 | 5064 | |
5016 | 5065 | #if ((defined BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE)) |
5017 | 5066 | #ifndef BTA_DM_GATT_CLOSE_DELAY_TOUT |
@@ -1510,6 +1510,60 @@ void BTA_DmBleSetAdvConfig (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv | ||
1510 | 1510 | bta_sys_sendmsg(p_msg); |
1511 | 1511 | } |
1512 | 1512 | } |
1513 | + | |
1514 | +/******************************************************************************* | |
1515 | +** | |
1516 | +** Function BTA_DmBleSetScanRsp | |
1517 | +** | |
1518 | +** Description This function is called to override the BTA scan response. | |
1519 | +** | |
1520 | +** Parameters Pointer to User defined ADV data structure | |
1521 | +** | |
1522 | +** Returns None | |
1523 | +** | |
1524 | +*******************************************************************************/ | |
1525 | +BTA_API extern void BTA_DmBleSetScanRsp (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv_cfg) | |
1526 | +{ | |
1527 | + tBTA_DM_API_SET_ADV_CONFIG *p_msg; | |
1528 | + | |
1529 | + if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG *) GKI_getbuf(sizeof(tBTA_DM_API_SET_ADV_CONFIG))) != NULL) | |
1530 | + { | |
1531 | + p_msg->hdr.event = BTA_DM_API_BLE_SET_SCAN_RSP_EVT; | |
1532 | + p_msg->data_mask = data_mask; | |
1533 | + p_msg->p_adv_cfg = p_adv_cfg; | |
1534 | + | |
1535 | + bta_sys_sendmsg(p_msg); | |
1536 | + } | |
1537 | +} | |
1538 | + | |
1539 | +/******************************************************************************* | |
1540 | +** | |
1541 | +** Function BTA_DmBleBroadcast | |
1542 | +** | |
1543 | +** Description This function starts or stops LE broadcasting. | |
1544 | +** | |
1545 | +** Parameters start: start or stop broadcast. | |
1546 | +** | |
1547 | +** Returns None | |
1548 | +** | |
1549 | +*******************************************************************************/ | |
1550 | +BTA_API extern void BTA_DmBleBroadcast (BOOLEAN start) | |
1551 | +{ | |
1552 | + tBTA_DM_API_BLE_OBSERVE *p_msg; | |
1553 | + | |
1554 | + APPL_TRACE_API1("BTA_DmBleBroadcast: start = %d ", start); | |
1555 | + | |
1556 | + if ((p_msg = (tBTA_DM_API_BLE_OBSERVE *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_OBSERVE))) != NULL) | |
1557 | + { | |
1558 | + memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_OBSERVE)); | |
1559 | + | |
1560 | + p_msg->hdr.event = BTA_DM_API_BLE_BROADCAST_EVT; | |
1561 | + p_msg->start = start; | |
1562 | + | |
1563 | + bta_sys_sendmsg(p_msg); | |
1564 | + } | |
1565 | +} | |
1566 | + | |
1513 | 1567 | #endif |
1514 | 1568 | /******************************************************************************* |
1515 | 1569 | ** |
@@ -101,6 +101,8 @@ enum | ||
101 | 101 | BTA_DM_API_BLE_OBSERVE_EVT, |
102 | 102 | BTA_DM_API_BLE_ADV_PARAM_EVT, |
103 | 103 | BTA_DM_API_BLE_SET_ADV_CONFIG_EVT, |
104 | + BTA_DM_API_BLE_SET_SCAN_RSP_EVT, | |
105 | + BTA_DM_API_BLE_BROADCAST_EVT, | |
104 | 106 | #endif |
105 | 107 | |
106 | 108 | #if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&( BTA_EIR_CANNED_UUID_LIST != TRUE )&&(BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0) |
@@ -996,6 +998,8 @@ extern void bta_dm_close_gatt_conn(tBTA_DM_MSG *p_data); | ||
996 | 998 | extern void bta_dm_ble_observe (tBTA_DM_MSG *p_data); |
997 | 999 | extern void bta_dm_ble_set_adv_params (tBTA_DM_MSG *p_data); |
998 | 1000 | extern void bta_dm_ble_set_adv_config (tBTA_DM_MSG *p_data); |
1001 | +extern void bta_dm_ble_set_scan_rsp (tBTA_DM_MSG *p_data); | |
1002 | +extern void bta_dm_ble_broadcast (tBTA_DM_MSG *p_data); | |
999 | 1003 | |
1000 | 1004 | #endif |
1001 | 1005 | extern void bta_dm_set_encryption(tBTA_DM_MSG *p_data); |
@@ -98,6 +98,8 @@ const tBTA_DM_ACTION bta_dm_action[] = | ||
98 | 98 | bta_dm_ble_observe, |
99 | 99 | bta_dm_ble_set_adv_params, /* BTA_DM_API_BLE_SCAN_PARAM_EVT */ |
100 | 100 | bta_dm_ble_set_adv_config, /* BTA_DM_API_BLE_SET_ADV_CONFIG_EVT */ |
101 | + bta_dm_ble_set_scan_rsp, /* BTA_DM_API_BLE_SET_SCAN_RSP_EVT */ | |
102 | + bta_dm_ble_broadcast, /* BTA_DM_API_BLE_BROADCAST_EVT */ | |
101 | 103 | #endif |
102 | 104 | |
103 | 105 | #if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&( BTA_EIR_CANNED_UUID_LIST != TRUE )&&(BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0) |
@@ -52,13 +52,16 @@ static void bta_gattc_cmpl_cback(UINT16 conn_id, tGATTC_OPTYPE op, tGATT_STATUS | ||
52 | 52 | |
53 | 53 | static void bta_gattc_deregister_cmpl(tBTA_GATTC_RCB *p_clreg); |
54 | 54 | |
55 | +static void bta_gattc_enc_cmpl_cback(tGATT_IF gattc_if, BD_ADDR bda); | |
56 | + | |
55 | 57 | static tGATT_CBACK bta_gattc_cl_cback = |
56 | 58 | { |
57 | 59 | bta_gattc_conn_cback, |
58 | 60 | bta_gattc_cmpl_cback, |
59 | 61 | bta_gattc_disc_res_cback, |
60 | 62 | bta_gattc_disc_cmpl_cback, |
61 | - NULL | |
63 | + NULL, | |
64 | + bta_gattc_enc_cmpl_cback | |
62 | 65 | }; |
63 | 66 | |
64 | 67 | /* opcode(tGATTC_OPTYPE) order has to be comply with internal event order */ |
@@ -399,6 +402,34 @@ void bta_gattc_process_api_open_cancel (tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p | ||
399 | 402 | |
400 | 403 | } |
401 | 404 | } |
405 | + | |
406 | +/******************************************************************************* | |
407 | +** | |
408 | +** Function bta_gattc_process_enc_cmpl | |
409 | +** | |
410 | +** Description process encryption complete message. | |
411 | +** | |
412 | +** Returns void | |
413 | +** | |
414 | +*******************************************************************************/ | |
415 | +void bta_gattc_process_enc_cmpl(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg) | |
416 | +{ | |
417 | + tBTA_GATTC_RCB *p_clreg; | |
418 | + tBTA_GATTC cb_data; | |
419 | + | |
420 | + p_clreg = bta_gattc_cl_get_regcb(p_msg->enc_cmpl.client_if); | |
421 | + | |
422 | + if (p_clreg && p_clreg->p_cback) | |
423 | + { | |
424 | + memset(&cb_data, 0, sizeof(tBTA_GATTC)); | |
425 | + | |
426 | + cb_data.enc_cmpl.client_if = p_msg->enc_cmpl.client_if; | |
427 | + bdcpy(cb_data.enc_cmpl.remote_bda, p_msg->enc_cmpl.remote_bda); | |
428 | + | |
429 | + (*p_clreg->p_cback)(BTA_GATTC_ENC_CMPL_CB_EVT, &cb_data); | |
430 | + } | |
431 | +} | |
432 | + | |
402 | 433 | /******************************************************************************* |
403 | 434 | ** |
404 | 435 | ** Function bta_gattc_cancel_open_error |
@@ -1635,6 +1666,50 @@ static void bta_gattc_conn_cback(tGATT_IF gattc_if, BD_ADDR bda, UINT16 conn_id, | ||
1635 | 1666 | |
1636 | 1667 | /******************************************************************************* |
1637 | 1668 | ** |
1669 | +** Function bta_gattc_enc_cmpl_cback | |
1670 | +** | |
1671 | +** Description encryption complete callback function to GATT client stack. | |
1672 | +** | |
1673 | +** Returns void | |
1674 | +** | |
1675 | +*******************************************************************************/ | |
1676 | +static void bta_gattc_enc_cmpl_cback(tGATT_IF gattc_if, BD_ADDR bda) | |
1677 | +{ | |
1678 | + tBTA_GATTC_DATA *p_buf; | |
1679 | + tBTA_GATTC_CLCB *p_clcb = NULL; | |
1680 | + | |
1681 | + if ((p_clcb = bta_gattc_find_clcb_by_cif(gattc_if, bda)) == NULL) | |
1682 | + { | |
1683 | + return; | |
1684 | + } | |
1685 | + | |
1686 | +#if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE) | |
1687 | + /* filter this event just for BTA HH LE GATT client, | |
1688 | + In the future, if we want to enable encryption complete event | |
1689 | + for all GATT clients, we can remove this code */ | |
1690 | + if (!bta_hh_le_is_hh_gatt_if(gattc_if)) | |
1691 | + { | |
1692 | + return; | |
1693 | + } | |
1694 | +#endif | |
1695 | + | |
1696 | + APPL_TRACE_DEBUG1("bta_gattc_enc_cmpl_cback: cif = %d", gattc_if); | |
1697 | + | |
1698 | + if ((p_buf = (tBTA_GATTC_DATA *) GKI_getbuf(sizeof(tBTA_GATTC_DATA))) != NULL) | |
1699 | + { | |
1700 | + memset(p_buf, 0, sizeof(tBTA_GATTC_DATA)); | |
1701 | + | |
1702 | + p_buf->enc_cmpl.hdr.event = BTA_GATTC_ENC_CMPL_EVT; | |
1703 | + p_buf->enc_cmpl.hdr.layer_specific = p_clcb->bta_conn_id; | |
1704 | + p_buf->enc_cmpl.client_if = gattc_if; | |
1705 | + bdcpy(p_buf->enc_cmpl.remote_bda, bda); | |
1706 | + | |
1707 | + bta_sys_sendmsg(p_buf); | |
1708 | + } | |
1709 | +} | |
1710 | + | |
1711 | +/******************************************************************************* | |
1712 | +** | |
1638 | 1713 | ** Function bta_gattc_process_api_refresh |
1639 | 1714 | ** |
1640 | 1715 | ** Description process refresh API to delete cache and start a new discovery |
@@ -2053,5 +2128,27 @@ void bta_gattc_listen(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg) | ||
2053 | 2128 | } |
2054 | 2129 | } |
2055 | 2130 | } |
2131 | + | |
2132 | +/******************************************************************************* | |
2133 | +** | |
2134 | +** Function bta_gattc_broadcast | |
2135 | +** | |
2136 | +** Description Start or stop broadcasting | |
2137 | +** | |
2138 | +** Returns void | |
2139 | +** | |
2140 | +********************************************************************************/ | |
2141 | +void bta_gattc_broadcast(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg) | |
2142 | +{ | |
2143 | + tBTA_GATTC_RCB *p_clreg = bta_gattc_cl_get_regcb(p_msg->api_listen.client_if); | |
2144 | + tBTA_GATTC cb_data; | |
2145 | + (void)(p_cb); | |
2146 | + | |
2147 | + cb_data.reg_oper.client_if = p_msg->api_listen.client_if; | |
2148 | + cb_data.reg_oper.status = BTM_BleBroadcast(p_msg->api_listen.start); | |
2149 | + | |
2150 | + if (p_clreg && p_clreg->p_cback) | |
2151 | + (*p_clreg->p_cback)(BTA_GATTC_LISTEN_EVT, &cb_data); | |
2152 | +} | |
2056 | 2153 | #endif |
2057 | 2154 | #endif |
@@ -1056,5 +1056,31 @@ void BTA_GATTC_Listen(tBTA_GATTC_IF client_if, BOOLEAN start, BD_ADDR_PTR target | ||
1056 | 1056 | return; |
1057 | 1057 | } |
1058 | 1058 | |
1059 | +/******************************************************************************* | |
1060 | +** | |
1061 | +** Function BTA_GATTC_Broadcast | |
1062 | +** | |
1063 | +** Description Start broadcasting (non-connectable advertisements) | |
1064 | +** | |
1065 | +** Parameters client_if: client interface. | |
1066 | +** start: to start or stop listening for connection | |
1067 | +** | |
1068 | +** Returns void | |
1069 | +** | |
1070 | +*******************************************************************************/ | |
1071 | +void BTA_GATTC_Broadcast(tBTA_GATTC_IF client_if, BOOLEAN start) | |
1072 | +{ | |
1073 | + tBTA_GATTC_API_LISTEN *p_buf; | |
1074 | + | |
1075 | + if ((p_buf = (tBTA_GATTC_API_LISTEN *) GKI_getbuf((UINT16)(sizeof(tBTA_GATTC_API_LISTEN) + BD_ADDR_LEN))) != NULL) | |
1076 | + { | |
1077 | + p_buf->hdr.event = BTA_GATTC_API_BROADCAST_EVT; | |
1078 | + p_buf->client_if = client_if; | |
1079 | + p_buf->start = start; | |
1080 | + bta_sys_sendmsg(p_buf); | |
1081 | + } | |
1082 | + return; | |
1083 | +} | |
1084 | + | |
1059 | 1085 | #endif /* BTA_GATT_INCLUDED */ |
1060 | 1086 |
@@ -69,7 +69,9 @@ enum | ||
69 | 69 | BTA_GATTC_API_REG_EVT, |
70 | 70 | BTA_GATTC_API_DEREG_EVT, |
71 | 71 | BTA_GATTC_API_LISTEN_EVT, |
72 | - BTA_GATTC_API_DISABLE_EVT | |
72 | + BTA_GATTC_API_BROADCAST_EVT, | |
73 | + BTA_GATTC_API_DISABLE_EVT, | |
74 | + BTA_GATTC_ENC_CMPL_EVT | |
73 | 75 | }; |
74 | 76 | typedef UINT16 tBTA_GATTC_INT_EVT; |
75 | 77 |
@@ -195,6 +197,13 @@ typedef struct | ||
195 | 197 | tGATT_DISCONN_REASON reason; |
196 | 198 | }tBTA_GATTC_INT_CONN; |
197 | 199 | |
200 | +typedef struct | |
201 | +{ | |
202 | + BT_HDR hdr; | |
203 | + BD_ADDR remote_bda; | |
204 | + tBTA_GATTC_IF client_if; | |
205 | +}tBTA_GATTC_ENC_CMPL; | |
206 | + | |
198 | 207 | typedef union |
199 | 208 | { |
200 | 209 | BT_HDR hdr; |
@@ -213,6 +222,7 @@ typedef union | ||
213 | 222 | tBTA_GATTC_CI_EVT ci_save; |
214 | 223 | tBTA_GATTC_CI_LOAD ci_load; |
215 | 224 | tBTA_GATTC_INT_CONN int_conn; |
225 | + tBTA_GATTC_ENC_CMPL enc_cmpl; | |
216 | 226 | |
217 | 227 | tBTA_GATTC_INT_START_IF int_start_if; |
218 | 228 | tBTA_GATTC_INT_DEREG int_dereg; |
@@ -433,6 +443,7 @@ extern void bta_gattc_start_if(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data); | ||
433 | 443 | extern void bta_gattc_process_api_open (tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg); |
434 | 444 | extern void bta_gattc_process_api_open_cancel (tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg); |
435 | 445 | extern void bta_gattc_deregister(tBTA_GATTC_CB *p_cb, tBTA_GATTC_RCB *p_clreg); |
446 | +extern void bta_gattc_process_enc_cmpl(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg); | |
436 | 447 | |
437 | 448 | /* function within state machine */ |
438 | 449 | extern void bta_gattc_open(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); |
@@ -474,6 +485,7 @@ extern void bta_gattc_send_open_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS | ||
474 | 485 | extern void bta_gattc_process_api_refresh(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg); |
475 | 486 | #if BLE_INCLUDED == TRUE |
476 | 487 | extern void bta_gattc_listen(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg); |
488 | +extern void bta_gattc_broadcast(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg); | |
477 | 489 | #endif |
478 | 490 | /* utility functions */ |
479 | 491 | extern tBTA_GATTC_CLCB * bta_gattc_find_clcb_by_cif (UINT8 client_if, BD_ADDR remote_bda); |
@@ -385,7 +385,15 @@ BOOLEAN bta_gattc_hdl_event(BT_HDR *p_msg) | ||
385 | 385 | case BTA_GATTC_API_LISTEN_EVT: |
386 | 386 | bta_gattc_listen(p_cb, (tBTA_GATTC_DATA *) p_msg); |
387 | 387 | break; |
388 | + case BTA_GATTC_API_BROADCAST_EVT: | |
389 | + bta_gattc_broadcast(p_cb, (tBTA_GATTC_DATA *) p_msg); | |
390 | + break; | |
388 | 391 | #endif |
392 | + | |
393 | + case BTA_GATTC_ENC_CMPL_EVT: | |
394 | + bta_gattc_process_enc_cmpl(p_cb, (tBTA_GATTC_DATA *) p_msg); | |
395 | + break; | |
396 | + | |
389 | 397 | default: |
390 | 398 | if (p_msg->event == BTA_GATTC_INT_CONN_EVT) |
391 | 399 | p_clcb = bta_gattc_find_int_conn_clcb((tBTA_GATTC_DATA *) p_msg); |
@@ -49,7 +49,8 @@ static tGATT_CBACK bta_gatts_cback = | ||
49 | 49 | NULL, |
50 | 50 | NULL, |
51 | 51 | NULL, |
52 | - bta_gatts_send_request_cback | |
52 | + bta_gatts_send_request_cback, | |
53 | + NULL | |
53 | 54 | }; |
54 | 55 | |
55 | 56 | tGATT_APPL_INFO bta_gatts_nv_cback = |
@@ -67,6 +67,7 @@ enum | ||
67 | 67 | BTA_HH_GATT_READ_DESCR_CMPL_EVT, |
68 | 68 | BTA_HH_GATT_WRITE_DESCR_CMPL_EVT, |
69 | 69 | BTA_HH_API_SCPP_UPDATE_EVT, |
70 | + BTA_HH_GATT_ENC_CMPL_EVT, | |
70 | 71 | #endif |
71 | 72 | |
72 | 73 | /* not handled by execute state machine */ |
@@ -182,6 +183,7 @@ typedef union | ||
182 | 183 | tBTA_HH_LE_CLOSE le_close; |
183 | 184 | tBTA_GATTC_OPEN le_open; |
184 | 185 | tBTA_HH_SCPP_UPDATE le_scpp_update; |
186 | + tBTA_GATTC_ENC_CMPL_CB le_enc_cmpl; | |
185 | 187 | #endif |
186 | 188 | } tBTA_HH_DATA; |
187 | 189 |
@@ -201,7 +203,7 @@ typedef struct | ||
201 | 203 | }tBTA_HH_LE_RPT; |
202 | 204 | |
203 | 205 | #ifndef BTA_HH_LE_RPT_MAX |
204 | -#define BTA_HH_LE_RPT_MAX 10 | |
206 | +#define BTA_HH_LE_RPT_MAX 20 | |
205 | 207 | #endif |
206 | 208 | |
207 | 209 | typedef struct |
@@ -283,6 +285,7 @@ typedef struct | ||
283 | 285 | UINT8 scps_notify; /* scan refresh supported/notification enabled */ |
284 | 286 | #endif |
285 | 287 | |
288 | + BOOLEAN security_pending; | |
286 | 289 | } tBTA_HH_DEV_CB; |
287 | 290 | |
288 | 291 | /* key board parsing control block */ |
@@ -404,7 +407,7 @@ extern void bta_hh_le_write_char_descr_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA * | ||
404 | 407 | extern void bta_hh_start_security(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_buf); |
405 | 408 | extern void bta_hh_security_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_buf); |
406 | 409 | extern void bta_hh_le_update_scpp(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_buf); |
407 | - | |
410 | +extern void bta_hh_le_notify_enc_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data); | |
408 | 411 | |
409 | 412 | #if BTA_HH_DEBUG |
410 | 413 | extern void bta_hh_trace_dev_db(void); |
@@ -28,6 +28,7 @@ | ||
28 | 28 | #include "bta_hh_co.h" |
29 | 29 | #include "bta_gatt_api.h" |
30 | 30 | #include "srvc_api.h" |
31 | +#include "btm_int.h" | |
31 | 32 | |
32 | 33 | #ifndef BTA_HH_LE_RECONN |
33 | 34 | #define BTA_HH_LE_RECONN TRUE |
@@ -37,7 +38,7 @@ | ||
37 | 38 | |
38 | 39 | #define BTA_HH_LE_RPT_TYPE_VALID(x) ((x) <= BTA_LE_HID_RPT_FEATURE && (x)>=BTA_LE_HID_RPT_INPUT) |
39 | 40 | |
40 | -#define BTA_HH_LE_RPT_INST_ID_MAP(s,c) (UINT8)(((s)<<4)||(c)) | |
41 | +#define BTA_HH_LE_RPT_INST_ID_MAP(s,c) (UINT8)(((s)<<4)|(c)) | |
41 | 42 | #define BTA_HH_LE_RPT_GET_SRVC_INST_ID(x) (UINT8)(x >> 4) |
42 | 43 | #define BTA_HH_LE_RPT_GET_RPT_INST_ID(x) (UINT8)(x & 0x0f) |
43 | 44 |
@@ -638,6 +639,8 @@ void bta_hh_le_read_rpt_ref_descr(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_LE_RPT *p_rp | ||
638 | 639 | |
639 | 640 | while (p_rpt != NULL) |
640 | 641 | { |
642 | + if (!p_rpt->in_use) break; | |
643 | + | |
641 | 644 | if (p_rpt->rpt_type == BTA_HH_RPTT_INPUT) |
642 | 645 | { |
643 | 646 | /* is battery report */ |
@@ -718,9 +721,10 @@ void bta_hh_le_save_rpt_ref(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_LE_RPT *p_rpt, | ||
718 | 721 | #endif |
719 | 722 | } |
720 | 723 | |
721 | - if (p_rpt->index < BTA_HH_LE_RPT_MAX) | |
724 | + if (p_rpt->index < BTA_HH_LE_RPT_MAX - 1) | |
722 | 725 | p_rpt ++; |
723 | - | |
726 | + else | |
727 | + p_rpt = NULL; | |
724 | 728 | /* read next report reference descriptor */ |
725 | 729 | bta_hh_le_read_rpt_ref_descr(p_dev_cb, p_rpt); |
726 | 730 |
@@ -1084,7 +1088,7 @@ void bta_hh_le_expl_rpt(tBTA_HH_DEV_CB *p_dev_cb, | ||
1084 | 1088 | p_char_id->char_id.inst_id, |
1085 | 1089 | prop) == NULL) |
1086 | 1090 | { |
1087 | - APPL_TRACE_ERROR0("Add report entry failed !!!") | |
1091 | + APPL_TRACE_ERROR0("Add report entry failed !!!"); | |
1088 | 1092 | break; |
1089 | 1093 | } |
1090 | 1094 |
@@ -1125,7 +1129,7 @@ void bta_hh_le_expl_boot_rpt(tBTA_HH_DEV_CB *p_dev_cb, UINT16 char_uuid, | ||
1125 | 1129 | prop) == NULL) |
1126 | 1130 | |
1127 | 1131 | { |
1128 | - APPL_TRACE_ERROR0("Add report entry failed !!!") | |
1132 | + APPL_TRACE_ERROR0("Add report entry failed !!!"); | |
1129 | 1133 | } |
1130 | 1134 | |
1131 | 1135 | return; |
@@ -1257,6 +1261,28 @@ void bta_hh_security_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_buf) | ||
1257 | 1261 | bta_hh_le_api_disc_act(p_cb); |
1258 | 1262 | |
1259 | 1263 | } |
1264 | + | |
1265 | +/******************************************************************************* | |
1266 | +** | |
1267 | +** Function bta_hh_le_notify_enc_cmpl | |
1268 | +** | |
1269 | +** Description process GATT encryption complete event | |
1270 | +** | |
1271 | +** Returns | |
1272 | +** | |
1273 | +*******************************************************************************/ | |
1274 | +void bta_hh_le_notify_enc_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_buf) | |
1275 | +{ | |
1276 | + if (p_cb == NULL || p_cb->security_pending == FALSE || | |
1277 | + p_buf == NULL || p_buf->le_enc_cmpl.client_if != bta_hh_cb.gatt_if) | |
1278 | + { | |
1279 | + return; | |
1280 | + } | |
1281 | + | |
1282 | + p_cb->security_pending = FALSE; | |
1283 | + bta_hh_start_security(p_cb, NULL); | |
1284 | +} | |
1285 | + | |
1260 | 1286 | /******************************************************************************* |
1261 | 1287 | ** |
1262 | 1288 | ** Function bta_hh_start_security |
@@ -1269,6 +1295,19 @@ void bta_hh_security_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_buf) | ||
1269 | 1295 | void bta_hh_start_security(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_buf) |
1270 | 1296 | { |
1271 | 1297 | UINT8 sec_flag=0; |
1298 | + tBTM_SEC_DEV_REC *p_dev_rec; | |
1299 | + | |
1300 | + p_dev_rec = btm_find_dev(p_cb->addr); | |
1301 | + if (p_dev_rec) | |
1302 | + { | |
1303 | + if (p_dev_rec->sec_state == BTM_SEC_STATE_ENCRYPTING || | |
1304 | + p_dev_rec->sec_state == BTM_SEC_STATE_AUTHENTICATING) | |
1305 | + { | |
1306 | + /* if security collision happened, wait for encryption done */ | |
1307 | + p_cb->security_pending = TRUE; | |
1308 | + return; | |
1309 | + } | |
1310 | + } | |
1272 | 1311 | |
1273 | 1312 | /* verify bond */ |
1274 | 1313 | BTM_GetSecurityFlags(p_cb->addr, &sec_flag); |
@@ -1372,7 +1411,7 @@ void bta_hh_le_close(tBTA_GATTC_CLOSE * p_data) | ||
1372 | 1411 | p_buf->reason = p_data->reason; |
1373 | 1412 | |
1374 | 1413 | p_dev_cb->conn_id = BTA_GATT_INVALID_CONN_ID; |
1375 | - | |
1414 | + p_dev_cb->security_pending = FALSE; | |
1376 | 1415 | bta_sys_sendmsg(p_buf); |
1377 | 1416 | } |
1378 | 1417 | } |
@@ -2593,6 +2632,8 @@ static void bta_hh_le_add_dev_bg_conn(tBTA_HH_DEV_CB *p_cb, BOOLEAN check_bond) | ||
2593 | 2632 | *******************************************************************************/ |
2594 | 2633 | UINT8 bta_hh_le_add_device(tBTA_HH_DEV_CB *p_cb, tBTA_HH_MAINT_DEV *p_dev_info) |
2595 | 2634 | { |
2635 | + p_cb->hid_handle = BTA_HH_GET_LE_DEV_HDL(p_cb->index); | |
2636 | + bta_hh_cb.le_cb_index[BTA_HH_GET_LE_CB_IDX(p_cb->hid_handle)] = p_cb->index; | |
2596 | 2637 | |
2597 | 2638 | /* update DI information */ |
2598 | 2639 | bta_hh_update_di_info(p_cb, |
@@ -2709,7 +2750,9 @@ static void bta_hh_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) | ||
2709 | 2750 | |
2710 | 2751 | case BTA_GATTC_OPEN_EVT: /* 2 */ |
2711 | 2752 | p_dev_cb = bta_hh_le_find_dev_cb_by_bda(p_data->open.remote_bda); |
2712 | - bta_hh_sm_execute(p_dev_cb, BTA_HH_GATT_OPEN_EVT, (tBTA_HH_DATA *)&p_data->open); | |
2753 | + if (p_dev_cb) { | |
2754 | + bta_hh_sm_execute(p_dev_cb, BTA_HH_GATT_OPEN_EVT, (tBTA_HH_DATA *)&p_data->open); | |
2755 | + } | |
2713 | 2756 | break; |
2714 | 2757 | |
2715 | 2758 | case BTA_GATTC_READ_CHAR_EVT: /* 3 */ |
@@ -2751,6 +2794,15 @@ static void bta_hh_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) | ||
2751 | 2794 | case BTA_GATTC_NOTIF_EVT: /* 10 */ |
2752 | 2795 | bta_hh_le_input_rpt_notify(&p_data->notify); |
2753 | 2796 | break; |
2797 | + | |
2798 | + case BTA_GATTC_ENC_CMPL_CB_EVT: /* 17 */ | |
2799 | + p_dev_cb = bta_hh_le_find_dev_cb_by_bda(p_data->enc_cmpl.remote_bda); | |
2800 | + if (p_dev_cb) { | |
2801 | + bta_hh_sm_execute(p_dev_cb, BTA_HH_GATT_ENC_CMPL_EVT, | |
2802 | + (tBTA_HH_DATA *)&p_data->enc_cmpl); | |
2803 | + } | |
2804 | + break; | |
2805 | + | |
2754 | 2806 | default: |
2755 | 2807 | break; |
2756 | 2808 | } |
@@ -66,7 +66,7 @@ enum | ||
66 | 66 | BTA_HH_START_SEC, |
67 | 67 | BTA_HH_SEC_CMPL, |
68 | 68 | BTA_HH_LE_UPDATE_SCPP, |
69 | - | |
69 | + BTA_HH_GATT_ENC_CMPL, | |
70 | 70 | #endif |
71 | 71 | BTA_HH_NUM_ACTIONS |
72 | 72 | }; |
@@ -106,6 +106,7 @@ const tBTA_HH_ACTION bta_hh_action[] = | ||
106 | 106 | ,bta_hh_start_security |
107 | 107 | ,bta_hh_security_cmpl |
108 | 108 | ,bta_hh_le_update_scpp |
109 | + ,bta_hh_le_notify_enc_cmpl | |
109 | 110 | #endif |
110 | 111 | }; |
111 | 112 |
@@ -140,6 +141,7 @@ const UINT8 bta_hh_st_idle[][BTA_HH_NUM_COLS] = | ||
140 | 141 | /* READ_DESCR_CMPL_EVT */ ,{BTA_HH_IGNORE, BTA_HH_IDLE_ST } |
141 | 142 | /* WRITE_DESCR_CMPL_EVT */ ,{BTA_HH_IGNORE, BTA_HH_IDLE_ST } |
142 | 143 | /* SCPP_UPDATE_EVT */ ,{BTA_HH_IGNORE, BTA_HH_IDLE_ST } |
144 | +/* BTA_HH_GATT_ENC_CMPL_EVT */ ,{BTA_HH_IGNORE, BTA_HH_IDLE_ST } | |
143 | 145 | #endif |
144 | 146 | |
145 | 147 | }; |
@@ -170,6 +172,7 @@ const UINT8 bta_hh_st_w4_conn[][BTA_HH_NUM_COLS] = | ||
170 | 172 | /* READ_DESCR_CMPL_EVT */ ,{BTA_HH_W4_LE_READ_DESCR, BTA_HH_W4_CONN_ST } |
171 | 173 | /* WRITE_DESCR_CMPL_EVT */ ,{BTA_HH_WRITE_DESCR, BTA_HH_W4_CONN_ST } |
172 | 174 | /* SCPP_UPDATE_EVT */ ,{BTA_HH_IGNORE, BTA_HH_W4_CONN_ST } |
175 | +/* BTA_HH_GATT_ENC_CMPL_EVT */ ,{BTA_HH_IGNORE, BTA_HH_W4_CONN_ST } | |
173 | 176 | #endif |
174 | 177 | }; |
175 | 178 |
@@ -199,6 +202,7 @@ const UINT8 bta_hh_st_connected[][BTA_HH_NUM_COLS] = | ||
199 | 202 | /* READ_DESCR_CMPL_EVT */ ,{BTA_HH_LE_READ_DESCR, BTA_HH_CONN_ST } /* do not currently read any descr when connection up */ |
200 | 203 | /* WRITE_DESCR_CMPL_EVT */ ,{BTA_HH_WRITE_DESCR, BTA_HH_CONN_ST } /* do not currently write any descr when connection up */ |
201 | 204 | /* SCPP_UPDATE_EVT */ ,{BTA_HH_LE_UPDATE_SCPP, BTA_HH_CONN_ST } |
205 | +/* BTA_HH_GATT_ENC_CMPL_EVT */ ,{BTA_HH_IGNORE, BTA_HH_CONN_ST } | |
202 | 206 | #endif |
203 | 207 | }; |
204 | 208 | #if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE) |
@@ -226,6 +230,7 @@ const UINT8 bta_hh_st_w4_sec[][BTA_HH_NUM_COLS] = | ||
226 | 230 | /* READ_DESCR_CMPL_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC }, |
227 | 231 | /* WRITE_DESCR_CMPL_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC } |
228 | 232 | /* SCPP_UPDATE_EVT */ ,{BTA_HH_IGNORE, BTA_HH_W4_SEC } |
233 | +/* BTA_HH_GATT_ENC_CMPL_EVT */ ,{BTA_HH_GATT_ENC_CMPL, BTA_HH_W4_SEC } | |
229 | 234 | }; |
230 | 235 | #endif |
231 | 236 |
@@ -1884,7 +1884,7 @@ BTA_API extern void BTA_DmBleObserve(BOOLEAN start, UINT8 duration, | ||
1884 | 1884 | *******************************************************************************/ |
1885 | 1885 | BTA_API extern void BTA_DmSetAfhChannelAssessment (BOOLEAN enable_or_disable); |
1886 | 1886 | |
1887 | -#if BLE_INCLUDE == TRUE | |
1887 | +#if BLE_INCLUDED == TRUE | |
1888 | 1888 | // btla-specific -- |
1889 | 1889 | /******************************************************************************* |
1890 | 1890 | ** |
@@ -1927,6 +1927,34 @@ BTA_API extern void BTA_DmBleEnableRemotePrivacy(BD_ADDR bd_addr, BOOLEAN privac | ||
1927 | 1927 | *******************************************************************************/ |
1928 | 1928 | BTA_API extern void BTA_DmBleSetAdvConfig (tBTA_BLE_AD_MASK data_mask, |
1929 | 1929 | tBTA_BLE_ADV_DATA *p_adv_cfg); |
1930 | + | |
1931 | +/******************************************************************************* | |
1932 | +** | |
1933 | +** Function BTA_DmBleSetScanRsp | |
1934 | +** | |
1935 | +** Description This function is called to override the BTA scan response. | |
1936 | +** | |
1937 | +** Parameters Pointer to User defined ADV data structure | |
1938 | +** | |
1939 | +** Returns None | |
1940 | +** | |
1941 | +*******************************************************************************/ | |
1942 | +BTA_API extern void BTA_DmBleSetScanRsp (tBTA_BLE_AD_MASK data_mask, | |
1943 | + tBTA_BLE_ADV_DATA *p_adv_cfg); | |
1944 | + | |
1945 | +/******************************************************************************* | |
1946 | +** | |
1947 | +** Function BTA_DmBleBroadcast | |
1948 | +** | |
1949 | +** Description This function starts or stops LE broadcasting. | |
1950 | +** | |
1951 | +** Parameters start: start or stop broadcast. | |
1952 | +** | |
1953 | +** Returns None | |
1954 | +** | |
1955 | +*******************************************************************************/ | |
1956 | +BTA_API extern void BTA_DmBleBroadcast (BOOLEAN start); | |
1957 | + | |
1930 | 1958 | #endif |
1931 | 1959 | |
1932 | 1960 | #ifdef __cplusplus |
@@ -115,6 +115,7 @@ typedef UINT8 tBTA_GATT_STATUS; | ||
115 | 115 | #define BTA_GATTC_CANCEL_OPEN_EVT 14 /* cancel open event */ |
116 | 116 | #define BTA_GATTC_SRVC_CHG_EVT 15 /* service change event */ |
117 | 117 | #define BTA_GATTC_LISTEN_EVT 16 /* listen event */ |
118 | +#define BTA_GATTC_ENC_CMPL_CB_EVT 17 /* encryption complete callback event */ | |
118 | 119 | |
119 | 120 | typedef UINT8 tBTA_GATTC_EVT; |
120 | 121 |
@@ -349,6 +350,12 @@ typedef struct | ||
349 | 350 | }tBTA_GATTC_OPEN_CLOSE; |
350 | 351 | // btla-specific -- |
351 | 352 | |
353 | +typedef struct | |
354 | +{ | |
355 | + tBTA_GATTC_IF client_if; | |
356 | + BD_ADDR remote_bda; | |
357 | +}tBTA_GATTC_ENC_CMPL_CB; | |
358 | + | |
352 | 359 | typedef union |
353 | 360 | { |
354 | 361 | tBTA_GATT_STATUS status; |
@@ -362,6 +369,7 @@ typedef union | ||
362 | 369 | tBTA_GATTC_WRITE write; /* write complete data */ |
363 | 370 | tBTA_GATTC_EXEC_CMPL exec_cmpl; /* execute complete */ |
364 | 371 | tBTA_GATTC_NOTIFY notify; /* notification/indication event data */ |
372 | + tBTA_GATTC_ENC_CMPL_CB enc_cmpl; | |
365 | 373 | BD_ADDR remote_bda; /* service change event */ |
366 | 374 | } tBTA_GATTC; |
367 | 375 |
@@ -1023,6 +1031,21 @@ BTA_API extern void BTA_GATTC_Refresh(BD_ADDR remote_bda); | ||
1023 | 1031 | BTA_API extern void BTA_GATTC_Listen(tBTA_GATTC_IF client_if, BOOLEAN start, BD_ADDR_PTR target_bda); |
1024 | 1032 | |
1025 | 1033 | /******************************************************************************* |
1034 | +** | |
1035 | +** Function BTA_GATTC_Broadcast | |
1036 | +** | |
1037 | +** Description Start broadcasting (non-connectable advertisements) | |
1038 | +** | |
1039 | +** Parameters client_if: client interface. | |
1040 | +** start: to start or stop listening for connection | |
1041 | +** | |
1042 | +** Returns void | |
1043 | +** | |
1044 | +*******************************************************************************/ | |
1045 | +BTA_API extern void BTA_GATTC_Broadcast(tBTA_GATTC_IF client_if, BOOLEAN start); | |
1046 | + | |
1047 | + | |
1048 | +/******************************************************************************* | |
1026 | 1049 | ** BTA GATT Server API |
1027 | 1050 | ********************************************************************************/ |
1028 | 1051 |
@@ -30,6 +30,7 @@ | ||
30 | 30 | #define BTIF_STORAGE_FILL_PROPERTY(p_prop, t, l, p_v) \ |
31 | 31 | (p_prop)->type = t;(p_prop)->len = l; (p_prop)->val = (p_v); |
32 | 32 | |
33 | +#define BTIF_STORAGE_MAX_ALLOWED_REMOTE_DEVICE 512 | |
33 | 34 | |
34 | 35 | /******************************************************************************* |
35 | 36 | ** Functions |
@@ -155,7 +155,6 @@ static void cleanup( void ) | ||
155 | 155 | return; |
156 | 156 | |
157 | 157 | btif_shutdown_bluetooth(); |
158 | - bt_utils_cleanup(); | |
159 | 158 | |
160 | 159 | /* hal callbacks reset upon shutdown complete callback */ |
161 | 160 |
@@ -37,6 +37,7 @@ | ||
37 | 37 | |
38 | 38 | #define LOG_TAG "BTIF_CORE" |
39 | 39 | #include "btif_api.h" |
40 | +#include "bt_utils.h" | |
40 | 41 | #include "bta_api.h" |
41 | 42 | #include "gki.h" |
42 | 43 | #include "btu.h" |
@@ -737,6 +738,14 @@ bt_status_t btif_shutdown_bluetooth(void) | ||
737 | 738 | { |
738 | 739 | BTIF_TRACE_DEBUG1("%s", __FUNCTION__); |
739 | 740 | |
741 | + if (btif_core_state == BTIF_CORE_STATE_DISABLING) | |
742 | + { | |
743 | + BTIF_TRACE_WARNING0("shutdown during disabling"); | |
744 | + /* shutdown called before disabling is done */ | |
745 | + btif_shutdown_pending = 1; | |
746 | + return BT_STATUS_NOT_READY; | |
747 | + } | |
748 | + | |
740 | 749 | if (btif_is_enabled()) |
741 | 750 | { |
742 | 751 | BTIF_TRACE_WARNING0("shutdown while still enabled, initiate disable"); |
@@ -765,6 +774,8 @@ bt_status_t btif_shutdown_bluetooth(void) | ||
765 | 774 | |
766 | 775 | btif_dut_mode = 0; |
767 | 776 | |
777 | + bt_utils_cleanup(); | |
778 | + | |
768 | 779 | BTIF_TRACE_DEBUG1("%s done", __FUNCTION__); |
769 | 780 | |
770 | 781 | return BT_STATUS_SUCCESS; |
@@ -104,8 +104,8 @@ typedef enum { | ||
104 | 104 | |
105 | 105 | typedef struct |
106 | 106 | { |
107 | - tBTM_BLE_AD_MASK mask; | |
108 | - tBTM_BLE_ADV_DATA data; | |
107 | + tBTA_BLE_AD_MASK mask; | |
108 | + tBTA_BLE_ADV_DATA data; | |
109 | 109 | } btgatt_adv_data; |
110 | 110 | |
111 | 111 | typedef struct |
@@ -463,10 +463,31 @@ static void btif_gattc_upstreams_evt(uint16_t event, char* p_param) | ||
463 | 463 | case BTIF_GATT_OBSERVE_EVT: |
464 | 464 | { |
465 | 465 | btif_gattc_cb_t *p_btif_cb = (btif_gattc_cb_t*)p_param; |
466 | - if (!btif_gattc_find_bdaddr(p_btif_cb->bd_addr.address)) | |
466 | + uint8_t remote_name_len; | |
467 | + uint8_t *p_eir_remote_name=NULL; | |
468 | + | |
469 | + p_eir_remote_name = BTA_CheckEirData(p_btif_cb->value, | |
470 | + BTM_EIR_COMPLETE_LOCAL_NAME_TYPE, &remote_name_len); | |
471 | + | |
472 | + if(p_eir_remote_name == NULL) | |
473 | + { | |
474 | + p_eir_remote_name = BTA_CheckEirData(p_btif_cb->value, | |
475 | + BT_EIR_SHORTENED_LOCAL_NAME_TYPE, &remote_name_len); | |
476 | + } | |
477 | + | |
478 | + if ((p_btif_cb->addr_type != BLE_ADDR_RANDOM) || (p_eir_remote_name)) | |
467 | 479 | { |
468 | - btif_gattc_add_remote_bdaddr(p_btif_cb->bd_addr.address, p_btif_cb->addr_type); | |
469 | - btif_gattc_update_properties(p_btif_cb); | |
480 | + if (!btif_gattc_find_bdaddr(p_btif_cb->bd_addr.address)) | |
481 | + { | |
482 | + static const char* exclude_filter[] = | |
483 | + {"LinkKey", "LE_KEY_PENC", "LE_KEY_PID", "LE_KEY_PCSRK", "LE_KEY_LENC", "LE_KEY_LCSRK"}; | |
484 | + | |
485 | + btif_gattc_add_remote_bdaddr(p_btif_cb->bd_addr.address, p_btif_cb->addr_type); | |
486 | + btif_gattc_update_properties(p_btif_cb); | |
487 | + btif_config_filter_remove("Remote", exclude_filter, sizeof(exclude_filter)/sizeof(char*), | |
488 | + BTIF_STORAGE_MAX_ALLOWED_REMOTE_DEVICE); | |
489 | + } | |
490 | + | |
470 | 491 | } |
471 | 492 | HAL_CBACK(bt_gatt_callbacks, client->scan_result_cb, |
472 | 493 | &p_btif_cb->bd_addr, p_btif_cb->rssi, p_btif_cb->value); |
@@ -819,17 +840,46 @@ static void btgattc_handle_event(uint16_t event, char* p_param) | ||
819 | 840 | break; |
820 | 841 | |
821 | 842 | case BTIF_GATTC_LISTEN: |
843 | +#ifdef BLE_PERIPHERAL_MODE_SUPPORT | |
822 | 844 | BTA_GATTC_Listen(p_cb->client_if, p_cb->start, NULL); |
845 | +#else | |
846 | + BTA_GATTC_Broadcast(p_cb->client_if, p_cb->start); | |
847 | +#endif | |
823 | 848 | break; |
824 | 849 | |
825 | 850 | case BTIF_GATTC_SET_ADV_DATA: |
826 | 851 | { |
827 | 852 | if (p_cb->start == 0) |
828 | - BTM_BleWriteAdvData(p_cb->adv_data.mask, &p_cb->adv_data.data); | |
853 | + BTA_DmBleSetAdvConfig(p_cb->adv_data.mask, &p_cb->adv_data.data); | |
829 | 854 | else |
830 | - BTM_BleWriteScanRsp(p_cb->adv_data.mask, &p_cb->adv_data.data); | |
855 | + BTA_DmBleSetScanRsp(p_cb->adv_data.mask, &p_cb->adv_data.data); | |
856 | + | |
857 | + // Cleanup ... | |
858 | + | |
859 | + // ... manufacturer data | |
831 | 860 | if (p_cb->adv_data.data.manu.p_val != NULL) |
832 | 861 | GKI_freebuf(p_cb->adv_data.data.manu.p_val); |
862 | + | |
863 | + // ... service data | |
864 | + if (p_cb->adv_data.data.p_proprietary != NULL) | |
865 | + { | |
866 | + int i = 0; | |
867 | + tBTA_BLE_PROP_ELEM *p_elem = p_cb->adv_data.data.p_proprietary->p_elem; | |
868 | + while (i++ != p_cb->adv_data.data.p_proprietary->num_elem && p_elem) | |
869 | + { | |
870 | + if (p_elem->p_val != NULL) | |
871 | + GKI_freebuf(p_elem->p_val); | |
872 | + ++p_elem; | |
873 | + } | |
874 | + if (p_cb->adv_data.data.p_proprietary->p_elem != NULL) | |
875 | + GKI_freebuf(p_cb->adv_data.data.p_proprietary->p_elem); | |
876 | + GKI_freebuf(p_cb->adv_data.data.p_proprietary); | |
877 | + } | |
878 | + | |
879 | + // ... service list | |
880 | + if (p_cb->adv_data.data.services.p_uuid != NULL) | |
881 | + GKI_freebuf(p_cb->adv_data.data.services.p_uuid); | |
882 | + | |
833 | 883 | break; |
834 | 884 | } |
835 | 885 |
@@ -904,7 +954,9 @@ static bt_status_t btif_gattc_listen(int client_if, bool start) | ||
904 | 954 | |
905 | 955 | static bt_status_t btif_gattc_set_adv_data(int client_if, bool set_scan_rsp, bool include_name, |
906 | 956 | bool include_txpower, int min_interval, int max_interval, int appearance, |
907 | - uint16_t manufacturer_len, char* manufacturer_data) | |
957 | + uint16_t manufacturer_len, char* manufacturer_data, | |
958 | + uint16_t service_data_len, char* service_data, | |
959 | + uint16_t service_uuid_len, char* service_uuid) | |
908 | 960 | { |
909 | 961 | CHECK_BTGATT_INIT(); |
910 | 962 | btif_gattc_cb_t btif_cb; |
@@ -950,6 +1002,112 @@ static bt_status_t btif_gattc_set_adv_data(int client_if, bool set_scan_rsp, boo | ||
950 | 1002 | } |
951 | 1003 | } |
952 | 1004 | |
1005 | + tBTA_BLE_PROP_ELEM *p_elem_service_data = NULL; | |
1006 | + tBTA_BLE_PROP_ELEM *p_elem_service_128 = NULL; | |
1007 | + | |
1008 | + if (service_data_len > 0 && service_data != NULL) | |
1009 | + { | |
1010 | + p_elem_service_data = GKI_getbuf(sizeof(tBTA_BLE_PROP_ELEM)); | |
1011 | + if (p_elem_service_data != NULL) | |
1012 | + { | |
1013 | + p_elem_service_data->p_val = GKI_getbuf(service_data_len); | |
1014 | + if (p_elem_service_data->p_val != NULL) | |
1015 | + { | |
1016 | + p_elem_service_data->adv_type = BTM_BLE_AD_TYPE_SERVICE_DATA; | |
1017 | + p_elem_service_data->len = service_data_len; | |
1018 | + memcpy(p_elem_service_data->p_val, service_data, service_data_len); | |
1019 | + | |
1020 | + } else { | |
1021 | + GKI_freebuf(p_elem_service_data); | |
1022 | + p_elem_service_data = NULL; | |
1023 | + } | |
1024 | + } | |
1025 | + } | |
1026 | + | |
1027 | + if (service_uuid_len > 0 && service_uuid != NULL) | |
1028 | + { | |
1029 | + btif_cb.adv_data.data.services.list_cmpl = FALSE; | |
1030 | + btif_cb.adv_data.data.services.num_service = 0; | |
1031 | + | |
1032 | + btif_cb.adv_data.data.services.p_uuid = | |
1033 | + GKI_getbuf(service_uuid_len / LEN_UUID_128 * LEN_UUID_16); | |
1034 | + if (btif_cb.adv_data.data.services.p_uuid != NULL) | |
1035 | + { | |
1036 | + UINT16 *p_uuid_out = btif_cb.adv_data.data.services.p_uuid; | |
1037 | + while (service_uuid_len >= LEN_UUID_128) | |
1038 | + { | |
1039 | + bt_uuid_t uuid; | |
1040 | + memset(&uuid, 0, sizeof(bt_uuid_t)); | |
1041 | + memcpy(&uuid.uu, service_uuid, LEN_UUID_128); | |
1042 | + | |
1043 | + tBT_UUID bt_uuid; | |
1044 | + memset(&bt_uuid, 0, sizeof(tBT_UUID)); | |
1045 | + btif_to_bta_uuid(&bt_uuid, &uuid); | |
1046 | + | |
1047 | + if (bt_uuid.len == LEN_UUID_16) | |
1048 | + { | |
1049 | + btif_cb.adv_data.mask |= BTM_BLE_AD_BIT_SERVICE; | |
1050 | + ++btif_cb.adv_data.data.services.num_service; | |
1051 | + *p_uuid_out++ = bt_uuid.uu.uuid16; | |
1052 | + | |
1053 | + } else if (bt_uuid.len == LEN_UUID_128 && p_elem_service_128 == NULL) { | |
1054 | + /* Currently, only one 128-bit UUID is supported */ | |
1055 | + p_elem_service_128 = GKI_getbuf(sizeof(tBTA_BLE_PROP_ELEM)); | |
1056 | + if (p_elem_service_128 != NULL) | |
1057 | + { | |
1058 | + p_elem_service_128->p_val = GKI_getbuf(LEN_UUID_128); | |
1059 | + if (p_elem_service_128->p_val != NULL) | |
1060 | + { | |
1061 | + p_elem_service_128->adv_type = BTM_BLE_AD_TYPE_128SRV_PART; | |
1062 | + p_elem_service_128->len = LEN_UUID_128; | |
1063 | + memcpy(p_elem_service_128->p_val, bt_uuid.uu.uuid128, LEN_UUID_128); | |
1064 | + | |
1065 | + } else { | |
1066 | + GKI_freebuf(p_elem_service_128); | |
1067 | + p_elem_service_128 = NULL; | |
1068 | + } | |
1069 | + } | |
1070 | + } | |
1071 | + | |
1072 | + service_uuid += LEN_UUID_128; | |
1073 | + service_uuid_len -= LEN_UUID_128; | |
1074 | + } | |
1075 | + } | |
1076 | + } | |
1077 | + | |
1078 | + if (p_elem_service_data != NULL || p_elem_service_128 != NULL) | |
1079 | + { | |
1080 | + btif_cb.adv_data.data.p_proprietary = GKI_getbuf(sizeof(tBTA_BLE_PROPRIETARY)); | |
1081 | + if (btif_cb.adv_data.data.p_proprietary != NULL) | |
1082 | + { | |
1083 | + tBTA_BLE_PROPRIETARY *p_prop = btif_cb.adv_data.data.p_proprietary; | |
1084 | + tBTA_BLE_PROP_ELEM *p_elem = NULL; | |
1085 | + p_prop->num_elem = 0; | |
1086 | + btif_cb.adv_data.mask |= BTM_BLE_AD_BIT_PROPRIETARY; | |
1087 | + | |
1088 | + if (p_elem_service_128 != NULL) | |
1089 | + ++p_prop->num_elem; | |
1090 | + | |
1091 | + if (p_elem_service_data != NULL) | |
1092 | + ++p_prop->num_elem; | |
1093 | + | |
1094 | + p_prop->p_elem = GKI_getbuf(sizeof(tBTA_BLE_PROP_ELEM) * p_prop->num_elem); | |
1095 | + p_elem = p_prop->p_elem; | |
1096 | + | |
1097 | + if (p_elem_service_128 != NULL) | |
1098 | + { | |
1099 | + memcpy(p_elem++, p_elem_service_128, sizeof(tBTA_BLE_PROP_ELEM)); | |
1100 | + GKI_freebuf(p_elem_service_128); | |
1101 | + } | |
1102 | + | |
1103 | + if (p_elem_service_data != NULL) | |
1104 | + { | |
1105 | + memcpy(p_elem++, p_elem_service_data, sizeof(tBTA_BLE_PROP_ELEM)); | |
1106 | + GKI_freebuf(p_elem_service_data); | |
1107 | + } | |
1108 | + } | |
1109 | + } | |
1110 | + | |
953 | 1111 | return btif_transfer_context(btgattc_handle_event, BTIF_GATTC_SET_ADV_DATA, |
954 | 1112 | (char*) &btif_cb, sizeof(btif_gattc_cb_t), NULL); |
955 | 1113 | } |
@@ -197,6 +197,7 @@ static tGATT_CBACK btif_test_callbacks = | ||
197 | 197 | btif_test_command_complete_cback, |
198 | 198 | btif_test_discovery_result_cback, |
199 | 199 | btif_test_discovery_complete_cback, |
200 | + NULL, | |
200 | 201 | NULL |
201 | 202 | }; |
202 | 203 |
@@ -533,6 +533,9 @@ void btif_hh_remove_device(bt_bdaddr_t bd_addr) | ||
533 | 533 | return; |
534 | 534 | } |
535 | 535 | |
536 | + /* need to notify up-layer device is disconnected to avoid state out of sync with up-layer */ | |
537 | + HAL_CBACK(bt_hh_callbacks, connection_state_cb, &(p_dev->bd_addr), BTHH_CONN_STATE_DISCONNECTED); | |
538 | + | |
536 | 539 | p_dev->dev_status = BTHH_CONN_STATE_UNKNOWN; |
537 | 540 | p_dev->dev_handle = BTA_HH_INVALID_HANDLE; |
538 | 541 | if (btif_hh_cb.device_num > 0) { |
@@ -935,9 +938,18 @@ static void btif_hh_upstreams_evt(UINT16 event, char* p_param) | ||
935 | 938 | } |
936 | 939 | { |
937 | 940 | char *cached_name = NULL; |
938 | - char name[] = "Broadcom Bluetooth HID"; | |
939 | - if (cached_name == NULL) { | |
940 | - cached_name = name; | |
941 | + bt_bdname_t bdname; | |
942 | + bt_property_t prop_name; | |
943 | + BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_BDNAME, | |
944 | + sizeof(bt_bdname_t), &bdname); | |
945 | + if (btif_storage_get_remote_device_property( | |
946 | + &p_dev->bd_addr, &prop_name) == BT_STATUS_SUCCESS) | |
947 | + { | |
948 | + cached_name = (char *)bdname.name; | |
949 | + } | |
950 | + else | |
951 | + { | |
952 | + cached_name = "Bluetooth HID"; | |
941 | 953 | } |
942 | 954 | |
943 | 955 | BTIF_TRACE_WARNING2("%s: name = %s", __FUNCTION__, cached_name); |
@@ -38,7 +38,7 @@ | ||
38 | 38 | #define LOG_TAG "BTIF_STORAGE" |
39 | 39 | |
40 | 40 | #include "btif_api.h" |
41 | - | |
41 | +#include "btif_storage.h" | |
42 | 42 | #include "btif_util.h" |
43 | 43 | #include "bd.h" |
44 | 44 | #include "gki.h" |
@@ -150,7 +150,6 @@ | ||
150 | 150 | #define BTIF_STORAGE_HL_APP_DATA "hl_app_data_" |
151 | 151 | #define BTIF_STORAGE_HL_APP_MDL_DATA "hl_app_mdl_data_" |
152 | 152 | |
153 | -#define BTIF_STORAGE_MAX_ALLOWED_REMOTE_DEVICE 512 | |
154 | 153 | /************************************************************************************ |
155 | 154 | ** Local type definitions |
156 | 155 | ************************************************************************************/ |
@@ -1591,7 +1591,28 @@ void btm_ble_conn_complete(UINT8 *p, UINT16 evt_len) | ||
1591 | 1591 | role = HCI_ROLE_UNKNOWN; |
1592 | 1592 | |
1593 | 1593 | if (status == HCI_ERR_DIRECTED_ADVERTISING_TIMEOUT) |
1594 | + { | |
1594 | 1595 | btm_ble_dir_adv_tout(); |
1596 | + } | |
1597 | + /* this is to work around broadcom firmware problem to handle | |
1598 | + * unsolicited command complete event for HCI_LE_Create_Connection_Cancel | |
1599 | + * and LE connection complete event with status error code (0x2) | |
1600 | + * unknown connection identifier from bluetooth controller | |
1601 | + * the workaround is to release the HCI connection to avoid out of sync | |
1602 | + * with bluetooth controller, which cause BT can't be turned off. | |
1603 | + */ | |
1604 | + else if ((status == HCI_ERR_NO_CONNECTION) && | |
1605 | + (btm_ble_get_conn_st() != BLE_CONN_CANCEL)) | |
1606 | + { | |
1607 | + tL2C_LCB *p_lcb; | |
1608 | + handle = HCID_GET_HANDLE (handle); | |
1609 | + p_lcb = l2cu_find_lcb_by_handle (handle); | |
1610 | + if (p_lcb != NULL) | |
1611 | + { | |
1612 | + l2c_link_hci_disc_comp (handle, HCI_ERR_PEER_USER); | |
1613 | + btm_sec_disconnected (handle, HCI_ERR_PEER_USER); | |
1614 | + } | |
1615 | + } | |
1595 | 1616 | } |
1596 | 1617 | |
1597 | 1618 | btm_ble_set_conn_st(BLE_CONN_IDLE); |
@@ -153,7 +153,7 @@ tBTM_STATUS BTM_BleObserve(BOOLEAN start, UINT8 duration, | ||
153 | 153 | tBTM_BLE_INQ_CB *p_inq = &btm_cb.ble_ctr_cb.inq_var; |
154 | 154 | tBTM_STATUS status = BTM_NO_RESOURCES; |
155 | 155 | |
156 | - BTM_TRACE_EVENT0 ("BTM_BleObserve "); | |
156 | + BTM_TRACE_EVENT1 ("BTM_BleObserve : scan_type:%d",btm_cb.btm_inq_vars.scan_type); | |
157 | 157 | |
158 | 158 | if (!HCI_LE_HOST_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_1])) |
159 | 159 | return BTM_ILLEGAL_VALUE; |
@@ -162,10 +162,22 @@ tBTM_STATUS BTM_BleObserve(BOOLEAN start, UINT8 duration, | ||
162 | 162 | { |
163 | 163 | /* shared inquiry database, do not allow observe if any inquiry is active */ |
164 | 164 | if (btm_cb.btm_inq_vars.inq_active || p_inq->proc_mode != BTM_BLE_INQUIRY_NONE) |
165 | - return BTM_BUSY; | |
166 | - | |
167 | - btm_cb.btm_inq_vars.p_inq_results_cb = p_results_cb; | |
168 | - btm_cb.btm_inq_vars.p_inq_cmpl_cb = p_cmpl_cb; | |
165 | + { | |
166 | + /*check if an interleave scan is already in progress*/ | |
167 | + if(btm_cb.btm_inq_vars.scan_type == INQ_GENERAL | |
168 | + && btm_cb.btm_inq_vars.p_inq_results_cb != NULL) | |
169 | + { | |
170 | + BTM_TRACE_EVENT0 ("BTM_BleObserve general inq in progress, redirecting the results"); | |
171 | + btm_cb.btm_inq_vars.p_inq_ble_results_cb = p_results_cb; | |
172 | + btm_cb.btm_inq_vars.p_inq_ble_cmpl_cb = p_cmpl_cb; | |
173 | + return BTM_SUCCESS; | |
174 | + } | |
175 | + else | |
176 | + return BTM_BUSY; | |
177 | + } | |
178 | + btm_cb.btm_inq_vars.scan_type = INQ_LE_OBSERVE; | |
179 | + btm_cb.btm_inq_vars.p_inq_ble_results_cb = p_results_cb; | |
180 | + btm_cb.btm_inq_vars.p_inq_ble_cmpl_cb = p_cmpl_cb; | |
169 | 181 | p_inq->scan_type = (p_inq->scan_type == BTM_BLE_SCAN_MODE_NONE) ? BTM_BLE_SCAN_MODE_ACTI: p_inq->scan_type; |
170 | 182 | |
171 | 183 | /* allow config scanning type */ |
@@ -190,10 +202,19 @@ tBTM_STATUS BTM_BleObserve(BOOLEAN start, UINT8 duration, | ||
190 | 202 | } |
191 | 203 | } |
192 | 204 | } |
193 | - else if (p_inq->proc_mode == BTM_BLE_OBSERVE) | |
205 | + else/*start = 0*/ | |
194 | 206 | { |
195 | - btm_cb.btm_inq_vars.inq_active &= ~BTM_LE_OBSERVE_ACTIVE; | |
196 | - btm_ble_stop_scan(); | |
207 | + if(btm_cb.btm_inq_vars.scan_type == INQ_GENERAL) | |
208 | + { | |
209 | + //Dont stop the scan. Just nullify the cbs | |
210 | + btm_cb.btm_inq_vars.p_inq_ble_results_cb = NULL; | |
211 | + btm_cb.btm_inq_vars.p_inq_ble_cmpl_cb = NULL; | |
212 | + } | |
213 | + else if (p_inq->proc_mode == BTM_BLE_OBSERVE) | |
214 | + { | |
215 | + btm_cb.btm_inq_vars.inq_active &= ~BTM_LE_OBSERVE_ACTIVE; | |
216 | + btm_ble_stop_scan(); | |
217 | + } | |
197 | 218 | } |
198 | 219 | |
199 | 220 | return status; |
@@ -1540,6 +1561,8 @@ BOOLEAN btm_ble_update_inq_result(tINQ_DB_ENT *p_i, UINT8 addr_type, UINT8 evt_t | ||
1540 | 1561 | if ((btm_cb.ble_ctr_cb.inq_var.scan_type == BTM_BLE_SCAN_MODE_ACTI && |
1541 | 1562 | (evt_type == BTM_BLE_CONNECT_EVT || evt_type == BTM_BLE_DISCOVER_EVT))) |
1542 | 1563 | { |
1564 | + BTM_TRACE_DEBUG1("btm_ble_update_inq_result scan_rsp=false, to_report=false,\ | |
1565 | + scan_type_active=%d", btm_cb.ble_ctr_cb.inq_var.scan_type); | |
1543 | 1566 | p_i->scan_rsp = FALSE; |
1544 | 1567 | to_report = FALSE; |
1545 | 1568 | } |
@@ -1669,6 +1692,8 @@ void btm_ble_process_adv_pkt (UINT8 *p_data) | ||
1669 | 1692 | btm_cb.ble_ctr_cb.p_select_cback == NULL)) |
1670 | 1693 | return; |
1671 | 1694 | |
1695 | + BTM_TRACE_DEBUG6("btm_ble_process_adv_pkt:bda= %0x:%0x:%0x:%0x:%0x:%0x", | |
1696 | + bda[0],bda[1],bda[2],bda[3],bda[4],bda[5]); | |
1672 | 1697 | btm_ble_process_adv_pkt_cont(bda, addr_type, evt_type, p); |
1673 | 1698 | } |
1674 | 1699 |
@@ -1688,9 +1713,12 @@ static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, UINT8 addr_type, UINT8 evt | ||
1688 | 1713 | { |
1689 | 1714 | tINQ_DB_ENT *p_i; |
1690 | 1715 | BOOLEAN to_report = FALSE; |
1716 | + BOOLEAN to_report_LE = TRUE; //var for reporting to LE observe | |
1691 | 1717 | tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars; |
1692 | 1718 | tBTM_INQ_RESULTS_CB *p_inq_results_cb = p_inq->p_inq_results_cb; |
1719 | + tBTM_INQ_RESULTS_CB *p_inq_ble_results_cb = p_inq->p_inq_ble_results_cb; | |
1693 | 1720 | tBTM_BLE_INQ_CB *p_le_inq_cb = &btm_cb.ble_ctr_cb.inq_var; |
1721 | + BTM_TRACE_DEBUG2("btm_ble_process_adv_pkt_cont: addr_type: %d, evt_type: %d", addr_type, evt_type); | |
1694 | 1722 | |
1695 | 1723 | p_i = btm_inq_db_find (bda); |
1696 | 1724 |
@@ -1710,11 +1738,10 @@ static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, UINT8 addr_type, UINT8 evt | ||
1710 | 1738 | } |
1711 | 1739 | else |
1712 | 1740 | { |
1713 | - /* if yes, skip it */ | |
1714 | - return; /* assumption: one result per event */ | |
1741 | + to_report = FALSE; | |
1715 | 1742 | } |
1716 | 1743 | } |
1717 | - else /* not been processed int his round */ | |
1744 | + else /* not been processed in this round */ | |
1718 | 1745 | { |
1719 | 1746 | to_report = TRUE; |
1720 | 1747 | } |
@@ -1722,33 +1749,31 @@ static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, UINT8 addr_type, UINT8 evt | ||
1722 | 1749 | /* If existing entry, use that, else get a new one (possibly reusing the oldest) */ |
1723 | 1750 | if (p_i == NULL) |
1724 | 1751 | { |
1725 | - if (btm_ble_is_discoverable(bda, evt_type, p)) | |
1752 | + if ((p_i = btm_inq_db_new (bda)) != NULL) | |
1726 | 1753 | { |
1727 | - if ((p_i = btm_inq_db_new (bda)) != NULL) | |
1728 | - { | |
1729 | - p_inq->inq_cmpl_info.num_resp++; | |
1730 | - to_report = TRUE; | |
1731 | - } | |
1732 | - else | |
1733 | - return; | |
1754 | + p_inq->inq_cmpl_info.num_resp++; | |
1755 | + } | |
1756 | + else | |
1757 | + return; | |
1758 | + | |
1759 | + if (to_report && btm_ble_is_discoverable(bda, evt_type, p)) | |
1760 | + { | |
1761 | + to_report = TRUE; | |
1734 | 1762 | } |
1735 | 1763 | else |
1736 | 1764 | { |
1737 | 1765 | BTM_TRACE_ERROR0("discard adv pkt"); |
1738 | - return; | |
1766 | + to_report = FALSE; | |
1739 | 1767 | } |
1740 | 1768 | } |
1741 | 1769 | else if (p_i->inq_count != p_inq->inq_counter) /* first time seen in this inquiry */ |
1742 | 1770 | { |
1743 | 1771 | p_inq->inq_cmpl_info.num_resp++; |
1744 | 1772 | } |
1745 | - | |
1746 | 1773 | /* update the LE device information in inquiry database */ |
1774 | + to_report_LE = btm_ble_update_inq_result(p_i, addr_type, evt_type, p); | |
1747 | 1775 | if (to_report) |
1748 | - { | |
1749 | - to_report = btm_ble_update_inq_result(p_i, addr_type, evt_type, p); | |
1750 | - } | |
1751 | - | |
1776 | + to_report = to_report_LE; | |
1752 | 1777 | #if BTM_USE_INQ_RESULTS_FILTER == TRUE |
1753 | 1778 | /* If the number of responses found and limited, issue a cancel inquiry */ |
1754 | 1779 | if (p_inq->inqparms.max_resps && |
@@ -1776,6 +1801,8 @@ static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, UINT8 addr_type, UINT8 evt | ||
1776 | 1801 | } |
1777 | 1802 | #endif |
1778 | 1803 | |
1804 | + BTM_TRACE_DEBUG2("btm_ble_process_adv_pkt_cont: to_report =%d, to_report_le=%d", | |
1805 | + to_report, to_report_LE); | |
1779 | 1806 | /* background connection in selective connection mode */ |
1780 | 1807 | if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_SELECTIVE) |
1781 | 1808 | { |
@@ -1787,9 +1814,13 @@ static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, UINT8 addr_type, UINT8 evt | ||
1787 | 1814 | BTM_TRACE_DEBUG0("None LE device, can not initiate selective connection"); |
1788 | 1815 | } |
1789 | 1816 | } |
1790 | - else if (p_inq_results_cb && to_report) | |
1817 | + else if (to_report || to_report_LE) | |
1791 | 1818 | { |
1792 | - (p_inq_results_cb)((tBTM_INQ_RESULTS *) &p_i->inq_info.results, p_le_inq_cb->adv_data_cache); | |
1819 | + if(p_inq_results_cb && to_report) | |
1820 | + (p_inq_results_cb)((tBTM_INQ_RESULTS *) &p_i->inq_info.results, p_le_inq_cb->adv_data_cache); | |
1821 | + if(p_inq_ble_results_cb && to_report_LE) | |
1822 | + (p_inq_ble_results_cb)((tBTM_INQ_RESULTS *) &p_i->inq_info.results, | |
1823 | + p_le_inq_cb->adv_data_cache); | |
1793 | 1824 | } |
1794 | 1825 | } |
1795 | 1826 |
@@ -810,8 +810,8 @@ tBTM_STATUS BTM_CancelInquiry(void) | ||
810 | 810 | */ |
811 | 811 | #endif |
812 | 812 | |
813 | - p_inq->inq_counter++; | |
814 | - btm_clr_inq_result_flt(); | |
813 | + p_inq->inq_counter++; | |
814 | + btm_clr_inq_result_flt(); | |
815 | 815 | } |
816 | 816 | |
817 | 817 | return (status); |
@@ -860,7 +860,27 @@ tBTM_STATUS BTM_StartInquiry (tBTM_INQ_PARMS *p_inqparms, tBTM_INQ_RESULTS_CB *p | ||
860 | 860 | /* Only one active inquiry is allowed in this implementation. |
861 | 861 | Also do not allow an inquiry if the inquiry filter is being updated */ |
862 | 862 | if (p_inq->inq_active || p_inq->inqfilt_active) |
863 | - return (BTM_BUSY); | |
863 | + { | |
864 | +#if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE) | |
865 | + /*check if LE observe is already running*/ | |
866 | + if(p_inq->scan_type==INQ_LE_OBSERVE && p_inq->p_inq_ble_results_cb!=NULL) | |
867 | + { | |
868 | + BTM_TRACE_API0("BTM_StartInquiry: LE observe in progress"); | |
869 | + p_inq->scan_type = INQ_GENERAL; | |
870 | + p_inq->inq_active = BTM_INQUIRY_INACTIVE; | |
871 | + btm_cb.ble_ctr_cb.inq_var.scan_type = BTM_BLE_SCAN_MODE_NONE; | |
872 | + btm_cb.ble_ctr_cb.inq_var.proc_mode = BTM_BLE_INQUIRY_NONE; | |
873 | + btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_DISABLE, BTM_BLE_DUPLICATE_ENABLE); | |
874 | + } | |
875 | + else | |
876 | +#endif | |
877 | + { | |
878 | + return (BTM_BUSY); | |
879 | + BTM_TRACE_API0("BTM_StartInquiry: return BUSY"); | |
880 | + } | |
881 | + } | |
882 | + else | |
883 | + p_inq->scan_type = INQ_GENERAL; | |
864 | 884 | |
865 | 885 | /*** Make sure the device is ready ***/ |
866 | 886 | if (!BTM_IsDeviceUp()) |
@@ -2402,7 +2422,13 @@ void btm_process_inq_complete (UINT8 status, UINT8 mode) | ||
2402 | 2422 | p_inq->inqparms.mode &= ~(mode); |
2403 | 2423 | #endif |
2404 | 2424 | |
2405 | - | |
2425 | + if(p_inq->scan_type == INQ_LE_OBSERVE && !p_inq->inq_active) | |
2426 | + { | |
2427 | + /*end of LE observe*/ | |
2428 | + p_inq->p_inq_ble_results_cb = (tBTM_INQ_RESULTS_CB *) NULL; | |
2429 | + p_inq->p_inq_ble_cmpl_cb = (tBTM_CMPL_CB *) NULL; | |
2430 | + p_inq->scan_type=INQ_NONE; | |
2431 | + } | |
2406 | 2432 | |
2407 | 2433 | |
2408 | 2434 | #if (BTM_INQ_DEBUG == TRUE) |
@@ -2473,9 +2499,22 @@ void btm_process_inq_complete (UINT8 status, UINT8 mode) | ||
2473 | 2499 | p_inq->inq_active = BTM_INQUIRY_INACTIVE; |
2474 | 2500 | /* call the inquiry again */ |
2475 | 2501 | BTM_StartInquiry(&p_inq->inqparms,p_inq->p_inq_results_cb,p_inq->p_inq_cmpl_cb); |
2502 | + return; | |
2476 | 2503 | } |
2477 | 2504 | #endif |
2478 | 2505 | } |
2506 | + if(p_inq->inqparms.mode == 0 && p_inq->scan_type == INQ_GENERAL)//this inquiry is complete | |
2507 | + { | |
2508 | + p_inq->scan_type = INQ_NONE; | |
2509 | +#if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE) | |
2510 | + /* check if the LE observe is pending */ | |
2511 | + if(p_inq->p_inq_ble_results_cb != NULL) | |
2512 | + { | |
2513 | + BTM_TRACE_DEBUG0("BTM Inq Compl: resuming a pending LE scan"); | |
2514 | + BTM_BleObserve(1,0, p_inq->p_inq_ble_results_cb, p_inq->p_inq_ble_cmpl_cb); | |
2515 | + } | |
2516 | +#endif | |
2517 | + } | |
2479 | 2518 | #if (BTM_INQ_DEBUG == TRUE) |
2480 | 2519 | BTM_TRACE_DEBUG3 ("inq_active:0x%x state:%d inqfilt_active:%d", |
2481 | 2520 | btm_cb.btm_inq_vars.inq_active, btm_cb.btm_inq_vars.state, btm_cb.btm_inq_vars.inqfilt_active); |
@@ -271,6 +271,14 @@ typedef struct | ||
271 | 271 | } tINQ_DB_ENT; |
272 | 272 | |
273 | 273 | |
274 | +enum | |
275 | +{ | |
276 | + INQ_NONE, | |
277 | + INQ_LE_OBSERVE, | |
278 | + INQ_GENERAL | |
279 | +}; | |
280 | +typedef UINT8 tBTM_INQ_TYPE; | |
281 | + | |
274 | 282 | typedef struct |
275 | 283 | { |
276 | 284 | tBTM_CMPL_CB *p_remname_cmpl_cb; |
@@ -288,6 +296,7 @@ typedef struct | ||
288 | 296 | UINT16 inq_scan_period; |
289 | 297 | UINT16 inq_scan_type; |
290 | 298 | UINT16 page_scan_type; /* current page scan type */ |
299 | + tBTM_INQ_TYPE scan_type; | |
291 | 300 | |
292 | 301 | BD_ADDR remname_bda; /* Name of bd addr for active remote name request */ |
293 | 302 | #define BTM_RMT_NAME_INACTIVE 0 |
@@ -298,6 +307,8 @@ typedef struct | ||
298 | 307 | |
299 | 308 | tBTM_CMPL_CB *p_inq_cmpl_cb; |
300 | 309 | tBTM_INQ_RESULTS_CB *p_inq_results_cb; |
310 | + tBTM_CMPL_CB *p_inq_ble_cmpl_cb; /*completion callback exclusively for LE Observe*/ | |
311 | + tBTM_INQ_RESULTS_CB *p_inq_ble_results_cb;/*results callback exclusively for LE observe*/ | |
301 | 312 | tBTM_CMPL_CB *p_inqfilter_cmpl_cb; /* Called (if not NULL) after inquiry filter completed */ |
302 | 313 | tBTM_INQ_DB_CHANGE_CB *p_inq_change_cb; /* Inquiry database changed callback */ |
303 | 314 | UINT32 inq_counter; /* Counter incremented each time an inquiry completes */ |
@@ -2266,7 +2266,16 @@ static void btu_ble_ll_conn_complete_evt ( UINT8 *p, UINT16 evt_len) | ||
2266 | 2266 | |
2267 | 2267 | static void btu_ble_ll_conn_param_upd_evt (UINT8 *p, UINT16 evt_len) |
2268 | 2268 | { |
2269 | -/* This is empty until an upper layer cares about returning event */ | |
2269 | + /* LE connection update has completed successfully as a master. */ | |
2270 | + /* We can enable the update request if the result is a success. */ | |
2271 | + /* extract the HCI handle first */ | |
2272 | + UINT8 status; | |
2273 | + UINT16 handle; | |
2274 | + BT_TRACE_0(TRACE_LAYER_HCI, TRACE_TYPE_EVENT, "btu_ble_ll_conn_param_upd_evt"); | |
2275 | + | |
2276 | + STREAM_TO_UINT8 (status, p); | |
2277 | + STREAM_TO_UINT16 (handle, p); | |
2278 | + L2CA_HandleConnUpdateEvent(handle, status); | |
2270 | 2279 | } |
2271 | 2280 | |
2272 | 2281 | static void btu_ble_read_remote_feat_evt (UINT8 *p, UINT16 evt_len) |
@@ -65,7 +65,8 @@ static tGATT_CBACK gap_cback = | ||
65 | 65 | gap_ble_c_cmpl_cback, |
66 | 66 | NULL, |
67 | 67 | NULL, |
68 | - gap_ble_s_attr_request_cback | |
68 | + gap_ble_s_attr_request_cback, | |
69 | + NULL | |
69 | 70 | }; |
70 | 71 | |
71 | 72 |
@@ -1294,7 +1294,9 @@ void GATT_Deregister (tGATT_IF gatt_if) | ||
1294 | 1294 | |
1295 | 1295 | gatt_deregister_bgdev_list(gatt_if); |
1296 | 1296 | /* update the listen mode */ |
1297 | +#ifdef BLE_PERIPHERAL_MODE_SUPPORT | |
1297 | 1298 | GATT_Listen(gatt_if, FALSE, NULL); |
1299 | +#endif | |
1298 | 1300 | |
1299 | 1301 | memset (p_reg, 0, sizeof(tGATT_REG)); |
1300 | 1302 | } |
@@ -48,7 +48,8 @@ static tGATT_CBACK gatt_profile_cback = | ||
48 | 48 | NULL, |
49 | 49 | NULL, |
50 | 50 | NULL, |
51 | - gatt_profile_request_cback | |
51 | + gatt_profile_request_cback, | |
52 | + NULL | |
52 | 53 | } ; |
53 | 54 | |
54 | 55 | /******************************************************************************* |
@@ -228,9 +228,18 @@ void gatt_notify_enc_cmpl(BD_ADDR bd_addr) | ||
228 | 228 | tGATT_TCB *p_tcb; |
229 | 229 | tGATT_PENDING_ENC_CLCB *p_buf; |
230 | 230 | UINT16 count; |
231 | + UINT8 i = 0; | |
231 | 232 | |
232 | 233 | if ((p_tcb = gatt_find_tcb_by_addr(bd_addr)) != NULL) |
233 | 234 | { |
235 | + for (i = 0; i < GATT_MAX_APPS; i++) | |
236 | + { | |
237 | + if (gatt_cb.cl_rcb[i].in_use && gatt_cb.cl_rcb[i].app_cb.p_enc_cmpl_cb) | |
238 | + { | |
239 | + (*gatt_cb.cl_rcb[i].app_cb.p_enc_cmpl_cb)(gatt_cb.cl_rcb[i].gatt_if, bd_addr); | |
240 | + } | |
241 | + } | |
242 | + | |
234 | 243 | if (gatt_get_sec_act(p_tcb) == GATT_SEC_ENC_PENDING) |
235 | 244 | { |
236 | 245 | gatt_set_sec_act(p_tcb, GATT_SEC_NONE); |
@@ -573,7 +573,8 @@ typedef void (tGATT_CONN_CBACK) (tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn_id, | ||
573 | 573 | /* attribute request callback for ATT server */ |
574 | 574 | typedef void (tGATT_REQ_CBACK )(UINT16 conn_id, UINT32 trans_id, tGATTS_REQ_TYPE type, tGATTS_DATA *p_data); |
575 | 575 | |
576 | - | |
576 | +/* Define a callback function when encryption is established. */ | |
577 | +typedef void (tGATT_ENC_CMPL_CB)(tGATT_IF gatt_if, BD_ADDR bda); | |
577 | 578 | |
578 | 579 | |
579 | 580 | /* Define the structure that applications use to register with |
@@ -587,6 +588,7 @@ typedef struct | ||
587 | 588 | tGATT_DISC_RES_CB *p_disc_res_cb; |
588 | 589 | tGATT_DISC_CMPL_CB *p_disc_cmpl_cb; |
589 | 590 | tGATT_REQ_CBACK *p_req_cb; |
591 | + tGATT_ENC_CMPL_CB *p_enc_cmpl_cb; | |
590 | 592 | } tGATT_CBACK; |
591 | 593 | |
592 | 594 | /*********************** Start Handle Management Definitions ********************** |
@@ -1146,6 +1146,18 @@ L2C_API extern BOOLEAN L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, BOOLEAN | ||
1146 | 1146 | |
1147 | 1147 | /******************************************************************************* |
1148 | 1148 | ** |
1149 | +** Function L2CA_HandleConnUpdateEvent | |
1150 | +** | |
1151 | +** Description This function enables the connection update request from remote | |
1152 | +** after a successful connection update response is received. | |
1153 | +** | |
1154 | +** Returns void | |
1155 | +** | |
1156 | +*******************************************************************************/ | |
1157 | +L2C_API void L2CA_HandleConnUpdateEvent (UINT16 handle, UINT8 status); | |
1158 | + | |
1159 | +/******************************************************************************* | |
1160 | +** | |
1149 | 1161 | ** Function L2CA_GetBleConnRole |
1150 | 1162 | ** |
1151 | 1163 | ** Description This function returns the connection role. |
@@ -81,6 +81,56 @@ BOOLEAN L2CA_CancelBleConnectReq (BD_ADDR rem_bda) | ||
81 | 81 | return(FALSE); |
82 | 82 | } |
83 | 83 | |
84 | +/******************************************************************************* | |
85 | +** | |
86 | +** Function L2CA_InternalBleConnUpdate | |
87 | +** | |
88 | +** Description update BLE connection based on status | |
89 | +** | |
90 | +** Parameters: lcb | |
91 | +** | |
92 | +** Return value: none | |
93 | +** | |
94 | +*******************************************************************************/ | |
95 | +static void L2CA_InternalBleConnUpdate (tL2C_LCB *p_lcb) | |
96 | +{ | |
97 | + if (p_lcb->upd_status & L2C_BLE_UPDATE_PENDING) return; | |
98 | + | |
99 | + if (p_lcb->upd_status & L2C_BLE_CONN_UPDATE_DISABLE) | |
100 | + { | |
101 | + /* application requests to disable parameters update. | |
102 | + If parameters are already updated, lets set them | |
103 | + up to what has been requested during connection establishement */ | |
104 | + if (p_lcb->upd_status & L2C_BLE_NOT_DEFAULT_PARAM) | |
105 | + { | |
106 | + tBTM_SEC_DEV_REC *p_dev_rec = btm_find_or_alloc_dev(p_lcb->remote_bd_addr); | |
107 | + | |
108 | + btsnd_hcic_ble_upd_ll_conn_params(p_lcb->handle, | |
109 | + (UINT16)((p_dev_rec->conn_params.min_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ? | |
110 | + p_dev_rec->conn_params.min_conn_int : BTM_BLE_CONN_INT_MIN_DEF), | |
111 | + (UINT16)((p_dev_rec->conn_params.max_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ? | |
112 | + p_dev_rec->conn_params.max_conn_int : BTM_BLE_CONN_INT_MAX_DEF), | |
113 | + (UINT16)((p_dev_rec->conn_params.slave_latency != BTM_BLE_CONN_PARAM_UNDEF) ? | |
114 | + p_dev_rec->conn_params.slave_latency : BTM_BLE_CONN_SLAVE_LATENCY_DEF), | |
115 | + (UINT16)((p_dev_rec->conn_params.supervision_tout != BTM_BLE_CONN_PARAM_UNDEF) ? | |
116 | + p_dev_rec->conn_params.supervision_tout : BTM_BLE_CONN_TIMEOUT_DEF), | |
117 | + 0, 0); | |
118 | + p_lcb->upd_status &= ~L2C_BLE_NOT_DEFAULT_PARAM; | |
119 | + p_lcb->upd_status |= (L2C_BLE_UPDATE_PENDING | L2C_BLE_NEW_CONN_PARAM); | |
120 | + } | |
121 | + } | |
122 | + else | |
123 | + { | |
124 | + /* application allows to do update, if we were delaying one do it now */ | |
125 | + if (p_lcb->upd_status & L2C_BLE_NEW_CONN_PARAM) | |
126 | + { | |
127 | + btsnd_hcic_ble_upd_ll_conn_params(p_lcb->handle, p_lcb->min_interval, | |
128 | + p_lcb->max_interval, p_lcb->latency, p_lcb->timeout, 0, 0); | |
129 | + p_lcb->upd_status &= ~L2C_BLE_NEW_CONN_PARAM; | |
130 | + p_lcb->upd_status |= (L2C_BLE_UPDATE_PENDING | L2C_BLE_NOT_DEFAULT_PARAM); | |
131 | + } | |
132 | + } | |
133 | +} | |
84 | 134 | |
85 | 135 | /******************************************************************************* |
86 | 136 | ** |
@@ -116,7 +166,14 @@ BOOLEAN L2CA_UpdateBleConnParams (BD_ADDR rem_bda, UINT16 min_int, UINT16 max_in | ||
116 | 166 | } |
117 | 167 | |
118 | 168 | if (p_lcb->link_role == HCI_ROLE_MASTER) |
119 | - btsnd_hcic_ble_upd_ll_conn_params (p_lcb->handle, min_int, max_int, latency, timeout, 0, 0); | |
169 | + { | |
170 | + p_lcb->min_interval = min_int; | |
171 | + p_lcb->max_interval = max_int; | |
172 | + p_lcb->latency = latency; | |
173 | + p_lcb->timeout = timeout; | |
174 | + p_lcb->upd_status |= L2C_BLE_NEW_CONN_PARAM; | |
175 | + L2CA_InternalBleConnUpdate(p_lcb); | |
176 | + } | |
120 | 177 | else |
121 | 178 | l2cu_send_peer_ble_par_req (p_lcb, min_int, max_int, latency, timeout); |
122 | 179 |
@@ -150,8 +207,9 @@ BOOLEAN L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, BOOLEAN enable) | ||
150 | 207 | return (FALSE); |
151 | 208 | } |
152 | 209 | |
153 | - L2CAP_TRACE_API4 ("L2CA_EnableUpdateBleConnParams - BD_ADDR %08x%04x enable %d current upd state %d", | |
154 | - (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], (rem_bda[4]<<8)+rem_bda[5], enable, p_lcb->upd_disabled); | |
210 | + L2CAP_TRACE_API4 ("L2CA_EnableUpdateBleConnParams - BD_ADDR %08x%04x enable %d upd state %d", | |
211 | + (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], (rem_bda[4]<<8)+rem_bda[5], | |
212 | + enable, p_lcb->upd_status); | |
155 | 213 | |
156 | 214 | if (!p_lcb->is_ble_link || (p_lcb->link_role != HCI_ROLE_MASTER)) |
157 | 215 | { |
@@ -162,42 +220,56 @@ BOOLEAN L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, BOOLEAN enable) | ||
162 | 220 | |
163 | 221 | if (enable) |
164 | 222 | { |
165 | - /* application allows to do update, if we were delaying one do it now, otherwise | |
166 | - just mark lcb that updates are enabled */ | |
167 | - if (p_lcb->upd_disabled == UPD_PENDING) | |
168 | - { | |
169 | - btsnd_hcic_ble_upd_ll_conn_params (p_lcb->handle, p_lcb->min_interval, p_lcb->max_interval, | |
170 | - p_lcb->latency, p_lcb->timeout, 0, 0); | |
171 | - p_lcb->upd_disabled = UPD_UPDATED; | |
172 | - } | |
173 | - else | |
174 | - { | |
175 | - p_lcb->upd_disabled = UPD_ENABLED; | |
176 | - } | |
223 | + p_lcb->upd_status &= ~L2C_BLE_CONN_UPDATE_DISABLE; | |
177 | 224 | } |
178 | 225 | else |
179 | 226 | { |
180 | - /* application requests to disable parameters update. If parameters are already updated, lets set them | |
181 | - up to what has been requested during connection establishement */ | |
182 | - if (p_lcb->upd_disabled == UPD_UPDATED) | |
183 | - { | |
184 | - tBTM_SEC_DEV_REC *p_dev_rec = btm_find_or_alloc_dev (rem_bda); | |
185 | - | |
186 | - btsnd_hcic_ble_upd_ll_conn_params (p_lcb->handle, | |
187 | - (UINT16)((p_dev_rec->conn_params.min_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.min_conn_int : BTM_BLE_CONN_INT_MIN_DEF), | |
188 | - (UINT16)((p_dev_rec->conn_params.max_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.max_conn_int : BTM_BLE_CONN_INT_MAX_DEF), | |
189 | - (UINT16)((p_dev_rec->conn_params.slave_latency != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.slave_latency : BTM_BLE_CONN_SLAVE_LATENCY_DEF), | |
190 | - (UINT16) ((p_dev_rec->conn_params.supervision_tout != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.supervision_tout : BTM_BLE_CONN_TIMEOUT_DEF), | |
191 | - 0, 0); | |
192 | - } | |
193 | - p_lcb->upd_disabled = UPD_DISABLED; | |
227 | + p_lcb->upd_status |= L2C_BLE_CONN_UPDATE_DISABLE; | |
194 | 228 | } |
195 | 229 | |
230 | + L2CA_InternalBleConnUpdate(p_lcb); | |
231 | + | |
196 | 232 | return (TRUE); |
197 | 233 | } |
198 | 234 | |
199 | 235 | /******************************************************************************* |
200 | 236 | ** |
237 | +** Function L2CA_HandleConnUpdateEvent | |
238 | +** | |
239 | +** Description This function enables the connection update request from remote | |
240 | +** after a successful connection update response is received. | |
241 | +** | |
242 | +** Returns void | |
243 | +** | |
244 | +*******************************************************************************/ | |
245 | +void L2CA_HandleConnUpdateEvent (UINT16 handle, UINT8 status) | |
246 | +{ | |
247 | + tL2C_LCB *p_lcb; | |
248 | + | |
249 | + L2CAP_TRACE_DEBUG0("L2CA_HandleConnUpdateEvent"); | |
250 | + | |
251 | + /* See if we have a link control block for the remote device */ | |
252 | + p_lcb = l2cu_find_lcb_by_handle(handle); | |
253 | + if (!p_lcb) | |
254 | + { | |
255 | + L2CAP_TRACE_WARNING1("L2CA_EnableUpdateBleConnParams: Invalid handle: %d", handle); | |
256 | + return; | |
257 | + } | |
258 | + | |
259 | + p_lcb->upd_status &= ~L2C_BLE_UPDATE_PENDING; | |
260 | + | |
261 | + if (status != HCI_SUCCESS) | |
262 | + { | |
263 | + L2CAP_TRACE_WARNING1("L2CA_EnableUpdateBleConnParams: Error status: %d", status); | |
264 | + } | |
265 | + | |
266 | + L2CA_InternalBleConnUpdate(p_lcb); | |
267 | + | |
268 | + L2CAP_TRACE_DEBUG1("L2CA_HandleConnUpdateEvent: upd_status=%d", p_lcb->upd_status); | |
269 | +} | |
270 | + | |
271 | +/******************************************************************************* | |
272 | +** | |
201 | 273 | ** Function L2CA_GetBleConnRole |
202 | 274 | ** |
203 | 275 | ** Description This function returns the connection role. |
@@ -321,6 +393,7 @@ void l2cble_scanner_conn_comp (UINT16 handle, BD_ADDR bda, tBLE_ADDR_TYPE type, | ||
321 | 393 | p_dev_rec->conn_params.slave_latency, |
322 | 394 | p_dev_rec->conn_params.supervision_tout, |
323 | 395 | 0, 0); |
396 | + p_lcb->upd_status |= L2C_BLE_UPDATE_PENDING; | |
324 | 397 | } |
325 | 398 | |
326 | 399 | /* Tell BTM Acl management about the link */ |
@@ -487,18 +560,8 @@ void l2cble_process_sig_cmd (tL2C_LCB *p_lcb, UINT8 *p, UINT16 pkt_len) | ||
487 | 560 | p_lcb->max_interval = max_interval; |
488 | 561 | p_lcb->latency = latency; |
489 | 562 | p_lcb->timeout = timeout; |
490 | - | |
491 | - if (p_lcb->upd_disabled == UPD_ENABLED) | |
492 | - { | |
493 | - btsnd_hcic_ble_upd_ll_conn_params (p_lcb->handle, min_interval, max_interval, | |
494 | - latency, timeout, 0, 0); | |
495 | - p_lcb->upd_disabled = UPD_UPDATED; | |
496 | - } | |
497 | - else | |
498 | - { | |
499 | - L2CAP_TRACE_EVENT0 ("L2CAP - LE - update currently disabled"); | |
500 | - p_lcb->upd_disabled = UPD_PENDING; | |
501 | - } | |
563 | + p_lcb->upd_status |= L2C_BLE_NEW_CONN_PARAM; | |
564 | + L2CA_InternalBleConnUpdate(p_lcb); | |
502 | 565 | } |
503 | 566 | } |
504 | 567 | else |
@@ -435,11 +435,11 @@ typedef struct t_l2c_linkcb | ||
435 | 435 | BOOLEAN is_ble_link; |
436 | 436 | tBLE_ADDR_TYPE ble_addr_type; |
437 | 437 | |
438 | -#define UPD_ENABLED 0 /* If peer requests update, we will change params */ | |
439 | -#define UPD_DISABLED 1 /* application requested not to update */ | |
440 | -#define UPD_PENDING 2 /* while updates are disabled, peer requested new parameters */ | |
441 | -#define UPD_UPDATED 3 /* peer updated connection parameters */ | |
442 | - UINT8 upd_disabled; | |
438 | +#define L2C_BLE_CONN_UPDATE_DISABLE 0x1 /* disable update connection parameters */ | |
439 | +#define L2C_BLE_NEW_CONN_PARAM 0x2 /* new connection parameter to be set */ | |
440 | +#define L2C_BLE_UPDATE_PENDING 0x4 /* waiting for connection update finished */ | |
441 | +#define L2C_BLE_NOT_DEFAULT_PARAM 0x8 /* not using default connection parameters */ | |
442 | + UINT8 upd_status; | |
443 | 443 | |
444 | 444 | UINT16 min_interval; /* parameters as requested by peripheral */ |
445 | 445 | UINT16 max_interval; |
@@ -905,10 +905,9 @@ void smp_delay_terminate(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) | ||
905 | 905 | |
906 | 906 | btu_stop_timer (&p_cb->rsp_timer_ent); |
907 | 907 | |
908 | - /* if remote user terminate connection, finish SMP pairing as normal */ | |
909 | - if (p_data->reason == HCI_ERR_PEER_USER) | |
910 | - p_cb->status = SMP_SUCCESS; | |
911 | - else | |
908 | + /* if remote user terminate connection, keep the previous status */ | |
909 | + /* this is to avoid reporting reverse status to uplayer */ | |
910 | + if (p_data->reason != HCI_ERR_PEER_USER) | |
912 | 911 | p_cb->status = SMP_CONN_TOUT; |
913 | 912 | |
914 | 913 | smp_proc_pairing_cmpl(p_cb); |
@@ -39,7 +39,8 @@ static tGATT_CBACK srvc_gatt_cback = | ||
39 | 39 | srvc_eng_c_cmpl_cback, |
40 | 40 | NULL, |
41 | 41 | NULL, |
42 | - srvc_eng_s_request_cback | |
42 | + srvc_eng_s_request_cback, | |
43 | + NULL | |
43 | 44 | } ; |
44 | 45 | /* type for action functions */ |
45 | 46 | typedef void (*tSRVC_ENG_C_CMPL_ACTION)(tSRVC_CLCB *p_clcb, tGATTC_OPTYPE op, |