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