コード例 #1
0
ファイル: wf_raw.c プロジェクト: logansam/WS2812WearableDemo
/*****************************************************************************
  Function:
    bool AllocateDataTxBuffer(uint16_t bytesNeeded)

  Summary:
    Allocates a Data Tx buffer for use by the TCP/IP stack.

  Description:
    Determines if WiFi chip has enough memory to allocate a tx data buffer, and,
    if so, allocates it.

  Precondition:
    None

  Parameters:
    bytesNeeded -- number of bytes needed for the data tx message

  Returns:
    True if data tx buffer successfully allocated, else False

  Remarks:
    None
*****************************************************************************/
bool AllocateDataTxBuffer(uint16_t bytesNeeded)
{
    uint16_t bufAvail;
    uint16_t byteCount;

    /* get total bytes available for DATA tx memory pool */
    bufAvail = Read16BitWFRegister(WF_HOST_WFIFO_BCNT0_REG) & 0x0fff; /* LS 12 bits contain length */

    /* if enough bytes available to allocate */
    if ( bufAvail >= bytesNeeded )
    {
        /* allocate and create the new Tx buffer (mgmt or data) */
        byteCount = RawMove(RAW_DATA_TX_ID, RAW_DATA_POOL, true, bytesNeeded);
        if (byteCount == 0)
        {
            EventEnqueue(WF_EVENT_ERROR, UD_TX_ALLOCATION_FAILED);
            return false;
        }

        /* flag this raw window as mounted (in use) */
        SetRawDataWindowState(RAW_DATA_TX_ID, WF_RAW_DATA_MOUNTED);
        return true;
    }
    /* else not enough bytes available at this time to satisfy request */
    else
    {
        return false;
    }
}
コード例 #2
0
ファイル: wf_power.c プロジェクト: ricklon/deIPcK
/*******************************************************************************
  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);
    }
}
コード例 #3
0
/*******************************************************************************
  Function:
    void WF_Connect()

  Summary:
    Commands the MRF24WB0MA/B or MRF24WG0MA/B to start a connection.

  Description:
    Directs the Connection Manager to scan for and connect to a WiFi network.
    This function does not wait until the connection attempt is successful, but
    returns immediately.  See WF_ProcessEvent for events that can occur as a
    result of a connection attempt being successful or not.

    Note that if the Connection Profile being used has WPA or WPA2 security
    enabled and is using a passphrase, the connection manager will first
    calculate the PSK key, and then start the connection process.  The key
    calculation can take up to 30 seconds.

  Precondition:
    MACInit must be called first.

  Parameters:
    CpId - If this value is equal to an existing Connection Profile�s ID than
            only that Connection Profile will be used to attempt a connection to
            a WiFi network.
            If this value is set to WF_CM_CONNECT_USING_LIST then the
            connectionProfileList will be used to connect, starting with the
            first Connection Profile in the list.

  Returns:
    None.

  Remarks:
    None.
  *****************************************************************************/
void WF_Connect(void)
{
    uint8_t  hdrBuf[4];

#if defined(WF_ERROR_CHECKING)
    {
        uint32_t errorCode;

        errorCode = UdCheckConnectionConfig();
        if (errorCode != UD_SUCCESS)
        {
            EventEnqueue(WF_EVENT_ERROR, errorCode);
            return;
        }
    }
#endif /* WF_ERROR_CHECKING */

    /* Write out header portion of msg (which is whole msg, there is no data) */
    hdrBuf[0] = WF_MGMT_REQUEST_TYPE;    /* indicate this is a mgmt msg     */
    hdrBuf[1] = WF_CM_CONNECT_SUBYTPE;   /* mgmt request subtype            */
    hdrBuf[2] = GetCpid();
    hdrBuf[3] = 0;

    SendMgmtMsg(hdrBuf,
                sizeof(hdrBuf),
                NULL,
                0);

    /* wait for mgmt response, free after it comes in, don't need data bytes */
    WaitForMgmtResponse(WF_CM_CONNECT_SUBYTPE, FREE_MGMT_BUFFER);
}
コード例 #4
0
/*******************************************************************************
  Function:
    UINT16 WF_Disconnect(void)

  Summary:
    Commands the MRF24WG to close any open connections and/or to cease attempting
    to connect.

  Description:
    Directs the Connection Manager to close any open connection or connection
    attempt in progress.  No further attempts to connect are taken until
    WF_Connect() is called.

  Precondition:
    

  Parameters:
    None.

  Returns:
    None

  Remarks:
    None.
  *****************************************************************************/
void WF_Disconnect(void)
{
    uint8_t  hdrBuf[2];
    uint8_t   connectionState; // not used, but required for function call

    /* WARNING !!! :
    * Disconnect is allowed only in connected state.
    * If module FW is in the midst of connection (or reconnection) process, then
    * disconnect can hammer connection process, and furthermore it may cause
    * fatal failure in module FW operation. 
    */

    // verify it is OK to issue a disconnect command
    WF_ConnectionStateGet(&connectionState);
    if ((connectionState != WF_CSTATE_CONNECTED_INFRASTRUCTURE) && (connectionState != WF_CSTATE_CONNECTED_ADHOC))
    {
        EventEnqueue(WF_EVENT_ERROR, UD_ERROR_DISCONNECT_NOT_ALLOWED);
        return;
    }

    hdrBuf[0] = WF_MGMT_REQUEST_TYPE;
    hdrBuf[1] = WF_CM_DISCONNECT_SUBYTPE;

    SendMgmtMsg(hdrBuf,
                sizeof(hdrBuf),
                NULL,
                0);

    /* wait for mgmt response, free after it comes in, don't need data bytes */
    WaitForMgmtResponse(WF_CM_DISCONNECT_SUBYTPE, FREE_MGMT_BUFFER);

    UdSetConnectionState(CS_NOT_CONNECTED);
}
コード例 #5
0
//============================================================================
void WF_SecurityWpsSet(t_wpsContext *p_context)
{
#if defined(WF_ERROR_CHECKING)
    uint32_t errorCode = UdSetSecurityWps(p_context);
    if (errorCode != UD_SUCCESS)
    {
        EventEnqueue(WF_EVENT_ERROR, errorCode);
        return;
    }
#endif /* WF_ERROR_CHECKING */

    WF_SetSecurity(p_context->wpsSecurityType,
                   0,
                   p_context->wpsPin,
                   p_context->wpsPinLength);

#if defined(WF_USE_HOST_WPA_KEY_CALCULATION)
    // if host wants the host to calculate a binary key from a possible WPS-PSK passphrase
    if (p_context->getPassPhrase == true)
    {
        // tell MRF24WG to send wpa-psk passphrase back to host (if AP using WPA passphrase)
        YieldPassPhraseToHost();
        
        // save pointer to passphrase info block
        g_p_wpaKeyInfo = p_context->p_keyInfo;
    }
#endif /* WF_USE_HOST_WPA_KEY_CALCULATION */
}
コード例 #6
0
/*******************************************************************************
  Function:
    void WF_ReconnectModeSet(uint8_t retryCount, uint8_t deauthAction, uint8_t beaconTimeout, uint8_t beaconTimeoutAction);

  Summary:
    Controls how the MRF24WG handles reconnection in the event of a beacon timeout
    or a deauthentication from the AP.

  Description:
     The host application has two basic options with respect to controlling how the
     MRF24WG handles a loss of WiFi connection.
        1) MRF24WG informs the host and automatically retries N times (or forever)
           to regain the connection
        2) MRF24WG simply informas the host application that the connection has
           been lost; it does not automatically try to regain the connection.
           Instead, it is up to the host to reestablish the connection.

  Parameters:
    retryCount    -- the number of times the MRF24WG should try to regain a connection:
                      0     -- Do not try to regain the connection (simply report event to host application)
                      1:254 -- number of times to try to regain the connection
                      255   -- Retry forever (WF_RETRY_FOREVER)

    deauthAction  -- WF_ATTEMPT_TO_RECONNECT or WF_DO_NOT_ATTEMPT_TO_RECONNECT

    beaconTimeOut -- Number of missed beacons before MRF24WG designates the
                     connection as lost:
                      0 -- MRF24WG will NOT monitor the beacon timeout condition
                            and will not indicate this condition to Host
                      1:255 -- number of missed beacons before connection declared lost

    beaconTimeoutAction -- WF_ATTEMPT_TO_RECONNECT or WF_DO_NOT_ATTEMPT_TO_RECONNECT
 
  Returns:
    None

  Remarks:
    If this function is not called, the MRF2WG default is the equivalent of:
        WF_SetReconnectMode(3, WF_ATTEMPT_TO_RECONNECT, 0, WF_DO_NOT_ATTEMPT_TO_RECONNECT);
        
    Examples of different scenarios are below.

    Example 1: MRF24WG should not do any connection retries and only report deauth events to host:
                 WF_SetReconnectMode(0, WF_DO_NOT_ATTEMPT_TO_RECONNECT, 0, WF_DO_NOT_ATTEMPT_TO_RECONNECT);

    Example 2: MRF24WG should not do any connection retries, but report deauth and beacon timeout events to host.
               Beacon timeout should be 5 beacon periods:
                 WF_SetReconnectMode(0, WF_DO_NOT_ATTEMPT_TO_RECONNECT, 5, WF_DO_NOT_ATTEMPT_TO_RECONNECT);

    Example 3: MRF24WG should ignore beacon timeouts, but attempt to reconnect 3 times if a deauth occurs:
                WF_SetReconnectMode(3, WF_ATTEMPT_TO_RECONNECT, 0, WF_DO_NOT_ATTEMPT_TO_RECONNECT);

    Example 4: MRF24WG should not do any connection retries if a deauth occcurs, but retry 3 times if a beacon
               timeout of 4 beacon periods occur:
                WF_SetReconnectMode(3, WF_DO_NOT_ATTEMPT_TO_RECONNECT, 4, WF_ATTEMPT_TO_RECONNECT);

    Example 5: MRF24WG should retry forever if either a deauth or beacon timeout occurs (beacon timeout is
               3 beacon periods):
                WF_SetReconnectMode(WF_RETRY_FOREVER, WF_ATTEMPT_TO_RECONNECT, 3, WF_ATTEMPT_TO_RECONNECT);

  *****************************************************************************/
void WF_ReconnectModeSet(uint8_t retryCount, uint8_t deauthAction, uint8_t beaconTimeout, uint8_t beaconTimeoutAction)
{
#if defined(WF_ERROR_CHECKING)
    {
        uint32_t errorCode;

        errorCode = UdSetReconnectMode(retryCount, deauthAction, beaconTimeout, beaconTimeoutAction);
        if (errorCode != UD_SUCCESS)
        {
            EventEnqueue(WF_EVENT_ERROR, errorCode);
            return;
        }
    }
#endif /* WF_ERROR_CHECKING */

    LowLevel_CASetElement(WF_CA_ELEMENT_LIST_RETRY_COUNT,       // Element ID
                          &retryCount,                          // pointer to element data
                          sizeof(retryCount));                  // number of element data bytes

    LowLevel_CASetElement(WF_CA_ELEMENT_DEAUTH_ACTION,          // Element ID
                          &deauthAction,                        // pointer to element data
                          sizeof(deauthAction));                // number of element data bytes

    LowLevel_CASetElement(WF_CA_ELEMENT_BEACON_TIMEOUT,         // Element ID
                          &beaconTimeout,                       // pointer to element data
                          sizeof(beaconTimeout));               // number of element data bytes

    LowLevel_CASetElement(WF_CA_ELEMENT_BEACON_TIMEOUT_ACTION,  // Element ID
                          &beaconTimeoutAction,                 // pointer to element data
                          sizeof(beaconTimeoutAction));         // number of element data bytes

}
コード例 #7
0
/*******************************************************************************
  Function:
    void WF_WpaConvPassphraseToKey(t_wpaKeyInfo *p_wpaPhrase)

  Summary:
    Converts the input WPA/WPA2 passphrase to a 32-byte binary key

  Description:
    None

  Parameters:
    p_keyInfo -- structure containing the ASCII WPA passphrase

  Returns:
    When this function completes the input structure field p_keyInfo->key[] will
    have been overwritten with the 32-byte binary key.  In addtion, the input
    structure field p_keyInfo->keyLength will be set to 32.

  Remarks:
    Called needs to be aware that two of the input fields will be overwritten
    with the result of the conversion.
  *****************************************************************************/
void WF_WpaConvPassphraseToKey(t_wpaKeyInfo *p_keyInfo)
{
    uint8_t binaryKey[WF_WPA_KEY_LENGTH];
#if defined(WF_ERROR_CHECKING)
    uint32_t errorCode = UdConvWpaPassphrase(p_keyInfo);
    if (errorCode != UD_SUCCESS)
    {
        EventEnqueue(WF_EVENT_ERROR, errorCode);
        return;
    }
#endif
    p_keyInfo->key[p_keyInfo->keyLength] = '\0';   // make sure passphrase is terminated

    // generate the binary key
    pbkdf2_sha1((const char *)p_keyInfo->key,
                (const char *)p_keyInfo->ssid,
                p_keyInfo->ssidLen,
                4096,
                binaryKey, // binary key will be written to this field
                32);

    // overwrite the passphrase with binary key
    memcpy(p_keyInfo->key, binaryKey, WF_WPA_KEY_LENGTH);

    // overwrite the length with the length of the binary key (always 32)
    p_keyInfo->keyLength = WF_WPA_KEY_LENGTH;
}
コード例 #8
0
ファイル: wf_raw.c プロジェクト: logansam/WS2812WearableDemo
/*****************************************************************************
  Function:
    BOOL AllocateMgmtTxBuffer(uint16_t bytesNeeded)

  Summary:
    Allocates a Mgmt Tx buffer

  Description:
    Determines if WiFi chip has enough memory to allocate a tx mgmt buffer, and,
    if so, allocates it.

  Precondition:
    None

  Parameters:
    bytesNeeded -- number of bytes needed for the mgmt tx message

  Returns:
    True if mgmt tx buffer successfully allocated, else False

  Remarks:
    None
*****************************************************************************/
bool AllocateMgmtTxBuffer(uint16_t bytesNeeded)
{
    uint16_t bufAvail;
    uint16_t byteCount;

    /* get total bytes available for MGMT tx memory pool */
    bufAvail = Read16BitWFRegister(WF_HOST_WFIFO_BCNT1_REG) & 0x0fff; /* LS 12 bits contain length */

    /* if enough bytes available to allocate */
    if ( bufAvail >= bytesNeeded )
    {
        /* allocate and create the new Mgmt Tx buffer */
        byteCount = RawMove(RAW_MGMT_TX_ID, RAW_MGMT_POOL, true, bytesNeeded);
        if (byteCount == 0)
        {
             EventEnqueue(WF_EVENT_ERROR, UD_ERROR_MGMT_BUFFER_ALLOCATION_FAILED);
             return false;
        }
        ClearIndexOutOfBoundsFlag(RAW_MGMT_TX_ID);
        return true;
    }
    /* else not enough bytes available at this time to satisfy request */
    else
    {
        /* if we allocated some bytes, but not enough, then deallocate what was allocated */
        if (bufAvail > 0)
        {
            RawMove(RAW_MGMT_RX_ID, RAW_MGMT_POOL, false, 0);
        }
        return false;
    }
}
コード例 #9
0
ファイル: wf_power.c プロジェクト: ricklon/deIPcK
void WF_TxPowerMaxSet(uint8_t maxTxPower)
{
#if defined(WF_ERROR_CHECKING)
    uint32_t errorCode = udSetTxPowerMax(maxTxPower);
    if (errorCode != UD_SUCCESS)
    {
        EventEnqueue(WF_EVENT_ERROR, errorCode);
        return;
    }
#endif
}
コード例 #10
0
ファイル: wf_param_msg.c プロジェクト: ricklon/deIPcK
void WF_TxModeSet(uint8_t mode)
{
#if defined(WF_ERROR_CHECKING)
    uint32_t errorCode = UdSetTxMode(mode);
    if (errorCode != UD_SUCCESS)
    {
        EventEnqueue(WF_EVENT_ERROR, errorCode);
    }
#endif
    SendSetParamMsg(PARAM_TX_MODE, &mode, 1);
}
コード例 #11
0
ファイル: wf_raw.c プロジェクト: denrusio/vak-opensource
/*
 * Write bytes to RAW window.
 * Parameters:
 *  rawId   - RAW ID
 *  pBuffer - Buffer containing bytes to write
 *  length  - number of bytes to read
 */
void RawSetByte(uint16_t rawId, const uint8_t *p_buffer, uint16_t length)
{
    uint8_t regId;

    // if trying to write past end of raw window
    if (isIndexOutOfBounds(rawId)) {
        EventEnqueue(WF_EVENT_ERROR, UD_ERROR_RAW_SET_BYTE_OUT_OF_BOUNDS);
    }

    /* write data to raw window */
    regId = g_RawDataReg[rawId];
    WriteWFArray(regId, p_buffer, length);
}
コード例 #12
0
ファイル: wf_raw.c プロジェクト: denrusio/vak-opensource
/*
 * Read bytes from the specified raw window.
 * Returns error code.
 *
 * Parameters:
 *  rawId   - RAW ID
 *  pBuffer - Buffer to read bytes into
 *  length  - number of bytes to read
 */
void RawGetByte(uint16_t rawId, uint8_t *pBuffer, uint16_t length)
{
    uint8_t regId;

    // if the raw index was previously set out of bounds
    if (isIndexOutOfBounds(rawId)) {
        // trying to read past end of raw window
        EventEnqueue(WF_EVENT_ERROR, UD_ERROR_RAW_GET_BYTE_OUT_OF_BOUNDS);
    }

    regId = g_RawDataReg[rawId];
    ReadWFArray(regId, pBuffer, length);
}
コード例 #13
0
void WF_SecurityOpenSet()
{
#if defined(WF_ERROR_CHECKING)
    uint32_t errorCode = UdSetSecurityOpen();
    if (errorCode != UD_SUCCESS)
    {
        EventEnqueue(WF_EVENT_ERROR, errorCode);
        return;
    }
#endif
    
    WF_SetSecurity(WF_SECURITY_OPEN, 0, NULL, 0);
}
コード例 #14
0
/*******************************************************************************
  Function:
    void WF_SsidSet(uint8_t *p_ssid, uint8_t *p_ssidLength)

  Summary:
    Sets the SSID for the specified Connection Profile ID.

  Description:
    Sets the SSID and SSID Length elements in the Connection Profile.  Note that
    an Access Point can have either a visible or hidden SSID.  If an Access Point
    uses a hidden SSID then an active scan must be used (see scanType field in the
    Connection Algorithm).

  Precondition:
    MACInit must be called first.

  Parameters:
    p_ssid - Pointer to the SSID string
    ssidLength - Number of bytes in the SSID

  Returns:
    None.

  Remarks:
    None.
  *****************************************************************************/
void WF_SsidSet(uint8_t *p_ssid,  uint8_t ssidLength)
{
#if defined(WF_ERROR_CHECKING)
    uint32_t errorCode = UdSetSsid(p_ssid, ssidLength);
    if (errorCode != UD_SUCCESS)
    {
        EventEnqueue(WF_EVENT_ERROR, errorCode);
        return;
    }
#endif
    LowLevel_CPSetElement(WF_CP_ELEMENT_SSID,   /* Element ID                   */
                          p_ssid,               /* pointer to element data      */
                          ssidLength);          /* number of element data bytes */
}
コード例 #15
0
ファイル: wf_param_msg.c プロジェクト: ricklon/deIPcK
/*******************************************************************************
  Function:
    void WF_SetRegionalDomain(uint8_t regionalDomain)

  Summary:
    Sets the regional domain.

  Description:
    Sets the regional domain on the MRF24W.  By default the MRF24W will use the 
    factory-set regional domain.  It is invalid to call this function while in a
    connected state.

    Valid values for the regional domain are:
        WF_DOMAIN_FCC (default)
        WF_DOMAIN_ETSI
        WF_DOMAIN_JAPAN
        WF_DOMAIN_OTHER

  Parameters:
    regionalDomain - desired regional domain

  Returns:
    None.

  Remarks:
    None.
 *****************************************************************************/
void WF_RegionalDomainSet(uint8_t regionalDomain)
{
#if defined(WF_ERROR_CHECKING)
    uint32_t errorCode;

    errorCode = UdSetDomain(regionalDomain);
    if (errorCode != UD_SUCCESS)
    {
       EventEnqueue(WF_EVENT_ERROR, errorCode);
       return;
    }
#endif /* WF_ERROR_CHECKING */

    SendSetParamMsg(PARAM_REGIONAL_DOMAIN, &regionalDomain, 1);
}
コード例 #16
0
ファイル: wf_param_msg.c プロジェクト: ricklon/deIPcK
/*******************************************************************************
  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
}
コード例 #17
0
void WF_WpsCredentialsGet(t_wpsCredentials *p_cred)
{
#if defined(WF_ERROR_CHECKING)
    uint32_t errorCode = UdGetWpsCredentials();
    if (errorCode != UD_SUCCESS)
    {
        EventEnqueue(WF_EVENT_ERROR, errorCode);
        return;
    }
#endif
    LowLevel_CPGetElement(WF_CP_ELEMENT_READ_WPS_CRED,    // Element ID
                          (uint8_t *)p_cred,              // pointer to element data
                          sizeof(*p_cred),                // number of element data bytes
                          true);                          // read data, free buffer after read
}
コード例 #18
0
ファイル: wf_param_msg.c プロジェクト: ricklon/deIPcK
void WF_RtsThresholdSet(uint16_t rtsThreshold)
{
    uint16_t tmp;

#if defined(WF_ERROR_CHECKING)
    uint32_t errorCode = UdSetRtsThreshold(rtsThreshold);
    if (errorCode != UD_SUCCESS)
    {
        EventEnqueue(WF_EVENT_ERROR, errorCode);
        return;
    }
#endif

    tmp = htons(rtsThreshold);
    SendSetParamMsg(PARAM_RTS_THRESHOLD, (uint8_t *)&tmp, sizeof(tmp));
}
コード例 #19
0
/* Function:
    DRV_WIFI_SecurityWpaSet(DRV_WIFI_WPA_CONTEXT *p_context)

  Summary:
    Sets WiFi security to use WPA or WPA2.

  Description:
    This function sets the WiFi security to WPA or WPA2.  One can only connect to
    an AP that is running the same WPA mode.

  Parameters:
    p_context - Desired WPA context.  See DRV_WIFI_WPA_CONTEXT structure.

 Returns:
    None.
 */
void DRV_WIFI_SecurityWpaSet(DRV_WIFI_WPA_CONTEXT *p_context)
{
#if defined(WF_ERROR_CHECKING)
    uint32_t errorCode;

    errorCode = UdSetSecurityWpa(p_context);
    if (errorCode != UD_SUCCESS)
    {
        EventEnqueue(WF_EVENT_ERROR, errorCode);
        return;
    }
#endif /* WF_ERROR_CHECKING */
    SetSecurity(p_context->wpaSecurityType,
                p_context->keyInfo.key,
                p_context->keyInfo.keyLength);
}
コード例 #20
0
ファイル: wf_raw.c プロジェクト: logansam/WS2812WearableDemo
/*****************************************************************************
 * FUNCTION: WaitForRawMoveComplete
 *
 * RETURNS: Number of bytes that were overlayed (not always applicable)
 *
 * PARAMS:
 *      rawId   - RAW ID
 *
 *  NOTES: Waits for a RAW move to complete.
 *****************************************************************************/
static uint16_t WaitForRawMoveComplete(uint8_t rawId)

{
    uint8_t  rawIntMask;
    uint16_t byteCount;
    uint8_t  regId;
    uint32_t elapsedTime;
    uint32_t startTime;

    /* create mask to check against for Raw Move complete interrupt for either RAW0 or RAW1 */
    if (rawId <= RAW_ID_1)
    {
        /* will be either raw 0 or raw 1 */
        rawIntMask = (rawId == RAW_ID_0)?WF_HOST_INT_MASK_RAW_0_INT_0:WF_HOST_INT_MASK_RAW_1_INT_0;
    }
    else
    {
        /* will be INTR2 bit in host register, signifying RAW2, RAW3, or RAW4 */
        rawIntMask = WF_HOST_INT_MASK_INT2;
    }

    startTime = WF_TimerRead();
    while (1)
    {
  //      InterruptCheck();
        /* if received an external interrupt that signaled the RAW Move */
        /* completed then break out of this loop                         */
        if(RawMoveState.rawInterruptMask & rawIntMask)
        {
            break;
        }

        elapsedTime = GetElapsedTime(startTime, WF_TimerRead());
        if (elapsedTime > 20)
        {
            EventEnqueue(WF_EVENT_ERROR, UD_ERROR_RAW_INTERRUPT_TIMEOUT);
            break;
        }

    } /* end while */

    /* read the byte count and return it */
    regId = g_RawCtrl1Reg[rawId];
    byteCount = Read16BitWFRegister(regId);

    return ( byteCount );
}
コード例 #21
0
/*******************************************************************************
  Function:
    void WF_ChannelListSet(uint8_t *p_channelList, uint8_t numChannels)

  Summary:
    Sets the channel list.

  Description:
    Sets the Channel List used by the Connection Algorithm.

  Precondition:
    MACInit must be called first.

  Parameters:
    p_channelList - Pointer to channel list.
    numChannels   - Number of channels in p_channelList.  If set to 0, the
                     MRF24W will use all valid channels for the current
                     regional domain.

  Returns:
    None.

  Remarks:
    None.
 *****************************************************************************/
void WF_ChannelListSet(uint8_t *p_channelList, uint8_t numChannels)
{
#if defined(WF_ERROR_CHECKING)
    uint32_t errorCode;

    errorCode = UdSetChannelList(p_channelList, numChannels);
    if (errorCode != UD_SUCCESS)
    {
        EventEnqueue(WF_EVENT_ERROR, errorCode);
        return;
    }
#endif
    
    LowLevel_CASetElement(WF_CA_ELEMENT_CHANNEL_LIST,  /* Element ID                   */
                          p_channelList,               /* pointer to element data      */
                          numChannels);                /* number of element data bytes */
}
コード例 #22
0
/*******************************************************************************
  Function:
    void WF_NetworkTypeSet(uint8_t networkType)

  Summary:
    Sets the network for the specified Connection Profile ID.

  Description:
    Sets the Network Type element a Connection Profile.  Allowable values are:
    * WF_NETWORK_TYPE_INFRASTRUCTURE
    * WF_NETWORK_TYPE_ADHOC

  Precondition:

  Parameters:
    networkType - Type of network to create (infrastructure or adhoc)

  Returns:
    None.

  Remarks:
    None.
  *****************************************************************************/
void WF_NetworkTypeSet(uint8_t networkType)
{
#if defined(WF_ERROR_CHECKING)
    uint32_t errorCode;

    errorCode = UdSetNetworkType(networkType);
    if (errorCode != UD_SUCCESS)
    {
        EventEnqueue(WF_EVENT_ERROR, errorCode);
        return;
    }
#endif

    LowLevel_CPSetElement(WF_CP_ELEMENT_NETWORK_TYPE,   /* Element ID                   */
                          &networkType,                 /* pointer to element data      */
                          1);                           /* number of element data bytes */
}
コード例 #23
0
//============================================================================
void WF_SecurityWepSet(t_wepContext* p_context)
{
#if defined(WF_ERROR_CHECKING)
    uint32_t errorCode;

    errorCode = UdSetSecurityWep(p_context);
    if (errorCode != UD_SUCCESS)
    {
        EventEnqueue(WF_EVENT_ERROR, errorCode);
        return;
    }
#endif /* WF_ERROR_CHECKING */

    WF_SetSecurity(p_context->wepSecurityType,
                   p_context->wepKeyIndex,
                   p_context->wepKey,
                   p_context->wepKeyLength);
}
コード例 #24
0
ファイル: wf_raw.c プロジェクト: denrusio/vak-opensource
/*
 * Mounts most recent Rx message.
 * Returns length, a number of bytes in the received message.
 *
 * This function mounts the most recent Rx message from the WiFi chip, which
 * could be either a management or a data message.
 *
 * Parameters:
 *  rawId -- RAW ID specifying which raw window to mount the rx packet in.
 */
uint16_t RawMountRxBuffer(uint8_t rawId)
{
    uint16_t length;

    length = RawMove(rawId, RAW_MAC, true, 0);

    // the length should never be 0 if notified of an Rx msg
    if (length == 0) {
        EventEnqueue(WF_EVENT_ERROR, UD_ERROR_RAW_RX_MOUNT_FAILED);
    }

    /* if mounting a Raw Rx data frame */
    if (rawId == RAW_DATA_RX_ID) {
        /* notify WiFi driver that an Rx data frame is mounted */
        SetRawDataWindowState(RAW_DATA_RX_ID, WF_RAW_DATA_MOUNTED);
    }
    return length;
}
コード例 #25
0
//============================================================================
void WF_SecurityWpaSet(t_wpaContext* p_context)
{
#if defined(WF_ERROR_CHECKING)
    uint32_t errorCode;

    errorCode = UdSetSecurityWpa(p_context);
    if (errorCode != UD_SUCCESS)
    {
        EventEnqueue(WF_EVENT_ERROR, errorCode);
        return;
    }
#endif /* WF_ERROR_CHECKING */

    WF_SetSecurity(p_context->wpaSecurityType,
                   0, // not used
                   p_context->keyInfo.key,
                   p_context->keyInfo.keyLength);
}
コード例 #26
0
ファイル: wf_raw.c プロジェクト: logansam/WS2812WearableDemo
/*****************************************************************************
  Function:
    void RawSetIndex(uint16_t rawId, uint16_t index)

  Summary:
    Sets the index within the specified RAW window.

  Description:
    Sets the index within the specified RAW window. If attempt to set RAW index
    outside boundaries of RAW window (past the end) this function will time out.
    It's legal to set the index past the end of the raw window so long as there
    is no attempt to read or write at that index.  For now, flag an event.

  Precondition:
    None

  Parameters:
    rawId -- RAW window ID
    index -- desired index within RAW window

  Returns:
     None

  Remarks:
    None
*****************************************************************************/
void RawSetIndex(uint16_t rawId, uint16_t index)
{
    uint8_t  regId;
    uint16_t regValue;
    uint32_t elapsedTime;
    uint32_t startTime;

    /* get the index register associated with the raw ID and write to it */
    regId = g_RawIndexReg[rawId];
    Write16BitWFRegister(regId, index);

    /* Get the raw status register address associated with the raw ID.  This will be polled to         */
    /* determine that:                                                                                 */
    /*  1) raw set index completed successfully  OR                                                    */
    /*  2) raw set index failed, implying that the raw index was set past the end of the raw window    */
    regId = g_RawStatusReg[rawId];

    /* read the status register until set index operation completes or times out */
    startTime = WF_TimerRead();
    while (1)
    {
        regValue = Read16BitWFRegister(regId);
        if ((regValue & WF_RAW_STATUS_REG_BUSY_MASK) == 0)
        {
            ClearIndexOutOfBoundsFlag(rawId);
            break;
        }

        elapsedTime = GetElapsedTime(startTime, WF_TimerRead());
        if (elapsedTime > 5)
        {
            // if we timed out that means that the caller is trying to set the index
            // past the end of the raw window.  Not illegal in of itself so long
            // as there is no attempt to read or write at this location.  But,
            // applications should avoid this to avoid the timeout in
            SetIndexOutOfBoundsFlag(rawId);
            EventEnqueue(WF_EVENT_ERROR, UD_ERROR_RAW_SET_INDEX_OUT_OF_BOUNDS);
            break;
        }
    }
}
コード例 #27
0
ファイル: wf_param_msg.c プロジェクト: ricklon/deIPcK
/*******************************************************************************
  Function:
    void WF_SetHwMultiCastFilter(UINT8 multicastFilterId,
                                 UINT8 multicastAddress[WF_MAC_ADDRESS_LENGTH])

  Summary:
    Sets a multicast address filter using one of the two multicast filters.

  Description:
    This function allows the application to configure up to 16 software Multicast
    Address Filters on the MRF24WB0M.  If two active multicast filters are set
    up they are OR'd together and the MRF24WG will receive and pass to the Host
    CPU received packets from either multicast address.
    The allowable values for the multicast filter are:
    * WF_MULTICAST_FILTER_1
    * WF_MULTICAST_FILTER_2

    By default, both Multicast Filters are inactive.

  Parameters:
    multicastFilterId - WF_MULTICAST_FILTER_1 or WF_MULTICAST_FILTER_2
    multicastAddress  - 6-byte address (all 0xFF will inactivate the filter)

  Returns:
    None.

  Remarks:
    None.
  *****************************************************************************/
void WF_SetHwMultiCastFilter(uint8_t multicastFilterId,
                             uint8_t multicastAddress[WF_MAC_ADDRESS_LENGTH])
{
    int i;
    bool    deactivateFlag = true;
    uint8_t msgData[8];

#if defined(WF_ERROR_CHECKING)
    uint32_t errorCode = UdSetHwMulticastFilter(multicastFilterId, multicastAddress);
    if (errorCode != UD_SUCCESS)
    {
        EventEnqueue(WF_EVENT_ERROR, errorCode);
    }
#endif

    /* check if all 6 bytes of the address are 0xff, implying that the caller wants to deactivate */
    /* the multicast filter.                                                                      */
    for (i = 0; i < 6; ++i)
    {
        /* if any byte is not 0xff then a presume a valid multicast address */
        if (multicastAddress[i] != 0xff)
        {
            deactivateFlag = false;
            break;
        }
    }

    msgData[0] = multicastFilterId;     /* Address Compare Register number to use   */
    if (deactivateFlag)
    {
        msgData[1] = ADDRESS_FILTER_DEACTIVATE;
    }
    else
    {
        msgData[1] = MULTICAST_ADDRESS;     /* type of address being used in the filter */
    }

    memcpy(&msgData[2], (void *)multicastAddress, WF_MAC_ADDRESS_LENGTH);
    SendSetParamMsg(PARAM_COMPARE_ADDRESS, msgData, sizeof(msgData) );
}
コード例 #28
0
void WF_ScanContextSet(t_scanContext *p_context)
{
    uint16_t tmp;

#if defined(WF_ERROR_CHECKING)
    uint32_t errorCode = UdSetScanContext(p_context);
    if (errorCode != UD_SUCCESS)
    {
        EventEnqueue(WF_EVENT_ERROR, errorCode);
        return;
    }
#endif

    LowLevel_CASetElement(WF_CA_ELEMENT_SCANTYPE,           // Element ID
                          &p_context->scanType,             // pointer to element data
                          sizeof(p_context->scanType));     // number of element data bytes

    LowLevel_CASetElement(WF_CA_ELEMENT_SCAN_COUNT,
                          &p_context->scanCount,
                          sizeof(p_context->scanCount));

    tmp = htons(p_context->minChannelTime);
    LowLevel_CASetElement(WF_CA_ELEMENT_MIN_CHANNEL_TIME,
                          (uint8_t *)&tmp,
                          sizeof(tmp));

    tmp = htons(p_context->maxChannelTime);
    LowLevel_CASetElement(WF_CA_ELEMENT_MAX_CHANNEL_TIME,
                          (uint8_t *)&tmp,
                          sizeof(tmp));

    tmp = htons(p_context->probeDelay);
    LowLevel_CASetElement(WF_CA_ELEMENT_PROBE_DELAY,
                          (uint8_t *)&tmp,
                          sizeof(tmp));
}
コード例 #29
0
ファイル: wf_eint.c プロジェクト: denrusio/vak-opensource
/*
 * Periodically called to check if the MRF24WG external interrupt occurred, and
 * completes the interrupt processing.
 *
 * Some processing takes place in the actual interrupt routine, and some processing
 * takes place later in the round robin.  This function checks if an interrupt
 * has occurred, and if so, performs the rest of the interrupt processing.
 */
void InterruptCheck()
{
    uint8_t  hostIntRegValue;
    uint8_t  hostIntMaskRegValue;
    uint8_t  hostInt;
    uint16_t hostInt2;
    uint32_t assertInfo;

    // in no interrupt to process
    if (!g_ExIntNeedsServicing)
    {
        return;
    }

    g_ExIntNeedsServicing = false;

     /* read hostInt register to determine cause of interrupt */
    hostIntRegValue = Read8BitWFRegister(WF_HOST_INTR_REG);

    // OR in the saved interrupts during the time when we were waiting for raw complete, set by WFEintHandler()
    hostIntRegValue |= g_HostIntSaved;

    // done with the saved interrupts, clear variable
    g_HostIntSaved = 0;

    hostIntMaskRegValue  = Read8BitWFRegister(WF_HOST_MASK_REG);

    // AND the two registers together to determine which active, enabled interrupt has occurred
    hostInt = hostIntRegValue & hostIntMaskRegValue;

    // if received a level 2 interrupt
    if ((hostInt & WF_HOST_INT_MASK_INT2) == WF_HOST_INT_MASK_INT2)
    {
        // Either a mgmt tx or mgmt rx Raw move complete occurred, which is how
        // this interrupt is normally used.  If this is the case, the event was
        // already handled in WF_EintHandler(), and all we need to do here is
        // clear the interrupt.  However, there is one other event to check for;
        // this interrupt is also used by the MRF24WG to signal that it has
        // hit an assert condition.  So, we check for that here.

        // if the MRF24WG has hit an assert condition
        hostInt2 = Read16BitWFRegister(WF_HOST_INTR2_REG);
        if (hostInt2 & WF_HOST_INT_MASK_MAIL_BOX_0_WRT)
        {
            // module number in upper 8 bits, assert information in lower 20 bits
            assertInfo = (((uint32_t)Read16BitWFRegister(WF_HOST_MAIL_BOX_0_MSW_REG)) << 16) |
                                     Read16BitWFRegister(WF_HOST_MAIL_BOX_0_LSW_REG);
            // signal this event
            EventEnqueue(WF_EVENT_MRF24WG_MODULE_ASSERT, assertInfo);
        }

        /* clear this interrupt */
        Write16BitWFRegister(WF_HOST_INTR2_REG, WF_HOST_INT_MASK_INT2);
    }
    /* else if got a FIFO 1 Threshold interrupt (Management Fifo).  Mgmt Rx msg ready to proces. */
    else if ((hostInt & WF_HOST_INT_MASK_FIFO_1_THRESHOLD) == WF_HOST_INT_MASK_FIFO_1_THRESHOLD)
    {
        /* clear this interrupt */
        Write8BitWFRegister(WF_HOST_INTR_REG, WF_HOST_INT_MASK_FIFO_1_THRESHOLD);

        // signal that a mgmt msg, either confirm or indicate, has been received
        // and needs to be processed
        SignalMgmtMsgRx();
    }
    /* else if got a FIFO 0 Threshold Interrupt (Data Fifo).  Data Rx msg ready to process. */
    else if ((hostInt & WF_HOST_INT_MASK_FIFO_0_THRESHOLD) == WF_HOST_INT_MASK_FIFO_0_THRESHOLD)
    {
        /* clear this interrupt */
        Write8BitWFRegister(WF_HOST_INTR_REG, WF_HOST_INT_MASK_FIFO_0_THRESHOLD);

        // signal that a data msg has been received and needs to be processed
        SignalPacketRx();
    }
    /* else got a Host interrupt that we don't handle */
    else if (hostInt) {
        /* clear this interrupt */
        Write8BitWFRegister(WF_HOST_INTR_REG, hostInt);
        WF_EintEnable();
    }
    /* we got a spurious interrupt (no bits set in register) */
    else {
        /* spurious interrupt */
        WF_EintEnable();
    }
}