|
|
@@ -25,6 +25,7 @@ static const char *TAG = "protocomm_nimble";
|
|
|
int ble_uuid_flat(const ble_uuid_t *, void *);
|
|
|
static uint8_t ble_uuid_base[BLE_UUID128_VAL_LENGTH];
|
|
|
static int num_chr_dsc;
|
|
|
+static uint16_t s_cached_conn_handle;
|
|
|
|
|
|
/* Standard 16 bit UUID for characteristic User Description*/
|
|
|
#define BLE_GATT_UUID_CHAR_DSC 0x2901
|
|
|
@@ -225,6 +226,7 @@ simple_ble_gap_event(struct ble_gap_event *event, void *arg)
|
|
|
ESP_LOGE(TAG, "No open connection with the specified handle");
|
|
|
return rc;
|
|
|
}
|
|
|
+ s_cached_conn_handle = event->connect.conn_handle;
|
|
|
} else {
|
|
|
/* Connection failed; resume advertising. */
|
|
|
simple_ble_advertise();
|
|
|
@@ -234,7 +236,7 @@ simple_ble_gap_event(struct ble_gap_event *event, void *arg)
|
|
|
case BLE_GAP_EVENT_DISCONNECT:
|
|
|
ESP_LOGD(TAG, "disconnect; reason=%d ", event->disconnect.reason);
|
|
|
transport_simple_ble_disconnect(event, arg);
|
|
|
-
|
|
|
+ s_cached_conn_handle = 0; /* Clear conn_handle value */
|
|
|
/* Connection terminated; resume advertising. */
|
|
|
simple_ble_advertise();
|
|
|
return 0;
|
|
|
@@ -536,6 +538,14 @@ static void transport_simple_ble_disconnect(struct ble_gap_event *event, void *a
|
|
|
esp_err_t ret;
|
|
|
ESP_LOGD(TAG, "Inside disconnect w/ session - %d",
|
|
|
event->disconnect.conn.conn_handle);
|
|
|
+
|
|
|
+#ifdef CONFIG_WIFI_PROV_KEEP_BLE_ON_AFTER_PROV
|
|
|
+ /* Ignore BLE events received after protocomm layer is stopped */
|
|
|
+ if (protoble_internal == NULL) {
|
|
|
+ ESP_LOGI(TAG,"Protocomm layer has already stopped");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+#endif
|
|
|
if (protoble_internal->pc_ble->sec &&
|
|
|
protoble_internal->pc_ble->sec->close_transport_session) {
|
|
|
ret =
|
|
|
@@ -948,12 +958,23 @@ esp_err_t protocomm_ble_stop(protocomm_t *pc)
|
|
|
rc);
|
|
|
}
|
|
|
|
|
|
+#ifndef CONFIG_WIFI_PROV_KEEP_BLE_ON_AFTER_PROV
|
|
|
+ /* If flag is enabled, don't stop the stack. User application can start a new advertising to perform its BT activities */
|
|
|
ret = nimble_port_stop();
|
|
|
if (ret == 0) {
|
|
|
nimble_port_deinit();
|
|
|
}
|
|
|
+#else
|
|
|
+#ifdef CONFIG_WIFI_PROV_DISCONNECT_AFTER_PROV
|
|
|
+ /* Keep BT stack on, but terminate the connection after provisioning */
|
|
|
+ rc = ble_gap_terminate(s_cached_conn_handle, BLE_ERR_REM_USER_CONN_TERM);
|
|
|
+ if (rc) {
|
|
|
+ ESP_LOGI(TAG, "Error in terminating connection rc = %d",rc);
|
|
|
+ }
|
|
|
+ free_gatt_ble_misc_memory(ble_cfg_p);
|
|
|
+#endif // CONFIG_WIFI_PROV_DISCONNECT_AFTER_PROV
|
|
|
+#endif // CONFIG_WIFI_PROV_KEEP_BLE_ON_AFTER_PROV
|
|
|
|
|
|
- free_gatt_ble_misc_memory(ble_cfg_p);
|
|
|
protocomm_ble_cleanup();
|
|
|
return ret;
|
|
|
}
|