mirror of
https://github.com/espressif/esp-idf
synced 2025-03-09 17:19:09 -04:00
Merge branch 'feature/wifi_prov_event_transport_paired' into 'master'
wifi_prov: Exposed events for transport pairing and disconnection Closes IDFGH-8557 See merge request espressif/esp-idf!20821
This commit is contained in:
commit
99579620b2
@ -7,11 +7,25 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <protocomm.h>
|
#include <protocomm.h>
|
||||||
|
#include "esp_event.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
ESP_EVENT_DECLARE_BASE(PROTOCOMM_TRANSPORT_BLE_EVENT);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Events generated by BLE transport
|
||||||
|
*
|
||||||
|
* These events are generated when the BLE transport is paired
|
||||||
|
* and disconnected.
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
PROTOCOMM_TRANSPORT_BLE_CONNECTED,
|
||||||
|
PROTOCOMM_TRANSPORT_BLE_DISCONNECTED,
|
||||||
|
} protocomm_transport_ble_event_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BLE device name cannot be larger than this value
|
* BLE device name cannot be larger than this value
|
||||||
* 31 bytes (max scan response size) - 1 byte (length) - 1 byte (type) = 29 bytes
|
* 31 bytes (max scan response size) - 1 byte (length) - 1 byte (type) = 29 bytes
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
#include "protocomm_priv.h"
|
#include "protocomm_priv.h"
|
||||||
#include "simple_ble.h"
|
#include "simple_ble.h"
|
||||||
|
|
||||||
|
ESP_EVENT_DEFINE_BASE(PROTOCOMM_TRANSPORT_BLE_EVENT);
|
||||||
|
|
||||||
/* NOTE: For the security2 scheme, the payload size is quite larger
|
/* NOTE: For the security2 scheme, the payload size is quite larger
|
||||||
* than that for security1. The increased value has been selected
|
* than that for security1. The increased value has been selected
|
||||||
* keeping in mind the largest packet size for security2 and the
|
* keeping in mind the largest packet size for security2 and the
|
||||||
@ -25,6 +27,7 @@
|
|||||||
#else
|
#else
|
||||||
#define CHAR_VAL_LEN_MAX (256 + 1)
|
#define CHAR_VAL_LEN_MAX (256 + 1)
|
||||||
#endif // CONFIG_ESP_PROTOCOMM_SUPPORT_SECURITY_VERSION_2
|
#endif // CONFIG_ESP_PROTOCOMM_SUPPORT_SECURITY_VERSION_2
|
||||||
|
|
||||||
#define PREPARE_BUF_MAX_SIZE CHAR_VAL_LEN_MAX
|
#define PREPARE_BUF_MAX_SIZE CHAR_VAL_LEN_MAX
|
||||||
|
|
||||||
static const char *TAG = "protocomm_ble";
|
static const char *TAG = "protocomm_ble";
|
||||||
@ -342,6 +345,10 @@ static void transport_simple_ble_disconnect(esp_gatts_cb_event_t event, esp_gatt
|
|||||||
param->disconnect.conn_id);
|
param->disconnect.conn_id);
|
||||||
if (ret != ESP_OK) {
|
if (ret != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "error closing the session after disconnect");
|
ESP_LOGE(TAG, "error closing the session after disconnect");
|
||||||
|
} else {
|
||||||
|
if (esp_event_post(PROTOCOMM_TRANSPORT_BLE_EVENT, PROTOCOMM_TRANSPORT_BLE_DISCONNECTED, NULL, 0, portMAX_DELAY) != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to post transport disconnection event");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protoble_internal->gatt_mtu = ESP_GATT_DEF_BLE_MTU_SIZE;
|
protoble_internal->gatt_mtu = ESP_GATT_DEF_BLE_MTU_SIZE;
|
||||||
@ -357,6 +364,10 @@ static void transport_simple_ble_connect(esp_gatts_cb_event_t event, esp_gatt_if
|
|||||||
param->connect.conn_id);
|
param->connect.conn_id);
|
||||||
if (ret != ESP_OK) {
|
if (ret != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "error creating the session");
|
ESP_LOGE(TAG, "error creating the session");
|
||||||
|
} else {
|
||||||
|
if (esp_event_post(PROTOCOMM_TRANSPORT_BLE_EVENT, PROTOCOMM_TRANSPORT_BLE_CONNECTED, NULL, 0, portMAX_DELAY) != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to post transport pairing event");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
static const char *TAG = "protocomm_nimble";
|
static const char *TAG = "protocomm_nimble";
|
||||||
|
|
||||||
|
ESP_EVENT_DEFINE_BASE(PROTOCOMM_TRANSPORT_BLE_EVENT);
|
||||||
|
|
||||||
int ble_uuid_flat(const ble_uuid_t *, void *);
|
int ble_uuid_flat(const ble_uuid_t *, void *);
|
||||||
static uint8_t ble_uuid_base[BLE_UUID128_VAL_LENGTH];
|
static uint8_t ble_uuid_base[BLE_UUID128_VAL_LENGTH];
|
||||||
static int num_chr_dsc;
|
static int num_chr_dsc;
|
||||||
@ -226,7 +228,7 @@ simple_ble_gap_event(struct ble_gap_event *event, void *arg)
|
|||||||
ESP_LOGE(TAG, "No open connection with the specified handle");
|
ESP_LOGE(TAG, "No open connection with the specified handle");
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
s_cached_conn_handle = event->connect.conn_handle;
|
s_cached_conn_handle = event->connect.conn_handle;
|
||||||
} else {
|
} else {
|
||||||
/* Connection failed; resume advertising. */
|
/* Connection failed; resume advertising. */
|
||||||
simple_ble_advertise();
|
simple_ble_advertise();
|
||||||
@ -236,7 +238,11 @@ simple_ble_gap_event(struct ble_gap_event *event, void *arg)
|
|||||||
case BLE_GAP_EVENT_DISCONNECT:
|
case BLE_GAP_EVENT_DISCONNECT:
|
||||||
ESP_LOGD(TAG, "disconnect; reason=%d ", event->disconnect.reason);
|
ESP_LOGD(TAG, "disconnect; reason=%d ", event->disconnect.reason);
|
||||||
transport_simple_ble_disconnect(event, arg);
|
transport_simple_ble_disconnect(event, arg);
|
||||||
s_cached_conn_handle = 0; /* Clear conn_handle value */
|
/* Clear conn_handle value */
|
||||||
|
s_cached_conn_handle = 0;
|
||||||
|
if (esp_event_post(PROTOCOMM_TRANSPORT_BLE_EVENT, PROTOCOMM_TRANSPORT_BLE_DISCONNECTED, NULL, 0, portMAX_DELAY) != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to post pairing event");
|
||||||
|
}
|
||||||
/* Connection terminated; resume advertising. */
|
/* Connection terminated; resume advertising. */
|
||||||
simple_ble_advertise();
|
simple_ble_advertise();
|
||||||
return 0;
|
return 0;
|
||||||
@ -552,6 +558,10 @@ static void transport_simple_ble_disconnect(struct ble_gap_event *event, void *a
|
|||||||
protoble_internal->pc_ble->sec->close_transport_session(protoble_internal->pc_ble->sec_inst, event->disconnect.conn.conn_handle);
|
protoble_internal->pc_ble->sec->close_transport_session(protoble_internal->pc_ble->sec_inst, event->disconnect.conn.conn_handle);
|
||||||
if (ret != ESP_OK) {
|
if (ret != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "error closing the session after disconnect");
|
ESP_LOGE(TAG, "error closing the session after disconnect");
|
||||||
|
} else {
|
||||||
|
if (esp_event_post(PROTOCOMM_TRANSPORT_BLE_EVENT, PROTOCOMM_TRANSPORT_BLE_DISCONNECTED, NULL, 0, portMAX_DELAY) != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to post transport disconnection event");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protoble_internal->gatt_mtu = BLE_ATT_MTU_DFLT;
|
protoble_internal->gatt_mtu = BLE_ATT_MTU_DFLT;
|
||||||
@ -567,6 +577,10 @@ static void transport_simple_ble_connect(struct ble_gap_event *event, void *arg)
|
|||||||
protoble_internal->pc_ble->sec->new_transport_session(protoble_internal->pc_ble->sec_inst, event->connect.conn_handle);
|
protoble_internal->pc_ble->sec->new_transport_session(protoble_internal->pc_ble->sec_inst, event->connect.conn_handle);
|
||||||
if (ret != ESP_OK) {
|
if (ret != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "error creating the session");
|
ESP_LOGE(TAG, "error creating the session");
|
||||||
|
} else {
|
||||||
|
if (esp_event_post(PROTOCOMM_TRANSPORT_BLE_EVENT, PROTOCOMM_TRANSPORT_BLE_CONNECTED, NULL, 0, portMAX_DELAY) != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to post transport pairing event");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,16 +156,44 @@ static void event_handler(void* arg, esp_event_base_t event_base,
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
|
} else if (event_base == WIFI_EVENT) {
|
||||||
esp_wifi_connect();
|
switch (event_id) {
|
||||||
|
case WIFI_EVENT_STA_START:
|
||||||
|
esp_wifi_connect();
|
||||||
|
break;
|
||||||
|
case WIFI_EVENT_STA_DISCONNECTED:
|
||||||
|
ESP_LOGI(TAG, "Disconnected. Connecting to the AP again...");
|
||||||
|
esp_wifi_connect();
|
||||||
|
break;
|
||||||
|
#ifdef CONFIG_EXAMPLE_PROV_TRANSPORT_SOFTAP
|
||||||
|
case WIFI_EVENT_AP_STACONNECTED:
|
||||||
|
ESP_LOGI(TAG, "SoftAP transport: Connected!");
|
||||||
|
break;
|
||||||
|
case WIFI_EVENT_AP_STADISCONNECTED:
|
||||||
|
ESP_LOGI(TAG, "SoftAP transport: Disconnected!");
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
|
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
|
||||||
ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
|
ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
|
||||||
ESP_LOGI(TAG, "Connected with IP Address:" IPSTR, IP2STR(&event->ip_info.ip));
|
ESP_LOGI(TAG, "Connected with IP Address:" IPSTR, IP2STR(&event->ip_info.ip));
|
||||||
/* Signal main application to continue execution */
|
/* Signal main application to continue execution */
|
||||||
xEventGroupSetBits(wifi_event_group, WIFI_CONNECTED_EVENT);
|
xEventGroupSetBits(wifi_event_group, WIFI_CONNECTED_EVENT);
|
||||||
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
|
#ifdef CONFIG_EXAMPLE_PROV_TRANSPORT_BLE
|
||||||
ESP_LOGI(TAG, "Disconnected. Connecting to the AP again...");
|
} else if (event_base == PROTOCOMM_TRANSPORT_BLE_EVENT) {
|
||||||
esp_wifi_connect();
|
switch (event_id) {
|
||||||
|
case PROTOCOMM_TRANSPORT_BLE_CONNECTED:
|
||||||
|
ESP_LOGI(TAG, "BLE transport: Connected!");
|
||||||
|
break;
|
||||||
|
case PROTOCOMM_TRANSPORT_BLE_DISCONNECTED:
|
||||||
|
ESP_LOGI(TAG, "BLE transport: Disconnected!");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,6 +286,9 @@ void app_main(void)
|
|||||||
|
|
||||||
/* Register our event handler for Wi-Fi, IP and Provisioning related events */
|
/* Register our event handler for Wi-Fi, IP and Provisioning related events */
|
||||||
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_PROV_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
|
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_PROV_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
|
||||||
|
#ifdef CONFIG_EXAMPLE_PROV_TRANSPORT_BLE
|
||||||
|
ESP_ERROR_CHECK(esp_event_handler_register(PROTOCOMM_TRANSPORT_BLE_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
|
||||||
|
#endif
|
||||||
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
|
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
|
||||||
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL));
|
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user