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