• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

external/bluetooth/bluedroid


コミットメタ情報

リビジョン3014db38dfd3ce589ce041d96771a7cae793edef (tree)
日時2014-08-27 19:27:53
作者Chih-Wei Huang <cwhuang@linu...>
コミッターChih-Wei Huang

ログメッセージ

Android 4.4.4 Release 2
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iEYEABECAAYFAlO7IZwACgkQ6K0/gZqxDnhBQgCfZ+mK+Kgj/SMeF+s8sLmj8sTY
1OoAmweuU2W0+Zzit9JbgtrwAPJ3dp/i
=28vo
-----END PGP SIGNATURE-----

Merge tag 'android-4.4.4_r2' into kitkat-x86

Android 4.4.4 Release 2

変更サマリ

差分

--- a/bta/dm/bta_dm_act.c
+++ b/bta/dm/bta_dm_act.c
@@ -673,6 +673,11 @@ void bta_dm_remove_device (tBTA_DM_MSG *p_data)
673673 int i;
674674 tBTA_DM_SEC sec_event;
675675
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+
676681 if (BTM_IsAclConnectionUp(p_dev->bd_addr))
677682 {
678683 /* 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)
692697 else /* Ok to remove the device in application layer */
693698 {
694699 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+
695705 if( bta_dm_cb.p_sec_cback )
696706 {
697707 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)
34593469 if( bta_dm_cb.device_list.peer_device[i].conn_state == BTA_DM_UNPAIRING )
34603470 {
34613471 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
34623476 issue_unpair_cb = TRUE;
34633477 }
34643478
@@ -3768,6 +3782,12 @@ static void bta_dm_remove_sec_dev_entry(BD_ADDR remote_bd_addr)
37683782 else
37693783 {
37703784 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
37713791 }
37723792 }
37733793
@@ -4997,6 +5017,7 @@ void bta_dm_ble_set_adv_params (tBTA_DM_MSG *p_data)
49975017 p_data->ble_set_adv_params.p_dir_bda,
49985018 BTA_DM_BLE_ADV_CHNL_MAP);
49995019 }
5020+
50005021 /*******************************************************************************
50015022 **
50025023 ** Function bta_dm_ble_set_adv_config
@@ -5012,6 +5033,34 @@ void bta_dm_ble_set_adv_config (tBTA_DM_MSG *p_data)
50125033 (tBTM_BLE_ADV_DATA *)p_data->ble_set_adv_data.p_adv_cfg);
50135034 }
50145035
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+}
50155064
50165065 #if ((defined BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE))
50175066 #ifndef BTA_DM_GATT_CLOSE_DELAY_TOUT
--- a/bta/dm/bta_dm_api.c
+++ b/bta/dm/bta_dm_api.c
@@ -1510,6 +1510,60 @@ void BTA_DmBleSetAdvConfig (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv
15101510 bta_sys_sendmsg(p_msg);
15111511 }
15121512 }
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+
15131567 #endif
15141568 /*******************************************************************************
15151569 **
--- a/bta/dm/bta_dm_int.h
+++ b/bta/dm/bta_dm_int.h
@@ -101,6 +101,8 @@ enum
101101 BTA_DM_API_BLE_OBSERVE_EVT,
102102 BTA_DM_API_BLE_ADV_PARAM_EVT,
103103 BTA_DM_API_BLE_SET_ADV_CONFIG_EVT,
104+ BTA_DM_API_BLE_SET_SCAN_RSP_EVT,
105+ BTA_DM_API_BLE_BROADCAST_EVT,
104106 #endif
105107
106108 #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);
996998 extern void bta_dm_ble_observe (tBTA_DM_MSG *p_data);
997999 extern void bta_dm_ble_set_adv_params (tBTA_DM_MSG *p_data);
9981000 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);
9991003
10001004 #endif
10011005 extern void bta_dm_set_encryption(tBTA_DM_MSG *p_data);
--- a/bta/dm/bta_dm_main.c
+++ b/bta/dm/bta_dm_main.c
@@ -98,6 +98,8 @@ const tBTA_DM_ACTION bta_dm_action[] =
9898 bta_dm_ble_observe,
9999 bta_dm_ble_set_adv_params, /* BTA_DM_API_BLE_SCAN_PARAM_EVT */
100100 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 */
101103 #endif
102104
103105 #if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&( BTA_EIR_CANNED_UUID_LIST != TRUE )&&(BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0)
--- a/bta/gatt/bta_gattc_act.c
+++ b/bta/gatt/bta_gattc_act.c
@@ -52,13 +52,16 @@ static void bta_gattc_cmpl_cback(UINT16 conn_id, tGATTC_OPTYPE op, tGATT_STATUS
5252
5353 static void bta_gattc_deregister_cmpl(tBTA_GATTC_RCB *p_clreg);
5454
55+static void bta_gattc_enc_cmpl_cback(tGATT_IF gattc_if, BD_ADDR bda);
56+
5557 static tGATT_CBACK bta_gattc_cl_cback =
5658 {
5759 bta_gattc_conn_cback,
5860 bta_gattc_cmpl_cback,
5961 bta_gattc_disc_res_cback,
6062 bta_gattc_disc_cmpl_cback,
61- NULL
63+ NULL,
64+ bta_gattc_enc_cmpl_cback
6265 };
6366
6467 /* 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
399402
400403 }
401404 }
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+
402433 /*******************************************************************************
403434 **
404435 ** 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,
16351666
16361667 /*******************************************************************************
16371668 **
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+**
16381713 ** Function bta_gattc_process_api_refresh
16391714 **
16401715 ** 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)
20532128 }
20542129 }
20552130 }
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+}
20562153 #endif
20572154 #endif
--- a/bta/gatt/bta_gattc_api.c
+++ b/bta/gatt/bta_gattc_api.c
@@ -1056,5 +1056,31 @@ void BTA_GATTC_Listen(tBTA_GATTC_IF client_if, BOOLEAN start, BD_ADDR_PTR target
10561056 return;
10571057 }
10581058
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+
10591085 #endif /* BTA_GATT_INCLUDED */
10601086
--- a/bta/gatt/bta_gattc_int.h
+++ b/bta/gatt/bta_gattc_int.h
@@ -69,7 +69,9 @@ enum
6969 BTA_GATTC_API_REG_EVT,
7070 BTA_GATTC_API_DEREG_EVT,
7171 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
7375 };
7476 typedef UINT16 tBTA_GATTC_INT_EVT;
7577
@@ -195,6 +197,13 @@ typedef struct
195197 tGATT_DISCONN_REASON reason;
196198 }tBTA_GATTC_INT_CONN;
197199
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+
198207 typedef union
199208 {
200209 BT_HDR hdr;
@@ -213,6 +222,7 @@ typedef union
213222 tBTA_GATTC_CI_EVT ci_save;
214223 tBTA_GATTC_CI_LOAD ci_load;
215224 tBTA_GATTC_INT_CONN int_conn;
225+ tBTA_GATTC_ENC_CMPL enc_cmpl;
216226
217227 tBTA_GATTC_INT_START_IF int_start_if;
218228 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);
433443 extern void bta_gattc_process_api_open (tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg);
434444 extern void bta_gattc_process_api_open_cancel (tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg);
435445 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);
436447
437448 /* function within state machine */
438449 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
474485 extern void bta_gattc_process_api_refresh(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg);
475486 #if BLE_INCLUDED == TRUE
476487 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);
477489 #endif
478490 /* utility functions */
479491 extern tBTA_GATTC_CLCB * bta_gattc_find_clcb_by_cif (UINT8 client_if, BD_ADDR remote_bda);
--- a/bta/gatt/bta_gattc_main.c
+++ b/bta/gatt/bta_gattc_main.c
@@ -385,7 +385,15 @@ BOOLEAN bta_gattc_hdl_event(BT_HDR *p_msg)
385385 case BTA_GATTC_API_LISTEN_EVT:
386386 bta_gattc_listen(p_cb, (tBTA_GATTC_DATA *) p_msg);
387387 break;
388+ case BTA_GATTC_API_BROADCAST_EVT:
389+ bta_gattc_broadcast(p_cb, (tBTA_GATTC_DATA *) p_msg);
390+ break;
388391 #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+
389397 default:
390398 if (p_msg->event == BTA_GATTC_INT_CONN_EVT)
391399 p_clcb = bta_gattc_find_int_conn_clcb((tBTA_GATTC_DATA *) p_msg);
--- a/bta/gatt/bta_gatts_act.c
+++ b/bta/gatt/bta_gatts_act.c
@@ -49,7 +49,8 @@ static tGATT_CBACK bta_gatts_cback =
4949 NULL,
5050 NULL,
5151 NULL,
52- bta_gatts_send_request_cback
52+ bta_gatts_send_request_cback,
53+ NULL
5354 };
5455
5556 tGATT_APPL_INFO bta_gatts_nv_cback =
--- a/bta/hh/bta_hh_int.h
+++ b/bta/hh/bta_hh_int.h
@@ -67,6 +67,7 @@ enum
6767 BTA_HH_GATT_READ_DESCR_CMPL_EVT,
6868 BTA_HH_GATT_WRITE_DESCR_CMPL_EVT,
6969 BTA_HH_API_SCPP_UPDATE_EVT,
70+ BTA_HH_GATT_ENC_CMPL_EVT,
7071 #endif
7172
7273 /* not handled by execute state machine */
@@ -182,6 +183,7 @@ typedef union
182183 tBTA_HH_LE_CLOSE le_close;
183184 tBTA_GATTC_OPEN le_open;
184185 tBTA_HH_SCPP_UPDATE le_scpp_update;
186+ tBTA_GATTC_ENC_CMPL_CB le_enc_cmpl;
185187 #endif
186188 } tBTA_HH_DATA;
187189
@@ -201,7 +203,7 @@ typedef struct
201203 }tBTA_HH_LE_RPT;
202204
203205 #ifndef BTA_HH_LE_RPT_MAX
204-#define BTA_HH_LE_RPT_MAX 10
206+#define BTA_HH_LE_RPT_MAX 20
205207 #endif
206208
207209 typedef struct
@@ -283,6 +285,7 @@ typedef struct
283285 UINT8 scps_notify; /* scan refresh supported/notification enabled */
284286 #endif
285287
288+ BOOLEAN security_pending;
286289 } tBTA_HH_DEV_CB;
287290
288291 /* 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 *
404407 extern void bta_hh_start_security(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_buf);
405408 extern void bta_hh_security_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_buf);
406409 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);
408411
409412 #if BTA_HH_DEBUG
410413 extern void bta_hh_trace_dev_db(void);
--- a/bta/hh/bta_hh_le.c
+++ b/bta/hh/bta_hh_le.c
@@ -28,6 +28,7 @@
2828 #include "bta_hh_co.h"
2929 #include "bta_gatt_api.h"
3030 #include "srvc_api.h"
31+#include "btm_int.h"
3132
3233 #ifndef BTA_HH_LE_RECONN
3334 #define BTA_HH_LE_RECONN TRUE
@@ -37,7 +38,7 @@
3738
3839 #define BTA_HH_LE_RPT_TYPE_VALID(x) ((x) <= BTA_LE_HID_RPT_FEATURE && (x)>=BTA_LE_HID_RPT_INPUT)
3940
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))
4142 #define BTA_HH_LE_RPT_GET_SRVC_INST_ID(x) (UINT8)(x >> 4)
4243 #define BTA_HH_LE_RPT_GET_RPT_INST_ID(x) (UINT8)(x & 0x0f)
4344
@@ -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
638639
639640 while (p_rpt != NULL)
640641 {
642+ if (!p_rpt->in_use) break;
643+
641644 if (p_rpt->rpt_type == BTA_HH_RPTT_INPUT)
642645 {
643646 /* 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,
718721 #endif
719722 }
720723
721- if (p_rpt->index < BTA_HH_LE_RPT_MAX)
724+ if (p_rpt->index < BTA_HH_LE_RPT_MAX - 1)
722725 p_rpt ++;
723-
726+ else
727+ p_rpt = NULL;
724728 /* read next report reference descriptor */
725729 bta_hh_le_read_rpt_ref_descr(p_dev_cb, p_rpt);
726730
@@ -1084,7 +1088,7 @@ void bta_hh_le_expl_rpt(tBTA_HH_DEV_CB *p_dev_cb,
10841088 p_char_id->char_id.inst_id,
10851089 prop) == NULL)
10861090 {
1087- APPL_TRACE_ERROR0("Add report entry failed !!!")
1091+ APPL_TRACE_ERROR0("Add report entry failed !!!");
10881092 break;
10891093 }
10901094
@@ -1125,7 +1129,7 @@ void bta_hh_le_expl_boot_rpt(tBTA_HH_DEV_CB *p_dev_cb, UINT16 char_uuid,
11251129 prop) == NULL)
11261130
11271131 {
1128- APPL_TRACE_ERROR0("Add report entry failed !!!")
1132+ APPL_TRACE_ERROR0("Add report entry failed !!!");
11291133 }
11301134
11311135 return;
@@ -1257,6 +1261,28 @@ void bta_hh_security_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_buf)
12571261 bta_hh_le_api_disc_act(p_cb);
12581262
12591263 }
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+
12601286 /*******************************************************************************
12611287 **
12621288 ** 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)
12691295 void bta_hh_start_security(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_buf)
12701296 {
12711297 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+ }
12721311
12731312 /* verify bond */
12741313 BTM_GetSecurityFlags(p_cb->addr, &sec_flag);
@@ -1372,7 +1411,7 @@ void bta_hh_le_close(tBTA_GATTC_CLOSE * p_data)
13721411 p_buf->reason = p_data->reason;
13731412
13741413 p_dev_cb->conn_id = BTA_GATT_INVALID_CONN_ID;
1375-
1414+ p_dev_cb->security_pending = FALSE;
13761415 bta_sys_sendmsg(p_buf);
13771416 }
13781417 }
@@ -2593,6 +2632,8 @@ static void bta_hh_le_add_dev_bg_conn(tBTA_HH_DEV_CB *p_cb, BOOLEAN check_bond)
25932632 *******************************************************************************/
25942633 UINT8 bta_hh_le_add_device(tBTA_HH_DEV_CB *p_cb, tBTA_HH_MAINT_DEV *p_dev_info)
25952634 {
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;
25962637
25972638 /* update DI information */
25982639 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)
27092750
27102751 case BTA_GATTC_OPEN_EVT: /* 2 */
27112752 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+ }
27132756 break;
27142757
27152758 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)
27512794 case BTA_GATTC_NOTIF_EVT: /* 10 */
27522795 bta_hh_le_input_rpt_notify(&p_data->notify);
27532796 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+
27542806 default:
27552807 break;
27562808 }
--- a/bta/hh/bta_hh_main.c
+++ b/bta/hh/bta_hh_main.c
@@ -66,7 +66,7 @@ enum
6666 BTA_HH_START_SEC,
6767 BTA_HH_SEC_CMPL,
6868 BTA_HH_LE_UPDATE_SCPP,
69-
69+ BTA_HH_GATT_ENC_CMPL,
7070 #endif
7171 BTA_HH_NUM_ACTIONS
7272 };
@@ -106,6 +106,7 @@ const tBTA_HH_ACTION bta_hh_action[] =
106106 ,bta_hh_start_security
107107 ,bta_hh_security_cmpl
108108 ,bta_hh_le_update_scpp
109+ ,bta_hh_le_notify_enc_cmpl
109110 #endif
110111 };
111112
@@ -140,6 +141,7 @@ const UINT8 bta_hh_st_idle[][BTA_HH_NUM_COLS] =
140141 /* READ_DESCR_CMPL_EVT */ ,{BTA_HH_IGNORE, BTA_HH_IDLE_ST }
141142 /* WRITE_DESCR_CMPL_EVT */ ,{BTA_HH_IGNORE, BTA_HH_IDLE_ST }
142143 /* SCPP_UPDATE_EVT */ ,{BTA_HH_IGNORE, BTA_HH_IDLE_ST }
144+/* BTA_HH_GATT_ENC_CMPL_EVT */ ,{BTA_HH_IGNORE, BTA_HH_IDLE_ST }
143145 #endif
144146
145147 };
@@ -170,6 +172,7 @@ const UINT8 bta_hh_st_w4_conn[][BTA_HH_NUM_COLS] =
170172 /* READ_DESCR_CMPL_EVT */ ,{BTA_HH_W4_LE_READ_DESCR, BTA_HH_W4_CONN_ST }
171173 /* WRITE_DESCR_CMPL_EVT */ ,{BTA_HH_WRITE_DESCR, BTA_HH_W4_CONN_ST }
172174 /* 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 }
173176 #endif
174177 };
175178
@@ -199,6 +202,7 @@ const UINT8 bta_hh_st_connected[][BTA_HH_NUM_COLS] =
199202 /* READ_DESCR_CMPL_EVT */ ,{BTA_HH_LE_READ_DESCR, BTA_HH_CONN_ST } /* do not currently read any descr when connection up */
200203 /* WRITE_DESCR_CMPL_EVT */ ,{BTA_HH_WRITE_DESCR, BTA_HH_CONN_ST } /* do not currently write any descr when connection up */
201204 /* 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 }
202206 #endif
203207 };
204208 #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] =
226230 /* READ_DESCR_CMPL_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
227231 /* WRITE_DESCR_CMPL_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC }
228232 /* 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 }
229234 };
230235 #endif
231236
--- a/bta/include/bta_api.h
+++ b/bta/include/bta_api.h
@@ -1884,7 +1884,7 @@ BTA_API extern void BTA_DmBleObserve(BOOLEAN start, UINT8 duration,
18841884 *******************************************************************************/
18851885 BTA_API extern void BTA_DmSetAfhChannelAssessment (BOOLEAN enable_or_disable);
18861886
1887-#if BLE_INCLUDE == TRUE
1887+#if BLE_INCLUDED == TRUE
18881888 // btla-specific --
18891889 /*******************************************************************************
18901890 **
@@ -1927,6 +1927,34 @@ BTA_API extern void BTA_DmBleEnableRemotePrivacy(BD_ADDR bd_addr, BOOLEAN privac
19271927 *******************************************************************************/
19281928 BTA_API extern void BTA_DmBleSetAdvConfig (tBTA_BLE_AD_MASK data_mask,
19291929 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+
19301958 #endif
19311959
19321960 #ifdef __cplusplus
--- a/bta/include/bta_gatt_api.h
+++ b/bta/include/bta_gatt_api.h
@@ -115,6 +115,7 @@ typedef UINT8 tBTA_GATT_STATUS;
115115 #define BTA_GATTC_CANCEL_OPEN_EVT 14 /* cancel open event */
116116 #define BTA_GATTC_SRVC_CHG_EVT 15 /* service change event */
117117 #define BTA_GATTC_LISTEN_EVT 16 /* listen event */
118+#define BTA_GATTC_ENC_CMPL_CB_EVT 17 /* encryption complete callback event */
118119
119120 typedef UINT8 tBTA_GATTC_EVT;
120121
@@ -349,6 +350,12 @@ typedef struct
349350 }tBTA_GATTC_OPEN_CLOSE;
350351 // btla-specific --
351352
353+typedef struct
354+{
355+ tBTA_GATTC_IF client_if;
356+ BD_ADDR remote_bda;
357+}tBTA_GATTC_ENC_CMPL_CB;
358+
352359 typedef union
353360 {
354361 tBTA_GATT_STATUS status;
@@ -362,6 +369,7 @@ typedef union
362369 tBTA_GATTC_WRITE write; /* write complete data */
363370 tBTA_GATTC_EXEC_CMPL exec_cmpl; /* execute complete */
364371 tBTA_GATTC_NOTIFY notify; /* notification/indication event data */
372+ tBTA_GATTC_ENC_CMPL_CB enc_cmpl;
365373 BD_ADDR remote_bda; /* service change event */
366374 } tBTA_GATTC;
367375
@@ -1023,6 +1031,21 @@ BTA_API extern void BTA_GATTC_Refresh(BD_ADDR remote_bda);
10231031 BTA_API extern void BTA_GATTC_Listen(tBTA_GATTC_IF client_if, BOOLEAN start, BD_ADDR_PTR target_bda);
10241032
10251033 /*******************************************************************************
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+/*******************************************************************************
10261049 ** BTA GATT Server API
10271050 ********************************************************************************/
10281051
--- a/btif/include/btif_storage.h
+++ b/btif/include/btif_storage.h
@@ -30,6 +30,7 @@
3030 #define BTIF_STORAGE_FILL_PROPERTY(p_prop, t, l, p_v) \
3131 (p_prop)->type = t;(p_prop)->len = l; (p_prop)->val = (p_v);
3232
33+#define BTIF_STORAGE_MAX_ALLOWED_REMOTE_DEVICE 512
3334
3435 /*******************************************************************************
3536 ** Functions
--- a/btif/src/bluetooth.c
+++ b/btif/src/bluetooth.c
@@ -155,7 +155,6 @@ static void cleanup( void )
155155 return;
156156
157157 btif_shutdown_bluetooth();
158- bt_utils_cleanup();
159158
160159 /* hal callbacks reset upon shutdown complete callback */
161160
--- a/btif/src/btif_core.c
+++ b/btif/src/btif_core.c
@@ -37,6 +37,7 @@
3737
3838 #define LOG_TAG "BTIF_CORE"
3939 #include "btif_api.h"
40+#include "bt_utils.h"
4041 #include "bta_api.h"
4142 #include "gki.h"
4243 #include "btu.h"
@@ -737,6 +738,14 @@ bt_status_t btif_shutdown_bluetooth(void)
737738 {
738739 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
739740
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+
740749 if (btif_is_enabled())
741750 {
742751 BTIF_TRACE_WARNING0("shutdown while still enabled, initiate disable");
@@ -765,6 +774,8 @@ bt_status_t btif_shutdown_bluetooth(void)
765774
766775 btif_dut_mode = 0;
767776
777+ bt_utils_cleanup();
778+
768779 BTIF_TRACE_DEBUG1("%s done", __FUNCTION__);
769780
770781 return BT_STATUS_SUCCESS;
--- a/btif/src/btif_gatt_client.c
+++ b/btif/src/btif_gatt_client.c
@@ -104,8 +104,8 @@ typedef enum {
104104
105105 typedef struct
106106 {
107- tBTM_BLE_AD_MASK mask;
108- tBTM_BLE_ADV_DATA data;
107+ tBTA_BLE_AD_MASK mask;
108+ tBTA_BLE_ADV_DATA data;
109109 } btgatt_adv_data;
110110
111111 typedef struct
@@ -463,10 +463,31 @@ static void btif_gattc_upstreams_evt(uint16_t event, char* p_param)
463463 case BTIF_GATT_OBSERVE_EVT:
464464 {
465465 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))
467479 {
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+
470491 }
471492 HAL_CBACK(bt_gatt_callbacks, client->scan_result_cb,
472493 &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)
819840 break;
820841
821842 case BTIF_GATTC_LISTEN:
843+#ifdef BLE_PERIPHERAL_MODE_SUPPORT
822844 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
823848 break;
824849
825850 case BTIF_GATTC_SET_ADV_DATA:
826851 {
827852 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);
829854 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
831860 if (p_cb->adv_data.data.manu.p_val != NULL)
832861 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+
833883 break;
834884 }
835885
@@ -904,7 +954,9 @@ static bt_status_t btif_gattc_listen(int client_if, bool start)
904954
905955 static bt_status_t btif_gattc_set_adv_data(int client_if, bool set_scan_rsp, bool include_name,
906956 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)
908960 {
909961 CHECK_BTGATT_INIT();
910962 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
9501002 }
9511003 }
9521004
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+
9531111 return btif_transfer_context(btgattc_handle_event, BTIF_GATTC_SET_ADV_DATA,
9541112 (char*) &btif_cb, sizeof(btif_gattc_cb_t), NULL);
9551113 }
--- a/btif/src/btif_gatt_test.c
+++ b/btif/src/btif_gatt_test.c
@@ -197,6 +197,7 @@ static tGATT_CBACK btif_test_callbacks =
197197 btif_test_command_complete_cback,
198198 btif_test_discovery_result_cback,
199199 btif_test_discovery_complete_cback,
200+ NULL,
200201 NULL
201202 };
202203
--- a/btif/src/btif_hh.c
+++ b/btif/src/btif_hh.c
@@ -533,6 +533,9 @@ void btif_hh_remove_device(bt_bdaddr_t bd_addr)
533533 return;
534534 }
535535
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+
536539 p_dev->dev_status = BTHH_CONN_STATE_UNKNOWN;
537540 p_dev->dev_handle = BTA_HH_INVALID_HANDLE;
538541 if (btif_hh_cb.device_num > 0) {
@@ -935,9 +938,18 @@ static void btif_hh_upstreams_evt(UINT16 event, char* p_param)
935938 }
936939 {
937940 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";
941953 }
942954
943955 BTIF_TRACE_WARNING2("%s: name = %s", __FUNCTION__, cached_name);
--- a/btif/src/btif_storage.c
+++ b/btif/src/btif_storage.c
@@ -38,7 +38,7 @@
3838 #define LOG_TAG "BTIF_STORAGE"
3939
4040 #include "btif_api.h"
41-
41+#include "btif_storage.h"
4242 #include "btif_util.h"
4343 #include "bd.h"
4444 #include "gki.h"
@@ -150,7 +150,6 @@
150150 #define BTIF_STORAGE_HL_APP_DATA "hl_app_data_"
151151 #define BTIF_STORAGE_HL_APP_MDL_DATA "hl_app_mdl_data_"
152152
153-#define BTIF_STORAGE_MAX_ALLOWED_REMOTE_DEVICE 512
154153 /************************************************************************************
155154 ** Local type definitions
156155 ************************************************************************************/
--- a/stack/btm/btm_ble.c
+++ b/stack/btm/btm_ble.c
@@ -1591,7 +1591,28 @@ void btm_ble_conn_complete(UINT8 *p, UINT16 evt_len)
15911591 role = HCI_ROLE_UNKNOWN;
15921592
15931593 if (status == HCI_ERR_DIRECTED_ADVERTISING_TIMEOUT)
1594+ {
15941595 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+ }
15951616 }
15961617
15971618 btm_ble_set_conn_st(BLE_CONN_IDLE);
--- a/stack/btm/btm_ble_gap.c
+++ b/stack/btm/btm_ble_gap.c
@@ -153,7 +153,7 @@ tBTM_STATUS BTM_BleObserve(BOOLEAN start, UINT8 duration,
153153 tBTM_BLE_INQ_CB *p_inq = &btm_cb.ble_ctr_cb.inq_var;
154154 tBTM_STATUS status = BTM_NO_RESOURCES;
155155
156- BTM_TRACE_EVENT0 ("BTM_BleObserve ");
156+ BTM_TRACE_EVENT1 ("BTM_BleObserve : scan_type:%d",btm_cb.btm_inq_vars.scan_type);
157157
158158 if (!HCI_LE_HOST_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_1]))
159159 return BTM_ILLEGAL_VALUE;
@@ -162,10 +162,22 @@ tBTM_STATUS BTM_BleObserve(BOOLEAN start, UINT8 duration,
162162 {
163163 /* shared inquiry database, do not allow observe if any inquiry is active */
164164 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;
169181 p_inq->scan_type = (p_inq->scan_type == BTM_BLE_SCAN_MODE_NONE) ? BTM_BLE_SCAN_MODE_ACTI: p_inq->scan_type;
170182
171183 /* allow config scanning type */
@@ -190,10 +202,19 @@ tBTM_STATUS BTM_BleObserve(BOOLEAN start, UINT8 duration,
190202 }
191203 }
192204 }
193- else if (p_inq->proc_mode == BTM_BLE_OBSERVE)
205+ else/*start = 0*/
194206 {
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+ }
197218 }
198219
199220 return status;
@@ -1540,6 +1561,8 @@ BOOLEAN btm_ble_update_inq_result(tINQ_DB_ENT *p_i, UINT8 addr_type, UINT8 evt_t
15401561 if ((btm_cb.ble_ctr_cb.inq_var.scan_type == BTM_BLE_SCAN_MODE_ACTI &&
15411562 (evt_type == BTM_BLE_CONNECT_EVT || evt_type == BTM_BLE_DISCOVER_EVT)))
15421563 {
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);
15431566 p_i->scan_rsp = FALSE;
15441567 to_report = FALSE;
15451568 }
@@ -1669,6 +1692,8 @@ void btm_ble_process_adv_pkt (UINT8 *p_data)
16691692 btm_cb.ble_ctr_cb.p_select_cback == NULL))
16701693 return;
16711694
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]);
16721697 btm_ble_process_adv_pkt_cont(bda, addr_type, evt_type, p);
16731698 }
16741699
@@ -1688,9 +1713,12 @@ static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, UINT8 addr_type, UINT8 evt
16881713 {
16891714 tINQ_DB_ENT *p_i;
16901715 BOOLEAN to_report = FALSE;
1716+ BOOLEAN to_report_LE = TRUE; //var for reporting to LE observe
16911717 tBTM_INQUIRY_VAR_ST *p_inq = &btm_cb.btm_inq_vars;
16921718 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;
16931720 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);
16941722
16951723 p_i = btm_inq_db_find (bda);
16961724
@@ -1710,11 +1738,10 @@ static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, UINT8 addr_type, UINT8 evt
17101738 }
17111739 else
17121740 {
1713- /* if yes, skip it */
1714- return; /* assumption: one result per event */
1741+ to_report = FALSE;
17151742 }
17161743 }
1717- else /* not been processed int his round */
1744+ else /* not been processed in this round */
17181745 {
17191746 to_report = TRUE;
17201747 }
@@ -1722,33 +1749,31 @@ static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, UINT8 addr_type, UINT8 evt
17221749 /* If existing entry, use that, else get a new one (possibly reusing the oldest) */
17231750 if (p_i == NULL)
17241751 {
1725- if (btm_ble_is_discoverable(bda, evt_type, p))
1752+ if ((p_i = btm_inq_db_new (bda)) != NULL)
17261753 {
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;
17341762 }
17351763 else
17361764 {
17371765 BTM_TRACE_ERROR0("discard adv pkt");
1738- return;
1766+ to_report = FALSE;
17391767 }
17401768 }
17411769 else if (p_i->inq_count != p_inq->inq_counter) /* first time seen in this inquiry */
17421770 {
17431771 p_inq->inq_cmpl_info.num_resp++;
17441772 }
1745-
17461773 /* update the LE device information in inquiry database */
1774+ to_report_LE = btm_ble_update_inq_result(p_i, addr_type, evt_type, p);
17471775 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;
17521777 #if BTM_USE_INQ_RESULTS_FILTER == TRUE
17531778 /* If the number of responses found and limited, issue a cancel inquiry */
17541779 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
17761801 }
17771802 #endif
17781803
1804+ BTM_TRACE_DEBUG2("btm_ble_process_adv_pkt_cont: to_report =%d, to_report_le=%d",
1805+ to_report, to_report_LE);
17791806 /* background connection in selective connection mode */
17801807 if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_SELECTIVE)
17811808 {
@@ -1787,9 +1814,13 @@ static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, UINT8 addr_type, UINT8 evt
17871814 BTM_TRACE_DEBUG0("None LE device, can not initiate selective connection");
17881815 }
17891816 }
1790- else if (p_inq_results_cb && to_report)
1817+ else if (to_report || to_report_LE)
17911818 {
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);
17931824 }
17941825 }
17951826
--- a/stack/btm/btm_inq.c
+++ b/stack/btm/btm_inq.c
@@ -810,8 +810,8 @@ tBTM_STATUS BTM_CancelInquiry(void)
810810 */
811811 #endif
812812
813- p_inq->inq_counter++;
814- btm_clr_inq_result_flt();
813+ p_inq->inq_counter++;
814+ btm_clr_inq_result_flt();
815815 }
816816
817817 return (status);
@@ -860,7 +860,27 @@ tBTM_STATUS BTM_StartInquiry (tBTM_INQ_PARMS *p_inqparms, tBTM_INQ_RESULTS_CB *p
860860 /* Only one active inquiry is allowed in this implementation.
861861 Also do not allow an inquiry if the inquiry filter is being updated */
862862 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;
864884
865885 /*** Make sure the device is ready ***/
866886 if (!BTM_IsDeviceUp())
@@ -2402,7 +2422,13 @@ void btm_process_inq_complete (UINT8 status, UINT8 mode)
24022422 p_inq->inqparms.mode &= ~(mode);
24032423 #endif
24042424
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+ }
24062432
24072433
24082434 #if (BTM_INQ_DEBUG == TRUE)
@@ -2473,9 +2499,22 @@ void btm_process_inq_complete (UINT8 status, UINT8 mode)
24732499 p_inq->inq_active = BTM_INQUIRY_INACTIVE;
24742500 /* call the inquiry again */
24752501 BTM_StartInquiry(&p_inq->inqparms,p_inq->p_inq_results_cb,p_inq->p_inq_cmpl_cb);
2502+ return;
24762503 }
24772504 #endif
24782505 }
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+ }
24792518 #if (BTM_INQ_DEBUG == TRUE)
24802519 BTM_TRACE_DEBUG3 ("inq_active:0x%x state:%d inqfilt_active:%d",
24812520 btm_cb.btm_inq_vars.inq_active, btm_cb.btm_inq_vars.state, btm_cb.btm_inq_vars.inqfilt_active);
--- a/stack/btm/btm_int.h
+++ b/stack/btm/btm_int.h
@@ -271,6 +271,14 @@ typedef struct
271271 } tINQ_DB_ENT;
272272
273273
274+enum
275+{
276+ INQ_NONE,
277+ INQ_LE_OBSERVE,
278+ INQ_GENERAL
279+};
280+typedef UINT8 tBTM_INQ_TYPE;
281+
274282 typedef struct
275283 {
276284 tBTM_CMPL_CB *p_remname_cmpl_cb;
@@ -288,6 +296,7 @@ typedef struct
288296 UINT16 inq_scan_period;
289297 UINT16 inq_scan_type;
290298 UINT16 page_scan_type; /* current page scan type */
299+ tBTM_INQ_TYPE scan_type;
291300
292301 BD_ADDR remname_bda; /* Name of bd addr for active remote name request */
293302 #define BTM_RMT_NAME_INACTIVE 0
@@ -298,6 +307,8 @@ typedef struct
298307
299308 tBTM_CMPL_CB *p_inq_cmpl_cb;
300309 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*/
301312 tBTM_CMPL_CB *p_inqfilter_cmpl_cb; /* Called (if not NULL) after inquiry filter completed */
302313 tBTM_INQ_DB_CHANGE_CB *p_inq_change_cb; /* Inquiry database changed callback */
303314 UINT32 inq_counter; /* Counter incremented each time an inquiry completes */
--- a/stack/btu/btu_hcif.c
+++ b/stack/btu/btu_hcif.c
@@ -2266,7 +2266,16 @@ static void btu_ble_ll_conn_complete_evt ( UINT8 *p, UINT16 evt_len)
22662266
22672267 static void btu_ble_ll_conn_param_upd_evt (UINT8 *p, UINT16 evt_len)
22682268 {
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);
22702279 }
22712280
22722281 static void btu_ble_read_remote_feat_evt (UINT8 *p, UINT16 evt_len)
--- a/stack/gap/gap_ble.c
+++ b/stack/gap/gap_ble.c
@@ -65,7 +65,8 @@ static tGATT_CBACK gap_cback =
6565 gap_ble_c_cmpl_cback,
6666 NULL,
6767 NULL,
68- gap_ble_s_attr_request_cback
68+ gap_ble_s_attr_request_cback,
69+ NULL
6970 };
7071
7172
--- a/stack/gatt/gatt_api.c
+++ b/stack/gatt/gatt_api.c
@@ -1294,7 +1294,9 @@ void GATT_Deregister (tGATT_IF gatt_if)
12941294
12951295 gatt_deregister_bgdev_list(gatt_if);
12961296 /* update the listen mode */
1297+#ifdef BLE_PERIPHERAL_MODE_SUPPORT
12971298 GATT_Listen(gatt_if, FALSE, NULL);
1299+#endif
12981300
12991301 memset (p_reg, 0, sizeof(tGATT_REG));
13001302 }
--- a/stack/gatt/gatt_attr.c
+++ b/stack/gatt/gatt_attr.c
@@ -48,7 +48,8 @@ static tGATT_CBACK gatt_profile_cback =
4848 NULL,
4949 NULL,
5050 NULL,
51- gatt_profile_request_cback
51+ gatt_profile_request_cback,
52+ NULL
5253 } ;
5354
5455 /*******************************************************************************
--- a/stack/gatt/gatt_auth.c
+++ b/stack/gatt/gatt_auth.c
@@ -228,9 +228,18 @@ void gatt_notify_enc_cmpl(BD_ADDR bd_addr)
228228 tGATT_TCB *p_tcb;
229229 tGATT_PENDING_ENC_CLCB *p_buf;
230230 UINT16 count;
231+ UINT8 i = 0;
231232
232233 if ((p_tcb = gatt_find_tcb_by_addr(bd_addr)) != NULL)
233234 {
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+
234243 if (gatt_get_sec_act(p_tcb) == GATT_SEC_ENC_PENDING)
235244 {
236245 gatt_set_sec_act(p_tcb, GATT_SEC_NONE);
--- a/stack/include/gatt_api.h
+++ b/stack/include/gatt_api.h
@@ -573,7 +573,8 @@ typedef void (tGATT_CONN_CBACK) (tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn_id,
573573 /* attribute request callback for ATT server */
574574 typedef void (tGATT_REQ_CBACK )(UINT16 conn_id, UINT32 trans_id, tGATTS_REQ_TYPE type, tGATTS_DATA *p_data);
575575
576-
576+/* Define a callback function when encryption is established. */
577+typedef void (tGATT_ENC_CMPL_CB)(tGATT_IF gatt_if, BD_ADDR bda);
577578
578579
579580 /* Define the structure that applications use to register with
@@ -587,6 +588,7 @@ typedef struct
587588 tGATT_DISC_RES_CB *p_disc_res_cb;
588589 tGATT_DISC_CMPL_CB *p_disc_cmpl_cb;
589590 tGATT_REQ_CBACK *p_req_cb;
591+ tGATT_ENC_CMPL_CB *p_enc_cmpl_cb;
590592 } tGATT_CBACK;
591593
592594 /*********************** Start Handle Management Definitions **********************
--- a/stack/include/l2c_api.h
+++ b/stack/include/l2c_api.h
@@ -1146,6 +1146,18 @@ L2C_API extern BOOLEAN L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, BOOLEAN
11461146
11471147 /*******************************************************************************
11481148 **
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+**
11491161 ** Function L2CA_GetBleConnRole
11501162 **
11511163 ** Description This function returns the connection role.
--- a/stack/l2cap/l2c_ble.c
+++ b/stack/l2cap/l2c_ble.c
@@ -81,6 +81,56 @@ BOOLEAN L2CA_CancelBleConnectReq (BD_ADDR rem_bda)
8181 return(FALSE);
8282 }
8383
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+}
84134
85135 /*******************************************************************************
86136 **
@@ -116,7 +166,14 @@ BOOLEAN L2CA_UpdateBleConnParams (BD_ADDR rem_bda, UINT16 min_int, UINT16 max_in
116166 }
117167
118168 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+ }
120177 else
121178 l2cu_send_peer_ble_par_req (p_lcb, min_int, max_int, latency, timeout);
122179
@@ -150,8 +207,9 @@ BOOLEAN L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, BOOLEAN enable)
150207 return (FALSE);
151208 }
152209
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);
155213
156214 if (!p_lcb->is_ble_link || (p_lcb->link_role != HCI_ROLE_MASTER))
157215 {
@@ -162,42 +220,56 @@ BOOLEAN L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, BOOLEAN enable)
162220
163221 if (enable)
164222 {
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;
177224 }
178225 else
179226 {
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;
194228 }
195229
230+ L2CA_InternalBleConnUpdate(p_lcb);
231+
196232 return (TRUE);
197233 }
198234
199235 /*******************************************************************************
200236 **
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+**
201273 ** Function L2CA_GetBleConnRole
202274 **
203275 ** 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,
321393 p_dev_rec->conn_params.slave_latency,
322394 p_dev_rec->conn_params.supervision_tout,
323395 0, 0);
396+ p_lcb->upd_status |= L2C_BLE_UPDATE_PENDING;
324397 }
325398
326399 /* 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)
487560 p_lcb->max_interval = max_interval;
488561 p_lcb->latency = latency;
489562 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);
502565 }
503566 }
504567 else
--- a/stack/l2cap/l2c_int.h
+++ b/stack/l2cap/l2c_int.h
@@ -435,11 +435,11 @@ typedef struct t_l2c_linkcb
435435 BOOLEAN is_ble_link;
436436 tBLE_ADDR_TYPE ble_addr_type;
437437
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;
443443
444444 UINT16 min_interval; /* parameters as requested by peripheral */
445445 UINT16 max_interval;
--- a/stack/smp/smp_act.c
+++ b/stack/smp/smp_act.c
@@ -905,10 +905,9 @@ void smp_delay_terminate(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
905905
906906 btu_stop_timer (&p_cb->rsp_timer_ent);
907907
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)
912911 p_cb->status = SMP_CONN_TOUT;
913912
914913 smp_proc_pairing_cmpl(p_cb);
--- a/stack/srvc/srvc_eng.c
+++ b/stack/srvc/srvc_eng.c
@@ -39,7 +39,8 @@ static tGATT_CBACK srvc_gatt_cback =
3939 srvc_eng_c_cmpl_cback,
4040 NULL,
4141 NULL,
42- srvc_eng_s_request_cback
42+ srvc_eng_s_request_cback,
43+ NULL
4344 } ;
4445 /* type for action functions */
4546 typedef void (*tSRVC_ENG_C_CMPL_ACTION)(tSRVC_CLCB *p_clcb, tGATTC_OPTYPE op,