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