Пример #1
0
static bool IsInitialized(IPSTATUS * pStatus)
{
    // we ONLY DO THIS ONCE
    static bool fInitSetup = false;

    AssignStatusSafely(pStatus, wfmrf24.priv.initStatus);

    // Run the task because we might not be in the Adaptor yet
    WF_Task();

    if (!fInitSetup && wfmrf24.priv.initStatus == (InitMask | WF_INIT_SUCCESSFUL))
    {
        uint8_t channels[] = {};
        t_scanContext scanContext = {WF_ACTIVE_SCAN, 1, 200, 400, 20};

        WF_RegionalDomainSet(WF_DOMAIN_FCC);
        WF_NetworkTypeSet(WF_NETWORK_TYPE_INFRASTRUCTURE);
        WF_ChannelListSet(channels, sizeof(channels));
        WF_ReconnectModeSet(3, WF_ATTEMPT_TO_RECONNECT, 40, WF_ATTEMPT_TO_RECONNECT);
        WF_ScanContextSet(&scanContext);

        // fixup the MAC
        if (memcmp(&wfmrf24.adpMRF24G.mac, &MACNONE, sizeof(MACADDR)) == 0)
        {
            WF_MacAddressGet((uint8_t *) &wfmrf24.adpMRF24G.mac);
        }
        else
        {
            WF_MacAddressSet((uint8_t *) &wfmrf24.adpMRF24G.mac);
        }

        // set up the hardware filters
        //WF_SetHwMultiCastFilter(WF_MULTICAST_FILTER_1, (uint8_t *) &wfmrf24.adpMRF24G.mac);
        WF_SetHwMultiCastFilter(WF_MULTICAST_FILTER_2, (uint8_t *) &MACNONE);

        // we are done
        fInitSetup = true;
    }
    return(wfmrf24.priv.initStatus == (InitMask | WF_INIT_SUCCESSFUL));
}
Пример #2
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;
}
Пример #3
0
static void EasyConfigConnect(void)
{
    WF_Disconnect();    // break the connection supporting the web page

    if (g_easyConfigCtx.ssid)    // if AP has an SSID (not a hidden SSID)
    {
        WF_SsidSet(g_easyConfigCtx.ssid, strlen((char*)g_easyConfigCtx.ssid));
    }

    // Set security supported by designated AP
    EasyConfigSetSecurity();

    #if defined (EZ_CONFIG_STORE) 
        #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
    #else
        //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
        }
    #endif

#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();
#endif

}