app/modules/enduser_setup.c
/**
 * Check Station
 *
 * Check that we've successfully entered station mode.
 */
Check Station
Check that we've successfully entered station mode.
Check Station Check that we ' ve successfully entered station mode .
static void enduser_setup_check_station(void *p)
{
  ENDUSER_SETUP_DEBUG("enduser_setup_check_station");
  (void)p;
  struct ip_info ip;
  c_memset(&ip, 0, sizeof(struct ip_info));
  wifi_get_ip_info(STATION_IF, &ip);
  int i;
  char has_ip = 0;
  for (i = 0; i < sizeof(struct ip_info); ++i)
  {
    has_ip |= ((char *) &ip)[i];
  }
  uint8_t currChan = wifi_get_channel();
  if (has_ip == 0)
  {
    uint8_t curr_status = wifi_station_get_connect_status();
    char buf[20];
    c_sprintf(buf, "status=%d,chan=%d", curr_status, currChan);
    ENDUSER_SETUP_DEBUG(buf);
    if (curr_status == 2 || curr_status == 3 || curr_status == 4)
    {
      state->connecting = 0;
      if (currChan != state->softAPchannel) {
        state->lastStationStatus = curr_status;
        ENDUSER_SETUP_DEBUG("Turning off Station due to different channel than AP");
        wifi_station_disconnect();
        wifi_set_opmode(SOFTAP_MODE);
        enduser_setup_ap_start();
      }
   }
   return;
  }
  state->success = 1;
  state->lastStationStatus = 5; 
  state->connecting = 0;
#if ENDUSER_SETUP_DEBUG_ENABLE  
  char debuginfo[100];
  c_sprintf(debuginfo, "AP_CHAN: %d, STA_CHAN: %d", state->softAPchannel, currChan);
  ENDUSER_SETUP_DEBUG(debuginfo); 
#endif
  if (currChan == state->softAPchannel)
  {
    enduser_setup_connected_callback();
    state->callbackDone = 1;
  }
  else
  {
    ENDUSER_SETUP_DEBUG("Turning off Station due to different channel than AP");
    wifi_station_disconnect();
    wifi_set_opmode(SOFTAP_MODE);
    enduser_setup_ap_start();
  }
  enduser_setup_check_station_stop();
  if (!manual)
  {
    os_timer_setfn(&(state->shutdown_timer), enduser_setup_stop_callback, NULL);
    os_timer_arm(&(state->shutdown_timer), 10*1000, FALSE);
  }
}
static void enduser_setup_check_station ( void * p ) { ENDUSER_SETUP_DEBUG ( " " ) ; ( void ) p ; struct ip_info ip ; c_memset ( & ip , 0 , sizeof ( struct ip_info ) ) ; wifi_get_ip_info ( STATION_IF , & ip ) ; int i ; char has_ip = 0 ; for ( i = 0 ; i < sizeof ( struct ip_info ) ; ++ i ) { has_ip |= ( ( char * ) & ip ) [ i ] ; } uint8_t currChan = wifi_get_channel ( ) ; if ( has_ip == 0 ) { uint8_t curr_status = wifi_station_get_connect_status ( ) ; char buf [ 20 ] ; c_sprintf ( buf , " " , curr_status , currChan ) ; ENDUSER_SETUP_DEBUG ( buf ) ; if ( curr_status == 2 || curr_status == 3 || curr_status == 4 ) { state -> connecting = 0 ; if ( currChan != state -> softAPchannel ) { state -> lastStationStatus = curr_status ; ENDUSER_SETUP_DEBUG ( " " ) ; wifi_station_disconnect ( ) ; wifi_set_opmode ( SOFTAP_MODE ) ; enduser_setup_ap_start ( ) ; } } return ; } state -> success = 1 ; state -> lastStationStatus = 5 ; state -> connecting = 0 ; #if ENDUSER_SETUP_DEBUG_ENABLE char debuginfo [ 100 ] ; c_sprintf ( debuginfo , " " , state -> softAPchannel , currChan ) ; ENDUSER_SETUP_DEBUG ( debuginfo ) ; #endif if ( currChan == state -> softAPchannel ) { enduser_setup_connected_callback ( ) ; state -> callbackDone = 1 ; } else { ENDUSER_SETUP_DEBUG ( " " ) ; wifi_station_disconnect ( ) ; wifi_set_opmode ( SOFTAP_MODE ) ; enduser_setup_ap_start ( ) ; } enduser_setup_check_station_stop ( ) ; if ( ! manual ) { os_timer_setfn ( & ( state -> shutdown_timer ) , enduser_setup_stop_callback , NULL ) ; os_timer_arm ( & ( state -> shutdown_timer ) , 10 * 1000 , FALSE ) ; } }
Check Station
 Check that we've successfully entered station mode.
Check Station Check that we ' ve successfully entered station mode .
/* No IP Address yet, so check the reported status */ /* If the status is an error status and the channel changed, then cache the 
       * status to state since the Station won't be able to report the same status
       * after switching the channel back to the SoftAP's
       */ /*  We have an IP Address, so the status is 5 (as of SDK 1.5.1) */ /* Trigger shutdown, but allow time for HTTP client to fetch last status. */