示例#1
0
static void EasyConfigTimerHandler(SYS_TICK curSysTick)
{
    curSysTick = curSysTick;  // avoid warning

    // delete timer now that delay has occurred
    SYS_TICK_TimerDelete(g_easyConfigCtx.timer);

    // This function being called from timer interrupt, so don't do any work
    // here, but, schedule the async event handler to call EasyConfigStateMachine
    g_easyConfigCtx.isWifiNeedToConfigure = true;

    WifiAsyncSetEventPending(ASYNC_EASY_CONFIG_PENDING);


}
示例#2
0
/*******************************************************************************
  Function:    
    void EnsureWFisAwake()

  Summary:
    If PS-Poll is active or the MRF24W is asleep, ensure that it is woken up.

  Description:
    Called by the WiFi driver when it needs to transmit or receive a data or 
    mgmt message. If the application has enabled PS-Poll mode and the WiFi 
    driver has activated PS-Poll mode then this function will deactivate PS-Poll
    mode and wake up the MRF24W.

  Precondition:
    MACInit must be called first.

  Parameters:
    None.

  Returns:
    None.
      
  Remarks:
    None.
  *****************************************************************************/
void EnsureWFisAwake()
{
    /* if the application desires the MRF24W to be in PS-Poll mode (PS-Poll with DTIM enabled or disabled */
    if ((g_powerSaveState == DRV_WIFI_PS_PS_POLL_DTIM_ENABLED) || (g_powerSaveState == DRV_WIFI_PS_PS_POLL_DTIM_DISABLED)) 
    {
        /* if the WF driver has activated PS-Poll */
        if (g_psPollActive == true)
        {
            /* wake up MRF24W */
            WFConfigureLowPowerMode(WF_LOW_POWER_MODE_OFF);
        }    
            
        // will need to put device back into PS-Poll sleep mode after transaction
        SetSleepNeeded();
        WifiAsyncSetEventPending(ASYNC_POWER_SAVE_PENDING); // wake up power save task
    }
}        
/*****************************************************************************
 * FUNCTION: WFProcessMgmtIndicateMsg
 *
 * RETURNS:  error code
 *
 * PARAMS:   None
 *
 *  NOTES:   Processes a management indicate message
 *****************************************************************************/
void WFProcessMgmtIndicateMsg()
{
    tMgmtIndicateHdr  hdr;
    uint8_t buf[6];
    uint8_t event = 0xff;
    uint16_t eventInfo;

    // read mgmt indicate header (2 bytes)
    RawRead(RAW_SCRATCH_ID, MGMT_INDICATE_BASE, sizeof(tMgmtIndicateHdr), (uint8_t *)&hdr);

    /* if not a management indicate then fatal error */
    SYS_ASSERT((hdr.type == WF_MGMT_INDICATE_TYPE), "Invalid Indicate Header" );
        
    /* Determine which event occurred and handle it */
    switch (hdr.subType)
    {
        /*-----------------------------------------------------------------*/        
        case WF_EVENT_CONNECTION_ATTEMPT_STATUS_SUBTYPE:
        /*-----------------------------------------------------------------*/
            RawReadRelative(RAW_SCRATCH_ID, 2, buf); /* read first 2 bytes after header */
            /* if connection attempt successful */
            if (buf[0] == CONNECTION_ATTEMPT_SUCCESSFUL)
            {
                event     = DRV_WIFI_EVENT_CONNECTION_SUCCESSFUL;
                eventInfo = DRV_WIFI_NO_ADDITIONAL_INFO;
                SignalWiFiConnectionChanged(true);
                #if defined(TCPIP_STACK_USE_IPV6)
                    WF_Initialize_IPV6_Multicast_Filter();
                #endif
                #if defined (TCPIP_STACK_USE_DHCP_CLIENT)
                    RenewDhcp();
                #endif
                SetLogicalConnectionState(true);
            }
            /* else connection attempt failed */
            else
            {
                event     = DRV_WIFI_EVENT_CONNECTION_FAILED;
                eventInfo = (uint16_t)(buf[0] << 8 | buf[1]);   /* contains connection failure code */
                SetLogicalConnectionState(false);
            }
            break;
            
        /*-----------------------------------------------------------------*/
        case WF_EVENT_CONNECTION_LOST_SUBTYPE:
        /*-----------------------------------------------------------------*/ 
            /* read next two data bytes in message
               buf[0] -- 1: Connection temporarily lost  2: Connection permanently lost 3: Connection Reestablished 
               buf[1] -- 0: Beacon Timeout  1: Deauth from AP  */
            RawReadRelative(RAW_SCRATCH_ID, 2, buf);

            if (buf[0] == CONNECTION_TEMPORARILY_LOST)
            {
                event     = DRV_WIFI_EVENT_CONNECTION_TEMPORARILY_LOST;
                eventInfo = (uint16_t)buf[1];    /* lost due to beacon timeout or deauth */
                SignalWiFiConnectionChanged(false);
                
                SetLogicalConnectionState(false);
            }    
            else if (buf[0] == CONNECTION_PERMANENTLY_LOST)
            {
                event     = DRV_WIFI_EVENT_CONNECTION_PERMANENTLY_LOST;
                eventInfo = (uint16_t)buf[1];   /* lost due to beacon timeout or deauth */
                SetLogicalConnectionState(false);
                SignalWiFiConnectionChanged(false);                
            }
            else if (buf[0] == CONNECTION_REESTABLISHED)
            {
                event     = DRV_WIFI_EVENT_CONNECTION_REESTABLISHED;
                eventInfo = (uint16_t)buf[1];    /* originally lost due to beacon timeout or deauth */
                #if defined(TCPIP_STACK_USE_DHCP_CLIENT)
                RenewDhcp();
                #endif
                SignalWiFiConnectionChanged(true);  
                
                SetLogicalConnectionState(true);
            }    
            else
            {
                /* invalid parameter in message */
                SYS_ASSERT(false, "");
            }        
            break;
        
        /*-----------------------------------------------------------------*/                    
        case WF_EVENT_SCAN_RESULTS_READY_SUBTYPE:        
        /*-----------------------------------------------------------------*/
            RawReadRelative(RAW_SCRATCH_ID, 1, buf);
            event = DRV_WIFI_EVENT_SCAN_RESULTS_READY;
            eventInfo = (uint16_t)buf[0];          /* number of scan results */
            break;
            
        /*-----------------------------------------------------------------*/
        case WF_EVENT_SCAN_IE_RESULTS_READY_SUBTYPE:
        /*-----------------------------------------------------------------*/
            event = DRV_WIFI_EVENT_IE_RESULTS_READY;
            /* read indexes 2 and 3 containing the 16-bit value of IE bytes */
            RawReadRelative(RAW_SCRATCH_ID, 2, (uint8_t *)&eventInfo);
            eventInfo = TCPIP_Helper_ntohs(eventInfo);     /* fix endianess of 16-bit value */
            break;    
        
        /*-----------------------------------------------------------------*/
        case WF_EVENT_KEY_CALCULATION_REQUEST_SUBTYPE:
        /*-----------------------------------------------------------------*/
            event = DRV_WIFI_EVENT_KEY_CALCULATION_REQUEST;
            RawReadRelative(RAW_SCRATCH_ID, sizeof(tMgmtIndicatePassphraseReady), (uint8_t *)&passphraseReady);
            WifiAsyncSetEventPending(ASYNC_WPABUTTON_CONNECT);
            break;

        /*-----------------------------------------------------------------*/
        case WF_EVENT_SOFT_AP_EVENT_SUBTYPE:    /* Valid only with 3108 or the later module FW version */
        /*-----------------------------------------------------------------*/
            event = DRV_WIFI_EVENT_SOFT_AP;
            RawReadRelative(RAW_SCRATCH_ID, sizeof(DRV_WIFI_MGMT_INDICATE_SOFT_AP_EVENT), (uint8_t *)&g_softAPEvent);
            break;
            
        /*-----------------------------------------------------------------*/
        case WF_EVENT_DISCONNECT_DONE_SUBTYPE:
        /*-----------------------------------------------------------------*/
            event =  DRV_WIFI_EVENT_DISCONNECT_DONE;
            /* set state to no connection */
            SetLogicalConnectionState(false);
            break;
            
        /*-----------------------------------------------------------------*/
        default:
        /*-----------------------------------------------------------------*/
            SYS_ASSERT(false, "");
            break;        
    }

    /* if the application wants to be notified of the event */
    WF_UserEventsSet(event, eventInfo, 1);
}
示例#4
0
static int WFEasyConfigProcess(TCPIP_NET_IF* pNetIf)
{
#if 0  // should not be needed
    uint8_t ConnectionState;
#endif
    t_securityContext securityContext;
    
    #if defined (EZ_CONFIG_STALL)
        if (CFGCXT.cfg_state == cfg_stopped)
        {
            /* State machine just started get current time stamp */
            CFGCXT.cfg_state = cfg_stalled;
            CFGCXT.timeStart = SYS_TICK_Get();
            return false;
        }

        /* Wait for stall time to expire */
        if (CFGCXT.cfg_state == cfg_stalled)
        {
            SYS_TICK time = SYS_TICK_Get();
            if ((time - CFGCXT.timeStart) < (WF_EASY_CONFIG_DELAY_TIME * SYS_TICK_TicksPerSecondGet()))
            {
                return false;
            }
        }
    #endif //EZ_CONFIG_STALL

#if 0  // should not be needed
    /* We will re-use the current profile */
    WF_ConnectionStateGet(&ConnectionState);
#endif

    /* Need to disconnect */
    WF_Disconnect();

    /* Set SSID... */
    if (CFGCXT.ssid)
    {
        WF_SsidSet(CFGCXT.ssid, strlen((char*)CFGCXT.ssid));
    }

    /* Now deal with security... */
    switch ((uint8_t)CFGCXT.security)
    {
        case WF_SECURITY_OPEN: /* No security */
            WF_SecurityOpenSet();
            break; 

        case WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE:
            if (CFGCXT.key)
            {
                securityContext.wpaContext.wpaSecurityType = WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE;
                securityContext.wpaContext.keyInfo.keyLength = strlen((char *)CFGCXT.key);
                memcpy(securityContext.wpaContext.keyInfo.key, CFGCXT.key, securityContext.wpaContext.keyInfo.keyLength);
                WF_SecurityWpaSet(&securityContext.wpaContext);
            }
            break;

        case WF_SECURITY_WPA_AUTO_WITH_KEY:
            if (CFGCXT.key) 
            {
                securityContext.wpaContext.wpaSecurityType = WF_SECURITY_WPA_AUTO_WITH_KEY;
                securityContext.wpaContext.keyInfo.keyLength = 32;
                memcpy(securityContext.wpaContext.keyInfo.key, CFGCXT.key, 32);
                WF_SecurityWpaSet(&securityContext.wpaContext);
            }
            break;

        case WF_SECURITY_WEP_40:
            if (CFGCXT.key)
            {
                securityContext.wepContext.wepSecurityType = WF_SECURITY_WEP_40;
                securityContext.wepContext.wepKeyLength    = WF_WEP40_KEY_LENGTH;
                memset(CFGCXT.key, 0x00, WF_WEP40_KEY_LENGTH);
                memset(securityContext.wepContext.wepKey, 0x00, WF_WEP40_KEY_LENGTH);
                securityContext.wepContext.wepKeyType      = WF_SECURITY_WEP_OPENKEY;
                WF_SecurityWepSet(&securityContext.wepContext);
            }
            break;

        case WF_SECURITY_WEP_104:
            if (CFGCXT.key)
            {
                securityContext.wepContext.wepSecurityType = WF_SECURITY_WEP_104;
                securityContext.wepContext.wepKeyLength    = WF_WEP104_KEY_LENGTH;
                memset(CFGCXT.key, 0x00, WF_WEP104_KEY_LENGTH);
                memset(securityContext.wepContext.wepKey, 0x00, WF_WEP104_KEY_LENGTH);
                securityContext.wepContext.wepKeyType      = WF_SECURITY_WEP_OPENKEY;
                WF_SecurityWepSet(&securityContext.wepContext);
            }
            break;
    }
 
    #if defined (EZ_CONFIG_STORE) && defined(TCPIP_STACK_USE_STORAGE)
        #if 0
            TCPIP_STORAGE_HANDLE hS;
            hS = TCPIPStorageOpen(0, 1);
            TCPIPStorageSaveIfConfig(hS, "MRF24W", true);
            TCPIPStorageClose(hS);
        #else
            WF_ConfigDataSave();
        #endif
    #endif // defined (EZ_CONFIG_STORE)

    /* Set wlan mode */
    WF_NetworkTypeSet(CFGCXT.type);

#if defined(DISABLE_MODULE_FW_CONNECT_MANAGER_IN_INFRASTRUCTURE)
    WF_ReconnectModeSet(0,                                  // report-only when connection lost (no reconnect)
                        WF_DO_NOT_ATTEMPT_TO_RECONNECT,     // report-only when deauth received (no reconnect)
                        40,                                 // set beacon timeout to 40 beacon periods
                        WF_DO_NOT_ATTEMPT_TO_RECONNECT);    // report only when beacon timeout occurs
#endif
    //TCPIP_NET_IF* p_config= (TCPIP_NET_IF*)GetNetworkConfig();
    if (p_wifi_ConfigData->networkType == WF_NETWORK_TYPE_INFRASTRUCTURE)
    {
        WF_ReconnectModeSet(WF_RETRY_FOREVER,           // retry forever to connect to WiFi network
                            WF_ATTEMPT_TO_RECONNECT,    // reconnect on deauth from AP
                            40,                         // beacon timeout is 40 beacon periods
                            WF_ATTEMPT_TO_RECONNECT);   // reconnect on beacon timeout
    }

#if WF_DEFAULT_NETWORK_TYPE == WF_NETWORK_TYPE_SOFT_AP
    // SoftAP: To allow redirection, need to hibernate before changing network type. Module
    //         FW has SoftAP flag and therefore hibernate mode is needed to clear this
    //         indication and allow proper network change. This should work for non-SoftAP,
    //         but these have not been tested yet.
    #if 0
        WF_hibernate.state = WF_HB_ENTER_SLEEP;
        WF_hibernate.wakeup_notice = false;
        //WFConsolePrintRomStr("SoftAP redirection: Put Wi-Fi module into hibernate mode.", true);

        DelayMs(200);

        WF_hibernate.wakeup_notice = true;
        //WFConsolePrintRomStr("Wakeup Wi-Fi module.", true);
    #else
        extern bool SoftAP_Redirection_Enable;
        SoftAP_Redirection_Enable = true;
    #endif
#else
    /* Kick off connection now... */
    WF_Connect();
    #if defined(TCPIP_STACK_USE_EVENT_NOTIFICATION)
        WifiAsyncSetEventPending(ASYNC_DHCP_CONFIG_PENDING); // configure DHCP after init complete
    #endif
#endif
    /* Change state and return true to show we are done! */
    CFGCXT.cfg_state = cfg_stopped;

    return true;
}
示例#5
0
/*****************************************************************************
 * FUNCTION: Demo_Wifi_Connect
 *
 * RETURNS:  TCPIP_MAC_RES
 *
 * PARAMS:   None
 *
 *  NOTES:   Connects to an 802.11 network.
 *****************************************************************************/
 TCPIP_MAC_RES Demo_Wifi_Connect(void)
{
    typedef enum {
        demo_Wifi_Connect_SM_1=0,
        demo_Wifi_Connect_SM_2,
        demo_Wifi_Connect_SM_3,
        demo_Wifi_Connect_SM_done
    }enum_demoWifiConnect_SM;
    static enum_demoWifiConnect_SM demoWifiConnect_SM = demo_Wifi_Connect_SM_1;
    TCPIP_MAC_RES RetCode = TCPIP_MAC_RES_PENDING;
	

    switch(demoWifiConnect_SM)
    {
        case demo_Wifi_Connect_SM_1:
        {
            uint8_t channelList[] = WF_DEFAULT_CHANNEL_LIST;
            DRV_WIFI_SCAN_CONTEXT scanContext;

#if (WF_DEFAULT_NETWORK_TYPE == DRV_WIFI_NETWORK_TYPE_SOFT_AP)
            uint8_t channelList_postscan[] = WF_DEFAULT_CHANNEL_LIST_POSTSCAN;
#endif

            DRV_WIFI_SsidSet(p_wifi_ConfigData->netSSID, p_wifi_ConfigData->SsidLength);

#if (WF_DEFAULT_NETWORK_TYPE == DRV_WIFI_NETWORK_TYPE_ADHOC) || (WF_DEFAULT_NETWORK_TYPE == DRV_WIFI_NETWORK_TYPE_SOFT_AP)
            DRV_WIFI_NetworkTypeSet(p_wifi_ConfigData->networkType);
#else
            DRV_WIFI_NetworkTypeSet(WF_DEFAULT_NETWORK_TYPE);
#endif

#ifndef WF_DEFAULT_SCAN_TYPE
            scanContext.scanType = DRV_WIFI_ACTIVE_SCAN;    
#else
            scanContext.scanType = WF_DEFAULT_SCAN_TYPE;
#endif

            scanContext.minChannelTime = DRV_WIFI_DEFAULT_SCAN_MIN_CHANNEL_TIME;
            scanContext.maxChannelTime = DRV_WIFI_DEFAULT_SCAN_MAX_CHANNEL_TIME;
            scanContext.probeDelay     = DRV_WIFI_DEFAULT_SCAN_PROBE_DELAY;
            scanContext.scanCount      = DRV_WIFI_DEFAULT_SCAN_COUNT;
            DRV_WIFI_ScanContextSet(&scanContext);

#if (WF_DEFAULT_NETWORK_TYPE == DRV_WIFI_NETWORK_TYPE_SOFT_AP)
            if (((CFGCXT.type != DRV_WIFI_NETWORK_TYPE_SOFT_AP) && (CFGCXT.prevWLAN == DRV_WIFI_NETWORK_TYPE_SOFT_AP)) ||
                (p_wifi_ConfigData->networkType != DRV_WIFI_NETWORK_TYPE_SOFT_AP))
            {
                DRV_WIFI_ChannelListSet(channelList_postscan, sizeof(channelList_postscan));
            }
            else
            {
                DRV_WIFI_ChannelListSet(channelList, sizeof(channelList));
            }
#else // not network type not DRV_WIFI_NETWORK_TYPE_SOFT_AP
            DRV_WIFI_ChannelListSet(channelList, sizeof(channelList));
#endif // (WF_DEFAULT_NETWORK_TYPE == DRV_WIFI_NETWORK_TYPE_SOFT_AP)

            // The Retry Count parameter tells the WiFi Connection manager how many attempts to make when trying
            // to connect to an existing network.  In the Infrastructure case, the default is to retry forever so that
            // if the AP is turned off or out of range, the radio will continue to attempt a connection until the
            // AP is eventually back on or in range.  In the Adhoc case, the default is to retry 3 times since the
            // purpose of attempting to establish a network in the Adhoc case is only to verify that one does not
            // initially exist.  If the retry count was set to DRV_WIFI_RETRY_FOREVER in the AdHoc mode, an AdHoc network
            // would never be established.
#if (WF_DEFAULT_NETWORK_TYPE == DRV_WIFI_NETWORK_TYPE_ADHOC) || (WF_DEFAULT_NETWORK_TYPE == DRV_WIFI_NETWORK_TYPE_SOFT_AP)
            if(p_wifi_ConfigData->networkType == DRV_WIFI_NETWORK_TYPE_INFRASTRUCTURE)
            {
                DRV_WIFI_ReconnectModeSet(DRV_WIFI_RETRY_FOREVER,   // retry forever to connect to WiFi network
                                    DRV_WIFI_ATTEMPT_TO_RECONNECT,  // reconnect on deauth from AP
                                    40,                             // beacon timeout is 40 beacon periods
                                    DRV_WIFI_ATTEMPT_TO_RECONNECT); // reconnect on beacon timeout
            }
            else if((p_wifi_ConfigData->networkType == DRV_WIFI_NETWORK_TYPE_ADHOC) || (p_wifi_ConfigData->networkType == DRV_WIFI_NETWORK_TYPE_SOFT_AP))
            {
                DRV_WIFI_ReconnectModeSet(WF_DEFAULT_LIST_RETRY_COUNT,    // retry N times to start or join AdHoc network
                                    DRV_WIFI_DO_NOT_ATTEMPT_TO_RECONNECT, // do not attempt to reconnect on deauth from station
                                    40,                                   // beacon timeout is 40 beacon periods
                                    DRV_WIFI_ATTEMPT_TO_RECONNECT);             // reconnect on beacon timeout
            }
            else
            {
                SYS_CONSOLE_MESSAGE("Please compile with correct XX_RETRY_COUNT\r\n");
                while(1);
            }
#else // network type not DRV_WIFI_NETWORK_TYPE_ADHOC or DRV_WIFI_NETWORK_TYPE_SOFT_AP
            DRV_WIFI_ReconnectModeSet(WF_DEFAULT_LIST_RETRY_COUNT, // retry N times to start or join AdHoc network
                                DRV_WIFI_ATTEMPT_TO_RECONNECT,     // reconnect on deauth from AP
                                40,                                // beacon timeout is 40 beacon periods
                                DRV_WIFI_ATTEMPT_TO_RECONNECT);    // reconnect on beacon timeout

#endif // (WF_DEFAULT_NETWORK_TYPE == DRV_WIFI_NETWORK_TYPE_ADHOC) || (WF_DEFAULT_NETWORK_TYPE == DRV_WIFI_NETWORK_TYPE_SOFT_AP)


            // Set Tx Mode
            DRV_WIFI_TxModeSet(WF_DEFAULT_TX_MODE); // WF_TXMODE_G_RATES, WF_TXMODE_B_RATES, WF_TXMODE_LEGACY_RATES

            // Error check items specific to WPS Push Button mode
#if (WF_DEFAULT_WIFI_SECURITY_MODE==DRV_WIFI_SECURITY_WPS_PUSH_BUTTON)
                //    SYS_ASSERT(strlen(p_wifi_ConfigData->netSSID) == 0, "");  // SSID must be empty when using WPS
                // To Do: fix this to work with different Domain and also empty channelList
                // SYS_ASSERT(sizeof(channelList)==11, "");      // must scan all channels for WPS
#endif
        
        }
        demoWifiConnect_SM++;
        break;

        case demo_Wifi_Connect_SM_2:
        {
            TCPIP_MAC_RES tmp = TCPIP_MAC_RES_OK;
            if (p_wifi_ConfigData->SecurityMode == DRV_WIFI_SECURITY_OPEN)
            {
                DRV_WIFI_SecurityOpenSet();
            }
            else if ((p_wifi_ConfigData->SecurityMode == DRV_WIFI_SECURITY_WEP_40) || (p_wifi_ConfigData->SecurityMode == DRV_WIFI_SECURITY_WEP_104))
            {
                SetWepSecurity();
            }
            else if ((p_wifi_ConfigData->SecurityMode == DRV_WIFI_SECURITY_WPA_AUTO_WITH_KEY)         ||
                     (p_wifi_ConfigData->SecurityMode == DRV_WIFI_SECURITY_WPA_WITH_KEY)              ||
                     (p_wifi_ConfigData->SecurityMode == DRV_WIFI_SECURITY_WPA_AUTO_WITH_PASS_PHRASE) ||
                     (p_wifi_ConfigData->SecurityMode == DRV_WIFI_SECURITY_WPA_WITH_PASS_PHRASE)      ||
                     (p_wifi_ConfigData->SecurityMode == DRV_WIFI_SECURITY_WPA2_WITH_KEY)             ||
                     (p_wifi_ConfigData->SecurityMode == DRV_WIFI_SECURITY_WPA2_WITH_PASS_PHRASE))
            {
                tmp = SetWpaSecurity();
            }
            else if ((p_wifi_ConfigData->SecurityMode == DRV_WIFI_SECURITY_WPS_PIN) ||
                    (p_wifi_ConfigData->SecurityMode == DRV_WIFI_SECURITY_WPS_PUSH_BUTTON))
            {
                SetWpsSecurity();
            }
            else if (p_wifi_ConfigData->SecurityMode == DRV_WIFI_SECURITY_EAP)
            {
                SetEapSecurity();
            }

            if(TCPIP_MAC_RES_OK == tmp ) demoWifiConnect_SM++;
        }
            
            break;
        
        case demo_Wifi_Connect_SM_3:
        {
#if WF_DEFAULT_PS_POLL == DRV_WIFI_ENABLED
            {
                DRV_WIFI_PS_POLL_CONTEXT psPollContext;
                psPollContext.dtimInterval   = DRV_WIFI_DEFAULT_PS_DTIM_INTERVAL;
                psPollContext.listenInterval = DRV_WIFI_DEFAULT_PS_LISTEN_INTERVAL;
                psPollContext.useDtim        = true;
                DRV_WIFI_PsPollEnable(&psPollContext);
            }
 #else    /* WF_DEFAULT_PS_POLL == DRV_WIFI_DISABLED */
            DRV_WIFI_PsPollDisable();
#endif    /* WF_DEFAULT_PS_POLL == DRV_WIFI_ENABLED */

#if defined(TCPIP_STACK_USE_GRATUITOUS_ARP)
            DRV_WIFI_GratuitousArpStart(5);  // output a gratuitous arp every 5 seconds (after connection)
#endif

 #if defined(SYS_CONSOLE_ENABLE)
             OutputDemoHeader();
#endif

        // override reconnect mode if connection manager disabled
#if defined(DISABLE_MODULE_FW_CONNECT_MANAGER_IN_INFRASTRUCTURE)
            DRV_WIFI_ReconnectModeSet(0,                               // report-only when connection lost (no reconnect)
                                DRV_WIFI_DO_NOT_ATTEMPT_TO_RECONNECT,  // report-only when deauth received (no reconnect)
                                40,                                    // set beacon timeout to 40 beacon periods
                                DRV_WIFI_DO_NOT_ATTEMPT_TO_RECONNECT); // report only when beacon timeout occurs
#endif

            WF_EnableDebugPrint(ENABLE_WPS_PRINTS);
            SYS_CONSOLE_MESSAGE("\r\nStart WiFi Connect . . .\r\n");

#if defined(TCPIP_STACK_USE_DHCP_CLIENT)
            if( DhcpHandle_Mrf24w == NULL)
            {    DhcpHandle_Mrf24w =  TCPIP_DHCP_HandlerRegister(TCPIP_STACK_NetHandleGet("MRF24W"), DhcpEventHandler, NULL);
            }
#endif  // defined(TCPIP_STACK_USE_DHCP_CLIENT)

            // start the WiFi connection process
            DRV_WIFI_Connect();

            WifiAsyncSetEventPending(ASYNC_DHCP_CONFIG_PENDING);  // ken test
        }
            demoWifiConnect_SM++;
            RetCode = TCPIP_MAC_RES_OK;
            //break;   //not break, will continue to demo_Wifi_Connect_SM_done
            
        case demo_Wifi_Connect_SM_done:
            demoWifiConnect_SM = demo_Wifi_Connect_SM_1;
            break;
    }
 
	return RetCode;
}