mirror of
https://github.com/espressif/esp-idf
synced 2025-03-10 01:29:21 -04:00
Merge branch 'feature/backport_blufi_coexist_phy_init_flag_v4.3' into 'release/v4.3'
esp_wifi: backport coexist fix, connectionless ps fix, blufi feature See merge request espressif/esp-idf!21609
This commit is contained in:
commit
ec25f91a9d
@ -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 */
|
||||
|
@ -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:{
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
/**
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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 */
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit f9493457825aabe75391eacc83c4792c26426800
|
||||
Subproject commit ec3f7f8522f875a5461aecf913123892b70232de
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
10
examples/bluetooth/blufi/main/Kconfig.projbuild
Normal file
10
examples/bluetooth/blufi/main/Kconfig.projbuild
Normal file
@ -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
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user