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