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