mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'bugfix/add_notify_flag_for_wifi_prov' into 'master'
fix(wifi_prov): Add notify characteristic flag support See merge request espressif/esp-idf!32311
This commit is contained in:
commit
0f11052406
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -148,6 +148,10 @@ typedef struct protocomm_ble_config {
|
||||
*/
|
||||
unsigned keep_ble_on:1;
|
||||
|
||||
/**
|
||||
* BLE characteristic notify flag
|
||||
*/
|
||||
unsigned ble_notify:1;
|
||||
} protocomm_ble_config_t;
|
||||
|
||||
/**
|
||||
|
@ -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_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_notify = ESP_GATT_CHAR_PROP_BIT_READ | ESP_GATT_CHAR_PROP_BIT_WRITE | \
|
||||
ESP_GATT_CHAR_PROP_BIT_NOTIFY;
|
||||
|
||||
typedef struct {
|
||||
uint8_t type;
|
||||
@ -64,6 +66,7 @@ typedef struct _protocomm_ble {
|
||||
uint16_t gatt_mtu;
|
||||
uint8_t *service_uuid;
|
||||
unsigned ble_link_encryption:1;
|
||||
unsigned ble_notify:1;
|
||||
} _protocomm_ble_internal_t;
|
||||
|
||||
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.max_length = sizeof(uint8_t);
|
||||
(*gatt_db_generated)[i].att_desc.length = sizeof(uint8_t);
|
||||
(*gatt_db_generated)[i].att_desc.value = (uint8_t *) &character_prop_read_write;
|
||||
|
||||
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;
|
||||
}
|
||||
} else if (i % 3 == 2) {
|
||||
/* Characteristic Value */
|
||||
(*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->gatt_mtu = ESP_GATT_DEF_BLE_MTU_SIZE;
|
||||
protoble_internal->ble_link_encryption = config->ble_link_encryption;
|
||||
protoble_internal->ble_notify = config->ble_notify;
|
||||
|
||||
// Config adv data
|
||||
adv_config.service_uuid_len = ESP_UUID_LEN_128;
|
||||
|
@ -69,6 +69,7 @@ typedef struct _protocomm_ble {
|
||||
ssize_t g_nu_lookup_count;
|
||||
uint16_t gatt_mtu;
|
||||
unsigned ble_link_encryption:1;
|
||||
unsigned ble_notify:1;
|
||||
} _protocomm_ble_internal_t;
|
||||
|
||||
static _protocomm_ble_internal_t *protoble_internal;
|
||||
@ -135,6 +136,8 @@ typedef struct {
|
||||
uint8_t *ble_addr;
|
||||
/** Flag to keep BLE on */
|
||||
unsigned keep_ble_on:1;
|
||||
/** BLE Characteristic notify flag */
|
||||
unsigned ble_notify:1;
|
||||
} simple_ble_cfg_t;
|
||||
|
||||
static simple_ble_cfg_t *ble_cfg_p;
|
||||
@ -267,6 +270,14 @@ simple_ble_gap_event(struct ble_gap_event *event, void *arg)
|
||||
event->mtu.value);
|
||||
transport_simple_ble_set_mtu(event, arg);
|
||||
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;
|
||||
}
|
||||
@ -717,6 +728,10 @@ ble_gatt_add_characteristics(struct ble_gatt_chr_def *characteristics, int idx)
|
||||
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;
|
||||
|
||||
/* Out of 128 bit UUID, 16 bits from g_nu_lookup table. Currently
|
||||
@ -974,6 +989,7 @@ esp_err_t protocomm_ble_start(protocomm_t *pc, const protocomm_ble_config_t *con
|
||||
protoble_internal->pc_ble = pc;
|
||||
protoble_internal->gatt_mtu = BLE_ATT_MTU_DFLT;
|
||||
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));
|
||||
if (ble_config == NULL) {
|
||||
|
@ -33,9 +33,17 @@ menu "Wi-Fi Provisioning Manager"
|
||||
config WIFI_PROV_BLE_FORCE_ENCRYPTION
|
||||
bool
|
||||
prompt "Force Link Encryption during characteristic Read / Write"
|
||||
depends on BT_ENABLED
|
||||
help
|
||||
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
|
||||
bool "Keep BT on after provisioning is done"
|
||||
depends on BT_ENABLED
|
||||
|
@ -65,6 +65,11 @@ static esp_err_t prov_start(protocomm_t *pc, void *config)
|
||||
#if defined(CONFIG_WIFI_PROV_BLE_FORCE_ENCRYPTION)
|
||||
ble_config->ble_link_encryption = 1;
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_WIFI_PROV_BLE_NOTIFY)
|
||||
ble_config->ble_notify = 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");
|
||||
|
Loading…
Reference in New Issue
Block a user