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