예제 #1
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;
}
예제 #2
0
/*******************************************************************************
  Function:
    uint16_t WF_Scan(uint8_t 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.

    MRF24WB0M & MRF24WG0M support up to max of 60 scan results (SSIDs).

  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:
    Host scan is allowed only in idle or connected state.
    If MRF24W FW is in the midst of connection ( or reconnection) process, then
    host scan can hammer connection process, and furthermore it may cause
    fatal failure in MRF24W FW operation. To use host scan, we strongly
    recommend the user to disable MRF24W FW connection manager by enabling
    #define DISABLE_MODULE_FW_CONNECT_MANAGER_IN_INFRASTRUCTURE
    in drv_wifi_config.h
  *****************************************************************************/
uint16_t WF_Scan(uint8_t CpId)
{
    uint8_t   hdr[4];
#ifndef MRF24WG
    uint8_t   connectionState;
    uint8_t   dummy;
#endif

    /* 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 drv_wifi_config.h
    */
    if (!WF_CMIsHostScanAllowed())
        return WF_ERROR_OPERATION_CANCELLED;

#ifndef MRF24WG
    WF_CMGetConnectionState(&connectionState, &dummy);
    if (connectionState == WF_CSTATE_NOT_CONNECTED)
        WF_CMConnect(0xff); /* 120c host scan bug workaround */
#endif

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