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