Scanning for a Wireless Access Point

When a wireless network interface is started, it becomes an active interface that is not yet capable of transmitting and receiving data since no operational link to a network medium is configured. The first step to join a network to have an operational link is the scan operation which consists of finding the wireless networks available in the range of the wireless module.

A wireless network interface should be able to scan any time after the network interface has been successfully started. A successful call to NetIF_WiFi_Scan() returns the wireless networks available to join which can be joined by the wireless network interface. See NetIF_WiFi_Scan for more information.

You can scan for a wireless network by calling the NetIF_WiFi_Scan() API function with the necessary parameters. A call to NetIF_WiFi_Scan() is shown below.

Listing - Calling NetIF_WiFi_Scan()
NET_IF_WIFI_AP  ap_buf[NB_AP_MAX]
CPU_INT16U      ap_ctn;
NET_ERR         err;

ap_ctn = NetIF_WiFi_Scan(if_nbr,             (1)
                         ap_buf,             (2)
                         NB_AP_MAX,          (3)
                         0,                  (4)
                         NET_IF_WIFI_CH_ALL, (5)
                        &err);               (6)
  1. NetIF_WiFi_Scan() requires six arguments. The first function argument is the interface number that the application wants to scan with. The interface number is acquired upon successful addition of the interface and upon the successful start of the interface.
  2. The second argument is a pointer to a wireless access point buffer that contains the wireless network found in the range of the interface.
  3. The third argument is the number of wireless access points that can be contained in the wireless access point buffer.
  4. The fourth argument is a pointer to a string that contains the SSID of any hidden wireless access points to find.
  5. The fifth argument is the wireless channel to scan.
  6. The last argument is a pointer to a NET_ERR to contain the return error code. The return error variable will contain the value NET_IF_WIFI_ERR_NONE if the scan process has been completed successfully.

There are very few things that could cause a network interface to not scan properly. The application developer should always inspect the return error code and take the appropriate action if an error occurs. Once the error is resolved, the application may again attempt to call NetIF_WiFi_Scan().