From ca17dc4f2d9fd9740c4655ab781486bee4265f06 Mon Sep 17 00:00:00 2001 From: zhangyanjiao Date: Fri, 2 Sep 2022 19:22:40 +0800 Subject: [PATCH 1/6] esp_wifi: report rssi info in wifi event --- components/esp_wifi/include/esp_wifi_types.h | 1 + 1 file changed, 1 insertion(+) diff --git a/components/esp_wifi/include/esp_wifi_types.h b/components/esp_wifi/include/esp_wifi_types.h index 401f0bbaf0..5760dec6a7 100644 --- a/components/esp_wifi/include/esp_wifi_types.h +++ b/components/esp_wifi/include/esp_wifi_types.h @@ -665,6 +665,7 @@ typedef struct { uint8_t ssid_len; /**< SSID length of disconnected AP */ uint8_t bssid[6]; /**< BSSID of disconnected AP */ uint8_t reason; /**< reason of disconnection */ + int8_t rssi; /**< rssi of disconnection */ } wifi_event_sta_disconnected_t; /** Argument structure for WIFI_EVENT_STA_AUTHMODE_CHANGE event */ From 626b87871d10c663f624594725baeb8ca6f71ae4 Mon Sep 17 00:00:00 2001 From: liuning Date: Fri, 22 Jul 2022 18:11:10 +0800 Subject: [PATCH 2/6] blufi: update version to 1.3 record connecting status, got ip status, maximum retry, connection end info (reason code, rssi) and provide greater information to phone --- .../bt/common/api/include/api/esp_blufi_api.h | 10 +++ .../common/btc/profile/esp/blufi/blufi_prf.c | 30 +++++++ .../btc/profile/esp/blufi/include/blufi_int.h | 5 +- .../bluetooth/blufi/main/Kconfig.projbuild | 10 +++ .../bluetooth/blufi/main/blufi_example_main.c | 85 ++++++++++++++++--- 5 files changed, 129 insertions(+), 11 deletions(-) create mode 100644 examples/bluetooth/blufi/main/Kconfig.projbuild diff --git a/components/bt/common/api/include/api/esp_blufi_api.h b/components/bt/common/api/include/api/esp_blufi_api.h index 004c1be2b2..ec95d49569 100644 --- a/components/bt/common/api/include/api/esp_blufi_api.h +++ b/components/bt/common/api/include/api/esp_blufi_api.h @@ -57,6 +57,8 @@ typedef enum { typedef enum { ESP_BLUFI_STA_CONN_SUCCESS = 0x00, ESP_BLUFI_STA_CONN_FAIL = 0x01, + ESP_BLUFI_STA_CONNECTING = 0x02, + ESP_BLUFI_STA_NO_IP = 0x03, } esp_blufi_sta_conn_state_t; /// BLUFI init status @@ -82,6 +84,8 @@ typedef enum { ESP_BLUFI_READ_PARAM_ERROR, ESP_BLUFI_MAKE_PUBLIC_ERROR, ESP_BLUFI_DATA_FORMAT_ERROR, + ESP_BLUFI_CALC_MD5_ERROR, + ESP_BLUFI_WIFI_SCAN_FAIL, } esp_blufi_error_state_t; /** @@ -105,6 +109,12 @@ typedef struct { bool softap_max_conn_num_set; /*!< is max connection number of softap interface set */ uint8_t softap_channel; /*!< channel of softap interface */ bool softap_channel_set; /*!< is channel of softap interface set */ + uint8_t sta_max_conn_retry; /*!< max retry of sta establish connection */ + bool sta_max_conn_retry_set; /*!< is max retry of sta establish connection set */ + uint8_t sta_conn_end_reason; /*!< reason of sta connection end */ + bool sta_conn_end_reason_set; /*!< is reason of sta connection end set */ + int8_t sta_conn_rssi; /*!< rssi of sta connection */ + bool sta_conn_rssi_set; /*!< is rssi of sta connection set */ } esp_blufi_extra_info_t; /** @brief Description of an WiFi AP */ diff --git a/components/bt/common/btc/profile/esp/blufi/blufi_prf.c b/components/bt/common/btc/profile/esp/blufi/blufi_prf.c index 24feb21451..164b0ae1ed 100644 --- a/components/bt/common/btc/profile/esp/blufi/blufi_prf.c +++ b/components/bt/common/btc/profile/esp/blufi/blufi_prf.c @@ -321,6 +321,21 @@ static void btc_blufi_wifi_conn_report(uint8_t opmode, uint8_t sta_conn_state, u *p++ = 1; *p++ = info->softap_channel; } + if (info->sta_max_conn_retry_set) { + *p++ = BLUFI_TYPE_DATA_SUBTYPE_STA_MAX_CONN_RETRY; + *p++ = 1; + *p++ = info->sta_max_conn_retry; + } + if (info->sta_conn_end_reason_set) { + *p++ = BLUFI_TYPE_DATA_SUBTYPE_STA_CONN_END_REASON; + *p++ = 1; + *p++ = info->sta_conn_end_reason; + } + if (info->sta_conn_rssi_set) { + *p++ = BLUFI_TYPE_DATA_SUBTYPE_STA_CONN_RSSI; + *p++ = 1; + *p++ = info->sta_conn_rssi; + } } if (p - data > data_len) { BTC_TRACE_ERROR("%s len error %d %d\n", __func__, (int)(p - data), data_len); @@ -714,6 +729,21 @@ void btc_blufi_call_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src) dst->wifi_conn_report.extra_info->softap_channel = src_info->softap_channel; dst->wifi_conn_report.extra_info_len += (1 + 2); } + if (src_info->sta_max_conn_retry_set) { + dst->wifi_conn_report.extra_info->sta_max_conn_retry_set = src_info->sta_max_conn_retry_set; + dst->wifi_conn_report.extra_info->sta_max_conn_retry = src_info->sta_max_conn_retry; + dst->wifi_conn_report.extra_info_len += (1 + 2); + } + if (src_info->sta_conn_end_reason_set) { + dst->wifi_conn_report.extra_info->sta_conn_end_reason_set = src_info->sta_conn_end_reason_set; + dst->wifi_conn_report.extra_info->sta_conn_end_reason = src_info->sta_conn_end_reason; + dst->wifi_conn_report.extra_info_len += (1 + 2); + } + if (src_info->sta_conn_rssi_set) { + dst->wifi_conn_report.extra_info->sta_conn_rssi_set = src_info->sta_conn_rssi_set; + dst->wifi_conn_report.extra_info->sta_conn_rssi = src_info->sta_conn_rssi; + dst->wifi_conn_report.extra_info_len += (1 + 2); + } break; } case BTC_BLUFI_ACT_SEND_WIFI_LIST:{ diff --git a/components/bt/common/btc/profile/esp/blufi/include/blufi_int.h b/components/bt/common/btc/profile/esp/blufi/include/blufi_int.h index 996621e048..be2c72c78d 100644 --- a/components/bt/common/btc/profile/esp/blufi/include/blufi_int.h +++ b/components/bt/common/btc/profile/esp/blufi/include/blufi_int.h @@ -20,7 +20,7 @@ #if (BLUFI_INCLUDED == TRUE) #define BTC_BLUFI_GREAT_VER 0x01 //Version + Subversion -#define BTC_BLUFI_SUB_VER 0x02 //Version + Subversion +#define BTC_BLUFI_SUB_VER 0x03 //Version + Subversion #define BTC_BLUFI_VERSION ((BTC_BLUFI_GREAT_VER<<8)|BTC_BLUFI_SUB_VER) //Version + Subversion typedef UINT8 tGATT_IF; @@ -129,6 +129,9 @@ extern tBLUFI_ENV *blufi_env_ptr; #define BLUFI_TYPE_DATA_SUBTYPE_WIFI_LIST 0x11 #define BLUFI_TYPE_DATA_SUBTYPE_ERROR_INFO 0x12 #define BLUFI_TYPE_DATA_SUBTYPE_CUSTOM_DATA 0x13 +#define BLUFI_TYPE_DATA_SUBTYPE_STA_MAX_CONN_RETRY 0x14 +#define BLUFI_TYPE_DATA_SUBTYPE_STA_CONN_END_REASON 0x15 +#define BLUFI_TYPE_DATA_SUBTYPE_STA_CONN_RSSI 0x16 #define BLUFI_TYPE_IS_CTRL(type) (BLUFI_GET_TYPE((type)) == BLUFI_TYPE_CTRL) #define BLUFI_TYPE_IS_DATA(type) (BLUFI_GET_TYPE((type)) == BLUFI_TYPE_DATA) diff --git a/examples/bluetooth/blufi/main/Kconfig.projbuild b/examples/bluetooth/blufi/main/Kconfig.projbuild new file mode 100644 index 0000000000..3ede60cb2e --- /dev/null +++ b/examples/bluetooth/blufi/main/Kconfig.projbuild @@ -0,0 +1,10 @@ +menu "Example Configuration" + + config EXAMPLE_WIFI_CONNECTION_MAXIMUM_RETRY + int "WiFi connection maximum retry" + range 0 255 + default 2 + help + WiFi connection maximum retry, from 0 to 255. + +endmenu diff --git a/examples/bluetooth/blufi/main/blufi_example_main.c b/examples/bluetooth/blufi/main/blufi_example_main.c index 460ee7fac7..c1eae029c5 100644 --- a/examples/bluetooth/blufi/main/blufi_example_main.c +++ b/examples/bluetooth/blufi/main/blufi_example_main.c @@ -37,6 +37,10 @@ #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x" #endif +#define EXAMPLE_WIFI_CONNECTION_MAXIMUM_RETRY CONFIG_EXAMPLE_WIFI_CONNECTION_MAXIMUM_RETRY +#define EXAMPLE_INVALID_REASON 255 +#define EXAMPLE_INVALID_RSSI -128 + static void example_event_callback(esp_blufi_cb_event_t event, esp_blufi_cb_param_t *param); #define WIFI_LIST_NUM 10 @@ -52,13 +56,53 @@ static EventGroupHandle_t wifi_event_group; to the AP with an IP? */ const int CONNECTED_BIT = BIT0; +static uint8_t example_wifi_retry = 0; + /* store the station info for send back to phone */ static bool gl_sta_connected = false; +static bool gl_sta_got_ip = false; static bool ble_is_connected = false; static uint8_t gl_sta_bssid[6]; static uint8_t gl_sta_ssid[32]; static int gl_sta_ssid_len; static wifi_sta_list_t gl_sta_list; +static bool gl_sta_is_connecting = false; +static esp_blufi_extra_info_t gl_sta_conn_info; + +static void example_record_wifi_conn_info(int rssi, uint8_t reason) +{ + memset(&gl_sta_conn_info, 0, sizeof(esp_blufi_extra_info_t)); + if (gl_sta_is_connecting) { + gl_sta_conn_info.sta_max_conn_retry_set = true; + gl_sta_conn_info.sta_max_conn_retry = EXAMPLE_WIFI_CONNECTION_MAXIMUM_RETRY; + } else { + gl_sta_conn_info.sta_conn_rssi_set = true; + gl_sta_conn_info.sta_conn_rssi = rssi; + gl_sta_conn_info.sta_conn_end_reason_set = true; + gl_sta_conn_info.sta_conn_end_reason = reason; + } +} + +static void example_wifi_connect(void) +{ + example_wifi_retry = 0; + gl_sta_is_connecting = (esp_wifi_connect() == ESP_OK); + example_record_wifi_conn_info(EXAMPLE_INVALID_RSSI, EXAMPLE_INVALID_REASON); +} + +static bool example_wifi_reconnect(void) +{ + bool ret; + if (gl_sta_is_connecting && example_wifi_retry++ < EXAMPLE_WIFI_CONNECTION_MAXIMUM_RETRY) { + BLUFI_INFO("BLUFI WiFi starts reconnection\n"); + gl_sta_is_connecting = (esp_wifi_connect() == ESP_OK); + example_record_wifi_conn_info(EXAMPLE_INVALID_RSSI, EXAMPLE_INVALID_REASON); + ret = true; + } else { + ret = false; + } + return ret; +} static int softap_get_current_connection_number(void) { @@ -89,6 +133,7 @@ static void ip_event_handler(void* arg, esp_event_base_t event_base, info.sta_bssid_set = true; info.sta_ssid = gl_sta_ssid; info.sta_ssid_len = gl_sta_ssid_len; + gl_sta_got_ip = true; if (ble_is_connected == true) { esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_SUCCESS, softap_get_current_connection_number(), &info); } else { @@ -106,27 +151,35 @@ static void wifi_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) { wifi_event_sta_connected_t *event; + wifi_event_sta_disconnected_t *disconnected_event; wifi_mode_t mode; switch (event_id) { case WIFI_EVENT_STA_START: - esp_wifi_connect(); + example_wifi_connect(); break; case WIFI_EVENT_STA_CONNECTED: gl_sta_connected = true; + gl_sta_is_connecting = false; event = (wifi_event_sta_connected_t*) event_data; memcpy(gl_sta_bssid, event->bssid, 6); memcpy(gl_sta_ssid, event->ssid, event->ssid_len); gl_sta_ssid_len = event->ssid_len; break; case WIFI_EVENT_STA_DISCONNECTED: + /* Only handle reconnection during connecting */ + if (gl_sta_connected == false && example_wifi_reconnect() == false) { + gl_sta_is_connecting = false; + disconnected_event = (wifi_event_sta_disconnected_t*) event_data; + example_record_wifi_conn_info(disconnected_event->rssi, disconnected_event->reason); + } /* This is a workaround as ESP32 WiFi libs don't currently auto-reassociate. */ gl_sta_connected = false; + gl_sta_got_ip = false; memset(gl_sta_ssid, 0, 32); memset(gl_sta_bssid, 0, 6); gl_sta_ssid_len = 0; - esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; case WIFI_EVENT_AP_START: @@ -135,9 +188,17 @@ static void wifi_event_handler(void* arg, esp_event_base_t event_base, /* TODO: get config or information of softap, then set to report extra_info */ if (ble_is_connected == true) { if (gl_sta_connected) { - esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_SUCCESS, softap_get_current_connection_number(), NULL); + esp_blufi_extra_info_t info; + memset(&info, 0, sizeof(esp_blufi_extra_info_t)); + memcpy(info.sta_bssid, gl_sta_bssid, 6); + info.sta_bssid_set = true; + info.sta_ssid = gl_sta_ssid; + info.sta_ssid_len = gl_sta_ssid_len; + esp_blufi_send_wifi_conn_report(mode, gl_sta_got_ip ? ESP_BLUFI_STA_CONN_SUCCESS : ESP_BLUFI_STA_NO_IP, softap_get_current_connection_number(), &info); + } else if (gl_sta_is_connecting) { + esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONNECTING, softap_get_current_connection_number(), &gl_sta_conn_info); } else { - esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_FAIL, softap_get_current_connection_number(), NULL); + esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_FAIL, softap_get_current_connection_number(), &gl_sta_conn_info); } } else { BLUFI_INFO("BLUFI BLE is not connected yet\n"); @@ -213,6 +274,7 @@ static void initialise_wifi(void) wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK( esp_wifi_init(&cfg) ); ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) ); + example_record_wifi_conn_info(EXAMPLE_INVALID_RSSI, EXAMPLE_INVALID_REASON); ESP_ERROR_CHECK( esp_wifi_start() ); } @@ -259,7 +321,7 @@ static void example_event_callback(esp_blufi_cb_event_t event, esp_blufi_cb_para so disconnect wifi before connection. */ esp_wifi_disconnect(); - esp_wifi_connect(); + example_wifi_connect(); break; case ESP_BLUFI_EVENT_REQ_DISCONNECT_FROM_AP: BLUFI_INFO("BLUFI requset wifi disconnect from AP\n"); @@ -275,17 +337,17 @@ static void example_event_callback(esp_blufi_cb_event_t event, esp_blufi_cb_para esp_wifi_get_mode(&mode); - - if (gl_sta_connected) { memset(&info, 0, sizeof(esp_blufi_extra_info_t)); memcpy(info.sta_bssid, gl_sta_bssid, 6); info.sta_bssid_set = true; info.sta_ssid = gl_sta_ssid; info.sta_ssid_len = gl_sta_ssid_len; - esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_SUCCESS, softap_get_current_connection_number(), &info); + esp_blufi_send_wifi_conn_report(mode, gl_sta_got_ip ? ESP_BLUFI_STA_CONN_SUCCESS : ESP_BLUFI_STA_NO_IP, softap_get_current_connection_number(), &info); + } else if (gl_sta_is_connecting) { + esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONNECTING, softap_get_current_connection_number(), &gl_sta_conn_info); } else { - esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_FAIL, softap_get_current_connection_number(), NULL); + esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_FAIL, softap_get_current_connection_number(), &gl_sta_conn_info); } BLUFI_INFO("BLUFI get wifi status from AP\n"); @@ -360,7 +422,10 @@ static void example_event_callback(esp_blufi_cb_event_t event, esp_blufi_cb_para .channel = 0, .show_hidden = false }; - esp_wifi_scan_start(&scanConf, true); + esp_err_t ret = esp_wifi_scan_start(&scanConf, true); + if (ret != ESP_OK) { + esp_blufi_send_error_info(ESP_BLUFI_WIFI_SCAN_FAIL); + } break; } case ESP_BLUFI_EVENT_RECV_CUSTOM_DATA: From dcdae209723b457a16e129e9815261d498607339 Mon Sep 17 00:00:00 2001 From: liuning Date: Mon, 19 Sep 2022 16:44:31 +0800 Subject: [PATCH 3/6] docs: update BluFi documentation --- docs/en/api-guides/blufi.rst | 25 +++++++++++++++++++++++-- docs/zh_CN/api-guides/blufi.rst | 24 ++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/docs/en/api-guides/blufi.rst b/docs/en/api-guides/blufi.rst index d9743dba67..c23f265867 100644 --- a/docs/en/api-guides/blufi.rst +++ b/docs/en/api-guides/blufi.rst @@ -292,14 +292,20 @@ The format of Ack Frame(8 bit): | | | | 0x03: SoftAP&STA | + + + +-----------------------------------------------------------------------+ | | | | data[1]:the connection state of the STA device, | - | | | | 0x0 indicates a connection state, | - | | | | and others represent a disconnected state; | + | | | | 0x0 indicates a connection state with IP address, | + | | | | 0x1 represent a disconnected state, | + | | | | 0x2 indicates a connecting state, | + | | | | and 0x3 indicates a connection state but no IP address. | + + + +-----------------------------------------------------------------------+ | | | | data[2]:the connection state of the SoftAP, | | | | | that is, how many STA devices have been connected. | + + + +-----------------------------------------------------------------------+ | | | | data[3] and the subsequent is in accordance with the | | | | | format of SSID/BSSID information. | + | | | | If device is in connecting state, | + | | | | maximum Wi-Fi reconnecting time would be included here. | + | | | | If device is in disconnected state, | + | | | | Wi-Fi connection end reason and RSSI would be included here. | +------------------+----------------------------------------------------+---------------------------------------------------------------+-----------------------------------------------------------------------+ | 0x10 (b’010000) | Version | | data[0]= great versiondata[1]= sub version | +------------------+----------------------------------------------------+---------------------------------------------------------------+-----------------------------------------------------------------------+ @@ -324,10 +330,25 @@ The format of Ack Frame(8 bit): | | | | 0x07: read param error | + + + +-----------------------------------------------------------------------+ | | | | 0x08: make public error | + + + + +-----------------------------------------------------------------------+ + | | | | 0x09: data format error | + + + + +-----------------------------------------------------------------------+ + | | | | 0x0a: calculate MD5 error | + + + + +-----------------------------------------------------------------------+ + | | | | 0x0b: Wi-Fi scan error | +------------------+----------------------------------------------------+---------------------------------------------------------------+-----------------------------------------------------------------------+ | 0x13 (b’010011) | Custom Data | To send or receive custom data. | The data frame supports to be sent into | | | | | fragments if the data length is too long. | +------------------+----------------------------------------------------+---------------------------------------------------------------+-----------------------------------------------------------------------+ + | 0x14 (b’010100) | Set the maximum Wi-Fi reconnecting time | | data[0] represents the maximum Wi-Fi reconnecting time. | + +------------------+----------------------------------------------------+---------------------------------------------------------------+-----------------------------------------------------------------------+ + | 0x15 (b’010101) | Set the Wi-Fi connection end reason | | data[0] represents the Wi-Fi connection end reason, | + | | | | whose type shall be same with struct `wifi_err_reason_t`. | + +------------------+----------------------------------------------------+---------------------------------------------------------------+-----------------------------------------------------------------------+ + | 0x16 (b’010110) | Set the RSSI at Wi-Fi connection end | | data[0] represents the RSSI at Wi-Fi connection end. | + | | | | If there is no meaningful RSSI in the connection end, | + | | | | this value shall be the meaningless one, which is `-128`. | + +------------------+----------------------------------------------------+---------------------------------------------------------------+-----------------------------------------------------------------------+ 2. Frame Control diff --git a/docs/zh_CN/api-guides/blufi.rst b/docs/zh_CN/api-guides/blufi.rst index 6d443d6f26..efb8d2595e 100644 --- a/docs/zh_CN/api-guides/blufi.rst +++ b/docs/zh_CN/api-guides/blufi.rst @@ -295,12 +295,17 @@ Ack 帧格式(8 bit): + + + +------------------------------------------------------+ | | | | data[1]:STA 的连接状态, | | | | | 0x0 表示处于连接状态, | - | | | | 其他表示处于非连接状态; | + | | | | 0x1 表示处于非连接状态, | + | | | | 0x2 表示处于正在连接状态, | + | | | | 0x3 表示处于连接状态但未获得 IP 地址。 | + + + +------------------------------------------------------+ | | | | data[2]:SoftAP 的连接状态, | | | | | 即表示有多少 STA 已经连接。 | + + + +------------------------------------------------------+ | | | | data[3] 及以后:为按照本协议格式 SSID\BSSID 等信息。 | + | | | | 如果 Wi-Fi 处于正在连接状态,这里将会有最大重连次数;| + | | | | 如果 Wi-Fi 处于非连接状态, | + | | | | 这里将会包含 Wi-Fi 断开连接原因和 RSSI 信息。 | +---------------+----------------------------------------+------------------------------------------------+------------------------------------------------------+ | 0x10 b’010000 | Version. | | data[0]= great version | + + + +------------------------------------------------------+ @@ -326,9 +331,24 @@ Ack 帧格式(8 bit): | | | | 0x07: read param error; | + + + +------------------------------------------------------+ | | | | 0x08: make public error. | + + + + +------------------------------------------------------+ + | | | | 0x09: data format error | + + + + +------------------------------------------------------+ + | | | | 0x0a: calculate MD5 error | + + + + +------------------------------------------------------+ + | | | | 0x0b: Wi-Fi scan error | +---------------+----------------------------------------+------------------------------------------------+------------------------------------------------------+ |0x13 (b’010011)| Custom data. | 用户发送或者接收自定义数据。 | 数据较长时可分片发送。 | +---------------+----------------------------------------+------------------------------------------------+------------------------------------------------------+ + |0x14 (b’010100)| Set the max Wi-Fi reconnecting time. | | data[0] 表示 Wi-Fi 最大重连次数。 | + +---------------+----------------------------------------+------------------------------------------------+------------------------------------------------------+ + |0x15 (b’010101)| Set the Wi-Fi connection end reason. | | data[0] 表示 Wi-Fi 连接失败原因, | + | | | | 它的类型应该和 `wifi_err_reason_t` 一致。 | + +---------------+----------------------------------------+------------------------------------------------+------------------------------------------------------+ + |0x16 (b’010110)| Set the RSSI at Wi-Fi connection end. | | data[0] 表示在 Wi-Fi 连接失败时的 RSSI。 | + | | | | 如果在连接结束时没有有意义的 RSSI , | + | | | | 这个值应该为一个无意义值 `-128`。 | + +---------------+----------------------------------------+------------------------------------------------+------------------------------------------------------+ 2. Frame Control @@ -448,4 +468,4 @@ BluFi Service UUID: 0xFFFF,16 bit BluFi (手机 -> ESP32) 特性:0xFF01,主要权限:可写 -BluFi (ESP32 -> 手机) 特性:0xFF02,主要权限:可读可通知 \ No newline at end of file +BluFi (ESP32 -> 手机) 特性:0xFF02,主要权限:可读可通知 From 312da39eb97a1ae833e614f6b972acde9af82a7a Mon Sep 17 00:00:00 2001 From: liuning Date: Sun, 9 Oct 2022 16:55:15 +0800 Subject: [PATCH 4/6] esp_wifi: fix some connectionless related issue --- components/esp_wifi/include/esp_wifi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/esp_wifi/include/esp_wifi.h b/components/esp_wifi/include/esp_wifi.h index 4addf9dd17..e25cce5a1a 100644 --- a/components/esp_wifi/include/esp_wifi.h +++ b/components/esp_wifi/include/esp_wifi.h @@ -1245,7 +1245,7 @@ esp_err_t esp_wifi_config_11b_rate(wifi_interface_t ifx, bool disable); * @attention 3. This configuration would influence nothing until some module configure wake_window * @attention 4. A sensible interval which is not too small is recommended (e.g. 100ms) * - * @param interval how much micriosecond would the chip wake up, from 1 to 65535. + * @param interval how much milliseconds would the chip wake up, from 1 to 65535. */ esp_err_t esp_wifi_set_connectionless_wake_interval(uint16_t interval); From ce2deab1a47274042d83d9d3b2bf4935fbfda7d8 Mon Sep 17 00:00:00 2001 From: liuning Date: Thu, 24 Nov 2022 20:18:27 +0800 Subject: [PATCH 5/6] phy: only set phy_init_flag at power domain off, when all modems deinit --- components/bt/controller/esp32/bt.c | 12 ++++++++++-- components/bt/controller/esp32c3/bt.c | 20 ++++++++------------ components/esp_wifi/include/esp_phy_init.h | 4 ++-- components/esp_wifi/src/phy_init.c | 18 ++++++++++++------ components/esp_wifi/src/wifi_init.c | 7 ++----- 5 files changed, 34 insertions(+), 27 deletions(-) diff --git a/components/bt/controller/esp32/bt.c b/components/bt/controller/esp32/bt.c index 502f233733..6112b31815 100644 --- a/components/bt/controller/esp32/bt.c +++ b/components/bt/controller/esp32/bt.c @@ -1215,14 +1215,16 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) ESP_LOGI(BTDM_LOG_TAG, "BT controller compile version [%s]", btdm_controller_get_compile_version()); + esp_phy_modem_init(); + + esp_bt_power_domain_on(); + s_wakeup_req_sem = semphr_create_wrapper(1, 0); if (s_wakeup_req_sem == NULL) { err = ESP_ERR_NO_MEM; goto error; } - esp_bt_power_domain_on(); - btdm_controller_mem_init(); periph_module_enable(PERIPH_BT_MODULE); @@ -1335,6 +1337,10 @@ error: semphr_delete_wrapper(s_wakeup_req_sem); s_wakeup_req_sem = NULL; } + + esp_bt_power_domain_off(); + + esp_phy_modem_deinit(); return err; } @@ -1380,6 +1386,8 @@ esp_err_t esp_bt_controller_deinit(void) esp_bt_power_domain_off(); + esp_phy_modem_deinit(); + return ESP_OK; } diff --git a/components/bt/controller/esp32c3/bt.c b/components/bt/controller/esp32c3/bt.c index b6c21c639d..137e670b66 100644 --- a/components/bt/controller/esp32c3/bt.c +++ b/components/bt/controller/esp32c3/bt.c @@ -1093,15 +1093,11 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) #if CONFIG_MAC_BB_PD esp_mac_bb_pd_mem_init(); #endif + esp_phy_modem_init(); esp_bt_power_domain_on(); sdk_config_extend_set_pll_track(false); -#if CONFIG_MAC_BB_PD - esp_mac_bb_pd_mem_init(); -#endif - esp_phy_pd_mem_init(); - btdm_controller_mem_init(); #if CONFIG_MAC_BB_PD @@ -1339,11 +1335,12 @@ error: esp_unregister_mac_bb_pu_callback(btdm_mac_bb_power_up_cb); #endif - + esp_bt_power_domain_off(); #if CONFIG_MAC_BB_PD esp_mac_bb_pd_mem_deinit(); #endif - esp_phy_pd_mem_deinit(); + esp_phy_modem_deinit(); + if (osi_funcs_p != NULL) { free(osi_funcs_p); osi_funcs_p = NULL; @@ -1420,12 +1417,11 @@ esp_err_t esp_bt_controller_deinit(void) esp_unregister_mac_bb_pu_callback(btdm_mac_bb_power_up_cb); #endif - /* Fix the issue caused by the power off the bt power domain. - * This issue is only on ESP32C3. - */ - phy_init_flag(); - esp_bt_power_domain_off(); +#if CONFIG_MAC_BB_PD + esp_mac_bb_pd_mem_deinit(); +#endif + esp_phy_modem_deinit(); free(osi_funcs_p); osi_funcs_p = NULL; diff --git a/components/esp_wifi/include/esp_phy_init.h b/components/esp_wifi/include/esp_phy_init.h index a22ac25a00..9c25ce6826 100644 --- a/components/esp_wifi/include/esp_phy_init.h +++ b/components/esp_wifi/include/esp_phy_init.h @@ -181,12 +181,12 @@ void esp_phy_load_cal_and_init(void); /** * @brief Initialize backup memory for Phy power up/down */ -void esp_phy_pd_mem_init(void); +void esp_phy_modem_init(void); /** * @brief Deinitialize backup memory for Phy power up/down */ -void esp_phy_pd_mem_deinit(void); +void esp_phy_modem_deinit(void); #if CONFIG_MAC_BB_PD /** diff --git a/components/esp_wifi/src/phy_init.c b/components/esp_wifi/src/phy_init.c index 72e354a1b9..d46b818952 100644 --- a/components/esp_wifi/src/phy_init.c +++ b/components/esp_wifi/src/phy_init.c @@ -85,7 +85,7 @@ static DRAM_ATTR portMUX_TYPE s_phy_int_mux = portMUX_INITIALIZER_UNLOCKED; /* Memory to store PHY digital registers */ static uint32_t* s_phy_digital_regs_mem = NULL; -static uint8_t s_phy_backup_mem_ref = 0; +static uint8_t s_phy_modem_init_ref = 0; #if CONFIG_MAC_BB_PD uint32_t* s_mac_bb_pd_mem = NULL; @@ -311,11 +311,11 @@ void esp_wifi_bt_power_domain_off(void) _lock_release(&s_wifi_bt_pd_controller.lock); } -void esp_phy_pd_mem_init(void) +void esp_phy_modem_init(void) { _lock_acquire(&s_phy_access_lock); - s_phy_backup_mem_ref++; + s_phy_modem_init_ref++; if (s_phy_digital_regs_mem == NULL) { s_phy_digital_regs_mem = (uint32_t *)heap_caps_malloc(SOC_PHY_DIG_REGS_MEM_SIZE, MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); } @@ -324,15 +324,21 @@ void esp_phy_pd_mem_init(void) } -void esp_phy_pd_mem_deinit(void) +void esp_phy_modem_deinit(void) { _lock_acquire(&s_phy_access_lock); - s_phy_backup_mem_ref--; - if (s_phy_backup_mem_ref == 0) { + s_phy_modem_init_ref--; + if (s_phy_modem_init_ref == 0) { s_is_phy_reg_stored = false; free(s_phy_digital_regs_mem); s_phy_digital_regs_mem = NULL; + /* Fix the issue caused by the power domain off. + * This issue is only on ESP32C3. + */ +#if CONFIG_IDF_TARGET_ESP32C3 + phy_init_flag(); +#endif } _lock_release(&s_phy_access_lock); diff --git a/components/esp_wifi/src/wifi_init.c b/components/esp_wifi/src/wifi_init.c index c7ffcc55b5..37446c0293 100644 --- a/components/esp_wifi/src/wifi_init.c +++ b/components/esp_wifi/src/wifi_init.c @@ -140,15 +140,12 @@ esp_err_t esp_wifi_deinit(void) #if CONFIG_MAC_BB_PD esp_unregister_mac_bb_pd_callback(pm_mac_sleep); esp_unregister_mac_bb_pu_callback(pm_mac_wakeup); -#endif -#if CONFIG_IDF_TARGET_ESP32C3 - phy_init_flag(); #endif esp_wifi_power_domain_off(); #if CONFIG_MAC_BB_PD esp_mac_bb_pd_mem_deinit(); #endif - esp_phy_pd_mem_deinit(); + esp_phy_modem_deinit(); return err; } @@ -268,7 +265,7 @@ esp_err_t esp_wifi_init(const wifi_init_config_t *config) esp_mac_bb_pd_mem_init(); esp_wifi_internal_set_mac_sleep(true); #endif - esp_phy_pd_mem_init(); + esp_phy_modem_init(); #if CONFIG_IDF_TARGET_ESP32 s_wifi_mac_time_update_cb = esp_wifi_internal_update_mac_time; #endif From a02a385ee22de18a4b64ad8668bd1cedb21f0735 Mon Sep 17 00:00:00 2001 From: liuning Date: Thu, 15 Dec 2022 10:14:32 +0800 Subject: [PATCH 6/6] esp_wifi: update lib --- components/esp_wifi/lib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index f949345782..ec3f7f8522 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit f9493457825aabe75391eacc83c4792c26426800 +Subproject commit ec3f7f8522f875a5461aecf913123892b70232de