فهرست منبع

Component/bt: add “service from” param for ESP_GATTC_SEARCH_CMPL_EVT

zhiweijian 7 سال پیش
والد
کامیت
e6d737780a

+ 5 - 0
components/bt/bluedroid/api/include/api/esp_gatt_defs.h

@@ -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)

+ 4 - 3
components/bt/bluedroid/api/include/api/esp_gattc_api.h

@@ -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

+ 2 - 0
components/bt/bluedroid/bta/gatt/bta_gattc_act.c

@@ -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);

+ 1 - 1
components/bt/bluedroid/bta/gatt/bta_gattc_cache.c

@@ -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);

+ 1 - 1
components/bt/bluedroid/bta/gatt/bta_gattc_utils.c

@@ -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);

+ 7 - 0
components/bt/bluedroid/bta/gatt/include/bta_gattc_int.h

@@ -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 */

+ 1 - 0
components/bt/bluedroid/bta/include/bta/bta_gatt_api.h

@@ -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 {

+ 1 - 0
components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c

@@ -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;
     }

+ 7 - 0
examples/bluetooth/gatt_client/main/gattc_demo.c

@@ -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;

+ 7 - 0
examples/bluetooth/gatt_security_client/main/example_ble_sec_gattc_demo.c

@@ -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;