Пример #1
0
/*
*********************************************************************************************************
*                                   WF_RxDataReadPacket()
*
* Description : Reads all or part of an Rx data packet from MRF24WB0M memory to Host CPU memory.
*
* Argument(s) : p_rxData   - pointer to where Rx data packet will be written
*               length     - Number of bytes to read from MRF24WB0M memory
*               startIndex - start index within MRF24WB0M memory to start read from
*
* Return(s)   : None
*
* Caller(s)   : Application
*
* Notes:      : None
*
*********************************************************************************************************
*/
void WF_RxDataReadPacket(uint8_t  *p_rxData,
                         uint16_t length,
                         uint16_t startIndex)
{
#if !defined(USE_WF_HOST_BUFFER)
    uint16_t byteCount;
#endif

    WF_ASSERT(startIndex == 0);

    /* if application calls this function, and gHostRAWDataPacketReceived is not true, then error, because */
    /* driver has not received a data packet.                                                              */
    if (!g_HostRAWDataPacketReceived)
    {
        WF_ASSERT(false);
    }

    g_HostRAWDataPacketReceived = false;     /* clear flag for next data packet */

    /* Ensure the MRF24WB0M is awake (only applies if PS-Poll was enabled) */
    EnsureWFisAwake();

#if !defined(USE_WF_HOST_BUFFER)  /* when testing with MCHP stack the packet is already mounted */
    /* Mount Read FIFO to RAW Rx window. Size of Rx data packet is returned */
    byteCount = RawMountRxBuffer();
    WF_ASSERT(byteCount > 0);
#endif

    /* now that buffer mounted it is safe to reenable interrupts */
    WF_EintEnable();

    /* read the requested bytes into callers buffer */
    RawRead(RAW_RX_ID, RAW_RX_DEST_ADD_INDEX + startIndex, length, p_rxData);
}
Пример #2
0
/*******************************************************************************
  Function:
    void WaitForMgmtResponse(UINT8 expectedSubtype, UINT8 freeAction)

  Summary:
    Waits for a management response

  Description:
    Called after sending a mgmt request.  This function waits for a mgmt
    response.  The caller can optionally request the the management
    response be freed immediately (by this function) or not freed.  If not
    freed, the caller is responsible to free the response buffer.

  Precondition:
    MACInit must be called.

  Parameters:
    expectedSubtype -- Expected subtype of the mgmt response
    freeAction           -- FREE_MGMT_BUFFER or DO_NOT_FREE_MGMT_BUFFER

  Returns:
    None

  Remarks:
      *****************************************************************************/
void WaitForMgmtResponse(UINT8 expectedSubtype, UINT8 freeAction)
{
#if defined(__18CXX)
    static tMgmtMsgRxHdr  hdr;
#else
    tMgmtMsgRxHdr  hdr;
#endif

    g_WaitingForMgmtResponse = TRUE;

    /* Wait until mgmt response is received */
    while (gMgmtConfirmMsgReceived == FALSE)
    {
        WFProcess();

        /* if received a data packet while waiting for mgmt packet */
        if (g_HostRAWDataPacketReceived)
        {
            // We can't let the StackTask processs data messages that come in while waiting for mgmt
            // response because the application might send another mgmt message, which is illegal until the response
            // is received for the first mgmt msg.  And, we can't prevent the race condition where a data message
            // comes in before a mgmt response is received.  Thus, the only solution is to throw away a data message
            // that comes in while waiting for a mgmt response.  This should happen very infrequently.  If using TCP then the
            // stack takes care of retries.  If using UDP, the application has to deal with occasional data messages not being
            // received.  Also, applications typically do not send a lot of management messages after connected.

            // throw away the data rx
            RawMountRxBuffer(RAW_DATA_RX_ID);
            DeallocateDataRxBuffer();
            g_HostRAWDataPacketReceived = FALSE;

            /* ensure interrupts enabled */
            WF_EintEnable();
        }
    }
    g_WaitingForMgmtResponse = FALSE;

    /* set this back to FALSE so the next mgmt send won't think he has a response before one is received */
    gMgmtConfirmMsgReceived = FALSE;


    /* if the caller wants to delete the response immediately (doesn't need any data from it */
    if (freeAction == FREE_MGMT_BUFFER)
    {
        /* read and verify result before freeing up buffer to ensure our message send was successful */
        RawRead(RAW_MGMT_RX_ID, 0, (UINT16)(sizeof(tMgmtMsgRxHdr)), (UINT8 *)&hdr);

        /* mgmt response subtype had better match subtype we were expecting */
        WF_ASSERT(hdr.subtype == expectedSubtype);

        /* Mgmt response 'result' field should always indicate success.  If this assert is hit the error codes are located */
        /* WFApi.h.  Search for WF_SUCCESS for the list of error codes.                                                    */
        if (hdr.result == WF_ERROR_HOST_SCAN_NOT_ALLOWED)
        {
#if defined(STACK_USE_UART)
            putrsUART("Host Scan Failed. Host scan is allowed only in idle or connected state\r\n");
#endif
        } else if (hdr.result == WF_ERROR_INVALID_WPS_PIN)
        {
#if defined(STACK_USE_UART)
            putrsUART("WPS failed : Invalid WPS PIN data\r\n");
#endif
        } else if (hdr.result == WF_ERROR_DISCONNECT_FAILED)
        {
#if defined(STACK_USE_UART)
            putrsUART("Disconnect failed. Disconnect is allowed only when module is in connected state\r\n");
#endif
        }
        else if (hdr.result == WF_ERROR_NO_STORED_BSS_DESCRIPTOR)
        {
#if defined(STACK_USE_UART)
            putrsUART("No stored scan results\r\n");
#endif
        }
        else if (hdr.result != WF_SUCCESS)
        {
#if defined(STACK_USE_UART)
            UINT8 buf[8];
            putrsUART("WaitForMgmtResponse result error: ");
            sprintf((char *)buf, "%d",hdr.result);
            putrsUART((char *)buf);
            putrsUART("\r\n");
#endif
            //WF_ASSERT(FALSE);
        }

        /* free mgmt buffer */
        DeallocateMgmtRxBuffer();
    }

}
Пример #3
0
/*****************************************************************************
 * FUNCTION: WaitForMgmtResponse
 *
 * RETURNS:  None
 *
 * PARAMS:   expectedSubtype -- The expected subtype of the mgmt response
 *           freeAction      -- FREE_MGMT_BUFFER or DO_NOT_FREE_MGMT_BUFFER
 *
 *  NOTES:   Called after sending a mgmt request.  This function waits for a mgmt
 *           response.  The caller can optionally request the the management 
 *           response be freed immediately (by this function) or not freed.  If not
 *           freed the caller is responsible to free the response buffer.
 *****************************************************************************/
void WaitForMgmtResponse(UINT8 expectedSubtype, UINT8 freeAction)
{
    #if defined(__18CXX)
        static tMgmtMsgRxHdr  hdr; 
    #else
        tMgmtMsgRxHdr  hdr; 
    #endif
    
    g_WaitingForMgmtResponse = TRUE;
        
    /* Wait until mgmt response is received */
    while (gMgmtConfirmMsgReceived == FALSE)
    {
        WFProcess();
        
        /* if received a data packet while waiting for mgmt packet */
        if (g_HostRAWDataPacketReceived)
        {
            // We can't let the StackTask processs data messages that come in while waiting for mgmt 
            // response because the application might send another mgmt message, which is illegal until the response
            // is received for the first mgmt msg.  And, we can't prevent the race condition where a data message 
            // comes in before a mgmt response is received.  Thus, the only solution is to throw away a data message
            // that comes in while waiting for a mgmt response.  This should happen very infrequently.  If using TCP then the 
            // stack takes care of retries.  If using UDP, the application has to deal with occasional data messages not being
            // received.  Also, applications typically do not send a lot of management messages after connected.

            // throw away the data rx 
            RawMountRxBuffer();
            DeallocateDataRxBuffer();
            g_HostRAWDataPacketReceived = FALSE;

            /* ensure interrupts enabled */
            WF_EintEnable();
        }    
    } 
    
    /* set this back to FALSE so the next mgmt send won't think he has a response before one is received */
    gMgmtConfirmMsgReceived = FALSE;
    
    
    /* if the caller wants to delete the response immediately (doesn't need any data from it */
    if (freeAction == FREE_MGMT_BUFFER)
    {
        /* read and verify result before freeing up buffer to ensure our message send was successful */
        RawRead(RAW_RX_ID, 0, (UINT16)(sizeof(tMgmtMsgRxHdr)), (UINT8 *)&hdr);

        /* mgmt response subtype had better match subtype we were expecting */
        WF_ASSERT(hdr.subtype == expectedSubtype);

        if (hdr.result == WF_ERROR_DISCONNECT_FAILED 
            || hdr.result == WF_ERROR_NOT_CONNECTED) {
            #if defined(STACK_USE_UART)
                putrsUART("Disconnect failed. Disconnect is allowed only when module is in connected state\r\n");
            #endif
        } else if (hdr.result == WF_ERROR_NO_STORED_BSS_DESCRIPTOR) {
            #if defined(STACK_USE_UART)
                putrsUART("No stored scan results\r\n");
            #endif
        } else {
            WF_ASSERT(hdr.result == WF_SUCCESS); 
        }

        /* free mgmt buffer */
        DeallocateMgmtRxBuffer();  
        
        /* if there was a mounted data packet prior to the mgmt tx/rx transaction, then restore it */
        if (RestoreRxData == TRUE)
        {
            RestoreRxData = FALSE;
            PopRawWindow(RAW_RX_ID);
            SetRawWindowState(RAW_RX_ID, WF_RAW_DATA_MOUNTED); 
        }          
    }   
}