Skip to content

Commit 0f11052

Browse files
committed
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
2 parents b341791 + fb55646 commit 0f11052

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed

components/protocomm/include/transports/protocomm_ble.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -148,6 +148,10 @@ typedef struct protocomm_ble_config {
148148
*/
149149
unsigned keep_ble_on:1;
150150

151+
/**
152+
* BLE characteristic notify flag
153+
*/
154+
unsigned ble_notify:1;
151155
} protocomm_ble_config_t;
152156

153157
/**

components/protocomm/src/transports/protocomm_ble.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ static const uint16_t primary_service_uuid = ESP_GATT_UUID_PRI_SERVICE;
3737
static const uint16_t character_declaration_uuid = ESP_GATT_UUID_CHAR_DECLARE;
3838
static const uint16_t character_user_description = ESP_GATT_UUID_CHAR_DESCRIPTION;
3939
static const uint8_t character_prop_read_write = ESP_GATT_CHAR_PROP_BIT_READ | ESP_GATT_CHAR_PROP_BIT_WRITE;
40+
static const uint8_t character_prop_read_write_notify = ESP_GATT_CHAR_PROP_BIT_READ | ESP_GATT_CHAR_PROP_BIT_WRITE | \
41+
ESP_GATT_CHAR_PROP_BIT_NOTIFY;
4042

4143
typedef struct {
4244
uint8_t type;
@@ -64,6 +66,7 @@ typedef struct _protocomm_ble {
6466
uint16_t gatt_mtu;
6567
uint8_t *service_uuid;
6668
unsigned ble_link_encryption:1;
69+
unsigned ble_notify:1;
6770
} _protocomm_ble_internal_t;
6871

6972
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)
450453
(*gatt_db_generated)[i].att_desc.uuid_p = (uint8_t *) &character_declaration_uuid;
451454
(*gatt_db_generated)[i].att_desc.max_length = sizeof(uint8_t);
452455
(*gatt_db_generated)[i].att_desc.length = sizeof(uint8_t);
453-
(*gatt_db_generated)[i].att_desc.value = (uint8_t *) &character_prop_read_write;
456+
457+
if (protoble_internal->ble_notify) {
458+
(*gatt_db_generated)[i].att_desc.value = (uint8_t *) &character_prop_read_write_notify;
459+
} else {
460+
(*gatt_db_generated)[i].att_desc.value = (uint8_t *) &character_prop_read_write;
461+
}
454462
} else if (i % 3 == 2) {
455463
/* Characteristic Value */
456464
(*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
562570
protoble_internal->pc_ble = pc;
563571
protoble_internal->gatt_mtu = ESP_GATT_DEF_BLE_MTU_SIZE;
564572
protoble_internal->ble_link_encryption = config->ble_link_encryption;
573+
protoble_internal->ble_notify = config->ble_notify;
565574

566575
// Config adv data
567576
adv_config.service_uuid_len = ESP_UUID_LEN_128;

components/protocomm/src/transports/protocomm_nimble.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ typedef struct _protocomm_ble {
6969
ssize_t g_nu_lookup_count;
7070
uint16_t gatt_mtu;
7171
unsigned ble_link_encryption:1;
72+
unsigned ble_notify:1;
7273
} _protocomm_ble_internal_t;
7374

7475
static _protocomm_ble_internal_t *protoble_internal;
@@ -135,6 +136,8 @@ typedef struct {
135136
uint8_t *ble_addr;
136137
/** Flag to keep BLE on */
137138
unsigned keep_ble_on:1;
139+
/** BLE Characteristic notify flag */
140+
unsigned ble_notify:1;
138141
} simple_ble_cfg_t;
139142

140143
static simple_ble_cfg_t *ble_cfg_p;
@@ -267,6 +270,14 @@ simple_ble_gap_event(struct ble_gap_event *event, void *arg)
267270
event->mtu.value);
268271
transport_simple_ble_set_mtu(event, arg);
269272
return 0;
273+
case BLE_GAP_EVENT_NOTIFY_TX:
274+
ESP_LOGI(TAG, "notify_tx event; conn_handle=%d attr_handle=%d "
275+
"status=%d is_indication=%d",
276+
event->notify_tx.conn_handle,
277+
event->notify_tx.attr_handle,
278+
event->notify_tx.status,
279+
event->notify_tx.indication);
280+
return 0;
270281
}
271282
return 0;
272283
}
@@ -717,6 +728,10 @@ ble_gatt_add_characteristics(struct ble_gatt_chr_def *characteristics, int idx)
717728
BLE_GATT_CHR_F_WRITE_ENC;
718729
}
719730

731+
if (protoble_internal->ble_notify) {
732+
(characteristics + idx)->flags |= BLE_GATT_CHR_F_NOTIFY;
733+
}
734+
720735
(characteristics + idx)->access_cb = gatt_svr_chr_access;
721736

722737
/* 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
974989
protoble_internal->pc_ble = pc;
975990
protoble_internal->gatt_mtu = BLE_ATT_MTU_DFLT;
976991
protoble_internal->ble_link_encryption = config->ble_link_encryption;
992+
protoble_internal->ble_notify = config->ble_notify;
977993

978994
simple_ble_cfg_t *ble_config = (simple_ble_cfg_t *) calloc(1, sizeof(simple_ble_cfg_t));
979995
if (ble_config == NULL) {

components/wifi_provisioning/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,17 @@ menu "Wi-Fi Provisioning Manager"
3333
config WIFI_PROV_BLE_FORCE_ENCRYPTION
3434
bool
3535
prompt "Force Link Encryption during characteristic Read / Write"
36+
depends on BT_ENABLED
3637
help
3738
Used to enforce link encryption when attempting to read / write characteristic
3839

40+
config WIFI_PROV_BLE_NOTIFY
41+
bool
42+
prompt "Add support for Notification for provisioning BLE descriptors"
43+
depends on BT_ENABLED
44+
help
45+
Used to enable support Notification in BLE descriptors of prov* characteristics
46+
3947
config WIFI_PROV_KEEP_BLE_ON_AFTER_PROV
4048
bool "Keep BT on after provisioning is done"
4149
depends on BT_ENABLED

components/wifi_provisioning/src/scheme_ble.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ static esp_err_t prov_start(protocomm_t *pc, void *config)
6565
#if defined(CONFIG_WIFI_PROV_BLE_FORCE_ENCRYPTION)
6666
ble_config->ble_link_encryption = 1;
6767
#endif
68+
69+
#if defined(CONFIG_WIFI_PROV_BLE_NOTIFY)
70+
ble_config->ble_notify = 1;
71+
#endif
72+
6873
/* Start protocomm as BLE service */
6974
if (protocomm_ble_start(pc, ble_config) != ESP_OK) {
7075
ESP_LOGE(TAG, "Failed to start protocomm BLE service");

0 commit comments

Comments
 (0)