qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1 | /**@File lib_wifi6.c |
| 2 | * @Brief :about function test |
| 3 | * @details : |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4 | * @Author : you.chen |
| 5 | * @Date : 2022-4-6 |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 6 | * @Version : V1.0 |
| 7 | * @copy ritght : Copyright (c) MobileTek |
| 8 | */ |
| 9 | #include <log/log.h> |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 10 | #include <stdio.h> |
| 11 | #include <sys/types.h> |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 12 | #include <stdlib.h> |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 13 | #include <string.h> |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 14 | #include "libwifi6.h" |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 15 | #include <wpa_ctrl.h> |
| 16 | #include <string.h> |
| 17 | #include <time.h> |
| 18 | #include <pthread.h> |
| 19 | #include <sys/socket.h> |
| 20 | #include <netinet/in.h> |
| 21 | #include <arpa/inet.h> |
| 22 | #include <netdb.h> |
| 23 | #include <ifaddrs.h> |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 24 | |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 25 | #ifdef __cplusplus |
| 26 | extern "C" { |
| 27 | #endif |
| 28 | #ifdef __cplusplus |
| 29 | } |
| 30 | #endif |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 31 | |
| 32 | #define MAX_CMD 128 |
| 33 | #define MAX_RET 4096 |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 34 | #define MODE_LEN 10 |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 35 | #define CTRL_STA 0 |
| 36 | #define CTRL_AP 1 |
| 37 | #define AP_NETWORK_0 0 |
| 38 | |
| 39 | pthread_t g_ap_watcher_pid = 0; |
| 40 | volatile int g_ap_watcher_stop_flag = 0; |
you.chen | a6fa5b2 | 2022-05-18 10:28:19 +0800 | [diff] [blame^] | 41 | volatile int g_ap_watcher_started_flag = 0; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 42 | |
| 43 | pthread_t g_sta_watcher_pid = 0; |
| 44 | volatile int g_sta_watcher_stop_flag = 0; |
| 45 | volatile int g_sta_scan_finish_flag = 0; |
you.chen | a6fa5b2 | 2022-05-18 10:28:19 +0800 | [diff] [blame^] | 46 | volatile int g_sta_watcher_started_flag = 0; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 47 | |
| 48 | void * g_ap_callback_priv = NULL; |
| 49 | AP_CALLBACK_FUNC_PTR g_ap_callback_func = NULL; |
| 50 | void * g_sta_callback_priv = NULL; |
| 51 | STA_CALLBACK_FUNC_PTR g_sta_callback_func = NULL; |
| 52 | |
| 53 | //const char * CTRL_PATH="/var/run/wpa_supplicant"; |
| 54 | const char * CTRL_PATH[2] = {"/var/run/wpa_supplicant/wlan0", "/var/run/wpa_supplicant/ap0"}; |
| 55 | //const char * CTRL_PATH[2] = {"/var/run/wpa_supplicant/wlan0", "/var/run/wpa_supplicant/wlan0"}; |
| 56 | const char * cmd_list_networks = "LIST_NETWORKS"; |
| 57 | const char * cmd_save_config = "SAVE_CONFIG"; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 58 | const char * cmd_disconnect = "DISCONNECT"; |
| 59 | const char * cmd_remove_all = "REMOVE_NETWORK all"; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 60 | const char * state_scan_result = "CTRL-EVENT-SCAN-RESULTS"; |
| 61 | |
| 62 | static struct wpa_ctrl * g_lynq_wpa_ctrl[2] = {0}; |
| 63 | |
| 64 | |
| 65 | typedef struct __curr_status_info { |
| 66 | ap_info_s *ap; |
| 67 | char * state; |
| 68 | int net_no; |
| 69 | }curr_status_info; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 70 | |
| 71 | #define PRINT_AND_RETURN_VALUE(str,value) \ |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 72 | {\ |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 73 | perror((str));\ |
| 74 | return (value);\ |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 75 | } |
| 76 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 77 | #define CHECK_IDX(idx, type) do { \ |
| 78 | if ( (idx == LYNQ_WIFI_INTERFACE_0 && type != CTRL_STA) || (idx == LYNQ_WIFI_INTERFACE_1 && type != CTRL_AP) \ |
| 79 | || idx < LYNQ_WIFI_INTERFACE_0 || idx > LYNQ_WIFI_INTERFACE_1 ) { \ |
| 80 | printf("not support create [%s] on interface [%d]\n", (type == CTRL_STA ? "station" : "ap"), idx); \ |
| 81 | return -1; \ |
| 82 | } \ |
| 83 | }while (0) |
| 84 | |
| 85 | #define CHECK_WPA_CTRL(index) int ret = 0;\ |
| 86 | size_t reply_len = MAX_RET; \ |
| 87 | char cmd_reply[MAX_RET]={0}; \ |
| 88 | struct wpa_ctrl *lynq_wpa_ctrl = NULL; \ |
| 89 | do{ \ |
| 90 | if (NULL == g_lynq_wpa_ctrl[index]) { \ |
| 91 | g_lynq_wpa_ctrl[index] = wpa_ctrl_open(CTRL_PATH[index]); \ |
| 92 | if (NULL == g_lynq_wpa_ctrl[index]) { \ |
| 93 | printf("wpa_ctrl_open fail\n"); \ |
| 94 | return -1; \ |
| 95 | } \ |
| 96 | } \ |
| 97 | lynq_wpa_ctrl = g_lynq_wpa_ctrl[index]; \ |
| 98 | }while(0) |
| 99 | |
| 100 | #define DO_REQUEST(cmd_str) do { \ |
| 101 | reply_len = MAX_RET;\ |
| 102 | cmd_reply[0] = '\0'; \ |
| 103 | printf("to call [%s]\n", cmd_str); \ |
| 104 | ret = wpa_ctrl_request(lynq_wpa_ctrl, cmd_str, strlen(cmd_str), cmd_reply, &reply_len, NULL); \ |
| 105 | if (ret != 0) { \ |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 106 | printf("call "#cmd_str" fail %d\n", ret); \ |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 107 | return ret; \ |
| 108 | } \ |
| 109 | cmd_reply[reply_len+1] = '\0'; \ |
| 110 | printf("cmd replay [ %s ]\n", cmd_reply); \ |
| 111 | }while(0) |
| 112 | |
| 113 | #define DO_OK_FAIL_REQUEST(cmd_str) do { \ |
| 114 | DO_REQUEST(cmd_str); \ |
| 115 | if (reply_len >=4 && memcmp(cmd_reply, "FAIL", 4) == 0 ) {\ |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 116 | printf("cmd "#cmd_str" return FAIL\n"); \ |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 117 | return -1; \ |
| 118 | } else if (reply_len >=2 && memcmp(cmd_reply, "OK", 2) != 0) { \ |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 119 | printf("cmd "#cmd_str" return not OK|FAIL\n"); \ |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 120 | return -1; \ |
| 121 | } \ |
| 122 | }while (0) |
| 123 | |
| 124 | |
| 125 | |
| 126 | static void APWatcherThreadProc() { |
| 127 | size_t len = MAX_RET; |
| 128 | char msg_notify[MAX_RET]; |
| 129 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 130 | struct wpa_ctrl *lynq_wpa_ctrl = NULL; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 131 | |
| 132 | while (g_ap_watcher_stop_flag == 0) { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 133 | if (lynq_wpa_ctrl == NULL) { |
| 134 | lynq_wpa_ctrl = wpa_ctrl_open(CTRL_PATH[CTRL_AP]); //@todo temp change |
| 135 | if (lynq_wpa_ctrl == NULL) { |
| 136 | usleep(100*1000); |
| 137 | continue; |
| 138 | } |
| 139 | |
| 140 | wpa_ctrl_attach(lynq_wpa_ctrl); |
you.chen | a6fa5b2 | 2022-05-18 10:28:19 +0800 | [diff] [blame^] | 141 | g_ap_watcher_started_flag = 1; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 142 | } |
| 143 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 144 | if ( 0 == wpa_ctrl_pending(lynq_wpa_ctrl)) { |
| 145 | usleep(100*1000); |
| 146 | continue; |
| 147 | } |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 148 | memset(msg_notify, 0, MAX_RET); |
| 149 | len = MAX_RET; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 150 | if (!wpa_ctrl_recv(lynq_wpa_ctrl, msg_notify, &len)) { |
| 151 | msg_notify[len+1] = '\0'; |
| 152 | printf("ap------> %s\n", msg_notify); |
| 153 | if (g_ap_callback_func == NULL) { |
| 154 | continue; |
| 155 | } |
| 156 | if (strstr(msg_notify, "AP-STA-DISCONNECTED") != NULL) { |
| 157 | g_ap_callback_func(g_ap_callback_priv, LYNQ_WIFI_STATUS_DISCONNECT); |
| 158 | } |
| 159 | else if (strstr(msg_notify, "AP-STA-CONNECTED") != NULL) { |
| 160 | g_ap_callback_func(g_ap_callback_priv, LYNQ_WIFI_STATUS_CONNECT); |
| 161 | } |
| 162 | } // end if (!wpa_ctrl_recv(lynq_wpa_ctrl, msg_notify, &len)) |
| 163 | } // end while (g_ap_watcher_stop_flag == 0) |
| 164 | wpa_ctrl_detach(lynq_wpa_ctrl); |
| 165 | wpa_ctrl_close(lynq_wpa_ctrl); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 166 | } |
| 167 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 168 | static void STAWatcherThreadProc() { |
| 169 | size_t len = MAX_RET; |
| 170 | char msg_notify[MAX_RET]; |
| 171 | char *pReason; |
| 172 | error_number_s error; |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 173 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 174 | struct wpa_ctrl *lynq_wpa_ctrl = NULL; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 175 | |
| 176 | while (g_sta_watcher_stop_flag == 0) { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 177 | if (lynq_wpa_ctrl == NULL) { |
| 178 | lynq_wpa_ctrl = wpa_ctrl_open(CTRL_PATH[CTRL_STA]); |
| 179 | if (lynq_wpa_ctrl == NULL) { |
| 180 | usleep(100*1000); |
| 181 | continue; |
| 182 | } |
| 183 | |
| 184 | wpa_ctrl_attach(lynq_wpa_ctrl); |
you.chen | a6fa5b2 | 2022-05-18 10:28:19 +0800 | [diff] [blame^] | 185 | g_sta_watcher_started_flag = 1; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 186 | } |
| 187 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 188 | if ( 0 == wpa_ctrl_pending(lynq_wpa_ctrl)) { |
| 189 | usleep(100*1000); |
| 190 | continue; |
| 191 | } |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 192 | memset(msg_notify, 0, MAX_RET); |
| 193 | len = MAX_RET; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 194 | if (!wpa_ctrl_recv(lynq_wpa_ctrl, msg_notify, &len)) { |
| 195 | msg_notify[len+1] = '\0'; |
| 196 | printf("sta ------> %s\n", msg_notify); |
| 197 | if (strstr(msg_notify, state_scan_result) != NULL) { |
| 198 | g_sta_scan_finish_flag = 1; |
| 199 | } |
| 200 | |
| 201 | if (g_sta_callback_func == NULL) { |
| 202 | continue; |
| 203 | } |
| 204 | error = -1; |
| 205 | if (strstr(msg_notify, "CTRL-EVENT-SCAN-RESULTS") != NULL) { |
| 206 | g_sta_callback_func(g_ap_callback_priv, LYNQ_WIFI_STA_STATUS_SCAN_RESULT, error); |
| 207 | } |
| 208 | else if (strstr(msg_notify, "CTRL-EVENT-CONNECTED") != NULL) { |
| 209 | g_sta_callback_func(g_ap_callback_priv, LYNQ_WIFI_STA_STATUS_CONNECT, error); |
| 210 | } |
| 211 | else if (strstr(msg_notify, "CTRL-EVENT-SSID-TEMP-DISABLED") != NULL) { |
| 212 | pReason = strstr(msg_notify, "reason="); |
| 213 | if (pReason != NULL) { |
| 214 | pReason += strlen("reason="); |
| 215 | if (memcpy(pReason, "CONN_FAILED", 11) == 0) { |
| 216 | error = LYNQ_TIME_OUT; |
| 217 | } |
| 218 | else if (memcpy(pReason, "WRONG_KEY", 9) == 0) { |
| 219 | error = LYNQ_PSW_ERROR; |
| 220 | } |
| 221 | g_sta_callback_func(g_ap_callback_priv, LYNQ_WIFI_STA_STATUS_DISCONNECT, error); |
| 222 | } |
| 223 | } |
| 224 | else if (strstr(msg_notify, "CTRL-EVENT-DISCONNECTED") != NULL) { |
| 225 | g_sta_callback_func(g_ap_callback_priv, LYNQ_WIFI_STA_STATUS_DISCONNECT, error); |
| 226 | } |
| 227 | else if (strstr(msg_notify, "CTRL-EVENT-NETWORK-NOT-FOUND") != NULL) { |
| 228 | g_sta_callback_func(g_ap_callback_priv, LYNQ_WIFI_STA_STATUS_DISCONNECT, LYNQ_NOT_FIND_AP); |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | wpa_ctrl_detach(lynq_wpa_ctrl); |
| 233 | wpa_ctrl_close(lynq_wpa_ctrl); |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 234 | } |
| 235 | |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 236 | int lynq_wifi_enable(void) |
| 237 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 238 | int ret = 0; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 239 | int i; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 240 | const char * cmd_check_service = |
| 241 | "state=`systemctl is-active wg870_drv_insmod.service`\n" |
| 242 | "[ \"\"$state == \"active\" ] && exit 0\n" |
| 243 | "[ \"\"$state == \"inactive\" ] && systemctl start wg870_drv_insmod.service\n"; |
| 244 | // if (g_lynq_wpa_ctrl[0] != NULL && g_lynq_wpa_ctrl[1] != NULL) { |
| 245 | // return 0; |
| 246 | // } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 247 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 248 | ret = system(cmd_check_service); |
| 249 | if (ret != 0) { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 250 | printf("service state %d\n", ret); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 251 | return -1; |
| 252 | } |
| 253 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 254 | for (i=0; i<10; i++) { |
you.chen | a6fa5b2 | 2022-05-18 10:28:19 +0800 | [diff] [blame^] | 255 | if (system("connmanctl technologies | grep -q \"/net/connman/technology/wifi\"") == 0) { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 256 | break; |
| 257 | } |
| 258 | usleep(300*1000); |
| 259 | } |
| 260 | |
| 261 | if (i >= 10) { |
| 262 | return -1; |
| 263 | } |
| 264 | |
you.chen | a6fa5b2 | 2022-05-18 10:28:19 +0800 | [diff] [blame^] | 265 | if (0 != system("ifconfig | grep -q ap0")) { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 266 | system("connmanctl enable wifi"); |
you.chen | a6fa5b2 | 2022-05-18 10:28:19 +0800 | [diff] [blame^] | 267 | usleep(300*1000); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 268 | system("wpa_cli -iwpa_wlan0_cmd -p/var/run/ IFNAME=wlan0 DRIVER interface_create ap0"); |
you.chen | a6fa5b2 | 2022-05-18 10:28:19 +0800 | [diff] [blame^] | 269 | usleep(300*1000); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 270 | system("connmanctl tether wifi on lynq 1qaz@WSX#$%^"); |
you.chen | a6fa5b2 | 2022-05-18 10:28:19 +0800 | [diff] [blame^] | 271 | usleep(300*1000); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 272 | } |
| 273 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 274 | if (g_ap_watcher_pid == 0 ) { |
| 275 | ret=pthread_create(&g_ap_watcher_pid,NULL,APWatcherThreadProc,NULL); |
| 276 | if(ret<0){ |
| 277 | return -1; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | if (g_sta_watcher_pid == 0 ) { |
| 282 | ret=pthread_create(&g_sta_watcher_pid,NULL,STAWatcherThreadProc,NULL); |
| 283 | if(ret<0){ |
| 284 | return -1; |
| 285 | } |
| 286 | } |
| 287 | |
you.chen | a6fa5b2 | 2022-05-18 10:28:19 +0800 | [diff] [blame^] | 288 | for (i=0; i<10; i++) { |
| 289 | usleep(300*1000); |
| 290 | if (g_ap_watcher_started_flag == 1 && g_sta_watcher_started_flag == 1) { |
| 291 | break; |
| 292 | } |
| 293 | } |
| 294 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 295 | return ret; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 296 | } |
| 297 | |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 298 | int lynq_wifi_disable(void) |
| 299 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 300 | g_ap_watcher_stop_flag = 1; |
| 301 | g_sta_watcher_stop_flag = 1; |
| 302 | if (g_ap_watcher_pid != 0) |
| 303 | pthread_join(g_ap_watcher_pid, NULL); |
| 304 | if (g_sta_watcher_pid != 0) |
| 305 | pthread_join(g_sta_watcher_pid, NULL); |
| 306 | if (g_lynq_wpa_ctrl[0] != NULL) |
| 307 | wpa_ctrl_close(g_lynq_wpa_ctrl[0]); |
| 308 | if (g_lynq_wpa_ctrl[1] != NULL) |
| 309 | wpa_ctrl_close(g_lynq_wpa_ctrl[1]); |
| 310 | g_ap_watcher_pid = 0; |
| 311 | g_sta_watcher_pid = 0; |
| 312 | g_lynq_wpa_ctrl[0] = NULL; |
| 313 | g_lynq_wpa_ctrl[1] = NULL; |
| 314 | system("systemctl stop wg870_drv_insmod.service"); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 315 | return 0; |
| 316 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 317 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 318 | static int inner_get_param(int interface, int net_no, char* param_name, char * out_put) { |
| 319 | |
| 320 | char lynq_cmd_get[128]={0}; |
| 321 | |
| 322 | if (out_put == NULL) { |
| 323 | printf("output ptr is null\n"); |
| 324 | return -1; |
| 325 | } |
| 326 | if (param_name == NULL) { |
| 327 | printf("param ptr is null"); |
| 328 | return -1; |
| 329 | } |
| 330 | if (param_name[0] == '\0') { |
| 331 | printf("param is empty"); |
| 332 | return -1; |
| 333 | } |
| 334 | |
| 335 | sprintf(lynq_cmd_get, "GET_NETWORK %d %s", net_no, param_name); |
| 336 | |
| 337 | CHECK_WPA_CTRL(interface); |
| 338 | |
| 339 | DO_REQUEST(lynq_cmd_get); |
| 340 | |
| 341 | if (memcmp(cmd_reply, "FAIL", 4) == 0) { |
| 342 | return -1; |
| 343 | } |
| 344 | |
you.chen | a6fa5b2 | 2022-05-18 10:28:19 +0800 | [diff] [blame^] | 345 | // printf("reply len %d, %08x\n", reply_len, (int)out_put); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 346 | memcpy(out_put, cmd_reply, reply_len + 1); |
| 347 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 348 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 349 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 350 | static int lynq_split(char * str, int len, char delimiter, char * results[]) { |
| 351 | int ret = 0; |
| 352 | char * end = str + len - 1; |
| 353 | results[ret++] = str; |
| 354 | while(str < end) { |
| 355 | if (*str == delimiter) { |
| 356 | *str++ = '\0'; |
| 357 | results[ret++] = str; |
| 358 | continue; |
| 359 | } |
| 360 | str++; |
| 361 | } |
| 362 | if (*str == delimiter) { |
| 363 | *str = '\0'; |
| 364 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 365 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 366 | return ret; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 367 | } |
| 368 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 369 | static void trim_space(char * p, int count) { |
| 370 | char * begin = p; |
| 371 | p += count; |
| 372 | printf("%C-%C||\n", *begin, *p); |
| 373 | while (p >= begin ) { |
| 374 | if (*p == ' ') { |
| 375 | *p-- = '\0'; |
| 376 | } |
| 377 | else { |
| 378 | break; |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | static int get_ip_mac_list(char * mac_list[128], char * ip_list[128]) { |
| 384 | FILE * fp; |
| 385 | int len, ret; |
| 386 | int count, count_words, index; |
| 387 | int mac_start, mac_end; |
| 388 | int ip_start, ip_end; |
| 389 | char *split_lines[128] = {0}; |
| 390 | char *buff; |
| 391 | const char * ip_header = "IP address"; |
| 392 | const char * mac_header = "HW address"; |
| 393 | const char * zero_mac = "00:00:00:00:00:00"; |
| 394 | |
| 395 | fp = fopen("/proc/net/arp", "rb"); |
| 396 | if (NULL == fp) { |
| 397 | printf("open file fail\n"); |
| 398 | return -1; |
| 399 | } |
| 400 | |
| 401 | buff = alloca(MAX_RET); |
| 402 | fseek(fp, 0, SEEK_SET); |
| 403 | len = fread(buff, 1, MAX_RET, fp); |
| 404 | fclose(fp); |
| 405 | if (len <= 0) { |
| 406 | printf("read file fail\n"); |
| 407 | return -1; |
| 408 | } |
| 409 | printf("file : %s\n", buff); |
| 410 | |
| 411 | count = lynq_split(buff, len, '\n', split_lines); |
| 412 | printf("----- %s\n", split_lines[0]); |
| 413 | |
| 414 | mac_end = 0; |
| 415 | count_words = strlen(split_lines[0]); |
| 416 | if (strstr(split_lines[0], mac_header) != NULL) { |
| 417 | mac_start = strstr(split_lines[0], mac_header) - split_lines[0]; |
| 418 | mac_end = mac_start + strlen(mac_header) + 1; |
| 419 | while (mac_end < count_words) { |
| 420 | if (split_lines[0][mac_end] != ' ') { |
| 421 | break; |
| 422 | } |
| 423 | mac_end++; |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | ip_end = 0; |
| 428 | if (strstr(split_lines[0], ip_header) != NULL) { |
| 429 | ip_start = strstr(split_lines[0], ip_header) - split_lines[0]; |
| 430 | ip_end = ip_start + strlen(ip_header) + 1; |
| 431 | while (ip_end < count_words) { |
| 432 | if (split_lines[0][ip_end] != ' ') { |
| 433 | break; |
| 434 | } |
| 435 | ip_end++; |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | if (mac_end == 0 || ip_end == 0) { |
| 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | ret = 0; |
| 444 | for(index = 1;index < count; index++) { |
| 445 | if (memcmp(split_lines[index] + mac_start, zero_mac, strlen(zero_mac)) == 0) { |
| 446 | continue; |
| 447 | } |
| 448 | mac_list[ret] = malloc(mac_end - mac_start + 1); |
| 449 | ip_list[ret] = malloc(ip_end - ip_start + 1); |
| 450 | memcpy(mac_list[ret], split_lines[index] + mac_start, mac_end - mac_start); |
| 451 | memcpy(ip_list[ret], split_lines[index] + ip_start, ip_end - ip_start); |
| 452 | trim_space(mac_list[ret], mac_end - mac_start - 1); |
| 453 | trim_space(ip_list[ret], ip_end - ip_start - 1); |
| 454 | ret++; |
| 455 | } |
| 456 | |
| 457 | return ret; |
| 458 | } |
| 459 | |
| 460 | static int get_hostname_by_ip(char *ip, char *hostname) { |
| 461 | struct in_addr addr ={0}; |
| 462 | struct hostent *ht; |
| 463 | |
| 464 | if (ip == NULL || *ip == '\0' || hostname == NULL) { |
| 465 | return -1; |
| 466 | } |
| 467 | |
| 468 | if (inet_aton(ip, &addr) == 0) { |
| 469 | printf("---inet_aton fail\n"); |
| 470 | return -1; |
| 471 | } |
| 472 | |
| 473 | ht = gethostbyaddr(&addr, sizeof(struct in_addr), AF_INET); |
| 474 | |
| 475 | if (ht == NULL) { |
| 476 | printf("---gethostbyaddr fail\n"); |
| 477 | herror(NULL); |
| 478 | return -1; |
| 479 | } |
| 480 | |
| 481 | strcpy(hostname, ht->h_name); |
| 482 | |
| 483 | return 0; |
| 484 | } |
| 485 | |
| 486 | static int lynq_get_network_number_list(lynq_wifi_index_e idx, int ap_sta, int net_no_list[], char * ssid) |
| 487 | { |
| 488 | int count, index, words_count; |
| 489 | char * split_lines[128]= {0}; |
| 490 | char * split_words[128] = {0}; |
| 491 | const char *lynq_wifi_list_networks = "LIST_NETWORKS"; |
| 492 | |
| 493 | CHECK_WPA_CTRL(ap_sta); |
| 494 | |
| 495 | DO_REQUEST(lynq_wifi_list_networks); |
| 496 | |
| 497 | count = lynq_split(cmd_reply, reply_len, '\n', split_lines); |
| 498 | |
| 499 | //@todo check ssid field to compatible |
| 500 | |
| 501 | ret = 0; |
| 502 | for(index=1; index < count; index++) { |
| 503 | words_count = lynq_split(split_lines[index], strlen(split_lines[index]), '\t', split_words); |
| 504 | if (words_count > 2) { |
| 505 | if (ssid == NULL || strcmp(split_words[1], ssid) == 0) { |
| 506 | net_no_list[ret++] = atoi(split_words[0]); |
| 507 | } |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | return ret; |
| 512 | } |
| 513 | |
| 514 | static int lynq_add_network(int ap_sta) { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 515 | size_t i=0; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 516 | CHECK_WPA_CTRL(ap_sta); |
| 517 | const char *lynq_wifi_add_network = "ADD_NETWORK"; |
| 518 | |
| 519 | DO_REQUEST(lynq_wifi_add_network); |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 520 | if (memcmp(cmd_reply, "FAIL", 4) == 0) { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 521 | return -1; |
| 522 | } |
| 523 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 524 | for(i=0;i<reply_len;i++) { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 525 | if(cmd_reply[i] == '\n') { |
| 526 | cmd_reply[i] = '\0'; |
| 527 | break; |
| 528 | } |
| 529 | } |
| 530 | return atoi(cmd_reply); |
| 531 | } |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 532 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 533 | static int lynq_check_network_number(lynq_wifi_index_e idx, int ap_sta, int net_no) |
| 534 | { |
| 535 | int count, index; |
| 536 | int net_no_list[128]; |
| 537 | |
| 538 | |
| 539 | count = lynq_get_network_number_list(idx, ap_sta, net_no_list, NULL); |
| 540 | for (index=0; index < count; index++) { |
| 541 | if (net_no_list[index] == net_no) { |
| 542 | return 0; |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | if (count >= 1) |
| 547 | index = net_no_list[count - 1]; |
| 548 | else |
| 549 | index = -1; |
| 550 | |
| 551 | while (index < net_no ) { |
| 552 | index = lynq_add_network(ap_sta); |
| 553 | if (index >= net_no) { // required network no created |
| 554 | return 0; |
| 555 | } |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 556 | else if( index < 0) { |
| 557 | printf("add network fail\n"); |
| 558 | return -1; |
| 559 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | if (index < 0) |
| 563 | return -1; |
| 564 | |
| 565 | return 0; |
| 566 | } |
| 567 | |
| 568 | static lynq_wifi_band_m convert_band_from_freq(int freq) { //@todo |
| 569 | if (freq > 5000 && freq < 6000) { |
| 570 | return LYNQ_WIFI_5G_band; |
| 571 | } |
| 572 | else if (freq > 2000 && freq < 3000) { |
| 573 | return LYNQ_WIFI_2G_band; |
| 574 | } |
| 575 | return LYNQ_WIFI_2_and_5G_band; |
| 576 | } |
| 577 | |
| 578 | static lynq_wifi_auth_s convert_auth_from_key_mgmt(char * key_mgmt) { |
| 579 | if (key_mgmt != NULL) { |
| 580 | if (memcmp( key_mgmt, "NONE", 4) == 0) { |
| 581 | return LYNQ_WIFI_AUTH_OPEN; |
| 582 | } |
| 583 | else if (memcmp( key_mgmt, "WEP", 3) == 0){ |
| 584 | return LYNQ_WIFI_AUTH_WEP; |
| 585 | } |
| 586 | else if (memcmp( key_mgmt, "WPA-PSK", 7) == 0){ |
| 587 | return LYNQ_WIFI_AUTH_WPA_PSK; |
| 588 | } |
| 589 | else if (memcmp( key_mgmt, "WPA2-PSK", 8) == 0){ |
| 590 | return LYNQ_WIFI_AUTH_WPA2_PSK; |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | return -1; |
| 595 | } |
| 596 | |
| 597 | static lynq_wifi_auth_s convert_max_auth_from_flag(char * flag) { |
| 598 | if (flag != NULL) { |
| 599 | if (strstr( flag, "WPA2-PSK") != NULL){ |
| 600 | return LYNQ_WIFI_AUTH_WPA2_PSK; |
| 601 | } |
| 602 | else if (strstr( flag, "WPA-PSK") != NULL){ |
| 603 | return LYNQ_WIFI_AUTH_WPA_PSK; |
| 604 | } |
| 605 | else if (strstr( flag, "WEP") != NULL){ |
| 606 | return LYNQ_WIFI_AUTH_WEP; |
| 607 | } |
| 608 | else if (strstr( flag, "NONE") != NULL) { |
| 609 | return LYNQ_WIFI_AUTH_OPEN; |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | return -1; |
| 614 | } |
| 615 | |
| 616 | static lynq_wifi_bandwidth_type_m convert_bandwidth_from_bw(int bw) { |
| 617 | switch (bw) { |
| 618 | case 10: |
| 619 | return LYNQ_WIFI_BANDWIDTH_HT10; |
| 620 | break; |
| 621 | case 20: |
| 622 | return LYNQ_WIFI_BANDWIDTH_HT20; |
| 623 | break; |
| 624 | case 40: |
| 625 | return LYNQ_WIFI_BANDWIDTH_HT40; |
| 626 | break; |
| 627 | case 80: |
| 628 | return LYNQ_WIFI_BANDWIDTH_HT80; |
| 629 | break; |
| 630 | default: |
| 631 | break; |
| 632 | } |
| 633 | |
| 634 | return -1; |
| 635 | } |
| 636 | |
| 637 | static int inner_get_status_info(int interface, curr_status_info *curr_state) { |
| 638 | int i, count; |
| 639 | char *p; |
| 640 | const char *lynq_status_cmd = "STATUS"; |
| 641 | const char * FLAG_SSID = "ssid="; |
| 642 | const char * FLAG_SBSID = "bssid="; |
| 643 | const char * FLAG_KEY_MGMT = "key_mgmt="; |
| 644 | const char * FLAG_FREQ = "freq="; |
| 645 | const char * FLAG_STATE = "wpa_state="; |
| 646 | const char * FLAG_ID = "id="; |
| 647 | char *split_lines[128] = {0}; |
| 648 | |
| 649 | CHECK_WPA_CTRL(interface); |
| 650 | |
| 651 | if (curr_state == NULL) { |
| 652 | return -1; |
| 653 | } |
| 654 | |
| 655 | DO_REQUEST(lynq_status_cmd); |
| 656 | |
| 657 | count = lynq_split(cmd_reply, reply_len, '\n', split_lines); |
| 658 | |
| 659 | curr_state->net_no = -1; |
| 660 | ret = -1; |
| 661 | for(i=0; i < count; i++) { |
| 662 | if (curr_state->ap != NULL) { |
| 663 | p = strstr(split_lines[i], FLAG_SSID); |
| 664 | if (p != NULL) { |
| 665 | strcpy(curr_state->ap->ap_ssid, p + strlen(FLAG_SSID)); |
| 666 | ret = 0; |
| 667 | continue; |
| 668 | } |
| 669 | p = strstr(split_lines[i], FLAG_SBSID); |
| 670 | if (p != NULL) { |
| 671 | strcpy(curr_state->ap->ap_mac, p + strlen(FLAG_SBSID)); |
| 672 | ret = 0; |
| 673 | continue; |
| 674 | } |
| 675 | p = strstr(split_lines[i], FLAG_KEY_MGMT); |
| 676 | if (p != NULL) { |
| 677 | curr_state->ap->auth = convert_auth_from_key_mgmt(p); |
| 678 | ret = 0; |
| 679 | continue; |
| 680 | } |
| 681 | p = strstr(split_lines[i], FLAG_FREQ); |
| 682 | if (p != NULL) { |
| 683 | curr_state->ap->band = convert_band_from_freq(atoi( p + strlen(FLAG_FREQ))); |
| 684 | ret = 0; |
| 685 | continue; |
| 686 | } |
| 687 | } // end if (ap != NULL) |
| 688 | if (curr_state->state != NULL) { |
| 689 | p = strstr(split_lines[i], FLAG_STATE); |
| 690 | if (p != NULL) { |
| 691 | strcpy(curr_state->state, p + strlen(FLAG_STATE)); |
| 692 | ret = 0; |
| 693 | continue; |
| 694 | } |
| 695 | |
| 696 | } //end else if (state != NULL) |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 697 | if ((p = strstr(split_lines[i], FLAG_ID)) == split_lines[i]) { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 698 | ret = 0; |
| 699 | curr_state->net_no = atoi(p); |
| 700 | printf("net_no %d, -- %s\n", curr_state->net_no, p); |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | return ret; |
| 705 | } |
| 706 | |
| 707 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 708 | int lynq_wifi_ap_ssid_set(lynq_wifi_index_e idx,char *ap_ssid) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 709 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 710 | char lynq_wifi_ssid_cmd[80]={0}; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 711 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 712 | if (ap_ssid == NULL) { |
| 713 | printf("ap_ssid is null\n"); |
| 714 | return -1; |
| 715 | } |
| 716 | else { |
| 717 | printf("idx:%d ap_ssid : %s\n", idx, ap_ssid); |
| 718 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 719 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 720 | if (lynq_check_network_number(idx, CTRL_AP, AP_NETWORK_0) != 0) { |
| 721 | return -1; |
| 722 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 723 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 724 | CHECK_IDX(idx, CTRL_AP); |
| 725 | |
| 726 | CHECK_WPA_CTRL(CTRL_AP); |
| 727 | |
| 728 | sprintf(lynq_wifi_ssid_cmd,"SET_NETWORK %d ssid \"%s\"", AP_NETWORK_0, ap_ssid); |
| 729 | |
| 730 | DO_OK_FAIL_REQUEST(lynq_wifi_ssid_cmd); |
| 731 | DO_OK_FAIL_REQUEST(cmd_save_config); |
| 732 | |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 733 | return 0; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 734 | |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 735 | } |
| 736 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 737 | int lynq_wifi_ap_ssid_get(lynq_wifi_index_e idx, char* ap_ssid) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 738 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 739 | int len; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 740 | CHECK_IDX(idx, CTRL_AP); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 741 | if (0 != inner_get_param(CTRL_AP, AP_NETWORK_0, "ssid", ap_ssid)) |
| 742 | return -1; |
| 743 | len = strlen(ap_ssid); |
| 744 | if (ap_ssid[0] == '\"') { |
| 745 | memmove(ap_ssid, ap_ssid + 1, len - 1); |
| 746 | len -= 1; |
| 747 | } |
| 748 | if (len > 0 && ap_ssid[len-1] == '\"') { |
| 749 | ap_ssid[len-1] = '\0'; |
| 750 | } |
| 751 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 752 | } |
| 753 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 754 | int lynq_wifi_ap_frequency_set(lynq_wifi_index_e idx,int lynq_wifi_frequency) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 755 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 756 | char lynq_wifi_frequency_cmd[128]={0}; |
| 757 | char lynq_cmd_mode[128]={0}; |
| 758 | char lynq_cmd_slect[128]={0}; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 759 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 760 | if((lynq_wifi_frequency != 2437) && (lynq_wifi_frequency != 5180)){ |
| 761 | PRINT_AND_RETURN_VALUE("set frequency not in range",-1); |
| 762 | } |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 763 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 764 | if (lynq_check_network_number(idx, CTRL_AP, AP_NETWORK_0) != 0) { |
| 765 | return -1; |
| 766 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 767 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 768 | CHECK_IDX(idx, CTRL_AP); |
| 769 | |
| 770 | CHECK_WPA_CTRL(CTRL_AP); |
| 771 | |
| 772 | sprintf(lynq_wifi_frequency_cmd,"SET_NETWORK %d frequency %d", AP_NETWORK_0, lynq_wifi_frequency); |
| 773 | sprintf(lynq_cmd_mode, "SET_NETWORK %d mode 2", AP_NETWORK_0); |
| 774 | sprintf(lynq_cmd_slect, "SELECT_NETWORK %d", AP_NETWORK_0); |
| 775 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 776 | DO_OK_FAIL_REQUEST(cmd_disconnect); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 777 | DO_OK_FAIL_REQUEST(lynq_wifi_frequency_cmd); |
| 778 | DO_OK_FAIL_REQUEST(lynq_cmd_mode); |
| 779 | DO_OK_FAIL_REQUEST(cmd_save_config); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 780 | |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 781 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 782 | } |
| 783 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 784 | int lynq_wifi_ap_frequency_get(lynq_wifi_index_e idx,int *lynq_wifi_frequency) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 785 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 786 | char lynq_frequency_str[MAX_RET] = {0}; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 787 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 788 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 789 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 790 | if (inner_get_param(CTRL_AP, AP_NETWORK_0, "frequency", lynq_frequency_str) != 0) { |
| 791 | return -1; |
| 792 | } |
| 793 | *lynq_wifi_frequency = atoi(lynq_frequency_str); |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 794 | |
| 795 | return 0; |
| 796 | } |
| 797 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 798 | int lynq_wifi_ap_bandwidth_set(lynq_wifi_index_e idx,lynq_wifi_bandwidth_type_m bandwidth) |
| 799 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 800 | CHECK_IDX(idx, CTRL_AP); |
| 801 | switch(bandwidth){ |
| 802 | case LYNQ_WIFI_BANDWIDTH_HT10: |
| 803 | { |
| 804 | printf("bandwith [%d] not support now\n", bandwidth); |
| 805 | return -1; |
| 806 | } |
| 807 | case LYNQ_WIFI_BANDWIDTH_HT20: |
| 808 | { |
| 809 | char lynq_cmd_bandwith[MAX_CMD]="wl chanspec 6"; |
| 810 | system("wl down"); |
| 811 | if (system(lynq_cmd_bandwith) != 0 ){ |
| 812 | return -1; |
| 813 | } |
| 814 | system("wl up"); |
| 815 | break; |
| 816 | } |
| 817 | case LYNQ_WIFI_BANDWIDTH_HT40: |
| 818 | { |
| 819 | char lynq_cmd_bandwith[MAX_CMD]="wl chanspec 153u"; |
| 820 | sprintf(lynq_cmd_bandwith, "wl chanspec "); |
| 821 | system("wl down"); |
| 822 | if (system(lynq_cmd_bandwith) != 0 ){ |
| 823 | return -1; |
| 824 | } |
| 825 | system("wl up"); |
| 826 | break; |
| 827 | } |
| 828 | case LYNQ_WIFI_BANDWIDTH_HT80: |
| 829 | { |
| 830 | char lynq_cmd_bandwith[MAX_CMD]="wl chanspec 36/80"; |
| 831 | system("wl down"); |
| 832 | if (system(lynq_cmd_bandwith) != 0 ){ |
| 833 | return -1; |
| 834 | } |
| 835 | system("wl up"); |
| 836 | break; |
| 837 | } |
| 838 | default: |
| 839 | { |
| 840 | printf("auth type [%d] not support now\n", bandwidth); |
| 841 | return -1; |
| 842 | } |
| 843 | } |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 844 | |
| 845 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 846 | return 0; |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 847 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 848 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 849 | int lynq_wifi_ap_bandwidth_get(lynq_wifi_index_e idx,lynq_wifi_bandwidth_type_m* bandwidth) |
| 850 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 851 | int count = 0; |
| 852 | int index = 0; |
| 853 | char *split_words[128] = {0}; |
| 854 | const char *lynq_chanspec_cmd = "DRIVER chanspec\n"; |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 855 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 856 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 857 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 858 | CHECK_WPA_CTRL(CTRL_AP); |
| 859 | |
| 860 | DO_REQUEST(lynq_chanspec_cmd); |
| 861 | |
| 862 | count = lynq_split(cmd_reply, reply_len, ' ', split_words); |
| 863 | for(;index < count; index++) { |
| 864 | if (strncmp(split_words[index], "bw", 2) != 0) { |
| 865 | continue; |
| 866 | } |
| 867 | |
| 868 | index++; |
| 869 | if (index >= count) { |
| 870 | return -1; |
| 871 | } |
| 872 | |
| 873 | printf("bw %s\n", split_words[index]); |
| 874 | *bandwidth = convert_bandwidth_from_bw(atoi(split_words[index])); |
| 875 | return 0; |
| 876 | } |
| 877 | |
| 878 | return -1; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 879 | } |
qs.xiong | 0fb469a | 2022-04-14 03:50:45 -0400 | [diff] [blame] | 880 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 881 | int lynq_wifi_ap_channel_set( lynq_wifi_index_e idx,int channel) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 882 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 883 | char lynq_cmd_channel[MAX_CMD]={0}; |
qs.xiong | 1d58e9b | 2022-04-14 06:17:01 -0400 | [diff] [blame] | 884 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 885 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 1d58e9b | 2022-04-14 06:17:01 -0400 | [diff] [blame] | 886 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 887 | sprintf(lynq_cmd_channel, "wl channel %d", channel); |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 888 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 889 | if (lynq_check_network_number(idx, CTRL_AP, AP_NETWORK_0) != 0) { |
| 890 | return -1; |
| 891 | } |
| 892 | |
| 893 | system("wl down"); |
| 894 | if (system(lynq_cmd_channel) != 0 ){ |
| 895 | return -1; |
| 896 | } |
| 897 | system("wl up"); |
| 898 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 899 | } |
qs.xiong | 0fb469a | 2022-04-14 03:50:45 -0400 | [diff] [blame] | 900 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 901 | int lynq_wifi_ap_channel_get( lynq_wifi_index_e idx,int* channel) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 902 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 903 | int count = 0; |
| 904 | int index = 0; |
| 905 | char *split_words[128] = {0}; |
| 906 | char lynq_chanspec_cmd[]="DRIVER chanspec\n"; |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 907 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 908 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 909 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 910 | CHECK_WPA_CTRL(CTRL_AP); |
| 911 | |
| 912 | DO_REQUEST(lynq_chanspec_cmd); |
| 913 | |
| 914 | count = lynq_split(cmd_reply, reply_len, ' ', split_words); |
| 915 | for(;index < count; index++) { |
| 916 | printf("---- %s\n",split_words[index]); |
| 917 | if (strncmp(split_words[index], "channel", 2) != 0) { |
| 918 | continue; |
| 919 | } |
| 920 | |
| 921 | index++; |
| 922 | if (index >= count) { |
| 923 | return -1; |
| 924 | } |
| 925 | |
| 926 | *channel = atoi(split_words[index]); |
| 927 | return 0; |
| 928 | } |
| 929 | |
| 930 | return -1; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 934 | int lynq_wifi_ap_auth_set(lynq_wifi_index_e idx, lynq_wifi_auth_s auth) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 935 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 936 | char ssid[MAX_CMD] = {0}; |
| 937 | int freq = 0; |
| 938 | char lynq_auth_cmd[64]={0}; |
| 939 | char lynq_auth_alg_cmd[64]={0}; |
| 940 | char lynq_psk_cmd[64]={0}; |
| 941 | char lynq_pairwise_cmd[64]={0}; |
| 942 | lynq_wifi_auth_s org_auth; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 943 | CHECK_IDX(idx, CTRL_AP); |
| 944 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 945 | CHECK_WPA_CTRL(CTRL_AP); |
| 946 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 947 | if (lynq_check_network_number(idx, CTRL_AP, AP_NETWORK_0) != AP_NETWORK_0) { |
| 948 | return -1; |
| 949 | } |
| 950 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 951 | if (0 == lynq_wifi_ap_auth_get(idx, &org_auth)) { |
| 952 | if (org_auth == auth) { |
| 953 | return 0; |
| 954 | } |
| 955 | else { |
| 956 | if (0 != lynq_wifi_ap_ssid_get(idx, ssid)) { |
| 957 | ssid[0] = '\0'; |
| 958 | } |
| 959 | lynq_wifi_ap_frequency_get(idx, &freq); |
| 960 | |
| 961 | DO_OK_FAIL_REQUEST(cmd_disconnect); |
| 962 | DO_OK_FAIL_REQUEST(cmd_remove_all); |
| 963 | if (ssid[0] != '\0') { |
| 964 | lynq_wifi_ap_ssid_set(idx, ssid); |
| 965 | } |
| 966 | if (freq != 0) { |
| 967 | lynq_wifi_ap_frequency_set(idx, freq); |
| 968 | } |
| 969 | } |
| 970 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 971 | |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 972 | switch(auth){ |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 973 | case LYNQ_WIFI_AUTH_OPEN: |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 974 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 975 | sprintf(lynq_auth_cmd,"SET_NETWORK %d key_mgmt NONE", AP_NETWORK_0); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 976 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 977 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 978 | break; |
| 979 | } |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 980 | case LYNQ_WIFI_AUTH_WEP: |
| 981 | { |
| 982 | sprintf(lynq_auth_cmd,"SET_NETWORK %d key_mgmt NONE", AP_NETWORK_0); |
| 983 | sprintf(lynq_auth_alg_cmd,"SET_NETWORK %d auth_alg SHARED", AP_NETWORK_0); |
| 984 | |
| 985 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
| 986 | DO_OK_FAIL_REQUEST(lynq_auth_alg_cmd); |
| 987 | break; |
| 988 | } |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 989 | case LYNQ_WIFI_AUTH_WPA_PSK: |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 990 | case LYNQ_WIFI_AUTH_WPA2_PSK: |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 991 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 992 | if (auth == LYNQ_WIFI_AUTH_WPA_PSK) { |
| 993 | sprintf(lynq_auth_cmd,"SET_NETWORK %d proto WPA", AP_NETWORK_0); |
| 994 | sprintf(lynq_psk_cmd,"SET_NETWORK %d key_mgmt WPA-PSK", AP_NETWORK_0); |
| 995 | } |
| 996 | else if (auth == LYNQ_WIFI_AUTH_WPA2_PSK) { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 997 | sprintf(lynq_auth_cmd,"SET_NETWORK %d proto RSN", AP_NETWORK_0); |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 998 | sprintf(lynq_psk_cmd,"SET_NETWORK %d key_mgmt WPA-PSK", AP_NETWORK_0); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 999 | } |
| 1000 | // sprintf(lynq_auth_cmd,"SET_NETWORK %d proto WPA2", AP_NETWORK_0); |
| 1001 | // sprintf(lynq_psk_cmd,"SET_NETWORK %d key_mgmt WPA-PSK", AP_NETWORK_0); |
| 1002 | sprintf(lynq_pairwise_cmd,"SET_NETWORK %d pairwise CCMP", AP_NETWORK_0); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1003 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1004 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
| 1005 | DO_OK_FAIL_REQUEST(lynq_psk_cmd); |
| 1006 | DO_OK_FAIL_REQUEST(lynq_pairwise_cmd); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1007 | break; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1008 | } |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1009 | default: |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1010 | { |
| 1011 | printf("auth type [%d] not support now\n", auth); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1012 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1013 | } |
| 1014 | } |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1015 | DO_OK_FAIL_REQUEST(cmd_save_config); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1016 | |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1017 | return 0; |
| 1018 | } |
| 1019 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1020 | int lynq_wifi_ap_auth_get(lynq_wifi_index_e idx, lynq_wifi_auth_s *auth) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1021 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1022 | char lynq_auth_str[MAX_RET] = {0}; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1023 | char lynq_auth_alg_str[MAX_RET] = {0}; |
| 1024 | char lynq_proto_str[MAX_RET] = {0}; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1025 | |
| 1026 | CHECK_IDX(idx, CTRL_AP); |
| 1027 | |
| 1028 | if (inner_get_param(CTRL_AP, AP_NETWORK_0, "key_mgmt", lynq_auth_str) != 0) { |
| 1029 | return -1; |
| 1030 | } |
| 1031 | |
| 1032 | if (memcmp( lynq_auth_str, "NONE", 4) == 0) { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1033 | if (inner_get_param(CTRL_AP, AP_NETWORK_0, "auth_alg", lynq_auth_alg_str) != 0) { |
| 1034 | *auth = LYNQ_WIFI_AUTH_OPEN; |
| 1035 | } |
| 1036 | else if (memcmp(lynq_auth_alg_str, "SHARED", 6) == 0){ |
| 1037 | *auth = LYNQ_WIFI_AUTH_WEP; |
| 1038 | } |
| 1039 | else { |
| 1040 | *auth = LYNQ_WIFI_AUTH_OPEN; |
| 1041 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1042 | } |
| 1043 | else { |
you.chen | a6fa5b2 | 2022-05-18 10:28:19 +0800 | [diff] [blame^] | 1044 | if (inner_get_param(CTRL_AP, AP_NETWORK_0, "proto", lynq_proto_str) != 0) { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1045 | *auth = LYNQ_WIFI_AUTH_WPA_PSK; |
| 1046 | } |
| 1047 | else if (memcmp(lynq_proto_str, "RSN", 3) == 0) { |
| 1048 | *auth = LYNQ_WIFI_AUTH_WPA2_PSK; |
| 1049 | } |
| 1050 | else { |
| 1051 | *auth = LYNQ_WIFI_AUTH_WPA_PSK; |
| 1052 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1053 | } |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1054 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1055 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1056 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1057 | |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1058 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1059 | int lynq_wifi_ap_start(lynq_wifi_index_e idx) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1060 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1061 | char LYNQ_WIFI_CMD[128]={0}; |
| 1062 | //const char *lynq_remove_all_cmd = "REMOVE_NETWORK all"; |
| 1063 | //const char *lynq_reconfig_cmd = "RECONFIGURE /data/wifi/wg870/wpa_supplicant.conf"; |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1064 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1065 | CHECK_IDX(idx, CTRL_AP); |
| 1066 | |
| 1067 | CHECK_WPA_CTRL(CTRL_AP); |
| 1068 | |
| 1069 | // system("connmanctl enable wifi"); |
| 1070 | // system("connmanctl tether wifi on cy-test 12345678"); |
| 1071 | // system("ifconfig wlan0 down"); |
| 1072 | // system("ifconfig wlan0 up"); |
| 1073 | // system("ifconfig wlan0 up"); |
| 1074 | |
| 1075 | //DO_OK_FAIL_REQUEST(lynq_remove_all_cmd); |
| 1076 | //DO_OK_FAIL_REQUEST(lynq_reconfig_cmd); |
| 1077 | |
| 1078 | sprintf(LYNQ_WIFI_CMD,"SELECT_NETWORK %d",AP_NETWORK_0); |
| 1079 | DO_OK_FAIL_REQUEST(LYNQ_WIFI_CMD); |
| 1080 | |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1081 | return 0; |
| 1082 | } |
| 1083 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1084 | int lynq_wifi_ap_restart(lynq_wifi_index_e idx) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1085 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1086 | return lynq_wifi_ap_stop(idx) == 0 ? lynq_wifi_ap_start(idx) : -1; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1087 | } |
| 1088 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1089 | int lynq_wifi_ap_stop(lynq_wifi_index_e idx) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1090 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1091 | char LYNQ_WIFI_CMD[128]={0}; |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1092 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1093 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1094 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1095 | CHECK_WPA_CTRL(CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1096 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1097 | sprintf(LYNQ_WIFI_CMD,"DISABLE_NETWORK %d",AP_NETWORK_0); |
| 1098 | |
| 1099 | DO_OK_FAIL_REQUEST(LYNQ_WIFI_CMD); |
| 1100 | |
you.chen | b4b121c | 2022-05-06 17:50:16 +0800 | [diff] [blame] | 1101 | // system("connmanctl tether wifi off"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1102 | |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1103 | return 0; |
| 1104 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1105 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1106 | int lynq_wifi_ap_hide_ssid(lynq_wifi_index_e idx) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1107 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1108 | char lynq_disable_cmd[128] = {0}; |
| 1109 | char lynq_select_cmd[128] = {0}; |
| 1110 | const char *lynq_hide_cmd = "SET HIDE_SSID 1"; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1111 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1112 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1113 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1114 | CHECK_WPA_CTRL(CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1115 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1116 | sprintf(lynq_disable_cmd,"DISABLE_NETWORK %d", AP_NETWORK_0); |
| 1117 | sprintf(lynq_select_cmd,"SELECT_NETWORK %d", AP_NETWORK_0); |
| 1118 | |
| 1119 | DO_OK_FAIL_REQUEST(lynq_disable_cmd); |
| 1120 | DO_OK_FAIL_REQUEST(lynq_hide_cmd); |
| 1121 | DO_OK_FAIL_REQUEST(lynq_select_cmd); |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1122 | |
| 1123 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1124 | } |
| 1125 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1126 | int lynq_wifi_ap_unhide_ssid(lynq_wifi_index_e idx) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1127 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1128 | char lynq_disable_cmd[128] = {0}; |
| 1129 | char lynq_select_cmd[128] = {0}; |
| 1130 | const char *lynq_unhide_cmd = "SET HIDE_SSID 0"; |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1131 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1132 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1133 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1134 | CHECK_WPA_CTRL(CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1135 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1136 | sprintf(lynq_disable_cmd,"DISABLE_NETWORK %d", AP_NETWORK_0); |
| 1137 | sprintf(lynq_select_cmd,"SELECT_NETWORK %d", AP_NETWORK_0); |
| 1138 | |
| 1139 | DO_OK_FAIL_REQUEST(lynq_disable_cmd); |
| 1140 | DO_OK_FAIL_REQUEST(lynq_unhide_cmd); |
| 1141 | DO_OK_FAIL_REQUEST(lynq_select_cmd); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1142 | |
| 1143 | return 0; |
| 1144 | } |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1145 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1146 | int lynq_ap_password_set(lynq_wifi_index_e idx,char *password) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1147 | { |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1148 | int pass_len; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1149 | char lynq_tmp_cmd[MAX_CMD] = {0}; |
| 1150 | char lynq_wep_tx_keyidx_cmd[MAX_CMD] = {0}; |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1151 | pass_len=strlen(password); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1152 | lynq_wifi_auth_s auth = -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1153 | if(pass_len < 8 || pass_len >= 64){ |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1154 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1155 | } |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1156 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1157 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1158 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1159 | if (0 != lynq_wifi_ap_auth_get(idx, &auth)) { |
| 1160 | return -1; |
| 1161 | } |
| 1162 | else if (auth == LYNQ_WIFI_AUTH_OPEN) { |
| 1163 | return -1; |
| 1164 | } |
| 1165 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1166 | CHECK_WPA_CTRL(CTRL_AP); |
| 1167 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1168 | if (auth == LYNQ_WIFI_AUTH_WEP) { |
| 1169 | sprintf(lynq_tmp_cmd,"SET_NETWORK %d wep_key0 \"%s\"",AP_NETWORK_0, password); |
| 1170 | sprintf(lynq_wep_tx_keyidx_cmd,"SET_NETWORK %d wep_tx_keyidx 0",AP_NETWORK_0); |
| 1171 | DO_OK_FAIL_REQUEST(lynq_tmp_cmd); |
| 1172 | DO_OK_FAIL_REQUEST(lynq_wep_tx_keyidx_cmd); |
| 1173 | } |
| 1174 | else if (auth == LYNQ_WIFI_AUTH_WPA_PSK || auth == LYNQ_WIFI_AUTH_WPA2_PSK) { |
| 1175 | sprintf(lynq_tmp_cmd,"SET_NETWORK %d psk \"%s\"",AP_NETWORK_0, password); |
| 1176 | DO_OK_FAIL_REQUEST(lynq_tmp_cmd); |
| 1177 | } |
| 1178 | else { |
| 1179 | return -1; |
| 1180 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1181 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1182 | DO_OK_FAIL_REQUEST(cmd_save_config); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1183 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1184 | return 0; |
| 1185 | } |
| 1186 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1187 | int lynq_ap_password_get(lynq_wifi_index_e idx, char *password) |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1188 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1189 | FILE * fp; |
| 1190 | int len, ret; |
| 1191 | int count, index; |
| 1192 | char *split_lines[128] = {0}; |
| 1193 | char *buff, *p; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1194 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1195 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1196 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1197 | fp = fopen("/data/wifi/wg870/wpa_supplicant_ap.conf", "rb"); |
| 1198 | // fp = fopen("/data/wifi/wg870/wpa_supplicant.conf", "rb"); |
| 1199 | if (NULL == fp) { |
| 1200 | printf("open file fail\n"); |
| 1201 | return -1; |
| 1202 | } |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1203 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1204 | buff = alloca(MAX_RET); |
| 1205 | fseek(fp, 0, SEEK_SET); |
| 1206 | len = fread(buff, 1, MAX_RET, fp); |
| 1207 | fclose(fp); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1208 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1209 | for(index=0; index < len; index ++) { |
| 1210 | if (memcmp(buff + index, "network={", 9) != 0) { |
| 1211 | continue; |
| 1212 | } |
| 1213 | p = buff + index + 9; |
| 1214 | for (; index < len; index ++ ) { |
| 1215 | if (buff[index] != '}') { |
| 1216 | continue; |
| 1217 | } |
| 1218 | buff[index] = '\0'; |
| 1219 | break; |
| 1220 | } |
| 1221 | len = buff + index - p; |
| 1222 | } |
| 1223 | |
| 1224 | count = lynq_split(p, len, '\n', split_lines); |
| 1225 | |
| 1226 | ret = -1; |
| 1227 | for(index=0; index < count; index++) { |
| 1228 | p = strstr(split_lines[index], "psk="); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1229 | if (p != NULL) { |
| 1230 | p += 4; |
| 1231 | if (*p == '\"') { |
| 1232 | p++; |
| 1233 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1234 | } |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1235 | else if (NULL != (p = strstr(split_lines[index], "wep_key0="))) { |
| 1236 | p += 9; |
| 1237 | if (*p == '\"') { |
| 1238 | p++; |
| 1239 | } |
| 1240 | } |
| 1241 | else { |
| 1242 | continue; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | strcpy(password, p); |
| 1246 | |
| 1247 | while(*password != '\0') { |
| 1248 | if (*password == '\"') { |
| 1249 | *password = '\0'; |
| 1250 | break; |
| 1251 | } |
| 1252 | password++; |
| 1253 | } |
| 1254 | ret = 0; |
| 1255 | break; |
| 1256 | } //end for(index=0; index < count; index++) |
| 1257 | |
| 1258 | return ret; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1259 | } |
| 1260 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1261 | static int inner_get_network_auth(int interface, int net_no, lynq_wifi_auth_s *auth) { |
| 1262 | char lynq_auth_str[MAX_RET] = {0}; |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 1263 | char lynq_proto_str[MAX_RET] = {0}; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1264 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1265 | if (inner_get_param(interface, net_no, "key_mgmt", lynq_auth_str) != 0) { |
| 1266 | return -1; |
| 1267 | } |
| 1268 | |
| 1269 | *auth = convert_auth_from_key_mgmt(lynq_auth_str); |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 1270 | |
| 1271 | if (*auth == LYNQ_WIFI_AUTH_WPA_PSK) { |
| 1272 | if (inner_get_param(interface, net_no, "proto", lynq_proto_str) == 0) { |
| 1273 | if (strcmp(lynq_proto_str, "RSN") == 0) { |
| 1274 | *auth = LYNQ_WIFI_AUTH_WPA2_PSK; |
| 1275 | } |
| 1276 | } |
| 1277 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1278 | return 0; |
| 1279 | } |
| 1280 | |
| 1281 | int lynq_sta_ssid_password_set(lynq_wifi_index_e idx, ap_info_s *ap, char *password) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1282 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1283 | int pass_len, net_no, count, index; |
| 1284 | char lynq_tmp_cmd[300]={0}; |
| 1285 | int net_no_list[128]; |
| 1286 | lynq_wifi_auth_s net_auth; |
| 1287 | pass_len=strlen(password); |
| 1288 | if(pass_len < 8 || pass_len >= 64){ |
| 1289 | return -1; |
| 1290 | } |
| 1291 | |
| 1292 | CHECK_IDX(idx, CTRL_STA); |
| 1293 | |
| 1294 | net_no = -1; |
| 1295 | count = lynq_get_network_number_list(idx, CTRL_STA, net_no_list, ap->ap_ssid); |
| 1296 | |
| 1297 | for (index=0; index < count; index++) { |
| 1298 | net_auth = -1; |
| 1299 | if (0 == inner_get_network_auth(CTRL_STA, net_no_list[index], &net_auth) && net_auth == ap->auth) { |
| 1300 | net_no = net_no_list[index]; |
| 1301 | break; |
| 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | if (net_no < 0) { |
| 1306 | return -1; |
| 1307 | } |
| 1308 | |
| 1309 | CHECK_WPA_CTRL(CTRL_STA); |
| 1310 | |
| 1311 | sprintf(lynq_tmp_cmd,"SET_NETWORK %d psk \"%s\"",net_no, password); |
| 1312 | |
| 1313 | DO_OK_FAIL_REQUEST(lynq_tmp_cmd); |
| 1314 | DO_OK_FAIL_REQUEST(cmd_save_config); |
| 1315 | |
| 1316 | return 0; |
| 1317 | } |
| 1318 | |
| 1319 | int lynq_sta_ssid_password_get(lynq_wifi_index_e idx, ap_info_s *ap, char *password) { // @todo |
| 1320 | |
| 1321 | FILE * fp; |
| 1322 | int len, ret; |
| 1323 | int count, index; |
| 1324 | char *split_lines[128] = {0}; |
| 1325 | char *buff, *p; |
| 1326 | |
| 1327 | CHECK_IDX(idx, CTRL_STA); |
| 1328 | |
| 1329 | fp = fopen("/data/wifi/wg870/wpa_supplicant.conf", "rb"); |
| 1330 | if (NULL == fp) { |
| 1331 | printf("open file fail\n"); |
| 1332 | return -1; |
| 1333 | } |
| 1334 | |
| 1335 | buff = alloca(MAX_RET); |
| 1336 | fseek(fp, 0, SEEK_SET); |
| 1337 | len = fread(buff, 1, MAX_RET, fp); |
| 1338 | fclose(fp); |
| 1339 | |
| 1340 | for(index=0; index < len; index ++) { |
| 1341 | for(; index < len; index ++) { |
| 1342 | if (memcmp(buff + index, "network={", 9) != 0) { |
| 1343 | continue; |
| 1344 | } |
| 1345 | p = buff + index + 9; |
| 1346 | for (; index < len; index ++ ) { |
| 1347 | if (buff[index] != '}') { |
| 1348 | continue; |
| 1349 | } |
| 1350 | buff[index] = '\0'; |
| 1351 | break; |
| 1352 | } |
| 1353 | len = buff + index - p; |
| 1354 | } |
| 1355 | |
| 1356 | if (strstr(p, ap->ap_ssid) != NULL) { |
| 1357 | break; |
| 1358 | } |
| 1359 | } |
| 1360 | |
| 1361 | if (index >= len) { |
| 1362 | return -1; |
| 1363 | } |
| 1364 | |
| 1365 | count = lynq_split(p, len, '\n', split_lines); |
| 1366 | |
| 1367 | ret = -1; |
| 1368 | for(index=0; index < count; index++) { |
| 1369 | p = strstr(split_lines[index], "psk="); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1370 | if (p != NULL) { |
| 1371 | p += 4; |
| 1372 | if (*p == '\"') { |
| 1373 | p++; |
| 1374 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1375 | } |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1376 | else if (NULL != (p = strstr(split_lines[index], "wep_key0="))) { |
| 1377 | p += 9; |
| 1378 | if (*p == '\"') { |
| 1379 | p++; |
| 1380 | } |
| 1381 | } |
| 1382 | else { |
| 1383 | continue; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | strcpy(password, p); |
| 1387 | |
| 1388 | while(*password != '\0') { |
| 1389 | if (*password == '\"') { |
| 1390 | *password = '\0'; |
| 1391 | break; |
| 1392 | } |
| 1393 | password++; |
| 1394 | } |
| 1395 | ret = 0; |
| 1396 | break; |
| 1397 | } //end for(index=0; index < count; index++) |
| 1398 | |
| 1399 | return ret; |
| 1400 | } |
| 1401 | |
| 1402 | static int inner_set_sta_ssid(int net_no, char *sta_ssid) |
| 1403 | { |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1404 | char lynq_wifi_ssid_cmd[80]={0}; |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1405 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1406 | if (sta_ssid == NULL) { |
| 1407 | printf("sta_ssid is null\n"); |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1408 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1409 | } |
| 1410 | |
| 1411 | CHECK_WPA_CTRL(CTRL_STA); |
| 1412 | |
| 1413 | sprintf(lynq_wifi_ssid_cmd,"SET_NETWORK %d ssid \"%s\"", net_no, sta_ssid); |
| 1414 | |
| 1415 | DO_OK_FAIL_REQUEST(lynq_wifi_ssid_cmd); |
| 1416 | // DO_OK_FAIL_REQUEST(cmd_save_config); |
| 1417 | |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1418 | return 0; |
| 1419 | |
| 1420 | } |
| 1421 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1422 | static int inner_sta_start_stop(int net_no, int start_flag, int save) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1423 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1424 | char lynq_disable_cmd[128]={0}; |
| 1425 | char lynq_select_cmd[128]={0}; |
| 1426 | |
| 1427 | CHECK_WPA_CTRL(CTRL_STA); |
| 1428 | |
| 1429 | if (save != 0) { |
| 1430 | DO_OK_FAIL_REQUEST(cmd_save_config); |
| 1431 | } |
| 1432 | |
| 1433 | if (start_flag == 0) { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1434 | // sprintf(lynq_disable_cmd,"DISABLE_NETWORK %d", net_no); |
| 1435 | sprintf(lynq_disable_cmd,"DISCONNECT"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1436 | DO_OK_FAIL_REQUEST(lynq_disable_cmd); |
| 1437 | } |
| 1438 | else { |
| 1439 | sprintf(lynq_select_cmd,"SELECT_NETWORK %d", net_no); |
| 1440 | DO_OK_FAIL_REQUEST(lynq_select_cmd); |
| 1441 | } |
| 1442 | |
| 1443 | return 0; |
| 1444 | } |
| 1445 | |
| 1446 | int lynq_wifi_get_sta_ssid(lynq_wifi_index_e idx, char* sta_ssid) |
| 1447 | { |
| 1448 | CHECK_IDX(idx, CTRL_STA); |
| 1449 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1450 | curr_status_info curr_state; |
| 1451 | ap_info_s ap_info; |
| 1452 | curr_state.ap = &ap_info; |
| 1453 | curr_state.state = NULL; |
| 1454 | |
| 1455 | if (0 == inner_get_status_info(CTRL_STA, &curr_state)) { |
| 1456 | strcpy(sta_ssid, ap_info.ap_ssid); |
| 1457 | return 0; |
| 1458 | } |
| 1459 | |
| 1460 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1461 | } |
| 1462 | |
| 1463 | int lynq_wifi_get_sta_available_ap(lynq_wifi_index_e idx, ap_detail_info_s *info) |
| 1464 | { |
| 1465 | scan_info_s *scan_list; |
| 1466 | saved_ap_info_s *save_list; |
| 1467 | int scan_len=0; |
| 1468 | int save_len=0; |
| 1469 | int best_index = -1; |
| 1470 | int best_scan_index = -1; |
| 1471 | int best_rssi = 0; |
| 1472 | int i, j; |
| 1473 | |
| 1474 | CHECK_IDX(idx, CTRL_STA); |
| 1475 | if (info == NULL) { |
| 1476 | return -1; |
| 1477 | } |
| 1478 | |
| 1479 | curr_status_info curr_state; |
| 1480 | ap_info_s ap_info; |
| 1481 | curr_state.ap = &ap_info; |
| 1482 | curr_state.state = NULL; |
| 1483 | |
| 1484 | if (0 == inner_get_status_info(CTRL_STA, &curr_state)) { |
| 1485 | memcpy(&info->base_info, &ap_info, sizeof (ap_info_s)); |
| 1486 | info->status = LYNQ_WIFI_AP_STATUS_ENABLE; |
| 1487 | lynq_get_connect_ap_rssi(idx, &info->rssi); |
| 1488 | return 0; |
| 1489 | } |
| 1490 | |
| 1491 | if (0 != lynq_get_scan_list(0, &scan_list, &scan_len)) { |
| 1492 | return -1; |
| 1493 | } |
| 1494 | |
| 1495 | if (0 != lynq_get_sta_saved_ap(0, &save_list, &save_len)) { |
| 1496 | return -1; |
| 1497 | } |
| 1498 | |
| 1499 | for (i=0; i < save_len; i++) { |
| 1500 | for (j=0; j < scan_len; j++) { |
| 1501 | if (strcmp(save_list[i].base_info.ap_ssid, scan_list[j].ssid) == 0 //@todo not finished |
| 1502 | && save_list[i].base_info.auth == scan_list[j].auth) { |
| 1503 | if (best_rssi == 0) { |
| 1504 | best_rssi = scan_list[j].rssi; |
| 1505 | } |
| 1506 | else if (best_rssi > scan_list[j].rssi) { |
| 1507 | best_index = i; |
| 1508 | best_scan_index = j; |
| 1509 | best_rssi = scan_list[j].rssi; |
| 1510 | } |
| 1511 | break; |
| 1512 | } |
| 1513 | } |
| 1514 | } |
| 1515 | |
| 1516 | if (best_index >= 0) { |
| 1517 | memcpy(&info->base_info, &save_list[best_index].base_info, sizeof (ap_info_s)); |
| 1518 | info->status = LYNQ_WIFI_AP_STATUS_DISABLE; |
| 1519 | info->rssi = best_rssi; |
| 1520 | return 0; |
| 1521 | } |
| 1522 | |
| 1523 | return -1; |
| 1524 | } |
| 1525 | |
| 1526 | static int inner_set_sta_auth_psw(int net_no, lynq_wifi_auth_s auth, char *password) |
| 1527 | { |
| 1528 | char lynq_auth_cmd[64]={0}; |
| 1529 | char lynq_ket_mgmt_cmd[64]={0}; |
| 1530 | char lynq_pairwise_cmd[64]={0}; |
| 1531 | char lynq_psk_cmd[64]={0}; |
| 1532 | |
| 1533 | CHECK_WPA_CTRL(CTRL_STA); |
| 1534 | |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1535 | switch(auth){ |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1536 | case LYNQ_WIFI_AUTH_OPEN: |
| 1537 | { |
| 1538 | sprintf(lynq_auth_cmd,"SET_NETWORK %d key_mgmt NONE", net_no); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1539 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1540 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
| 1541 | // DO_OK_FAIL_REQUEST(cmd_save_config); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1542 | break; |
| 1543 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1544 | case LYNQ_WIFI_AUTH_WPA_PSK: |
| 1545 | case LYNQ_WIFI_AUTH_WPA2_PSK: |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1546 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1547 | if (auth == LYNQ_WIFI_AUTH_WPA_PSK) { |
| 1548 | sprintf(lynq_auth_cmd,"SET_NETWORK %d proto WPA", net_no); |
| 1549 | } |
| 1550 | else if (auth == LYNQ_WIFI_AUTH_WPA2_PSK) { |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 1551 | sprintf(lynq_auth_cmd,"SET_NETWORK %d proto RSN", net_no); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1552 | } |
| 1553 | sprintf(lynq_ket_mgmt_cmd,"SET_NETWORK %d key_mgmt WPA-PSK", net_no); |
| 1554 | sprintf(lynq_pairwise_cmd,"SET_NETWORK %d pairwise CCMP", net_no); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1555 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1556 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
| 1557 | DO_OK_FAIL_REQUEST(lynq_ket_mgmt_cmd); |
| 1558 | DO_OK_FAIL_REQUEST(lynq_pairwise_cmd); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1559 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1560 | if (password != NULL) { |
| 1561 | sprintf(lynq_psk_cmd, "SET_NETWORK %d psk \"%s\"", net_no, password); |
| 1562 | DO_OK_FAIL_REQUEST(lynq_psk_cmd); |
| 1563 | } |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1564 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1565 | // DO_OK_FAIL_REQUEST(cmd_save_config); |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1566 | break; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1567 | } |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1568 | default: |
| 1569 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1570 | } |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1571 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1572 | return 0; |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1573 | } |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1574 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1575 | static int inner_get_curr_net_no(int interface) { |
| 1576 | curr_status_info curr_state; |
| 1577 | curr_state.ap = NULL; |
| 1578 | curr_state.state = NULL; |
| 1579 | |
| 1580 | if (0 != inner_get_status_info(interface, &curr_state)) { |
| 1581 | return -1; |
| 1582 | } |
| 1583 | |
| 1584 | return curr_state.net_no; |
| 1585 | } |
| 1586 | |
| 1587 | int lynq_wifi_get_sta_auth(lynq_wifi_index_e idx, lynq_wifi_auth_s *auth) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1588 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1589 | int net_no; |
| 1590 | CHECK_IDX(idx, CTRL_STA); |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1591 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1592 | net_no = inner_get_curr_net_no(CTRL_STA); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1593 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1594 | if (net_no < 0) { |
| 1595 | return -1; |
| 1596 | } |
| 1597 | |
| 1598 | return inner_get_network_auth(CTRL_STA, net_no, auth); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1599 | } |
| 1600 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1601 | int lynq_wifi_sta_connect(lynq_wifi_index_e idx, char *ssid, lynq_wifi_auth_s auth, char *psw) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1602 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1603 | int count, net_no, index; |
| 1604 | int net_no_list[128]; |
| 1605 | lynq_wifi_auth_s net_auth; |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1606 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1607 | if (ssid == NULL || *ssid == '\0') { |
| 1608 | printf("bad ssid\n"); |
| 1609 | return -1; |
| 1610 | } |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1611 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1612 | if (LYNQ_WIFI_AUTH_OPEN != auth) { |
| 1613 | if (psw == NULL || strlen(psw) < 8 || strlen(psw) >= 64) { |
| 1614 | printf("bad password\n"); |
| 1615 | return -1; |
| 1616 | } |
| 1617 | } |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1618 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1619 | CHECK_IDX(idx, CTRL_STA); |
| 1620 | |
| 1621 | net_no = -1; |
| 1622 | count = lynq_get_network_number_list(idx, CTRL_STA, net_no_list, ssid); |
| 1623 | |
| 1624 | for (index=0; index < count; index++) { |
| 1625 | net_auth = -1; |
| 1626 | if (0 == inner_get_network_auth(CTRL_STA, net_no_list[index], &net_auth) && net_auth == auth) { |
| 1627 | net_no = net_no_list[index]; |
| 1628 | break; |
| 1629 | } |
| 1630 | } |
| 1631 | |
| 1632 | if (net_no < 0) { |
| 1633 | net_no = lynq_add_network(CTRL_STA); |
| 1634 | if (net_no == -1) { |
| 1635 | return -1; |
| 1636 | } |
| 1637 | |
| 1638 | printf("net no is %d\n", net_no); |
| 1639 | if (0 != inner_set_sta_ssid(net_no, ssid)) { |
| 1640 | return -1; |
| 1641 | } |
| 1642 | } |
| 1643 | |
| 1644 | if (0 != inner_set_sta_auth_psw(net_no, auth, psw)) { |
| 1645 | return -1; |
| 1646 | } |
| 1647 | |
| 1648 | return inner_sta_start_stop(net_no, 1, 1); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1649 | } |
| 1650 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1651 | int lynq_wifi_sta_disconnect(lynq_wifi_index_e idx, char *ssid) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1652 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1653 | ap_info_s ap; |
| 1654 | curr_status_info curr_state; |
| 1655 | ap.ap_ssid[0] = '\0'; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1656 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1657 | if (ssid == NULL || *ssid == '\0') { |
| 1658 | return -1; |
| 1659 | } |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1660 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1661 | CHECK_IDX(idx, CTRL_STA); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1662 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1663 | curr_state.ap = ≈ |
you.chen | b4b121c | 2022-05-06 17:50:16 +0800 | [diff] [blame] | 1664 | curr_state.state = NULL; |
| 1665 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1666 | if (inner_get_status_info(CTRL_STA, &curr_state) != 0) { |
| 1667 | return 0; |
| 1668 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1669 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1670 | if (strcmp(ap.ap_ssid, ssid) != 0) { |
| 1671 | return 0; |
| 1672 | } |
| 1673 | |
| 1674 | return inner_sta_start_stop(curr_state.net_no, 0, 0); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1675 | } |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1676 | |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 1677 | int lynq_wifi_sta_start(lynq_wifi_index_e idx) |
| 1678 | { |
| 1679 | // const char *lynq_reconfigure_cmd = "RECONFIGURE /data/wifi/wg870/wpa_supplicant.conf"; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1680 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1681 | CHECK_IDX(idx, CTRL_STA); |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 1682 | CHECK_WPA_CTRL(CTRL_STA); |
| 1683 | |
| 1684 | system("connmanctl enable wifi"); |
| 1685 | |
you.chen | a6fa5b2 | 2022-05-18 10:28:19 +0800 | [diff] [blame^] | 1686 | if (system("ifconfig | grep -q wlan0") != 0) { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1687 | return -1; |
| 1688 | } |
qs.xiong | 9c99fa9 | 2022-03-15 08:03:26 -0400 | [diff] [blame] | 1689 | |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 1690 | // DO_OK_FAIL_REQUEST(lynq_reconfigure_cmd); |
| 1691 | |
| 1692 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1693 | } |
| 1694 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1695 | int lynq_wifi_sta_stop(lynq_wifi_index_e idx) |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1696 | { |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 1697 | char lynq_disable_network_cmd[MAX_CMD]; |
| 1698 | curr_status_info curr_state; |
| 1699 | ap_info_s ap_info; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1700 | |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 1701 | CHECK_IDX(idx, CTRL_STA); |
| 1702 | CHECK_WPA_CTRL(CTRL_STA); |
| 1703 | |
| 1704 | curr_state.ap = &ap_info; |
| 1705 | curr_state.state = NULL; |
| 1706 | |
| 1707 | if (0 != inner_get_status_info(CTRL_STA, &curr_state) || curr_state.net_no < 0) { |
| 1708 | return 0; |
| 1709 | } |
| 1710 | |
| 1711 | sprintf(lynq_disable_network_cmd, "DISABLE_NETWORK %d", curr_state.net_no); |
| 1712 | DO_OK_FAIL_REQUEST(lynq_disable_network_cmd); |
| 1713 | |
| 1714 | DO_OK_FAIL_REQUEST(cmd_save_config); |
| 1715 | |
| 1716 | return 0; |
| 1717 | // return system("connmanctl disable wifi"); |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1718 | } |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1719 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1720 | //static int inner_get_sta_info(lynq_wifi_index_e idx, const char * bssid, device_info_s *dev) { |
| 1721 | // int i, count; |
| 1722 | // char *p; |
| 1723 | // const char * FLAG_SSID = "ssid="; |
| 1724 | // const char * FLAG_SBSID = "bssid="; |
| 1725 | // const char * FLAG_KEY_MGMT = "key_mgmt="; |
| 1726 | // const char * FLAG_FREQ = "freq="; |
| 1727 | // char lynq_sta_cmd[MAX_CMD]; |
| 1728 | // char *split_lines[128] = {0}; |
| 1729 | |
| 1730 | // CHECK_WPA_CTRL(CTRL_AP); |
| 1731 | |
| 1732 | // sprintf(lynq_sta_cmd, "STA %s", bssid); |
| 1733 | |
| 1734 | // DO_REQUEST(lynq_sta_cmd); |
| 1735 | |
| 1736 | // count = lynq_split(cmd_reply, reply_len, '\n', split_lines); |
| 1737 | |
| 1738 | // for(i=0; i < count; i++) { |
| 1739 | // p = strstr(split_lines[i], FLAG_SSID); |
| 1740 | // if (p != NULL) { |
| 1741 | // strcpy(ap->ap_ssid, p + strlen(FLAG_SSID)); |
| 1742 | // continue; |
| 1743 | // } |
| 1744 | // } |
| 1745 | |
| 1746 | // lynq_get_interface_ip(idx, ap->ap_ip); |
| 1747 | // lynq_ap_password_set(idx, ap->psw); |
| 1748 | |
| 1749 | // return 0; |
| 1750 | //} |
| 1751 | |
| 1752 | static int inner_get_status_info_ap (int interface, ap_info_s *ap) { |
| 1753 | curr_status_info curr_state; |
| 1754 | curr_state.ap = ap; |
| 1755 | curr_state.state = NULL; |
| 1756 | return inner_get_status_info(interface, &curr_state); |
| 1757 | } |
| 1758 | |
| 1759 | int lynq_get_ap_device_list(lynq_wifi_index_e idx, ap_info_s **ap, device_info_s ** list,int * len) |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1760 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1761 | int ip_count, index, i, line_count; |
| 1762 | const char *lynq_first_sta_cmd = "STA-FIRST"; |
| 1763 | char lynq_next_sta_cmd[MAX_CMD]; |
| 1764 | char *bssid[1024] = {0}; |
| 1765 | char *mac_list[128] = {0}; |
| 1766 | char *ip_list[128] = {0}; |
| 1767 | char *split_lines[128] = {0}; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1768 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1769 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1770 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1771 | CHECK_WPA_CTRL(CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1772 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1773 | // ap_info_s * tmp_ap; |
| 1774 | // device_info_s * tmp_list; |
| 1775 | if (ap == NULL || list == NULL || len == NULL) { |
| 1776 | printf("bad input param"); |
| 1777 | return -1; |
| 1778 | } |
| 1779 | |
| 1780 | // ap = &tmp_ap; |
| 1781 | // list = &tmp_list; |
| 1782 | *ap = malloc(sizeof (ap_info_s)); |
| 1783 | |
| 1784 | if (inner_get_status_info_ap (CTRL_AP, *ap) != 0) { |
| 1785 | return -1; |
| 1786 | } |
| 1787 | |
| 1788 | lynq_get_interface_ip(idx, (*ap)->ap_ip); |
| 1789 | lynq_ap_password_get(idx, (*ap)->psw); |
| 1790 | |
| 1791 | ip_count = get_ip_mac_list(mac_list, ip_list); |
| 1792 | printf("get count %d\n", ip_count); |
| 1793 | |
| 1794 | DO_REQUEST(lynq_first_sta_cmd); |
| 1795 | |
| 1796 | index = 0; |
| 1797 | while (reply_len > 0) { |
| 1798 | if (memcmp(cmd_reply, "FAIL", 4) == 0) { |
| 1799 | break; |
| 1800 | } |
| 1801 | line_count = lynq_split(cmd_reply, reply_len, '\n', split_lines); |
| 1802 | bssid[index] = malloc(strlen(split_lines[0]) + 1); |
| 1803 | strcpy(bssid[index], split_lines[0]); |
| 1804 | index++; |
| 1805 | sprintf(lynq_next_sta_cmd, "STA-NEXT %s", split_lines[0]); |
| 1806 | reply_len = MAX_RET; |
| 1807 | cmd_reply[0] = '\0'; |
| 1808 | ret = wpa_ctrl_request(lynq_wpa_ctrl, lynq_next_sta_cmd, strlen(lynq_next_sta_cmd), cmd_reply, &reply_len, NULL); |
| 1809 | if (ret != 0 || memcpy(cmd_reply, "FAIL", 4) == 0) { |
| 1810 | break; |
| 1811 | } |
| 1812 | } |
| 1813 | |
| 1814 | *len = index; |
| 1815 | |
| 1816 | *list = malloc(sizeof(device_info_s) * (*len)); |
| 1817 | for (index=0; index < *len; index++) { |
| 1818 | strcpy((*list)[index].sta_mac, bssid[index]); |
| 1819 | for(i=0;i < ip_count; i++ ) { |
| 1820 | if (strcmp(bssid[index], mac_list[i]) == 0) { |
| 1821 | strcpy((*list)[index].sta_ip, ip_list[i]); |
| 1822 | break; |
| 1823 | } |
| 1824 | } |
| 1825 | get_hostname_by_ip((*list)[index].sta_ip, list[index]->hostname); |
| 1826 | (*list)[index].status = LYNQ_WIFI_STATUS_CONNECT; |
| 1827 | free(bssid[index]); |
| 1828 | } |
| 1829 | |
| 1830 | return 0; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1831 | } |
| 1832 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1833 | int lynq_get_scan_list(lynq_wifi_index_e idx, scan_info_s ** list,int * len) |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1834 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1835 | int i, count, index, count_words; |
| 1836 | const char *lynq_scan_result_cmd = "SCAN_RESULTS"; |
| 1837 | char *split_lines[128] = {0}; |
| 1838 | char *split_words[128] = {0}; |
| 1839 | scan_info_s * p; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1840 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1841 | if (list == NULL || len == NULL) { |
| 1842 | return -1; |
| 1843 | } |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1844 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1845 | CHECK_IDX(idx, CTRL_STA); |
| 1846 | |
| 1847 | CHECK_WPA_CTRL(CTRL_STA); |
| 1848 | |
| 1849 | DO_REQUEST(lynq_scan_result_cmd); |
| 1850 | |
| 1851 | count = lynq_split(cmd_reply, reply_len, '\n', split_lines); |
| 1852 | *len = count - 1; |
| 1853 | *list = malloc(sizeof (scan_info_s) * *len); |
| 1854 | |
| 1855 | count_words = lynq_split(split_lines[0], strlen(split_lines[0]), '/', split_words); //@todo get with header |
| 1856 | for (index=0; index <count_words; index++) { |
| 1857 | printf("----header: %s\n", split_words[index]); |
| 1858 | } |
| 1859 | |
| 1860 | for(index = 1;index < count; index++) { |
| 1861 | printf("---- %s\n",split_lines[index]); |
| 1862 | count_words = lynq_split(split_lines[index], strlen(split_lines[index]), '\t', split_words); |
| 1863 | if (count_words < 4) |
| 1864 | continue; |
| 1865 | printf("count: %d, %s\n", count_words, split_words[0]); |
| 1866 | //bssid / frequency / signal level / flags / ssid |
| 1867 | p = (*list) + index - 1; |
| 1868 | strcpy(p->mac, split_words[0]); |
| 1869 | p->band = convert_band_from_freq(atoi(split_words[1])); |
| 1870 | p->rssi = -1 * atoi( split_words[2]); |
| 1871 | p->auth = convert_max_auth_from_flag(split_words[3]); |
| 1872 | strcpy(p->ssid, split_words[4]); |
| 1873 | } |
| 1874 | |
| 1875 | return 0; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1876 | } |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1877 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1878 | int lynq_sta_forget_ap(lynq_wifi_index_e idx, char *ssid, lynq_wifi_auth_s auth) |
| 1879 | { |
| 1880 | int count, net_no, index; |
| 1881 | int net_no_list[128]; |
| 1882 | lynq_wifi_auth_s net_auth; |
| 1883 | char lynq_remove_cmd[MAX_CMD]; |
| 1884 | |
| 1885 | if (ssid == NULL || *ssid == '\0') { |
| 1886 | printf("bad ssid\n"); |
| 1887 | return -1; |
| 1888 | } |
| 1889 | |
| 1890 | CHECK_IDX(idx, CTRL_STA); |
| 1891 | |
| 1892 | CHECK_WPA_CTRL(CTRL_STA); |
| 1893 | |
| 1894 | net_no = -1; |
| 1895 | count = lynq_get_network_number_list(idx, CTRL_STA, net_no_list, ssid); |
| 1896 | |
| 1897 | for (index=0; index < count; index++) { |
| 1898 | net_auth = -1; |
| 1899 | if (0 == inner_get_network_auth(CTRL_STA, net_no_list[index], &net_auth) && net_auth == auth) { |
| 1900 | net_no = net_no_list[index]; |
| 1901 | break; |
| 1902 | } |
| 1903 | } |
| 1904 | |
| 1905 | if (net_no < 0) { |
| 1906 | return 0; |
| 1907 | } |
| 1908 | |
| 1909 | sprintf(lynq_remove_cmd, "REMOVE_NETWORK %d", net_no); |
| 1910 | |
| 1911 | DO_OK_FAIL_REQUEST(lynq_remove_cmd); |
| 1912 | DO_OK_FAIL_REQUEST(cmd_save_config); |
| 1913 | |
| 1914 | return 0; |
| 1915 | } |
| 1916 | |
| 1917 | int lynq_get_sta_saved_ap(lynq_wifi_index_e idx, saved_ap_info_s ** list, int * len) |
| 1918 | { |
| 1919 | int count, index; |
| 1920 | int net_no_list[128]; |
| 1921 | char freq[16]; |
| 1922 | |
| 1923 | if (list == NULL || len == NULL) { |
| 1924 | printf("bad param\n"); |
| 1925 | return -1; |
| 1926 | } |
| 1927 | |
| 1928 | CHECK_IDX(idx, CTRL_STA); |
| 1929 | |
| 1930 | // CHECK_WPA_CTRL(CTRL_STA); |
| 1931 | |
| 1932 | count = lynq_get_network_number_list(idx, CTRL_STA, net_no_list, NULL); |
| 1933 | printf("count is %d\n", count); |
| 1934 | |
| 1935 | *list = malloc(sizeof (saved_ap_info_s) * count); |
| 1936 | *len = count; |
| 1937 | |
| 1938 | for (index=0; index < count; index++) { |
| 1939 | printf("to get ssid %d\n", index); |
| 1940 | inner_get_param(CTRL_STA, net_no_list[index], "ssid", (*list)[index].base_info.ap_ssid); |
| 1941 | printf("to get bssid\n"); |
| 1942 | inner_get_param(CTRL_STA, net_no_list[index], "bssid", (*list)[index].base_info.ap_mac); |
| 1943 | printf("to get inner_get_network_auth\n"); |
| 1944 | inner_get_network_auth(CTRL_STA, net_no_list[index], &(*list)[index].base_info.auth); |
| 1945 | printf("to get frequency\n"); |
| 1946 | if (inner_get_param(CTRL_STA, net_no_list[index], "frequency", freq) == 0) { |
| 1947 | (*list)[index].base_info.band = convert_band_from_freq(atoi(freq)); |
| 1948 | } |
| 1949 | else { |
| 1950 | (*list)[index].base_info.band = -1; |
| 1951 | } |
| 1952 | |
| 1953 | } |
| 1954 | |
| 1955 | return 0; |
| 1956 | } |
| 1957 | |
| 1958 | int lynq_wifi_sta_start_scan(lynq_wifi_index_e idx) |
| 1959 | { |
| 1960 | const char *lynq_scan_cmd = "SCAN"; |
| 1961 | |
| 1962 | CHECK_IDX(idx, CTRL_STA); |
| 1963 | |
| 1964 | CHECK_WPA_CTRL(CTRL_STA); |
| 1965 | |
| 1966 | DO_OK_FAIL_REQUEST(lynq_scan_cmd); |
| 1967 | |
| 1968 | return 0; |
| 1969 | } |
| 1970 | |
| 1971 | int lynq_reg_ap_event_callback(void * priv, AP_CALLBACK_FUNC_PTR cb) { |
| 1972 | if (cb == NULL) { |
| 1973 | return -1; |
| 1974 | } |
| 1975 | |
| 1976 | g_ap_callback_priv = priv; |
| 1977 | g_ap_callback_func = cb; |
| 1978 | |
| 1979 | return 0; |
| 1980 | } |
| 1981 | |
| 1982 | int lynq_unreg_ap_event_callback(void * priv) { |
| 1983 | if (g_ap_callback_priv == priv) { |
| 1984 | g_ap_callback_func = NULL; |
| 1985 | g_ap_callback_priv = NULL; |
| 1986 | return 0; |
| 1987 | } |
| 1988 | return -1; |
| 1989 | } |
| 1990 | |
| 1991 | int lynq_reg_sta_event_callback(void * priv, STA_CALLBACK_FUNC_PTR cb){ |
| 1992 | if (cb == NULL) { |
| 1993 | return -1; |
| 1994 | } |
| 1995 | |
| 1996 | g_sta_callback_priv = priv; |
| 1997 | g_sta_callback_func = cb; |
| 1998 | |
| 1999 | return 0; |
| 2000 | } |
| 2001 | |
| 2002 | int lynq_unreg_sta_event_callback(void * priv) { |
| 2003 | if (g_sta_callback_priv == priv) { |
| 2004 | g_sta_callback_func = NULL; |
| 2005 | g_sta_callback_priv = NULL; |
| 2006 | return 0; |
| 2007 | } |
| 2008 | return -1; |
| 2009 | } |
| 2010 | |
| 2011 | |
| 2012 | static int inner_get_status_info_state (int interface, char *state) { |
| 2013 | curr_status_info curr_state; |
| 2014 | curr_state.ap = NULL; |
| 2015 | curr_state.state = state; |
| 2016 | return inner_get_status_info(interface, &curr_state); |
| 2017 | } |
| 2018 | |
| 2019 | int lynq_get_ap_status(lynq_wifi_index_e idx, lynq_wifi_ap_run_status_s * ap_status) |
| 2020 | { |
| 2021 | char state[MAX_CMD]; |
| 2022 | const char * STATE_COMPLETED = "COMPLETED"; |
| 2023 | CHECK_IDX(idx, CTRL_AP); |
| 2024 | |
| 2025 | if (inner_get_status_info_state(CTRL_AP, state) != 0) { |
| 2026 | *ap_status = LYNQ_WIFI_AP_STATUS_DISABLE; |
| 2027 | return 0; |
| 2028 | } |
| 2029 | |
| 2030 | if (memcmp(state, STATE_COMPLETED, strlen (STATE_COMPLETED)) == 0) { |
| 2031 | *ap_status = LYNQ_WIFI_AP_STATUS_ENABLE; |
| 2032 | } |
| 2033 | else { |
| 2034 | *ap_status = LYNQ_WIFI_AP_STATUS_DISABLE; |
| 2035 | } |
| 2036 | |
| 2037 | return 0; |
| 2038 | } |
| 2039 | |
| 2040 | int lynq_get_sta_status(lynq_wifi_index_e idx, lynq_wifi_sta_run_status_s * sta_status) { |
| 2041 | char state[MAX_CMD]; |
| 2042 | const char * STATE_COMPLETED = "COMPLETED"; |
| 2043 | CHECK_IDX(idx, CTRL_STA); |
| 2044 | |
| 2045 | if (inner_get_status_info_state(CTRL_STA, state) != 0) { |
| 2046 | *sta_status = LYNQ_WIFI_STA_STATUS_DISABLE; |
| 2047 | return 0; |
| 2048 | } |
| 2049 | |
| 2050 | if (memcmp(state, STATE_COMPLETED, strlen (STATE_COMPLETED)) == 0) { |
| 2051 | *sta_status = LYNQ_WIFI_STA_STATUS_ENABLE; |
| 2052 | } |
| 2053 | else { |
| 2054 | *sta_status = LYNQ_WIFI_STA_STATUS_DISABLE; |
| 2055 | } |
| 2056 | |
| 2057 | return 0; |
| 2058 | } |
| 2059 | |
| 2060 | int lynq_get_country_code(lynq_wifi_index_e idx, char * country_code) { |
| 2061 | // CHECK_IDX(idx, CTRL_AP); |
| 2062 | // int ret = 0; |
| 2063 | // size_t reply_len = MAX_RET; |
| 2064 | // char cmd_reply[MAX_RET]={0}; |
| 2065 | // const char * cmd_str = "GET country"; |
| 2066 | // struct wpa_ctrl *s_lynq_wpa_ctrl = NULL; |
| 2067 | // do{ |
| 2068 | // if (NULL == s_lynq_wpa_ctrl) { |
| 2069 | // s_lynq_wpa_ctrl = wpa_ctrl_open("/var/run/wpa_wlan0_cmd"); |
| 2070 | // if (NULL == s_lynq_wpa_ctrl ) { |
| 2071 | // printf("wpa_ctrl_open fail\n"); |
| 2072 | // return -1; |
| 2073 | // } |
| 2074 | // } |
| 2075 | // }while(0); |
| 2076 | |
| 2077 | // do { |
| 2078 | // reply_len = MAX_RET; |
| 2079 | // cmd_reply[0] = '\0'; |
| 2080 | // printf("to call [%s]\n", cmd_str); |
| 2081 | // ret = wpa_ctrl_request(s_lynq_wpa_ctrl, cmd_str, strlen(cmd_str), cmd_reply, &reply_len, NULL); |
| 2082 | // if (ret != 0) { |
| 2083 | // printf("call ##cmd_str fail %d\n", ret); |
| 2084 | // return ret; |
| 2085 | // } |
| 2086 | // cmd_reply[reply_len+1] = '\0'; |
| 2087 | // printf("cmd replay [ %s ]\n", cmd_reply); |
| 2088 | // }while(0); |
| 2089 | |
| 2090 | FILE *fp; |
| 2091 | size_t i = 0; |
| 2092 | char lynq_cmd_ret[MAX_RET]={0}; |
| 2093 | |
| 2094 | // CHECK_IDX(idx, CTRL_AP); |
| 2095 | |
| 2096 | if((fp=popen("wl country","r"))==NULL) |
| 2097 | { |
| 2098 | perror("popen error!"); |
| 2099 | return -1; |
| 2100 | } |
| 2101 | if((fread(lynq_cmd_ret,sizeof(lynq_cmd_ret),1,fp))<0) |
| 2102 | { |
| 2103 | perror("fread fail!"); |
| 2104 | return -1; |
| 2105 | } |
| 2106 | |
| 2107 | for(i=0; i < strlen(lynq_cmd_ret); i++) { |
| 2108 | if (lynq_cmd_ret[i] == ' ') { |
| 2109 | lynq_cmd_ret[i] = '\0'; |
| 2110 | break; |
| 2111 | } |
| 2112 | } |
| 2113 | |
| 2114 | strcpy(country_code,lynq_cmd_ret); |
| 2115 | printf("---country code %s\n", country_code); |
| 2116 | |
| 2117 | int ret=pclose(fp); |
| 2118 | if(ret==-1) |
| 2119 | { |
| 2120 | perror("close file faild"); |
| 2121 | } |
| 2122 | |
| 2123 | return 0; |
| 2124 | } |
| 2125 | |
| 2126 | int lynq_set_country_code(lynq_wifi_index_e idx, char * country_code) { |
| 2127 | // const char * cmd_str = "GET country"; |
| 2128 | // CHECK_IDX(idx, CTRL_AP); |
| 2129 | // CHECK_WPA_CTRL(CTRL_STA); |
| 2130 | |
| 2131 | // DO_REQUEST(cmd_str); |
| 2132 | // printf("result %s\n", cmd_reply); |
| 2133 | |
| 2134 | if (country_code == NULL || *country_code == '\0') { |
| 2135 | printf("bad country code\n"); |
| 2136 | return -1; |
| 2137 | } |
| 2138 | |
| 2139 | char lynq_country_cmd[MAX_CMD]; |
| 2140 | sprintf(lynq_country_cmd, "wl country %s", country_code); |
| 2141 | if (system(lynq_country_cmd) == 0) { |
| 2142 | return 0; |
| 2143 | } |
| 2144 | |
| 2145 | return -1; |
| 2146 | } |
| 2147 | |
| 2148 | int lynq_get_connect_ap_mac(lynq_wifi_index_e idx,char *mac) |
| 2149 | { |
| 2150 | if (mac == NULL) { |
| 2151 | return -1; |
| 2152 | } |
| 2153 | |
| 2154 | CHECK_IDX(idx, CTRL_STA); |
| 2155 | ap_info_s ap; |
| 2156 | ap.ap_mac[0] = '\0'; |
| 2157 | |
| 2158 | if (inner_get_status_info_ap(CTRL_STA, &ap) != 0) { |
| 2159 | return -1; |
| 2160 | } |
| 2161 | strcpy(mac, ap.ap_mac); |
| 2162 | |
| 2163 | return 0; |
| 2164 | } |
| 2165 | |
| 2166 | int lynq_get_interface_ip(lynq_wifi_index_e idx, char *ip) |
| 2167 | { |
| 2168 | struct ifaddrs *ifaddr, *ifa; |
| 2169 | int family, s; |
| 2170 | char host[NI_MAXHOST]; |
| 2171 | const char * ifaName = "wlan0"; |
| 2172 | if (idx == 1) { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2173 | ifaName = "tether"; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2174 | } |
| 2175 | else if (idx != 0) { |
| 2176 | return -1; |
| 2177 | } |
| 2178 | |
| 2179 | if (getifaddrs(&ifaddr) == -1) |
| 2180 | { |
| 2181 | perror("getifaddrs"); |
| 2182 | return -1; |
| 2183 | //exit(EXIT_FAILURE); |
| 2184 | } |
| 2185 | |
| 2186 | |
| 2187 | for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) |
| 2188 | { |
| 2189 | if (ifa->ifa_addr == NULL) |
| 2190 | continue; |
| 2191 | host[0] = '\0'; |
| 2192 | s=getnameinfo(ifa->ifa_addr,sizeof(struct sockaddr_in),host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); |
| 2193 | |
| 2194 | printf("inter face %s-%s, ip %s, %d - %d \n", ifa->ifa_name, ifaName, host,ifa->ifa_addr->sa_family, AF_INET); |
| 2195 | if((strcmp(ifa->ifa_name,ifaName)==0)) |
| 2196 | { |
| 2197 | if (s != 0) |
| 2198 | { |
| 2199 | // printf("getnameinfo() failed: %s", gai_strerror(s)); |
| 2200 | //exit(EXIT_FAILURE); |
| 2201 | } |
| 2202 | freeifaddrs(ifaddr); |
| 2203 | strcpy(ip, host); |
| 2204 | printf("ip %s\n", ip); |
| 2205 | return 0; |
| 2206 | //printf(" Interface : <%s>",ifa->ifa_name ); |
| 2207 | //printf(" Address : <%s>", host); |
| 2208 | } |
| 2209 | } |
| 2210 | return -1; |
| 2211 | } |
| 2212 | |
| 2213 | int lynq_get_interface_mac(lynq_wifi_index_e idx,char *mac) |
| 2214 | { |
| 2215 | int count; |
| 2216 | size_t i; |
| 2217 | char *split_words[128] = {0}; |
| 2218 | const char *lynq_get_mac_cmd = "DRIVER MACADDR"; |
| 2219 | |
| 2220 | CHECK_WPA_CTRL(idx); |
| 2221 | |
| 2222 | DO_REQUEST(lynq_get_mac_cmd); |
| 2223 | |
| 2224 | if (memcmp(cmd_reply, "FAIL", 4) == 0) { |
| 2225 | return -1; |
| 2226 | } |
| 2227 | |
| 2228 | count = lynq_split(cmd_reply, reply_len, '=', split_words); |
| 2229 | |
| 2230 | if (count < 2) { |
| 2231 | return -1; |
| 2232 | } |
| 2233 | |
| 2234 | for (i=0; i < strlen(split_words[1]); i++ ) { |
| 2235 | if (split_words[1][i] != ' ') { |
| 2236 | break; |
| 2237 | } |
| 2238 | } |
| 2239 | |
| 2240 | strcpy(mac, split_words[1] + i); |
| 2241 | |
| 2242 | return 0; |
| 2243 | } |
| 2244 | |
| 2245 | int lynq_get_connect_ap_rssi(lynq_wifi_index_e idx,int * rssi) |
| 2246 | { |
| 2247 | // int count; |
| 2248 | // char *split_words[128] = {0}; |
| 2249 | // const char *lynq_get_rssi_cmd = "DRIVER RSSI"; |
| 2250 | |
| 2251 | // if (rssi == NULL) { |
| 2252 | // return -1; |
| 2253 | // } |
| 2254 | |
| 2255 | // CHECK_IDX(idx, CTRL_STA); |
| 2256 | |
| 2257 | // CHECK_WPA_CTRL(CTRL_STA); |
| 2258 | |
| 2259 | // DO_REQUEST(lynq_get_rssi_cmd); |
| 2260 | |
| 2261 | // if (memcmp(cmd_reply, "FAIL", 4) == 0) { |
| 2262 | // return -1; |
| 2263 | // } |
| 2264 | |
| 2265 | // count = lynq_split(cmd_reply, reply_len, ' ', split_words); |
| 2266 | |
| 2267 | // if (count < 2) { |
| 2268 | // return -1; |
| 2269 | // } |
| 2270 | |
| 2271 | // *rssi = atoi(split_words[1]) * -1; |
| 2272 | |
| 2273 | FILE *fp; |
| 2274 | size_t i = 0; |
| 2275 | char lynq_cmd_ret[MAX_RET]={0}; |
| 2276 | |
| 2277 | // CHECK_IDX(idx, CTRL_AP); |
| 2278 | |
| 2279 | if((fp=popen("wl country","r"))==NULL) |
| 2280 | { |
| 2281 | perror("popen error!"); |
| 2282 | return -1; |
| 2283 | } |
| 2284 | if((fread(lynq_cmd_ret,sizeof(lynq_cmd_ret),1,fp))<0) |
| 2285 | { |
| 2286 | perror("fread fail!"); |
| 2287 | return -1; |
| 2288 | } |
| 2289 | *rssi = atoi(lynq_cmd_ret); |
| 2290 | |
| 2291 | return 0; |
| 2292 | } |
| 2293 | |
| 2294 | int lynq_get_connect_ap_band(lynq_wifi_index_e idx, lynq_wifi_band_m * band) |
| 2295 | { |
| 2296 | if (band == NULL) { |
| 2297 | return -1; |
| 2298 | } |
| 2299 | |
| 2300 | CHECK_IDX(idx, CTRL_STA); |
| 2301 | ap_info_s ap; |
| 2302 | ap.band = -1; |
| 2303 | |
| 2304 | if (inner_get_status_info_ap(CTRL_STA, &ap) != 0) { |
| 2305 | return -1; |
| 2306 | } |
| 2307 | *band = ap.band; |
| 2308 | |
| 2309 | return 0; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2310 | } |