/*******************************************************************************
  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:
    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);
    }
}
Example #3
0
/*******************************************************************************
  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);
}
Example #4
0
/*******************************************************************************
  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); */
}
Example #5
0
/*******************************************************************************
  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 *)&paramData[0], 6);
    p_config->action = paramData[7];
    p_config->macBitMask = paramData[8];
}                                   
/*******************************************************************************
  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:	
    UINT16 WF_CMDisconnect(void)

  Summary:
    Commands the MRF24W 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_CMConnect() is called.  Generates the event 
    WF_EVENT_CONNECTION_PERMANENTLY_LOST when the connection is successfully
    terminated.
    
  Precondition:
    MACInit must be called.

  Parameters:
    None.

  Returns:
    Operation results. Success or Failure
  	
  Remarks:
    None.
  *****************************************************************************/
UINT16 WF_CMDisconnect(void)
{
    UINT8  hdrBuf[2];

	/* WARNING !!! : 
	* Disconnect is allowed only in connected state. 
	* If module FW is in the midst of connection ( or reconenction) process, then
	* disconnect can hammer connection process, and furthermore it may cause
	* fatal failure in module FW operation. To be safte to use disconnect, we strongly
	* recommend you to disable module FW connection manager by uncommenting
	* #define DISABLE_MODULE_FW_CONNECT_MANAGER_IN_INFRASTRUCTURE	
	* in WF_Config.h
	*/
	if (!WF_CMIsDisconnectAllowed())
		return WF_ERROR_DISCONNECT_FAILED;

    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);

    /* set state to no connection */
    SetLogicalConnectionState(FALSE);
    
    return WF_SUCCESS;
}    
Example #8
0
/*******************************************************************************
  Function:	
    UINT16 WF_Scan(UINT8 CpId)

  Summary:
    Commands the MRF24W to start a scan operation.  This will generate the 
    WF_EVENT_SCAN_RESULTS_READY event.

  Description:
    Directs the MRF24W to initiate a scan operation utilizing the input 
    Connection Profile ID.  The Host Application will be notified that the scan 
    results are ready when it receives the WF_EVENT_SCAN_RESULTS_READY event.  
    The eventInfo field for this event will contain the number of scan results.  
    Once the scan results are ready they can be retrieved with 
    WF_ScanGetResult().

    Scan results are retained on the MRF24W until:
    1.	Calling WF_Scan() again (after scan results returned from previous 
         call).
    2.	MRF24W reset.

  Precondition:
  	MACInit must be called first.

  Parameters:
    CpId - Connection Profile to use.  
            If the CpId is valid then the values from that Connection Profile 
            will be used for filtering scan results.  If the CpId is set to 
            WF_SCAN_ALL (0xFF) then a default filter will be used.

            Valid CpId
            * If CP has a defined SSID only scan results with that SSID are 
               retained.  
            * If CP does not have a defined SSID then all scanned SSID’s will be 
               retained
            * Only scan results from Infrastructure or AdHoc networks are 
               retained, depending on the value of networkType in the Connection Profile
            * The channel list that is scanned will be determined from 
               channelList in the Connection Algorithm (which must be defined 
               before calling this function).

            CpId is equal to WF_SCAN_ALL
            * All scan results are retained (both Infrastructure and Ad Hoc 
               networks).
            * All channels within the MRF24W’s regional domain will be 
               scanned.
            * No Connection Profiles need to be defined before calling this 
               function.
            * The Connection Algorithm does not need to be defined before 
               calling this function.

  Returns:
  	Operation results. Success or Failure
  	
  Remarks:
  	None.
  *****************************************************************************/
UINT16 WF_Scan(UINT8 CpId)
{
    UINT8   hdr[4];

	/* WARNING !!! : 
	* Host scan is allowed only in idle or connected state. 
	* If module FW is in the midst of connection ( or reconenction) process, then
	* host scan can hammer connection process, and furthermore it may cause
	* fatal failure in module FW operation. To be safte to use host scan, we strongly
	* recommend you to disable module FW connection manager by uncommenting
	* #define DISABLE_MODULE_FW_CONNECT_MANAGER_IN_INFRASTRUCTURE	
	* in WF_Config.h
	*/
	if (!WF_CMIsHostScanAllowed())	
		return WF_ERROR_OPERATION_CANCELLED;
    
    hdr[0] = WF_MGMT_REQUEST_TYPE;
    hdr[1] = WF_SCAN_START_SUBTYPE; 
    hdr[2] = CpId;                  /* Connection Profile ID */
    hdr[3] = 0;                     /* not used              */
    
    SendMgmtMsg(hdr,             /* header           */
                sizeof(hdr),     /* size of header   */
                NULL,            /* no data          */
                0);              /* no data          */

    /* wait for mgmt response, free it after it comes in (no data needed) */
	WaitForMgmtResponse(WF_SCAN_START_SUBTYPE, FREE_MGMT_BUFFER); 

	return WF_SUCCESS;
}
/*******************************************************************************
  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);
}
/*******************************************************************************
  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);
}
Example #11
0
/*******************************************************************************
  Function:
    uint16_t DRV_WIFI_Scan(bool scanAll)

  Summary:
    Commands the MRF24W to start a scan operation.  This will generate the
    WF_EVENT_SCAN_RESULTS_READY event.

  Description:
    Directs the MRF24W to initiate a scan operation.  The Host Application will
    be notified that the scan results are ready when it receives the
    WF_EVENT_SCAN_RESULTS_READY event.  The eventInfo field for this event will
    contain the number of scan results.  Once the scan results are ready they
    can be retrieved with DRV_WIFI_ScanGetResult().

    Scan results are retained on the MRF24W until:
    1. Calling DRV_WIFI_Scan() again (after scan results returned from previous
         call).
    2. MRF24W reset.

  Parameters:
    scanAll -
            If false:
            * If SSID defined then only scan results with that SSID are retained.
            * If SSID not defined then all scanned SSID’s will be retained
            * Only scan results from Infrastructure or AdHoc networks are retained
            * The channel list that is scanned will be determined from the channels
              passed in via DRV_WIFI_ChannelListSet().

            If true:
            * All scan results are retained (both Infrastructure and Ad Hoc
               networks).
            * All channels within the MRF24W’s regional domain will be
               scanned.

  Returns:
    None.
  *****************************************************************************/
uint16_t DRV_WIFI_Scan(bool scanAll)
{
    uint8_t   hdr[4];
    
    /* WARNING !!! : 
    * Host scan is allowed only in idle or connected state. 
    * If module FW is in the midst of connection ( or reconenction) process, then
    * host scan can hammer connection process, and furthermore it may cause
    * fatal failure in module FW operation. To be safte to use host scan, we strongly
    * recommend you to disable module FW connection manager by setting
    * WF_MODULE_CONNECTION_MANAGER == DRV_WIFI_DISABLED in wf_drv_config.h
    */
    if (!isHostScanAllowed())
    {
        return DRV_WIFI_ERROR_OPERATION_CANCELLED;
    }

    hdr[0] = WF_MGMT_REQUEST_TYPE;
    hdr[1] = WF_SCAN_START_SUBTYPE;
    hdr[2] = (scanAll == true)?0xff:CPID;
    hdr[3] = 0;                   /* not used              */
    
    SendMgmtMsg(hdr,             /* header           */
                sizeof(hdr),     /* size of header   */
                NULL,            /* no data          */
                0);              /* no data          */

    /* wait for mgmt response, free it after it comes in (no data needed) */
    WaitForMgmtResponse(WF_SCAN_START_SUBTYPE, FREE_MGMT_BUFFER);

    return DRV_WIFI_SUCCESS;
}
/*******************************************************************************
  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:
    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 *)&paramData[0], 6);
}
/*******************************************************************************
  Function:
    uint16_t WF_CMDisconnect(void)

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

  Description:
    Directs the Connection Manager to close the open connection.
    No further attempts to connect are taken until WF_CMConnect() is called.

  Precondition:
    MACInit must be called.

  Parameters:
    None.

  Returns:
    Operation results. Success or Failure

  Remarks:
    Disconnection can work only in the connected state.
    To use this API safely, we recommend to disable module FW connection
    manager by setting WF_MODULE_CONNECTION_MANAGER == WF_DISABLED
    in drv_wifi_config.h
  *****************************************************************************/
uint16_t WF_CMDisconnect(void)
{
    uint8_t  hdrBuf[2];

    /* Check if we can call disconnect. Disconnect can work only in the connected state */
    if (!WF_CMIsDisconnectAllowed())
    {
        return WF_ERROR_DISCONNECT_FAILED;
    }

    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);

    /* set state to no connection */
    SetLogicalConnectionState(false);

    return WF_SUCCESS;
}
/*******************************************************************************
  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);
    }
}
// creates a connection profile on MRF24WG that will be used forever
void ConnectionProfileCreate(void)
{
    uint8_t  hdr[2];

    hdr[0] = WF_MGMT_REQUEST_TYPE;
    hdr[1] = WF_CP_CREATE_PROFILE_SUBTYPE;

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

    /* wait for MRF24W management response, read data, free response after read */
    WaitForMgmtResponse(WF_CP_CREATE_PROFILE_SUBTYPE, FREE_MGMT_BUFFER);
}
/*******************************************************************************
  Function:	
    void WF_CPDelete(UINT8 CpId)

  Summary:
    Deletes a Connection Profile on the MRF24W.

  Description:
    Deletes the specified Connection Profile.  If the Connection Profile was in 
    FLASH it will be erased from FLASH.

    NOTE: First release of this code will not support FLASH, only the two CP’s 
    in memory.

  Precondition:
    MACInit must be called first.

  Parameters:
    CpId - Connection Profile to delete.

  Returns:
    None.
  	
  Remarks:
    None.
  *****************************************************************************/
void WF_CPDelete(UINT8 CpId)
{
    UINT8  hdr[2];

    hdr[0] = WF_MGMT_REQUEST_TYPE;
    hdr[1] = WF_CP_DELETE_PROFILE_SUBTYPE;
    
    SendMgmtMsg(hdr,
                sizeof(hdr),
                &CpId,           /* input data */
                1);              /* data size  */

    /* wait for mgmt response, free it after it comes in (no data needed) */
	WaitForMgmtResponse(WF_CP_DELETE_PROFILE_SUBTYPE, FREE_MGMT_BUFFER); 
}
Example #18
0
static void SendPowerModeMsg(t_WFPwrModeReq *p_powerMode)
{
    uint8_t hdr[2];

    hdr[0] = WF_MGMT_REQUEST_TYPE;
    hdr[1] = WF_SET_POWER_MODE_SUBTYPE;

    SendMgmtMsg(hdr,
                sizeof(hdr),
               (uint8_t *)p_powerMode,
               sizeof(t_WFPwrModeReq));

    /* wait for mgmt response, free buffer after it comes in (no data to read) */
    WaitForMgmtResponse(WF_SET_POWER_MODE_SUBTYPE, FREE_MGMT_BUFFER);
}
/*******************************************************************************
  Function:    
    void SetSecurity(uint8_t securityType,
                     uint8_t *p_securityKey,
                     uint8_t securityKeyLength)

  Summary:
    Sets the security

  Description:
    Configures security

    <table>
    Security                                      Key         Length
    --------                                      ---         ------
    DRV_WIFI_SECURITY_OPEN                        N/A         N/A
    DRV_WIFI_SECURITY_WEP_40                      hex         4, 5 byte keys
    DRV_WIFI_SECURITY_WEP_104                     hex         4, 13 byte keys
    DRV_WIFI_SECURITY_WPA_WITH_KEY                hex         32 bytes
    DRV_WIFI_SECURITY_WPA_WITH_PASS_PHRASE        ascii       8-63 ascii characters
    DRV_WIFI_SECURITY_WPA2_WITH_KEY               hex         32 bytes
    DRV_WIFI_SECURITY_WPA2_WITH_PASS_PHRASE       ascii       8-63 ascii characters
    DRV_WIFI_SECURITY_WPA_AUTO_WITH_KEY           hex         32 bytes
    DRV_WIFI_SECURITY_WPA_AUTO_WITH_PASS_PHRASE   ascii       8-63 ascii characters
    </table>

  Precondition:
    MACInit must be called first.

  Parameters:
    securityType - Value corresponding to the security type desired.
    p_securityKey - Binary key or passphrase (not used if security is 
                     DRV_WIFI_SECURITY_OPEN)
    securityKeyLength - Number of bytes in p_securityKey (not used if security
                         is DRV_WIFI_SECURITY_OPEN)

  Returns:
    None.
      
  Remarks:
    None.
  *****************************************************************************/
static void SetSecurity(uint8_t securityType,
                        uint8_t *p_securityKey,
                        uint8_t securityKeyLength)
{
    uint8_t  hdrBuf[7];
    uint8_t  *p_key;

    /* Write out header portion of msg */
    hdrBuf[0] = WF_MGMT_REQUEST_TYPE;           /* indicate this is a mgmt msg     */
    hdrBuf[1] = WF_CP_SET_ELEMENT_SUBTYPE;      /* mgmt request subtype            */     
    hdrBuf[2] = CPID;                           /* Connection Profile ID           */
    hdrBuf[3] = WF_CP_ELEMENT_SECURITY;         /* Element ID                      */
    
    /* Next to header bytes are really part of data, but need to put them in header*/
    /* bytes in order to prepend to security key                                   */
    hdrBuf[5] = securityType;                   
    hdrBuf[6] = 0;                              /* only support wep key index 0    */
    
    /* if security is open (no key) or WPS push button method */
    if (securityType == DRV_WIFI_SECURITY_OPEN            ||
        securityType == DRV_WIFI_SECURITY_WPS_PUSH_BUTTON ||
        securityType == DRV_WIFI_SECURITY_EAP)
    {
        hdrBuf[4]         = 2;      /* Only data is security type and wep index */ 
        p_key             = NULL;   
        securityKeyLength = 0;    

    } 
    /* else security is selected, so need to send key */   
    else
    {
        hdrBuf[4] = 2 + securityKeyLength;  /* data is security type + wep index + key */
        p_key     = p_securityKey;       
    }    
    
    SendMgmtMsg(hdrBuf,              /* msg header which includes the security type and WEP index)    */
                sizeof(hdrBuf),      /* msg header length                                             */
                p_key,               /* msg data (security key), can be NULL                          */
                securityKeyLength);  /* msg data length (will be 0 if p_securityKey is NULL)          */
    
    /* wait for mgmt response, free after it comes in, don't need data bytes */
    WaitForMgmtResponse(WF_CP_SET_ELEMENT_SUBTYPE, FREE_MGMT_BUFFER);

    p_wifi_ConfigData->SecurityMode = securityType;
    p_wifi_ConfigData->SecurityKeyLength = securityKeyLength;
    memcpy(p_wifi_ConfigData->SecurityKey,p_securityKey,securityKeyLength);
}   
Example #20
0
/*******************************************************************************
  Function:    
    void WF_CPSetSecurity(UINT8 CpId, 
                          UINT8 securityType,
                          UINT8 wepKeyIndex,
                          UINT8 *p_securityKey,
                          UINT8 securityKeyLength)

  Summary:
    Sets the security for the specified Connection Profile.

  Description:
    Configures security for a Connection Profile.

    <table>
    Security                                Key         Length
    --------                                ---         ------
    WF_SECURITY_OPEN                        N/A         N/A
    WF_SECURITY_WEP_40                      hex         4, 5 byte keys
    WF_SECURITY_WEP_104                     hex         4, 13 byte keys
    WF_SECURITY_WPA_WITH_KEY                hex         32 bytes
    WF_SECURITY_WPA_WITH_PASS_PHRASE        ascii       8-63 ascii characters
    WF_SECURITY_WPA2_WITH_KEY               hex         32 bytes
    WF_SECURITY_WPA2_WITH_PASS_PHRASE       ascii       8-63 ascii characters
    WF_SECURITY_WPA_AUTO_WITH_KEY           hex         32 bytes
    WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE   ascii       8-63 ascii characters
    WF_SECURITY_WPS_PUSH_BUTTON 
    WF_SECURITY_WPS_PIN   
    WF_SECURITY_WPA2_ENTERPRISE
    </table>

  Precondition:
    MACInit must be called first.

  Parameters:
    CpId - Connection Profile ID
    securityType - Value corresponding to the security type desired.
    wepKeyIndex - Only index 0 is valid. (Applicable for WF_SECURITY_WEP_40 or
                   WF_SECURITY_WEP_104)
    p_securityKey - Binary key or passphrase (not used if security is 
                     WF_SECURITY_OPEN)
    securityKeyLength - Number of bytes in p_securityKey (not used if security
                         is WF_SECURITY_OPEN)

  Returns:
    None.
      
  Remarks:
    None.
  *****************************************************************************/
void WF_CPSetSecurity(UINT8 CpId, 
                      UINT8 securityType,
                      UINT8 wepKeyIndex,
                      UINT8 *p_securityKey,
                      UINT8 securityKeyLength)
{
    UINT8  hdrBuf[7];
    UINT8  *p_key;

    /* Write out header portion of msg */
    hdrBuf[0] = WF_MGMT_REQUEST_TYPE;           /* indicate this is a mgmt msg     */
    hdrBuf[1] = WF_CP_SET_ELEMENT_SUBTYPE;      /* mgmt request subtype            */     
    hdrBuf[2] = CpId;                           /* Connection Profile ID           */
    hdrBuf[3] = WF_CP_ELEMENT_SECURITY;         /* Element ID                      */
    
    /* Next to header bytes are really part of data, but need to put them in header      */
    /* bytes in order to prepend to security key                                         */
    hdrBuf[5] = securityType;                   
    hdrBuf[6] = wepKeyIndex;                     
    
    /* if security is open (no key) or WPS push button or WPA2 enterprise method */
    if (securityType == WF_SECURITY_OPEN 
        || securityType == WF_SECURITY_WPS_PUSH_BUTTON
        || securityType == WF_SECURITY_WPA2_ENTERPRISE)
    {
        hdrBuf[4]         = 2;      /* Only data is security type and wep index */ 
        p_key             = NULL;   
        securityKeyLength = 0;    

    } 
    /* else security is selected, so need to send key */   
    else
    {
        hdrBuf[4] = 2 + securityKeyLength;  /* data is security type + wep index + key */
        p_key     = p_securityKey;       
    }    
    
    SendMgmtMsg(hdrBuf,              /* msg header which includes the security type and WEP index)    */
                sizeof(hdrBuf),      /* msg header length                                             */
                p_key,               /* msg data (security key), can be NULL                          */
                securityKeyLength);  /* msg data length (will be 0 if p_securityKey is NULL)          */
    
    /* wait for mgmt response, free after it comes in, don't need data bytes */
    WaitForMgmtResponse(WF_CP_SET_ELEMENT_SUBTYPE, FREE_MGMT_BUFFER);
}   
void WF_CMConnectWicom(UINT8 CpId, tWFConnectParams *connParams)
{
   UINT8  hdrBuf[4];

    /* 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] = CpId;
    hdrBuf[3] = 0;  

    SendMgmtMsg(hdrBuf,
                sizeof(hdrBuf),
                (UINT8 *)connParams,
                sizeof(tWFConnectParams));

    /* wait for mgmt response, free after it comes in, don't need data bytes */
    WaitForMgmtResponse(WF_CM_CONNECT_SUBYTPE, FREE_MGMT_BUFFER);
}
/*******************************************************************************
  Function:
    void WF_CMConnect(uint8_t CpId)

  Summary:
    Commands the MRF24W 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-PSK/WPA2-PSK security
    and is using a passphrase, the connection manager will first calculate the PSK,
	and then start the connection process. Convert of passphrase to PSK can take up
    to 32 seconds in MRF24WB and 25 seconds in MRF24WG.

  Precondition:
    MACInit must be called first.

  Parameters:
    CpId - If this value is equal to an existing Connection Profile ID then
            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_CMConnect(uint8_t CpId)
{
    uint8_t  hdrBuf[4];

    /* 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] = CpId;
    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);
}
/*******************************************************************************
  Function:
    static void CPElementSet(uint8_t elementId,
                             uint8_t *p_elementData,
                             uint8_t elementDataLength)

  Summary:
    Set an element of the connection profile on the MRF24W.

  Description:
    All Connection Profile 'Set 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 set.
    p_elementData - Pointer to element data.
    elementDataLength - Number of bytes pointed to by p_elementData.

  Returns:
    None.

  Remarks:
    None.
 *******************************************************************************/
static void CPElementSet(uint8_t elementId,
                         uint8_t *p_elementData,
                         uint8_t elementDataLength)
{
    uint8_t hdrBuf[5];

    /* Write out header portion of msg. */
    hdrBuf[0] = WF_MGMT_REQUEST_TYPE;      /* indicate this is a mgmt msg     */
    hdrBuf[1] = WF_CP_SET_ELEMENT_SUBTYPE; /* MGMT Request Subtype            */
    hdrBuf[2] = CPID;                      /* Connection Profile ID           */
    hdrBuf[3] = elementId;                 /* Element ID                      */
    hdrBuf[4] = elementDataLength;         /* number of bytes of element data */

    SendMgmtMsg(hdrBuf, sizeof(hdrBuf), p_elementData, elementDataLength);  

    /* wait for mgmt response, free after it comes in, don't need data bytes */
    WaitForMgmtResponse(WF_CP_SET_ELEMENT_SUBTYPE, FREE_MGMT_BUFFER);
}
/*******************************************************************************
  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 */
}    
Example #25
0
/*******************************************************************************
  Function:	
    void SendSetParamMsg(UINT8 paramType, 
                         UINT8 *p_paramData, 
                         UINT8 paramDataLength)

  Summary:
    Sends a SetParam Mgmt request to MRF24WB0M and waits for response.

  Description:
    Index Set Param Request
    ----- -----------------
    0     type            (always 0x02 signifying a mgmt request)
    1     subtype         (always 0x10 signifying a Set 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)
    4     payload[0]      first byte of param data
    N     payload[n]      Nth byte of payload data
            
    Index  Set 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)

  Precondition:
  	MACInit must be called first.

  Parameters:
    paramType - Parameter type associated with the SetParam msg.
    p_paramData - pointer to parameter data
    paramDataLength - Number of bytes pointed to by p_paramData

  Returns:
  	None.
  	
  Remarks:
  	None.
  *****************************************************************************/
void SendSetParamMsg(UINT8 paramType, 
                     UINT8 *p_paramData, 
                     UINT8 paramDataLength)
{
    UINT8 hdr[4];
    
    hdr[0] = WF_MGMT_REQUEST_TYPE;
    hdr[1] = WF_SET_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    */
                p_paramData,       /* param data        */
                paramDataLength);  /* param data length */

   	/* wait for MRF24WB0M management response; free response because not needed */
	WaitForMgmtResponse(WF_SET_PARAM_SUBTYPE, FREE_MGMT_BUFFER); 
}    
Example #26
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:
    static void LowLevel_CASetElement(uint8_t elementId,
                                      uint8_t *p_elementData,
                                      uint8_t elementDataLength)

  Summary:
    Set an element of the connection algorithm on the MRF24W.

  Description:
    Low-level function to send the appropriate management message to the
    MRF24W to set the Connection Algorithm element.

  Precondition:
    MACInit must be called first.

  Parameters:
    elementId - Element that is being set
    p_elementData - Pointer to element data
    elementDataLength - Number of bytes pointed to by p_elementData

  Returns:
    None.

  Remarks:
    All Connection Algorithm 'Set Element' functions call this function
    to construct the management message.  The caller must fix up any endian
    issues prior to calling this function.
 *****************************************************************************/
static void LowLevel_CASetElement(uint8_t elementId,
                                  uint8_t *p_elementData,
                                  uint8_t elementDataLength)
{
    uint8_t  hdrBuf[4];

    hdrBuf[0] = WF_MGMT_REQUEST_TYPE;           /* indicate this is a mgmt msg     */
    hdrBuf[1] = WF_CA_SET_ELEMENT_SUBTYPE;      /* mgmt request subtype            */
    hdrBuf[2] = elementId;                      /* Element ID                      */
    hdrBuf[3] = elementDataLength;              /* number of bytes of element data */

    SendMgmtMsg(hdrBuf,
                sizeof(hdrBuf),
                p_elementData,
                elementDataLength);

    /* wait for mgmt response, free after it comes in, don't need data bytes */
    WaitForMgmtResponse(WF_CA_SET_ELEMENT_SUBTYPE, FREE_MGMT_BUFFER);
}
/*******************************************************************************
  Function:
    void SetSecurity(uint8_t securityType,
                     uint8_t *p_securityKey,
                     uint8_t securityKeyLength)

  Summary:
    Sets the security.

  Description:
    Configures security.

    <table>
    Security                                      Key         Length
    --------                                      ---         ------
    DRV_WIFI_SECURITY_OPEN                        N/A         N/A
    DRV_WIFI_SECURITY_WEP_40                      hex         4, 5 byte keys
    DRV_WIFI_SECURITY_WEP_104                     hex         4, 13 byte keys
    DRV_WIFI_SECURITY_WPA_AUTO_WITH_KEY           hex         32 bytes
    DRV_WIFI_SECURITY_WPA_AUTO_WITH_PASS_PHRASE   ascii       8-63 ascii characters
    DRV_WIFI_SECURITY_WPA_WITH_KEY                hex         32 bytes
    DRV_WIFI_SECURITY_WPA_WITH_PASS_PHRASE        ascii       8-63 ascii characters
    DRV_WIFI_SECURITY_WPA2_WITH_KEY               hex         32 bytes
    DRV_WIFI_SECURITY_WPA2_WITH_PASS_PHRASE       ascii       8-63 ascii characters
    </table>

  Precondition:
    MACInit must be called first.

  Parameters:
    securityType - Value corresponding to the security type desired.
    p_securityKey - Binary key or passphrase (not used if security is
                     DRV_WIFI_SECURITY_OPEN).
    securityKeyLength - Number of bytes in p_securityKey (not used if security
                         is DRV_WIFI_SECURITY_OPEN).

  Returns:
    None.

  Remarks:
    None.
 *******************************************************************************/
static void SetSecurity(uint8_t securityType,
                        uint8_t *p_securityKey,
                        uint8_t securityKeyLength)
{
    uint8_t hdrBuf[7];
    uint8_t *p_key;

    /* write out header portion of msg */
    hdrBuf[0] = WF_MGMT_REQUEST_TYPE;      /* indicate this is a mgmt msg     */
    hdrBuf[1] = WF_CP_SET_ELEMENT_SUBTYPE; /* MGMT Request Subtype            */
    hdrBuf[2] = CPID;                      /* Connection Profile ID           */
    hdrBuf[3] = WF_CP_ELEMENT_SECURITY;    /* Element ID                      */

    /* Next to header bytes are really part of data, but need to put them in header */
    /* bytes in order to prepend to security key.                                   */
    hdrBuf[5] = securityType;
    hdrBuf[6] = 0; /* only support wep key index 0 */

    /* if security is open (no key) or WPS push button method */
    if (securityType == DRV_WIFI_SECURITY_OPEN ||
        securityType == DRV_WIFI_SECURITY_WPS_PUSH_BUTTON)
    {
        hdrBuf[4] = 2; /* only data is security type and wep index */
        p_key = NULL;
        securityKeyLength = 0;
    }
    /* else security is selected, so need to send key */
    else
    {
        hdrBuf[4] = 2 + securityKeyLength; /* data is security type + wep index + key */
        p_key = p_securityKey;
    }

    SendMgmtMsg(hdrBuf, sizeof(hdrBuf), p_key, securityKeyLength); 

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

    DRV_WIFI_CONFIG_PARAMS(securityMode) = securityType;
    DRV_WIFI_CONFIG_PARAMS(securityKeyLen) = securityKeyLength;
    memcpy(DRV_WIFI_CONFIG_PARAMS(securityKey), p_securityKey, securityKeyLength);
}
/*******************************************************************************
  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                 */
}    
void WF_CPSetPMK(UINT8 CpId, UINT8 *pmk)
{
    UINT8  hdrBuf[5];
    UINT8  *p_key;

    /* Write out header portion of msg */
    hdrBuf[0] = WF_MGMT_REQUEST_TYPE;           /* indicate this is a mgmt msg     */
    hdrBuf[1] = WF_CP_SET_ELEMENT_SUBTYPE;      /* mgmt request subtype            */     
    hdrBuf[2] = CpId;                           /* Connection Profile ID           */
    hdrBuf[3] = WF_CP_ELEMENT_UPDATE_PMK;         /* Element ID                      */
  	hdrBuf[4] = 32;      /* pmk length */ 

    SendMgmtMsg(hdrBuf,              /* msg header which includes the security type and WEP index)    */
                sizeof(hdrBuf),      /* msg header length                                             */
                pmk,               /* msg data (security key), can be NULL                          */
                32);  /* msg data length (will be 0 if p_securityKey is NULL)          */

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