]> granicus.if.org Git - esp-idf/commitdiff
component/bt: Fix the write value not store in the queue command bug.
authorYulong <huangyulong@espressif.com>
Wed, 8 Nov 2017 09:23:12 +0000 (04:23 -0500)
committeryulong <huangyulong@espressif.com>
Thu, 9 Nov 2017 06:47:11 +0000 (14:47 +0800)
components/bt/bluedroid/bta/gatt/bta_gattc_act.c
components/bt/bluedroid/bta/gatt/bta_gattc_utils.c
components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c

index d7a13bd3f8e089553eaa43a78acc01f2eb7bc71d..c5a2990d9ddbdc1b91b358f1a2efd87daa994ed3 100644 (file)
@@ -1478,6 +1478,9 @@ static void bta_gattc_pop_command_to_send(tBTA_GATTC_CLCB *p_clcb)
         if (p_data != NULL) {
             /* execute pending operation of link block still present */
             if (l2cu_find_lcb_by_bd_addr(p_clcb->p_srcb->server_bda, BT_TRANSPORT_LE) != NULL) {
+                if (p_data->hdr.event == BTA_GATTC_API_WRITE_EVT) {
+                    APPL_TRACE_ERROR("%s(), p_data = %d", __func__, p_data->api_write.p_value[0]);
+                }
                 // The data to be sent to the gattc state machine for processing
                 if(bta_gattc_sm_execute(p_clcb, p_data->hdr.event, p_data)) {
                     list_remove(p_clcb->p_cmd_list, (void *)p_data);
@@ -1497,6 +1500,7 @@ static void bta_gattc_pop_command_to_send(tBTA_GATTC_CLCB *p_clcb)
 *******************************************************************************/
 void bta_gattc_free_command_data(tBTA_GATTC_CLCB *p_clcb)
 {
+    assert(p_clcb->p_cmd_list);
     //Check the list is empty or not.
     if (!list_is_empty(p_clcb->p_cmd_list)) {
         /* Traversal the command queue, check the p_q_cmd is point to the queue data or not, if the p_q_cmd point to the
index a91d52329307ff353399f38669851f002576d6be..a4b8523f592461e56f3234007733bc674eeb0a62 100644 (file)
@@ -48,6 +48,8 @@ static const UINT8  base_uuid[LEN_UUID_128] = {0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x0
 
 static const BD_ADDR dummy_bda = {0, 0, 0, 0, 0, 0};
 
+#define GATTC_COMMAND_QUEUE_SIZE_MAX    30
+
 /*******************************************************************************
 **
 ** Function         bta_gatt_convert_uuid16_to_uuid128
@@ -452,13 +454,28 @@ BOOLEAN bta_gattc_enqueue(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
         return FALSE;
     }
     else if (p_clcb->p_cmd_list) {
-        void *cmd_data = osi_malloc(sizeof(tBTA_GATTC_DATA));
-        if (cmd_data) {
+               UINT16 len = 0;
+               tBTA_GATTC_DATA *cmd_data = NULL;
+               if (list_length(p_clcb->p_cmd_list) >= GATTC_COMMAND_QUEUE_SIZE_MAX) {
+            //APPL_TRACE_ERROR("%s(), the gattc command queue is full." __func__);
+                       return FALSE;
+               }
+
+               if (p_data->hdr.event == BTA_GATTC_API_WRITE_EVT) {
+            len = p_data->api_write.len;
+                       cmd_data = (tBTA_GATTC_DATA *)osi_malloc(sizeof(tBTA_GATTC_DATA) + len);
+
+                       cmd_data->api_write.p_value = (UINT8 *)(cmd_data + 1);
+                       memcpy(cmd_data, p_data, sizeof(tBTA_GATTC_DATA));
+                       memcpy(cmd_data->api_write.p_value, p_data->api_write.p_value, len);
+               } else {
+                   cmd_data = (tBTA_GATTC_DATA *)osi_malloc(sizeof(tBTA_GATTC_DATA));
             memset(cmd_data, 0, sizeof(tBTA_GATTC_DATA));
             memcpy(cmd_data, p_data, sizeof(tBTA_GATTC_DATA));
-            //store the command to the command list.
-            list_append(p_clcb->p_cmd_list, cmd_data);
         }
+
+        //store the command to the command list.
+        list_append(p_clcb->p_cmd_list, (void *)cmd_data);
         return FALSE;
     }
 
index 5b33f0f77c0fb8926e5ada902e7c503e5c4a2a6e..c13b9ff0e26822fbef2344631ffb128701dc96a3 100644 (file)
@@ -253,7 +253,7 @@ static void btc_gattc_fill_gatt_db_conversion(uint16_t count, uint16_t num, esp_
         }
         case ESP_GATT_DB_DESCRIPTOR: {
             esp_gattc_descr_elem_t *descr_result = (esp_gattc_descr_elem_t *)result;
-            for (int i = 0; i < (num - offset); i++) {
+            for (int i = 0; i < db_size; i++) {
                 descr_result->handle = db[offset + i].attribute_handle;
                 btc128_to_bta_uuid(&bta_uuid, db[offset + i].uuid.uu);
                 bta_to_btc_uuid(&descr_result->uuid, &bta_uuid);