Merge branch 'bugfix/add_notify_flag_for_wifi_prov_v5.2' into 'release/v5.2'

fix(wifi_prov): Add notify characteristic flag support (v5.2)

See merge request espressif/esp-idf!33184
This commit is contained in:
Mahavir Jain 2024-09-26 11:44:06 +08:00
commit 4fb04ce3aa
5 changed files with 44 additions and 1 deletions

View File

@ -142,6 +142,11 @@ typedef struct protocomm_ble_config {
* BLE address * BLE address
*/ */
uint8_t *ble_addr; uint8_t *ble_addr;
/**
* BLE characteristic notify flag
*/
unsigned ble_notify:1;
} protocomm_ble_config_t; } protocomm_ble_config_t;
/** /**

View File

@ -37,6 +37,8 @@ static const uint16_t primary_service_uuid = ESP_GATT_UUID_PRI_SERVICE;
static const uint16_t character_declaration_uuid = ESP_GATT_UUID_CHAR_DECLARE; static const uint16_t character_declaration_uuid = ESP_GATT_UUID_CHAR_DECLARE;
static const uint16_t character_user_description = ESP_GATT_UUID_CHAR_DESCRIPTION; static const uint16_t character_user_description = ESP_GATT_UUID_CHAR_DESCRIPTION;
static const uint8_t character_prop_read_write = ESP_GATT_CHAR_PROP_BIT_READ | ESP_GATT_CHAR_PROP_BIT_WRITE; static const uint8_t character_prop_read_write = ESP_GATT_CHAR_PROP_BIT_READ | ESP_GATT_CHAR_PROP_BIT_WRITE;
static const uint8_t character_prop_read_write_notify = ESP_GATT_CHAR_PROP_BIT_READ | ESP_GATT_CHAR_PROP_BIT_WRITE | \
ESP_GATT_CHAR_PROP_BIT_NOTIFY;
typedef struct { typedef struct {
uint8_t type; uint8_t type;
@ -64,6 +66,7 @@ typedef struct _protocomm_ble {
uint16_t gatt_mtu; uint16_t gatt_mtu;
uint8_t *service_uuid; uint8_t *service_uuid;
unsigned ble_link_encryption:1; unsigned ble_link_encryption:1;
unsigned ble_notify:1;
} _protocomm_ble_internal_t; } _protocomm_ble_internal_t;
static _protocomm_ble_internal_t *protoble_internal; static _protocomm_ble_internal_t *protoble_internal;
@ -450,7 +453,12 @@ static ssize_t populate_gatt_db(esp_gatts_attr_db_t **gatt_db_generated)
(*gatt_db_generated)[i].att_desc.uuid_p = (uint8_t *) &character_declaration_uuid; (*gatt_db_generated)[i].att_desc.uuid_p = (uint8_t *) &character_declaration_uuid;
(*gatt_db_generated)[i].att_desc.max_length = sizeof(uint8_t); (*gatt_db_generated)[i].att_desc.max_length = sizeof(uint8_t);
(*gatt_db_generated)[i].att_desc.length = sizeof(uint8_t); (*gatt_db_generated)[i].att_desc.length = sizeof(uint8_t);
if (protoble_internal->ble_notify) {
(*gatt_db_generated)[i].att_desc.value = (uint8_t *) &character_prop_read_write_notify;
} else {
(*gatt_db_generated)[i].att_desc.value = (uint8_t *) &character_prop_read_write; (*gatt_db_generated)[i].att_desc.value = (uint8_t *) &character_prop_read_write;
}
} else if (i % 3 == 2) { } else if (i % 3 == 2) {
/* Characteristic Value */ /* Characteristic Value */
(*gatt_db_generated)[i].att_desc.perm = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE ; (*gatt_db_generated)[i].att_desc.perm = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE ;
@ -562,6 +570,7 @@ esp_err_t protocomm_ble_start(protocomm_t *pc, const protocomm_ble_config_t *con
protoble_internal->pc_ble = pc; protoble_internal->pc_ble = pc;
protoble_internal->gatt_mtu = ESP_GATT_DEF_BLE_MTU_SIZE; protoble_internal->gatt_mtu = ESP_GATT_DEF_BLE_MTU_SIZE;
protoble_internal->ble_link_encryption = config->ble_link_encryption; protoble_internal->ble_link_encryption = config->ble_link_encryption;
protoble_internal->ble_notify = config->ble_notify;
// Config adv data // Config adv data
adv_config.service_uuid_len = ESP_UUID_LEN_128; adv_config.service_uuid_len = ESP_UUID_LEN_128;

View File

@ -69,6 +69,7 @@ typedef struct _protocomm_ble {
ssize_t g_nu_lookup_count; ssize_t g_nu_lookup_count;
uint16_t gatt_mtu; uint16_t gatt_mtu;
unsigned ble_link_encryption:1; unsigned ble_link_encryption:1;
unsigned ble_notify:1;
} _protocomm_ble_internal_t; } _protocomm_ble_internal_t;
static _protocomm_ble_internal_t *protoble_internal; static _protocomm_ble_internal_t *protoble_internal;
@ -133,6 +134,8 @@ typedef struct {
unsigned ble_link_encryption:1; unsigned ble_link_encryption:1;
/** BLE address */ /** BLE address */
uint8_t *ble_addr; uint8_t *ble_addr;
/** BLE Characteristic notify flag */
unsigned ble_notify:1;
} simple_ble_cfg_t; } simple_ble_cfg_t;
static simple_ble_cfg_t *ble_cfg_p; static simple_ble_cfg_t *ble_cfg_p;
@ -265,6 +268,14 @@ simple_ble_gap_event(struct ble_gap_event *event, void *arg)
event->mtu.value); event->mtu.value);
transport_simple_ble_set_mtu(event, arg); transport_simple_ble_set_mtu(event, arg);
return 0; return 0;
case BLE_GAP_EVENT_NOTIFY_TX:
ESP_LOGI(TAG, "notify_tx event; conn_handle=%d attr_handle=%d "
"status=%d is_indication=%d",
event->notify_tx.conn_handle,
event->notify_tx.attr_handle,
event->notify_tx.status,
event->notify_tx.indication);
return 0;
} }
return 0; return 0;
} }
@ -715,6 +726,10 @@ ble_gatt_add_characteristics(struct ble_gatt_chr_def *characteristics, int idx)
BLE_GATT_CHR_F_WRITE_ENC; BLE_GATT_CHR_F_WRITE_ENC;
} }
if (protoble_internal->ble_notify) {
(characteristics + idx)->flags |= BLE_GATT_CHR_F_NOTIFY;
}
(characteristics + idx)->access_cb = gatt_svr_chr_access; (characteristics + idx)->access_cb = gatt_svr_chr_access;
/* Out of 128 bit UUID, 16 bits from g_nu_lookup table. Currently /* Out of 128 bit UUID, 16 bits from g_nu_lookup table. Currently
@ -972,6 +987,7 @@ esp_err_t protocomm_ble_start(protocomm_t *pc, const protocomm_ble_config_t *con
protoble_internal->pc_ble = pc; protoble_internal->pc_ble = pc;
protoble_internal->gatt_mtu = BLE_ATT_MTU_DFLT; protoble_internal->gatt_mtu = BLE_ATT_MTU_DFLT;
protoble_internal->ble_link_encryption = config->ble_link_encryption; protoble_internal->ble_link_encryption = config->ble_link_encryption;
protoble_internal->ble_notify = config->ble_notify;
simple_ble_cfg_t *ble_config = (simple_ble_cfg_t *) calloc(1, sizeof(simple_ble_cfg_t)); simple_ble_cfg_t *ble_config = (simple_ble_cfg_t *) calloc(1, sizeof(simple_ble_cfg_t));
if (ble_config == NULL) { if (ble_config == NULL) {

View File

@ -33,9 +33,17 @@ menu "Wi-Fi Provisioning Manager"
config WIFI_PROV_BLE_FORCE_ENCRYPTION config WIFI_PROV_BLE_FORCE_ENCRYPTION
bool bool
prompt "Force Link Encryption during characteristic Read / Write" prompt "Force Link Encryption during characteristic Read / Write"
depends on BT_ENABLED
help help
Used to enforce link encryption when attempting to read / write characteristic Used to enforce link encryption when attempting to read / write characteristic
config WIFI_PROV_BLE_NOTIFY
bool
prompt "Add support for Notification for provisioning BLE descriptors"
depends on BT_ENABLED
help
Used to enable support Notification in BLE descriptors of prov* characteristics
config WIFI_PROV_KEEP_BLE_ON_AFTER_PROV config WIFI_PROV_KEEP_BLE_ON_AFTER_PROV
bool "Keep BT on after provisioning is done" bool "Keep BT on after provisioning is done"
depends on BT_ENABLED depends on BT_ENABLED

View File

@ -51,6 +51,11 @@ static esp_err_t prov_start(protocomm_t *pc, void *config)
#if defined(CONFIG_WIFI_PROV_BLE_FORCE_ENCRYPTION) #if defined(CONFIG_WIFI_PROV_BLE_FORCE_ENCRYPTION)
ble_config->ble_link_encryption = 1; ble_config->ble_link_encryption = 1;
#endif #endif
#if defined(CONFIG_WIFI_PROV_BLE_NOTIFY)
ble_config->ble_notify = 1;
#endif
/* Start protocomm as BLE service */ /* Start protocomm as BLE service */
if (protocomm_ble_start(pc, ble_config) != ESP_OK) { if (protocomm_ble_start(pc, ble_config) != ESP_OK) {
ESP_LOGE(TAG, "Failed to start protocomm BLE service"); ESP_LOGE(TAG, "Failed to start protocomm BLE service");