//==============================================================================
uint32_t UdSetChannelList(uint8_t *p_channelList, uint8_t numChannels)
{
    uint32_t errorCode = UD_SUCCESS;

    // can't change channel list unless not connected
    if (UdGetConnectionState() != CS_NOT_CONNECTED)
    {
        return UD_ERROR_ONLY_VALID_WHEN_NOT_CONNECTED;
    }

    errorCode = ValidateChannelList(p_channelList, numChannels);
    if (errorCode != UD_SUCCESS)
    {
        UdSetChannelListInvalid();
        return errorCode;
    }
    else
    {
        UdSetChannelListValid();
    }

    memset(g_udState.channelList, 0x00, sizeof(g_udState.channelList));
    memcpy(g_udState.channelList, p_channelList, numChannels);
    g_udState.numChannels = numChannels;

    return errorCode;
}
Exemple #2
0
/*******************************************************************************
  Function:
    void WF_PsPollEnable(t_psPollContext *p_context)

  Summary:
    Enables PS Poll mode.

  Description:
    Enables PS Poll mode.  PS-Poll (Power-Save Poll) is a mode allowing for
    longer battery life.  The MRF24W coordinates with the Access Point to go
    to sleep and wake up at periodic intervals to check for data messages, which
    the Access Point will buffer.  The listenInterval in the Connection
    Algorithm defines the sleep interval.  By default, PS-Poll mode is disabled.

    When PS Poll is enabled, the WF Host Driver will automatically force the
    MRF24W to wake up each time the Host sends Tx data or a control message
    to the MRF24W.  When the Host message transaction is complete the
    MRF24W driver will automatically re-enable PS Poll mode.

    When the application is likely to experience a high volume of data traffic
    then PS-Poll mode should be disabled for two reasons:
    1. No power savings will be realized in the presence of heavy data traffic.
    2. Performance will be impacted adversely as the WiFi Host Driver
        continually activates and deactivates PS-Poll mode via SPI messages.

  Precondition:
    MACInit must be called first.

  Parameters:
    p_context -  pointer to ps poll context

  Returns:
    None.

  Remarks:
    None.
  *****************************************************************************/
void WF_PsPollEnable(t_psPollContext *p_context)
{
    t_WFPwrModeReq   pwrModeReq;

    // if not currently connected then return
    if(UdGetConnectionState() != CS_CONNECTED)
    {
        EventEnqueue(WF_EVENT_ERROR, UD_INVALID_PS_POLL_ERROR);
        return;
    }

    // save the Ps-Poll context
    UdEnablePsPoll(p_context);

    SetListenInterval(p_context->listenInterval);
    SetDtimInterval(p_context->dtimInterval);

    // fill in request structure and send message to MRF24WG
    pwrModeReq.mode     = PS_POLL_ENABLED;
    pwrModeReq.wake     = 0;
    pwrModeReq.rcvDtims = p_context->useDtim;
    SendPowerModeMsg(&pwrModeReq);

    WFConfigureLowPowerMode(WF_LOW_POWER_MODE_ON);

    if (p_context->useDtim)
    {
        PowerStateSet(WF_PS_PS_POLL_DTIM_ENABLED);
    }
    else
    {
        PowerStateSet(WF_PS_PS_POLL_DTIM_DISABLED);
    }
}
//==============================================================================
uint32_t UdSetSsid(uint8_t *p_ssid, uint8_t ssidLength)
{
    uint32_t errorCode;

    // can't change SSID unless not connected
    if (UdGetConnectionState() != CS_NOT_CONNECTED)
    {
        return UD_ERROR_ONLY_VALID_WHEN_NOT_CONNECTED;
    }

    errorCode = ValidateSsid(p_ssid, ssidLength);
    if (errorCode != UD_SUCCESS)
    {
        UdSetSsidInvalid();
        return errorCode;
    }
    else
    {
        UdSetSsidValid();
        memset(g_udState.ssid, 0x00, sizeof(g_udState.ssid));
        memcpy(g_udState.ssid, p_ssid, ssidLength);
        g_udState.ssidLength = ssidLength;
    }

    return UD_SUCCESS;
}
//==============================================================================
uint32_t UdSetDomain(uint8_t domain)
{
    uint32_t errorCode = UD_SUCCESS;

    // can't change domain unless not connected
    if (UdGetConnectionState() != CS_NOT_CONNECTED)
    {
        errorCode = UD_ERROR_ONLY_VALID_WHEN_NOT_CONNECTED;
        goto errorExit;
    }

    if ((domain != WF_DOMAIN_FCC) && (domain != WF_DOMAIN_ETSI) && (domain != WF_DOMAIN_JAPAN))
    {
        UdSetDomainInvalid();
        errorCode = UD_ERROR_INVALID_WPS_PIN;
        goto errorExit;
    }
    else
    {
        UdSetDomainValid();
        g_udState.domain = domain;
    }

errorExit:
    return errorCode;
}
//==============================================================================
uint32_t UdSetAdhocNetworkContext(t_adHocNetworkContext *p_context)
{
    uint32_t errorCode = UD_SUCCESS;

    // can't change scan context unless not connected
    if (UdGetConnectionState() != CS_NOT_CONNECTED)
    {
        return UD_ERROR_ONLY_VALID_WHEN_NOT_CONNECTED;
    }

    if ((p_context->hiddenSsid != true) && (p_context->hiddenSsid != false))
    {
       errorCode = UD_ERROR_INVALID_HIDDEN_SSID;
       goto errorExit;
    }

    if (p_context->mode > WF_ADHOC_START_ONLY)
    {
        errorCode = UD_ERROR_INVALID_ADHOC_MODE;
        goto errorExit;
    }

errorExit:
    return errorCode;
}
//==============================================================================
uint32_t UdSetScanContext(t_scanContext *p_context)
{
    uint32_t errorCode = UD_SUCCESS;

    // can't change scan context unless not connected
    if (UdGetConnectionState() != CS_NOT_CONNECTED)
    {
        return UD_ERROR_ONLY_VALID_WHEN_NOT_CONNECTED;
    }

    if ((p_context->scanType != WF_ACTIVE_SCAN) && (p_context->scanType != WF_PASSIVE_SCAN))
    {
        errorCode = UD_ERROR_INVALID_SCAN_TYPE;
        goto errorExit;
    }

errorExit:
    if (errorCode == UD_SUCCESS)
    {
        UdSetScanContextValid();
    }
    else
    {
        UdSetScanContextInvalid();
    }

    return errorCode;
}
Exemple #7
0
static void PsPollCheck(void)
{
    // if PS-Poll was disabled temporarily and needs to be reenabled, and, we are in
    // a connected state
    if ((isPsPollNeedReactivate()) && (UdGetConnectionState() == CS_CONNECTED))
    {
        ClearPsPollReactivate();
        WFConfigureLowPowerMode(WF_LOW_POWER_MODE_ON);

    }
}
//==============================================================================
uint32_t UdSetRssi(uint8_t rssi)
{
    rssi = rssi; // avoid warning

    // can't change RSSI unless not connected
    if (UdGetConnectionState() != CS_NOT_CONNECTED)
    {
        return UD_ERROR_ONLY_VALID_WHEN_NOT_CONNECTED;
    }
    else
    {
        return UD_SUCCESS;
    }
}
//==============================================================================
uint32_t UdSetBssid(uint8_t *p_bssid)
{
    p_bssid = p_bssid; // avoid warning

    // can't change BSSID unless not connected
    if (UdGetConnectionState() != CS_NOT_CONNECTED)
    {
        return UD_ERROR_ONLY_VALID_WHEN_NOT_CONNECTED;
    }
    else
    {
        return UD_SUCCESS;
    }
}
//==============================================================================
uint32_t UdSetSecurityOpen(void)
{
    // can't change security unless not connected
    if (UdGetConnectionState() == CS_NOT_CONNECTED)
    {
        UdSetSecurityValid();
        return UD_SUCCESS;
    }
    else
    {
        UdSetSecurityInvalid();
        return UD_ERROR_ONLY_VALID_WHEN_NOT_CONNECTED;
    }
}
Exemple #11
0
/*******************************************************************************
  Function:
    void WF_MacAddressSet(UINT8 *p_mac)

  Summary:
    Uses a different MAC address for the MRF24W

  Description:
    Directs the MRF24W to use the input MAC address instead of its
    factory-default MAC address.  This function does not overwrite the factory
    default, which is in FLASH memory ? it simply tells the MRF24W to use a
    different MAC.

  Precondition:
    MACInit must be called first.  Cannot be called when the MRF24W is in a
    connected state.

  Parameters:
    p_mac  - Pointer to 6-byte MAC that will be sent to MRF24W

  Returns:
    None.

  Remarks:
    None.
 *****************************************************************************/
void WF_MacAddressSet(uint8_t *p_mac)
{
#if defined(WF_ERROR_CHECKING)
    // can't change MAC address unless not connected
    if (UdGetConnectionState() != CS_NOT_CONNECTED)
    {
        EventEnqueue(WF_EVENT_ERROR, UD_ERROR_ONLY_VALID_WHEN_NOT_CONNECTED);
        return;
    }
#endif
    SendSetParamMsg(PARAM_MAC_ADDRESS, p_mac, WF_MAC_ADDRESS_LENGTH);
#if defined(TCP_CLIENT_DEMO)
    UpdateWifiIffMac(p_mac);
#endif
}
//==============================================================================
uint32_t UdSetRtsThreshold(uint16_t rtsThreshold)
{
    // can't change RSSI unless not connected
    if (UdGetConnectionState() != CS_NOT_CONNECTED)
    {
        return UD_ERROR_ONLY_VALID_WHEN_NOT_CONNECTED;
    }

    if (rtsThreshold > MAX_RTS_THRESHOLD)
    {
        return UD_ERROR_INVALID_RTS_THRESHOLD;
    }

    return UD_SUCCESS;
}
//==============================================================================
uint32_t UdSetTxMode(uint8_t mode)
{
    // can't change SSID unless not connected
    if (UdGetConnectionState() != CS_NOT_CONNECTED)
    {
        return UD_ERROR_ONLY_VALID_WHEN_NOT_CONNECTED;
    }

    if (mode > WF_TXMODE_LEGACY_RATES)
    {
        return UD_ERROR_INVALID_TX_MODE;
    }
    else
    {
        return UD_SUCCESS;
    }
}
//==============================================================================
uint32_t UdSetNetworkType(uint8_t networkType)
{
    // can't change channel list unless not connected
    if (UdGetConnectionState() != CS_NOT_CONNECTED)
    {
        return UD_ERROR_ONLY_VALID_WHEN_NOT_CONNECTED;
    }

    if ((networkType < WF_MIN_NETWORK_TYPE) || (networkType > WF_MAX_NETWORK_TYPE))
    {
        UdSetNetworkTypeValid();
        return UD_INVALID_NETWORK_TYPE;
    }

    UdSetNetworkTypeValid();
    g_udState.networkType = networkType;
    return UD_SUCCESS;
}
//==============================================================================
uint32_t UdSetSecurityWps(t_wpsContext *p_context)
{
    uint32_t errorCode = UD_SUCCESS;
    uint8_t  securityType;

    securityType = p_context->wpsSecurityType;

    // can't change security unless not connected
    if (UdGetConnectionState() != CS_NOT_CONNECTED)
    {
        errorCode = UD_ERROR_ONLY_VALID_WHEN_NOT_CONNECTED;
        goto errorExit;
    }
#if defined(WF_USE_HOST_WPA_KEY_CALCULATION)
    if ((p_context->getPassPhrase != true) && (p_context->getPassPhrase != false))
    {
        errorCode = UD_ERROR_INVALID_GET_PASS_PHRASE;
        goto errorExit;
    }

    if (p_context->getPassPhrase == true)
    {
        if (p_context->p_keyInfo == NULL)
        {
            errorCode = UD_ERROR_NULL_PASS_PHRASE_INFO;
            goto errorExit;
        }
    }
#endif

    if (securityType == WF_SECURITY_WPS_PUSH_BUTTON)
    {
        // nothing to check here
    }
    //----------------------
    // else if using WPS PIN
    //----------------------
    else if (securityType == WF_SECURITY_WPS_PIN)
    {
        if (p_context->wpsPinLength != 8)
        {
            errorCode = UD_ERROR_WPS_PIN_LENGTH_INVALID;
            goto errorExit;
        }

        errorCode = ValidateWpsPin(p_context->wpsPin);
        if (errorCode != UD_SUCCESS)
        {
            goto errorExit;
        }
    }

errorExit:
    if (errorCode == UD_SUCCESS)
    {
        UdSetSecurityValid();
        g_udState.securityType = p_context->wpsSecurityType;
    }
    else
    {
        UdSetSecurityInvalid();
    }

    return errorCode;
}
//==============================================================================
uint32_t UdSetSecurityWpa(t_wpaContext *p_context)
{
    uint32_t errorCode = UD_SUCCESS;
    uint8_t securityType;
    uint8_t securityKeyLength;
    int i;

    securityKeyLength = p_context->keyInfo.keyLength;

    // can't change security unless not connected
    if (UdGetConnectionState() != CS_NOT_CONNECTED)
    {
        errorCode = UD_ERROR_ONLY_VALID_WHEN_NOT_CONNECTED;
        goto errorExit;
    }

    // security type must be one of the WPA security types
    securityType = p_context->wpaSecurityType;
    if ((securityType < WF_SECURITY_WPA_WITH_KEY) || (securityType > WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE))
    {
        errorCode = UD_ERROR_INVALID_SECURITY_TYPE;
        goto errorExit;
    }

    //-----------------------------
    // if using WPA with binary key
    //----------------------------------
    if ((securityType == WF_SECURITY_WPA_WITH_KEY)       ||
        (securityType == WF_SECURITY_WPA2_WITH_KEY)      ||
        (securityType == WF_SECURITY_WPA_AUTO_WITH_KEY))
    {
        // binary key must be 64 hex digits (32 bytes)
        if (securityKeyLength != 32)
        {
            errorCode = UD_ERROR_INVALID_WPA_KEY_LENGTH;
            goto errorExit;
        }
    }
    //----------------------------------
    // else if using WPA with passphrase
    //----------------------------------
    if ((securityType == WF_SECURITY_WPA_WITH_PASS_PHRASE)       ||
        (securityType == WF_SECURITY_WPA2_WITH_PASS_PHRASE)      ||
        (securityType == WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE))
    {
        // ASCII key phrase must be between 8 and 63 bytes
        if ((securityKeyLength < 8) || (securityKeyLength > 63))
        {
            errorCode = UD_ERROR_INVALID_WPA_PASSPHRASE_LENGTH;
            goto errorExit;
        }

        // ASCII passphase characters must be printable (0x20 thru 0x7E)
        for (i = 0; i < securityKeyLength; ++i)
        {
            uint8_t tmp;
            tmp = p_context->keyInfo.key[i];
            if ((tmp < 0x20) || (tmp > 0x7e))
            {
                errorCode = UD_ERROR_INVALID_WPA_PASSPHRASE_CHARACTERS;
                goto errorExit;
            }
        }
    }

errorExit:
    if (errorCode == UD_SUCCESS)
    {
        UdSetSecurityValid();
        g_udState.securityType = p_context->wpaSecurityType;
    }
    else
    {
        UdSetSecurityInvalid();
    }

    return errorCode;
}
//==============================================================================
uint32_t UdSetSecurityWep(t_wepContext *p_context)
{
    uint32_t errorCode = UD_SUCCESS;

    // can't change security unless not connected
    if (UdGetConnectionState() != CS_NOT_CONNECTED)
    {
        errorCode = UD_ERROR_ONLY_VALID_WHEN_NOT_CONNECTED;
        goto errorExit;
    }

    if ((p_context->wepSecurityType != WF_SECURITY_WEP_40) && (p_context->wepSecurityType != WF_SECURITY_WEP_104))
    {
        errorCode = UD_ERROR_INVALID_WEP_SECURITY_TYPE;
        goto errorExit;
    }

    // if WEP-40
    if (p_context->wepSecurityType == WF_SECURITY_WEP_40)
    {
        // key must be 4 5-byte keys, or 20 bytes
        if (p_context->wepKeyLength != 20)
        {
            errorCode = UD_ERROR_WEP_40_KEY_INVALID_LENGTH;
            goto errorExit;
        }
    }
    // else WEP-104
    else
    {
        // key must be 4 13-byte keys, or 52 bytes
        if (p_context->wepKeyLength != 52)
        {
            errorCode = UD_ERROR_WEP_104_KEY_INVALID_LENGTH;
            goto errorExit;
        }
    }

    // WEP key index must be 0-3
    if (p_context->wepKeyIndex > 3)
    {
        errorCode = UD_ERROR_INVALID_WEP_KEY_INDEX;
        goto errorExit;
    }

    if ((p_context->wepKeyType != WF_SECURITY_WEP_SHAREDKEY) && (p_context->wepKeyType != WF_SECURITY_WEP_OPENKEY))
    {
        errorCode = UD_ERROR_INVALID_WEP_KEY_TYPE;
        goto errorExit;
    }

errorExit:
    if (errorCode == UD_SUCCESS)
    {
        UdSetSecurityValid();
        g_udState.securityType = p_context->wepSecurityType;
    }
    else
    {
        UdSetSecurityInvalid();
    }

    return errorCode;
}