]> granicus.if.org Git - esp-idf/commitdiff
Component/bt: add “service from” param for ESP_GATTC_SEARCH_CMPL_EVT
authorzhiweijian <zhiweijian@espressif.com>
Fri, 28 Sep 2018 06:12:32 +0000 (14:12 +0800)
committerbot <bot@espressif.com>
Fri, 28 Sep 2018 12:59:01 +0000 (12:59 +0000)
components/bt/bluedroid/api/include/api/esp_gatt_defs.h
components/bt/bluedroid/api/include/api/esp_gattc_api.h
components/bt/bluedroid/bta/gatt/bta_gattc_act.c
components/bt/bluedroid/bta/gatt/bta_gattc_cache.c
components/bt/bluedroid/bta/gatt/bta_gattc_utils.c
components/bt/bluedroid/bta/gatt/include/bta_gattc_int.h
components/bt/bluedroid/bta/include/bta/bta_gatt_api.h
components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c
examples/bluetooth/gatt_client/main/gattc_demo.c
examples/bluetooth/gatt_security_client/main/example_ble_sec_gattc_demo.c

index de4bc89769fca9abf8f40993dce7963dff2507ce..d6c140a1400b7a166676f13951a6e18d6263db40 100644 (file)
@@ -289,6 +289,11 @@ typedef uint8_t esp_gatt_char_prop_t;
 /// GATT maximum attribute length
 #define ESP_GATT_MAX_ATTR_LEN   600 //as same as GATT_MAX_ATTR_LEN
 
+typedef enum {
+    ESP_GATT_SERVICE_FROM_REMOTE_DEVICE         = 0,                                       /* relate to BTA_GATTC_SERVICE_INFO_FROM_REMOTE_DEVICE in bta_gattc_int.h */
+    ESP_GATT_SERVICE_FROM_NVS_FLASH             = 1,                                       /* relate to BTA_GATTC_SERVICE_INFO_FROM_NVS_FLASH in bta_gattc_int.h */
+    ESP_GATT_SERVICE_FROM_UNKNOWN               = 2,                                       /* relate to BTA_GATTC_SERVICE_INFO_FROM_UNKNOWN in bta_gattc_int.h */
+} esp_service_source_t;
 
 /**
  * @brief Attribute description (used to create database)
index b0fabb7a1b401361f879d9dd2540f291d3f577fe..f4a36de687a28990633a6b1ba2a98e944bed2bdb 100644 (file)
@@ -115,9 +115,10 @@ typedef union {
      * @brief ESP_GATTC_SEARCH_CMPL_EVT
      */
     struct gattc_search_cmpl_evt_param {
-        esp_gatt_status_t status;       /*!< Operation status */
-        uint16_t conn_id;               /*!< Connection id */
-    } search_cmpl;                      /*!< Gatt client callback param of ESP_GATTC_SEARCH_CMPL_EVT */
+        esp_gatt_status_t status;                     /*!< Operation status */
+        uint16_t conn_id;                             /*!< Connection id */
+        esp_service_source_t searched_service_source; /*!< The source of the service information */
+    } search_cmpl;                                    /*!< Gatt client callback param of ESP_GATTC_SEARCH_CMPL_EVT */
 
     /**
      * @brief ESP_GATTC_SEARCH_RES_EVT
index 29a9d47279aa721b685767b67f58c83bbbd85e2c..690b9c4efcde54f63db26f834930baa7436dc4c6 100644 (file)
@@ -983,6 +983,7 @@ void bta_gattc_start_discover(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
             } else {
                 p_clcb->disc_active = TRUE;
             }
+            p_clcb->searched_service_source = BTA_GATTC_SERVICE_INFO_FROM_REMOTE_DEVICE;
         } else {
             APPL_TRACE_ERROR("unknown device, can not start discovery");
         }
@@ -1471,6 +1472,7 @@ void bta_gattc_search(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
     }
     cb_data.search_cmpl.status  = status;
     cb_data.search_cmpl.conn_id = p_clcb->bta_conn_id;
+    cb_data.search_cmpl.searched_service_source = p_clcb->searched_service_source;
 
     /* end of search or no server cache available */
     ( *p_clcb->p_rcb->p_cback)(BTA_GATTC_SEARCH_CMPL_EVT,  &cb_data);
index 2d6e9ee15871651469213570cd4f205824c20158..d9823d473ac27593fe82f6c55903dc7d34be2b4d 100644 (file)
@@ -2116,7 +2116,7 @@ bool bta_gattc_cache_load(tBTA_GATTC_CLCB *p_clcb)
         APPL_TRACE_DEBUG("%s(), gattc cache load fail, status = %x", __func__, status);
         return false;
     }
-
+    p_clcb->searched_service_source = BTA_GATTC_SERVICE_INFO_FROM_NVS_FLASH;
     bta_gattc_rebuild_cache(p_clcb->p_srcb, num_attr, attr);
     //free the attr buffer after used.
     osi_free(attr);
index 37193438a81318aa020502c0bb1c8d4588b5dc73..fd44375fa826d2e467fbb81cee36366d68499f43 100644 (file)
@@ -229,7 +229,7 @@ tBTA_GATTC_CLCB *bta_gattc_clcb_alloc(tBTA_GATTC_IF client_if, BD_ADDR remote_bd
             p_clcb->status          = BTA_GATT_OK;
             p_clcb->transport       = transport;
             bdcpy(p_clcb->bda, remote_bda);
-
+            p_clcb->searched_service_source = BTA_GATTC_SERVICE_INFO_FROM_UNKNOWN;
             p_clcb->p_rcb = bta_gattc_cl_get_regcb(client_if);
             if (p_clcb->p_cmd_list == NULL) {
                 p_clcb->p_cmd_list = list_new(osi_free_func);
index 68887f0891cdd28ff5f3eaf47ca4cccad5045f6a..ad440c2bcdcfc735c3a8f3730682385cfa8a8f0b 100644 (file)
@@ -73,6 +73,12 @@ typedef UINT16 tBTA_GATTC_INT_EVT;
 
 #define BTA_GATTC_SERVICE_CHANGED_LEN    4
 
+typedef enum {
+    BTA_GATTC_SERVICE_INFO_FROM_REMOTE_DEVICE         = 0, 
+    BTA_GATTC_SERVICE_INFO_FROM_NVS_FLASH             = 1,
+    BTA_GATTC_SERVICE_INFO_FROM_UNKNOWN               = 2,
+} tBTA_SERVICE_SOURCE_t;
+
 /* max client application GATTC can support */
 #ifndef     BTA_GATTC_CL_MAX
 #if (GATT_MAX_PHY_CHANNEL > 3)
@@ -343,6 +349,7 @@ typedef struct {
     tBTA_GATTC_STATE    state;
     tBTA_GATT_STATUS    status;
     UINT16              reason;
+    UINT8               searched_service_source;
 } tBTA_GATTC_CLCB;
 
 /* background connection tracking information */
index bc0539c1525b4fdd6d38fef0178c4e5499cd2b7d..0bfbf669366ce50ff931eb817d53a680245d2e04 100644 (file)
@@ -315,6 +315,7 @@ typedef struct {
 typedef struct {
     UINT16              conn_id;
     tBTA_GATT_STATUS    status;
+    UINT8               searched_service_source;
 } tBTA_GATTC_SEARCH_CMPL;
 
 typedef struct {
index bb7d6cbbdfc2a931adadfd9fa12adf08dfc59885..4c45f829d527944f44f5c3f84531f127e01d37bb 100644 (file)
@@ -826,6 +826,7 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
         gattc_if = BTC_GATT_GET_GATT_IF(search_cmpl->conn_id);
         param.search_cmpl.conn_id = BTC_GATT_GET_CONN_ID(search_cmpl->conn_id);
         param.search_cmpl.status = search_cmpl->status;
+        param.search_cmpl.searched_service_source = search_cmpl->searched_service_source;
         btc_gattc_cb_to_app(ESP_GATTC_SEARCH_CMPL_EVT, gattc_if, &param);
         break;
     }
index e86841ae795864704913453fcf408720bce8f986..43799fe85314b41d6315e2bc3723933a66bf3d06 100644 (file)
@@ -150,6 +150,13 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
             ESP_LOGE(GATTC_TAG, "search service failed, error status = %x", p_data->search_cmpl.status);
             break;
         }
+        if(p_data->search_cmpl.searched_service_source == ESP_GATT_SERVICE_FROM_REMOTE_DEVICE) {
+            ESP_LOGI(GATTC_TAG, "Get service information from remote device");
+        } else if (p_data->search_cmpl.searched_service_source == ESP_GATT_SERVICE_FROM_NVS_FLASH) {
+            ESP_LOGI(GATTC_TAG, "Get service information from flash");
+        } else {
+            ESP_LOGI(GATTC_TAG, "unknown service source");
+        }
         ESP_LOGI(GATTC_TAG, "ESP_GATTC_SEARCH_CMPL_EVT");
         if (get_server){
             uint16_t count = 0;
index ed842b64cfae3687d515e60efd1a24e6f4be5f6a..deb35da10d3c7c0965610b1fd3b1fa3f1fba5fca 100644 (file)
@@ -173,6 +173,13 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
             ESP_LOGE(GATTC_TAG, "search service failed, error status = %x", p_data->search_cmpl.status);
             break;
         }
+        if(p_data->search_cmpl.searched_service_source == ESP_GATT_SERVICE_FROM_REMOTE_DEVICE) {
+            ESP_LOGI(GATTC_TAG, "Get service information from remote device");
+        } else if (p_data->search_cmpl.searched_service_source == ESP_GATT_SERVICE_FROM_NVS_FLASH) {
+            ESP_LOGI(GATTC_TAG, "Get service information from flash");
+        } else {
+            ESP_LOGI(GATTC_TAG, "unknown service source");
+        }
         if (get_service){
             uint16_t count  = 0;
             uint16_t offset = 0;