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