Skip to content

Commit

Permalink
Merge branch 'fix/protocomm_kconfig_flag' into 'master'
Browse files Browse the repository at this point in the history
protocomm: Fix Kconfig flag dependency on wifi_provisioning component

Closes IDFGH-7925

See merge request espressif/esp-idf!22083
  • Loading branch information
mahavirj committed Jan 20, 2023
2 parents 1731007 + 7759079 commit 7943a92
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
5 changes: 5 additions & 0 deletions components/protocomm/include/transports/protocomm_ble.h
Expand Up @@ -103,6 +103,11 @@ typedef struct protocomm_ble_config {
*/
unsigned ble_sm_sc:1;

/**
* BLE security flag
*/
unsigned ble_link_encryption:1;

} protocomm_ble_config_t;

/**
Expand Down
8 changes: 5 additions & 3 deletions components/protocomm/src/transports/protocomm_ble.c
Expand Up @@ -63,6 +63,7 @@ typedef struct _protocomm_ble {
ssize_t g_nu_lookup_count;
uint16_t gatt_mtu;
uint8_t *service_uuid;
unsigned ble_link_encryption:1;
} _protocomm_ble_internal_t;

static _protocomm_ble_internal_t *protoble_internal;
Expand Down Expand Up @@ -435,9 +436,9 @@ static ssize_t populate_gatt_db(esp_gatts_attr_db_t **gatt_db_generated)
} else if (i % 3 == 2) {
/* Characteristic Value */
(*gatt_db_generated)[i].att_desc.perm = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE ;
#if CONFIG_WIFI_PROV_BLE_FORCE_ENCRYPTION
(*gatt_db_generated)[i].att_desc.perm |= ESP_GATT_PERM_READ_ENCRYPTED | ESP_GATT_PERM_WRITE_ENCRYPTED;
#endif
if (protoble_internal->ble_link_encryption) {
(*gatt_db_generated)[i].att_desc.perm |= ESP_GATT_PERM_READ_ENCRYPTED | ESP_GATT_PERM_WRITE_ENCRYPTED;
}
(*gatt_db_generated)[i].att_desc.uuid_length = ESP_UUID_LEN_128;
(*gatt_db_generated)[i].att_desc.uuid_p = protoble_internal->g_nu_lookup[i / 3].uuid128;
(*gatt_db_generated)[i].att_desc.max_length = CHAR_VAL_LEN_MAX;
Expand Down Expand Up @@ -538,6 +539,7 @@ esp_err_t protocomm_ble_start(protocomm_t *pc, const protocomm_ble_config_t *con
pc->remove_endpoint = protocomm_ble_remove_endpoint;
protoble_internal->pc_ble = pc;
protoble_internal->gatt_mtu = ESP_GATT_DEF_BLE_MTU_SIZE;
protoble_internal->ble_link_encryption = config->ble_link_encryption;

// Config adv data
adv_config.service_uuid_len = ESP_UUID_LEN_128;
Expand Down
12 changes: 8 additions & 4 deletions components/protocomm/src/transports/protocomm_nimble.c
Expand Up @@ -68,6 +68,7 @@ typedef struct _protocomm_ble {
protocomm_ble_name_uuid_t *g_nu_lookup;
ssize_t g_nu_lookup_count;
uint16_t gatt_mtu;
unsigned ble_link_encryption:1;
} _protocomm_ble_internal_t;

static _protocomm_ble_internal_t *protoble_internal;
Expand Down Expand Up @@ -127,6 +128,8 @@ typedef struct {
unsigned ble_bonding:1;
/** BLE Secure Connection flag */
unsigned ble_sm_sc:1;
/** BLE Link Encryption flag */
unsigned ble_link_encryption:1;
} simple_ble_cfg_t;

static simple_ble_cfg_t *ble_cfg_p;
Expand Down Expand Up @@ -665,10 +668,10 @@ ble_gatt_add_characteristics(struct ble_gatt_chr_def *characteristics, int idx)
(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
if (protoble_internal->ble_link_encryption) {
(characteristics + idx)->flags |= BLE_GATT_CHR_F_READ_ENC |
BLE_GATT_CHR_F_WRITE_ENC;
}

(characteristics + idx)->access_cb = gatt_svr_chr_access;

Expand Down Expand Up @@ -921,6 +924,7 @@ esp_err_t protocomm_ble_start(protocomm_t *pc, const protocomm_ble_config_t *con
pc->remove_endpoint = protocomm_ble_remove_endpoint;
protoble_internal->pc_ble = pc;
protoble_internal->gatt_mtu = BLE_ATT_MTU_DFLT;
protoble_internal->ble_link_encryption = config->ble_link_encryption;

simple_ble_cfg_t *ble_config = (simple_ble_cfg_t *) calloc(1, sizeof(simple_ble_cfg_t));
if (ble_config == NULL) {
Expand Down
13 changes: 8 additions & 5 deletions components/wifi_provisioning/src/scheme_ble.c
Expand Up @@ -38,14 +38,17 @@ static esp_err_t prov_start(protocomm_t *pc, void *config)

protocomm_ble_config_t *ble_config = (protocomm_ble_config_t *) config;

#if defined(CONFIG_WIFI_PROV_BLE_BONDING)
#if defined(CONFIG_WIFI_PROV_BLE_BONDING)
ble_config->ble_bonding = 1;
#endif
#endif

#if defined(CONFIG_WIFI_PROV_BLE_SEC_CONN) || defined(CONFIG_BT_BLUEDROID_ENABLED)
ble_config->ble_sm_sc = 1;
#endif
#if defined(CONFIG_WIFI_PROV_BLE_SEC_CONN) || defined(CONFIG_BT_BLUEDROID_ENABLED)
ble_config->ble_sm_sc = 1;
#endif

#if defined(CONFIG_WIFI_PROV_BLE_FORCE_ENCRYPTION)
ble_config->ble_link_encryption = 1;
#endif
/* Start protocomm as BLE service */
if (protocomm_ble_start(pc, ble_config) != ESP_OK) {
ESP_LOGE(TAG, "Failed to start protocomm BLE service");
Expand Down

0 comments on commit 7943a92

Please sign in to comment.