Skip to content

Commit 3327672

Browse files
committed
Merge branch 'bugfix/fix_ble_conn_mgr_lock' into 'master'
Check the status of the notification for ble_conn_mgr See merge request ae_group/esp-iot-solution!775
2 parents 6871058 + bafa66a commit 3327672

File tree

5 files changed

+40
-6
lines changed

5 files changed

+40
-6
lines changed

components/bluetooth/ble_conn_mgr/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v0.1.1 - 2023-6-12
2+
3+
### Bug Fixes:
4+
5+
- Add duration to wait for write data completed
6+
17
## v0.1.0
28

39
This is the first release version for BLE connection management component in Espressif Component Registry, more detailed descriptions about the project, please refer to [User_Guide](https://docs.espressif.com/projects/esp-iot-solution/en/latest/bluetooth/ble_conn_mgr.html).

components/bluetooth/ble_conn_mgr/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ menu "BLE Connection Management"
2020
default 1 if BLE_CONN_MGR_ROLE_CENTRAL
2121
default 2 if BLE_CONN_MGR_ROLE_BOTH
2222

23+
config BLE_CONN_MGR_WAIT_DURATION
24+
int "Duration to wait for completed"
25+
range 10 31
26+
default 31
27+
help
28+
Set the duration to wait for completed. Use a value big enough to avoid retransmissions.
29+
2330
config BLE_CONN_MGR_EXTENDED_ADV
2431
bool
2532
depends on BLE_CONN_MGR_ROLE_PERIPHERAL || BLE_CONN_MGR_ROLE_BOTH && SOC_BLE_50_SUPPORTED

components/bluetooth/ble_conn_mgr/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "0.1.0"
1+
version: "0.1.1"
22
description: A common layer to manage the BLE connection, support both Bluedroid and Nimble
33
url: https://github.com/espressif/esp-iot-solution/tree/master/components/bluetooth/ble_conn_mgr
44
dependencies:

components/bluetooth/ble_conn_mgr/include/esp_ble_conn_mgr.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ extern "C"
2929
#define BLE_CONN_GATT_CHR_NOTIFY 0x0010 /*!< Characteristic notify properties */
3030
#define BLE_CONN_GATT_CHR_INDICATE 0x0020 /*!< Characteristic indicate properties */
3131

32+
/**
33+
* @brief This is type of function that will handle the registered characteristic
34+
*
35+
* @param[in] inbuf The pointer to store data: read operation if NULL or write operation if not NULL
36+
* @param[in] inlen The store data length
37+
* @param[out] outbuf Variable to store data, it'll free by connection management component
38+
* @param[out] outlen Variable to store data length
39+
* @param[in] priv_data Private data context
40+
*
41+
* @return
42+
* - ESP_OK on successful
43+
* - ESP_ERR_INVALID_ARG on wrong parameter
44+
* - ESP_FAIL on error
45+
*/
3246
typedef esp_err_t (*esp_ble_conn_cb_t)(const uint8_t *inbuf,
3347
uint16_t inlen,
3448
uint8_t **outbuf,

components/bluetooth/ble_conn_mgr/src/esp_nimble.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,8 +1336,14 @@ static int esp_ble_conn_gap_event(struct ble_gap_event *event, void *arg)
13361336
#endif
13371337
#endif
13381338
case BLE_GAP_EVENT_NOTIFY_TX:
1339-
if ((event->notify_tx.status == BLE_HS_EDONE) || (event->notify_tx.status == BLE_HS_ETIMEOUT)) {
1340-
xSemaphoreGive(conn_session->semaphore);
1339+
if (event->notify_tx.indication) {
1340+
if ((event->notify_tx.status == BLE_HS_EDONE) || (event->notify_tx.status == BLE_HS_ETIMEOUT)) {
1341+
xSemaphoreGive(conn_session->semaphore);
1342+
}
1343+
} else {
1344+
if (event->notify_tx.status == 0) {
1345+
xSemaphoreGive(conn_session->semaphore);
1346+
}
13411347
}
13421348
break;
13431349
case BLE_GAP_EVENT_CONNECT:
@@ -2258,6 +2264,7 @@ esp_err_t esp_ble_conn_notify(const esp_ble_conn_data_t *inbuff)
22582264
rc = ble_gattc_notify_custom(conn_session->conn_handle, attr_mbuf->attr_handle, om);
22592265
if (!rc) {
22602266
ESP_LOGD(TAG, "Notify sent, attr_handle = %d", attr_mbuf->attr_handle);
2267+
return (xSemaphoreTake(conn_session->semaphore, pdMS_TO_TICKS(CONFIG_BLE_CONN_MGR_WAIT_DURATION * 1000)) != pdPASS) ? ESP_ERR_TIMEOUT : ESP_OK;
22612268
} else {
22622269
ESP_LOGE(TAG, "Error in sending notify, rc = %d", rc);
22632270
}
@@ -2319,7 +2326,7 @@ esp_err_t esp_ble_conn_read(esp_ble_conn_data_t *inbuff)
23192326
return rc;
23202327
}
23212328

2322-
if (xSemaphoreTake(conn_session->semaphore, pdMS_TO_TICKS(31 * 1000)) != pdPASS) {
2329+
if (xSemaphoreTake(conn_session->semaphore, pdMS_TO_TICKS(CONFIG_BLE_CONN_MGR_WAIT_DURATION * 1000)) != pdPASS) {
23232330
return ESP_ERR_TIMEOUT;
23242331
}
23252332
#endif
@@ -2403,7 +2410,7 @@ esp_err_t esp_ble_conn_write(const esp_ble_conn_data_t *inbuff)
24032410

24042411
if (!rc) {
24052412
ESP_LOGD(TAG, "Sent data, attr_handle = %d", chr_val_handle);
2406-
return (xSemaphoreTake(conn_session->semaphore, pdMS_TO_TICKS(31 * 1000)) != pdPASS) ? ESP_ERR_TIMEOUT : ESP_OK;
2413+
return (xSemaphoreTake(conn_session->semaphore, pdMS_TO_TICKS(CONFIG_BLE_CONN_MGR_WAIT_DURATION * 1000)) != pdPASS) ? ESP_ERR_TIMEOUT : ESP_OK;
24072414
} else {
24082415
ESP_LOGE(TAG, "Error in sending data, rc = %d", rc);
24092416
}
@@ -2475,7 +2482,7 @@ esp_err_t esp_ble_conn_subscribe(esp_ble_conn_desc_t desc, const esp_ble_conn_da
24752482

24762483
if (!rc) {
24772484
ESP_LOGD(TAG, "Descriptors data, attr_handle = %d", handle);
2478-
return (xSemaphoreTake(conn_session->semaphore, pdMS_TO_TICKS(31 * 1000)) != pdPASS) ? ESP_ERR_TIMEOUT : ESP_OK;
2485+
return (xSemaphoreTake(conn_session->semaphore, pdMS_TO_TICKS(CONFIG_BLE_CONN_MGR_WAIT_DURATION * 1000)) != pdPASS) ? ESP_ERR_TIMEOUT : ESP_OK;
24792486
} else {
24802487
ESP_LOGE(TAG, "Error in descriptors data, rc = %d", rc);
24812488
}

0 commit comments

Comments
 (0)