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 |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 34 | #undef LOG_TAG |
| 35 | #define LOG_TAG "LYNQ_WIFI" |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 36 | #define MAX_CMD 128 |
| 37 | #define MAX_RET 4096 |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 38 | #define MODE_LEN 10 |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 39 | #define CTRL_STA 0 |
| 40 | #define CTRL_AP 1 |
| 41 | #define AP_NETWORK_0 0 |
qs.xiong | f71b53b | 2023-05-03 13:12:07 +0800 | [diff] [blame] | 42 | #define STA_MAX_SAVED_AP_NUM 50 |
qs.xiong | 44fac67 | 2023-08-29 16:15:55 +0800 | [diff] [blame] | 43 | #define MAC_LEN 17 |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 44 | |
| 45 | pthread_t g_ap_watcher_pid = 0; |
| 46 | volatile int g_ap_watcher_stop_flag = 0; |
you.chen | a6fa5b2 | 2022-05-18 10:28:19 +0800 | [diff] [blame] | 47 | volatile int g_ap_watcher_started_flag = 0; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 48 | |
qs.xiong | 44fac67 | 2023-08-29 16:15:55 +0800 | [diff] [blame] | 49 | pthread_t g_ap_tmp_watcher_pid = 0; |
| 50 | volatile int g_ap_tmp_watcher_stop_flag = 0; |
| 51 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 52 | pthread_t g_sta_watcher_pid = 0; |
| 53 | volatile int g_sta_watcher_stop_flag = 0; |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 54 | volatile int g_sta_scan_finish_flag = 1; |
you.chen | a6fa5b2 | 2022-05-18 10:28:19 +0800 | [diff] [blame] | 55 | volatile int g_sta_watcher_started_flag = 0; |
qs.xiong | 2020242 | 2023-09-06 18:01:18 +0800 | [diff] [blame] | 56 | volatile int g_sta_conncet_status_flag = 0; |
you.chen | 0c9bee2 | 2023-10-25 13:03:14 +0800 | [diff] [blame^] | 57 | volatile int g_sta_fake_scan_finish_flag = 0; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 58 | |
qs.xiong | fcc914b | 2023-07-06 21:16:20 +0800 | [diff] [blame] | 59 | pthread_t g_sta_auto_watcher_pid = 0; |
| 60 | volatile int g_sta_auto_watcher_stop_flag = 0; |
| 61 | volatile int g_sta_auto_scan_finish_flag = 1; |
| 62 | volatile int g_sta_auto_watcher_started_flag = 0; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 63 | void * g_ap_callback_priv = NULL; |
| 64 | AP_CALLBACK_FUNC_PTR g_ap_callback_func = NULL; |
| 65 | void * g_sta_callback_priv = NULL; |
| 66 | STA_CALLBACK_FUNC_PTR g_sta_callback_func = NULL; |
qs.xiong | fcc914b | 2023-07-06 21:16:20 +0800 | [diff] [blame] | 67 | void * g_sta_auto_callback_priv = NULL; |
| 68 | STA_AUTO_CALLBACK_FUNC_PTR g_sta_auto_callback_func = NULL; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 69 | |
| 70 | //const char * CTRL_PATH="/var/run/wpa_supplicant"; |
| 71 | const char * CTRL_PATH[2] = {"/var/run/wpa_supplicant/wlan0", "/var/run/wpa_supplicant/ap0"}; |
| 72 | //const char * CTRL_PATH[2] = {"/var/run/wpa_supplicant/wlan0", "/var/run/wpa_supplicant/wlan0"}; |
| 73 | const char * cmd_list_networks = "LIST_NETWORKS"; |
| 74 | const char * cmd_save_config = "SAVE_CONFIG"; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 75 | const char * cmd_disconnect = "DISCONNECT"; |
| 76 | const char * cmd_remove_all = "REMOVE_NETWORK all"; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 77 | const char * state_scan_result = "CTRL-EVENT-SCAN-RESULTS"; |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 78 | const char * STATE_COMPLETED = "COMPLETED"; |
qs.xiong | 5a2ba93 | 2023-09-13 16:30:21 +0800 | [diff] [blame] | 79 | const char * STATE_SCANNING = "SCANNING"; |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 80 | const char * STATE_DISCONNECTED = "DISCONNECTED"; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 81 | |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 82 | const char * cmd_ping = "PING"; |
| 83 | const char * rsp_pong = "PONG"; |
| 84 | const int SLEEP_TIME_ON_IDLE = 100 * 1000; // usecond |
| 85 | const int MAX_IDLE_COUNT = 600; // 60s |
| 86 | |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 87 | const char * start_wg870_service_script = "/etc/wg870/scripts/start_wg870_service.sh"; |
| 88 | const char * get_interface_name_script = "/etc/wg870/scripts/get_interface_name.sh"; |
| 89 | const char * start_stop_sta_script = "/etc/wg870/scripts/start_stop_sta.sh"; |
| 90 | const char * start_stop_ap_script = "/etc/wg870/scripts/start_stop_ap.sh"; |
| 91 | const char * sta_status_change_script = "/etc/wg870/scripts/sta_status_change.sh"; |
| 92 | |
| 93 | static char s_ap_iterface_name[64] = {0}; |
| 94 | |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 95 | struct local_wpa_ctrl{ |
| 96 | struct wpa_ctrl *ctrl; |
| 97 | pthread_mutex_t mutex; |
| 98 | }; |
| 99 | |
qs.xiong | 0956040 | 2023-10-27 21:58:55 +0800 | [diff] [blame] | 100 | volatile int g_history_disconnect_valid_num = 0; |
qs.xiong | b37f8c4 | 2023-09-13 21:21:58 +0800 | [diff] [blame] | 101 | int g_history_disconnect_net[128]; |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 102 | |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 103 | static pthread_mutex_t s_check_wpa_ctrl_mutex = PTHREAD_MUTEX_INITIALIZER; |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 104 | static pthread_mutex_t s_sta_callback_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 105 | static pthread_mutex_t s_ap_callback_mutex = PTHREAD_MUTEX_INITIALIZER; |
qs.xiong | fcc914b | 2023-07-06 21:16:20 +0800 | [diff] [blame] | 106 | // add for auto connect |
| 107 | static pthread_mutex_t s_sta_auto_callback_mutex = PTHREAD_MUTEX_INITIALIZER; |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 108 | |
| 109 | static struct local_wpa_ctrl * g_lynq_wpa_ctrl[2] = {0}; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 110 | |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 111 | //you.chen add for tv-box start |
| 112 | volatile int g_gbw_enabled = 0; |
| 113 | char * g_gbw_mac = NULL; |
| 114 | pthread_t g_gbw_watcher_pid = 0; |
| 115 | static int startGBW(); |
| 116 | static int stopGBW(); |
| 117 | //you.chen add for tv-box end |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 118 | |
| 119 | typedef struct __curr_status_info { |
| 120 | ap_info_s *ap; |
| 121 | char * state; |
| 122 | int net_no; |
| 123 | }curr_status_info; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 124 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 125 | typedef enum { |
| 126 | INNER_STA_STATUS_INIT = 0, |
| 127 | INNER_STA_STATUS_CONNECTING, |
| 128 | INNER_STA_STATUS_ASSOCIATING, |
| 129 | INNER_STA_STATUS_ASSOCIATED, |
| 130 | INNER_STA_STATUS_CONNECTED, |
| 131 | INNER_STA_STATUS_DISCONNECTING, |
| 132 | INNER_STA_STATUS_DISCONNECTED, |
| 133 | INNER_STA_STATUS_CANCEL, |
| 134 | }inner_sta_status_s; |
| 135 | |
| 136 | static pthread_cond_t s_global_check_cond = PTHREAD_COND_INITIALIZER; |
| 137 | static pthread_mutex_t s_global_check_mutex = PTHREAD_MUTEX_INITIALIZER; |
you.chen | 6e72416 | 2023-10-19 19:10:01 +0800 | [diff] [blame] | 138 | volatile inner_sta_status_s s_sta_status = INNER_STA_STATUS_INIT; |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 139 | static error_number_s s_sta_error_number = -1; |
| 140 | static char s_sta_current_connecting_ssid[64] = {0}; |
| 141 | static struct timespec s_sta_connect_timeout; |
| 142 | const int MAX_CONNNECT_TIME = 15; // second |
| 143 | pthread_t g_global_watcher_pid = 0; |
| 144 | static int s_service_invoke_timeout_cnt=0; |
| 145 | const int FAKE_MAX_INT_VALUE = 99999; |
| 146 | |
qs.xiong | 0956040 | 2023-10-27 21:58:55 +0800 | [diff] [blame] | 147 | static void print_disconnect_list() |
| 148 | { |
| 149 | int i; |
| 150 | for( i = 0; i < g_history_disconnect_valid_num; i++ ) |
| 151 | { |
| 152 | RLOGD(" list of g_history_disconnect_valid_num is %d histroy_list[%d]:%d --------- %d",g_history_disconnect_valid_num,i,g_history_disconnect_net[i],__LINE__); |
| 153 | } |
| 154 | |
| 155 | return; |
| 156 | } |
| 157 | |
| 158 | // idex ----> history_disconnect_list[x] index |
| 159 | static int removeElement(int idex) |
| 160 | { |
| 161 | RLOGD("into removeElement"); |
| 162 | if( index < 0 ) |
| 163 | { |
| 164 | RLOGD("WIFI [removeElement] input idex < 0,idex is %d: ",idex); |
| 165 | return -1; |
| 166 | } |
| 167 | RLOGD("%s line: %d g_history_disconnect_net[%d]: %d end g_history_disconnect_net[%d]:%d",__func__,__LINE__,idex,g_history_disconnect_net[idex],g_history_disconnect_valid_num-1, g_history_disconnect_net[g_history_disconnect_valid_num-1]); |
| 168 | g_history_disconnect_net[idex] = g_history_disconnect_net[g_history_disconnect_valid_num-1]; //g_history_disconnect_vaild_num -1 for get last index |
| 169 | g_history_disconnect_valid_num --; |
| 170 | RLOGD("end removeElement"); |
| 171 | return 0; |
| 172 | } |
| 173 | static int check_history_disconenct_ap_list(int val) |
| 174 | { |
| 175 | print_disconnect_list(); |
| 176 | RLOGD("WIFI[check_history_disconenct_ap_list]into check_history_disconenct_ap_list && input val is %d g_history_disconnect_valid_num is %d line",val,g_history_disconnect_valid_num,__LINE__); |
| 177 | int i; |
| 178 | for( i = 0; i < g_history_disconnect_valid_num; i++) |
| 179 | { |
| 180 | if( val == g_history_disconnect_net[i] ) |
| 181 | { |
| 182 | RLOGD("[wifi]-----input val is %d,g_history_disconnect_net[%d]:%d",val,i,g_history_disconnect_net[i]); |
| 183 | RLOGD("end check_history_disconenct_ap_list && return network index"); |
| 184 | return i; |
| 185 | } |
| 186 | } |
| 187 | RLOGD("end check_history_disconenct_ap_list && return fail,didn't need remove networkid %d from list g_history_disconnect_valid_num is %d line %d",val,g_history_disconnect_valid_num,__LINE__); |
| 188 | return -1; |
| 189 | } |
| 190 | |
| 191 | |
| 192 | static void lynq_sta_removeElement(int net_no) |
| 193 | { |
| 194 | int ret; |
| 195 | |
| 196 | ret = check_history_disconenct_ap_list(net_no); |
| 197 | if( ret == -1 ) |
| 198 | { |
| 199 | RLOGD("curr_net_no not in history_disconenct_lsit,return 0 %s %d",__func__,__LINE__); |
| 200 | return; |
| 201 | }else |
| 202 | { |
| 203 | ret = removeElement(ret); |
| 204 | if( ret == 0 ) |
| 205 | { |
| 206 | RLOGD("removeElement pass %s %d",__func__,__LINE__); |
| 207 | return; |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | return; |
| 212 | } |
| 213 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 214 | static void notify_service_invoke_fail(int error) |
| 215 | { |
| 216 | struct local_wpa_ctrl *lynq_wpa_ctrl = NULL; |
| 217 | pthread_mutex_lock(&s_global_check_mutex); |
| 218 | if (error == -2) //timeout |
| 219 | { |
| 220 | s_service_invoke_timeout_cnt++; |
| 221 | if (s_service_invoke_timeout_cnt > 10) |
| 222 | { |
| 223 | pthread_cond_signal(&s_global_check_cond); |
| 224 | } |
| 225 | } |
| 226 | else if (error == -1) |
| 227 | { |
| 228 | // check if can connect wpa service |
| 229 | lynq_wpa_ctrl = wpa_ctrl_open(CTRL_PATH[0]); |
| 230 | if (lynq_wpa_ctrl == NULL) |
| 231 | { |
| 232 | s_service_invoke_timeout_cnt = FAKE_MAX_INT_VALUE; |
| 233 | pthread_cond_signal(&s_global_check_cond); |
| 234 | } |
| 235 | wpa_ctrl_close(lynq_wpa_ctrl); |
| 236 | lynq_wpa_ctrl = wpa_ctrl_open(CTRL_PATH[1]); |
| 237 | if (lynq_wpa_ctrl == NULL) |
| 238 | { |
| 239 | s_service_invoke_timeout_cnt = FAKE_MAX_INT_VALUE; |
| 240 | pthread_cond_signal(&s_global_check_cond); |
| 241 | } |
| 242 | wpa_ctrl_close(lynq_wpa_ctrl); |
| 243 | } |
| 244 | |
| 245 | pthread_mutex_unlock(&s_global_check_mutex); |
| 246 | } |
| 247 | |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 248 | static int system_call_v(const char * fmt, ...) |
| 249 | { |
| 250 | char str_cmd[256] = {0}; |
| 251 | va_list args; |
| 252 | va_start(args, fmt); |
| 253 | vsprintf(str_cmd, fmt, args); |
| 254 | va_end(args); |
| 255 | printf("system call----------%s\n", str_cmd); |
| 256 | return system(str_cmd); |
| 257 | } |
| 258 | |
you.chen | 0df3e7e | 2023-05-10 15:56:26 +0800 | [diff] [blame] | 259 | static int exec_cmd(const char *str_cmd, char * str_cmd_ret, size_t max_len); |
| 260 | |
| 261 | static const char * inner_get_ap_interface_name() |
| 262 | { |
| 263 | char * p; |
| 264 | char cmd[128]={0}; |
| 265 | |
| 266 | sprintf(cmd, "%s %d", get_interface_name_script, LYNQ_WIFI_INTERFACE_1); |
| 267 | if (0 != exec_cmd(cmd, s_ap_iterface_name, sizeof(s_ap_iterface_name)) || s_ap_iterface_name[0] == '\0') |
| 268 | { |
| 269 | memset(s_ap_iterface_name, 0, sizeof (s_ap_iterface_name)); |
| 270 | return NULL; |
| 271 | } |
| 272 | p = strchr(s_ap_iterface_name, ' '); |
| 273 | if (NULL != p) |
| 274 | { |
| 275 | *p = '\0'; |
| 276 | } |
| 277 | p = strchr(s_ap_iterface_name, '\n'); |
| 278 | if (NULL != p) |
| 279 | { |
| 280 | *p = '\0'; |
| 281 | } |
| 282 | if (s_ap_iterface_name[0] == '\0') |
| 283 | { |
| 284 | return NULL; |
| 285 | } |
| 286 | |
| 287 | return s_ap_iterface_name; |
| 288 | } |
| 289 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 290 | static void check_tether_and_notify() |
| 291 | { |
| 292 | RLOGD("check_tether_and_notify called"); |
you.chen | 0df3e7e | 2023-05-10 15:56:26 +0800 | [diff] [blame] | 293 | if (inner_get_ap_interface_name() == NULL || 0 == system_call_v("ifconfig | grep %s", s_ap_iterface_name)) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 294 | { |
| 295 | return; |
| 296 | } |
| 297 | pthread_mutex_lock(&s_global_check_mutex); |
| 298 | s_service_invoke_timeout_cnt = FAKE_MAX_INT_VALUE; |
| 299 | pthread_cond_signal(&s_global_check_cond); |
| 300 | pthread_mutex_unlock(&s_global_check_mutex); |
| 301 | } |
| 302 | |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 303 | static int local_wpa_ctrl_request(struct local_wpa_ctrl *ctrl, const char *cmd, size_t cmd_len, |
| 304 | char *reply, size_t *reply_len, |
| 305 | void (*msg_cb)(char *msg, size_t len)) |
| 306 | { |
| 307 | int ret; |
| 308 | if (ctrl->ctrl == NULL) { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 309 | RLOGE("local_wpa_ctrl_request ctrl is null\n"); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 310 | return -1; |
| 311 | } |
| 312 | pthread_mutex_lock(&ctrl->mutex); |
| 313 | ret = wpa_ctrl_request(ctrl->ctrl, cmd, cmd_len, reply, reply_len, msg_cb); |
| 314 | pthread_mutex_unlock(&ctrl->mutex); |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 315 | if (ret != 0) |
| 316 | { |
| 317 | notify_service_invoke_fail(ret); |
| 318 | } |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 319 | return ret; |
| 320 | } |
| 321 | |
| 322 | static struct local_wpa_ctrl * inner_get_wpa_ctrl(int index) { |
| 323 | int repeat_cnt; |
| 324 | struct local_wpa_ctrl *lynq_wpa_ctrl = NULL; |
| 325 | pthread_mutex_lock(&s_check_wpa_ctrl_mutex); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 326 | RLOGD("inner_get_wpa_ctrl\n"); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 327 | for (repeat_cnt = 0; repeat_cnt < 5 && NULL == g_lynq_wpa_ctrl[index]; repeat_cnt++) { |
| 328 | pthread_mutex_unlock(&s_check_wpa_ctrl_mutex); |
| 329 | // printf("wait enable finish\n"); |
| 330 | usleep(500 * 1000); |
| 331 | pthread_mutex_lock(&s_check_wpa_ctrl_mutex); |
| 332 | } |
| 333 | if (NULL == g_lynq_wpa_ctrl[index]) { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 334 | RLOGE("NULL == g_lynq_wpa_ctrl[index]"); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 335 | goto out_addr; |
| 336 | } |
| 337 | if (NULL == g_lynq_wpa_ctrl[index]->ctrl) { |
| 338 | g_lynq_wpa_ctrl[index]->ctrl = wpa_ctrl_open(CTRL_PATH[index]); |
| 339 | if (NULL == g_lynq_wpa_ctrl[index]->ctrl) { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 340 | RLOGE("wpa_ctrl_open fail\n"); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 341 | goto out_addr; |
| 342 | } |
| 343 | pthread_mutex_init(&g_lynq_wpa_ctrl[index]->mutex, NULL); |
| 344 | } |
| 345 | lynq_wpa_ctrl = g_lynq_wpa_ctrl[index]; |
| 346 | out_addr: |
| 347 | pthread_mutex_unlock(&s_check_wpa_ctrl_mutex); |
| 348 | return lynq_wpa_ctrl; |
| 349 | } |
| 350 | |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 351 | #define PRINT_AND_RETURN_VALUE(str,value) \ |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 352 | {\ |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 353 | perror((str));\ |
| 354 | return (value);\ |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 355 | } |
| 356 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 357 | #define CHECK_IDX(idx, type) do { \ |
| 358 | if ( (idx == LYNQ_WIFI_INTERFACE_0 && type != CTRL_STA) || (idx == LYNQ_WIFI_INTERFACE_1 && type != CTRL_AP) \ |
| 359 | || idx < LYNQ_WIFI_INTERFACE_0 || idx > LYNQ_WIFI_INTERFACE_1 ) { \ |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 360 | 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] | 361 | return -1; \ |
| 362 | } \ |
| 363 | }while (0) |
| 364 | |
| 365 | #define CHECK_WPA_CTRL(index) int ret = 0;\ |
| 366 | size_t reply_len = MAX_RET; \ |
| 367 | char cmd_reply[MAX_RET]={0}; \ |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 368 | struct local_wpa_ctrl *lynq_wpa_ctrl = NULL; \ |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 369 | do{ \ |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 370 | lynq_wpa_ctrl = inner_get_wpa_ctrl(index); \ |
| 371 | if (NULL == lynq_wpa_ctrl) return -1; \ |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 372 | }while(0) |
| 373 | |
| 374 | #define DO_REQUEST(cmd_str) do { \ |
| 375 | reply_len = MAX_RET;\ |
| 376 | cmd_reply[0] = '\0'; \ |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 377 | RLOGD("to call [%s]\n", cmd_str); \ |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 378 | 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] | 379 | if (ret != 0) { \ |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 380 | RLOGE("call "#cmd_str" fail %d\n", ret); \ |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 381 | return ret; \ |
| 382 | } \ |
| 383 | cmd_reply[reply_len+1] = '\0'; \ |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 384 | RLOGD("cmd replay [ %s ]\n", cmd_reply); \ |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 385 | }while(0) |
| 386 | |
| 387 | #define DO_OK_FAIL_REQUEST(cmd_str) do { \ |
| 388 | DO_REQUEST(cmd_str); \ |
| 389 | if (reply_len >=4 && memcmp(cmd_reply, "FAIL", 4) == 0 ) {\ |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 390 | RLOGE("cmd "#cmd_str" return FAIL\n"); \ |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 391 | return -1; \ |
| 392 | } else if (reply_len >=2 && memcmp(cmd_reply, "OK", 2) != 0) { \ |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 393 | RLOGE("cmd "#cmd_str" return not OK|FAIL\n"); \ |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 394 | return -1; \ |
| 395 | } \ |
| 396 | }while (0) |
| 397 | |
| 398 | |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 399 | static int check_connection(struct wpa_ctrl * wpa_ctrl) |
| 400 | { |
| 401 | size_t reply_len = MAX_RET; |
| 402 | char cmd_reply[MAX_RET]={0}; |
| 403 | int ret; |
| 404 | |
| 405 | RLOGD("check_connection [%p]", wpa_ctrl); |
| 406 | ret = wpa_ctrl_request(wpa_ctrl, cmd_ping, strlen(cmd_ping), cmd_reply, &reply_len, NULL); |
| 407 | |
| 408 | if (ret != 0 || reply_len < 4 || memcmp(cmd_reply, rsp_pong, 4) != 0) |
| 409 | { |
| 410 | 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] | 411 | if (ret != 0) |
| 412 | { |
| 413 | notify_service_invoke_fail(ret); |
| 414 | } |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 415 | return -1; |
| 416 | } |
| 417 | |
| 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | /** |
| 422 | * @brief check_pending_msg |
| 423 | * @param lynq_wpa_ctrl |
| 424 | * @return 1 has msg, 0 no msg, -1 error |
| 425 | */ |
| 426 | static int check_pending_msg(struct wpa_ctrl ** pp_lynq_wpa_ctrl, int type, int* idle_count, int *started_flag) |
| 427 | { |
| 428 | int ret; |
| 429 | |
| 430 | if (*pp_lynq_wpa_ctrl == NULL) // need connect |
| 431 | { |
| 432 | *pp_lynq_wpa_ctrl = wpa_ctrl_open(CTRL_PATH[type]); //@todo temp change |
| 433 | if (*pp_lynq_wpa_ctrl == NULL) |
| 434 | { |
| 435 | usleep(SLEEP_TIME_ON_IDLE); |
| 436 | return -1; |
| 437 | } |
| 438 | |
| 439 | ret = wpa_ctrl_attach(*pp_lynq_wpa_ctrl); |
| 440 | if (ret == 0) // attach success |
| 441 | { |
| 442 | *started_flag = 1; |
| 443 | } |
| 444 | else |
| 445 | { |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 446 | RLOGE("[wifi error]sta watch thread wpa_ctrl_attach fail"); |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 447 | wpa_ctrl_close(*pp_lynq_wpa_ctrl); |
| 448 | *pp_lynq_wpa_ctrl = NULL; |
| 449 | *idle_count = 0; |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 450 | notify_service_invoke_fail(-2); |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 451 | usleep(SLEEP_TIME_ON_IDLE); |
| 452 | return -1; |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | ret = wpa_ctrl_pending(*pp_lynq_wpa_ctrl); |
| 457 | if ( ret == 0) // no pending messages |
| 458 | { |
| 459 | usleep(SLEEP_TIME_ON_IDLE); |
| 460 | *idle_count += 1; |
| 461 | if (*idle_count > MAX_IDLE_COUNT) |
| 462 | { |
| 463 | if (check_connection(*pp_lynq_wpa_ctrl) != 0) |
| 464 | { |
| 465 | wpa_ctrl_detach(*pp_lynq_wpa_ctrl); |
| 466 | wpa_ctrl_close(*pp_lynq_wpa_ctrl); |
| 467 | *pp_lynq_wpa_ctrl = NULL; |
| 468 | *idle_count = 0; |
| 469 | return -1; |
| 470 | } |
| 471 | *idle_count = 0; |
| 472 | } |
| 473 | return 0; |
| 474 | } |
| 475 | else if ( ret == -1) // on error |
| 476 | { |
| 477 | RLOGE("[wifi error]sta wpa_ctrl_pending"); |
| 478 | wpa_ctrl_detach(*pp_lynq_wpa_ctrl); |
| 479 | wpa_ctrl_close(*pp_lynq_wpa_ctrl); |
| 480 | *pp_lynq_wpa_ctrl = NULL; |
| 481 | *idle_count = 0; |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 482 | notify_service_invoke_fail(ret); |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 483 | return -1; |
| 484 | } |
| 485 | |
| 486 | *idle_count = 0; |
| 487 | return 1; |
| 488 | } |
| 489 | |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 490 | static inline void inner_notify_ap_msg(lynq_wifi_ap_status_s status) |
| 491 | { |
| 492 | pthread_mutex_lock(&s_ap_callback_mutex); |
| 493 | if (g_ap_callback_func != NULL) |
| 494 | g_ap_callback_func(g_ap_callback_priv, status); |
| 495 | pthread_mutex_unlock(&s_ap_callback_mutex); |
| 496 | } |
| 497 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 498 | static void APWatcherThreadProc() { |
| 499 | size_t len = MAX_RET; |
| 500 | char msg_notify[MAX_RET]; |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 501 | int idle_count = 0; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 502 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 503 | struct wpa_ctrl *lynq_wpa_ctrl = NULL; |
you.chen | 92fd5d3 | 2022-05-25 10:09:47 +0800 | [diff] [blame] | 504 | g_ap_watcher_stop_flag = 0; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 505 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 506 | while (g_ap_watcher_stop_flag == 0) |
| 507 | { |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 508 | if (check_pending_msg(&lynq_wpa_ctrl, CTRL_AP, &idle_count, &g_ap_watcher_started_flag) != 1) |
| 509 | { |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 510 | if (g_ap_callback_func != NULL && idle_count == MAX_IDLE_COUNT - 100 ) |
| 511 | { |
| 512 | check_tether_and_notify(); |
| 513 | } |
| 514 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 515 | continue; |
| 516 | } |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 517 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 518 | memset(msg_notify, 0, MAX_RET); |
| 519 | len = MAX_RET; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 520 | if (!wpa_ctrl_recv(lynq_wpa_ctrl, msg_notify, &len)) |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 521 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 522 | msg_notify[len+1] = '\0'; |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 523 | RLOGD("APWatcherThreadProc ap------> %s\n", msg_notify); |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 524 | //you.chen change for tv-box start |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 525 | if (strstr(msg_notify, "AP-STA-DISCONNECTED") != NULL) |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 526 | { |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 527 | inner_notify_ap_msg(LYNQ_WIFI_STATUS_DISCONNECT); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 528 | if (g_gbw_enabled == 1 && g_gbw_mac != NULL) |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 529 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 530 | RLOGD("disconect %d, %s ,%s\n", g_gbw_enabled, g_gbw_mac, strstr(msg_notify, (const char*)g_gbw_mac)); |
| 531 | if (strstr(msg_notify, (const char*)g_gbw_mac) != NULL) |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 532 | { |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 533 | stopGBW(); |
| 534 | } |
| 535 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 536 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 537 | else if (strstr(msg_notify, "AP-STA-CONNECTED") != NULL) |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 538 | { |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 539 | inner_notify_ap_msg(LYNQ_WIFI_STATUS_CONNECT); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 540 | if (g_gbw_enabled == 1 && g_gbw_mac != NULL) |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 541 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 542 | RLOGD("conect %d, %s ,%s\n", g_gbw_enabled, g_gbw_mac, strstr(msg_notify, (const char*)g_gbw_mac)); |
| 543 | if (strstr(msg_notify, (const char*)g_gbw_mac) != NULL) |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 544 | { |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 545 | startGBW(); |
| 546 | } |
| 547 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 548 | } |
qs.xiong | baec30f | 2023-09-20 13:10:15 +0800 | [diff] [blame] | 549 | else if ( strstr(msg_notify, "Failed to start AP functionality") != NULL ) |
qs.xiong | 31163d6 | 2023-07-11 18:54:40 +0800 | [diff] [blame] | 550 | { |
| 551 | RLOGD("APWatcherThreadProc ap------> service error"); |
| 552 | inner_notify_ap_msg(LYNQ_WIFI_SERVICE_ABNORMAL); |
| 553 | } |
| 554 | else |
| 555 | { |
| 556 | RLOGD("APWatcherThreadProc ap------> going on check next msg"); |
| 557 | } |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 558 | //you.chen add for tv-box end |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 559 | } // end if (!wpa_ctrl_recv(lynq_wpa_ctrl, msg_notify, &len)) |
| 560 | } // end while (g_ap_watcher_stop_flag == 0) |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 561 | if (lynq_wpa_ctrl != NULL) |
| 562 | { |
you.chen | 92fd5d3 | 2022-05-25 10:09:47 +0800 | [diff] [blame] | 563 | wpa_ctrl_detach(lynq_wpa_ctrl); |
| 564 | wpa_ctrl_close(lynq_wpa_ctrl); |
| 565 | } |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 566 | } |
| 567 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 568 | static void inner_check_connect_error(const char * event_msg, lynq_wifi_sta_status_s state, error_number_s error_num) |
| 569 | { |
| 570 | char * p; |
| 571 | const char * try_associat_flag = "Trying to associate"; |
| 572 | const char * associated_flag = "Associated with "; |
| 573 | |
| 574 | pthread_mutex_lock(&s_global_check_mutex); |
| 575 | if (s_sta_status < INNER_STA_STATUS_CONNECTING || s_sta_status >= INNER_STA_STATUS_CONNECTED) //not in connecting stage, egnore |
| 576 | { |
| 577 | pthread_mutex_unlock(&s_global_check_mutex); |
| 578 | return; |
| 579 | } |
| 580 | |
you.chen | 6e72416 | 2023-10-19 19:10:01 +0800 | [diff] [blame] | 581 | // youchen@2023-10-17 add for "not notify connect fail directly" begin |
| 582 | if (state == LYNQ_WIFI_STA_STATUS_CONNECT_FAIL) |
| 583 | { |
| 584 | s_sta_error_number = error_num; |
| 585 | s_sta_status = INNER_STA_STATUS_DISCONNECTED; |
| 586 | RLOGD("inner_check_connect_error line: %d, curr state %d, %d %d ------",__LINE__, state, s_sta_status, s_sta_error_number); |
| 587 | pthread_cond_signal(&s_global_check_cond); |
| 588 | pthread_mutex_unlock(&s_global_check_mutex); |
| 589 | return; |
| 590 | } |
| 591 | // youchen@2023-10-17 add for "not notify connect fail directly" end |
| 592 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 593 | if (state == LYNQ_WIFI_STATUS_EGNORE) |
| 594 | { |
| 595 | if (strstr(event_msg, try_associat_flag) != NULL && strstr(event_msg, s_sta_current_connecting_ssid) != NULL) //associating request ssid |
| 596 | { |
| 597 | s_sta_status = INNER_STA_STATUS_ASSOCIATING; |
| 598 | } |
| 599 | else if (s_sta_status == INNER_STA_STATUS_ASSOCIATING && (p=strstr(event_msg, associated_flag)) != NULL) |
| 600 | { |
| 601 | s_sta_status = INNER_STA_STATUS_ASSOCIATED; |
| 602 | } |
| 603 | } |
| 604 | else if (state == LYNQ_WIFI_STA_STATUS_DISCONNECT) |
| 605 | { |
| 606 | s_sta_error_number = error_num; |
| 607 | if (s_sta_status >= INNER_STA_STATUS_ASSOCIATING && strstr(event_msg, "CTRL-EVENT-SSID-TEMP-DISABLED") != NULL && error_num != LYNQ_WAIT_CONNECT_ACTIVE) |
| 608 | { |
| 609 | s_sta_status = INNER_STA_STATUS_DISCONNECTED; |
you.chen | 6e72416 | 2023-10-19 19:10:01 +0800 | [diff] [blame] | 610 | RLOGD("inner_check_connect_error line: %d, curr state %d, %d %d ------",__LINE__, state, s_sta_status, s_sta_error_number); |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 611 | pthread_cond_signal(&s_global_check_cond); |
| 612 | } |
| 613 | } |
| 614 | else if (state == LYNQ_WIFI_STA_STATUS_CONNECT) |
| 615 | { |
| 616 | s_sta_status = INNER_STA_STATUS_CONNECTED; |
you.chen | 6e72416 | 2023-10-19 19:10:01 +0800 | [diff] [blame] | 617 | RLOGD("inner_check_connect_error line: %d, curr state %d, %d %d ------",__LINE__, state, s_sta_status, s_sta_error_number); |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 618 | pthread_cond_signal(&s_global_check_cond); |
| 619 | } |
| 620 | pthread_mutex_unlock(&s_global_check_mutex); |
| 621 | } |
| 622 | |
qs.xiong | b37f8c4 | 2023-09-13 21:21:58 +0800 | [diff] [blame] | 623 | static int lynq_split(char * str, int len, char delimiter, char * results[]); |
| 624 | static inline char inner_convert_char(char in); |
| 625 | static inline void inner_copy_ssid(char * out_ssid, const char * ssid, size_t out_ssid_len); |
| 626 | static int lynq_get_network_number_list(lynq_wifi_index_e idx, int ap_sta, int net_no_list[], char * ssid); |
| 627 | |
| 628 | |
| 629 | |
qs.xiong | 44fac67 | 2023-08-29 16:15:55 +0800 | [diff] [blame] | 630 | /* |
| 631 | just tmp add for fix sta connect ap fail check ap connect info |
| 632 | return 0 --->Current no sta device connect this AP |
| 633 | */ |
| 634 | static int lynq_connected_ap_sta_status() { |
| 635 | |
| 636 | FILE *fp; |
| 637 | size_t i = 0; |
| 638 | int ret; |
| 639 | char lynq_cmd_ret[MAX_RET]={0}; |
| 640 | |
| 641 | if((fp=popen("wpa_cli -iwpa_wlan0_cmd -p/var/run/ IFNAME=ap0 list_sta","r"))==NULL) |
| 642 | { |
| 643 | perror("popen error!"); |
| 644 | return -1; |
| 645 | } |
| 646 | if((fread(lynq_cmd_ret,sizeof(lynq_cmd_ret),1,fp))<0) |
| 647 | { |
| 648 | perror("fread fail!"); |
| 649 | ret=pclose(fp); |
| 650 | if(ret == -1) |
| 651 | perror("close file faild"); |
| 652 | return -1; |
| 653 | } |
| 654 | if( strlen(lynq_cmd_ret) < MAC_LEN) |
| 655 | { |
| 656 | RLOGD("---Current no sta device connect this AP %s %d\n", lynq_cmd_ret,strlen(lynq_cmd_ret)); |
| 657 | ret=pclose(fp); |
| 658 | if(ret==-1) |
| 659 | { |
| 660 | perror("close file faild"); |
| 661 | } |
| 662 | return 0; |
| 663 | }else{ |
| 664 | ret=pclose(fp); |
| 665 | if(ret==-1) |
| 666 | { |
| 667 | perror("close file faild"); |
| 668 | } |
| 669 | RLOGD("---Current has sta device connect this AP--- %s\n", lynq_cmd_ret); |
| 670 | return 1; |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | /* |
| 675 | just tmp add for fix sta connect ap fail; check fw status |
| 676 | return 1 ----> fw status error; need wl down/up |
| 677 | */ |
| 678 | static int check_current_fw_status() { |
| 679 | |
| 680 | FILE *fp; |
| 681 | FILE *fp1; |
| 682 | size_t i = 0; |
| 683 | int ret; |
| 684 | char lynq_cmd_ret_2g[MAX_RET]={0}; |
| 685 | char lynq_cmd_ret_5g[MAX_RET]={0}; |
| 686 | |
| 687 | const char * fw_status = "0x0096"; //0x0096 is normal fw status |
| 688 | |
| 689 | if((fp=popen("wl shmem 0x15ee a","r"))==NULL) |
| 690 | { |
| 691 | perror("popen error!"); |
| 692 | return -1; |
| 693 | } |
| 694 | if((fread(lynq_cmd_ret_5g,sizeof(lynq_cmd_ret_2g),1,fp))<0) |
| 695 | { |
| 696 | perror("fread fail!"); |
| 697 | if(pclose(fp) == -1) |
| 698 | perror("close fp file faild"); |
| 699 | return -1; |
| 700 | } |
| 701 | |
| 702 | if((fp1=popen("wl shmem 0x15ee b","r"))==NULL) |
| 703 | { |
| 704 | perror("popen error!"); |
| 705 | if(pclose(fp) == -1) |
| 706 | perror("clsoe fp file faild"); |
| 707 | return -1; |
| 708 | } |
| 709 | if((fread(lynq_cmd_ret_2g,sizeof(lynq_cmd_ret_5g),1,fp1))<0) |
| 710 | { |
| 711 | perror("fread fail!"); |
| 712 | if(pclose(fp1) == -1) |
| 713 | perror("clsoe fp1 file faild"); |
| 714 | if(pclose(fp) == -1) |
| 715 | perror("clsoe fp file faild"); |
| 716 | return -1; |
| 717 | } |
| 718 | |
| 719 | if ( strncmp(fw_status,lynq_cmd_ret_2g,6) == 0 || strncmp(fw_status,lynq_cmd_ret_5g,6) == 0 ) |
| 720 | { |
| 721 | ret=pclose(fp); |
| 722 | if(ret==-1) |
| 723 | { |
| 724 | perror("close fp file faild"); |
| 725 | } |
| 726 | ret=pclose(fp1); |
| 727 | if(ret==-1) |
| 728 | { |
| 729 | perror("close fp1 file faild"); |
| 730 | } |
| 731 | return 0; |
| 732 | }else |
| 733 | { |
| 734 | ret=pclose(fp); |
| 735 | if(ret==-1) |
| 736 | { |
| 737 | perror("close file faild"); |
| 738 | } |
| 739 | if(pclose(fp1) == -1) |
| 740 | { |
| 741 | perror("clsoe file fp1 faild"); |
| 742 | } |
| 743 | RLOGD("current fw status --error--"); |
| 744 | return 1; |
| 745 | } |
| 746 | } |
| 747 | |
qs.xiong | 1d4263a | 2023-09-06 10:46:23 +0800 | [diff] [blame] | 748 | /* |
| 749 | eg: wl counters info |
| 750 | sh-3.2# wl counters |
| 751 | counters_version 30 |
| 752 | datalen 1648 |
| 753 | Slice_index: 0 |
| 754 | reinitreason_counts: 0(0) 1(0) 2(3) 3(0) 4(0) 5(0) 6(0) 7(0) 8(0) 9(0) 10(0) 11(0) 12(0) 13(0) 14(2) 15(0) 16(0) 17(0) 18(0) 19(0) 20(0) 21(0) 22(0) 23(0) 24(0) 25(0) 26(0) 27(0) 28(0) 29(0) 30(0) 31(0) 32(0) 33(0) 34(0) 35(0) 36(0) 37(0) 38(0) 39(0) 40(0) 41(0) 42(0) 43(0) 44(0) 45(0) 46(0) 47(0) 48(0) 49(0) 50(0) 51(0) 52(0) 53(0) 54(0) |
| 755 | reinit 0 reset 2 pciereset 0 cfgrestore 0 dma_hang 0 ampdu_wds 0 |
| 756 | |
| 757 | check reinit status |
| 758 | return 0 ===> fw did wl reinit cmd |
| 759 | */ |
| 760 | static int check_current_reinit_info() |
| 761 | { |
| 762 | FILE *fp; |
| 763 | int ret; |
| 764 | char lynq_cmd_ret[MAX_RET]={0}; |
| 765 | char * dest; |
| 766 | char destid[3]={0}; |
| 767 | if((fp=popen("wl counters","r"))==NULL) |
| 768 | { |
| 769 | perror("popen error!"); |
| 770 | return -1; |
| 771 | } |
| 772 | if((fread(lynq_cmd_ret,sizeof(lynq_cmd_ret),1,fp))<0) |
| 773 | { |
| 774 | perror("fread fail!"); |
| 775 | if(pclose(fp) == -1) |
| 776 | { |
| 777 | perror("close fp file faild"); |
| 778 | } |
| 779 | return -1; |
| 780 | } |
| 781 | dest = strstr(lynq_cmd_ret,"reinit "); |
| 782 | if(dest != NULL) |
| 783 | { |
| 784 | dest +=strlen("reinit "); |
| 785 | RLOGD("current get dest str is %s",dest); |
| 786 | memcpy(destid,dest,2); |
| 787 | ret = atoi(destid); |
| 788 | RLOGD("get current wl counters cmd return counts is %d",ret); |
| 789 | if( ret != 0 ) |
| 790 | { |
| 791 | RLOGD("current fw did run cmd wl reinit"); |
| 792 | if( pclose(fp) == -1 ) |
| 793 | { |
| 794 | perror("close fp file faild"); |
| 795 | } |
| 796 | return 0; |
| 797 | } |
| 798 | } |
| 799 | if( pclose(fp) == -1 ) |
| 800 | { |
| 801 | perror("close fp file faild"); |
| 802 | } |
| 803 | RLOGD("current fw didn't run cmd wl reinit,dest ptr is NULL"); |
| 804 | return -1; |
| 805 | } |
| 806 | |
qs.xiong | 44fac67 | 2023-08-29 16:15:55 +0800 | [diff] [blame] | 807 | static void APTmpWatcherThreadProc() { |
| 808 | |
| 809 | int i = 0; |
| 810 | int delytime = 300; |
| 811 | g_ap_tmp_watcher_stop_flag = 0; |
| 812 | |
| 813 | RLOGD("APTmpWatcherThreadProc ----> ThreadProc start"); |
| 814 | while(1) |
| 815 | { |
| 816 | sleep(1); |
| 817 | i++; |
qs.xiong | 1d4263a | 2023-09-06 10:46:23 +0800 | [diff] [blame] | 818 | if ( (i % 30) == 0 ) |
| 819 | { |
| 820 | if ( check_current_reinit_info() == 0 ) |
| 821 | { |
| 822 | system("wl reset_cnts"); |
| 823 | system("wl down"); |
| 824 | system("wl up"); |
| 825 | RLOGD("APTmpWatcherThreadProc:check fw did reinit cmd,do down/up reset"); |
| 826 | } |
| 827 | } |
qs.xiong | 08e6aac | 2023-09-06 23:12:27 +0800 | [diff] [blame] | 828 | if ( (i % 10) == 0 ) |
qs.xiong | 44fac67 | 2023-08-29 16:15:55 +0800 | [diff] [blame] | 829 | { |
qs.xiong | 08e6aac | 2023-09-06 23:12:27 +0800 | [diff] [blame] | 830 | if( lynq_connected_ap_sta_status() == 0 ) //0 --->no sta device connect this ap |
qs.xiong | 44fac67 | 2023-08-29 16:15:55 +0800 | [diff] [blame] | 831 | { |
| 832 | if(check_current_fw_status() == 1) //1 --->current fw status not 0x0096 |
| 833 | { |
| 834 | system("wl down"); |
| 835 | system("wl up"); |
| 836 | } |
qs.xiong | 44fac67 | 2023-08-29 16:15:55 +0800 | [diff] [blame] | 837 | } |
qs.xiong | 08e6aac | 2023-09-06 23:12:27 +0800 | [diff] [blame] | 838 | } |
| 839 | if ( i == delytime ) |
| 840 | { |
qs.xiong | 44fac67 | 2023-08-29 16:15:55 +0800 | [diff] [blame] | 841 | i = 0; |
| 842 | } |
| 843 | if( g_ap_tmp_watcher_stop_flag == 1 ) //quit proc |
| 844 | { |
| 845 | RLOGD("APTmpWatcherThreadProc ----- > ap closed or wifi disabled"); |
| 846 | return; |
| 847 | } |
qs.xiong | 08e6aac | 2023-09-06 23:12:27 +0800 | [diff] [blame] | 848 | |
qs.xiong | 44fac67 | 2023-08-29 16:15:55 +0800 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | } |
| 852 | |
qs.xiong | f0128b1 | 2023-06-29 17:29:39 +0800 | [diff] [blame] | 853 | static int lynq_wifi_sta_stop_network(lynq_wifi_index_e idx,int networkid) |
| 854 | { |
| 855 | char LYNQ_DISABLE_CMD[128]={0}; |
| 856 | |
| 857 | CHECK_IDX(idx, CTRL_STA); |
| 858 | CHECK_WPA_CTRL(CTRL_STA); |
| 859 | |
| 860 | sprintf(LYNQ_DISABLE_CMD,"DISABLE_NETWORK %d",networkid); |
qs.xiong | b5dab08 | 2023-10-13 14:43:41 +0800 | [diff] [blame] | 861 | RLOGD("LYNQ_DISABLE_CMD is:%s\n",LYNQ_DISABLE_CMD); |
qs.xiong | f0128b1 | 2023-06-29 17:29:39 +0800 | [diff] [blame] | 862 | DO_OK_FAIL_REQUEST(LYNQ_DISABLE_CMD); |
qs.xiong | c93bf2b | 2023-08-25 10:22:08 +0800 | [diff] [blame] | 863 | |
qs.xiong | f0128b1 | 2023-06-29 17:29:39 +0800 | [diff] [blame] | 864 | return 0; |
qs.xiong | c93bf2b | 2023-08-25 10:22:08 +0800 | [diff] [blame] | 865 | |
qs.xiong | f0128b1 | 2023-06-29 17:29:39 +0800 | [diff] [blame] | 866 | } |
| 867 | |
qs.xiong | b37f8c4 | 2023-09-13 21:21:58 +0800 | [diff] [blame] | 868 | static int lynq_wifi_sta_enable_network(lynq_wifi_index_e idx,int networkid) |
| 869 | { |
| 870 | char LYNQ_ENABLE_CMD[128]={0}; |
| 871 | |
| 872 | CHECK_IDX(idx, CTRL_STA); |
| 873 | CHECK_WPA_CTRL(CTRL_STA); |
| 874 | |
| 875 | |
| 876 | sprintf(LYNQ_ENABLE_CMD,"ENABLE_NETWORK %d",networkid); |
qs.xiong | b5dab08 | 2023-10-13 14:43:41 +0800 | [diff] [blame] | 877 | RLOGD("LYNQ_ENABLE_CMD is:%s\n",LYNQ_ENABLE_CMD); |
qs.xiong | b37f8c4 | 2023-09-13 21:21:58 +0800 | [diff] [blame] | 878 | DO_OK_FAIL_REQUEST(LYNQ_ENABLE_CMD); |
| 879 | |
| 880 | return 0; |
| 881 | |
| 882 | } |
| 883 | |
| 884 | static int lynq_tmp_enable_network(lynq_wifi_index_e idx,int net_no_list[],int len) |
| 885 | { |
| 886 | |
| 887 | int index,networkid; |
| 888 | |
| 889 | for ( index = 0; index < len ;index++) |
| 890 | { |
| 891 | networkid = net_no_list[index]; |
qs.xiong | b8518cd | 2023-09-22 18:43:42 +0800 | [diff] [blame] | 892 | if( lynq_wifi_sta_enable_network(idx,networkid) != 0 ) |
qs.xiong | b37f8c4 | 2023-09-13 21:21:58 +0800 | [diff] [blame] | 893 | { |
| 894 | RLOGE("[wifi]lynq_tmp_enable_network id is %d fail",networkid); |
| 895 | } |
| 896 | RLOGD("[wifi]lynq_tmp_enable_network id is %d",networkid); |
| 897 | } |
| 898 | return 0; |
| 899 | |
| 900 | } |
| 901 | |
| 902 | |
| 903 | /* |
| 904 | dis_net_list user disconnect list |
| 905 | */ |
| 906 | static void lynq_two_arr_merge(int dis_net_list[],int valid_num,int out[],int * outlen) |
| 907 | { |
qs.xiong | 0956040 | 2023-10-27 21:58:55 +0800 | [diff] [blame] | 908 | RLOGD("enter %s %d",__func__,__LINE__); |
| 909 | print_disconnect_list(); |
qs.xiong | b37f8c4 | 2023-09-13 21:21:58 +0800 | [diff] [blame] | 910 | int count,ncount,index; |
| 911 | int flag = 0; |
| 912 | int merge_index = 0; |
| 913 | int net_no_list[128]; |
| 914 | |
qs.xiong | 0956040 | 2023-10-27 21:58:55 +0800 | [diff] [blame] | 915 | for(ncount = 0;ncount < valid_num; ncount++ ) |
| 916 | { |
| 917 | RLOGD("input history disconenct_list[%d] %d %d",ncount,dis_net_list[ncount],__LINE__); |
| 918 | } |
| 919 | |
qs.xiong | b37f8c4 | 2023-09-13 21:21:58 +0800 | [diff] [blame] | 920 | index =lynq_get_network_number_list(0, 0, net_no_list,NULL); |
| 921 | for( count = 0; count < index; count++) |
| 922 | { |
| 923 | for(ncount = 0; ncount < valid_num; ncount++) |
| 924 | { |
qs.xiong | 0956040 | 2023-10-27 21:58:55 +0800 | [diff] [blame] | 925 | RLOGD(" %s dis_net_list[%d]->%d %d",__func__,ncount,dis_net_list[ncount],__LINE__); |
qs.xiong | b37f8c4 | 2023-09-13 21:21:58 +0800 | [diff] [blame] | 926 | if(net_no_list[count] == dis_net_list[ncount]) |
| 927 | { |
qs.xiong | 0956040 | 2023-10-27 21:58:55 +0800 | [diff] [blame] | 928 | RLOGD("[wifi]this is history disconnect idx ----> %d %d",net_no_list[count],__LINE__); |
qs.xiong | b37f8c4 | 2023-09-13 21:21:58 +0800 | [diff] [blame] | 929 | flag = 1; |
| 930 | break; |
| 931 | } |
| 932 | } |
| 933 | if( flag != 1 ) |
| 934 | { |
| 935 | out[merge_index] = net_no_list[count]; |
qs.xiong | 0956040 | 2023-10-27 21:58:55 +0800 | [diff] [blame] | 936 | RLOGD("out[%d]: %d net_no_list[%d]: %d %d",merge_index,out[merge_index],count,net_no_list[count],__LINE__); |
qs.xiong | b37f8c4 | 2023-09-13 21:21:58 +0800 | [diff] [blame] | 937 | merge_index ++; |
| 938 | } |
| 939 | flag = 0; |
| 940 | } |
| 941 | * outlen =merge_index; |
| 942 | RLOGD("[wifi]lynq_two_arr_merge get len is -----> %d",* outlen); |
| 943 | return; |
| 944 | } |
qs.xiong | f0128b1 | 2023-06-29 17:29:39 +0800 | [diff] [blame] | 945 | |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 946 | void get_state_error(const char* modify, lynq_wifi_sta_status_s* state, error_number_s* error) |
| 947 | { |
| 948 | char *pReason; |
qs.xiong | f0128b1 | 2023-06-29 17:29:39 +0800 | [diff] [blame] | 949 | char *wpanetid; |
| 950 | char destid[3] = {0}; |
| 951 | int tmpdisid = -1; |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 952 | *error = LYNQ_WAIT_CONNECT_ACTIVE; |
| 953 | if (strstr(modify, "CTRL-EVENT-SCAN-RESULTS") != NULL) |
| 954 | { |
| 955 | *state = LYNQ_WIFI_STA_STATUS_SCAN_RESULT; |
| 956 | RLOGD("CTRL-EVENT-SCAN-RESULTS state:%d,error:%d\n",*state,*error); |
| 957 | return; |
| 958 | } |
| 959 | |
qs.xiong | 2020242 | 2023-09-06 18:01:18 +0800 | [diff] [blame] | 960 | if (strstr(modify, "Trying to associate") != NULL) |
| 961 | { |
| 962 | RLOGD("Current sta is Trying to associate"); |
| 963 | *state = LYNQ_WIFI_STATUS_EGNORE; |
| 964 | g_sta_conncet_status_flag = 1; |
| 965 | return; |
| 966 | } |
| 967 | |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 968 | if (strstr(modify, "CTRL-EVENT-CONNECTED") != NULL) |
| 969 | { |
| 970 | *state = LYNQ_WIFI_STA_STATUS_CONNECT; |
qs.xiong | 0956040 | 2023-10-27 21:58:55 +0800 | [diff] [blame] | 971 | RLOGD("CTRL-EVENT-CONNECTED state:%d,error:%d",*state,*error); |
qs.xiong | 2020242 | 2023-09-06 18:01:18 +0800 | [diff] [blame] | 972 | g_sta_conncet_status_flag = 0; |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 973 | return; |
| 974 | } |
| 975 | |
qs.xiong | 1e81dfa | 2023-09-27 15:52:37 +0800 | [diff] [blame] | 976 | if (strstr(modify,"CTRL-EVENT-AUTH-REJECT") != NULL) |
| 977 | { |
| 978 | *error = LYNQ_PSW_ERROR; |
| 979 | *state = LYNQ_WIFI_STA_STATUS_CONNECT_FAIL; |
| 980 | RLOGD("CTRL-EVENT-AUTH-REJECT state:%d,error:%d\n",*state,*error); |
| 981 | g_sta_conncet_status_flag = 0; |
| 982 | return; |
| 983 | } |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 984 | if (strstr(modify, "CTRL-EVENT-SSID-TEMP-DISABLED") != NULL) |
| 985 | { |
qs.xiong | f0128b1 | 2023-06-29 17:29:39 +0800 | [diff] [blame] | 986 | *state = LYNQ_WIFI_STA_STATUS_DISCONNECT; |
| 987 | wpanetid = strstr(modify,"id="); |
| 988 | if ( wpanetid != NULL ) |
| 989 | { |
| 990 | wpanetid +=strlen("id="); |
| 991 | memcpy(destid,wpanetid,2); |
| 992 | tmpdisid = atoi(destid); |
| 993 | |
| 994 | } |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 995 | pReason = strstr(modify, "reason="); |
| 996 | if (pReason != NULL) |
| 997 | { |
| 998 | pReason += strlen("reason="); |
| 999 | if (memcmp(pReason, "CONN_FAILED", 11) == 0) |
| 1000 | { |
| 1001 | *error = LYNQ_TIME_OUT; |
| 1002 | } |
| 1003 | else if (memcmp(pReason, "WRONG_KEY", 9) == 0) |
| 1004 | { |
| 1005 | *error = LYNQ_PSW_ERROR; |
qs.xiong | 7d24bf5 | 2023-09-20 13:22:35 +0800 | [diff] [blame] | 1006 | *state = LYNQ_WIFI_STA_STATUS_CONNECT_FAIL; |
qs.xiong | f0128b1 | 2023-06-29 17:29:39 +0800 | [diff] [blame] | 1007 | // tmp fix sta autoconnect connect and disconnect |
you.chen | 6e72416 | 2023-10-19 19:10:01 +0800 | [diff] [blame] | 1008 | // you.chen@2023-10-17 only disable network during autoconnect |
| 1009 | if(tmpdisid != -1 && s_sta_status == INNER_STA_STATUS_INIT && lynq_wifi_sta_stop_network(0,tmpdisid) != 0) |
qs.xiong | f0128b1 | 2023-06-29 17:29:39 +0800 | [diff] [blame] | 1010 | { |
| 1011 | RLOGE("stop wlan0 network %d fail",tmpdisid); |
| 1012 | } |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 1013 | } |
| 1014 | else |
| 1015 | { |
| 1016 | *error = LYNQ_UNSPECIFIED_REASON; |
| 1017 | } |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 1018 | } |
| 1019 | else |
| 1020 | { |
| 1021 | *error = LYNQ_UNSPECIFIED_REASON; |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 1022 | } |
qs.xiong | f0128b1 | 2023-06-29 17:29:39 +0800 | [diff] [blame] | 1023 | RLOGD("CTRL-EVENT-SSID-TEMP-DISABLED state:%d,error:%d,tmpnetid:%d",*state,*error,tmpdisid); |
qs.xiong | 2020242 | 2023-09-06 18:01:18 +0800 | [diff] [blame] | 1024 | g_sta_conncet_status_flag = 0; |
qs.xiong | f0128b1 | 2023-06-29 17:29:39 +0800 | [diff] [blame] | 1025 | return; |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 1026 | |
| 1027 | } |
| 1028 | |
| 1029 | if (strstr(modify, "CTRL-EVENT-NETWORK-NOT-FOUND") != NULL) |
| 1030 | { |
| 1031 | *error = LYNQ_NOT_FIND_AP; |
| 1032 | *state = LYNQ_WIFI_STA_STATUS_DISCONNECT; |
| 1033 | RLOGD("CTRL-EVENT-NETWORK-NOT-FOUND state:%d,error:%d\n",*state,*error); |
qs.xiong | 2020242 | 2023-09-06 18:01:18 +0800 | [diff] [blame] | 1034 | g_sta_conncet_status_flag = 0; |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 1035 | return; |
| 1036 | } |
| 1037 | |
| 1038 | |
| 1039 | if (strstr(modify, "CTRL-EVENT-ASSOC-REJECT") != NULL) |
| 1040 | { |
| 1041 | RLOGD("FIND CTRL EVENT : CTRL-EVENT-ASSOC-REJECT\n"); |
| 1042 | pReason = strstr(modify, "status_code="); |
| 1043 | if (pReason != NULL) |
| 1044 | { |
| 1045 | pReason += strlen("status_code="); |
| 1046 | if (memcmp(pReason, "17", 2) == 0) |
| 1047 | { |
| 1048 | *error = LYNQ_AP_UNABLE_HANDLE; |
| 1049 | } |
| 1050 | else if (memcmp(pReason, "1",1) == 0) |
| 1051 | { |
| 1052 | *error = LYNQ_UNSPECIFIED_REASON; |
| 1053 | } |
| 1054 | else |
| 1055 | { |
| 1056 | *error = LYNQ_UNSPECIFIED_REASON; |
| 1057 | } |
| 1058 | |
| 1059 | *state = LYNQ_WIFI_STA_STATUS_DISCONNECT; |
| 1060 | RLOGD("CTRL-EVENT-ASSOC-REJECT BUT NOT STATUS_CODE NOT 1 or 17 state:%d,error:%d\n",*state,*error); |
qs.xiong | 2020242 | 2023-09-06 18:01:18 +0800 | [diff] [blame] | 1061 | g_sta_conncet_status_flag = 0; |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 1062 | return; |
| 1063 | } |
| 1064 | else |
| 1065 | { |
| 1066 | RLOGD("FIND CTRL EVENT : CTRL-EVENT-ASSOC-REJECT BUT NOT FOUND STATUS_CODE\n"); |
| 1067 | *error = LYNQ_UNSPECIFIED_REASON; |
| 1068 | *state = LYNQ_WIFI_STA_STATUS_DISCONNECT; |
| 1069 | RLOGD("CTRL-EVENT-ASSOC-REJECT state:%d,error:%d\n",*state,*error); |
| 1070 | return; |
| 1071 | } |
| 1072 | } |
| 1073 | |
| 1074 | if (strstr(modify, "CTRL-EVENT-SAE-UNKNOWN-PASSWORD-IDENTIFIER") != NULL) |
| 1075 | { |
| 1076 | RLOGD("FIND CTRL EVENT : CTRL-EVENT-SAE-UNKNOWN-PASSWORD-IDENTIFIER\n"); |
| 1077 | *error = LYNQ_AUTHENTICATION_NO_LONGER_VALID; |
| 1078 | *state = LYNQ_WIFI_STA_STATUS_DISCONNECT; |
| 1079 | RLOGD("CTRL-EVENT-SAE-UNKNOWN-PASSWORD-IDENTIFIER state:%d,error:%d\n",*state,*error); |
| 1080 | return; |
| 1081 | } |
| 1082 | |
| 1083 | if (strstr(modify, "CTRL-EVENT-DISCONNECTED") != NULL) |
| 1084 | { |
| 1085 | RLOGD("FIND CTRL EVENT : CTRL-EVENT-DISCONNECTED\n"); |
| 1086 | *error = LYNQ_WAIT_CONNECT_ACTIVE; |
| 1087 | *state = LYNQ_WIFI_STA_STATUS_DISCONNECT; |
| 1088 | RLOGD("CTRL-EVENT-DISCONNECTED state:%d,error:%d\n",*state,*error); |
| 1089 | return; |
| 1090 | } |
| 1091 | |
qs.xiong | df637b2 | 2023-10-26 19:30:07 +0800 | [diff] [blame] | 1092 | // add by qs.xiong 20231026 tmp fix sta association request to the driver failed |
| 1093 | if (strstr(modify, "Association request to the driver failed") != NULL) |
| 1094 | { |
| 1095 | RLOGD("Association request to the driver failed --- recover"); |
| 1096 | system("wl down"); |
| 1097 | system("wl up"); |
| 1098 | *error = LYNQ_UNSPECIFIED_REASON; |
| 1099 | *state = LYNQ_WIFI_STA_STATUS_DISCONNECT; |
| 1100 | RLOGD("CTRL-EVENT-DISCONNECTED state:%d,error:%d\n",*state,*error); |
| 1101 | return; |
| 1102 | } |
| 1103 | // add by qs.xiong 20231026 tmp fix sta association request to the driver failed end |
| 1104 | |
| 1105 | |
you.chen | 32cb31e | 2023-04-13 14:05:45 +0800 | [diff] [blame] | 1106 | RLOGD("EVENT : %s\n", modify); |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 1107 | *error = LYNQ_UNSPECIFIED_REASON; |
you.chen | 32cb31e | 2023-04-13 14:05:45 +0800 | [diff] [blame] | 1108 | *state = LYNQ_WIFI_STATUS_EGNORE; |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 1109 | RLOGD("LAST : STA state:%d,error:%d\n",*state,*error); |
| 1110 | return; |
| 1111 | |
| 1112 | } |
| 1113 | |
qs.xiong | fcc914b | 2023-07-06 21:16:20 +0800 | [diff] [blame] | 1114 | void get_state_error_networkid(const char* modify, lynq_wifi_sta_status_s* state, error_number_s* error,int *networkid) |
| 1115 | { |
| 1116 | char *pReason; |
| 1117 | char *wpanetid; |
| 1118 | char destid[3]; |
| 1119 | *error = LYNQ_WAIT_CONNECT_ACTIVE; |
| 1120 | *networkid = -1; |
| 1121 | if (strstr(modify, "CTRL-EVENT-SCAN-RESULTS") != NULL) |
| 1122 | { |
| 1123 | *state = LYNQ_WIFI_STA_STATUS_SCAN_RESULT; |
| 1124 | RLOGD("CTRL-EVENT-SCAN-RESULTS state:%d,error:%d,,networkid:%d\n",*state,*error,*networkid); |
| 1125 | return; |
| 1126 | } |
| 1127 | if (strstr(modify, "CTRL-EVENT-CONNECTED") != NULL) |
| 1128 | { |
| 1129 | RLOGD("[xiong]:wpanetid = strstrmodify;\n"); |
| 1130 | wpanetid = strstr(modify,"id="); |
| 1131 | if ( wpanetid != NULL ) |
| 1132 | { |
| 1133 | wpanetid +=strlen("id="); |
| 1134 | RLOGD("[xiong]:memcpy(destid,wpanetid,0\n"); |
| 1135 | if (memcpy(destid,wpanetid,2) != NULL) |
| 1136 | { |
| 1137 | RLOGD("[xiong]:memcpy(destid,wpanetid,1\n"); |
| 1138 | *networkid = atoi(destid); |
| 1139 | RLOGD("get networkid is %d\n",*networkid); |
| 1140 | } |
| 1141 | RLOGD("[xiong]:memcpy(destid,wpanetid,2\n"); |
| 1142 | } |
| 1143 | *state = LYNQ_WIFI_STA_STATUS_CONNECT; |
| 1144 | RLOGD("CTRL-EVENT-CONNECTED state:%d,error:%d,networkid:%d\n",*state,*error,*networkid); |
| 1145 | return; |
| 1146 | } |
| 1147 | if (strstr(modify, "CTRL-EVENT-SSID-TEMP-DISABLED") != NULL) |
| 1148 | { |
| 1149 | wpanetid = strstr(modify,"id="); |
| 1150 | if ( wpanetid != NULL ) |
| 1151 | { |
| 1152 | wpanetid +=strlen("id="); |
| 1153 | if (memcpy(destid,wpanetid,2) != NULL) |
| 1154 | { |
| 1155 | *networkid = atoi(destid); |
| 1156 | RLOGD("get networkid is %d\n",*networkid); |
| 1157 | } |
| 1158 | } |
| 1159 | pReason = strstr(modify, "reason="); |
| 1160 | if (pReason != NULL) |
| 1161 | { |
| 1162 | pReason += strlen("reason="); |
| 1163 | if (memcmp(pReason, "CONN_FAILED", 11) == 0) |
| 1164 | { |
| 1165 | *error = LYNQ_TIME_OUT; |
| 1166 | } |
| 1167 | else if (memcmp(pReason, "WRONG_KEY", 9) == 0) |
| 1168 | { |
| 1169 | *error = LYNQ_PSW_ERROR; |
| 1170 | } |
| 1171 | else |
| 1172 | { |
| 1173 | *error = LYNQ_UNSPECIFIED_REASON; |
| 1174 | } |
| 1175 | *state = LYNQ_WIFI_STA_STATUS_CONNECT_FAIL; |
| 1176 | RLOGD("CTRL-EVENT-SSID-TEMP-DISABLED state:%d,error:%d,networkid:%d\n",*state,*error,*networkid); |
| 1177 | return; |
| 1178 | } |
| 1179 | else |
| 1180 | { |
| 1181 | *error = LYNQ_UNSPECIFIED_REASON; |
| 1182 | *state = LYNQ_WIFI_STA_STATUS_CONNECT_FAIL; |
| 1183 | return; |
| 1184 | } |
| 1185 | } |
| 1186 | if (strstr(modify, "CTRL-EVENT-ASSOC-REJECT") != NULL) |
| 1187 | { |
| 1188 | wpanetid = strstr(modify,"id="); |
| 1189 | if ( wpanetid != NULL ) |
| 1190 | { |
| 1191 | wpanetid +=strlen("id="); |
| 1192 | if (memcpy(destid,wpanetid,2) != NULL) |
| 1193 | { |
| 1194 | *networkid = atoi(destid); |
| 1195 | RLOGD("get networkid is %d\n",*networkid); |
| 1196 | } |
| 1197 | } |
| 1198 | RLOGD("FIND CTRL EVENT : CTRL-EVENT-ASSOC-REJECT\n"); |
| 1199 | pReason = strstr(modify, "status_code="); |
| 1200 | if (pReason != NULL) |
| 1201 | { |
| 1202 | pReason += strlen("status_code="); |
| 1203 | if (memcmp(pReason, "17", 2) == 0) |
| 1204 | { |
| 1205 | *error = LYNQ_AP_UNABLE_HANDLE; |
| 1206 | } |
| 1207 | else if (memcmp(pReason, "1",1) == 0) |
| 1208 | { |
| 1209 | *error = LYNQ_UNSPECIFIED_REASON; |
| 1210 | } |
| 1211 | else |
| 1212 | { |
| 1213 | *error = LYNQ_UNSPECIFIED_REASON; |
| 1214 | } |
| 1215 | *state = LYNQ_WIFI_STA_STATUS_DISCONNECT; |
| 1216 | RLOGD("CTRL-EVENT-ASSOC-REJECT BUT NOT STATUS_CODE NOT 1 or 17 state:%d,error:%d,networkid:%d\n",*state,*error,*networkid); |
| 1217 | return; |
| 1218 | } |
| 1219 | else |
| 1220 | { |
| 1221 | RLOGD("FIND CTRL EVENT : CTRL-EVENT-ASSOC-REJECT BUT NOT FOUND STATUS_CODE\n"); |
| 1222 | *error = LYNQ_UNSPECIFIED_REASON; |
| 1223 | *state = LYNQ_WIFI_STA_STATUS_DISCONNECT; |
qs.xiong | 44fac67 | 2023-08-29 16:15:55 +0800 | [diff] [blame] | 1224 | RLOGD("CTRL-EVENT-ASSOC-REJECT state:%d,error:%d,networkid:%d\n",*state,*error,*networkid); |
qs.xiong | fcc914b | 2023-07-06 21:16:20 +0800 | [diff] [blame] | 1225 | return; |
| 1226 | } |
| 1227 | } |
| 1228 | if (strstr(modify, "CTRL-EVENT-SAE-UNKNOWN-PASSWORD-IDENTIFIER") != NULL) |
| 1229 | { |
| 1230 | RLOGD("FIND CTRL EVENT : CTRL-EVENT-SAE-UNKNOWN-PASSWORD-IDENTIFIER\n"); |
| 1231 | *error = LYNQ_AUTHENTICATION_NO_LONGER_VALID; |
| 1232 | *state = LYNQ_WIFI_STA_STATUS_DISCONNECT; |
| 1233 | RLOGD("CTRL-EVENT-SAE-UNKNOWN-PASSWORD-IDENTIFIER state:%d,error:%d,networkid:%d\n",*state,*error,*networkid); |
| 1234 | return; |
| 1235 | } |
| 1236 | if (strstr(modify, "CTRL-EVENT-DISCONNECTED") != NULL) |
| 1237 | { |
| 1238 | RLOGD("FIND CTRL EVENT : CTRL-EVENT-DISCONNECTED\n"); |
| 1239 | *error = LYNQ_WAIT_CONNECT_ACTIVE; |
| 1240 | *state = LYNQ_WIFI_STA_STATUS_DISCONNECT; |
| 1241 | RLOGD("CTRL-EVENT-DISCONNECTED state:%d,error:%d,networkid:%d\n",*state,*error,*networkid); |
| 1242 | return; |
| 1243 | } |
| 1244 | RLOGD("EVENT : %s\n", modify); |
| 1245 | *error = LYNQ_UNSPECIFIED_REASON; |
| 1246 | *state = LYNQ_WIFI_STATUS_EGNORE; |
| 1247 | RLOGD("LAST : STA state:%d,error:%d,network:%d\n",*state,*error,*networkid); |
| 1248 | return; |
| 1249 | } |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 1250 | static void notify_connect_status(lynq_wifi_sta_status_s state, error_number_s error) |
| 1251 | { |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 1252 | pthread_mutex_lock(&s_sta_callback_mutex); |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 1253 | if (g_sta_callback_func != NULL && state != LYNQ_WIFI_STATUS_EGNORE) |
| 1254 | { |
| 1255 | RLOGD("STAWatcherThreadProc callback begin ------> %d %d\n", state, error); |
| 1256 | g_sta_callback_func(g_sta_callback_priv, state, error); |
| 1257 | RLOGD("STAWatcherThreadProc callback end ------> %d %d\n", state, error); |
| 1258 | } |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 1259 | pthread_mutex_unlock(&s_sta_callback_mutex); |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 1260 | } |
qs.xiong | fcc914b | 2023-07-06 21:16:20 +0800 | [diff] [blame] | 1261 | static void notify_auto_connect_status(lynq_wifi_sta_status_s state, error_number_s error,int networkid) |
| 1262 | { |
| 1263 | pthread_mutex_lock(&s_sta_callback_mutex); |
| 1264 | if (g_sta_callback_func != NULL && state != LYNQ_WIFI_STATUS_EGNORE) |
| 1265 | { |
| 1266 | RLOGD("STAWatcherThreadProc callback begin ------> %d %d %d\n", state, error,networkid); |
| 1267 | g_sta_auto_callback_func(g_sta_auto_callback_priv, state, error,networkid); |
| 1268 | RLOGD("STAAutoWatcherThreadProc callback end ------> %d %d %d\n", state, error,networkid); |
| 1269 | } |
| 1270 | pthread_mutex_unlock(&s_sta_callback_mutex); |
| 1271 | } |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 1272 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1273 | static void STAWatcherThreadProc() { |
| 1274 | size_t len = MAX_RET; |
| 1275 | char msg_notify[MAX_RET]; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1276 | error_number_s error; |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 1277 | lynq_wifi_sta_status_s state, last_state = -1; |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 1278 | int idle_count = 0; |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1279 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1280 | struct wpa_ctrl *lynq_wpa_ctrl = NULL; |
you.chen | 92fd5d3 | 2022-05-25 10:09:47 +0800 | [diff] [blame] | 1281 | g_sta_watcher_stop_flag = 0; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1282 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 1283 | RLOGD("STAWatcherThreadProc thread started ------"); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1284 | while (g_sta_watcher_stop_flag == 0) |
| 1285 | { |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 1286 | 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] | 1287 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1288 | continue; |
| 1289 | } |
you.chen | f711c8a | 2023-04-13 13:49:45 +0800 | [diff] [blame] | 1290 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1291 | memset(msg_notify, 0, MAX_RET); |
| 1292 | len = MAX_RET; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1293 | if (!wpa_ctrl_recv(lynq_wpa_ctrl, msg_notify, &len)) |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 1294 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1295 | msg_notify[len+1] = '\0'; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1296 | RLOGD("STAWatcherThreadProc sta ------> %s\n", msg_notify); |
| 1297 | if (strstr(msg_notify, state_scan_result) != NULL) |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 1298 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1299 | g_sta_scan_finish_flag = 1; |
| 1300 | } |
| 1301 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1302 | if (g_sta_callback_func == NULL) |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 1303 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1304 | continue; |
| 1305 | } |
qs.xiong | 455c30b | 2023-04-12 11:40:02 +0800 | [diff] [blame] | 1306 | get_state_error(msg_notify,&state,&error); |
you.chen | 6e72416 | 2023-10-19 19:10:01 +0800 | [diff] [blame] | 1307 | // youchen@2023-10-17 add for "not notify connect fail directly" begin |
| 1308 | if (state == LYNQ_WIFI_STA_STATUS_CONNECT_FAIL) |
| 1309 | { |
| 1310 | notify_connect_status(LYNQ_WIFI_STA_STATUS_DISCONNECT, error); |
| 1311 | } |
you.chen | 0c9bee2 | 2023-10-25 13:03:14 +0800 | [diff] [blame^] | 1312 | else if (state == LYNQ_WIFI_STA_STATUS_SCAN_RESULT && |
| 1313 | s_sta_status != INNER_STA_STATUS_INIT && g_sta_conncet_status_flag != 0) |
| 1314 | { |
| 1315 | RLOGD("donot report scan result during in call connect manual"); |
| 1316 | } |
you.chen | 6e72416 | 2023-10-19 19:10:01 +0800 | [diff] [blame] | 1317 | else |
| 1318 | { |
| 1319 | notify_connect_status(state, error); |
| 1320 | } |
| 1321 | // youchen@2023-10-17 add for "not notify connect fail directly" end |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 1322 | |
| 1323 | if (state != LYNQ_WIFI_STA_STATUS_SCAN_RESULT) |
you.chen | 32cb31e | 2023-04-13 14:05:45 +0800 | [diff] [blame] | 1324 | { |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 1325 | inner_check_connect_error(msg_notify, state, error); |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 1326 | if (last_state != state) |
| 1327 | { |
| 1328 | if (state == LYNQ_WIFI_STA_STATUS_CONNECT) |
| 1329 | { |
| 1330 | system_call_v("%s %s", sta_status_change_script, "connect"); |
| 1331 | } |
| 1332 | else if (state == LYNQ_WIFI_STA_STATUS_DISCONNECT) |
| 1333 | { |
| 1334 | system_call_v("%s %s", sta_status_change_script, "disconnect"); |
| 1335 | } |
| 1336 | } |
qs.xiong | 0956040 | 2023-10-27 21:58:55 +0800 | [diff] [blame] | 1337 | |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 1338 | last_state = state; |
you.chen | 0c9bee2 | 2023-10-25 13:03:14 +0800 | [diff] [blame^] | 1339 | if (g_sta_fake_scan_finish_flag == 1) |
| 1340 | { |
| 1341 | g_sta_fake_scan_finish_flag = 0; |
| 1342 | notify_connect_status(LYNQ_WIFI_STA_STATUS_SCAN_RESULT, 0); |
| 1343 | } |
you.chen | 32cb31e | 2023-04-13 14:05:45 +0800 | [diff] [blame] | 1344 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1345 | } |
| 1346 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1347 | if (lynq_wpa_ctrl != NULL) |
| 1348 | { |
you.chen | 92fd5d3 | 2022-05-25 10:09:47 +0800 | [diff] [blame] | 1349 | wpa_ctrl_detach(lynq_wpa_ctrl); |
| 1350 | wpa_ctrl_close(lynq_wpa_ctrl); |
| 1351 | } |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1352 | } |
qs.xiong | fcc914b | 2023-07-06 21:16:20 +0800 | [diff] [blame] | 1353 | static void STAAutoWatcherThreadProc() { |
| 1354 | size_t len = MAX_RET; |
| 1355 | char msg_notify[MAX_RET]; |
| 1356 | error_number_s error; |
you.chen | 6e72416 | 2023-10-19 19:10:01 +0800 | [diff] [blame] | 1357 | lynq_wifi_sta_status_s state; |
qs.xiong | fcc914b | 2023-07-06 21:16:20 +0800 | [diff] [blame] | 1358 | int idle_count = 0; |
| 1359 | int networkid; |
| 1360 | struct wpa_ctrl *lynq_wpa_ctrl = NULL; |
| 1361 | g_sta_auto_watcher_stop_flag = 0; |
| 1362 | RLOGD("STAAutoWatcherThreadProc thread started ------"); |
| 1363 | while (g_sta_auto_watcher_stop_flag == 0) |
| 1364 | { |
| 1365 | if (check_pending_msg(&lynq_wpa_ctrl, CTRL_STA, &idle_count, &g_sta_auto_watcher_started_flag) != 1) |
| 1366 | { |
| 1367 | continue; |
| 1368 | } |
| 1369 | memset(msg_notify, 0, MAX_RET); |
| 1370 | len = MAX_RET; |
| 1371 | if (!wpa_ctrl_recv(lynq_wpa_ctrl, msg_notify, &len)) |
| 1372 | { |
| 1373 | msg_notify[len+1] = '\0'; |
| 1374 | RLOGD("STAAutoWatcherThreadProc sta ------> %s\n", msg_notify); |
| 1375 | if (strstr(msg_notify, state_scan_result) != NULL) |
| 1376 | { |
| 1377 | g_sta_auto_scan_finish_flag = 1; |
| 1378 | } |
| 1379 | if (g_sta_auto_callback_func == NULL) |
| 1380 | { |
| 1381 | continue; |
| 1382 | } |
| 1383 | get_state_error_networkid(msg_notify,&state,&error,&networkid); // add net state error network function |
| 1384 | notify_auto_connect_status(state, error,networkid); |
qs.xiong | fcc914b | 2023-07-06 21:16:20 +0800 | [diff] [blame] | 1385 | } |
| 1386 | } |
| 1387 | if (lynq_wpa_ctrl != NULL) |
| 1388 | { |
| 1389 | wpa_ctrl_detach(lynq_wpa_ctrl); |
| 1390 | wpa_ctrl_close(lynq_wpa_ctrl); |
| 1391 | } |
| 1392 | } |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1393 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 1394 | // this thread will not exit when lynq_wifi_disable called,to avoid dead lock,take care |
| 1395 | static void GlobalWatcherThreadProc() |
| 1396 | { |
| 1397 | int ret, connect_timeout, service_abnormal; |
| 1398 | error_number_s error_num = -1; |
| 1399 | inner_sta_status_s sta_status; |
| 1400 | scan_info_s *scan_list = NULL; |
| 1401 | int i, scan_len=0; |
| 1402 | char connecting_ssid[64]; |
| 1403 | struct timeval now; |
| 1404 | |
| 1405 | RLOGD("GlobalWatcherThreadProc start to run"); |
| 1406 | |
| 1407 | while (1) |
| 1408 | { |
| 1409 | pthread_mutex_lock(&s_global_check_mutex); |
| 1410 | pthread_cond_wait(&s_global_check_cond,&s_global_check_mutex); |
| 1411 | if (s_sta_status == INNER_STA_STATUS_CONNECTED) |
| 1412 | { |
| 1413 | pthread_mutex_unlock(&s_global_check_mutex); |
| 1414 | usleep(50*1000); |
| 1415 | notify_connect_status(LYNQ_WIFI_STA_STATUS_CONNECT, 0); |
| 1416 | continue; |
| 1417 | } |
| 1418 | |
| 1419 | connect_timeout = 0; |
| 1420 | service_abnormal = 0; |
| 1421 | if (s_sta_status >= INNER_STA_STATUS_CONNECTING && s_sta_status < INNER_STA_STATUS_CONNECTED) |
| 1422 | { |
| 1423 | while (1) |
| 1424 | { |
| 1425 | ret = pthread_cond_timedwait(&s_global_check_cond, &s_global_check_mutex, &s_sta_connect_timeout); |
| 1426 | if (ret == ETIME) |
| 1427 | { |
| 1428 | connect_timeout = 1; |
| 1429 | } |
| 1430 | else if (ret != 0) |
| 1431 | { |
| 1432 | gettimeofday(&now,NULL); |
| 1433 | if (now.tv_sec < s_sta_connect_timeout.tv_sec) //time not arrive |
| 1434 | { |
| 1435 | usleep(SLEEP_TIME_ON_IDLE); |
| 1436 | continue; |
| 1437 | } |
| 1438 | connect_timeout = 1; |
| 1439 | } |
| 1440 | sta_status = s_sta_status; |
| 1441 | error_num = s_sta_error_number; |
| 1442 | s_sta_status = INNER_STA_STATUS_INIT; |
| 1443 | strcpy(connecting_ssid, s_sta_current_connecting_ssid); |
| 1444 | memset(&s_sta_connect_timeout, 0, sizeof (s_sta_connect_timeout)); |
| 1445 | memset(&s_sta_current_connecting_ssid, 0, sizeof (s_sta_current_connecting_ssid)); |
| 1446 | break; |
| 1447 | } |
| 1448 | } |
| 1449 | if (s_service_invoke_timeout_cnt > 10) |
| 1450 | { |
| 1451 | service_abnormal = 1; |
| 1452 | s_service_invoke_timeout_cnt = 0; |
| 1453 | } |
| 1454 | pthread_mutex_unlock(&s_global_check_mutex); |
| 1455 | |
| 1456 | if (service_abnormal == 1) |
| 1457 | { |
| 1458 | sleep(1); |
| 1459 | RLOGE("wpa service is abnormal info app to exit"); |
| 1460 | notify_connect_status(LYNQ_WIFI_STA_SERVICE_ABNORMAL, -1); |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 1461 | |
| 1462 | inner_notify_ap_msg(LYNQ_WIFI_SERVICE_ABNORMAL); |
| 1463 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 1464 | sleep(FAKE_MAX_INT_VALUE); // wait process to exit |
| 1465 | } |
| 1466 | |
| 1467 | if (sta_status == INNER_STA_STATUS_CANCEL) |
| 1468 | { |
| 1469 | continue; |
| 1470 | } |
| 1471 | else if (sta_status == INNER_STA_STATUS_CONNECTED) |
| 1472 | { |
| 1473 | notify_connect_status(LYNQ_WIFI_STA_STATUS_CONNECT, 0); |
| 1474 | } |
| 1475 | else if (connect_timeout == 0 && error_num == LYNQ_NOT_FIND_AP) // not found ap maybe mismatch auth |
| 1476 | { |
| 1477 | if (0 == lynq_get_scan_list(0, &scan_list, &scan_len) && NULL != scan_list) // if not found, but scan result exist, maybe auth error |
| 1478 | { |
| 1479 | for(i=0; i < scan_len;i++) |
| 1480 | { |
| 1481 | if (strcmp(scan_list[i].ssid, connecting_ssid) == 0) |
| 1482 | { |
| 1483 | error_num = LYNQ_AUTH_ERROR; |
| 1484 | break; |
| 1485 | } |
| 1486 | } |
| 1487 | free(scan_list); |
| 1488 | } |
| 1489 | notify_connect_status(LYNQ_WIFI_STA_STATUS_CONNECT_FAIL, error_num); |
| 1490 | } |
| 1491 | else if (connect_timeout == 0) |
| 1492 | { |
| 1493 | notify_connect_status(LYNQ_WIFI_STA_STATUS_CONNECT_FAIL, error_num); |
| 1494 | } |
| 1495 | else // wait timeout |
| 1496 | { |
| 1497 | if (0 != lynq_get_sta_status(LYNQ_WIFI_INTERFACE_0, &sta_status)) // get status fail |
| 1498 | { |
| 1499 | ; // wpa service abnormal |
| 1500 | } |
| 1501 | else if (sta_status == LYNQ_WIFI_STA_STATUS_ENABLE) // connect ok |
| 1502 | { |
| 1503 | RLOGD("GlobalWatcherThreadProc notify connected"); |
| 1504 | notify_connect_status(LYNQ_WIFI_STA_STATUS_CONNECT, 0); |
| 1505 | } |
| 1506 | else |
| 1507 | { |
| 1508 | RLOGD("GlobalWatcherThreadProc notify timeout"); |
| 1509 | notify_connect_status(LYNQ_WIFI_STA_STATUS_CONNECT_FAIL, LYNQ_TIME_OUT); |
| 1510 | } |
| 1511 | } |
| 1512 | } // while (1) |
| 1513 | } |
| 1514 | |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1515 | int lynq_wifi_enable(void) |
| 1516 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1517 | int ret = 0; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1518 | int i; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1519 | RLOGD("enter lynq_wifi_enable"); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1520 | pthread_mutex_lock(&s_check_wpa_ctrl_mutex); |
| 1521 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1522 | if (g_lynq_wpa_ctrl[0] != NULL && g_lynq_wpa_ctrl[1] != NULL) |
| 1523 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1524 | goto out_enable; |
| 1525 | } |
| 1526 | |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 1527 | ret = system(start_wg870_service_script); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1528 | if (ret != 0) |
| 1529 | { |
| 1530 | //printf("service state %d\n", ret); |
| 1531 | RLOGE("[wifi error]service state %d",ret); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1532 | ret = -1; |
| 1533 | goto out_enable; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1534 | } |
lh | fe8da90 | 2022-10-11 18:55:36 +0800 | [diff] [blame] | 1535 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 1536 | if (g_global_watcher_pid == 0 ) // this thread will not exit when lynq_wifi_disable called,to avoid dead lock,take care |
| 1537 | { |
| 1538 | ret=pthread_create(&g_global_watcher_pid,NULL,GlobalWatcherThreadProc,NULL); |
| 1539 | if(ret<0) |
| 1540 | { |
| 1541 | RLOGE("[wifi error]creat GlobalWatcherThreadProc fail"); |
| 1542 | ret = -1; |
| 1543 | goto out_enable; |
| 1544 | } |
| 1545 | } |
| 1546 | |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1547 | g_lynq_wpa_ctrl[0] = malloc(sizeof (struct local_wpa_ctrl)); |
| 1548 | g_lynq_wpa_ctrl[1] = malloc(sizeof (struct local_wpa_ctrl)); |
| 1549 | memset(g_lynq_wpa_ctrl[0], 0 , sizeof(struct local_wpa_ctrl)); |
| 1550 | memset(g_lynq_wpa_ctrl[1], 0 , sizeof(struct local_wpa_ctrl)); |
| 1551 | out_enable: |
| 1552 | pthread_mutex_unlock(&s_check_wpa_ctrl_mutex); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1553 | return ret; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1554 | } |
| 1555 | |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1556 | int lynq_wifi_disable(void) |
| 1557 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1558 | RLOGD("enter lynq_wifi_disable"); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1559 | pthread_mutex_lock(&s_check_wpa_ctrl_mutex); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1560 | g_ap_watcher_stop_flag = 1; |
| 1561 | g_sta_watcher_stop_flag = 1; |
qs.xiong | fcc914b | 2023-07-06 21:16:20 +0800 | [diff] [blame] | 1562 | g_sta_auto_watcher_stop_flag = 1; |
qs.xiong | 44fac67 | 2023-08-29 16:15:55 +0800 | [diff] [blame] | 1563 | g_ap_tmp_watcher_stop_flag = 1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1564 | if (g_ap_watcher_pid != 0) |
| 1565 | pthread_join(g_ap_watcher_pid, NULL); |
| 1566 | if (g_sta_watcher_pid != 0) |
| 1567 | pthread_join(g_sta_watcher_pid, NULL); |
qs.xiong | fcc914b | 2023-07-06 21:16:20 +0800 | [diff] [blame] | 1568 | if (g_sta_auto_watcher_pid != 0) |
| 1569 | pthread_join(g_sta_auto_watcher_pid, NULL); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1570 | if (g_lynq_wpa_ctrl[0] != NULL) |
| 1571 | wpa_ctrl_close(g_lynq_wpa_ctrl[0]); |
| 1572 | if (g_lynq_wpa_ctrl[1] != NULL) |
| 1573 | wpa_ctrl_close(g_lynq_wpa_ctrl[1]); |
qs.xiong | 44fac67 | 2023-08-29 16:15:55 +0800 | [diff] [blame] | 1574 | if (g_ap_tmp_watcher_pid != 0) |
| 1575 | pthread_join(g_ap_tmp_watcher_pid, NULL); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1576 | g_ap_watcher_pid = 0; |
| 1577 | g_sta_watcher_pid = 0; |
qs.xiong | fcc914b | 2023-07-06 21:16:20 +0800 | [diff] [blame] | 1578 | g_sta_auto_watcher_pid = 0; |
qs.xiong | 08e6aac | 2023-09-06 23:12:27 +0800 | [diff] [blame] | 1579 | g_ap_tmp_watcher_pid = 0; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1580 | g_lynq_wpa_ctrl[0] = NULL; |
| 1581 | g_lynq_wpa_ctrl[1] = NULL; |
qs.xiong | b37f8c4 | 2023-09-13 21:21:58 +0800 | [diff] [blame] | 1582 | g_history_disconnect_valid_num = 0; //clean history_disconenct_list info |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1583 | system("systemctl stop wg870_drv_insmod.service"); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1584 | pthread_mutex_unlock(&s_check_wpa_ctrl_mutex); |
| 1585 | return 0; |
| 1586 | } |
| 1587 | |
| 1588 | static inline char inner_convert_char(char in) |
| 1589 | { |
| 1590 | if (in >= '0' && in <= '9') |
| 1591 | { |
| 1592 | return in - '0'; |
| 1593 | } |
| 1594 | else if (in >= 'a' && in <= 'f') |
| 1595 | { |
| 1596 | return in - 'a' + 10; |
| 1597 | } |
| 1598 | else if (in >= 'A' && in <= 'F') |
| 1599 | { |
| 1600 | return in - 'A' + 10; |
| 1601 | } |
| 1602 | else |
| 1603 | { |
| 1604 | return '\xff'; |
| 1605 | } |
| 1606 | } |
| 1607 | |
| 1608 | static inline void inner_copy_ssid(char * out_ssid, const char * ssid, size_t out_ssid_len) |
| 1609 | { |
| 1610 | char *p; |
| 1611 | size_t pos = 0; |
| 1612 | if (NULL == out_ssid) |
| 1613 | return; |
| 1614 | //printf("input ssid=[%s]\n", ssid); |
| 1615 | memset(out_ssid, 0, out_ssid_len); |
| 1616 | if (NULL == ssid) |
| 1617 | return; |
| 1618 | p = strchr(ssid, '\\'); |
| 1619 | if (NULL == p) |
| 1620 | { |
| 1621 | strncpy(out_ssid, ssid, out_ssid_len); |
| 1622 | //printf(" first %s\n", out_ssid); |
| 1623 | } |
| 1624 | else |
| 1625 | { |
| 1626 | pos = p - ssid; |
| 1627 | memcpy(out_ssid, ssid, pos); |
| 1628 | //printf("pos %lu -- %s\n", pos, out_ssid); |
| 1629 | for(; pos < out_ssid_len; pos ++) |
| 1630 | { |
| 1631 | if (p[0] == '\0') |
| 1632 | { |
| 1633 | //printf(" out %s\n", out_ssid); |
| 1634 | return; |
| 1635 | } |
| 1636 | else if (p[0] != '\\') |
| 1637 | { |
| 1638 | out_ssid[pos] = p[0]; |
| 1639 | p += 1; |
| 1640 | } |
| 1641 | else if (p[1] == 'x' || p[1] == 'X') |
| 1642 | { |
| 1643 | out_ssid[pos] = inner_convert_char(p[2]) << 4 | inner_convert_char(p[3]); |
| 1644 | p += 4; |
| 1645 | } |
| 1646 | else if (p[1] == '\\') |
| 1647 | { |
| 1648 | out_ssid[pos] = '\\'; |
| 1649 | p += 2; |
| 1650 | } |
| 1651 | else if (p[1] == 't') |
| 1652 | { |
| 1653 | out_ssid[pos] = '\t'; |
| 1654 | p += 2; |
| 1655 | } |
| 1656 | else if (p[1] == 'r') |
| 1657 | { |
| 1658 | out_ssid[pos] = '\r'; |
| 1659 | p += 2; |
| 1660 | } |
| 1661 | else if (p[1] == 'n') |
| 1662 | { |
| 1663 | out_ssid[pos] = '\n'; |
| 1664 | p += 2; |
| 1665 | }//todo find a better way to convert? |
| 1666 | } |
| 1667 | } |
| 1668 | //printf(" out %s\n", out_ssid); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1669 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1670 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1671 | 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] | 1672 | int i, ssid_len; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1673 | char lynq_cmd_get[128]={0}; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1674 | RLOGD("enter inner_get_param"); |
| 1675 | if (out_put == NULL) |
| 1676 | { |
| 1677 | RLOGE("output ptr is null"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1678 | return -1; |
| 1679 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1680 | if (param_name == NULL) |
| 1681 | { |
| 1682 | RLOGE("param ptr is null"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1683 | return -1; |
| 1684 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1685 | if (param_name[0] == '\0') |
| 1686 | { |
| 1687 | RLOGE("param is empty"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1688 | return -1; |
| 1689 | } |
| 1690 | |
| 1691 | sprintf(lynq_cmd_get, "GET_NETWORK %d %s", net_no, param_name); |
| 1692 | |
| 1693 | CHECK_WPA_CTRL(interface); |
| 1694 | |
| 1695 | DO_REQUEST(lynq_cmd_get); |
| 1696 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1697 | if (memcmp(cmd_reply, "FAIL", 4) == 0) |
| 1698 | { |
| 1699 | RLOGE("wpa_supplicant return cmd_reply is FAIL"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1700 | return -1; |
| 1701 | } |
| 1702 | |
you.chen | a6fa5b2 | 2022-05-18 10:28:19 +0800 | [diff] [blame] | 1703 | // printf("reply len %d, %08x\n", reply_len, (int)out_put); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1704 | if (strcmp(param_name, "ssid") == 0) |
| 1705 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1706 | if (cmd_reply[0] == '\"') |
| 1707 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1708 | ssid_len = reply_len - 1; |
| 1709 | memcpy(out_put, cmd_reply + 1, ssid_len); |
| 1710 | if (out_put[ssid_len-1] == '\"') |
| 1711 | { |
| 1712 | out_put[ssid_len-1] = '\0'; |
| 1713 | } |
| 1714 | else |
| 1715 | { |
| 1716 | out_put[ssid_len] = '\0'; |
| 1717 | } |
| 1718 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1719 | else |
| 1720 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1721 | ssid_len = reply_len / 2; |
| 1722 | for(i=0; i<ssid_len; i++) |
| 1723 | { |
| 1724 | out_put[i] = inner_convert_char(cmd_reply[i*2]) << 4 | inner_convert_char(cmd_reply[i*2 + 1]); |
| 1725 | } |
| 1726 | out_put[ssid_len] = '\0'; |
| 1727 | } |
| 1728 | } |
| 1729 | else |
| 1730 | { |
| 1731 | memcpy(out_put, cmd_reply, reply_len + 1); |
| 1732 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1733 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1734 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1735 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1736 | static int lynq_split(char * str, int len, char delimiter, char * results[]) { |
| 1737 | int ret = 0; |
| 1738 | char * end = str + len - 1; |
| 1739 | results[ret++] = str; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1740 | while(str < end) |
| 1741 | { |
| 1742 | if (*str == delimiter) |
| 1743 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1744 | *str++ = '\0'; |
| 1745 | results[ret++] = str; |
| 1746 | continue; |
| 1747 | } |
| 1748 | str++; |
| 1749 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1750 | if (*str == delimiter) |
| 1751 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1752 | *str = '\0'; |
| 1753 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1754 | |
you.chen | 6ed36a6 | 2023-04-27 17:51:56 +0800 | [diff] [blame] | 1755 | results[ret] = NULL; |
| 1756 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1757 | return ret; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1758 | } |
| 1759 | |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1760 | static int inner_get_ip_by_mac(const char * mac, char * ip, int ip_len) |
| 1761 | { |
| 1762 | char * p; |
| 1763 | int ret = 0; |
| 1764 | char cmd[256]={0}; |
| 1765 | if (NULL == mac || NULL == ip) |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1766 | return -1; |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1767 | memset(ip, 0, ip_len); |
qs.xiong | 0897143 | 2023-07-05 19:17:34 +0800 | [diff] [blame] | 1768 | sprintf(cmd, "ip n s | grep \"lladdr\" | grep \"%s\" | awk '{print $1}' | grep -v \":\" | head -1", mac); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1769 | ret = exec_cmd(cmd, ip, ip_len); |
| 1770 | p = strchr(ip, '\n'); |
| 1771 | if (NULL != p) |
| 1772 | { |
| 1773 | *p = '\0'; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1774 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1775 | RLOGD("inner_get_ip_by_mac %s\n", ip); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1776 | return ret; |
| 1777 | } |
| 1778 | |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1779 | static int inner_get_hostname_by_ip(char *ip, char *hostname) { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1780 | struct in_addr addr ={0}; |
| 1781 | struct hostent *ht; |
you.chen | 186d3c3 | 2023-05-18 14:19:46 +0800 | [diff] [blame] | 1782 | char cmd[64] = {0}; |
| 1783 | char * p; |
| 1784 | int ret; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1785 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1786 | if (ip == NULL || *ip == '\0' || hostname == NULL) |
| 1787 | { |
| 1788 | RLOGE("ip == NULL or hostname == NULL"); |
| 1789 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1790 | } |
| 1791 | |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1792 | *hostname = '\0'; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1793 | if (inet_aton(ip, &addr) == 0) |
| 1794 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1795 | printf("---inet_aton fail\n"); |
| 1796 | return -1; |
| 1797 | } |
| 1798 | |
| 1799 | ht = gethostbyaddr(&addr, sizeof(struct in_addr), AF_INET); |
| 1800 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1801 | if (ht == NULL) |
| 1802 | { |
you.chen | 186d3c3 | 2023-05-18 14:19:46 +0800 | [diff] [blame] | 1803 | hostname[0] = '\0'; |
| 1804 | sprintf(cmd, "grep -F '%s' /run/wg870/ap0.lease | awk '{print $4}' | tail -1", ip); |
| 1805 | ret = exec_cmd(cmd, hostname, 32); |
| 1806 | if (ret == 0) |
| 1807 | { |
| 1808 | p = strchr(hostname, '\n'); |
| 1809 | if (p != NULL) |
| 1810 | { |
| 1811 | *p = '\0'; |
| 1812 | } |
| 1813 | return 0; |
| 1814 | } |
| 1815 | hostname[0] = '\0'; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1816 | RLOGE("---gethostbyaddr fail\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1817 | herror(NULL); |
| 1818 | return -1; |
| 1819 | } |
| 1820 | |
| 1821 | strcpy(hostname, ht->h_name); |
| 1822 | |
| 1823 | return 0; |
| 1824 | } |
| 1825 | |
| 1826 | static int lynq_get_network_number_list(lynq_wifi_index_e idx, int ap_sta, int net_no_list[], char * ssid) |
| 1827 | { |
| 1828 | int count, index, words_count; |
| 1829 | char * split_lines[128]= {0}; |
| 1830 | char * split_words[128] = {0}; |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1831 | char local_ssid[128] = {0}; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1832 | const char *lynq_wifi_list_networks = "LIST_NETWORKS"; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1833 | 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] | 1834 | |
| 1835 | CHECK_WPA_CTRL(ap_sta); |
| 1836 | |
| 1837 | DO_REQUEST(lynq_wifi_list_networks); |
| 1838 | |
| 1839 | count = lynq_split(cmd_reply, reply_len, '\n', split_lines); |
| 1840 | |
| 1841 | //@todo check ssid field to compatible |
| 1842 | |
| 1843 | ret = 0; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1844 | for(index=1; index < count; index++) |
| 1845 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1846 | 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] | 1847 | if (words_count > 2) |
| 1848 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1849 | inner_copy_ssid(local_ssid, split_words[1], sizeof (local_ssid)); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1850 | if (ssid == NULL || strcmp(local_ssid, ssid) == 0) |
| 1851 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1852 | net_no_list[ret++] = atoi(split_words[0]); |
| 1853 | } |
| 1854 | } |
| 1855 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1856 | 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] | 1857 | return ret; |
| 1858 | } |
| 1859 | |
| 1860 | static int lynq_add_network(int ap_sta) { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 1861 | size_t i=0; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1862 | CHECK_WPA_CTRL(ap_sta); |
| 1863 | const char *lynq_wifi_add_network = "ADD_NETWORK"; |
| 1864 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1865 | RLOGD("[lynq_add_network] enter lynq_add_network"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1866 | DO_REQUEST(lynq_wifi_add_network); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1867 | if (memcmp(cmd_reply, "FAIL", 4) == 0) |
| 1868 | { |
| 1869 | RLOGE("[wifi error]lynq_add_network cmd_reply FAIL"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1870 | return -1; |
| 1871 | } |
| 1872 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1873 | for(i=0;i<reply_len;i++) |
| 1874 | { |
| 1875 | if(cmd_reply[i] == '\n') |
| 1876 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1877 | cmd_reply[i] = '\0'; |
| 1878 | break; |
| 1879 | } |
| 1880 | } |
| 1881 | return atoi(cmd_reply); |
| 1882 | } |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 1883 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1884 | static int lynq_check_network_number(lynq_wifi_index_e idx, int ap_sta, int net_no) |
| 1885 | { |
| 1886 | int count, index; |
| 1887 | int net_no_list[128]; |
| 1888 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1889 | RLOGD("[lynq_check_network_number] enter lynq_check_network_number api"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1890 | 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] | 1891 | for (index=0; index < count; index++) |
| 1892 | { |
| 1893 | if (net_no_list[index] == net_no) |
| 1894 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1895 | return 0; |
| 1896 | } |
| 1897 | } |
| 1898 | |
| 1899 | if (count >= 1) |
| 1900 | index = net_no_list[count - 1]; |
| 1901 | else |
| 1902 | index = -1; |
| 1903 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1904 | while (index < net_no ) |
| 1905 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1906 | index = lynq_add_network(ap_sta); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1907 | if (index >= net_no) |
| 1908 | { // required network no created |
| 1909 | RLOGD("required network no created\n");; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1910 | return 0; |
| 1911 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1912 | else if( index < 0) |
| 1913 | { |
| 1914 | RLOGE("[lynq_check_network_number] add network fail"); |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 1915 | return -1; |
| 1916 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1917 | } |
| 1918 | |
| 1919 | if (index < 0) |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1920 | { |
| 1921 | RLOGE("[lynq_check_network_number] network index < 0"); |
| 1922 | return -1; |
| 1923 | } |
| 1924 | RLOGD("[lynq_check_network_number] work finished &state is ok"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1925 | return 0; |
| 1926 | } |
| 1927 | |
| 1928 | static lynq_wifi_band_m convert_band_from_freq(int freq) { //@todo |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1929 | if (freq > 5000 && freq < 6000) |
| 1930 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1931 | return LYNQ_WIFI_5G_band; |
| 1932 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1933 | else if (freq > 2000 && freq < 3000) |
| 1934 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1935 | return LYNQ_WIFI_2G_band; |
| 1936 | } |
| 1937 | return LYNQ_WIFI_2_and_5G_band; |
| 1938 | } |
| 1939 | |
| 1940 | 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] | 1941 | if (key_mgmt != NULL) |
| 1942 | { |
| 1943 | if (memcmp( key_mgmt, "NONE", 4) == 0) |
| 1944 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1945 | return LYNQ_WIFI_AUTH_OPEN; |
| 1946 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1947 | else if (memcmp( key_mgmt, "WEP", 3) == 0) |
| 1948 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1949 | return LYNQ_WIFI_AUTH_WEP; |
| 1950 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1951 | else if (memcmp( key_mgmt, "WPA-PSK", 7) == 0) |
| 1952 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1953 | return LYNQ_WIFI_AUTH_WPA_PSK; |
| 1954 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1955 | else if (memcmp( key_mgmt, "WPA2-PSK", 8) == 0) |
| 1956 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1957 | return LYNQ_WIFI_AUTH_WPA2_PSK; |
| 1958 | } |
| 1959 | } |
| 1960 | |
| 1961 | return -1; |
| 1962 | } |
| 1963 | |
| 1964 | static lynq_wifi_auth_s convert_max_auth_from_flag(char * flag) { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1965 | if (flag != NULL) |
| 1966 | { |
qs.xiong | ba01e1f | 2023-09-06 14:14:32 +0800 | [diff] [blame] | 1967 | if ( strstr(flag,"WPA2-PSK+SAE-CCMP") != NULL || strstr(flag, "SHA256") != NULL || strstr(flag,"WPA2-SAE") != NULL || ( strstr(flag,"SAE-H2E") != NULL && strstr(flag,"WPS") == NULL ) ) |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 1968 | { |
| 1969 | return LYNQ_WIFI_AUTH_WPA3_PSK; |
qs.xiong | 46f4156 | 2023-07-11 21:06:47 +0800 | [diff] [blame] | 1970 | }else if ( strstr( flag,"SAE-CCMP") != NULL || strstr(flag,"SAE-H2E") != NULL ) |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 1971 | { |
| 1972 | return LYNQ_WIFI_AUTH_WPA2_WPA3_PSK; |
| 1973 | }else if (strstr( flag, "WPA2-PSK") != NULL) |
| 1974 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1975 | return LYNQ_WIFI_AUTH_WPA2_PSK; |
| 1976 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1977 | else if (strstr( flag, "WPA-PSK") != NULL) |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 1978 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1979 | return LYNQ_WIFI_AUTH_WPA_PSK; |
| 1980 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1981 | else if (strstr( flag, "WEP") != NULL) |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 1982 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1983 | return LYNQ_WIFI_AUTH_WEP; |
| 1984 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1985 | else if (strstr( flag, "NONE") != NULL) |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 1986 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1987 | return LYNQ_WIFI_AUTH_OPEN; |
| 1988 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1989 | else if (strcmp( flag, "[ESS]") == 0 || strcmp( flag,"[WPS][ESS]") == 0) |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 1990 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 1991 | return LYNQ_WIFI_AUTH_OPEN; |
| 1992 | } |
qs.xiong | 46f4156 | 2023-07-11 21:06:47 +0800 | [diff] [blame] | 1993 | else |
| 1994 | { |
| 1995 | RLOGD("convert_max_auth_from_flag not-found auth mode"); |
| 1996 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1997 | } |
| 1998 | |
| 1999 | return -1; |
| 2000 | } |
| 2001 | |
| 2002 | static lynq_wifi_bandwidth_type_m convert_bandwidth_from_bw(int bw) { |
| 2003 | switch (bw) { |
| 2004 | case 10: |
| 2005 | return LYNQ_WIFI_BANDWIDTH_HT10; |
| 2006 | break; |
| 2007 | case 20: |
| 2008 | return LYNQ_WIFI_BANDWIDTH_HT20; |
| 2009 | break; |
| 2010 | case 40: |
| 2011 | return LYNQ_WIFI_BANDWIDTH_HT40; |
| 2012 | break; |
| 2013 | case 80: |
| 2014 | return LYNQ_WIFI_BANDWIDTH_HT80; |
| 2015 | break; |
| 2016 | default: |
| 2017 | break; |
| 2018 | } |
| 2019 | |
| 2020 | return -1; |
| 2021 | } |
| 2022 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2023 | 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] | 2024 | static int inner_get_status_info(int interface, curr_status_info *curr_state) { |
| 2025 | int i, count; |
| 2026 | char *p; |
| 2027 | const char *lynq_status_cmd = "STATUS"; |
| 2028 | const char * FLAG_SSID = "ssid="; |
| 2029 | const char * FLAG_SBSID = "bssid="; |
| 2030 | const char * FLAG_KEY_MGMT = "key_mgmt="; |
| 2031 | const char * FLAG_FREQ = "freq="; |
| 2032 | const char * FLAG_STATE = "wpa_state="; |
| 2033 | const char * FLAG_ID = "id="; |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 2034 | const char * FLAG_IPADDR = "ip_address="; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2035 | char *split_lines[128] = {0}; |
| 2036 | |
| 2037 | CHECK_WPA_CTRL(interface); |
| 2038 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2039 | if (curr_state == NULL) |
| 2040 | { |
| 2041 | RLOGE("[wifi error][inner_get_status_info]curr_state is NULL"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2042 | return -1; |
| 2043 | } |
| 2044 | |
| 2045 | DO_REQUEST(lynq_status_cmd); |
| 2046 | |
| 2047 | count = lynq_split(cmd_reply, reply_len, '\n', split_lines); |
| 2048 | |
| 2049 | curr_state->net_no = -1; |
| 2050 | ret = -1; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2051 | for(i=0; i < count; i++) |
| 2052 | { |
| 2053 | if (curr_state->ap != NULL) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2054 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2055 | p = strstr(split_lines[i], FLAG_SBSID); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2056 | if (p != NULL) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2057 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 2058 | 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] | 2059 | ret = 0; |
| 2060 | continue; |
| 2061 | } |
you.chen | f58b3c9 | 2022-06-21 16:53:48 +0800 | [diff] [blame] | 2062 | p = strstr(split_lines[i], FLAG_SSID); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2063 | if (p != NULL) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2064 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 2065 | 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] | 2066 | ret = 0; |
| 2067 | continue; |
| 2068 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2069 | p = strstr(split_lines[i], FLAG_KEY_MGMT); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2070 | if (p != NULL) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2071 | { |
you.chen | 450d017 | 2022-07-15 17:56:48 +0800 | [diff] [blame] | 2072 | 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] | 2073 | 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] | 2074 | ret = 0; |
| 2075 | continue; |
| 2076 | } |
| 2077 | p = strstr(split_lines[i], FLAG_FREQ); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2078 | if (p != NULL) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2079 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2080 | curr_state->ap->band = convert_band_from_freq(atoi( p + strlen(FLAG_FREQ))); |
| 2081 | ret = 0; |
| 2082 | continue; |
| 2083 | } |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 2084 | p = strstr(split_lines[i], FLAG_IPADDR); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2085 | if (p != NULL) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2086 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 2087 | strncpy(curr_state->ap->ap_ip, p + strlen(FLAG_IPADDR), sizeof(curr_state->ap->ap_ip)); |
| 2088 | ret = 0; |
| 2089 | continue; |
| 2090 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2091 | } // end if (ap != NULL) |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2092 | if (curr_state->state != NULL) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2093 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2094 | p = strstr(split_lines[i], FLAG_STATE); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2095 | if (p != NULL) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2096 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2097 | strcpy(curr_state->state, p + strlen(FLAG_STATE)); |
| 2098 | ret = 0; |
| 2099 | continue; |
| 2100 | } |
| 2101 | |
| 2102 | } //end else if (state != NULL) |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2103 | if ((p = strstr(split_lines[i], FLAG_ID)) == split_lines[i]) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2104 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2105 | ret = 0; |
you.chen | 450d017 | 2022-07-15 17:56:48 +0800 | [diff] [blame] | 2106 | curr_state->net_no = atoi(p + strlen(FLAG_ID)); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2107 | 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] | 2108 | } |
| 2109 | } |
| 2110 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2111 | if (ret == 0 && curr_state->ap != NULL && curr_state->net_no >= 0) // auth may not right when add wpa3 |
| 2112 | { |
| 2113 | inner_get_network_auth(interface, curr_state->net_no, &curr_state->ap->auth); |
| 2114 | } |
| 2115 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2116 | return ret; |
| 2117 | } |
| 2118 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2119 | 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] | 2120 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2121 | RLOGD("enter lynq_wifi_ap_ssid_set"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2122 | char lynq_wifi_ssid_cmd[80]={0}; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2123 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2124 | if (ap_ssid == NULL) |
| 2125 | { |
| 2126 | RLOGE("Input ap_ssid is NULL"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2127 | return -1; |
| 2128 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2129 | else |
| 2130 | { |
| 2131 | 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] | 2132 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 2133 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2134 | if (lynq_check_network_number(idx, CTRL_AP, AP_NETWORK_0) != 0) |
| 2135 | { |
| 2136 | RLOGE("Do check ap network_number fail"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2137 | return -1; |
| 2138 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 2139 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2140 | CHECK_IDX(idx, CTRL_AP); |
| 2141 | |
| 2142 | CHECK_WPA_CTRL(CTRL_AP); |
| 2143 | |
| 2144 | sprintf(lynq_wifi_ssid_cmd,"SET_NETWORK %d ssid \"%s\"", AP_NETWORK_0, ap_ssid); |
| 2145 | |
| 2146 | DO_OK_FAIL_REQUEST(lynq_wifi_ssid_cmd); |
| 2147 | DO_OK_FAIL_REQUEST(cmd_save_config); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2148 | RLOGD("[lynq_wifi_ap_ssid_set] set ssid sucss"); |
| 2149 | return 0; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2150 | |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2151 | } |
| 2152 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2153 | 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] | 2154 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2155 | RLOGD("enter lynq_wifi_ap_ssid_get"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2156 | CHECK_IDX(idx, CTRL_AP); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 2157 | return inner_get_param(CTRL_AP, AP_NETWORK_0, "ssid", ap_ssid); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2158 | } |
| 2159 | |
qs.xiong | c9c79f7 | 2022-10-17 15:27:18 +0800 | [diff] [blame] | 2160 | /***** |
| 2161 | *frequency <------>channel |
| 2162 | * |
| 2163 | *frequency 1 2 3 4 5 6 7 8 9 10 11 12 13 36 40 44 48 149 153 157 161 165 |
| 2164 | * |
| 2165 | * |
| 2166 | *channel 2412,2417,2422,2427,2532,2437,2442,2447,2452,2457,2462,2467,2472,5180,5200,5220,5240,5745,5765,5785,5805,5825 |
| 2167 | * |
| 2168 | * |
| 2169 | * */ |
| 2170 | static int lynq_check_set_frequency(int input_frequency){ |
qs.xiong | c00b603 | 2022-11-29 16:28:03 +0800 | [diff] [blame] | 2171 | 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}; |
| 2172 | int i; |
| 2173 | int arr_len = sizeof(legitimate_frequency) / sizeof(int); |
| 2174 | |
qs.xiong | 69a332b | 2022-12-02 09:58:57 +0800 | [diff] [blame] | 2175 | for(i = 0; i < arr_len; i++) |
qs.xiong | c00b603 | 2022-11-29 16:28:03 +0800 | [diff] [blame] | 2176 | { |
| 2177 | if(input_frequency == legitimate_frequency[i]) |
qs.xiong | c9c79f7 | 2022-10-17 15:27:18 +0800 | [diff] [blame] | 2178 | break; |
qs.xiong | c9c79f7 | 2022-10-17 15:27:18 +0800 | [diff] [blame] | 2179 | } |
qs.xiong | c00b603 | 2022-11-29 16:28:03 +0800 | [diff] [blame] | 2180 | |
| 2181 | if(i == arr_len) |
| 2182 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2183 | 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] | 2184 | return -1; |
| 2185 | } |
qs.xiong | c00b603 | 2022-11-29 16:28:03 +0800 | [diff] [blame] | 2186 | |
qs.xiong | c9c79f7 | 2022-10-17 15:27:18 +0800 | [diff] [blame] | 2187 | return 0; |
| 2188 | } |
qs.xiong | 1367346 | 2023-02-21 19:12:54 +0800 | [diff] [blame] | 2189 | |
| 2190 | static int lynq_check_frequencyby_country_code(int input_frequency) |
| 2191 | { |
| 2192 | char str_cnc[]="CN"; |
| 2193 | char str_dest[20]=""; |
| 2194 | |
| 2195 | if( lynq_get_country_code(1,str_dest) != 0 ) |
| 2196 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2197 | RLOGE("get country_code error\n"); |
qs.xiong | 1367346 | 2023-02-21 19:12:54 +0800 | [diff] [blame] | 2198 | return -1; |
| 2199 | } |
| 2200 | if( strncmp(str_dest,str_cnc,2) != 0 ) |
| 2201 | { |
| 2202 | return 0; |
| 2203 | }else if( 2473 < input_frequency && input_frequency < 5744) |
| 2204 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2205 | RLOGE("input frequency is bad\n"); |
qs.xiong | 1367346 | 2023-02-21 19:12:54 +0800 | [diff] [blame] | 2206 | return -1; |
| 2207 | } |
| 2208 | return 0; |
| 2209 | } |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2210 | 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] | 2211 | { |
qs.xiong | c00b603 | 2022-11-29 16:28:03 +0800 | [diff] [blame] | 2212 | int check; |
qs.xiong | c9c79f7 | 2022-10-17 15:27:18 +0800 | [diff] [blame] | 2213 | char lynq_wifi_frequency_cmd[128]={0}; |
| 2214 | char lynq_cmd_mode[128]={0}; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2215 | char lynq_cmd_slect[128]={0}; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2216 | 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] | 2217 | //@do check input frequency |
qs.xiong | c00b603 | 2022-11-29 16:28:03 +0800 | [diff] [blame] | 2218 | check = lynq_check_set_frequency(lynq_wifi_frequency); |
| 2219 | if(check != 0) |
| 2220 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2221 | RLOGE("do check frequency error"); |
qs.xiong | c9c79f7 | 2022-10-17 15:27:18 +0800 | [diff] [blame] | 2222 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2223 | } |
qs.xiong | 1367346 | 2023-02-21 19:12:54 +0800 | [diff] [blame] | 2224 | check = lynq_check_frequencyby_country_code(lynq_wifi_frequency); |
| 2225 | if(check != 0) |
| 2226 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2227 | RLOGE("do check frequency error"); |
qs.xiong | 1367346 | 2023-02-21 19:12:54 +0800 | [diff] [blame] | 2228 | return -1; |
| 2229 | } |
| 2230 | |
qs.xiong | c00b603 | 2022-11-29 16:28:03 +0800 | [diff] [blame] | 2231 | if (lynq_check_network_number(idx, CTRL_AP, AP_NETWORK_0) != 0) |
| 2232 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2233 | RLOGE("[set ap frequecny][lynq_check_network_number] error"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2234 | return -1; |
| 2235 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 2236 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2237 | CHECK_IDX(idx, CTRL_AP); |
| 2238 | |
| 2239 | CHECK_WPA_CTRL(CTRL_AP); |
| 2240 | |
| 2241 | sprintf(lynq_wifi_frequency_cmd,"SET_NETWORK %d frequency %d", AP_NETWORK_0, lynq_wifi_frequency); |
| 2242 | sprintf(lynq_cmd_mode, "SET_NETWORK %d mode 2", AP_NETWORK_0); |
| 2243 | sprintf(lynq_cmd_slect, "SELECT_NETWORK %d", AP_NETWORK_0); |
| 2244 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2245 | DO_OK_FAIL_REQUEST(cmd_disconnect); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2246 | DO_OK_FAIL_REQUEST(lynq_wifi_frequency_cmd); |
| 2247 | DO_OK_FAIL_REQUEST(lynq_cmd_mode); |
| 2248 | DO_OK_FAIL_REQUEST(cmd_save_config); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2249 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2250 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2251 | } |
| 2252 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2253 | 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] | 2254 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2255 | char lynq_frequency_str[MAX_RET] = {0}; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2256 | 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] | 2257 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2258 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2259 | if (inner_get_param(CTRL_AP, AP_NETWORK_0, "frequency", lynq_frequency_str) != 0) |
| 2260 | { |
| 2261 | 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] | 2262 | return -1; |
| 2263 | } |
| 2264 | *lynq_wifi_frequency = atoi(lynq_frequency_str); |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2265 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2266 | return 0; |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2267 | } |
| 2268 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2269 | int lynq_wifi_ap_bandwidth_set(lynq_wifi_index_e idx,lynq_wifi_bandwidth_type_m bandwidth) |
| 2270 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2271 | RLOGD("enter lynq_wifi_ap_bandwidth_set"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2272 | CHECK_IDX(idx, CTRL_AP); |
| 2273 | switch(bandwidth){ |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2274 | case LYNQ_WIFI_BANDWIDTH_HT10: |
| 2275 | { |
| 2276 | RLOGE("bandwith [%d] not support now\n", bandwidth); |
| 2277 | return -1; |
| 2278 | } |
| 2279 | case LYNQ_WIFI_BANDWIDTH_HT20: |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2280 | { |
| 2281 | char lynq_cmd_bandwith[MAX_CMD]="wl chanspec 6"; |
| 2282 | system("wl down"); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2283 | if (system(lynq_cmd_bandwith) != 0 ) |
| 2284 | { |
| 2285 | RLOGE("lynq_wifi_ap_bandwidth_set erro"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2286 | return -1; |
| 2287 | } |
| 2288 | system("wl up"); |
| 2289 | break; |
| 2290 | } |
| 2291 | case LYNQ_WIFI_BANDWIDTH_HT40: |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2292 | { |
qs.xiong | 1037919 | 2023-02-21 13:19:42 +0800 | [diff] [blame] | 2293 | char lynq_cmd_bandwith[MAX_CMD]="wl chanspec 149/40"; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2294 | sprintf(lynq_cmd_bandwith, "wl chanspec "); |
| 2295 | system("wl down"); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2296 | if (system(lynq_cmd_bandwith) != 0 ) |
| 2297 | { |
| 2298 | RLOGE("lynq_wifi_ap_bandwidth_set erro"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2299 | return -1; |
| 2300 | } |
| 2301 | system("wl up"); |
| 2302 | break; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2303 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2304 | case LYNQ_WIFI_BANDWIDTH_HT80: |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2305 | { |
qs.xiong | 1037919 | 2023-02-21 13:19:42 +0800 | [diff] [blame] | 2306 | char lynq_cmd_bandwith[MAX_CMD]="wl chanspec 149/80"; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2307 | system("wl down"); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2308 | if (system(lynq_cmd_bandwith) != 0 ) |
| 2309 | { |
| 2310 | RLOGE("lynq_wifi_ap_bandwidth_set erro"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2311 | return -1; |
| 2312 | } |
| 2313 | system("wl up"); |
| 2314 | break; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2315 | } |
| 2316 | default: |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2317 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2318 | RLOGE("auth type [%d] not support now\n", bandwidth); |
| 2319 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2320 | } |
| 2321 | } |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2322 | |
| 2323 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2324 | return 0; |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2325 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2326 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2327 | int lynq_wifi_ap_bandwidth_get(lynq_wifi_index_e idx,lynq_wifi_bandwidth_type_m* bandwidth) |
| 2328 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2329 | int count = 0; |
| 2330 | int index = 0; |
| 2331 | char *split_words[128] = {0}; |
| 2332 | const char *lynq_chanspec_cmd = "DRIVER chanspec\n"; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2333 | RLOGD("enter lynq_wifi_ap_bandwidth_get"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2334 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2335 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2336 | CHECK_WPA_CTRL(CTRL_AP); |
| 2337 | |
| 2338 | DO_REQUEST(lynq_chanspec_cmd); |
| 2339 | |
| 2340 | count = lynq_split(cmd_reply, reply_len, ' ', split_words); |
| 2341 | for(;index < count; index++) { |
| 2342 | if (strncmp(split_words[index], "bw", 2) != 0) { |
| 2343 | continue; |
| 2344 | } |
| 2345 | |
| 2346 | index++; |
| 2347 | if (index >= count) { |
| 2348 | return -1; |
| 2349 | } |
| 2350 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2351 | RLOGD("bw %s\n", split_words[index]); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2352 | *bandwidth = convert_bandwidth_from_bw(atoi(split_words[index])); |
| 2353 | return 0; |
| 2354 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2355 | RLOGE("[wifi error]lynq_wifi_ap_bandwidth_get"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2356 | return -1; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2357 | } |
qs.xiong | 0fb469a | 2022-04-14 03:50:45 -0400 | [diff] [blame] | 2358 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2359 | 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] | 2360 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2361 | char lynq_cmd_channel[MAX_CMD]={0}; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2362 | 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] | 2363 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 1d58e9b | 2022-04-14 06:17:01 -0400 | [diff] [blame] | 2364 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2365 | sprintf(lynq_cmd_channel, "wl channel %d", channel); |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 2366 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2367 | if (lynq_check_network_number(idx, CTRL_AP, AP_NETWORK_0) != 0) |
| 2368 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2369 | return -1; |
| 2370 | } |
| 2371 | |
| 2372 | system("wl down"); |
| 2373 | if (system(lynq_cmd_channel) != 0 ){ |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2374 | RLOGE("lynq_wifi_ap_channel_set erro"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2375 | return -1; |
| 2376 | } |
| 2377 | system("wl up"); |
| 2378 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2379 | } |
qs.xiong | 0fb469a | 2022-04-14 03:50:45 -0400 | [diff] [blame] | 2380 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2381 | 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] | 2382 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2383 | int count = 0; |
| 2384 | int index = 0; |
| 2385 | char *split_words[128] = {0}; |
| 2386 | char lynq_chanspec_cmd[]="DRIVER chanspec\n"; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2387 | RLOGD("enter lynq_wifi_ap_channel_get"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2388 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 2389 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2390 | CHECK_WPA_CTRL(CTRL_AP); |
| 2391 | |
| 2392 | DO_REQUEST(lynq_chanspec_cmd); |
| 2393 | |
| 2394 | count = lynq_split(cmd_reply, reply_len, ' ', split_words); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2395 | for(;index < count; index++) |
| 2396 | { |
| 2397 | RLOGD("[lynq_wifi_ap_channel_get]---- %s\n",split_words[index]); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2398 | if (strncmp(split_words[index], "channel", 2) != 0) { |
| 2399 | continue; |
| 2400 | } |
| 2401 | |
| 2402 | index++; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2403 | if (index >= count) |
| 2404 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2405 | return -1; |
| 2406 | } |
| 2407 | |
| 2408 | *channel = atoi(split_words[index]); |
| 2409 | return 0; |
| 2410 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2411 | RLOGE("[lynq_wifi_ap_channel_get] function fail"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2412 | return -1; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2413 | } |
| 2414 | |
| 2415 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2416 | 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] | 2417 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2418 | char ssid[MAX_CMD] = {0}; |
| 2419 | int freq = 0; |
| 2420 | char lynq_auth_cmd[64]={0}; |
| 2421 | char lynq_auth_alg_cmd[64]={0}; |
| 2422 | char lynq_psk_cmd[64]={0}; |
| 2423 | char lynq_pairwise_cmd[64]={0}; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2424 | char lynq_ieee80211_cmd[64]={0}; |
| 2425 | 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] | 2426 | lynq_wifi_auth_s org_auth; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2427 | CHECK_IDX(idx, CTRL_AP); |
| 2428 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2429 | CHECK_WPA_CTRL(CTRL_AP); |
| 2430 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2431 | if (lynq_check_network_number(idx, CTRL_AP, AP_NETWORK_0) != AP_NETWORK_0) |
| 2432 | { |
| 2433 | RLOGE("[wifi error][lynq_wifi_ap_auth_set] check network fail\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2434 | return -1; |
| 2435 | } |
| 2436 | |
you.chen | 92fd5d3 | 2022-05-25 10:09:47 +0800 | [diff] [blame] | 2437 | 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] | 2438 | if (org_auth == auth) { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2439 | RLOGD("org_auth --- is %d\n",org_auth); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2440 | return 0; |
| 2441 | } |
| 2442 | else { |
| 2443 | if (0 != lynq_wifi_ap_ssid_get(idx, ssid)) { |
| 2444 | ssid[0] = '\0'; |
| 2445 | } |
| 2446 | lynq_wifi_ap_frequency_get(idx, &freq); |
| 2447 | |
| 2448 | DO_OK_FAIL_REQUEST(cmd_disconnect); |
| 2449 | DO_OK_FAIL_REQUEST(cmd_remove_all); |
| 2450 | if (ssid[0] != '\0') { |
| 2451 | lynq_wifi_ap_ssid_set(idx, ssid); |
| 2452 | } |
| 2453 | if (freq != 0) { |
| 2454 | lynq_wifi_ap_frequency_set(idx, freq); |
| 2455 | } |
| 2456 | } |
| 2457 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2458 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2459 | switch(auth){ |
| 2460 | case LYNQ_WIFI_AUTH_OPEN: |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2461 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2462 | RLOGD("auth == is LYNQ_WIFI_AUTH_OPEN\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2463 | 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] | 2464 | sprintf(lynq_pairwise_cmd,"SET_NETWORK %d pairwise NONE", AP_NETWORK_0); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2465 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2466 | break; |
| 2467 | } |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2468 | case LYNQ_WIFI_AUTH_WEP: |
| 2469 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2470 | RLOGD("auth == is LYNQ_WIFI_AUTH_WEP\n"); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2471 | 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] | 2472 | sprintf(lynq_pairwise_cmd,"SET_NETWORK %d pairwise NONE", AP_NETWORK_0); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2473 | sprintf(lynq_auth_alg_cmd,"SET_NETWORK %d auth_alg SHARED", AP_NETWORK_0); |
| 2474 | |
| 2475 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
| 2476 | DO_OK_FAIL_REQUEST(lynq_auth_alg_cmd); |
| 2477 | break; |
| 2478 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2479 | case LYNQ_WIFI_AUTH_WPA_PSK: |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2480 | { |
| 2481 | sprintf(lynq_auth_cmd,"SET_NETWORK %d proto WPA", AP_NETWORK_0); |
| 2482 | sprintf(lynq_psk_cmd,"SET_NETWORK %d key_mgmt WPA-PSK", AP_NETWORK_0); |
| 2483 | sprintf(lynq_pairwise_cmd,"SET_NETWORK %d pairwise CCMP", AP_NETWORK_0); |
| 2484 | |
| 2485 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
| 2486 | DO_OK_FAIL_REQUEST(lynq_psk_cmd); |
| 2487 | DO_OK_FAIL_REQUEST(lynq_pairwise_cmd); |
| 2488 | break; |
| 2489 | |
| 2490 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2491 | case LYNQ_WIFI_AUTH_WPA2_PSK: |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2492 | { |
| 2493 | if (auth == LYNQ_WIFI_AUTH_WPA_PSK) |
| 2494 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2495 | sprintf(lynq_auth_cmd,"SET_NETWORK %d proto WPA", AP_NETWORK_0); |
| 2496 | sprintf(lynq_psk_cmd,"SET_NETWORK %d key_mgmt WPA-PSK", AP_NETWORK_0); |
| 2497 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2498 | else if (auth == LYNQ_WIFI_AUTH_WPA2_PSK) |
| 2499 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2500 | sprintf(lynq_auth_cmd,"SET_NETWORK %d proto RSN", AP_NETWORK_0); |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2501 | 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] | 2502 | } |
| 2503 | // sprintf(lynq_auth_cmd,"SET_NETWORK %d proto WPA2", AP_NETWORK_0); |
| 2504 | // sprintf(lynq_psk_cmd,"SET_NETWORK %d key_mgmt WPA-PSK", AP_NETWORK_0); |
| 2505 | sprintf(lynq_pairwise_cmd,"SET_NETWORK %d pairwise CCMP", AP_NETWORK_0); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2506 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2507 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
| 2508 | DO_OK_FAIL_REQUEST(lynq_psk_cmd); |
| 2509 | DO_OK_FAIL_REQUEST(lynq_pairwise_cmd); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2510 | break; |
| 2511 | } |
| 2512 | case LYNQ_WIFI_AUTH_WPA2_WPA3_PSK: |
| 2513 | { |
| 2514 | sprintf(lynq_auth_cmd,"SET_NETWORK %d proto WPA2", AP_NETWORK_0); |
| 2515 | sprintf(lynq_ieee80211_cmd,"SET_NETWORK %d ieee80211w 1", AP_NETWORK_0); |
| 2516 | sprintf(lynq_psk_cmd,"SET_NETWORK %d key_mgmt WPA-PSK SAE", AP_NETWORK_0); |
| 2517 | sprintf(lynq_pairwise_cmd,"SET_NETWORK %d pairwise CCMP", AP_NETWORK_0); |
| 2518 | |
| 2519 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
| 2520 | DO_OK_FAIL_REQUEST(lynq_ieee80211_cmd); |
| 2521 | DO_OK_FAIL_REQUEST(lynq_psk_cmd); |
| 2522 | DO_OK_FAIL_REQUEST(lynq_pairwise_cmd); |
| 2523 | break; |
| 2524 | } |
| 2525 | case LYNQ_WIFI_AUTH_WPA3_PSK: |
| 2526 | { |
| 2527 | sprintf(lynq_auth_cmd,"SET_NETWORK %d proto WPA2", AP_NETWORK_0); |
| 2528 | sprintf(lynq_ieee80211_cmd,"SET_NETWORK %d ieee80211w 2", AP_NETWORK_0); |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 2529 | 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] | 2530 | sprintf(lynq_pairwise_cmd,"SET_NETWORK %d pairwise CCMP", AP_NETWORK_0); |
| 2531 | |
| 2532 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
| 2533 | DO_OK_FAIL_REQUEST(lynq_ieee80211_cmd); |
| 2534 | DO_OK_FAIL_REQUEST(lynq_psk_cmd); |
| 2535 | DO_OK_FAIL_REQUEST(lynq_pairwise_cmd); |
| 2536 | break; |
| 2537 | } |
| 2538 | default: |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2539 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2540 | RLOGE("auth type [%d] not support now\n", auth); |
| 2541 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2542 | } |
| 2543 | } |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2544 | DO_OK_FAIL_REQUEST(cmd_save_config); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2545 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2546 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2547 | } |
| 2548 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2549 | 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] | 2550 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2551 | char lynq_auth_str[MAX_RET] = {0}; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2552 | char lynq_auth_alg_str[MAX_RET] = {0}; |
| 2553 | char lynq_proto_str[MAX_RET] = {0}; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2554 | RLOGD("enter lynq_wifi_ap_auth_get"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2555 | CHECK_IDX(idx, CTRL_AP); |
| 2556 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2557 | if (inner_get_param(CTRL_AP, AP_NETWORK_0, "key_mgmt", lynq_auth_str) != 0) |
| 2558 | { |
| 2559 | RLOGE("[wifi error][lynq_wifi_ap_auth_get] check network fail"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2560 | return -1; |
| 2561 | } |
| 2562 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2563 | if (memcmp( lynq_auth_str, "NONE", 4) == 0) |
| 2564 | { |
| 2565 | if (inner_get_param(CTRL_AP, AP_NETWORK_0, "auth_alg", lynq_auth_alg_str) != 0) |
| 2566 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2567 | RLOGD("---auth is OPEN\n"); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2568 | *auth = LYNQ_WIFI_AUTH_OPEN; |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2569 | return 0; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2570 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2571 | else if (memcmp(lynq_auth_alg_str, "SHARED", 6) == 0) |
| 2572 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2573 | RLOGD("---auth is WEP\n"); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2574 | *auth = LYNQ_WIFI_AUTH_WEP; |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2575 | return 0; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2576 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2577 | else |
| 2578 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2579 | RLOGD("---auth is OPEN\n"); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2580 | *auth = LYNQ_WIFI_AUTH_OPEN; |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2581 | return 0; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2582 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2583 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2584 | else if(strcmp( lynq_auth_str, "WPA-PSK") == 0 ) |
| 2585 | { |
| 2586 | if (inner_get_param(CTRL_AP, AP_NETWORK_0, "proto", lynq_proto_str) != 0) |
| 2587 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2588 | RLOGE("---auth is -1\n"); |
you.chen | 92fd5d3 | 2022-05-25 10:09:47 +0800 | [diff] [blame] | 2589 | *auth = -1; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2590 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2591 | else if (memcmp(lynq_proto_str, "RSN", 3) == 0) |
| 2592 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2593 | RLOGD("---auth WPA2_PSK\n"); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2594 | *auth = LYNQ_WIFI_AUTH_WPA2_PSK; |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2595 | return 0; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2596 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2597 | else |
| 2598 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2599 | RLOGD("---auth WPA_PSK\n"); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2600 | *auth = LYNQ_WIFI_AUTH_WPA_PSK; |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2601 | return 0; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2602 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2603 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2604 | |
| 2605 | if (inner_get_param(CTRL_AP, AP_NETWORK_0, "ieee80211w", lynq_auth_str) != 0) |
| 2606 | { |
| 2607 | RLOGE("[wifi error][lynq_wifi_ap_auth_get] check network auth ieee80211w fail"); |
| 2608 | return -1; |
| 2609 | } |
| 2610 | |
| 2611 | if (memcmp(lynq_auth_str,"1",1) == 0 ) |
| 2612 | { |
| 2613 | RLOGD("auth : LYNQ_WIFI_AUTH_WPA2_WPA3_PSK\n"); |
| 2614 | *auth = LYNQ_WIFI_AUTH_WPA2_WPA3_PSK; |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2615 | return 0; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2616 | }else if (memcmp(lynq_auth_str,"2",1) == 0 ) |
| 2617 | { |
| 2618 | RLOGD("auth : LYNQ_WIFI_AUTH_WPA3_PSK\n"); |
| 2619 | *auth = LYNQ_WIFI_AUTH_WPA3_PSK; |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2620 | return 0; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2621 | } |
| 2622 | else |
| 2623 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2624 | RLOGE("---auth -- -1\n"); |
you.chen | 92fd5d3 | 2022-05-25 10:09:47 +0800 | [diff] [blame] | 2625 | *auth = -1; |
| 2626 | } |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2627 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2628 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2629 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 2630 | |
you.chen | b95401e | 2023-05-12 19:39:06 +0800 | [diff] [blame] | 2631 | static int inner_check_ap_connected(lynq_wifi_index_e idx, int retry_count) |
| 2632 | { |
| 2633 | char status[64]; |
you.chen | cba1349 | 2023-05-19 13:53:43 +0800 | [diff] [blame] | 2634 | char LYNQ_WIFI_CMD[32]={0}; |
you.chen | b95401e | 2023-05-12 19:39:06 +0800 | [diff] [blame] | 2635 | curr_status_info curr_state; |
| 2636 | |
| 2637 | CHECK_WPA_CTRL(CTRL_AP); |
| 2638 | |
| 2639 | memset(status, 0, sizeof (status)); |
| 2640 | |
| 2641 | curr_state.ap = NULL; |
| 2642 | curr_state.state = status; |
| 2643 | |
| 2644 | printf("inner_check_ap_connected %d\n", retry_count); |
qs.xiong | 5a2ba93 | 2023-09-13 16:30:21 +0800 | [diff] [blame] | 2645 | usleep(250*1000); |
qs.xiong | 2b2c8cd | 2023-09-14 15:58:51 +0800 | [diff] [blame] | 2646 | if (0 == inner_get_status_info(idx, &curr_state)) |
you.chen | b95401e | 2023-05-12 19:39:06 +0800 | [diff] [blame] | 2647 | { |
qs.xiong | 2b2c8cd | 2023-09-14 15:58:51 +0800 | [diff] [blame] | 2648 | if ((strcmp(status, STATE_SCANNING) == 0)|| (strcmp(status, STATE_COMPLETED) == 0)) |
you.chen | b95401e | 2023-05-12 19:39:06 +0800 | [diff] [blame] | 2649 | { |
| 2650 | return 0; |
| 2651 | } |
qs.xiong | 5a2ba93 | 2023-09-13 16:30:21 +0800 | [diff] [blame] | 2652 | else if (retry_count == 8) //not ok in 2s, do reconnect |
you.chen | b95401e | 2023-05-12 19:39:06 +0800 | [diff] [blame] | 2653 | { |
| 2654 | DO_REQUEST("RECONNECT"); |
| 2655 | return inner_check_ap_connected(idx, retry_count+1); |
| 2656 | } |
you.chen | cba1349 | 2023-05-19 13:53:43 +0800 | [diff] [blame] | 2657 | else if (retry_count > 20) |
you.chen | b95401e | 2023-05-12 19:39:06 +0800 | [diff] [blame] | 2658 | { |
| 2659 | printf("retry 10 time\n"); |
| 2660 | return -1; |
| 2661 | } |
| 2662 | else |
| 2663 | { |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 2664 | if (strcmp(status, STATE_DISCONNECTED) == 0) |
| 2665 | { |
| 2666 | sprintf(LYNQ_WIFI_CMD,"SELECT_NETWORK %d",AP_NETWORK_0); |
| 2667 | DO_REQUEST(LYNQ_WIFI_CMD); |
| 2668 | } |
you.chen | b95401e | 2023-05-12 19:39:06 +0800 | [diff] [blame] | 2669 | return inner_check_ap_connected(idx, retry_count+1); |
| 2670 | } |
| 2671 | } |
| 2672 | return -1; |
| 2673 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 2674 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2675 | int lynq_wifi_ap_start(lynq_wifi_index_e idx) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2676 | { |
qs.xiong | 5a2ba93 | 2023-09-13 16:30:21 +0800 | [diff] [blame] | 2677 | RLOGD("[lynq_wifi]----enter lynq_wifi_ap_start"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2678 | char LYNQ_WIFI_CMD[128]={0}; |
qs.xiong | b37f8c4 | 2023-09-13 21:21:58 +0800 | [diff] [blame] | 2679 | //const char *lynq_remove_all_cmd = "REMOVE_NETWORK all"; |
| 2680 | //const char *lynq_reconfig_cmd = "RECONFIGURE /data/wifi/wg870/wpa_supplicant.conf"; |
| 2681 | RLOGD("enter lynq_wifi_ap_channel_get"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2682 | CHECK_IDX(idx, CTRL_AP); |
| 2683 | |
| 2684 | CHECK_WPA_CTRL(CTRL_AP); |
| 2685 | |
you.chen | 0df3e7e | 2023-05-10 15:56:26 +0800 | [diff] [blame] | 2686 | if (inner_get_ap_interface_name() == NULL) |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 2687 | { |
you.chen | 0df3e7e | 2023-05-10 15:56:26 +0800 | [diff] [blame] | 2688 | RLOGE("lynq_wifi_ap_start get ap name fail"); |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 2689 | return -1; |
| 2690 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2691 | |
qs.xiong | b37f8c4 | 2023-09-13 21:21:58 +0800 | [diff] [blame] | 2692 | //DO_OK_FAIL_REQUEST(lynq_remove_all_cmd); |
| 2693 | //DO_OK_FAIL_REQUEST(lynq_reconfig_cmd); |
| 2694 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2695 | sprintf(LYNQ_WIFI_CMD,"SELECT_NETWORK %d",AP_NETWORK_0); |
| 2696 | DO_OK_FAIL_REQUEST(LYNQ_WIFI_CMD); |
| 2697 | |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 2698 | ret = system_call_v("%s %s", start_stop_ap_script, "start"); |
| 2699 | if (ret != 0) |
| 2700 | { |
| 2701 | RLOGE("lynq_wifi_ap_start excute script fail"); |
| 2702 | return -1; |
| 2703 | } |
| 2704 | |
you.chen | b95401e | 2023-05-12 19:39:06 +0800 | [diff] [blame] | 2705 | if (inner_check_ap_connected(idx, 0) != 0) |
| 2706 | { |
| 2707 | return -1; |
| 2708 | } |
| 2709 | |
you.chen | 0df3e7e | 2023-05-10 15:56:26 +0800 | [diff] [blame] | 2710 | check_tether_and_notify(); |
qs.xiong | 44fac67 | 2023-08-29 16:15:55 +0800 | [diff] [blame] | 2711 | if (g_ap_tmp_watcher_pid == 0) |
| 2712 | { |
| 2713 | if(pthread_create(&g_ap_tmp_watcher_pid,NULL,APTmpWatcherThreadProc,NULL) < 0) |
| 2714 | { |
| 2715 | g_ap_tmp_watcher_pid = 0; |
| 2716 | RLOGE("[wifi error]create APTmpWatcherThreadProc fail"); |
| 2717 | return -1; |
| 2718 | } |
| 2719 | RLOGD("[lynq_wifi_ap_start] creat APTmpWatcherThreadProc ok"); |
| 2720 | } |
qs.xiong | 5a2ba93 | 2023-09-13 16:30:21 +0800 | [diff] [blame] | 2721 | RLOGD("[lynq_wifi]----end lynq_wifi_ap_start"); |
qs.xiong | b37f8c4 | 2023-09-13 21:21:58 +0800 | [diff] [blame] | 2722 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2723 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2724 | } |
| 2725 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2726 | int lynq_wifi_ap_restart(lynq_wifi_index_e idx) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2727 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2728 | 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] | 2729 | } |
| 2730 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2731 | int lynq_wifi_ap_stop(lynq_wifi_index_e idx) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2732 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2733 | char LYNQ_WIFI_CMD[128]={0}; |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 2734 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2735 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2736 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2737 | CHECK_WPA_CTRL(CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2738 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2739 | sprintf(LYNQ_WIFI_CMD,"DISABLE_NETWORK %d",AP_NETWORK_0); |
| 2740 | |
| 2741 | DO_OK_FAIL_REQUEST(LYNQ_WIFI_CMD); |
| 2742 | |
you.chen | b4b121c | 2022-05-06 17:50:16 +0800 | [diff] [blame] | 2743 | // system("connmanctl tether wifi off"); |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 2744 | |
| 2745 | ret = system_call_v("%s %s", start_stop_ap_script, "stop"); |
| 2746 | if (ret != 0) |
| 2747 | { |
| 2748 | RLOGE("lynq_wifi_ap_start excute script fail"); |
| 2749 | return -1; |
| 2750 | } |
qs.xiong | 44fac67 | 2023-08-29 16:15:55 +0800 | [diff] [blame] | 2751 | g_ap_tmp_watcher_stop_flag = 1; |
| 2752 | if (g_ap_tmp_watcher_pid != 0) |
| 2753 | pthread_join(g_ap_tmp_watcher_pid, NULL); |
| 2754 | g_ap_tmp_watcher_pid = 0; |
qs.xiong | ae96e1f | 2023-08-23 17:08:36 +0800 | [diff] [blame] | 2755 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2756 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2757 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 2758 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2759 | int lynq_wifi_ap_hide_ssid(lynq_wifi_index_e idx) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2760 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2761 | char lynq_disable_cmd[128] = {0}; |
| 2762 | char lynq_select_cmd[128] = {0}; |
| 2763 | const char *lynq_hide_cmd = "SET HIDE_SSID 1"; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2764 | RLOGD("enter lynq_wifi_ap_hide_ssid"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2765 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2766 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2767 | CHECK_WPA_CTRL(CTRL_AP); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2768 | sprintf(lynq_disable_cmd,"DISABLE_NETWORK %d", AP_NETWORK_0); |
| 2769 | sprintf(lynq_select_cmd,"SELECT_NETWORK %d", AP_NETWORK_0); |
| 2770 | |
| 2771 | DO_OK_FAIL_REQUEST(lynq_disable_cmd); |
| 2772 | DO_OK_FAIL_REQUEST(lynq_hide_cmd); |
| 2773 | DO_OK_FAIL_REQUEST(lynq_select_cmd); |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 2774 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2775 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2776 | } |
| 2777 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2778 | int lynq_wifi_ap_unhide_ssid(lynq_wifi_index_e idx) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2779 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2780 | char lynq_disable_cmd[128] = {0}; |
| 2781 | char lynq_select_cmd[128] = {0}; |
| 2782 | const char *lynq_unhide_cmd = "SET HIDE_SSID 0"; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2783 | RLOGD("enter lynq_wifi_ap_unhide_ssid"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2784 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2785 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2786 | CHECK_WPA_CTRL(CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2787 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2788 | sprintf(lynq_disable_cmd,"DISABLE_NETWORK %d", AP_NETWORK_0); |
| 2789 | sprintf(lynq_select_cmd,"SELECT_NETWORK %d", AP_NETWORK_0); |
| 2790 | |
| 2791 | DO_OK_FAIL_REQUEST(lynq_disable_cmd); |
| 2792 | DO_OK_FAIL_REQUEST(lynq_unhide_cmd); |
| 2793 | DO_OK_FAIL_REQUEST(lynq_select_cmd); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2794 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2795 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2796 | } |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2797 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2798 | int lynq_ap_password_set(lynq_wifi_index_e idx,char *password) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2799 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2800 | int pass_len; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2801 | char lynq_tmp_cmd[MAX_CMD] = {0}; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2802 | char lynq_wpa2_wpa3[64] = {0}; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2803 | char lynq_wep_tx_keyidx_cmd[MAX_CMD] = {0}; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2804 | RLOGD("enter lynq_ap_password_set"); |
| 2805 | if( password == NULL ) |
| 2806 | { |
| 2807 | RLOGE("[lynq_ap_password_set]input password is NULL"); |
qs.xiong | e707432 | 2022-06-27 11:34:53 +0800 | [diff] [blame] | 2808 | return -1; |
| 2809 | } |
| 2810 | pass_len=strlen(password); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2811 | lynq_wifi_auth_s auth = -1; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2812 | if(pass_len < 8 || pass_len >= 64) |
| 2813 | { |
| 2814 | RLOGE("[lynq_ap_password_set]input password len not in rage"); |
| 2815 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2816 | } |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2817 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2818 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2819 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2820 | if (0 != lynq_wifi_ap_auth_get(idx, &auth)) |
| 2821 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2822 | RLOGE("[lynq_ap_password_set] get ap auth info error\n"); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2823 | return -1; |
| 2824 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2825 | else if (auth == LYNQ_WIFI_AUTH_OPEN) |
| 2826 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2827 | RLOGD("ap auth :LYNQ_WIFI_AUTH_OPEN\n"); |
| 2828 | return 0; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2829 | } |
| 2830 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2831 | CHECK_WPA_CTRL(CTRL_AP); |
| 2832 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2833 | if (auth == LYNQ_WIFI_AUTH_WEP) |
| 2834 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2835 | RLOGD("[lynq_ap_password_set]ap auth : LYNQ_WIFI_AUTH_WEP\n"); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2836 | sprintf(lynq_tmp_cmd,"SET_NETWORK %d wep_key0 \"%s\"",AP_NETWORK_0, password); |
| 2837 | sprintf(lynq_wep_tx_keyidx_cmd,"SET_NETWORK %d wep_tx_keyidx 0",AP_NETWORK_0); |
| 2838 | DO_OK_FAIL_REQUEST(lynq_tmp_cmd); |
| 2839 | DO_OK_FAIL_REQUEST(lynq_wep_tx_keyidx_cmd); |
| 2840 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2841 | else if (auth == LYNQ_WIFI_AUTH_WPA_PSK || auth == LYNQ_WIFI_AUTH_WPA2_PSK) |
| 2842 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2843 | 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] | 2844 | sprintf(lynq_tmp_cmd,"SET_NETWORK %d psk \"%s\"",AP_NETWORK_0, password); |
| 2845 | DO_OK_FAIL_REQUEST(lynq_tmp_cmd); |
| 2846 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2847 | else if (auth == LYNQ_WIFI_AUTH_WPA2_WPA3_PSK || auth == LYNQ_WIFI_AUTH_WPA3_PSK) |
| 2848 | { |
| 2849 | |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2850 | 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] | 2851 | 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] | 2852 | 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] | 2853 | DO_OK_FAIL_REQUEST(lynq_tmp_cmd); |
| 2854 | DO_OK_FAIL_REQUEST(lynq_wpa2_wpa3); |
| 2855 | |
| 2856 | } |
| 2857 | else |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2858 | { |
| 2859 | RLOGD("[lynq_ap_password_set]ap auth :get ap auth error\n"); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2860 | return -1; |
| 2861 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2862 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2863 | DO_OK_FAIL_REQUEST(cmd_save_config); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2864 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2865 | return 0; |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2866 | } |
| 2867 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2868 | int lynq_ap_password_get(lynq_wifi_index_e idx, char *password) |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2869 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2870 | FILE * fp; |
| 2871 | int len, ret; |
| 2872 | int count, index; |
| 2873 | char *split_lines[128] = {0}; |
| 2874 | char *buff, *p; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2875 | RLOGD("enter lynq_ap_password_get"); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2876 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2877 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2878 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2879 | fp = fopen("/data/wifi/wg870/wpa_supplicant_ap.conf", "rb"); |
| 2880 | // fp = fopen("/data/wifi/wg870/wpa_supplicant.conf", "rb"); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2881 | if (NULL == fp) |
| 2882 | { |
| 2883 | RLOGE("open file fail\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2884 | return -1; |
| 2885 | } |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2886 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2887 | buff = alloca(MAX_RET); |
| 2888 | fseek(fp, 0, SEEK_SET); |
| 2889 | len = fread(buff, 1, MAX_RET, fp); |
| 2890 | fclose(fp); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2891 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2892 | for(index=0; index < len; index ++) |
| 2893 | { |
| 2894 | if (memcmp(buff + index, "network={", 9) != 0) |
| 2895 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2896 | continue; |
| 2897 | } |
| 2898 | p = buff + index + 9; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2899 | for (; index < len; index ++ ) |
| 2900 | { |
| 2901 | if (buff[index] != '}') |
| 2902 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2903 | continue; |
| 2904 | } |
| 2905 | buff[index] = '\0'; |
| 2906 | break; |
| 2907 | } |
| 2908 | len = buff + index - p; |
| 2909 | } |
| 2910 | |
| 2911 | count = lynq_split(p, len, '\n', split_lines); |
| 2912 | |
| 2913 | ret = -1; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2914 | for(index=0; index < count; index++) |
| 2915 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2916 | p = strstr(split_lines[index], "psk="); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2917 | if (p != NULL) |
| 2918 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2919 | p += 4; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2920 | if (*p == '\"') |
| 2921 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2922 | p++; |
| 2923 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2924 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2925 | else if (NULL != (p = strstr(split_lines[index], "wep_key0="))) |
| 2926 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2927 | p += 9; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2928 | if (*p == '\"') |
| 2929 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2930 | p++; |
| 2931 | } |
| 2932 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2933 | else |
| 2934 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2935 | continue; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2936 | } |
| 2937 | |
| 2938 | strcpy(password, p); |
| 2939 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2940 | while(*password != '\0') |
| 2941 | { |
| 2942 | if (*password == '\"') |
| 2943 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2944 | *password = '\0'; |
| 2945 | break; |
| 2946 | } |
| 2947 | password++; |
| 2948 | } |
| 2949 | ret = 0; |
| 2950 | break; |
| 2951 | } //end for(index=0; index < count; index++) |
| 2952 | |
| 2953 | return ret; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2954 | } |
| 2955 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2956 | static int inner_get_network_auth(int interface, int net_no, lynq_wifi_auth_s *auth) { |
| 2957 | char lynq_auth_str[MAX_RET] = {0}; |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2958 | char lynq_proto_str[MAX_RET] = {0}; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2959 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2960 | if (inner_get_param(interface, net_no, "key_mgmt", lynq_auth_str) != 0) |
| 2961 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2962 | return -1; |
| 2963 | } |
| 2964 | |
| 2965 | *auth = convert_auth_from_key_mgmt(lynq_auth_str); |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2966 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2967 | if (*auth == LYNQ_WIFI_AUTH_WPA_PSK) |
| 2968 | { |
| 2969 | if (inner_get_param(interface, net_no, "proto", lynq_proto_str) == 0) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2970 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2971 | if (strcmp(lynq_proto_str, "RSN") == 0) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2972 | { |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2973 | *auth = LYNQ_WIFI_AUTH_WPA2_PSK; |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2974 | return 0; |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2975 | } |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2976 | else if (strcmp(lynq_proto_str, "WPA") == 0) // need compare when wpa3 supported |
| 2977 | { |
| 2978 | return 0; |
| 2979 | } |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2980 | } |
| 2981 | } |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2982 | else if (*auth == LYNQ_WIFI_AUTH_OPEN || *auth == LYNQ_WIFI_AUTH_WEP) |
| 2983 | { |
| 2984 | return 0; |
| 2985 | } |
| 2986 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2987 | if (inner_get_param(interface, net_no,"ieee80211w",lynq_auth_str) !=0) |
| 2988 | { |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2989 | RLOGE("check ieee80211w error\n"); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2990 | return -1; |
| 2991 | } |
| 2992 | if ( strncmp(lynq_auth_str,"1",1) == 0 ) |
| 2993 | { |
| 2994 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2995 | *auth = LYNQ_WIFI_AUTH_WPA2_WPA3_PSK; |
| 2996 | return 0; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2997 | }else if( strncmp(lynq_auth_str,"2",1) == 0 ) |
| 2998 | { |
| 2999 | |
| 3000 | *auth = LYNQ_WIFI_AUTH_WPA3_PSK; |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 3001 | return 0; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3002 | }else |
| 3003 | { |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 3004 | RLOGE("check ieee80211w error, not 1 or 2\n"); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3005 | *auth = -1; |
| 3006 | return -1; |
| 3007 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3008 | return 0; |
| 3009 | } |
| 3010 | |
| 3011 | 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] | 3012 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3013 | RLOGD("enter lynq_sta_ssid_password_set"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3014 | int pass_len, net_no, count, index; |
| 3015 | char lynq_tmp_cmd[300]={0}; |
| 3016 | int net_no_list[128]; |
| 3017 | lynq_wifi_auth_s net_auth; |
| 3018 | pass_len=strlen(password); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3019 | if(pass_len < 8 || pass_len >= 64) |
| 3020 | { |
| 3021 | RLOGE("[lynq_sta_ssid_password_set]input psw error"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3022 | return -1; |
| 3023 | } |
| 3024 | |
| 3025 | CHECK_IDX(idx, CTRL_STA); |
| 3026 | |
| 3027 | net_no = -1; |
| 3028 | count = lynq_get_network_number_list(idx, CTRL_STA, net_no_list, ap->ap_ssid); |
| 3029 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3030 | for (index=0; index < count; index++) |
| 3031 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3032 | net_auth = -1; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3033 | if (0 == inner_get_network_auth(CTRL_STA, net_no_list[index], &net_auth) && net_auth == ap->auth) |
| 3034 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3035 | net_no = net_no_list[index]; |
| 3036 | break; |
| 3037 | } |
| 3038 | } |
| 3039 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3040 | if (net_no < 0) |
| 3041 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3042 | return -1; |
| 3043 | } |
| 3044 | |
| 3045 | CHECK_WPA_CTRL(CTRL_STA); |
| 3046 | |
| 3047 | sprintf(lynq_tmp_cmd,"SET_NETWORK %d psk \"%s\"",net_no, password); |
| 3048 | |
| 3049 | DO_OK_FAIL_REQUEST(lynq_tmp_cmd); |
| 3050 | DO_OK_FAIL_REQUEST(cmd_save_config); |
| 3051 | |
| 3052 | return 0; |
| 3053 | } |
| 3054 | |
qs.xiong | b5dab08 | 2023-10-13 14:43:41 +0800 | [diff] [blame] | 3055 | /** |
| 3056 | * buff data |
| 3057 | * buff_len size of buff |
| 3058 | * idx sta |
| 3059 | * *ap ap info for find ssid && password |
| 3060 | * password return password |
| 3061 | * |
| 3062 | */ |
| 3063 | static int lynq_sta_ssid_password_auth_get(char * buff,int buff_len,lynq_wifi_index_e idx, ap_info_s *ap,char *password) { // @todo |
| 3064 | |
| 3065 | int ret, network_len, i, ssid_len,curr_auth; |
| 3066 | int count, index,org_index; |
| 3067 | char *split_lines[128] = {0}; |
| 3068 | char *p, *ssid, *ssid_end_flag,*ptr; |
| 3069 | char tmp_ssid[128]={0}; |
| 3070 | char tmp_auth[24]={0}; |
| 3071 | |
| 3072 | org_index = 0; |
| 3073 | network_len = 0; |
| 3074 | p = NULL; |
| 3075 | |
| 3076 | CHECK_IDX(idx, CTRL_STA); |
| 3077 | |
| 3078 | while(1){ |
| 3079 | network_len = 0; |
| 3080 | p == NULL; |
| 3081 | for(; org_index < buff_len; org_index ++) |
| 3082 | { |
| 3083 | for(; org_index < buff_len; org_index ++) |
| 3084 | { |
| 3085 | if (memcmp(buff + org_index, "network={", 9) != 0) |
| 3086 | { |
| 3087 | continue; |
| 3088 | } |
| 3089 | p = buff + org_index + 9; |
| 3090 | |
| 3091 | for (; org_index < buff_len; org_index ++ ) |
| 3092 | { |
| 3093 | if (buff[org_index] != '}') |
| 3094 | { |
| 3095 | continue; |
| 3096 | } |
| 3097 | buff[org_index] = '\0'; |
| 3098 | break; |
| 3099 | } |
| 3100 | network_len = buff + org_index - p; |
| 3101 | break; |
| 3102 | } |
| 3103 | |
| 3104 | if (p == NULL) |
| 3105 | { |
| 3106 | RLOGD("not find dest info %s(),line %dERROR",__func__,__LINE__); |
| 3107 | return -1; |
| 3108 | } |
| 3109 | |
| 3110 | ssid = strstr(p, "ssid="); |
| 3111 | if (ssid != NULL) { |
| 3112 | ssid += strlen("ssid="); |
| 3113 | if (ssid[0] == '\"') |
| 3114 | { |
| 3115 | if (memcmp(ssid + 1, ap->ap_ssid, strlen(ap->ap_ssid)) == 0 && ssid[strlen(ap->ap_ssid) + 1] == '\"') |
| 3116 | { |
| 3117 | RLOGD("-----curr_get ssid form config is %s",ssid); |
| 3118 | break; |
| 3119 | } |
| 3120 | RLOGD("-----countine to find dest ssid %s ---curr_get ssid from config is %s",ap->ap_ssid,ssid); |
| 3121 | } |
| 3122 | else |
| 3123 | { |
| 3124 | ssid_end_flag = strstr(ssid, "\n"); |
| 3125 | if (ssid_end_flag != NULL) |
| 3126 | { |
| 3127 | ssid_len = (ssid_end_flag - ssid) / 2; |
| 3128 | for(i=0; i<ssid_len; i++) |
| 3129 | { |
| 3130 | tmp_ssid[i] = inner_convert_char(ssid[i*2]) << 4 | inner_convert_char(ssid[i*2 + 1]); |
| 3131 | } |
| 3132 | if (memcmp(tmp_ssid, ap->ap_ssid, ssid_len) == 0) |
| 3133 | { |
| 3134 | RLOGD("curr_ssid is(from config) ---- %s ap_info ssid --->",tmp_ssid,ap->ap_ssid); |
| 3135 | break; |
| 3136 | } |
| 3137 | } |
| 3138 | } |
| 3139 | } |
| 3140 | |
| 3141 | } |
| 3142 | |
| 3143 | if (org_index >= buff_len || NULL == p || network_len <= 0) |
| 3144 | { |
| 3145 | |
| 3146 | if (buff != NULL) |
| 3147 | RLOGD("not find dest ssid %s(),line %dERROR",__func__,__LINE__); |
| 3148 | return -1; |
| 3149 | } |
| 3150 | |
| 3151 | count = lynq_split(p, network_len, '\n', split_lines); |
| 3152 | ret = -1; |
| 3153 | for( index=0; index < count; index++ ) |
| 3154 | { |
| 3155 | p = strstr(split_lines[index], "key_mgmt="); |
| 3156 | RLOGD("current p str ------- %s",p); |
| 3157 | if(p != NULL) |
| 3158 | { |
| 3159 | p += 9; |
| 3160 | if(memcmp(p,"SAE",3) == 0) |
| 3161 | { |
| 3162 | curr_auth = 5; |
| 3163 | }else if(memcmp(p,"WPA-PSK SAE",11) == 0) |
| 3164 | { |
| 3165 | curr_auth = 4; |
| 3166 | }else if(memcmp(p,"WPA-PSK",7) == 0 ) |
| 3167 | { |
| 3168 | curr_auth = 3; |
| 3169 | }else if(memcmp(p,"NONE",4) == 0 ) |
| 3170 | { |
| 3171 | curr_auth = 0; |
| 3172 | }else{ |
| 3173 | curr_auth = 1; |
| 3174 | } |
| 3175 | RLOGD("************curret_get_auth is %d ssid is %s",curr_auth,ap->ap_ssid); |
| 3176 | if( curr_auth < 1 || curr_auth > 6) |
| 3177 | { |
| 3178 | ret = -1; |
| 3179 | } |
| 3180 | break; |
| 3181 | } |
| 3182 | } |
| 3183 | if( curr_auth == 0) |
| 3184 | { |
| 3185 | return 0; |
| 3186 | }else if(curr_auth == ap->auth || ap->auth <= 3 && curr_auth <= 3 && curr_auth != -1 ) |
| 3187 | { |
| 3188 | for(index=0; index < count; index++) |
| 3189 | { |
| 3190 | /*get psw info*/ |
| 3191 | |
| 3192 | p = strstr(split_lines[index], "psk="); |
| 3193 | if (p != NULL) |
| 3194 | { |
| 3195 | p += 4; |
| 3196 | if (*p == '\"') |
| 3197 | { |
| 3198 | p++; |
| 3199 | } |
| 3200 | } |
| 3201 | else if (NULL != (p = strstr(split_lines[index], "wep_key0="))) |
| 3202 | { |
| 3203 | p += 9; |
| 3204 | if (*p == '\"') |
| 3205 | { |
| 3206 | p++; |
| 3207 | } |
| 3208 | } |
| 3209 | else |
| 3210 | { |
| 3211 | continue; |
| 3212 | } |
| 3213 | |
| 3214 | if (*p == '\"') |
| 3215 | p++; |
| 3216 | strncpy(password, p, 64); |
| 3217 | p = password; |
| 3218 | while(password - p < 64 && *password != '\0') |
| 3219 | { |
| 3220 | if (*password == '\"') |
| 3221 | { |
| 3222 | *password = '\0'; |
| 3223 | RLOGD("---------password------- p:: %s",p); |
| 3224 | ret = 0; |
| 3225 | break; |
| 3226 | } |
| 3227 | password++; |
| 3228 | } |
| 3229 | break; |
| 3230 | } |
| 3231 | break; |
| 3232 | } |
| 3233 | } |
| 3234 | |
| 3235 | return ret; |
| 3236 | } |
| 3237 | |
| 3238 | |
| 3239 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3240 | int lynq_sta_ssid_password_get(lynq_wifi_index_e idx, ap_info_s *ap, char *password) { // @todo |
| 3241 | |
| 3242 | FILE * fp; |
qs.xiong | b5dab08 | 2023-10-13 14:43:41 +0800 | [diff] [blame] | 3243 | int len, ret; |
| 3244 | char *info_buff; |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 3245 | RLOGD("enter lynq_sta_ssid_password_get"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3246 | |
qs.xiong | b5dab08 | 2023-10-13 14:43:41 +0800 | [diff] [blame] | 3247 | info_buff = NULL; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3248 | CHECK_IDX(idx, CTRL_STA); |
| 3249 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3250 | if (NULL == password) |
| 3251 | { |
| 3252 | RLOGE("bad param\n"); |
you.chen | 755332b | 2022-08-06 16:59:10 +0800 | [diff] [blame] | 3253 | return -1; |
| 3254 | } |
| 3255 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3256 | fp = fopen("/data/wifi/wg870/wpa_supplicant.conf", "rb"); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3257 | if (NULL == fp) |
| 3258 | { |
| 3259 | RLOGE("[lynq_sta_ssid_password_get] open file fail\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3260 | return -1; |
| 3261 | } |
| 3262 | |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 3263 | fseek(fp, 0, SEEK_END); |
| 3264 | len = ftell(fp); |
qs.xiong | b5dab08 | 2023-10-13 14:43:41 +0800 | [diff] [blame] | 3265 | info_buff = malloc(len + 1); |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 3266 | |
qs.xiong | b5dab08 | 2023-10-13 14:43:41 +0800 | [diff] [blame] | 3267 | if (info_buff == NULL) |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 3268 | { |
| 3269 | RLOGE("[lynq_sta_ssid_password_get] malloc memory [%d] fail\n", len); |
| 3270 | return -1; |
| 3271 | } |
| 3272 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3273 | fseek(fp, 0, SEEK_SET); |
qs.xiong | b5dab08 | 2023-10-13 14:43:41 +0800 | [diff] [blame] | 3274 | len = fread(info_buff, 1, len, fp); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3275 | fclose(fp); |
| 3276 | |
qs.xiong | b5dab08 | 2023-10-13 14:43:41 +0800 | [diff] [blame] | 3277 | |
| 3278 | ret= lynq_sta_ssid_password_auth_get(info_buff,len,0, ap,password); |
| 3279 | |
| 3280 | if(ret == 0) |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3281 | { |
qs.xiong | b5dab08 | 2023-10-13 14:43:41 +0800 | [diff] [blame] | 3282 | RLOGD("lynq_sta_ssid_password_auth_get pass return ssid :%s psw is %s",ap->ap_ssid,password); |
| 3283 | free(info_buff); |
| 3284 | return 0; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3285 | } |
qs.xiong | b5dab08 | 2023-10-13 14:43:41 +0800 | [diff] [blame] | 3286 | else{ |
| 3287 | free(info_buff); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3288 | return -1; |
| 3289 | } |
| 3290 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3291 | } |
| 3292 | |
qs.xiong | b5dab08 | 2023-10-13 14:43:41 +0800 | [diff] [blame] | 3293 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3294 | static int inner_set_sta_ssid(int net_no, char *sta_ssid) |
| 3295 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3296 | char lynq_wifi_ssid_cmd[80]={0}; |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 3297 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3298 | if (sta_ssid == NULL) |
| 3299 | { |
| 3300 | RLOGE("sta_ssid is null\n"); |
| 3301 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3302 | } |
| 3303 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3304 | CHECK_WPA_CTRL(CTRL_STA); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3305 | |
| 3306 | sprintf(lynq_wifi_ssid_cmd,"SET_NETWORK %d ssid \"%s\"", net_no, sta_ssid); |
| 3307 | |
| 3308 | DO_OK_FAIL_REQUEST(lynq_wifi_ssid_cmd); |
| 3309 | // DO_OK_FAIL_REQUEST(cmd_save_config); |
| 3310 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3311 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 3312 | |
| 3313 | } |
| 3314 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3315 | 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] | 3316 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3317 | char lynq_disable_cmd[128]={0}; |
| 3318 | char lynq_select_cmd[128]={0}; |
| 3319 | |
| 3320 | CHECK_WPA_CTRL(CTRL_STA); |
| 3321 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3322 | if (save != 0) |
| 3323 | { |
you.chen | c29444e | 2022-06-07 18:01:16 +0800 | [diff] [blame] | 3324 | if (start_flag != 0) |
| 3325 | { |
| 3326 | sprintf(lynq_select_cmd,"ENABLE_NETWORK %d", net_no); |
| 3327 | DO_OK_FAIL_REQUEST(lynq_select_cmd); |
| 3328 | } |
| 3329 | else |
| 3330 | { |
| 3331 | sprintf(lynq_select_cmd,"DISABLE_NETWORK %d", net_no); |
| 3332 | DO_OK_FAIL_REQUEST(lynq_select_cmd); |
| 3333 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3334 | DO_OK_FAIL_REQUEST(cmd_save_config); |
| 3335 | } |
| 3336 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3337 | if (start_flag == 0) |
| 3338 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 3339 | sprintf(lynq_disable_cmd,"DISCONNECT"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3340 | DO_OK_FAIL_REQUEST(lynq_disable_cmd); |
| 3341 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3342 | else |
| 3343 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3344 | sprintf(lynq_select_cmd,"SELECT_NETWORK %d", net_no); |
| 3345 | DO_OK_FAIL_REQUEST(lynq_select_cmd); |
| 3346 | } |
| 3347 | |
| 3348 | return 0; |
| 3349 | } |
| 3350 | |
| 3351 | int lynq_wifi_get_sta_ssid(lynq_wifi_index_e idx, char* sta_ssid) |
| 3352 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3353 | RLOGD("enter lynq_sta_ssid_password_set"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3354 | CHECK_IDX(idx, CTRL_STA); |
| 3355 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 3356 | curr_status_info curr_state; |
| 3357 | ap_info_s ap_info; |
| 3358 | curr_state.ap = &ap_info; |
| 3359 | curr_state.state = NULL; |
| 3360 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3361 | if (0 == inner_get_status_info(CTRL_STA, &curr_state)) |
| 3362 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 3363 | strncpy(sta_ssid, ap_info.ap_ssid, sizeof (ap_info.ap_ssid)); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 3364 | return 0; |
| 3365 | } |
| 3366 | |
| 3367 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3368 | } |
| 3369 | |
| 3370 | int lynq_wifi_get_sta_available_ap(lynq_wifi_index_e idx, ap_detail_info_s *info) |
| 3371 | { |
qs.xiong | 5d716d2 | 2023-09-20 20:08:39 +0800 | [diff] [blame] | 3372 | RLOGD("[wifi] ---ernter lynq_wifi_get_sta_available_ap"); |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3373 | scan_info_s *scan_list = NULL; |
| 3374 | saved_ap_info_s *save_list = NULL; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3375 | int scan_len=0; |
| 3376 | int save_len=0; |
| 3377 | int best_index = -1; |
| 3378 | int best_scan_index = -1; |
| 3379 | int best_rssi = 0; |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3380 | int i, j, ret; |
| 3381 | |
| 3382 | ret = -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3383 | |
| 3384 | CHECK_IDX(idx, CTRL_STA); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3385 | if (info == NULL) |
| 3386 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3387 | return -1; |
| 3388 | } |
| 3389 | |
| 3390 | curr_status_info curr_state; |
| 3391 | ap_info_s ap_info; |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3392 | char status[64]; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3393 | |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3394 | memset(&ap_info, 0, sizeof (ap_info)); |
| 3395 | memset(status, 0, sizeof (status)); |
| 3396 | |
| 3397 | curr_state.ap = &ap_info; |
| 3398 | curr_state.state = status; |
| 3399 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3400 | if (0 == inner_get_status_info(CTRL_STA, &curr_state) && curr_state.net_no >= 0) |
| 3401 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3402 | memcpy(&info->base_info, &ap_info, sizeof (ap_info_s)); |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3403 | if (strcmp(status, STATE_COMPLETED) == 0) |
| 3404 | { |
| 3405 | info->status = LYNQ_WIFI_AP_STATUS_ENABLE; |
qs.xiong | 5d716d2 | 2023-09-20 20:08:39 +0800 | [diff] [blame] | 3406 | RLOGD("[wifi] ---lynq_wifi_get_sta_available_ap status --> LYNQ_WIFI_AP_STATUS_ENABLE"); |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3407 | } |
| 3408 | else |
| 3409 | { |
| 3410 | info->status = LYNQ_WIFI_AP_STATUS_DISABLE; |
qs.xiong | 5d716d2 | 2023-09-20 20:08:39 +0800 | [diff] [blame] | 3411 | RLOGD("[wifi] ---lynq_wifi_get_sta_available_ap status --> LYNQ_WIFI_AP_STATUS_DISABLE"); |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3412 | } |
you.chen | 593621d | 2023-04-27 17:52:44 +0800 | [diff] [blame] | 3413 | lynq_get_connect_ap_ip(idx, info->base_info.ap_ip); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3414 | lynq_get_connect_ap_rssi(idx, &info->rssi); |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3415 | lynq_sta_ssid_password_get(idx, & info->base_info, info->base_info.psw); |
qs.xiong | 5d716d2 | 2023-09-20 20:08:39 +0800 | [diff] [blame] | 3416 | RLOGD("[wifi] ---ent --lynq_wifi_get_sta_available_ap"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3417 | return 0; |
| 3418 | } |
| 3419 | |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3420 | lynq_wifi_sta_start_scan(idx); |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 3421 | sleep(2); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3422 | if (0 != lynq_get_scan_list(0, &scan_list, &scan_len)) |
| 3423 | { |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3424 | if (NULL != scan_list) |
| 3425 | { |
| 3426 | free(scan_list); |
| 3427 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3428 | return -1; |
| 3429 | } |
| 3430 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3431 | if (0 != lynq_get_sta_saved_ap(0, &save_list, &save_len)) |
| 3432 | { |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3433 | if (NULL != scan_list) |
| 3434 | { |
| 3435 | free(scan_list); |
| 3436 | } |
| 3437 | if (NULL != save_list) |
| 3438 | { |
| 3439 | free(save_list); |
| 3440 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3441 | return -1; |
| 3442 | } |
| 3443 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3444 | for (i=0; i < save_len; i++) |
| 3445 | { |
| 3446 | for (j=0; j < scan_len; j++) |
| 3447 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3448 | 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] | 3449 | && save_list[i].base_info.auth == scan_list[j].auth) |
| 3450 | { |
| 3451 | if (best_rssi == 0) |
| 3452 | { |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3453 | best_index = i; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3454 | best_rssi = scan_list[j].rssi; |
| 3455 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3456 | else if (best_rssi > scan_list[j].rssi) |
| 3457 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3458 | best_index = i; |
| 3459 | best_scan_index = j; |
| 3460 | best_rssi = scan_list[j].rssi; |
| 3461 | } |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 3462 | 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] | 3463 | break; |
| 3464 | } |
| 3465 | } |
| 3466 | } |
| 3467 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3468 | if (best_index >= 0) |
| 3469 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3470 | 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] | 3471 | 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] | 3472 | info->status = LYNQ_WIFI_AP_STATUS_DISABLE; |
qs.xiong | 5d716d2 | 2023-09-20 20:08:39 +0800 | [diff] [blame] | 3473 | RLOGD("[wifi] ---lynq_wifi_get_sta_available_ap status ---> LYNQ_WIFI_AP_STATUS_ENABLE"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3474 | info->rssi = best_rssi; |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3475 | ret = 0; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3476 | } |
| 3477 | |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3478 | if (NULL != scan_list) |
| 3479 | { |
| 3480 | free(scan_list); |
| 3481 | } |
| 3482 | if (NULL != save_list) |
| 3483 | { |
| 3484 | free(save_list); |
| 3485 | } |
| 3486 | |
qs.xiong | 5d716d2 | 2023-09-20 20:08:39 +0800 | [diff] [blame] | 3487 | RLOGD("[wifi] ---end -lynq_wifi_get_sta_available_ap"); |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3488 | return ret; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3489 | } |
| 3490 | |
| 3491 | static int inner_set_sta_auth_psw(int net_no, lynq_wifi_auth_s auth, char *password) |
| 3492 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 3493 | char lynq_auth_cmd[128]={0}; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3494 | char lynq_ket_mgmt_cmd[64]={0}; |
| 3495 | char lynq_pairwise_cmd[64]={0}; |
| 3496 | char lynq_psk_cmd[64]={0}; |
| 3497 | |
| 3498 | CHECK_WPA_CTRL(CTRL_STA); |
| 3499 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3500 | switch(auth) |
| 3501 | { |
| 3502 | case LYNQ_WIFI_AUTH_OPEN: |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3503 | { |
| 3504 | sprintf(lynq_auth_cmd,"SET_NETWORK %d key_mgmt NONE", net_no); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 3505 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3506 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3507 | // DO_OK_FAIL_REQUEST(cmd_save_config); |
| 3508 | break; |
| 3509 | } |
| 3510 | case LYNQ_WIFI_AUTH_WPA_PSK: |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3511 | case LYNQ_WIFI_AUTH_WPA2_PSK: |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3512 | { |
| 3513 | if (auth == LYNQ_WIFI_AUTH_WPA_PSK) |
| 3514 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3515 | sprintf(lynq_auth_cmd,"SET_NETWORK %d proto WPA", net_no); |
| 3516 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3517 | else if (auth == LYNQ_WIFI_AUTH_WPA2_PSK) |
| 3518 | { |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 3519 | sprintf(lynq_auth_cmd,"SET_NETWORK %d proto RSN", net_no); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3520 | } |
| 3521 | sprintf(lynq_ket_mgmt_cmd,"SET_NETWORK %d key_mgmt WPA-PSK", net_no); |
| 3522 | sprintf(lynq_pairwise_cmd,"SET_NETWORK %d pairwise CCMP", net_no); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 3523 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3524 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
| 3525 | DO_OK_FAIL_REQUEST(lynq_ket_mgmt_cmd); |
| 3526 | DO_OK_FAIL_REQUEST(lynq_pairwise_cmd); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 3527 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3528 | if (password != NULL) |
| 3529 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3530 | sprintf(lynq_psk_cmd, "SET_NETWORK %d psk \"%s\"", net_no, password); |
| 3531 | DO_OK_FAIL_REQUEST(lynq_psk_cmd); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3532 | sprintf(lynq_pairwise_cmd,"SET_NETWORK %d pairwise CCMP", net_no); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3533 | } |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 3534 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3535 | // DO_OK_FAIL_REQUEST(cmd_save_config); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3536 | break; |
| 3537 | } |
| 3538 | case LYNQ_WIFI_AUTH_WPA2_WPA3_PSK: |
| 3539 | { |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 3540 | sprintf(lynq_auth_cmd,"SET_NETWORK %d ieee80211w 1",net_no); |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 3541 | 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] | 3542 | sprintf(lynq_pairwise_cmd,"SET_NETWORK %d pairwise CCMP", net_no); |
| 3543 | sprintf(lynq_psk_cmd, "SET_NETWORK %d psk \"%s\"", net_no, password); |
| 3544 | |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 3545 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3546 | DO_OK_FAIL_REQUEST(lynq_ket_mgmt_cmd); |
| 3547 | DO_OK_FAIL_REQUEST(lynq_pairwise_cmd); |
| 3548 | DO_OK_FAIL_REQUEST(lynq_psk_cmd); |
| 3549 | |
| 3550 | break; |
| 3551 | } |
| 3552 | case LYNQ_WIFI_AUTH_WPA3_PSK: |
| 3553 | { |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 3554 | sprintf(lynq_auth_cmd,"SET_NETWORK %d ieee80211w 2",net_no); |
qs.xiong | 03556d5 | 2023-04-17 09:45:19 +0800 | [diff] [blame] | 3555 | 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] | 3556 | sprintf(lynq_pairwise_cmd,"SET_NETWORK %d pairwise CCMP", net_no); |
| 3557 | sprintf(lynq_psk_cmd, "SET_NETWORK %d psk \"%s\"", net_no, password); |
| 3558 | |
qs.xiong | b37f8c4 | 2023-09-13 21:21:58 +0800 | [diff] [blame] | 3559 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3560 | DO_OK_FAIL_REQUEST(lynq_ket_mgmt_cmd); |
| 3561 | DO_OK_FAIL_REQUEST(lynq_pairwise_cmd); |
| 3562 | DO_OK_FAIL_REQUEST(lynq_psk_cmd); |
| 3563 | |
| 3564 | break; |
| 3565 | } |
| 3566 | default: |
| 3567 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3568 | } |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 3569 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3570 | return 0; |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 3571 | } |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 3572 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3573 | static int inner_get_curr_net_no(int interface) { |
| 3574 | curr_status_info curr_state; |
| 3575 | curr_state.ap = NULL; |
| 3576 | curr_state.state = NULL; |
| 3577 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3578 | if (0 != inner_get_status_info(interface, &curr_state)) |
| 3579 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3580 | return -1; |
| 3581 | } |
| 3582 | |
| 3583 | return curr_state.net_no; |
| 3584 | } |
| 3585 | |
| 3586 | 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] | 3587 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3588 | int net_no; |
| 3589 | CHECK_IDX(idx, CTRL_STA); |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 3590 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3591 | net_no = inner_get_curr_net_no(CTRL_STA); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 3592 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3593 | if (net_no < 0) |
| 3594 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3595 | return -1; |
| 3596 | } |
| 3597 | |
| 3598 | return inner_get_network_auth(CTRL_STA, net_no, auth); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 3599 | } |
| 3600 | |
you.chen | b95401e | 2023-05-12 19:39:06 +0800 | [diff] [blame] | 3601 | int lynq_wifi_sta_connect_timeout(lynq_wifi_index_e idx, char *ssid, lynq_wifi_auth_s auth, char *psw, int timeout) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 3602 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3603 | int count, net_no, index; |
| 3604 | int net_no_list[128]; |
qs.xiong | f71b53b | 2023-05-03 13:12:07 +0800 | [diff] [blame] | 3605 | char rm_net_cmd[128]; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3606 | lynq_wifi_auth_s net_auth; |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 3607 | curr_status_info curr_state; |
| 3608 | ap_info_s ap_info; |
| 3609 | char status[64]; |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 3610 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3611 | if (ssid == NULL || *ssid == '\0') |
| 3612 | { |
| 3613 | RLOGE("bad ssid\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3614 | return -1; |
| 3615 | } |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 3616 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3617 | if (LYNQ_WIFI_AUTH_OPEN != auth) |
| 3618 | { |
| 3619 | if (psw == NULL || strlen(psw) < 8 || strlen(psw) >= 64) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 3620 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3621 | RLOGE("bad password\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3622 | return -1; |
| 3623 | } |
| 3624 | } |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 3625 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 3626 | |
| 3627 | pthread_mutex_lock(&s_global_check_mutex); |
| 3628 | if (s_sta_status != INNER_STA_STATUS_INIT) |
| 3629 | { |
| 3630 | s_sta_status = INNER_STA_STATUS_CANCEL; |
| 3631 | pthread_cond_signal(&s_global_check_cond); |
| 3632 | } |
| 3633 | pthread_mutex_unlock(&s_global_check_mutex); |
| 3634 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3635 | CHECK_IDX(idx, CTRL_STA); |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 3636 | CHECK_WPA_CTRL(CTRL_STA); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3637 | |
| 3638 | net_no = -1; |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 3639 | memset(&ap_info, 0, sizeof (ap_info)); |
| 3640 | memset(status, 0, sizeof (status)); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3641 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 3642 | curr_state.ap = &ap_info; |
| 3643 | curr_state.state = status; |
| 3644 | |
| 3645 | 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] | 3646 | { |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 3647 | if (strcmp(status, STATE_COMPLETED) == 0 && strcmp(ap_info.ap_ssid, ssid) ==0 && ap_info.auth == auth) |
| 3648 | { |
| 3649 | net_no = curr_state.net_no; |
| 3650 | if (0 == lynq_sta_ssid_password_get(idx, &ap_info, ap_info.psw) |
| 3651 | && strcmp(ap_info.psw, psw) == 0) |
| 3652 | { |
| 3653 | RLOGD("already connected\n"); |
| 3654 | |
| 3655 | pthread_mutex_lock(&s_global_check_mutex); |
| 3656 | s_sta_status = INNER_STA_STATUS_CONNECTED; |
qs.xiong | 0956040 | 2023-10-27 21:58:55 +0800 | [diff] [blame] | 3657 | lynq_sta_removeElement(net_no); |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 3658 | pthread_cond_signal(&s_global_check_cond); |
| 3659 | pthread_mutex_unlock(&s_global_check_mutex); |
| 3660 | return 0; |
| 3661 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3662 | } |
| 3663 | } |
| 3664 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 3665 | if (net_no == -1) |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3666 | { |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 3667 | count = lynq_get_network_number_list(idx, CTRL_STA, net_no_list, ssid); |
| 3668 | |
| 3669 | for (index=0; index < count; index++) |
| 3670 | { |
| 3671 | net_auth = -1; |
| 3672 | if (0 == inner_get_network_auth(CTRL_STA, net_no_list[index], &net_auth) && net_auth == auth) |
| 3673 | { |
| 3674 | net_no = net_no_list[index]; |
| 3675 | break; |
| 3676 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3677 | } |
| 3678 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 3679 | if (net_no < 0) |
| 3680 | { |
qs.xiong | f71b53b | 2023-05-03 13:12:07 +0800 | [diff] [blame] | 3681 | count = lynq_get_network_number_list(idx, CTRL_STA, net_no_list, NULL); |
| 3682 | for ( index = 0; index < (count - STA_MAX_SAVED_AP_NUM + 1 ) ;index++) //+1 is for add new network |
| 3683 | { |
| 3684 | sprintf(rm_net_cmd,"REMOVE_NETWORK %d",net_no_list[index]); |
| 3685 | RLOGD("call cmd rm_net_cmd: %s;index is %d\n",rm_net_cmd,index); |
| 3686 | DO_OK_FAIL_REQUEST(rm_net_cmd); |
| 3687 | } |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 3688 | net_no = lynq_add_network(CTRL_STA); |
| 3689 | if (net_no == -1) |
| 3690 | { |
| 3691 | return -1; |
| 3692 | } |
| 3693 | |
| 3694 | RLOGD("net no is %d\n", net_no); |
| 3695 | if (0 != inner_set_sta_ssid(net_no, ssid)) |
| 3696 | { |
| 3697 | return -1; |
| 3698 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3699 | } |
| 3700 | } |
| 3701 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3702 | if (0 != inner_set_sta_auth_psw(net_no, auth, psw)) |
| 3703 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3704 | return -1; |
| 3705 | } |
| 3706 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 3707 | |
| 3708 | DO_OK_FAIL_REQUEST(cmd_disconnect); |
you.chen | 186d3c3 | 2023-05-18 14:19:46 +0800 | [diff] [blame] | 3709 | system("echo \"\" > /tmp/wlan0_dhcpcd_router"); |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 3710 | usleep(200*1000); |
| 3711 | |
qs.xiong | 0956040 | 2023-10-27 21:58:55 +0800 | [diff] [blame] | 3712 | pthread_mutex_lock(&s_global_check_mutex); |
| 3713 | lynq_sta_removeElement(net_no); |
| 3714 | pthread_mutex_unlock(&s_global_check_mutex); |
| 3715 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 3716 | ret = inner_sta_start_stop(net_no, 1, 1); |
| 3717 | |
| 3718 | pthread_mutex_lock(&s_global_check_mutex); |
| 3719 | s_sta_status = INNER_STA_STATUS_CONNECTING; |
you.chen | 0c9bee2 | 2023-10-25 13:03:14 +0800 | [diff] [blame^] | 3720 | g_sta_conncet_status_flag = 1; |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 3721 | strcpy(s_sta_current_connecting_ssid, ssid); |
| 3722 | struct timeval now; |
| 3723 | gettimeofday(&now,NULL); |
you.chen | b95401e | 2023-05-12 19:39:06 +0800 | [diff] [blame] | 3724 | s_sta_connect_timeout.tv_sec = now.tv_sec + timeout; |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 3725 | s_sta_connect_timeout.tv_nsec = now.tv_usec*1000; |
| 3726 | pthread_cond_signal(&s_global_check_cond); |
| 3727 | pthread_mutex_unlock(&s_global_check_mutex); |
| 3728 | return ret; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 3729 | } |
| 3730 | |
you.chen | b95401e | 2023-05-12 19:39:06 +0800 | [diff] [blame] | 3731 | int lynq_wifi_sta_connect(lynq_wifi_index_e idx, char *ssid, lynq_wifi_auth_s auth, char *psw) |
| 3732 | { |
| 3733 | return lynq_wifi_sta_connect_timeout(idx, ssid, auth, psw, MAX_CONNNECT_TIME); |
| 3734 | } |
| 3735 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3736 | int lynq_wifi_sta_disconnect(lynq_wifi_index_e idx, char *ssid) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 3737 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3738 | ap_info_s ap; |
| 3739 | curr_status_info curr_state; |
| 3740 | ap.ap_ssid[0] = '\0'; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 3741 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3742 | if (ssid == NULL || *ssid == '\0') |
| 3743 | { |
| 3744 | RLOGE("input ssid is NULL\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3745 | return -1; |
| 3746 | } |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 3747 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3748 | CHECK_IDX(idx, CTRL_STA); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 3749 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3750 | curr_state.ap = ≈ |
you.chen | b4b121c | 2022-05-06 17:50:16 +0800 | [diff] [blame] | 3751 | curr_state.state = NULL; |
| 3752 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3753 | if (inner_get_status_info(CTRL_STA, &curr_state) != 0) |
| 3754 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3755 | return 0; |
| 3756 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 3757 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3758 | if (strcmp(ap.ap_ssid, ssid) != 0) |
| 3759 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3760 | return 0; |
| 3761 | } |
| 3762 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 3763 | pthread_mutex_lock(&s_global_check_mutex); |
| 3764 | s_sta_status = INNER_STA_STATUS_DISCONNECTING; |
| 3765 | pthread_mutex_unlock(&s_global_check_mutex); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3766 | return inner_sta_start_stop(curr_state.net_no, 0, 0); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 3767 | } |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 3768 | |
qs.xiong | c93bf2b | 2023-08-25 10:22:08 +0800 | [diff] [blame] | 3769 | int lynq_wifi_sta_disconnect_ap(lynq_wifi_index_e idx, char *ssid) |
| 3770 | { |
qs.xiong | 0956040 | 2023-10-27 21:58:55 +0800 | [diff] [blame] | 3771 | int i,check_history_idx_flag; |
qs.xiong | c93bf2b | 2023-08-25 10:22:08 +0800 | [diff] [blame] | 3772 | ap_info_s ap; |
| 3773 | curr_status_info curr_state; |
| 3774 | ap.ap_ssid[0] = '\0'; |
qs.xiong | 0956040 | 2023-10-27 21:58:55 +0800 | [diff] [blame] | 3775 | check_history_idx_flag = 0; |
qs.xiong | c93bf2b | 2023-08-25 10:22:08 +0800 | [diff] [blame] | 3776 | |
| 3777 | if (ssid == NULL || *ssid == '\0') |
| 3778 | { |
| 3779 | RLOGE("input ssid is NULL\n"); |
| 3780 | return -1; |
| 3781 | } |
| 3782 | |
| 3783 | CHECK_IDX(idx, CTRL_STA); |
| 3784 | |
| 3785 | |
| 3786 | curr_state.ap = ≈ |
| 3787 | curr_state.state = NULL; |
| 3788 | |
| 3789 | if (inner_get_status_info(CTRL_STA, &curr_state) != 0) |
| 3790 | { |
| 3791 | return 0; |
| 3792 | } |
| 3793 | |
| 3794 | if (strcmp(ap.ap_ssid, ssid) != 0) |
| 3795 | { |
| 3796 | return 0; |
| 3797 | } |
| 3798 | |
| 3799 | pthread_mutex_lock(&s_global_check_mutex); |
| 3800 | s_sta_status = INNER_STA_STATUS_DISCONNECTING; |
qs.xiong | 0956040 | 2023-10-27 21:58:55 +0800 | [diff] [blame] | 3801 | RLOGD("WIFI[lynq_wifi_sta_disconnect_ap]g_history_disconnect_valid_num is %d",g_history_disconnect_valid_num); |
| 3802 | for( i = 0; i< g_history_disconnect_valid_num ; i++) |
| 3803 | { |
| 3804 | RLOGD("WIFI[lynq_wifi_sta_disconnect_ap]g_history_disconnect_net[%d] is %d,current disconnet network is %d",i,g_history_disconnect_net[i],curr_state.net_no); |
| 3805 | if( g_history_disconnect_net[i] == curr_state.net_no) |
| 3806 | { |
| 3807 | RLOGD("current disconenct ap idx is %d && last aready into g_history_disconenct_net",curr_state.net_no); |
| 3808 | check_history_idx_flag = 1; |
| 3809 | break; |
| 3810 | } |
| 3811 | } |
| 3812 | if ( check_history_idx_flag == 0) |
| 3813 | { |
| 3814 | RLOGD("current need add ap idx is %d ,g_history_disconnect_valid_num is %d line %d",curr_state.net_no,g_history_disconnect_valid_num,__LINE__); |
| 3815 | g_history_disconnect_net[g_history_disconnect_valid_num] = curr_state.net_no; |
| 3816 | g_history_disconnect_valid_num++; |
| 3817 | } |
| 3818 | RLOGD("%s %d",__func__,__LINE__); |
| 3819 | print_disconnect_list(); |
qs.xiong | c93bf2b | 2023-08-25 10:22:08 +0800 | [diff] [blame] | 3820 | pthread_mutex_unlock(&s_global_check_mutex); |
| 3821 | return lynq_wifi_sta_stop_network(idx, curr_state.net_no); |
| 3822 | |
| 3823 | } |
| 3824 | |
| 3825 | |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 3826 | int lynq_wifi_sta_start(lynq_wifi_index_e idx) |
| 3827 | { |
qs.xiong | b37f8c4 | 2023-09-13 21:21:58 +0800 | [diff] [blame] | 3828 | |
qs.xiong | ad2f89d | 2023-01-18 13:17:41 +0800 | [diff] [blame] | 3829 | const char *lynq_enable_sta_cmd = "wpa_cli -iwpa_wlan0_cmd -p/var/run/ IFNAME=wlan0 enable_net all"; |
| 3830 | const char *lynq_reconnect_cmd = "wpa_cli -iwpa_wlan0_cmd -p/var/run/ IFNAME=wlan0 reconnect"; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 3831 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3832 | CHECK_IDX(idx, CTRL_STA); |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 3833 | CHECK_WPA_CTRL(CTRL_STA); |
| 3834 | |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 3835 | ret = system_call_v("%s %s", start_stop_sta_script, "start"); |
| 3836 | if (ret != 0) |
qs.xiong | ad2f89d | 2023-01-18 13:17:41 +0800 | [diff] [blame] | 3837 | { |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 3838 | RLOGE("lynq_wifi_ap_start excute script fail"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3839 | return -1; |
| 3840 | } |
qs.xiong | 9c99fa9 | 2022-03-15 08:03:26 -0400 | [diff] [blame] | 3841 | |
qs.xiong | ad2f89d | 2023-01-18 13:17:41 +0800 | [diff] [blame] | 3842 | system(lynq_enable_sta_cmd); |
| 3843 | system(lynq_reconnect_cmd); |
qs.xiong | b37f8c4 | 2023-09-13 21:21:58 +0800 | [diff] [blame] | 3844 | pthread_mutex_lock(&s_global_check_mutex); |
| 3845 | g_history_disconnect_valid_num = 0; //clean history_disconenct_list info |
you.chen | 6e72416 | 2023-10-19 19:10:01 +0800 | [diff] [blame] | 3846 | s_sta_status = INNER_STA_STATUS_INIT; |
qs.xiong | b37f8c4 | 2023-09-13 21:21:58 +0800 | [diff] [blame] | 3847 | pthread_mutex_unlock(&s_global_check_mutex); |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 3848 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 3849 | } |
| 3850 | |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 3851 | static int inner_get_status_info_state (int interface, char *state) { |
| 3852 | curr_status_info curr_state; |
| 3853 | curr_state.ap = NULL; |
| 3854 | curr_state.state = state; |
| 3855 | return inner_get_status_info(interface, &curr_state); |
| 3856 | } |
qs.xiong | c93bf2b | 2023-08-25 10:22:08 +0800 | [diff] [blame] | 3857 | |
| 3858 | int lynq_wifi_sta_start_auto(lynq_wifi_index_e idx) |
| 3859 | { |
| 3860 | |
qs.xiong | b37f8c4 | 2023-09-13 21:21:58 +0800 | [diff] [blame] | 3861 | RLOGD("[wifi]enter lynq_wifi_sta_start_auto start"); |
| 3862 | int tmp_open_idx[128]; |
| 3863 | int len; |
qs.xiong | c93bf2b | 2023-08-25 10:22:08 +0800 | [diff] [blame] | 3864 | |
qs.xiong | b37f8c4 | 2023-09-13 21:21:58 +0800 | [diff] [blame] | 3865 | pthread_mutex_lock(&s_global_check_mutex); |
you.chen | 6e72416 | 2023-10-19 19:10:01 +0800 | [diff] [blame] | 3866 | s_sta_status = INNER_STA_STATUS_INIT; |
qs.xiong | b37f8c4 | 2023-09-13 21:21:58 +0800 | [diff] [blame] | 3867 | lynq_two_arr_merge(g_history_disconnect_net,g_history_disconnect_valid_num,tmp_open_idx,&len); |
| 3868 | pthread_mutex_unlock(&s_global_check_mutex); |
| 3869 | if(lynq_tmp_enable_network(idx,tmp_open_idx,len) != 0 ) |
qs.xiong | c93bf2b | 2023-08-25 10:22:08 +0800 | [diff] [blame] | 3870 | { |
qs.xiong | b37f8c4 | 2023-09-13 21:21:58 +0800 | [diff] [blame] | 3871 | RLOGD("[wifi]lynq_tmp_enable_network error"); |
qs.xiong | c93bf2b | 2023-08-25 10:22:08 +0800 | [diff] [blame] | 3872 | } |
| 3873 | |
qs.xiong | b37f8c4 | 2023-09-13 21:21:58 +0800 | [diff] [blame] | 3874 | RLOGD("[wifi]enter lynq_wifi_sta_start_auto end"); |
qs.xiong | c93bf2b | 2023-08-25 10:22:08 +0800 | [diff] [blame] | 3875 | return 0; |
| 3876 | } |
| 3877 | |
| 3878 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3879 | int lynq_wifi_sta_stop(lynq_wifi_index_e idx) |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 3880 | { |
qs.xiong | ad2f89d | 2023-01-18 13:17:41 +0800 | [diff] [blame] | 3881 | // char lynq_disable_network_cmd[MAX_CMD]; |
| 3882 | // curr_status_info curr_state; |
| 3883 | // ap_info_s ap_info; |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 3884 | int i=0; |
| 3885 | char state[MAX_CMD]; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3886 | |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 3887 | // 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] | 3888 | CHECK_IDX(idx, CTRL_STA); |
| 3889 | CHECK_WPA_CTRL(CTRL_STA); |
| 3890 | |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 3891 | // system(lynq_disable_sta_cmd); |
| 3892 | DO_OK_FAIL_REQUEST(cmd_disconnect); |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 3893 | DO_OK_FAIL_REQUEST(cmd_save_config); |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 3894 | |
| 3895 | ret = system_call_v("%s %s", start_stop_sta_script, "stop"); |
| 3896 | if (ret != 0) |
| 3897 | { |
| 3898 | RLOGE("lynq_wifi_ap_start excute script fail"); |
| 3899 | return -1; |
| 3900 | } |
| 3901 | |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 3902 | for (i=0; i < 30; i++) // to check if sta is realy stoped |
| 3903 | { |
| 3904 | if (inner_get_status_info_state(idx, state) != 0) |
| 3905 | { |
| 3906 | break; |
| 3907 | } |
| 3908 | |
| 3909 | if (memcmp(state, STATE_DISCONNECTED, strlen (STATE_DISCONNECTED)) == 0) |
| 3910 | { |
| 3911 | break; |
| 3912 | } |
| 3913 | RLOGD("lynq_wifi_ap_start curr state %s", state); |
| 3914 | usleep(SLEEP_TIME_ON_IDLE); |
| 3915 | } |
qs.xiong | b37f8c4 | 2023-09-13 21:21:58 +0800 | [diff] [blame] | 3916 | pthread_mutex_lock(&s_global_check_mutex); |
| 3917 | g_history_disconnect_valid_num = 0; //clean history_disconenct_list info |
| 3918 | pthread_mutex_unlock(&s_global_check_mutex); |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 3919 | return 0; |
| 3920 | // return system("connmanctl disable wifi"); |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 3921 | } |
qs.xiong | fcc914b | 2023-07-06 21:16:20 +0800 | [diff] [blame] | 3922 | int lynq_wifi_sta_stop_net(lynq_wifi_index_e idx,int networkid) |
| 3923 | { |
| 3924 | char LYNQ_DISABLE_CMD[128]={0}; |
| 3925 | CHECK_IDX(idx, CTRL_STA); |
| 3926 | CHECK_WPA_CTRL(CTRL_STA); |
| 3927 | sprintf(LYNQ_DISABLE_CMD,"DISABLE_NETWORK %d",networkid); |
| 3928 | RLOGD("LYNQ_DISABLE_CMD is:%d\n",LYNQ_DISABLE_CMD); |
| 3929 | DO_OK_FAIL_REQUEST(LYNQ_DISABLE_CMD); |
| 3930 | return 0; |
| 3931 | } |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 3932 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3933 | //static int inner_get_sta_info(lynq_wifi_index_e idx, const char * bssid, device_info_s *dev) { |
| 3934 | // int i, count; |
| 3935 | // char *p; |
| 3936 | // const char * FLAG_SSID = "ssid="; |
| 3937 | // const char * FLAG_SBSID = "bssid="; |
| 3938 | // const char * FLAG_KEY_MGMT = "key_mgmt="; |
| 3939 | // const char * FLAG_FREQ = "freq="; |
| 3940 | // char lynq_sta_cmd[MAX_CMD]; |
| 3941 | // char *split_lines[128] = {0}; |
| 3942 | |
| 3943 | // CHECK_WPA_CTRL(CTRL_AP); |
| 3944 | |
| 3945 | // sprintf(lynq_sta_cmd, "STA %s", bssid); |
| 3946 | |
| 3947 | // DO_REQUEST(lynq_sta_cmd); |
| 3948 | |
| 3949 | // count = lynq_split(cmd_reply, reply_len, '\n', split_lines); |
| 3950 | |
| 3951 | // for(i=0; i < count; i++) { |
| 3952 | // p = strstr(split_lines[i], FLAG_SSID); |
| 3953 | // if (p != NULL) { |
| 3954 | // strcpy(ap->ap_ssid, p + strlen(FLAG_SSID)); |
| 3955 | // continue; |
| 3956 | // } |
| 3957 | // } |
| 3958 | |
| 3959 | // lynq_get_interface_ip(idx, ap->ap_ip); |
| 3960 | // lynq_ap_password_set(idx, ap->psw); |
| 3961 | |
| 3962 | // return 0; |
| 3963 | //} |
| 3964 | |
| 3965 | static int inner_get_status_info_ap (int interface, ap_info_s *ap) { |
| 3966 | curr_status_info curr_state; |
| 3967 | curr_state.ap = ap; |
| 3968 | curr_state.state = NULL; |
| 3969 | return inner_get_status_info(interface, &curr_state); |
| 3970 | } |
| 3971 | |
| 3972 | 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] | 3973 | { |
qs.xiong | 5071c80 | 2023-09-06 14:04:15 +0800 | [diff] [blame] | 3974 | RLOGD("[wifi]-----enter lynq_get_ap_device_list"); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 3975 | int index, line_count; |
| 3976 | device_info_s *dev_info; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3977 | const char *lynq_first_sta_cmd = "STA-FIRST"; |
| 3978 | char lynq_next_sta_cmd[MAX_CMD]; |
| 3979 | char *bssid[1024] = {0}; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3980 | char *split_lines[128] = {0}; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 3981 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3982 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 3983 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3984 | CHECK_WPA_CTRL(CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 3985 | |
you.chen | b95401e | 2023-05-12 19:39:06 +0800 | [diff] [blame] | 3986 | // ap_info_s * tmp_ap; |
| 3987 | // device_info_s * tmp_list; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3988 | if (ap == NULL || list == NULL || len == NULL) |
| 3989 | { |
| 3990 | RLOGE("bad input param"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3991 | return -1; |
| 3992 | } |
| 3993 | |
you.chen | b95401e | 2023-05-12 19:39:06 +0800 | [diff] [blame] | 3994 | // ap = &tmp_ap; |
| 3995 | // list = &tmp_list; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3996 | *ap = malloc(sizeof (ap_info_s)); |
you.chen | b95401e | 2023-05-12 19:39:06 +0800 | [diff] [blame] | 3997 | memset(*ap, 0, sizeof (ap_info_s)); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3998 | |
you.chen | b95401e | 2023-05-12 19:39:06 +0800 | [diff] [blame] | 3999 | if (inner_get_status_info_ap (CTRL_AP, *ap) != 0 || (*ap)->ap_ssid[0] == '\0') |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4000 | { |
you.chen | b95401e | 2023-05-12 19:39:06 +0800 | [diff] [blame] | 4001 | RLOGE("inner_get_status_info_ap !=0 or ap_ssid is empty\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4002 | return -1; |
| 4003 | } |
| 4004 | |
| 4005 | lynq_get_interface_ip(idx, (*ap)->ap_ip); |
| 4006 | lynq_ap_password_get(idx, (*ap)->psw); |
| 4007 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4008 | DO_REQUEST(lynq_first_sta_cmd); |
| 4009 | |
| 4010 | index = 0; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4011 | while (reply_len > 0) |
| 4012 | { |
| 4013 | if (memcmp(cmd_reply, "FAIL", 4) == 0) |
you.chen | b95401e | 2023-05-12 19:39:06 +0800 | [diff] [blame] | 4014 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4015 | break; |
| 4016 | } |
| 4017 | line_count = lynq_split(cmd_reply, reply_len, '\n', split_lines); |
| 4018 | bssid[index] = malloc(strlen(split_lines[0]) + 1); |
| 4019 | strcpy(bssid[index], split_lines[0]); |
| 4020 | index++; |
| 4021 | sprintf(lynq_next_sta_cmd, "STA-NEXT %s", split_lines[0]); |
| 4022 | reply_len = MAX_RET; |
| 4023 | cmd_reply[0] = '\0'; |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 4024 | 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] | 4025 | if (ret != 0 || memcmp(cmd_reply, "FAIL", 4) == 0) |
you.chen | b95401e | 2023-05-12 19:39:06 +0800 | [diff] [blame] | 4026 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4027 | RLOGD("run %s fail \n", lynq_next_sta_cmd); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4028 | break; |
| 4029 | } |
| 4030 | } |
| 4031 | |
| 4032 | *len = index; |
| 4033 | |
| 4034 | *list = malloc(sizeof(device_info_s) * (*len)); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4035 | for (index=0; index < *len; index++) |
| 4036 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 4037 | dev_info = &(*list)[index]; |
| 4038 | memset(dev_info, 0, sizeof(device_info_s)); |
| 4039 | strncpy(dev_info->sta_mac, bssid[index], sizeof (dev_info->sta_mac)); |
| 4040 | inner_get_ip_by_mac(dev_info->sta_mac, dev_info->sta_ip, sizeof (dev_info->sta_ip)); |
| 4041 | inner_get_hostname_by_ip(dev_info->sta_ip, dev_info->hostname); |
| 4042 | dev_info->status = LYNQ_WIFI_STATUS_CONNECT; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4043 | free(bssid[index]); |
| 4044 | } |
qs.xiong | 5071c80 | 2023-09-06 14:04:15 +0800 | [diff] [blame] | 4045 | RLOGD("[wifi]-----end lynq_get_ap_device_list"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4046 | return 0; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 4047 | } |
| 4048 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4049 | 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] | 4050 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4051 | int i, count, index, count_words; |
| 4052 | const char *lynq_scan_result_cmd = "SCAN_RESULTS"; |
| 4053 | char *split_lines[128] = {0}; |
| 4054 | char *split_words[128] = {0}; |
| 4055 | scan_info_s * p; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 4056 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4057 | if (list == NULL || len == NULL) |
| 4058 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4059 | return -1; |
| 4060 | } |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 4061 | |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 4062 | for (i =0; i < 50 && g_sta_scan_finish_flag == 0; i++) |
| 4063 | { |
| 4064 | usleep(100 * 1000); |
| 4065 | } |
| 4066 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4067 | CHECK_IDX(idx, CTRL_STA); |
| 4068 | |
| 4069 | CHECK_WPA_CTRL(CTRL_STA); |
| 4070 | |
| 4071 | DO_REQUEST(lynq_scan_result_cmd); |
| 4072 | |
| 4073 | count = lynq_split(cmd_reply, reply_len, '\n', split_lines); |
| 4074 | *len = count - 1; |
| 4075 | *list = malloc(sizeof (scan_info_s) * *len); |
| 4076 | |
| 4077 | 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] | 4078 | for (index=0; index <count_words; index++) |
| 4079 | { |
| 4080 | RLOGD("----header: %s\n", split_words[index]); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4081 | } |
| 4082 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4083 | for(index = 1;index < count; index++) |
| 4084 | { |
| 4085 | RLOGD("---- %s\n",split_lines[index]); |
you.chen | 6ed36a6 | 2023-04-27 17:51:56 +0800 | [diff] [blame] | 4086 | memset(split_words, 0 , sizeof (split_words)); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4087 | count_words = lynq_split(split_lines[index], strlen(split_lines[index]), '\t', split_words); |
| 4088 | if (count_words < 4) |
| 4089 | continue; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4090 | RLOGD("count: %d, %s\n", count_words, split_words[0]); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4091 | //bssid / frequency / signal level / flags / ssid |
| 4092 | p = (*list) + index - 1; |
| 4093 | strcpy(p->mac, split_words[0]); |
| 4094 | p->band = convert_band_from_freq(atoi(split_words[1])); |
| 4095 | p->rssi = -1 * atoi( split_words[2]); |
| 4096 | p->auth = convert_max_auth_from_flag(split_words[3]); |
you.chen | 6ed36a6 | 2023-04-27 17:51:56 +0800 | [diff] [blame] | 4097 | if (count_words == 4) // ssid hided |
| 4098 | { |
| 4099 | p->ssid[0] = '\0'; |
| 4100 | } |
| 4101 | else |
| 4102 | { |
| 4103 | inner_copy_ssid(p->ssid, split_words[4], sizeof (p->ssid)); |
| 4104 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4105 | } |
| 4106 | |
| 4107 | return 0; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 4108 | } |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 4109 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4110 | int lynq_sta_forget_ap(lynq_wifi_index_e idx, char *ssid, lynq_wifi_auth_s auth) |
| 4111 | { |
| 4112 | int count, net_no, index; |
| 4113 | int net_no_list[128]; |
| 4114 | lynq_wifi_auth_s net_auth; |
qs.xiong | 0956040 | 2023-10-27 21:58:55 +0800 | [diff] [blame] | 4115 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4116 | char lynq_remove_cmd[MAX_CMD]; |
| 4117 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4118 | if (ssid == NULL || *ssid == '\0') |
| 4119 | { |
| 4120 | RLOGD("bad ssid\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4121 | return -1; |
| 4122 | } |
| 4123 | |
| 4124 | CHECK_IDX(idx, CTRL_STA); |
| 4125 | |
| 4126 | CHECK_WPA_CTRL(CTRL_STA); |
| 4127 | |
| 4128 | net_no = -1; |
| 4129 | count = lynq_get_network_number_list(idx, CTRL_STA, net_no_list, ssid); |
| 4130 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4131 | for (index=0; index < count; index++) |
| 4132 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4133 | net_auth = -1; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4134 | if (0 == inner_get_network_auth(CTRL_STA, net_no_list[index], &net_auth) && net_auth == auth) |
| 4135 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4136 | net_no = net_no_list[index]; |
| 4137 | break; |
| 4138 | } |
| 4139 | } |
| 4140 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4141 | if (net_no < 0) |
| 4142 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4143 | return 0; |
| 4144 | } |
| 4145 | |
| 4146 | sprintf(lynq_remove_cmd, "REMOVE_NETWORK %d", net_no); |
| 4147 | |
| 4148 | DO_OK_FAIL_REQUEST(lynq_remove_cmd); |
qs.xiong | 0956040 | 2023-10-27 21:58:55 +0800 | [diff] [blame] | 4149 | |
| 4150 | RLOGD("WIFI[lynq_sta_forget_ap][check_history_disconenct_ap_list] input net_no is %d",net_no); |
| 4151 | |
| 4152 | pthread_mutex_lock(&s_global_check_mutex); |
| 4153 | lynq_sta_removeElement(net_no); |
| 4154 | pthread_mutex_unlock(&s_global_check_mutex); |
| 4155 | |
| 4156 | RLOGD("%s %d",__func__,__LINE__); |
| 4157 | print_disconnect_list(); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4158 | DO_OK_FAIL_REQUEST(cmd_save_config); |
| 4159 | |
| 4160 | return 0; |
| 4161 | } |
| 4162 | |
| 4163 | 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] | 4164 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 4165 | int count, index; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4166 | int net_no_list[128]; |
| 4167 | char freq[16]; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4168 | RLOGD("enter lynq_get_sta_saved_ap api\n"); |
| 4169 | if (list == NULL || len == NULL) |
| 4170 | { |
| 4171 | RLOGE("bad param,please check!"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4172 | return -1; |
| 4173 | } |
| 4174 | |
| 4175 | CHECK_IDX(idx, CTRL_STA); |
| 4176 | |
| 4177 | // CHECK_WPA_CTRL(CTRL_STA); |
| 4178 | |
| 4179 | 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] | 4180 | RLOGD("[lynq_get_sta_saved_ap]count is %d\n", count); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4181 | |
you.chen | 057aac4 | 2023-04-13 14:06:58 +0800 | [diff] [blame] | 4182 | if (count < 0) |
| 4183 | { |
| 4184 | RLOGE("list network fail"); |
| 4185 | return count; |
| 4186 | } |
| 4187 | else if (count == 0) |
| 4188 | { |
| 4189 | *list = NULL; |
| 4190 | *len = 0; |
| 4191 | return 0; |
| 4192 | } |
| 4193 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4194 | *list = malloc(sizeof (saved_ap_info_s) * count); |
you.chen | 755332b | 2022-08-06 16:59:10 +0800 | [diff] [blame] | 4195 | memset(*list, 0, sizeof (saved_ap_info_s) * count); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4196 | *len = count; |
| 4197 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4198 | for (index=0; index < count; index++) |
| 4199 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4200 | 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] | 4201 | 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] | 4202 | 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] | 4203 | 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] | 4204 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4205 | (*list)[index].base_info.band = convert_band_from_freq(atoi(freq)); |
| 4206 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4207 | else |
you.chen | 057aac4 | 2023-04-13 14:06:58 +0800 | [diff] [blame] | 4208 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4209 | (*list)[index].base_info.band = -1; |
| 4210 | } |
you.chen | 057aac4 | 2023-04-13 14:06:58 +0800 | [diff] [blame] | 4211 | RLOGD("[lynq_get_sta_saved_ap][inner_get_param]to get psw"); |
you.chen | 755332b | 2022-08-06 16:59:10 +0800 | [diff] [blame] | 4212 | 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] | 4213 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4214 | RLOGD("[lynq_get_sta_saved_ap] return ok"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4215 | return 0; |
| 4216 | } |
| 4217 | |
| 4218 | int lynq_wifi_sta_start_scan(lynq_wifi_index_e idx) |
| 4219 | { |
you.chen | 0c9bee2 | 2023-10-25 13:03:14 +0800 | [diff] [blame^] | 4220 | if ( s_sta_status == INNER_STA_STATUS_INIT && g_sta_conncet_status_flag != 0 ) |
qs.xiong | 2020242 | 2023-09-06 18:01:18 +0800 | [diff] [blame] | 4221 | { |
you.chen | 0c9bee2 | 2023-10-25 13:03:14 +0800 | [diff] [blame^] | 4222 | RLOGD("current sta is autoconnecting dest ap,fake scan result"); |
| 4223 | g_sta_fake_scan_finish_flag = 1; |
| 4224 | return 0; |
| 4225 | } |
| 4226 | else if (g_sta_conncet_status_flag != 0) |
| 4227 | { |
| 4228 | RLOGD("current sta is connecting dest ap, don't scan"); |
qs.xiong | ba5b5f2 | 2023-09-19 14:55:34 +0800 | [diff] [blame] | 4229 | return 1; |
qs.xiong | 2020242 | 2023-09-06 18:01:18 +0800 | [diff] [blame] | 4230 | } |
you.chen | 0c9bee2 | 2023-10-25 13:03:14 +0800 | [diff] [blame^] | 4231 | |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 4232 | 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] | 4233 | const char *lynq_scan_cmd = "SCAN"; |
| 4234 | |
| 4235 | CHECK_IDX(idx, CTRL_STA); |
| 4236 | |
| 4237 | CHECK_WPA_CTRL(CTRL_STA); |
| 4238 | |
you.chen | 0df3e7e | 2023-05-10 15:56:26 +0800 | [diff] [blame] | 4239 | if (g_sta_scan_finish_flag == 1 && s_sta_status == INNER_STA_STATUS_INIT) // temp add |
| 4240 | { |
| 4241 | RLOGD("tmp clear scanlist"); |
| 4242 | system(clean_last_re); |
| 4243 | } |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 4244 | g_sta_scan_finish_flag = 0; |
qs.xiong | b3f26af | 2023-02-17 18:41:07 +0800 | [diff] [blame] | 4245 | DO_REQUEST(lynq_scan_cmd); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4246 | if (reply_len >=9 && memcmp(cmd_reply, "FAIL-BUSY", 9) == 0 ) |
| 4247 | { |
qs.xiong | b3f26af | 2023-02-17 18:41:07 +0800 | [diff] [blame] | 4248 | return 0; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4249 | } else if (reply_len >=2 && memcmp(cmd_reply, "OK", 2) != 0) |
| 4250 | { |
qs.xiong | b3f26af | 2023-02-17 18:41:07 +0800 | [diff] [blame] | 4251 | g_sta_scan_finish_flag = 1; |
| 4252 | return -1; |
| 4253 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4254 | |
| 4255 | return 0; |
| 4256 | } |
| 4257 | |
| 4258 | 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] | 4259 | if (cb == NULL) |
| 4260 | { |
| 4261 | RLOGE("lynq_reg_ap_event_callback ptr is NULL,plese check!\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4262 | return -1; |
| 4263 | } |
| 4264 | |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 4265 | pthread_mutex_lock(&s_ap_callback_mutex); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4266 | g_ap_callback_priv = priv; |
| 4267 | g_ap_callback_func = cb; |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 4268 | pthread_mutex_unlock(&s_ap_callback_mutex); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4269 | |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 4270 | pthread_mutex_lock(&s_check_wpa_ctrl_mutex); |
you.chen | e9d0003 | 2023-04-24 13:55:29 +0800 | [diff] [blame] | 4271 | if (g_ap_watcher_pid == 0 ) |
| 4272 | { |
| 4273 | if(pthread_create(&g_ap_watcher_pid,NULL,APWatcherThreadProc,NULL) < 0) |
| 4274 | { |
| 4275 | g_ap_watcher_pid = 0; |
| 4276 | pthread_mutex_unlock(&s_check_wpa_ctrl_mutex); |
| 4277 | RLOGE("[wifi error]creat APWatcherThreadProc fail"); |
| 4278 | return -1; |
| 4279 | } |
| 4280 | } |
| 4281 | |
| 4282 | pthread_mutex_unlock(&s_check_wpa_ctrl_mutex); |
| 4283 | RLOGD("creat APWatcherTheradProc susccs"); |
| 4284 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4285 | return 0; |
| 4286 | } |
| 4287 | |
| 4288 | int lynq_unreg_ap_event_callback(void * priv) { |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 4289 | pthread_mutex_lock(&s_ap_callback_mutex); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4290 | if (g_ap_callback_priv == priv) |
| 4291 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4292 | g_ap_callback_func = NULL; |
| 4293 | g_ap_callback_priv = NULL; |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 4294 | pthread_mutex_unlock(&s_ap_callback_mutex); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4295 | return 0; |
| 4296 | } |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 4297 | pthread_mutex_unlock(&s_ap_callback_mutex); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4298 | return -1; |
| 4299 | } |
| 4300 | |
| 4301 | 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] | 4302 | if (cb == NULL) |
| 4303 | { |
| 4304 | RLOGE("lynq_reg_sta_event_callback ptr is NULL,plese check!\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4305 | return -1; |
| 4306 | } |
| 4307 | |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 4308 | pthread_mutex_lock(&s_sta_callback_mutex); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4309 | g_sta_callback_priv = priv; |
| 4310 | g_sta_callback_func = cb; |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 4311 | pthread_mutex_unlock(&s_sta_callback_mutex); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4312 | |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 4313 | pthread_mutex_lock(&s_check_wpa_ctrl_mutex); |
you.chen | e9d0003 | 2023-04-24 13:55:29 +0800 | [diff] [blame] | 4314 | if (g_sta_watcher_pid == 0 ) { |
| 4315 | if(pthread_create(&g_sta_watcher_pid,NULL,STAWatcherThreadProc,NULL) < 0) |
| 4316 | { |
| 4317 | g_sta_watcher_pid = 0; |
| 4318 | pthread_mutex_unlock(&s_check_wpa_ctrl_mutex); |
| 4319 | RLOGE("[wifi error]creat STAWatcherThreadProc fail"); |
| 4320 | return -1; |
| 4321 | } |
| 4322 | } |
| 4323 | |
| 4324 | pthread_mutex_unlock(&s_check_wpa_ctrl_mutex); |
| 4325 | RLOGD("creat STAWatcherTheradProc susccs"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4326 | return 0; |
| 4327 | } |
| 4328 | |
| 4329 | int lynq_unreg_sta_event_callback(void * priv) { |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 4330 | pthread_mutex_lock(&s_sta_callback_mutex); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4331 | if (g_sta_callback_priv == priv) |
| 4332 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4333 | g_sta_callback_func = NULL; |
| 4334 | g_sta_callback_priv = NULL; |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 4335 | pthread_mutex_unlock(&s_sta_callback_mutex); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4336 | return 0; |
| 4337 | } |
you.chen | 6d24705 | 2023-06-01 16:39:54 +0800 | [diff] [blame] | 4338 | pthread_mutex_unlock(&s_sta_callback_mutex); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4339 | return -1; |
| 4340 | } |
| 4341 | |
qs.xiong | fcc914b | 2023-07-06 21:16:20 +0800 | [diff] [blame] | 4342 | int lynq_reg_sta_auto_event_callback(void * priv, STA_AUTO_CALLBACK_FUNC_PTR cb){ |
| 4343 | if (cb == NULL) |
| 4344 | { |
| 4345 | RLOGE("lynq_reg_sta_auto_event_callback ptr is NULL,plese check!\n"); |
| 4346 | return -1; |
| 4347 | } |
| 4348 | pthread_mutex_lock(&s_sta_auto_callback_mutex); |
| 4349 | g_sta_auto_callback_priv = priv; |
| 4350 | g_sta_auto_callback_func = cb; |
| 4351 | pthread_mutex_unlock(&s_sta_auto_callback_mutex); |
| 4352 | pthread_mutex_lock(&s_check_wpa_ctrl_mutex); |
| 4353 | if (g_sta_auto_watcher_pid == 0 ) { |
| 4354 | if(pthread_create(&g_sta_auto_watcher_pid,NULL,STAAutoWatcherThreadProc,NULL) < 0) //create STAAutoWatcherThreadProc |
| 4355 | { |
| 4356 | g_sta_auto_watcher_pid = 0; |
| 4357 | pthread_mutex_unlock(&s_check_wpa_ctrl_mutex); |
| 4358 | RLOGE("[wifi error]creat STAWatcherThreadProc fail"); |
| 4359 | return -1; |
| 4360 | } |
| 4361 | } |
| 4362 | pthread_mutex_unlock(&s_check_wpa_ctrl_mutex); |
| 4363 | RLOGD("creat STAWatcherTheradProc susccs"); |
| 4364 | return 0; |
| 4365 | } |
| 4366 | int lynq_unreg_sta_auto_event_callback(void * priv) { |
| 4367 | pthread_mutex_lock(&s_sta_auto_callback_mutex); |
| 4368 | if (g_sta_auto_callback_priv == priv) |
| 4369 | { |
| 4370 | g_sta_auto_watcher_stop_flag = 1; |
| 4371 | if (g_sta_auto_watcher_pid != 0) |
| 4372 | { |
| 4373 | pthread_join(g_sta_auto_watcher_pid, NULL); |
| 4374 | } |
| 4375 | g_sta_auto_watcher_pid = 0; |
| 4376 | g_sta_auto_callback_func = NULL; |
| 4377 | g_sta_auto_callback_priv = NULL; |
| 4378 | pthread_mutex_unlock(&s_sta_auto_callback_mutex); |
| 4379 | return 0; |
| 4380 | } |
| 4381 | pthread_mutex_unlock(&s_sta_auto_callback_mutex); |
| 4382 | return -1; |
| 4383 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4384 | int lynq_get_ap_status(lynq_wifi_index_e idx, lynq_wifi_ap_run_status_s * ap_status) |
| 4385 | { |
| 4386 | char state[MAX_CMD]; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4387 | RLOGD("enter lynq_get_ap_status\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4388 | CHECK_IDX(idx, CTRL_AP); |
| 4389 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4390 | if (inner_get_status_info_state(CTRL_AP, state) != 0) |
| 4391 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4392 | *ap_status = LYNQ_WIFI_AP_STATUS_DISABLE; |
| 4393 | return 0; |
| 4394 | } |
| 4395 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4396 | if (memcmp(state, STATE_COMPLETED, strlen (STATE_COMPLETED)) == 0) |
| 4397 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4398 | *ap_status = LYNQ_WIFI_AP_STATUS_ENABLE; |
| 4399 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4400 | else |
| 4401 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4402 | *ap_status = LYNQ_WIFI_AP_STATUS_DISABLE; |
| 4403 | } |
| 4404 | |
| 4405 | return 0; |
| 4406 | } |
| 4407 | |
| 4408 | int lynq_get_sta_status(lynq_wifi_index_e idx, lynq_wifi_sta_run_status_s * sta_status) { |
| 4409 | char state[MAX_CMD]; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4410 | RLOGD("enter lynq_get_sta_status\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4411 | CHECK_IDX(idx, CTRL_STA); |
| 4412 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4413 | if (inner_get_status_info_state(CTRL_STA, state) != 0) |
| 4414 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4415 | *sta_status = LYNQ_WIFI_STA_STATUS_DISABLE; |
| 4416 | return 0; |
| 4417 | } |
| 4418 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4419 | if (memcmp(state, STATE_COMPLETED, strlen (STATE_COMPLETED)) == 0) |
| 4420 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4421 | *sta_status = LYNQ_WIFI_STA_STATUS_ENABLE; |
| 4422 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4423 | else |
| 4424 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4425 | *sta_status = LYNQ_WIFI_STA_STATUS_DISABLE; |
| 4426 | } |
| 4427 | |
| 4428 | return 0; |
| 4429 | } |
| 4430 | |
| 4431 | int lynq_get_country_code(lynq_wifi_index_e idx, char * country_code) { |
| 4432 | // CHECK_IDX(idx, CTRL_AP); |
| 4433 | // int ret = 0; |
| 4434 | // size_t reply_len = MAX_RET; |
| 4435 | // char cmd_reply[MAX_RET]={0}; |
| 4436 | // const char * cmd_str = "GET country"; |
| 4437 | // struct wpa_ctrl *s_lynq_wpa_ctrl = NULL; |
| 4438 | // do{ |
| 4439 | // if (NULL == s_lynq_wpa_ctrl) { |
| 4440 | // s_lynq_wpa_ctrl = wpa_ctrl_open("/var/run/wpa_wlan0_cmd"); |
| 4441 | // if (NULL == s_lynq_wpa_ctrl ) { |
| 4442 | // printf("wpa_ctrl_open fail\n"); |
| 4443 | // return -1; |
| 4444 | // } |
| 4445 | // } |
| 4446 | // }while(0); |
| 4447 | |
| 4448 | // do { |
| 4449 | // reply_len = MAX_RET; |
| 4450 | // cmd_reply[0] = '\0'; |
| 4451 | // printf("to call [%s]\n", cmd_str); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 4452 | // 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] | 4453 | // if (ret != 0) { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4454 | // RLOGE("call ##cmd_str fail %d\n", ret); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4455 | // return ret; |
| 4456 | // } |
| 4457 | // cmd_reply[reply_len+1] = '\0'; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4458 | // RLOGD("cmd replay [ %s ]\n", cmd_reply); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4459 | // }while(0); |
| 4460 | |
| 4461 | FILE *fp; |
| 4462 | size_t i = 0; |
| 4463 | char lynq_cmd_ret[MAX_RET]={0}; |
| 4464 | |
| 4465 | // CHECK_IDX(idx, CTRL_AP); |
| 4466 | |
| 4467 | if((fp=popen("wl country","r"))==NULL) |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4468 | { |
| 4469 | perror("popen error!"); |
| 4470 | return -1; |
| 4471 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4472 | if((fread(lynq_cmd_ret,sizeof(lynq_cmd_ret),1,fp))<0) |
| 4473 | { |
| 4474 | perror("fread fail!"); |
| 4475 | return -1; |
| 4476 | } |
| 4477 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4478 | for(i=0; i < strlen(lynq_cmd_ret); i++) |
| 4479 | { |
| 4480 | if (lynq_cmd_ret[i] == ' ') |
| 4481 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4482 | lynq_cmd_ret[i] = '\0'; |
| 4483 | break; |
| 4484 | } |
| 4485 | } |
| 4486 | |
| 4487 | strcpy(country_code,lynq_cmd_ret); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4488 | RLOGD("---country code %s\n", country_code); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4489 | |
| 4490 | int ret=pclose(fp); |
| 4491 | if(ret==-1) |
| 4492 | { |
| 4493 | perror("close file faild"); |
| 4494 | } |
| 4495 | |
| 4496 | return 0; |
| 4497 | } |
| 4498 | |
qs.xiong | 44fac67 | 2023-08-29 16:15:55 +0800 | [diff] [blame] | 4499 | |
you.chen | 705a7ef | 2023-06-01 22:06:45 +0800 | [diff] [blame] | 4500 | static int check_and_init_uci_config(char * country_code) |
| 4501 | { |
| 4502 | FILE * fp; |
| 4503 | int is_different = 0; |
| 4504 | const char * check_uci_cmd ="uci show | grep lynq_wifi_country_code"; |
| 4505 | const char * create_uci_cmd ="uci set lynq_uci.lynq_wifi_country_code='lynq_wifi_country_code'"; |
| 4506 | const char * commit_uci_cmd ="uci commit"; |
| 4507 | char set_country_cmd[MAX_CMD]; |
| 4508 | char lynq_cmd_ret[MAX_CMD]={0}; |
xj | 3df9fd8 | 2023-06-01 20:50:02 +0800 | [diff] [blame] | 4509 | |
you.chen | 705a7ef | 2023-06-01 22:06:45 +0800 | [diff] [blame] | 4510 | sprintf(set_country_cmd, "uci set lynq_uci.lynq_wifi_country_code.code='%s'",country_code); |
qs.xiong | 62034bf | 2023-06-01 19:23:13 +0800 | [diff] [blame] | 4511 | |
you.chen | 705a7ef | 2023-06-01 22:06:45 +0800 | [diff] [blame] | 4512 | if (0 != system(check_uci_cmd)) |
qs.xiong | 62034bf | 2023-06-01 19:23:13 +0800 | [diff] [blame] | 4513 | { |
you.chen | 705a7ef | 2023-06-01 22:06:45 +0800 | [diff] [blame] | 4514 | if (0 != system(create_uci_cmd)) |
| 4515 | { |
| 4516 | RLOGE("creat_uci_cmd fail"); |
| 4517 | return -1; |
| 4518 | } |
| 4519 | is_different = 1; |
| 4520 | } |
| 4521 | |
| 4522 | if((fp=popen("uci get lynq_uci.lynq_wifi_country_code.code","r"))==NULL) |
| 4523 | { |
| 4524 | RLOGE("popen error!"); |
qs.xiong | 62034bf | 2023-06-01 19:23:13 +0800 | [diff] [blame] | 4525 | return -1; |
| 4526 | } |
| 4527 | |
you.chen | 705a7ef | 2023-06-01 22:06:45 +0800 | [diff] [blame] | 4528 | if((fread(lynq_cmd_ret,sizeof(lynq_cmd_ret),1,fp))<0 ) |
qs.xiong | 62034bf | 2023-06-01 19:23:13 +0800 | [diff] [blame] | 4529 | { |
you.chen | 705a7ef | 2023-06-01 22:06:45 +0800 | [diff] [blame] | 4530 | RLOGE("fread fail!"); |
| 4531 | fclose(fp); |
| 4532 | return -1; |
qs.xiong | 62034bf | 2023-06-01 19:23:13 +0800 | [diff] [blame] | 4533 | } |
| 4534 | |
you.chen | 705a7ef | 2023-06-01 22:06:45 +0800 | [diff] [blame] | 4535 | if ( strncmp(lynq_cmd_ret,country_code,2) != 0 ) |
| 4536 | { |
qs.xiong | 44fac67 | 2023-08-29 16:15:55 +0800 | [diff] [blame] | 4537 | RLOGE("get country code for uci %s,input cpuntry code is:%s\n",lynq_cmd_ret,country_code); |
you.chen | 705a7ef | 2023-06-01 22:06:45 +0800 | [diff] [blame] | 4538 | is_different = 1; |
| 4539 | } |
| 4540 | |
| 4541 | fclose(fp); |
| 4542 | |
| 4543 | if (is_different) |
| 4544 | { |
| 4545 | if ( 0 != system(set_country_cmd)) |
| 4546 | { |
| 4547 | RLOGE("set_country_cmd fail"); |
| 4548 | return -1; |
| 4549 | } |
| 4550 | if (0 != system(commit_uci_cmd)) |
| 4551 | { |
| 4552 | RLOGE("commmit fail"); |
| 4553 | } |
| 4554 | } |
| 4555 | |
| 4556 | return is_different; |
| 4557 | } |
| 4558 | |
| 4559 | int lynq_set_country_code(lynq_wifi_index_e idx, char * country_code) { |
| 4560 | char check_current_code[10]; |
| 4561 | const char * support_country[] = {"CN", "EU"}; |
| 4562 | |
| 4563 | int ret,is_different, i, cc_count; |
| 4564 | |
| 4565 | if (country_code == NULL || country_code[0] == '\0') |
| 4566 | { |
| 4567 | RLOGE("bad country code\n"); |
| 4568 | return -1; |
| 4569 | } |
| 4570 | |
| 4571 | cc_count = sizeof (support_country) / sizeof (char*); |
| 4572 | for(i=0; i < cc_count; i++) |
| 4573 | { |
| 4574 | if (strcmp(support_country[i], country_code) == 0) |
| 4575 | { |
| 4576 | break; |
| 4577 | } |
| 4578 | } |
| 4579 | |
| 4580 | if (i >= cc_count) |
| 4581 | { |
| 4582 | RLOGE("unspported country code %s\n", country_code); |
| 4583 | return -1; |
| 4584 | } |
| 4585 | |
| 4586 | is_different = check_and_init_uci_config(country_code); |
| 4587 | if( is_different < 0 ) |
| 4588 | { |
| 4589 | RLOGE("init set uci fail\n"); |
| 4590 | return -1; |
| 4591 | } |
| 4592 | |
| 4593 | ret = lynq_get_country_code(idx,check_current_code); |
| 4594 | if( ret == 0 && (is_different == 1 || strcmp(check_current_code, country_code) != 0)) |
| 4595 | { |
| 4596 | ret = lynq_wifi_disable(); |
| 4597 | if(ret != 0 ) |
| 4598 | { |
| 4599 | RLOGE("berfore set country,find bcmdhd insmod,remod fail\n"); |
| 4600 | return -1; |
| 4601 | } |
| 4602 | } |
| 4603 | |
| 4604 | return 0; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4605 | } |
| 4606 | |
| 4607 | int lynq_get_connect_ap_mac(lynq_wifi_index_e idx,char *mac) |
| 4608 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4609 | RLOGD("enter lynq_get_connect_ap_mac\n"); |
| 4610 | if (mac == NULL) |
| 4611 | { |
| 4612 | RLOGE("input ptr is NULL,please check\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4613 | return -1; |
| 4614 | } |
| 4615 | |
| 4616 | CHECK_IDX(idx, CTRL_STA); |
| 4617 | ap_info_s ap; |
| 4618 | ap.ap_mac[0] = '\0'; |
| 4619 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4620 | if (inner_get_status_info_ap(CTRL_STA, &ap) != 0) |
| 4621 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4622 | return -1; |
| 4623 | } |
| 4624 | strcpy(mac, ap.ap_mac); |
| 4625 | |
| 4626 | return 0; |
| 4627 | } |
| 4628 | |
| 4629 | int lynq_get_interface_ip(lynq_wifi_index_e idx, char *ip) |
| 4630 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4631 | RLOGD("enter lynq_get_interface_ip\n"); |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 4632 | struct ifaddrs *ifaddr_header, *ifaddr; |
| 4633 | struct in_addr * ifa; |
| 4634 | const char * ifaName = "wlan0"; |
| 4635 | if (ip == NULL) |
| 4636 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4637 | 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] | 4638 | return -1; |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 4639 | } |
you.chen | f58b3c9 | 2022-06-21 16:53:48 +0800 | [diff] [blame] | 4640 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4641 | if (idx == 1) |
| 4642 | { |
you.chen | 0df3e7e | 2023-05-10 15:56:26 +0800 | [diff] [blame] | 4643 | ifaName = inner_get_ap_interface_name(); |
| 4644 | if (ifaName == NULL) |
| 4645 | { |
| 4646 | RLOGE("[lynq_get_interface_ip] ap name get fail"); |
| 4647 | return -1; |
| 4648 | } |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 4649 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4650 | else if (idx != 0) |
| 4651 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4652 | return -1; |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 4653 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4654 | |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 4655 | if (getifaddrs(&ifaddr_header) == -1) |
| 4656 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4657 | perror("getifaddrs"); |
| 4658 | return -1; |
| 4659 | //exit(EXIT_FAILURE); |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 4660 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4661 | |
| 4662 | |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 4663 | for (ifaddr = ifaddr_header; ifaddr != NULL; ifaddr = ifaddr->ifa_next) |
| 4664 | { |
| 4665 | if (ifaddr->ifa_addr == NULL) |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4666 | continue; |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 4667 | if((strcmp(ifaddr->ifa_name,ifaName)==0)) |
| 4668 | { |
| 4669 | if (ifaddr->ifa_addr->sa_family==AF_INET) // check it is IP4 |
| 4670 | { |
| 4671 | // is a valid IP4 Address |
| 4672 | ifa=&((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr; |
| 4673 | inet_ntop(AF_INET, ifa, ip, INET_ADDRSTRLEN); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4674 | 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] | 4675 | freeifaddrs(ifaddr_header); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4676 | RLOGD("ip %s\n", ip); |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 4677 | return 0; |
| 4678 | } |
| 4679 | } |
| 4680 | } |
qs.xiong | c4f007c | 2023-02-08 18:16:58 +0800 | [diff] [blame] | 4681 | freeifaddrs(ifaddr_header); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4682 | RLOGE("[lynq_get_interface_ip] can't find interface | other erro\n"); |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 4683 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4684 | } |
| 4685 | |
| 4686 | int lynq_get_interface_mac(lynq_wifi_index_e idx,char *mac) |
| 4687 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4688 | RLOGD("enter lynq_get_interface_mac\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4689 | int count; |
| 4690 | size_t i; |
qs.xiong | dd6e44c | 2023-08-08 15:02:53 +0800 | [diff] [blame] | 4691 | int WIFI_INTERFACE_MAC_LEN = 17; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4692 | char *split_words[128] = {0}; |
| 4693 | const char *lynq_get_mac_cmd = "DRIVER MACADDR"; |
| 4694 | |
| 4695 | CHECK_WPA_CTRL(idx); |
| 4696 | |
| 4697 | DO_REQUEST(lynq_get_mac_cmd); |
| 4698 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4699 | if (memcmp(cmd_reply, "FAIL", 4) == 0) |
| 4700 | { |
| 4701 | 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] | 4702 | return -1; |
| 4703 | } |
| 4704 | |
| 4705 | count = lynq_split(cmd_reply, reply_len, '=', split_words); |
| 4706 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4707 | if (count < 2) |
| 4708 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4709 | return -1; |
| 4710 | } |
| 4711 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4712 | for (i=0; i < strlen(split_words[1]); i++ ) |
| 4713 | { |
| 4714 | if (split_words[1][i] != ' ') |
| 4715 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4716 | break; |
| 4717 | } |
| 4718 | } |
| 4719 | |
qs.xiong | dd6e44c | 2023-08-08 15:02:53 +0800 | [diff] [blame] | 4720 | strncpy(mac, split_words[1] + i, WIFI_INTERFACE_MAC_LEN); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4721 | |
| 4722 | return 0; |
| 4723 | } |
| 4724 | |
| 4725 | int lynq_get_connect_ap_rssi(lynq_wifi_index_e idx,int * rssi) |
| 4726 | { |
| 4727 | // int count; |
| 4728 | // char *split_words[128] = {0}; |
| 4729 | // const char *lynq_get_rssi_cmd = "DRIVER RSSI"; |
| 4730 | |
| 4731 | // if (rssi == NULL) { |
| 4732 | // return -1; |
| 4733 | // } |
| 4734 | |
| 4735 | // CHECK_IDX(idx, CTRL_STA); |
| 4736 | |
| 4737 | // CHECK_WPA_CTRL(CTRL_STA); |
| 4738 | |
| 4739 | // DO_REQUEST(lynq_get_rssi_cmd); |
| 4740 | |
| 4741 | // if (memcmp(cmd_reply, "FAIL", 4) == 0) { |
| 4742 | // return -1; |
| 4743 | // } |
| 4744 | |
| 4745 | // count = lynq_split(cmd_reply, reply_len, ' ', split_words); |
| 4746 | |
| 4747 | // if (count < 2) { |
| 4748 | // return -1; |
| 4749 | // } |
| 4750 | |
| 4751 | // *rssi = atoi(split_words[1]) * -1; |
| 4752 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4753 | char lynq_cmd_ret[MAX_RET]={0}; |
| 4754 | |
qs.xiong | ff0ae0f | 2022-10-11 15:47:14 +0800 | [diff] [blame] | 4755 | /*******change other cmd to get rssi******* |
| 4756 | * |
| 4757 | *wl rssi ---> wl -i wlan0 rssi |
| 4758 | * |
| 4759 | ***** change by qs.xiong 20221011*******/ |
you.chen | 23c4a5f | 2023-04-12 16:46:00 +0800 | [diff] [blame] | 4760 | 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] | 4761 | { |
you.chen | 23c4a5f | 2023-04-12 16:46:00 +0800 | [diff] [blame] | 4762 | 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] | 4763 | return -1; |
| 4764 | } |
you.chen | 9f17e4d | 2022-06-06 17:18:18 +0800 | [diff] [blame] | 4765 | *rssi = atoi(lynq_cmd_ret) * -1; |
qs.xiong | ff0ae0f | 2022-10-11 15:47:14 +0800 | [diff] [blame] | 4766 | /****** if got rssi is 0,means sta didn't connected any device****/ |
| 4767 | if(*rssi == 0) |
| 4768 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4769 | 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] | 4770 | return -1; |
qs.xiong | ff0ae0f | 2022-10-11 15:47:14 +0800 | [diff] [blame] | 4771 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4772 | |
| 4773 | return 0; |
| 4774 | } |
| 4775 | |
| 4776 | int lynq_get_connect_ap_band(lynq_wifi_index_e idx, lynq_wifi_band_m * band) |
| 4777 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4778 | RLOGD("enter lynq_get_connect_ap_band\n"); |
| 4779 | if (band == NULL) |
| 4780 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4781 | return -1; |
| 4782 | } |
| 4783 | |
| 4784 | CHECK_IDX(idx, CTRL_STA); |
| 4785 | ap_info_s ap; |
| 4786 | ap.band = -1; |
| 4787 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4788 | if (inner_get_status_info_ap(CTRL_STA, &ap) != 0) |
| 4789 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 4790 | return -1; |
| 4791 | } |
| 4792 | *band = ap.band; |
| 4793 | |
| 4794 | return 0; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 4795 | } |
you.chen | f58b3c9 | 2022-06-21 16:53:48 +0800 | [diff] [blame] | 4796 | |
| 4797 | int lynq_get_connect_ap_ip(lynq_wifi_index_e idx, char *ip) |
| 4798 | { |
you.chen | b95401e | 2023-05-12 19:39:06 +0800 | [diff] [blame] | 4799 | int ret; |
| 4800 | char *p; |
qs.xiong | e4cbf1c | 2023-02-28 18:22:49 +0800 | [diff] [blame] | 4801 | char bssid[1024] = {0}; |
you.chen | f58b3c9 | 2022-06-21 16:53:48 +0800 | [diff] [blame] | 4802 | |
| 4803 | if (ip == NULL) |
| 4804 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4805 | 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] | 4806 | return -1; |
| 4807 | } |
| 4808 | |
| 4809 | CHECK_IDX(idx, CTRL_STA); |
| 4810 | |
qs.xiong | e4cbf1c | 2023-02-28 18:22:49 +0800 | [diff] [blame] | 4811 | if (lynq_get_connect_ap_mac(idx, bssid) != 0) |
you.chen | f58b3c9 | 2022-06-21 16:53:48 +0800 | [diff] [blame] | 4812 | { |
| 4813 | return -1; |
| 4814 | } |
qs.xiong | e4cbf1c | 2023-02-28 18:22:49 +0800 | [diff] [blame] | 4815 | |
you.chen | b95401e | 2023-05-12 19:39:06 +0800 | [diff] [blame] | 4816 | ip[0] = '\0'; |
| 4817 | ret = inner_get_ip_by_mac(bssid, ip, 32); //better input by user |
| 4818 | if (ret != 0) |
| 4819 | { |
| 4820 | RLOGE("[lynq_get_connect_ap_ip] inner_get_ip_by_mac return fail"); |
| 4821 | return -1; |
| 4822 | } |
| 4823 | |
| 4824 | if (ip[0] == '\0' || strchr(ip, ':') != NULL) //temp change, not ok |
| 4825 | { |
| 4826 | ip[0] = '\0'; |
you.chen | 186d3c3 | 2023-05-18 14:19:46 +0800 | [diff] [blame] | 4827 | ret = exec_cmd("grep \"new_router\" /tmp/wlan0_dhcpcd_router | awk '{print $2}'| tail -1", ip, 32); |
you.chen | b95401e | 2023-05-12 19:39:06 +0800 | [diff] [blame] | 4828 | if (ret != 0) |
| 4829 | { |
| 4830 | ip[0] = '\0'; |
| 4831 | return 0; |
| 4832 | } |
| 4833 | else |
| 4834 | { |
| 4835 | p = strchr(ip, '\n'); |
| 4836 | if (p != NULL) |
| 4837 | { |
| 4838 | *p = '\0'; |
| 4839 | } |
| 4840 | } |
| 4841 | } |
| 4842 | return 0; |
you.chen | f58b3c9 | 2022-06-21 16:53:48 +0800 | [diff] [blame] | 4843 | } |
| 4844 | |
qs.xiong | e02a525 | 2023-09-20 14:00:21 +0800 | [diff] [blame] | 4845 | int lynq_get_sta_connected_dns(lynq_wifi_index_e idx, char *dns) |
| 4846 | { |
| 4847 | RLOGD("[wifi]--enter--lynq_get_sta_connected_dns"); |
| 4848 | return lynq_get_connect_ap_ip(idx,dns); //> not 100 % get dns info |
| 4849 | } |
| 4850 | |
qs.xiong | 026c5c7 | 2022-10-17 11:15:45 +0800 | [diff] [blame] | 4851 | int lynq_ap_connect_num(int sta_number) |
| 4852 | { |
| 4853 | char lynq_limit_cmd[32]={0}; |
| 4854 | int ret; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4855 | if((sta_number < 1 ) && (sta_number > 15)) |
| 4856 | { |
| 4857 | RLOGE("sta_number: not in range\n",sta_number); |
qs.xiong | 026c5c7 | 2022-10-17 11:15:45 +0800 | [diff] [blame] | 4858 | return -1; |
| 4859 | } |
| 4860 | sprintf(lynq_limit_cmd,"wl maxassoc %d", sta_number); |
| 4861 | ret = system(lynq_limit_cmd); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4862 | if(ret != 0) |
| 4863 | { |
| 4864 | RLOGE("cmd of limit ap devices number error\n"); |
qs.xiong | 026c5c7 | 2022-10-17 11:15:45 +0800 | [diff] [blame] | 4865 | } |
| 4866 | return 0; |
| 4867 | } |
you.chen | f58b3c9 | 2022-06-21 16:53:48 +0800 | [diff] [blame] | 4868 | |
qs.xiong | 7790555 | 2022-10-17 11:19:57 +0800 | [diff] [blame] | 4869 | int lynq_enable_acs(lynq_wifi_index_e idx,int acs_mode) |
| 4870 | { |
| 4871 | |
| 4872 | char lynq_wifi_acs_cmd[128]={0}; |
| 4873 | char lynq_cmd_mode[128]={0}; |
| 4874 | char lynq_cmd_slect[128]={0}; |
| 4875 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4876 | if((acs_mode != 2) && (acs_mode != 5)) |
| 4877 | { |
qs.xiong | 7790555 | 2022-10-17 11:19:57 +0800 | [diff] [blame] | 4878 | PRINT_AND_RETURN_VALUE("set acs_mode is error",-1); |
| 4879 | } |
| 4880 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4881 | if (lynq_check_network_number(idx, CTRL_AP, AP_NETWORK_0) != 0) |
| 4882 | { |
qs.xiong | 7790555 | 2022-10-17 11:19:57 +0800 | [diff] [blame] | 4883 | return -1; |
| 4884 | } |
| 4885 | |
| 4886 | CHECK_IDX(idx, CTRL_AP); |
| 4887 | |
| 4888 | CHECK_WPA_CTRL(CTRL_AP); |
| 4889 | |
| 4890 | sprintf(lynq_wifi_acs_cmd,"SET_NETWORK %d frequency %d", AP_NETWORK_0, acs_mode); |
| 4891 | sprintf(lynq_cmd_mode, "SET_NETWORK %d mode 2", AP_NETWORK_0); |
| 4892 | sprintf(lynq_cmd_slect, "SELECT_NETWORK %d", AP_NETWORK_0); |
| 4893 | |
| 4894 | DO_OK_FAIL_REQUEST(cmd_disconnect); |
| 4895 | DO_OK_FAIL_REQUEST(lynq_wifi_acs_cmd); |
| 4896 | DO_OK_FAIL_REQUEST(lynq_cmd_mode); |
| 4897 | DO_OK_FAIL_REQUEST(cmd_save_config); |
| 4898 | DO_OK_FAIL_REQUEST(lynq_cmd_slect); |
| 4899 | |
| 4900 | return 0; |
| 4901 | } |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 4902 | //you.chen add for tv-box start |
| 4903 | static int exec_cmd(const char *str_cmd, char * str_cmd_ret, size_t max_len) { |
| 4904 | FILE *fp; |
| 4905 | //printf("to exec cmd:%s\n", str_cmd); |
| 4906 | if((fp=popen(str_cmd,"r"))==NULL) |
| 4907 | { |
| 4908 | perror("popen error!"); |
| 4909 | return -1; |
| 4910 | } |
| 4911 | if((fread(str_cmd_ret,max_len,1,fp))<0) |
| 4912 | { |
| 4913 | perror("fread fail!"); |
| 4914 | fclose(fp); |
| 4915 | return -1; |
| 4916 | } |
| 4917 | fclose(fp); |
| 4918 | return 0; |
| 4919 | } |
| 4920 | |
| 4921 | static int get_netmask_length(const char* mask) |
| 4922 | { |
| 4923 | int masklen=0, i=0; |
| 4924 | int netmask=0; |
| 4925 | |
| 4926 | if(mask == NULL) |
| 4927 | { |
| 4928 | return 0; |
| 4929 | } |
| 4930 | |
| 4931 | struct in_addr ip_addr; |
| 4932 | if( inet_aton(mask, &ip_addr) ) |
| 4933 | { |
| 4934 | netmask = ntohl(ip_addr.s_addr); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4935 | }else |
| 4936 | { |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 4937 | netmask = 0; |
| 4938 | return 0; |
| 4939 | } |
| 4940 | |
| 4941 | while(0 == (netmask & 0x01) && i<32) |
| 4942 | { |
| 4943 | i++; |
| 4944 | netmask = netmask>>1; |
| 4945 | } |
| 4946 | masklen = 32-i; |
| 4947 | return masklen; |
| 4948 | } |
| 4949 | |
| 4950 | static int get_tether_route_str(char *str_cmd_ret, size_t max_len) { |
| 4951 | int mask_len; |
| 4952 | char *p; |
| 4953 | char tmp[64] = {0}; |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 4954 | sprintf(tmp, "ifconfig %s | grep Mask", s_ap_iterface_name); |
| 4955 | if (exec_cmd(tmp, str_cmd_ret, max_len) != 0) |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 4956 | return -1; |
| 4957 | p = strstr(str_cmd_ret, "Mask:"); |
| 4958 | if (p == NULL) |
| 4959 | return -1; |
| 4960 | mask_len = get_netmask_length(p + 5); |
| 4961 | if (mask_len == 0) |
| 4962 | return -1; |
| 4963 | p = strstr(str_cmd_ret, "inet addr:"); |
| 4964 | if (p == NULL) |
| 4965 | return -1; |
| 4966 | strcpy(tmp, p + 10); |
| 4967 | p = strstr(tmp, " "); |
| 4968 | if (p != NULL) |
| 4969 | *p = '\0'; |
| 4970 | sprintf(str_cmd_ret, "%s/%d", tmp, mask_len); |
| 4971 | return 0; |
| 4972 | } |
| 4973 | |
| 4974 | static void GBWWatchThreadProc() { |
| 4975 | int i,n, nloop, nmax, ncheckcount, nidlecount; |
| 4976 | unsigned long long lastAP1Bytes, lastAP2Bytes, currAP1Bytes, currAP2Bytes; |
| 4977 | unsigned int lastAP1Drop,lastAP2Drop, currAP1Drop, currAP2Drop; |
| 4978 | unsigned int setAP1Speed, setAP2Speed, lastAP1Speed, lastAP2Speed, currAP1Speed, currAP2Speed,currSetAP1Speed; |
| 4979 | char *results[16] = {0}; |
| 4980 | char str_cmd[256] = {0}; |
| 4981 | char str_cmd_ret[128] = {0}; |
| 4982 | char dest_ip[32] = {0}; |
| 4983 | lastAP1Bytes = lastAP2Bytes = 0; |
| 4984 | lastAP1Drop = lastAP2Drop = 0; |
| 4985 | lastAP1Speed = lastAP2Speed = 0; |
| 4986 | setAP1Speed = 50; |
| 4987 | setAP2Speed = 80; |
| 4988 | nloop = 0; |
| 4989 | nmax = 6; |
| 4990 | ncheckcount = nidlecount = 0; |
| 4991 | |
you.chen | 0df3e7e | 2023-05-10 15:56:26 +0800 | [diff] [blame] | 4992 | if (inner_get_ap_interface_name() == NULL) |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 4993 | { |
| 4994 | RLOGE("------gbw thread run\n"); |
| 4995 | return; |
| 4996 | } |
| 4997 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 4998 | RLOGD("------gbw thread run\n"); |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 4999 | sprintf(str_cmd, "ip neigh | grep %s | awk '{print $1}'", g_gbw_mac); |
| 5000 | while (dest_ip[0] == '\0') { |
| 5001 | sleep(1); |
| 5002 | str_cmd_ret[0] = '\0'; |
| 5003 | exec_cmd(str_cmd, str_cmd_ret, sizeof (str_cmd_ret)); |
| 5004 | for(n = 0; n < (int)sizeof(str_cmd_ret) && str_cmd_ret[n] != '\0'; n++) { |
| 5005 | if (str_cmd_ret[n] == '\n'){ |
| 5006 | str_cmd_ret[n] = '\0'; |
| 5007 | break; |
| 5008 | } |
| 5009 | } |
| 5010 | if (str_cmd_ret[0] != '\0') |
| 5011 | { |
| 5012 | strcpy(dest_ip, str_cmd_ret); |
| 5013 | } |
| 5014 | } |
| 5015 | |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 5016 | system_call_v("tc qdisc del dev %s root > /dev/null 2>&1", s_ap_iterface_name); |
| 5017 | system_call_v("tc qdisc add dev %s root handle 1: htb r2q 1", s_ap_iterface_name); |
| 5018 | system_call_v("tc class add dev %s parent 1: classid 1:1 htb rate 50Mbit ceil 70Mbit prio 2 quantum 3000", s_ap_iterface_name); |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 5019 | if (get_tether_route_str(str_cmd_ret, sizeof (str_cmd_ret)) != 0) |
| 5020 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 5021 | RLOGD("not get tether info\n"); |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 5022 | return; |
| 5023 | } |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 5024 | system_call_v("tc filter add dev %s parent 1: protocol ip prio 16 u32 match ip dst %s flowid 1:1", s_ap_iterface_name, str_cmd_ret); |
| 5025 | system_call_v("tc class add dev %s parent 1: classid 1:2 htb rate 80Mbit ceil 100Mbit prio 0 quantum 3000000", s_ap_iterface_name); |
| 5026 | system_call_v("tc filter add dev %s parent 1: protocol ip prio 1 u32 match ip dst %s flowid 1:2", s_ap_iterface_name, dest_ip); |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 5027 | |
| 5028 | while (1) { |
| 5029 | sleep(1); |
| 5030 | memset(str_cmd, 0, sizeof(str_cmd)); |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 5031 | memset(str_cmd_ret, 0, sizeof(str_cmd_ret)); |
| 5032 | sprintf(str_cmd, "tc -s class show dev %s classid 1:1 | grep Sent", s_ap_iterface_name); |
| 5033 | if (0 != exec_cmd(str_cmd, str_cmd_ret, sizeof (str_cmd_ret))) |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 5034 | continue; |
| 5035 | //printf("ap1 --- %s\n", str_cmd); |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 5036 | n = lynq_split(str_cmd_ret, strlen(str_cmd_ret), ' ', results); |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 5037 | if (n > 9) { |
| 5038 | if (strcmp(results[1], "Sent") == 0) { |
| 5039 | currAP1Bytes = atoll(results[2]); |
| 5040 | } |
| 5041 | if (strcmp(results[6], "(dropped") == 0) { |
| 5042 | currAP1Drop = atoi(results[7]); |
| 5043 | } |
| 5044 | } |
| 5045 | |
| 5046 | memset(str_cmd, 0, sizeof(str_cmd)); |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 5047 | memset(str_cmd_ret, 0, sizeof(str_cmd_ret)); |
| 5048 | sprintf(str_cmd, "tc -s class show dev %s classid 1:2 | grep Sent", s_ap_iterface_name); |
| 5049 | if (0 != exec_cmd(str_cmd, str_cmd_ret, sizeof (str_cmd_ret))) |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 5050 | continue; |
| 5051 | //printf("ap2 --- %s\n", str_cmd); |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 5052 | n = lynq_split(str_cmd_ret, strlen(str_cmd_ret), ' ', results); |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 5053 | if (n > 9) { |
| 5054 | if (strcmp(results[1], "Sent") == 0) { |
| 5055 | currAP2Bytes = atoll(results[2]); |
| 5056 | } |
| 5057 | if (strcmp(results[6], "(dropped") == 0) { |
| 5058 | currAP2Drop = atoi(results[7]); |
| 5059 | } |
| 5060 | } |
| 5061 | |
| 5062 | //printf("ap1 %llu- %u, ap2 %llu-%u\n", currAP1Bytes, currAP1Drop, currAP2Bytes, currAP2Drop); |
| 5063 | if (currAP1Bytes < lastAP1Bytes || currAP2Bytes < lastAP2Bytes) { |
| 5064 | lastAP1Bytes = currAP1Bytes; |
| 5065 | lastAP2Bytes = currAP2Bytes; |
| 5066 | continue; |
| 5067 | } |
| 5068 | |
| 5069 | currAP1Speed = (currAP1Bytes - lastAP1Bytes) / 128 / 1024; |
| 5070 | currAP2Speed = (currAP2Bytes - lastAP2Bytes) / 128 / 1024; |
| 5071 | //printf("ap1 speed %d mb, ap2 speed %d mb\n", currAP1Speed, currAP2Speed); |
| 5072 | lastAP1Speed = currAP1Speed; |
| 5073 | lastAP2Speed = currAP2Speed; |
| 5074 | lastAP1Bytes = currAP1Bytes; |
| 5075 | lastAP2Bytes = currAP2Bytes; |
| 5076 | |
| 5077 | currSetAP1Speed = setAP1Speed; |
| 5078 | if ((currAP2Speed < 30 && currAP2Speed > 5) && currAP1Speed > 5) { |
| 5079 | ncheckcount++; |
| 5080 | if (ncheckcount > 3) { |
| 5081 | ncheckcount = 0; |
| 5082 | currSetAP1Speed = 5; |
| 5083 | } |
| 5084 | } |
| 5085 | else { |
| 5086 | ncheckcount = 0; |
| 5087 | if (currAP1Speed < 5) |
| 5088 | nidlecount++; |
| 5089 | else |
| 5090 | nidlecount = 0; |
| 5091 | |
| 5092 | } |
| 5093 | |
| 5094 | if (nidlecount > 60 ){ |
| 5095 | currSetAP1Speed = 50; |
| 5096 | } |
| 5097 | |
| 5098 | if (currSetAP1Speed != setAP1Speed) { |
| 5099 | setAP1Speed = currSetAP1Speed; |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 5100 | system_call_v(str_cmd, "tc class replace dev %s parent 1: classid 1:1 htb rate %dMbit ceil %dMbit prio 2 quantum 3000", |
| 5101 | s_ap_iterface_name, setAP1Speed, (int)(setAP1Speed*1.4)); |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 5102 | } |
| 5103 | } |
| 5104 | } |
| 5105 | |
| 5106 | int enableGBW(const char* mac) { |
| 5107 | int i,len; |
| 5108 | char get_ipaddr_cmd[128]={0}; |
| 5109 | ap_info_s *ap; |
| 5110 | device_info_s * list; |
| 5111 | |
| 5112 | if (mac == NULL || g_gbw_enabled == 1) |
| 5113 | return -1; |
| 5114 | len = strlen(mac); |
| 5115 | g_gbw_mac = malloc(len + 1); |
| 5116 | for(i=0;i<len;i++) { |
| 5117 | if (mac[i] >= 'A' && mac[i] <= 'Z') |
| 5118 | { |
| 5119 | g_gbw_mac[i] = 'a' + (mac[i] - 'A'); |
| 5120 | } |
| 5121 | else |
| 5122 | g_gbw_mac[i] = mac[i]; |
| 5123 | } |
| 5124 | g_gbw_mac[i] = '\0'; |
| 5125 | g_gbw_enabled = 1; |
| 5126 | |
| 5127 | sprintf(get_ipaddr_cmd, "ip neigh | grep %s", g_gbw_mac); |
| 5128 | if (system(get_ipaddr_cmd) == 0) { |
| 5129 | //startGBW(); |
| 5130 | if ( 0 ==lynq_get_ap_device_list(1, &ap, &list,&len) ) { |
| 5131 | for (i=0;i<len;i++) { |
| 5132 | //printf("--mac:%s, name:%s\n",list[i].sta_mac, list[i].hostname); |
| 5133 | if (strcmp(g_gbw_mac, list[i].sta_mac) == 0) |
| 5134 | startGBW(); |
| 5135 | } |
| 5136 | free(ap); |
| 5137 | free(list); |
| 5138 | } |
| 5139 | } |
| 5140 | return 0; |
| 5141 | } |
| 5142 | |
| 5143 | int disableGBW() { |
| 5144 | stopGBW(); |
| 5145 | free(g_gbw_mac); |
| 5146 | g_gbw_mac = NULL; |
| 5147 | g_gbw_enabled = 1; |
| 5148 | return 0; |
| 5149 | } |
| 5150 | |
| 5151 | static int startGBW() { |
| 5152 | if (g_gbw_watcher_pid != 0) { |
| 5153 | stopGBW(); |
| 5154 | } |
| 5155 | pthread_create(&g_gbw_watcher_pid,NULL,GBWWatchThreadProc,NULL); |
| 5156 | } |
| 5157 | |
| 5158 | static int stopGBW() { |
| 5159 | void* retval; |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 5160 | char cmd[64] = {0}; |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 5161 | pthread_cancel(g_gbw_watcher_pid); |
| 5162 | pthread_join(g_gbw_watcher_pid, &retval); |
| 5163 | g_gbw_watcher_pid = 0; |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 5164 | sprintf(cmd, "%s %d", get_interface_name_script, LYNQ_WIFI_INTERFACE_1); |
| 5165 | if (s_ap_iterface_name[0] != '\0') |
| 5166 | { |
| 5167 | sprintf(cmd, "tc qdisc del dev %s root", s_ap_iterface_name); |
| 5168 | system(cmd); |
| 5169 | } |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 5170 | } |
| 5171 | //you.chen add for tv-box end |