From e6d737780aa8df4649dbfffc8b2a8edad432261b Mon Sep 17 00:00:00 2001 From: zhiweijian Date: Fri, 28 Sep 2018 14:12:32 +0800 Subject: [PATCH] =?utf8?q?Component/bt:=20add=20=E2=80=9Cservice=20from?= =?utf8?q?=E2=80=9D=20param=20for=20ESP=5FGATTC=5FSEARCH=5FCMPL=5FEVT?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- components/bt/bluedroid/api/include/api/esp_gatt_defs.h | 5 +++++ components/bt/bluedroid/api/include/api/esp_gattc_api.h | 7 ++++--- components/bt/bluedroid/bta/gatt/bta_gattc_act.c | 2 ++ components/bt/bluedroid/bta/gatt/bta_gattc_cache.c | 2 +- components/bt/bluedroid/bta/gatt/bta_gattc_utils.c | 2 +- components/bt/bluedroid/bta/gatt/include/bta_gattc_int.h | 7 +++++++ components/bt/bluedroid/bta/include/bta/bta_gatt_api.h | 1 + components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c | 1 + examples/bluetooth/gatt_client/main/gattc_demo.c | 7 +++++++ .../gatt_security_client/main/example_ble_sec_gattc_demo.c | 7 +++++++ 10 files changed, 36 insertions(+), 5 deletions(-) diff --git a/components/bt/bluedroid/api/include/api/esp_gatt_defs.h b/components/bt/bluedroid/api/include/api/esp_gatt_defs.h index de4bc89769..d6c140a140 100644 --- a/components/bt/bluedroid/api/include/api/esp_gatt_defs.h +++ b/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) diff --git a/components/bt/bluedroid/api/include/api/esp_gattc_api.h b/components/bt/bluedroid/api/include/api/esp_gattc_api.h index b0fabb7a1b..f4a36de687 100644 --- a/components/bt/bluedroid/api/include/api/esp_gattc_api.h +++ b/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 diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_act.c b/components/bt/bluedroid/bta/gatt/bta_gattc_act.c index 29a9d47279..690b9c4efc 100644 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_act.c +++ b/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); diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_cache.c b/components/bt/bluedroid/bta/gatt/bta_gattc_cache.c index 2d6e9ee158..d9823d473a 100644 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_cache.c +++ b/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); diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c b/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c index 37193438a8..fd44375fa8 100644 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c +++ b/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); diff --git a/components/bt/bluedroid/bta/gatt/include/bta_gattc_int.h b/components/bt/bluedroid/bta/gatt/include/bta_gattc_int.h index 68887f0891..ad440c2bcd 100644 --- a/components/bt/bluedroid/bta/gatt/include/bta_gattc_int.h +++ b/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 */ diff --git a/components/bt/bluedroid/bta/include/bta/bta_gatt_api.h b/components/bt/bluedroid/bta/include/bta/bta_gatt_api.h index bc0539c152..0bfbf66936 100644 --- a/components/bt/bluedroid/bta/include/bta/bta_gatt_api.h +++ b/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 { diff --git a/components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c b/components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c index bb7d6cbbdf..4c45f829d5 100644 --- a/components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c +++ b/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, ¶m); break; } diff --git a/examples/bluetooth/gatt_client/main/gattc_demo.c b/examples/bluetooth/gatt_client/main/gattc_demo.c index e86841ae79..43799fe853 100644 --- a/examples/bluetooth/gatt_client/main/gattc_demo.c +++ b/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; diff --git a/examples/bluetooth/gatt_security_client/main/example_ble_sec_gattc_demo.c b/examples/bluetooth/gatt_security_client/main/example_ble_sec_gattc_demo.c index ed842b64cf..deb35da10d 100644 --- a/examples/bluetooth/gatt_security_client/main/example_ble_sec_gattc_demo.c +++ b/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; -- 2.50.1