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.
22 #include <sys/types.h>
26 #include <sys/socket.h>
27 #include <sys/ioctl.h>
30 #include <linux/if_arp.h>
33 #include "ctrl_config.h"
36 /***** Please Read *****/
37 /* Before use : User must enter user configuration parameter in "ctrl_config.h" file */
39 #define STA_INTERFACE "ethsta0"
40 #define AP_INTERFACE "ethap0"
42 #define WIFI_VENDOR_IE_ELEMENT_ID 0xDD
44 #define VENDOR_OUI_0 1
45 #define VENDOR_OUI_1 2
46 #define VENDOR_OUI_2 3
47 #define VENDOR_OUI_TYPE 22
49 #define CTRL_CMD_DEFAULT_REQ() { \
50 .msg_type = CTRL_REQ, \
51 .ctrl_resp_cb = NULL, \
52 .cmd_timeout_sec = DEFAULT_CTRL_RESP_TIMEOUT /*30 sec*/ \
55 #define CLEANUP_CTRL_MSG(msg) do { \
57 if (msg->free_buffer_handle) { \
58 if (msg->free_buffer_func) { \
59 msg->free_buffer_func(msg->free_buffer_handle); \
60 msg->free_buffer_handle = NULL; \
70 #define MIN_TIMESTAMP_STR_SIZE 30
75 } event_callback_table_t;
77 static char * get_timestamp(char *str, uint16_t str_size)
79 if (str && str_size>=MIN_TIMESTAMP_STR_SIZE) {
80 time_t t = time(NULL);
81 struct tm tm = *localtime(&t);
82 sprintf(str, "%d-%02d-%02d %02d:%02d:%02d > ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
88 static int ctrl_app_event_callback(ctrl_cmd_t * app_event)
90 char ts[MIN_TIMESTAMP_STR_SIZE] = {'\0'};
92 if (!app_event || (app_event->msg_type != CTRL_EVENT)) {
94 printf("Msg type is not event[%u]\n",app_event->msg_type);
98 if ((app_event->msg_id <= CTRL_EVENT_BASE) ||
99 (app_event->msg_id >= CTRL_EVENT_MAX)) {
100 printf("Event Msg ID[%u] is not correct\n",app_event->msg_id);
104 switch(app_event->msg_id) {
106 case CTRL_EVENT_ESP_INIT: {
107 printf("%s App EVENT: ESP INIT\n",
108 get_timestamp(ts, MIN_TIMESTAMP_STR_SIZE));
110 } case CTRL_EVENT_HEARTBEAT: {
111 printf("%s App EVENT: Heartbeat event [%d]\n",
112 get_timestamp(ts, MIN_TIMESTAMP_STR_SIZE),
113 app_event->u.e_heartbeat.hb_num);
115 } case CTRL_EVENT_STATION_DISCONNECT_FROM_AP: {
116 printf("%s App EVENT: Station mode: Disconnect Reason[%u]\n",
117 get_timestamp(ts, MIN_TIMESTAMP_STR_SIZE), app_event->resp_event_status);
119 } case CTRL_EVENT_STATION_DISCONNECT_FROM_ESP_SOFTAP: {
120 char *p = app_event->u.e_sta_disconnected.mac;
121 if (p && strlen(p)) {
122 printf("%s App EVENT: SoftAP mode: Disconnect MAC[%s]\n",
123 get_timestamp(ts, MIN_TIMESTAMP_STR_SIZE), p);
127 printf("%s Invalid event[%u] to parse\n",
128 get_timestamp(ts, MIN_TIMESTAMP_STR_SIZE), app_event->msg_id);
132 CLEANUP_CTRL_MSG(app_event);
136 CLEANUP_CTRL_MSG(app_event);
140 static void process_failed_responses(ctrl_cmd_t *app_msg)
142 uint8_t request_failed_flag = true;
144 /* Identify general issue, common for all control requests */
145 switch (app_msg->resp_event_status) {
146 case CTRL_ERR_REQ_IN_PROG:
147 printf("Error reported: Command In progress, Please wait\n");
149 case CTRL_ERR_REQUEST_TIMEOUT:
150 printf("Error reported: Response Timeout\n");
152 case CTRL_ERR_MEMORY_FAILURE:
153 printf("Error reported: Memory allocation failed\n");
155 case CTRL_ERR_UNSUPPORTED_MSG:
156 printf("Error reported: Unsupported control msg\n");
158 case CTRL_ERR_INCORRECT_ARG:
159 printf("Error reported: Invalid or out of range parameter values\n");
161 case CTRL_ERR_PROTOBUF_ENCODE:
162 printf("Error reported: Protobuf encode failed\n");
164 case CTRL_ERR_PROTOBUF_DECODE:
165 printf("Error reported: Protobuf decode failed\n");
167 case CTRL_ERR_SET_ASYNC_CB:
168 printf("Error reported: Failed to set aync callback\n");
170 case CTRL_ERR_TRANSPORT_SEND:
171 printf("Error reported: Problem while sending data on serial driver\n");
174 request_failed_flag = false;
178 /* if control request failed, no need to proceed for response checking */
179 if (request_failed_flag)
182 /* Identify control request specific issue */
183 switch (app_msg->msg_id) {
185 case CTRL_RESP_OTA_END:
186 case CTRL_RESP_OTA_BEGIN:
187 case CTRL_RESP_OTA_WRITE: {
188 /* intentional fallthrough */
189 printf("OTA procedure failed\n");
191 } case CTRL_RESP_CONNECT_AP: {
192 if (app_msg->resp_event_status == CTRL_ERR_NO_AP_FOUND) {
193 printf("SSID: not found/connectable\n");
194 } else if (app_msg->resp_event_status ==
195 CTRL_ERR_INVALID_PASSWORD) {
196 printf("Invalid password for SSID\n");
198 printf("Failed to connect with AP \n");
201 } case CTRL_RESP_START_SOFTAP: {
202 printf("Failed to start SoftAP\n");
205 case CTRL_RESP_STOP_SOFTAP:
206 case CTRL_RESP_GET_SOFTAP_CONFIG: {
207 printf("Possibly softap is not running/started\n");
210 printf("Failed Control Response\n");
216 static int process_resp_disconnect_ap(ctrl_cmd_t * app_msg)
218 int ret = SUCCESS, sockfd = 0;
220 ret = create_socket(AF_INET, SOCK_DGRAM, IPPROTO_IP, &sockfd);
222 printf("Failure to open socket\n");
226 ret = interface_down(sockfd, STA_INTERFACE);
227 if (ret == SUCCESS) {
228 printf("%s interface down\n", STA_INTERFACE);
230 printf("Unable to down %s interface\n", STA_INTERFACE);
234 ret = close_socket(sockfd);
236 printf("Failure to close socket\n");
243 ret = close_socket(sockfd);
245 printf("Failure to close socket\n");
250 static int process_resp_connect_ap(ctrl_cmd_t * app_msg)
252 int ret = SUCCESS, sockfd = 0;
254 if (!strlen(app_msg->u.wifi_ap_config.out_mac)) {
255 printf("Failure: station mac is empty\n");
259 ret = create_socket(AF_INET, SOCK_DGRAM, IPPROTO_IP, &sockfd);
261 printf("Failure to open socket\n");
265 ret = interface_down(sockfd, STA_INTERFACE);
266 if (ret == SUCCESS) {
267 printf("%s interface down\n", STA_INTERFACE);
269 printf("Unable to down %s interface\n", STA_INTERFACE);
273 ret = set_hw_addr(sockfd, STA_INTERFACE, app_msg->u.wifi_ap_config.out_mac);
274 if (ret == SUCCESS) {
275 printf("MAC address %s set to %s interface\n",
276 app_msg->u.wifi_ap_config.out_mac, STA_INTERFACE);
278 printf("Unable to set MAC address to %s interface\n", STA_INTERFACE);
282 ret = interface_up(sockfd, STA_INTERFACE);
283 if (ret == SUCCESS) {
284 printf("%s interface up\n", STA_INTERFACE);
286 printf("Unable to up %s interface\n", STA_INTERFACE);
290 ret = close_socket(sockfd);
292 printf("Failure to close socket\n");
298 ret = close_socket(sockfd);
300 printf("Failure to close socket\n");
305 static int process_resp_stop_softap(ctrl_cmd_t * app_msg)
307 int ret = SUCCESS, sockfd = 0;
309 ret = create_socket(AF_INET, SOCK_DGRAM, IPPROTO_IP, &sockfd);
311 printf("Failure to open socket\n");
315 ret = interface_down(sockfd, AP_INTERFACE);
316 if (ret == SUCCESS) {
317 printf("%s interface down\n", AP_INTERFACE);
319 printf("Unable to down %s interface\n", AP_INTERFACE);
323 ret = close_socket(sockfd);
325 printf("Failure to close socket\n");
331 ret = close_socket(sockfd);
333 printf("Failure to close socket\n");
338 static int process_resp_start_softap(ctrl_cmd_t * app_msg)
340 int ret = SUCCESS, sockfd = 0;
342 if (!strlen(app_msg->u.wifi_softap_config.out_mac)) {
343 printf("Failure: softap mac is empty\n");
347 ret = create_socket(AF_INET, SOCK_DGRAM, IPPROTO_IP, &sockfd);
349 printf("Failure to open socket\n");
353 ret = interface_down(sockfd, AP_INTERFACE);
354 if (ret == SUCCESS) {
355 printf("%s interface down\n", AP_INTERFACE);
357 printf("Unable to down %s interface\n", AP_INTERFACE);
361 ret = set_hw_addr(sockfd, AP_INTERFACE, app_msg->u.wifi_softap_config.out_mac);
362 if (ret == SUCCESS) {
363 printf("MAC address %s set to %s interface\n",
364 app_msg->u.wifi_softap_config.out_mac, AP_INTERFACE);
366 printf("Unable to set MAC address to %s interface\n", AP_INTERFACE);
370 ret = interface_up(sockfd, AP_INTERFACE);
371 if (ret == SUCCESS) {
372 printf("%s interface up\n", AP_INTERFACE);
374 printf("Unable to up %s interface\n", AP_INTERFACE);
378 ret = close_socket(sockfd);
380 printf("Failure to close socket\n");
386 ret = close_socket(sockfd);
388 printf("Failure to close socket\n");
394 int unregister_event_callbacks(void)
398 for (evt=CTRL_EVENT_BASE+1; evt<CTRL_EVENT_MAX; evt++) {
399 if (CALLBACK_SET_SUCCESS != reset_event_callback(evt) ) {
400 printf("reset event callback failed for event[%u]\n", evt);
407 int register_event_callbacks(void)
412 event_callback_table_t events[] = {
413 { CTRL_EVENT_ESP_INIT, ctrl_app_event_callback },
414 { CTRL_EVENT_HEARTBEAT, ctrl_app_event_callback },
415 { CTRL_EVENT_STATION_DISCONNECT_FROM_AP, ctrl_app_event_callback },
416 { CTRL_EVENT_STATION_DISCONNECT_FROM_ESP_SOFTAP, ctrl_app_event_callback },
419 for (evt=0; evt<sizeof(events)/sizeof(event_callback_table_t); evt++) {
420 if (CALLBACK_SET_SUCCESS != set_event_callback(events[evt].event, events[evt].fun) ) {
421 printf("event callback register failed for event[%u]\n", events[evt].event);
430 int ctrl_app_resp_callback(ctrl_cmd_t * app_resp)
433 if (!app_resp || (app_resp->msg_type != CTRL_RESP)) {
435 printf("Msg type is not response[%u]\n",app_resp->msg_type);
439 if ((app_resp->msg_id <= CTRL_RESP_BASE) || (app_resp->msg_id >= CTRL_RESP_MAX)) {
440 printf("Response Msg ID[%u] is not correct\n",app_resp->msg_id);
444 if (app_resp->resp_event_status != SUCCESS) {
445 process_failed_responses(app_resp);
449 switch(app_resp->msg_id) {
451 case CTRL_RESP_GET_MAC_ADDR: {
452 printf("mac address is %s\n", app_resp->u.wifi_mac.mac);
454 } case CTRL_RESP_SET_MAC_ADDRESS : {
455 printf("MAC address is set\n");
457 } case CTRL_RESP_GET_WIFI_MODE : {
458 printf("wifi mode is : ");
459 switch (app_resp->u.wifi_mode.mode) {
460 case WIFI_MODE_STA: printf("station\n"); break;
461 case WIFI_MODE_AP: printf("softap\n"); break;
462 case WIFI_MODE_APSTA: printf("station+softap\n"); break;
463 case WIFI_MODE_NONE: printf("none"); break;
464 default: printf("unknown\n"); break;
467 } case CTRL_RESP_SET_WIFI_MODE : {
468 printf("wifi mode is set\n");
470 } case CTRL_RESP_GET_AP_SCAN_LIST : {
471 wifi_ap_scan_list_t * w_scan_p = &app_resp->u.wifi_ap_scan;
472 wifi_scanlist_t *list = w_scan_p->out_list;
474 if (!w_scan_p->count) {
475 printf("No AP found \n");
479 printf("Failed to get scanned AP list \n");
483 printf("Number of available APs is %d \n", w_scan_p->count);
484 for (i=0; i<w_scan_p->count; i++) {
485 printf("%d) ssid \"%s\" bssid \"%s\" rssi \"%d\" channel \"%d\" auth mode \"%d\" \n",\
486 i, list[i].ssid, list[i].bssid, list[i].rssi,
487 list[i].channel, list[i].encryption_mode);
491 } case CTRL_RESP_GET_AP_CONFIG : {
492 wifi_ap_config_t *p = &app_resp->u.wifi_ap_config;
493 if (0 == strncmp(SUCCESS_STR, p->status, strlen(SUCCESS_STR))) {
494 printf("AP's ssid '%s'\n", p->ssid);
495 printf("AP's bssid i.e. MAC address %s\n", p->bssid);
496 printf("AP's channel number %d\n", p->channel);
497 printf("AP's rssi %d\n", p->rssi);
498 printf("AP's encryption mode %d\n", p->encryption_mode);
500 printf("Station mode status: %s\n",p->status);
503 } case CTRL_RESP_CONNECT_AP : {
504 if (process_resp_connect_ap(app_resp))
507 } case CTRL_RESP_DISCONNECT_AP : {
508 printf("Disconnected from AP \n");
509 if (process_resp_disconnect_ap(app_resp))
512 } case CTRL_RESP_GET_SOFTAP_CONFIG : {
513 softap_config_t * resp_p = &app_resp->u.wifi_softap_config;
515 printf("softAP ssid %s \n", resp_p->ssid);
516 printf("softAP pwd %s \n", resp_p->pwd);
517 printf("softAP channel ID %d \n", resp_p->channel);
518 printf("softAP encryption mode %d \n", resp_p->encryption_mode);
519 printf("softAP max connections %d \n", resp_p->max_connections);
520 printf("softAP ssid broadcast status %d \n", resp_p->ssid_hidden);
521 printf("softAP bandwidth mode %d \n", resp_p->bandwidth);
524 } case CTRL_RESP_SET_SOFTAP_VND_IE : {
525 printf("Success in set vendor specific ie\n");
527 } case CTRL_RESP_START_SOFTAP : {
528 printf("esp32 softAP started \n");
529 if (process_resp_start_softap(app_resp))
532 } case CTRL_RESP_GET_SOFTAP_CONN_STA_LIST : {
533 int count = app_resp->u.wifi_softap_con_sta.count;
534 wifi_connected_stations_list_t *stations_list =
535 app_resp->u.wifi_softap_con_sta.out_list;
537 printf("sta list count: %u\n",count);
539 printf("No station found \n");
543 if (!stations_list) {
544 printf("Failed to get connected stations list \n");
546 for (i=0; i<count; i++) {
547 printf("%d th stations's bssid \"%s\" rssi \"%d\" \n",i, \
548 stations_list[i].bssid, stations_list[i].rssi);
552 } case CTRL_RESP_STOP_SOFTAP : {
553 printf("esp32 softAP stopped\n");
554 if (process_resp_stop_softap(app_resp))
557 } case CTRL_RESP_SET_PS_MODE : {
558 printf("Wifi power save mode set\n");
560 } case CTRL_RESP_GET_PS_MODE : {
561 printf("Wifi power save mode is: ");
563 switch(app_resp->u.wifi_ps.ps_mode) {
564 case WIFI_PS_MIN_MODEM:
567 case WIFI_PS_MAX_MODEM:
575 } case CTRL_RESP_OTA_BEGIN : {
576 printf("OTA begin success\n");
578 } case CTRL_RESP_OTA_WRITE : {
579 printf("OTA write success\n");
581 } case CTRL_RESP_OTA_END : {
582 printf("OTA end success\n");
584 } case CTRL_RESP_SET_WIFI_MAX_TX_POWER: {
585 printf("Set wifi max tx power success\n");
587 } case CTRL_RESP_GET_WIFI_CURR_TX_POWER: {
588 printf("wifi curr tx power : %d\n",
589 app_resp->u.wifi_tx_power.power);
591 } case CTRL_RESP_CONFIG_HEARTBEAT: {
592 printf("Heartbeat operation successful\n");
595 printf("Invalid Response[%u] to parse\n", app_resp->msg_id);
601 CLEANUP_CTRL_MSG(app_resp);
605 CLEANUP_CTRL_MSG(app_resp);
609 int test_get_wifi_mode(void)
611 /* implemented Asynchronous */
612 ctrl_cmd_t req = CTRL_CMD_DEFAULT_REQ();
614 /* register callback for reply */
615 req.ctrl_resp_cb = ctrl_app_resp_callback;
623 int test_set_wifi_mode(int mode)
625 /* implemented synchronous */
626 ctrl_cmd_t req = CTRL_CMD_DEFAULT_REQ();
627 ctrl_cmd_t *resp = NULL;
629 req.u.wifi_mode.mode = mode;
630 resp = wifi_set_mode(req);
632 return ctrl_app_resp_callback(resp);
635 int test_set_wifi_mode_station(void)
637 return test_set_wifi_mode(WIFI_MODE_STA);
640 int test_set_wifi_mode_softap(void)
642 return test_set_wifi_mode(WIFI_MODE_AP);
645 int test_set_wifi_mode_station_softap(void)
647 return test_set_wifi_mode(WIFI_MODE_APSTA);
650 int test_set_wifi_mode_none(void)
652 return test_set_wifi_mode(WIFI_MODE_NONE);
655 int test_get_wifi_mac_addr(int mode)
657 /* implemented synchronous */
658 ctrl_cmd_t req = CTRL_CMD_DEFAULT_REQ();
659 ctrl_cmd_t *resp = NULL;
661 req.u.wifi_mac.mode = mode;
662 resp = wifi_get_mac(req);
664 return ctrl_app_resp_callback(resp);
667 int test_station_mode_get_mac_addr(void)
669 return test_get_wifi_mac_addr(WIFI_MODE_STA);
672 int test_set_mac_addr(int mode, char *mac)
674 /* implemented synchronous */
675 ctrl_cmd_t req = CTRL_CMD_DEFAULT_REQ();
676 ctrl_cmd_t *resp = NULL;
678 int ret = test_set_wifi_mode(mode);
679 if (ret == SUCCESS) {
680 req.u.wifi_mac.mode = mode;
681 strncpy(req.u.wifi_mac.mac, mac, MAX_MAC_STR_LEN);
682 req.u.wifi_mac.mac[MAX_MAC_STR_LEN-1] = '\0';
684 resp = wifi_set_mac(req);
685 return ctrl_app_resp_callback(resp);
690 int test_station_mode_set_mac_addr_of_esp(void)
692 return test_set_mac_addr(WIFI_MODE_STA, STATION_MODE_MAC_ADDRESS);
695 int test_softap_mode_set_mac_addr_of_esp(void)
697 return test_set_mac_addr(WIFI_MODE_STA, SOFTAP_MODE_MAC_ADDRESS);
700 int test_softap_mode_get_mac_addr(void)
702 return test_get_wifi_mac_addr(WIFI_MODE_AP);
705 int test_station_mode_connect(void)
707 /* implemented Asynchronous */
708 ctrl_cmd_t req = CTRL_CMD_DEFAULT_REQ();
710 strcpy((char *)&req.u.wifi_ap_config.ssid, STATION_MODE_SSID);
711 strcpy((char *)&req.u.wifi_ap_config.pwd, STATION_MODE_PWD);
712 strcpy((char *)&req.u.wifi_ap_config.bssid, STATION_MODE_BSSID);
713 req.u.wifi_ap_config.is_wpa3_supported = STATION_MODE_IS_WPA3_SUPPORTED;
714 req.u.wifi_ap_config.listen_interval = STATION_MODE_LISTEN_INTERVAL;
716 /* register callback for handling reply asynch-ly */
717 req.ctrl_resp_cb = ctrl_app_resp_callback;
719 wifi_connect_ap(req);
724 int test_station_mode_get_info(void)
726 /* implemented synchronous */
727 ctrl_cmd_t req = CTRL_CMD_DEFAULT_REQ();
728 ctrl_cmd_t *resp = NULL;
730 resp = wifi_get_ap_config(req);
732 return ctrl_app_resp_callback(resp);
735 int test_get_available_wifi(void)
737 /* implemented synchronous */
738 ctrl_cmd_t req = CTRL_CMD_DEFAULT_REQ();
739 ctrl_cmd_t *resp = NULL;
741 resp = wifi_ap_scan_list(req);
743 return ctrl_app_resp_callback(resp);
746 int test_station_mode_disconnect(void)
748 /* implemented synchronous */
749 ctrl_cmd_t req = CTRL_CMD_DEFAULT_REQ();
750 ctrl_cmd_t *resp = NULL;
752 resp = wifi_disconnect_ap(req);
754 return ctrl_app_resp_callback(resp);
757 int test_softap_mode_start(void)
759 /* implemented synchronous */
760 ctrl_cmd_t req = CTRL_CMD_DEFAULT_REQ();
761 ctrl_cmd_t *resp = NULL;
763 strncpy((char *)&req.u.wifi_softap_config.ssid,
764 SOFTAP_MODE_SSID, MAX_MAC_STR_LEN-1);
765 strncpy((char *)&req.u.wifi_softap_config.pwd,
766 SOFTAP_MODE_PWD, MAX_MAC_STR_LEN-1);
767 req.u.wifi_softap_config.channel = SOFTAP_MODE_CHANNEL;
768 req.u.wifi_softap_config.encryption_mode = SOFTAP_MODE_ENCRYPTION_MODE;
769 req.u.wifi_softap_config.max_connections = SOFTAP_MODE_MAX_ALLOWED_CLIENTS;
770 req.u.wifi_softap_config.ssid_hidden = SOFTAP_MODE_SSID_HIDDEN;
771 req.u.wifi_softap_config.bandwidth = SOFTAP_MODE_BANDWIDTH;
773 resp = wifi_start_softap(req);
775 return ctrl_app_resp_callback(resp);
778 int test_softap_mode_get_info(void)
780 /* implemented synchronous */
781 ctrl_cmd_t req = CTRL_CMD_DEFAULT_REQ();
782 ctrl_cmd_t *resp = NULL;
784 resp = wifi_get_softap_config(req);
786 return ctrl_app_resp_callback(resp);
789 int test_softap_mode_connected_clients_info(void)
791 /* implemented synchronous */
792 ctrl_cmd_t req = CTRL_CMD_DEFAULT_REQ();
793 ctrl_cmd_t *resp = NULL;
795 resp = wifi_get_softap_connected_station_list(req);
797 return ctrl_app_resp_callback(resp);
800 int test_softap_mode_stop(void)
802 /* implemented synchronous */
803 ctrl_cmd_t req = CTRL_CMD_DEFAULT_REQ();
804 ctrl_cmd_t *resp = NULL;
806 resp = wifi_stop_softap(req);
808 return ctrl_app_resp_callback(resp);
811 int test_set_wifi_power_save_mode(int psmode)
813 /* implemented synchronous */
814 ctrl_cmd_t req = CTRL_CMD_DEFAULT_REQ();
815 ctrl_cmd_t *resp = NULL;
817 req.u.wifi_ps.ps_mode = psmode;
818 resp = wifi_set_power_save_mode(req);
820 return ctrl_app_resp_callback(resp);
823 int test_set_wifi_power_save_mode_max(void)
825 return test_set_wifi_power_save_mode(WIFI_PS_MAX_MODEM);
828 int test_set_wifi_power_save_mode_min(void)
830 return test_set_wifi_power_save_mode(WIFI_PS_MIN_MODEM);
833 int test_get_wifi_power_save_mode(void)
835 /* implemented synchronous */
836 ctrl_cmd_t req = CTRL_CMD_DEFAULT_REQ();
837 ctrl_cmd_t *resp = NULL;
839 resp = wifi_get_power_save_mode(req);
841 return ctrl_app_resp_callback(resp);
844 int test_reset_vendor_specific_ie(void)
846 /* implemented synchronous */
847 ctrl_cmd_t req = CTRL_CMD_DEFAULT_REQ();
848 ctrl_cmd_t *resp = NULL;
849 char *data = "Example vendor IE data";
851 char *v_data = (char*)calloc(1, strlen(data));
853 printf("Failed to allocate memory \n");
856 memcpy(v_data, data, strlen(data));
858 req.u.wifi_softap_vendor_ie.enable = false;
859 req.u.wifi_softap_vendor_ie.type = WIFI_VND_IE_TYPE_BEACON;
860 req.u.wifi_softap_vendor_ie.idx = WIFI_VND_IE_ID_0;
861 req.u.wifi_softap_vendor_ie.vnd_ie.element_id = WIFI_VENDOR_IE_ELEMENT_ID;
862 req.u.wifi_softap_vendor_ie.vnd_ie.length = strlen(data)+OFFSET;
863 req.u.wifi_softap_vendor_ie.vnd_ie.vendor_oui[0] = VENDOR_OUI_0;
864 req.u.wifi_softap_vendor_ie.vnd_ie.vendor_oui[1] = VENDOR_OUI_1;
865 req.u.wifi_softap_vendor_ie.vnd_ie.vendor_oui[2] = VENDOR_OUI_2;
866 req.u.wifi_softap_vendor_ie.vnd_ie.vendor_oui_type = VENDOR_OUI_TYPE;
867 req.u.wifi_softap_vendor_ie.vnd_ie.payload = (uint8_t *)v_data;
868 req.u.wifi_softap_vendor_ie.vnd_ie.payload_len = strlen(data);
870 req.free_buffer_func = free;
871 req.free_buffer_handle = v_data;
873 resp = wifi_set_vendor_specific_ie(req);
875 return ctrl_app_resp_callback(resp);
877 void free_hook(void *ptr)
880 printf("Freeing 0x%p\n",ptr);
886 int test_set_vendor_specific_ie(void)
888 /* implemented synchronous */
889 ctrl_cmd_t req = CTRL_CMD_DEFAULT_REQ();
890 ctrl_cmd_t *resp = NULL;
891 char *data = "Example vendor IE data";
893 char *v_data = (char*)calloc(1, strlen(data));
895 printf("Failed to allocate memory \n");
898 memcpy(v_data, data, strlen(data));
900 req.u.wifi_softap_vendor_ie.enable = true;
901 req.u.wifi_softap_vendor_ie.type = WIFI_VND_IE_TYPE_BEACON;
902 req.u.wifi_softap_vendor_ie.idx = WIFI_VND_IE_ID_0;
903 req.u.wifi_softap_vendor_ie.vnd_ie.element_id = WIFI_VENDOR_IE_ELEMENT_ID;
904 req.u.wifi_softap_vendor_ie.vnd_ie.length = strlen(data)+OFFSET;
905 req.u.wifi_softap_vendor_ie.vnd_ie.vendor_oui[0] = VENDOR_OUI_0;
906 req.u.wifi_softap_vendor_ie.vnd_ie.vendor_oui[1] = VENDOR_OUI_1;
907 req.u.wifi_softap_vendor_ie.vnd_ie.vendor_oui[2] = VENDOR_OUI_2;
908 req.u.wifi_softap_vendor_ie.vnd_ie.vendor_oui_type = VENDOR_OUI_TYPE;
909 req.u.wifi_softap_vendor_ie.vnd_ie.payload = (uint8_t *)v_data;
910 req.u.wifi_softap_vendor_ie.vnd_ie.payload_len = strlen(data);
912 req.free_buffer_func = free_hook;
913 req.free_buffer_handle = v_data;
915 resp = wifi_set_vendor_specific_ie(req);
917 return ctrl_app_resp_callback(resp);
920 int test_ota_begin(void)
922 /* implemented synchronous */
923 ctrl_cmd_t req = CTRL_CMD_DEFAULT_REQ();
924 ctrl_cmd_t *resp = NULL;
926 resp = ota_begin(req);
928 return ctrl_app_resp_callback(resp);
931 int test_ota_write(uint8_t* ota_data, uint32_t ota_data_len)
933 /* implemented synchronous */
934 ctrl_cmd_t req = CTRL_CMD_DEFAULT_REQ();
935 ctrl_cmd_t *resp = NULL;
937 req.u.ota_write.ota_data = ota_data;
938 req.u.ota_write.ota_data_len = ota_data_len;
940 resp = ota_write(req);
942 return ctrl_app_resp_callback(resp);
945 int test_ota_end(void)
947 /* implemented synchronous */
948 ctrl_cmd_t req = CTRL_CMD_DEFAULT_REQ();
949 ctrl_cmd_t *resp = NULL;
953 return ctrl_app_resp_callback(resp);
956 int test_ota(char* image_path)
959 char ota_chunk[CHUNK_SIZE] = {0};
960 int ret = test_ota_begin();
961 if (ret == SUCCESS) {
962 f = fopen(image_path,"rb");
964 printf("Failed to open file %s \n", image_path);
967 printf("Success in opening %s file \n", image_path);
970 fread(&ota_chunk, CHUNK_SIZE, 1, f);
971 ret = test_ota_write((uint8_t* )&ota_chunk, CHUNK_SIZE);
973 printf("OTA procedure failed!!\n");
978 ret = test_ota_end();
985 printf("ESP32 will restart after 5 sec\n");
989 int test_wifi_set_max_tx_power(int in_power)
991 /* implemented synchronous */
992 ctrl_cmd_t req = CTRL_CMD_DEFAULT_REQ();
993 ctrl_cmd_t *resp = NULL;
995 req.u.wifi_tx_power.power = in_power;
996 resp = wifi_set_max_tx_power(req);
998 return ctrl_app_resp_callback(resp);
1001 int test_wifi_get_curr_tx_power()
1003 /* implemented synchronous */
1004 ctrl_cmd_t req = CTRL_CMD_DEFAULT_REQ();
1005 ctrl_cmd_t *resp = NULL;
1007 resp = wifi_get_curr_tx_power(req);
1009 return ctrl_app_resp_callback(resp);
1012 int test_config_heartbeat(void)
1014 /* implemented synchronous */
1015 ctrl_cmd_t *resp = NULL;
1016 ctrl_cmd_t req = CTRL_CMD_DEFAULT_REQ();
1017 req.u.e_heartbeat.enable = YES;
1018 req.u.e_heartbeat.duration = HEARTBEAT_DURATION_SEC;
1020 resp = config_heartbeat(req);
1022 return ctrl_app_resp_callback(resp);
1025 int test_disable_heartbeat(void)
1027 /* implemented synchronous */
1028 ctrl_cmd_t *resp = NULL;
1029 ctrl_cmd_t req = CTRL_CMD_DEFAULT_REQ();
1030 req.u.e_heartbeat.enable = NO;
1032 resp = config_heartbeat(req);
1034 return ctrl_app_resp_callback(resp);