【Feedback】WiFi mode switch STA<->AP: LoadProhibitedCause and connection issue

DarkSide
Posts: 29
Joined: Mon Apr 06, 2015 6:51 pm

【Feedback】WiFi mode switch STA<->AP: LoadProhibitedCause and connection issue

Postby DarkSide » Wed Jun 08, 2016 7:03 am

Hello.
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?

ESP_Faye
Posts: 1643
Joined: Mon Oct 27, 2014 11:08 am

Re: WiFi mode switch STA<->AP: LoadProhibitedCause and connection issue

Postby ESP_Faye » Fri Jun 17, 2016 2:55 pm

Hi,

Please have a try with the attachment based on ESP8266_NONOS_SDK_V1.5.4.

If your problem is still unsolved, please feel free to let us know.
Attachments
set_phy_mode_issue_test_160617.zip
(168.31 KiB) Downloaded 343 times

DarkSide
Posts: 29
Joined: Mon Apr 06, 2015 6:51 pm

Re: WiFi mode switch STA<->AP: LoadProhibitedCause and connection issue

Postby DarkSide » Sat Jun 18, 2016 12:53 am

Yes, this patch have solved issue.
But, can you please tell me, do I actually need to manually change PHY mode? In my case I need STA mode in "N" and AP mode in "G" (because AP does not work in "N" per specification). Or it will be enough to call wifi_set_phy_mode(PHY_MODE_11N) after platform start and it will automatically fallback to "G" mode when switched to AP and back to "N" when switched to STA?

DG2016
Posts: 3
Joined: Mon Jun 20, 2016 10:16 pm

Re: WiFi mode switch STA<->AP: LoadProhibitedCause and connection issue

Postby DG2016 » Mon Jun 20, 2016 10:42 pm

Dear all,

I am new in the ESP8266 community, so I was browsing the forum in order to get some insights about the dhcp server. While I was doing so, I stumbled across this post which I found interesting.

I need to configure the chip in station mode, and I also want to host a dhcp server that can configure the host. In particular I want to configure the host's DNS server via the offer option number 6 of the dhcp server.

Do you think this is possible? Because I have always seen that the dhcp server is used in combination with softAP mode (which of course makes sense), but that is not what I want.

Thanks in advance!!

ESP_Faye
Posts: 1643
Joined: Mon Oct 27, 2014 11:08 am

Re: WiFi mode switch STA<->AP: LoadProhibitedCause and connection issue

Postby ESP_Faye » Wed Jun 22, 2016 11:54 am

Hi,

In particular I want to configure the host's DNS server via the offer option number 6 of the dhcp server.

Sorry that I do not really understand your request.
Can APIs below help ?

Code: Select all

wifi_set_opmode(STATIONAP_MODE);
wifi_softap_set_dhcps_offer_option
espconn_dns_setserver

DarkSide
Posts: 29
Joined: Mon Apr 06, 2015 6:51 pm

Re: 【Feedback】WiFi mode switch STA<->AP: LoadProhibitedCause and connection issue

Postby DarkSide » Thu Jul 07, 2016 5:22 pm

I still waiting for reply to my question:
But, can you please tell me, do I actually need to manually change PHY mode? In my case I need STA mode in "N" and AP mode in "G" (because AP does not work in "N" per specification). Or it will be enough to call wifi_set_phy_mode(PHY_MODE_11N) after platform start and it will automatically fallback to "G" mode when switched to AP and back to "N" when switched to STA?

Who is online

Users browsing this forum: No registered users and 1 guest