mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-01 18:50:34 +03:00
fix(nimble): Fix vulnerabilities in NimBLE examples
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
void send_heart_rate_indication(void);
|
||||
void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg);
|
||||
void gatt_svr_subscribe_cb(struct ble_gap_event *event);
|
||||
void gatt_svr_reset_heart_rate_subscription(void);
|
||||
int gatt_svc_init(void);
|
||||
|
||||
#endif // GATT_SVR_H
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
@@ -80,7 +80,7 @@ static void heart_rate_task(void *param) {
|
||||
|
||||
void app_main(void) {
|
||||
/* Local variables */
|
||||
int rc = 0;
|
||||
BaseType_t rc = 0;
|
||||
esp_err_t ret;
|
||||
|
||||
/* LED initialization */
|
||||
@@ -129,7 +129,17 @@ void app_main(void) {
|
||||
nimble_host_config_init();
|
||||
|
||||
/* Start NimBLE host task thread and return */
|
||||
xTaskCreate(nimble_host_task, "NimBLE Host", 4*1024, NULL, 5, NULL);
|
||||
xTaskCreate(heart_rate_task, "Heart Rate", 4*1024, NULL, 5, NULL);
|
||||
rc = xTaskCreate(nimble_host_task, "NimBLE Host", 4 * 1024, NULL,
|
||||
5, NULL);
|
||||
if (rc != pdPASS) {
|
||||
ESP_LOGE(TAG, "failed to create NimBLE host task");
|
||||
return;
|
||||
}
|
||||
|
||||
rc = xTaskCreate(heart_rate_task, "Heart Rate", 4 * 1024, NULL, 5, NULL);
|
||||
if (rc != pdPASS) {
|
||||
ESP_LOGE(TAG, "failed to create heart rate task");
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -186,6 +186,9 @@ static int gap_event_handler(struct ble_gap_event *event, void *arg) {
|
||||
ESP_LOGI(TAG, "disconnected from peer; reason=%d",
|
||||
event->disconnect.reason);
|
||||
|
||||
/* Reset heart rate subscription state */
|
||||
gatt_svr_reset_heart_rate_subscription();
|
||||
|
||||
/* Restart advertising */
|
||||
start_advertising();
|
||||
return rc;
|
||||
|
||||
@@ -23,7 +23,7 @@ static uint8_t heart_rate_chr_val[2] = {0};
|
||||
static uint16_t heart_rate_chr_val_handle;
|
||||
static const ble_uuid16_t heart_rate_chr_uuid = BLE_UUID16_INIT(0x2A37);
|
||||
|
||||
static uint16_t heart_rate_chr_conn_handle = 0;
|
||||
static uint16_t heart_rate_chr_conn_handle = BLE_HS_CONN_HANDLE_NONE;
|
||||
static bool heart_rate_chr_conn_handle_inited = false;
|
||||
static bool heart_rate_ind_status = false;
|
||||
|
||||
@@ -240,6 +240,12 @@ void gatt_svr_subscribe_cb(struct ble_gap_event *event) {
|
||||
}
|
||||
}
|
||||
|
||||
void gatt_svr_reset_heart_rate_subscription(void) {
|
||||
heart_rate_chr_conn_handle = BLE_HS_CONN_HANDLE_NONE;
|
||||
heart_rate_chr_conn_handle_inited = false;
|
||||
heart_rate_ind_status = false;
|
||||
}
|
||||
|
||||
/*
|
||||
* GATT server initialization
|
||||
* 1. Initialize GATT service
|
||||
|
||||
Reference in New Issue
Block a user