2 * Espressif Systems Wireless LAN device driver
4 * Copyright (C) 2015-2021 Espressif Systems (Shanghai) PTE LTD
6 * This software file (the "File") is distributed by Espressif Systems (Shanghai)
7 * PTE LTD under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
23 #include "platform_wrapper.h"
26 #define SSID_LENGTH 32
33 #define STATION_MODE_MAC_ADDRESS "1a:11:11:11:11:11"
34 #define STATION_MODE_SSID "MyWifi"
35 #define STATION_MODE_PWD "MyWifiPass@123"
36 #define STATION_MODE_BSSID ""
37 #define STATION_MODE_IS_WPA3_SUPPORTED false
38 #define STATION_MODE_LISTEN_INTERVAL 5
41 #define SOFTAP_MODE_MAC_ADDRESS "1a:22:22:22:22:22"
42 #define SOFTAP_MODE_SSID "ESPWifi"
43 #define SOFTAP_MODE_PWD "ESPWifi@123"
44 #define SOFTAP_MODE_CHANNEL 1
45 #define SOFTAP_MODE_ENCRYPTION_MODE 3
46 #define SOFTAP_MODE_MAX_ALLOWED_CLIENTS 4
47 #define SOFTAP_MODE_SSID_HIDDEN false
48 #define SOFTAP_MODE_BANDWIDTH 2
50 #define TEST_DEBUG_PRINTS 1
53 static void test_get_wifi_mode()
56 int ret = wifi_get_mode(&mode);
57 printf("==== %s =>\n",__func__);
59 printf("wifi mode is %d \n",mode);
61 printf("Failed to get wifi mode \n");
66 static int test_set_wifi_mode(int mode)
69 ret = wifi_set_mode(mode);
70 #ifdef TEST_DEBUG_PRINTS
71 printf("==== %s =>\n",__func__);
73 printf("wifi mode is %d \n", mode);
75 printf("error in setting mode \n");
82 static int test_set_wifi_mode_none()
84 return test_set_wifi_mode(WIFI_MODE_NONE);
87 static int test_set_wifi_mode_station()
89 return test_set_wifi_mode(WIFI_MODE_STA);
92 static int test_set_wifi_mode_softap()
94 return test_set_wifi_mode(WIFI_MODE_AP);
97 static int test_set_wifi_mode_station_softap()
99 return test_set_wifi_mode(WIFI_MODE_APSTA);
102 static void test_station_mode_get_mac_addr()
104 char mac[MAC_LENGTH] = "";
106 printf("==== %s =>\n",__func__);
107 ret = wifi_get_mac(WIFI_MODE_STA, mac);
108 if (ret == SUCCESS) {
109 printf("Station mode: mac address %s \n", mac);
111 printf("Failed to get station mode MAC address \n");
116 static int test_station_mode_set_mac_addr_of_esp()
119 char mac[MAC_LENGTH] = STATION_MODE_MAC_ADDRESS;
120 ret = wifi_set_mac(WIFI_MODE_STA, mac);
121 #ifdef TEST_DEBUG_PRINTS
122 printf("==== %s =>\n",__func__);
123 if (ret == SUCCESS) {
124 printf("MAC address is set \n");
126 printf("MAC address is not set \n");
134 static int test_softap_mode_set_mac_addr_of_esp()
137 char mac[MAC_LENGTH] = SOFTAP_MODE_MAC_ADDRESS;
138 ret = wifi_set_mac(WIFI_MODE_AP, mac);
139 #ifdef TEST_DEBUG_PRINTS
140 printf("==== %s =>\n",__func__);
141 if (ret == SUCCESS) {
142 printf("MAC address is set \n");
144 printf("MAC address is not set \n");
152 static void test_softap_mode_get_mac_addr()
154 char mac[MAC_LENGTH] = "";
155 int ret = wifi_get_mac(WIFI_MODE_AP, mac);
156 printf("==== %s =>\n",__func__);
157 if (ret == SUCCESS) {
158 printf("Softap mode: mac address %s \n", mac);
160 printf("Failed to get softap mode MAC address \n");
165 static int test_station_mode_connect()
168 esp_hosted_control_config_t config = {0};
170 strcpy((char *)&config.station.ssid , STATION_MODE_SSID);
171 strcpy((char *)&config.station.pwd , STATION_MODE_PWD);
172 strcpy((char *)&config.station.bssid, STATION_MODE_BSSID);
173 config.station.is_wpa3_supported = STATION_MODE_IS_WPA3_SUPPORTED;
174 config.station.listen_interval = STATION_MODE_LISTEN_INTERVAL;
176 ret = wifi_set_ap_config(config);
177 #ifdef TEST_DEBUG_PRINTS
178 printf("==== %s =>\n",__func__);
179 if (ret == SUCCESS) {
180 printf("Connected to AP \n");
182 printf("Failed to connect with AP \n");
189 static int test_station_mode_get_info()
192 esp_hosted_control_config_t config = {0};
194 printf("==== %s =>\n",__func__);
195 ret = wifi_get_ap_config(&config);
196 if (ret == SUCCESS) {
197 printf("AP's ssid %s \n", config.station.ssid);
198 printf("AP's bssid i.e. MAC address %s \n", config.station.bssid);
199 printf("AP's channel number %d \n", config.station.channel);
200 printf("AP's rssi %d \n", config.station.rssi);
201 printf("AP's encryption mode %d \n", config.station.encryption_mode);
203 printf("AP's status %s \n", config.station.status);
210 static void test_get_available_wifi()
213 esp_hosted_wifi_scanlist_t *list = NULL;
215 printf("==== %s =>\n",__func__);
216 list = wifi_ap_scan_list(&count);
218 printf("No AP found \n");
220 printf("Failed to get scanned AP list \n");
222 printf("Number of available APs is %d \n", count);
223 for (int i=0; i<count; i++) {
224 printf("%d th AP's ssid \"%s\" bssid \"%s\" rssi \"%d\" channel \"%d\" authentication mode \"%d\" \n",i, list[i].ssid, list[i].bssid, list[i].rssi, list[i].channel, list[i].encryption_mode);
228 esp_hosted_free(list);
234 static int test_station_mode_disconnect()
236 int ret = wifi_disconnect_ap();
237 #ifdef TEST_DEBUG_PRINTS
238 printf("==== %s =>\n",__func__);
239 if (ret == SUCCESS) {
240 printf("Disconnected from AP \n");
242 printf("Failed to disconnect from AP \n");
250 static int test_softap_mode_start()
253 esp_hosted_control_config_t config = {0};
255 strcpy((char *)&config.softap.ssid, SOFTAP_MODE_SSID);
256 strcpy((char *)&config.softap.pwd, SOFTAP_MODE_PWD);
257 config.softap.channel = SOFTAP_MODE_CHANNEL;
258 config.softap.encryption_mode = SOFTAP_MODE_ENCRYPTION_MODE;
259 config.softap.max_connections = SOFTAP_MODE_MAX_ALLOWED_CLIENTS;
260 config.softap.ssid_hidden = SOFTAP_MODE_SSID_HIDDEN;
261 config.softap.bandwidth = SOFTAP_MODE_BANDWIDTH;
263 ret = wifi_set_softap_config(config);
264 #ifdef TEST_DEBUG_PRINTS
265 printf("==== %s =>\n",__func__);
266 if (ret == SUCCESS) {
267 printf("esp32 softAP started \n");
269 printf("Failed to set softAP config \n");
276 static int test_softap_mode_get_info()
278 esp_hosted_control_config_t config = {0};
279 int ret = wifi_get_softap_config(&config);
280 printf("==== %s =>\n",__func__);
281 if (ret == SUCCESS) {
282 printf("softAP ssid %s \n", config.softap.ssid);
283 printf("softAP pwd %s \n", config.softap.pwd);
284 printf("softAP channel ID %d \n", config.softap.channel);
285 printf("softAP encryption mode %d \n", config.softap.encryption_mode);
286 printf("softAP max connections %d \n", config.softap.max_connections);
287 printf("softAP ssid broadcast status %d \n", config.softap.ssid_hidden);
288 printf("softAP bandwidth mode %d \n", config.softap.bandwidth);
290 printf("Failed to get softAP config \n");
297 static void test_softap_mode_connected_clients_info()
300 esp_hosted_wifi_connected_stations_list *stations_list = NULL;
302 printf("==== %s =>\n",__func__);
303 stations_list = wifi_connected_stations_list(&count);
305 printf("No station found \n");
306 } else if (!stations_list) {
307 printf("Failed to get connected stations list \n");
309 for (int i=0; i<count; i++) {
310 printf("%d th stations's bssid \"%s\" rssi \"%d\" \n",i, stations_list[i].bssid, stations_list[i].rssi);
314 esp_hosted_free(stations_list);
315 stations_list = NULL;
320 static int test_softap_mode_stop()
322 int ret = wifi_stop_softap();
323 #ifdef TEST_DEBUG_PRINTS
324 printf("==== %s =>\n",__func__);
325 if (ret == SUCCESS) {
326 printf("ESP32 softAP stopped \n");
328 printf("Failed to stop ESP32 softAP \n");
337 static int test_set_wifi_power_save_mode()
339 int power_save_mode = WIFI_PS_MIN_MODEM;
340 int ret = wifi_set_power_save_mode(power_save_mode);
342 #ifdef TEST_DEBUG_PRINTS
343 printf("==== %s =>\n",__func__);
344 if (ret == SUCCESS) {
345 printf("Power save mode set \n");
347 printf("Power save mode is not set \n");
355 static int test_get_wifi_power_save_mode()
357 int power_save_mode = WIFI_PS_MIN_MODEM;
358 int ret = wifi_get_power_save_mode(&power_save_mode);
359 #ifdef TEST_DEBUG_PRINTS
360 printf("==== %s =>\n",__func__);
361 if (ret == SUCCESS) {
362 printf("Power save mode is %d \n", power_save_mode);
364 printf("Failed to get power save mode \n");
374 /* Below APIs could be used by demo application */
375 test_set_wifi_mode_none();
377 test_get_wifi_mode();
379 test_get_available_wifi();
383 test_set_wifi_mode_station();
385 test_station_mode_set_mac_addr_of_esp();
387 test_station_mode_get_mac_addr();
389 test_station_mode_connect();
391 test_station_mode_get_info();
393 test_station_mode_disconnect();
397 test_set_wifi_mode_softap();
399 test_softap_mode_set_mac_addr_of_esp();
401 test_softap_mode_get_mac_addr();
403 test_softap_mode_start();
405 test_softap_mode_get_info();
407 test_softap_mode_connected_clients_info();
409 test_softap_mode_stop();
411 /* station + softap mode*/
413 test_set_wifi_mode_station_softap();
415 test_station_mode_connect();
417 test_softap_mode_start();
419 test_station_mode_get_info();
421 test_softap_mode_get_info();
423 test_station_mode_disconnect();
425 test_softap_mode_stop();
427 /* power save mode */
429 test_set_wifi_power_save_mode();
431 test_get_wifi_power_save_mode();