Skip to content

Commit

Permalink
Merge branch 'bugfix/fix_ble_conn_mgr_lock' into 'master'
Browse files Browse the repository at this point in the history
Check the status of the notification for ble_conn_mgr

See merge request ae_group/esp-iot-solution!775
  • Loading branch information
wujiangang committed Jan 22, 2024
2 parents 6871058 + bafa66a commit 3327672
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 6 deletions.
6 changes: 6 additions & 0 deletions components/bluetooth/ble_conn_mgr/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v0.1.1 - 2023-6-12

### Bug Fixes:

- Add duration to wait for write data completed

## v0.1.0

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).
Expand Down
7 changes: 7 additions & 0 deletions components/bluetooth/ble_conn_mgr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ menu "BLE Connection Management"
default 1 if BLE_CONN_MGR_ROLE_CENTRAL
default 2 if BLE_CONN_MGR_ROLE_BOTH

config BLE_CONN_MGR_WAIT_DURATION
int "Duration to wait for completed"
range 10 31
default 31
help
Set the duration to wait for completed. Use a value big enough to avoid retransmissions.

config BLE_CONN_MGR_EXTENDED_ADV
bool
depends on BLE_CONN_MGR_ROLE_PERIPHERAL || BLE_CONN_MGR_ROLE_BOTH && SOC_BLE_50_SUPPORTED
Expand Down
2 changes: 1 addition & 1 deletion components/bluetooth/ble_conn_mgr/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "0.1.0"
version: "0.1.1"
description: A common layer to manage the BLE connection, support both Bluedroid and Nimble
url: https://github.com/espressif/esp-iot-solution/tree/master/components/bluetooth/ble_conn_mgr
dependencies:
Expand Down
14 changes: 14 additions & 0 deletions components/bluetooth/ble_conn_mgr/include/esp_ble_conn_mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ extern "C"
#define BLE_CONN_GATT_CHR_NOTIFY 0x0010 /*!< Characteristic notify properties */
#define BLE_CONN_GATT_CHR_INDICATE 0x0020 /*!< Characteristic indicate properties */

/**
* @brief This is type of function that will handle the registered characteristic
*
* @param[in] inbuf The pointer to store data: read operation if NULL or write operation if not NULL
* @param[in] inlen The store data length
* @param[out] outbuf Variable to store data, it'll free by connection management component
* @param[out] outlen Variable to store data length
* @param[in] priv_data Private data context
*
* @return
* - ESP_OK on successful
* - ESP_ERR_INVALID_ARG on wrong parameter
* - ESP_FAIL on error
*/
typedef esp_err_t (*esp_ble_conn_cb_t)(const uint8_t *inbuf,
uint16_t inlen,
uint8_t **outbuf,
Expand Down
17 changes: 12 additions & 5 deletions components/bluetooth/ble_conn_mgr/src/esp_nimble.c
Original file line number Diff line number Diff line change
Expand Up @@ -1336,8 +1336,14 @@ static int esp_ble_conn_gap_event(struct ble_gap_event *event, void *arg)
#endif
#endif
case BLE_GAP_EVENT_NOTIFY_TX:
if ((event->notify_tx.status == BLE_HS_EDONE) || (event->notify_tx.status == BLE_HS_ETIMEOUT)) {
xSemaphoreGive(conn_session->semaphore);
if (event->notify_tx.indication) {
if ((event->notify_tx.status == BLE_HS_EDONE) || (event->notify_tx.status == BLE_HS_ETIMEOUT)) {
xSemaphoreGive(conn_session->semaphore);
}
} else {
if (event->notify_tx.status == 0) {
xSemaphoreGive(conn_session->semaphore);
}
}
break;
case BLE_GAP_EVENT_CONNECT:
Expand Down Expand Up @@ -2258,6 +2264,7 @@ esp_err_t esp_ble_conn_notify(const esp_ble_conn_data_t *inbuff)
rc = ble_gattc_notify_custom(conn_session->conn_handle, attr_mbuf->attr_handle, om);
if (!rc) {
ESP_LOGD(TAG, "Notify sent, attr_handle = %d", attr_mbuf->attr_handle);
return (xSemaphoreTake(conn_session->semaphore, pdMS_TO_TICKS(CONFIG_BLE_CONN_MGR_WAIT_DURATION * 1000)) != pdPASS) ? ESP_ERR_TIMEOUT : ESP_OK;
} else {
ESP_LOGE(TAG, "Error in sending notify, rc = %d", rc);
}
Expand Down Expand Up @@ -2319,7 +2326,7 @@ esp_err_t esp_ble_conn_read(esp_ble_conn_data_t *inbuff)
return rc;
}

if (xSemaphoreTake(conn_session->semaphore, pdMS_TO_TICKS(31 * 1000)) != pdPASS) {
if (xSemaphoreTake(conn_session->semaphore, pdMS_TO_TICKS(CONFIG_BLE_CONN_MGR_WAIT_DURATION * 1000)) != pdPASS) {
return ESP_ERR_TIMEOUT;
}
#endif
Expand Down Expand Up @@ -2403,7 +2410,7 @@ esp_err_t esp_ble_conn_write(const esp_ble_conn_data_t *inbuff)

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

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

0 comments on commit 3327672

Please sign in to comment.