fix(nimble): Added security related fixes

This commit is contained in:
Shreeyash Bhakare
2026-06-11 17:02:24 +05:30
committed by Rahul Tank
parent b522b887ab
commit a2739c9ee1
3 changed files with 13 additions and 8 deletions

View File

@@ -159,17 +159,17 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_
adv_config_done |= scan_rsp_config_flag;
break;
case ESP_GATTS_READ_EVT:
if (g_ble_cfg_p) {
if (g_ble_cfg_p && g_ble_cfg_p->read_fn) {
g_ble_cfg_p->read_fn(event, gatts_if, param);
}
break;
case ESP_GATTS_WRITE_EVT:
if (g_ble_cfg_p) {
if (g_ble_cfg_p && g_ble_cfg_p->write_fn) {
g_ble_cfg_p->write_fn(event, gatts_if, param);
}
break;
case ESP_GATTS_EXEC_WRITE_EVT:
if (g_ble_cfg_p) {
if (g_ble_cfg_p && g_ble_cfg_p->exec_write_fn) {
g_ble_cfg_p->exec_write_fn(event, gatts_if, param);
}
break;
@@ -187,7 +187,7 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_
break;
case ESP_GATTS_CONNECT_EVT:
ESP_LOGD(TAG, "ESP_GATTS_CONNECT_EVT, conn_id = %d", param->connect.conn_id);
if (g_ble_cfg_p) {
if (g_ble_cfg_p && g_ble_cfg_p->connect_fn) {
g_ble_cfg_p->connect_fn(event, gatts_if, param);
}
esp_ble_conn_update_params_t conn_params = {0};
@@ -202,7 +202,7 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_
break;
case ESP_GATTS_DISCONNECT_EVT:
ESP_LOGD(TAG, "ESP_GATTS_DISCONNECT_EVT, reason = %d", param->disconnect.reason);
if (g_ble_cfg_p) {
if (g_ble_cfg_p && g_ble_cfg_p->disconnect_fn) {
g_ble_cfg_p->disconnect_fn(event, gatts_if, param);
}
memset(s_cached_remote_bda, 0, sizeof(esp_bd_addr_t));
@@ -263,7 +263,6 @@ esp_err_t simple_ble_deinit(void)
simple_ble_cfg_t *ble_cfg = g_ble_cfg_p;
g_ble_cfg_p = NULL;
if (ble_cfg) {
free(ble_cfg->gatt_db);
ble_cfg->gatt_db = NULL;
free(ble_cfg);
}

View File

@@ -74,6 +74,7 @@ typedef struct _protocomm_ble {
} _protocomm_ble_internal_t;
static _protocomm_ble_internal_t *protoble_internal;
static esp_gatts_attr_db_t *s_gatt_db;
static bool protocomm_ble_transport_active(void)
{
@@ -715,6 +716,8 @@ static ssize_t populate_gatt_db(esp_gatts_attr_db_t **gatt_db_generated)
static void protocomm_ble_cleanup(void)
{
protocomm_ble_reset_prepare_write();
free(s_gatt_db);
s_gatt_db = NULL;
if (protoble_internal) {
if (protoble_internal->service_uuid) {
free(protoble_internal->service_uuid);
@@ -891,6 +894,7 @@ esp_err_t protocomm_ble_start(protocomm_t *pc, const protocomm_ble_config_t *con
ble_config->device_name = protocomm_ble_device_name;
ble_config->gatt_db_count = populate_gatt_db(&ble_config->gatt_db);
s_gatt_db = ble_config->gatt_db;
ble_config->ble_bonding = config->ble_bonding;
ble_config->ble_sm_sc = config->ble_sm_sc;
@@ -904,7 +908,9 @@ esp_err_t protocomm_ble_start(protocomm_t *pc, const protocomm_ble_config_t *con
if (ble_config->gatt_db_count == -1) {
ESP_LOGE(TAG, "Invalid GATT database count");
free(ble_config->gatt_db);
free(s_gatt_db);
s_gatt_db = NULL;
ble_config->gatt_db = NULL;
free(ble_config);
protocomm_ble_cleanup();
return ESP_ERR_INVALID_STATE;