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