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