• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

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

system/bt


Commit MetaInfo

Revisionca22ac493ab777199084d87b3c7627e7f27555af (tree)
Zeit2013-03-15 04:51:08
AutorAndre Eisenbach <andre@broa...>
CommiterMatthew Xie

Log Message

LE fixes

- Null pointer exception check added.

An exception occurs at the memcpy in the bta_dm_gatt_disc_result.
User removed the battery on Ble device(Smart Nudge) during bonding
and connection. This exception occurs sometimes.
I used Broadcom LE Explorer to reproduce it.

- Fixed disconnect and encryption behaviour

Disconnect will now disconnect the physical link immediately when no
other application is interested in the device anymore. Also, the
connection to a remote device is now dropped if encryption fails.

- Deep copy buffers when transfering context

Certain BTA server event types require a deep copy of the request
data buffers when transfering context. Shallow copy of the pointers
involved may cause a crash when overlapping read and write requests
are received.

- 2nd encryption has not started

need to send encryption complete callback
when the encryption fail due to link drop without a complete event.
Otherwise BTA layer would not be able to clean up the status,
and no further encryption can be started.

Change-Id: If93e0a188e8779830c8991e4193b96dc95e23e5d

Ändern Zusammenfassung

Diff

--- a/bta/dm/bta_dm_act.c
+++ b/bta/dm/bta_dm_act.c
@@ -4978,10 +4978,17 @@ static void bta_dm_gatt_disc_result(tBTA_GATT_ID service_id)
49784978 {
49794979 APPL_TRACE_DEBUG3("ADDING BLE SERVICE uuid=0x%x, ble_ptr = 0x%x, ble_raw_used = 0x%x", service_id.uuid.uu.uuid16,bta_dm_search_cb.p_ble_rawdata,bta_dm_search_cb.ble_raw_used);
49804980
4981- memcpy((bta_dm_search_cb.p_ble_rawdata + bta_dm_search_cb.ble_raw_used), &service_id,
4982- sizeof(service_id) );
4981+ if(bta_dm_search_cb.p_ble_rawdata)
4982+ {
4983+ memcpy((bta_dm_search_cb.p_ble_rawdata + bta_dm_search_cb.ble_raw_used), &service_id,
4984+ sizeof(service_id) );
49834985
4984- bta_dm_search_cb.ble_raw_used += sizeof(service_id);
4986+ bta_dm_search_cb.ble_raw_used += sizeof(service_id);
4987+ }
4988+ else
4989+ {
4990+ APPL_TRACE_ERROR0("p_ble_rawdata is NULL");
4991+ }
49854992
49864993 }
49874994 else
--- a/bta/gatt/bta_gattc_act.c
+++ b/bta/gatt/bta_gattc_act.c
@@ -712,10 +712,7 @@ void bta_gattc_close(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
712712 cb_data.close.reason = p_clcb->reason;
713713 bdcpy(cb_data.close.remote_bda, p_clcb->bda);
714714
715- if (p_clcb->status == BTA_GATT_OK)
716- {
717- bta_gattc_clcb_dealloc(p_clcb);
718- }
715+ bta_gattc_clcb_dealloc(p_clcb);
719716
720717 ( * p_cback)(BTA_GATTC_CLOSE_EVT, (tBTA_GATTC *)&cb_data);
721718
--- a/bta/gatt/bta_gattc_cache.c
+++ b/bta/gatt/bta_gattc_cache.c
@@ -470,8 +470,6 @@ tBTA_GATT_STATUS bta_gattc_discover_procedure(UINT16 conn_id, tBTA_GATTC_SERV *p
470470
471471 if (param.s_handle > param.e_handle)
472472 {
473- APPL_TRACE_ERROR2("discover range invalid: [0x%04x ~ 0x%04x]", param.s_handle, param.e_handle);
474-
475473 return GATT_ERROR;
476474 }
477475 }
@@ -489,8 +487,6 @@ tBTA_GATT_STATUS bta_gattc_discover_procedure(UINT16 conn_id, tBTA_GATTC_SERV *p
489487 *******************************************************************************/
490488 tBTA_GATT_STATUS bta_gattc_start_disc_include_srvc(UINT16 conn_id, tBTA_GATTC_SERV *p_srvc_cb)
491489 {
492- APPL_TRACE_DEBUG0("starting discovery included service");
493-
494490 return bta_gattc_discover_procedure(conn_id, p_srvc_cb, GATT_DISC_INC_SRVC);
495491 }
496492 /*******************************************************************************
@@ -506,8 +502,6 @@ tBTA_GATT_STATUS bta_gattc_start_disc_char(UINT16 conn_id, tBTA_GATTC_SERV *p_sr
506502 {
507503 p_srvc_cb->total_char = 0;
508504
509- APPL_TRACE_DEBUG0("starting discover characteristics");
510-
511505 return bta_gattc_discover_procedure(conn_id, p_srvc_cb, GATT_DISC_CHAR);
512506 }
513507 /*******************************************************************************
@@ -606,8 +600,6 @@ static void bta_gattc_char_disc_cmpl(UINT16 conn_id, tBTA_GATTC_SERV *p_srvc_cb)
606600 {
607601 tBTA_GATTC_ATTR_REC *p_rec = p_srvc_cb->p_srvc_list + p_srvc_cb->cur_char_idx;
608602
609- APPL_TRACE_DEBUG1("Total %d Char found ", p_srvc_cb->total_char);
610-
611603 /* if there are characteristic needs to be explored */
612604 if (p_srvc_cb->total_char > 0)
613605 {
@@ -709,7 +701,7 @@ static tBTA_GATT_STATUS bta_gattc_add_srvc_to_list(tBTA_GATTC_SERV *p_srvc_cb,
709701 tBTA_GATTC_ATTR_REC *p_rec = NULL;
710702 tBTA_GATT_STATUS status = BTA_GATT_OK;
711703
712- if (p_srvc_cb->next_avail_idx < BTA_GATTC_MAX_CACHE_CHAR)
704+ if (p_srvc_cb->p_srvc_list && p_srvc_cb->next_avail_idx < BTA_GATTC_MAX_CACHE_CHAR)
713705 {
714706 p_rec = p_srvc_cb->p_srvc_list + p_srvc_cb->next_avail_idx;
715707
@@ -731,7 +723,7 @@ static tBTA_GATT_STATUS bta_gattc_add_srvc_to_list(tBTA_GATTC_SERV *p_srvc_cb,
731723 { /* allocate bigger buffer ?? */
732724 status = GATT_DB_FULL;
733725
734- APPL_TRACE_ERROR0("char not added, no resources");
726+ APPL_TRACE_ERROR0("service not added, no resources or wrong state");
735727 }
736728 return status;
737729 }
@@ -913,10 +905,11 @@ void bta_gattc_disc_res_cback (UINT16 conn_id, tGATT_DISC_TYPE disc_type, tGATT_
913905 {
914906 tBTA_GATTC_SERV * p_srvc_cb = NULL;
915907 BOOLEAN pri_srvc;
908+ tBTA_GATTC_CLCB *p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id);
916909
917910 p_srvc_cb = bta_gattc_find_scb_by_cid(conn_id);
918911
919- if (p_srvc_cb != NULL)
912+ if (p_srvc_cb != NULL && p_clcb != NULL && p_clcb->state == BTA_GATTC_DISCOVER_ST)
920913 {
921914 switch (disc_type)
922915 {
@@ -981,7 +974,8 @@ void bta_gattc_disc_cmpl_cback (UINT16 conn_id, tGATT_DISC_TYPE disc_type, tGATT
981974
982975 if ( p_clcb && (status != GATT_SUCCESS || p_clcb->status != GATT_SUCCESS) )
983976 {
984- p_clcb->status = status;
977+ if (p_clcb->status == GATT_SUCCESS)
978+ p_clcb->status = status;
985979 bta_gattc_sm_execute(p_clcb, BTA_GATTC_DISCOVER_CMPL_EVT, NULL);
986980 return;
987981 }
@@ -1080,7 +1074,7 @@ UINT16 bta_gattc_id2handle(tBTA_GATTC_SERV *p_srcb, tBTA_GATT_SRVC_ID *p_service
10801074 if (bta_gattc_uuid_compare(descr_uuid, attr_uuid, TRUE))
10811075 {
10821076 #if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
1083- APPL_TRACE_DEBUG0("found descripotor!!");
1077+ APPL_TRACE_DEBUG0("found descriptor!!");
10841078 #endif
10851079 handle = p_attr->attr_handle;
10861080 done = TRUE;
@@ -1335,7 +1329,9 @@ static tBTA_GATT_STATUS bta_gattc_find_record(tBTA_GATTC_SERV *p_srcb,
13351329 attr_type == p_attr->attr_type)
13361330 {
13371331
1332+#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
13381333 APPL_TRACE_DEBUG0("found char handle mapping characteristic");
1334+#endif
13391335 p_result->inst_id = p_attr->inst_id;
13401336
13411337 if (p_param != NULL)
@@ -1354,10 +1350,12 @@ static tBTA_GATT_STATUS bta_gattc_find_record(tBTA_GATTC_SERV *p_srcb,
13541350 }
13551351 p_attr = p_attr->p_next;
13561352 }
1353+#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
13571354 if (status)
13581355 {
13591356 APPL_TRACE_ERROR0("In the given service, can not find matching record");
13601357 }
1358+#endif
13611359 break;
13621360 }
13631361
--- a/btif/src/btif_dm.c
+++ b/btif/src/btif_dm.c
@@ -2256,9 +2256,8 @@ static void btif_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
22562256 /*Map the HCI fail reason to bt status */
22572257 switch (p_auth_cmpl->fail_reason)
22582258 {
2259-
2260- btif_dm_remove_ble_bonding_keys();
22612259 default:
2260+ btif_dm_remove_ble_bonding_keys();
22622261 status = BT_STATUS_FAIL;
22632262 break;
22642263 }
--- a/btif/src/btif_gatt_server.c
+++ b/btif/src/btif_gatt_server.c
@@ -39,6 +39,7 @@
3939
4040 #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
4141
42+#include "gki.h"
4243 #include "bta_api.h"
4344 #include "bta_gatt_api.h"
4445 #include "bd.h"
@@ -116,6 +117,54 @@ extern const btgatt_callbacks_t *bt_gatt_callbacks;
116117 ** Static functions
117118 ************************************************************************************/
118119
120+static void btapp_gatts_copy_req_data(UINT16 event, char *p_dest, char *p_src)
121+{
122+ tBTA_GATTS *p_dest_data = (tBTA_GATTS*) p_dest;
123+ tBTA_GATTS *p_src_data = (tBTA_GATTS*) p_src;
124+
125+ if (!p_src_data || !p_dest_data)
126+ return;
127+
128+ // Copy basic structure first
129+ memcpy(p_dest_data, p_src_data, sizeof(tBTA_GATTS));
130+
131+ // Allocate buffer for request data if necessary
132+ switch (event)
133+ {
134+ case BTA_GATTS_READ_EVT:
135+ case BTA_GATTS_WRITE_EVT:
136+ case BTA_GATTS_EXEC_WRITE_EVT:
137+ case BTA_GATTS_MTU_EVT:
138+ p_dest_data->req_data.p_data = GKI_getbuf(sizeof(tBTA_GATTS_REQ_DATA));
139+ if (p_dest_data->req_data.p_data != NULL)
140+ {
141+ memcpy(p_dest_data->req_data.p_data, p_src_data->req_data.p_data,
142+ sizeof(tBTA_GATTS_REQ_DATA));
143+ }
144+ break;
145+
146+ default:
147+ break;
148+ }
149+}
150+
151+static void btapp_gatts_free_req_data(UINT16 event, tBTA_GATTS *p_data)
152+{
153+ switch (event)
154+ {
155+ case BTA_GATTS_READ_EVT:
156+ case BTA_GATTS_WRITE_EVT:
157+ case BTA_GATTS_EXEC_WRITE_EVT:
158+ case BTA_GATTS_MTU_EVT:
159+ if (p_data && p_data->req_data.p_data)
160+ GKI_freebuf(p_data->req_data.p_data);
161+ break;
162+
163+ default:
164+ break;
165+ }
166+}
167+
119168 static void btapp_gatts_handle_cback(uint16_t event, char* p_param)
120169 {
121170 ALOGD("%s: Event %d", __FUNCTION__, event);
@@ -284,13 +333,15 @@ static void btapp_gatts_handle_cback(uint16_t event, char* p_param)
284333 ALOGE("%s: Unhandled event (%d)!", __FUNCTION__, event);
285334 break;
286335 }
336+
337+ btapp_gatts_free_req_data(event, p_data);
287338 }
288339
289340 static void btapp_gatts_cback(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
290341 {
291342 bt_status_t status;
292343 status = btif_transfer_context(btapp_gatts_handle_cback, (uint16_t) event,
293- (void*)p_data, sizeof(tBTA_GATTS), NULL);
344+ (void*)p_data, sizeof(tBTA_GATTS), btapp_gatts_copy_req_data);
294345 ASSERTC(status == BT_STATUS_SUCCESS, "Context transfer failed!", status);
295346 }
296347
--- a/btif/src/btif_gatt_util.c
+++ b/btif/src/btif_gatt_util.c
@@ -55,6 +55,8 @@ static char BASE_UUID[16] = {
5555
5656 static btif_gatt_encrypted_link_t encrypted_links[BTIF_GATT_MAX_ENC_LINK_RECORDS];
5757
58+extern bt_status_t btif_dm_remove_bond(const bt_bdaddr_t *bd_addr);
59+
5860 int uuidType(unsigned char* p_uuid)
5961 {
6062 int i = 0;
@@ -330,7 +332,11 @@ static void btif_gatt_set_encryption_cb (BD_ADDR bd_addr, tBTA_STATUS result)
330332 {
331333 btif_gatt_add_encrypted_link(bd_addr);
332334 } else {
335+ bt_bdaddr_t bda;
336+ bdcpy(bda.address, bd_addr);
337+
333338 btif_gatt_remove_encrypted_link(bd_addr);
339+ btif_dm_remove_bond(&bda);
334340 }
335341 }
336342
@@ -348,4 +354,4 @@ void btif_gatt_check_encrypted_link (BD_ADDR bd_addr)
348354 BTA_DmSetEncryption(bd_addr,
349355 &btif_gatt_set_encryption_cb, BTM_BLE_SEC_ENCRYPT);
350356 }
351-}
\ No newline at end of file
357+}
--- a/stack/btm/btm_ble.c
+++ b/stack/btm/btm_ble.c
@@ -1198,12 +1198,17 @@ BOOLEAN btm_ble_start_encrypt(BD_ADDR bda, BOOLEAN use_stk, BT_OCTET16 stk)
11981198 if (!btsnd_hcic_ble_start_enc(p_rec->hci_handle, dummy_rand, 0, stk))
11991199 return FALSE;
12001200 }
1201- else
1201+ else if (p_rec->ble.key_type & BTM_LE_KEY_PENC)
12021202 {
12031203 if (!btsnd_hcic_ble_start_enc(p_rec->hci_handle, p_rec->ble.keys.rand,
12041204 p_rec->ble.keys.ediv, p_rec->ble.keys.ltk))
12051205 return FALSE;
12061206 }
1207+ else
1208+ {
1209+ return FALSE;
1210+ }
1211+
12071212 return TRUE;
12081213 }
12091214
--- a/stack/btm/btm_sec.c
+++ b/stack/btm/btm_sec.c
@@ -4471,6 +4471,7 @@ void btm_sec_disconnected (UINT16 handle, UINT8 reason)
44714471 tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev_by_handle (handle);
44724472 UINT8 old_pairing_flags = btm_cb.pairing_flags;
44734473 int result = HCI_ERR_AUTH_FAILURE;
4474+ tBTM_SEC_CALLBACK *p_callback = NULL;
44744475
44754476 /* If page was delayed for disc complete, can do it now */
44764477 btm_cb.discing = FALSE;
@@ -4532,7 +4533,17 @@ void btm_sec_disconnected (UINT16 handle, UINT8 reason)
45324533 p_dev_rec->sec_flags &= ~(BTM_SEC_AUTHORIZED | BTM_SEC_AUTHENTICATED | BTM_SEC_ENCRYPTED | BTM_SEC_ROLE_SWITCHED);
45334534
45344535 p_dev_rec->security_required = BTM_SEC_NONE;
4535- p_dev_rec->p_callback = NULL; /* when the peer device time out the authentication before we do, this call back must be reset here */
4536+
4537+ p_callback = p_dev_rec->p_callback;
4538+
4539+ /* if security is pending, send callback to clean up the security state */
4540+ if(p_callback)
4541+ {
4542+ p_dev_rec->p_callback = NULL; /* when the peer device time out the authentication before
4543+ we do, this call back must be reset here */
4544+ (*p_callback) (p_dev_rec->bd_addr, p_dev_rec->p_ref_data, BTM_ERR_PROCESSING);
4545+ }
4546+
45364547 BTM_TRACE_EVENT1("after Update sec_flags=0x%x", p_dev_rec->sec_flags);
45374548 }
45384549
--- a/stack/l2cap/l2c_api.c
+++ b/stack/l2cap/l2c_api.c
@@ -1489,6 +1489,12 @@ BOOLEAN L2CA_RemoveFixedChnl (UINT16 fixed_cid, BD_ADDR rem_bda)
14891489
14901490 p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL] = NULL;
14911491 p_lcb->disc_reason = HCI_ERR_CONN_CAUSE_LOCAL_HOST;
1492+
1493+#if BLE_INCLUDED == TRUE
1494+ if (fixed_cid == L2CAP_ATT_CID && !p_lcb->ccb_queue.p_first_ccb)
1495+ p_lcb->idle_timeout = 0;
1496+#endif
1497+
14921498 l2cu_release_ccb (p_ccb);
14931499
14941500 return (TRUE);