Creating Wireless Ad Hoc Access Point
Some applications may need to create a wireless ad hoc access point that can be accessed by other devices. Wireless ad hoc access points can be created by calling the NetIF_WiFi_CreateAdhoc()
API function with the necessary parameters. See
NetIF_WiFi_CreateAP
for more information.
A call to NetIF_WiFi_CreateAdhoc()
is shown below:
Listing - Call to NetIF_WiFi_CreateAdhoc()
NET_ERR err; ap_ctn = NetIF_WiFi_CreateAdhoc(if_nbr, (1) NET_IF_WIFI_DATA_RATE_AUTO, (2) NET_IF_WIFI_SECURITY_WEP, (3) NET_IF_WIFI_PWR_LEVEL_HI, (4) NET_IF_WIFI_CH_1 (5) "adhoc_ssid", (6) "adhoc_password", (7) &err); (8)
NetIF_WiFi_CreateAdhoc()
requires eight arguments. The first argument is the interface number, which is acquired upon successfully adding and starting the interface.- The second argument is the data rate used on the wireless network.
- The third argument is the wireless security type of the wireless network.
- The fourth argument is the radio power level used to communicate on the wireless network.
- The fifth argument is the wireless channel for the ad hoc network.
- The sixth argument is a pointer to a string that contains the SSID of the wireless access point.
- The seventh argument is a pointer to a string that contains the pre-shared key of the wireless access point.
- The last argument is a pointer to a
NET_ERR
that contains the return error code. The return error variable will contain the valueNET_IF_WIFI_ERR_NONE
if the create process has been completed successfully.
If an error occurs, you should always inspect the return error code and take the appropriate action. There are very few things that could cause a failure to create an ad hoc network properly. Once the error is resolved, the application may again attempt to call NetIF_WiFi_CreateAdhoc()
.