コード例 #1
0
//============================================================================
void WF_WpsKeyGenerate(void)
{
    // create the binary key
    WF_WpaConvPassphraseToKey(g_p_wpaKeyInfo);

    // send it to MRF24WG
    SetPSK(g_p_wpaKeyInfo->key);
}
コード例 #2
0
ファイル: DEMRF24G.cpp プロジェクト: Digilent/vivado-library
// this should be safe to call at any time
bool DEMRF24::wpaCalPSK(const char * szSsid, const char * szPassphrase, WPA2KEY& wpaKey)
{
    t_wpaKeyInfo wpaInfo;

    if( szSsid != NULL &&
        szPassphrase != NULL &&
        (wpaInfo.ssidLen = strlen(szSsid)) <= WF_MAX_SSID_LENGTH &&
        (wpaInfo.keyLength = strlen(szPassphrase)) <= WF_MAX_PASSPHRASE_LENGTH )
    {

        memcpy(wpaInfo.ssid, szSsid, wpaInfo.ssidLen);
        memcpy(wpaInfo.key, szPassphrase, wpaInfo.keyLength);

        WF_WpaConvPassphraseToKey(&wpaInfo);

        memcpy(wpaKey.rgbKey, wpaInfo.key, sizeof(WPA2KEY));

        return(true);
    }

    return(false);
}
コード例 #3
0
ファイル: MRF24GAdaptor.c プロジェクト: zhandb/vak-opensource
// 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));
}