]> granicus.if.org Git - esp-idf/commitdiff
Component/bt: fix register multi service change when register multi gattc
authorzhiweijian <zhiweijian@espressif.com>
Tue, 26 Jun 2018 08:39:30 +0000 (16:39 +0800)
committerzhiweijian <zhiweijian@espressif.com>
Fri, 29 Jun 2018 11:54:22 +0000 (19:54 +0800)
components/bt/bluedroid/bta/gatt/bta_gattc_act.c
components/bt/bluedroid/bta/gatt/include/bta_gattc_int.h

index eaca767d6ae84be33099b2e4d30ab42efb61a561..29a9d47279aa721b685767b67f58c83bbbd85e2c 100644 (file)
@@ -672,6 +672,8 @@ void bta_gattc_conn(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
             if (bta_gattc_cache_load(p_clcb)) {
                 p_clcb->p_srcb->state = BTA_GATTC_SERV_IDLE;
                 bta_gattc_reset_discover_st(p_clcb->p_srcb, BTA_GATT_OK);
+                //register service change
+                bta_gattc_register_service_change_notify(p_clcb->bta_conn_id, p_clcb->bda);
             } else 
 #endif
             { /* cache is building */
@@ -1296,6 +1298,7 @@ void bta_gattc_write_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_OP_CMPL *p_data)
     cb_data.write.conn_id = p_clcb->bta_conn_id;
     if (p_conn && p_conn->svc_change_descr_handle == cb_data.write.handle) {
         if(cb_data.write.status != BTA_GATT_OK) {
+            p_conn->write_remote_svc_change_ccc_done = FALSE;
             APPL_TRACE_ERROR("service change write ccc failed");
         }
         return;
@@ -1875,6 +1878,10 @@ BOOLEAN bta_gattc_process_srvc_chg_ind(UINT16 conn_id,
 
             /* if connection available, refresh cache by doing discovery now */
             if (p_clcb != NULL) {
+                tBTA_GATTC_CONN *p_conn = bta_gattc_conn_find(p_clcb->bda);
+                if(p_conn) {
+                    p_conn->write_remote_svc_change_ccc_done = FALSE;
+                }
                 bta_gattc_sm_execute(p_clcb, BTA_GATTC_INT_DISCOVER_EVT, NULL);
             }
         }
@@ -2280,6 +2287,10 @@ tBTA_GATTC_FIND_SERVICE_CB bta_gattc_register_service_change_notify(UINT16 conn_
     tBT_UUID gatt_service_uuid = {LEN_UUID_16, {UUID_SERVCLASS_GATT_SERVER}};
     tBT_UUID gatt_service_change_uuid = {LEN_UUID_16, {GATT_UUID_GATT_SRV_CHGD}};
     tBT_UUID gatt_ccc_uuid = {LEN_UUID_16, {GATT_UUID_CHAR_CLIENT_CONFIG}};
+    tBTA_GATTC_CONN *p_conn = bta_gattc_conn_find_alloc(remote_bda);
+    if(p_conn && p_conn->write_remote_svc_change_ccc_done) {
+        return SERVICE_CHANGE_CCC_WRITTEN_SUCCESS;
+    }
 
     p_srcb = bta_gattc_find_srcb(remote_bda);
     if ((p_srcb != NULL) && (p_srcb->p_srvc_cache != NULL)) {
@@ -2344,9 +2355,9 @@ tBTA_GATTC_FIND_SERVICE_CB bta_gattc_register_service_change_notify(UINT16 conn_
     }
 
     if (gatt_ccc_found == TRUE){
-        tBTA_GATTC_CONN *p_conn = bta_gattc_conn_find_alloc(remote_bda);
         if (p_conn) {
             p_conn->svc_change_descr_handle = p_desc->handle;
+            p_conn->write_remote_svc_change_ccc_done = TRUE;
         }
         result = SERVICE_CHANGE_CCC_WRITTEN_SUCCESS;
         uint16_t indicate_value = GATT_CLT_CONFIG_INDICATION;
index 89864aacea9c455ba177b42153f0ccf029194628..2b550d908d971196ee16f687ae742d6788b9d8df 100644 (file)
@@ -365,7 +365,8 @@ typedef struct {
 typedef struct {
     BOOLEAN             in_use;
     BD_ADDR             remote_bda;
-    UINT16              svc_change_descr_handle; 
+    UINT16              svc_change_descr_handle;
+    BOOLEAN             write_remote_svc_change_ccc_done;
 } tBTA_GATTC_CONN;
 
 enum {