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 | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 24 | #include "log/log.h" |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 25 | #include <sys/time.h> |
| 26 | #include <asm/errno.h> |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 27 | |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 28 | #ifdef __cplusplus |
| 29 | extern "C" { |
| 30 | #endif |
| 31 | #ifdef __cplusplus |
| 32 | } |
| 33 | #endif |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 34 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 35 | #undef LOG_TAG |
| 36 | #define LOG_TAG "LYNQ_WIFI" |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 37 | #define MAX_CMD 128 |
| 38 | #define MAX_RET 4096 |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 39 | #define MODE_LEN 10 |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 40 | #define CTRL_STA 0 |
| 41 | #define CTRL_AP 1 |
| 42 | #define AP_NETWORK_0 0 |
| 43 | |
| 44 | pthread_t g_ap_watcher_pid = 0; |
| 45 | volatile int g_ap_watcher_stop_flag = 0; |
you.chen | a6fa5b2 | 2022-05-18 10:28:19 +0800 | [diff] [blame] | 46 | volatile int g_ap_watcher_started_flag = 0; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 47 | |
| 48 | pthread_t g_sta_watcher_pid = 0; |
| 49 | volatile int g_sta_watcher_stop_flag = 0; |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 50 | volatile int g_sta_scan_finish_flag = 1; |
you.chen | a6fa5b2 | 2022-05-18 10:28:19 +0800 | [diff] [blame] | 51 | volatile int g_sta_watcher_started_flag = 0; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 52 | |
| 53 | void * g_ap_callback_priv = NULL; |
| 54 | AP_CALLBACK_FUNC_PTR g_ap_callback_func = NULL; |
| 55 | void * g_sta_callback_priv = NULL; |
| 56 | STA_CALLBACK_FUNC_PTR g_sta_callback_func = NULL; |
| 57 | |
| 58 | //const char * CTRL_PATH="/var/run/wpa_supplicant"; |
| 59 | const char * CTRL_PATH[2] = {"/var/run/wpa_supplicant/wlan0", "/var/run/wpa_supplicant/ap0"}; |
| 60 | //const char * CTRL_PATH[2] = {"/var/run/wpa_supplicant/wlan0", "/var/run/wpa_supplicant/wlan0"}; |
| 61 | const char * cmd_list_networks = "LIST_NETWORKS"; |
| 62 | const char * cmd_save_config = "SAVE_CONFIG"; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 63 | const char * cmd_disconnect = "DISCONNECT"; |
| 64 | const char * cmd_remove_all = "REMOVE_NETWORK all"; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 65 | const char * state_scan_result = "CTRL-EVENT-SCAN-RESULTS"; |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 66 | const char * STATE_COMPLETED = "COMPLETED"; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 67 | |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 68 | const char * cmd_ping = "PING"; |
| 69 | const char * rsp_pong = "PONG"; |
| 70 | const int SLEEP_TIME_ON_IDLE = 100 * 1000; // usecond |
| 71 | const int MAX_IDLE_COUNT = 600; // 60s |
| 72 | |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 73 | struct local_wpa_ctrl{ |
| 74 | struct wpa_ctrl *ctrl; |
| 75 | pthread_mutex_t mutex; |
| 76 | }; |
| 77 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 78 | |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 79 | static pthread_mutex_t s_check_wpa_ctrl_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 80 | |
| 81 | static struct local_wpa_ctrl * g_lynq_wpa_ctrl[2] = {0}; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 82 | |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 83 | //you.chen add for tv-box start |
| 84 | volatile int g_gbw_enabled = 0; |
| 85 | char * g_gbw_mac = NULL; |
| 86 | pthread_t g_gbw_watcher_pid = 0; |
| 87 | static int startGBW(); |
| 88 | static int stopGBW(); |
| 89 | //you.chen add for tv-box end |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 90 | |
| 91 | typedef struct __curr_status_info { |
| 92 | ap_info_s *ap; |
| 93 | char * state; |
| 94 | int net_no; |
| 95 | }curr_status_info; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 96 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 97 | typedef enum { |
| 98 | INNER_STA_STATUS_INIT = 0, |
| 99 | INNER_STA_STATUS_CONNECTING, |
| 100 | INNER_STA_STATUS_ASSOCIATING, |
| 101 | INNER_STA_STATUS_ASSOCIATED, |
| 102 | INNER_STA_STATUS_CONNECTED, |
| 103 | INNER_STA_STATUS_DISCONNECTING, |
| 104 | INNER_STA_STATUS_DISCONNECTED, |
| 105 | INNER_STA_STATUS_CANCEL, |
| 106 | }inner_sta_status_s; |
| 107 | |
| 108 | static pthread_cond_t s_global_check_cond = PTHREAD_COND_INITIALIZER; |
| 109 | static pthread_mutex_t s_global_check_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 110 | static inner_sta_status_s s_sta_status = INNER_STA_STATUS_INIT; |
| 111 | static error_number_s s_sta_error_number = -1; |
| 112 | static char s_sta_current_connecting_ssid[64] = {0}; |
| 113 | static struct timespec s_sta_connect_timeout; |
| 114 | const int MAX_CONNNECT_TIME = 15; // second |
| 115 | pthread_t g_global_watcher_pid = 0; |
| 116 | static int s_service_invoke_timeout_cnt=0; |
| 117 | const int FAKE_MAX_INT_VALUE = 99999; |
| 118 | |
| 119 | static void notify_service_invoke_fail(int error) |
| 120 | { |
| 121 | struct local_wpa_ctrl *lynq_wpa_ctrl = NULL; |
| 122 | pthread_mutex_lock(&s_global_check_mutex); |
| 123 | if (error == -2) //timeout |
| 124 | { |
| 125 | s_service_invoke_timeout_cnt++; |
| 126 | if (s_service_invoke_timeout_cnt > 10) |
| 127 | { |
| 128 | pthread_cond_signal(&s_global_check_cond); |
| 129 | } |
| 130 | } |
| 131 | else if (error == -1) |
| 132 | { |
| 133 | // check if can connect wpa service |
| 134 | lynq_wpa_ctrl = wpa_ctrl_open(CTRL_PATH[0]); |
| 135 | if (lynq_wpa_ctrl == NULL) |
| 136 | { |
| 137 | s_service_invoke_timeout_cnt = FAKE_MAX_INT_VALUE; |
| 138 | pthread_cond_signal(&s_global_check_cond); |
| 139 | } |
| 140 | wpa_ctrl_close(lynq_wpa_ctrl); |
| 141 | lynq_wpa_ctrl = wpa_ctrl_open(CTRL_PATH[1]); |
| 142 | if (lynq_wpa_ctrl == NULL) |
| 143 | { |
| 144 | s_service_invoke_timeout_cnt = FAKE_MAX_INT_VALUE; |
| 145 | pthread_cond_signal(&s_global_check_cond); |
| 146 | } |
| 147 | wpa_ctrl_close(lynq_wpa_ctrl); |
| 148 | } |
| 149 | |
| 150 | pthread_mutex_unlock(&s_global_check_mutex); |
| 151 | } |
| 152 | |
| 153 | static void check_tether_and_notify() |
| 154 | { |
| 155 | RLOGD("check_tether_and_notify called"); |
| 156 | if (0 == system("ifconfig | grep tether")) |
| 157 | { |
| 158 | return; |
| 159 | } |
| 160 | pthread_mutex_lock(&s_global_check_mutex); |
| 161 | s_service_invoke_timeout_cnt = FAKE_MAX_INT_VALUE; |
| 162 | pthread_cond_signal(&s_global_check_cond); |
| 163 | pthread_mutex_unlock(&s_global_check_mutex); |
| 164 | } |
| 165 | |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 166 | static int local_wpa_ctrl_request(struct local_wpa_ctrl *ctrl, const char *cmd, size_t cmd_len, |
| 167 | char *reply, size_t *reply_len, |
| 168 | void (*msg_cb)(char *msg, size_t len)) |
| 169 | { |
| 170 | int ret; |
| 171 | if (ctrl->ctrl == NULL) { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 172 | RLOGE("local_wpa_ctrl_request ctrl is null\n"); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 173 | return -1; |
| 174 | } |
| 175 | pthread_mutex_lock(&ctrl->mutex); |
| 176 | ret = wpa_ctrl_request(ctrl->ctrl, cmd, cmd_len, reply, reply_len, msg_cb); |
| 177 | pthread_mutex_unlock(&ctrl->mutex); |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 178 | if (ret != 0) |
| 179 | { |
| 180 | notify_service_invoke_fail(ret); |
| 181 | } |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 182 | return ret; |
| 183 | } |
| 184 | |
| 185 | static struct local_wpa_ctrl * inner_get_wpa_ctrl(int index) { |
| 186 | int repeat_cnt; |
| 187 | struct local_wpa_ctrl *lynq_wpa_ctrl = NULL; |
| 188 | pthread_mutex_lock(&s_check_wpa_ctrl_mutex); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 189 | RLOGD("inner_get_wpa_ctrl\n"); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 190 | for (repeat_cnt = 0; repeat_cnt < 5 && NULL == g_lynq_wpa_ctrl[index]; repeat_cnt++) { |
| 191 | pthread_mutex_unlock(&s_check_wpa_ctrl_mutex); |
| 192 | // printf("wait enable finish\n"); |
| 193 | usleep(500 * 1000); |
| 194 | pthread_mutex_lock(&s_check_wpa_ctrl_mutex); |
| 195 | } |
| 196 | if (NULL == g_lynq_wpa_ctrl[index]) { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 197 | RLOGE("NULL == g_lynq_wpa_ctrl[index]"); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 198 | goto out_addr; |
| 199 | } |
| 200 | if (NULL == g_lynq_wpa_ctrl[index]->ctrl) { |
| 201 | g_lynq_wpa_ctrl[index]->ctrl = wpa_ctrl_open(CTRL_PATH[index]); |
| 202 | if (NULL == g_lynq_wpa_ctrl[index]->ctrl) { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 203 | RLOGE("wpa_ctrl_open fail\n"); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 204 | goto out_addr; |
| 205 | } |
| 206 | pthread_mutex_init(&g_lynq_wpa_ctrl[index]->mutex, NULL); |
| 207 | } |
| 208 | lynq_wpa_ctrl = g_lynq_wpa_ctrl[index]; |
| 209 | out_addr: |
| 210 | pthread_mutex_unlock(&s_check_wpa_ctrl_mutex); |
| 211 | return lynq_wpa_ctrl; |
| 212 | } |
| 213 | |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 214 | #define PRINT_AND_RETURN_VALUE(str,value) \ |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 215 | {\ |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 216 | perror((str));\ |
| 217 | return (value);\ |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 218 | } |
| 219 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 220 | #define CHECK_IDX(idx, type) do { \ |
| 221 | if ( (idx == LYNQ_WIFI_INTERFACE_0 && type != CTRL_STA) || (idx == LYNQ_WIFI_INTERFACE_1 && type != CTRL_AP) \ |
| 222 | || idx < LYNQ_WIFI_INTERFACE_0 || idx > LYNQ_WIFI_INTERFACE_1 ) { \ |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 223 | RLOGE("not support create [%s] on interface [%d]\n", (type == CTRL_STA ? "station" : "ap"), idx); \ |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 224 | return -1; \ |
| 225 | } \ |
| 226 | }while (0) |
| 227 | |
| 228 | #define CHECK_WPA_CTRL(index) int ret = 0;\ |
| 229 | size_t reply_len = MAX_RET; \ |
| 230 | char cmd_reply[MAX_RET]={0}; \ |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 231 | struct local_wpa_ctrl *lynq_wpa_ctrl = NULL; \ |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 232 | do{ \ |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 233 | lynq_wpa_ctrl = inner_get_wpa_ctrl(index); \ |
| 234 | if (NULL == lynq_wpa_ctrl) return -1; \ |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 235 | }while(0) |
| 236 | |
| 237 | #define DO_REQUEST(cmd_str) do { \ |
| 238 | reply_len = MAX_RET;\ |
| 239 | cmd_reply[0] = '\0'; \ |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 240 | RLOGD("to call [%s]\n", cmd_str); \ |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 241 | ret = local_wpa_ctrl_request(lynq_wpa_ctrl, cmd_str, strlen(cmd_str), cmd_reply, &reply_len, NULL); \ |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 242 | if (ret != 0) { \ |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 243 | RLOGE("call "#cmd_str" fail %d\n", ret); \ |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 244 | return ret; \ |
| 245 | } \ |
| 246 | cmd_reply[reply_len+1] = '\0'; \ |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 247 | RLOGD("cmd replay [ %s ]\n", cmd_reply); \ |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 248 | }while(0) |
| 249 | |
| 250 | #define DO_OK_FAIL_REQUEST(cmd_str) do { \ |
| 251 | DO_REQUEST(cmd_str); \ |
| 252 | if (reply_len >=4 && memcmp(cmd_reply, "FAIL", 4) == 0 ) {\ |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 253 | RLOGE("cmd "#cmd_str" return FAIL\n"); \ |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 254 | return -1; \ |
| 255 | } else if (reply_len >=2 && memcmp(cmd_reply, "OK", 2) != 0) { \ |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 256 | RLOGE("cmd "#cmd_str" return not OK|FAIL\n"); \ |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 257 | return -1; \ |
| 258 | } \ |
| 259 | }while (0) |
| 260 | |
| 261 | |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 262 | static int exec_cmd(const char *str_cmd, char * str_cmd_ret, size_t max_len); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 263 | |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 264 | static int check_connection(struct wpa_ctrl * wpa_ctrl) |
| 265 | { |
| 266 | size_t reply_len = MAX_RET; |
| 267 | char cmd_reply[MAX_RET]={0}; |
| 268 | int ret; |
| 269 | |
| 270 | RLOGD("check_connection [%p]", wpa_ctrl); |
| 271 | ret = wpa_ctrl_request(wpa_ctrl, cmd_ping, strlen(cmd_ping), cmd_reply, &reply_len, NULL); |
| 272 | |
| 273 | if (ret != 0 || reply_len < 4 || memcmp(cmd_reply, rsp_pong, 4) != 0) |
| 274 | { |
| 275 | RLOGE("check_connection error: ctrl [%p], ret [%d], reply_len [%d], rsp [%s]", wpa_ctrl, ret, reply_len, cmd_reply); |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 276 | if (ret != 0) |
| 277 | { |
| 278 | notify_service_invoke_fail(ret); |
| 279 | } |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 280 | return -1; |
| 281 | } |
| 282 | |
| 283 | return 0; |
| 284 | } |
| 285 | |
| 286 | /** |
| 287 | * @brief check_pending_msg |
| 288 | * @param lynq_wpa_ctrl |
| 289 | * @return 1 has msg, 0 no msg, -1 error |
| 290 | */ |
| 291 | static int check_pending_msg(struct wpa_ctrl ** pp_lynq_wpa_ctrl, int type, int* idle_count, int *started_flag) |
| 292 | { |
| 293 | int ret; |
| 294 | |
| 295 | if (*pp_lynq_wpa_ctrl == NULL) // need connect |
| 296 | { |
| 297 | *pp_lynq_wpa_ctrl = wpa_ctrl_open(CTRL_PATH[type]); //@todo temp change |
| 298 | if (*pp_lynq_wpa_ctrl == NULL) |
| 299 | { |
| 300 | usleep(SLEEP_TIME_ON_IDLE); |
| 301 | return -1; |
| 302 | } |
| 303 | |
| 304 | ret = wpa_ctrl_attach(*pp_lynq_wpa_ctrl); |
| 305 | if (ret == 0) // attach success |
| 306 | { |
| 307 | *started_flag = 1; |
| 308 | } |
| 309 | else |
| 310 | { |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 311 | RLOGE("[wifi error]sta watch thread wpa_ctrl_attach fail"); |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 312 | wpa_ctrl_close(*pp_lynq_wpa_ctrl); |
| 313 | *pp_lynq_wpa_ctrl = NULL; |
| 314 | *idle_count = 0; |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 315 | notify_service_invoke_fail(-2); |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 316 | usleep(SLEEP_TIME_ON_IDLE); |
| 317 | return -1; |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | ret = wpa_ctrl_pending(*pp_lynq_wpa_ctrl); |
| 322 | if ( ret == 0) // no pending messages |
| 323 | { |
| 324 | usleep(SLEEP_TIME_ON_IDLE); |
| 325 | *idle_count += 1; |
| 326 | if (*idle_count > MAX_IDLE_COUNT) |
| 327 | { |
| 328 | if (check_connection(*pp_lynq_wpa_ctrl) != 0) |
| 329 | { |
| 330 | wpa_ctrl_detach(*pp_lynq_wpa_ctrl); |
| 331 | wpa_ctrl_close(*pp_lynq_wpa_ctrl); |
| 332 | *pp_lynq_wpa_ctrl = NULL; |
| 333 | *idle_count = 0; |
| 334 | return -1; |
| 335 | } |
| 336 | *idle_count = 0; |
| 337 | } |
| 338 | return 0; |
| 339 | } |
| 340 | else if ( ret == -1) // on error |
| 341 | { |
| 342 | RLOGE("[wifi error]sta wpa_ctrl_pending"); |
| 343 | wpa_ctrl_detach(*pp_lynq_wpa_ctrl); |
| 344 | wpa_ctrl_close(*pp_lynq_wpa_ctrl); |
| 345 | *pp_lynq_wpa_ctrl = NULL; |
| 346 | *idle_count = 0; |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 347 | notify_service_invoke_fail(ret); |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 348 | return -1; |
| 349 | } |
| 350 | |
| 351 | *idle_count = 0; |
| 352 | return 1; |
| 353 | } |
| 354 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 355 | static void APWatcherThreadProc() { |
| 356 | size_t len = MAX_RET; |
| 357 | char msg_notify[MAX_RET]; |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 358 | int idle_count = 0; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 359 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 360 | struct wpa_ctrl *lynq_wpa_ctrl = NULL; |
you.chen | 92fd5d3 | 2022-05-25 10:09:47 +0800 | [diff] [blame] | 361 | g_ap_watcher_stop_flag = 0; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 362 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 363 | while (g_ap_watcher_stop_flag == 0) |
| 364 | { |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 365 | if (check_pending_msg(&lynq_wpa_ctrl, CTRL_AP, &idle_count, &g_ap_watcher_started_flag) != 1) |
| 366 | { |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 367 | if (g_ap_callback_func != NULL && idle_count == MAX_IDLE_COUNT - 100 ) |
| 368 | { |
| 369 | check_tether_and_notify(); |
| 370 | } |
| 371 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 372 | continue; |
| 373 | } |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 374 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 375 | memset(msg_notify, 0, MAX_RET); |
| 376 | len = MAX_RET; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 377 | if (!wpa_ctrl_recv(lynq_wpa_ctrl, msg_notify, &len)) |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 378 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 379 | msg_notify[len+1] = '\0'; |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 380 | RLOGD("APWatcherThreadProc ap------> %s\n", msg_notify); |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 381 | //you.chen change for tv-box start |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 382 | if (strstr(msg_notify, "AP-STA-DISCONNECTED") != NULL) |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 383 | { |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 384 | if (g_ap_callback_func != NULL) |
| 385 | g_ap_callback_func(g_ap_callback_priv, LYNQ_WIFI_STATUS_DISCONNECT); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 386 | if (g_gbw_enabled == 1 && g_gbw_mac != NULL) |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 387 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 388 | RLOGD("disconect %d, %s ,%s\n", g_gbw_enabled, g_gbw_mac, strstr(msg_notify, (const char*)g_gbw_mac)); |
| 389 | if (strstr(msg_notify, (const char*)g_gbw_mac) != NULL) |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 390 | { |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 391 | stopGBW(); |
| 392 | } |
| 393 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 394 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 395 | else if (strstr(msg_notify, "AP-STA-CONNECTED") != NULL) |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 396 | { |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 397 | if (g_ap_callback_func != NULL) |
| 398 | g_ap_callback_func(g_ap_callback_priv, LYNQ_WIFI_STATUS_CONNECT); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 399 | if (g_gbw_enabled == 1 && g_gbw_mac != NULL) |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 400 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 401 | RLOGD("conect %d, %s ,%s\n", g_gbw_enabled, g_gbw_mac, strstr(msg_notify, (const char*)g_gbw_mac)); |
| 402 | if (strstr(msg_notify, (const char*)g_gbw_mac) != NULL) |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 403 | { |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 404 | startGBW(); |
| 405 | } |
| 406 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 407 | } |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 408 | //you.chen add for tv-box end |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 409 | } // end if (!wpa_ctrl_recv(lynq_wpa_ctrl, msg_notify, &len)) |
| 410 | } // end while (g_ap_watcher_stop_flag == 0) |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 411 | if (lynq_wpa_ctrl != NULL) |
| 412 | { |
you.chen | 92fd5d3 | 2022-05-25 10:09:47 +0800 | [diff] [blame] | 413 | wpa_ctrl_detach(lynq_wpa_ctrl); |
| 414 | wpa_ctrl_close(lynq_wpa_ctrl); |
| 415 | } |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 416 | } |
| 417 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 418 | static void inner_check_connect_error(const char * event_msg, lynq_wifi_sta_status_s state, error_number_s error_num) |
| 419 | { |
| 420 | char * p; |
| 421 | const char * try_associat_flag = "Trying to associate"; |
| 422 | const char * associated_flag = "Associated with "; |
| 423 | |
| 424 | pthread_mutex_lock(&s_global_check_mutex); |
| 425 | if (s_sta_status < INNER_STA_STATUS_CONNECTING || s_sta_status >= INNER_STA_STATUS_CONNECTED) //not in connecting stage, egnore |
| 426 | { |
| 427 | pthread_mutex_unlock(&s_global_check_mutex); |
| 428 | return; |
| 429 | } |
| 430 | |
| 431 | if (state == LYNQ_WIFI_STATUS_EGNORE) |
| 432 | { |
| 433 | if (strstr(event_msg, try_associat_flag) != NULL && strstr(event_msg, s_sta_current_connecting_ssid) != NULL) //associating request ssid |
| 434 | { |
| 435 | s_sta_status = INNER_STA_STATUS_ASSOCIATING; |
| 436 | } |
| 437 | else if (s_sta_status == INNER_STA_STATUS_ASSOCIATING && (p=strstr(event_msg, associated_flag)) != NULL) |
| 438 | { |
| 439 | s_sta_status = INNER_STA_STATUS_ASSOCIATED; |
| 440 | } |
| 441 | } |
| 442 | else if (state == LYNQ_WIFI_STA_STATUS_DISCONNECT) |
| 443 | { |
| 444 | s_sta_error_number = error_num; |
| 445 | if (s_sta_status >= INNER_STA_STATUS_ASSOCIATING && strstr(event_msg, "CTRL-EVENT-SSID-TEMP-DISABLED") != NULL && error_num != LYNQ_WAIT_CONNECT_ACTIVE) |
| 446 | { |
| 447 | s_sta_status = INNER_STA_STATUS_DISCONNECTED; |
| 448 | pthread_cond_signal(&s_global_check_cond); |
| 449 | } |
| 450 | } |
| 451 | else if (state == LYNQ_WIFI_STA_STATUS_CONNECT) |
| 452 | { |
| 453 | s_sta_status = INNER_STA_STATUS_CONNECTED; |
| 454 | pthread_cond_signal(&s_global_check_cond); |
| 455 | } |
| 456 | pthread_mutex_unlock(&s_global_check_mutex); |
| 457 | } |
| 458 | |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 459 | void get_state_error(const char* modify, lynq_wifi_sta_status_s* state, error_number_s* error) |
| 460 | { |
| 461 | char *pReason; |
| 462 | *error = LYNQ_WAIT_CONNECT_ACTIVE; |
| 463 | if (strstr(modify, "CTRL-EVENT-SCAN-RESULTS") != NULL) |
| 464 | { |
| 465 | *state = LYNQ_WIFI_STA_STATUS_SCAN_RESULT; |
| 466 | RLOGD("CTRL-EVENT-SCAN-RESULTS state:%d,error:%d\n",*state,*error); |
| 467 | return; |
| 468 | } |
| 469 | |
| 470 | if (strstr(modify, "CTRL-EVENT-CONNECTED") != NULL) |
| 471 | { |
| 472 | *state = LYNQ_WIFI_STA_STATUS_CONNECT; |
| 473 | RLOGD("CTRL-EVENT-CONNECTED state:%d,error:%d\n",*state,*error); |
| 474 | return; |
| 475 | } |
| 476 | |
| 477 | if (strstr(modify, "CTRL-EVENT-SSID-TEMP-DISABLED") != NULL) |
| 478 | { |
| 479 | pReason = strstr(modify, "reason="); |
| 480 | if (pReason != NULL) |
| 481 | { |
| 482 | pReason += strlen("reason="); |
| 483 | if (memcmp(pReason, "CONN_FAILED", 11) == 0) |
| 484 | { |
| 485 | *error = LYNQ_TIME_OUT; |
| 486 | } |
| 487 | else if (memcmp(pReason, "WRONG_KEY", 9) == 0) |
| 488 | { |
| 489 | *error = LYNQ_PSW_ERROR; |
| 490 | } |
| 491 | else |
| 492 | { |
| 493 | *error = LYNQ_UNSPECIFIED_REASON; |
| 494 | } |
| 495 | *state = LYNQ_WIFI_STA_STATUS_DISCONNECT; |
| 496 | RLOGD("CTRL-EVENT-SSID-TEMP-DISABLED state:%d,error:%d\n",*state,*error); |
| 497 | return; |
| 498 | } |
| 499 | else |
| 500 | { |
| 501 | *error = LYNQ_UNSPECIFIED_REASON; |
| 502 | *state = LYNQ_WIFI_STA_STATUS_DISCONNECT; |
| 503 | return; |
| 504 | } |
| 505 | |
| 506 | } |
| 507 | |
| 508 | if (strstr(modify, "CTRL-EVENT-NETWORK-NOT-FOUND") != NULL) |
| 509 | { |
| 510 | *error = LYNQ_NOT_FIND_AP; |
| 511 | *state = LYNQ_WIFI_STA_STATUS_DISCONNECT; |
| 512 | RLOGD("CTRL-EVENT-NETWORK-NOT-FOUND state:%d,error:%d\n",*state,*error); |
| 513 | return; |
| 514 | } |
| 515 | |
| 516 | |
| 517 | if (strstr(modify, "CTRL-EVENT-ASSOC-REJECT") != NULL) |
| 518 | { |
| 519 | RLOGD("FIND CTRL EVENT : CTRL-EVENT-ASSOC-REJECT\n"); |
| 520 | pReason = strstr(modify, "status_code="); |
| 521 | if (pReason != NULL) |
| 522 | { |
| 523 | pReason += strlen("status_code="); |
| 524 | if (memcmp(pReason, "17", 2) == 0) |
| 525 | { |
| 526 | *error = LYNQ_AP_UNABLE_HANDLE; |
| 527 | } |
| 528 | else if (memcmp(pReason, "1",1) == 0) |
| 529 | { |
| 530 | *error = LYNQ_UNSPECIFIED_REASON; |
| 531 | } |
| 532 | else |
| 533 | { |
| 534 | *error = LYNQ_UNSPECIFIED_REASON; |
| 535 | } |
| 536 | |
| 537 | *state = LYNQ_WIFI_STA_STATUS_DISCONNECT; |
| 538 | RLOGD("CTRL-EVENT-ASSOC-REJECT BUT NOT STATUS_CODE NOT 1 or 17 state:%d,error:%d\n",*state,*error); |
| 539 | return; |
| 540 | } |
| 541 | else |
| 542 | { |
| 543 | RLOGD("FIND CTRL EVENT : CTRL-EVENT-ASSOC-REJECT BUT NOT FOUND STATUS_CODE\n"); |
| 544 | *error = LYNQ_UNSPECIFIED_REASON; |
| 545 | *state = LYNQ_WIFI_STA_STATUS_DISCONNECT; |
| 546 | RLOGD("CTRL-EVENT-ASSOC-REJECT state:%d,error:%d\n",*state,*error); |
| 547 | return; |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | if (strstr(modify, "CTRL-EVENT-SAE-UNKNOWN-PASSWORD-IDENTIFIER") != NULL) |
| 552 | { |
| 553 | RLOGD("FIND CTRL EVENT : CTRL-EVENT-SAE-UNKNOWN-PASSWORD-IDENTIFIER\n"); |
| 554 | *error = LYNQ_AUTHENTICATION_NO_LONGER_VALID; |
| 555 | *state = LYNQ_WIFI_STA_STATUS_DISCONNECT; |
| 556 | RLOGD("CTRL-EVENT-SAE-UNKNOWN-PASSWORD-IDENTIFIER state:%d,error:%d\n",*state,*error); |
| 557 | return; |
| 558 | } |
| 559 | |
| 560 | if (strstr(modify, "CTRL-EVENT-DISCONNECTED") != NULL) |
| 561 | { |
| 562 | RLOGD("FIND CTRL EVENT : CTRL-EVENT-DISCONNECTED\n"); |
| 563 | *error = LYNQ_WAIT_CONNECT_ACTIVE; |
| 564 | *state = LYNQ_WIFI_STA_STATUS_DISCONNECT; |
| 565 | RLOGD("CTRL-EVENT-DISCONNECTED state:%d,error:%d\n",*state,*error); |
| 566 | return; |
| 567 | } |
| 568 | |
you.chen | 32cb31e | 2023-04-13 14:05:45 +0800 | [diff] [blame] | 569 | RLOGD("EVENT : %s\n", modify); |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 570 | *error = LYNQ_UNSPECIFIED_REASON; |
you.chen | 32cb31e | 2023-04-13 14:05:45 +0800 | [diff] [blame] | 571 | *state = LYNQ_WIFI_STATUS_EGNORE; |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 572 | RLOGD("LAST : STA state:%d,error:%d\n",*state,*error); |
| 573 | return; |
| 574 | |
| 575 | } |
| 576 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 577 | static void notify_connect_status(lynq_wifi_sta_status_s state, error_number_s error) |
| 578 | { |
| 579 | if (g_sta_callback_func != NULL && state != LYNQ_WIFI_STATUS_EGNORE) |
| 580 | { |
| 581 | RLOGD("STAWatcherThreadProc callback begin ------> %d %d\n", state, error); |
| 582 | g_sta_callback_func(g_sta_callback_priv, state, error); |
| 583 | RLOGD("STAWatcherThreadProc callback end ------> %d %d\n", state, error); |
| 584 | } |
| 585 | } |
| 586 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 587 | static void STAWatcherThreadProc() { |
| 588 | size_t len = MAX_RET; |
| 589 | char msg_notify[MAX_RET]; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 590 | error_number_s error; |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 591 | lynq_wifi_sta_status_s state; |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 592 | int idle_count = 0; |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 593 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 594 | struct wpa_ctrl *lynq_wpa_ctrl = NULL; |
you.chen | 92fd5d3 | 2022-05-25 10:09:47 +0800 | [diff] [blame] | 595 | g_sta_watcher_stop_flag = 0; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 596 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 597 | RLOGD("STAWatcherThreadProc thread started ------"); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 598 | while (g_sta_watcher_stop_flag == 0) |
| 599 | { |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 600 | if (check_pending_msg(&lynq_wpa_ctrl, CTRL_STA, &idle_count, &g_sta_watcher_started_flag) != 1) |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 601 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 602 | continue; |
| 603 | } |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 604 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 605 | memset(msg_notify, 0, MAX_RET); |
| 606 | len = MAX_RET; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 607 | if (!wpa_ctrl_recv(lynq_wpa_ctrl, msg_notify, &len)) |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 608 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 609 | msg_notify[len+1] = '\0'; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 610 | RLOGD("STAWatcherThreadProc sta ------> %s\n", msg_notify); |
| 611 | if (strstr(msg_notify, state_scan_result) != NULL) |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 612 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 613 | g_sta_scan_finish_flag = 1; |
| 614 | } |
| 615 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 616 | if (g_sta_callback_func == NULL) |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 617 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 618 | continue; |
| 619 | } |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 620 | get_state_error(msg_notify,&state,&error); |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 621 | notify_connect_status(state, error); |
| 622 | |
| 623 | if (state != LYNQ_WIFI_STA_STATUS_SCAN_RESULT) |
you.chen | 32cb31e | 2023-04-13 14:05:45 +0800 | [diff] [blame] | 624 | { |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 625 | inner_check_connect_error(msg_notify, state, error); |
you.chen | 32cb31e | 2023-04-13 14:05:45 +0800 | [diff] [blame] | 626 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 627 | } |
| 628 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 629 | if (lynq_wpa_ctrl != NULL) |
| 630 | { |
you.chen | 92fd5d3 | 2022-05-25 10:09:47 +0800 | [diff] [blame] | 631 | wpa_ctrl_detach(lynq_wpa_ctrl); |
| 632 | wpa_ctrl_close(lynq_wpa_ctrl); |
| 633 | } |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 634 | } |
| 635 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 636 | // this thread will not exit when lynq_wifi_disable called,to avoid dead lock,take care |
| 637 | static void GlobalWatcherThreadProc() |
| 638 | { |
| 639 | int ret, connect_timeout, service_abnormal; |
| 640 | error_number_s error_num = -1; |
| 641 | inner_sta_status_s sta_status; |
| 642 | scan_info_s *scan_list = NULL; |
| 643 | int i, scan_len=0; |
| 644 | char connecting_ssid[64]; |
| 645 | struct timeval now; |
| 646 | |
| 647 | RLOGD("GlobalWatcherThreadProc start to run"); |
| 648 | |
| 649 | while (1) |
| 650 | { |
| 651 | pthread_mutex_lock(&s_global_check_mutex); |
| 652 | pthread_cond_wait(&s_global_check_cond,&s_global_check_mutex); |
| 653 | if (s_sta_status == INNER_STA_STATUS_CONNECTED) |
| 654 | { |
| 655 | pthread_mutex_unlock(&s_global_check_mutex); |
| 656 | usleep(50*1000); |
| 657 | notify_connect_status(LYNQ_WIFI_STA_STATUS_CONNECT, 0); |
| 658 | continue; |
| 659 | } |
| 660 | |
| 661 | connect_timeout = 0; |
| 662 | service_abnormal = 0; |
| 663 | if (s_sta_status >= INNER_STA_STATUS_CONNECTING && s_sta_status < INNER_STA_STATUS_CONNECTED) |
| 664 | { |
| 665 | while (1) |
| 666 | { |
| 667 | ret = pthread_cond_timedwait(&s_global_check_cond, &s_global_check_mutex, &s_sta_connect_timeout); |
| 668 | if (ret == ETIME) |
| 669 | { |
| 670 | connect_timeout = 1; |
| 671 | } |
| 672 | else if (ret != 0) |
| 673 | { |
| 674 | gettimeofday(&now,NULL); |
| 675 | if (now.tv_sec < s_sta_connect_timeout.tv_sec) //time not arrive |
| 676 | { |
| 677 | usleep(SLEEP_TIME_ON_IDLE); |
| 678 | continue; |
| 679 | } |
| 680 | connect_timeout = 1; |
| 681 | } |
| 682 | sta_status = s_sta_status; |
| 683 | error_num = s_sta_error_number; |
| 684 | s_sta_status = INNER_STA_STATUS_INIT; |
| 685 | strcpy(connecting_ssid, s_sta_current_connecting_ssid); |
| 686 | memset(&s_sta_connect_timeout, 0, sizeof (s_sta_connect_timeout)); |
| 687 | memset(&s_sta_current_connecting_ssid, 0, sizeof (s_sta_current_connecting_ssid)); |
| 688 | break; |
| 689 | } |
| 690 | } |
| 691 | if (s_service_invoke_timeout_cnt > 10) |
| 692 | { |
| 693 | service_abnormal = 1; |
| 694 | s_service_invoke_timeout_cnt = 0; |
| 695 | } |
| 696 | pthread_mutex_unlock(&s_global_check_mutex); |
| 697 | |
| 698 | if (service_abnormal == 1) |
| 699 | { |
| 700 | sleep(1); |
| 701 | RLOGE("wpa service is abnormal info app to exit"); |
| 702 | notify_connect_status(LYNQ_WIFI_STA_SERVICE_ABNORMAL, -1); |
| 703 | if (g_ap_callback_func != NULL) |
| 704 | { |
| 705 | g_ap_callback_func(g_ap_callback_priv, LYNQ_WIFI_SERVICE_ABNORMAL); |
| 706 | } |
| 707 | sleep(FAKE_MAX_INT_VALUE); // wait process to exit |
| 708 | } |
| 709 | |
| 710 | if (sta_status == INNER_STA_STATUS_CANCEL) |
| 711 | { |
| 712 | continue; |
| 713 | } |
| 714 | else if (sta_status == INNER_STA_STATUS_CONNECTED) |
| 715 | { |
| 716 | notify_connect_status(LYNQ_WIFI_STA_STATUS_CONNECT, 0); |
| 717 | } |
| 718 | else if (connect_timeout == 0 && error_num == LYNQ_NOT_FIND_AP) // not found ap maybe mismatch auth |
| 719 | { |
| 720 | if (0 == lynq_get_scan_list(0, &scan_list, &scan_len) && NULL != scan_list) // if not found, but scan result exist, maybe auth error |
| 721 | { |
| 722 | for(i=0; i < scan_len;i++) |
| 723 | { |
| 724 | if (strcmp(scan_list[i].ssid, connecting_ssid) == 0) |
| 725 | { |
| 726 | error_num = LYNQ_AUTH_ERROR; |
| 727 | break; |
| 728 | } |
| 729 | } |
| 730 | free(scan_list); |
| 731 | } |
| 732 | notify_connect_status(LYNQ_WIFI_STA_STATUS_CONNECT_FAIL, error_num); |
| 733 | } |
| 734 | else if (connect_timeout == 0) |
| 735 | { |
| 736 | notify_connect_status(LYNQ_WIFI_STA_STATUS_CONNECT_FAIL, error_num); |
| 737 | } |
| 738 | else // wait timeout |
| 739 | { |
| 740 | if (0 != lynq_get_sta_status(LYNQ_WIFI_INTERFACE_0, &sta_status)) // get status fail |
| 741 | { |
| 742 | ; // wpa service abnormal |
| 743 | } |
| 744 | else if (sta_status == LYNQ_WIFI_STA_STATUS_ENABLE) // connect ok |
| 745 | { |
| 746 | RLOGD("GlobalWatcherThreadProc notify connected"); |
| 747 | notify_connect_status(LYNQ_WIFI_STA_STATUS_CONNECT, 0); |
| 748 | } |
| 749 | else |
| 750 | { |
| 751 | RLOGD("GlobalWatcherThreadProc notify timeout"); |
| 752 | notify_connect_status(LYNQ_WIFI_STA_STATUS_CONNECT_FAIL, LYNQ_TIME_OUT); |
| 753 | } |
| 754 | } |
| 755 | } // while (1) |
| 756 | } |
| 757 | |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 758 | int lynq_wifi_enable(void) |
| 759 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 760 | int ret = 0; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 761 | int i; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 762 | RLOGD("enter lynq_wifi_enable"); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 763 | pthread_mutex_lock(&s_check_wpa_ctrl_mutex); |
| 764 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 765 | if (g_lynq_wpa_ctrl[0] != NULL && g_lynq_wpa_ctrl[1] != NULL) |
| 766 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 767 | goto out_enable; |
| 768 | } |
| 769 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 770 | const char * cmd_check_service = |
| 771 | "state=`systemctl is-active wg870_drv_insmod.service`\n" |
| 772 | "[ \"\"$state == \"active\" ] && exit 0\n" |
| 773 | "[ \"\"$state == \"inactive\" ] && systemctl start wg870_drv_insmod.service\n"; |
| 774 | // if (g_lynq_wpa_ctrl[0] != NULL && g_lynq_wpa_ctrl[1] != NULL) { |
| 775 | // return 0; |
| 776 | // } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 777 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 778 | ret = system(cmd_check_service); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 779 | if (ret != 0) |
| 780 | { |
| 781 | //printf("service state %d\n", ret); |
| 782 | RLOGE("[wifi error]service state %d",ret); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 783 | ret = -1; |
| 784 | goto out_enable; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 785 | } |
lh | fe8da90 | 2022-10-11 18:55:36 +0800 | [diff] [blame] | 786 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 787 | RLOGD("check service state is OK"); |
| 788 | for (i=0; i<10; i++) |
| 789 | { |
you.chen | a6fa5b2 | 2022-05-18 10:28:19 +0800 | [diff] [blame] | 790 | if (system("connmanctl technologies | grep -q \"/net/connman/technology/wifi\"") == 0) { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 791 | break; |
| 792 | } |
| 793 | usleep(300*1000); |
| 794 | } |
| 795 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 796 | if (i >= 10) |
| 797 | { |
| 798 | RLOGE("[wifi error] check connman technologies no wifi"); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 799 | ret = -1; |
| 800 | goto out_enable; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 801 | } |
| 802 | |
you.chen | 9f17e4d | 2022-06-06 17:18:18 +0800 | [diff] [blame] | 803 | //@todo delete add temp check for socket avilable start (20220606) |
| 804 | for (i=0; i<60; i++) |
| 805 | { |
| 806 | if (system("netstat -an | grep -q DGRAM") == 0) { |
| 807 | break; |
| 808 | } |
| 809 | sleep(1); |
| 810 | } |
| 811 | |
| 812 | if (i >= 60) |
| 813 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 814 | ret = -1; |
| 815 | goto out_enable; |
you.chen | 9f17e4d | 2022-06-06 17:18:18 +0800 | [diff] [blame] | 816 | } |
| 817 | //@todo delete add temp check for socket avilable end (20220606) |
| 818 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 819 | if (0 != system("ifconfig | grep -q ap0")) |
| 820 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 821 | system("connmanctl enable wifi"); |
you.chen | a6fa5b2 | 2022-05-18 10:28:19 +0800 | [diff] [blame] | 822 | usleep(300*1000); |
you.chen | 01bfac3 | 2022-06-07 10:36:00 +0800 | [diff] [blame] | 823 | system("wpa_cli -iwpa_wlan0_cmd -p/var/run/ IFNAME=wlan0 disconnect"); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 824 | 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] | 825 | usleep(300*1000); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 826 | system("connmanctl tether wifi on lynq 1qaz@WSX#$%^"); |
you.chen | a6fa5b2 | 2022-05-18 10:28:19 +0800 | [diff] [blame] | 827 | usleep(300*1000); |
you.chen | 01bfac3 | 2022-06-07 10:36:00 +0800 | [diff] [blame] | 828 | system("wpa_cli -iwpa_wlan0_cmd -p/var/run/ IFNAME=ap0 disconnect"); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 829 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 830 | if (g_ap_watcher_pid == 0 ) |
qs.xiong | 55f3276 | 2023-02-16 15:59:45 +0800 | [diff] [blame] | 831 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 832 | ret=pthread_create(&g_ap_watcher_pid,NULL,APWatcherThreadProc,NULL); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 833 | if(ret<0) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 834 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 835 | RLOGE("[wifi error]creat APWatcherThreadProc fail"); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 836 | ret = -1; |
| 837 | goto out_enable; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 838 | } |
| 839 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 840 | |
| 841 | RLOGD("creat APWatcherTheradProc susccs"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 842 | if (g_sta_watcher_pid == 0 ) { |
| 843 | ret=pthread_create(&g_sta_watcher_pid,NULL,STAWatcherThreadProc,NULL); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 844 | if(ret<0) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 845 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 846 | RLOGE("[wifi error]creat STAWatcherThreadProc fail"); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 847 | ret = -1; |
| 848 | goto out_enable; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 849 | } |
| 850 | } |
| 851 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 852 | if (g_global_watcher_pid == 0 ) // this thread will not exit when lynq_wifi_disable called,to avoid dead lock,take care |
| 853 | { |
| 854 | ret=pthread_create(&g_global_watcher_pid,NULL,GlobalWatcherThreadProc,NULL); |
| 855 | if(ret<0) |
| 856 | { |
| 857 | RLOGE("[wifi error]creat GlobalWatcherThreadProc fail"); |
| 858 | ret = -1; |
| 859 | goto out_enable; |
| 860 | } |
| 861 | } |
| 862 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 863 | RLOGD("creat STAWatcherTheradProc susccs"); |
| 864 | for (i=0; i<10; i++) |
| 865 | { |
you.chen | a6fa5b2 | 2022-05-18 10:28:19 +0800 | [diff] [blame] | 866 | usleep(300*1000); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 867 | if (g_ap_watcher_started_flag == 1 && g_sta_watcher_started_flag == 1) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 868 | { |
you.chen | a6fa5b2 | 2022-05-18 10:28:19 +0800 | [diff] [blame] | 869 | break; |
| 870 | } |
| 871 | } |
| 872 | |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 873 | g_lynq_wpa_ctrl[0] = malloc(sizeof (struct local_wpa_ctrl)); |
| 874 | g_lynq_wpa_ctrl[1] = malloc(sizeof (struct local_wpa_ctrl)); |
| 875 | memset(g_lynq_wpa_ctrl[0], 0 , sizeof(struct local_wpa_ctrl)); |
| 876 | memset(g_lynq_wpa_ctrl[1], 0 , sizeof(struct local_wpa_ctrl)); |
| 877 | out_enable: |
| 878 | pthread_mutex_unlock(&s_check_wpa_ctrl_mutex); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 879 | return ret; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 880 | } |
| 881 | |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 882 | int lynq_wifi_disable(void) |
| 883 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 884 | RLOGD("enter lynq_wifi_disable"); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 885 | pthread_mutex_lock(&s_check_wpa_ctrl_mutex); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 886 | g_ap_watcher_stop_flag = 1; |
| 887 | g_sta_watcher_stop_flag = 1; |
| 888 | if (g_ap_watcher_pid != 0) |
| 889 | pthread_join(g_ap_watcher_pid, NULL); |
| 890 | if (g_sta_watcher_pid != 0) |
| 891 | pthread_join(g_sta_watcher_pid, NULL); |
| 892 | if (g_lynq_wpa_ctrl[0] != NULL) |
| 893 | wpa_ctrl_close(g_lynq_wpa_ctrl[0]); |
| 894 | if (g_lynq_wpa_ctrl[1] != NULL) |
| 895 | wpa_ctrl_close(g_lynq_wpa_ctrl[1]); |
| 896 | g_ap_watcher_pid = 0; |
| 897 | g_sta_watcher_pid = 0; |
| 898 | g_lynq_wpa_ctrl[0] = NULL; |
| 899 | g_lynq_wpa_ctrl[1] = NULL; |
| 900 | system("systemctl stop wg870_drv_insmod.service"); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 901 | pthread_mutex_unlock(&s_check_wpa_ctrl_mutex); |
| 902 | return 0; |
| 903 | } |
| 904 | |
| 905 | static inline char inner_convert_char(char in) |
| 906 | { |
| 907 | if (in >= '0' && in <= '9') |
| 908 | { |
| 909 | return in - '0'; |
| 910 | } |
| 911 | else if (in >= 'a' && in <= 'f') |
| 912 | { |
| 913 | return in - 'a' + 10; |
| 914 | } |
| 915 | else if (in >= 'A' && in <= 'F') |
| 916 | { |
| 917 | return in - 'A' + 10; |
| 918 | } |
| 919 | else |
| 920 | { |
| 921 | return '\xff'; |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | static inline void inner_copy_ssid(char * out_ssid, const char * ssid, size_t out_ssid_len) |
| 926 | { |
| 927 | char *p; |
| 928 | size_t pos = 0; |
| 929 | if (NULL == out_ssid) |
| 930 | return; |
| 931 | //printf("input ssid=[%s]\n", ssid); |
| 932 | memset(out_ssid, 0, out_ssid_len); |
| 933 | if (NULL == ssid) |
| 934 | return; |
| 935 | p = strchr(ssid, '\\'); |
| 936 | if (NULL == p) |
| 937 | { |
| 938 | strncpy(out_ssid, ssid, out_ssid_len); |
| 939 | //printf(" first %s\n", out_ssid); |
| 940 | } |
| 941 | else |
| 942 | { |
| 943 | pos = p - ssid; |
| 944 | memcpy(out_ssid, ssid, pos); |
| 945 | //printf("pos %lu -- %s\n", pos, out_ssid); |
| 946 | for(; pos < out_ssid_len; pos ++) |
| 947 | { |
| 948 | if (p[0] == '\0') |
| 949 | { |
| 950 | //printf(" out %s\n", out_ssid); |
| 951 | return; |
| 952 | } |
| 953 | else if (p[0] != '\\') |
| 954 | { |
| 955 | out_ssid[pos] = p[0]; |
| 956 | p += 1; |
| 957 | } |
| 958 | else if (p[1] == 'x' || p[1] == 'X') |
| 959 | { |
| 960 | out_ssid[pos] = inner_convert_char(p[2]) << 4 | inner_convert_char(p[3]); |
| 961 | p += 4; |
| 962 | } |
| 963 | else if (p[1] == '\\') |
| 964 | { |
| 965 | out_ssid[pos] = '\\'; |
| 966 | p += 2; |
| 967 | } |
| 968 | else if (p[1] == 't') |
| 969 | { |
| 970 | out_ssid[pos] = '\t'; |
| 971 | p += 2; |
| 972 | } |
| 973 | else if (p[1] == 'r') |
| 974 | { |
| 975 | out_ssid[pos] = '\r'; |
| 976 | p += 2; |
| 977 | } |
| 978 | else if (p[1] == 'n') |
| 979 | { |
| 980 | out_ssid[pos] = '\n'; |
| 981 | p += 2; |
| 982 | }//todo find a better way to convert? |
| 983 | } |
| 984 | } |
| 985 | //printf(" out %s\n", out_ssid); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 986 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 987 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 988 | static int inner_get_param(int interface, int net_no, char* param_name, char * out_put) { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 989 | int i, ssid_len; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 990 | char lynq_cmd_get[128]={0}; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 991 | RLOGD("enter inner_get_param"); |
| 992 | if (out_put == NULL) |
| 993 | { |
| 994 | RLOGE("output ptr is null"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 995 | return -1; |
| 996 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 997 | if (param_name == NULL) |
| 998 | { |
| 999 | RLOGE("param ptr is null"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1000 | return -1; |
| 1001 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1002 | if (param_name[0] == '\0') |
| 1003 | { |
| 1004 | RLOGE("param is empty"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1005 | return -1; |
| 1006 | } |
| 1007 | |
| 1008 | sprintf(lynq_cmd_get, "GET_NETWORK %d %s", net_no, param_name); |
| 1009 | |
| 1010 | CHECK_WPA_CTRL(interface); |
| 1011 | |
| 1012 | DO_REQUEST(lynq_cmd_get); |
| 1013 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1014 | if (memcmp(cmd_reply, "FAIL", 4) == 0) |
| 1015 | { |
| 1016 | RLOGE("wpa_supplicant return cmd_reply is FAIL"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1017 | return -1; |
| 1018 | } |
| 1019 | |
you.chen | a6fa5b2 | 2022-05-18 10:28:19 +0800 | [diff] [blame] | 1020 | // printf("reply len %d, %08x\n", reply_len, (int)out_put); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1021 | if (strcmp(param_name, "ssid") == 0) |
| 1022 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1023 | if (cmd_reply[0] == '\"') |
| 1024 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1025 | ssid_len = reply_len - 1; |
| 1026 | memcpy(out_put, cmd_reply + 1, ssid_len); |
| 1027 | if (out_put[ssid_len-1] == '\"') |
| 1028 | { |
| 1029 | out_put[ssid_len-1] = '\0'; |
| 1030 | } |
| 1031 | else |
| 1032 | { |
| 1033 | out_put[ssid_len] = '\0'; |
| 1034 | } |
| 1035 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1036 | else |
| 1037 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1038 | ssid_len = reply_len / 2; |
| 1039 | for(i=0; i<ssid_len; i++) |
| 1040 | { |
| 1041 | out_put[i] = inner_convert_char(cmd_reply[i*2]) << 4 | inner_convert_char(cmd_reply[i*2 + 1]); |
| 1042 | } |
| 1043 | out_put[ssid_len] = '\0'; |
| 1044 | } |
| 1045 | } |
| 1046 | else |
| 1047 | { |
| 1048 | memcpy(out_put, cmd_reply, reply_len + 1); |
| 1049 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1050 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1051 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1052 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1053 | static int lynq_split(char * str, int len, char delimiter, char * results[]) { |
| 1054 | int ret = 0; |
| 1055 | char * end = str + len - 1; |
| 1056 | results[ret++] = str; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1057 | while(str < end) |
| 1058 | { |
| 1059 | if (*str == delimiter) |
| 1060 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1061 | *str++ = '\0'; |
| 1062 | results[ret++] = str; |
| 1063 | continue; |
| 1064 | } |
| 1065 | str++; |
| 1066 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1067 | if (*str == delimiter) |
| 1068 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1069 | *str = '\0'; |
| 1070 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1071 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1072 | return ret; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1073 | } |
| 1074 | |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1075 | static int inner_get_ip_by_mac(const char * mac, char * ip, int ip_len) |
| 1076 | { |
| 1077 | char * p; |
| 1078 | int ret = 0; |
| 1079 | char cmd[256]={0}; |
| 1080 | if (NULL == mac || NULL == ip) |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1081 | return -1; |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1082 | memset(ip, 0, ip_len); |
qs.xiong | 1367346 | 2023-02-21 19:12:54 +0800 | [diff] [blame] | 1083 | sprintf(cmd, "ip n s | grep \"lladdr\" | grep \"%s\" | head -1 | awk '{print $1}'", mac); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1084 | ret = exec_cmd(cmd, ip, ip_len); |
| 1085 | p = strchr(ip, '\n'); |
| 1086 | if (NULL != p) |
| 1087 | { |
| 1088 | *p = '\0'; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1089 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1090 | RLOGD("inner_get_ip_by_mac %s\n", ip); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1091 | return ret; |
| 1092 | } |
| 1093 | |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1094 | static int inner_get_hostname_by_ip(char *ip, char *hostname) { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1095 | struct in_addr addr ={0}; |
| 1096 | struct hostent *ht; |
| 1097 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1098 | if (ip == NULL || *ip == '\0' || hostname == NULL) |
| 1099 | { |
| 1100 | RLOGE("ip == NULL or hostname == NULL"); |
| 1101 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1102 | } |
| 1103 | |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1104 | *hostname = '\0'; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1105 | if (inet_aton(ip, &addr) == 0) |
| 1106 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1107 | printf("---inet_aton fail\n"); |
| 1108 | return -1; |
| 1109 | } |
| 1110 | |
| 1111 | ht = gethostbyaddr(&addr, sizeof(struct in_addr), AF_INET); |
| 1112 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1113 | if (ht == NULL) |
| 1114 | { |
| 1115 | RLOGE("---gethostbyaddr fail\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1116 | herror(NULL); |
| 1117 | return -1; |
| 1118 | } |
| 1119 | |
| 1120 | strcpy(hostname, ht->h_name); |
| 1121 | |
| 1122 | return 0; |
| 1123 | } |
| 1124 | |
| 1125 | static int lynq_get_network_number_list(lynq_wifi_index_e idx, int ap_sta, int net_no_list[], char * ssid) |
| 1126 | { |
| 1127 | int count, index, words_count; |
| 1128 | char * split_lines[128]= {0}; |
| 1129 | char * split_words[128] = {0}; |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1130 | char local_ssid[128] = {0}; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1131 | const char *lynq_wifi_list_networks = "LIST_NETWORKS"; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1132 | RLOGD("[lynq_get_network_number_list] enter lynq_get_network_number_list api"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1133 | |
| 1134 | CHECK_WPA_CTRL(ap_sta); |
| 1135 | |
| 1136 | DO_REQUEST(lynq_wifi_list_networks); |
| 1137 | |
| 1138 | count = lynq_split(cmd_reply, reply_len, '\n', split_lines); |
| 1139 | |
| 1140 | //@todo check ssid field to compatible |
| 1141 | |
| 1142 | ret = 0; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1143 | for(index=1; index < count; index++) |
| 1144 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1145 | words_count = lynq_split(split_lines[index], strlen(split_lines[index]), '\t', split_words); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1146 | if (words_count > 2) |
| 1147 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1148 | inner_copy_ssid(local_ssid, split_words[1], sizeof (local_ssid)); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1149 | if (ssid == NULL || strcmp(local_ssid, ssid) == 0) |
| 1150 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1151 | net_no_list[ret++] = atoi(split_words[0]); |
| 1152 | } |
| 1153 | } |
| 1154 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1155 | RLOGD("[lynq_get_network_number_list] lynq_get_network_number_list return ok"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1156 | return ret; |
| 1157 | } |
| 1158 | |
| 1159 | static int lynq_add_network(int ap_sta) { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1160 | size_t i=0; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1161 | CHECK_WPA_CTRL(ap_sta); |
| 1162 | const char *lynq_wifi_add_network = "ADD_NETWORK"; |
| 1163 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1164 | RLOGD("[lynq_add_network] enter lynq_add_network"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1165 | DO_REQUEST(lynq_wifi_add_network); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1166 | if (memcmp(cmd_reply, "FAIL", 4) == 0) |
| 1167 | { |
| 1168 | RLOGE("[wifi error]lynq_add_network cmd_reply FAIL"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1169 | return -1; |
| 1170 | } |
| 1171 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1172 | for(i=0;i<reply_len;i++) |
| 1173 | { |
| 1174 | if(cmd_reply[i] == '\n') |
| 1175 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1176 | cmd_reply[i] = '\0'; |
| 1177 | break; |
| 1178 | } |
| 1179 | } |
| 1180 | return atoi(cmd_reply); |
| 1181 | } |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 1182 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1183 | static int lynq_check_network_number(lynq_wifi_index_e idx, int ap_sta, int net_no) |
| 1184 | { |
| 1185 | int count, index; |
| 1186 | int net_no_list[128]; |
| 1187 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1188 | RLOGD("[lynq_check_network_number] enter lynq_check_network_number api"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1189 | count = lynq_get_network_number_list(idx, ap_sta, net_no_list, NULL); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1190 | for (index=0; index < count; index++) |
| 1191 | { |
| 1192 | if (net_no_list[index] == net_no) |
| 1193 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1194 | return 0; |
| 1195 | } |
| 1196 | } |
| 1197 | |
| 1198 | if (count >= 1) |
| 1199 | index = net_no_list[count - 1]; |
| 1200 | else |
| 1201 | index = -1; |
| 1202 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1203 | while (index < net_no ) |
| 1204 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1205 | index = lynq_add_network(ap_sta); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1206 | if (index >= net_no) |
| 1207 | { // required network no created |
| 1208 | RLOGD("required network no created\n");; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1209 | return 0; |
| 1210 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1211 | else if( index < 0) |
| 1212 | { |
| 1213 | RLOGE("[lynq_check_network_number] add network fail"); |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 1214 | return -1; |
| 1215 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | if (index < 0) |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1219 | { |
| 1220 | RLOGE("[lynq_check_network_number] network index < 0"); |
| 1221 | return -1; |
| 1222 | } |
| 1223 | RLOGD("[lynq_check_network_number] work finished &state is ok"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1224 | return 0; |
| 1225 | } |
| 1226 | |
| 1227 | static lynq_wifi_band_m convert_band_from_freq(int freq) { //@todo |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1228 | if (freq > 5000 && freq < 6000) |
| 1229 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1230 | return LYNQ_WIFI_5G_band; |
| 1231 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1232 | else if (freq > 2000 && freq < 3000) |
| 1233 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1234 | return LYNQ_WIFI_2G_band; |
| 1235 | } |
| 1236 | return LYNQ_WIFI_2_and_5G_band; |
| 1237 | } |
| 1238 | |
| 1239 | static lynq_wifi_auth_s convert_auth_from_key_mgmt(char * key_mgmt) { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1240 | if (key_mgmt != NULL) |
| 1241 | { |
| 1242 | if (memcmp( key_mgmt, "NONE", 4) == 0) |
| 1243 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1244 | return LYNQ_WIFI_AUTH_OPEN; |
| 1245 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1246 | else if (memcmp( key_mgmt, "WEP", 3) == 0) |
| 1247 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1248 | return LYNQ_WIFI_AUTH_WEP; |
| 1249 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1250 | else if (memcmp( key_mgmt, "WPA-PSK", 7) == 0) |
| 1251 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1252 | return LYNQ_WIFI_AUTH_WPA_PSK; |
| 1253 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1254 | else if (memcmp( key_mgmt, "WPA2-PSK", 8) == 0) |
| 1255 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1256 | return LYNQ_WIFI_AUTH_WPA2_PSK; |
| 1257 | } |
| 1258 | } |
| 1259 | |
| 1260 | return -1; |
| 1261 | } |
| 1262 | |
| 1263 | static lynq_wifi_auth_s convert_max_auth_from_flag(char * flag) { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1264 | if (flag != NULL) |
| 1265 | { |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 1266 | if ( strstr(flag, "SHA256") != NULL || strstr(flag,"WPA2-SAE") != NULL || strstr(flag,"SAE-H2E") != NULL) |
| 1267 | { |
| 1268 | return LYNQ_WIFI_AUTH_WPA3_PSK; |
| 1269 | }else if ( strstr( flag,"SAE-CCMP") != NULL ) |
| 1270 | { |
| 1271 | return LYNQ_WIFI_AUTH_WPA2_WPA3_PSK; |
| 1272 | }else if (strstr( flag, "WPA2-PSK") != NULL) |
| 1273 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1274 | return LYNQ_WIFI_AUTH_WPA2_PSK; |
| 1275 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1276 | else if (strstr( flag, "WPA-PSK") != NULL) |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 1277 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1278 | return LYNQ_WIFI_AUTH_WPA_PSK; |
| 1279 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1280 | else if (strstr( flag, "WEP") != NULL) |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 1281 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1282 | return LYNQ_WIFI_AUTH_WEP; |
| 1283 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1284 | else if (strstr( flag, "NONE") != NULL) |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 1285 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1286 | return LYNQ_WIFI_AUTH_OPEN; |
| 1287 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1288 | else if (strcmp( flag, "[ESS]") == 0 || strcmp( flag,"[WPS][ESS]") == 0) |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 1289 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1290 | return LYNQ_WIFI_AUTH_OPEN; |
| 1291 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | return -1; |
| 1295 | } |
| 1296 | |
| 1297 | static lynq_wifi_bandwidth_type_m convert_bandwidth_from_bw(int bw) { |
| 1298 | switch (bw) { |
| 1299 | case 10: |
| 1300 | return LYNQ_WIFI_BANDWIDTH_HT10; |
| 1301 | break; |
| 1302 | case 20: |
| 1303 | return LYNQ_WIFI_BANDWIDTH_HT20; |
| 1304 | break; |
| 1305 | case 40: |
| 1306 | return LYNQ_WIFI_BANDWIDTH_HT40; |
| 1307 | break; |
| 1308 | case 80: |
| 1309 | return LYNQ_WIFI_BANDWIDTH_HT80; |
| 1310 | break; |
| 1311 | default: |
| 1312 | break; |
| 1313 | } |
| 1314 | |
| 1315 | return -1; |
| 1316 | } |
| 1317 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 1318 | static int inner_get_network_auth(int interface, int net_no, lynq_wifi_auth_s *auth); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1319 | static int inner_get_status_info(int interface, curr_status_info *curr_state) { |
| 1320 | int i, count; |
| 1321 | char *p; |
| 1322 | const char *lynq_status_cmd = "STATUS"; |
| 1323 | const char * FLAG_SSID = "ssid="; |
| 1324 | const char * FLAG_SBSID = "bssid="; |
| 1325 | const char * FLAG_KEY_MGMT = "key_mgmt="; |
| 1326 | const char * FLAG_FREQ = "freq="; |
| 1327 | const char * FLAG_STATE = "wpa_state="; |
| 1328 | const char * FLAG_ID = "id="; |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1329 | const char * FLAG_IPADDR = "ip_address="; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1330 | char *split_lines[128] = {0}; |
| 1331 | |
| 1332 | CHECK_WPA_CTRL(interface); |
| 1333 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1334 | if (curr_state == NULL) |
| 1335 | { |
| 1336 | RLOGE("[wifi error][inner_get_status_info]curr_state is NULL"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1337 | return -1; |
| 1338 | } |
| 1339 | |
| 1340 | DO_REQUEST(lynq_status_cmd); |
| 1341 | |
| 1342 | count = lynq_split(cmd_reply, reply_len, '\n', split_lines); |
| 1343 | |
| 1344 | curr_state->net_no = -1; |
| 1345 | ret = -1; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1346 | for(i=0; i < count; i++) |
| 1347 | { |
| 1348 | if (curr_state->ap != NULL) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 1349 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1350 | p = strstr(split_lines[i], FLAG_SBSID); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1351 | if (p != NULL) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 1352 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1353 | strncpy(curr_state->ap->ap_mac, p + strlen(FLAG_SBSID), sizeof(curr_state->ap->ap_mac)); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1354 | ret = 0; |
| 1355 | continue; |
| 1356 | } |
you.chen | f58b3c9 | 2022-06-21 16:53:48 +0800 | [diff] [blame] | 1357 | p = strstr(split_lines[i], FLAG_SSID); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1358 | if (p != NULL) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 1359 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1360 | inner_copy_ssid(curr_state->ap->ap_ssid, p + strlen(FLAG_SSID), sizeof (curr_state->ap->ap_ssid)); |
you.chen | f58b3c9 | 2022-06-21 16:53:48 +0800 | [diff] [blame] | 1361 | ret = 0; |
| 1362 | continue; |
| 1363 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1364 | p = strstr(split_lines[i], FLAG_KEY_MGMT); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1365 | if (p != NULL) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 1366 | { |
you.chen | 450d017 | 2022-07-15 17:56:48 +0800 | [diff] [blame] | 1367 | curr_state->ap->auth = convert_auth_from_key_mgmt(p + strlen(FLAG_KEY_MGMT)); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1368 | RLOGD("inner_get_status_info: key_mgmt %d, -- %s\n", curr_state->ap->auth, p); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1369 | ret = 0; |
| 1370 | continue; |
| 1371 | } |
| 1372 | p = strstr(split_lines[i], FLAG_FREQ); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1373 | if (p != NULL) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 1374 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1375 | curr_state->ap->band = convert_band_from_freq(atoi( p + strlen(FLAG_FREQ))); |
| 1376 | ret = 0; |
| 1377 | continue; |
| 1378 | } |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1379 | p = strstr(split_lines[i], FLAG_IPADDR); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1380 | if (p != NULL) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 1381 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1382 | strncpy(curr_state->ap->ap_ip, p + strlen(FLAG_IPADDR), sizeof(curr_state->ap->ap_ip)); |
| 1383 | ret = 0; |
| 1384 | continue; |
| 1385 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1386 | } // end if (ap != NULL) |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1387 | if (curr_state->state != NULL) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 1388 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1389 | p = strstr(split_lines[i], FLAG_STATE); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1390 | if (p != NULL) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 1391 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1392 | strcpy(curr_state->state, p + strlen(FLAG_STATE)); |
| 1393 | ret = 0; |
| 1394 | continue; |
| 1395 | } |
| 1396 | |
| 1397 | } //end else if (state != NULL) |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1398 | if ((p = strstr(split_lines[i], FLAG_ID)) == split_lines[i]) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 1399 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1400 | ret = 0; |
you.chen | 450d017 | 2022-07-15 17:56:48 +0800 | [diff] [blame] | 1401 | curr_state->net_no = atoi(p + strlen(FLAG_ID)); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1402 | RLOGD("inner_get_status_info:net_no %d, -- %s\n", curr_state->net_no, p); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1403 | } |
| 1404 | } |
| 1405 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 1406 | if (ret == 0 && curr_state->ap != NULL && curr_state->net_no >= 0) // auth may not right when add wpa3 |
| 1407 | { |
| 1408 | inner_get_network_auth(interface, curr_state->net_no, &curr_state->ap->auth); |
| 1409 | } |
| 1410 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1411 | return ret; |
| 1412 | } |
| 1413 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1414 | 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] | 1415 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1416 | RLOGD("enter lynq_wifi_ap_ssid_set"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1417 | char lynq_wifi_ssid_cmd[80]={0}; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1418 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1419 | if (ap_ssid == NULL) |
| 1420 | { |
| 1421 | RLOGE("Input ap_ssid is NULL"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1422 | return -1; |
| 1423 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1424 | else |
| 1425 | { |
| 1426 | RLOGD("[lynq_wifi_ap_ssid_set]idx:%d ap_ssid : %s\n", idx, ap_ssid); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1427 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1428 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1429 | if (lynq_check_network_number(idx, CTRL_AP, AP_NETWORK_0) != 0) |
| 1430 | { |
| 1431 | RLOGE("Do check ap network_number fail"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1432 | return -1; |
| 1433 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1434 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1435 | CHECK_IDX(idx, CTRL_AP); |
| 1436 | |
| 1437 | CHECK_WPA_CTRL(CTRL_AP); |
| 1438 | |
| 1439 | sprintf(lynq_wifi_ssid_cmd,"SET_NETWORK %d ssid \"%s\"", AP_NETWORK_0, ap_ssid); |
| 1440 | |
| 1441 | DO_OK_FAIL_REQUEST(lynq_wifi_ssid_cmd); |
| 1442 | DO_OK_FAIL_REQUEST(cmd_save_config); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1443 | RLOGD("[lynq_wifi_ap_ssid_set] set ssid sucss"); |
| 1444 | return 0; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1445 | |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1446 | } |
| 1447 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1448 | 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] | 1449 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1450 | RLOGD("enter lynq_wifi_ap_ssid_get"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1451 | CHECK_IDX(idx, CTRL_AP); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1452 | return inner_get_param(CTRL_AP, AP_NETWORK_0, "ssid", ap_ssid); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1453 | } |
| 1454 | |
qs.xiong | c9c79f7 | 2022-10-17 15:27:18 +0800 | [diff] [blame] | 1455 | /***** |
| 1456 | *frequency <------>channel |
| 1457 | * |
| 1458 | *frequency 1 2 3 4 5 6 7 8 9 10 11 12 13 36 40 44 48 149 153 157 161 165 |
| 1459 | * |
| 1460 | * |
| 1461 | *channel 2412,2417,2422,2427,2532,2437,2442,2447,2452,2457,2462,2467,2472,5180,5200,5220,5240,5745,5765,5785,5805,5825 |
| 1462 | * |
| 1463 | * |
| 1464 | * */ |
| 1465 | static int lynq_check_set_frequency(int input_frequency){ |
qs.xiong | c00b603 | 2022-11-29 16:28:03 +0800 | [diff] [blame] | 1466 | int legitimate_frequency[]={2412,2417,2422,2427,2432,2437,2442,2447,2452,2457,2462,2467,2472,5180,5200,5220,5240,5745,5765,5785,5805,5825}; |
| 1467 | int i; |
| 1468 | int arr_len = sizeof(legitimate_frequency) / sizeof(int); |
| 1469 | |
qs.xiong | 69a332b | 2022-12-02 09:58:57 +0800 | [diff] [blame] | 1470 | for(i = 0; i < arr_len; i++) |
qs.xiong | c00b603 | 2022-11-29 16:28:03 +0800 | [diff] [blame] | 1471 | { |
| 1472 | if(input_frequency == legitimate_frequency[i]) |
qs.xiong | c9c79f7 | 2022-10-17 15:27:18 +0800 | [diff] [blame] | 1473 | break; |
qs.xiong | c9c79f7 | 2022-10-17 15:27:18 +0800 | [diff] [blame] | 1474 | } |
qs.xiong | c00b603 | 2022-11-29 16:28:03 +0800 | [diff] [blame] | 1475 | |
| 1476 | if(i == arr_len) |
| 1477 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1478 | RLOGE("[lynq_check_set_frequency]input frequency is --->%d,please check it\n", input_frequency); |
qs.xiong | c9c79f7 | 2022-10-17 15:27:18 +0800 | [diff] [blame] | 1479 | return -1; |
| 1480 | } |
qs.xiong | c00b603 | 2022-11-29 16:28:03 +0800 | [diff] [blame] | 1481 | |
qs.xiong | c9c79f7 | 2022-10-17 15:27:18 +0800 | [diff] [blame] | 1482 | return 0; |
| 1483 | } |
qs.xiong | 1367346 | 2023-02-21 19:12:54 +0800 | [diff] [blame] | 1484 | |
| 1485 | static int lynq_check_frequencyby_country_code(int input_frequency) |
| 1486 | { |
| 1487 | char str_cnc[]="CN"; |
| 1488 | char str_dest[20]=""; |
| 1489 | |
| 1490 | if( lynq_get_country_code(1,str_dest) != 0 ) |
| 1491 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1492 | RLOGE("get country_code error\n"); |
qs.xiong | 1367346 | 2023-02-21 19:12:54 +0800 | [diff] [blame] | 1493 | return -1; |
| 1494 | } |
| 1495 | if( strncmp(str_dest,str_cnc,2) != 0 ) |
| 1496 | { |
| 1497 | return 0; |
| 1498 | }else if( 2473 < input_frequency && input_frequency < 5744) |
| 1499 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1500 | RLOGE("input frequency is bad\n"); |
qs.xiong | 1367346 | 2023-02-21 19:12:54 +0800 | [diff] [blame] | 1501 | return -1; |
| 1502 | } |
| 1503 | return 0; |
| 1504 | } |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1505 | 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] | 1506 | { |
qs.xiong | c00b603 | 2022-11-29 16:28:03 +0800 | [diff] [blame] | 1507 | int check; |
qs.xiong | c9c79f7 | 2022-10-17 15:27:18 +0800 | [diff] [blame] | 1508 | char lynq_wifi_frequency_cmd[128]={0}; |
| 1509 | char lynq_cmd_mode[128]={0}; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1510 | char lynq_cmd_slect[128]={0}; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1511 | RLOGD("enter lynq_wifi_ap_frequency_set and input frequency is:%d", lynq_wifi_frequency); |
qs.xiong | c9c79f7 | 2022-10-17 15:27:18 +0800 | [diff] [blame] | 1512 | //@do check input frequency |
qs.xiong | c00b603 | 2022-11-29 16:28:03 +0800 | [diff] [blame] | 1513 | check = lynq_check_set_frequency(lynq_wifi_frequency); |
| 1514 | if(check != 0) |
| 1515 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1516 | RLOGE("do check frequency error"); |
qs.xiong | c9c79f7 | 2022-10-17 15:27:18 +0800 | [diff] [blame] | 1517 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1518 | } |
qs.xiong | 1367346 | 2023-02-21 19:12:54 +0800 | [diff] [blame] | 1519 | check = lynq_check_frequencyby_country_code(lynq_wifi_frequency); |
| 1520 | if(check != 0) |
| 1521 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1522 | RLOGE("do check frequency error"); |
qs.xiong | 1367346 | 2023-02-21 19:12:54 +0800 | [diff] [blame] | 1523 | return -1; |
| 1524 | } |
| 1525 | |
qs.xiong | c00b603 | 2022-11-29 16:28:03 +0800 | [diff] [blame] | 1526 | if (lynq_check_network_number(idx, CTRL_AP, AP_NETWORK_0) != 0) |
| 1527 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1528 | RLOGE("[set ap frequecny][lynq_check_network_number] error"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1529 | return -1; |
| 1530 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1531 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1532 | CHECK_IDX(idx, CTRL_AP); |
| 1533 | |
| 1534 | CHECK_WPA_CTRL(CTRL_AP); |
| 1535 | |
| 1536 | sprintf(lynq_wifi_frequency_cmd,"SET_NETWORK %d frequency %d", AP_NETWORK_0, lynq_wifi_frequency); |
| 1537 | sprintf(lynq_cmd_mode, "SET_NETWORK %d mode 2", AP_NETWORK_0); |
| 1538 | sprintf(lynq_cmd_slect, "SELECT_NETWORK %d", AP_NETWORK_0); |
| 1539 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1540 | DO_OK_FAIL_REQUEST(cmd_disconnect); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1541 | DO_OK_FAIL_REQUEST(lynq_wifi_frequency_cmd); |
| 1542 | DO_OK_FAIL_REQUEST(lynq_cmd_mode); |
| 1543 | DO_OK_FAIL_REQUEST(cmd_save_config); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1544 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1545 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1546 | } |
| 1547 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1548 | 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] | 1549 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1550 | char lynq_frequency_str[MAX_RET] = {0}; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1551 | RLOGD("enter lynq_wifi_ap_frequency_get and input idx is %d",idx); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1552 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1553 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1554 | if (inner_get_param(CTRL_AP, AP_NETWORK_0, "frequency", lynq_frequency_str) != 0) |
| 1555 | { |
| 1556 | RLOGE("[wifi error][lynq_wifi_ap_frequency_get]get frequency from device fail"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1557 | return -1; |
| 1558 | } |
| 1559 | *lynq_wifi_frequency = atoi(lynq_frequency_str); |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1560 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1561 | return 0; |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1562 | } |
| 1563 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1564 | int lynq_wifi_ap_bandwidth_set(lynq_wifi_index_e idx,lynq_wifi_bandwidth_type_m bandwidth) |
| 1565 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1566 | RLOGD("enter lynq_wifi_ap_bandwidth_set"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1567 | CHECK_IDX(idx, CTRL_AP); |
| 1568 | switch(bandwidth){ |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1569 | case LYNQ_WIFI_BANDWIDTH_HT10: |
| 1570 | { |
| 1571 | RLOGE("bandwith [%d] not support now\n", bandwidth); |
| 1572 | return -1; |
| 1573 | } |
| 1574 | case LYNQ_WIFI_BANDWIDTH_HT20: |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1575 | { |
| 1576 | char lynq_cmd_bandwith[MAX_CMD]="wl chanspec 6"; |
| 1577 | system("wl down"); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1578 | if (system(lynq_cmd_bandwith) != 0 ) |
| 1579 | { |
| 1580 | RLOGE("lynq_wifi_ap_bandwidth_set erro"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1581 | return -1; |
| 1582 | } |
| 1583 | system("wl up"); |
| 1584 | break; |
| 1585 | } |
| 1586 | case LYNQ_WIFI_BANDWIDTH_HT40: |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1587 | { |
qs.xiong | 1037919 | 2023-02-21 13:19:42 +0800 | [diff] [blame] | 1588 | char lynq_cmd_bandwith[MAX_CMD]="wl chanspec 149/40"; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1589 | sprintf(lynq_cmd_bandwith, "wl chanspec "); |
| 1590 | system("wl down"); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1591 | if (system(lynq_cmd_bandwith) != 0 ) |
| 1592 | { |
| 1593 | RLOGE("lynq_wifi_ap_bandwidth_set erro"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1594 | return -1; |
| 1595 | } |
| 1596 | system("wl up"); |
| 1597 | break; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1598 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1599 | case LYNQ_WIFI_BANDWIDTH_HT80: |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1600 | { |
qs.xiong | 1037919 | 2023-02-21 13:19:42 +0800 | [diff] [blame] | 1601 | char lynq_cmd_bandwith[MAX_CMD]="wl chanspec 149/80"; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1602 | system("wl down"); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1603 | if (system(lynq_cmd_bandwith) != 0 ) |
| 1604 | { |
| 1605 | RLOGE("lynq_wifi_ap_bandwidth_set erro"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1606 | return -1; |
| 1607 | } |
| 1608 | system("wl up"); |
| 1609 | break; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1610 | } |
| 1611 | default: |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1612 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1613 | RLOGE("auth type [%d] not support now\n", bandwidth); |
| 1614 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1615 | } |
| 1616 | } |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1617 | |
| 1618 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1619 | return 0; |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1620 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1621 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1622 | int lynq_wifi_ap_bandwidth_get(lynq_wifi_index_e idx,lynq_wifi_bandwidth_type_m* bandwidth) |
| 1623 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1624 | int count = 0; |
| 1625 | int index = 0; |
| 1626 | char *split_words[128] = {0}; |
| 1627 | const char *lynq_chanspec_cmd = "DRIVER chanspec\n"; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1628 | RLOGD("enter lynq_wifi_ap_bandwidth_get"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1629 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1630 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1631 | CHECK_WPA_CTRL(CTRL_AP); |
| 1632 | |
| 1633 | DO_REQUEST(lynq_chanspec_cmd); |
| 1634 | |
| 1635 | count = lynq_split(cmd_reply, reply_len, ' ', split_words); |
| 1636 | for(;index < count; index++) { |
| 1637 | if (strncmp(split_words[index], "bw", 2) != 0) { |
| 1638 | continue; |
| 1639 | } |
| 1640 | |
| 1641 | index++; |
| 1642 | if (index >= count) { |
| 1643 | return -1; |
| 1644 | } |
| 1645 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1646 | RLOGD("bw %s\n", split_words[index]); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1647 | *bandwidth = convert_bandwidth_from_bw(atoi(split_words[index])); |
| 1648 | return 0; |
| 1649 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1650 | RLOGE("[wifi error]lynq_wifi_ap_bandwidth_get"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1651 | return -1; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1652 | } |
qs.xiong | 0fb469a | 2022-04-14 03:50:45 -0400 | [diff] [blame] | 1653 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1654 | 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] | 1655 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1656 | char lynq_cmd_channel[MAX_CMD]={0}; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1657 | RLOGD("enter lynq_wifi_ap_channel_set and input channel is %d",channel); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1658 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 1d58e9b | 2022-04-14 06:17:01 -0400 | [diff] [blame] | 1659 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1660 | sprintf(lynq_cmd_channel, "wl channel %d", channel); |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1661 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1662 | if (lynq_check_network_number(idx, CTRL_AP, AP_NETWORK_0) != 0) |
| 1663 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1664 | return -1; |
| 1665 | } |
| 1666 | |
| 1667 | system("wl down"); |
| 1668 | if (system(lynq_cmd_channel) != 0 ){ |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1669 | RLOGE("lynq_wifi_ap_channel_set erro"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1670 | return -1; |
| 1671 | } |
| 1672 | system("wl up"); |
| 1673 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1674 | } |
qs.xiong | 0fb469a | 2022-04-14 03:50:45 -0400 | [diff] [blame] | 1675 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1676 | 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] | 1677 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1678 | int count = 0; |
| 1679 | int index = 0; |
| 1680 | char *split_words[128] = {0}; |
| 1681 | char lynq_chanspec_cmd[]="DRIVER chanspec\n"; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1682 | RLOGD("enter lynq_wifi_ap_channel_get"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1683 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1684 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1685 | CHECK_WPA_CTRL(CTRL_AP); |
| 1686 | |
| 1687 | DO_REQUEST(lynq_chanspec_cmd); |
| 1688 | |
| 1689 | count = lynq_split(cmd_reply, reply_len, ' ', split_words); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1690 | for(;index < count; index++) |
| 1691 | { |
| 1692 | RLOGD("[lynq_wifi_ap_channel_get]---- %s\n",split_words[index]); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1693 | if (strncmp(split_words[index], "channel", 2) != 0) { |
| 1694 | continue; |
| 1695 | } |
| 1696 | |
| 1697 | index++; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1698 | if (index >= count) |
| 1699 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1700 | return -1; |
| 1701 | } |
| 1702 | |
| 1703 | *channel = atoi(split_words[index]); |
| 1704 | return 0; |
| 1705 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1706 | RLOGE("[lynq_wifi_ap_channel_get] function fail"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1707 | return -1; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1711 | 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] | 1712 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1713 | char ssid[MAX_CMD] = {0}; |
| 1714 | int freq = 0; |
| 1715 | char lynq_auth_cmd[64]={0}; |
| 1716 | char lynq_auth_alg_cmd[64]={0}; |
| 1717 | char lynq_psk_cmd[64]={0}; |
| 1718 | char lynq_pairwise_cmd[64]={0}; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1719 | char lynq_ieee80211_cmd[64]={0}; |
| 1720 | RLOGD("enter lynq_wifi_ap_auth_set and input idx is:%d,auth is:%d",idx,auth); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1721 | lynq_wifi_auth_s org_auth; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1722 | CHECK_IDX(idx, CTRL_AP); |
| 1723 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1724 | CHECK_WPA_CTRL(CTRL_AP); |
| 1725 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1726 | if (lynq_check_network_number(idx, CTRL_AP, AP_NETWORK_0) != AP_NETWORK_0) |
| 1727 | { |
| 1728 | RLOGE("[wifi error][lynq_wifi_ap_auth_set] check network fail\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1729 | return -1; |
| 1730 | } |
| 1731 | |
you.chen | 92fd5d3 | 2022-05-25 10:09:47 +0800 | [diff] [blame] | 1732 | if (0 == lynq_wifi_ap_auth_get(idx, &org_auth) && org_auth != -1) { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1733 | if (org_auth == auth) { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 1734 | RLOGD("org_auth --- is %d\n",org_auth); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1735 | return 0; |
| 1736 | } |
| 1737 | else { |
| 1738 | if (0 != lynq_wifi_ap_ssid_get(idx, ssid)) { |
| 1739 | ssid[0] = '\0'; |
| 1740 | } |
| 1741 | lynq_wifi_ap_frequency_get(idx, &freq); |
| 1742 | |
| 1743 | DO_OK_FAIL_REQUEST(cmd_disconnect); |
| 1744 | DO_OK_FAIL_REQUEST(cmd_remove_all); |
| 1745 | if (ssid[0] != '\0') { |
| 1746 | lynq_wifi_ap_ssid_set(idx, ssid); |
| 1747 | } |
| 1748 | if (freq != 0) { |
| 1749 | lynq_wifi_ap_frequency_set(idx, freq); |
| 1750 | } |
| 1751 | } |
| 1752 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1753 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1754 | switch(auth){ |
| 1755 | case LYNQ_WIFI_AUTH_OPEN: |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1756 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 1757 | RLOGD("auth == is LYNQ_WIFI_AUTH_OPEN\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1758 | sprintf(lynq_auth_cmd,"SET_NETWORK %d key_mgmt NONE", AP_NETWORK_0); |
you.chen | 92fd5d3 | 2022-05-25 10:09:47 +0800 | [diff] [blame] | 1759 | sprintf(lynq_pairwise_cmd,"SET_NETWORK %d pairwise NONE", AP_NETWORK_0); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1760 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1761 | break; |
| 1762 | } |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1763 | case LYNQ_WIFI_AUTH_WEP: |
| 1764 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 1765 | RLOGD("auth == is LYNQ_WIFI_AUTH_WEP\n"); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1766 | sprintf(lynq_auth_cmd,"SET_NETWORK %d key_mgmt NONE", AP_NETWORK_0); |
you.chen | 92fd5d3 | 2022-05-25 10:09:47 +0800 | [diff] [blame] | 1767 | sprintf(lynq_pairwise_cmd,"SET_NETWORK %d pairwise NONE", AP_NETWORK_0); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1768 | sprintf(lynq_auth_alg_cmd,"SET_NETWORK %d auth_alg SHARED", AP_NETWORK_0); |
| 1769 | |
| 1770 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
| 1771 | DO_OK_FAIL_REQUEST(lynq_auth_alg_cmd); |
| 1772 | break; |
| 1773 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1774 | case LYNQ_WIFI_AUTH_WPA_PSK: |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 1775 | { |
| 1776 | sprintf(lynq_auth_cmd,"SET_NETWORK %d proto WPA", AP_NETWORK_0); |
| 1777 | sprintf(lynq_psk_cmd,"SET_NETWORK %d key_mgmt WPA-PSK", AP_NETWORK_0); |
| 1778 | sprintf(lynq_pairwise_cmd,"SET_NETWORK %d pairwise CCMP", AP_NETWORK_0); |
| 1779 | |
| 1780 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
| 1781 | DO_OK_FAIL_REQUEST(lynq_psk_cmd); |
| 1782 | DO_OK_FAIL_REQUEST(lynq_pairwise_cmd); |
| 1783 | break; |
| 1784 | |
| 1785 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1786 | case LYNQ_WIFI_AUTH_WPA2_PSK: |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1787 | { |
| 1788 | if (auth == LYNQ_WIFI_AUTH_WPA_PSK) |
| 1789 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1790 | sprintf(lynq_auth_cmd,"SET_NETWORK %d proto WPA", AP_NETWORK_0); |
| 1791 | sprintf(lynq_psk_cmd,"SET_NETWORK %d key_mgmt WPA-PSK", AP_NETWORK_0); |
| 1792 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1793 | else if (auth == LYNQ_WIFI_AUTH_WPA2_PSK) |
| 1794 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1795 | sprintf(lynq_auth_cmd,"SET_NETWORK %d proto RSN", AP_NETWORK_0); |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 1796 | 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] | 1797 | } |
| 1798 | // sprintf(lynq_auth_cmd,"SET_NETWORK %d proto WPA2", AP_NETWORK_0); |
| 1799 | // sprintf(lynq_psk_cmd,"SET_NETWORK %d key_mgmt WPA-PSK", AP_NETWORK_0); |
| 1800 | sprintf(lynq_pairwise_cmd,"SET_NETWORK %d pairwise CCMP", AP_NETWORK_0); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1801 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1802 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
| 1803 | DO_OK_FAIL_REQUEST(lynq_psk_cmd); |
| 1804 | DO_OK_FAIL_REQUEST(lynq_pairwise_cmd); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1805 | break; |
| 1806 | } |
| 1807 | case LYNQ_WIFI_AUTH_WPA2_WPA3_PSK: |
| 1808 | { |
| 1809 | sprintf(lynq_auth_cmd,"SET_NETWORK %d proto WPA2", AP_NETWORK_0); |
| 1810 | sprintf(lynq_ieee80211_cmd,"SET_NETWORK %d ieee80211w 1", AP_NETWORK_0); |
| 1811 | sprintf(lynq_psk_cmd,"SET_NETWORK %d key_mgmt WPA-PSK SAE", AP_NETWORK_0); |
| 1812 | sprintf(lynq_pairwise_cmd,"SET_NETWORK %d pairwise CCMP", AP_NETWORK_0); |
| 1813 | |
| 1814 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
| 1815 | DO_OK_FAIL_REQUEST(lynq_ieee80211_cmd); |
| 1816 | DO_OK_FAIL_REQUEST(lynq_psk_cmd); |
| 1817 | DO_OK_FAIL_REQUEST(lynq_pairwise_cmd); |
| 1818 | break; |
| 1819 | } |
| 1820 | case LYNQ_WIFI_AUTH_WPA3_PSK: |
| 1821 | { |
| 1822 | sprintf(lynq_auth_cmd,"SET_NETWORK %d proto WPA2", AP_NETWORK_0); |
| 1823 | sprintf(lynq_ieee80211_cmd,"SET_NETWORK %d ieee80211w 2", AP_NETWORK_0); |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 1824 | sprintf(lynq_psk_cmd,"SET_NETWORK %d key_mgmt SAE", AP_NETWORK_0); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1825 | sprintf(lynq_pairwise_cmd,"SET_NETWORK %d pairwise CCMP", AP_NETWORK_0); |
| 1826 | |
| 1827 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
| 1828 | DO_OK_FAIL_REQUEST(lynq_ieee80211_cmd); |
| 1829 | DO_OK_FAIL_REQUEST(lynq_psk_cmd); |
| 1830 | DO_OK_FAIL_REQUEST(lynq_pairwise_cmd); |
| 1831 | break; |
| 1832 | } |
| 1833 | default: |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1834 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1835 | RLOGE("auth type [%d] not support now\n", auth); |
| 1836 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1837 | } |
| 1838 | } |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1839 | DO_OK_FAIL_REQUEST(cmd_save_config); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1840 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1841 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1842 | } |
| 1843 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1844 | 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] | 1845 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1846 | char lynq_auth_str[MAX_RET] = {0}; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1847 | char lynq_auth_alg_str[MAX_RET] = {0}; |
| 1848 | char lynq_proto_str[MAX_RET] = {0}; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1849 | RLOGD("enter lynq_wifi_ap_auth_get"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1850 | CHECK_IDX(idx, CTRL_AP); |
| 1851 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1852 | if (inner_get_param(CTRL_AP, AP_NETWORK_0, "key_mgmt", lynq_auth_str) != 0) |
| 1853 | { |
| 1854 | RLOGE("[wifi error][lynq_wifi_ap_auth_get] check network fail"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1855 | return -1; |
| 1856 | } |
| 1857 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1858 | if (memcmp( lynq_auth_str, "NONE", 4) == 0) |
| 1859 | { |
| 1860 | if (inner_get_param(CTRL_AP, AP_NETWORK_0, "auth_alg", lynq_auth_alg_str) != 0) |
| 1861 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 1862 | RLOGD("---auth is OPEN\n"); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1863 | *auth = LYNQ_WIFI_AUTH_OPEN; |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 1864 | return 0; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1865 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1866 | else if (memcmp(lynq_auth_alg_str, "SHARED", 6) == 0) |
| 1867 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 1868 | RLOGD("---auth is WEP\n"); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1869 | *auth = LYNQ_WIFI_AUTH_WEP; |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 1870 | return 0; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1871 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1872 | else |
| 1873 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 1874 | RLOGD("---auth is OPEN\n"); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1875 | *auth = LYNQ_WIFI_AUTH_OPEN; |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 1876 | return 0; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1877 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1878 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1879 | else if(strcmp( lynq_auth_str, "WPA-PSK") == 0 ) |
| 1880 | { |
| 1881 | if (inner_get_param(CTRL_AP, AP_NETWORK_0, "proto", lynq_proto_str) != 0) |
| 1882 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 1883 | RLOGE("---auth is -1\n"); |
you.chen | 92fd5d3 | 2022-05-25 10:09:47 +0800 | [diff] [blame] | 1884 | *auth = -1; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1885 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1886 | else if (memcmp(lynq_proto_str, "RSN", 3) == 0) |
| 1887 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 1888 | RLOGD("---auth WPA2_PSK\n"); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1889 | *auth = LYNQ_WIFI_AUTH_WPA2_PSK; |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 1890 | return 0; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1891 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1892 | else |
| 1893 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 1894 | RLOGD("---auth WPA_PSK\n"); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1895 | *auth = LYNQ_WIFI_AUTH_WPA_PSK; |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 1896 | return 0; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1897 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1898 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1899 | |
| 1900 | if (inner_get_param(CTRL_AP, AP_NETWORK_0, "ieee80211w", lynq_auth_str) != 0) |
| 1901 | { |
| 1902 | RLOGE("[wifi error][lynq_wifi_ap_auth_get] check network auth ieee80211w fail"); |
| 1903 | return -1; |
| 1904 | } |
| 1905 | |
| 1906 | if (memcmp(lynq_auth_str,"1",1) == 0 ) |
| 1907 | { |
| 1908 | RLOGD("auth : LYNQ_WIFI_AUTH_WPA2_WPA3_PSK\n"); |
| 1909 | *auth = LYNQ_WIFI_AUTH_WPA2_WPA3_PSK; |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 1910 | return 0; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1911 | }else if (memcmp(lynq_auth_str,"2",1) == 0 ) |
| 1912 | { |
| 1913 | RLOGD("auth : LYNQ_WIFI_AUTH_WPA3_PSK\n"); |
| 1914 | *auth = LYNQ_WIFI_AUTH_WPA3_PSK; |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 1915 | return 0; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1916 | } |
| 1917 | else |
| 1918 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 1919 | RLOGE("---auth -- -1\n"); |
you.chen | 92fd5d3 | 2022-05-25 10:09:47 +0800 | [diff] [blame] | 1920 | *auth = -1; |
| 1921 | } |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1922 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1923 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1924 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1925 | |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1926 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1927 | int lynq_wifi_ap_start(lynq_wifi_index_e idx) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1928 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1929 | char LYNQ_WIFI_CMD[128]={0}; |
| 1930 | //const char *lynq_remove_all_cmd = "REMOVE_NETWORK all"; |
| 1931 | //const char *lynq_reconfig_cmd = "RECONFIGURE /data/wifi/wg870/wpa_supplicant.conf"; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1932 | RLOGD("enter lynq_wifi_ap_channel_get"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1933 | CHECK_IDX(idx, CTRL_AP); |
| 1934 | |
| 1935 | CHECK_WPA_CTRL(CTRL_AP); |
| 1936 | |
| 1937 | // system("connmanctl enable wifi"); |
| 1938 | // system("connmanctl tether wifi on cy-test 12345678"); |
| 1939 | // system("ifconfig wlan0 down"); |
| 1940 | // system("ifconfig wlan0 up"); |
| 1941 | // system("ifconfig wlan0 up"); |
| 1942 | |
| 1943 | //DO_OK_FAIL_REQUEST(lynq_remove_all_cmd); |
| 1944 | //DO_OK_FAIL_REQUEST(lynq_reconfig_cmd); |
| 1945 | |
| 1946 | sprintf(LYNQ_WIFI_CMD,"SELECT_NETWORK %d",AP_NETWORK_0); |
| 1947 | DO_OK_FAIL_REQUEST(LYNQ_WIFI_CMD); |
| 1948 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 1949 | check_tether_and_notify(); |
| 1950 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1951 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1952 | } |
| 1953 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1954 | int lynq_wifi_ap_restart(lynq_wifi_index_e idx) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1955 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1956 | 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] | 1957 | } |
| 1958 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1959 | int lynq_wifi_ap_stop(lynq_wifi_index_e idx) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1960 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1961 | char LYNQ_WIFI_CMD[128]={0}; |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1962 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1963 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1964 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1965 | CHECK_WPA_CTRL(CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1966 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1967 | sprintf(LYNQ_WIFI_CMD,"DISABLE_NETWORK %d",AP_NETWORK_0); |
| 1968 | |
| 1969 | DO_OK_FAIL_REQUEST(LYNQ_WIFI_CMD); |
| 1970 | |
you.chen | b4b121c | 2022-05-06 17:50:16 +0800 | [diff] [blame] | 1971 | // system("connmanctl tether wifi off"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1972 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1973 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1974 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1975 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1976 | int lynq_wifi_ap_hide_ssid(lynq_wifi_index_e idx) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1977 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1978 | char lynq_disable_cmd[128] = {0}; |
| 1979 | char lynq_select_cmd[128] = {0}; |
| 1980 | const char *lynq_hide_cmd = "SET HIDE_SSID 1"; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1981 | RLOGD("enter lynq_wifi_ap_hide_ssid"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1982 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1983 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1984 | CHECK_WPA_CTRL(CTRL_AP); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1985 | sprintf(lynq_disable_cmd,"DISABLE_NETWORK %d", AP_NETWORK_0); |
| 1986 | sprintf(lynq_select_cmd,"SELECT_NETWORK %d", AP_NETWORK_0); |
| 1987 | |
| 1988 | DO_OK_FAIL_REQUEST(lynq_disable_cmd); |
| 1989 | DO_OK_FAIL_REQUEST(lynq_hide_cmd); |
| 1990 | DO_OK_FAIL_REQUEST(lynq_select_cmd); |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1991 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1992 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1993 | } |
| 1994 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1995 | int lynq_wifi_ap_unhide_ssid(lynq_wifi_index_e idx) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1996 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1997 | char lynq_disable_cmd[128] = {0}; |
| 1998 | char lynq_select_cmd[128] = {0}; |
| 1999 | const char *lynq_unhide_cmd = "SET HIDE_SSID 0"; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2000 | RLOGD("enter lynq_wifi_ap_unhide_ssid"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2001 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2002 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2003 | CHECK_WPA_CTRL(CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2004 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2005 | sprintf(lynq_disable_cmd,"DISABLE_NETWORK %d", AP_NETWORK_0); |
| 2006 | sprintf(lynq_select_cmd,"SELECT_NETWORK %d", AP_NETWORK_0); |
| 2007 | |
| 2008 | DO_OK_FAIL_REQUEST(lynq_disable_cmd); |
| 2009 | DO_OK_FAIL_REQUEST(lynq_unhide_cmd); |
| 2010 | DO_OK_FAIL_REQUEST(lynq_select_cmd); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2011 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2012 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2013 | } |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2014 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2015 | int lynq_ap_password_set(lynq_wifi_index_e idx,char *password) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2016 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2017 | int pass_len; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2018 | char lynq_tmp_cmd[MAX_CMD] = {0}; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2019 | char lynq_wpa2_wpa3[64] = {0}; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2020 | char lynq_wep_tx_keyidx_cmd[MAX_CMD] = {0}; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2021 | RLOGD("enter lynq_ap_password_set"); |
| 2022 | if( password == NULL ) |
| 2023 | { |
| 2024 | RLOGE("[lynq_ap_password_set]input password is NULL"); |
qs.xiong | e707432 | 2022-06-27 11:34:53 +0800 | [diff] [blame] | 2025 | return -1; |
| 2026 | } |
| 2027 | pass_len=strlen(password); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2028 | lynq_wifi_auth_s auth = -1; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2029 | if(pass_len < 8 || pass_len >= 64) |
| 2030 | { |
| 2031 | RLOGE("[lynq_ap_password_set]input password len not in rage"); |
| 2032 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2033 | } |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2034 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2035 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2036 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2037 | if (0 != lynq_wifi_ap_auth_get(idx, &auth)) |
| 2038 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2039 | RLOGE("[lynq_ap_password_set] get ap auth info error\n"); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2040 | return -1; |
| 2041 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2042 | else if (auth == LYNQ_WIFI_AUTH_OPEN) |
| 2043 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2044 | RLOGD("ap auth :LYNQ_WIFI_AUTH_OPEN\n"); |
| 2045 | return 0; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2046 | } |
| 2047 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2048 | CHECK_WPA_CTRL(CTRL_AP); |
| 2049 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2050 | if (auth == LYNQ_WIFI_AUTH_WEP) |
| 2051 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2052 | RLOGD("[lynq_ap_password_set]ap auth : LYNQ_WIFI_AUTH_WEP\n"); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2053 | sprintf(lynq_tmp_cmd,"SET_NETWORK %d wep_key0 \"%s\"",AP_NETWORK_0, password); |
| 2054 | sprintf(lynq_wep_tx_keyidx_cmd,"SET_NETWORK %d wep_tx_keyidx 0",AP_NETWORK_0); |
| 2055 | DO_OK_FAIL_REQUEST(lynq_tmp_cmd); |
| 2056 | DO_OK_FAIL_REQUEST(lynq_wep_tx_keyidx_cmd); |
| 2057 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2058 | else if (auth == LYNQ_WIFI_AUTH_WPA_PSK || auth == LYNQ_WIFI_AUTH_WPA2_PSK) |
| 2059 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2060 | RLOGD("[lynq_ap_password_set]ap auth :LYNQ_WIFI_AUTH_WPA_PSK LYNQ_WIFI_AUTH_WPA2_PSK\n"); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2061 | sprintf(lynq_tmp_cmd,"SET_NETWORK %d psk \"%s\"",AP_NETWORK_0, password); |
| 2062 | DO_OK_FAIL_REQUEST(lynq_tmp_cmd); |
| 2063 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2064 | else if (auth == LYNQ_WIFI_AUTH_WPA2_WPA3_PSK || auth == LYNQ_WIFI_AUTH_WPA3_PSK) |
| 2065 | { |
| 2066 | |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2067 | RLOGD("[lynq_ap_password_set]ap auth :LYNQ_WIFI_AUTH_WPA2_WPA3 LYNQ_WIFI_AUTH_WPA3_PSK\n"); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2068 | sprintf(lynq_tmp_cmd,"SET_NETWORK %d psk \"%s\"",AP_NETWORK_0, password); |
qs.xiong | fd771f4 | 2023-03-28 14:06:12 +0800 | [diff] [blame] | 2069 | sprintf(lynq_wpa2_wpa3,"SET_NETWORK %d sae_password \"%s\"",AP_NETWORK_0, password); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2070 | DO_OK_FAIL_REQUEST(lynq_tmp_cmd); |
| 2071 | DO_OK_FAIL_REQUEST(lynq_wpa2_wpa3); |
| 2072 | |
| 2073 | } |
| 2074 | else |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2075 | { |
| 2076 | RLOGD("[lynq_ap_password_set]ap auth :get ap auth error\n"); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2077 | return -1; |
| 2078 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2079 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2080 | DO_OK_FAIL_REQUEST(cmd_save_config); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2081 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2082 | return 0; |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2083 | } |
| 2084 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2085 | int lynq_ap_password_get(lynq_wifi_index_e idx, char *password) |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2086 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2087 | FILE * fp; |
| 2088 | int len, ret; |
| 2089 | int count, index; |
| 2090 | char *split_lines[128] = {0}; |
| 2091 | char *buff, *p; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2092 | RLOGD("enter lynq_ap_password_get"); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2093 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2094 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2095 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2096 | fp = fopen("/data/wifi/wg870/wpa_supplicant_ap.conf", "rb"); |
| 2097 | // fp = fopen("/data/wifi/wg870/wpa_supplicant.conf", "rb"); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2098 | if (NULL == fp) |
| 2099 | { |
| 2100 | RLOGE("open file fail\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2101 | return -1; |
| 2102 | } |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2103 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2104 | buff = alloca(MAX_RET); |
| 2105 | fseek(fp, 0, SEEK_SET); |
| 2106 | len = fread(buff, 1, MAX_RET, fp); |
| 2107 | fclose(fp); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2108 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2109 | for(index=0; index < len; index ++) |
| 2110 | { |
| 2111 | if (memcmp(buff + index, "network={", 9) != 0) |
| 2112 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2113 | continue; |
| 2114 | } |
| 2115 | p = buff + index + 9; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2116 | for (; index < len; index ++ ) |
| 2117 | { |
| 2118 | if (buff[index] != '}') |
| 2119 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2120 | continue; |
| 2121 | } |
| 2122 | buff[index] = '\0'; |
| 2123 | break; |
| 2124 | } |
| 2125 | len = buff + index - p; |
| 2126 | } |
| 2127 | |
| 2128 | count = lynq_split(p, len, '\n', split_lines); |
| 2129 | |
| 2130 | ret = -1; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2131 | for(index=0; index < count; index++) |
| 2132 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2133 | p = strstr(split_lines[index], "psk="); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2134 | if (p != NULL) |
| 2135 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2136 | p += 4; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2137 | if (*p == '\"') |
| 2138 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2139 | p++; |
| 2140 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2141 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2142 | else if (NULL != (p = strstr(split_lines[index], "wep_key0="))) |
| 2143 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2144 | p += 9; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2145 | if (*p == '\"') |
| 2146 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2147 | p++; |
| 2148 | } |
| 2149 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2150 | else |
| 2151 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2152 | continue; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2153 | } |
| 2154 | |
| 2155 | strcpy(password, p); |
| 2156 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2157 | while(*password != '\0') |
| 2158 | { |
| 2159 | if (*password == '\"') |
| 2160 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2161 | *password = '\0'; |
| 2162 | break; |
| 2163 | } |
| 2164 | password++; |
| 2165 | } |
| 2166 | ret = 0; |
| 2167 | break; |
| 2168 | } //end for(index=0; index < count; index++) |
| 2169 | |
| 2170 | return ret; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2171 | } |
| 2172 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2173 | static int inner_get_network_auth(int interface, int net_no, lynq_wifi_auth_s *auth) { |
| 2174 | char lynq_auth_str[MAX_RET] = {0}; |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2175 | char lynq_proto_str[MAX_RET] = {0}; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2176 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2177 | if (inner_get_param(interface, net_no, "key_mgmt", lynq_auth_str) != 0) |
| 2178 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2179 | return -1; |
| 2180 | } |
| 2181 | |
| 2182 | *auth = convert_auth_from_key_mgmt(lynq_auth_str); |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2183 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2184 | if (*auth == LYNQ_WIFI_AUTH_WPA_PSK) |
| 2185 | { |
| 2186 | if (inner_get_param(interface, net_no, "proto", lynq_proto_str) == 0) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 2187 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2188 | if (strcmp(lynq_proto_str, "RSN") == 0) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 2189 | { |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2190 | *auth = LYNQ_WIFI_AUTH_WPA2_PSK; |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2191 | return 0; |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2192 | } |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 2193 | else if (strcmp(lynq_proto_str, "WPA") == 0) // need compare when wpa3 supported |
| 2194 | { |
| 2195 | return 0; |
| 2196 | } |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2197 | } |
| 2198 | } |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 2199 | else if (*auth == LYNQ_WIFI_AUTH_OPEN || *auth == LYNQ_WIFI_AUTH_WEP) |
| 2200 | { |
| 2201 | return 0; |
| 2202 | } |
| 2203 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2204 | if (inner_get_param(interface, net_no,"ieee80211w",lynq_auth_str) !=0) |
| 2205 | { |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 2206 | RLOGE("check ieee80211w error\n"); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2207 | return -1; |
| 2208 | } |
| 2209 | if ( strncmp(lynq_auth_str,"1",1) == 0 ) |
| 2210 | { |
| 2211 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 2212 | *auth = LYNQ_WIFI_AUTH_WPA2_WPA3_PSK; |
| 2213 | return 0; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2214 | }else if( strncmp(lynq_auth_str,"2",1) == 0 ) |
| 2215 | { |
| 2216 | |
| 2217 | *auth = LYNQ_WIFI_AUTH_WPA3_PSK; |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2218 | return 0; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2219 | }else |
| 2220 | { |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 2221 | RLOGE("check ieee80211w error, not 1 or 2\n"); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2222 | *auth = -1; |
| 2223 | return -1; |
| 2224 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2225 | return 0; |
| 2226 | } |
| 2227 | |
| 2228 | 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] | 2229 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2230 | RLOGD("enter lynq_sta_ssid_password_set"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2231 | int pass_len, net_no, count, index; |
| 2232 | char lynq_tmp_cmd[300]={0}; |
| 2233 | int net_no_list[128]; |
| 2234 | lynq_wifi_auth_s net_auth; |
| 2235 | pass_len=strlen(password); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2236 | if(pass_len < 8 || pass_len >= 64) |
| 2237 | { |
| 2238 | RLOGE("[lynq_sta_ssid_password_set]input psw error"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2239 | return -1; |
| 2240 | } |
| 2241 | |
| 2242 | CHECK_IDX(idx, CTRL_STA); |
| 2243 | |
| 2244 | net_no = -1; |
| 2245 | count = lynq_get_network_number_list(idx, CTRL_STA, net_no_list, ap->ap_ssid); |
| 2246 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2247 | for (index=0; index < count; index++) |
| 2248 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2249 | net_auth = -1; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2250 | if (0 == inner_get_network_auth(CTRL_STA, net_no_list[index], &net_auth) && net_auth == ap->auth) |
| 2251 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2252 | net_no = net_no_list[index]; |
| 2253 | break; |
| 2254 | } |
| 2255 | } |
| 2256 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2257 | if (net_no < 0) |
| 2258 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2259 | return -1; |
| 2260 | } |
| 2261 | |
| 2262 | CHECK_WPA_CTRL(CTRL_STA); |
| 2263 | |
| 2264 | sprintf(lynq_tmp_cmd,"SET_NETWORK %d psk \"%s\"",net_no, password); |
| 2265 | |
| 2266 | DO_OK_FAIL_REQUEST(lynq_tmp_cmd); |
| 2267 | DO_OK_FAIL_REQUEST(cmd_save_config); |
| 2268 | |
| 2269 | return 0; |
| 2270 | } |
| 2271 | |
| 2272 | int lynq_sta_ssid_password_get(lynq_wifi_index_e idx, ap_info_s *ap, char *password) { // @todo |
| 2273 | |
| 2274 | FILE * fp; |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 2275 | int len, ret, network_len, i, ssid_len; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2276 | int count, index; |
| 2277 | char *split_lines[128] = {0}; |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 2278 | char *buff, *p, *ssid, *ssid_end_flag; |
| 2279 | char tmp_ssid[128]={0}; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2280 | RLOGD("enter lynq_sta_ssid_password_get"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2281 | |
you.chen | 755332b | 2022-08-06 16:59:10 +0800 | [diff] [blame] | 2282 | network_len = 0; |
| 2283 | p = NULL; |
| 2284 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2285 | CHECK_IDX(idx, CTRL_STA); |
| 2286 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2287 | if (NULL == password) |
| 2288 | { |
| 2289 | RLOGE("bad param\n"); |
you.chen | 755332b | 2022-08-06 16:59:10 +0800 | [diff] [blame] | 2290 | return -1; |
| 2291 | } |
| 2292 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2293 | fp = fopen("/data/wifi/wg870/wpa_supplicant.conf", "rb"); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2294 | if (NULL == fp) |
| 2295 | { |
| 2296 | RLOGE("[lynq_sta_ssid_password_get] open file fail\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2297 | return -1; |
| 2298 | } |
| 2299 | |
| 2300 | buff = alloca(MAX_RET); |
| 2301 | fseek(fp, 0, SEEK_SET); |
| 2302 | len = fread(buff, 1, MAX_RET, fp); |
| 2303 | fclose(fp); |
| 2304 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2305 | for(index=0; index < len; index ++) |
| 2306 | { |
| 2307 | for(; index < len; index ++) |
| 2308 | { |
| 2309 | if (memcmp(buff + index, "network={", 9) != 0) |
| 2310 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2311 | continue; |
| 2312 | } |
| 2313 | p = buff + index + 9; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2314 | for (; index < len; index ++ ) |
| 2315 | { |
| 2316 | if (buff[index] != '}') |
| 2317 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2318 | continue; |
| 2319 | } |
| 2320 | buff[index] = '\0'; |
| 2321 | break; |
| 2322 | } |
you.chen | 755332b | 2022-08-06 16:59:10 +0800 | [diff] [blame] | 2323 | network_len = buff + index - p; |
| 2324 | break; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2325 | } |
| 2326 | |
qs.xiong | b3f26af | 2023-02-17 18:41:07 +0800 | [diff] [blame] | 2327 | if (p == NULL) |
| 2328 | return -1; |
| 2329 | |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 2330 | ssid = strstr(p, "ssid="); |
| 2331 | if (ssid != NULL) { |
| 2332 | ssid += strlen("ssid="); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2333 | if (ssid[0] == '\"') |
| 2334 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 2335 | if (memcmp(ssid + 1, ap->ap_ssid, strlen(ap->ap_ssid)) == 0 && ssid[strlen(ap->ap_ssid) + 1] == '\"') |
| 2336 | break; |
| 2337 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2338 | else |
| 2339 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 2340 | ssid_end_flag = strstr(ssid, "\n"); |
| 2341 | if (ssid_end_flag != NULL) |
| 2342 | { |
| 2343 | ssid_len = (ssid_end_flag - ssid) / 2; |
| 2344 | for(i=0; i<ssid_len; i++) |
| 2345 | { |
| 2346 | tmp_ssid[i] = inner_convert_char(ssid[i*2]) << 4 | inner_convert_char(ssid[i*2 + 1]); |
| 2347 | } |
| 2348 | if (memcmp(tmp_ssid, ap->ap_ssid, ssid_len) == 0) |
| 2349 | break; |
| 2350 | } |
| 2351 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2352 | } |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 2353 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2354 | } |
| 2355 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2356 | if (index >= len || NULL == p || network_len <= 0) |
| 2357 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2358 | return -1; |
| 2359 | } |
| 2360 | |
you.chen | 755332b | 2022-08-06 16:59:10 +0800 | [diff] [blame] | 2361 | count = lynq_split(p, network_len, '\n', split_lines); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2362 | |
| 2363 | ret = -1; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2364 | for(index=0; index < count; index++) |
| 2365 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2366 | p = strstr(split_lines[index], "psk="); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2367 | if (p != NULL) |
| 2368 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2369 | p += 4; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2370 | if (*p == '\"') |
| 2371 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2372 | p++; |
| 2373 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2374 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2375 | else if (NULL != (p = strstr(split_lines[index], "wep_key0="))) |
| 2376 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2377 | p += 9; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2378 | if (*p == '\"') |
| 2379 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2380 | p++; |
| 2381 | } |
| 2382 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2383 | else |
| 2384 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2385 | continue; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2386 | } |
| 2387 | |
qs.xiong | 1367346 | 2023-02-21 19:12:54 +0800 | [diff] [blame] | 2388 | if (*p == '\"') |
| 2389 | p++; |
| 2390 | strncpy(password, p, 64); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2391 | |
qs.xiong | 1367346 | 2023-02-21 19:12:54 +0800 | [diff] [blame] | 2392 | p = password; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2393 | while(password - p < 64 && *password != '\0') |
| 2394 | { |
| 2395 | if (*password == '\"') |
| 2396 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2397 | *password = '\0'; |
| 2398 | break; |
| 2399 | } |
| 2400 | password++; |
| 2401 | } |
| 2402 | ret = 0; |
| 2403 | break; |
| 2404 | } //end for(index=0; index < count; index++) |
| 2405 | |
| 2406 | return ret; |
| 2407 | } |
| 2408 | |
| 2409 | static int inner_set_sta_ssid(int net_no, char *sta_ssid) |
| 2410 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2411 | char lynq_wifi_ssid_cmd[80]={0}; |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2412 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2413 | if (sta_ssid == NULL) |
| 2414 | { |
| 2415 | RLOGE("sta_ssid is null\n"); |
| 2416 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2417 | } |
| 2418 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2419 | CHECK_WPA_CTRL(CTRL_STA); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2420 | |
| 2421 | sprintf(lynq_wifi_ssid_cmd,"SET_NETWORK %d ssid \"%s\"", net_no, sta_ssid); |
| 2422 | |
| 2423 | DO_OK_FAIL_REQUEST(lynq_wifi_ssid_cmd); |
| 2424 | // DO_OK_FAIL_REQUEST(cmd_save_config); |
| 2425 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2426 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2427 | |
| 2428 | } |
| 2429 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2430 | 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] | 2431 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2432 | char lynq_disable_cmd[128]={0}; |
| 2433 | char lynq_select_cmd[128]={0}; |
| 2434 | |
| 2435 | CHECK_WPA_CTRL(CTRL_STA); |
| 2436 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2437 | if (save != 0) |
| 2438 | { |
you.chen | c29444e | 2022-06-07 18:01:16 +0800 | [diff] [blame] | 2439 | if (start_flag != 0) |
| 2440 | { |
| 2441 | sprintf(lynq_select_cmd,"ENABLE_NETWORK %d", net_no); |
| 2442 | DO_OK_FAIL_REQUEST(lynq_select_cmd); |
| 2443 | } |
| 2444 | else |
| 2445 | { |
| 2446 | sprintf(lynq_select_cmd,"DISABLE_NETWORK %d", net_no); |
| 2447 | DO_OK_FAIL_REQUEST(lynq_select_cmd); |
| 2448 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2449 | DO_OK_FAIL_REQUEST(cmd_save_config); |
| 2450 | } |
| 2451 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2452 | if (start_flag == 0) |
| 2453 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2454 | sprintf(lynq_disable_cmd,"DISCONNECT"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2455 | DO_OK_FAIL_REQUEST(lynq_disable_cmd); |
| 2456 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2457 | else |
| 2458 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2459 | sprintf(lynq_select_cmd,"SELECT_NETWORK %d", net_no); |
| 2460 | DO_OK_FAIL_REQUEST(lynq_select_cmd); |
| 2461 | } |
| 2462 | |
| 2463 | return 0; |
| 2464 | } |
| 2465 | |
| 2466 | int lynq_wifi_get_sta_ssid(lynq_wifi_index_e idx, char* sta_ssid) |
| 2467 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2468 | RLOGD("enter lynq_sta_ssid_password_set"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2469 | CHECK_IDX(idx, CTRL_STA); |
| 2470 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2471 | curr_status_info curr_state; |
| 2472 | ap_info_s ap_info; |
| 2473 | curr_state.ap = &ap_info; |
| 2474 | curr_state.state = NULL; |
| 2475 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2476 | if (0 == inner_get_status_info(CTRL_STA, &curr_state)) |
| 2477 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 2478 | strncpy(sta_ssid, ap_info.ap_ssid, sizeof (ap_info.ap_ssid)); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2479 | return 0; |
| 2480 | } |
| 2481 | |
| 2482 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2483 | } |
| 2484 | |
| 2485 | int lynq_wifi_get_sta_available_ap(lynq_wifi_index_e idx, ap_detail_info_s *info) |
| 2486 | { |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 2487 | scan_info_s *scan_list = NULL; |
| 2488 | saved_ap_info_s *save_list = NULL; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2489 | int scan_len=0; |
| 2490 | int save_len=0; |
| 2491 | int best_index = -1; |
| 2492 | int best_scan_index = -1; |
| 2493 | int best_rssi = 0; |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 2494 | int i, j, ret; |
| 2495 | |
| 2496 | ret = -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2497 | |
| 2498 | CHECK_IDX(idx, CTRL_STA); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2499 | if (info == NULL) |
| 2500 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2501 | return -1; |
| 2502 | } |
| 2503 | |
| 2504 | curr_status_info curr_state; |
| 2505 | ap_info_s ap_info; |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 2506 | char status[64]; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2507 | |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 2508 | memset(&ap_info, 0, sizeof (ap_info)); |
| 2509 | memset(status, 0, sizeof (status)); |
| 2510 | |
| 2511 | curr_state.ap = &ap_info; |
| 2512 | curr_state.state = status; |
| 2513 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2514 | if (0 == inner_get_status_info(CTRL_STA, &curr_state) && curr_state.net_no >= 0) |
| 2515 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2516 | memcpy(&info->base_info, &ap_info, sizeof (ap_info_s)); |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 2517 | if (strcmp(status, STATE_COMPLETED) == 0) |
| 2518 | { |
| 2519 | info->status = LYNQ_WIFI_AP_STATUS_ENABLE; |
| 2520 | } |
| 2521 | else |
| 2522 | { |
| 2523 | info->status = LYNQ_WIFI_AP_STATUS_DISABLE; |
| 2524 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2525 | lynq_get_connect_ap_rssi(idx, &info->rssi); |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 2526 | lynq_sta_ssid_password_get(idx, & info->base_info, info->base_info.psw); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2527 | return 0; |
| 2528 | } |
| 2529 | |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 2530 | lynq_wifi_sta_start_scan(idx); |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 2531 | sleep(2); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2532 | if (0 != lynq_get_scan_list(0, &scan_list, &scan_len)) |
| 2533 | { |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 2534 | if (NULL != scan_list) |
| 2535 | { |
| 2536 | free(scan_list); |
| 2537 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2538 | return -1; |
| 2539 | } |
| 2540 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2541 | if (0 != lynq_get_sta_saved_ap(0, &save_list, &save_len)) |
| 2542 | { |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 2543 | if (NULL != scan_list) |
| 2544 | { |
| 2545 | free(scan_list); |
| 2546 | } |
| 2547 | if (NULL != save_list) |
| 2548 | { |
| 2549 | free(save_list); |
| 2550 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2551 | return -1; |
| 2552 | } |
| 2553 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2554 | for (i=0; i < save_len; i++) |
| 2555 | { |
| 2556 | for (j=0; j < scan_len; j++) |
| 2557 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2558 | if (strcmp(save_list[i].base_info.ap_ssid, scan_list[j].ssid) == 0 //@todo not finished |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2559 | && save_list[i].base_info.auth == scan_list[j].auth) |
| 2560 | { |
| 2561 | if (best_rssi == 0) |
| 2562 | { |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 2563 | best_index = i; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2564 | best_rssi = scan_list[j].rssi; |
| 2565 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2566 | else if (best_rssi > scan_list[j].rssi) |
| 2567 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2568 | best_index = i; |
| 2569 | best_scan_index = j; |
| 2570 | best_rssi = scan_list[j].rssi; |
| 2571 | } |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 2572 | strncpy(save_list[i].base_info.ap_mac, scan_list[j].mac, sizeof (save_list[i].base_info.ap_mac)); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2573 | break; |
| 2574 | } |
| 2575 | } |
| 2576 | } |
| 2577 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2578 | if (best_index >= 0) |
| 2579 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2580 | memcpy(&info->base_info, &save_list[best_index].base_info, sizeof (ap_info_s)); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 2581 | inner_get_ip_by_mac( info->base_info.ap_mac, info->base_info.ap_ip, sizeof (info->base_info.ap_ip)); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2582 | info->status = LYNQ_WIFI_AP_STATUS_DISABLE; |
| 2583 | info->rssi = best_rssi; |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 2584 | ret = 0; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2585 | } |
| 2586 | |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 2587 | if (NULL != scan_list) |
| 2588 | { |
| 2589 | free(scan_list); |
| 2590 | } |
| 2591 | if (NULL != save_list) |
| 2592 | { |
| 2593 | free(save_list); |
| 2594 | } |
| 2595 | |
| 2596 | return ret; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2597 | } |
| 2598 | |
| 2599 | static int inner_set_sta_auth_psw(int net_no, lynq_wifi_auth_s auth, char *password) |
| 2600 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2601 | char lynq_auth_cmd[128]={0}; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2602 | char lynq_ket_mgmt_cmd[64]={0}; |
| 2603 | char lynq_pairwise_cmd[64]={0}; |
| 2604 | char lynq_psk_cmd[64]={0}; |
| 2605 | |
| 2606 | CHECK_WPA_CTRL(CTRL_STA); |
| 2607 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2608 | switch(auth) |
| 2609 | { |
| 2610 | case LYNQ_WIFI_AUTH_OPEN: |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2611 | { |
| 2612 | sprintf(lynq_auth_cmd,"SET_NETWORK %d key_mgmt NONE", net_no); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2613 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2614 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2615 | // DO_OK_FAIL_REQUEST(cmd_save_config); |
| 2616 | break; |
| 2617 | } |
| 2618 | case LYNQ_WIFI_AUTH_WPA_PSK: |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2619 | case LYNQ_WIFI_AUTH_WPA2_PSK: |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2620 | { |
| 2621 | if (auth == LYNQ_WIFI_AUTH_WPA_PSK) |
| 2622 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2623 | sprintf(lynq_auth_cmd,"SET_NETWORK %d proto WPA", net_no); |
| 2624 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2625 | else if (auth == LYNQ_WIFI_AUTH_WPA2_PSK) |
| 2626 | { |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2627 | sprintf(lynq_auth_cmd,"SET_NETWORK %d proto RSN", net_no); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2628 | } |
| 2629 | sprintf(lynq_ket_mgmt_cmd,"SET_NETWORK %d key_mgmt WPA-PSK", net_no); |
| 2630 | sprintf(lynq_pairwise_cmd,"SET_NETWORK %d pairwise CCMP", net_no); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2631 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2632 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
| 2633 | DO_OK_FAIL_REQUEST(lynq_ket_mgmt_cmd); |
| 2634 | DO_OK_FAIL_REQUEST(lynq_pairwise_cmd); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2635 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2636 | if (password != NULL) |
| 2637 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2638 | sprintf(lynq_psk_cmd, "SET_NETWORK %d psk \"%s\"", net_no, password); |
| 2639 | DO_OK_FAIL_REQUEST(lynq_psk_cmd); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2640 | sprintf(lynq_pairwise_cmd,"SET_NETWORK %d pairwise CCMP", net_no); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2641 | } |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2642 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2643 | // DO_OK_FAIL_REQUEST(cmd_save_config); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2644 | break; |
| 2645 | } |
| 2646 | case LYNQ_WIFI_AUTH_WPA2_WPA3_PSK: |
| 2647 | { |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 2648 | sprintf(lynq_auth_cmd,"SET_NETWORK %d ieee80211w 1",net_no); |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2649 | sprintf(lynq_ket_mgmt_cmd,"SET_NETWORK %d key_mgmt SAE WPA-PSK",net_no); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2650 | sprintf(lynq_pairwise_cmd,"SET_NETWORK %d pairwise CCMP", net_no); |
| 2651 | sprintf(lynq_psk_cmd, "SET_NETWORK %d psk \"%s\"", net_no, password); |
| 2652 | |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 2653 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2654 | DO_OK_FAIL_REQUEST(lynq_ket_mgmt_cmd); |
| 2655 | DO_OK_FAIL_REQUEST(lynq_pairwise_cmd); |
| 2656 | DO_OK_FAIL_REQUEST(lynq_psk_cmd); |
| 2657 | |
| 2658 | break; |
| 2659 | } |
| 2660 | case LYNQ_WIFI_AUTH_WPA3_PSK: |
| 2661 | { |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 2662 | sprintf(lynq_auth_cmd,"SET_NETWORK %d ieee80211w 2",net_no); |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2663 | sprintf(lynq_ket_mgmt_cmd,"SET_NETWORk %d key_mgmt SAE",net_no); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2664 | sprintf(lynq_pairwise_cmd,"SET_NETWORK %d pairwise CCMP", net_no); |
| 2665 | sprintf(lynq_psk_cmd, "SET_NETWORK %d psk \"%s\"", net_no, password); |
| 2666 | |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 2667 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 2668 | RLOGD("inner_set_sta_auth_psw before set SAE CMD"); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2669 | DO_OK_FAIL_REQUEST(lynq_ket_mgmt_cmd); |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 2670 | RLOGD("inner_set_sta_auth_psw after set SAE CMD"); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2671 | DO_OK_FAIL_REQUEST(lynq_pairwise_cmd); |
| 2672 | DO_OK_FAIL_REQUEST(lynq_psk_cmd); |
| 2673 | |
| 2674 | break; |
| 2675 | } |
| 2676 | default: |
| 2677 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2678 | } |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2679 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2680 | return 0; |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 2681 | } |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2682 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2683 | static int inner_get_curr_net_no(int interface) { |
| 2684 | curr_status_info curr_state; |
| 2685 | curr_state.ap = NULL; |
| 2686 | curr_state.state = NULL; |
| 2687 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2688 | if (0 != inner_get_status_info(interface, &curr_state)) |
| 2689 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2690 | return -1; |
| 2691 | } |
| 2692 | |
| 2693 | return curr_state.net_no; |
| 2694 | } |
| 2695 | |
| 2696 | 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] | 2697 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2698 | int net_no; |
| 2699 | CHECK_IDX(idx, CTRL_STA); |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2700 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2701 | net_no = inner_get_curr_net_no(CTRL_STA); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2702 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2703 | if (net_no < 0) |
| 2704 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2705 | return -1; |
| 2706 | } |
| 2707 | |
| 2708 | return inner_get_network_auth(CTRL_STA, net_no, auth); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2709 | } |
| 2710 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2711 | 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] | 2712 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2713 | int count, net_no, index; |
| 2714 | int net_no_list[128]; |
| 2715 | lynq_wifi_auth_s net_auth; |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 2716 | curr_status_info curr_state; |
| 2717 | ap_info_s ap_info; |
| 2718 | char status[64]; |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2719 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2720 | if (ssid == NULL || *ssid == '\0') |
| 2721 | { |
| 2722 | RLOGE("bad ssid\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2723 | return -1; |
| 2724 | } |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2725 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2726 | if (LYNQ_WIFI_AUTH_OPEN != auth) |
| 2727 | { |
| 2728 | if (psw == NULL || strlen(psw) < 8 || strlen(psw) >= 64) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 2729 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2730 | RLOGE("bad password\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2731 | return -1; |
| 2732 | } |
| 2733 | } |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2734 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 2735 | |
| 2736 | pthread_mutex_lock(&s_global_check_mutex); |
| 2737 | if (s_sta_status != INNER_STA_STATUS_INIT) |
| 2738 | { |
| 2739 | s_sta_status = INNER_STA_STATUS_CANCEL; |
| 2740 | pthread_cond_signal(&s_global_check_cond); |
| 2741 | } |
| 2742 | pthread_mutex_unlock(&s_global_check_mutex); |
| 2743 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2744 | CHECK_IDX(idx, CTRL_STA); |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 2745 | CHECK_WPA_CTRL(CTRL_STA); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2746 | |
| 2747 | net_no = -1; |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 2748 | memset(&ap_info, 0, sizeof (ap_info)); |
| 2749 | memset(status, 0, sizeof (status)); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2750 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 2751 | curr_state.ap = &ap_info; |
| 2752 | curr_state.state = status; |
| 2753 | |
| 2754 | if (0 == inner_get_status_info(CTRL_STA, &curr_state) && curr_state.net_no >= 0) |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2755 | { |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 2756 | if (strcmp(status, STATE_COMPLETED) == 0 && strcmp(ap_info.ap_ssid, ssid) ==0 && ap_info.auth == auth) |
| 2757 | { |
| 2758 | net_no = curr_state.net_no; |
| 2759 | if (0 == lynq_sta_ssid_password_get(idx, &ap_info, ap_info.psw) |
| 2760 | && strcmp(ap_info.psw, psw) == 0) |
| 2761 | { |
| 2762 | RLOGD("already connected\n"); |
| 2763 | |
| 2764 | pthread_mutex_lock(&s_global_check_mutex); |
| 2765 | s_sta_status = INNER_STA_STATUS_CONNECTED; |
| 2766 | pthread_cond_signal(&s_global_check_cond); |
| 2767 | pthread_mutex_unlock(&s_global_check_mutex); |
| 2768 | return 0; |
| 2769 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2770 | } |
| 2771 | } |
| 2772 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 2773 | if (net_no == -1) |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2774 | { |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 2775 | count = lynq_get_network_number_list(idx, CTRL_STA, net_no_list, ssid); |
| 2776 | |
| 2777 | for (index=0; index < count; index++) |
| 2778 | { |
| 2779 | net_auth = -1; |
| 2780 | if (0 == inner_get_network_auth(CTRL_STA, net_no_list[index], &net_auth) && net_auth == auth) |
| 2781 | { |
| 2782 | net_no = net_no_list[index]; |
| 2783 | break; |
| 2784 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2785 | } |
| 2786 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 2787 | if (net_no < 0) |
| 2788 | { |
| 2789 | net_no = lynq_add_network(CTRL_STA); |
| 2790 | if (net_no == -1) |
| 2791 | { |
| 2792 | return -1; |
| 2793 | } |
| 2794 | |
| 2795 | RLOGD("net no is %d\n", net_no); |
| 2796 | if (0 != inner_set_sta_ssid(net_no, ssid)) |
| 2797 | { |
| 2798 | return -1; |
| 2799 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2800 | } |
| 2801 | } |
| 2802 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2803 | if (0 != inner_set_sta_auth_psw(net_no, auth, psw)) |
| 2804 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2805 | return -1; |
| 2806 | } |
| 2807 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 2808 | |
| 2809 | DO_OK_FAIL_REQUEST(cmd_disconnect); |
| 2810 | usleep(200*1000); |
| 2811 | |
| 2812 | ret = inner_sta_start_stop(net_no, 1, 1); |
| 2813 | |
| 2814 | pthread_mutex_lock(&s_global_check_mutex); |
| 2815 | s_sta_status = INNER_STA_STATUS_CONNECTING; |
| 2816 | strcpy(s_sta_current_connecting_ssid, ssid); |
| 2817 | struct timeval now; |
| 2818 | gettimeofday(&now,NULL); |
| 2819 | s_sta_connect_timeout.tv_sec = now.tv_sec + MAX_CONNNECT_TIME; |
| 2820 | s_sta_connect_timeout.tv_nsec = now.tv_usec*1000; |
| 2821 | pthread_cond_signal(&s_global_check_cond); |
| 2822 | pthread_mutex_unlock(&s_global_check_mutex); |
| 2823 | return ret; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2824 | } |
| 2825 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2826 | int lynq_wifi_sta_disconnect(lynq_wifi_index_e idx, char *ssid) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2827 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2828 | ap_info_s ap; |
| 2829 | curr_status_info curr_state; |
| 2830 | ap.ap_ssid[0] = '\0'; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2831 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2832 | if (ssid == NULL || *ssid == '\0') |
| 2833 | { |
| 2834 | RLOGE("input ssid is NULL\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2835 | return -1; |
| 2836 | } |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2837 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2838 | CHECK_IDX(idx, CTRL_STA); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2839 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2840 | curr_state.ap = ≈ |
you.chen | b4b121c | 2022-05-06 17:50:16 +0800 | [diff] [blame] | 2841 | curr_state.state = NULL; |
| 2842 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2843 | if (inner_get_status_info(CTRL_STA, &curr_state) != 0) |
| 2844 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2845 | return 0; |
| 2846 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 2847 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2848 | if (strcmp(ap.ap_ssid, ssid) != 0) |
| 2849 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2850 | return 0; |
| 2851 | } |
| 2852 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 2853 | pthread_mutex_lock(&s_global_check_mutex); |
| 2854 | s_sta_status = INNER_STA_STATUS_DISCONNECTING; |
| 2855 | pthread_mutex_unlock(&s_global_check_mutex); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2856 | return inner_sta_start_stop(curr_state.net_no, 0, 0); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2857 | } |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2858 | |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2859 | int lynq_wifi_sta_start(lynq_wifi_index_e idx) |
| 2860 | { |
qs.xiong | ad2f89d | 2023-01-18 13:17:41 +0800 | [diff] [blame] | 2861 | // const char *lynq_reconfigure_cmd = "wpa_cli -iwpa_wlan0_cmd -p/var/run/ IFNAME=wlan0 RECONFIGURE /data/wifi/wg870/wpa_supplicant.conf"; |
| 2862 | // const char *lynq_reconnect_cmd = "RECONNECT"; |
| 2863 | const char *lynq_enable_sta_cmd = "wpa_cli -iwpa_wlan0_cmd -p/var/run/ IFNAME=wlan0 enable_net all"; |
| 2864 | const char *lynq_reconnect_cmd = "wpa_cli -iwpa_wlan0_cmd -p/var/run/ IFNAME=wlan0 reconnect"; |
| 2865 | // const char *lynq_first_sta_cmd = "wpa_cli -iwpa_wlan0_cmd -p/var/run/ IFNAME=wlan0 remove_net all"; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2866 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2867 | CHECK_IDX(idx, CTRL_STA); |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2868 | CHECK_WPA_CTRL(CTRL_STA); |
| 2869 | |
| 2870 | system("connmanctl enable wifi"); |
| 2871 | |
qs.xiong | ad2f89d | 2023-01-18 13:17:41 +0800 | [diff] [blame] | 2872 | if (system("ifconfig | grep -q wlan0") != 0) |
| 2873 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2874 | return -1; |
| 2875 | } |
qs.xiong | 9c99fa9 | 2022-03-15 08:03:26 -0400 | [diff] [blame] | 2876 | |
qs.xiong | ad2f89d | 2023-01-18 13:17:41 +0800 | [diff] [blame] | 2877 | // DO_OK_FAIL_REQUEST(cmd_remove_all); |
| 2878 | // system(lynq_first_sta_cmd); |
| 2879 | // system(lynq_reconfigure_cmd); |
| 2880 | // DO_OK_FAIL_REQUEST(lynq_reconnect_cmd); |
| 2881 | system(lynq_enable_sta_cmd); |
| 2882 | system(lynq_reconnect_cmd); |
| 2883 | // DO_OK_FAIL_REQUEST(lynq_reconnect_cmd); |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2884 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2885 | } |
| 2886 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2887 | int lynq_wifi_sta_stop(lynq_wifi_index_e idx) |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2888 | { |
qs.xiong | ad2f89d | 2023-01-18 13:17:41 +0800 | [diff] [blame] | 2889 | // char lynq_disable_network_cmd[MAX_CMD]; |
| 2890 | // curr_status_info curr_state; |
| 2891 | // ap_info_s ap_info; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2892 | |
qs.xiong | ad2f89d | 2023-01-18 13:17:41 +0800 | [diff] [blame] | 2893 | const char * lynq_disable_sta_cmd = "wpa_cli -iwpa_wlan0_cmd -p/var/run/ IFNAME=wlan0 disable_net all"; |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2894 | CHECK_IDX(idx, CTRL_STA); |
| 2895 | CHECK_WPA_CTRL(CTRL_STA); |
| 2896 | |
qs.xiong | ad2f89d | 2023-01-18 13:17:41 +0800 | [diff] [blame] | 2897 | // curr_state.ap = &ap_info; |
| 2898 | // curr_state.state = NULL; |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2899 | |
qs.xiong | ad2f89d | 2023-01-18 13:17:41 +0800 | [diff] [blame] | 2900 | // if (0 != inner_get_status_info(CTRL_STA, &curr_state) || curr_state.net_no < 0) { |
| 2901 | // return 0; |
| 2902 | // } |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2903 | |
qs.xiong | ad2f89d | 2023-01-18 13:17:41 +0800 | [diff] [blame] | 2904 | // sprintf(lynq_disable_network_cmd, "DISABLE_NETWORK %d", curr_state.net_no); |
| 2905 | // DO_OK_FAIL_REQUEST(lynq_disable_network_cmd); |
| 2906 | system(lynq_disable_sta_cmd); |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2907 | DO_OK_FAIL_REQUEST(cmd_save_config); |
| 2908 | |
| 2909 | return 0; |
| 2910 | // return system("connmanctl disable wifi"); |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2911 | } |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2912 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2913 | //static int inner_get_sta_info(lynq_wifi_index_e idx, const char * bssid, device_info_s *dev) { |
| 2914 | // int i, count; |
| 2915 | // char *p; |
| 2916 | // const char * FLAG_SSID = "ssid="; |
| 2917 | // const char * FLAG_SBSID = "bssid="; |
| 2918 | // const char * FLAG_KEY_MGMT = "key_mgmt="; |
| 2919 | // const char * FLAG_FREQ = "freq="; |
| 2920 | // char lynq_sta_cmd[MAX_CMD]; |
| 2921 | // char *split_lines[128] = {0}; |
| 2922 | |
| 2923 | // CHECK_WPA_CTRL(CTRL_AP); |
| 2924 | |
| 2925 | // sprintf(lynq_sta_cmd, "STA %s", bssid); |
| 2926 | |
| 2927 | // DO_REQUEST(lynq_sta_cmd); |
| 2928 | |
| 2929 | // count = lynq_split(cmd_reply, reply_len, '\n', split_lines); |
| 2930 | |
| 2931 | // for(i=0; i < count; i++) { |
| 2932 | // p = strstr(split_lines[i], FLAG_SSID); |
| 2933 | // if (p != NULL) { |
| 2934 | // strcpy(ap->ap_ssid, p + strlen(FLAG_SSID)); |
| 2935 | // continue; |
| 2936 | // } |
| 2937 | // } |
| 2938 | |
| 2939 | // lynq_get_interface_ip(idx, ap->ap_ip); |
| 2940 | // lynq_ap_password_set(idx, ap->psw); |
| 2941 | |
| 2942 | // return 0; |
| 2943 | //} |
| 2944 | |
| 2945 | static int inner_get_status_info_ap (int interface, ap_info_s *ap) { |
| 2946 | curr_status_info curr_state; |
| 2947 | curr_state.ap = ap; |
| 2948 | curr_state.state = NULL; |
| 2949 | return inner_get_status_info(interface, &curr_state); |
| 2950 | } |
| 2951 | |
| 2952 | 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] | 2953 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 2954 | int index, line_count; |
| 2955 | device_info_s *dev_info; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2956 | const char *lynq_first_sta_cmd = "STA-FIRST"; |
| 2957 | char lynq_next_sta_cmd[MAX_CMD]; |
| 2958 | char *bssid[1024] = {0}; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2959 | char *split_lines[128] = {0}; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2960 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2961 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2962 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2963 | CHECK_WPA_CTRL(CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2964 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2965 | // ap_info_s * tmp_ap; |
| 2966 | // device_info_s * tmp_list; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2967 | if (ap == NULL || list == NULL || len == NULL) |
| 2968 | { |
| 2969 | RLOGE("bad input param"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2970 | return -1; |
| 2971 | } |
| 2972 | |
| 2973 | // ap = &tmp_ap; |
| 2974 | // list = &tmp_list; |
| 2975 | *ap = malloc(sizeof (ap_info_s)); |
| 2976 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2977 | if (inner_get_status_info_ap (CTRL_AP, *ap) != 0) |
| 2978 | { |
| 2979 | RLOGE("inner_get_status_info_ap !=0\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2980 | return -1; |
| 2981 | } |
| 2982 | |
| 2983 | lynq_get_interface_ip(idx, (*ap)->ap_ip); |
| 2984 | lynq_ap_password_get(idx, (*ap)->psw); |
| 2985 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2986 | DO_REQUEST(lynq_first_sta_cmd); |
| 2987 | |
| 2988 | index = 0; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2989 | while (reply_len > 0) |
| 2990 | { |
| 2991 | if (memcmp(cmd_reply, "FAIL", 4) == 0) |
| 2992 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2993 | break; |
| 2994 | } |
| 2995 | line_count = lynq_split(cmd_reply, reply_len, '\n', split_lines); |
| 2996 | bssid[index] = malloc(strlen(split_lines[0]) + 1); |
| 2997 | strcpy(bssid[index], split_lines[0]); |
| 2998 | index++; |
| 2999 | sprintf(lynq_next_sta_cmd, "STA-NEXT %s", split_lines[0]); |
| 3000 | reply_len = MAX_RET; |
| 3001 | cmd_reply[0] = '\0'; |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 3002 | ret = local_wpa_ctrl_request(lynq_wpa_ctrl, lynq_next_sta_cmd, strlen(lynq_next_sta_cmd), cmd_reply, &reply_len, NULL); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3003 | if (ret != 0 || memcmp(cmd_reply, "FAIL", 4) == 0) |
| 3004 | { |
| 3005 | RLOGD("run %s fail \n", lynq_next_sta_cmd); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3006 | break; |
| 3007 | } |
| 3008 | } |
| 3009 | |
| 3010 | *len = index; |
| 3011 | |
| 3012 | *list = malloc(sizeof(device_info_s) * (*len)); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3013 | for (index=0; index < *len; index++) |
| 3014 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 3015 | dev_info = &(*list)[index]; |
| 3016 | memset(dev_info, 0, sizeof(device_info_s)); |
| 3017 | strncpy(dev_info->sta_mac, bssid[index], sizeof (dev_info->sta_mac)); |
| 3018 | inner_get_ip_by_mac(dev_info->sta_mac, dev_info->sta_ip, sizeof (dev_info->sta_ip)); |
| 3019 | inner_get_hostname_by_ip(dev_info->sta_ip, dev_info->hostname); |
| 3020 | dev_info->status = LYNQ_WIFI_STATUS_CONNECT; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3021 | free(bssid[index]); |
| 3022 | } |
| 3023 | |
| 3024 | return 0; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 3025 | } |
| 3026 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3027 | 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] | 3028 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3029 | int i, count, index, count_words; |
| 3030 | const char *lynq_scan_result_cmd = "SCAN_RESULTS"; |
| 3031 | char *split_lines[128] = {0}; |
| 3032 | char *split_words[128] = {0}; |
| 3033 | scan_info_s * p; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 3034 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3035 | if (list == NULL || len == NULL) |
| 3036 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3037 | return -1; |
| 3038 | } |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 3039 | |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3040 | for (i =0; i < 50 && g_sta_scan_finish_flag == 0; i++) |
| 3041 | { |
| 3042 | usleep(100 * 1000); |
| 3043 | } |
| 3044 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3045 | CHECK_IDX(idx, CTRL_STA); |
| 3046 | |
| 3047 | CHECK_WPA_CTRL(CTRL_STA); |
| 3048 | |
| 3049 | DO_REQUEST(lynq_scan_result_cmd); |
| 3050 | |
| 3051 | count = lynq_split(cmd_reply, reply_len, '\n', split_lines); |
| 3052 | *len = count - 1; |
| 3053 | *list = malloc(sizeof (scan_info_s) * *len); |
| 3054 | |
| 3055 | count_words = lynq_split(split_lines[0], strlen(split_lines[0]), '/', split_words); //@todo get with header |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3056 | for (index=0; index <count_words; index++) |
| 3057 | { |
| 3058 | RLOGD("----header: %s\n", split_words[index]); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3059 | } |
| 3060 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3061 | for(index = 1;index < count; index++) |
| 3062 | { |
| 3063 | RLOGD("---- %s\n",split_lines[index]); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3064 | count_words = lynq_split(split_lines[index], strlen(split_lines[index]), '\t', split_words); |
| 3065 | if (count_words < 4) |
| 3066 | continue; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3067 | RLOGD("count: %d, %s\n", count_words, split_words[0]); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3068 | //bssid / frequency / signal level / flags / ssid |
| 3069 | p = (*list) + index - 1; |
| 3070 | strcpy(p->mac, split_words[0]); |
| 3071 | p->band = convert_band_from_freq(atoi(split_words[1])); |
| 3072 | p->rssi = -1 * atoi( split_words[2]); |
| 3073 | p->auth = convert_max_auth_from_flag(split_words[3]); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 3074 | inner_copy_ssid(p->ssid, split_words[4], sizeof (p->ssid)); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3075 | } |
| 3076 | |
| 3077 | return 0; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 3078 | } |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 3079 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3080 | int lynq_sta_forget_ap(lynq_wifi_index_e idx, char *ssid, lynq_wifi_auth_s auth) |
| 3081 | { |
| 3082 | int count, net_no, index; |
| 3083 | int net_no_list[128]; |
| 3084 | lynq_wifi_auth_s net_auth; |
| 3085 | char lynq_remove_cmd[MAX_CMD]; |
| 3086 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3087 | if (ssid == NULL || *ssid == '\0') |
| 3088 | { |
| 3089 | RLOGD("bad ssid\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3090 | return -1; |
| 3091 | } |
| 3092 | |
| 3093 | CHECK_IDX(idx, CTRL_STA); |
| 3094 | |
| 3095 | CHECK_WPA_CTRL(CTRL_STA); |
| 3096 | |
| 3097 | net_no = -1; |
| 3098 | count = lynq_get_network_number_list(idx, CTRL_STA, net_no_list, ssid); |
| 3099 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3100 | for (index=0; index < count; index++) |
| 3101 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3102 | net_auth = -1; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3103 | if (0 == inner_get_network_auth(CTRL_STA, net_no_list[index], &net_auth) && net_auth == auth) |
| 3104 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3105 | net_no = net_no_list[index]; |
| 3106 | break; |
| 3107 | } |
| 3108 | } |
| 3109 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3110 | if (net_no < 0) |
| 3111 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3112 | return 0; |
| 3113 | } |
| 3114 | |
| 3115 | sprintf(lynq_remove_cmd, "REMOVE_NETWORK %d", net_no); |
| 3116 | |
| 3117 | DO_OK_FAIL_REQUEST(lynq_remove_cmd); |
| 3118 | DO_OK_FAIL_REQUEST(cmd_save_config); |
| 3119 | |
| 3120 | return 0; |
| 3121 | } |
| 3122 | |
| 3123 | int lynq_get_sta_saved_ap(lynq_wifi_index_e idx, saved_ap_info_s ** list, int * len) |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3124 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 3125 | int count, index; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3126 | int net_no_list[128]; |
| 3127 | char freq[16]; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3128 | RLOGD("enter lynq_get_sta_saved_ap api\n"); |
| 3129 | if (list == NULL || len == NULL) |
| 3130 | { |
| 3131 | RLOGE("bad param,please check!"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3132 | return -1; |
| 3133 | } |
| 3134 | |
| 3135 | CHECK_IDX(idx, CTRL_STA); |
| 3136 | |
| 3137 | // CHECK_WPA_CTRL(CTRL_STA); |
| 3138 | |
| 3139 | count = lynq_get_network_number_list(idx, CTRL_STA, net_no_list, NULL); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3140 | RLOGD("[lynq_get_sta_saved_ap]count is %d\n", count); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3141 | |
you.chen | 057aac4 | 2023-04-13 14:06:58 +0800 | [diff] [blame] | 3142 | if (count < 0) |
| 3143 | { |
| 3144 | RLOGE("list network fail"); |
| 3145 | return count; |
| 3146 | } |
| 3147 | else if (count == 0) |
| 3148 | { |
| 3149 | *list = NULL; |
| 3150 | *len = 0; |
| 3151 | return 0; |
| 3152 | } |
| 3153 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3154 | *list = malloc(sizeof (saved_ap_info_s) * count); |
you.chen | 755332b | 2022-08-06 16:59:10 +0800 | [diff] [blame] | 3155 | memset(*list, 0, sizeof (saved_ap_info_s) * count); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3156 | *len = count; |
| 3157 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3158 | for (index=0; index < count; index++) |
| 3159 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3160 | inner_get_param(CTRL_STA, net_no_list[index], "ssid", (*list)[index].base_info.ap_ssid); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3161 | inner_get_param(CTRL_STA, net_no_list[index], "bssid", (*list)[index].base_info.ap_mac); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3162 | inner_get_network_auth(CTRL_STA, net_no_list[index], &(*list)[index].base_info.auth); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3163 | if (inner_get_param(CTRL_STA, net_no_list[index], "frequency", freq) == 0) |
you.chen | 057aac4 | 2023-04-13 14:06:58 +0800 | [diff] [blame] | 3164 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3165 | (*list)[index].base_info.band = convert_band_from_freq(atoi(freq)); |
| 3166 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3167 | else |
you.chen | 057aac4 | 2023-04-13 14:06:58 +0800 | [diff] [blame] | 3168 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3169 | (*list)[index].base_info.band = -1; |
| 3170 | } |
you.chen | 057aac4 | 2023-04-13 14:06:58 +0800 | [diff] [blame] | 3171 | RLOGD("[lynq_get_sta_saved_ap][inner_get_param]to get psw"); |
you.chen | 755332b | 2022-08-06 16:59:10 +0800 | [diff] [blame] | 3172 | lynq_sta_ssid_password_get(idx, & (*list)[index].base_info, (*list)[index].base_info.psw); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3173 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3174 | RLOGD("[lynq_get_sta_saved_ap] return ok"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3175 | return 0; |
| 3176 | } |
| 3177 | |
| 3178 | int lynq_wifi_sta_start_scan(lynq_wifi_index_e idx) |
| 3179 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 3180 | const char *clean_last_re ="wpa_cli -iwpa_wlan0_cmd -p/var/run/ IFNAME=wlan0 bss_flush"; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3181 | const char *lynq_scan_cmd = "SCAN"; |
| 3182 | |
| 3183 | CHECK_IDX(idx, CTRL_STA); |
| 3184 | |
| 3185 | CHECK_WPA_CTRL(CTRL_STA); |
| 3186 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame^] | 3187 | // system(clean_last_re); // youchen @ 2023-04-14 temp delete ,next time to fix the orginal bug |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3188 | g_sta_scan_finish_flag = 0; |
qs.xiong | b3f26af | 2023-02-17 18:41:07 +0800 | [diff] [blame] | 3189 | DO_REQUEST(lynq_scan_cmd); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3190 | if (reply_len >=9 && memcmp(cmd_reply, "FAIL-BUSY", 9) == 0 ) |
| 3191 | { |
qs.xiong | b3f26af | 2023-02-17 18:41:07 +0800 | [diff] [blame] | 3192 | return 0; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3193 | } else if (reply_len >=2 && memcmp(cmd_reply, "OK", 2) != 0) |
| 3194 | { |
qs.xiong | b3f26af | 2023-02-17 18:41:07 +0800 | [diff] [blame] | 3195 | g_sta_scan_finish_flag = 1; |
| 3196 | return -1; |
| 3197 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3198 | |
| 3199 | return 0; |
| 3200 | } |
| 3201 | |
| 3202 | int lynq_reg_ap_event_callback(void * priv, AP_CALLBACK_FUNC_PTR cb) { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3203 | if (cb == NULL) |
| 3204 | { |
| 3205 | RLOGE("lynq_reg_ap_event_callback ptr is NULL,plese check!\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3206 | return -1; |
| 3207 | } |
| 3208 | |
| 3209 | g_ap_callback_priv = priv; |
| 3210 | g_ap_callback_func = cb; |
| 3211 | |
| 3212 | return 0; |
| 3213 | } |
| 3214 | |
| 3215 | int lynq_unreg_ap_event_callback(void * priv) { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3216 | if (g_ap_callback_priv == priv) |
| 3217 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3218 | g_ap_callback_func = NULL; |
| 3219 | g_ap_callback_priv = NULL; |
| 3220 | return 0; |
| 3221 | } |
| 3222 | return -1; |
| 3223 | } |
| 3224 | |
| 3225 | int lynq_reg_sta_event_callback(void * priv, STA_CALLBACK_FUNC_PTR cb){ |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3226 | if (cb == NULL) |
| 3227 | { |
| 3228 | RLOGE("lynq_reg_sta_event_callback ptr is NULL,plese check!\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3229 | return -1; |
| 3230 | } |
| 3231 | |
| 3232 | g_sta_callback_priv = priv; |
| 3233 | g_sta_callback_func = cb; |
| 3234 | |
| 3235 | return 0; |
| 3236 | } |
| 3237 | |
| 3238 | int lynq_unreg_sta_event_callback(void * priv) { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3239 | if (g_sta_callback_priv == priv) |
| 3240 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3241 | g_sta_callback_func = NULL; |
| 3242 | g_sta_callback_priv = NULL; |
| 3243 | return 0; |
| 3244 | } |
| 3245 | return -1; |
| 3246 | } |
| 3247 | |
| 3248 | |
| 3249 | static int inner_get_status_info_state (int interface, char *state) { |
| 3250 | curr_status_info curr_state; |
| 3251 | curr_state.ap = NULL; |
| 3252 | curr_state.state = state; |
| 3253 | return inner_get_status_info(interface, &curr_state); |
| 3254 | } |
| 3255 | |
| 3256 | int lynq_get_ap_status(lynq_wifi_index_e idx, lynq_wifi_ap_run_status_s * ap_status) |
| 3257 | { |
| 3258 | char state[MAX_CMD]; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3259 | RLOGD("enter lynq_get_ap_status\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3260 | CHECK_IDX(idx, CTRL_AP); |
| 3261 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3262 | if (inner_get_status_info_state(CTRL_AP, state) != 0) |
| 3263 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3264 | *ap_status = LYNQ_WIFI_AP_STATUS_DISABLE; |
| 3265 | return 0; |
| 3266 | } |
| 3267 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3268 | if (memcmp(state, STATE_COMPLETED, strlen (STATE_COMPLETED)) == 0) |
| 3269 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3270 | *ap_status = LYNQ_WIFI_AP_STATUS_ENABLE; |
| 3271 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3272 | else |
| 3273 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3274 | *ap_status = LYNQ_WIFI_AP_STATUS_DISABLE; |
| 3275 | } |
| 3276 | |
| 3277 | return 0; |
| 3278 | } |
| 3279 | |
| 3280 | int lynq_get_sta_status(lynq_wifi_index_e idx, lynq_wifi_sta_run_status_s * sta_status) { |
| 3281 | char state[MAX_CMD]; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3282 | RLOGD("enter lynq_get_sta_status\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3283 | CHECK_IDX(idx, CTRL_STA); |
| 3284 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3285 | if (inner_get_status_info_state(CTRL_STA, state) != 0) |
| 3286 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3287 | *sta_status = LYNQ_WIFI_STA_STATUS_DISABLE; |
| 3288 | return 0; |
| 3289 | } |
| 3290 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3291 | if (memcmp(state, STATE_COMPLETED, strlen (STATE_COMPLETED)) == 0) |
| 3292 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3293 | *sta_status = LYNQ_WIFI_STA_STATUS_ENABLE; |
| 3294 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3295 | else |
| 3296 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3297 | *sta_status = LYNQ_WIFI_STA_STATUS_DISABLE; |
| 3298 | } |
| 3299 | |
| 3300 | return 0; |
| 3301 | } |
| 3302 | |
| 3303 | int lynq_get_country_code(lynq_wifi_index_e idx, char * country_code) { |
| 3304 | // CHECK_IDX(idx, CTRL_AP); |
| 3305 | // int ret = 0; |
| 3306 | // size_t reply_len = MAX_RET; |
| 3307 | // char cmd_reply[MAX_RET]={0}; |
| 3308 | // const char * cmd_str = "GET country"; |
| 3309 | // struct wpa_ctrl *s_lynq_wpa_ctrl = NULL; |
| 3310 | // do{ |
| 3311 | // if (NULL == s_lynq_wpa_ctrl) { |
| 3312 | // s_lynq_wpa_ctrl = wpa_ctrl_open("/var/run/wpa_wlan0_cmd"); |
| 3313 | // if (NULL == s_lynq_wpa_ctrl ) { |
| 3314 | // printf("wpa_ctrl_open fail\n"); |
| 3315 | // return -1; |
| 3316 | // } |
| 3317 | // } |
| 3318 | // }while(0); |
| 3319 | |
| 3320 | // do { |
| 3321 | // reply_len = MAX_RET; |
| 3322 | // cmd_reply[0] = '\0'; |
| 3323 | // printf("to call [%s]\n", cmd_str); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 3324 | // ret = local_wpa_ctrl_request(s_lynq_wpa_ctrl, cmd_str, strlen(cmd_str), cmd_reply, &reply_len, NULL); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3325 | // if (ret != 0) { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3326 | // RLOGE("call ##cmd_str fail %d\n", ret); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3327 | // return ret; |
| 3328 | // } |
| 3329 | // cmd_reply[reply_len+1] = '\0'; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3330 | // RLOGD("cmd replay [ %s ]\n", cmd_reply); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3331 | // }while(0); |
| 3332 | |
| 3333 | FILE *fp; |
| 3334 | size_t i = 0; |
| 3335 | char lynq_cmd_ret[MAX_RET]={0}; |
| 3336 | |
| 3337 | // CHECK_IDX(idx, CTRL_AP); |
| 3338 | |
| 3339 | if((fp=popen("wl country","r"))==NULL) |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3340 | { |
| 3341 | perror("popen error!"); |
| 3342 | return -1; |
| 3343 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3344 | if((fread(lynq_cmd_ret,sizeof(lynq_cmd_ret),1,fp))<0) |
| 3345 | { |
| 3346 | perror("fread fail!"); |
| 3347 | return -1; |
| 3348 | } |
| 3349 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3350 | for(i=0; i < strlen(lynq_cmd_ret); i++) |
| 3351 | { |
| 3352 | if (lynq_cmd_ret[i] == ' ') |
| 3353 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3354 | lynq_cmd_ret[i] = '\0'; |
| 3355 | break; |
| 3356 | } |
| 3357 | } |
| 3358 | |
| 3359 | strcpy(country_code,lynq_cmd_ret); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3360 | RLOGD("---country code %s\n", country_code); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3361 | |
| 3362 | int ret=pclose(fp); |
| 3363 | if(ret==-1) |
| 3364 | { |
| 3365 | perror("close file faild"); |
| 3366 | } |
| 3367 | |
| 3368 | return 0; |
| 3369 | } |
| 3370 | |
| 3371 | int lynq_set_country_code(lynq_wifi_index_e idx, char * country_code) { |
| 3372 | // const char * cmd_str = "GET country"; |
| 3373 | // CHECK_IDX(idx, CTRL_AP); |
| 3374 | // CHECK_WPA_CTRL(CTRL_STA); |
| 3375 | |
| 3376 | // DO_REQUEST(cmd_str); |
| 3377 | // printf("result %s\n", cmd_reply); |
| 3378 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3379 | if (country_code == NULL || *country_code == '\0') |
| 3380 | { |
| 3381 | RLOGD("bad country code\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3382 | return -1; |
| 3383 | } |
| 3384 | |
| 3385 | char lynq_country_cmd[MAX_CMD]; |
| 3386 | sprintf(lynq_country_cmd, "wl country %s", country_code); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3387 | if (system(lynq_country_cmd) == 0) |
| 3388 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3389 | return 0; |
| 3390 | } |
| 3391 | |
| 3392 | return -1; |
| 3393 | } |
| 3394 | |
| 3395 | int lynq_get_connect_ap_mac(lynq_wifi_index_e idx,char *mac) |
| 3396 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3397 | RLOGD("enter lynq_get_connect_ap_mac\n"); |
| 3398 | if (mac == NULL) |
| 3399 | { |
| 3400 | RLOGE("input ptr is NULL,please check\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3401 | return -1; |
| 3402 | } |
| 3403 | |
| 3404 | CHECK_IDX(idx, CTRL_STA); |
| 3405 | ap_info_s ap; |
| 3406 | ap.ap_mac[0] = '\0'; |
| 3407 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3408 | if (inner_get_status_info_ap(CTRL_STA, &ap) != 0) |
| 3409 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3410 | return -1; |
| 3411 | } |
| 3412 | strcpy(mac, ap.ap_mac); |
| 3413 | |
| 3414 | return 0; |
| 3415 | } |
| 3416 | |
| 3417 | int lynq_get_interface_ip(lynq_wifi_index_e idx, char *ip) |
| 3418 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3419 | RLOGD("enter lynq_get_interface_ip\n"); |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3420 | struct ifaddrs *ifaddr_header, *ifaddr; |
| 3421 | struct in_addr * ifa; |
| 3422 | const char * ifaName = "wlan0"; |
| 3423 | if (ip == NULL) |
| 3424 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3425 | RLOGE("[lynq_get_interface_ip]input erro,input is NULL ptr,please check\n"); |
you.chen | f58b3c9 | 2022-06-21 16:53:48 +0800 | [diff] [blame] | 3426 | return -1; |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3427 | } |
you.chen | f58b3c9 | 2022-06-21 16:53:48 +0800 | [diff] [blame] | 3428 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3429 | if (idx == 1) |
| 3430 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 3431 | ifaName = "tether"; |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3432 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3433 | else if (idx != 0) |
| 3434 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3435 | return -1; |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3436 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3437 | |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3438 | if (getifaddrs(&ifaddr_header) == -1) |
| 3439 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3440 | perror("getifaddrs"); |
| 3441 | return -1; |
| 3442 | //exit(EXIT_FAILURE); |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3443 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3444 | |
| 3445 | |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3446 | for (ifaddr = ifaddr_header; ifaddr != NULL; ifaddr = ifaddr->ifa_next) |
| 3447 | { |
| 3448 | if (ifaddr->ifa_addr == NULL) |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3449 | continue; |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3450 | if((strcmp(ifaddr->ifa_name,ifaName)==0)) |
| 3451 | { |
| 3452 | if (ifaddr->ifa_addr->sa_family==AF_INET) // check it is IP4 |
| 3453 | { |
| 3454 | // is a valid IP4 Address |
| 3455 | ifa=&((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr; |
| 3456 | inet_ntop(AF_INET, ifa, ip, INET_ADDRSTRLEN); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3457 | RLOGD("[lynq_get_interface_ip]:%s IP Address %s/n", ifaddr->ifa_name, ip); |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3458 | freeifaddrs(ifaddr_header); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3459 | RLOGD("ip %s\n", ip); |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3460 | return 0; |
| 3461 | } |
| 3462 | } |
| 3463 | } |
qs.xiong | c4f007c | 2023-02-08 18:16:58 +0800 | [diff] [blame] | 3464 | freeifaddrs(ifaddr_header); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3465 | RLOGE("[lynq_get_interface_ip] can't find interface | other erro\n"); |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3466 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3467 | } |
| 3468 | |
| 3469 | int lynq_get_interface_mac(lynq_wifi_index_e idx,char *mac) |
| 3470 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3471 | RLOGD("enter lynq_get_interface_mac\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3472 | int count; |
| 3473 | size_t i; |
| 3474 | char *split_words[128] = {0}; |
| 3475 | const char *lynq_get_mac_cmd = "DRIVER MACADDR"; |
| 3476 | |
| 3477 | CHECK_WPA_CTRL(idx); |
| 3478 | |
| 3479 | DO_REQUEST(lynq_get_mac_cmd); |
| 3480 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3481 | if (memcmp(cmd_reply, "FAIL", 4) == 0) |
| 3482 | { |
| 3483 | RLOGE("[lynq_get_interface_mac]do request cmd --DRIVER MACADDR-- reply FAIL\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3484 | return -1; |
| 3485 | } |
| 3486 | |
| 3487 | count = lynq_split(cmd_reply, reply_len, '=', split_words); |
| 3488 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3489 | if (count < 2) |
| 3490 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3491 | return -1; |
| 3492 | } |
| 3493 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3494 | for (i=0; i < strlen(split_words[1]); i++ ) |
| 3495 | { |
| 3496 | if (split_words[1][i] != ' ') |
| 3497 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3498 | break; |
| 3499 | } |
| 3500 | } |
| 3501 | |
| 3502 | strcpy(mac, split_words[1] + i); |
| 3503 | |
| 3504 | return 0; |
| 3505 | } |
| 3506 | |
| 3507 | int lynq_get_connect_ap_rssi(lynq_wifi_index_e idx,int * rssi) |
| 3508 | { |
| 3509 | // int count; |
| 3510 | // char *split_words[128] = {0}; |
| 3511 | // const char *lynq_get_rssi_cmd = "DRIVER RSSI"; |
| 3512 | |
| 3513 | // if (rssi == NULL) { |
| 3514 | // return -1; |
| 3515 | // } |
| 3516 | |
| 3517 | // CHECK_IDX(idx, CTRL_STA); |
| 3518 | |
| 3519 | // CHECK_WPA_CTRL(CTRL_STA); |
| 3520 | |
| 3521 | // DO_REQUEST(lynq_get_rssi_cmd); |
| 3522 | |
| 3523 | // if (memcmp(cmd_reply, "FAIL", 4) == 0) { |
| 3524 | // return -1; |
| 3525 | // } |
| 3526 | |
| 3527 | // count = lynq_split(cmd_reply, reply_len, ' ', split_words); |
| 3528 | |
| 3529 | // if (count < 2) { |
| 3530 | // return -1; |
| 3531 | // } |
| 3532 | |
| 3533 | // *rssi = atoi(split_words[1]) * -1; |
| 3534 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3535 | char lynq_cmd_ret[MAX_RET]={0}; |
| 3536 | |
qs.xiong | ff0ae0f | 2022-10-11 15:47:14 +0800 | [diff] [blame] | 3537 | /*******change other cmd to get rssi******* |
| 3538 | * |
| 3539 | *wl rssi ---> wl -i wlan0 rssi |
| 3540 | * |
| 3541 | ***** change by qs.xiong 20221011*******/ |
you.chen | 23c4a5f | 2023-04-12 16:46:00 +0800 | [diff] [blame] | 3542 | if (0 != exec_cmd("wl -i wlan0 rssi", lynq_cmd_ret, MAX_RET)) |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3543 | { |
you.chen | 23c4a5f | 2023-04-12 16:46:00 +0800 | [diff] [blame] | 3544 | RLOGE("[lynq_get_connect_ap_rssi] exec cmd [ wl -i wlan0 rssi ] fail"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3545 | return -1; |
| 3546 | } |
you.chen | 9f17e4d | 2022-06-06 17:18:18 +0800 | [diff] [blame] | 3547 | *rssi = atoi(lynq_cmd_ret) * -1; |
qs.xiong | ff0ae0f | 2022-10-11 15:47:14 +0800 | [diff] [blame] | 3548 | /****** if got rssi is 0,means sta didn't connected any device****/ |
| 3549 | if(*rssi == 0) |
| 3550 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3551 | RLOGE("[lynq_get_connect_ap_rssi]sta didn't connected any ap device,please check connection\n"); |
you.chen | 23c4a5f | 2023-04-12 16:46:00 +0800 | [diff] [blame] | 3552 | return -1; |
qs.xiong | ff0ae0f | 2022-10-11 15:47:14 +0800 | [diff] [blame] | 3553 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3554 | |
| 3555 | return 0; |
| 3556 | } |
| 3557 | |
| 3558 | int lynq_get_connect_ap_band(lynq_wifi_index_e idx, lynq_wifi_band_m * band) |
| 3559 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3560 | RLOGD("enter lynq_get_connect_ap_band\n"); |
| 3561 | if (band == NULL) |
| 3562 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3563 | return -1; |
| 3564 | } |
| 3565 | |
| 3566 | CHECK_IDX(idx, CTRL_STA); |
| 3567 | ap_info_s ap; |
| 3568 | ap.band = -1; |
| 3569 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3570 | if (inner_get_status_info_ap(CTRL_STA, &ap) != 0) |
| 3571 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3572 | return -1; |
| 3573 | } |
| 3574 | *band = ap.band; |
| 3575 | |
| 3576 | return 0; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 3577 | } |
you.chen | f58b3c9 | 2022-06-21 16:53:48 +0800 | [diff] [blame] | 3578 | |
| 3579 | int lynq_get_connect_ap_ip(lynq_wifi_index_e idx, char *ip) |
| 3580 | { |
qs.xiong | e4cbf1c | 2023-02-28 18:22:49 +0800 | [diff] [blame] | 3581 | char bssid[1024] = {0}; |
you.chen | f58b3c9 | 2022-06-21 16:53:48 +0800 | [diff] [blame] | 3582 | |
| 3583 | if (ip == NULL) |
| 3584 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3585 | RLOGE("[lynq_get_connect_ap_ip]invalid param ptr ip,input ptr is NULL\n"); |
you.chen | f58b3c9 | 2022-06-21 16:53:48 +0800 | [diff] [blame] | 3586 | return -1; |
| 3587 | } |
| 3588 | |
| 3589 | CHECK_IDX(idx, CTRL_STA); |
| 3590 | |
qs.xiong | e4cbf1c | 2023-02-28 18:22:49 +0800 | [diff] [blame] | 3591 | if (lynq_get_connect_ap_mac(idx, bssid) != 0) |
you.chen | f58b3c9 | 2022-06-21 16:53:48 +0800 | [diff] [blame] | 3592 | { |
| 3593 | return -1; |
| 3594 | } |
qs.xiong | e4cbf1c | 2023-02-28 18:22:49 +0800 | [diff] [blame] | 3595 | |
| 3596 | return inner_get_ip_by_mac(bssid, ip, 32); //better input by user |
you.chen | f58b3c9 | 2022-06-21 16:53:48 +0800 | [diff] [blame] | 3597 | } |
| 3598 | |
qs.xiong | 026c5c7 | 2022-10-17 11:15:45 +0800 | [diff] [blame] | 3599 | int lynq_ap_connect_num(int sta_number) |
| 3600 | { |
| 3601 | char lynq_limit_cmd[32]={0}; |
| 3602 | int ret; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3603 | if((sta_number < 1 ) && (sta_number > 15)) |
| 3604 | { |
| 3605 | RLOGE("sta_number: not in range\n",sta_number); |
qs.xiong | 026c5c7 | 2022-10-17 11:15:45 +0800 | [diff] [blame] | 3606 | return -1; |
| 3607 | } |
| 3608 | sprintf(lynq_limit_cmd,"wl maxassoc %d", sta_number); |
| 3609 | ret = system(lynq_limit_cmd); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3610 | if(ret != 0) |
| 3611 | { |
| 3612 | RLOGE("cmd of limit ap devices number error\n"); |
qs.xiong | 026c5c7 | 2022-10-17 11:15:45 +0800 | [diff] [blame] | 3613 | } |
| 3614 | return 0; |
| 3615 | } |
you.chen | f58b3c9 | 2022-06-21 16:53:48 +0800 | [diff] [blame] | 3616 | |
qs.xiong | 7790555 | 2022-10-17 11:19:57 +0800 | [diff] [blame] | 3617 | int lynq_enable_acs(lynq_wifi_index_e idx,int acs_mode) |
| 3618 | { |
| 3619 | |
| 3620 | char lynq_wifi_acs_cmd[128]={0}; |
| 3621 | char lynq_cmd_mode[128]={0}; |
| 3622 | char lynq_cmd_slect[128]={0}; |
| 3623 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3624 | if((acs_mode != 2) && (acs_mode != 5)) |
| 3625 | { |
qs.xiong | 7790555 | 2022-10-17 11:19:57 +0800 | [diff] [blame] | 3626 | PRINT_AND_RETURN_VALUE("set acs_mode is error",-1); |
| 3627 | } |
| 3628 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3629 | if (lynq_check_network_number(idx, CTRL_AP, AP_NETWORK_0) != 0) |
| 3630 | { |
qs.xiong | 7790555 | 2022-10-17 11:19:57 +0800 | [diff] [blame] | 3631 | return -1; |
| 3632 | } |
| 3633 | |
| 3634 | CHECK_IDX(idx, CTRL_AP); |
| 3635 | |
| 3636 | CHECK_WPA_CTRL(CTRL_AP); |
| 3637 | |
| 3638 | sprintf(lynq_wifi_acs_cmd,"SET_NETWORK %d frequency %d", AP_NETWORK_0, acs_mode); |
| 3639 | sprintf(lynq_cmd_mode, "SET_NETWORK %d mode 2", AP_NETWORK_0); |
| 3640 | sprintf(lynq_cmd_slect, "SELECT_NETWORK %d", AP_NETWORK_0); |
| 3641 | |
| 3642 | DO_OK_FAIL_REQUEST(cmd_disconnect); |
| 3643 | DO_OK_FAIL_REQUEST(lynq_wifi_acs_cmd); |
| 3644 | DO_OK_FAIL_REQUEST(lynq_cmd_mode); |
| 3645 | DO_OK_FAIL_REQUEST(cmd_save_config); |
| 3646 | DO_OK_FAIL_REQUEST(lynq_cmd_slect); |
| 3647 | |
| 3648 | return 0; |
| 3649 | } |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 3650 | //you.chen add for tv-box start |
| 3651 | static int exec_cmd(const char *str_cmd, char * str_cmd_ret, size_t max_len) { |
| 3652 | FILE *fp; |
| 3653 | //printf("to exec cmd:%s\n", str_cmd); |
| 3654 | if((fp=popen(str_cmd,"r"))==NULL) |
| 3655 | { |
| 3656 | perror("popen error!"); |
| 3657 | return -1; |
| 3658 | } |
| 3659 | if((fread(str_cmd_ret,max_len,1,fp))<0) |
| 3660 | { |
| 3661 | perror("fread fail!"); |
| 3662 | fclose(fp); |
| 3663 | return -1; |
| 3664 | } |
| 3665 | fclose(fp); |
| 3666 | return 0; |
| 3667 | } |
| 3668 | |
| 3669 | static int get_netmask_length(const char* mask) |
| 3670 | { |
| 3671 | int masklen=0, i=0; |
| 3672 | int netmask=0; |
| 3673 | |
| 3674 | if(mask == NULL) |
| 3675 | { |
| 3676 | return 0; |
| 3677 | } |
| 3678 | |
| 3679 | struct in_addr ip_addr; |
| 3680 | if( inet_aton(mask, &ip_addr) ) |
| 3681 | { |
| 3682 | netmask = ntohl(ip_addr.s_addr); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3683 | }else |
| 3684 | { |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 3685 | netmask = 0; |
| 3686 | return 0; |
| 3687 | } |
| 3688 | |
| 3689 | while(0 == (netmask & 0x01) && i<32) |
| 3690 | { |
| 3691 | i++; |
| 3692 | netmask = netmask>>1; |
| 3693 | } |
| 3694 | masklen = 32-i; |
| 3695 | return masklen; |
| 3696 | } |
| 3697 | |
| 3698 | static int get_tether_route_str(char *str_cmd_ret, size_t max_len) { |
| 3699 | int mask_len; |
| 3700 | char *p; |
| 3701 | char tmp[64] = {0}; |
| 3702 | if (exec_cmd("ifconfig tether | grep Mask", str_cmd_ret, max_len) != 0) |
| 3703 | return -1; |
| 3704 | p = strstr(str_cmd_ret, "Mask:"); |
| 3705 | if (p == NULL) |
| 3706 | return -1; |
| 3707 | mask_len = get_netmask_length(p + 5); |
| 3708 | if (mask_len == 0) |
| 3709 | return -1; |
| 3710 | p = strstr(str_cmd_ret, "inet addr:"); |
| 3711 | if (p == NULL) |
| 3712 | return -1; |
| 3713 | strcpy(tmp, p + 10); |
| 3714 | p = strstr(tmp, " "); |
| 3715 | if (p != NULL) |
| 3716 | *p = '\0'; |
| 3717 | sprintf(str_cmd_ret, "%s/%d", tmp, mask_len); |
| 3718 | return 0; |
| 3719 | } |
| 3720 | |
| 3721 | static void GBWWatchThreadProc() { |
| 3722 | int i,n, nloop, nmax, ncheckcount, nidlecount; |
| 3723 | unsigned long long lastAP1Bytes, lastAP2Bytes, currAP1Bytes, currAP2Bytes; |
| 3724 | unsigned int lastAP1Drop,lastAP2Drop, currAP1Drop, currAP2Drop; |
| 3725 | unsigned int setAP1Speed, setAP2Speed, lastAP1Speed, lastAP2Speed, currAP1Speed, currAP2Speed,currSetAP1Speed; |
| 3726 | char *results[16] = {0}; |
| 3727 | char str_cmd[256] = {0}; |
| 3728 | char str_cmd_ret[128] = {0}; |
| 3729 | char dest_ip[32] = {0}; |
| 3730 | lastAP1Bytes = lastAP2Bytes = 0; |
| 3731 | lastAP1Drop = lastAP2Drop = 0; |
| 3732 | lastAP1Speed = lastAP2Speed = 0; |
| 3733 | setAP1Speed = 50; |
| 3734 | setAP2Speed = 80; |
| 3735 | nloop = 0; |
| 3736 | nmax = 6; |
| 3737 | ncheckcount = nidlecount = 0; |
| 3738 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3739 | RLOGD("------gbw thread run\n"); |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 3740 | sprintf(str_cmd, "ip neigh | grep %s | awk '{print $1}'", g_gbw_mac); |
| 3741 | while (dest_ip[0] == '\0') { |
| 3742 | sleep(1); |
| 3743 | str_cmd_ret[0] = '\0'; |
| 3744 | exec_cmd(str_cmd, str_cmd_ret, sizeof (str_cmd_ret)); |
| 3745 | for(n = 0; n < (int)sizeof(str_cmd_ret) && str_cmd_ret[n] != '\0'; n++) { |
| 3746 | if (str_cmd_ret[n] == '\n'){ |
| 3747 | str_cmd_ret[n] = '\0'; |
| 3748 | break; |
| 3749 | } |
| 3750 | } |
| 3751 | if (str_cmd_ret[0] != '\0') |
| 3752 | { |
| 3753 | strcpy(dest_ip, str_cmd_ret); |
| 3754 | } |
| 3755 | } |
| 3756 | |
| 3757 | system("tc qdisc del dev tether root > /dev/null 2>&1"); |
| 3758 | system("tc qdisc add dev tether root handle 1: htb r2q 1"); |
| 3759 | system("tc class add dev tether parent 1: classid 1:1 htb rate 50Mbit ceil 70Mbit prio 2 quantum 3000"); |
| 3760 | if (get_tether_route_str(str_cmd_ret, sizeof (str_cmd_ret)) != 0) |
| 3761 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3762 | RLOGD("not get tether info\n"); |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 3763 | return; |
| 3764 | } |
| 3765 | sprintf(str_cmd, "tc filter add dev tether parent 1: protocol ip prio 16 u32 match ip dst %s flowid 1:1", str_cmd_ret); |
| 3766 | system(str_cmd); |
| 3767 | system("tc class add dev tether parent 1: classid 1:2 htb rate 80Mbit ceil 100Mbit prio 0 quantum 3000000"); |
| 3768 | sprintf(str_cmd, "tc filter add dev tether parent 1: protocol ip prio 1 u32 match ip dst %s flowid 1:2", dest_ip); |
| 3769 | //printf("----cmd:%s\n", str_cmd); |
| 3770 | system(str_cmd); |
| 3771 | |
| 3772 | while (1) { |
| 3773 | sleep(1); |
| 3774 | memset(str_cmd, 0, sizeof(str_cmd)); |
| 3775 | if (0 != exec_cmd("tc -s class show dev tether classid 1:1 | grep Sent", str_cmd, sizeof (str_cmd))) |
| 3776 | continue; |
| 3777 | //printf("ap1 --- %s\n", str_cmd); |
| 3778 | n = lynq_split(str_cmd, strlen(str_cmd), ' ', results); |
| 3779 | if (n > 9) { |
| 3780 | if (strcmp(results[1], "Sent") == 0) { |
| 3781 | currAP1Bytes = atoll(results[2]); |
| 3782 | } |
| 3783 | if (strcmp(results[6], "(dropped") == 0) { |
| 3784 | currAP1Drop = atoi(results[7]); |
| 3785 | } |
| 3786 | } |
| 3787 | |
| 3788 | memset(str_cmd, 0, sizeof(str_cmd)); |
| 3789 | if (0 != exec_cmd("tc -s class show dev tether classid 1:2 | grep Sent", str_cmd, sizeof (str_cmd))) |
| 3790 | continue; |
| 3791 | //printf("ap2 --- %s\n", str_cmd); |
| 3792 | n = lynq_split(str_cmd, strlen(str_cmd), ' ', results); |
| 3793 | if (n > 9) { |
| 3794 | if (strcmp(results[1], "Sent") == 0) { |
| 3795 | currAP2Bytes = atoll(results[2]); |
| 3796 | } |
| 3797 | if (strcmp(results[6], "(dropped") == 0) { |
| 3798 | currAP2Drop = atoi(results[7]); |
| 3799 | } |
| 3800 | } |
| 3801 | |
| 3802 | //printf("ap1 %llu- %u, ap2 %llu-%u\n", currAP1Bytes, currAP1Drop, currAP2Bytes, currAP2Drop); |
| 3803 | if (currAP1Bytes < lastAP1Bytes || currAP2Bytes < lastAP2Bytes) { |
| 3804 | lastAP1Bytes = currAP1Bytes; |
| 3805 | lastAP2Bytes = currAP2Bytes; |
| 3806 | continue; |
| 3807 | } |
| 3808 | |
| 3809 | currAP1Speed = (currAP1Bytes - lastAP1Bytes) / 128 / 1024; |
| 3810 | currAP2Speed = (currAP2Bytes - lastAP2Bytes) / 128 / 1024; |
| 3811 | //printf("ap1 speed %d mb, ap2 speed %d mb\n", currAP1Speed, currAP2Speed); |
| 3812 | lastAP1Speed = currAP1Speed; |
| 3813 | lastAP2Speed = currAP2Speed; |
| 3814 | lastAP1Bytes = currAP1Bytes; |
| 3815 | lastAP2Bytes = currAP2Bytes; |
| 3816 | |
| 3817 | currSetAP1Speed = setAP1Speed; |
| 3818 | if ((currAP2Speed < 30 && currAP2Speed > 5) && currAP1Speed > 5) { |
| 3819 | ncheckcount++; |
| 3820 | if (ncheckcount > 3) { |
| 3821 | ncheckcount = 0; |
| 3822 | currSetAP1Speed = 5; |
| 3823 | } |
| 3824 | } |
| 3825 | else { |
| 3826 | ncheckcount = 0; |
| 3827 | if (currAP1Speed < 5) |
| 3828 | nidlecount++; |
| 3829 | else |
| 3830 | nidlecount = 0; |
| 3831 | |
| 3832 | } |
| 3833 | |
| 3834 | if (nidlecount > 60 ){ |
| 3835 | currSetAP1Speed = 50; |
| 3836 | } |
| 3837 | |
| 3838 | if (currSetAP1Speed != setAP1Speed) { |
| 3839 | setAP1Speed = currSetAP1Speed; |
| 3840 | sprintf(str_cmd, "tc class replace dev tether parent 1: classid 1:1 htb rate %dMbit ceil %dMbit prio 2 quantum 3000", setAP1Speed, (int)(setAP1Speed*1.4)); |
| 3841 | //printf("------***change speed: %s\n", str_cmd); |
| 3842 | system(str_cmd); |
| 3843 | } |
| 3844 | } |
| 3845 | } |
| 3846 | |
| 3847 | int enableGBW(const char* mac) { |
| 3848 | int i,len; |
| 3849 | char get_ipaddr_cmd[128]={0}; |
| 3850 | ap_info_s *ap; |
| 3851 | device_info_s * list; |
| 3852 | |
| 3853 | if (mac == NULL || g_gbw_enabled == 1) |
| 3854 | return -1; |
| 3855 | len = strlen(mac); |
| 3856 | g_gbw_mac = malloc(len + 1); |
| 3857 | for(i=0;i<len;i++) { |
| 3858 | if (mac[i] >= 'A' && mac[i] <= 'Z') |
| 3859 | { |
| 3860 | g_gbw_mac[i] = 'a' + (mac[i] - 'A'); |
| 3861 | } |
| 3862 | else |
| 3863 | g_gbw_mac[i] = mac[i]; |
| 3864 | } |
| 3865 | g_gbw_mac[i] = '\0'; |
| 3866 | g_gbw_enabled = 1; |
| 3867 | |
| 3868 | sprintf(get_ipaddr_cmd, "ip neigh | grep %s", g_gbw_mac); |
| 3869 | if (system(get_ipaddr_cmd) == 0) { |
| 3870 | //startGBW(); |
| 3871 | if ( 0 ==lynq_get_ap_device_list(1, &ap, &list,&len) ) { |
| 3872 | for (i=0;i<len;i++) { |
| 3873 | //printf("--mac:%s, name:%s\n",list[i].sta_mac, list[i].hostname); |
| 3874 | if (strcmp(g_gbw_mac, list[i].sta_mac) == 0) |
| 3875 | startGBW(); |
| 3876 | } |
| 3877 | free(ap); |
| 3878 | free(list); |
| 3879 | } |
| 3880 | } |
| 3881 | return 0; |
| 3882 | } |
| 3883 | |
| 3884 | int disableGBW() { |
| 3885 | stopGBW(); |
| 3886 | free(g_gbw_mac); |
| 3887 | g_gbw_mac = NULL; |
| 3888 | g_gbw_enabled = 1; |
| 3889 | return 0; |
| 3890 | } |
| 3891 | |
| 3892 | static int startGBW() { |
| 3893 | if (g_gbw_watcher_pid != 0) { |
| 3894 | stopGBW(); |
| 3895 | } |
| 3896 | pthread_create(&g_gbw_watcher_pid,NULL,GBWWatchThreadProc,NULL); |
| 3897 | } |
| 3898 | |
| 3899 | static int stopGBW() { |
| 3900 | void* retval; |
| 3901 | pthread_cancel(g_gbw_watcher_pid); |
| 3902 | pthread_join(g_gbw_watcher_pid, &retval); |
| 3903 | g_gbw_watcher_pid = 0; |
| 3904 | system("tc qdisc del dev tether root"); |
| 3905 | } |
| 3906 | //you.chen add for tv-box end |