Esempio n. 1
0
static void EasyConfigSetSecurity(void)
{
    t_securityContext securityContext;

    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;
    } // end switch
}
Esempio n. 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;
}
Esempio n. 3
0
// must loop on connect until a connect
static bool Connect(SECURITY security, const uint8_t * szSsid, const void * pvPkt, int iKey, bool fPICKeyCalc, IPSTATUS * pStatus)
{
    t_wepContext wep;
    t_wpaContext wpa;
    t_wpsContext wps;

    if (!IsInitialized(pStatus))
    {
        return(false);
    }
    else if (szSsid == NULL || (security != DEWF_SECURITY_OPEN && pvPkt == NULL))
    {
        AssignStatusSafely(pStatus, ispInvalidArgument);
    }
    else if (IsInitNotLinked(pStatus))
    {
        // set the SSID
        WF_SsidSet((uint8_t *) szSsid, strlen(szSsid));

        switch(security)
        {
        case DEWF_SECURITY_OPEN:
            WF_SecurityOpenSet();
            break;

        case DEWF_SECURITY_WEP_40:
            wep.wepSecurityType     = security;                 // WF_SECURITY_WEP_40 or WF_SECURITY_WEP_104
            wep.wepKeyIndex         = iKey;                     // 0 thru 3
            wep.wepKeyLength        = sizeof(WEP40KEY);         // number of bytes pointed to by p_wepKey
            memcpy(wep.wepKey, pvPkt, sizeof(WEP40KEY));        // array containing WEP binary security key (4 5-byte keys for WEP-40, 4 13-byte keys for WEP-104)
            wep.wepKeyType          = WF_SECURITY_WEP_OPENKEY;  // WF_SECURITY_WEP_OPENKEY (default) or WF_SECURITY_WEP_SHAREDKEY
            WF_SecurityWepSet(&wep);
            break;

        case DEWF_SECURITY_WEP_104:
            wep.wepSecurityType     = security;                 // WF_SECURITY_WEP_40 or WF_SECURITY_WEP_104
            wep.wepKeyIndex         = iKey;                     // 0 thru 3
            wep.wepKeyLength        = sizeof(WEP104KEY);        // number of bytes pointed to by p_wepKey
            memcpy(wep.wepKey, pvPkt, sizeof(WEP104KEY));       // array containing WEP binary security key (4 5-byte keys for WEP-40, 4 13-byte keys for WEP-104)
            wep.wepKeyType          = WF_SECURITY_WEP_OPENKEY;  // WF_SECURITY_WEP_OPENKEY (default) or WF_SECURITY_WEP_SHAREDKEY
            WF_SecurityWepSet(&wep);
            break;

        case DEWF_SECURITY_WPA_WITH_PASS_PHRASE:
        case DEWF_SECURITY_WPA2_WITH_PASS_PHRASE:
        case DEWF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE:
            wpa.wpaSecurityType     = security;                 // WF_SECURITY_WPA_WITH_KEY, WF_SECURITY_WPA_WITH_PASS_PHRASE, WF_SECURITY_WPA2_WITH_KEY, WF_SECURITY_WPA2_WITH_PASS_PHRASE,WF_SECURITY_WPA_AUTO_WITH_KEY, WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE
            wpa.keyInfo.keyLength   = strlen(pvPkt);            // number of bytes in binary key (always 32) or passphrase
            memcpy(wpa.keyInfo.key, pvPkt, wpa.keyInfo.keyLength);  // binary key or passphrase
            wpa.keyInfo.ssidLen     = strlen(szSsid);           // number of bytes in SSID
            memcpy(wpa.keyInfo.ssid, szSsid, wpa.keyInfo.ssidLen);  // ssid

            if (fPICKeyCalc)
            {
                // this is very ugly as it holds the PIC
                // for 4 seconds
                WF_WpaConvPassphraseToKey(&wpa.keyInfo);    // not sure how to check for errors
                wpa.wpaSecurityType--;                      // go to the KEY form of the type
            }

            WF_SecurityWpaSet(&wpa);
            break;

        case DEWF_SECURITY_WPA_WITH_KEY:
        case DEWF_SECURITY_WPA2_WITH_KEY:
        case DEWF_SECURITY_WPA_AUTO_WITH_KEY:
            wpa.wpaSecurityType     = security;                             // WF_SECURITY_WPA_WITH_KEY, WF_SECURITY_WPA_WITH_PASS_PHRASE, WF_SECURITY_WPA2_WITH_KEY, WF_SECURITY_WPA2_WITH_PASS_PHRASE,WF_SECURITY_WPA_AUTO_WITH_KEY, WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE
            wpa.keyInfo.keyLength   = sizeof(WPA2KEY);                      // number of bytes in binary key (always 32) or passphrase
            memcpy(wpa.keyInfo.key, pvPkt, sizeof(WPA2KEY));               // binary key or passphrase
            wpa.keyInfo.ssidLen     = strlen(szSsid);                       // number of bytes in SSID
            memcpy(wpa.keyInfo.ssid, szSsid, wpa.keyInfo.ssidLen);          // ssid
            WF_SecurityWpaSet(&wpa);
            break;

        case DEWF_SECURITY_WPS_PUSH_BUTTON:
            wps.wpsPinLength = WF_WPS_PIN_LENGTH;               // should always be 8
            memcpy(wps.wpsPin, pvPkt, WF_WPS_PIN_LENGTH);     // if using WF_SECURITY_WPS_PIN then pointer to 8-digit pin
        // fall thru

        case DEWF_SECURITY_WPS_PIN:
            wps.wpsSecurityType = security;                    // WF_SECURITY_WPS_PUSH_BUTTON or WF_SECURITY_WPS_PIN
            wps.getPassPhrase = fPICKeyCalc;                    // calculate key in PIC32(true) or on MRF (false)
            memset(&wpaKeyInfoG, 0, sizeof(t_wpaKeyInfo));
            wps.p_keyInfo = &wpaKeyInfoG;                       // pointer to where the Universal driver will store passphrase info (must be global memory)
            WF_SecurityWpsSet(&wps);
            break;

        default:
            AssignStatusSafely(((IPSTATUS *) pStatus), ispInvalidArgument);
            return(false);
            break;
        }
        wfmrf24.priv.fMRFBusy = true;
        WF_Connect();
    }

    return(IsLinked(pStatus));
}