/******************************************************************************* Function: void WF_MulticastGetConfig(uint8_t filterId, t_wfMultiCastConfig *p_config); Summary: Gets a multicast address filter from one of the two multicast filters. Description: Gets the current state of the specified Multicast Filter. Normally would call SendGetParamMsg, but this GetParam returns all 6 address filters + 2 more bytes for a total of 48 bytes plus header. So, doing this msg manually to not require a large stack allocation to hold all the data. Exact format of management message stored on device is: [0] -- always mgmt response (2) [1] -- always WF_GET_PARAM_SUBTYPE (16) [2] -- result (1 if successful) [3] -- mac state (not used) [4] -- data length (length of response data starting at index 6) [5] -- not used [6-11] -- Compare Address 0 address [12] -- Compare Address 0 group [13] -- Compare Address 0 type [14] -- Compare Address 0 macBitMask [15-17] -- Not used [18-23] -- Compare Address 1 address [24] -- Compare Address 1 group [25] -- Compare Address 1 type [26] -- Compare Address 1 macBitMask [27-29] -- Not used [30-35] -- Compare Address 2 address [36] -- Compare Address 2 group [37] -- Compare Address 2 type [38] -- Compare Address 2 macBitMask [39-41] -- Not used [42-47] -- Compare Address 3 address [48] -- Compare Address 3 group [49] -- Compare Address 3 type [50] -- Compare Address 3 macBitMask [51-53] -- Not used [54-59] -- Compare Address 4 address [60] -- Compare Address 4 group [61] -- Compare Address 4 type [62] -- Compare Address 4 macBitMask [63-65] -- Not used [66-71] -- Compare Address 5 address [72] -- Compare Address 5 group [73] -- Compare Address 5 type [74] -- Compare Address 5 macBitMask [75-77] -- Not used Precondition: MACInit must be called first. Parameters: filterId -- ID of filter being retrieved. Must be: DRV_WIFI_MULTICAST_FILTER_1 or DRV_WIFI_MULTICAST_FILTER_2 p_config -- Pointer to config structure filled in by this function. Returns: None. Remarks: None. *****************************************************************************/ void WF_MulticastGetConfig(uint8_t filterId, DRV_WIFI_SWMULTICAST_CONFIG *p_config) { uint8_t hdr[4]; uint8_t paramData[12]; SYS_ASSERT( (filterId <= DRV_WIFI_MULTICAST_FILTER_16), ""); hdr[0] = WF_MGMT_REQUEST_TYPE; hdr[1] = WF_GET_PARAM_SUBTYPE; hdr[2] = 0x00; /* MS 8 bits of param Id, always 0 */ hdr[3] = PARAM_COMPARE_ADDRESS; /* LS 8 bits of param ID */ SendMgmtMsg(hdr, /* header */ sizeof(hdr), /* size of header */ &filterId, /* multicast filter id */ 1); /* length is 1 */ WaitForMgmtResponseAndReadData(WF_GET_PARAM_SUBTYPE, /* expected subtype */ sizeof(paramData), /* num data bytes to read */ MSG_PARAM_START_DATA_INDEX, /* starting at this index */ paramData); /* write the response data here */ /* put param data into return structure */ p_config->filterId = filterId; memcpy((void *)p_config->macBytes, (void *)¶mData[0], 6); p_config->action = paramData[7]; p_config->macBitMask = paramData[8]; }
/******************************************************************************* Function: void DRV_WIFI_ScanGetResult(uint8_t listIndex, t_wfScanResult *p_scanResult) Summary: Read selected scan results back from MRF24W. Description: After a scan has completed this function is used to read one scan result at a time from the MRF24WG. Parameters: listIndex - Index (0-based list) of the scan entry to retrieve. p_scanResult - Pointer to where scan result is written. See DRV_WIFI_SCAN_RESULT structure. Returns: None. *****************************************************************************/ void DRV_WIFI_ScanGetResult(uint8_t listIndex, DRV_WIFI_SCAN_RESULT *p_scanResult) { uint8_t hdr[4]; hdr[0] = WF_MGMT_REQUEST_TYPE; hdr[1] = WF_SCAN_GET_RESULTS_SUBTYPE; hdr[2] = listIndex; /* scan result index to read from */ hdr[3] = 1; /* number of results to read */ SendMgmtMsg(hdr, /* header */ sizeof(hdr), /* size of header */ NULL, /* no data */ 0); /* no data */ /* index 4 contains number of scan results returned, index 5 is first byte of first scan result */ WaitForMgmtResponseAndReadData(WF_SCAN_GET_RESULTS_SUBTYPE, /* expected subtype */ sizeof(DRV_WIFI_SCAN_RESULT), /* num data bytes to read */ 5, /* starting at this index */ (uint8_t *)p_scanResult); /* write the response data here */ /* fix up endianness on the two 16-bit values in the scan results */ p_scanResult->beaconPeriod = TCPIP_Helper_ntohs(p_scanResult->beaconPeriod); p_scanResult->atimWindow = TCPIP_Helper_ntohs(p_scanResult->atimWindow); }
/******************************************************************************* Function: void WF_CMGetConnectionState(UINT8 *p_state, UINT8 *p_currentCpId) Summary: Returns the current connection state. Description: Precondition: MACInit must be called first. Parameters: p_state - Pointer to location where connection state will be written p_currentCpId - Pointer to location of current connection profile ID that is being queried. Returns: None. Remarks: None. *****************************************************************************/ void WF_CMGetConnectionState(UINT8 *p_state, UINT8 *p_currentCpId) { UINT8 hdrBuf[2]; UINT8 msgData[2]; hdrBuf[0] = WF_MGMT_REQUEST_TYPE; hdrBuf[1] = WF_CM_GET_CONNECTION_STATUS_SUBYTPE; SendMgmtMsg(hdrBuf, sizeof(hdrBuf), NULL, 0); /* wait for mgmt response, read data, free after read */ WaitForMgmtResponseAndReadData(WF_CM_GET_CONNECTION_STATUS_SUBYTPE, sizeof(msgData), /* num data bytes to read */ MGMT_RESP_1ST_DATA_BYTE_INDEX, /* only used if num data bytes > 0 */ msgData); /* only used if num data bytes > 0 */ *p_state = msgData[0]; /* connection state */ *p_currentCpId = msgData[1]; /* current CpId */ if ((*p_state == WF_CSTATE_CONNECTED_INFRASTRUCTURE) || (*p_state == WF_CSTATE_CONNECTED_ADHOC)) { SetLogicalConnectionState(TRUE); } else { SetLogicalConnectionState(FALSE); } }
/******************************************************************************* Function: static void LowLevel_CPGetElement(UINT8 CpId, UINT8 elementId, UINT8 *p_elementData, UINT8 elementDataLength, UINT8 dataReadAction) Summary: Get an element of the connection profile on the MRF24W. Description: All Connection Profile 'Get Element' functions call this function to construct the management message. The caller must fix up any endian issues prior to calling this function. Precondition: MACInit must be called first. Parameters: CpId - Connection Profile ID elementId - Element that is being read p_elementData - Pointer to where element data will be written elementDataLength - Number of element data bytes that will be read dataReadAction - If TRUE then read data per paramters and free mgmt response buffer. If FALSE then return after response received, do not read any data as the caller will do that, and don't free buffer, as caller will do that as well. Returns: None. Remarks: None. *****************************************************************************/ static void LowLevel_CPGetElement(UINT8 CpId, UINT8 elementId, UINT8 *p_elementData, UINT8 elementDataLength, UINT8 dataReadAction) /* TRUE or FALSE */ { UINT8 hdrBuf[4]; hdrBuf[0] = WF_MGMT_REQUEST_TYPE; /* indicate this is a mgmt msg */ hdrBuf[1] = WF_CP_GET_ELEMENT_SUBTYPE; /* mgmt request subtype */ hdrBuf[2] = CpId; /* Connection Profile ID */ hdrBuf[3] = elementId; /* Element ID */ SendMgmtMsg(hdrBuf, /* msg header */ sizeof(hdrBuf), /* msg header length */ NULL, /* msg data */ 0); /* msg data length */ if (dataReadAction == (UINT8)TRUE) { /* wait for mgmt response, read desired data, and then free response buffer */ WaitForMgmtResponseAndReadData(WF_CP_GET_ELEMENT_SUBTYPE, elementDataLength, /* num data bytes to read */ sizeof(tCPElementResponseHdr), /* index of first byte of element data */ p_elementData); /* where to write element data */ } else { /* wait for mgmt response, don't read any data bytes, do not release mgmt buffer */ WaitForMgmtResponse(WF_CP_GET_ELEMENT_SUBTYPE, DO_NOT_FREE_MGMT_BUFFER); } }
/******************************************************************************* Function: void WF_ScanGetResult(uint8_t listIndex, tWFScanResult *p_scanResult) Summary: Read scan results back from MRF24W. Description: After a scan has completed this function is used to read one or more of the scan results from the MRF24W. The scan results will be written contiguously starting at p_scanResult (see tWFScanResult structure for format of scan result). MRF24WB0M & MRF24WG0M support up to max of 60 scan results (SSIDs). Precondition: MACInit must be called first. WF_EVENT_SCAN_RESULTS_READY event must have already occurrerd. Parameters: listIndex - Index (0-based list) of the scan entry to retrieve. p_scanResult - Pointer to location to store the scan result structure Returns: None. Remarks: RSSI can only be obtained from the scan results p_scanResult->rssi. MRF24W checks out the signal strength from the preamble of the incoming packets. The higher the values, the stronger is the received signal strength. p_scanResult->rssi contains received signal strength indicator (RSSI). * MRF24WB : RSSI_MAX (200) , RSSI_MIN (106). * MRF24WG : RSSI_MAX (128) , RSSI_MIN (43). The RSSI value is not directly translated to dbm because this is not calibrated number. However, as a guideline, for 802.11b, MAX(200) corresponds to 0 dbm, MIN (106) corresponds to -94 dbm. *****************************************************************************/ void WF_ScanGetResult(uint8_t listIndex, tWFScanResult *p_scanResult) { uint8_t hdr[4]; /* char rssiChan[48]; */ /* reference for how to retrieve RSSI */ hdr[0] = WF_MGMT_REQUEST_TYPE; hdr[1] = WF_SCAN_GET_RESULTS_SUBTYPE; hdr[2] = listIndex; /* scan result index to read from */ hdr[3] = 1; /* number of results to read */ SendMgmtMsg(hdr, /* header */ sizeof(hdr), /* size of header */ NULL, /* no data */ 0); /* no data */ /* index 4 contains number of scan results returned, index 5 is first byte of first scan result */ WaitForMgmtResponseAndReadData(WF_SCAN_GET_RESULTS_SUBTYPE, /* expected subtype */ sizeof(tWFScanResult), /* num data bytes to read */ 5, /* starting at this index */ (uint8_t *)p_scanResult); /* write the response data here */ /* fix up endianness on the two 16-bit values in the scan results */ p_scanResult->beaconPeriod = WFSTOHS(p_scanResult->beaconPeriod); p_scanResult->atimWindow = WFSTOHS(p_scanResult->atimWindow); /* reference for how to retrieve RSSI */ /* Display SSID & Channel */ /* sprintf(rssiChan, " => RSSI: %u, Channel: %u\r\n", p_scanResult->rssi, p_scanResult->channel); */ /* putsUART(rssiChan); */ }
/******************************************************************************* Function: void DRV_WIFI_HWMulticastFilterGet(uint8_t multicastFilterId, uint8_t multicastAddress[6]) Summary: Gets a multicast address filter from one of the two multicast filters. Description: Gets the current state of the specified Multicast Filter. // DOM-IGNORE-BEGIN Normally would call SendGetParamMsg, but this GetParam returns all 6 address filters + 2 more bytes for a total of 48 bytes plus header. So, doing this msg manually to not require a large stack allocation to hold all the data. Exact format of returned message is: [0] -- always mgmt response (2) [1] -- always WF_GET_PARAM_SUBTYPE (16) [2] -- result (1 if successful) [3] -- mac state (not used) [4] -- data length (length of response data starting at index 6) [5] -- not used [6-11] -- Compare Address 0 address [12] -- Compare Address 0 group [13] -- Compare Address 0 type [14-19] -- Compare Address 1 address [20] -- Compare Address 1 group [21] -- Compare Address 1 type [22-27] -- Compare Address 2 address [28] -- Compare Address 2 group [29] -- Compare Address 2 type [30-35] -- Compare Address 3 address [36] -- Compare Address 3 group [37] -- Compare Address 3 type [38-43] -- Compare Address 4 address [44] -- Compare Address 4 group [45] -- Compare Address 4 type [46-51] -- Compare Address 5 address [52] -- Compare Address 5 group [53] -- Compare Address 5 type // DOM-IGNORE-END Parameters: multicastFilterId - DRV_WIFI_MULTICAST_FILTER_1 or DRV_WIFI_MULTICAST_FILTER_2 multicastAddress - 6-byte address Returns: None. *****************************************************************************/ void DRV_WIFI_HWMulticastFilterGet(uint8_t multicastFilterId, uint8_t multicastAddress[6]) { uint8_t hdr[4]; uint8_t paramData[8]; uint8_t startIndex; DRV_WIFI_ASSERT(multicastFilterId == DRV_WIFI_MULTICAST_FILTER_1 || multicastFilterId == DRV_WIFI_MULTICAST_FILTER_2, ""); hdr[0] = WF_MGMT_REQUEST_TYPE; hdr[1] = WF_GET_PARAM_SUBTYPE; hdr[2] = 0x00; /* MS 8 bits of param Id, always 0 */ hdr[3] = PARAM_COMPARE_ADDRESS; /* LS 8 bits of param ID */ SendMgmtMsg(hdr, /* header */ sizeof(hdr), /* size of header */ NULL, /* no data */ 0); /* no data */ if (multicastFilterId == DRV_WIFI_MULTICAST_FILTER_1) { startIndex = 38; /* index of first byte of index 4 address filter */ } else { startIndex = 46; /* index of first byte of index 5 address filter */ } WaitForMgmtResponseAndReadData(WF_GET_PARAM_SUBTYPE, /* expected subtype */ sizeof(paramData), /* num data bytes to read */ startIndex, /* starting at this index */ paramData); /* write the response data here */ memcpy((void *)multicastAddress, (void *)¶mData[0], 6); }
/******************************************************************************* Function: static void LowLevel_CAGetElement(uint8_t elementId, uint8_t *p_elementData, uint8_t elementDataLength, uint8_t dataReadAction) Summary: Get an element of the connection algorithm on the MRF24W. Description: Low-level function to send the appropriate management message to the MRF24W to get the Connection Algorithm element. Precondition: MACInit must be called first. Parameters: elementId - Element that is being read p_elementData - Pointer to where element data will be written elementDataLength - Number of element data bytes that will be read dataReadAction - If TRUE then read data per paramters and free mgmt response buffer. If FALSE then return after response received, do not read any data as the caller will do that, and don't free buffer, as caller will do that as well. Returns: None. Remarks: All Connection Algorithm 'Get Element' functions call this function to construct the management message. The caller must fix up any endian issues after getting the data from this function. *****************************************************************************/ static void LowLevel_CAGetElement(uint8_t elementId, uint8_t *p_elementData, uint8_t elementDataLength, bool dataReadAction) { uint8_t hdrBuf[4]; hdrBuf[0] = WF_MGMT_REQUEST_TYPE; /* indicate this is a mgmt msg */ hdrBuf[1] = WF_CA_GET_ELEMENT_SUBTYPE; /* mgmt request subtype */ hdrBuf[2] = elementId; /* Element ID */ hdrBuf[3] = 0; /* not used */ SendMgmtMsg(hdrBuf, sizeof(hdrBuf), NULL, 0); if (dataReadAction == true) { /* wait for mgmt response, read desired data, and then free response buffer */ WaitForMgmtResponseAndReadData(WF_CA_GET_ELEMENT_SUBTYPE, elementDataLength, /* num data bytes to read */ sizeof(tCAElementResponseHdr), /* index of first byte of element data */ p_elementData); /* where to write element data */ } else { /* wait for mgmt response, don't read any data bytes, do not release mgmt buffer */ WaitForMgmtResponse(WF_CA_GET_ELEMENT_SUBTYPE, DO_NOT_FREE_MGMT_BUFFER); } }
/******************************************************************************* Function: static void CPElementGet(uint8_t elementId, uint8_t *p_elementData, uint8_t elementDataLength, uint8_t dataReadAction) Summary: Get an element of the connection profile on the MRF24W. Description: All Connection Profile 'Get Element' functions call this function to construct the management message. The caller must fix up any endian issues prior to calling this function. Precondition: MACInit must be called first. Parameters: elementId - Element that is being read. p_elementData - Pointer to where element data will be written. elementDataLength - Number of element data bytes that will be read. dataReadAction - If true then read data per paramters and free mgmt response buffer. If false then return after response received, do not read any data as the caller will do that, and don't free buffer, as caller will do that as well. Returns: None. Remarks: None. *******************************************************************************/ static void CPElementGet(uint8_t elementId, uint8_t *p_elementData, uint8_t elementDataLength, uint8_t dataReadAction) /* true or false */ { uint8_t hdrBuf[4]; hdrBuf[0] = WF_MGMT_REQUEST_TYPE; /* indicate this is a mgmt msg */ hdrBuf[1] = WF_CP_GET_ELEMENT_SUBTYPE; /* mgmt request subtype */ hdrBuf[2] = CPID; /* Connection Profile ID */ hdrBuf[3] = elementId; /* Element ID */ SendMgmtMsg(hdrBuf, sizeof(hdrBuf), NULL, 0); if (dataReadAction == (uint8_t)true) { /* wait for mgmt response, read desired data, and then free response buffer */ WaitForMgmtResponseAndReadData(WF_CP_GET_ELEMENT_SUBTYPE, elementDataLength, sizeof(CPELEMENT_RESPONSE_HDR), p_elementData); } else { /* wait for mgmt response, don't read any data bytes, do not release mgmt buffer */ WaitForMgmtResponse(WF_CP_GET_ELEMENT_SUBTYPE, DO_NOT_FREE_MGMT_BUFFER); } }
/******************************************************************************* Function: void WF_ConnectionStateGet(uint8_t *p_state) Summary: Returns the current connection state. Description: Precondition: MACInit must be called first. Parameters: p_state - Pointer to location where connection state will be written Returns: None. Remarks: None. *****************************************************************************/ void WF_ConnectionStateGet(uint8_t *p_state) { uint8_t hdrBuf[2]; uint8_t msgData[2]; hdrBuf[0] = WF_MGMT_REQUEST_TYPE; hdrBuf[1] = WF_CM_GET_CONNECTION_STATUS_SUBYTPE; SendMgmtMsg(hdrBuf, sizeof(hdrBuf), NULL, 0); /* wait for mgmt response, read data, free after read */ WaitForMgmtResponseAndReadData(WF_CM_GET_CONNECTION_STATUS_SUBYTPE, sizeof(msgData), /* num data bytes to read */ MGMT_RESP_1ST_DATA_BYTE_INDEX, /* only used if num data bytes > 0 */ msgData); /* only used if num data bytes > 0 */ *p_state = msgData[0]; /* connection state */ if ((*p_state == WF_CSTATE_CONNECTED_INFRASTRUCTURE) || (*p_state == WF_CSTATE_CONNECTED_ADHOC)) { SetLogicalConnectionState(true); } else { SetLogicalConnectionState(false); } }
/******************************************************************************* Function: void WF_CPGetIds(UINT8 *p_cpIdList) Summary: Retrieves the CP ID bit mask. Description: Returns a list of all Connection Profile ID’s that have been created on the MRF24W. This is not to be confused with the Connection Algorithm’s connectionProfileList. This function returns a bit mask corresponding to a list of all Connection Profiles that have been created (whether they are in the connectionProfileList or not). Any Connection Profiles that have been saved to FLASH will be included. Note: the first release will only support two Connection Profiles in memory. Saving CP’s to FLASH will not be supported. Precondition: MACInit must be called first. Parameters: p_cpIdList - Pointer to value representing the bit mask where each bit index (plus 1) corresponds to a Connection Profile ID that has been created. For example, if this value is 0x03, then Connection Profile ID’s 1 and and 2 have been created. Returns: None. Remarks: None. *****************************************************************************/ void WF_CPGetIds(UINT8 *p_cpIdList) { UINT8 hdr[2]; hdr[0] = WF_MGMT_REQUEST_TYPE; hdr[1] = WF_CP_GET_ID_LIST_SUBTYPE; SendMgmtMsg(hdr, sizeof(hdr), NULL, 0); /* wait for mgmt response, read data, free after read */ WaitForMgmtResponseAndReadData(WF_CP_GET_ID_LIST_SUBTYPE, 1, /* num data bytes to read */ MGMT_RESP_1ST_DATA_BYTE_INDEX, /* only used if num data bytes > 0 */ p_cpIdList); /* only used if num data bytes > 0 */ }
/******************************************************************************* Function: void SendGetParamMsg(UINT8 paramType, UINT8 *p_paramData, UINT8 paramDataLength) Summary: Sends a GetParam Mgmt request to MRF24W and waits for response. Description: After response is received the param data is read from message and written to p_paramData. It is up to the caller to fix up endianness. Index Get Param Request ----- ----------------- 0 type (always 0x02 signifying a mgmt request) 1 subtype (always 0x10 signifying a Get Param Msg) 2 param ID [msb] (MS byte of parameter ID being requested, e.g. PARAM_SYSTEM_VERSION) 3 param ID [lsb] (LS byte of parameter ID being requested, e.g. PARAM_SYSTEM_VERSION) Index Get Param Response ------ ------------------ 0 type (always 0x02 signifying a mgmt response) 1 subtype (always 0x10 signifying a Param Response Msg 2 result (1 if successful -- any other value indicates failure 3 mac state (not used) 4 data length Length of response data starting at index 6 (in bytes) 5 not used 6 Data[0] first byte of returned parameter data N Data[N] Nth byte of param data Precondition: MACInit must be called first. Parameters: Returns: None. Remarks: None. *****************************************************************************/ static void SendGetParamMsg(uint8_t paramType, uint8_t *p_paramData, uint8_t paramDataLength) { uint8_t hdr[4]; hdr[0] = WF_MGMT_REQUEST_TYPE; hdr[1] = WF_GET_PARAM_SUBTYPE; hdr[2] = 0x00; /* MS 8 bits of param Id, always 0 */ hdr[3] = paramType; /* LS 8 bits of param ID */ SendMgmtMsg(hdr, /* header */ sizeof(hdr), /* size of header */ NULL, /* no data */ 0); /* no data */ WaitForMgmtResponseAndReadData(WF_GET_PARAM_SUBTYPE, /* expected subtype */ paramDataLength, /* num data bytes to read */ MSG_PARAM_START_DATA_INDEX, /* data for GetParam always starts at index 6 */ p_paramData); /* write the response data here */ }
/******************************************************************************* Function: void WF_CPCreate(UINT8 *p_CpId) Summary: Creates a Connection Profile on the MRF24W. Description: Requests the MRF24W to create a Connection Profile (CP), assign it an ID, and set all the elements to default values. The ID returned by this function is used in other connection profile functions. A maximum of 2 Connection Profiles can exist on the MRF24W. Precondition: MACInit must be called first. Parameters: p_CpId - Pointer to where Connection Profile ID will be written. If function fails, the CP ID will be set to 0xff. Returns: None. Remarks: None. *****************************************************************************/ void WF_CPCreate(UINT8 *p_CpId) { UINT8 hdr[2]; *p_CpId = 0xff; hdr[0] = WF_MGMT_REQUEST_TYPE; hdr[1] = WF_CP_CREATE_PROFILE_SUBTYPE; SendMgmtMsg(hdr, sizeof(hdr), NULL, /* no data */ 0); /* no data */ /* wait for MRF24W management response, read data, free response after read */ WaitForMgmtResponseAndReadData(WF_CP_CREATE_PROFILE_SUBTYPE, 1, /* num data bytes to read */ MGMT_RESP_1ST_DATA_BYTE_INDEX, /* read starting at index 4 */ p_CpId); /* write data here */ }
/******************************************************************************* Function: void WF_CheckConnectionState(UINT8 *p_state, UINT8 *p_currentCpId) Summary: Returns the current connection state. Description: Returns the current connection state. Parameters: p_state - Pointer to location where connection state will be written Returns: None. Remarks: Response msg is actually two bytes, the second byte being the Connection Profile ID. Since this is not being used, set msgData to a 1-byte array. *****************************************************************************/ void WF_ConnectionStateGet(uint8_t *p_state) { uint8_t hdrBuf[2]; uint8_t msgData[1]; hdrBuf[0] = WF_MGMT_REQUEST_TYPE; hdrBuf[1] = WF_CM_GET_CONNECTION_STATUS_SUBYTPE; SendMgmtMsg(hdrBuf, sizeof(hdrBuf), NULL, 0); // wait for mgmt response, read data, free after read WaitForMgmtResponseAndReadData(WF_CM_GET_CONNECTION_STATUS_SUBYTPE, sizeof(msgData), // num data bytes to read MGMT_RESP_1ST_DATA_BYTE_INDEX, // only used if num data bytes > 0 msgData); // only used if num data bytes > 0 *p_state = msgData[0]; // connection state }
/******************************************************************************* Function: void WF_CMCheckConnectionState(UINT8 *p_state, UINT8 *p_currentCpId) Summary: Returns the current connection state. Description: Precondition: MACInit must be called first. Parameters: p_state - Pointer to location where connection state will be written p_currentCpId - Pointer to location of current connection profile ID that is being queried. Returns: None. Remarks: None. *****************************************************************************/ void WF_CMCheckConnectionState(UINT8 *p_state, UINT8 *p_currentCpId) { UINT8 hdrBuf[2]; UINT8 msgData[2]; hdrBuf[0] = WF_MGMT_REQUEST_TYPE; hdrBuf[1] = WF_CM_GET_CONNECTION_STATUS_SUBYTPE; SendMgmtMsg(hdrBuf, sizeof(hdrBuf), NULL, 0); /* wait for mgmt response, read data, free after read */ WaitForMgmtResponseAndReadData(WF_CM_GET_CONNECTION_STATUS_SUBYTPE, sizeof(msgData), /* num data bytes to read */ MGMT_RESP_1ST_DATA_BYTE_INDEX, /* only used if num data bytes > 0 */ msgData); /* only used if num data bytes > 0 */ *p_state = msgData[0]; /* connection state */ *p_currentCpId = msgData[1]; /* current CpId */ }
//extern uint8_t state_SavedBeforeScan, ID_SavedBeforeScan; void WF_CMGetConnectionState(uint8_t *p_state, uint8_t *p_currentCpId) { uint8_t hdrBuf[2]; uint8_t msgData[2]; #if 0 //defined ( EZ_CONFIG_SCAN ) if (IS_SCAN_IN_PROGRESS(SCANCXT.scanState)) { *p_state = state_SavedBeforeScan; *p_currentCpId = ID_SavedBeforeScan; return; } #endif hdrBuf[0] = WF_MGMT_REQUEST_TYPE; hdrBuf[1] = WF_CM_GET_CONNECTION_STATUS_SUBYTPE; SendMgmtMsg(hdrBuf, sizeof(hdrBuf), NULL, 0); /* wait for mgmt response, read data, free after read */ WaitForMgmtResponseAndReadData(WF_CM_GET_CONNECTION_STATUS_SUBYTPE, sizeof(msgData), /* num data bytes to read */ MGMT_RESP_1ST_DATA_BYTE_INDEX, /* only used if num data bytes > 0 */ msgData); /* only used if num data bytes > 0 */ *p_state = msgData[0]; /* connection state */ *p_currentCpId = msgData[1]; /* current CpId */ if ((*p_state == WF_CSTATE_CONNECTED_INFRASTRUCTURE) || (*p_state == WF_CSTATE_CONNECTED_ADHOC)) { SetLogicalConnectionState(true); } else { SetLogicalConnectionState(false); } }