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