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