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