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