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