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