예제 #1
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)
{
    tMgmtMsgRxHdr  hdr;
    
    /* Wait until mgmt response is received */
    while (gMgmtConfirmMsgReceived == FALSE)
    {
        WFProcess();
        
        /* if received a data packet while waiting for mgmt packet */
        if (g_HostRAWDataPacketReceived)
        {
            /* loop until stack has processed the received data message */
            while (g_HostRAWDataPacketReceived)      
            {
                StackTask(); 
            }    

            /* 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 '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.                                                    */
        WF_ASSERT(hdr.result == WF_SUCCESS);

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

        /* 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); 
        }          
    }   
}  
예제 #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); 
        }          
    }   
}