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