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