lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /*
|
| 2 | * wlan-station.c -- wifi station mode Deal module
|
| 3 | *
|
| 4 | * Copyright (c) ZTE Corporation All Rights Reserved.
|
| 5 | *
|
| 6 | * $Id: wlan-station.c, v 0.1 2015-03-09 $
|
| 7 | * Authors : XUJIAN - xu.jian5@zte.com.cn>
|
| 8 | */
|
| 9 | #include "wifi_util.h"
|
| 10 | #include "wlan-station.h"
|
| 11 | #include "Vector.h"
|
| 12 | #include "wifi_sta_ctrl.h"
|
| 13 | #include "soft_timer.h"
|
| 14 | #include "rtk_arch.h"
|
| 15 | #include <semaphore.h>
|
| 16 | #include <limits.h>
|
| 17 | #define SUCCESS "1"
|
| 18 | #define FAILED "0"
|
| 19 | #define REPLY_BUF_SIZE 4096 // wpa_supplicant's maximum size.
|
| 20 |
|
| 21 | #define UEVENT_BUFFER_SIZE 1024*2
|
| 22 |
|
| 23 | #define WIFI_STATION_CMD_LEN 256
|
| 24 |
|
| 25 | //¶¨Ê±Æ÷Ïà¹Ø
|
| 26 | #define WIFI_STATION_TIMER_CONNECT 109
|
| 27 | #define WIFI_STATION_TIMER_GET_STATUS 110
|
| 28 | #define WIFI_STATION_TIMER_SCAN 111
|
| 29 | //add sim card init status query timer
|
| 30 | #define WIFI_STATION_TIMER_SIM_CARD_STATUS 112
|
| 31 | #define WIFI_STATION_TIMER_GET_SCAN_RESULTS 113
|
| 32 |
|
| 33 | #define WIFI_STATION_TIMER_CONNECT_INTERVAL 1000
|
| 34 | #define WIFI_STATION_TIMER_GET_STATUS_INTERVAL 2000
|
| 35 | #define WIFI_STATION_TIMER_SCAN_INTERVAL 60000 /// 10 ----> 15s nxl
|
| 36 |
|
| 37 | #define WIFI_STATION_TIMER_GET_SCAN_RESULTS_INTERVAL 8000 /// 10 ----> 15s nxl
|
| 38 |
|
| 39 |
|
| 40 | #define WIFI_STATION_TIMER_SIM_CARD_STATUS_INTERVAL 2000
|
| 41 |
|
| 42 | #define WIFI_STATION_TIMER_WAIT_CONNECT_COUNT 20
|
| 43 | #define WIFI_STATION_TIMER_CONNECT_TIME_OUT 116
|
| 44 |
|
| 45 | //ɨÃèÏà¹Ø
|
| 46 | #define WIFI_STATION_SCAN_DURATION 8
|
| 47 | #define WIFI_STATION_SCRIPT_RSP_LINE_LEN 1024
|
| 48 | #define WIFI_STATION_SCAN_RESULT_STR_LEN 1024
|
| 49 | #define WIFI_STATION_SCAN_ONE_RESULT_STR_LEN 256
|
| 50 | #define WIFI_STATION_SCAN_RESULT_LIST_NUM 60//Ò»°ãʵ¼Ê¹Ì¼þÄÜɨ³öÀ´30¼¸¸ö£¬ÏµÍ³ÄÜ´æ´¢µÄɨÃè½á¹û×î¶à²»³¬¹ý2048¸ö×Ö½Ú
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 | #define WIFI_STATION_SIGNAL_LEVEL1 -80
|
| 57 | #define WIFI_STATION_SIGNAL_LEVEL2 -78
|
| 58 | #define WIFI_STATION_SIGNAL_LEVEL3 -75
|
| 59 | #define WIFI_STATION_SIGNAL_LEVEL4 -72
|
| 60 |
|
| 61 | #define WIFI_STATION_CHANNEL1 2412
|
| 62 | #define WIFI_STATION_CHANNEL2 2417
|
| 63 | #define WIFI_STATION_CHANNEL3 2422
|
| 64 | #define WIFI_STATION_CHANNEL4 2427
|
| 65 | #define WIFI_STATION_CHANNEL5 2432
|
| 66 | #define WIFI_STATION_CHANNEL6 2437
|
| 67 | #define WIFI_STATION_CHANNEL7 2442
|
| 68 | #define WIFI_STATION_CHANNEL8 2447
|
| 69 | #define WIFI_STATION_CHANNEL9 2452
|
| 70 | #define WIFI_STATION_CHANNEL10 2457
|
| 71 | #define WIFI_STATION_CHANNEL11 2462
|
| 72 | #define WIFI_STATION_CHANNEL12 2467
|
| 73 | #define WIFI_STATION_CHANNEL13 2472
|
| 74 | #define WIFI_STATION_FREQ_LEN 16
|
| 75 |
|
| 76 | #define WIFI_STATION_MSG_SOURCE_STR_LEN 15
|
| 77 | #define WIFI_STATION_IP_STATUS_LEN 16
|
| 78 | #define WIFI_CONNECTION_LEN 4
|
| 79 | #define WIFI_ZPBIC_STATUS_LEN 16
|
| 80 | #define WIFI_STATION_WPA_SUPPLICANT_STATUS_LEN 16
|
| 81 |
|
| 82 | #define WIFI_STATION_SCAN_RESULT_PARSE_IGNORE "bssid / frequency /"
|
| 83 |
|
| 84 | #define WIFI_STATION_AUTH_WPA_PSK "WPA-PSK"
|
| 85 | #define WIFI_STATION_AUTH_WPA2_PSK "WPA2-PSK"
|
| 86 | #define WIFI_STATION_AUTH_WPA_EAP "WPA-EAP"
|
| 87 | #define WIFI_STATION_AUTH_WPA2_EAP "WPA2-EAP"
|
| 88 | #define WIFI_STATION_AUTH_SHARED "SHARED"
|
| 89 | #define WIFI_STATION_AUTH_WPA3 "SAE"
|
| 90 |
|
| 91 | #define WIFI_STATION_ENCRYPT_CCMP "CCMP"
|
| 92 | #define WIFI_STATION_ENCRYPT_TKIP "TKIP"
|
| 93 | #define WIFI_STATION_ENCRYPT_WEP "WEP"
|
| 94 |
|
| 95 | #define WIFI_STATION_PROFILE_AUTH_WPA_PSK "WPAPSK"
|
| 96 | #define WIFI_STATION_PROFILE_AUTH_WPA2_PSK "WPA2PSK"
|
| 97 | //#define WIFI_STATION_PROFILE_AUTH_WPA_EAP "WPAEAP"
|
| 98 | //#define WIFI_STATION_PROFILE_AUTH_WPA2_EAP "WPA2EAP"
|
| 99 | #define WIFI_STATION_PROFILE_AUTH_WPA_EAP "EAP-SIM/AKA"
|
| 100 | #define WIFI_STATION_PROFILE_AUTH_SHARED "SHARED"
|
| 101 | #define WIFI_STATION_PROFILE_AUTH_WPA3 "WPA3Personal"
|
| 102 | #define WIFI_STATION_PROFILE_AUTH_WPA2_WPA3 "WPA2WPA3"
|
| 103 |
|
| 104 | #define WIFI_STATION_PROFILE_ENCRYPT_WEP "WEP"
|
| 105 | #define WIFI_STATION_PROFILE_ENCRYPT_CCMP "CCMP"
|
| 106 | #define WIFI_STATION_PROFILE_ENCRYPT_TKIP "TKIP"
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 | #define WIFI_STATION_STATUS_RESULT_PARSE_BSSID "bssid"
|
| 111 | #define WIFI_STATION_STATUS_RESULT_PARSE_SSID "ssid"
|
| 112 | #define WIFI_STATION_STATUS_RESULT_PARSE_WPA_STATUS "wpa_state"
|
| 113 | #define WIFI_STATION_STATUS_RESULT_PARSE_SUPPLICANT_PAE_STATUS "Supplicant PAE state"
|
| 114 | #define WIFI_STATION_STATUS_RESULT_PARSE_SUPPPORT_STATUS "suppPortStatus"
|
| 115 | #define WIFI_STATION_STATUS_RESULT_PARSE_EAP_STATUS "EAP state"
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 | #define WIFI_STATION_STATUS_RESULT_WPA_STATUS_OK "COMPLETED"
|
| 121 |
|
| 122 | #define WIFI_STATION_STATUS_RESULT_WPA_STATUS_INACTIVE "INACTIVE"
|
| 123 | #define WIFI_STATION_STATUS_RESULT_WPA_STATUS_SCANNING "SCANNING"
|
| 124 | #define WIFI_STATION_TIMER_SCANNING_STATE_COUNT 10
|
| 125 |
|
| 126 | #define WIFI_STATION_STATUS_RESULT_WPA_STATUS_AUTHENTICATING "AUTHENTICATING"
|
| 127 | #define WIFI_STATION_STATUS_RESULT_WPA_STATUS_ASSOCIATING "ASSOCIATING"
|
| 128 | #define WIFI_STATION_STATUS_RESULT_WPA_STATUS_ASSOCIATED "ASSOCIATED"
|
| 129 | #define WIFI_STATION_STATUS_RESULT_WPA_STATUS_4WAY_HANDSHAKE "4WAY_HANDSHAKE"
|
| 130 | #define WIFI_STATION_STATUS_RESULT_WPA_STATUS_4WAY_GROUP_HANDSHAKE "GROUP_HANDSHAKE"
|
| 131 | #define WIFI_STATION_STATUS_RESULT_WPA_STATUS_4WAY_GROUP_UNKNOWN "UNKNOWN"
|
| 132 | #define WIFI_STATION_STATUS_RESULT_WPA_STATUS_4WAY_GROUP_DISCONNECTED "DISCONNECTED"
|
| 133 | #define WIFI_STATION_STATUS_RESULT_WPA_STATUS_4WAY_GROUP_INTERFACE_DISABLED "INTERFACE_DISABLED"
|
| 134 |
|
| 135 |
|
| 136 | #define WIFI_STATION_STATUS_RESULT_EAP_STATUS_FAIL "FAILURE"
|
| 137 | #define WIFI_STATION_STATUS_RESULT_EAP_STATUS_SUCCESS "SUCCESS"
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 | #define WIFI_STATION_IP_STATUS_CONNECT "connect"
|
| 142 | #define WIFI_STATION_IP_STATUS_DISCONNECT "disconnect"
|
| 143 | #define WIFI_STATION_IP_STATUS_CONNECTING "connecting"
|
| 144 | #define WIFI_STATION_IP_STATUS_DHCPING "dhcping"
|
| 145 |
|
| 146 | #define INVALID_NETWORK_ID -1
|
| 147 |
|
| 148 | #define safe_free(x) do { if(x) {free(x); x=NULL;} } while(0)
|
| 149 |
|
| 150 | #define WPA_CLI "wpa_cli -p"ROOT_DIR"/wifi/wpa_supplicant -iwlan0-vxd"
|
| 151 |
|
| 152 | #define WIFI_CARD_MODE_LEN 3
|
| 153 |
|
| 154 | #define WIFI_PIN_STATUS_LEN 3
|
| 155 |
|
| 156 | #define SIMCARD_INIT_SUCCESS "success"
|
| 157 | #define SIMCARD_INIT_UNDEFINED "undefined"
|
| 158 | #define SIMCARD_INIT_NO_CARD "no_card"
|
| 159 | //#define SIMCARD_INIT_LOCKED "locked"
|
| 160 | //#define SIMCARD_INIT_FAIL "fail"
|
| 161 | //#define SIMCARD_INIT_PARTIAL_SUCCESS "partial_success"
|
| 162 |
|
| 163 |
|
| 164 | extern struct wlan_sta_manager *sta_manager;
|
| 165 | extern int need_channel_follow;
|
| 166 |
|
| 167 | //static int g_timer_sim_init_undefined_status_count = 0;
|
| 168 | //add by zhouti ÔÚeap ÈÏÖ¤¹ý³Ìǰ·¢Ë͵ÄÒì²½ÏûÏ¢Ôڵȴýʱºò£¬Èç¹ûÓû§disconnect£¬ÄÇôÐèÒªÅжϻØÀ´µÄrespÏûÏ¢ÊÇ·ñΪÕâ´ÎµÄ»ØÓ¦£¬Èç¹ûÊǾÍÐèÒª¶ªÆú²»´¦Àí
|
| 169 | static int g_send_count = 0;
|
| 170 | static int g_pre_send_count = 0;
|
| 171 |
|
| 172 | //gebin: Õ⼸¸öµÄÄ¿µÄ¾ÍÊÇΪÁËÔÚÏ̼߳䴫µÝ²ÎÊý°É??? Èç¹ûÕâÑù¾Í²»ÒªÓÃÈ«¾Ö±äÁ¿ÁË£¬ipc¿ÉÒÔ´«²ÎÊý
|
| 173 | char g_linked_ap_mac[WIFI_STATION_MAC_LEN] = {0};
|
| 174 | int g_linked_network_id = -1;
|
| 175 | int g_linked_network_id_last = -1;
|
| 176 | /*±£´æµ±Ç°ÀúÊ·ÁбíAPÄÚÈÝ*/
|
| 177 | static spot_t *g_spot_list_p[WIFI_STATION_SPOT_LIST_NUM] = {NULL};//ÈȵãÁбíÖ¸ÕëÊý×é
|
| 178 |
|
| 179 | static scan_result_t *g_scan_result_list_p[WIFI_STATION_SCAN_RESULT_LIST_NUM] = {NULL};//ɨÃèÈȵãÁбíÖ¸ÕëÊý×é
|
| 180 | static int g_cardmode = 0; //È«¾Ö¼Ç¼sim¿¨ÀàÐÍ
|
| 181 |
|
| 182 | static int g_blc_send_close_apsta = 0; // È«¾Ö¼Ç¼BLC·¢Ë͹رÕÏûÏ¢Ôò²»ÔÙÖ÷¶¯Á¬½Ówifi,Ö±µ½BLC·¢ËÍ´ò¿ª
|
| 183 | int g_wpa_supplicant;
|
| 184 | extern sem_t g_wpa_supplicant_id;
|
| 185 |
|
| 186 | int has_exec_disconnect = 0; //ÊÇ·ñÖ´Ðйý¶Ï¿ª²Ù×÷
|
| 187 | int has_exec_select_network = 0; //ÊÇ·ñÖ´ÐйýÑ¡ÔñÁ¬½Óijһ¸öÈȵã
|
| 188 | int webui_select_network = 0; //¼Ç¼webuiÏ·¢µÄÑ¡Ôñij¸öÈȵãÁ¬½ÓÃüÁî
|
| 189 | int g_disable_other_network = 0; //ÊÇ·ñ½ûÓÃÆäËûµÄÈȵã
|
| 190 |
|
| 191 | int g_connecting_time_out_timer = 0;//È«¾Ö¼Ç¼ÊÇ·ñÒÑ´´½¨Á¬½Ó³¬Ê±¶¨Ê±Æ÷
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame^] | 192 |
|
| 193 | #ifdef USE_CAP_SUPPORT
|
| 194 | int g_cap_scan = 0; //½öcap·¢Æðscanʱ,²ÅÉϱ¨½á¹û,ºǫִ́Ðнá¹û²»±¨
|
| 195 | static int send_sta_status_to_cap(int status, int reason);
|
| 196 | #endif
|
| 197 |
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 198 | static int wifi_station_connect (int from_where);
|
| 199 | static void wifi_station_scan (void);
|
| 200 | static void *wifi_station_query_sim_card_status(void *arg);
|
| 201 | static void sta_connect (int network_id);
|
| 202 | extern void basic_deal_all (int cmd);
|
| 203 | static int find_linked_ap_index(void);
|
| 204 | static void delete_quote (char * str);
|
| 205 | static void wlan_station_deinit(void);
|
| 206 | static void process_tmp_disabled (char *buf);
|
| 207 |
|
| 208 | extern int check_alive(struct wlan_socket *skt);
|
| 209 |
|
| 210 |
|
| 211 | inline char * sta_docmd(const char *cmd)
|
| 212 | {
|
| 213 | return docmd (&sta_manager->sock, cmd);
|
| 214 | }
|
| 215 |
|
| 216 |
|
| 217 | /*
|
| 218 | 0 : not exist
|
| 219 | 1: alive
|
| 220 | */
|
| 221 | int check_supplicant_alive()
|
| 222 | {
|
| 223 | return check_alive(&sta_manager->sock);
|
| 224 |
|
| 225 | }
|
| 226 |
|
| 227 |
|
| 228 | void *send_message_to_handle_connect_timeout(void *arg)
|
| 229 | {
|
| 230 | ipc_send_message (MODULE_ID_WLAN_SERVER, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_CONNECT_TIMEOUT, 0, NULL, 0);
|
| 231 | return NULL;
|
| 232 | }
|
| 233 | void Create_connect_timeout_timer()
|
| 234 | {
|
| 235 | wf_log ("[111]g_connecting_time_out_timer=%d", g_connecting_time_out_timer);
|
| 236 | if (g_connecting_time_out_timer) {
|
| 237 | wf_log ("[xxx]station connecting timeout softtimer already exists");
|
| 238 | return;
|
| 239 | }
|
| 240 | wf_log ("[222]create station connecting timeout softtimer");
|
| 241 | sc_timer_create (WIFI_STATION_TIMER_CONNECT_TIME_OUT, TIMER_FLAG_ONCE, 60 * 1000, send_message_to_handle_connect_timeout, NULL);
|
| 242 | g_connecting_time_out_timer = 1;
|
| 243 | wf_log ("[333]g_connecting_time_out_timer=%d", g_connecting_time_out_timer);
|
| 244 | return;
|
| 245 | }
|
| 246 | void Delete_connect_timeout_timer (void)
|
| 247 | {
|
| 248 | wf_log ("[555]g_connecting_time_out_timer=%d", g_connecting_time_out_timer);
|
| 249 | if (g_connecting_time_out_timer == 0) {
|
| 250 | wf_log ("[xxx]station connecting timeout softtimer was already deleted");
|
| 251 | return;
|
| 252 | }
|
| 253 | wf_log ("[666]delete station connecting timeout softtimer");
|
| 254 | sc_timer_delete (WIFI_STATION_TIMER_CONNECT_TIME_OUT);
|
| 255 | g_connecting_time_out_timer = 0;
|
| 256 | wf_log ("[777]g_connecting_time_out_timer=%d", g_connecting_time_out_timer);
|
| 257 | return;
|
| 258 | }
|
| 259 |
|
| 260 | //Ö´ÐÐÒ»¸öshellÃüÁÊä³ö½á¹ûÖðÐд洢ÔÚresvecÖУ¬²¢·µ»ØÐÐÊý
|
| 261 | static int32_t convert2vector (const char *str, vector_t* resvec)
|
| 262 | {
|
| 263 | char *tmp = NULL; //ÉèÖÃÒ»¸öºÏÊʵij¤¶È£¬ÒԴ洢ÿһÐÐÊä³ö
|
| 264 | char *ret = NULL;
|
| 265 | FILE *fp = NULL;
|
| 266 | int tmp_len = 0;
|
| 267 |
|
| 268 | if (str == NULL || resvec == NULL) {
|
| 269 | return -1;
|
| 270 | }
|
| 271 |
|
| 272 | fp = fopen ("/tmp/scan_results", "w+"); //½¨Á¢¹ÜµÀ
|
| 273 | if (!fp) {
|
| 274 | wf_log ("fopen errno: %d\n", errno);
|
| 275 | return -1;
|
| 276 | }
|
| 277 | fprintf (fp, "%s", str);
|
| 278 | fseek (fp, 0, SEEK_SET);
|
| 279 | tmp = safe_malloc (WIFI_STATION_SCRIPT_RSP_LINE_LEN, TRUE);
|
| 280 |
|
| 281 | again:
|
| 282 | errno = 0;
|
| 283 | while ((ret=fgets (tmp, WIFI_STATION_SCRIPT_RSP_LINE_LEN, fp)) != NULL) {
|
| 284 | tmp_len = strlen (tmp);
|
| 285 | if (tmp_len > 0) {
|
| 286 | if (tmp[tmp_len - 1] == '\n') {
|
| 287 | tmp[tmp_len - 1] = '\0'; //È¥³ý»»Ðзû
|
| 288 | }
|
| 289 | vector_push_back (resvec, var_string (tmp));
|
| 290 | }
|
| 291 | }
|
| 292 |
|
| 293 | if (EINTR ==errno) { //kw 3
|
| 294 | wf_log("fgets recv EINTR!");
|
| 295 | goto again;
|
| 296 | }
|
| 297 |
|
| 298 | fclose (fp);
|
| 299 | safe_free (tmp);
|
| 300 |
|
| 301 | return vector_size (resvec);
|
| 302 | }
|
| 303 |
|
| 304 |
|
| 305 | //TODO ÍøÂç×éÍø¿ÚDOWN UP·â×°
|
| 306 | static void network_down_up (BOOL is_up)
|
| 307 | {
|
| 308 | if (is_up == TRUE) {
|
| 309 | sc_cfg_set ("WAN_MODE", "WIFI"); //usb,ppp,wifi
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 310 | /*printf("[wlan-station]calling ipv4.sh linkup\n");
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 311 | system("zte_ipv4.sh \"linkup\"");
|
| 312 | printf("[wlan-station]calling internet.sh\n");
|
| 313 | system("internet.sh");
|
| 314 | printf("[wlan-station]calling nat.sh\n");
|
| 315 | system("nat.sh");*/
|
| 316 | netdev_connect_internet (WIFI_WAN_DEV, MODULE_ID_WIFI);
|
| 317 |
|
| 318 | wf_log ("[wlan-station]netdev_connect_internet");
|
| 319 | } else {
|
| 320 | netdev_disconnect_internet (WIFI_WAN_DEV, MODULE_ID_WIFI);
|
| 321 | wf_log ("[wlan-station]netdev_disconnect_internet");
|
| 322 | //system("zte_ipv4.sh \"linkdown\"");
|
| 323 | sc_cfg_set ("WAN_MODE", "PPP"); //usb,ppp,wifi
|
| 324 | }
|
| 325 | }
|
| 326 |
|
| 327 |
|
| 328 | static void update_EX_APLIST_connect_status (BOOL is_connected)
|
| 329 | {
|
| 330 | char *scan_result_str = NULL;
|
| 331 | char *scan_result_str_tmp = NULL;
|
| 332 | int i = 0;
|
| 333 | int found_ap_index = -1;
|
| 334 | char *splited_string = NULL;
|
| 335 | char *splited_string1 = NULL;
|
| 336 | char *save = NULL;
|
| 337 | char *save1 = NULL;
|
| 338 | char *delimiter = ";";
|
| 339 | int found_str_index = 0;
|
| 340 | BOOL is_found = FALSE;
|
| 341 | BOOL is_find_EX_APLIST1 = FALSE;
|
| 342 |
|
| 343 | int index = 0;
|
| 344 | // ²»¹ÜÊÇÁ´½Ó³É¹¦»¹ÊǶϿª£¬¶¼¿ÉÒÔÕÒµ½¶ÔÓ¦µÄÈȵ㣬²»»áΪÎÞЧֵ
|
| 345 | index = find_linked_ap_index();
|
| 346 |
|
| 347 | for (i = 0; i < WIFI_STATION_SCAN_RESULT_LIST_NUM; i++) {
|
| 348 | if (g_scan_result_list_p[i] != NULL && index != -1) {
|
| 349 | if (strcmp (g_scan_result_list_p[i]->mac, g_spot_list_p[index]->mac) == 0) {
|
| 350 | found_ap_index = i;
|
| 351 |
|
| 352 | if (is_connected == TRUE) {
|
| 353 | g_scan_result_list_p[i]->connect_status = 1;
|
| 354 | } else {
|
| 355 | g_scan_result_list_p[i]->connect_status = 0;
|
| 356 | }
|
| 357 |
|
| 358 | break;
|
| 359 | }
|
| 360 | }
|
| 361 |
|
| 362 | }
|
| 363 |
|
| 364 | //ûÕÒµ½APÔòÖ±½ÓÍ˳ö
|
| 365 | if (found_ap_index == -1) {
|
| 366 | return;
|
| 367 | }
|
| 368 |
|
| 369 | scan_result_str = safe_malloc (WIFI_STATION_SCAN_RESULT_STR_LEN, FALSE);
|
| 370 | scan_result_str_tmp = safe_malloc (WIFI_STATION_SCAN_RESULT_STR_LEN, FALSE);
|
| 371 | if (scan_result_str == NULL || scan_result_str_tmp == NULL) {
|
| 372 | safe_free (scan_result_str);
|
| 373 | safe_free (scan_result_str_tmp);
|
| 374 | return;
|
| 375 | }
|
| 376 |
|
| 377 | //²éÕÒEX_APLIST
|
| 378 | sc_cfg_get ("EX_APLIST", scan_result_str, WIFI_STATION_SCAN_RESULT_STR_LEN);
|
| 379 |
|
| 380 | safe_strcpy (scan_result_str_tmp, scan_result_str, WIFI_STATION_SCAN_RESULT_STR_LEN);
|
| 381 | //ÒԷֺŷָî×Ö·û´®
|
| 382 | i = 0;
|
| 383 | splited_string = strtok_r (scan_result_str_tmp, delimiter, &save);
|
| 384 | while (splited_string) {
|
| 385 | if (i == found_ap_index) {
|
| 386 | //ÕÒµ½connect_statusÔÚ×Ö·û´®ÖеÄË÷Òý
|
| 387 | found_str_index += 2;
|
| 388 |
|
| 389 | is_found = TRUE;
|
| 390 | break;
|
| 391 | }
|
| 392 | found_str_index += strlen (splited_string) + 1; //ÒªÔÙ¼ÓÉϷֺŵÄ1¸ö×Ö·û³¤¶È
|
| 393 |
|
| 394 | i++;
|
| 395 | splited_string = strtok_r (NULL, delimiter, &save);
|
| 396 | }
|
| 397 |
|
| 398 | //²éÕÒEX_APLIST1
|
| 399 | if (is_found == FALSE) {
|
| 400 | is_find_EX_APLIST1 = TRUE;
|
| 401 | found_str_index = 0;
|
| 402 | memset (scan_result_str, 0, WIFI_STATION_SCAN_RESULT_STR_LEN);
|
| 403 | memset (scan_result_str_tmp, 0, WIFI_STATION_SCAN_RESULT_STR_LEN);
|
| 404 | sc_cfg_get ("EX_APLIST1", scan_result_str, WIFI_STATION_SCAN_RESULT_STR_LEN);
|
| 405 |
|
| 406 | safe_strcpy (scan_result_str_tmp, scan_result_str, WIFI_STATION_SCAN_RESULT_STR_LEN);
|
| 407 |
|
| 408 | splited_string1 = strtok_r (scan_result_str_tmp, delimiter, &save1);
|
| 409 | while (splited_string1) {
|
| 410 | if (i == found_ap_index) {
|
| 411 | //ÕÒµ½connect_statusÔÚ×Ö·û´®ÖеÄË÷Òý
|
| 412 | found_str_index += 2;
|
| 413 |
|
| 414 | is_found = TRUE;
|
| 415 | break;
|
| 416 | }
|
| 417 | found_str_index += strlen (splited_string1) + 1; //ÒªÔÙ¼ÓÉϷֺŵÄ1¸ö×Ö·û³¤¶È
|
| 418 |
|
| 419 | i++;
|
| 420 | splited_string1 = strtok_r (NULL, delimiter, &save1);
|
| 421 | }
|
| 422 | }
|
| 423 |
|
| 424 | if (is_found == TRUE
|
| 425 | && found_str_index > 0 && found_str_index < strlen (scan_result_str)) {
|
| 426 | if (is_connected == TRUE) {
|
| 427 | scan_result_str[found_str_index] = '1';
|
| 428 | } else {
|
| 429 | scan_result_str[found_str_index] = '0';
|
| 430 | }
|
| 431 |
|
| 432 | if (is_find_EX_APLIST1 == TRUE) {
|
| 433 | sc_cfg_set ("EX_APLIST1", scan_result_str);
|
| 434 | } else {
|
| 435 | sc_cfg_set ("EX_APLIST", scan_result_str);
|
| 436 | }
|
| 437 | }
|
| 438 |
|
| 439 | safe_free (scan_result_str);
|
| 440 | safe_free (scan_result_str_tmp);
|
| 441 | }
|
| 442 |
|
| 443 | static spot_t* parse_spot_string (char *spot_string)
|
| 444 | {
|
| 445 | spot_t *spot = NULL;
|
| 446 | char *splited_string = NULL;
|
| 447 | char *save = NULL;
|
| 448 | const char *delimiter = ",";
|
| 449 | wifi_profile_content_t wifi_profile_content = WIFI_STATION_CONTENT_UNDEFINED;
|
| 450 | char spot_string_tmp[WIFI_STATION_SPOT_LEN] = {0};
|
| 451 |
|
| 452 | if (spot_string == NULL) {
|
| 453 | return NULL;
|
| 454 | }
|
| 455 | //klocwork
|
| 456 | strncpy(spot_string_tmp, spot_string, sizeof(spot_string_tmp)-1);
|
| 457 |
|
| 458 | spot = safe_malloc (sizeof (spot_t), FALSE);
|
| 459 | if (spot == NULL) {
|
| 460 | return NULL;
|
| 461 | }
|
| 462 |
|
| 463 | spot->is_tried_connect = FALSE;
|
| 464 |
|
| 465 | //·Ö¸î×Ö·û´®£¬´æ´¢µ½½á¹¹Ìå
|
| 466 | splited_string = strtok_r (spot_string_tmp, delimiter, &save);
|
| 467 | while (splited_string) {
|
| 468 | wifi_profile_content++;
|
| 469 | switch (wifi_profile_content) {
|
| 470 | case WIFI_STATION_PROFILE_NAME:
|
| 471 | //safe_strcpy (spot->profile_name, splited_string, WIFI_STATION_SPOT_PROFILE_NAME_LEN);
|
| 472 | strncpy (spot->profile_name, splited_string, sizeof(spot->profile_name)-1);
|
| 473 | break;
|
| 474 | case WIFI_STATION_FROM_PROVIDER:
|
| 475 | spot->from_provider = atoi (splited_string);
|
| 476 | break;
|
| 477 | case WIFI_STATION_CONNECT_STATUS:
|
| 478 | spot->connect_status = atoi (splited_string);
|
| 479 | break;
|
| 480 | case WIFI_STATION_SIGNAL:
|
| 481 | spot->signal = atoi (splited_string);
|
| 482 | break;
|
| 483 | case WIFI_STATION_SSID:
|
| 484 | //safe_strcpy (spot->ssid, splited_string, WIFI_STATION_SSID_LEN);
|
| 485 | strncpy (spot->ssid, splited_string, sizeof(spot->ssid)-1);
|
| 486 | break;
|
| 487 | case WIFI_STATION_AUTH_MODE:
|
| 488 | //safe_strcpy (spot->auth_mode, splited_string, WIFI_STATION_AUTH_MODE_LEN);
|
| 489 | strncpy (spot->auth_mode, splited_string, sizeof(spot->auth_mode)-1);
|
| 490 | break;
|
| 491 | case WIFI_STATION_ENCRYPT_TYPE:
|
| 492 | //safe_strcpy (spot->encrypt_type, splited_string, WIFI_STATION_ENCRYPT_TYPE_LEN);
|
| 493 | strncpy (spot->encrypt_type, splited_string, sizeof(spot->encrypt_type)-1);
|
| 494 | break;
|
| 495 | case WIFI_STATION_PASSWORD:
|
| 496 | //safe_strcpy (spot->password, splited_string, WIFI_STATION_SPOT_PASSWORD_LEN);
|
| 497 | strncpy (spot->password, splited_string, sizeof(spot->password)-1);
|
| 498 | break;
|
| 499 | case WIFI_STATION_KEY_ID:
|
| 500 | spot->keyID = atoi (splited_string);
|
| 501 | break;
|
| 502 | case WIFI_STATION_AP_MAC:
|
| 503 | //safe_strcpy (spot->mac, splited_string, WIFI_STATION_MAC_LEN);
|
| 504 | strncpy (spot->mac, splited_string, sizeof(spot->mac)-1);
|
| 505 | break;
|
| 506 | default:
|
| 507 | break;
|
| 508 | }
|
| 509 |
|
| 510 | splited_string = strtok_r (NULL, delimiter, &save);
|
| 511 | }
|
| 512 |
|
| 513 | spot->network_id = -1; // from nv profile , there is no network id property, so ,default set it -1
|
| 514 |
|
| 515 | if (wifi_profile_content != WIFI_STATION_AP_MAC) {
|
| 516 | safe_free (spot);
|
| 517 | return NULL;
|
| 518 | }
|
| 519 |
|
| 520 |
|
| 521 | return spot;
|
| 522 |
|
| 523 | }
|
| 524 |
|
| 525 |
|
| 526 | static void save_config (spot_t *spot)
|
| 527 | {
|
| 528 |
|
| 529 | char cmd[WIFI_STATION_CMD_LEN] = {0};
|
| 530 | char *ptr = NULL;
|
| 531 | char *ptr2 = NULL;
|
| 532 | char *ptr3 = NULL;
|
| 533 | char *ptr_w3 = NULL;
|
| 534 | char *ptr_w23 = NULL;
|
| 535 | char *ptr5 = NULL;
|
| 536 | char *ptr6 = NULL;
|
| 537 | int key_len = 0;
|
| 538 | int id;
|
| 539 |
|
| 540 | if (spot == NULL) {
|
| 541 | return;
|
| 542 | }
|
| 543 |
|
| 544 | if (spot->network_id == -1) {
|
| 545 |
|
| 546 | //id = atoi (sta_docmd ("ADD_NETWORK"));
|
| 547 | //klocwork
|
| 548 | char *reply = NULL;
|
| 549 | reply = sta_docmd("ADD_NETWORK");
|
| 550 | if (reply == NULL) {
|
| 551 | return;
|
| 552 | }
|
| 553 | id = atoi(reply);
|
| 554 |
|
| 555 | spot->network_id = id;
|
| 556 | wf_log ("[sav_config] new spot get new networkid=%d", id);
|
| 557 |
|
| 558 | } else {
|
| 559 | id = spot->network_id ;
|
| 560 | wf_log ("[sav_config] old spot have networkid=%d", id);
|
| 561 |
|
| 562 | }
|
| 563 |
|
| 564 |
|
| 565 | sprintf (cmd, "SET_NETWORK %d ssid \"%s\"", id , spot->ssid);
|
| 566 | sta_docmd (cmd);
|
| 567 |
|
| 568 | memset (cmd, 0, WIFI_STATION_CMD_LEN);
|
| 569 | ptr = strstr (spot->auth_mode, WIFI_STATION_PROFILE_AUTH_WPA_PSK);
|
| 570 | ptr2 = strstr (spot->auth_mode, WIFI_STATION_PROFILE_AUTH_WPA2_PSK);
|
| 571 | ptr3 = strstr (spot->auth_mode, WIFI_STATION_PROFILE_AUTH_WPA_EAP);
|
| 572 | ptr_w3 = strstr(spot->auth_mode, WIFI_STATION_PROFILE_AUTH_WPA3);
|
| 573 | ptr_w23 = strstr(spot->auth_mode, WIFI_STATION_PROFILE_AUTH_WPA2_WPA3);
|
| 574 |
|
| 575 | ptr5 = strstr (spot->encrypt_type, WIFI_STATION_PROFILE_ENCRYPT_CCMP);
|
| 576 | ptr6 = strstr (spot->encrypt_type, WIFI_STATION_PROFILE_ENCRYPT_TKIP);
|
| 577 |
|
| 578 | sprintf (cmd, "SET_NETWORK %d priority 1", id);
|
| 579 | sta_docmd (cmd);
|
| 580 |
|
| 581 |
|
| 582 | if (ptr || ptr2) {
|
| 583 | sprintf (cmd, "SET_NETWORK %d key_mgmt WPA-PSK", id);
|
| 584 | sta_docmd (cmd);
|
| 585 |
|
| 586 | if (ptr && !ptr2) {
|
| 587 | sprintf (cmd, "SET_NETWORK %d proto WPA", id);
|
| 588 | sta_docmd (cmd);
|
| 589 | } else if (!ptr && ptr2) {
|
| 590 | sprintf (cmd, "SET_NETWORK %d proto WPA2", id);
|
| 591 | sta_docmd (cmd);
|
| 592 | } else{
|
| 593 | sprintf (cmd, "SET_NETWORK %d proto WPA RSN", id);
|
| 594 | sta_docmd (cmd);
|
| 595 | }
|
| 596 |
|
| 597 | if (ptr5 && !ptr6) {
|
| 598 | sprintf (cmd, "SET_NETWORK %d pairwise CCMP", id);
|
| 599 | sta_docmd (cmd);
|
| 600 | } else if (!ptr5 && ptr6) {
|
| 601 | sprintf (cmd, "SET_NETWORK %d pairwise TKIP", id);
|
| 602 | sta_docmd (cmd);
|
| 603 | } else {
|
| 604 | wf_log ("[save_config]can support both of CCMP TKIP", ptr5, ptr6);
|
| 605 | sprintf (cmd, "SET_NETWORK %d pairwise CCMP TKIP", id);
|
| 606 | sta_docmd (cmd);
|
| 607 | }
|
| 608 |
|
| 609 | sprintf (cmd, "SET_NETWORK %d psk \"%s\" ", id , spot->password);
|
| 610 | sta_docmd (cmd);
|
| 611 | } else if (ptr3) { //|| ptr4)
|
| 612 | sprintf (cmd, "SET_NETWORK %d key_mgmt WPA-EAP", id);
|
| 613 | sta_docmd (cmd);
|
| 614 |
|
| 615 | if (g_cardmode == CARD_MODE_USIM) {
|
| 616 | sprintf (cmd, "SET_NETWORK %d eap AKA", id);
|
| 617 | sta_docmd (cmd);
|
| 618 | } else {
|
| 619 | sprintf (cmd, "SET_NETWORK %d eap SIM", id);
|
| 620 | sta_docmd (cmd);
|
| 621 | }
|
| 622 | sprintf (cmd, "SET_NETWORK %d pcsc '\" \"'", id);
|
| 623 | sta_docmd (cmd);
|
| 624 |
|
| 625 | //ÖØÐ¸²¸ÇÉèÖÃÓÅÏȼ¶Îª×î¸ß
|
| 626 | sprintf (cmd, "SET_NETWORK %d priority 4", id);
|
| 627 | sta_docmd (cmd);
|
| 628 |
|
| 629 | } else if (ptr_w3) {
|
| 630 | sprintf (cmd, "SET_NETWORK %d key_mgmt SAE", id);
|
| 631 | sta_docmd (cmd);
|
| 632 |
|
| 633 | //if set ,other need ieee80211w 0?
|
| 634 | //sprintf (cmd, "SET_NETWORK %d proto RSN", id);
|
| 635 | //sta_docmd (cmd);
|
| 636 |
|
| 637 | //sprintf (cmd, "SET_NETWORK %d pairwise CCMP", id);
|
| 638 | //sta_docmd (cmd);
|
| 639 |
|
| 640 | //sprintf (cmd, "SET_NETWORK %d ieee80211w 2", id);
|
| 641 | //sta_docmd (cmd);
|
| 642 |
|
| 643 |
|
| 644 | sprintf (cmd, "SET_NETWORK %d psk \"%s\"", id , spot->password);
|
| 645 | sta_docmd (cmd);
|
| 646 | } else if (ptr_w23) {
|
| 647 | sprintf (cmd, "SET_NETWORK %d key_mgmt SAE WPA-PSK", id);
|
| 648 | sta_docmd (cmd);
|
| 649 |
|
| 650 | //sprintf (cmd, "SET_NETWORK %d proto RSN", id);
|
| 651 | //sta_docmd (cmd);
|
| 652 |
|
| 653 | //sprintf (cmd, "SET_NETWORK %d pairwise CCMP", id);
|
| 654 | //sta_docmd (cmd);
|
| 655 |
|
| 656 | //sprintf (cmd, "SET_NETWORK %d ieee80211w 1", id);
|
| 657 | //sta_docmd (cmd);
|
| 658 |
|
| 659 |
|
| 660 | sprintf (cmd, "SET_NETWORK %d psk \"%s\"", id , spot->password);
|
| 661 | sta_docmd (cmd);
|
| 662 | } else {
|
| 663 | sprintf (cmd, "SET_NETWORK %d key_mgmt NONE", id);
|
| 664 | sta_docmd (cmd);
|
| 665 | }
|
| 666 |
|
| 667 | ptr = NULL;
|
| 668 | ptr = strstr (spot->encrypt_type, WIFI_STATION_PROFILE_ENCRYPT_WEP);
|
| 669 | if (ptr) {
|
| 670 | sprintf (cmd, "SET_NETWORK %d wep_tx_keyidx %d", id , spot->keyID);
|
| 671 | sta_docmd (cmd);
|
| 672 |
|
| 673 | key_len = strlen (spot->password);
|
| 674 | wf_log ("key_len=%d,password_wep=%s", key_len, spot->password);
|
| 675 | memset (cmd, 0, WIFI_STATION_CMD_LEN);
|
| 676 | if (key_len == 5 || key_len == 13) { //ascii
|
| 677 | sprintf (cmd, "SET_NETWORK %d wep_key%d \"%s\"", id , spot->keyID, spot->password);
|
| 678 | } else if (key_len == 10 || key_len == 26) { //hex
|
| 679 | sprintf (cmd, "SET_NETWORK %d wep_key%d %s", id, spot->keyID, spot->password);
|
| 680 | } else {
|
| 681 | sprintf (cmd, "SET_NETWORK %d wep_key%d \"%s\"", id, spot->keyID, spot->password);
|
| 682 | }
|
| 683 | sta_docmd (cmd);
|
| 684 | }
|
| 685 |
|
| 686 | ptr = NULL;
|
| 687 | ptr = strstr (spot->auth_mode, WIFI_STATION_PROFILE_AUTH_SHARED);
|
| 688 | if (ptr) {
|
| 689 | sprintf (cmd, "SET_NETWORK %d auth_alg SHARED", id);
|
| 690 | sta_docmd (cmd);
|
| 691 | }
|
| 692 |
|
| 693 | sprintf (cmd, "SET_NETWORK %d scan_ssid 1", id);
|
| 694 | sta_docmd (cmd);
|
| 695 |
|
| 696 |
|
| 697 | sta_docmd ("SAVE_CONFIG");
|
| 698 | sta_docmd ("LIST_NETWORKS");
|
| 699 | }
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 | static void dump_spot(void)
|
| 704 | {
|
| 705 | int i = 0;
|
| 706 | int spot_num = 0;
|
| 707 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 708 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 709 | spot_num = atoi (wifi_profile_num);
|
| 710 | if (spot_num > WIFI_STATION_SPOT_LIST_NUM || spot_num < 0)
|
| 711 | return;
|
| 712 |
|
| 713 | //´ËʱµÄ¸öÊýÒѾÊǼõ¹ýµÄÁË£¬ËùÒÔ¸öÊýÒª¼Ó1
|
| 714 | for (i = 0; i < spot_num; i++) {
|
| 715 | if (NULL != g_spot_list_p[i]) {
|
| 716 | wf_log ("spot[%d]%s,%d,%d,%d,%s,%s,%s,%s,%d,%s,%d", i , g_spot_list_p[i]->profile_name,
|
| 717 | g_spot_list_p[i]->from_provider, g_spot_list_p[i]->connect_status, g_spot_list_p[i]->signal,
|
| 718 | g_spot_list_p[i]->ssid, g_spot_list_p[i]->auth_mode, g_spot_list_p[i]->encrypt_type,
|
| 719 | g_spot_list_p[i]->password, g_spot_list_p[i]->keyID, g_spot_list_p[i]->mac, g_spot_list_p[i]->network_id);
|
| 720 | } else {
|
| 721 | wf_log ("ERROR, g_spot_list_p[%d] should not be NULL spot_num = %d\n ", i, spot_num);
|
| 722 | }
|
| 723 | }
|
| 724 | }
|
| 725 |
|
| 726 | static void del_spot (int id)
|
| 727 | {
|
| 728 | int i = 0;
|
| 729 | int spot_num = 0;
|
| 730 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 731 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 732 | spot_num = atoi (wifi_profile_num);
|
| 733 | if (spot_num >= WIFI_STATION_SPOT_LIST_NUM || spot_num < 0)//klocwork
|
| 734 | return;
|
| 735 |
|
| 736 | safe_free (g_spot_list_p[id]);
|
| 737 |
|
| 738 | //´ËʱµÄ¸öÊýÒѾÊǼõ¹ýµÄÁË£¬ËùÒÔ¸öÊýÒª¼Ó1
|
| 739 | for (i = id + 1; i <= spot_num; i++) {
|
| 740 |
|
| 741 | if (g_spot_list_p[i] != NULL) {
|
| 742 | g_spot_list_p[i - 1] = g_spot_list_p[i];
|
| 743 | g_spot_list_p[i] = NULL;
|
| 744 | }
|
| 745 | }
|
| 746 |
|
| 747 |
|
| 748 | //dump_spot();
|
| 749 | }
|
| 750 |
|
| 751 | /*webui ÒѾ½«ÐÂÔöµÄÈÈµã´æÈënv
|
| 752 | ´Ëº¯ÊýÐèÒª½«nvÖÐÐÂÈȵ㠸üе½ÎÒÃÇÓ¦ÓõÄÈ«¾Ö±äÁ¿ÖÐ
|
| 753 | ²¢½«ÐÂÈÈµã´æÈëÅäÖÃÎļþ£¬²¢½«»ñÈ¡µÄnetworkid ´æÈëÈ«¾Ö±äÁ¿
|
| 754 |
|
| 755 | */
|
| 756 | static void webui_update_spot_list (updateinfo_t *info)
|
| 757 | {
|
| 758 | int i = 0;
|
| 759 | spot_t *spot = NULL;
|
| 760 | int spot_num = 0;
|
| 761 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 762 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 763 | int flag = 0;
|
| 764 |
|
| 765 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 766 | spot_num = atoi (wifi_profile_num);
|
| 767 |
|
| 768 | wf_log ("action=%s profile=%s", info->action, info->spot);
|
| 769 |
|
| 770 | //Ìí¼ÓµÄÈȵ㲻¿ÉÄÜÊÇÔËÓªÉÌÈȵ㣬²»¿ÉÄÜÊÇÕýÁ´½ÓµÄÈȵ㣬ËùÒÔ¶¼ÊÇÆÕͨÈȵ㣬ֱ½Ó°´Ë³Ðò¼ÓÔÚºóÃæ
|
| 771 | if (strcmp (info->action, "add") == 0) {
|
| 772 |
|
| 773 | wf_log ("%s processing", info->action);
|
| 774 | if (spot_num < 1 || spot_num > WIFI_STATION_SPOT_LIST_NUM) {//klocwork
|
| 775 | return;
|
| 776 | }
|
| 777 |
|
| 778 | spot = parse_spot_string (info->spot);
|
| 779 | if (spot == NULL) {//klocwork
|
| 780 | return;
|
| 781 | }
|
| 782 | spot->network_id = -1;
|
| 783 | save_config (spot);
|
| 784 | g_spot_list_p[spot_num - 1] = spot;
|
| 785 |
|
| 786 | //Èç¹ûÊǶϿª×´Ì¬£¬Ö±½ÓÁ¬½Ó£¬Èç¹ûÊÇÁ¬½Ó״̬£¬Ö»ÐèÒªenable¾Í¿ÉÒÔÁË
|
| 787 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 788 |
|
| 789 | if (strcmp (sta_ip_status, "disconnect") == 0) {
|
| 790 | sta_connect (spot->network_id);
|
| 791 | }
|
| 792 |
|
| 793 | } else if (strcmp (info->action, "modify") == 0) {
|
| 794 | wf_log ("%s processing", info->action);
|
| 795 | spot = parse_spot_string (info->spot);
|
| 796 | if (spot == NULL) {//klocwork
|
| 797 | return;
|
| 798 | }
|
| 799 | for (i = 0; i < WIFI_STATION_SPOT_LIST_NUM; i++) {
|
| 800 | if (g_spot_list_p[i] != NULL && !strcmp (g_spot_list_p[i]->profile_name, spot->profile_name)) {
|
| 801 | spot->network_id = g_spot_list_p[i]->network_id;
|
| 802 | safe_free (g_spot_list_p[i]);
|
| 803 | g_spot_list_p[i] = spot;
|
| 804 | save_config (spot);
|
| 805 | flag = 1;
|
| 806 | break;
|
| 807 | }
|
| 808 | }
|
| 809 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 810 |
|
| 811 | if (strcmp (sta_ip_status, "disconnect") == 0) {
|
| 812 | sta_connect (spot->network_id);
|
| 813 | }
|
| 814 | if (flag == 0) {//for klocwork,¼Ç¼ȫ¾ÖµÄ²»ÄÜɾ
|
| 815 | safe_free (spot);
|
| 816 | }
|
| 817 | } else if (strcmp (info->action, "delete") == 0) {
|
| 818 | int network_id = -1;;
|
| 819 | int del_id = -1;
|
| 820 | char cmd[WIFI_STATION_CMD_LEN] = {0};
|
| 821 | wf_log ("%s processing", info->action);
|
| 822 |
|
| 823 | dump_spot();
|
| 824 | for (i = 0; i < WIFI_STATION_SPOT_LIST_NUM; i++) {
|
| 825 | if (g_spot_list_p[i] != NULL && !strncmp (g_spot_list_p[i]->profile_name, info->spot, strlen(g_spot_list_p[i]->profile_name))) {
|
| 826 | network_id = g_spot_list_p[i]->network_id;
|
| 827 | del_id = i;
|
| 828 | break;
|
| 829 | }
|
| 830 | }
|
| 831 |
|
| 832 | if (network_id != -1) {
|
| 833 | sprintf (cmd, "REMOVE_NETWORK %d", network_id);
|
| 834 | sta_docmd (cmd);
|
| 835 | sta_docmd ("SAVE_CONFIG");
|
| 836 |
|
| 837 | if (del_id != -1)
|
| 838 | del_spot (del_id);
|
| 839 | } else {
|
| 840 | wf_log ("spot:%s not found", info->spot);
|
| 841 | }
|
| 842 |
|
| 843 | }
|
| 844 | dump_spot();
|
| 845 | }
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 | /*
|
| 850 | ÔÚɾ³ýÈȵã¹ý³ÌÖÐͻȻ¶Ïµç£¬ÎÞ·¨±£´æµ½conf Îļþ£¬ÐèÒªÖØÐÂͬ²½Ò»ÏÂ
|
| 851 |
|
| 852 | */
|
| 853 |
|
| 854 | static int get_spot_info_from_conf (spot_ssid_id_t *info, int num)
|
| 855 | {
|
| 856 |
|
| 857 | int i = 0;
|
| 858 | char cmd[WIFI_STATION_CMD_LEN] = {0};
|
| 859 | char * reply = NULL;
|
| 860 |
|
| 861 | for (i = 0; i < WIFI_STATION_SPOT_LIST_NUM; i++) {
|
| 862 |
|
| 863 | info->id = -1;
|
| 864 | memset (info->ssid, 0 , sizeof (info->ssid));
|
| 865 |
|
| 866 | sprintf (cmd, "GET_NETWORK %d ssid", i);
|
| 867 | reply = sta_docmd (cmd);
|
| 868 | if (reply != NULL) {
|
| 869 | wf_log ("[update networkid from conf]reply SSID=%s", reply);
|
| 870 | strncpy (info->ssid, reply, sizeof (info->ssid)-1);
|
| 871 | } else {
|
| 872 | wf_log ("[update networkid from conf]conf read over!");
|
| 873 | break;
|
| 874 | }
|
| 875 |
|
| 876 | if (strlen (info->ssid) > 0) {
|
| 877 | wf_log ("[update networkid from conf] delete quote");
|
| 878 |
|
| 879 | delete_quote (info->ssid);
|
| 880 | }
|
| 881 |
|
| 882 | info->id = i;
|
| 883 | wf_log ("[update networkid from conf]SSID=%s, network_id=%d", info->ssid, i);
|
| 884 | info += 1;
|
| 885 | }
|
| 886 |
|
| 887 | return i;
|
| 888 | }
|
| 889 |
|
| 890 |
|
| 891 | /**/
|
| 892 | static void delete_quote (char * str)
|
| 893 | {
|
| 894 | int len = 0;
|
| 895 | printf("str=%s\n", str);
|
| 896 | if (*str == '\"') {
|
| 897 | //strcpy (str, str + 1); //cov m
|
| 898 | len = strlen(str + 1);
|
| 899 | memmove(str, str + 1, len + 1);
|
| 900 | *(str + len) = '\0';
|
| 901 | }
|
| 902 | printf("str=%s\n", str);
|
| 903 |
|
| 904 | if (*(str + strlen(str) - 1) == '\"')
|
| 905 | *(str + strlen(str) - 1) = '\0';
|
| 906 |
|
| 907 | printf("str=%s\n", str);
|
| 908 | }
|
| 909 |
|
| 910 |
|
| 911 | //1. ¿ªÆô¹Ø±Õapsta
|
| 912 | /*
|
| 913 |
|
| 914 | ¿ªÆô: conf fileÖØÐ±»wpa_supplicant¶ÁÈ¡£¬ÖØÆô·ÖÅänetwork id£¬ÐèÒªÖØÐÂͬ²½µ½spot list
|
| 915 |
|
| 916 |
|
| 917 | ¹Ø±Õ: ²»Çå¿Õconf file£¬ ΪÁ˺͹ػú±£³ÖÒ»Ö£¬Ò²ÐèÒª½«spot ÄÚÈÝÇå¿Õ
|
| 918 | */
|
| 919 |
|
| 920 |
|
| 921 | //2. ¿ª»ú¹Ø»ú
|
| 922 | /*
|
| 923 |
|
| 924 | ¹Ø»ú: Õý³£¹Ø»úºÍÒì³£¶Ïµç£¬¶¼²»»áÓÐÈκβÙ×÷Á÷³Ì£¬confÎļþ²»»áÐÞ¸Ä
|
| 925 | ¿ª»ú: Ö±½ÓÖØÐ·ÖÅäspot Äڴ棬´Ónvͬ²½spotÊý¾Ý£¬È»ºó´ÓconfÎļþÖÐͬ²½networkid£¬Èç¹ûûÓжÔÓ¦µÄnetworid
|
| 926 |
|
| 927 | ÔòÐèÒªÖØÐÂÌí¼Ó¸ÃÈȵ㵽confÎļþÖУ¬±ÈÈçÊÇÖ±½ÓÔ¤ÖõÄÔËÓªÉÌÈȵã
|
| 928 |
|
| 929 | */
|
| 930 | void sync_nv_spot_list_conf_file()
|
| 931 | {
|
| 932 | spot_ssid_id_t g_spot_ssid_id_p[WIFI_STATION_SPOT_LIST_NUM] = {{0}};
|
| 933 |
|
| 934 | int i = 0, j = 0;
|
| 935 | int spot_num = 0;
|
| 936 | int conf_spot_num = 0;
|
| 937 |
|
| 938 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 939 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 940 | spot_num = atoi (wifi_profile_num);
|
| 941 | if (spot_num > WIFI_STATION_SPOT_LIST_NUM || spot_num < 0)
|
| 942 | return;
|
| 943 |
|
| 944 | memset (g_spot_ssid_id_p, 0, WIFI_STATION_SPOT_LIST_NUM * sizeof (struct spot_ssid_id));
|
| 945 | conf_spot_num = get_spot_info_from_conf (g_spot_ssid_id_p, spot_num);
|
| 946 | wf_log ("spot_num=%d,conf_spot_num=%d", spot_num, conf_spot_num);
|
| 947 |
|
| 948 | for (i = 0; i < spot_num; i++) {
|
| 949 | wf_log ("[sync spot before]SSID:%s, networkid=%d", g_spot_list_p[i]->ssid, g_spot_list_p[i]->network_id);
|
| 950 | for (j = 0; j < WIFI_STATION_SPOT_LIST_NUM; j ++) {
|
| 951 | //[sync before]spot SSID:CPE_E3DE4E, conf ssid="CPE_E3DE4E", dubble quote !!!!!!
|
| 952 | wf_log ("[compare to conf]spot SSID:%s, conf ssid=%s", g_spot_list_p[i]->ssid, g_spot_ssid_id_p[j].ssid);
|
| 953 | if (strcmp (g_spot_ssid_id_p[j].ssid, g_spot_list_p[i]->ssid) == 0) {
|
| 954 | g_spot_list_p[i]->network_id = g_spot_ssid_id_p[j].id;
|
| 955 | break;
|
| 956 | }
|
| 957 | }
|
| 958 |
|
| 959 | if (-1 == g_spot_list_p[i]->network_id) {
|
| 960 | save_config (g_spot_list_p[i]); //Èç¹ûconfÖÐûÓУ¬ÔòÐèÒª¼ÓÈ룬update spot networkid
|
| 961 | }
|
| 962 | wf_log ("[sync spot after]SSID:%s, networkid=%d", g_spot_list_p[i]->ssid, g_spot_list_p[i]->network_id);
|
| 963 | }
|
| 964 |
|
| 965 | /*ÌÞ³ý confÎļþÖÐûÓÐÕý³£É¾³ýµÄspot*/
|
| 966 | for (i = 0; i < conf_spot_num; i++) {
|
| 967 | int conf_spot_in_nv = 0;
|
| 968 |
|
| 969 | wf_log ("[sync conf before]SSID:%s, networkid=%d", g_spot_ssid_id_p[i].ssid, g_spot_ssid_id_p[i].id);
|
| 970 | if (strlen (g_spot_ssid_id_p[i].ssid) > 0) {
|
| 971 | for (j = 0; j < spot_num; j ++) {
|
| 972 | wf_log ("[compare to spot]g_spot_list_p[j]->ssid=%s", g_spot_list_p[j]->ssid);
|
| 973 | if (strcmp (g_spot_ssid_id_p[i].ssid, g_spot_list_p[j]->ssid) == 0) {
|
| 974 | conf_spot_in_nv = 1;
|
| 975 | break;
|
| 976 | }
|
| 977 | }
|
| 978 |
|
| 979 | // Èç¹û²»´æÔÚnvÖУ¬ÐèҪɾ³ý
|
| 980 | if (0 == conf_spot_in_nv) {
|
| 981 | char cmd[WIFI_STATION_CMD_LEN] = {0};
|
| 982 | sprintf (cmd, "REMOVE_NETWORK %d", g_spot_ssid_id_p[i].id);
|
| 983 | sta_docmd (cmd);
|
| 984 | }
|
| 985 | }
|
| 986 |
|
| 987 | wf_log ("[sync conf after]SSID:%s, networkid=%d", g_spot_ssid_id_p[i].ssid, g_spot_ssid_id_p[i].id);
|
| 988 | }
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 | }
|
| 993 |
|
| 994 | //»ñÈ¡ÈȵãÁÐ±í£¬·µ»ØÒ»¸öÖ¸ÕëÊý×飬·ÅÈëÈ«¾Ö
|
| 995 | static void get_spot_list (void)
|
| 996 | {
|
| 997 | int i = 0;
|
| 998 | int j = 0;
|
| 999 | char spot_string[WIFI_STATION_SPOT_LEN] = {0};
|
| 1000 | char wifi_profile_nv_name[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 1001 | spot_t *spot = NULL;
|
| 1002 | int spot_num = 0;
|
| 1003 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 1004 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 1005 | spot_num = atoi (wifi_profile_num);
|
| 1006 |
|
| 1007 | wf_log ("free [g_spot_list_p] all spot");
|
| 1008 |
|
| 1009 | //ÏÈÊÍ·Å֮ǰ´æ´¢µÄÈȵãÁбíÄÚ´æ
|
| 1010 | for (i = 0; i < WIFI_STATION_SPOT_LIST_NUM; i++) {
|
| 1011 | safe_free (g_spot_list_p[i]);
|
| 1012 | //g_spot_list_p[i] = NULL;
|
| 1013 | }
|
| 1014 |
|
| 1015 | if (spot_num > 0 && spot_num <= WIFI_STATION_SPOT_LIST_NUM) {
|
| 1016 | for (i = 0; i < spot_num; i++) {
|
| 1017 | if (i == 0) {
|
| 1018 | sc_cfg_get ("wifi_profile", spot_string, WIFI_STATION_SPOT_LEN);
|
| 1019 | } else {
|
| 1020 | memset (wifi_profile_nv_name, 0, WIFI_STATION_PROFILE_NV_NAME_LEN);
|
| 1021 | snprintf (wifi_profile_nv_name, WIFI_STATION_PROFILE_NV_NAME_LEN, "wifi_profile%d", i);
|
| 1022 | sc_cfg_get (wifi_profile_nv_name, spot_string, WIFI_STATION_SPOT_LEN);
|
| 1023 | }
|
| 1024 |
|
| 1025 | wf_log ("get_spot_list spot_string[%d]= %s", i, spot_string);
|
| 1026 | spot = parse_spot_string (spot_string);
|
| 1027 | if (spot != NULL) {
|
| 1028 | g_spot_list_p[j] = spot;
|
| 1029 | j++;
|
| 1030 | }
|
| 1031 | }
|
| 1032 | }
|
| 1033 |
|
| 1034 | }
|
| 1035 |
|
| 1036 | static void save_spot_list (void)
|
| 1037 | {
|
| 1038 | int i = 0;
|
| 1039 | char spot_string[WIFI_STATION_SPOT_LEN] = {0};
|
| 1040 | char wifi_profile_nv_name[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 1041 |
|
| 1042 | for (i = 0; i < WIFI_STATION_SPOT_LIST_NUM; i++) {
|
| 1043 | if (g_spot_list_p[i] != NULL) {
|
| 1044 | snprintf (spot_string, WIFI_STATION_SPOT_LEN, "%s,%d,%d,%d,%s,%s,%s,%s,%d,%s", g_spot_list_p[i]->profile_name,
|
| 1045 | g_spot_list_p[i]->from_provider, g_spot_list_p[i]->connect_status, g_spot_list_p[i]->signal,
|
| 1046 | g_spot_list_p[i]->ssid, g_spot_list_p[i]->auth_mode, g_spot_list_p[i]->encrypt_type,
|
| 1047 | g_spot_list_p[i]->password, g_spot_list_p[i]->keyID, g_spot_list_p[i]->mac);
|
| 1048 |
|
| 1049 | wf_log (" g_spot_list_p[%d]=%s, [%d]", i, spot_string, g_spot_list_p[i]->network_id);
|
| 1050 |
|
| 1051 | if (i == 0) {
|
| 1052 | sc_cfg_set ("wifi_profile", spot_string);
|
| 1053 | } else {
|
| 1054 | snprintf (wifi_profile_nv_name, WIFI_STATION_PROFILE_NV_NAME_LEN, "wifi_profile%d", i);
|
| 1055 | sc_cfg_set (wifi_profile_nv_name, spot_string);
|
| 1056 | }
|
| 1057 | }
|
| 1058 | }
|
| 1059 | }
|
| 1060 |
|
| 1061 |
|
| 1062 | /*
|
| 1063 | ½«Á´½Ó³É¹¦µÄÈȵ㣬Åŵ½µÚһλ
|
| 1064 | */
|
| 1065 | static void resort_spot_list (void)
|
| 1066 | {
|
| 1067 |
|
| 1068 | int i = 0, j = 0;
|
| 1069 | int index = 0;
|
| 1070 | spot_t * spot = NULL;
|
| 1071 | // char profile[WIFI_STATION_SPOT_PROFILE_NAME_LEN] = {0};
|
| 1072 |
|
| 1073 | // sc_cfg_get("EX_wifi_profile", profile, WIFI_STATION_SPOT_PROFILE_NAME_LEN);
|
| 1074 |
|
| 1075 |
|
| 1076 | for (i = 0; i < WIFI_STATION_SPOT_LIST_NUM; i++) {
|
| 1077 | if (g_spot_list_p[i] != NULL) {
|
| 1078 | if (g_spot_list_p[i]->connect_status == 1) {
|
| 1079 | index = i;
|
| 1080 | spot = g_spot_list_p[i];
|
| 1081 | break;
|
| 1082 | }
|
| 1083 | }
|
| 1084 |
|
| 1085 | }
|
| 1086 |
|
| 1087 | if (index == 0) return;
|
| 1088 |
|
| 1089 | for (i = 0; i < WIFI_STATION_SPOT_LIST_NUM; i++) {
|
| 1090 | if (1 == g_spot_list_p[i]->from_provider) {
|
| 1091 | continue;
|
| 1092 | } else {
|
| 1093 | //move other spot
|
| 1094 | for (j = index; j > i; j--) { // ¼Ù¶¨×îºóÒ»¸ö¿Ï¶¨Êǿյ쬲»¿ÉÄÜ10¸öÂúÁË£¬»¹ÔÚÌí¼ÓÈȵ㣬֮ǰÒѾÅжϴíÎó·µ»ØÁË
|
| 1095 | if (g_spot_list_p[j] == NULL) continue;
|
| 1096 | else {
|
| 1097 | g_spot_list_p[j] = g_spot_list_p[j - 1]; //j must greater than 0
|
| 1098 | }
|
| 1099 | }
|
| 1100 | if (i != index) {
|
| 1101 | g_spot_list_p[i] = spot;
|
| 1102 | wf_log ("[%s]SSID=[%s] from %d move to %d", __FILE__, spot->ssid, index, i);
|
| 1103 | } else {
|
| 1104 | wf_log ("[%s]SSID=[%s] do not move", __FILE__, spot->ssid);
|
| 1105 | }
|
| 1106 | break;
|
| 1107 | }
|
| 1108 | }
|
| 1109 |
|
| 1110 | //¸ü¸Ä˳Ðòºó£¬ÐèÒªÖØÐ±¸·Ý signal
|
| 1111 | //reback_up_signal();
|
| 1112 |
|
| 1113 | save_spot_list();
|
| 1114 |
|
| 1115 | }
|
| 1116 |
|
| 1117 |
|
| 1118 | static void update_spot_list_signal_connect_status (short signal, short connect_status)
|
| 1119 | {
|
| 1120 | int i = 0;
|
| 1121 |
|
| 1122 | for (i = 0; i < WIFI_STATION_SPOT_LIST_NUM; i++) {
|
| 1123 | if (g_spot_list_p[i] != NULL) {
|
| 1124 | if (signal >= 0) {
|
| 1125 | g_spot_list_p[i]->signal = signal;
|
| 1126 | }
|
| 1127 |
|
| 1128 | if (connect_status >= 0) {
|
| 1129 | g_spot_list_p[i]->connect_status = connect_status;
|
| 1130 | }
|
| 1131 | }
|
| 1132 | }
|
| 1133 |
|
| 1134 | }
|
| 1135 |
|
| 1136 | static void update_spot_connect_status_by_status_result (BOOL is_connected)
|
| 1137 | {
|
| 1138 | int i = 0;
|
| 1139 | char spot_string[WIFI_STATION_SPOT_LEN] = {0};
|
| 1140 | char wifi_profile_nv_name[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 1141 |
|
| 1142 | wf_log ("is_connected=%d, g_linked_network_id= %d", is_connected, g_linked_network_id);
|
| 1143 |
|
| 1144 | for (i = 0; i < WIFI_STATION_SPOT_LIST_NUM; i++) {
|
| 1145 | if (g_spot_list_p[i] != NULL && g_spot_list_p[i] ->network_id == g_linked_network_id) {
|
| 1146 | if (is_connected == TRUE) {
|
| 1147 | g_spot_list_p[i]->connect_status = 1;
|
| 1148 | } else {
|
| 1149 | g_spot_list_p[i]->connect_status = 0;
|
| 1150 | }
|
| 1151 |
|
| 1152 | if (strcmp (g_spot_list_p[i]->mac, "0F:00:00:00:00:00") == 0) {
|
| 1153 | strcpy (g_spot_list_p[i]->mac, g_linked_ap_mac);
|
| 1154 | }
|
| 1155 | wf_log ("g_spot_list_p[%d]->mac=%s", i, g_spot_list_p[i]->mac);
|
| 1156 | wf_log ("profile[%d]=%d", i, g_spot_list_p[i]->connect_status);
|
| 1157 |
|
| 1158 | snprintf (spot_string, WIFI_STATION_SPOT_LEN, "%s,%d,%d,%d,%s,%s,%s,%s,%d,%s", g_spot_list_p[i]->profile_name,
|
| 1159 | g_spot_list_p[i]->from_provider, g_spot_list_p[i]->connect_status, g_spot_list_p[i]->signal,
|
| 1160 | g_spot_list_p[i]->ssid, g_spot_list_p[i]->auth_mode, g_spot_list_p[i]->encrypt_type,
|
| 1161 | g_spot_list_p[i]->password, g_spot_list_p[i]->keyID, g_spot_list_p[i]->mac);
|
| 1162 |
|
| 1163 | if (i == 0) {
|
| 1164 | sc_cfg_set ("wifi_profile", spot_string);
|
| 1165 | } else {
|
| 1166 | snprintf (wifi_profile_nv_name, WIFI_STATION_PROFILE_NV_NAME_LEN, "wifi_profile%d", i);
|
| 1167 | sc_cfg_set (wifi_profile_nv_name, spot_string);
|
| 1168 | }
|
| 1169 |
|
| 1170 | break;
|
| 1171 | }
|
| 1172 | }
|
| 1173 | }
|
| 1174 |
|
| 1175 | static void update_spot_signal_by_scan_result (scan_result_t *scan_result)
|
| 1176 | {
|
| 1177 | int i = 0;
|
| 1178 |
|
| 1179 | if (scan_result == NULL) {
|
| 1180 | return;
|
| 1181 | }
|
| 1182 |
|
| 1183 | for (i = 0; i < WIFI_STATION_SPOT_LIST_NUM; i++) {
|
| 1184 | if (g_spot_list_p[i] != NULL) {
|
| 1185 | if (strcmp (g_spot_list_p[i]->mac, scan_result->mac) == 0 &&
|
| 1186 |
|
| 1187 | strcmp (g_spot_list_p[i]->ssid, scan_result->ssid) == 0
|
| 1188 | // && (strcmp(g_spot_list_p[i]->auth_mode, scan_result->auth_mode) == 0 ||
|
| 1189 | // (strcmp(g_spot_list_p[i]->auth_mode,WIFI_STATION_PROFILE_AUTH_WPA_EAP)==0 && strcmp(scan_result->auth_mode,"802.1X")==0))
|
| 1190 | /*&& strstr(g_spot_list_p[i]->encrypt_type, scan_result->encrypt_type) != NULL*/)
|
| 1191 | // Õë¶ÔÒþ²ØÈȵ㣬ÊÖ¶¯Ìí¼ÓµÄcipherΪauto£¬µ¼ÖÂÎÞ·¨Ê¶±ð¸üÐÂÈȵãÐźÅ
|
| 1192 | //±¾À´ÐèҪʹÓÃmac½øÐÐÆ¥Å䣬Î÷°²²»ÅäºÏ£¬Ö»ÓÐÈ¡ÕâÑùµÄ·±Ëö°ì·¨
|
| 1193 | //webui×Ô¶¯Ê¶±ðtkip aesΪauto£¬±£´æÔÚnv profileÀïÃæÎªTKIPCCMP,µ¼Ö´˴¦ÎÞ·¨Æ¥Å䣬ÎÞ·¨¸üÐÂÈȵãÐźÅ
|
| 1194 | //EAP-SIM/AKA, ÓëÔ±¾Ð´µÄ802.1xÒ²²»Æ¥Å䣬µ¼ÖÂÎÞ·¨¸üÐÂÈȵãÐźÅ
|
| 1195 | //ÐÞ¸ÄΪɨÃèÈȵãµÄ¼ÓÃÜÀàÐÍΪTKIP CCMP,Ö»ÒªÄÜÔÚ±£´æÈȵãÖÐÕÒµ½´Ë×Ö·û£¬ÔòÈÏΪÊÇͬһ¸öÈȵ㣬µ«ÊÇÎÞ·¨½â¾öÕæµÄÓÐÁ½¸öÏàͬµÄÈȵ㣬Õâ¸öÎÞ·¨Ê¶±ð
|
| 1196 | {
|
| 1197 | g_spot_list_p[i]->signal = scan_result->signal;
|
| 1198 | break;
|
| 1199 | }
|
| 1200 | }
|
| 1201 | }
|
| 1202 | }
|
| 1203 |
|
| 1204 |
|
| 1205 | static void sort_scan_result_by_signal (scan_result_t **scan_result, int size)
|
| 1206 | {
|
| 1207 | int i, j = 0;
|
| 1208 | scan_result_t *insertnode = NULL;
|
| 1209 |
|
| 1210 | if (scan_result == NULL) {
|
| 1211 | return;
|
| 1212 | }
|
| 1213 |
|
| 1214 | for (i = 0; i < size; i++) {
|
| 1215 | if (scan_result[i] == NULL) {
|
| 1216 | return;
|
| 1217 | }
|
| 1218 | }
|
| 1219 |
|
| 1220 | //Ö±½Ó²åÈëÅÅÐòËã·¨
|
| 1221 | for (i = 1; i < size; i++) { //ÒÀ´Î²åÈëÊýÖµ
|
| 1222 | insertnode = scan_result[i]; //ÉèÖÃÓû²åÈëµÄÊýÖµ,ÉÚ±ø
|
| 1223 | j = i - 1; //Óû²åÈëÊý×éµÄ¿ªÊ¼Î»ÖÃ
|
| 1224 | while (j >= 0 && insertnode->signal > scan_result[j]->signal) { //ÕÒÊʵ±µÄ²åÈëλÖÃ
|
| 1225 | scan_result[j + 1] = scan_result[j];
|
| 1226 | j--;
|
| 1227 | }
|
| 1228 | scan_result[j + 1] = insertnode;
|
| 1229 | }
|
| 1230 |
|
| 1231 | }
|
| 1232 |
|
| 1233 | /*
|
| 1234 | inputStr: if there is a \, then
|
| 1235 | outputStr: add \\ before, to be \\\
|
| 1236 |
|
| 1237 |
|
| 1238 | */
|
| 1239 |
|
| 1240 | static char* process_backlash (char* inputStr, char* outputStr)
|
| 1241 | {
|
| 1242 | int len = 0;
|
| 1243 | int i, j = 0;
|
| 1244 | if ( (NULL == inputStr) || (NULL == outputStr)) {
|
| 1245 | return NULL;
|
| 1246 | }
|
| 1247 |
|
| 1248 | len = strlen (inputStr);
|
| 1249 | for (i = 0; i < len; i++) { //linux תÒå
|
| 1250 | if ( (inputStr[i] == 0x5c && inputStr[i + 1] == 'x')) {
|
| 1251 | outputStr[j++] = 0x5c;
|
| 1252 | }
|
| 1253 | outputStr[j++] = inputStr[i];
|
| 1254 | }
|
| 1255 | outputStr[j] = '\0';
|
| 1256 | //printf("[process_backlash]inputStr=%s,outputStr=%s",inputStr,outputStr);
|
| 1257 |
|
| 1258 | return outputStr;
|
| 1259 | }
|
| 1260 |
|
| 1261 | static void save_scan_result (scan_result_t* scan_result, char *scan_result_str, char *scan_result_str1)
|
| 1262 | {
|
| 1263 | char *scan_result_str_temp = NULL;
|
| 1264 | char one_scan_result_str[WIFI_STATION_SCAN_ONE_RESULT_STR_LEN] = {0};
|
| 1265 | int one_scan_result_str_len = 0;
|
| 1266 |
|
| 1267 | char ssid[128] = {0};
|
| 1268 | if (scan_result == NULL
|
| 1269 | || scan_result_str == NULL
|
| 1270 | || scan_result_str1 == NULL) {
|
| 1271 | return;
|
| 1272 | }
|
| 1273 |
|
| 1274 | if (strlen (scan_result->ssid) <= 0) {
|
| 1275 | return;
|
| 1276 | }
|
| 1277 |
|
| 1278 | scan_result_str_temp = safe_malloc (WIFI_STATION_SCAN_RESULT_STR_LEN, TRUE);
|
| 1279 |
|
| 1280 |
|
| 1281 | process_backlash (scan_result->ssid, ssid);
|
| 1282 |
|
| 1283 | snprintf (one_scan_result_str, WIFI_STATION_SCAN_ONE_RESULT_STR_LEN, "%d,%d,%s,%d,%d,%s,%s,%s", scan_result->from_provider, scan_result->connect_status, ssid,
|
| 1284 | scan_result->signal, scan_result->channel, scan_result->auth_mode, scan_result->encrypt_type, scan_result->mac);
|
| 1285 |
|
| 1286 | one_scan_result_str_len = strlen (one_scan_result_str);
|
| 1287 |
|
| 1288 | //cfg½Ó¿ÚÊÇÒÔ"nv name=nv value\0"·½Ê½À´´æ´¢£¬ÇÒÒ»´Î×Ϊ1024£¬Òò´ËÕâ±ßÊÇ+2
|
| 1289 | if (one_scan_result_str_len + strlen (scan_result_str) + strlen ("EX_APLIST") + 2 > WIFI_STATION_SCAN_RESULT_STR_LEN) {
|
| 1290 | if (one_scan_result_str_len + strlen (scan_result_str1) + strlen ("EX_APLIST1") + 2 > WIFI_STATION_SCAN_RESULT_STR_LEN) {
|
| 1291 | //³¬³ö2048×Ö½ÚÁË£¬Í˳ö
|
| 1292 | safe_free (scan_result_str_temp);
|
| 1293 | return;
|
| 1294 | } else {
|
| 1295 | safe_strcpy (scan_result_str_temp, scan_result_str1, strlen(scan_result_str1) + 1);
|
| 1296 |
|
| 1297 | strncat (scan_result_str_temp, one_scan_result_str, one_scan_result_str_len);
|
| 1298 | strncat (scan_result_str_temp, ";", 1);
|
| 1299 |
|
| 1300 | //¸³Öµ½á¹û
|
| 1301 | safe_strcpy (scan_result_str1, scan_result_str_temp, WIFI_STATION_SCAN_RESULT_STR_LEN);
|
| 1302 | }
|
| 1303 | } else {
|
| 1304 | safe_strcpy (scan_result_str_temp, scan_result_str, strlen(scan_result_str) + 1);//wlocwork
|
| 1305 |
|
| 1306 | strncat (scan_result_str_temp, one_scan_result_str, one_scan_result_str_len);
|
| 1307 | strncat (scan_result_str_temp, ";", 1);
|
| 1308 |
|
| 1309 | //¸³Öµ½á¹û
|
| 1310 | safe_strcpy (scan_result_str, scan_result_str_temp, WIFI_STATION_SCAN_RESULT_STR_LEN);
|
| 1311 | }
|
| 1312 |
|
| 1313 | safe_free (scan_result_str_temp);
|
| 1314 |
|
| 1315 | }
|
| 1316 |
|
| 1317 |
|
| 1318 | static scan_result_t* parse_scan_result (Var *var)
|
| 1319 | {
|
| 1320 | char *ptr = NULL;
|
| 1321 | char *ptr1 = NULL;
|
| 1322 | char *ptr2 = NULL;
|
| 1323 | char *ptr3 = NULL;
|
| 1324 | char *ptr4 = NULL;
|
| 1325 | char *ptr5 = NULL;
|
| 1326 | scan_result_t *scan_result = NULL;
|
| 1327 | int frequency = 0;
|
| 1328 | int signal = 0;
|
| 1329 | char flags[WIFI_STATION_FLAGS_LEN] = {0};
|
| 1330 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 1331 |
|
| 1332 | char operater_ap[32] = {0};
|
| 1333 |
|
| 1334 | if (var == NULL) {
|
| 1335 | return NULL;
|
| 1336 | }
|
| 1337 |
|
| 1338 | //²éÕÒÊÇ·ñÊǿɺöÂÔµÄÒ»ÐÐ
|
| 1339 | ptr = strstr (var->val.str.sval, WIFI_STATION_SCAN_RESULT_PARSE_IGNORE);
|
| 1340 | if (ptr) {
|
| 1341 | return NULL;
|
| 1342 | } else {
|
| 1343 | //·ÖÅäɨÃè½á¹ûÄÚ´æ
|
| 1344 | scan_result = safe_malloc (sizeof (scan_result_t), FALSE);
|
| 1345 | if (scan_result == NULL) {
|
| 1346 | return NULL;
|
| 1347 | }
|
| 1348 |
|
| 1349 | //Æ¥ÅäɨÃè½á¹ûÐÅÏ¢
|
| 1350 | sscanf (var->val.str.sval, "%19[0-9,a-f,A-F,:] %d %d %127s %127[^\n]", scan_result->mac, &frequency, &signal, flags, scan_result->ssid);
|
| 1351 |
|
| 1352 | if (strncmp (scan_result->ssid, "\\x00", 4) == 0) {
|
| 1353 | wf_log ("scan_result->mac=[%s] scan_result->ssid=[%s]is a hidden AP",
|
| 1354 | scan_result->mac, scan_result->ssid);
|
| 1355 | safe_free (scan_result);
|
| 1356 | return NULL;
|
| 1357 | }
|
| 1358 |
|
| 1359 |
|
| 1360 | sc_cfg_get ("operater_ap", operater_ap, sizeof (operater_ap));
|
| 1361 | if (strcmp (scan_result->ssid, operater_ap) == 0) {
|
| 1362 | scan_result->from_provider = 1;//fromProvider ÊÇ·ñÀ´×ÔÔËÓªÉÌ
|
| 1363 | } else {
|
| 1364 | scan_result->from_provider = 0;//fromProvider ÊÇ·ñÀ´×ÔÔËÓªÉÌ
|
| 1365 | }
|
| 1366 |
|
| 1367 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 1368 | //connectStatus Á¬½Ó״̬
|
| 1369 | if (g_linked_network_id != -1 && strcmp (sta_ip_status, "connect") == 0) {
|
| 1370 | int i = 0;
|
| 1371 | i = find_linked_ap_index();
|
| 1372 | if (i != -1) {
|
| 1373 | wf_log ("g_spot_list_p[i]->ssid=[%s],scan_result->ssid=[%s]",
|
| 1374 | g_spot_list_p[i]->ssid, scan_result->ssid);
|
| 1375 |
|
| 1376 | if (strcmp (g_spot_list_p[i]->mac, scan_result->mac) == 0
|
| 1377 | && strcmp (g_spot_list_p[i]->ssid, scan_result->ssid) == 0) {
|
| 1378 | scan_result->connect_status = 1;
|
| 1379 | } else {
|
| 1380 | scan_result->connect_status = 0;
|
| 1381 |
|
| 1382 | }
|
| 1383 | wf_log ("connect_status = [%d]", scan_result->connect_status);
|
| 1384 | } else {
|
| 1385 | scan_result->connect_status = 0;
|
| 1386 | }
|
| 1387 |
|
| 1388 | } else {
|
| 1389 | scan_result->connect_status = 0;
|
| 1390 | }
|
| 1391 |
|
| 1392 | //signalÐźÅÇ¿¶È
|
| 1393 | if (signal > WIFI_STATION_SIGNAL_LEVEL4) {
|
| 1394 | scan_result->signal = 4;
|
| 1395 | } else if (signal > WIFI_STATION_SIGNAL_LEVEL3) {//kw 3
|
| 1396 | scan_result->signal = 3;
|
| 1397 | } else if (signal > WIFI_STATION_SIGNAL_LEVEL2) {
|
| 1398 | scan_result->signal = 2;
|
| 1399 | } else if (signal > WIFI_STATION_SIGNAL_LEVEL1) {
|
| 1400 | scan_result->signal = 1;
|
| 1401 | } else {
|
| 1402 | scan_result->signal = 0;
|
| 1403 | }
|
| 1404 |
|
| 1405 | //channel
|
| 1406 | switch (frequency) {
|
| 1407 | case WIFI_STATION_CHANNEL1:
|
| 1408 | scan_result->channel = 1;
|
| 1409 | break;
|
| 1410 | case WIFI_STATION_CHANNEL2:
|
| 1411 | scan_result->channel = 2;
|
| 1412 | break;
|
| 1413 | case WIFI_STATION_CHANNEL3:
|
| 1414 | scan_result->channel = 3;
|
| 1415 | break;
|
| 1416 | case WIFI_STATION_CHANNEL4:
|
| 1417 | scan_result->channel = 4;
|
| 1418 | break;
|
| 1419 | case WIFI_STATION_CHANNEL5:
|
| 1420 | scan_result->channel = 5;
|
| 1421 | break;
|
| 1422 | case WIFI_STATION_CHANNEL6:
|
| 1423 | scan_result->channel = 6;
|
| 1424 | break;
|
| 1425 | case WIFI_STATION_CHANNEL7:
|
| 1426 | scan_result->channel = 7;
|
| 1427 | break;
|
| 1428 | case WIFI_STATION_CHANNEL8:
|
| 1429 | scan_result->channel = 8;
|
| 1430 | break;
|
| 1431 | case WIFI_STATION_CHANNEL9:
|
| 1432 | scan_result->channel = 9;
|
| 1433 | break;
|
| 1434 | case WIFI_STATION_CHANNEL10:
|
| 1435 | scan_result->channel = 10;
|
| 1436 | break;
|
| 1437 | case WIFI_STATION_CHANNEL11:
|
| 1438 | scan_result->channel = 11;
|
| 1439 | break;
|
| 1440 | case WIFI_STATION_CHANNEL12:
|
| 1441 | scan_result->channel = 12;
|
| 1442 | break;
|
| 1443 | case WIFI_STATION_CHANNEL13:
|
| 1444 | scan_result->channel = 13;
|
| 1445 | break;
|
| 1446 | default:
|
| 1447 | scan_result->channel = 0;
|
| 1448 | break;
|
| 1449 | }
|
| 1450 |
|
| 1451 | //authMode¼øÈ¨Ä£Ê½
|
| 1452 | ptr = NULL;
|
| 1453 | ptr2 = NULL;
|
| 1454 | ptr3 = NULL;
|
| 1455 | ptr = strstr (flags, WIFI_STATION_AUTH_WPA_PSK);
|
| 1456 | ptr1 = strstr (flags, WIFI_STATION_AUTH_WPA3); //wpa2/wpa3: [WPA2-PSK+SAE-CCMP] wpa3: [WPA2-SAE-CCMP][ESS]
|
| 1457 | ptr2 = strstr (flags, WIFI_STATION_AUTH_WPA2_PSK);
|
| 1458 | ptr3 = strstr (flags, WIFI_STATION_AUTH_SHARED);
|
| 1459 | ptr4 = strstr (flags, WIFI_STATION_AUTH_WPA_EAP);
|
| 1460 | ptr5 = strstr (flags, WIFI_STATION_AUTH_WPA2_EAP);
|
| 1461 | if (ptr && ptr2) {
|
| 1462 | snprintf (scan_result->auth_mode, WIFI_STATION_AUTH_MODE_LEN, "WPAPSKWPA2PSK");
|
| 1463 | } else if (ptr1 && ptr2) {
|
| 1464 | snprintf (scan_result->auth_mode, WIFI_STATION_AUTH_MODE_LEN, "WPA2WPA3");
|
| 1465 | } else if (ptr) {
|
| 1466 | snprintf (scan_result->auth_mode, WIFI_STATION_AUTH_MODE_LEN, "WPAPSK");
|
| 1467 | } else if (ptr2) {
|
| 1468 | snprintf (scan_result->auth_mode, WIFI_STATION_AUTH_MODE_LEN, "WPA2PSK");
|
| 1469 | } else if (ptr1) {
|
| 1470 | snprintf (scan_result->auth_mode, WIFI_STATION_AUTH_MODE_LEN, "WPA3Personal");
|
| 1471 | } else if (ptr3) {
|
| 1472 | snprintf (scan_result->auth_mode, WIFI_STATION_AUTH_MODE_LEN, "SHARED");
|
| 1473 | } else if (ptr4 && ptr5) {
|
| 1474 |
|
| 1475 | snprintf (scan_result->auth_mode, WIFI_STATION_AUTH_MODE_LEN, "802.1X");
|
| 1476 | //TODO scan_result->from_provider = 1;//fromProvider ÊÇ·ñÀ´×ÔÔËÓªÉÌ
|
| 1477 | } else if (ptr4) {
|
| 1478 | snprintf (scan_result->auth_mode, WIFI_STATION_AUTH_MODE_LEN, "802.1X");
|
| 1479 |
|
| 1480 | //TODO scan_result->from_provider = 1;//fromProvider ÊÇ·ñÀ´×ÔÔËÓªÉÌ
|
| 1481 | } else if (ptr5) {
|
| 1482 | snprintf (scan_result->auth_mode, WIFI_STATION_AUTH_MODE_LEN, "802.1X");
|
| 1483 |
|
| 1484 | //TODO scan_result->from_provider = 1;//fromProvider ÊÇ·ñÀ´×ÔÔËÓªÉÌ
|
| 1485 | } else {
|
| 1486 | snprintf (scan_result->auth_mode, WIFI_STATION_AUTH_MODE_LEN, "OPEN");
|
| 1487 | }
|
| 1488 |
|
| 1489 | //encryptType¼ÓÃÜÀàÐÍ
|
| 1490 | ptr = NULL;
|
| 1491 | ptr2 = NULL;
|
| 1492 | ptr3 = NULL;
|
| 1493 | ptr = strstr (flags, WIFI_STATION_ENCRYPT_CCMP);
|
| 1494 | ptr2 = strstr (flags, WIFI_STATION_ENCRYPT_TKIP);
|
| 1495 | ptr3 = strstr (flags, WIFI_STATION_ENCRYPT_WEP);
|
| 1496 | if (ptr && ptr2) {
|
| 1497 | snprintf (scan_result->encrypt_type, WIFI_STATION_ENCRYPT_TYPE_LEN, "TKIPCCMP");
|
| 1498 | } else if (ptr) {
|
| 1499 | snprintf (scan_result->encrypt_type, WIFI_STATION_ENCRYPT_TYPE_LEN, "CCMP");
|
| 1500 | } else if (ptr2) {
|
| 1501 | snprintf (scan_result->encrypt_type, WIFI_STATION_ENCRYPT_TYPE_LEN, "TKIP");
|
| 1502 | } else if (ptr3) {
|
| 1503 | snprintf (scan_result->encrypt_type, WIFI_STATION_ENCRYPT_TYPE_LEN, "WEP");
|
| 1504 | } else {
|
| 1505 | snprintf (scan_result->encrypt_type, WIFI_STATION_ENCRYPT_TYPE_LEN, "NONE");
|
| 1506 | }
|
| 1507 | }
|
| 1508 |
|
| 1509 | return scan_result;
|
| 1510 |
|
| 1511 | }
|
| 1512 |
|
| 1513 |
|
| 1514 | static void handle_scan_result (vector_t* v)
|
| 1515 | {
|
| 1516 | int i = 0;
|
| 1517 | int j = 0;
|
| 1518 | Var *var = NULL;
|
| 1519 | char *scan_result_str = NULL;
|
| 1520 | char *scan_result_str1 = NULL;
|
| 1521 | int scan_result_str_len = 0;
|
| 1522 | int scan_result_str_len1 = 0;
|
| 1523 | scan_result_t *scan_result = NULL;
|
| 1524 |
|
| 1525 | if (v == NULL) {
|
| 1526 | return;
|
| 1527 | }
|
| 1528 |
|
| 1529 | scan_result_str = safe_malloc (WIFI_STATION_SCAN_RESULT_STR_LEN, FALSE);
|
| 1530 | scan_result_str1 = safe_malloc (WIFI_STATION_SCAN_RESULT_STR_LEN, FALSE);
|
| 1531 |
|
| 1532 | if (scan_result_str == NULL || scan_result_str1 == NULL) {
|
| 1533 | safe_free (scan_result_str);
|
| 1534 | safe_free (scan_result_str1);
|
| 1535 | return;
|
| 1536 | }
|
| 1537 |
|
| 1538 | //ÏÈÊÍ·Å֮ǰ´æ´¢µÄɨÃèÈȵãÁбíÄÚ´æ
|
| 1539 | for (i = 0; i < WIFI_STATION_SCAN_RESULT_LIST_NUM; i++) {
|
| 1540 | safe_free (g_scan_result_list_p[i]);
|
| 1541 | //g_scan_result_list_p[i] = NULL;
|
| 1542 | //printf("xujian safe_free g_scan_result_list_p[%d] = %d \n", i, g_scan_result_list_p[i]);
|
| 1543 | }
|
| 1544 |
|
| 1545 | // Ö»ÄÜÊÇÔÚwebui¸üÐÂÁбí²Å»áÈ¥»ñÈ¡ÁÐ±í£¬ÆäËûÇé¿ö²»ÐèÒª
|
| 1546 | // get_spot_list();
|
| 1547 | //Ïȳõʼ»¯ÈȵãÁбíµÄÐźÅΪ0
|
| 1548 | update_spot_list_signal_connect_status (0, -1);
|
| 1549 |
|
| 1550 | for (i = 0; i < vector_size (v); i++) {
|
| 1551 | if (j >= WIFI_STATION_SCAN_RESULT_LIST_NUM) {
|
| 1552 | break;
|
| 1553 | }
|
| 1554 |
|
| 1555 | var = vector_get (v, i);
|
| 1556 | if (var->type == IS_STRING) {
|
| 1557 | scan_result = parse_scan_result (var); // ÀïÃæÓÐ ¸üРɨÃèÁбíµÄ ÈȵãÁ¬½ÓÇé¿ö£¬¸ù¾ÝmacµØÖ·½øÐÐÆ¥Åä
|
| 1558 | if (scan_result != NULL) {
|
| 1559 | g_scan_result_list_p[j] = scan_result;
|
| 1560 |
|
| 1561 | //²éÕÒ¸üжÔÓ¦ÈȵãµÄÐźÅÇ¿¶È
|
| 1562 | update_spot_signal_by_scan_result (g_scan_result_list_p[j]);
|
| 1563 |
|
| 1564 | j++;
|
| 1565 | }
|
| 1566 | }
|
| 1567 | }
|
| 1568 |
|
| 1569 | save_spot_list();
|
| 1570 |
|
| 1571 | sort_scan_result_by_signal (g_scan_result_list_p, j);
|
| 1572 |
|
| 1573 | for (i = 0; i < j; i++) {
|
| 1574 | save_scan_result (g_scan_result_list_p[i], scan_result_str, scan_result_str1);
|
| 1575 | }
|
| 1576 |
|
| 1577 | scan_result_str_len = strlen (scan_result_str);
|
| 1578 | scan_result_str_len1 = strlen (scan_result_str1);
|
| 1579 |
|
| 1580 | wf_log ("scan_result_str_len = %d scan_result_str_len1 = %d j = %d", scan_result_str_len, scan_result_str_len1, j);
|
| 1581 |
|
| 1582 | //ÏÈÇå¿ÕɨÃèÁбíNV£¬ÔÙд
|
| 1583 | sc_cfg_set ("EX_APLIST", "");
|
| 1584 | sc_cfg_set ("EX_APLIST1", "");
|
| 1585 |
|
| 1586 | if (scan_result_str_len > 0 && scan_result_str_len < WIFI_STATION_SCAN_RESULT_STR_LEN) {
|
| 1587 | scan_result_str[scan_result_str_len - 1] = '\0'; //È¥µô×îºóÒ»¸ö·ÖºÅ
|
| 1588 | sc_cfg_set ("EX_APLIST", scan_result_str);
|
| 1589 | }//klocwork
|
| 1590 | if (scan_result_str_len1 > 0 && scan_result_str_len1 < WIFI_STATION_SCAN_RESULT_STR_LEN) {
|
| 1591 | scan_result_str1[scan_result_str_len1 - 1] = '\0'; //È¥µô×îºóÒ»¸ö·ÖºÅ
|
| 1592 | sc_cfg_set ("EX_APLIST1", scan_result_str1);
|
| 1593 | }
|
| 1594 |
|
| 1595 | safe_free (scan_result_str);
|
| 1596 | safe_free (scan_result_str1);
|
| 1597 | }
|
| 1598 |
|
| 1599 |
|
| 1600 | static void ipfail_disconnect_ap()
|
| 1601 | {
|
| 1602 | char cmd[WIFI_STATION_CMD_LEN] = {0};
|
| 1603 | int spot_num = 0;
|
| 1604 | int i = 0;
|
| 1605 |
|
| 1606 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 1607 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 1608 | spot_num = atoi (wifi_profile_num);
|
| 1609 |
|
| 1610 | for (i = 0; i < spot_num; i++) {
|
| 1611 | if (g_spot_list_p[i]->network_id == g_linked_network_id) {
|
| 1612 | wf_log ("[SSID= %s] ip dhcp failed ,will be disabled, and set priority 0", g_spot_list_p[i]->ssid);
|
| 1613 | sprintf (cmd, "DISABLE_NETWORK %d", g_linked_network_id);
|
| 1614 | sta_docmd (cmd);
|
| 1615 |
|
| 1616 | sprintf (cmd, "SET_NETWORK %d priority 0", g_linked_network_id);
|
| 1617 | sta_docmd (cmd);
|
| 1618 | break;
|
| 1619 | }
|
| 1620 | }
|
| 1621 | wifi_station_connect (MODULE_ID_WIFI);
|
| 1622 | // disable cmd will disconnect the ap , and sta_disconnected will deal the process
|
| 1623 | // i guess wpa_supplicant will connect other enabled spot
|
| 1624 |
|
| 1625 | }
|
| 1626 |
|
| 1627 |
|
| 1628 | static void handle_sim_init_status_timer()
|
| 1629 | {
|
| 1630 | char sim_zpbic_status[WIFI_ZPBIC_STATUS_LEN] = {0};
|
| 1631 |
|
| 1632 | if (g_send_count != g_pre_send_count) {
|
| 1633 | wf_log ("g_send_count is %d -----g_pre_send_count is %d", g_send_count, g_pre_send_count);
|
| 1634 | return;
|
| 1635 | }
|
| 1636 | sc_cfg_get ("sim_zpbic_status", sim_zpbic_status, sizeof (sim_zpbic_status));
|
| 1637 | if (strcmp (sim_zpbic_status, SIMCARD_INIT_NO_CARD) == 0) {
|
| 1638 | //ɾ³ýsim init ״̬¶¨Ê±Æ÷
|
| 1639 | wf_log ("sim_zpbic_status is fail");
|
| 1640 | // g_timer_sim_init_undefined_status_count = 0;
|
| 1641 | //sc_timer_delete(WIFI_STATION_TIMER_SIM_CARD_STATUS);
|
| 1642 | wifi_station_connect (MODULE_ID_WIFI);
|
| 1643 |
|
| 1644 | return;
|
| 1645 | } else if (strcmp (sim_zpbic_status, SIMCARD_INIT_UNDEFINED) == 0) {
|
| 1646 | // printf(" handle_sim_init_status_timer in g_timer_sim_init_undefined_status_count is %d", //g_timer_sim_init_undefined_status_count);
|
| 1647 | #if 0
|
| 1648 | if (g_timer_sim_init_undefined_status_count >= 4) {
|
| 1649 | //ɾ³ýsim init ״̬¶¨Ê±Æ÷
|
| 1650 | //printf(" handle_sim_init_status_timer g_timer_sim_init_undefined_status_count is %d", //g_timer_sim_init_undefined_status_count);
|
| 1651 | //g_timer_sim_init_undefined_status_count = 0;
|
| 1652 | sc_timer_delete (WIFI_STATION_TIMER_SIM_CARD_STATUS);
|
| 1653 | wlan_station_msg_handle_ex();
|
| 1654 | return;
|
| 1655 | }
|
| 1656 | //g_timer_sim_init_undefined_status_count++;
|
| 1657 | #endif
|
| 1658 | sc_timer_create (WIFI_STATION_TIMER_SIM_CARD_STATUS,
|
| 1659 | TIMER_FLAG_ONCE, WIFI_STATION_TIMER_SIM_CARD_STATUS_INTERVAL,
|
| 1660 | wifi_station_query_sim_card_status, NULL);
|
| 1661 | } else if (strcmp (sim_zpbic_status, SIMCARD_INIT_SUCCESS) == 0) {
|
| 1662 | wf_log (" success");
|
| 1663 |
|
| 1664 | //wlan_station_msg_handle_connect();
|
| 1665 | wifi_station_connect (MODULE_ID_WIFI);
|
| 1666 | } else {
|
| 1667 | wf_log ("unknow");
|
| 1668 |
|
| 1669 | wifi_station_connect (MODULE_ID_WIFI);
|
| 1670 |
|
| 1671 | }
|
| 1672 | }
|
| 1673 |
|
| 1674 |
|
| 1675 | static void wpa_supplicant_scan (void)
|
| 1676 | {
|
| 1677 | sta_docmd ("SCAN");
|
| 1678 | }
|
| 1679 |
|
| 1680 | static void wpa_supplicant_get_scan_result (vector_t* v)
|
| 1681 | {
|
| 1682 | char *reply = NULL;
|
| 1683 |
|
| 1684 | if (v == NULL) {
|
| 1685 | return;
|
| 1686 | }
|
| 1687 |
|
| 1688 | //»ñȡɨÃè½á¹û
|
| 1689 | wf_log ("wlan-station get_scan_result");
|
| 1690 | // exec_script(WPA_CLI" scan_results", v);
|
| 1691 | reply = sta_docmd ("SCAN_RESULTS");
|
| 1692 |
|
| 1693 | // wf_log("[scan] scan results:\n %s" , reply);
|
| 1694 | convert2vector (reply, v);
|
| 1695 | }
|
| 1696 |
|
| 1697 |
|
| 1698 | static void *wifi_station_query_sim_card_status(void* arg)
|
| 1699 | {
|
| 1700 | //wlan_station_send_message(MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_SIM_INIT_TIMER_PROCESS, 0, NULL);
|
| 1701 | ipc_send_message (MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_SIM_INIT_TIMER_PROCESS, 0, NULL, 0);
|
| 1702 | return NULL;
|
| 1703 | }
|
| 1704 |
|
| 1705 | static void wifi_station_scan (void)
|
| 1706 | {
|
| 1707 | char wifi_sta_connection[WIFI_CONNECTION_LEN] = {0};
|
| 1708 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 1709 |
|
| 1710 | sc_cfg_get ("wifi_sta_connection", wifi_sta_connection, sizeof (wifi_sta_connection));
|
| 1711 |
|
| 1712 |
|
| 1713 | wf_log ("wifi_station_scan");
|
| 1714 | //¹¦ÄܹرÕÔòÖ±½ÓÍ˳ö
|
| 1715 | if (strcmp (wifi_sta_connection, "1") != 0) {
|
| 1716 | return;
|
| 1717 | }
|
| 1718 |
|
| 1719 | //ÕýÔÚÁ¬½Ó״̬ÔòÍ˳ö
|
| 1720 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 1721 | if (strcmp (sta_ip_status, WIFI_STATION_IP_STATUS_CONNECTING) == 0 ||
|
| 1722 | strcmp (sta_ip_status, WIFI_STATION_IP_STATUS_DHCPING) == 0) {
|
| 1723 | wf_log ("sta_ip_status=connecting,set scan_finish=2========");
|
| 1724 | sc_cfg_set ("scan_finish", "2"); //Ä¿µÄÊǸæËßwebui£¬´Ëʱµ×²ãÔÚconnecting
|
| 1725 | return;
|
| 1726 | }
|
| 1727 |
|
| 1728 | //wpa_supplicant½ø³ÌûÆô¶¯ÔòÆô¶¯£¬ÊôÓÚÒì³£±£»¤
|
| 1729 | if (check_supplicant_alive() ==0) {
|
| 1730 | wf_log ("wpa supplicant is not running!xx");
|
| 1731 | sc_cfg_set ("scan_finish", "2"); //Ä¿µÄÊǸæËßwebui£¬´Ëʱµ×²ã³öÎÊÌâÁË
|
| 1732 |
|
| 1733 | return;
|
| 1734 | }
|
| 1735 | // sc_cfg_set("scan_finish", "0");
|
| 1736 |
|
| 1737 | //ɨÃè
|
| 1738 | wpa_supplicant_scan();
|
| 1739 |
|
| 1740 | }
|
| 1741 |
|
| 1742 | static void wifi_station_get_scan_results (void)
|
| 1743 | {
|
| 1744 | vector_t *v = NULL;
|
| 1745 | char wifi_sta_connection[WIFI_CONNECTION_LEN] = {0};
|
| 1746 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 1747 | sc_cfg_get ("wifi_sta_connection", wifi_sta_connection, sizeof (wifi_sta_connection));
|
| 1748 |
|
| 1749 | wf_log ("wifi_station_get_scan_results");
|
| 1750 |
|
| 1751 | //¹¦ÄܹرÕÔòÖ±½ÓÍ˳ö
|
| 1752 | if (strcmp (wifi_sta_connection, "1") != 0) {
|
| 1753 | wf_log ("wifi_sta_connection isn't 1,abormal!!!========");
|
| 1754 | return;
|
| 1755 | }
|
| 1756 |
|
| 1757 | //ÕýÔÚÁ¬½Ó״̬ÔòÍ˳ö
|
| 1758 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 1759 | if (strcmp (sta_ip_status, WIFI_STATION_IP_STATUS_CONNECTING) == 0 ||
|
| 1760 | strcmp (sta_ip_status, WIFI_STATION_IP_STATUS_DHCPING) == 0) {
|
| 1761 | wf_log ("sta_ip_status=connecting,set scan_finish=2========");
|
| 1762 | sc_cfg_set ("scan_finish", "2"); //Ä¿µÄÊǸæËßwebui£¬´Ëʱµ×²ãÔÚconnecting
|
| 1763 | return;
|
| 1764 | }
|
| 1765 |
|
| 1766 | //wpa_supplicant½ø³ÌûÆô¶¯ÔòÆô¶¯£¬ÊôÓÚÒì³£±£»¤
|
| 1767 | if (check_supplicant_alive() ==0) {
|
| 1768 | wf_log ("detect wpa_supplicant isnot running========");
|
| 1769 | sc_cfg_set ("scan_finish", "2"); //Ä¿µÄÊǸæËßwebui£¬´Ëʱµ×²ã³öÎÊÌâÁË
|
| 1770 | return;
|
| 1771 | }
|
| 1772 |
|
| 1773 | v = vector_init();
|
| 1774 | wf_log ("starting scan result");
|
| 1775 |
|
| 1776 | //»ñȡɨÃè½á¹û
|
| 1777 | wpa_supplicant_get_scan_result (v);
|
| 1778 |
|
| 1779 | //´¦ÀíɨÃè½á¹û
|
| 1780 | handle_scan_result (v);
|
| 1781 |
|
| 1782 | sc_cfg_set ("scan_finish", "1");
|
| 1783 |
|
| 1784 | wf_log ("set scan finish 1");
|
| 1785 |
|
| 1786 | vector_free (v);
|
| 1787 | }
|
| 1788 |
|
| 1789 | static void wifi_station_open_apsta(void)
|
| 1790 | {
|
| 1791 | wf_log ("restart apsta");
|
| 1792 | basic_deal_all (WIFI_CFG_RESTART_APSTATION); //ÐèÒª½«µ¥¶ÀAPģʽÇл»Îªapsta ģʽ
|
| 1793 | }
|
| 1794 |
|
| 1795 | static void sta_enable_all_networks (void)
|
| 1796 | {
|
| 1797 | wf_log (" webui_select_network= %d, g_disable_other_network=%d ",
|
| 1798 | webui_select_network, g_disable_other_network);
|
| 1799 |
|
| 1800 | #if 0
|
| 1801 | // µ¥¶À´¦Àíwebui ÔÚÁ´½Ó״̬£¬Ñ¡ÔñÆäËûÈÈµã½øÐÐÁ´½ÓÇé¿ö
|
| 1802 | if (webui_select_network == 1) {
|
| 1803 | webui_select_network = 0; // ½ö½öΪÁ˱ÜÃâselectÃüÁîÒýÆðµÄÉϸöÈȵãµÄ¶Ï¿ªÊ¼þ
|
| 1804 | return;
|
| 1805 | }
|
| 1806 | #endif
|
| 1807 |
|
| 1808 | if (g_disable_other_network == 1) {
|
| 1809 | sc_cfg_set ("sta_ip_status", WIFI_STATION_IP_STATUS_CONNECTING);
|
| 1810 | sta_docmd ("ENABLE_NETWORK all");
|
| 1811 | // reconnect , willl connect last one ???
|
| 1812 | sta_docmd ("RECONNECT");
|
| 1813 | //has_exec_select_network =0;
|
| 1814 | g_disable_other_network = 0; // select will disable others networks, so enable all , then reset it
|
| 1815 | }
|
| 1816 | }
|
| 1817 |
|
| 1818 | static void sta_disconnected (void)
|
| 1819 | {
|
| 1820 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 1821 |
|
| 1822 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 1823 |
|
| 1824 | if (strcmp (sta_ip_status, "disconnect") != 0) { // ÓпÉÄÜÊǹرÕapsta£¬ÒѾ×öÁËdeinit£¬ËùÒÔÏÂÃæÁ÷³Ì¾Í²»ÐèÒªÁË
|
| 1825 | write_status (STASTATUS, "F"); //F ±íʾ ¶Ï¿ª×´Ì¬£¬0~4 ±íʾÐźÅÇ¿¶È 5¸ö¼¶±ð
|
| 1826 | //¸üÐÂEX_APLISTÖеÄÁ¬½Ó״̬Ϊ0
|
| 1827 | update_EX_APLIST_connect_status (FALSE);
|
| 1828 | //¸üÐÂÈȵãÁбíÖжÔÓ¦ÈȵãµÄÁ¬½Ó״̬Ϊfalse
|
| 1829 | update_spot_connect_status_by_status_result (FALSE);
|
| 1830 |
|
| 1831 | network_down_up (FALSE);
|
| 1832 |
|
| 1833 | g_linked_network_id_last = g_linked_network_id;
|
| 1834 |
|
| 1835 | if (0 ==webui_select_network) {
|
| 1836 | sc_cfg_set ("sta_ip_status", WIFI_STATION_IP_STATUS_DISCONNECT);
|
| 1837 | }else if(1 == webui_select_network){
|
| 1838 | sc_cfg_set ("sta_ip_status", WIFI_STATION_IP_STATUS_CONNECTING);
|
| 1839 | webui_select_network =0;
|
| 1840 | }
|
| 1841 |
|
| 1842 | }
|
| 1843 | }
|
| 1844 |
|
| 1845 | static void sta_disconnect (void)
|
| 1846 | {
|
| 1847 | int i = 0;
|
| 1848 | int network_id = -1;
|
| 1849 | char cmd[WIFI_STATION_CMD_LEN] = {0};
|
| 1850 | int spot_num = 0;
|
| 1851 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 1852 |
|
| 1853 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 1854 | spot_num = atoi (wifi_profile_num);
|
| 1855 |
|
| 1856 | dump_spot();
|
| 1857 | for (i = 0; i < spot_num; i++) {
|
| 1858 | if (NULL != g_spot_list_p[i] && g_spot_list_p[i]->connect_status == 1) {
|
| 1859 | network_id = g_spot_list_p[i]->network_id;
|
| 1860 | break;
|
| 1861 | }
|
| 1862 | }
|
| 1863 |
|
| 1864 | if (network_id != -1) {
|
| 1865 | sprintf (cmd, "DISCONNECT");
|
| 1866 | sta_docmd (cmd);
|
| 1867 | has_exec_disconnect = 1;
|
| 1868 | // sprintf(cmd, "DISABLE_NETWORK %d", network_id);
|
| 1869 | // sta_docmd(cmd);
|
| 1870 | } else {
|
| 1871 | wf_log ("All SSID AP already disconnect, do not disconnect again");
|
| 1872 | }
|
| 1873 | }
|
| 1874 |
|
| 1875 | static void sta_connect (int network_id)
|
| 1876 | {
|
| 1877 | int i = 0;
|
| 1878 | // int network_id = -1;
|
| 1879 | char cmd[WIFI_STATION_CMD_LEN] = {0};
|
| 1880 | int spot_num = 0;
|
| 1881 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 1882 | char ssid[WIFI_STATION_SSID_LEN] = {0};
|
| 1883 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 1884 | char manual_d_wifi[8] = {0};
|
| 1885 | char blc_wan_mode[32] = {0};
|
| 1886 |
|
| 1887 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 1888 | spot_num = atoi (wifi_profile_num);
|
| 1889 |
|
| 1890 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 1891 | sc_cfg_get ("manual_d_wifi", manual_d_wifi, sizeof (manual_d_wifi));
|
| 1892 | sc_cfg_get ("blc_wan_mode", blc_wan_mode, sizeof (blc_wan_mode));
|
| 1893 |
|
| 1894 | if ((strcmp (manual_d_wifi, "1") == 0) || (strcmp ("PPPOE", blc_wan_mode) == 0)) {
|
| 1895 | wf_log ("connect failed manual_d_wifi=%s,blc_wan_mode=%s",
|
| 1896 | manual_d_wifi, blc_wan_mode);
|
| 1897 | return;
|
| 1898 | }
|
| 1899 |
|
| 1900 | if (network_id == INVALID_NETWORK_ID) {
|
| 1901 | // set sta_ip_status, for webui
|
| 1902 | sc_cfg_get ("EX_SSID1", ssid, WIFI_STATION_SSID_LEN);
|
| 1903 | // sc_cfg_get("EX_mac", mac, WIFI_STATION_MAC_LEN);
|
| 1904 |
|
| 1905 | for (i = 0; i < spot_num; i++) {
|
| 1906 | wf_log ("g_spot_list_p[%d] = 0x%p", i , g_spot_list_p[i]);//cov m
|
| 1907 | if (g_spot_list_p[i] != NULL && !strcmp (g_spot_list_p[i]->ssid, ssid)) {
|
| 1908 |
|
| 1909 | //protect not to connect twice
|
| 1910 | if(1 == g_spot_list_p[i]->connect_status ){
|
| 1911 | wf_log ("[%s] is connect ,do not need connect again,[sta_ip_status=%s]", ssid, sta_ip_status);
|
| 1912 | return;
|
| 1913 | }
|
| 1914 | network_id = g_spot_list_p[i]->network_id;
|
| 1915 | //select¶¯×÷»áÒýÆðÁ¬×ŵÄÈȵã¶Ï¿ª£¬¶Ï¿ªÊ±ºòÒª¼Ç¼´Ë¶¯×÷£¬²»ÐèÒªÔÙÈ¥enable all
|
| 1916 | if (strcmp (sta_ip_status, WIFI_STATION_IP_STATUS_CONNECT) == 0 )
|
| 1917 | webui_select_network = 1;
|
| 1918 | break;
|
| 1919 | }
|
| 1920 | }
|
| 1921 | }
|
| 1922 |
|
| 1923 | if (network_id == -1) {
|
| 1924 | wf_log ("got the wrong network id");
|
| 1925 | sc_cfg_set ("sta_ip_status", WIFI_STATION_IP_STATUS_DISCONNECT);
|
| 1926 | return;
|
| 1927 | } else {
|
| 1928 | // if(strcmp(sta_ip_status, WIFI_STATION_IP_STATUS_DISCONNECT) != 0)
|
| 1929 | {
|
| 1930 | sprintf (cmd, "SELECT_NETWORK %d", network_id);
|
| 1931 | sta_docmd (cmd);
|
| 1932 | g_disable_other_network = 1;
|
| 1933 | }
|
| 1934 | sprintf (cmd, "ENABLE_NETWORK %d", network_id);
|
| 1935 | sta_docmd (cmd);
|
| 1936 |
|
| 1937 | sta_docmd ("SAVE_CONFIG");
|
| 1938 |
|
| 1939 | #if 0
|
| 1940 | if (has_exec_disconnect == 1) {
|
| 1941 | sta_docmd ("RECONNECT");
|
| 1942 | has_exec_disconnect = 0; // reconnect will reset has_exec_disconnect
|
| 1943 | }
|
| 1944 | #endif
|
| 1945 | }
|
| 1946 |
|
| 1947 | // Create_connect_timeout_timer(); //´´½¨Á¬½Ó³¬Ê±¶¨Ê±Æ÷
|
| 1948 | }
|
| 1949 |
|
| 1950 | static void do_dhcp (void)
|
| 1951 | {
|
| 1952 | //Á¬½Ó³É¹¦£¬µ÷ÍøÂç×é½Ó¿Ú½øÐÐDHCPÁ÷³Ì·ÖÅäIPµØÖ·
|
| 1953 | network_down_up (TRUE);
|
| 1954 | }
|
| 1955 |
|
| 1956 | /*
|
| 1957 |
|
| 1958 | µ±¶Ï¿ªÊ±ºò£¬¸üÐÂÈȵãÁ´½Ó״̬£¬g_linked_network_id »¹ÊǼǼµÄÁ´½ÓµÄÈȵã
|
| 1959 |
|
| 1960 | sta_ip_status ¼Ç¼µÄ״̬»¹ÊÇconnect ״̬
|
| 1961 | */
|
| 1962 | static int find_linked_ap_index(void)
|
| 1963 | {
|
| 1964 | int spot_num = 0;
|
| 1965 | int i = 0;
|
| 1966 |
|
| 1967 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 1968 |
|
| 1969 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 1970 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 1971 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 1972 |
|
| 1973 | spot_num = atoi (wifi_profile_num);
|
| 1974 |
|
| 1975 | if (-1 == g_linked_network_id) return -1;
|
| 1976 |
|
| 1977 | for (i = 0; i < spot_num; i++) {
|
| 1978 | if (g_spot_list_p[i]->network_id == g_linked_network_id) {
|
| 1979 | wf_log ("find_linked_ap_index = %d", i); // Ò»°ã ¶¼ÊÇ0£¬µ±ÓÐÔËÓªÉÌÈȵãʱºò¿ÉÄܲ»ÊÇ0
|
| 1980 | return i;
|
| 1981 | }
|
| 1982 | }
|
| 1983 |
|
| 1984 | return -1;
|
| 1985 |
|
| 1986 | }
|
| 1987 |
|
| 1988 | static void disable_network (char * ssid)
|
| 1989 | {
|
| 1990 | char cmd[WIFI_STATION_CMD_LEN] = {0};
|
| 1991 | int spot_num = 0;
|
| 1992 | int i = 0;
|
| 1993 |
|
| 1994 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 1995 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 1996 |
|
| 1997 | spot_num = atoi (wifi_profile_num);
|
| 1998 |
|
| 1999 | for (i = 0; i < spot_num; i++) {
|
| 2000 | if (strcmp (g_spot_list_p[i]->ssid, ssid) == 0) {
|
| 2001 | if (-1 != g_spot_list_p[i]->network_id) {
|
| 2002 | sprintf (cmd, "DISABLE_NETWORK %d", g_spot_list_p[i]->network_id);
|
| 2003 | sta_docmd (cmd);
|
| 2004 | sta_docmd ("SAVE_CONFIG");
|
| 2005 | break;
|
| 2006 | } else {
|
| 2007 | wf_log ("Error !! ssid =%s, networkid = %d\n ", g_spot_list_p[i]->ssid, g_spot_list_p[i]->network_id);
|
| 2008 | }
|
| 2009 | }
|
| 2010 | }
|
| 2011 | }
|
| 2012 |
|
| 2013 | static void update_current_EX (char * ssid, char * mac)
|
| 2014 | {
|
| 2015 | char buf[WIFI_STATION_SPOT_KEY_ID_LEN] = {0};
|
| 2016 | int spot_num = 0;
|
| 2017 | int i = 0;
|
| 2018 |
|
| 2019 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 2020 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 2021 |
|
| 2022 | spot_num = atoi (wifi_profile_num);
|
| 2023 |
|
| 2024 | for (i = 0; i < spot_num; i++) {
|
| 2025 | if (strcmp (g_spot_list_p[i]->ssid, ssid) == 0) {
|
| 2026 | sc_cfg_set ("EX_wifi_profile", g_spot_list_p[i]->profile_name);
|
| 2027 | sc_cfg_set ("EX_SSID1", ssid);
|
| 2028 | sc_cfg_set ("EX_AuthMode", g_spot_list_p[i]->auth_mode);
|
| 2029 | sc_cfg_set ("EX_EncrypType", g_spot_list_p[i]->encrypt_type);
|
| 2030 |
|
| 2031 | sprintf (buf, "%d", g_spot_list_p[i]->keyID);
|
| 2032 | sc_cfg_set ("EX_DefaultKeyID", buf);
|
| 2033 |
|
| 2034 | sc_cfg_set ("EX_WPAPSK1", g_spot_list_p[i]->password);
|
| 2035 | sc_cfg_set ("EX_WEPKEY", g_spot_list_p[i]->password);
|
| 2036 | sc_cfg_set ("EX_mac", mac);
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame^] | 2037 | #ifdef USE_CAP_SUPPORT
|
| 2038 | memset(buf, 0, sizeof(buf));
|
| 2039 | snprintf(buf, sizeof(buf), "%d", g_spot_list_p[i]->signal);
|
| 2040 | sc_cfg_set ("EX_signal", buf);
|
| 2041 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2042 | break;
|
| 2043 | }
|
| 2044 | }
|
| 2045 | }
|
| 2046 |
|
| 2047 | static void disable_other_network (int network_id)
|
| 2048 | {
|
| 2049 |
|
| 2050 | char cmd[WIFI_STATION_CMD_LEN] = {0};
|
| 2051 | int spot_num = 0;
|
| 2052 | int i = 0;
|
| 2053 |
|
| 2054 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 2055 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 2056 |
|
| 2057 | spot_num = atoi (wifi_profile_num);
|
| 2058 | if (spot_num > WIFI_STATION_SPOT_LIST_NUM || spot_num < 0)
|
| 2059 | return;
|
| 2060 |
|
| 2061 | for (i = 0; i < spot_num; i++) {
|
| 2062 | if (g_spot_list_p[i]->network_id == network_id) {
|
| 2063 | continue;
|
| 2064 | }
|
| 2065 |
|
| 2066 | sprintf (cmd, "DISABLE_NETWORK %d", g_spot_list_p[i]->network_id);
|
| 2067 | sta_docmd (cmd);
|
| 2068 | }
|
| 2069 |
|
| 2070 | g_disable_other_network = 1;
|
| 2071 |
|
| 2072 | }
|
| 2073 |
|
| 2074 | static void sta_connected()
|
| 2075 | {
|
| 2076 | char cmd[WIFI_STATION_CMD_LEN] = {0};
|
| 2077 |
|
| 2078 | write_status (STASTATUS, "4"); //F ±íʾ ¶Ï¿ª×´Ì¬£¬0~4 ±íʾÐźÅÇ¿¶È 5¸ö¼¶±ð ÔÝʱÐźÅдÂú¸ñ
|
| 2079 |
|
| 2080 | //¸üÐÂÈȵãÁбíÖжÔÓ¦ÈȵãµÄÁ¬½Ó״̬Ϊtrue
|
| 2081 | update_spot_connect_status_by_status_result (TRUE);
|
| 2082 |
|
| 2083 | //¸üÐÂËùÓÐÈȵãÁбíÖеÄis_tried_connectΪfalse
|
| 2084 | //update_spot_list_is_tried_connect(FALSE);
|
| 2085 |
|
| 2086 | resort_spot_list();
|
| 2087 |
|
| 2088 | //¸üÐÂEX_APLISTÖеÄÁ¬½Ó״̬Ϊ1
|
| 2089 | update_EX_APLIST_connect_status (TRUE);
|
| 2090 |
|
| 2091 | // set the success AP to EX_SSID1
|
| 2092 | // update_current_EX();
|
| 2093 |
|
| 2094 | sc_cfg_set ("sta_ip_status", WIFI_STATION_IP_STATUS_CONNECT);
|
| 2095 | // Delete_connect_timeout_timer();
|
| 2096 |
|
| 2097 | wf_log ("g_linked_network_id_last = %d, g_linked_network_id= %d", g_linked_network_id_last, g_linked_network_id);
|
| 2098 |
|
| 2099 | // ²»ÊÇÎÞЧid£¬ÇÒÉÏÒ»¸öÁ´½ÓµÄºÍÕâ´ÎÁ´½ÓµÄ²»ÊÇͬһ¸öÈȵã
|
| 2100 | if (g_linked_network_id_last != -1 && g_linked_network_id_last != g_linked_network_id) { // thr first time, there's no the last id
|
| 2101 | sprintf (cmd, "SET_NETWORK %d priority 2", g_linked_network_id_last);
|
| 2102 | sta_docmd (cmd);
|
| 2103 | }
|
| 2104 | sprintf (cmd, "SET_NETWORK %d priority 3", g_linked_network_id);
|
| 2105 | sta_docmd (cmd);
|
| 2106 |
|
| 2107 | wf_log ("g_disable_other_network= %d", g_disable_other_network);
|
| 2108 |
|
| 2109 | //Èç¹û²»ÊÇselect ÃüÁîÖ®ºóÍê³ÉµÄÁ´½Ó£¬¾Í²»»ádisableÆäËûÈȵ㣬Ӧ¸ÃÊÇwpa_supplicant ÔÚenable allºó×ÔÐÐÑ¡ÔñÈÈµã½øÐÐÁ´½Ó
|
| 2110 | if (g_disable_other_network == 0) {
|
| 2111 | disable_other_network (g_linked_network_id);
|
| 2112 | // g_disable_other_network =1;
|
| 2113 | }
|
| 2114 |
|
| 2115 | sta_docmd ("SAVE_CONFIG");
|
| 2116 |
|
| 2117 | }
|
| 2118 |
|
| 2119 | static void update_eapsim_spot(void)
|
| 2120 | {
|
| 2121 | int i = 0;
|
| 2122 | int spot_num = 0;
|
| 2123 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 2124 | char cmd[WIFI_STATION_CMD_LEN] = {0};
|
| 2125 |
|
| 2126 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 2127 | spot_num = atoi (wifi_profile_num);
|
| 2128 | if (spot_num > WIFI_STATION_SPOT_LIST_NUM || spot_num < 0)
|
| 2129 | return;
|
| 2130 |
|
| 2131 | for (i = 0; i < spot_num; i++) {
|
| 2132 | if (strstr (g_spot_list_p[i]->auth_mode, WIFI_STATION_PROFILE_AUTH_WPA_EAP)) { //|| strstr(auth_mode, WIFI_STATION_PROFILE_AUTH_WPA2_EAP))
|
| 2133 | if (g_cardmode == CARD_MODE_USIM) {
|
| 2134 | sprintf (cmd, "SET_NETWORK %d eap AKA", g_spot_list_p[i]->network_id);
|
| 2135 | sta_docmd (cmd);
|
| 2136 | } else {
|
| 2137 | sprintf (cmd, " SET_NETWORK %d eap SIM", g_spot_list_p[i]->network_id);
|
| 2138 | sta_docmd (cmd);
|
| 2139 | }
|
| 2140 | }
|
| 2141 | }
|
| 2142 | }
|
| 2143 |
|
| 2144 | /*
|
| 2145 | * just enable all networks let supplicant to connect automaticly
|
| 2146 | */
|
| 2147 | static int wifi_station_connect (int from_where)
|
| 2148 | {
|
| 2149 | char wifi_profile_num[8] = {0};
|
| 2150 | char manual_d_wifi[8] = {0};
|
| 2151 | char wifi_cur_state[8] = {0};
|
| 2152 | char blc_wan_mode[16] = {0};
|
| 2153 |
|
| 2154 | wf_log ("enter from %d blc_close_apsta= %d", from_where, g_blc_send_close_apsta);
|
| 2155 |
|
| 2156 | if (g_blc_send_close_apsta == 1) {
|
| 2157 | wf_log ("blc send close wifi,so only blc can open wifi again.");
|
| 2158 | return -1;
|
| 2159 | }
|
| 2160 |
|
| 2161 | //Èç¹ûûÓпÉÒÔÓõÄÈȵ㣬ֱ½Ó·µ»ØÊ§°Ü
|
| 2162 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 2163 | sc_cfg_get ("manual_d_wifi", manual_d_wifi, sizeof (manual_d_wifi));
|
| 2164 | sc_cfg_get ("blc_wan_mode", blc_wan_mode, sizeof (blc_wan_mode));
|
| 2165 | sc_cfg_get ("wifi_cur_state", wifi_cur_state, sizeof (wifi_cur_state));
|
| 2166 |
|
| 2167 | //ÊÖ¶¯¶Ï¿ªwifi£¬¼´Ê¹Ö÷¿ØÔÙÈÃÁ¬½Ó£¬Ò²²»»áÔÙÁ¬½ÓÁË
|
| 2168 | if ( (strcmp (wifi_cur_state, WIFI_CLOSED) == 0) || (strcmp (wifi_profile_num, "0") == 0)
|
| 2169 | || (strcmp (manual_d_wifi, "1") == 0) || (strcmp ("PPPOE", blc_wan_mode) == 0)) {
|
| 2170 | wf_log ("connect failed wifi_cur_state=%s, wifi_profile_num=%s,manual_d_wifi=%s,blc_wan_mode=%s",
|
| 2171 | wifi_cur_state, wifi_profile_num, manual_d_wifi, blc_wan_mode);
|
| 2172 | return -1;
|
| 2173 | }
|
| 2174 |
|
| 2175 | sta_enable_all_networks();
|
| 2176 | // Create_connect_timeout_timer(); //´´½¨Á¬½Ó³¬Ê±¶¨Ê±Æ÷
|
| 2177 | return 0;
|
| 2178 | }
|
| 2179 |
|
| 2180 | static void wifi_station_nv_init (void)
|
| 2181 | {
|
| 2182 | sc_cfg_set ("sta_ip_status", WIFI_STATION_IP_STATUS_DISCONNECT);
|
| 2183 | sc_cfg_set ("scan_finish", "0");
|
| 2184 | //sc_cfg_set("EX_APLIST", "");
|
| 2185 | //sc_cfg_set("EX_APLIST1", "");
|
| 2186 | sc_cfg_set ("manual_d_wifi", "0");
|
| 2187 |
|
| 2188 | memset (g_linked_ap_mac, 0, WIFI_STATION_MAC_LEN);
|
| 2189 | g_linked_network_id = -1;
|
| 2190 | g_linked_network_id_last = -1;
|
| 2191 |
|
| 2192 | has_exec_disconnect = 0;
|
| 2193 | webui_select_network = 0;
|
| 2194 | g_disable_other_network = 1;
|
| 2195 |
|
| 2196 | get_spot_list();
|
| 2197 | sync_nv_spot_list_conf_file();
|
| 2198 | update_spot_list_signal_connect_status (0, 0);
|
| 2199 | save_spot_list();
|
| 2200 | }
|
| 2201 |
|
| 2202 | static int exist_eap_simaka_spot()
|
| 2203 | {
|
| 2204 | int i = 0;
|
| 2205 | int spot_num = 0;
|
| 2206 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 2207 |
|
| 2208 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 2209 | spot_num = atoi (wifi_profile_num);
|
| 2210 |
|
| 2211 | for (i = 0; i < spot_num; i++) {
|
| 2212 | if (strstr (g_spot_list_p[i]->auth_mode, WIFI_STATION_PROFILE_AUTH_WPA_EAP)) //|| strstr(auth_mode, WIFI_STATION_PROFILE_AUTH_WPA2_EAP))
|
| 2213 | return g_spot_list_p[i]->network_id;
|
| 2214 | }
|
| 2215 | return -1;
|
| 2216 | }
|
| 2217 |
|
| 2218 |
|
| 2219 | void wlan_station_init (void)
|
| 2220 | {
|
| 2221 | if(1 == g_wpa_supplicant)return ;
|
| 2222 |
|
| 2223 | wf_log ("time=%d", time(NULL));
|
| 2224 | if (sta_manager->start_supplicant(sta_manager) == 0) {
|
| 2225 | wf_log ("time=%d", time(NULL));
|
| 2226 | wf_log (" wpa_supplicant run success");
|
| 2227 |
|
| 2228 | if (0 == wifi_connect_to_supplicant(&sta_manager->sock)) {
|
| 2229 | wf_log (" socket connect success");
|
| 2230 | sem_post (&g_wpa_supplicant_id);
|
| 2231 | g_wpa_supplicant = 1;
|
| 2232 | } else {
|
| 2233 | wlan_station_deinit();
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame^] | 2234 | #ifdef USE_CAP_SUPPORT
|
| 2235 | send_sta_status_to_cap(IN_WIFI_STA_STATUS_ERROR, IN_WIFI_REASON_CODE_NONE);
|
| 2236 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2237 | return;
|
| 2238 | }
|
| 2239 | }else {
|
| 2240 | wf_log ("wpa_supplicant start failed");
|
| 2241 | wlan_station_deinit();
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame^] | 2242 | #ifdef USE_CAP_SUPPORT
|
| 2243 | send_sta_status_to_cap(IN_WIFI_STA_STATUS_ERROR, IN_WIFI_REASON_CODE_NONE);
|
| 2244 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2245 | return;
|
| 2246 | }
|
| 2247 |
|
| 2248 |
|
| 2249 | wifi_station_nv_init();
|
| 2250 | sta_docmd ("SCAN_INTERVAL 15");
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame^] | 2251 |
|
| 2252 | #ifdef USE_CAP_SUPPORT
|
| 2253 | send_sta_status_to_cap(IN_WIFI_STA_STATUS_IDLE, IN_WIFI_REASON_CODE_NONE);
|
| 2254 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2255 |
|
| 2256 | //Èç¹ûÓÐEAP-SIMÈȵ㣬ÔòÐèÒªÏÈ×߸òéѯSIM¿¨ÐÅÏ¢Á÷³Ì
|
| 2257 |
|
| 2258 | if (-1 != exist_eap_simaka_spot()) { // ²»ÊÇ-1£¬ Ôò´æÔÚsimaka spot
|
| 2259 | //eap send msg for card type
|
| 2260 | /*if((0 == strcmp(ssid, "CMCC-SIM-test1")) || (0 == strcmp(ssid, "CMCC-SIM-test2")))
|
| 2261 | {
|
| 2262 | strcpy(auth_mode, WIFI_STATION_PROFILE_AUTH_WPA_EAP);
|
| 2263 | }*/
|
| 2264 |
|
| 2265 | //if(0 == wlan_station_send_message(ZUFI_MODULE_ID_AT_MAIN, MODULE_ID_CARD_MODE_REQ, 0, NULL))
|
| 2266 | if (0 == ipc_send_message (MODULE_ID_WIFI, MODULE_ID_AT_CTL, MSG_CMD_CARD_MODE_REQ, 0, NULL, 0)) {
|
| 2267 | //·¢ËÍ ²éѯ¿¨Ä£Ê½ÏûÏ¢£¬µÈ´ýÒì²½·µ»Ø
|
| 2268 | g_pre_send_count = g_send_count;
|
| 2269 | return;
|
| 2270 | } else {
|
| 2271 | wifi_station_connect (MODULE_ID_WIFI);
|
| 2272 | }
|
| 2273 | } else {
|
| 2274 | wifi_station_connect (MODULE_ID_WIFI);
|
| 2275 | }
|
| 2276 | }
|
| 2277 |
|
| 2278 | static void clear_conf_file(void)
|
| 2279 | {
|
| 2280 | sta_docmd ("REMOVE_NETWORK all");
|
| 2281 | sta_docmd ("SAVE_CONFIG");
|
| 2282 | }
|
| 2283 |
|
| 2284 | static void clear_spot_list(void)
|
| 2285 | {
|
| 2286 | int i = 0;
|
| 2287 | wf_log ("[clear_spot_list]");
|
| 2288 |
|
| 2289 | for (i = 0; i < WIFI_STATION_SPOT_LIST_NUM; i++) {
|
| 2290 | if (g_spot_list_p[i] != NULL) {
|
| 2291 | safe_free (g_spot_list_p[i]);
|
| 2292 | }
|
| 2293 |
|
| 2294 | }
|
| 2295 |
|
| 2296 | }
|
| 2297 | static void wlan_station_deinit(void)
|
| 2298 | {
|
| 2299 | int count = 50;
|
| 2300 |
|
| 2301 | wf_log ("enter");
|
| 2302 |
|
| 2303 | sta_docmd ("DISABLE_NETWORK all");
|
| 2304 | sta_docmd ("SAVE_CONFIG");
|
| 2305 | #if !defined(__REALTEK_8192_CHIP__)
|
| 2306 | sta_docmd ("TERMINATE");
|
| 2307 | usleep (150000);
|
| 2308 |
|
| 2309 | while (count-- > 0) {
|
| 2310 | if (check_alive(&sta_manager->sock) == 0) {
|
| 2311 | wf_log ("TERMINATE over\n");
|
| 2312 | break;
|
| 2313 | }
|
| 2314 | usleep (100000);
|
| 2315 | }
|
| 2316 | #endif
|
| 2317 |
|
| 2318 | g_disable_other_network = 1;
|
| 2319 | sta_manager->close_connection(sta_manager);
|
| 2320 |
|
| 2321 | g_wpa_supplicant = 0;
|
| 2322 |
|
| 2323 | clear_spot_list();
|
| 2324 | memset (g_linked_ap_mac, 0, WIFI_STATION_MAC_LEN);
|
| 2325 | g_linked_network_id = -1;
|
| 2326 | g_linked_network_id_last = -1;
|
| 2327 | has_exec_disconnect = 0;
|
| 2328 | webui_select_network = 0;
|
| 2329 | sc_cfg_set ("scan_finish", "0");
|
| 2330 | sc_cfg_set ("EX_APLIST", "");
|
| 2331 | sc_cfg_set ("EX_APLIST1", "");
|
| 2332 |
|
| 2333 | sc_cfg_set ("sta_ip_status", WIFI_STATION_IP_STATUS_DISCONNECT);
|
| 2334 |
|
| 2335 | }
|
| 2336 |
|
| 2337 |
|
| 2338 | void wifi_station_close()
|
| 2339 | {
|
| 2340 | sta_disconnected();
|
| 2341 | wlan_station_deinit();
|
| 2342 | }
|
| 2343 |
|
| 2344 |
|
| 2345 | BOOL wlan_station_is_station_msg (unsigned short msg)
|
| 2346 | {
|
| 2347 | if (msg >= MSG_CMD_WIFI_STATION_OPEN && msg <= MSG_CMD_WIFI_STATION_END) {
|
| 2348 | return TRUE;
|
| 2349 | } else if(msg == MSG_CMD_NET_WAN_DIAL_FAIL ||
|
| 2350 | msg == MSG_CMD_CARD_MODE_RSP ||
|
| 2351 | msg == MSG_CMD_PIN_STATUS_RSP){
|
| 2352 | return TRUE;
|
| 2353 | }
|
| 2354 | else{
|
| 2355 | return FALSE;
|
| 2356 | }
|
| 2357 | }
|
| 2358 |
|
| 2359 | static void wlan_station_msg_handle_card_mode_for_eap (MSG_BUF *pMsg)
|
| 2360 | {
|
| 2361 | #if 0
|
| 2362 | spot_t *p = NULL;
|
| 2363 | char profile_name[WIFI_STATION_SPOT_PROFILE_NAME_LEN] = {0};
|
| 2364 | char *ssid = NULL;
|
| 2365 | char auth_mode[WIFI_STATION_AUTH_MODE_LEN] = {0};
|
| 2366 | char encrypt_type[WIFI_STATION_ENCRYPT_TYPE_LEN] = {0};
|
| 2367 | char *password_wpa = NULL;
|
| 2368 | char *password_wep = NULL;
|
| 2369 | #endif
|
| 2370 | char cardmodestr[WIFI_CARD_MODE_LEN+1] = {0};
|
| 2371 | int cardmode = 0;
|
| 2372 |
|
| 2373 | if (g_send_count != g_pre_send_count) {
|
| 2374 | wf_log ("------------wlan_station_msg_handle_card_mode-----g_send_count is %d -----g_pre_send_count is %d", g_send_count, g_pre_send_count);
|
| 2375 | return;
|
| 2376 | }
|
| 2377 | wf_log ("------------wlan_station_msg_handle_card_mode------------++++++++++++++++++++++++++++++");
|
| 2378 | if (pMsg != NULL) {
|
| 2379 | //kw 3
|
| 2380 | memcpy (cardmodestr, pMsg->aucDataBuf, WIFI_CARD_MODE_LEN);
|
| 2381 |
|
| 2382 | wf_log ("------------wlan_station_msg_handle_card_mode--------333----++++++++++++++++++++++++++++++");
|
| 2383 | cardmode = atoi (cardmodestr);
|
| 2384 | wf_log ("------------wlan_station_msg_handle_card_mode--------cardmode is %d----++++++++++++++++++++++++++++++", cardmode);
|
| 2385 | if (cardmode < 0 || cardmode > INT_MAX-1) //kw 3, cardmode 0-2
|
| 2386 | cardmode = 0;
|
| 2387 | }
|
| 2388 |
|
| 2389 | g_cardmode = cardmode;
|
| 2390 |
|
| 2391 | if (cardmode != CARD_MODE_USIM && cardmode != CARD_MODE_SIM) {
|
| 2392 | wifi_station_connect (MODULE_ID_WIFI);
|
| 2393 | } else {
|
| 2394 | //eap send msg for pin status
|
| 2395 | if (0 == ipc_send_message (MODULE_ID_WIFI, MODULE_ID_AT_CTL, MSG_CMD_PIN_STATUS_REQ, 0, NULL, 0)) {
|
| 2396 | wf_log ("------------ipc_send_message-------MSG_CMD_PIN_STATUSREQ-----++++++++++++++++++++++++++++++");
|
| 2397 | g_pre_send_count = g_send_count;
|
| 2398 | return;
|
| 2399 | } else {
|
| 2400 | wf_log ("------------ipc_send_message-------MODULE_ID_PIN_STATUS_REQ--ex---++++++++++++++++++++++++++++++");
|
| 2401 | wifi_station_connect (MODULE_ID_WIFI);
|
| 2402 |
|
| 2403 | }
|
| 2404 |
|
| 2405 | //wlan_station_msg_handle_connect();
|
| 2406 | }
|
| 2407 | }
|
| 2408 |
|
| 2409 | static void wlan_station_msg_handle_pin_status_for_eap (MSG_BUF *pMsg)
|
| 2410 | {
|
| 2411 | char pinstatusstr[WIFI_PIN_STATUS_LEN+1] = {0};
|
| 2412 | int pinstatus = 0;
|
| 2413 | char sim_zpbic_status[WIFI_ZPBIC_STATUS_LEN] = {0};
|
| 2414 |
|
| 2415 | if (g_send_count != g_pre_send_count) {
|
| 2416 | wf_log ("------------wlan_station_msg_handle_pin_status_for_eap-----g_send_count is %d -----g_pre_send_count is %d", g_send_count, g_pre_send_count);
|
| 2417 | return;
|
| 2418 | }
|
| 2419 | wf_log ("------------wlan_station_msg_handle_pin_status_for_eap------------++++++++++++++++++++++++++++++");
|
| 2420 | if (pMsg != NULL) {
|
| 2421 | //kw 3
|
| 2422 | memcpy (pinstatusstr, pMsg->aucDataBuf, WIFI_PIN_STATUS_LEN);
|
| 2423 |
|
| 2424 | pinstatus = atoi (pinstatusstr);
|
| 2425 |
|
| 2426 | if (PIN_STATUS_NO_PIN != pinstatus) {
|
| 2427 | wifi_station_connect (MODULE_ID_WIFI);
|
| 2428 |
|
| 2429 | } else {
|
| 2430 | //Ôö¼Ó¶Ô¿¨³õʼ»¯ÊÇ·ñÍê³ÉµÄÅжÏ
|
| 2431 | sc_cfg_get ("sim_zpbic_status", sim_zpbic_status, sizeof (sim_zpbic_status));
|
| 2432 | if (0 == strcmp (sim_zpbic_status, SIMCARD_INIT_SUCCESS)) {
|
| 2433 | wf_log ("--------------------sim_zpbic_status-----SIMCARD_INIT_SUCCESS ++++++++++++++-------------");
|
| 2434 | update_eapsim_spot();
|
| 2435 | // wlan_station_msg_handle_connect();
|
| 2436 | wifi_station_connect (MODULE_ID_WIFI);
|
| 2437 | } else if (0 == strcmp (sim_zpbic_status, SIMCARD_INIT_UNDEFINED)) {
|
| 2438 | wf_log ("--------------------sim_zpbic_status-----SIMCARD_INIT_UNDEFINED ++++++++++++++-------------");
|
| 2439 | //g_timer_sim_init_undefined_status_count = 0;
|
| 2440 | g_pre_send_count = g_send_count;
|
| 2441 | //δÍê³É¿¨ÎļþµÄ³õʼ»¯ÎÞ·¨½øÐÐeapÈÏÖ¤£¬ÐèÒª´´½¨¶¨Ê±Æ÷ÂÖѯsim¿¨³õʼ»¯×´Ì¬
|
| 2442 | sc_timer_create (WIFI_STATION_TIMER_SIM_CARD_STATUS,
|
| 2443 | TIMER_FLAG_ONCE, WIFI_STATION_TIMER_SIM_CARD_STATUS_INTERVAL,
|
| 2444 | wifi_station_query_sim_card_status, NULL);
|
| 2445 | } else {
|
| 2446 | wf_log ("--------------------sim_zpbic_status-----wlan_station_msg_handle_ex ++++++++++++++-------------");
|
| 2447 | wifi_station_connect (MODULE_ID_WIFI);
|
| 2448 | }
|
| 2449 | }
|
| 2450 | }
|
| 2451 | }
|
| 2452 |
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame^] | 2453 | #ifdef USE_CAP_SUPPORT
|
| 2454 | static void cap_update_spot_param(wlan_sta_param_t *param)
|
| 2455 | {
|
| 2456 | updateinfo_t info = {0};
|
| 2457 | int spot_num = 0;
|
| 2458 | char spot_tmp[WIFI_STATION_SPOT_LEN] = {0};
|
| 2459 | char wifi_profile_num[WIFI_STATION_PROFILE_NV_NAME_LEN] = {0};
|
| 2460 |
|
| 2461 | snprintf(spot_tmp, sizeof(spot_tmp), "123456789123456789,0,0,0,%s,%s,%s,%s,0,0F:00:00:00:00:00",
|
| 2462 | param->ssid, param->authmode, param->encrypt, param->pwd);
|
| 2463 | if (g_wpa_supplicant == 1) {
|
| 2464 | /*request disconnection from the currently connected
|
| 2465 | * network. This will stop any ongoing scans and initiate deauthentication.
|
| 2466 | */
|
| 2467 | sta_docmd("DISCONNECT");
|
| 2468 |
|
| 2469 | sc_cfg_get("wifi_profile_num", wifi_profile_num, sizeof(wifi_profile_num));
|
| 2470 | spot_num = atoi(wifi_profile_num);
|
| 2471 | if (spot_num > 0) {
|
| 2472 | strncpy(info.action, "delete", sizeof(info.action)-1);
|
| 2473 | //strncpy(info.spot, wifi_update_profile, sizeof(info.spot)-1);
|
| 2474 | sc_cfg_get("wifi_profile", info.spot, sizeof(info.spot));
|
| 2475 | webui_update_spot_list(&info);
|
| 2476 | //usleep(100);
|
| 2477 | sc_cfg_set("sta_ip_status", "disconnect");
|
| 2478 | }
|
| 2479 |
|
| 2480 |
|
| 2481 | sc_cfg_set("wifi_profile_num", "1");
|
| 2482 | sc_cfg_set("wifi_profile", spot_tmp);
|
| 2483 | memset(&info, 0, sizeof(info));
|
| 2484 | strncpy(info.action, "add", sizeof(info.action)-1);
|
| 2485 | strncpy(info.spot, spot_tmp, sizeof(info.spot)-1);
|
| 2486 | webui_update_spot_list(&info);
|
| 2487 | }
|
| 2488 | else {
|
| 2489 | //ûÓгõʼ»¯µÄʱºò
|
| 2490 | sc_cfg_set("wifi_profile_num", "1");
|
| 2491 | sc_cfg_set("wifi_profile", spot_tmp);
|
| 2492 | //wpa_suplicantµÄÅäÖÿ´ÊÇ·ñÐèÒª¸Ä£¬Èç¹ûÒѳõʼ»¯ÁË£¬Ó¦¸ÃÒª¸Ä
|
| 2493 | }
|
| 2494 |
|
| 2495 | }
|
| 2496 |
|
| 2497 | static void cap_station_enable(wlan_sta_enable_t *sta_ena)
|
| 2498 | {
|
| 2499 | if (sta_ena->enable == 1) {
|
| 2500 | if (1 == g_wpa_supplicant) {
|
| 2501 | wf_log("station has opened");
|
| 2502 | return;
|
| 2503 | }
|
| 2504 | //MSG_CMD_WIFI_STATION_OPEN;
|
| 2505 | #if defined(__REALTEK_8192_CHIP__) || defined(__AIC_8800DW_CHIP__)
|
| 2506 | wifi_station_open_apsta();
|
| 2507 | //wifi_station_connect(MODULE_ID_WEB_CGI);//´ò¿ªµÄʱºòÒѾÁ¬ÁËÒ»´Î£¬Ã»ÓбØÒªÔÙ´ÎÁ¬½Ó
|
| 2508 | #else
|
| 2509 | wf_log("-MSG_CMD_WIFI_STATION_OPEN-");
|
| 2510 | wlan_station_init();
|
| 2511 | #endif
|
| 2512 | }
|
| 2513 | else {
|
| 2514 | #ifdef USE_CAP_SUPPORT
|
| 2515 | send_sta_status_to_cap(IN_WIFI_STA_STATUS_NONE, IN_WIFI_REASON_CODE_NONE);
|
| 2516 | #endif
|
| 2517 | if (0 == g_wpa_supplicant) {
|
| 2518 | wf_log("station has closed");
|
| 2519 | return;
|
| 2520 | }
|
| 2521 | //MSG_CMD_WIFI_STATION_CLOSE;
|
| 2522 | sta_disconnected();
|
| 2523 | wlan_station_deinit();
|
| 2524 | #if defined(__REALTEK_8192_CHIP__)|| defined(__AIC_8800DW_CHIP__)
|
| 2525 | basic_deal_all (WIFI_CFG_RESTART_AP);
|
| 2526 | #endif
|
| 2527 | }
|
| 2528 |
|
| 2529 | }
|
| 2530 |
|
| 2531 | static int send_sta_status_to_cap(int status, int reason)
|
| 2532 | {
|
| 2533 | int ret = 0;
|
| 2534 | wlan_sta_status_t sta_stat = {0};
|
| 2535 |
|
| 2536 | sta_stat.status = status;
|
| 2537 | //2.4 5G¶ÀÁ¢Íø¿ÚʱÐèÐÞ¸Ä
|
| 2538 | strncpy(sta_stat.ifname, sta_manager->drv_proxy.iface_name, sizeof(sta_stat.ifname) - 1);
|
| 2539 |
|
| 2540 | if (sta_stat.status == IN_WIFI_STA_STATUS_CONNECTING
|
| 2541 | || sta_stat.status == IN_WIFI_STA_STATUS_ASSOCIATED
|
| 2542 | || sta_stat.status == IN_WIFI_STA_STATUS_CONNECTED) {
|
| 2543 | char wifi_mac[20] = {0};
|
| 2544 | char wifi_signal[20] = {0};
|
| 2545 | sc_cfg_get("EX_mac", wifi_mac, sizeof(wifi_mac));
|
| 2546 | sc_cfg_get("EX_signal", wifi_signal, sizeof(wifi_signal));
|
| 2547 |
|
| 2548 | strncpy(sta_stat.ap_bssid, wifi_mac, sizeof(sta_stat.ap_bssid) - 1);
|
| 2549 | sta_stat.signal_level = atoi(wifi_signal);
|
| 2550 | }
|
| 2551 |
|
| 2552 | if (sta_stat.status == IN_WIFI_STA_STATUS_ERROR) {
|
| 2553 | sta_stat.reason_code = reason;
|
| 2554 | }
|
| 2555 |
|
| 2556 | if (sta_stat.status == IN_WIFI_STA_STATUS_CONNECTED) {
|
| 2557 | char wbwanv6_enable[20] = {0};
|
| 2558 | char wifiwan_ip[64] = {0};
|
| 2559 | char wifiwan_ipv6[64] = {0};
|
| 2560 | char nv_wifiwan[20] = {0};
|
| 2561 | char nv_wifiwan_ip[32] = {0};
|
| 2562 | char nv_wifiwan_ipv6[32] = {0};
|
| 2563 |
|
| 2564 | //wlan
|
| 2565 | sc_cfg_get("wifiwan", nv_wifiwan, sizeof(nv_wifiwan));
|
| 2566 | //ipv4
|
| 2567 | snprintf(nv_wifiwan_ip, sizeof(nv_wifiwan_ip), "%s_ip", nv_wifiwan);
|
| 2568 | sc_cfg_get(nv_wifiwan_ip, wifiwan_ip, sizeof(wifiwan_ip));
|
| 2569 | sta_stat.has_addr = 1;
|
| 2570 | strncpy(sta_stat.str_addr, wifiwan_ip, sizeof(sta_stat.str_addr) - 1);
|
| 2571 |
|
| 2572 | //ipv6
|
| 2573 | snprintf(nv_wifiwan_ipv6, sizeof(nv_wifiwan_ipv6), "%s_ipv6_ip", nv_wifiwan);
|
| 2574 | sc_cfg_get(nv_wifiwan_ipv6, wifiwan_ipv6, sizeof(wifiwan_ipv6));
|
| 2575 | sc_cfg_get("wbwanv6_enable", wbwanv6_enable, sizeof(wbwanv6_enable));
|
| 2576 | if (atoi(wbwanv6_enable) == 1) {
|
| 2577 | sta_stat.has_addr6 = 1;
|
| 2578 | strncpy(sta_stat.str_addr6, wifiwan_ipv6, sizeof(sta_stat.str_addr6) - 1);
|
| 2579 | }
|
| 2580 | }
|
| 2581 |
|
| 2582 | ret = send_soc_msg(FAR_PS, MODULE_ID_WIFI, MSG_CMD_CAP_STA_STATUS, sizeof(sta_stat), &sta_stat);
|
| 2583 | if (ret != 0) {
|
| 2584 | wf_log("send_soc_msg fail, ret:%d\n", ret);
|
| 2585 | }
|
| 2586 |
|
| 2587 | return ret;
|
| 2588 | }
|
| 2589 |
|
| 2590 | static void cap_station_scan(void)
|
| 2591 | {
|
| 2592 | char wifi_sta_connection[WIFI_CONNECTION_LEN] = {0};
|
| 2593 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 2594 |
|
| 2595 | sc_cfg_get("wifi_sta_connection", wifi_sta_connection, sizeof (wifi_sta_connection));
|
| 2596 |
|
| 2597 | wf_log("cap_station_scan");
|
| 2598 | //¹¦ÄܹرÕÔòÖ±½ÓÍ˳ö
|
| 2599 | if (strcmp(wifi_sta_connection, "1") != 0) {
|
| 2600 | wf_log("station close: %s", wifi_sta_connection);
|
| 2601 | return;
|
| 2602 | }
|
| 2603 |
|
| 2604 | //wpa_supplicant½ø³ÌûÆô¶¯ÔòÆô¶¯£¬ÊôÓÚÒì³£±£»¤
|
| 2605 | if (check_supplicant_alive() == 0) {
|
| 2606 | wf_log("wpa supplicant is not running!xx");
|
| 2607 | //Õânv¿ÉÒÔ¿¼ÂÇcap¸´ÓÃ
|
| 2608 | sc_cfg_set("scan_finish", "2"); //Ä¿µÄÊǸæËßwebui£¬´Ëʱµ×²ã³öÎÊÌâÁË
|
| 2609 | return;
|
| 2610 | }
|
| 2611 |
|
| 2612 | //ÕýÔÚÁ¬½Ó״̬ÔòÍ˳ö Á¬½ÓʱÄÚ²¿ÓÐɨÃè ½á¹û²»Ò»¶¨ÊÇÉϲãÏëÒªµÄ
|
| 2613 | sc_cfg_get("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 2614 | if (strcmp(sta_ip_status, WIFI_STATION_IP_STATUS_CONNECTING) == 0) {
|
| 2615 | wf_log("sta_ip_status=connecting,set scan_finish=2========");
|
| 2616 | //sc_cfg_set ("scan_finish", "2"); //Ä¿µÄÊǸæËßwebui£¬´Ëʱµ×²ãÔÚconnecting
|
| 2617 | //return;
|
| 2618 | }
|
| 2619 |
|
| 2620 | if (strcmp (sta_ip_status, WIFI_STATION_IP_STATUS_DHCPING) == 0) {
|
| 2621 | wf_log ("sta_ip_status=dhcping,set scan_finish=2========");
|
| 2622 | //¼ÌÐøÉ¨Ãè¿´¿´
|
| 2623 | //sc_cfg_set ("scan_finish", "2"); //Ä¿µÄÊǸæËßwebui£¬´Ëʱµ×²ãÔÚconnecting
|
| 2624 | //return;
|
| 2625 | }
|
| 2626 |
|
| 2627 | //ɨÃè
|
| 2628 | g_cap_scan = 1;
|
| 2629 | wpa_supplicant_scan();
|
| 2630 |
|
| 2631 |
|
| 2632 | }
|
| 2633 |
|
| 2634 | static int transe_sta_auth_mode(char *authmode)
|
| 2635 | {
|
| 2636 | int sc_auth = CAP_WIFI_AUTH_UNSUP;
|
| 2637 |
|
| 2638 | if (strcmp(authmode, "OPEN") == 0) {
|
| 2639 | sc_auth = CAP_WIFI_AUTH_OPEN;
|
| 2640 | }
|
| 2641 | else if (strcmp(authmode, "WPA2PSK") == 0) {
|
| 2642 | sc_auth = CAP_WIFI_AUTH_WPA2;
|
| 2643 | }
|
| 2644 | else if (strcmp(authmode, "WPA3Personal") == 0) {
|
| 2645 | sc_auth = CAP_WIFI_AUTH_WPA3;
|
| 2646 | }
|
| 2647 | else if (strcmp(authmode, "WPAPSKWPA2PSK") == 0) {
|
| 2648 | sc_auth = CAP_WIFI_AUTH_WPA12;
|
| 2649 | }
|
| 2650 | else if (strcmp(authmode, "WPA2WPA3") == 0) {
|
| 2651 | sc_auth = CAP_WIFI_AUTH_WPA23;
|
| 2652 | }
|
| 2653 | else {
|
| 2654 | wf_log("unsuport authmode:%s\n", authmode);
|
| 2655 | }
|
| 2656 | return sc_auth;
|
| 2657 | }
|
| 2658 |
|
| 2659 | //ÅÅÐòÁË È¡ÐźźõÄǰ30
|
| 2660 | static int send_scan_result_to_cap(void)
|
| 2661 | {
|
| 2662 | wlan_sta_scan_list_t scan_list = {0};
|
| 2663 | int ret = 0;
|
| 2664 |
|
| 2665 | int i = 0;
|
| 2666 | for (i = 0; i < WIFI_STATION_SCAN_RESULT_LIST_NUM && i < CAP_WIFI_MAX_SCAN_CNT; i++) {
|
| 2667 | if (g_scan_result_list_p[i] == NULL) {
|
| 2668 | break;
|
| 2669 | }
|
| 2670 |
|
| 2671 | scan_list.info[i].auth = transe_sta_auth_mode(g_scan_result_list_p[i]->auth_mode);
|
| 2672 | scan_list.info[i].channel = g_scan_result_list_p[i]->channel;
|
| 2673 | scan_list.info[i].signal_level = g_scan_result_list_p[i]->signal;
|
| 2674 | strncpy(scan_list.info[i].essid, g_scan_result_list_p[i]->ssid, sizeof(scan_list.info[i].essid)-1);
|
| 2675 | strncpy(scan_list.info[i].bssid, g_scan_result_list_p[i]->mac, sizeof(scan_list.info[i].bssid)-1);
|
| 2676 | scan_list.cnt++;
|
| 2677 | }
|
| 2678 | //Ŀǰ30¸ö,¶àÁ˺˼äat´«²»¹ýÈ¡,×î´ó´«3500/2B,Òòhex2str
|
| 2679 | ret = send_soc_msg(FAR_PS, MODULE_ID_WIFI, MSG_CMD_CAP_STA_SCAN_RES, sizeof(scan_list), &scan_list);
|
| 2680 | if (ret != 0) {
|
| 2681 | wf_log("send_soc_msg fail, ret:%d\n", ret);
|
| 2682 | }
|
| 2683 |
|
| 2684 | return ret;
|
| 2685 | }
|
| 2686 |
|
| 2687 | static void scan_result_to_cap(void)
|
| 2688 | {
|
| 2689 | int ret = 0;
|
| 2690 |
|
| 2691 | if (g_cap_scan == 1) {
|
| 2692 | ret = send_scan_result_to_cap();
|
| 2693 | if (ret == 0) {
|
| 2694 | g_cap_scan = 0;
|
| 2695 | }
|
| 2696 | }
|
| 2697 |
|
| 2698 | }
|
| 2699 |
|
| 2700 | #endif
|
| 2701 |
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2702 | //wifi station´¦Àíº¯Êý
|
| 2703 | int wlan_sta_parse_msg (MSG_BUF *pMsg)
|
| 2704 | {
|
| 2705 |
|
| 2706 | int ret = 0;
|
| 2707 | switch (pMsg->usMsgCmd) {
|
| 2708 | case MSG_CMD_WIFI_STATION_OPEN: {
|
| 2709 | #if defined(__REALTEK_8192_CHIP__) || defined(__AIC_8800DW_CHIP__)
|
| 2710 | wifi_station_open_apsta();
|
| 2711 | //wifi_station_connect(MODULE_ID_WEB_CGI);//´ò¿ªµÄʱºòÒѾÁ¬ÁËÒ»´Î£¬Ã»ÓбØÒªÔÙ´ÎÁ¬½Ó
|
| 2712 | #else
|
| 2713 | wf_log("-MSG_CMD_WIFI_STATION_OPEN-");
|
| 2714 | wlan_station_init();
|
| 2715 | #endif
|
| 2716 | break;
|
| 2717 | }
|
| 2718 | case MSG_CMD_WIFI_STATION_CLOSE: {
|
| 2719 | sta_disconnected();
|
| 2720 | wlan_station_deinit();
|
| 2721 | #if defined(__REALTEK_8192_CHIP__)|| defined(__AIC_8800DW_CHIP__)
|
| 2722 | basic_deal_all (WIFI_CFG_RESTART_AP);
|
| 2723 | #endif
|
| 2724 | break;
|
| 2725 | }
|
| 2726 | case MSG_CMD_WIFI_STATION_CLOSE_OPEN_MSSID: {
|
| 2727 | sta_disconnected();
|
| 2728 | wlan_station_deinit();
|
| 2729 | basic_deal_all (WIFI_CFG_CLOSESTA_OPENMSSID);
|
| 2730 | break;
|
| 2731 | }
|
| 2732 | case MSG_CMD_WIFI_STATION_SPOT_UPDATE: {
|
| 2733 | webui_update_spot_list ( (updateinfo_t*) (pMsg->aucDataBuf));
|
| 2734 |
|
| 2735 | //ÿ´ÎÓû§¸üÐÂÈȵãºó£¬²»ÐèÒª¸üб£´æsignalµÄÈ«¾Ö±äÁ¿£¬¶øÊÇÔÚɨÃèµÄʱºò£¬À´¼ì²âÊÇ·ñÓб仯
|
| 2736 | //ËùÒÔÔÚÈȵã±ä»¯ºó£¬ÐèҪͨ¹ýscanÀ´¾¡¿ì¸üÐÂÈȵã״̬
|
| 2737 | break;
|
| 2738 | }
|
| 2739 | case MSG_CMD_WIFI_STATION_SCAN: {
|
| 2740 | wifi_station_scan();
|
| 2741 | break;
|
| 2742 | }
|
| 2743 | case MSG_CMD_WIFI_STATION_CONNECT: {
|
| 2744 | sta_connect (INVALID_NETWORK_ID);
|
| 2745 | break;
|
| 2746 | }
|
| 2747 | case MSG_CMD_WIFI_STATION_DISCONNECT: {
|
| 2748 | sta_disconnect();
|
| 2749 | break;
|
| 2750 | }
|
| 2751 | case MSG_CMD_WIFI_STATION_GET_SCAN_RESULTS: {
|
| 2752 | wifi_station_get_scan_results();
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame^] | 2753 | #ifdef USE_CAP_SUPPORT
|
| 2754 | scan_result_to_cap();
|
| 2755 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2756 | break;
|
| 2757 | }
|
| 2758 | case MSG_CMD_WIFI_STATION_SIM_INIT_TIMER_PROCESS: {
|
| 2759 | handle_sim_init_status_timer();
|
| 2760 | break;
|
| 2761 | }
|
| 2762 | case MSG_CMD_WIFI_STATION_EVENT_CONNECTED: {
|
| 2763 | wf_log ("[wifi event connected , goto dhcp]");
|
| 2764 | sc_cfg_set ("sta_ip_status", "dhcping");
|
| 2765 | do_dhcp();
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame^] | 2766 | #ifdef USE_CAP_SUPPORT
|
| 2767 | send_sta_status_to_cap(IN_WIFI_STA_STATUS_ASSOCIATED, IN_WIFI_REASON_CODE_NONE);
|
| 2768 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2769 | break;
|
| 2770 | }
|
| 2771 | case MSG_CMD_WIFI_STATION_EVENT_DISCONNECTED: {
|
| 2772 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 2773 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 2774 |
|
| 2775 | if (strcmp (sta_ip_status, "connect") == 0 || strcmp (sta_ip_status, "dhcping") == 0) {
|
| 2776 | sta_disconnected();
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame^] | 2777 | #ifdef USE_CAP_SUPPORT
|
| 2778 | send_sta_status_to_cap(IN_WIFI_STA_STATUS_IDLE, IN_WIFI_REASON_CODE_NONE);
|
| 2779 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2780 | }
|
| 2781 | else{
|
| 2782 | wf_log ("The Spot connect failed, just set sta_ip_status disconnect");
|
| 2783 | sc_cfg_set ("sta_ip_status", "disconnect");
|
| 2784 | }
|
| 2785 | break;
|
| 2786 | }
|
| 2787 | case MSG_CMD_WIFI_STATION_EVENT_CONNECTING: {
|
| 2788 | sc_cfg_set("sta_ip_status", WIFI_STATION_IP_STATUS_CONNECTING);
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame^] | 2789 | #ifdef USE_CAP_SUPPORT
|
| 2790 | send_sta_status_to_cap(IN_WIFI_STA_STATUS_CONNECTING, IN_WIFI_REASON_CODE_NONE);
|
| 2791 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2792 | break;
|
| 2793 | }
|
| 2794 |
|
| 2795 | case MSG_CMD_BLC_OPEN_WIFISTATION_ACCESS: { // you can connect
|
| 2796 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 2797 |
|
| 2798 | g_blc_send_close_apsta = 0;
|
| 2799 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 2800 |
|
| 2801 | wf_log ("sta_ip_status=%s", sta_ip_status);
|
| 2802 |
|
| 2803 | if (strcmp (sta_ip_status, WIFI_STATION_IP_STATUS_DISCONNECT) == 0) {
|
| 2804 | wifi_station_connect (MODULE_ID_MAIN_CTRL);
|
| 2805 | } else {
|
| 2806 | wf_log ("do not deal connect cmd, sta_ip_status=%s", sta_ip_status);
|
| 2807 | }
|
| 2808 | break;
|
| 2809 | }
|
| 2810 | case MSG_CMD_BLC_CLOSE_WIFISTATION_ACCESS: {
|
| 2811 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 2812 |
|
| 2813 | g_blc_send_close_apsta = 1;
|
| 2814 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 2815 | if (strcmp (sta_ip_status, WIFI_STATION_IP_STATUS_DISCONNECT) != 0) {
|
| 2816 | sta_disconnect();// if wifi not connect ok , then if there is disconnect event??
|
| 2817 | } else {
|
| 2818 | wf_log ("do not deal disconnect cmd, sta_ip_status=%s", sta_ip_status);
|
| 2819 |
|
| 2820 | }
|
| 2821 | break;
|
| 2822 | }
|
| 2823 |
|
| 2824 | case MSG_CMD_WIFI_STATION_BLC_CONNECTED: {
|
| 2825 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 2826 |
|
| 2827 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 2828 | if (strcmp (sta_ip_status, WIFI_STATION_IP_STATUS_DHCPING) == 0) {
|
| 2829 | wf_log ("[wlan-station] wlan0-vxd get ip success");
|
| 2830 | sta_connected();
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame^] | 2831 | #ifdef USE_CAP_SUPPORT
|
| 2832 | send_sta_status_to_cap(IN_WIFI_STA_STATUS_CONNECTED, IN_WIFI_REASON_CODE_NONE);
|
| 2833 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2834 | }
|
| 2835 | else{
|
| 2836 | wf_log (" DO not deal , sta_ip_status=%s", sta_ip_status);
|
| 2837 | }
|
| 2838 | break;
|
| 2839 | }
|
| 2840 |
|
| 2841 | case MSG_CMD_NET_WAN_DIAL_FAIL: {
|
| 2842 | wf_log ("wlan0-vxd dhcp ip failed");
|
| 2843 | ipfail_disconnect_ap();
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame^] | 2844 | #ifdef USE_CAP_SUPPORT
|
| 2845 | send_sta_status_to_cap(IN_WIFI_STA_STATUS_ERROR, IN_WIFI_REASON_CODE_DHCP_FAILED);
|
| 2846 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2847 | break;
|
| 2848 | }
|
| 2849 | case MSG_CMD_CARD_MODE_RSP: {
|
| 2850 | wlan_station_msg_handle_card_mode_for_eap (pMsg);
|
| 2851 | break;
|
| 2852 | }
|
| 2853 | case MSG_CMD_PIN_STATUS_RSP: {
|
| 2854 | wlan_station_msg_handle_pin_status_for_eap (pMsg);
|
| 2855 | break;
|
| 2856 | }
|
| 2857 | case MSG_CMD_WIFI_STATION_CONNECT_TIMEOUT: {
|
| 2858 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 2859 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 2860 | wf_log ("handle connect timeout msg,sta_ip_status=%s", sta_ip_status);
|
| 2861 | if (strcmp (sta_ip_status, WIFI_STATION_IP_STATUS_CONNECTING) == 0) {
|
| 2862 | sta_disconnect();
|
| 2863 | sc_cfg_set ("sta_ip_status", WIFI_STATION_IP_STATUS_DISCONNECT);
|
| 2864 | g_connecting_time_out_timer = 0;
|
| 2865 | }
|
| 2866 | break;
|
| 2867 | }
|
| 2868 |
|
| 2869 | case MSG_CMD_WIFI_STATION_NO_AVAILABLE_AP:{
|
| 2870 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 2871 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 2872 | wf_log ("handle no available ap, sta_ip_status=%s", sta_ip_status);
|
| 2873 | if (strcmp (sta_ip_status, WIFI_STATION_IP_STATUS_CONNECTING) == 0) {
|
| 2874 | sc_cfg_set ("sta_ip_status", "disconnect");
|
| 2875 | if(1 == g_disable_other_network){
|
| 2876 | sta_docmd ("ENABLE_NETWORK all");// the connecting status will be set by assocating event, if no assoc , just be disconnect
|
| 2877 | g_disable_other_network = 0;
|
| 2878 | }
|
| 2879 | }
|
| 2880 | break;
|
| 2881 | }
|
| 2882 | case MSG_CMD_WIFI_STATION_TEMP_DISABLED: {
|
| 2883 | if (g_wpa_supplicant == 1) {
|
| 2884 | //wf_log ("MSG_CMD_WIFI_STATION_TEMP_DISABLED=%s", (char *)(pMsg->aucDataBuf));
|
| 2885 |
|
| 2886 | sc_cfg_set ("sta_ip_status", WIFI_STATION_IP_STATUS_DISCONNECT);
|
| 2887 | process_tmp_disabled((char *)(pMsg->aucDataBuf));
|
| 2888 | }
|
| 2889 | break;
|
| 2890 | }
|
| 2891 | case MSG_CMD_WIFI_STATION_FAILED_SET: {
|
| 2892 | char sta_ip_status[WIFI_STATION_IP_STATUS_LEN] = {0};
|
| 2893 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 2894 | wf_log ("handle Failed to set, sta_ip_status=%s", sta_ip_status);
|
| 2895 | if (strcmp (sta_ip_status, WIFI_STATION_IP_STATUS_CONNECTING) == 0) {
|
| 2896 | sc_cfg_set ("sta_ip_status", "disconnect");
|
| 2897 | //if(1 == g_disable_other_network){
|
| 2898 | // sta_docmd ("ENABLE_NETWORK all");// the connecting status will be set by assocating event, if no assoc , just be disconnect
|
| 2899 | // g_disable_other_network = 0;
|
| 2900 | //}
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame^] | 2901 | #ifdef USE_CAP_SUPPORT
|
| 2902 | send_sta_status_to_cap(IN_WIFI_STA_STATUS_ERROR, IN_WIFI_REASON_CODE_SET_FAILED);
|
| 2903 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2904 | }
|
| 2905 | break;
|
| 2906 | }
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame^] | 2907 | #ifdef USE_CAP_SUPPORT
|
| 2908 | case MSG_CMD_CAP_STA_SET_PARAM: {
|
| 2909 | cap_update_spot_param((wlan_sta_param_t *)(pMsg->aucDataBuf));
|
| 2910 | break;
|
| 2911 | }
|
| 2912 | case MSG_CMD_CAP_STA_ENABLE: {
|
| 2913 | //ûÓе¥¶À¿ª¹ØstaµÄ¹¦ÄÜ,ÏÈÊÊÅä³Éap´æÔÚµÄÇé¿öÏ¿ª¹Østa
|
| 2914 | cap_station_enable((wlan_sta_enable_t *)(pMsg->aucDataBuf));
|
| 2915 | break;
|
| 2916 | }
|
| 2917 | case MSG_CMD_CAP_STA_SCAN: {
|
| 2918 | cap_station_scan();
|
| 2919 | break;
|
| 2920 | }
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2921 |
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame^] | 2922 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 2923 | default: {
|
| 2924 | ret = -1;
|
| 2925 | break;
|
| 2926 | }
|
| 2927 | }
|
| 2928 |
|
| 2929 | return ret;
|
| 2930 | }
|
| 2931 |
|
| 2932 |
|
| 2933 | int get_int_from_event (char * buf, char * tag)
|
| 2934 | {
|
| 2935 | int ret = -1;
|
| 2936 | char * pstr = NULL;
|
| 2937 |
|
| 2938 | if(NULL == buf || NULL == tag)
|
| 2939 | return -1;
|
| 2940 |
|
| 2941 | pstr = strstr (buf, tag);
|
| 2942 | if (pstr != NULL) {
|
| 2943 | pstr += strlen (tag);
|
| 2944 | ret = atoi (pstr);
|
| 2945 | }
|
| 2946 |
|
| 2947 | return ret;
|
| 2948 | }
|
| 2949 |
|
| 2950 | /*
|
| 2951 | ÃÀÀö¶³È˵ÄÁù³¯¹Å¶¼ÄÏhh, ÖÐÎÄssid»á±È½Ï³¤
|
| 2952 | \xe7\xbe\x8e\xe4\xb8\xbd\xe5\x86\xbb\xe4\xba\xba\xe7\x9a\x84\xe5\x85\xad\xe6\x9c\x9d\xe5\x8f\xa4\xe9\x83\xbd\xe5\x8d\x97hh
|
| 2953 | */
|
| 2954 | void process_trying_to_assoc (char * buf)
|
| 2955 | {
|
| 2956 | char * start = NULL;
|
| 2957 | char * end = NULL;
|
| 2958 | char ssid[WIFI_STATION_SSID_LEN] = {0};
|
| 2959 | char mac[WIFI_STATION_MAC_LEN] = {0};
|
| 2960 | unsigned int len = 0;//klocwork
|
| 2961 |
|
| 2962 | start = strstr (buf, "SSID=\'") + strlen("SSID=\'");
|
| 2963 | if (start != NULL) {
|
| 2964 | end = strstr (start, "\' ");//klocwork
|
| 2965 | }
|
| 2966 |
|
| 2967 | strncpy (mac, buf + strlen ("Trying to associate with "), 17);
|
| 2968 | wf_log ("Trying to associate with mac=%s", mac);
|
| 2969 | if (end != NULL && start != NULL) {
|
| 2970 | len = end - start;
|
| 2971 | len = MIN(len, WIFI_STATION_SSID_LEN-1);
|
| 2972 | //strncpy (ssid, start, len);
|
| 2973 | //ssid[WIFI_STATION_SSID_LEN-1] = '\0';//klocwork
|
| 2974 | snprintf(ssid,len+1,"%s",start);
|
| 2975 | wf_log ("Trying to associate with ssid= %s", ssid);
|
| 2976 | }
|
| 2977 |
|
| 2978 | update_current_EX (ssid, mac);
|
| 2979 |
|
| 2980 | }
|
| 2981 |
|
| 2982 | //Trying to associate with ca:c2:f1:74:2f:f4 (SSID='D_mi_D' freq=2412 MHz)
|
| 2983 | //SME: Trying to authenticate with 90:1d:27:78:2c:1e (SSID='Ufi_782111' freq=2412 MHz)
|
| 2984 | static void channel_follow(char * buf)
|
| 2985 | {
|
| 2986 | char * start = NULL;
|
| 2987 | char * end = NULL;
|
| 2988 | char freq[WIFI_STATION_FREQ_LEN] = {0};
|
| 2989 | unsigned int len = 0;//klocwork
|
| 2990 | int frequency = 0;
|
| 2991 |
|
| 2992 | start = strstr(buf, "freq=") + strlen("freq=");
|
| 2993 | if (start != NULL) {
|
| 2994 | end = strstr (start, " MHz");//klocwork
|
| 2995 | }
|
| 2996 |
|
| 2997 | if (end != NULL && start != NULL) {
|
| 2998 | len = end - start;
|
| 2999 | len = MIN(len, WIFI_STATION_FREQ_LEN-1);
|
| 3000 | snprintf(freq, len+1, "%s", start);
|
| 3001 | frequency = atoi(freq);
|
| 3002 | wf_log("Trying to associate with freq= %s[%d]", freq, frequency);
|
| 3003 |
|
| 3004 | switch (frequency) {
|
| 3005 | case WIFI_STATION_CHANNEL1:
|
| 3006 | sc_cfg_set("flower_channel", "1");
|
| 3007 | break;
|
| 3008 | case WIFI_STATION_CHANNEL2:
|
| 3009 | sc_cfg_set("flower_channel", "2");
|
| 3010 | break;
|
| 3011 | case WIFI_STATION_CHANNEL3:
|
| 3012 | sc_cfg_set("flower_channel", "3");
|
| 3013 | break;
|
| 3014 | case WIFI_STATION_CHANNEL4:
|
| 3015 | sc_cfg_set("flower_channel", "4");
|
| 3016 | break;
|
| 3017 | case WIFI_STATION_CHANNEL5:
|
| 3018 | sc_cfg_set("flower_channel", "5");
|
| 3019 | break;
|
| 3020 | case WIFI_STATION_CHANNEL6:
|
| 3021 | sc_cfg_set("flower_channel", "6");
|
| 3022 | break;
|
| 3023 | case WIFI_STATION_CHANNEL7:
|
| 3024 | sc_cfg_set("flower_channel", "7");
|
| 3025 | break;
|
| 3026 | case WIFI_STATION_CHANNEL8:
|
| 3027 | sc_cfg_set("flower_channel", "8");
|
| 3028 | break;
|
| 3029 | case WIFI_STATION_CHANNEL9:
|
| 3030 | sc_cfg_set("flower_channel", "9");
|
| 3031 | break;
|
| 3032 | case WIFI_STATION_CHANNEL10:
|
| 3033 | sc_cfg_set("flower_channel", "10");
|
| 3034 | break;
|
| 3035 | case WIFI_STATION_CHANNEL11:
|
| 3036 | sc_cfg_set("flower_channel", "11");
|
| 3037 | break;
|
| 3038 | case WIFI_STATION_CHANNEL12:
|
| 3039 | sc_cfg_set("flower_channel", "12");
|
| 3040 | break;
|
| 3041 | case WIFI_STATION_CHANNEL13:
|
| 3042 | sc_cfg_set("flower_channel", "13");
|
| 3043 | break;
|
| 3044 | default:
|
| 3045 | sc_cfg_set("flower_channel", "0");
|
| 3046 | wf_log("channel_follow with unknow freq = [%d]", frequency);
|
| 3047 | break;
|
| 3048 | }
|
| 3049 | }
|
| 3050 |
|
| 3051 | ipc_send_message (MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_CHANNEL_FOLLOW, 0, NULL, 0);
|
| 3052 |
|
| 3053 | }
|
| 3054 |
|
| 3055 | /*
|
| 3056 | STA: CTRL-EVENT-SSID-TEMP-DISABLED id=7 ssid="ydh" auth_failures=5 duration=60 reason=CONN_FAILED
|
| 3057 |
|
| 3058 | */
|
| 3059 |
|
| 3060 | static void process_tmp_disabled (char *buf)
|
| 3061 | {
|
| 3062 | char *p_WRONG_KEY = NULL;
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame^] | 3063 | char *p_AUTH_FAILED = NULL;
|
| 3064 | char *p_CONN_FAILED = NULL;
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 3065 | char wifi_profile_num[8] = {0};
|
| 3066 | char cmd[WIFI_STATION_CMD_LEN] = {0};
|
| 3067 | int network_id = -1;
|
| 3068 | int auth_failures = 0;
|
| 3069 |
|
| 3070 | sc_cfg_get ("wifi_profile_num", wifi_profile_num, sizeof (wifi_profile_num));
|
| 3071 | p_WRONG_KEY = strstr (buf, "WRONG_KEY");
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame^] | 3072 | #ifdef USE_CAP_SUPPORT
|
| 3073 | p_AUTH_FAILED = strstr(buf, "AUTH_FAILED");
|
| 3074 | p_CONN_FAILED = strstr(buf, "CONN_FAILED");
|
| 3075 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 3076 | /*
|
| 3077 | ¿ÉÒÔÓиüÓÅ»¯µÄËã·¨£¬Ìá¸ßÁ´½ÓЧÂÊ
|
| 3078 | */
|
| 3079 | auth_failures = get_int_from_event (buf, "auth_failures=");
|
| 3080 |
|
| 3081 | if (atoi (wifi_profile_num) > 1 && (p_WRONG_KEY || auth_failures > 1)) {
|
| 3082 | network_id = get_int_from_event (buf, "id=");
|
| 3083 |
|
| 3084 | wf_log ("network_id = %d wrong key or tmp_disabled_times = %d", network_id, auth_failures);
|
| 3085 |
|
| 3086 | sprintf (cmd, "SET_NETWORK %d priority 0", network_id);
|
| 3087 | sta_docmd (cmd);
|
| 3088 | sta_docmd ("SAVE_CONFIG");
|
| 3089 |
|
| 3090 | wifi_station_connect (MODULE_ID_WIFI);
|
| 3091 |
|
| 3092 | if (p_WRONG_KEY) {
|
| 3093 | wf_log ("network_id = %d wrong key to disable it", network_id);
|
| 3094 | sprintf (cmd , "DISABLE_NETWORK %d", network_id);
|
| 3095 | sta_docmd (cmd);
|
| 3096 | sta_docmd ("SAVE_CONFIG");
|
| 3097 | }
|
| 3098 | }
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame^] | 3099 |
|
| 3100 | #ifdef USE_CAP_SUPPORT
|
| 3101 | if (p_WRONG_KEY) {
|
| 3102 | send_sta_status_to_cap(IN_WIFI_STA_STATUS_ERROR, IN_WIFI_REASON_CODE_WRONG_KEY);
|
| 3103 | }
|
| 3104 | else if (p_AUTH_FAILED) {
|
| 3105 | send_sta_status_to_cap(IN_WIFI_STA_STATUS_ERROR, IN_WIFI_REASON_CODE_AUTH_FAILED);
|
| 3106 | }
|
| 3107 | else if (p_CONN_FAILED) {
|
| 3108 | send_sta_status_to_cap(IN_WIFI_STA_STATUS_ERROR, IN_WIFI_REASON_CODE_CONN_FAILED);
|
| 3109 | }
|
| 3110 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 3111 | }
|
| 3112 |
|
| 3113 |
|
| 3114 | void *station_loop (void *param)
|
| 3115 | {
|
| 3116 | char buf[UEVENT_BUFFER_SIZE];
|
| 3117 | char name[32] = {0};
|
| 3118 | static int scan_times = 0;
|
| 3119 | int loop_run = 0;
|
| 3120 |
|
| 3121 | strncpy (name, (char*) param, sizeof(name)-1);
|
| 3122 | prctl (PR_SET_NAME, name, 0, 0, 0);
|
| 3123 |
|
| 3124 | while (1) { //¼àÌýcharging״̬µÄ²å°Î
|
| 3125 | //if wpa_supplicant is stop ,then wait
|
| 3126 | //if recv the sem, g_wpa_supplicant ==1
|
| 3127 | // wf_log("station_loop: g_wpa_supplicant= %d", g_wpa_supplicant);
|
| 3128 | if (g_wpa_supplicant == 0 || 0 == loop_run) {
|
| 3129 | sem_wait (&g_wpa_supplicant_id);
|
| 3130 | }
|
| 3131 | loop_run =1;
|
| 3132 | // ʼþ²Î¿¼wpa_supplantÖÐwpa_ctrl.hÖж¨Òå
|
| 3133 | int nread = wifi_wait_for_event (&sta_manager->sock, buf, sizeof (buf));
|
| 3134 |
|
| 3135 | //wake_sta_lock();
|
| 3136 | if (nread > 0) {
|
| 3137 | wf_log ("STA: %s", buf);
|
| 3138 |
|
| 3139 | if (strstr (buf, "CTRL-EVENT-SCAN-RESULTS")) {
|
| 3140 | char sta_ip_status[16] = {0};
|
| 3141 | sc_cfg_get ("sta_ip_status", sta_ip_status, sizeof (sta_ip_status));
|
| 3142 |
|
| 3143 | if (strcmp (sta_ip_status, "connecting") != 0) {//disconnect connect dhcping
|
| 3144 | wf_log ("snd msg to get scan results");
|
| 3145 | scan_times = 0; // IF status change to not connecting, then set 0
|
| 3146 | ipc_send_message (MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_GET_SCAN_RESULTS, 0, NULL, 0);
|
| 3147 | } else {
|
| 3148 | // 17S ccan interval, 17*12 =204S about, to disconnect, just set the nv value, the wpa_supplicant still scan to connect
|
| 3149 | // the final status ,is enable all network, and scan to connect ,but sta_ip_status is disconnect
|
| 3150 | scan_times ++;
|
| 3151 | if (4 == scan_times) {//12-->4 , decrease the waiting time
|
| 3152 | wf_log ("can not find available spot, just set sta_ip_status disconnect", buf);
|
| 3153 | ipc_send_message (MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_NO_AVAILABLE_AP, 0, NULL, 0);
|
| 3154 | scan_times = 0;
|
| 3155 | }
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame^] | 3156 | #ifdef USE_CAP_SUPPORT
|
| 3157 | ipc_send_message (MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_GET_SCAN_RESULTS, 0, NULL, 0);
|
| 3158 | #endif
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 3159 | }
|
| 3160 | }
|
| 3161 | //STA: CTRL-EVENT-CONNECTED - Connection to a6:44:d1:86:c5:d9 completed [id=0 id_str=]
|
| 3162 |
|
| 3163 | else if (strstr (buf, "CTRL-EVENT-CONNECTED")) {
|
| 3164 | ipc_send_message (MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_CONNECTED_ENABLE_AP_CMD, 0, NULL, 0);
|
| 3165 |
|
| 3166 | char *p = strstr (buf, "Connection to ");
|
| 3167 |
|
| 3168 | scan_times = 0; // IF status change to not connecting, then set 0
|
| 3169 |
|
| 3170 | if (p != NULL) {//
|
| 3171 | p += strlen ("Connection to ");
|
| 3172 | strncpy (g_linked_ap_mac, p, 17);
|
| 3173 | }
|
| 3174 | g_linked_network_id = get_int_from_event (buf, "[id=");
|
| 3175 | wf_log ("g_linked_network_id_last = %d, g_linked_network_id= %d", g_linked_network_id_last, g_linked_network_id);
|
| 3176 | //wf_send_message( MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_EVENT_CONNECTED, 0, NULL);
|
| 3177 | ipc_send_message (MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_EVENT_CONNECTED, 0, NULL, 0);
|
| 3178 | } else if (strstr (buf, "CTRL-EVENT-DISCONNECTED")) {
|
| 3179 | ipc_send_message (MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_EVENT_DISCONNECTED, 0, NULL, 0);
|
| 3180 | }
|
| 3181 |
|
| 3182 | //STA: CTRL-EVENT-SSID-REENABLED id=0 ssid="ZONG MBB-MF920W+-000012"
|
| 3183 | else if (strstr (buf, "CTRL-EVENT-SSID-REENABLED")) {
|
| 3184 | scan_times = 0; // when reenable , it indicate there is available AP, so set it 0
|
| 3185 | ipc_send_message (MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_EVENT_CONNECTING, 0, NULL, 0);
|
| 3186 | }
|
| 3187 | //STA: Trying to associate with 00:90:49:58:00:73 (SSID='Wo4G-0073' freq=2412 MHz)
|
| 3188 | else if (strstr (buf, "Trying to associate with")) {
|
| 3189 | #if defined(__AIC_8800DW_CHIP__)
|
| 3190 | channel_follow(buf);
|
| 3191 | #endif
|
| 3192 | scan_times = 0; // when begin to assoc , it indicate there is available AP, so set it 0
|
| 3193 | // CTRL-EVENT-SSID-REENABLED maybe lost
|
| 3194 | ipc_send_message (MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_EVENT_CONNECTING, 0, NULL, 0);
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame^] | 3195 | process_trying_to_assoc (buf); //·Åipc_send_messageÇ°Ãæ
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 3196 | }
|
| 3197 | //SME: Trying to authenticate with 90:1d:27:78:2c:1e (SSID='Ufi_782111' freq=2412 MHz)
|
| 3198 | else if (strstr (buf, "Trying to authenticate with")) {
|
| 3199 | #if defined(__SSV_6X5X_CHIP__)
|
| 3200 | channel_follow(buf);
|
| 3201 | #endif
|
| 3202 | }
|
| 3203 | else if (strstr (buf , "CTRL-EVENT-SIGNAL-CHANGE")) {
|
| 3204 | wf_log ("snd msg to update signal level");
|
| 3205 | }
|
| 3206 | // CTRL-EVENT-SSID-TEMP-DISABLED id=0 ssid="CPE_E3DE4E" auth_failures=2 duration=20 reason=WRONG_KEY ¡¢AUTH_FAILED¡¢CONN_FAILED
|
| 3207 | else if (strstr (buf, "CTRL-EVENT-SSID-TEMP-DISABLED")) {
|
| 3208 | //time sequence sc_cfg_set sta_ip_status, process in another thread with other event
|
| 3209 | ipc_send_message (MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_TEMP_DISABLED, nread, buf, 0);
|
| 3210 | }
|
| 3211 | //WPA: Failed to select authenticated key management type --- 1
|
| 3212 | //WPA: Failed to set WPA key management and encryption suites --- 2
|
| 3213 | else if (strstr (buf, "WPA: Failed to set")) {
|
| 3214 | //sta auth failed
|
| 3215 | ipc_send_message (MODULE_ID_WIFI, MODULE_ID_WIFI, MSG_CMD_WIFI_STATION_FAILED_SET, 0, NULL, 0);
|
| 3216 | }
|
| 3217 | else if (strstr (buf, "CTRL-EVENT-TERMINATING")) {
|
| 3218 |
|
| 3219 | loop_run = 0;
|
| 3220 | }
|
| 3221 | } else {
|
| 3222 | wf_log ("Could not read pending message.");
|
| 3223 | }
|
| 3224 | }
|
| 3225 |
|
| 3226 | return NULL;
|
| 3227 | }
|
| 3228 |
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame^] | 3229 | void wifi_station_cancel_scan(void)
|
| 3230 | {
|
| 3231 | sta_docmd("ABORT_SCAN"); //cancel current scan, and remove scan works
|
| 3232 | sta_docmd("SCAN_INTERVAL 15"); //eloop scan timer reset
|
| 3233 | }
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 3234 |
|
| 3235 | void wlan_station_open()
|
| 3236 | {
|
| 3237 |
|
| 3238 | }
|
| 3239 |
|
| 3240 | void wlan_statemachine_init()
|
| 3241 | {
|
| 3242 |
|
| 3243 | }
|
| 3244 |
|
| 3245 |
|