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