From 00cdf62ce77a3bee2148bf4ba7add092cb451409 Mon Sep 17 00:00:00 2001 From: Yulong Date: Tue, 16 May 2017 09:10:37 -0400 Subject: [PATCH 1/3] component/bt: fixed the discover primary service not correct if server changes service during disconnect period. --- components/bt/bluedroid/api/esp_gattc_api.c | 17 +++++++++++++++++ .../bluedroid/btc/profile/std/gatt/btc_gattc.c | 3 +++ .../btc/profile/std/include/btc_gattc.h | 7 ++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/components/bt/bluedroid/api/esp_gattc_api.c b/components/bt/bluedroid/api/esp_gattc_api.c index bb368a68de..1b4714d437 100644 --- a/components/bt/bluedroid/api/esp_gattc_api.c +++ b/components/bt/bluedroid/api/esp_gattc_api.c @@ -482,5 +482,22 @@ esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gattc_if, return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); } +esp_gatt_status_t esp_ble_gattc_cache_refresh(esp_bd_addr_t remote_bda) +{ + btc_msg_t msg; + btc_ble_gattc_args_t arg; + + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GATTC; + msg.act = BTC_GATTC_ACT_CACHE_REFRESH; + memcpy(arg.cache_refresh.remote_bda, remote_bda, sizeof(esp_bd_addr_t)); + + return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} + #endif ///GATTC_INCLUDED == TRUE 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 4d126ff6c3..eaeb904a4d 100644 --- a/components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c +++ b/components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c @@ -551,6 +551,9 @@ void btc_gattc_call_handler(btc_msg_t *msg) case BTC_GATTC_ACT_UNREG_FOR_NOTIFY: btc_gattc_unreg_for_notify(arg); break; + case BTC_GATTC_ACT_CACHE_REFRESH: + BTA_GATTC_Refresh(arg->cache_refresh.remote_bda); + break; default: LOG_ERROR("%s: Unhandled event (%d)!\n", __FUNCTION__, msg->act); break; diff --git a/components/bt/bluedroid/btc/profile/std/include/btc_gattc.h b/components/bt/bluedroid/btc/profile/std/include/btc_gattc.h index 2528668381..1374dc0a72 100644 --- a/components/bt/bluedroid/btc/profile/std/include/btc_gattc.h +++ b/components/bt/bluedroid/btc/profile/std/include/btc_gattc.h @@ -41,7 +41,8 @@ typedef enum { BTC_GATTC_ACT_PREPARE_WRITE_CHAR_DESCR, BTC_GATTC_ACT_EXECUTE_WRITE, BTC_GATTC_ACT_REG_FOR_NOTIFY, - BTC_GATTC_ACT_UNREG_FOR_NOTIFY + BTC_GATTC_ACT_UNREG_FOR_NOTIFY, + BTC_GATTC_ACT_CACHE_REFRESH, } btc_gattc_act_t; /* btc_ble_gattc_args_t */ @@ -186,6 +187,10 @@ typedef union { esp_gatt_srvc_id_t service_id; esp_gatt_id_t char_id; } unreg_for_notify; + //BTC_GATTC_ACT_CACHE_REFRESH, + struct cache_refresh_arg { + esp_bd_addr_t remote_bda; + } cache_refresh; } btc_ble_gattc_args_t; void btc_gattc_call_handler(btc_msg_t *msg); From 8f1a6989eefd9edb1dc3f1f689cb3af6aa3a28f1 Mon Sep 17 00:00:00 2001 From: Yulong Date: Thu, 18 May 2017 02:07:16 -0400 Subject: [PATCH 2/3] component/bt: Added the declaration for esp_ble_gattc_cache_refresh in the gattc api header file. --- components/bt/bluedroid/api/include/esp_gattc_api.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/components/bt/bluedroid/api/include/esp_gattc_api.h b/components/bt/bluedroid/api/include/esp_gattc_api.h index ae53bf5751..43267f311e 100644 --- a/components/bt/bluedroid/api/include/esp_gattc_api.h +++ b/components/bt/bluedroid/api/include/esp_gattc_api.h @@ -629,6 +629,19 @@ esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gattc_if, esp_gatt_srvc_id_t *srvc_id, esp_gatt_id_t *char_id); + +/** +* @brief Refresh the server cache store in the gattc stack of the remote device +* +* @param[in] remote_bda: remote device BD address. +* +* @return +* - ESP_OK: unregister succeeds +* - other: failed +* +*/ +esp_gatt_status_t esp_ble_gattc_cache_refresh(esp_bd_addr_t remote_bda); + #ifdef __cplusplus } #endif From b401bbc4d643e1dd32a3fd183217472e346a6084 Mon Sep 17 00:00:00 2001 From: Yulong Date: Thu, 18 May 2017 02:11:42 -0400 Subject: [PATCH 3/3] component/bt: change the esp_ble_gattc_cache_refresh API return value from esp_gatt_status_t to esp_err_t. --- components/bt/bluedroid/api/esp_gattc_api.c | 2 +- components/bt/bluedroid/api/include/esp_gattc_api.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/bt/bluedroid/api/esp_gattc_api.c b/components/bt/bluedroid/api/esp_gattc_api.c index 1b4714d437..b80966cd86 100644 --- a/components/bt/bluedroid/api/esp_gattc_api.c +++ b/components/bt/bluedroid/api/esp_gattc_api.c @@ -482,7 +482,7 @@ esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gattc_if, return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); } -esp_gatt_status_t esp_ble_gattc_cache_refresh(esp_bd_addr_t remote_bda) +esp_err_t esp_ble_gattc_cache_refresh(esp_bd_addr_t remote_bda) { btc_msg_t msg; btc_ble_gattc_args_t arg; diff --git a/components/bt/bluedroid/api/include/esp_gattc_api.h b/components/bt/bluedroid/api/include/esp_gattc_api.h index 43267f311e..c2cae797b7 100644 --- a/components/bt/bluedroid/api/include/esp_gattc_api.h +++ b/components/bt/bluedroid/api/include/esp_gattc_api.h @@ -636,11 +636,11 @@ esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gattc_if, * @param[in] remote_bda: remote device BD address. * * @return -* - ESP_OK: unregister succeeds +* - ESP_OK: success * - other: failed * */ -esp_gatt_status_t esp_ble_gattc_cache_refresh(esp_bd_addr_t remote_bda); +esp_err_t esp_ble_gattc_cache_refresh(esp_bd_addr_t remote_bda); #ifdef __cplusplus }