]> granicus.if.org Git - esp-idf/commitdiff
Component/bt: fix get attr value API error
authorzhiweijian <zhiweijian@espressif.com>
Tue, 30 Oct 2018 07:00:23 +0000 (15:00 +0800)
committerzhiweijian <zhiweijian@espressif.com>
Tue, 30 Oct 2018 07:00:23 +0000 (15:00 +0800)
components/bt/bluedroid/api/esp_gatts_api.c
components/bt/bluedroid/stack/gatt/gatt_api.c
components/bt/bluedroid/stack/gatt/gatt_db.c

index 2b3b0ba807d30d7ff7a1193e5bd8e460edb64101..80d89b30bbfdd5c9e09cd09bec89aed74c42d32a 100644 (file)
@@ -321,6 +321,7 @@ esp_gatt_status_t esp_ble_gatts_get_attr_value(uint16_t attr_handle, uint16_t *l
     ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
 
     if (attr_handle == ESP_GATT_ILLEGAL_HANDLE) {
+        *length = 0;
         return ESP_GATT_INVALID_HANDLE;
     }
 
index cbc37e3aa3c88c73ce4c9a61c8e156c65ec2fa4b..e6ea5b4f0486b245457c290ea99ea604182616a5 100644 (file)
@@ -766,7 +766,8 @@ tGATT_STATUS GATTS_GetAttributeValue(UINT16 attr_handle, UINT16 *length, UINT8 *
                     attr_handle);
 
      if ((p_decl = gatt_find_hdl_buffer_by_attr_handle(attr_handle)) == NULL) {
-         GATT_TRACE_ERROR("Service not created\n"); 
+         GATT_TRACE_ERROR("Service not created\n");
+         *length = 0;
          return GATT_INVALID_HANDLE;
      }
 
index 5b822b25d278a0f12fb4d05130ccababe49f52d9..8a051174823bf37258c8c5f637c08b5fe3427657 100644 (file)
@@ -783,10 +783,12 @@ tGATT_STATUS gatts_get_attribute_value(tGATT_SVC_DB *p_db, UINT16 attr_handle,
 
     if (p_db == NULL) {
         GATT_TRACE_ERROR("gatts_get_attribute_value Fail:p_db is NULL.\n");
+        *length = 0;
         return GATT_INVALID_PDU;
     }
     if (p_db->p_attr_list == NULL) {
         GATT_TRACE_ERROR("gatts_get_attribute_value Fail:p_db->p_attr_list is NULL.\n");
+        *length = 0;
         return GATT_INVALID_PDU;
     }
     if (length == NULL){
@@ -795,6 +797,7 @@ tGATT_STATUS gatts_get_attribute_value(tGATT_SVC_DB *p_db, UINT16 attr_handle,
     }
     if (value == NULL){
         GATT_TRACE_ERROR("gatts_get_attribute_value Fail:value is NULL.\n");
+        *length = 0;
         return GATT_INVALID_PDU;
     }
 
@@ -814,19 +817,19 @@ tGATT_STATUS gatts_get_attribute_value(tGATT_SVC_DB *p_db, UINT16 attr_handle,
                         *value = p_cur->p_value->attr_val.attr_val;
                         return GATT_SUCCESS;
                     } else {
-                        GATT_TRACE_ERROR("gatts_get_attribute_value failed:the value length is 0");
-                        return GATT_INVALID_ATTR_LEN;
+                        *length = 0;
+                        return GATT_SUCCESS;
                     }
                     break;
                 }
             } else {
-                if (p_cur->p_value->attr_val.attr_len != 0) {
+                if (p_cur->p_value && p_cur->p_value->attr_val.attr_len != 0) {
                     *length = p_cur->p_value->attr_val.attr_len;
                     *value = p_cur->p_value->attr_val.attr_val;
                     return GATT_SUCCESS;
                 } else {
-                    GATT_TRACE_ERROR("gatts_get_attribute_value failed:the value length is 0");
-                    return GATT_INVALID_ATTR_LEN;
+                    *length = 0;
+                    return GATT_SUCCESS;
                 }
 
             }