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