/***************************************************************************** * FUNCTION: SendMgmtMsg * * RETURNS: error code * * PARAMS: p_header -- pointer to mgmt message header data * headerLength -- number of bytes in the header * will be written * p_data -- pointer to mgmt message data * dataLength -- number of byte of data * * NOTES: Sends a management message *****************************************************************************/ void SendMgmtMsg(UINT8 *p_header, UINT8 headerLength, UINT8 *p_data, UINT8 dataLength) { #if defined(__18CXX) static UINT32 startTickCount; static UINT32 maxAllowedTicks; #else UINT32 startTickCount; UINT32 maxAllowedTicks; #endif /* cannot send management messages while in WF_ProcessEvent() */ WF_ASSERT(!isInWFProcessEvent()); EnsureWFisAwake(); /* if a Rx Data packet is mounted that has not yet been processed */ if (GetRawWindowState(RAW_RX_ID) == WF_RAW_DATA_MOUNTED) { /* save it, so after mgmt response received it can be restored */ PushRawWindow(RAW_RX_ID); RestoreRxData = TRUE; } /* mounts a tx mgmt buffer on the MRF24W when data tx is done */ maxAllowedTicks = TICKS_PER_SECOND / 200; /* 5 ms timeout */ startTickCount = (UINT32)TickGet(); while (!WFisTxMgmtReady() ) { MACProcess(); /* DEBUG -- REMOVE AFTER FIGURE OUT WHY TIMING OUT (RARELY HAPPENS) */ if (TickGet() - startTickCount >= maxAllowedTicks) { /* force flags so WFisTxMgmtReady will return TRUE */ SetRawWindowState(RAW_TX_ID, WF_RAW_UNMOUNTED); RawWindowReady[RAW_TX_ID] = FALSE; } } /* write out management header */ RawSetByte(RAW_TX_ID, p_header, headerLength); /* write out data (if any) */ if (dataLength > 0) { RawSetByte(RAW_TX_ID, p_data, dataLength); } /* send mgmt msg to MRF24W */ SendRAWManagementFrame(headerLength + dataLength); }
/******************************************************************************* Function: void SendMgmtMsg(UINT8 *p_header, UINT8 headerLength, UINT8 *p_data, UINT8 dataLength) Summary: Sends a management message to MRF24W. Description: Allocates management buffer on MRF24W. Then sends the management message (header + data) to MRF24W. Precondition: MACInit must be called. Parameters: p_header -- pointer to mgmt message header data headerLength -- number of bytes in the header will be written p_data -- pointer to mgmt message data dataLength -- number of bytes of data Returns: None Remarks: *****************************************************************************/ void SendMgmtMsg(UINT8 *p_header, UINT8 headerLength, UINT8 *p_data, UINT8 dataLength) { UINT32 timeoutPeriod; UINT32 startTickCount; /* cannot send management messages while in WF_ProcessEvent() */ WF_ASSERT(!isInWFProcessEvent()); EnsureWFisAwake(); /* Allocate a management buffer on the WiFi device. May have to wait a bit while the previous Data Tx packet is being sent */ /* which will free up the memory for this mgmt packet. */ timeoutPeriod = TICKS_PER_SECOND / 2; /* 500 ms */ startTickCount = (UINT32)TickGet(); while (AllocateMgmtTxBuffer(WF_MAX_TX_MGMT_MSG_SIZE) == FALSE) { if (TickGet() - startTickCount >= timeoutPeriod) { WF_ASSERT(FALSE); } } /* write out management header */ RawSetByte(RAW_MGMT_TX_ID, p_header, headerLength); /* write out data (if any) */ if (dataLength > 0) { RawSetByte(RAW_MGMT_TX_ID, p_data, dataLength); } /* send mgmt msg to MRF24W */ SendRAWManagementFrame(headerLength + dataLength); }