Found next issues on SDK 1.5.4 when switching from STA to AP.
First of all always when switching from STA to AP any connection to AP is now not possible until reboot. AP is seen but when client trying to connect - it always fail with something like "authentication failed".
Second, sometimes when switching from STA to AP I having LoadProhibitedCause exception at address 0x4022aa03:
Code: Select all
4022a9f8 <netif_set_up>:
4022a9f8: f0c112 addi a1, a1, -16
4022a9fb: 0161c2 s32i a12, a1, 4
4022a9fe: 006102 s32i a0, a1, 0
4022aa01: 02cd mov.n a12, a2
4022aa03: 390202 l8ui a0, a2, 57
4022aa06: 120c movi.n a2, 1
4022aa08: 1de007 bbsi a0, 0, 4022aa29 <netif_set_up+0x31>
4022aa0b: 200020 or a0, a0, a2
4022aa0e: 394c02 s8i a0, a12, 57
4022aa11: 146047 bbci a0, 4, 4022aa29 <netif_set_up+0x31>
4022aa14: 096057 bbci a0, 5, 4022aa21 <netif_set_up+0x29>
4022aa17: 0c2d mov.n a2, a12
4022aa19: 3c4b addi.n a3, a12, 4
4022aa1b: fee485 call0 40229864 <etharp_request>
4022aa1e: 390c02 l8ui a0, a12, 57
4022aa21: 046077 bbci a0, 7, 4022aa29 <netif_set_up+0x31>
4022aa24: 0c2d mov.n a2, a12
4022aa26: fef9c5 call0 402299c4 <igmp_report_groups>
4022aa29: 11c8 l32i.n a12, a1, 4
4022aa2b: 0108 l32i.n a0, a1, 0
4022aa2d: 10c112 addi a1, a1, 16
4022aa30: f00d ret.n
And here is my code I'm using to switch between WiFi modes:
Code: Select all
LOCAL bool ICACHE_FLASH_ATTR setup_wifi_ap_mode()
{
struct softap_config apconfig;
if(wifi_softap_get_config(&apconfig))
{
if (wifi_get_opmode() == STATION_MODE)
{
wifi_station_disconnect();
wifi_station_dhcpc_stop();
}
wifi_set_opmode(SOFTAP_MODE);
wifi_set_phy_mode(PHY_MODE_11G); // N only supported in STA
wifi_set_sleep_type(NONE_SLEEP_T);
os_memset(apconfig.ssid, 0, sizeof(apconfig.ssid));
os_memset(apconfig.password, 0, sizeof(apconfig.password));
apconfig.ssid_len = os_sprintf(apconfig.ssid, _sys_cfg.ap_ssid);
os_sprintf(apconfig.password, "%s", _sys_cfg.ap_pass);
apconfig.authmode = _sys_cfg.ap_authmode;
apconfig.ssid_hidden = _sys_cfg.ap_hidden;
apconfig.channel = _sys_cfg.ap_channel;
apconfig.max_connection = 4;
apconfig.beacon_interval = 100;
if(wifi_softap_set_config(&apconfig))
{
wifi_softap_dhcps_stop();
struct ip_info ipinfo;
wifi_get_ip_info(SOFTAP_IF, &ipinfo);
char *ip = (char *)_sys_cfg.ap_ip;
char *mask = (char *)_sys_cfg.ap_mask;
char *gw = (char *)_sys_cfg.ap_gw;
if (ip) ipinfo.ip.addr = ipaddr_addr(ip);
if (mask) ipinfo.netmask.addr = ipaddr_addr(mask);
if (gw) ipinfo.gw.addr = ipaddr_addr(gw);
wifi_set_ip_info(SOFTAP_IF, &ipinfo);
wifi_softap_dhcps_start();
return true;
}
}
return false;
}
LOCAL bool ICACHE_FLASH_ATTR setup_wifi_station_mode()
{
struct station_config stconfig;
if(wifi_station_get_config(&stconfig))
{
if (wifi_get_opmode() == SOFTAP_MODE)
{
wifi_softap_dhcps_stop();
}
wifi_set_opmode(STATION_MODE);
wifi_set_phy_mode(PHY_MODE_11N); // N only supported in STA
wifi_set_sleep_type(NONE_SLEEP_T);
os_memset(stconfig.ssid, 0, sizeof(stconfig.ssid));
os_memset(stconfig.password, 0, sizeof(stconfig.password));
os_sprintf(stconfig.ssid, "%s", _sys_cfg.sta_ssid);
os_sprintf(stconfig.password, "%s", _sys_cfg.sta_pass);
stconfig.bssid_set = 0;
if(wifi_station_set_config(&stconfig))
{
wifi_station_disconnect();
wifi_station_dhcpc_stop();
wifi_station_set_hostname((char *)_sys_cfg.hostname);
wifi_station_connect();
wifi_station_dhcpc_start();
wifi_station_set_auto_connect(1);
return true;
}
}
return false;
}
Steps to reproduce:
1) start in AP mode (all ok)
2) switch to STA mode (all ok)
3) switch again to AP mode (fail)
Sometimes DHCP server even not starting (no line in console telling that "dhcp server start:(ip... mask.... gw...)")
Any ideas?
UPD:
Looks like SDK dislike "wifi_set_phy_mode" calls. I have removed it, and now all fine. Now the question is: if I set iee80211.n mode before any wifi operations, what mode will be used for STA and AP? G or N? and what mode will be if I switch between bettwen STA and AP in runtime?