Merge branch 'bugfix/wifi_prov_mgr_conn_issue' into 'release/v4.3'

NimBLE: Fixed device disconnection issue of wifi prov mgr

Closes IDF-4655

See merge request espressif/esp-idf!17621
This commit is contained in:
Isha Pardikar 2022-02-17 18:42:25 +05:30
parent eeea576409
commit 6a92fb2d76
7 changed files with 53 additions and 13 deletions

View File

@ -84,6 +84,11 @@ typedef struct protocomm_ble_config {
*/
unsigned ble_bonding:1;
/**
* BLE security flag
*/
unsigned ble_sm_sc:1;
} protocomm_ble_config_t;
/**

View File

@ -266,11 +266,12 @@ esp_err_t simple_ble_start(simple_ble_cfg_t *cfg)
ESP_LOGD(TAG, "Free mem at end of simple_ble_init %d", esp_get_free_heap_size());
/* set the security iocap & auth_req & key size & init key response key parameters to the stack*/
esp_ble_auth_req_t auth_req;
esp_ble_auth_req_t auth_req= ESP_LE_AUTH_REQ_MITM;
if (cfg->ble_bonding) {
auth_req = ESP_LE_AUTH_REQ_SC_MITM_BOND; //bonding with peer device after authentication
} else {
auth_req = ESP_LE_AUTH_REQ_SC_MITM;
auth_req |= ESP_LE_AUTH_BOND; //bonding with peer device after authentication
}
if (cfg->ble_sm_sc) {
auth_req |= ESP_LE_AUTH_REQ_SC_ONLY;
}
esp_ble_io_cap_t iocap = ESP_IO_CAP_NONE; //set the IO capability to No output No input
uint8_t key_size = 16; //the key size should be 7~16 bytes

View File

@ -49,8 +49,10 @@ typedef struct {
simple_ble_cb_t *connect_fn;
/** MTU set callback */
simple_ble_cb_t *set_mtu_fn;
/** BLE bonding **/
unsigned ble_bonding:1;
/** BLE bonding */
unsigned ble_bonding:1;
/** BLE Secure Connection flag */
unsigned ble_sm_sc:1;
} simple_ble_cfg_t;

View File

@ -646,6 +646,7 @@ esp_err_t protocomm_ble_start(protocomm_t *pc, const protocomm_ble_config_t *con
ble_config->gatt_db_count = populate_gatt_db(&ble_config->gatt_db);
ble_config->ble_bonding = config->ble_bonding;
ble_config->ble_sm_sc = config->ble_sm_sc;
if (ble_config->gatt_db_count == -1) {
ESP_LOGE(TAG, "Invalid GATT database count");

View File

@ -121,8 +121,10 @@ typedef struct {
simple_ble_cb_t *connect_fn;
/** MTU set callback */
simple_ble_cb_t *set_mtu_fn;
/** BLE bonding **/
unsigned ble_bonding:1;
/** BLE bonding */
unsigned ble_bonding:1;
/** BLE Secure Connection flag */
unsigned ble_sm_sc:1;
} simple_ble_cfg_t;
static simple_ble_cfg_t *ble_cfg_p;
@ -498,7 +500,7 @@ static int simple_ble_start(const simple_ble_cfg_t *cfg)
ble_hs_cfg.sm_io_cap = BLE_SM_IO_CAP_NO_IO; /* Just Works */
ble_hs_cfg.sm_bonding = cfg->ble_bonding;
ble_hs_cfg.sm_mitm = 1;
ble_hs_cfg.sm_sc = 1; /* Enable secure connection by default */
ble_hs_cfg.sm_sc = cfg->ble_sm_sc;
/* Distribute LTK and IRK */
ble_hs_cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID;
@ -641,7 +643,14 @@ ble_gatt_add_characteristics(struct ble_gatt_chr_def *characteristics, int idx)
memcpy(temp_uuid128_name.value, ble_uuid_base, BLE_UUID128_VAL_LENGTH);
memcpy(&temp_uuid128_name.value[12], &protoble_internal->g_nu_lookup[idx].uuid, 2);
(characteristics + idx)->flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE;
(characteristics + idx)->flags = BLE_GATT_CHR_F_READ |
BLE_GATT_CHR_F_WRITE ;
#if defined(CONFIG_WIFI_PROV_BLE_FORCE_ENCRYPTION)
(characteristics + idx)->flags |= BLE_GATT_CHR_F_READ_ENC |
BLE_GATT_CHR_F_WRITE_ENC;
#endif
(characteristics + idx)->access_cb = gatt_svr_chr_access;
/* Out of 128 bit UUID, 16 bits from g_nu_lookup table. Currently
@ -912,6 +921,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->ble_bonding = config->ble_bonding;
ble_config->ble_sm_sc = config->ble_sm_sc;
if (populate_gatt_db(&ble_config->gatt_db, config) != 0) {
ESP_LOGE(TAG, "Error populating GATT Database");

View File

@ -17,9 +17,26 @@ menu "Wi-Fi Provisioning Manager"
config WIFI_PROV_BLE_BONDING
bool
default n
prompt "Enable BLE bonding"
depends on BT_ENABLED
default y
help
This option is applicable only when provisioning transport is BLE.
config WIFI_PROV_BLE_SEC_CONN
bool
prompt "Enable BLE Secure connection flag"
depends on BT_NIMBLE_ENABLED
default y
help
Used to enable Secure connection support when provisioning transport is BLE.
config WIFI_PROV_BLE_FORCE_ENCRYPTION
bool
prompt "Force Link Encryption during characteristic Read / Write"
depends on BT_NIMBLE_ENABLED
default y
help
Used to enforce link encryption when attempting to read / write characteristic
endmenu

View File

@ -38,8 +38,12 @@ static esp_err_t prov_start(protocomm_t *pc, void *config)
protocomm_ble_config_t *ble_config = (protocomm_ble_config_t *) config;
#ifdef CONFIG_WIFI_PROV_BLE_BONDING
ble_config->ble_bonding = 1;
#if defined(CONFIG_WIFI_PROV_BLE_BONDING)
ble_config->ble_bonding = 1;
#endif
#if defined(CONFIG_WIFI_PROV_BLE_SEC_CONN) || defined(CONFIG_BT_BLUEDROID_ENABLED)
ble_config->ble_sm_sc = 1;
#endif
/* Start protocomm as BLE service */