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 | |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1907 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1908 | int lynq_wifi_ap_start(lynq_wifi_index_e idx) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1909 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1910 | char LYNQ_WIFI_CMD[128]={0}; |
| 1911 | //const char *lynq_remove_all_cmd = "REMOVE_NETWORK all"; |
| 1912 | //const char *lynq_reconfig_cmd = "RECONFIGURE /data/wifi/wg870/wpa_supplicant.conf"; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1913 | RLOGD("enter lynq_wifi_ap_channel_get"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1914 | CHECK_IDX(idx, CTRL_AP); |
| 1915 | |
| 1916 | CHECK_WPA_CTRL(CTRL_AP); |
| 1917 | |
you.chen | 0df3e7e | 2023-05-10 15:56:26 +0800 | [diff] [blame^] | 1918 | if (inner_get_ap_interface_name() == NULL) |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 1919 | { |
you.chen | 0df3e7e | 2023-05-10 15:56:26 +0800 | [diff] [blame^] | 1920 | RLOGE("lynq_wifi_ap_start get ap name fail"); |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 1921 | return -1; |
| 1922 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1923 | |
| 1924 | //DO_OK_FAIL_REQUEST(lynq_remove_all_cmd); |
| 1925 | //DO_OK_FAIL_REQUEST(lynq_reconfig_cmd); |
| 1926 | |
| 1927 | sprintf(LYNQ_WIFI_CMD,"SELECT_NETWORK %d",AP_NETWORK_0); |
| 1928 | DO_OK_FAIL_REQUEST(LYNQ_WIFI_CMD); |
| 1929 | |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 1930 | ret = system_call_v("%s %s", start_stop_ap_script, "start"); |
| 1931 | if (ret != 0) |
| 1932 | { |
| 1933 | RLOGE("lynq_wifi_ap_start excute script fail"); |
| 1934 | return -1; |
| 1935 | } |
| 1936 | |
you.chen | 0df3e7e | 2023-05-10 15:56:26 +0800 | [diff] [blame^] | 1937 | check_tether_and_notify(); |
| 1938 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1939 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1940 | } |
| 1941 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1942 | int lynq_wifi_ap_restart(lynq_wifi_index_e idx) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1943 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1944 | 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] | 1945 | } |
| 1946 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1947 | int lynq_wifi_ap_stop(lynq_wifi_index_e idx) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1948 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1949 | char LYNQ_WIFI_CMD[128]={0}; |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1950 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1951 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1952 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1953 | CHECK_WPA_CTRL(CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1954 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1955 | sprintf(LYNQ_WIFI_CMD,"DISABLE_NETWORK %d",AP_NETWORK_0); |
| 1956 | |
| 1957 | DO_OK_FAIL_REQUEST(LYNQ_WIFI_CMD); |
| 1958 | |
you.chen | b4b121c | 2022-05-06 17:50:16 +0800 | [diff] [blame] | 1959 | // system("connmanctl tether wifi off"); |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 1960 | |
| 1961 | ret = system_call_v("%s %s", start_stop_ap_script, "stop"); |
| 1962 | if (ret != 0) |
| 1963 | { |
| 1964 | RLOGE("lynq_wifi_ap_start excute script fail"); |
| 1965 | return -1; |
| 1966 | } |
| 1967 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1968 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1969 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1970 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1971 | int lynq_wifi_ap_hide_ssid(lynq_wifi_index_e idx) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1972 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1973 | char lynq_disable_cmd[128] = {0}; |
| 1974 | char lynq_select_cmd[128] = {0}; |
| 1975 | const char *lynq_hide_cmd = "SET HIDE_SSID 1"; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1976 | RLOGD("enter lynq_wifi_ap_hide_ssid"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1977 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1978 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1979 | CHECK_WPA_CTRL(CTRL_AP); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1980 | sprintf(lynq_disable_cmd,"DISABLE_NETWORK %d", AP_NETWORK_0); |
| 1981 | sprintf(lynq_select_cmd,"SELECT_NETWORK %d", AP_NETWORK_0); |
| 1982 | |
| 1983 | DO_OK_FAIL_REQUEST(lynq_disable_cmd); |
| 1984 | DO_OK_FAIL_REQUEST(lynq_hide_cmd); |
| 1985 | DO_OK_FAIL_REQUEST(lynq_select_cmd); |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 1986 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1987 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1988 | } |
| 1989 | |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 1990 | int lynq_wifi_ap_unhide_ssid(lynq_wifi_index_e idx) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1991 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1992 | char lynq_disable_cmd[128] = {0}; |
| 1993 | char lynq_select_cmd[128] = {0}; |
| 1994 | const char *lynq_unhide_cmd = "SET HIDE_SSID 0"; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 1995 | RLOGD("enter lynq_wifi_ap_unhide_ssid"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1996 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 1997 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 1998 | CHECK_WPA_CTRL(CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 1999 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2000 | sprintf(lynq_disable_cmd,"DISABLE_NETWORK %d", AP_NETWORK_0); |
| 2001 | sprintf(lynq_select_cmd,"SELECT_NETWORK %d", AP_NETWORK_0); |
| 2002 | |
| 2003 | DO_OK_FAIL_REQUEST(lynq_disable_cmd); |
| 2004 | DO_OK_FAIL_REQUEST(lynq_unhide_cmd); |
| 2005 | DO_OK_FAIL_REQUEST(lynq_select_cmd); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2006 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2007 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2008 | } |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2009 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2010 | int lynq_ap_password_set(lynq_wifi_index_e idx,char *password) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2011 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2012 | int pass_len; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2013 | char lynq_tmp_cmd[MAX_CMD] = {0}; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2014 | char lynq_wpa2_wpa3[64] = {0}; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2015 | char lynq_wep_tx_keyidx_cmd[MAX_CMD] = {0}; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2016 | RLOGD("enter lynq_ap_password_set"); |
| 2017 | if( password == NULL ) |
| 2018 | { |
| 2019 | RLOGE("[lynq_ap_password_set]input password is NULL"); |
qs.xiong | e707432 | 2022-06-27 11:34:53 +0800 | [diff] [blame] | 2020 | return -1; |
| 2021 | } |
| 2022 | pass_len=strlen(password); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2023 | lynq_wifi_auth_s auth = -1; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2024 | if(pass_len < 8 || pass_len >= 64) |
| 2025 | { |
| 2026 | RLOGE("[lynq_ap_password_set]input password len not in rage"); |
| 2027 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2028 | } |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2029 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2030 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2031 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2032 | if (0 != lynq_wifi_ap_auth_get(idx, &auth)) |
| 2033 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2034 | RLOGE("[lynq_ap_password_set] get ap auth info error\n"); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2035 | return -1; |
| 2036 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2037 | else if (auth == LYNQ_WIFI_AUTH_OPEN) |
| 2038 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2039 | RLOGD("ap auth :LYNQ_WIFI_AUTH_OPEN\n"); |
| 2040 | return 0; |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2041 | } |
| 2042 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2043 | CHECK_WPA_CTRL(CTRL_AP); |
| 2044 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2045 | if (auth == LYNQ_WIFI_AUTH_WEP) |
| 2046 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2047 | RLOGD("[lynq_ap_password_set]ap auth : LYNQ_WIFI_AUTH_WEP\n"); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2048 | sprintf(lynq_tmp_cmd,"SET_NETWORK %d wep_key0 \"%s\"",AP_NETWORK_0, password); |
| 2049 | sprintf(lynq_wep_tx_keyidx_cmd,"SET_NETWORK %d wep_tx_keyidx 0",AP_NETWORK_0); |
| 2050 | DO_OK_FAIL_REQUEST(lynq_tmp_cmd); |
| 2051 | DO_OK_FAIL_REQUEST(lynq_wep_tx_keyidx_cmd); |
| 2052 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2053 | else if (auth == LYNQ_WIFI_AUTH_WPA_PSK || auth == LYNQ_WIFI_AUTH_WPA2_PSK) |
| 2054 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2055 | 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] | 2056 | sprintf(lynq_tmp_cmd,"SET_NETWORK %d psk \"%s\"",AP_NETWORK_0, password); |
| 2057 | DO_OK_FAIL_REQUEST(lynq_tmp_cmd); |
| 2058 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2059 | else if (auth == LYNQ_WIFI_AUTH_WPA2_WPA3_PSK || auth == LYNQ_WIFI_AUTH_WPA3_PSK) |
| 2060 | { |
| 2061 | |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2062 | 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] | 2063 | 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] | 2064 | 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] | 2065 | DO_OK_FAIL_REQUEST(lynq_tmp_cmd); |
| 2066 | DO_OK_FAIL_REQUEST(lynq_wpa2_wpa3); |
| 2067 | |
| 2068 | } |
| 2069 | else |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2070 | { |
| 2071 | RLOGD("[lynq_ap_password_set]ap auth :get ap auth error\n"); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2072 | return -1; |
| 2073 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2074 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2075 | DO_OK_FAIL_REQUEST(cmd_save_config); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2076 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2077 | return 0; |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2078 | } |
| 2079 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2080 | int lynq_ap_password_get(lynq_wifi_index_e idx, char *password) |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2081 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2082 | FILE * fp; |
| 2083 | int len, ret; |
| 2084 | int count, index; |
| 2085 | char *split_lines[128] = {0}; |
| 2086 | char *buff, *p; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2087 | RLOGD("enter lynq_ap_password_get"); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2088 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2089 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2090 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2091 | fp = fopen("/data/wifi/wg870/wpa_supplicant_ap.conf", "rb"); |
| 2092 | // fp = fopen("/data/wifi/wg870/wpa_supplicant.conf", "rb"); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2093 | if (NULL == fp) |
| 2094 | { |
| 2095 | RLOGE("open file fail\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2096 | return -1; |
| 2097 | } |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2098 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2099 | buff = alloca(MAX_RET); |
| 2100 | fseek(fp, 0, SEEK_SET); |
| 2101 | len = fread(buff, 1, MAX_RET, fp); |
| 2102 | fclose(fp); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2103 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2104 | for(index=0; index < len; index ++) |
| 2105 | { |
| 2106 | if (memcmp(buff + index, "network={", 9) != 0) |
| 2107 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2108 | continue; |
| 2109 | } |
| 2110 | p = buff + index + 9; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2111 | for (; index < len; index ++ ) |
| 2112 | { |
| 2113 | if (buff[index] != '}') |
| 2114 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2115 | continue; |
| 2116 | } |
| 2117 | buff[index] = '\0'; |
| 2118 | break; |
| 2119 | } |
| 2120 | len = buff + index - p; |
| 2121 | } |
| 2122 | |
| 2123 | count = lynq_split(p, len, '\n', split_lines); |
| 2124 | |
| 2125 | ret = -1; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2126 | for(index=0; index < count; index++) |
| 2127 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2128 | p = strstr(split_lines[index], "psk="); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2129 | if (p != NULL) |
| 2130 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2131 | p += 4; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2132 | if (*p == '\"') |
| 2133 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2134 | p++; |
| 2135 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2136 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2137 | else if (NULL != (p = strstr(split_lines[index], "wep_key0="))) |
| 2138 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2139 | p += 9; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2140 | if (*p == '\"') |
| 2141 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2142 | p++; |
| 2143 | } |
| 2144 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2145 | else |
| 2146 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2147 | continue; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | strcpy(password, p); |
| 2151 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2152 | while(*password != '\0') |
| 2153 | { |
| 2154 | if (*password == '\"') |
| 2155 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2156 | *password = '\0'; |
| 2157 | break; |
| 2158 | } |
| 2159 | password++; |
| 2160 | } |
| 2161 | ret = 0; |
| 2162 | break; |
| 2163 | } //end for(index=0; index < count; index++) |
| 2164 | |
| 2165 | return ret; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2166 | } |
| 2167 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2168 | static int inner_get_network_auth(int interface, int net_no, lynq_wifi_auth_s *auth) { |
| 2169 | char lynq_auth_str[MAX_RET] = {0}; |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2170 | char lynq_proto_str[MAX_RET] = {0}; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2171 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2172 | if (inner_get_param(interface, net_no, "key_mgmt", lynq_auth_str) != 0) |
| 2173 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2174 | return -1; |
| 2175 | } |
| 2176 | |
| 2177 | *auth = convert_auth_from_key_mgmt(lynq_auth_str); |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2178 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2179 | if (*auth == LYNQ_WIFI_AUTH_WPA_PSK) |
| 2180 | { |
| 2181 | if (inner_get_param(interface, net_no, "proto", lynq_proto_str) == 0) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2182 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2183 | if (strcmp(lynq_proto_str, "RSN") == 0) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2184 | { |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2185 | *auth = LYNQ_WIFI_AUTH_WPA2_PSK; |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2186 | return 0; |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2187 | } |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2188 | else if (strcmp(lynq_proto_str, "WPA") == 0) // need compare when wpa3 supported |
| 2189 | { |
| 2190 | return 0; |
| 2191 | } |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2192 | } |
| 2193 | } |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2194 | else if (*auth == LYNQ_WIFI_AUTH_OPEN || *auth == LYNQ_WIFI_AUTH_WEP) |
| 2195 | { |
| 2196 | return 0; |
| 2197 | } |
| 2198 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2199 | if (inner_get_param(interface, net_no,"ieee80211w",lynq_auth_str) !=0) |
| 2200 | { |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2201 | RLOGE("check ieee80211w error\n"); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2202 | return -1; |
| 2203 | } |
| 2204 | if ( strncmp(lynq_auth_str,"1",1) == 0 ) |
| 2205 | { |
| 2206 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2207 | *auth = LYNQ_WIFI_AUTH_WPA2_WPA3_PSK; |
| 2208 | return 0; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2209 | }else if( strncmp(lynq_auth_str,"2",1) == 0 ) |
| 2210 | { |
| 2211 | |
| 2212 | *auth = LYNQ_WIFI_AUTH_WPA3_PSK; |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2213 | return 0; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2214 | }else |
| 2215 | { |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2216 | RLOGE("check ieee80211w error, not 1 or 2\n"); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2217 | *auth = -1; |
| 2218 | return -1; |
| 2219 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2220 | return 0; |
| 2221 | } |
| 2222 | |
| 2223 | 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] | 2224 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2225 | RLOGD("enter lynq_sta_ssid_password_set"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2226 | int pass_len, net_no, count, index; |
| 2227 | char lynq_tmp_cmd[300]={0}; |
| 2228 | int net_no_list[128]; |
| 2229 | lynq_wifi_auth_s net_auth; |
| 2230 | pass_len=strlen(password); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2231 | if(pass_len < 8 || pass_len >= 64) |
| 2232 | { |
| 2233 | RLOGE("[lynq_sta_ssid_password_set]input psw error"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2234 | return -1; |
| 2235 | } |
| 2236 | |
| 2237 | CHECK_IDX(idx, CTRL_STA); |
| 2238 | |
| 2239 | net_no = -1; |
| 2240 | count = lynq_get_network_number_list(idx, CTRL_STA, net_no_list, ap->ap_ssid); |
| 2241 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2242 | for (index=0; index < count; index++) |
| 2243 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2244 | net_auth = -1; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2245 | if (0 == inner_get_network_auth(CTRL_STA, net_no_list[index], &net_auth) && net_auth == ap->auth) |
| 2246 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2247 | net_no = net_no_list[index]; |
| 2248 | break; |
| 2249 | } |
| 2250 | } |
| 2251 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2252 | if (net_no < 0) |
| 2253 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2254 | return -1; |
| 2255 | } |
| 2256 | |
| 2257 | CHECK_WPA_CTRL(CTRL_STA); |
| 2258 | |
| 2259 | sprintf(lynq_tmp_cmd,"SET_NETWORK %d psk \"%s\"",net_no, password); |
| 2260 | |
| 2261 | DO_OK_FAIL_REQUEST(lynq_tmp_cmd); |
| 2262 | DO_OK_FAIL_REQUEST(cmd_save_config); |
| 2263 | |
| 2264 | return 0; |
| 2265 | } |
| 2266 | |
| 2267 | int lynq_sta_ssid_password_get(lynq_wifi_index_e idx, ap_info_s *ap, char *password) { // @todo |
| 2268 | |
| 2269 | FILE * fp; |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 2270 | int len, ret, network_len, i, ssid_len; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2271 | int count, index; |
| 2272 | char *split_lines[128] = {0}; |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 2273 | char *buff, *p, *ssid, *ssid_end_flag; |
| 2274 | char tmp_ssid[128]={0}; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2275 | RLOGD("enter lynq_sta_ssid_password_get"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2276 | |
you.chen | 755332b | 2022-08-06 16:59:10 +0800 | [diff] [blame] | 2277 | network_len = 0; |
| 2278 | p = NULL; |
| 2279 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2280 | CHECK_IDX(idx, CTRL_STA); |
| 2281 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2282 | if (NULL == password) |
| 2283 | { |
| 2284 | RLOGE("bad param\n"); |
you.chen | 755332b | 2022-08-06 16:59:10 +0800 | [diff] [blame] | 2285 | return -1; |
| 2286 | } |
| 2287 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2288 | fp = fopen("/data/wifi/wg870/wpa_supplicant.conf", "rb"); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2289 | if (NULL == fp) |
| 2290 | { |
| 2291 | RLOGE("[lynq_sta_ssid_password_get] open file fail\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2292 | return -1; |
| 2293 | } |
| 2294 | |
| 2295 | buff = alloca(MAX_RET); |
| 2296 | fseek(fp, 0, SEEK_SET); |
| 2297 | len = fread(buff, 1, MAX_RET, fp); |
| 2298 | fclose(fp); |
| 2299 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2300 | for(index=0; index < len; index ++) |
| 2301 | { |
| 2302 | for(; index < len; index ++) |
| 2303 | { |
| 2304 | if (memcmp(buff + index, "network={", 9) != 0) |
| 2305 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2306 | continue; |
| 2307 | } |
| 2308 | p = buff + index + 9; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2309 | for (; index < len; index ++ ) |
| 2310 | { |
| 2311 | if (buff[index] != '}') |
| 2312 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2313 | continue; |
| 2314 | } |
| 2315 | buff[index] = '\0'; |
| 2316 | break; |
| 2317 | } |
you.chen | 755332b | 2022-08-06 16:59:10 +0800 | [diff] [blame] | 2318 | network_len = buff + index - p; |
| 2319 | break; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2320 | } |
| 2321 | |
qs.xiong | b3f26af | 2023-02-17 18:41:07 +0800 | [diff] [blame] | 2322 | if (p == NULL) |
| 2323 | return -1; |
| 2324 | |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 2325 | ssid = strstr(p, "ssid="); |
| 2326 | if (ssid != NULL) { |
| 2327 | ssid += strlen("ssid="); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2328 | if (ssid[0] == '\"') |
| 2329 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 2330 | if (memcmp(ssid + 1, ap->ap_ssid, strlen(ap->ap_ssid)) == 0 && ssid[strlen(ap->ap_ssid) + 1] == '\"') |
| 2331 | break; |
| 2332 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2333 | else |
| 2334 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 2335 | ssid_end_flag = strstr(ssid, "\n"); |
| 2336 | if (ssid_end_flag != NULL) |
| 2337 | { |
| 2338 | ssid_len = (ssid_end_flag - ssid) / 2; |
| 2339 | for(i=0; i<ssid_len; i++) |
| 2340 | { |
| 2341 | tmp_ssid[i] = inner_convert_char(ssid[i*2]) << 4 | inner_convert_char(ssid[i*2 + 1]); |
| 2342 | } |
| 2343 | if (memcmp(tmp_ssid, ap->ap_ssid, ssid_len) == 0) |
| 2344 | break; |
| 2345 | } |
| 2346 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2347 | } |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 2348 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2349 | } |
| 2350 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2351 | if (index >= len || NULL == p || network_len <= 0) |
| 2352 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2353 | return -1; |
| 2354 | } |
| 2355 | |
you.chen | 755332b | 2022-08-06 16:59:10 +0800 | [diff] [blame] | 2356 | count = lynq_split(p, network_len, '\n', split_lines); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2357 | |
| 2358 | ret = -1; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2359 | for(index=0; index < count; index++) |
| 2360 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2361 | p = strstr(split_lines[index], "psk="); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2362 | if (p != NULL) |
| 2363 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2364 | p += 4; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2365 | if (*p == '\"') |
| 2366 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2367 | p++; |
| 2368 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2369 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2370 | else if (NULL != (p = strstr(split_lines[index], "wep_key0="))) |
| 2371 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2372 | p += 9; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2373 | if (*p == '\"') |
| 2374 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2375 | p++; |
| 2376 | } |
| 2377 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2378 | else |
| 2379 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2380 | continue; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2381 | } |
| 2382 | |
qs.xiong | 1367346 | 2023-02-21 19:12:54 +0800 | [diff] [blame] | 2383 | if (*p == '\"') |
| 2384 | p++; |
| 2385 | strncpy(password, p, 64); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2386 | |
qs.xiong | 1367346 | 2023-02-21 19:12:54 +0800 | [diff] [blame] | 2387 | p = password; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2388 | while(password - p < 64 && *password != '\0') |
| 2389 | { |
| 2390 | if (*password == '\"') |
| 2391 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2392 | *password = '\0'; |
| 2393 | break; |
| 2394 | } |
| 2395 | password++; |
| 2396 | } |
| 2397 | ret = 0; |
| 2398 | break; |
| 2399 | } //end for(index=0; index < count; index++) |
| 2400 | |
| 2401 | return ret; |
| 2402 | } |
| 2403 | |
| 2404 | static int inner_set_sta_ssid(int net_no, char *sta_ssid) |
| 2405 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2406 | char lynq_wifi_ssid_cmd[80]={0}; |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2407 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2408 | if (sta_ssid == NULL) |
| 2409 | { |
| 2410 | RLOGE("sta_ssid is null\n"); |
| 2411 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2412 | } |
| 2413 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2414 | CHECK_WPA_CTRL(CTRL_STA); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2415 | |
| 2416 | sprintf(lynq_wifi_ssid_cmd,"SET_NETWORK %d ssid \"%s\"", net_no, sta_ssid); |
| 2417 | |
| 2418 | DO_OK_FAIL_REQUEST(lynq_wifi_ssid_cmd); |
| 2419 | // DO_OK_FAIL_REQUEST(cmd_save_config); |
| 2420 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2421 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2422 | |
| 2423 | } |
| 2424 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2425 | 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] | 2426 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2427 | char lynq_disable_cmd[128]={0}; |
| 2428 | char lynq_select_cmd[128]={0}; |
| 2429 | |
| 2430 | CHECK_WPA_CTRL(CTRL_STA); |
| 2431 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2432 | if (save != 0) |
| 2433 | { |
you.chen | c29444e | 2022-06-07 18:01:16 +0800 | [diff] [blame] | 2434 | if (start_flag != 0) |
| 2435 | { |
| 2436 | sprintf(lynq_select_cmd,"ENABLE_NETWORK %d", net_no); |
| 2437 | DO_OK_FAIL_REQUEST(lynq_select_cmd); |
| 2438 | } |
| 2439 | else |
| 2440 | { |
| 2441 | sprintf(lynq_select_cmd,"DISABLE_NETWORK %d", net_no); |
| 2442 | DO_OK_FAIL_REQUEST(lynq_select_cmd); |
| 2443 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2444 | DO_OK_FAIL_REQUEST(cmd_save_config); |
| 2445 | } |
| 2446 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2447 | if (start_flag == 0) |
| 2448 | { |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2449 | sprintf(lynq_disable_cmd,"DISCONNECT"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2450 | DO_OK_FAIL_REQUEST(lynq_disable_cmd); |
| 2451 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2452 | else |
| 2453 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2454 | sprintf(lynq_select_cmd,"SELECT_NETWORK %d", net_no); |
| 2455 | DO_OK_FAIL_REQUEST(lynq_select_cmd); |
| 2456 | } |
| 2457 | |
| 2458 | return 0; |
| 2459 | } |
| 2460 | |
| 2461 | int lynq_wifi_get_sta_ssid(lynq_wifi_index_e idx, char* sta_ssid) |
| 2462 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2463 | RLOGD("enter lynq_sta_ssid_password_set"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2464 | CHECK_IDX(idx, CTRL_STA); |
| 2465 | |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2466 | curr_status_info curr_state; |
| 2467 | ap_info_s ap_info; |
| 2468 | curr_state.ap = &ap_info; |
| 2469 | curr_state.state = NULL; |
| 2470 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2471 | if (0 == inner_get_status_info(CTRL_STA, &curr_state)) |
| 2472 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 2473 | strncpy(sta_ssid, ap_info.ap_ssid, sizeof (ap_info.ap_ssid)); |
you.chen | 6c2dd9c | 2022-05-16 17:55:28 +0800 | [diff] [blame] | 2474 | return 0; |
| 2475 | } |
| 2476 | |
| 2477 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2478 | } |
| 2479 | |
| 2480 | int lynq_wifi_get_sta_available_ap(lynq_wifi_index_e idx, ap_detail_info_s *info) |
| 2481 | { |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 2482 | scan_info_s *scan_list = NULL; |
| 2483 | saved_ap_info_s *save_list = NULL; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2484 | int scan_len=0; |
| 2485 | int save_len=0; |
| 2486 | int best_index = -1; |
| 2487 | int best_scan_index = -1; |
| 2488 | int best_rssi = 0; |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 2489 | int i, j, ret; |
| 2490 | |
| 2491 | ret = -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2492 | |
| 2493 | CHECK_IDX(idx, CTRL_STA); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2494 | if (info == NULL) |
| 2495 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2496 | return -1; |
| 2497 | } |
| 2498 | |
| 2499 | curr_status_info curr_state; |
| 2500 | ap_info_s ap_info; |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 2501 | char status[64]; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2502 | |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 2503 | memset(&ap_info, 0, sizeof (ap_info)); |
| 2504 | memset(status, 0, sizeof (status)); |
| 2505 | |
| 2506 | curr_state.ap = &ap_info; |
| 2507 | curr_state.state = status; |
| 2508 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2509 | if (0 == inner_get_status_info(CTRL_STA, &curr_state) && curr_state.net_no >= 0) |
| 2510 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2511 | memcpy(&info->base_info, &ap_info, sizeof (ap_info_s)); |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 2512 | if (strcmp(status, STATE_COMPLETED) == 0) |
| 2513 | { |
| 2514 | info->status = LYNQ_WIFI_AP_STATUS_ENABLE; |
| 2515 | } |
| 2516 | else |
| 2517 | { |
| 2518 | info->status = LYNQ_WIFI_AP_STATUS_DISABLE; |
| 2519 | } |
you.chen | 593621d | 2023-04-27 17:52:44 +0800 | [diff] [blame] | 2520 | lynq_get_connect_ap_ip(idx, info->base_info.ap_ip); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2521 | lynq_get_connect_ap_rssi(idx, &info->rssi); |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 2522 | 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] | 2523 | return 0; |
| 2524 | } |
| 2525 | |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 2526 | lynq_wifi_sta_start_scan(idx); |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 2527 | sleep(2); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2528 | if (0 != lynq_get_scan_list(0, &scan_list, &scan_len)) |
| 2529 | { |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 2530 | if (NULL != scan_list) |
| 2531 | { |
| 2532 | free(scan_list); |
| 2533 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2534 | return -1; |
| 2535 | } |
| 2536 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2537 | if (0 != lynq_get_sta_saved_ap(0, &save_list, &save_len)) |
| 2538 | { |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 2539 | if (NULL != scan_list) |
| 2540 | { |
| 2541 | free(scan_list); |
| 2542 | } |
| 2543 | if (NULL != save_list) |
| 2544 | { |
| 2545 | free(save_list); |
| 2546 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2547 | return -1; |
| 2548 | } |
| 2549 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2550 | for (i=0; i < save_len; i++) |
| 2551 | { |
| 2552 | for (j=0; j < scan_len; j++) |
| 2553 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2554 | 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] | 2555 | && save_list[i].base_info.auth == scan_list[j].auth) |
| 2556 | { |
| 2557 | if (best_rssi == 0) |
| 2558 | { |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 2559 | best_index = i; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2560 | best_rssi = scan_list[j].rssi; |
| 2561 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2562 | else if (best_rssi > scan_list[j].rssi) |
| 2563 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2564 | best_index = i; |
| 2565 | best_scan_index = j; |
| 2566 | best_rssi = scan_list[j].rssi; |
| 2567 | } |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 2568 | 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] | 2569 | break; |
| 2570 | } |
| 2571 | } |
| 2572 | } |
| 2573 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2574 | if (best_index >= 0) |
| 2575 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2576 | 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] | 2577 | 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] | 2578 | info->status = LYNQ_WIFI_AP_STATUS_DISABLE; |
| 2579 | info->rssi = best_rssi; |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 2580 | ret = 0; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2581 | } |
| 2582 | |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 2583 | if (NULL != scan_list) |
| 2584 | { |
| 2585 | free(scan_list); |
| 2586 | } |
| 2587 | if (NULL != save_list) |
| 2588 | { |
| 2589 | free(save_list); |
| 2590 | } |
| 2591 | |
| 2592 | return ret; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2593 | } |
| 2594 | |
| 2595 | static int inner_set_sta_auth_psw(int net_no, lynq_wifi_auth_s auth, char *password) |
| 2596 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2597 | char lynq_auth_cmd[128]={0}; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2598 | char lynq_ket_mgmt_cmd[64]={0}; |
| 2599 | char lynq_pairwise_cmd[64]={0}; |
| 2600 | char lynq_psk_cmd[64]={0}; |
| 2601 | |
| 2602 | CHECK_WPA_CTRL(CTRL_STA); |
| 2603 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2604 | switch(auth) |
| 2605 | { |
| 2606 | case LYNQ_WIFI_AUTH_OPEN: |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2607 | { |
| 2608 | sprintf(lynq_auth_cmd,"SET_NETWORK %d key_mgmt NONE", net_no); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2609 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2610 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2611 | // DO_OK_FAIL_REQUEST(cmd_save_config); |
| 2612 | break; |
| 2613 | } |
| 2614 | case LYNQ_WIFI_AUTH_WPA_PSK: |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2615 | case LYNQ_WIFI_AUTH_WPA2_PSK: |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2616 | { |
| 2617 | if (auth == LYNQ_WIFI_AUTH_WPA_PSK) |
| 2618 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2619 | sprintf(lynq_auth_cmd,"SET_NETWORK %d proto WPA", net_no); |
| 2620 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2621 | else if (auth == LYNQ_WIFI_AUTH_WPA2_PSK) |
| 2622 | { |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2623 | sprintf(lynq_auth_cmd,"SET_NETWORK %d proto RSN", net_no); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2624 | } |
| 2625 | sprintf(lynq_ket_mgmt_cmd,"SET_NETWORK %d key_mgmt WPA-PSK", net_no); |
| 2626 | sprintf(lynq_pairwise_cmd,"SET_NETWORK %d pairwise CCMP", net_no); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2627 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2628 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
| 2629 | DO_OK_FAIL_REQUEST(lynq_ket_mgmt_cmd); |
| 2630 | DO_OK_FAIL_REQUEST(lynq_pairwise_cmd); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2631 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2632 | if (password != NULL) |
| 2633 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2634 | sprintf(lynq_psk_cmd, "SET_NETWORK %d psk \"%s\"", net_no, password); |
| 2635 | DO_OK_FAIL_REQUEST(lynq_psk_cmd); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2636 | sprintf(lynq_pairwise_cmd,"SET_NETWORK %d pairwise CCMP", net_no); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2637 | } |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2638 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2639 | // DO_OK_FAIL_REQUEST(cmd_save_config); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2640 | break; |
| 2641 | } |
| 2642 | case LYNQ_WIFI_AUTH_WPA2_WPA3_PSK: |
| 2643 | { |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 2644 | sprintf(lynq_auth_cmd,"SET_NETWORK %d ieee80211w 1",net_no); |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 2645 | 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] | 2646 | sprintf(lynq_pairwise_cmd,"SET_NETWORK %d pairwise CCMP", net_no); |
| 2647 | sprintf(lynq_psk_cmd, "SET_NETWORK %d psk \"%s\"", net_no, password); |
| 2648 | |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 2649 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2650 | DO_OK_FAIL_REQUEST(lynq_ket_mgmt_cmd); |
| 2651 | DO_OK_FAIL_REQUEST(lynq_pairwise_cmd); |
| 2652 | DO_OK_FAIL_REQUEST(lynq_psk_cmd); |
| 2653 | |
| 2654 | break; |
| 2655 | } |
| 2656 | case LYNQ_WIFI_AUTH_WPA3_PSK: |
| 2657 | { |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 2658 | sprintf(lynq_auth_cmd,"SET_NETWORK %d ieee80211w 2",net_no); |
qs.xiong | 03556d5 | 2023-04-17 09:45:19 +0800 | [diff] [blame] | 2659 | 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] | 2660 | sprintf(lynq_pairwise_cmd,"SET_NETWORK %d pairwise CCMP", net_no); |
| 2661 | sprintf(lynq_psk_cmd, "SET_NETWORK %d psk \"%s\"", net_no, password); |
| 2662 | |
qs.xiong | 3e50681 | 2023-04-06 11:08:48 +0800 | [diff] [blame] | 2663 | DO_OK_FAIL_REQUEST(lynq_auth_cmd); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2664 | DO_OK_FAIL_REQUEST(lynq_ket_mgmt_cmd); |
| 2665 | DO_OK_FAIL_REQUEST(lynq_pairwise_cmd); |
| 2666 | DO_OK_FAIL_REQUEST(lynq_psk_cmd); |
| 2667 | |
| 2668 | break; |
| 2669 | } |
| 2670 | default: |
| 2671 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2672 | } |
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 | return 0; |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 2675 | } |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2676 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2677 | static int inner_get_curr_net_no(int interface) { |
| 2678 | curr_status_info curr_state; |
| 2679 | curr_state.ap = NULL; |
| 2680 | curr_state.state = NULL; |
| 2681 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2682 | if (0 != inner_get_status_info(interface, &curr_state)) |
| 2683 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2684 | return -1; |
| 2685 | } |
| 2686 | |
| 2687 | return curr_state.net_no; |
| 2688 | } |
| 2689 | |
| 2690 | 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] | 2691 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2692 | int net_no; |
| 2693 | CHECK_IDX(idx, CTRL_STA); |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2694 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2695 | net_no = inner_get_curr_net_no(CTRL_STA); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2696 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2697 | if (net_no < 0) |
| 2698 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2699 | return -1; |
| 2700 | } |
| 2701 | |
| 2702 | return inner_get_network_auth(CTRL_STA, net_no, auth); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2703 | } |
| 2704 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2705 | int lynq_wifi_sta_connect(lynq_wifi_index_e idx, char *ssid, lynq_wifi_auth_s auth, char *psw) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2706 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2707 | int count, net_no, index; |
| 2708 | int net_no_list[128]; |
qs.xiong | f71b53b | 2023-05-03 13:12:07 +0800 | [diff] [blame] | 2709 | char rm_net_cmd[128]; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2710 | lynq_wifi_auth_s net_auth; |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2711 | curr_status_info curr_state; |
| 2712 | ap_info_s ap_info; |
| 2713 | char status[64]; |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2714 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2715 | if (ssid == NULL || *ssid == '\0') |
| 2716 | { |
| 2717 | RLOGE("bad ssid\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2718 | return -1; |
| 2719 | } |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2720 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2721 | if (LYNQ_WIFI_AUTH_OPEN != auth) |
| 2722 | { |
| 2723 | if (psw == NULL || strlen(psw) < 8 || strlen(psw) >= 64) |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2724 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2725 | RLOGE("bad password\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2726 | return -1; |
| 2727 | } |
| 2728 | } |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2729 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2730 | |
| 2731 | pthread_mutex_lock(&s_global_check_mutex); |
| 2732 | if (s_sta_status != INNER_STA_STATUS_INIT) |
| 2733 | { |
| 2734 | s_sta_status = INNER_STA_STATUS_CANCEL; |
| 2735 | pthread_cond_signal(&s_global_check_cond); |
| 2736 | } |
| 2737 | pthread_mutex_unlock(&s_global_check_mutex); |
| 2738 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2739 | CHECK_IDX(idx, CTRL_STA); |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2740 | CHECK_WPA_CTRL(CTRL_STA); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2741 | |
| 2742 | net_no = -1; |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2743 | memset(&ap_info, 0, sizeof (ap_info)); |
| 2744 | memset(status, 0, sizeof (status)); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2745 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2746 | curr_state.ap = &ap_info; |
| 2747 | curr_state.state = status; |
| 2748 | |
| 2749 | 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] | 2750 | { |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2751 | if (strcmp(status, STATE_COMPLETED) == 0 && strcmp(ap_info.ap_ssid, ssid) ==0 && ap_info.auth == auth) |
| 2752 | { |
| 2753 | net_no = curr_state.net_no; |
| 2754 | if (0 == lynq_sta_ssid_password_get(idx, &ap_info, ap_info.psw) |
| 2755 | && strcmp(ap_info.psw, psw) == 0) |
| 2756 | { |
| 2757 | RLOGD("already connected\n"); |
| 2758 | |
| 2759 | pthread_mutex_lock(&s_global_check_mutex); |
| 2760 | s_sta_status = INNER_STA_STATUS_CONNECTED; |
| 2761 | pthread_cond_signal(&s_global_check_cond); |
| 2762 | pthread_mutex_unlock(&s_global_check_mutex); |
| 2763 | return 0; |
| 2764 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2765 | } |
| 2766 | } |
| 2767 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2768 | if (net_no == -1) |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2769 | { |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2770 | count = lynq_get_network_number_list(idx, CTRL_STA, net_no_list, ssid); |
| 2771 | |
| 2772 | for (index=0; index < count; index++) |
| 2773 | { |
| 2774 | net_auth = -1; |
| 2775 | if (0 == inner_get_network_auth(CTRL_STA, net_no_list[index], &net_auth) && net_auth == auth) |
| 2776 | { |
| 2777 | net_no = net_no_list[index]; |
| 2778 | break; |
| 2779 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2780 | } |
| 2781 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2782 | if (net_no < 0) |
| 2783 | { |
qs.xiong | f71b53b | 2023-05-03 13:12:07 +0800 | [diff] [blame] | 2784 | count = lynq_get_network_number_list(idx, CTRL_STA, net_no_list, NULL); |
| 2785 | for ( index = 0; index < (count - STA_MAX_SAVED_AP_NUM + 1 ) ;index++) //+1 is for add new network |
| 2786 | { |
| 2787 | sprintf(rm_net_cmd,"REMOVE_NETWORK %d",net_no_list[index]); |
| 2788 | RLOGD("call cmd rm_net_cmd: %s;index is %d\n",rm_net_cmd,index); |
| 2789 | DO_OK_FAIL_REQUEST(rm_net_cmd); |
| 2790 | } |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2791 | net_no = lynq_add_network(CTRL_STA); |
| 2792 | if (net_no == -1) |
| 2793 | { |
| 2794 | return -1; |
| 2795 | } |
| 2796 | |
| 2797 | RLOGD("net no is %d\n", net_no); |
| 2798 | if (0 != inner_set_sta_ssid(net_no, ssid)) |
| 2799 | { |
| 2800 | return -1; |
| 2801 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2802 | } |
| 2803 | } |
| 2804 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2805 | if (0 != inner_set_sta_auth_psw(net_no, auth, psw)) |
| 2806 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2807 | return -1; |
| 2808 | } |
| 2809 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2810 | |
| 2811 | DO_OK_FAIL_REQUEST(cmd_disconnect); |
| 2812 | usleep(200*1000); |
| 2813 | |
| 2814 | ret = inner_sta_start_stop(net_no, 1, 1); |
| 2815 | |
| 2816 | pthread_mutex_lock(&s_global_check_mutex); |
| 2817 | s_sta_status = INNER_STA_STATUS_CONNECTING; |
| 2818 | strcpy(s_sta_current_connecting_ssid, ssid); |
| 2819 | struct timeval now; |
| 2820 | gettimeofday(&now,NULL); |
| 2821 | s_sta_connect_timeout.tv_sec = now.tv_sec + MAX_CONNNECT_TIME; |
| 2822 | s_sta_connect_timeout.tv_nsec = now.tv_usec*1000; |
| 2823 | pthread_cond_signal(&s_global_check_cond); |
| 2824 | pthread_mutex_unlock(&s_global_check_mutex); |
| 2825 | return ret; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2826 | } |
| 2827 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2828 | int lynq_wifi_sta_disconnect(lynq_wifi_index_e idx, char *ssid) |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2829 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2830 | ap_info_s ap; |
| 2831 | curr_status_info curr_state; |
| 2832 | ap.ap_ssid[0] = '\0'; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2833 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2834 | if (ssid == NULL || *ssid == '\0') |
| 2835 | { |
| 2836 | RLOGE("input ssid is NULL\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2837 | return -1; |
| 2838 | } |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2839 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2840 | CHECK_IDX(idx, CTRL_STA); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2841 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2842 | curr_state.ap = ≈ |
you.chen | b4b121c | 2022-05-06 17:50:16 +0800 | [diff] [blame] | 2843 | curr_state.state = NULL; |
| 2844 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2845 | if (inner_get_status_info(CTRL_STA, &curr_state) != 0) |
| 2846 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2847 | return 0; |
| 2848 | } |
qs.xiong | 1af5daf | 2022-03-14 09:12:12 -0400 | [diff] [blame] | 2849 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2850 | if (strcmp(ap.ap_ssid, ssid) != 0) |
| 2851 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2852 | return 0; |
| 2853 | } |
| 2854 | |
you.chen | 70f377f | 2023-04-14 18:17:09 +0800 | [diff] [blame] | 2855 | pthread_mutex_lock(&s_global_check_mutex); |
| 2856 | s_sta_status = INNER_STA_STATUS_DISCONNECTING; |
| 2857 | pthread_mutex_unlock(&s_global_check_mutex); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2858 | return inner_sta_start_stop(curr_state.net_no, 0, 0); |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2859 | } |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2860 | |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2861 | int lynq_wifi_sta_start(lynq_wifi_index_e idx) |
| 2862 | { |
qs.xiong | ad2f89d | 2023-01-18 13:17:41 +0800 | [diff] [blame] | 2863 | // const char *lynq_reconfigure_cmd = "wpa_cli -iwpa_wlan0_cmd -p/var/run/ IFNAME=wlan0 RECONFIGURE /data/wifi/wg870/wpa_supplicant.conf"; |
| 2864 | // const char *lynq_reconnect_cmd = "RECONNECT"; |
| 2865 | const char *lynq_enable_sta_cmd = "wpa_cli -iwpa_wlan0_cmd -p/var/run/ IFNAME=wlan0 enable_net all"; |
| 2866 | const char *lynq_reconnect_cmd = "wpa_cli -iwpa_wlan0_cmd -p/var/run/ IFNAME=wlan0 reconnect"; |
| 2867 | // 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] | 2868 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2869 | CHECK_IDX(idx, CTRL_STA); |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2870 | CHECK_WPA_CTRL(CTRL_STA); |
| 2871 | |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 2872 | ret = system_call_v("%s %s", start_stop_sta_script, "start"); |
| 2873 | if (ret != 0) |
qs.xiong | ad2f89d | 2023-01-18 13:17:41 +0800 | [diff] [blame] | 2874 | { |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 2875 | RLOGE("lynq_wifi_ap_start excute script fail"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2876 | return -1; |
| 2877 | } |
qs.xiong | 9c99fa9 | 2022-03-15 08:03:26 -0400 | [diff] [blame] | 2878 | |
qs.xiong | ad2f89d | 2023-01-18 13:17:41 +0800 | [diff] [blame] | 2879 | system(lynq_enable_sta_cmd); |
| 2880 | system(lynq_reconnect_cmd); |
| 2881 | // DO_OK_FAIL_REQUEST(lynq_reconnect_cmd); |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2882 | return 0; |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2883 | } |
| 2884 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2885 | int lynq_wifi_sta_stop(lynq_wifi_index_e idx) |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2886 | { |
qs.xiong | ad2f89d | 2023-01-18 13:17:41 +0800 | [diff] [blame] | 2887 | // char lynq_disable_network_cmd[MAX_CMD]; |
| 2888 | // curr_status_info curr_state; |
| 2889 | // ap_info_s ap_info; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2890 | |
qs.xiong | ad2f89d | 2023-01-18 13:17:41 +0800 | [diff] [blame] | 2891 | 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] | 2892 | CHECK_IDX(idx, CTRL_STA); |
| 2893 | CHECK_WPA_CTRL(CTRL_STA); |
| 2894 | |
qs.xiong | ad2f89d | 2023-01-18 13:17:41 +0800 | [diff] [blame] | 2895 | system(lynq_disable_sta_cmd); |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2896 | DO_OK_FAIL_REQUEST(cmd_save_config); |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 2897 | |
| 2898 | ret = system_call_v("%s %s", start_stop_sta_script, "stop"); |
| 2899 | if (ret != 0) |
| 2900 | { |
| 2901 | RLOGE("lynq_wifi_ap_start excute script fail"); |
| 2902 | return -1; |
| 2903 | } |
| 2904 | |
you.chen | a6cd55a | 2022-05-08 12:20:18 +0800 | [diff] [blame] | 2905 | return 0; |
| 2906 | // return system("connmanctl disable wifi"); |
qs.xiong | f1b525b | 2022-03-31 00:58:23 -0400 | [diff] [blame] | 2907 | } |
qs.xiong | 7a105ce | 2022-03-02 09:43:11 -0500 | [diff] [blame] | 2908 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2909 | //static int inner_get_sta_info(lynq_wifi_index_e idx, const char * bssid, device_info_s *dev) { |
| 2910 | // int i, count; |
| 2911 | // char *p; |
| 2912 | // const char * FLAG_SSID = "ssid="; |
| 2913 | // const char * FLAG_SBSID = "bssid="; |
| 2914 | // const char * FLAG_KEY_MGMT = "key_mgmt="; |
| 2915 | // const char * FLAG_FREQ = "freq="; |
| 2916 | // char lynq_sta_cmd[MAX_CMD]; |
| 2917 | // char *split_lines[128] = {0}; |
| 2918 | |
| 2919 | // CHECK_WPA_CTRL(CTRL_AP); |
| 2920 | |
| 2921 | // sprintf(lynq_sta_cmd, "STA %s", bssid); |
| 2922 | |
| 2923 | // DO_REQUEST(lynq_sta_cmd); |
| 2924 | |
| 2925 | // count = lynq_split(cmd_reply, reply_len, '\n', split_lines); |
| 2926 | |
| 2927 | // for(i=0; i < count; i++) { |
| 2928 | // p = strstr(split_lines[i], FLAG_SSID); |
| 2929 | // if (p != NULL) { |
| 2930 | // strcpy(ap->ap_ssid, p + strlen(FLAG_SSID)); |
| 2931 | // continue; |
| 2932 | // } |
| 2933 | // } |
| 2934 | |
| 2935 | // lynq_get_interface_ip(idx, ap->ap_ip); |
| 2936 | // lynq_ap_password_set(idx, ap->psw); |
| 2937 | |
| 2938 | // return 0; |
| 2939 | //} |
| 2940 | |
| 2941 | static int inner_get_status_info_ap (int interface, ap_info_s *ap) { |
| 2942 | curr_status_info curr_state; |
| 2943 | curr_state.ap = ap; |
| 2944 | curr_state.state = NULL; |
| 2945 | return inner_get_status_info(interface, &curr_state); |
| 2946 | } |
| 2947 | |
| 2948 | 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] | 2949 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 2950 | int index, line_count; |
| 2951 | device_info_s *dev_info; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2952 | const char *lynq_first_sta_cmd = "STA-FIRST"; |
| 2953 | char lynq_next_sta_cmd[MAX_CMD]; |
| 2954 | char *bssid[1024] = {0}; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2955 | char *split_lines[128] = {0}; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2956 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2957 | CHECK_IDX(idx, CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2958 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2959 | CHECK_WPA_CTRL(CTRL_AP); |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 2960 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2961 | // ap_info_s * tmp_ap; |
| 2962 | // device_info_s * tmp_list; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2963 | if (ap == NULL || list == NULL || len == NULL) |
| 2964 | { |
| 2965 | RLOGE("bad input param"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2966 | return -1; |
| 2967 | } |
| 2968 | |
| 2969 | // ap = &tmp_ap; |
| 2970 | // list = &tmp_list; |
| 2971 | *ap = malloc(sizeof (ap_info_s)); |
| 2972 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2973 | if (inner_get_status_info_ap (CTRL_AP, *ap) != 0) |
| 2974 | { |
| 2975 | RLOGE("inner_get_status_info_ap !=0\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2976 | return -1; |
| 2977 | } |
| 2978 | |
| 2979 | lynq_get_interface_ip(idx, (*ap)->ap_ip); |
| 2980 | lynq_ap_password_get(idx, (*ap)->psw); |
| 2981 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2982 | DO_REQUEST(lynq_first_sta_cmd); |
| 2983 | |
| 2984 | index = 0; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 2985 | while (reply_len > 0) |
| 2986 | { |
| 2987 | if (memcmp(cmd_reply, "FAIL", 4) == 0) |
| 2988 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 2989 | break; |
| 2990 | } |
| 2991 | line_count = lynq_split(cmd_reply, reply_len, '\n', split_lines); |
| 2992 | bssid[index] = malloc(strlen(split_lines[0]) + 1); |
| 2993 | strcpy(bssid[index], split_lines[0]); |
| 2994 | index++; |
| 2995 | sprintf(lynq_next_sta_cmd, "STA-NEXT %s", split_lines[0]); |
| 2996 | reply_len = MAX_RET; |
| 2997 | cmd_reply[0] = '\0'; |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 2998 | 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] | 2999 | if (ret != 0 || memcmp(cmd_reply, "FAIL", 4) == 0) |
| 3000 | { |
| 3001 | RLOGD("run %s fail \n", lynq_next_sta_cmd); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3002 | break; |
| 3003 | } |
| 3004 | } |
| 3005 | |
| 3006 | *len = index; |
| 3007 | |
| 3008 | *list = malloc(sizeof(device_info_s) * (*len)); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3009 | for (index=0; index < *len; index++) |
| 3010 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 3011 | dev_info = &(*list)[index]; |
| 3012 | memset(dev_info, 0, sizeof(device_info_s)); |
| 3013 | strncpy(dev_info->sta_mac, bssid[index], sizeof (dev_info->sta_mac)); |
| 3014 | inner_get_ip_by_mac(dev_info->sta_mac, dev_info->sta_ip, sizeof (dev_info->sta_ip)); |
| 3015 | inner_get_hostname_by_ip(dev_info->sta_ip, dev_info->hostname); |
| 3016 | dev_info->status = LYNQ_WIFI_STATUS_CONNECT; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3017 | free(bssid[index]); |
| 3018 | } |
| 3019 | |
| 3020 | return 0; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 3021 | } |
| 3022 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3023 | 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] | 3024 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3025 | int i, count, index, count_words; |
| 3026 | const char *lynq_scan_result_cmd = "SCAN_RESULTS"; |
| 3027 | char *split_lines[128] = {0}; |
| 3028 | char *split_words[128] = {0}; |
| 3029 | scan_info_s * p; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 3030 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3031 | if (list == NULL || len == NULL) |
| 3032 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3033 | return -1; |
| 3034 | } |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 3035 | |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3036 | for (i =0; i < 50 && g_sta_scan_finish_flag == 0; i++) |
| 3037 | { |
| 3038 | usleep(100 * 1000); |
| 3039 | } |
| 3040 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3041 | CHECK_IDX(idx, CTRL_STA); |
| 3042 | |
| 3043 | CHECK_WPA_CTRL(CTRL_STA); |
| 3044 | |
| 3045 | DO_REQUEST(lynq_scan_result_cmd); |
| 3046 | |
| 3047 | count = lynq_split(cmd_reply, reply_len, '\n', split_lines); |
| 3048 | *len = count - 1; |
| 3049 | *list = malloc(sizeof (scan_info_s) * *len); |
| 3050 | |
| 3051 | 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] | 3052 | for (index=0; index <count_words; index++) |
| 3053 | { |
| 3054 | RLOGD("----header: %s\n", split_words[index]); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3055 | } |
| 3056 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3057 | for(index = 1;index < count; index++) |
| 3058 | { |
| 3059 | RLOGD("---- %s\n",split_lines[index]); |
you.chen | 6ed36a6 | 2023-04-27 17:51:56 +0800 | [diff] [blame] | 3060 | memset(split_words, 0 , sizeof (split_words)); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3061 | count_words = lynq_split(split_lines[index], strlen(split_lines[index]), '\t', split_words); |
| 3062 | if (count_words < 4) |
| 3063 | continue; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3064 | RLOGD("count: %d, %s\n", count_words, split_words[0]); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3065 | //bssid / frequency / signal level / flags / ssid |
| 3066 | p = (*list) + index - 1; |
| 3067 | strcpy(p->mac, split_words[0]); |
| 3068 | p->band = convert_band_from_freq(atoi(split_words[1])); |
| 3069 | p->rssi = -1 * atoi( split_words[2]); |
| 3070 | p->auth = convert_max_auth_from_flag(split_words[3]); |
you.chen | 6ed36a6 | 2023-04-27 17:51:56 +0800 | [diff] [blame] | 3071 | if (count_words == 4) // ssid hided |
| 3072 | { |
| 3073 | p->ssid[0] = '\0'; |
| 3074 | } |
| 3075 | else |
| 3076 | { |
| 3077 | inner_copy_ssid(p->ssid, split_words[4], sizeof (p->ssid)); |
| 3078 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3079 | } |
| 3080 | |
| 3081 | return 0; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 3082 | } |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 3083 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3084 | int lynq_sta_forget_ap(lynq_wifi_index_e idx, char *ssid, lynq_wifi_auth_s auth) |
| 3085 | { |
| 3086 | int count, net_no, index; |
| 3087 | int net_no_list[128]; |
| 3088 | lynq_wifi_auth_s net_auth; |
| 3089 | char lynq_remove_cmd[MAX_CMD]; |
| 3090 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3091 | if (ssid == NULL || *ssid == '\0') |
| 3092 | { |
| 3093 | RLOGD("bad ssid\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3094 | return -1; |
| 3095 | } |
| 3096 | |
| 3097 | CHECK_IDX(idx, CTRL_STA); |
| 3098 | |
| 3099 | CHECK_WPA_CTRL(CTRL_STA); |
| 3100 | |
| 3101 | net_no = -1; |
| 3102 | count = lynq_get_network_number_list(idx, CTRL_STA, net_no_list, ssid); |
| 3103 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3104 | for (index=0; index < count; index++) |
| 3105 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3106 | net_auth = -1; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3107 | if (0 == inner_get_network_auth(CTRL_STA, net_no_list[index], &net_auth) && net_auth == auth) |
| 3108 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3109 | net_no = net_no_list[index]; |
| 3110 | break; |
| 3111 | } |
| 3112 | } |
| 3113 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3114 | if (net_no < 0) |
| 3115 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3116 | return 0; |
| 3117 | } |
| 3118 | |
| 3119 | sprintf(lynq_remove_cmd, "REMOVE_NETWORK %d", net_no); |
| 3120 | |
| 3121 | DO_OK_FAIL_REQUEST(lynq_remove_cmd); |
| 3122 | DO_OK_FAIL_REQUEST(cmd_save_config); |
| 3123 | |
| 3124 | return 0; |
| 3125 | } |
| 3126 | |
| 3127 | 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] | 3128 | { |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 3129 | int count, index; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3130 | int net_no_list[128]; |
| 3131 | char freq[16]; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3132 | RLOGD("enter lynq_get_sta_saved_ap api\n"); |
| 3133 | if (list == NULL || len == NULL) |
| 3134 | { |
| 3135 | RLOGE("bad param,please check!"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3136 | return -1; |
| 3137 | } |
| 3138 | |
| 3139 | CHECK_IDX(idx, CTRL_STA); |
| 3140 | |
| 3141 | // CHECK_WPA_CTRL(CTRL_STA); |
| 3142 | |
| 3143 | 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] | 3144 | RLOGD("[lynq_get_sta_saved_ap]count is %d\n", count); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3145 | |
you.chen | 057aac4 | 2023-04-13 14:06:58 +0800 | [diff] [blame] | 3146 | if (count < 0) |
| 3147 | { |
| 3148 | RLOGE("list network fail"); |
| 3149 | return count; |
| 3150 | } |
| 3151 | else if (count == 0) |
| 3152 | { |
| 3153 | *list = NULL; |
| 3154 | *len = 0; |
| 3155 | return 0; |
| 3156 | } |
| 3157 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3158 | *list = malloc(sizeof (saved_ap_info_s) * count); |
you.chen | 755332b | 2022-08-06 16:59:10 +0800 | [diff] [blame] | 3159 | memset(*list, 0, sizeof (saved_ap_info_s) * count); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3160 | *len = count; |
| 3161 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3162 | for (index=0; index < count; index++) |
| 3163 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3164 | 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] | 3165 | 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] | 3166 | 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] | 3167 | 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] | 3168 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3169 | (*list)[index].base_info.band = convert_band_from_freq(atoi(freq)); |
| 3170 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3171 | else |
you.chen | 057aac4 | 2023-04-13 14:06:58 +0800 | [diff] [blame] | 3172 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3173 | (*list)[index].base_info.band = -1; |
| 3174 | } |
you.chen | 057aac4 | 2023-04-13 14:06:58 +0800 | [diff] [blame] | 3175 | RLOGD("[lynq_get_sta_saved_ap][inner_get_param]to get psw"); |
you.chen | 755332b | 2022-08-06 16:59:10 +0800 | [diff] [blame] | 3176 | 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] | 3177 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3178 | RLOGD("[lynq_get_sta_saved_ap] return ok"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3179 | return 0; |
| 3180 | } |
| 3181 | |
| 3182 | int lynq_wifi_sta_start_scan(lynq_wifi_index_e idx) |
| 3183 | { |
qs.xiong | c8d92a6 | 2023-03-29 17:36:14 +0800 | [diff] [blame] | 3184 | 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] | 3185 | const char *lynq_scan_cmd = "SCAN"; |
| 3186 | |
| 3187 | CHECK_IDX(idx, CTRL_STA); |
| 3188 | |
| 3189 | CHECK_WPA_CTRL(CTRL_STA); |
| 3190 | |
you.chen | 0df3e7e | 2023-05-10 15:56:26 +0800 | [diff] [blame^] | 3191 | if (g_sta_scan_finish_flag == 1 && s_sta_status == INNER_STA_STATUS_INIT) // temp add |
| 3192 | { |
| 3193 | RLOGD("tmp clear scanlist"); |
| 3194 | system(clean_last_re); |
| 3195 | } |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3196 | g_sta_scan_finish_flag = 0; |
qs.xiong | b3f26af | 2023-02-17 18:41:07 +0800 | [diff] [blame] | 3197 | DO_REQUEST(lynq_scan_cmd); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3198 | if (reply_len >=9 && memcmp(cmd_reply, "FAIL-BUSY", 9) == 0 ) |
| 3199 | { |
qs.xiong | b3f26af | 2023-02-17 18:41:07 +0800 | [diff] [blame] | 3200 | return 0; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3201 | } else if (reply_len >=2 && memcmp(cmd_reply, "OK", 2) != 0) |
| 3202 | { |
qs.xiong | b3f26af | 2023-02-17 18:41:07 +0800 | [diff] [blame] | 3203 | g_sta_scan_finish_flag = 1; |
| 3204 | return -1; |
| 3205 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3206 | |
| 3207 | return 0; |
| 3208 | } |
| 3209 | |
| 3210 | 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] | 3211 | if (cb == NULL) |
| 3212 | { |
| 3213 | RLOGE("lynq_reg_ap_event_callback ptr is NULL,plese check!\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3214 | return -1; |
| 3215 | } |
| 3216 | |
you.chen | e9d0003 | 2023-04-24 13:55:29 +0800 | [diff] [blame] | 3217 | pthread_mutex_lock(&s_check_wpa_ctrl_mutex); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3218 | g_ap_callback_priv = priv; |
| 3219 | g_ap_callback_func = cb; |
| 3220 | |
you.chen | e9d0003 | 2023-04-24 13:55:29 +0800 | [diff] [blame] | 3221 | if (g_ap_watcher_pid == 0 ) |
| 3222 | { |
| 3223 | if(pthread_create(&g_ap_watcher_pid,NULL,APWatcherThreadProc,NULL) < 0) |
| 3224 | { |
| 3225 | g_ap_watcher_pid = 0; |
| 3226 | pthread_mutex_unlock(&s_check_wpa_ctrl_mutex); |
| 3227 | RLOGE("[wifi error]creat APWatcherThreadProc fail"); |
| 3228 | return -1; |
| 3229 | } |
| 3230 | } |
| 3231 | |
| 3232 | pthread_mutex_unlock(&s_check_wpa_ctrl_mutex); |
| 3233 | RLOGD("creat APWatcherTheradProc susccs"); |
| 3234 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3235 | return 0; |
| 3236 | } |
| 3237 | |
| 3238 | int lynq_unreg_ap_event_callback(void * priv) { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3239 | if (g_ap_callback_priv == priv) |
| 3240 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3241 | g_ap_callback_func = NULL; |
| 3242 | g_ap_callback_priv = NULL; |
| 3243 | return 0; |
| 3244 | } |
| 3245 | return -1; |
| 3246 | } |
| 3247 | |
| 3248 | 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] | 3249 | if (cb == NULL) |
| 3250 | { |
| 3251 | RLOGE("lynq_reg_sta_event_callback ptr is NULL,plese check!\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3252 | return -1; |
| 3253 | } |
| 3254 | |
you.chen | e9d0003 | 2023-04-24 13:55:29 +0800 | [diff] [blame] | 3255 | pthread_mutex_lock(&s_check_wpa_ctrl_mutex); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3256 | g_sta_callback_priv = priv; |
| 3257 | g_sta_callback_func = cb; |
| 3258 | |
you.chen | e9d0003 | 2023-04-24 13:55:29 +0800 | [diff] [blame] | 3259 | if (g_sta_watcher_pid == 0 ) { |
| 3260 | if(pthread_create(&g_sta_watcher_pid,NULL,STAWatcherThreadProc,NULL) < 0) |
| 3261 | { |
| 3262 | g_sta_watcher_pid = 0; |
| 3263 | pthread_mutex_unlock(&s_check_wpa_ctrl_mutex); |
| 3264 | RLOGE("[wifi error]creat STAWatcherThreadProc fail"); |
| 3265 | return -1; |
| 3266 | } |
| 3267 | } |
| 3268 | |
| 3269 | pthread_mutex_unlock(&s_check_wpa_ctrl_mutex); |
| 3270 | RLOGD("creat STAWatcherTheradProc susccs"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3271 | return 0; |
| 3272 | } |
| 3273 | |
| 3274 | int lynq_unreg_sta_event_callback(void * priv) { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3275 | if (g_sta_callback_priv == priv) |
| 3276 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3277 | g_sta_callback_func = NULL; |
| 3278 | g_sta_callback_priv = NULL; |
| 3279 | return 0; |
| 3280 | } |
| 3281 | return -1; |
| 3282 | } |
| 3283 | |
| 3284 | |
| 3285 | static int inner_get_status_info_state (int interface, char *state) { |
| 3286 | curr_status_info curr_state; |
| 3287 | curr_state.ap = NULL; |
| 3288 | curr_state.state = state; |
| 3289 | return inner_get_status_info(interface, &curr_state); |
| 3290 | } |
| 3291 | |
| 3292 | int lynq_get_ap_status(lynq_wifi_index_e idx, lynq_wifi_ap_run_status_s * ap_status) |
| 3293 | { |
| 3294 | char state[MAX_CMD]; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3295 | RLOGD("enter lynq_get_ap_status\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3296 | CHECK_IDX(idx, CTRL_AP); |
| 3297 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3298 | if (inner_get_status_info_state(CTRL_AP, state) != 0) |
| 3299 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3300 | *ap_status = LYNQ_WIFI_AP_STATUS_DISABLE; |
| 3301 | return 0; |
| 3302 | } |
| 3303 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3304 | if (memcmp(state, STATE_COMPLETED, strlen (STATE_COMPLETED)) == 0) |
| 3305 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3306 | *ap_status = LYNQ_WIFI_AP_STATUS_ENABLE; |
| 3307 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3308 | else |
| 3309 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3310 | *ap_status = LYNQ_WIFI_AP_STATUS_DISABLE; |
| 3311 | } |
| 3312 | |
| 3313 | return 0; |
| 3314 | } |
| 3315 | |
| 3316 | int lynq_get_sta_status(lynq_wifi_index_e idx, lynq_wifi_sta_run_status_s * sta_status) { |
| 3317 | char state[MAX_CMD]; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3318 | RLOGD("enter lynq_get_sta_status\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3319 | CHECK_IDX(idx, CTRL_STA); |
| 3320 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3321 | if (inner_get_status_info_state(CTRL_STA, state) != 0) |
| 3322 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3323 | *sta_status = LYNQ_WIFI_STA_STATUS_DISABLE; |
| 3324 | return 0; |
| 3325 | } |
| 3326 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3327 | if (memcmp(state, STATE_COMPLETED, strlen (STATE_COMPLETED)) == 0) |
| 3328 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3329 | *sta_status = LYNQ_WIFI_STA_STATUS_ENABLE; |
| 3330 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3331 | else |
| 3332 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3333 | *sta_status = LYNQ_WIFI_STA_STATUS_DISABLE; |
| 3334 | } |
| 3335 | |
| 3336 | return 0; |
| 3337 | } |
| 3338 | |
| 3339 | int lynq_get_country_code(lynq_wifi_index_e idx, char * country_code) { |
| 3340 | // CHECK_IDX(idx, CTRL_AP); |
| 3341 | // int ret = 0; |
| 3342 | // size_t reply_len = MAX_RET; |
| 3343 | // char cmd_reply[MAX_RET]={0}; |
| 3344 | // const char * cmd_str = "GET country"; |
| 3345 | // struct wpa_ctrl *s_lynq_wpa_ctrl = NULL; |
| 3346 | // do{ |
| 3347 | // if (NULL == s_lynq_wpa_ctrl) { |
| 3348 | // s_lynq_wpa_ctrl = wpa_ctrl_open("/var/run/wpa_wlan0_cmd"); |
| 3349 | // if (NULL == s_lynq_wpa_ctrl ) { |
| 3350 | // printf("wpa_ctrl_open fail\n"); |
| 3351 | // return -1; |
| 3352 | // } |
| 3353 | // } |
| 3354 | // }while(0); |
| 3355 | |
| 3356 | // do { |
| 3357 | // reply_len = MAX_RET; |
| 3358 | // cmd_reply[0] = '\0'; |
| 3359 | // printf("to call [%s]\n", cmd_str); |
you.chen | d2fef3f | 2023-02-13 10:50:35 +0800 | [diff] [blame] | 3360 | // 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] | 3361 | // if (ret != 0) { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3362 | // RLOGE("call ##cmd_str fail %d\n", ret); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3363 | // return ret; |
| 3364 | // } |
| 3365 | // cmd_reply[reply_len+1] = '\0'; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3366 | // RLOGD("cmd replay [ %s ]\n", cmd_reply); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3367 | // }while(0); |
| 3368 | |
| 3369 | FILE *fp; |
| 3370 | size_t i = 0; |
| 3371 | char lynq_cmd_ret[MAX_RET]={0}; |
| 3372 | |
| 3373 | // CHECK_IDX(idx, CTRL_AP); |
| 3374 | |
| 3375 | if((fp=popen("wl country","r"))==NULL) |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3376 | { |
| 3377 | perror("popen error!"); |
| 3378 | return -1; |
| 3379 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3380 | if((fread(lynq_cmd_ret,sizeof(lynq_cmd_ret),1,fp))<0) |
| 3381 | { |
| 3382 | perror("fread fail!"); |
| 3383 | return -1; |
| 3384 | } |
| 3385 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3386 | for(i=0; i < strlen(lynq_cmd_ret); i++) |
| 3387 | { |
| 3388 | if (lynq_cmd_ret[i] == ' ') |
| 3389 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3390 | lynq_cmd_ret[i] = '\0'; |
| 3391 | break; |
| 3392 | } |
| 3393 | } |
| 3394 | |
| 3395 | strcpy(country_code,lynq_cmd_ret); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3396 | RLOGD("---country code %s\n", country_code); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3397 | |
| 3398 | int ret=pclose(fp); |
| 3399 | if(ret==-1) |
| 3400 | { |
| 3401 | perror("close file faild"); |
| 3402 | } |
| 3403 | |
| 3404 | return 0; |
| 3405 | } |
| 3406 | |
| 3407 | int lynq_set_country_code(lynq_wifi_index_e idx, char * country_code) { |
| 3408 | // const char * cmd_str = "GET country"; |
| 3409 | // CHECK_IDX(idx, CTRL_AP); |
| 3410 | // CHECK_WPA_CTRL(CTRL_STA); |
| 3411 | |
| 3412 | // DO_REQUEST(cmd_str); |
| 3413 | // printf("result %s\n", cmd_reply); |
| 3414 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3415 | if (country_code == NULL || *country_code == '\0') |
| 3416 | { |
| 3417 | RLOGD("bad country code\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3418 | return -1; |
| 3419 | } |
| 3420 | |
| 3421 | char lynq_country_cmd[MAX_CMD]; |
| 3422 | sprintf(lynq_country_cmd, "wl country %s", country_code); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3423 | if (system(lynq_country_cmd) == 0) |
| 3424 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3425 | return 0; |
| 3426 | } |
| 3427 | |
| 3428 | return -1; |
| 3429 | } |
| 3430 | |
| 3431 | int lynq_get_connect_ap_mac(lynq_wifi_index_e idx,char *mac) |
| 3432 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3433 | RLOGD("enter lynq_get_connect_ap_mac\n"); |
| 3434 | if (mac == NULL) |
| 3435 | { |
| 3436 | RLOGE("input ptr is NULL,please check\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3437 | return -1; |
| 3438 | } |
| 3439 | |
| 3440 | CHECK_IDX(idx, CTRL_STA); |
| 3441 | ap_info_s ap; |
| 3442 | ap.ap_mac[0] = '\0'; |
| 3443 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3444 | if (inner_get_status_info_ap(CTRL_STA, &ap) != 0) |
| 3445 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3446 | return -1; |
| 3447 | } |
| 3448 | strcpy(mac, ap.ap_mac); |
| 3449 | |
| 3450 | return 0; |
| 3451 | } |
| 3452 | |
| 3453 | int lynq_get_interface_ip(lynq_wifi_index_e idx, char *ip) |
| 3454 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3455 | RLOGD("enter lynq_get_interface_ip\n"); |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3456 | struct ifaddrs *ifaddr_header, *ifaddr; |
| 3457 | struct in_addr * ifa; |
| 3458 | const char * ifaName = "wlan0"; |
| 3459 | if (ip == NULL) |
| 3460 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3461 | 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] | 3462 | return -1; |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3463 | } |
you.chen | f58b3c9 | 2022-06-21 16:53:48 +0800 | [diff] [blame] | 3464 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3465 | if (idx == 1) |
| 3466 | { |
you.chen | 0df3e7e | 2023-05-10 15:56:26 +0800 | [diff] [blame^] | 3467 | ifaName = inner_get_ap_interface_name(); |
| 3468 | if (ifaName == NULL) |
| 3469 | { |
| 3470 | RLOGE("[lynq_get_interface_ip] ap name get fail"); |
| 3471 | return -1; |
| 3472 | } |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3473 | } |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3474 | else if (idx != 0) |
| 3475 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3476 | return -1; |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3477 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3478 | |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3479 | if (getifaddrs(&ifaddr_header) == -1) |
| 3480 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3481 | perror("getifaddrs"); |
| 3482 | return -1; |
| 3483 | //exit(EXIT_FAILURE); |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3484 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3485 | |
| 3486 | |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3487 | for (ifaddr = ifaddr_header; ifaddr != NULL; ifaddr = ifaddr->ifa_next) |
| 3488 | { |
| 3489 | if (ifaddr->ifa_addr == NULL) |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3490 | continue; |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3491 | if((strcmp(ifaddr->ifa_name,ifaName)==0)) |
| 3492 | { |
| 3493 | if (ifaddr->ifa_addr->sa_family==AF_INET) // check it is IP4 |
| 3494 | { |
| 3495 | // is a valid IP4 Address |
| 3496 | ifa=&((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr; |
| 3497 | inet_ntop(AF_INET, ifa, ip, INET_ADDRSTRLEN); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3498 | 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] | 3499 | freeifaddrs(ifaddr_header); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3500 | RLOGD("ip %s\n", ip); |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3501 | return 0; |
| 3502 | } |
| 3503 | } |
| 3504 | } |
qs.xiong | c4f007c | 2023-02-08 18:16:58 +0800 | [diff] [blame] | 3505 | freeifaddrs(ifaddr_header); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3506 | RLOGE("[lynq_get_interface_ip] can't find interface | other erro\n"); |
you.chen | 9ac6639 | 2022-08-06 17:01:16 +0800 | [diff] [blame] | 3507 | return -1; |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3508 | } |
| 3509 | |
| 3510 | int lynq_get_interface_mac(lynq_wifi_index_e idx,char *mac) |
| 3511 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3512 | RLOGD("enter lynq_get_interface_mac\n"); |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3513 | int count; |
| 3514 | size_t i; |
| 3515 | char *split_words[128] = {0}; |
| 3516 | const char *lynq_get_mac_cmd = "DRIVER MACADDR"; |
| 3517 | |
| 3518 | CHECK_WPA_CTRL(idx); |
| 3519 | |
| 3520 | DO_REQUEST(lynq_get_mac_cmd); |
| 3521 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3522 | if (memcmp(cmd_reply, "FAIL", 4) == 0) |
| 3523 | { |
| 3524 | 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] | 3525 | return -1; |
| 3526 | } |
| 3527 | |
| 3528 | count = lynq_split(cmd_reply, reply_len, '=', split_words); |
| 3529 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3530 | if (count < 2) |
| 3531 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3532 | return -1; |
| 3533 | } |
| 3534 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3535 | for (i=0; i < strlen(split_words[1]); i++ ) |
| 3536 | { |
| 3537 | if (split_words[1][i] != ' ') |
| 3538 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3539 | break; |
| 3540 | } |
| 3541 | } |
| 3542 | |
| 3543 | strcpy(mac, split_words[1] + i); |
| 3544 | |
| 3545 | return 0; |
| 3546 | } |
| 3547 | |
| 3548 | int lynq_get_connect_ap_rssi(lynq_wifi_index_e idx,int * rssi) |
| 3549 | { |
| 3550 | // int count; |
| 3551 | // char *split_words[128] = {0}; |
| 3552 | // const char *lynq_get_rssi_cmd = "DRIVER RSSI"; |
| 3553 | |
| 3554 | // if (rssi == NULL) { |
| 3555 | // return -1; |
| 3556 | // } |
| 3557 | |
| 3558 | // CHECK_IDX(idx, CTRL_STA); |
| 3559 | |
| 3560 | // CHECK_WPA_CTRL(CTRL_STA); |
| 3561 | |
| 3562 | // DO_REQUEST(lynq_get_rssi_cmd); |
| 3563 | |
| 3564 | // if (memcmp(cmd_reply, "FAIL", 4) == 0) { |
| 3565 | // return -1; |
| 3566 | // } |
| 3567 | |
| 3568 | // count = lynq_split(cmd_reply, reply_len, ' ', split_words); |
| 3569 | |
| 3570 | // if (count < 2) { |
| 3571 | // return -1; |
| 3572 | // } |
| 3573 | |
| 3574 | // *rssi = atoi(split_words[1]) * -1; |
| 3575 | |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3576 | char lynq_cmd_ret[MAX_RET]={0}; |
| 3577 | |
qs.xiong | ff0ae0f | 2022-10-11 15:47:14 +0800 | [diff] [blame] | 3578 | /*******change other cmd to get rssi******* |
| 3579 | * |
| 3580 | *wl rssi ---> wl -i wlan0 rssi |
| 3581 | * |
| 3582 | ***** change by qs.xiong 20221011*******/ |
you.chen | 23c4a5f | 2023-04-12 16:46:00 +0800 | [diff] [blame] | 3583 | 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] | 3584 | { |
you.chen | 23c4a5f | 2023-04-12 16:46:00 +0800 | [diff] [blame] | 3585 | 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] | 3586 | return -1; |
| 3587 | } |
you.chen | 9f17e4d | 2022-06-06 17:18:18 +0800 | [diff] [blame] | 3588 | *rssi = atoi(lynq_cmd_ret) * -1; |
qs.xiong | ff0ae0f | 2022-10-11 15:47:14 +0800 | [diff] [blame] | 3589 | /****** if got rssi is 0,means sta didn't connected any device****/ |
| 3590 | if(*rssi == 0) |
| 3591 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3592 | 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] | 3593 | return -1; |
qs.xiong | ff0ae0f | 2022-10-11 15:47:14 +0800 | [diff] [blame] | 3594 | } |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3595 | |
| 3596 | return 0; |
| 3597 | } |
| 3598 | |
| 3599 | int lynq_get_connect_ap_band(lynq_wifi_index_e idx, lynq_wifi_band_m * band) |
| 3600 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3601 | RLOGD("enter lynq_get_connect_ap_band\n"); |
| 3602 | if (band == NULL) |
| 3603 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3604 | return -1; |
| 3605 | } |
| 3606 | |
| 3607 | CHECK_IDX(idx, CTRL_STA); |
| 3608 | ap_info_s ap; |
| 3609 | ap.band = -1; |
| 3610 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3611 | if (inner_get_status_info_ap(CTRL_STA, &ap) != 0) |
| 3612 | { |
you.chen | 3502019 | 2022-05-06 11:30:57 +0800 | [diff] [blame] | 3613 | return -1; |
| 3614 | } |
| 3615 | *band = ap.band; |
| 3616 | |
| 3617 | return 0; |
qs.xiong | 97fa59b | 2022-04-07 05:41:29 -0400 | [diff] [blame] | 3618 | } |
you.chen | f58b3c9 | 2022-06-21 16:53:48 +0800 | [diff] [blame] | 3619 | |
| 3620 | int lynq_get_connect_ap_ip(lynq_wifi_index_e idx, char *ip) |
| 3621 | { |
qs.xiong | e4cbf1c | 2023-02-28 18:22:49 +0800 | [diff] [blame] | 3622 | char bssid[1024] = {0}; |
you.chen | f58b3c9 | 2022-06-21 16:53:48 +0800 | [diff] [blame] | 3623 | |
| 3624 | if (ip == NULL) |
| 3625 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3626 | 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] | 3627 | return -1; |
| 3628 | } |
| 3629 | |
| 3630 | CHECK_IDX(idx, CTRL_STA); |
| 3631 | |
qs.xiong | e4cbf1c | 2023-02-28 18:22:49 +0800 | [diff] [blame] | 3632 | if (lynq_get_connect_ap_mac(idx, bssid) != 0) |
you.chen | f58b3c9 | 2022-06-21 16:53:48 +0800 | [diff] [blame] | 3633 | { |
| 3634 | return -1; |
| 3635 | } |
qs.xiong | e4cbf1c | 2023-02-28 18:22:49 +0800 | [diff] [blame] | 3636 | |
| 3637 | return inner_get_ip_by_mac(bssid, ip, 32); //better input by user |
you.chen | f58b3c9 | 2022-06-21 16:53:48 +0800 | [diff] [blame] | 3638 | } |
| 3639 | |
qs.xiong | 026c5c7 | 2022-10-17 11:15:45 +0800 | [diff] [blame] | 3640 | int lynq_ap_connect_num(int sta_number) |
| 3641 | { |
| 3642 | char lynq_limit_cmd[32]={0}; |
| 3643 | int ret; |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3644 | if((sta_number < 1 ) && (sta_number > 15)) |
| 3645 | { |
| 3646 | RLOGE("sta_number: not in range\n",sta_number); |
qs.xiong | 026c5c7 | 2022-10-17 11:15:45 +0800 | [diff] [blame] | 3647 | return -1; |
| 3648 | } |
| 3649 | sprintf(lynq_limit_cmd,"wl maxassoc %d", sta_number); |
| 3650 | ret = system(lynq_limit_cmd); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3651 | if(ret != 0) |
| 3652 | { |
| 3653 | RLOGE("cmd of limit ap devices number error\n"); |
qs.xiong | 026c5c7 | 2022-10-17 11:15:45 +0800 | [diff] [blame] | 3654 | } |
| 3655 | return 0; |
| 3656 | } |
you.chen | f58b3c9 | 2022-06-21 16:53:48 +0800 | [diff] [blame] | 3657 | |
qs.xiong | 7790555 | 2022-10-17 11:19:57 +0800 | [diff] [blame] | 3658 | int lynq_enable_acs(lynq_wifi_index_e idx,int acs_mode) |
| 3659 | { |
| 3660 | |
| 3661 | char lynq_wifi_acs_cmd[128]={0}; |
| 3662 | char lynq_cmd_mode[128]={0}; |
| 3663 | char lynq_cmd_slect[128]={0}; |
| 3664 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3665 | if((acs_mode != 2) && (acs_mode != 5)) |
| 3666 | { |
qs.xiong | 7790555 | 2022-10-17 11:19:57 +0800 | [diff] [blame] | 3667 | PRINT_AND_RETURN_VALUE("set acs_mode is error",-1); |
| 3668 | } |
| 3669 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3670 | if (lynq_check_network_number(idx, CTRL_AP, AP_NETWORK_0) != 0) |
| 3671 | { |
qs.xiong | 7790555 | 2022-10-17 11:19:57 +0800 | [diff] [blame] | 3672 | return -1; |
| 3673 | } |
| 3674 | |
| 3675 | CHECK_IDX(idx, CTRL_AP); |
| 3676 | |
| 3677 | CHECK_WPA_CTRL(CTRL_AP); |
| 3678 | |
| 3679 | sprintf(lynq_wifi_acs_cmd,"SET_NETWORK %d frequency %d", AP_NETWORK_0, acs_mode); |
| 3680 | sprintf(lynq_cmd_mode, "SET_NETWORK %d mode 2", AP_NETWORK_0); |
| 3681 | sprintf(lynq_cmd_slect, "SELECT_NETWORK %d", AP_NETWORK_0); |
| 3682 | |
| 3683 | DO_OK_FAIL_REQUEST(cmd_disconnect); |
| 3684 | DO_OK_FAIL_REQUEST(lynq_wifi_acs_cmd); |
| 3685 | DO_OK_FAIL_REQUEST(lynq_cmd_mode); |
| 3686 | DO_OK_FAIL_REQUEST(cmd_save_config); |
| 3687 | DO_OK_FAIL_REQUEST(lynq_cmd_slect); |
| 3688 | |
| 3689 | return 0; |
| 3690 | } |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 3691 | //you.chen add for tv-box start |
| 3692 | static int exec_cmd(const char *str_cmd, char * str_cmd_ret, size_t max_len) { |
| 3693 | FILE *fp; |
| 3694 | //printf("to exec cmd:%s\n", str_cmd); |
| 3695 | if((fp=popen(str_cmd,"r"))==NULL) |
| 3696 | { |
| 3697 | perror("popen error!"); |
| 3698 | return -1; |
| 3699 | } |
| 3700 | if((fread(str_cmd_ret,max_len,1,fp))<0) |
| 3701 | { |
| 3702 | perror("fread fail!"); |
| 3703 | fclose(fp); |
| 3704 | return -1; |
| 3705 | } |
| 3706 | fclose(fp); |
| 3707 | return 0; |
| 3708 | } |
| 3709 | |
| 3710 | static int get_netmask_length(const char* mask) |
| 3711 | { |
| 3712 | int masklen=0, i=0; |
| 3713 | int netmask=0; |
| 3714 | |
| 3715 | if(mask == NULL) |
| 3716 | { |
| 3717 | return 0; |
| 3718 | } |
| 3719 | |
| 3720 | struct in_addr ip_addr; |
| 3721 | if( inet_aton(mask, &ip_addr) ) |
| 3722 | { |
| 3723 | netmask = ntohl(ip_addr.s_addr); |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3724 | }else |
| 3725 | { |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 3726 | netmask = 0; |
| 3727 | return 0; |
| 3728 | } |
| 3729 | |
| 3730 | while(0 == (netmask & 0x01) && i<32) |
| 3731 | { |
| 3732 | i++; |
| 3733 | netmask = netmask>>1; |
| 3734 | } |
| 3735 | masklen = 32-i; |
| 3736 | return masklen; |
| 3737 | } |
| 3738 | |
| 3739 | static int get_tether_route_str(char *str_cmd_ret, size_t max_len) { |
| 3740 | int mask_len; |
| 3741 | char *p; |
| 3742 | char tmp[64] = {0}; |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 3743 | sprintf(tmp, "ifconfig %s | grep Mask", s_ap_iterface_name); |
| 3744 | if (exec_cmd(tmp, str_cmd_ret, max_len) != 0) |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 3745 | return -1; |
| 3746 | p = strstr(str_cmd_ret, "Mask:"); |
| 3747 | if (p == NULL) |
| 3748 | return -1; |
| 3749 | mask_len = get_netmask_length(p + 5); |
| 3750 | if (mask_len == 0) |
| 3751 | return -1; |
| 3752 | p = strstr(str_cmd_ret, "inet addr:"); |
| 3753 | if (p == NULL) |
| 3754 | return -1; |
| 3755 | strcpy(tmp, p + 10); |
| 3756 | p = strstr(tmp, " "); |
| 3757 | if (p != NULL) |
| 3758 | *p = '\0'; |
| 3759 | sprintf(str_cmd_ret, "%s/%d", tmp, mask_len); |
| 3760 | return 0; |
| 3761 | } |
| 3762 | |
| 3763 | static void GBWWatchThreadProc() { |
| 3764 | int i,n, nloop, nmax, ncheckcount, nidlecount; |
| 3765 | unsigned long long lastAP1Bytes, lastAP2Bytes, currAP1Bytes, currAP2Bytes; |
| 3766 | unsigned int lastAP1Drop,lastAP2Drop, currAP1Drop, currAP2Drop; |
| 3767 | unsigned int setAP1Speed, setAP2Speed, lastAP1Speed, lastAP2Speed, currAP1Speed, currAP2Speed,currSetAP1Speed; |
| 3768 | char *results[16] = {0}; |
| 3769 | char str_cmd[256] = {0}; |
| 3770 | char str_cmd_ret[128] = {0}; |
| 3771 | char dest_ip[32] = {0}; |
| 3772 | lastAP1Bytes = lastAP2Bytes = 0; |
| 3773 | lastAP1Drop = lastAP2Drop = 0; |
| 3774 | lastAP1Speed = lastAP2Speed = 0; |
| 3775 | setAP1Speed = 50; |
| 3776 | setAP2Speed = 80; |
| 3777 | nloop = 0; |
| 3778 | nmax = 6; |
| 3779 | ncheckcount = nidlecount = 0; |
| 3780 | |
you.chen | 0df3e7e | 2023-05-10 15:56:26 +0800 | [diff] [blame^] | 3781 | if (inner_get_ap_interface_name() == NULL) |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 3782 | { |
| 3783 | RLOGE("------gbw thread run\n"); |
| 3784 | return; |
| 3785 | } |
| 3786 | |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3787 | RLOGD("------gbw thread run\n"); |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 3788 | sprintf(str_cmd, "ip neigh | grep %s | awk '{print $1}'", g_gbw_mac); |
| 3789 | while (dest_ip[0] == '\0') { |
| 3790 | sleep(1); |
| 3791 | str_cmd_ret[0] = '\0'; |
| 3792 | exec_cmd(str_cmd, str_cmd_ret, sizeof (str_cmd_ret)); |
| 3793 | for(n = 0; n < (int)sizeof(str_cmd_ret) && str_cmd_ret[n] != '\0'; n++) { |
| 3794 | if (str_cmd_ret[n] == '\n'){ |
| 3795 | str_cmd_ret[n] = '\0'; |
| 3796 | break; |
| 3797 | } |
| 3798 | } |
| 3799 | if (str_cmd_ret[0] != '\0') |
| 3800 | { |
| 3801 | strcpy(dest_ip, str_cmd_ret); |
| 3802 | } |
| 3803 | } |
| 3804 | |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 3805 | system_call_v("tc qdisc del dev %s root > /dev/null 2>&1", s_ap_iterface_name); |
| 3806 | system_call_v("tc qdisc add dev %s root handle 1: htb r2q 1", s_ap_iterface_name); |
| 3807 | 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] | 3808 | if (get_tether_route_str(str_cmd_ret, sizeof (str_cmd_ret)) != 0) |
| 3809 | { |
qs.xiong | 9fbf74e | 2023-03-28 13:38:22 +0800 | [diff] [blame] | 3810 | RLOGD("not get tether info\n"); |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 3811 | return; |
| 3812 | } |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 3813 | 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); |
| 3814 | 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); |
| 3815 | 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] | 3816 | |
| 3817 | while (1) { |
| 3818 | sleep(1); |
| 3819 | memset(str_cmd, 0, sizeof(str_cmd)); |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 3820 | memset(str_cmd_ret, 0, sizeof(str_cmd_ret)); |
| 3821 | sprintf(str_cmd, "tc -s class show dev %s classid 1:1 | grep Sent", s_ap_iterface_name); |
| 3822 | 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] | 3823 | continue; |
| 3824 | //printf("ap1 --- %s\n", str_cmd); |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 3825 | n = lynq_split(str_cmd_ret, strlen(str_cmd_ret), ' ', results); |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 3826 | if (n > 9) { |
| 3827 | if (strcmp(results[1], "Sent") == 0) { |
| 3828 | currAP1Bytes = atoll(results[2]); |
| 3829 | } |
| 3830 | if (strcmp(results[6], "(dropped") == 0) { |
| 3831 | currAP1Drop = atoi(results[7]); |
| 3832 | } |
| 3833 | } |
| 3834 | |
| 3835 | memset(str_cmd, 0, sizeof(str_cmd)); |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 3836 | memset(str_cmd_ret, 0, sizeof(str_cmd_ret)); |
| 3837 | sprintf(str_cmd, "tc -s class show dev %s classid 1:2 | grep Sent", s_ap_iterface_name); |
| 3838 | 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] | 3839 | continue; |
| 3840 | //printf("ap2 --- %s\n", str_cmd); |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 3841 | n = lynq_split(str_cmd_ret, strlen(str_cmd_ret), ' ', results); |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 3842 | if (n > 9) { |
| 3843 | if (strcmp(results[1], "Sent") == 0) { |
| 3844 | currAP2Bytes = atoll(results[2]); |
| 3845 | } |
| 3846 | if (strcmp(results[6], "(dropped") == 0) { |
| 3847 | currAP2Drop = atoi(results[7]); |
| 3848 | } |
| 3849 | } |
| 3850 | |
| 3851 | //printf("ap1 %llu- %u, ap2 %llu-%u\n", currAP1Bytes, currAP1Drop, currAP2Bytes, currAP2Drop); |
| 3852 | if (currAP1Bytes < lastAP1Bytes || currAP2Bytes < lastAP2Bytes) { |
| 3853 | lastAP1Bytes = currAP1Bytes; |
| 3854 | lastAP2Bytes = currAP2Bytes; |
| 3855 | continue; |
| 3856 | } |
| 3857 | |
| 3858 | currAP1Speed = (currAP1Bytes - lastAP1Bytes) / 128 / 1024; |
| 3859 | currAP2Speed = (currAP2Bytes - lastAP2Bytes) / 128 / 1024; |
| 3860 | //printf("ap1 speed %d mb, ap2 speed %d mb\n", currAP1Speed, currAP2Speed); |
| 3861 | lastAP1Speed = currAP1Speed; |
| 3862 | lastAP2Speed = currAP2Speed; |
| 3863 | lastAP1Bytes = currAP1Bytes; |
| 3864 | lastAP2Bytes = currAP2Bytes; |
| 3865 | |
| 3866 | currSetAP1Speed = setAP1Speed; |
| 3867 | if ((currAP2Speed < 30 && currAP2Speed > 5) && currAP1Speed > 5) { |
| 3868 | ncheckcount++; |
| 3869 | if (ncheckcount > 3) { |
| 3870 | ncheckcount = 0; |
| 3871 | currSetAP1Speed = 5; |
| 3872 | } |
| 3873 | } |
| 3874 | else { |
| 3875 | ncheckcount = 0; |
| 3876 | if (currAP1Speed < 5) |
| 3877 | nidlecount++; |
| 3878 | else |
| 3879 | nidlecount = 0; |
| 3880 | |
| 3881 | } |
| 3882 | |
| 3883 | if (nidlecount > 60 ){ |
| 3884 | currSetAP1Speed = 50; |
| 3885 | } |
| 3886 | |
| 3887 | if (currSetAP1Speed != setAP1Speed) { |
| 3888 | setAP1Speed = currSetAP1Speed; |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 3889 | system_call_v(str_cmd, "tc class replace dev %s parent 1: classid 1:1 htb rate %dMbit ceil %dMbit prio 2 quantum 3000", |
| 3890 | s_ap_iterface_name, setAP1Speed, (int)(setAP1Speed*1.4)); |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 3891 | } |
| 3892 | } |
| 3893 | } |
| 3894 | |
| 3895 | int enableGBW(const char* mac) { |
| 3896 | int i,len; |
| 3897 | char get_ipaddr_cmd[128]={0}; |
| 3898 | ap_info_s *ap; |
| 3899 | device_info_s * list; |
| 3900 | |
| 3901 | if (mac == NULL || g_gbw_enabled == 1) |
| 3902 | return -1; |
| 3903 | len = strlen(mac); |
| 3904 | g_gbw_mac = malloc(len + 1); |
| 3905 | for(i=0;i<len;i++) { |
| 3906 | if (mac[i] >= 'A' && mac[i] <= 'Z') |
| 3907 | { |
| 3908 | g_gbw_mac[i] = 'a' + (mac[i] - 'A'); |
| 3909 | } |
| 3910 | else |
| 3911 | g_gbw_mac[i] = mac[i]; |
| 3912 | } |
| 3913 | g_gbw_mac[i] = '\0'; |
| 3914 | g_gbw_enabled = 1; |
| 3915 | |
| 3916 | sprintf(get_ipaddr_cmd, "ip neigh | grep %s", g_gbw_mac); |
| 3917 | if (system(get_ipaddr_cmd) == 0) { |
| 3918 | //startGBW(); |
| 3919 | if ( 0 ==lynq_get_ap_device_list(1, &ap, &list,&len) ) { |
| 3920 | for (i=0;i<len;i++) { |
| 3921 | //printf("--mac:%s, name:%s\n",list[i].sta_mac, list[i].hostname); |
| 3922 | if (strcmp(g_gbw_mac, list[i].sta_mac) == 0) |
| 3923 | startGBW(); |
| 3924 | } |
| 3925 | free(ap); |
| 3926 | free(list); |
| 3927 | } |
| 3928 | } |
| 3929 | return 0; |
| 3930 | } |
| 3931 | |
| 3932 | int disableGBW() { |
| 3933 | stopGBW(); |
| 3934 | free(g_gbw_mac); |
| 3935 | g_gbw_mac = NULL; |
| 3936 | g_gbw_enabled = 1; |
| 3937 | return 0; |
| 3938 | } |
| 3939 | |
| 3940 | static int startGBW() { |
| 3941 | if (g_gbw_watcher_pid != 0) { |
| 3942 | stopGBW(); |
| 3943 | } |
| 3944 | pthread_create(&g_gbw_watcher_pid,NULL,GBWWatchThreadProc,NULL); |
| 3945 | } |
| 3946 | |
| 3947 | static int stopGBW() { |
| 3948 | void* retval; |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 3949 | char cmd[64] = {0}; |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 3950 | pthread_cancel(g_gbw_watcher_pid); |
| 3951 | pthread_join(g_gbw_watcher_pid, &retval); |
| 3952 | g_gbw_watcher_pid = 0; |
you.chen | c992858 | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 3953 | sprintf(cmd, "%s %d", get_interface_name_script, LYNQ_WIFI_INTERFACE_1); |
| 3954 | if (s_ap_iterface_name[0] != '\0') |
| 3955 | { |
| 3956 | sprintf(cmd, "tc qdisc del dev %s root", s_ap_iterface_name); |
| 3957 | system(cmd); |
| 3958 | } |
you.chen | 0f5c643 | 2022-11-07 18:31:14 +0800 | [diff] [blame] | 3959 | } |
| 3960 | //you.chen add for tv-box end |