blob: ec79bf3d2fce44e7b97c5fc30169761beca7c50c [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001//#include <message.h>
2#include <limits.h>
3#include <errno.h>
4#include <wifi.h>
5#include "wlan_interface.h"
6#include "softap_api.h"
7
8#define WIFI_SSID_LEN 33
9#define WLAN_SECURITY_LEN 20
10#define WLAN_ENCRYTYPE_LEN 10
11#define WLAN_DEFAULTID_LEN 2
12#define WLAN_WEPKEY_LEN 32
13#define WLAN_PSK_LEN 65
14#define WLAN_ENCODE_PSK_LEN 100
15
16#define WF_AU_OPEN "OPEN" //wifi auth mode?
17#define WF_AU_SHARE "SHARED"
18#define WF_AU_WEPAUTO "WEPAUTO"
19#define WF_AU_WPA "WPAPSK"
20#define WF_AU_WPA2 "WPA2PSK"
21#define WF_AU_WPA_WPA2 "WPAPSKWPA2PSK"
22#define WF_AU_WAPIPSK "WAPIPSK"
23#define WF_AU_WPA3 "WPA3Personal"
24#define WF_AU_WPA2_WPA3 "WPA2WPA3"
25#define WF_ENCRY_NONE "NONE" //encrypt
26#define WF_ENCRY_WEP "WEP"
27#define WF_ENCRY_TKIP "TKIP"
28#define WF_ENCRY_CCMP "CCMP"
29#define WF_ENCRY_AES "AES"
30#define WF_ENCRY_TKIP_CCMP "TKIPCCMP"
31#define WF_ENCRY_TKIP_AES "TKIPAES"
32
33#define MAX_WIFI_NUM 32
34
35static int zte_station_connect_time_calc(char *timeStr);
36static void zte_get_vap_sta_list(RT_802_11_MAC_TABLE *staList, char *iface);
37//int get_vap_sta_num(char *vapIface);
38
39static int zte_wlan_ssid1_basic_set(char *ssid_in)
40{
41 char *ssid = NULL;
42 char nv_tmp[WIFI_SSID_LEN] = {0};
43
44 if (NULL == ssid_in)
45 {
46 printf("input ssid is null\n");
47 return -1;
48 }
49
50 if ((!strcmp(ssid_in, "")) || (strlen(ssid_in) <= 0) || (strlen(ssid_in) > WIFI_SSID_LEN))
51 {
52 printf("input ssid is error\n");
53 return -1;
54 }
55
56 //ssid
57 memset(nv_tmp, 0, sizeof(nv_tmp));
58 //kw 3
59 sc_cfg_get("SSID1", nv_tmp, sizeof(nv_tmp));
60 if (0 != strcmp(ssid_in, nv_tmp))
61 {
62 sc_cfg_set("SSID1", ssid_in);
63 //sc_cfg_save();
64 }
65 else
66 {
67 printf("input ssid is same \n");
68 return 1;
69 }
70
71 return 0;
72}
73
74static int zte_wlan_ssid1_security_set(char *password)
75{
76 char authMode[WLAN_SECURITY_LEN] = {0};
77 char encrypType[WLAN_ENCRYTYPE_LEN] = {0};
78 char DefaultKeyID[WLAN_DEFAULTID_LEN] = {0};
79 int changeSecurityMode = 1;
80
81 sc_cfg_get("AuthMode", authMode, sizeof(authMode));
82 sc_cfg_get("EncrypType", encrypType, sizeof(encrypType));
83
84 //kw 3
xf.libdd93d52023-05-12 07:10:14 -070085 printf("wlan_ssid1_security_set authMode = [%s]\n", authMode);
86 printf("wlan_ssid1_security_set encrypType = [%s]\n", encrypType);
lh9ed821d2023-04-07 01:36:19 -070087 if(NULL == password)//&& (!(!strcmp(authMode, WF_AU_OPEN) && !strcmp(encrypType, WF_ENCRY_NONE))))
88 {
xf.libdd93d52023-05-12 07:10:14 -070089 printf("wlan_ssid1_security_set password is null\n");
lh9ed821d2023-04-07 01:36:19 -070090 return -1;
91 }
92#if 0 //kw 3
93 if((!strcmp(authMode, WF_AU_OPEN)) && (!strcmp(encrypType, WF_ENCRY_NONE)))
94 {
95 if(strlen(password) == 0 || (!strcmp(password, "")))
96 {
97 printf("%s, WF_AU_OPEN password len is 0\n", __FUNCTION__);
98 return 1;
99 }
100 else
101 {
102 if((strlen(password) < 8) || (strlen(password) > 64))
103 {
104 printf("%s, password len is error\n", __FUNCTION__);
105 return -1;
106 }
107 }
108 }
109 else
110 {
111 if((strlen(password) < 8) || (strlen(password) > 64) || (!strcmp(password, "")))
112 {
113 printf("%s, not open password len is error\n", __FUNCTION__);
114 return -1;
115 }
116 }
117#endif
118 if(((!strcmp(authMode, WF_AU_WPA_WPA2)) && (!strcmp(encrypType, WF_ENCRY_TKIP_AES))))
119 {
120 changeSecurityMode = 0;
121 }
122 else
123 {
124 sc_cfg_set("AuthMode", WF_AU_WPA_WPA2);
125 sc_cfg_set("EncrypType", WF_ENCRY_TKIP_AES);
126 }
127 if((!strcmp(authMode, WF_AU_OPEN)) || (!strcmp(authMode, WF_AU_SHARE)) || (!strcmp(authMode, WF_AU_WEPAUTO)))
128 {
129 if(((!strcmp(authMode, WF_AU_OPEN)) && (!strcmp(encrypType, WF_ENCRY_WEP))) ||
130 (!strcmp(authMode, WF_AU_SHARE)) || (!strcmp(authMode, WF_AU_WEPAUTO)))
131 {
132 int len = 0;
133 len = strlen(password);
134 if(len != 5 && len != 10 && len != 13 && len != 26) //kw 3 ;wep 5,13(no 16)
135 {
xf.libdd93d52023-05-12 07:10:14 -0700136 printf("wlan_ssid1_security_set wep psk len = [%d]\n", len);
lh9ed821d2023-04-07 01:36:19 -0700137 return -1;
138 }
139 sc_cfg_get("DefaultKeyID",DefaultKeyID,sizeof(DefaultKeyID));
140 //kw 3
141 char old_wep_key[WLAN_WEPKEY_LEN] = {0};
142
143 if(!strcmp(DefaultKeyID, "1"))
144 {
145 sc_cfg_get("Key2Str1",old_wep_key,sizeof(old_wep_key));
146 if(strcmp(old_wep_key, password))
147 {
148 sc_cfg_set("Key2Str1", password);
149 //sc_cfg_save();
150 }
151 else
152 {
xf.libdd93d52023-05-12 07:10:14 -0700153 printf("wlan_ssid1_security_set wep psk is same\n");
lh9ed821d2023-04-07 01:36:19 -0700154 return 1;
155 }
156 }
157 else if(!strcmp(DefaultKeyID, "2"))
158 {
159 sc_cfg_get("Key3Str1",old_wep_key,sizeof(old_wep_key));
160
161 if(strcmp(old_wep_key, password))
162 {
163 sc_cfg_set("Key3Str1", password);
164 //sc_cfg_save();
165 }
166 else
167 {
xf.libdd93d52023-05-12 07:10:14 -0700168 printf("wlan_ssid1_security_set wep psk is same\n");
lh9ed821d2023-04-07 01:36:19 -0700169 return 1;
170 }
171 }
172 else if(!strcmp(DefaultKeyID, "3"))
173 {
174 sc_cfg_get("Key4Str1",old_wep_key,sizeof(old_wep_key));
175 if(strcmp(old_wep_key, password))
176 {
177 sc_cfg_set("Key4Str1", password);
178 //sc_cfg_save();
179 }
180 else
181 {
xf.libdd93d52023-05-12 07:10:14 -0700182 printf("wlan_ssid1_security_set wep psk is same\n");
lh9ed821d2023-04-07 01:36:19 -0700183 return 1;
184 }
185 }
186 else
187 {
188 sc_cfg_get("Key1Str1",old_wep_key,sizeof(old_wep_key));
189 if(strcmp(old_wep_key, password))
190 {
191 sc_cfg_set("Key1Str1", password);
192 //sc_cfg_save();
193 }
194 else
195 {
xf.libdd93d52023-05-12 07:10:14 -0700196 printf("wlan_ssid1_security_set wep psk is same\n");
lh9ed821d2023-04-07 01:36:19 -0700197 return 1;
198 }
199 }
200
201 }
202 else if(!strcmp(authMode, WF_AU_OPEN) && !strcmp(encrypType, WF_ENCRY_NONE))
203 {
204 printf("authMode is open and not wep \n");
205 return 1;
206
207 }
208 }
209 else if(!strcmp(authMode, WF_AU_WPA) || !strcmp(authMode, WF_AU_WPA2) || !strcmp(authMode, WF_AU_WPA_WPA2))
210 {
211 char psk[WLAN_PSK_LEN] = {0};
212 int len = 0;
213 char encode[WLAN_ENCODE_PSK_LEN] = {0};
214 len = strlen(password);
215
216 if(len < 8 || len > 64)
217 {
218 printf("%s password len is %d \n",authMode, len);
219 return -1;
220 }
221 sc_cfg_get("WPAPSK1",psk,sizeof(psk));
222 //kw 3
223 if(strcmp(psk, password))
224 {
225 sc_cfg_set("WPAPSK1", password);
226 base64_encode(password, len, encode, WLAN_ENCODE_PSK_LEN);
227 sc_cfg_set("WPAPSK1_encode", encode);
228 //sc_cfg_save();
229 }
230 else
231 {
232 if(!changeSecurityMode)
233 {
234 printf("%s, wpapskwpa2psk psk is same\n", __FUNCTION__);
235 return 1;
236 }
237 }
238
239 }
240 else if(!strcmp(authMode, WF_AU_WAPIPSK))
241 {
242 char psk[WLAN_PSK_LEN] = {0};
243 int len = 0;
244 char encode[WLAN_ENCODE_PSK_LEN] = {0};
245 len = strlen(password);
246
247 if(len < 8 || len > 64)
248 {
249 printf("WF_AU_WAPIPSK password len is %d \n", len);
250 return -1;
251 }
252 sc_cfg_get("WPAPSK1",psk,sizeof(psk));
253 //kw 3
254 if(strcmp(psk, password))
255 {
256 sc_cfg_set("WPAPSK1", password);
257 base64_encode(password, len, encode, WLAN_ENCODE_PSK_LEN);
258 sc_cfg_set("WPAPSK1_encode", encode);
259 //sc_cfg_save();
260 }
261 else
262 {
263 if(!changeSecurityMode)
264 {
265 printf("%s, wapi psk is same\n", __FUNCTION__);
266 return 1;
267 }
268 }
269
270 }
271 else
272 {
273 // other security mode is invalid
274 printf("ERROR:security mode is invalid\n");
275 return -1;
276 }
277
278 return 0;
279}
280
281int zte_wlan_get_ssid1_settings(char* ssid, char* password, int ssid_len, int password_len)
282{
283 char authMode[WLAN_SECURITY_LEN] = {0};
284 char encrypType[WLAN_ENCRYTYPE_LEN] = {0};
285 char DefaultKeyID[WLAN_DEFAULTID_LEN] = {0};
286
287 if(NULL == ssid || NULL == password)
288 {
289 printf("ERROR:input ssid && password is null\n");
290 return -1;
291 }
292
293 //kw 3
294 char old_ssid[WIFI_SSID_LEN] = {0};
295 sc_cfg_get("SSID1",old_ssid,sizeof(old_ssid));
296 strncpy(ssid, old_ssid, ssid_len - 1);
297
298 sc_cfg_get("AuthMode",authMode,sizeof(authMode));
299 sc_cfg_get("EncrypType",encrypType,sizeof(encrypType));
300
xf.libdd93d52023-05-12 07:10:14 -0700301 printf("wlan_ssid1_security_get authMode = [%s]\n", authMode);
302 printf("wlan_ssid1_security_get encrypType = [%s]\n", encrypType);
lh9ed821d2023-04-07 01:36:19 -0700303
304 if((!strcmp(authMode, WF_AU_OPEN)) || (!strcmp(authMode, WF_AU_SHARE)) || (!strcmp(authMode, WF_AU_WEPAUTO)))
305 {
306 if(((!strcmp(authMode, WF_AU_OPEN)) && (!strcmp(encrypType, WF_ENCRY_WEP))) ||
307 (!strcmp(authMode, WF_AU_SHARE)) || (!strcmp(authMode, WF_AU_WEPAUTO)))
308 {
309 sc_cfg_get("DefaultKeyID",DefaultKeyID,sizeof(DefaultKeyID));
310
311 char old_wep_key[WLAN_WEPKEY_LEN] = {0};
312 if(!strcmp(DefaultKeyID, "1"))
313 {
314 sc_cfg_get("Key2Str1",old_wep_key,sizeof(old_wep_key));
315 strncpy(password, old_wep_key, password_len-1);
316 }
317 else if(!strcmp(DefaultKeyID, "2"))
318 {
319 sc_cfg_get("Key3Str1",old_wep_key,sizeof(old_wep_key));
320 strncpy(password, old_wep_key, password_len-1);
321 }
322 else if(!strcmp(DefaultKeyID, "3"))
323 {
324 sc_cfg_get("Key4Str1",old_wep_key,sizeof(old_wep_key));
325 strncpy(password, old_wep_key, password_len-1);
326 }
327 else
328 {
329 sc_cfg_get("Key1Str1",old_wep_key,sizeof(old_wep_key));
330 strncpy(password, old_wep_key, password_len-1);
331 }
332
333 }
334 }
335 else if(!strcmp(authMode, WF_AU_WPA) || !strcmp(authMode, WF_AU_WPA2) || !strcmp(authMode, WF_AU_WPA_WPA2))
336 {
337 char psk[WLAN_PSK_LEN] = {0};
338 sc_cfg_get("WPAPSK1",psk,sizeof(psk));
339 strncpy(password, psk, password_len-1);
340 }
341 else if(!strcmp(authMode, WF_AU_WAPIPSK))
342 {
343 char psk[WLAN_PSK_LEN] = {0};
344 sc_cfg_get("WPAPSK1",psk,sizeof(psk));
345 strncpy(password, psk, password_len-1);
346 }
347 else
348 {
349 return -1;
350 }
351
352 return 0;
353}
354
355int zte_wlan_ssid1_set(char* ssid, char* password)
356{
357 int ret_for_basic = 0;
358 int ret_for_security = 0;
359
360 ret_for_basic = zte_wlan_ssid1_basic_set(ssid);
361 if(-1 == ret_for_basic)
362 {
xf.libdd93d52023-05-12 07:10:14 -0700363 printf("wlan_ssid1_basic_set is false\n");
lh9ed821d2023-04-07 01:36:19 -0700364 return -1;
365 }
366 ret_for_security = zte_wlan_ssid1_security_set(password);
367 if(-1 == ret_for_security)
368 {
xf.libdd93d52023-05-12 07:10:14 -0700369 printf("call lan_ssid1_security_set failure .\n");
lh9ed821d2023-04-07 01:36:19 -0700370 return -1;//kw 3
371 }
372
373 if(ret_for_basic == 0 || ret_for_security == 0)
374 {
375 if(0 == ipc_send_message(MODULE_ID_WLAN_SERVER, MODULE_ID_WIFI, MSG_CMD_WIFI_ADVANCED, 2, "1", 0))
376 {
377 //sc_cfg_set("RadioOff", "0");
378 printf("wifi set cmd done!\n");
379 }
380 else
381 {
xf.libdd93d52023-05-12 07:10:14 -0700382 printf("wifi set cmd wlan_ssid1_set error!\n");
lh9ed821d2023-04-07 01:36:19 -0700383 return -1;
384 }
385 }
386 return 0;
387}
388
389//wifi_hal.c of realtek, in order to capture sta num of va0 and va1(if multi ssid is enabled)
390int zte_wlan_capture_sta_num()
391{
392 int staNum_va0 = 0;
393 int staNum_va1 = 0;
394 int staTotalNum = 0;
395 char radioOff[8] = {0};
396 char mutli_ssid_enable[8] = {0};
397 char wifi_cur_state[8] = {0};
398 //sc_cfg_get("RadioOff",radioOff,sizeof(radioOff));
399 sc_cfg_get("wifi_cur_state",wifi_cur_state,sizeof(wifi_cur_state));
400 sc_cfg_get("m_ssid_enable",mutli_ssid_enable,sizeof(mutli_ssid_enable));
401
402 if( !strncmp(wifi_cur_state,"0",1) )
403 {
404 printf("[%s]wifi is off, can't obtain sta info!!\n",__FUNCTION__);
405 return 0;
406 }
407
408 //staNum_va0 = get_vap_sta_num("wlan0-va0");
409#ifdef __SINGLE_AP__
410 staNum_va0 = get_vap_sta_num("wlan0");
411#else
412 staNum_va0 = get_vap_sta_num("wlan0-va0");
413#endif
414
415 printf("[%s] the Sta Num of Va0 = %d\n",__FUNCTION__,staNum_va0);
416
417 if( !strncmp(mutli_ssid_enable,"1",1))
418 {
419 staNum_va1 = get_vap_sta_num("wlan0-va1");
420 printf("[%s] the Sta Num of Va1 = %d\n",__FUNCTION__,staNum_va1);
421 }
422 if ((staNum_va0 < 0 || staNum_va0 > MAX_WIFI_NUM) ||
423 (staNum_va1 < 0 || staNum_va1 > MAX_WIFI_NUM)) { //kw 3
424 printf("[%s]staNum error: %d,%d!!\n",__FUNCTION__,staNum_va0,staNum_va1);
425 return 0;
426 }
427 staTotalNum = staNum_va0 + staNum_va1;
428 printf("[%s] staTotalNum = %d\n",__FUNCTION__,staTotalNum);
429 return staTotalNum;
430 }
431#if 0
432//get vap sta num, second method:no use of complex algorithms,just read first line of sta_info
433static int get_vap_sta_num(char* vapIface)
434{
435 int sta_num = 0;
436 char buf[128] = {0};
437 FILE *fp = NULL;
438 FILE *fp_num = NULL;
439 printf("[%s] vapIface=%s\n",__FUNCTION__, vapIface);
440 memset(buf,0,sizeof(buf));
441 sprintf(buf, "cat /proc/%s/sta_info > /tmp/lib-stalist-%s", vapIface,vapIface);
442 system(buf);
443
444 memset(buf,0,sizeof(buf));
445 sprintf(buf, "/tmp/lib-stalist-%s",vapIface);
446
447 fp = fopen(buf, "r");
448
449 if(NULL == fp)
450 {
451 fprintf(stderr, "can not open file lib-stalist-%s.",vapIface);
452 return 0;
453 }
454 memset(buf,0,sizeof(buf));
455 sprintf(buf, "cat /tmp/lib-stalist-%s | grep \"active\" | cut -d \':\' -f 2 | cut -d \')\' -f 1 > /tmp/lib-sta-num-%s",vapIface,vapIface);
456 system(buf);
457
458 memset(buf,0,sizeof(buf));
459 sprintf(buf,"/tmp/lib-sta-num-%s",vapIface);
460 fp_num = fopen(buf,"r");
461
462 if(NULL == fp_num)
463 {
464 fprintf(stderr, "can not open file lib-sta-num-%s.",vapIface);
465
466 goto END;
467 }
468
469 fscanf(fp_num,"%d",&sta_num);
470 printf("[%s] sta_num is %d\n",__FUNCTION__,sta_num);
471END:
472 if(NULL != fp)
473 {
474 fclose(fp);
475 }
476
477 if(NULL != fp_num)
478 {
479 fclose(fp_num);
480 }
481
482 return sta_num;
483}
484#endif
485
486//get vap sta num, second method:no use of complex algorithms,just read first line of sta_info
487int get_vap_sta_num(char* vapIface)
488{
489 int sta_num = 0;
490 char sta_num_str[8] = {0};
491 char buf[128] = {0};
492 char sta_info_buf[128] = {0};
493 int sta_info_len = 0;
494 int i, j = 0;
495 FILE *fp = NULL;
496 printf("[%s] vapIface=%s\n",__FUNCTION__, vapIface);
497
498 memset(buf,0,sizeof(buf));
499 sprintf(buf, "/proc/%s/sta_info", vapIface);
500
501 fp = fopen(buf, "r");
502 if(NULL == fp)
503 {
504 fprintf(stderr, "can not open file /proc/%s/sta_info.",vapIface);
505 return 0;
506 }
507 fgets(sta_info_buf,sizeof(sta_info_buf),fp);
508 printf("[%s]sta_info_buf is %s\n",__FUNCTION__,sta_info_buf);
509 if(strcmp(sta_info_buf,"")==0)
510 {
511 printf("[%s]sta_info is null\n",__FUNCTION__);
512 fclose(fp);
513 return 0;
514 }
515 sta_info_len = strlen(sta_info_buf);
516 for(i=0;i<sta_info_len;i++)
517 {
518 if(sta_info_buf[i] >= '0' && sta_info_buf[i] <= '9')
519 {
520 sta_num_str[j++] = sta_info_buf[i];
521 if (j >= sizeof(sta_num_str)-1)//klocwork
522 break;
523 }
524 }
525
526 printf("[%s]sta_num_str:%s\n",__FUNCTION__,sta_num_str);
527
528 sta_num = atoi(sta_num_str);
529
530 printf("[%s]sta_num:%d\n",__FUNCTION__,sta_num);
531 //kw 3
532 fclose(fp);
533
534 return sta_num;
535}
536
537static int zte_station_connect_time_calc(char* timeStr)
538{
539 //timeStr : [1 hr 2 min 3 sec]
540 //char timeStr[32] = {0};
541 char *splited_val = NULL;
542 char *splited_str = NULL;
543 char *delimiter = " ";
544 char *save = NULL;
545 int time = 0;
546 int splited_int = 0;
547
548 //strncpy(timeStr, str, 31);
549 //timeStr[31] = '\0';
550 printf("timeStr %s\n", timeStr);
551 splited_val = strtok_r(timeStr, delimiter, &save);
552 if(NULL != splited_val)
553 {
554 printf("splited_val is %s\n", splited_val);
555 splited_str = strtok_r(NULL, delimiter, &save);
556 }
557 else
558 {
559 printf("splited_val is NULL\n");
560 }
561
562 while(NULL != splited_val && NULL != splited_str)
563 {
564 printf("val %s, str %s\n", splited_val, splited_str);
565 splited_int = atoi(splited_val);
566
567 if(splited_int < 0 || splited_int > INT_MAX-1) {//kw 3
568 printf("[%s]splited_int error: %d!!\n",__FUNCTION__,splited_int);
569 return 0;
570 }
571 if(0 == strncmp(splited_str, "hr", 2))
572 {
573 time += splited_int * 60 * 60;
574 }else if(0 == strncmp(splited_str, "min", 3))
575 {
576 time += splited_int * 60;
577 }else if(0 == strncmp(splited_str, "sec", 3))
578 {
579 time += splited_int;
580 }
581 splited_val = strtok_r(NULL, delimiter, &save);
582 if(NULL != splited_val)
583 {
584 splited_str = strtok_r(NULL, delimiter, &save);
585 }
586 }
587 char temp[32] = {0};
588 sprintf(temp, "%d", time);
589 sc_cfg_set("link_time", temp);
590 return time;
591}
592
593int copyfile(const char *source, const char * target)
594{
595 FILE *fp_s = NULL;
596 FILE *fp_t = NULL;
597 char buf[1024]={0};
598 int lenR = 0;
599 int lenW=0;
600
601 if( NULL== source || NULL == target) return -1;
602 if((fp_s = fopen(source,"r"))== NULL)
603 {
604 printf("[copyfile]sunwenming %s can not be open\n", source);
605 return -1;
606 }
607
608 if((fp_t = fopen(target,"w"))== NULL)
609 {
610 printf("[copyfile]sunwenming %s can not be open\n", target);
611 fclose(fp_s); //kw 3
612 return -1;
613 }
614
615 while((lenR = fread(buf, 1, 1024, fp_s)) > 0)
616 {
617 if((lenW = fwrite(buf, 1, lenR, fp_t)) != lenR)
618 {
619 printf("[copyfile]sunwenming write to %s failed\n", target);
620 fclose(fp_s); //kw 3
621 fclose(fp_t);
622 return -1;
623 }
624 memset(buf, 0, 1024);
625 }
626 //kw 3
627 fclose(fp_s);
628 fclose(fp_t);
629 return 0;
630}
631
632static void zte_get_sta_info_to_file(char * iface,char * authmode)
633{
634 FILE *in_fp = NULL;
635 FILE *out_fp = NULL;
636 FILE *fp = NULL;
637 FILE *tmp_fp = NULL;
638 FILE *tmp_fp1 = NULL;
639 FILE *tmp_fp2 = NULL;
640 FILE *tmp_fp3 = NULL;
641 FILE *tmp_fp4 = NULL;
642
643 char sta_info_buf[128] = {0};
644 char *ptr = NULL;
645 char tmp_buf[128] = {0};
646 char out_buf[128]= {0};
647 char buf[128]= {0};
648
649 memset(buf, 0, sizeof(buf));
650 memset(out_buf, 0, sizeof(buf));
651 sprintf(buf, "/proc/%s/sta_info", iface);
652 sprintf(out_buf, "/tmp/stalist1");
653
654 copyfile(buf,out_buf);
655/*
656 tmp_fp = fopen("/tmp/maclist", "w+");
657 fclose(tmp_fp);
658 tmp_fp = fopen("/tmp/expiredtime", "w+");
659 fclose(tmp_fp);
660 tmp_fp = fopen("/tmp/statelist", "w+");
661 fclose(tmp_fp);
662 tmp_fp = fopen("/tmp/timelist", "w+");
663 fclose(tmp_fp);
664*/
665 fp = fopen("/tmp/stalist1", "r");
666 if(NULL == fp)
667 {
xf.libdd93d52023-05-12 07:10:14 -0700668 printf("[get_sta_info_to_file]can not open file /tmp/stalist1.");
lh9ed821d2023-04-07 01:36:19 -0700669 goto END;
670 }
671 if((tmp_fp1 = fopen("/tmp/maclist", "w+")) == NULL){
xf.libdd93d52023-05-12 07:10:14 -0700672 printf("[get_sta_info_to_file] can not open /tmp/maclist\n");
lh9ed821d2023-04-07 01:36:19 -0700673 goto END;
674
675 }
676 if((tmp_fp2 = fopen("/tmp/expiredtime", "w+")) == NULL){
xf.libdd93d52023-05-12 07:10:14 -0700677 printf("[get_sta_info_to_file] can not open /tmp/expiredtime\n");
lh9ed821d2023-04-07 01:36:19 -0700678 goto END;
679
680 }
681 if((tmp_fp3 = fopen("/tmp/statelist", "w+")) == NULL) {
xf.libdd93d52023-05-12 07:10:14 -0700682 printf("[get_sta_info_to_file] can not open /tmp/statelist\n");
lh9ed821d2023-04-07 01:36:19 -0700683 goto END;
684
685 }
686 if((tmp_fp4 = fopen("/tmp/timelist", "w+")) ==NULL){
xf.libdd93d52023-05-12 07:10:14 -0700687 printf("[get_sta_info_to_file] can not open /tmp/timelist\n");
lh9ed821d2023-04-07 01:36:19 -0700688 goto END;
689 }
690
691 while(!feof(fp))
692 {
693 fgets(sta_info_buf,sizeof(sta_info_buf),fp);
694 if((strstr(sta_info_buf,"hwaddr")) != NULL)
695 {
696 fputs(sta_info_buf,tmp_fp1);
697 }
698 else if((strstr(sta_info_buf,"expired_time")) != NULL)
699 {
700 fputs(sta_info_buf,tmp_fp2);
701 }
702 else if (((strstr(sta_info_buf,"ieee8021x_ctrlport")) != NULL)&&((!strcmp(authmode,"WPAPSK"))||(!strcmp(authmode,"WPA2PSK"))||(!strcmp(authmode,"WPAPSKWPA2PSK"))||(!strcmp(authmode,"WPA3Personal"))||(!strcmp(authmode,"WPA2WPA3"))))
703 {
704 fputs(sta_info_buf,tmp_fp3);
705 }
706 else if(((strstr(sta_info_buf,"wapi_state")) != NULL)&&(!strcmp(authmode,"WAPIPSK")))
707 {
708 fputs(sta_info_buf,tmp_fp3);
709 }
710 else if((strstr(sta_info_buf,"link_time")) != NULL)
711 {
712 fputs(sta_info_buf,tmp_fp4);
713 }
714 }
715
716END:
717 if(fp != NULL)fclose(fp);
718 if(tmp_fp1 != NULL)fclose(tmp_fp1);
719 if(tmp_fp2 != NULL)fclose(tmp_fp2);
720 if(tmp_fp3 != NULL)fclose(tmp_fp3);
721 if(tmp_fp4 != NULL)fclose(tmp_fp4);
722 return;
723}
724
725static void zte_get_vap_sta_list(RT_802_11_MAC_TABLE *staList, char * iface)
726{
727 int i = 0;
728 int s = 0;
729 int k = 0;
730 int j = 0;
731 int index = 0;
732 int state_index = 0;
733 int ssid_index = 0;
734 char authmode[20] = {0};
735 char buf[128] = {0};
736 char connectTime[33] = {0};
737 char staNum[3] = {0};
738 char num_tmp[3] = {0};
739 char mac_tmp[18] = {0};
740 char state[3] = {0};//klocwork
741 char *p = NULL;
742 char *p_tmp = NULL;
743 char *p1= NULL;
744 char *p_tmp1 = NULL;
745 char *p2= NULL;
746 char *p_tmp2 = NULL;
747
748 //FILE *p_stalist1 = NULL;
749 FILE *p_maclist = NULL;
750 FILE *p_timelist = NULL;
751 FILE *p_statelist = NULL;
752 FILE *p_expiredtime = NULL;
753 int state_flag[MAX_WIFI_NUM] = {-1};
754 int expiredtime_flag[MAX_WIFI_NUM] = {-1};
755 char mac_time[33] = {0};
756 char expiredtime[4] = {0};
757 int security_flag = 0;
758
759 printf("\n[%s][%s] iface = %s\n",__FILE__, __FUNCTION__, iface);
760
761#ifdef __SINGLE_AP__
762 if(!strcmp(iface,"wlan0"))
763#else
764 if(!strcmp(iface,"wlan0-va0"))
765#endif
766 {
767 ssid_index = 1;
768 sc_cfg_get("AuthMode",authmode,sizeof(authmode));
769 }
770 else if(!strcmp(iface,"wlan0-va1"))
771 {
772 ssid_index = 2;
773 sc_cfg_get("m_AuthMode",authmode,sizeof(authmode));
774 }
775
776 zte_get_sta_info_to_file(iface,authmode);
777
778// memset(buf, 0, sizeof(buf));
779// sprintf(buf, "cat /proc/%s/sta_info > /tmp/stalist1", iface);
780// system(buf);
781// p_stalist1 = fopen("/tmp/stalist1", "r");
782// if(NULL == p_stalist1)
783// {
784// fprintf(stderr, "can not open file /tmp/stalist1.");
785// return;
786// }
787
788// system("cat /tmp/stalist1 | grep \"hwaddr\" > /tmp/maclist");
789 p_maclist = fopen("/tmp/maclist", "r");
790 if(NULL == p_maclist)
791 {
792 fprintf(stderr, "can not open file /tmp/maclist.");
793 goto END;
794 }
795
796// system("cat /tmp/stalist1 | grep \"expired_time\" > /tmp/expiredtime");
797 p_expiredtime = fopen("/tmp/expiredtime", "r");
798 if(NULL == p_expiredtime)
799 {
800 fprintf(stderr, "can not open file /tmp/expiredtime.");
801 goto END;
802 }
803
804 memset(buf, 0, sizeof(buf));
805 i = 0;
806 while(!(feof(p_expiredtime)))
807 {
808 while(fgets(buf, sizeof(buf), p_expiredtime))
809 {
810 memset(expiredtime, 0, 4);
811 if((p2 = strstr(buf, ":")) != NULL)
812 {
813 p_tmp2 = p2+2;
814 strncpy(expiredtime, p_tmp2, 3);
815 if(atoi(expiredtime) > 0) //kw 3
816 {
817 expiredtime_flag[index] = i;
818 printf("\n [%s] expiredtime_flag[%d] is %d\n", iface, index, expiredtime_flag[index]);
819 index++;
820 }
821 i++;
822 }
823 memset(buf, 0, sizeof(buf));
824 }
825 }
826
827 if((!strcmp(authmode,"WPAPSK"))||(!strcmp(authmode,"WPA2PSK"))||(!strcmp(authmode,"WPAPSKWPA2PSK"))||(!strcmp(authmode,"WPA3Personal"))||(!strcmp(authmode,"WPA2WPA3")))
828 {
829// system("cat /tmp/stalist1 | grep \"ieee8021x_ctrlport\" > /tmp/statelist");
830 p_statelist = fopen("/tmp/statelist", "r");
831 if(NULL == p_statelist)
832 {
833 fprintf(stderr, "can not open file /tmp/statelist.");
834 goto END;
835 }
836 memset(buf, 0, sizeof(buf));
837 security_flag = 1;
838 i = 0;
839 index = 0;
840 while(!(feof(p_statelist)))
841 {
842 while(fgets(buf, sizeof(buf), p_statelist))
843 {
844 memset(state, 0, 3);
845 if((p1 = strstr(buf, ":")) != NULL)
846 {
847 p_tmp1 = p1+2;
848 strncpy(state, p_tmp1, 1);
849 if(expiredtime_flag[index] == i)
850 {
851 if(!strcmp(state, "1"))
852 {
853 state_flag[state_index] = i;
854 state_index++;
855 }
856 index++;
857 }
858 i++;
859 }
860 memset(buf, 0, sizeof(buf));
861 }
862 }
863 }
864 else if(!strcmp(authmode,"WAPIPSK"))
865 {
866// system("cat /tmp/stalist1 | grep \"wapi_state\" > /tmp/statelist");
867 p_statelist = fopen("/tmp/statelist", "r");
868 if(NULL == p_statelist)
869 {
870 fprintf(stderr, "can not open file /tmp/statelist.");
871 goto END;
872 }
873 memset(buf, 0, sizeof(buf));
874 security_flag = 1;
875 i = 0;
876 index = 0;
877 while(!(feof(p_statelist)))
878 {
879 while(fgets(buf, sizeof(buf), p_statelist))
880 {
881 memset(state, 0, 3);
882 if((p1 = strstr(buf, ":")) != NULL)
883 {
884 p_tmp1 = p1+2;
885 strncpy(state, p_tmp1, 2);
886 if(expiredtime_flag[index] == i)
887 {
888 if(!strcmp(state, "13"))
889 {
890 state_flag[state_index] = i;
891 state_index++;
892 }
893 index++;
894 }
895 i++;
896 }
897 memset(buf, 0, sizeof(buf));
898 }
899 }
900 }
901 index = 0;
902 state_index = 0;
903 i = 0;
904 memset(buf, 0, sizeof(buf));
905 while(!(feof(p_maclist)))
906 {
907 while(fgets(buf, sizeof(buf), p_maclist))
908 {
909 memset(mac_tmp, 0, 18);
910 if((p = strstr(buf, ":")) != NULL)
911 {
912 if(((security_flag == 1) && (state_flag[state_index] == i)) || ((security_flag == 0) && (expiredtime_flag[index] == i)))
913 {
914 p_tmp = p+2;
915 strncpy(mac_tmp, p_tmp, 12);
916 for(s=0,k=0; s<6; s++,k+=2)
917 {
918 memset(num_tmp, 0 ,3);
919 strncpy(num_tmp, mac_tmp + k, 2);
920 num_tmp[2] = '\0';
921 staList->Entry[staList->Num].Addr[s] = s2x(num_tmp);
922 }
923 staList->Entry[staList->Num].SSID_index = ssid_index;
924 staList->Num += 1;
925 if(security_flag == 1)
926 {
927 state_index++;
928 }
929 else
930 {
931 index++;
932 }
933 }
934 i++;
935 }
936 memset(buf, 0, sizeof(buf));
937 }
938 }
939
940// system("cat /tmp/stalist1 | grep \"link_time\" > /tmp/timelist");
941 p_timelist = fopen("/tmp/timelist", "r");
942 if(NULL == p_timelist)
943 {
944 printf("[%s]can not open file /tmp/timelist.\n", __FUNCTION__);
945 goto END;
946 }
947 memset(buf, 0, sizeof(buf));
948 p = NULL;
949 p_tmp = NULL;
950 i = 0;
951 state_index = 0;
952 index = 0;
953 while(!(feof(p_timelist)))
954 {
955 while(fgets(buf, sizeof(buf), p_timelist))
956 {
957 memset(mac_time,0,33);
958
959 if((p = strstr(buf, ":")) != NULL)
960 {
961 if(((security_flag == 1) && (state_flag[state_index] == i)) || ((security_flag == 0) && (expiredtime_flag[index] == i)))
962 {
963
964 p_tmp = p+2;
965 strncpy(mac_time,p_tmp,32);
966 //kw 3
967 staList->Entry[j].ConnectedTime = zte_station_connect_time_calc(mac_time);
968 j++;
969 if(security_flag == 1)
970 {
971 state_index++;
972 }
973 else
974 {
975 index++;
976 }
977 }
978 i++;
979 }
980 memset(buf, 0, sizeof(buf));
981
982 }
983 }
984
985 /*ȡWIFI նʱ*/
986END:
987 //if(NULL != p_stalist1) fclose(p_stalist1);//kw 3
988 if(NULL != p_maclist) fclose(p_maclist);
989 if(NULL != p_timelist)fclose(p_timelist);
990 if(NULL != p_statelist)fclose(p_statelist);
991 if(NULL != p_expiredtime)fclose(p_expiredtime);
992}
993
994void zte_get_wifi_sta_list(RT_802_11_MAC_TABLE *staList)
995{
996 int i = 0, j=0;
997 char m_ssid_enable[8]={0};
998 RT_802_11_MAC_TABLE staList_va0={0};
999 RT_802_11_MAC_TABLE staList_va1={0};
1000 char station_mac[32*18] = {0};
1001 char station_mac_tmp[32*18] = {0};
1002 char staNum[12]={0};
1003 char RaidoOff[8]={0};
1004 char wifi_cur_state[8]={0};
1005 //sc_cfg_get("RadioOff",RaidoOff,sizeof(RaidoOff));
1006 sc_cfg_get("wifi_cur_state",wifi_cur_state,sizeof(wifi_cur_state));
1007 if(atoi(wifi_cur_state) == 0)
1008 {
1009 printf("wifi is Off, can not read sta_info\n");
1010 //sc_cfg_set("wificount", staNum);
1011 //sc_cfg_set("station_num", staNum);
1012 sc_cfg_set("station_mac", station_mac_tmp);
1013 return;
1014 }
1015 sc_cfg_get("m_ssid_enable", m_ssid_enable, sizeof(m_ssid_enable));
1016
1017#ifdef __SINGLE_AP__
1018 zte_get_vap_sta_list(&staList_va0,"wlan0");
1019#else
1020 zte_get_vap_sta_list(&staList_va0,"wlan0-va0");
1021
1022#endif
1023
1024 printf("\n[%s] staList_va0->Num=%d\n",__FUNCTION__, staList_va0.Num);
1025// copy staList_va0 to staList
1026 staList->Num = staList_va0.Num;
1027 for (i = 0; i < staList_va0.Num; i++)
1028 {
1029 memcpy((void*)&staList->Entry[i],(void*)&staList_va0.Entry[i], sizeof(RT_802_11_MAC_ENTRY));
1030 sprintf(station_mac + i * 18, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X;",\
1031 staList->Entry[i].Addr[0], staList->Entry[i].Addr[1],
1032 staList->Entry[i].Addr[2], staList->Entry[i].Addr[3],
1033 staList->Entry[i].Addr[4], staList->Entry[i].Addr[5]);
1034 }
1035
1036 printf("[%s] m_ssid_enable=%s\n",__FUNCTION__, m_ssid_enable);
1037 if(atoi(m_ssid_enable) == 1)
1038 {
1039 zte_get_vap_sta_list(&staList_va1,"wlan0-va1");
1040// copy staList_va1 to staList
1041 printf("\n[%s] staList_va1->Num=%d\n",__FUNCTION__, staList_va1.Num);
1042 staList->Num += staList_va1.Num;
1043 for (i = staList_va0.Num,j =0; i < staList->Num; i++,j++)
1044 {
1045 memcpy((void*)&staList->Entry[i],(void*)&staList_va1.Entry[j], sizeof(RT_802_11_MAC_ENTRY));
1046 sprintf(station_mac + i * 18, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X;",\
1047 staList->Entry[i].Addr[0], staList->Entry[i].Addr[1],
1048 staList->Entry[i].Addr[2], staList->Entry[i].Addr[3],
1049 staList->Entry[i].Addr[4], staList->Entry[i].Addr[5]);
1050 }
1051 }
1052 sprintf(staNum, "%d", staList->Num);
1053 //sc_cfg_set("wificount", staNum);
1054 //sc_cfg_set("station_num", staNum);
1055
1056 if (staList->Num != 0)
1057 {
1058 strncpy(station_mac_tmp, station_mac, strlen(station_mac) - 1);
1059 }
1060 sc_cfg_set("station_mac", station_mac_tmp);
1061}
1062#if 0 //kw 3
1063int get_channel()
1064{
1065 char channel[8] = {0};
1066 pipecmd("iwpriv wlan0 get_mib channel |cut -d':' -f2", channel);
1067 return atoi(channel);
1068}
1069#endif