yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame^] | 1 |
|
| 2 |
|
| 3 | /*Í·Îļþ*/
|
| 4 | #include "wifi_util.h"
|
| 5 | #include "wifi.h"
|
| 6 | //#include "wlan-server.h"
|
| 7 | #include "wifi_hal.h"
|
| 8 | #include "wifi_drv_ko.h"
|
| 9 | #include "rtk_arch.h"
|
| 10 | #include "wlan-station.h"
|
| 11 | #include <sys/wait.h>
|
| 12 | #include <ctype.h>
|
| 13 | #include <wifi_ap_ctrl.h>
|
| 14 | #include <wlan_rtc_sleep.h>
|
| 15 | /*ºê¶¨Òå*/
|
| 16 |
|
| 17 | #define CONFIG_DIR WIFI_CONFIG_ROOT_DIR"/wlan0"
|
| 18 | #define CONFIG_DIR_VA0 WIFI_CONFIG_ROOT_DIR"/wlan0-va0"
|
| 19 | #define CONFIG_DIR_VA1 WIFI_CONFIG_ROOT_DIR"/wlan0-va1"
|
| 20 | #define CONFIG_DIR_VXD WIFI_CONFIG_ROOT_DIR"/wlan0-vxd"
|
| 21 | #define INITSH WIFI_SCRIPT_DIR"/init.sh"
|
| 22 | #define INITSH1 WIFI_SCRIPT_DIR"/init1.sh"
|
| 23 | #define PARASET WIFI_SCRIPT_DIR"/para_set.sh"
|
| 24 | #define PARASET1 WIFI_SCRIPT_DIR"/para_set1.sh"
|
| 25 | #define WLAN_DEAL WIFI_SCRIPT_DIR"/wlan_basic_deal.sh"
|
| 26 |
|
| 27 | #define WSCD_CONFIG_STATUS (WIFI_WPS_TMP_DIR "/wscd_status")
|
| 28 | #define WSCD_LAST_SUCCESS_ENROLLEE (WIFI_WPS_TMP_DIR "/wscd_enrollee")
|
| 29 |
|
| 30 |
|
| 31 | #define SHORT_MODE_DEC 22
|
| 32 |
|
| 33 | #define MEDIUM_MODE_DEC 8
|
| 34 |
|
| 35 | #define MAX_STA_NUM 32
|
| 36 |
|
| 37 | extern struct wlan_ap_server * ap_server ;
|
| 38 | /*±äÁ¿ÉùÃ÷*/
|
| 39 | int g_get_access_sta_count = 0;
|
| 40 | int wps_rtc_timer_open = 0;
|
| 41 | char g_wps_sta_mac[32] = {0};
|
| 42 |
|
| 43 | int g_wifi_inited=0;
|
| 44 |
|
| 45 | extern char g_wps_sta_mac[32];//wpsÁ¬½ÓµÄsta mac
|
| 46 |
|
| 47 |
|
| 48 | static char old_accesspolicy[2] = {0};//¼Ç¼ºÚor°×Ãûµ¥
|
| 49 | static CHAR g_old_acl_black_mac[MAX_STA_NUM][13] = {{0}};//ÒÑÉèÖõĺÚÃûµ¥macÁбí
|
| 50 | static int g_old_acl_black_mac_num = 0;//ÒÑÉèÖõĺÚÃûµ¥¸öÊý
|
| 51 | static CHAR g_old_acl_white_mac[MAX_STA_NUM][13] = {{0}};//ÒÑÉèÖõİ×Ãûµ¥macÁбí
|
| 52 | static int g_old_acl_white_mac_num = 0;//ÒÑÉèÖõİ×Ãûµ¥¸öÊý
|
| 53 | static char g_acl_mode[2] = {0};//acl mode:0(none) 1(white) 2(black)
|
| 54 |
|
| 55 |
|
| 56 | /**************************ºê¶¨Òå*************************/
|
| 57 |
|
| 58 | #define WAKE_UP_TIME 5
|
| 59 | #define WPS_STATION_ACCESS_CHECK_ALL_PERIOD 15
|
| 60 | #define WPS_STATION_ACCESS_CHECK_PERIOD 3
|
| 61 | /**********mmi wlan wps status***************/
|
| 62 | #define WPS_ACTIVING "0"
|
| 63 | #define WPS_ACTIVED "1"
|
| 64 | #define WPS_DEACTIVING "2"
|
| 65 | #define WPS_DEACTIVED "3"
|
| 66 | #define WPS_ACTIVE_MAX "4"
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 | /*º¯ÊýÉùÃ÷*/
|
| 71 | static int wlan_get_mac_list (char* station_mac, char* athx);
|
| 72 | extern char* translateStringToEcho (char* inputStr, char* outputStr);
|
| 73 | void wps_down();
|
| 74 | extern void acl_mode_set();
|
| 75 | void basic_deal (struct wlan_ap_server *ap_svr, int cmd);
|
| 76 | void wlan_generate_para_file();
|
| 77 |
|
| 78 | struct wlan_ap_server realtek_8192_ap = {
|
| 79 |
|
| 80 | .sock ={
|
| 81 | .iface_name = "wlan0",
|
| 82 | .sockets_dir = "/etc_rw/wifi/hostapd",
|
| 83 | },
|
| 84 | .drv_proxy =
|
| 85 | {
|
| 86 |
|
| 87 | .drv_init_flag = 1, //realtek do not use ko, so set it has been inited
|
| 88 | .iface_name = "wlan0-vxd",
|
| 89 | .drv_init = wlan_drv_init,
|
| 90 | .drv_deinit = wlan_drv_deinit,
|
| 91 | },
|
| 92 | .init = wlan_generate_para_file,
|
| 93 | .basic_deal = basic_deal,
|
| 94 | };
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 | #ifdef __SINGLE_AP__
|
| 100 |
|
| 101 | static void startPINWPS (char *pin)
|
| 102 | {
|
| 103 | char cmd[48] = {0};
|
| 104 |
|
| 105 | if (NULL != pin) {
|
| 106 | sprintf (cmd, WIFI_SCRIPT_DIR"/wps_init1.sh pin %s", pin);
|
| 107 | } else {
|
| 108 | sprintf (cmd, WIFI_SCRIPT_DIR"/wps_init1.sh pin %s", "12345670");
|
| 109 | perror ("startPINWPS pin is NULL\n");
|
| 110 | }
|
| 111 | wf_log ("startPINWPS cmd=%s", cmd);
|
| 112 | zxic_system(cmd); //kw 3
|
| 113 | }
|
| 114 |
|
| 115 | static void startPBCWPS()
|
| 116 | {
|
| 117 | system (WIFI_SCRIPT_DIR"/wps_init1.sh pbc");
|
| 118 | }
|
| 119 |
|
| 120 | #else
|
| 121 | static void startPINWPS (char *pin)
|
| 122 | {
|
| 123 | char cmd[48] = {0};
|
| 124 |
|
| 125 | if (NULL != pin) {
|
| 126 | sprintf (cmd, WIFI_SCRIPT_DIR"/wps_init.sh pin %s", pin);
|
| 127 | } else {
|
| 128 | sprintf (cmd, WIFI_SCRIPT_DIR"/wps_init.sh pin %s", "12345670");
|
| 129 | perror ("startPINWPS pin is NULL\n");
|
| 130 | }
|
| 131 | wf_log ("startPINWPS cmd=%s", cmd);
|
| 132 | zxic_system(cmd);
|
| 133 | }
|
| 134 |
|
| 135 | static void startPBCWPS()
|
| 136 | {
|
| 137 | system (WIFI_SCRIPT_DIR"/wps_init.sh pbc");
|
| 138 | }
|
| 139 |
|
| 140 | #endif
|
| 141 |
|
| 142 |
|
| 143 | static VOID wlan_set_countryCode()
|
| 144 | {
|
| 145 | CHAR countryCode[10] = {0};
|
| 146 |
|
| 147 | cfg_get_item ("CountryCode", countryCode, sizeof (countryCode));
|
| 148 | if ( (strcmp (countryCode, "NONE")) && (strcmp (countryCode, " "))) {
|
| 149 | wlan_write_file (CONFIG_DIR"/countrycode_enable", "1");
|
| 150 | wlan_write_file (CONFIG_DIR"/countrycode", countryCode);
|
| 151 | } else {
|
| 152 | wlan_write_file (CONFIG_DIR"/countrycode_enable", "0");
|
| 153 | }
|
| 154 | }
|
| 155 |
|
| 156 | static VOID wlan_set_apmode()
|
| 157 | {
|
| 158 | wlan_write_file (CONFIG_DIR"/wlan_mode", "0");
|
| 159 | }
|
| 160 |
|
| 161 |
|
| 162 | static VOID wlan_RF_config (CHAR *wirelessMode)
|
| 163 | {
|
| 164 | CHAR htMode[2] = {0};
|
| 165 | cfg_get_item ("wifi_11n_cap", htMode, sizeof (htMode));
|
| 166 |
|
| 167 | //20M bandwidth
|
| 168 | if ((!strcmp (htMode, "0"))
|
| 169 | || ( (!strcmp (htMode, "1")) && ( (NULL != wirelessMode) && ((!strcmp (wirelessMode, "0")) || (!strcmp (wirelessMode, "1")) || (!strcmp (wirelessMode, "3")))))) {
|
| 170 | wlan_write_file (CONFIG_DIR"/coexist_enabled", "0");
|
| 171 | wlan_write_file (CONFIG_DIR"/channel_bonding", "0");
|
| 172 | }
|
| 173 | //20M/40M bandwidth auto
|
| 174 | else if ( (!strcmp (htMode, "1")) && ( (NULL != wirelessMode) && ((!strcmp (wirelessMode, "2")) || (!strcmp (wirelessMode, "4"))))) {
|
| 175 | wlan_write_file (CONFIG_DIR"/coexist_enabled", "1");
|
| 176 | wlan_write_file (CONFIG_DIR"/channel_bonding", "1");
|
| 177 | } else {
|
| 178 | wlan_write_file (CONFIG_DIR"/coexist_enabled", "1");
|
| 179 | wlan_write_file (CONFIG_DIR"/channel_bonding", "1");
|
| 180 | }
|
| 181 |
|
| 182 | }
|
| 183 |
|
| 184 | static VOID wlan_rate_config (UINT8 *wirelessMode, UINT8 *wifiBand)
|
| 185 | {
|
| 186 | if (!strcmp (wifiBand, "b")) {
|
| 187 | wlan_write_file (CONFIG_DIR"/rate_adaptive_enabled", "1");
|
| 188 | wlan_write_file (CONFIG_DIR"/fix_rate", "0");
|
| 189 | } else if (strcmp (wifiBand, "b")) {
|
| 190 | wlan_write_file (CONFIG_DIR"/rate_adaptive_enabled", "1");
|
| 191 | wlan_write_file (CONFIG_DIR"/fix_rate", "0");
|
| 192 | }
|
| 193 | }
|
| 194 |
|
| 195 | static VOID wlan_80211Mode_config()
|
| 196 | {
|
| 197 | CHAR wirelessMode[2] = {0};
|
| 198 | CHAR wifiBand[2] = {0};
|
| 199 |
|
| 200 | cfg_get_item ("WirelessMode", wirelessMode, sizeof (wirelessMode));
|
| 201 | cfg_get_item ("wifi_band", wifiBand, sizeof (wifiBand));
|
| 202 |
|
| 203 |
|
| 204 | if ( (!strcmp (wirelessMode, "4")) && (!strcmp (wifiBand, "b"))) {//11b/g/n mixed mode
|
| 205 | wlan_write_file (CONFIG_DIR"/band", "11");
|
| 206 | }
|
| 207 | else if ( (!strcmp (wirelessMode, "2")) && (!strcmp (wifiBand, "b"))) {//11n
|
| 208 | wlan_write_file (CONFIG_DIR"/band", "8");
|
| 209 | }
|
| 210 | else if ( (!strcmp (wirelessMode, "0")) && (!strcmp (wifiBand, "b"))) {//11b only
|
| 211 | wlan_write_file (CONFIG_DIR"/band", "1");
|
| 212 | }
|
| 213 | else if ( (!strcmp (wirelessMode, "1")) && (!strcmp (wifiBand, "b"))) {//11g only
|
| 214 | wlan_write_file (CONFIG_DIR"/band", "2");
|
| 215 | }
|
| 216 | else if ( (!strcmp (wirelessMode, "3")) && (!strcmp (wifiBand, "b"))) {//11b/g
|
| 217 | wlan_write_file (CONFIG_DIR"/band", "3");
|
| 218 | } else {
|
| 219 | wlan_write_file (CONFIG_DIR"/band", "11");
|
| 220 | }
|
| 221 |
|
| 222 | wlan_RF_config (wirelessMode);
|
| 223 | wlan_rate_config (wirelessMode, wifiBand);
|
| 224 | }
|
| 225 |
|
| 226 |
|
| 227 | static VOID wlan_set_wifiConverage()
|
| 228 | {
|
| 229 | CHAR wifiCoverage[16] = {0};
|
| 230 | CHAR file_path_buf[100] = {0};
|
| 231 |
|
| 232 | cfg_get_item ("wifi_coverage", wifiCoverage, sizeof (wifiCoverage));
|
| 233 | sprintf (file_path_buf, "%s/tx_power_percet", CONFIG_DIR);
|
| 234 |
|
| 235 | if (!strcmp (wifiCoverage, "short_mode")) {
|
| 236 | wlan_write_file (CONFIG_DIR"/tx_power_percet", "40");
|
| 237 | } else if (!strcmp (wifiCoverage, "medium_mode")) {
|
| 238 | wlan_write_file (CONFIG_DIR"/tx_power_percet", "70");
|
| 239 | } else { //long mode
|
| 240 | wlan_write_file (CONFIG_DIR"/tx_power_percet", "100");
|
| 241 | }
|
| 242 | }
|
| 243 |
|
| 244 | static void wlan_set_channel_for_lte (int changeMode, char* htMode)
|
| 245 | {
|
| 246 | CHAR file_path_buf[100] = {0};
|
| 247 |
|
| 248 | wf_log (">>wlan_set_channel_for_lte changeMode is %d", changeMode);
|
| 249 | if (changeMode == 2) { //TDD
|
| 250 | wlan_write_file (CONFIG_DIR"/channel", "11");
|
| 251 |
|
| 252 | if ( (NULL != htMode) && (!strcmp (htMode, "1"))) {
|
| 253 | wlan_write_file (CONFIG_DIR"/control_sideband", "0");
|
| 254 | }
|
| 255 | } else if (changeMode == 1) { //FDD
|
| 256 | wlan_write_file (CONFIG_DIR"/channel", "1");
|
| 257 | if ( (NULL != htMode) && (!strcmp (htMode, "1"))) {
|
| 258 | wlan_write_file (CONFIG_DIR"/control_sideband", "1");
|
| 259 | }
|
| 260 | }
|
| 261 | }
|
| 262 |
|
| 263 | static VOID wlan_set_channel()
|
| 264 | {
|
| 265 | CHAR autoChannelSelect[2] = {0};
|
| 266 | CHAR channel[3] = {0};
|
| 267 | CHAR file_path_buf[100] = {0};
|
| 268 | CHAR htMode[2] = {0};
|
| 269 |
|
| 270 |
|
| 271 | cfg_get_item ("wifi_11n_cap", htMode, sizeof (htMode));
|
| 272 | cfg_get_item ("Channel", channel, sizeof (channel));
|
| 273 |
|
| 274 |
|
| 275 | if ( (!strcmp (channel, "")) || (!strcmp (channel, "0"))) {
|
| 276 | //cfg_set ("AutoChannelSelect" , "1");
|
| 277 | wf_log("wlan_set_channel AutoChannelSelect \n");
|
| 278 | strcpy(autoChannelSelect, "1");
|
| 279 | } else {
|
| 280 | //cfg_set ("AutoChannelSelect" , "0");
|
| 281 | wf_log("wlan_set_channel AutoChannelSelect not \n");
|
| 282 | strcpy(autoChannelSelect, "0");
|
| 283 | }
|
| 284 |
|
| 285 | if (strcmp (autoChannelSelect, "1")) {
|
| 286 | wlan_write_file (CONFIG_DIR"/channel", channel);
|
| 287 | memset (file_path_buf, 0, 100);
|
| 288 | if (!strcmp (htMode, "1")) {
|
| 289 | if (atoi (channel) < 5) {
|
| 290 | wlan_write_file (CONFIG_DIR"/control_sideband", "1");
|
| 291 | } else {
|
| 292 | wlan_write_file (CONFIG_DIR"/control_sideband", "0");
|
| 293 | }
|
| 294 | }
|
| 295 | } else { //auto channel
|
| 296 | wlan_write_file (CONFIG_DIR"/channel", "0");
|
| 297 | }
|
| 298 | }
|
| 299 |
|
| 300 | static VOID wlan_set_maxassoc()
|
| 301 | {
|
| 302 | CHAR maxAccessNum[8] = {0};
|
| 303 | CHAR max_sta_num_str[8] = {0};
|
| 304 |
|
| 305 | cfg_get_item ("MAX_Access_num", maxAccessNum, sizeof (maxAccessNum));
|
| 306 |
|
| 307 | if (atoi (maxAccessNum) < MAX_STA_NUM) {
|
| 308 | wlan_write_file (CONFIG_DIR"/supported_sta_num", maxAccessNum);
|
| 309 | } else {
|
| 310 | sprintf (max_sta_num_str, "%d", MAX_STA_NUM);
|
| 311 | wlan_write_file (CONFIG_DIR"/supported_sta_num", max_sta_num_str);
|
| 312 | }
|
| 313 | }
|
| 314 |
|
| 315 | static VOID wlan_set_bss()
|
| 316 | {
|
| 317 | CHAR ssid[33] = {0};
|
| 318 | CHAR wifi_mac[20] = {0};
|
| 319 | CHAR tmp_mac[20] = {0};
|
| 320 | CHAR tmp_ssid[65] = {0};
|
| 321 |
|
| 322 | cfg_get_item ("SSID1", ssid, sizeof (ssid));
|
| 323 | cfg_get_item ("m_wifi_mac", wifi_mac, sizeof (wifi_mac));
|
| 324 |
|
| 325 | translateStringToEcho (ssid, tmp_ssid);// ²»Ê¹ÓÃecho ºó£¬ÊÇ·ñ¿ÉÒÔÖ±½ÓдÈëÎļþ£¿²âÊÔ½á¹û£¿£¿
|
| 326 | wlan_write_file (CONFIG_DIR"/ssid", tmp_ssid);
|
| 327 |
|
| 328 | if(strlen(wifi_mac)==0) return;
|
| 329 |
|
| 330 | sprintf (tmp_mac, "%c%c%c%c%c%c%c%c%c%c%c%c", wifi_mac[0], wifi_mac[1], wifi_mac[3], wifi_mac[4], wifi_mac[6], wifi_mac[7], wifi_mac[9], wifi_mac[10], wifi_mac[12], wifi_mac[13], wifi_mac[15], wifi_mac[16]);
|
| 331 | wlan_write_file (CONFIG_DIR"/wlan0_addr", tmp_mac);
|
| 332 |
|
| 333 | }
|
| 334 |
|
| 335 | static VOID wlan_set_hideSSID()
|
| 336 | {
|
| 337 | CHAR hideSSID[2] = {0};
|
| 338 | CHAR file_path_buf[100] = {0};
|
| 339 |
|
| 340 | cfg_get_item ("HideSSID", hideSSID, sizeof (hideSSID));
|
| 341 |
|
| 342 | if (!strcmp (hideSSID, "1")) {
|
| 343 | wlan_write_file (CONFIG_DIR"/hidden_ssid", "1");
|
| 344 | } else {
|
| 345 | wlan_write_file (CONFIG_DIR"/hidden_ssid", "0");
|
| 346 | }
|
| 347 | }
|
| 348 |
|
| 349 | static VOID wlan_set_aggregation()
|
| 350 | {
|
| 351 | wlan_write_file (CONFIG_DIR"/aggregation", "1");
|
| 352 | }
|
| 353 |
|
| 354 | static VOID wlan_set_wmm()
|
| 355 | {
|
| 356 | wlan_write_file (CONFIG_DIR"/wmm_enabled", "1");
|
| 357 | }
|
| 358 |
|
| 359 | static VOID wlan_set_NoForwarding()
|
| 360 | {
|
| 361 | CHAR isolate[2] = {0};
|
| 362 |
|
| 363 | cfg_get_item ("NoForwarding", isolate, sizeof (isolate));
|
| 364 |
|
| 365 | if (!strcmp (isolate, "1")) {
|
| 366 | wlan_write_file (CONFIG_DIR"/block_relay", "1");
|
| 367 | } else {
|
| 368 | wlan_write_file (CONFIG_DIR"/block_relay", "0");
|
| 369 | }
|
| 370 | }
|
| 371 |
|
| 372 | static VOID wlan_set_ShortGI()
|
| 373 | {
|
| 374 |
|
| 375 | CHAR ht_gi[2] = {0};
|
| 376 |
|
| 377 | cfg_get_item ("HT_GI", ht_gi, sizeof (ht_gi));
|
| 378 |
|
| 379 | if (!strcmp (ht_gi, "1")) {
|
| 380 | wlan_write_file (CONFIG_DIR"/short_gi", "1");
|
| 381 | } else {
|
| 382 | wlan_write_file (CONFIG_DIR"/short_gi", "0");
|
| 383 | }
|
| 384 | }
|
| 385 |
|
| 386 | static VOID wlan_set_dtim()
|
| 387 | {
|
| 388 | CHAR dtim[2] = {0};
|
| 389 | cfg_get_item ("DtimPeriod", dtim, sizeof (dtim));
|
| 390 | wlan_write_file (CONFIG_DIR"/dtim_period", dtim);
|
| 391 | }
|
| 392 |
|
| 393 |
|
| 394 | static VOID wlan_set_fragthreshold()
|
| 395 | {
|
| 396 | CHAR fragThreshold[10] = {0};
|
| 397 | cfg_get_item ("FragThreshold", fragThreshold, sizeof (fragThreshold));
|
| 398 | wlan_write_file (CONFIG_DIR"/frag_threshold", fragThreshold);
|
| 399 | }
|
| 400 |
|
| 401 | static VOID wlan_set_rtsthreshold()
|
| 402 | {
|
| 403 | CHAR rtsThreshold[10] = {0};
|
| 404 |
|
| 405 | cfg_get_item ("RTSThreshold", rtsThreshold, sizeof (rtsThreshold));
|
| 406 | wlan_write_file (CONFIG_DIR"/rts_threshold", rtsThreshold);
|
| 407 | }
|
| 408 |
|
| 409 | static VOID wlan_set_encrypType_WPA (const char *ifname)
|
| 410 | {
|
| 411 | CHAR EncrypType[16] = {0};
|
| 412 | CHAR cmd[100] = {0};
|
| 413 | CHAR * dir = NULL;
|
| 414 |
|
| 415 | if (strcmp (ifname, "wlan0") == 0) {
|
| 416 | dir = CONFIG_DIR;
|
| 417 | cfg_get_item ("EncrypType", EncrypType, sizeof (EncrypType));
|
| 418 | } else if (strcmp (ifname, "wlan0-va0") == 0) {
|
| 419 | dir = CONFIG_DIR_VA0;
|
| 420 | cfg_get_item ("EncrypType", EncrypType, sizeof (EncrypType));
|
| 421 | } else if (strcmp (ifname, "wlan0-va1") == 0) {
|
| 422 | dir = CONFIG_DIR_VA1;
|
| 423 | cfg_get_item ("m_EncrypType", EncrypType, sizeof (EncrypType));
|
| 424 | } else {
|
| 425 | wf_log ("ifcae not find!");
|
| 426 | return;
|
| 427 | }
|
| 428 |
|
| 429 | if (!strcmp (EncrypType, "AES")) {
|
| 430 | sprintf (cmd, "%s/wpa_cipher", dir);
|
| 431 | wlan_write_file (cmd, "2");
|
| 432 | memset (cmd, 0, 100);
|
| 433 | sprintf (cmd, "%s/wpa2_cipher", dir);
|
| 434 | wlan_write_file (cmd, "0");
|
| 435 | } else if (!strcmp (EncrypType, "TKIP")) {
|
| 436 | sprintf (cmd, "%s/wpa_cipher", dir);
|
| 437 | wlan_write_file (cmd, "1");
|
| 438 | memset (cmd, 0, 100);
|
| 439 | sprintf (cmd, "%s/wpa2_cipher", dir);
|
| 440 | wlan_write_file (cmd, "0");
|
| 441 |
|
| 442 | } else if (!strcmp (EncrypType, "TKIPAES")) {
|
| 443 | sprintf (cmd, "%s/wpa_cipher", dir);
|
| 444 | wlan_write_file (cmd, "3");
|
| 445 | memset (cmd, 0, 100);
|
| 446 | sprintf (cmd, "%s/wpa2_cipher", dir);
|
| 447 | wlan_write_file (cmd, "0");
|
| 448 | }
|
| 449 | }
|
| 450 |
|
| 451 | static VOID wlan_set_encrypType_WPA2 (const char * ifname)
|
| 452 | {
|
| 453 | CHAR EncrypType[16] = {0};
|
| 454 | CHAR cmd[100] = {0};
|
| 455 | CHAR * dir = NULL;
|
| 456 |
|
| 457 | if (strcmp (ifname, "wlan0") == 0) {
|
| 458 | dir = CONFIG_DIR;
|
| 459 | cfg_get_item ("EncrypType", EncrypType, sizeof (EncrypType));
|
| 460 | } else if (strcmp (ifname, "wlan0-va0") == 0) {
|
| 461 | dir = CONFIG_DIR_VA0;
|
| 462 | cfg_get_item ("EncrypType", EncrypType, sizeof (EncrypType));
|
| 463 | } else if (strcmp (ifname, "wlan0-va1") == 0) {
|
| 464 | dir = CONFIG_DIR_VA1;
|
| 465 | cfg_get_item ("m_EncrypType", EncrypType, sizeof (EncrypType));
|
| 466 | } else {
|
| 467 | wf_log ("ifcae not find!");
|
| 468 | return;
|
| 469 | }
|
| 470 |
|
| 471 | if (!strcmp (EncrypType, "AES")) {
|
| 472 | sprintf (cmd, "%s/wpa_cipher", dir);
|
| 473 | wlan_write_file (cmd, "0");
|
| 474 | memset (cmd, 0, 100);
|
| 475 | sprintf (cmd, "%s/wpa2_cipher", dir);
|
| 476 | wlan_write_file (cmd, "2");
|
| 477 | } else if (!strcmp (EncrypType, "TKIP")) {
|
| 478 | sprintf (cmd, "%s/wpa_cipher", dir);
|
| 479 | wlan_write_file (cmd, "0");
|
| 480 | memset (cmd, 0, 100);
|
| 481 | sprintf (cmd, "%s/wpa2_cipher", dir);
|
| 482 | wlan_write_file (cmd, "1");
|
| 483 | } else if (!strcmp (EncrypType, "TKIPAES")) {
|
| 484 | sprintf (cmd, "%s/wpa_cipher", dir);
|
| 485 | wlan_write_file (cmd, "0");
|
| 486 | memset (cmd, 0, 100);
|
| 487 | sprintf (cmd, "%s/wpa2_cipher", dir);
|
| 488 | wlan_write_file (cmd, "3");
|
| 489 | }
|
| 490 | }
|
| 491 |
|
| 492 | static VOID wlan_set_encrypType_WPAWPA2 (const char* ifname)
|
| 493 | {
|
| 494 | CHAR EncrypType[12] = {0};
|
| 495 | CHAR cmd[100] = {0};
|
| 496 |
|
| 497 | CHAR * dir = NULL;
|
| 498 |
|
| 499 | if (strcmp (ifname, "wlan0") == 0) {
|
| 500 | dir = CONFIG_DIR;
|
| 501 | cfg_get_item ("EncrypType", EncrypType, sizeof (EncrypType));
|
| 502 | } else if (strcmp (ifname, "wlan0-va0") == 0) {
|
| 503 | dir = CONFIG_DIR_VA0;
|
| 504 | cfg_get_item ("EncrypType", EncrypType, sizeof (EncrypType));
|
| 505 | } else if (strcmp (ifname, "wlan0-va1") == 0) {
|
| 506 | dir = CONFIG_DIR_VA1;
|
| 507 | cfg_get_item ("m_EncrypType", EncrypType, sizeof (EncrypType));
|
| 508 | } else {
|
| 509 | wf_log ("ifcae not find!");
|
| 510 | return;
|
| 511 | }
|
| 512 |
|
| 513 | if (!strcmp (EncrypType, "AES")) {
|
| 514 | sprintf (cmd, "%s/wpa_cipher", dir);
|
| 515 | wlan_write_file (cmd, "2");
|
| 516 | memset (cmd, 0, 100);
|
| 517 | sprintf (cmd, "%s/wpa2_cipher", dir);
|
| 518 | wlan_write_file (cmd, "2");
|
| 519 |
|
| 520 |
|
| 521 | } else if (!strcmp (EncrypType, "TKIP")) {
|
| 522 | sprintf (cmd, "%s/wpa_cipher", dir);
|
| 523 | wlan_write_file (cmd, "1");
|
| 524 | memset (cmd, 0, 100);
|
| 525 | sprintf (cmd, "%s/wpa2_cipher", dir);
|
| 526 | wlan_write_file (cmd, "1");
|
| 527 |
|
| 528 | } else if (!strcmp (EncrypType, "TKIPAES")) {
|
| 529 | sprintf (cmd, "%s/wpa_cipher", dir);
|
| 530 | wlan_write_file (cmd, "3");
|
| 531 | memset (cmd, 0, 100);
|
| 532 | sprintf (cmd, "%s/wpa2_cipher", dir);
|
| 533 | wlan_write_file (cmd, "3");
|
| 534 |
|
| 535 |
|
| 536 | }
|
| 537 | }
|
| 538 |
|
| 539 | static VOID wlan_set_encrypType_WPA3 (const char * ifname)
|
| 540 | {
|
| 541 | CHAR EncrypType[16] = {0};
|
| 542 | CHAR cmd[100] = {0};
|
| 543 | CHAR * dir = NULL;
|
| 544 |
|
| 545 | if (strcmp (ifname, "wlan0") == 0) {
|
| 546 | dir = CONFIG_DIR;
|
| 547 | cfg_get_item ("EncrypType", EncrypType, sizeof (EncrypType));
|
| 548 | } else if (strcmp (ifname, "wlan0-va0") == 0) {
|
| 549 | dir = CONFIG_DIR_VA0;
|
| 550 | cfg_get_item ("EncrypType", EncrypType, sizeof (EncrypType));
|
| 551 | } else if (strcmp (ifname, "wlan0-va1") == 0) {
|
| 552 | dir = CONFIG_DIR_VA1;
|
| 553 | cfg_get_item ("m_EncrypType", EncrypType, sizeof (EncrypType));
|
| 554 | } else {
|
| 555 | wf_log ("ifcae not find!");
|
| 556 | return;
|
| 557 | }
|
| 558 |
|
| 559 | sprintf (cmd, "%s/wpa_cipher", dir);
|
| 560 | wlan_write_file (cmd, "0");
|
| 561 | memset (cmd, 0, 100);
|
| 562 | sprintf (cmd, "%s/wpa2_cipher", dir);
|
| 563 | wlan_write_file (cmd, "2");
|
| 564 |
|
| 565 | }
|
| 566 |
|
| 567 |
|
| 568 | static VOID wlan_set_wep_key_hex (CHAR *KeyStr, int i, const char * dir)
|
| 569 | {
|
| 570 | int len = 0;
|
| 571 | CHAR cmd[100] = {0};
|
| 572 | if (NULL == KeyStr) {
|
| 573 | return;
|
| 574 | }
|
| 575 | len = strlen (KeyStr);
|
| 576 | if (len == 10) { //64
|
| 577 | //kw 3
|
| 578 | memset (cmd, 0 , 100);
|
| 579 | sprintf (cmd, "%s/wep", dir);
|
| 580 | wlan_write_file (cmd, "1");
|
| 581 |
|
| 582 | memset (cmd, 0 , 100);
|
| 583 | sprintf (cmd, "%s/wepkey%d_64_hex", dir, i);
|
| 584 | wlan_write_file (cmd, KeyStr);
|
| 585 |
|
| 586 | } else if (len == 26) { // 128
|
| 587 | //kw 3
|
| 588 | memset (cmd, 0 , 100);
|
| 589 | sprintf (cmd, "%s/wep", dir);
|
| 590 | wlan_write_file (cmd, "2");
|
| 591 |
|
| 592 | memset (cmd, 0 , 100);
|
| 593 | sprintf (cmd, "%s/wepkey%d_128_hex", dir, i);
|
| 594 | wlan_write_file (cmd, KeyStr);
|
| 595 |
|
| 596 | } else {
|
| 597 | wf_log ("wlan_set_wep_key_hex KeyStr is bad !");
|
| 598 | return;
|
| 599 | }
|
| 600 | }
|
| 601 |
|
| 602 | static int ascii_trans_hex (CHAR *asc_in, CHAR *hex_out)
|
| 603 | {
|
| 604 | int len = 0;
|
| 605 | int i , j = 0;
|
| 606 | CHAR tmp_str[32] = {0};
|
| 607 | CHAR str[3] = {0};
|
| 608 | #if 0 //kw 3
|
| 609 | if ( (NULL == asc_in) || (NULL == hex_out)) {
|
| 610 | return 0;
|
| 611 | }
|
| 612 | #endif
|
| 613 | len = strlen (asc_in);
|
| 614 |
|
| 615 | for (i = 0, j = 0; i < len; i++, j += 2) {
|
| 616 | sprintf (str, "%02x", asc_in[i]);
|
| 617 | tmp_str[j] = str[0];
|
| 618 | tmp_str[j + 1] = str[1];
|
| 619 | }
|
| 620 | tmp_str[j] = '\0';
|
| 621 |
|
| 622 | strcpy (hex_out, tmp_str);
|
| 623 | return 1;
|
| 624 | }
|
| 625 |
|
| 626 |
|
| 627 | static VOID wlan_set_wep_key_ascii (CHAR *KeyStr, int i, const char * dir)
|
| 628 | {
|
| 629 | int len = 0;
|
| 630 | CHAR cmd[128] = {0};
|
| 631 |
|
| 632 | if (NULL == KeyStr) {
|
| 633 | return;
|
| 634 | }
|
| 635 | len = strlen (KeyStr);
|
| 636 |
|
| 637 | if (len == 5) { //64
|
| 638 | CHAR hexKeyStr[12] = {0};
|
| 639 | //kw 3
|
| 640 | memset (cmd, 0 , 128);
|
| 641 | sprintf (cmd, "%s/wep", dir);
|
| 642 | wlan_write_file (cmd, "1");
|
| 643 | //kw 3
|
| 644 | ascii_trans_hex (KeyStr, hexKeyStr);
|
| 645 | memset (cmd, 0 , 128);
|
| 646 | sprintf (cmd, "%s/wepkey%d_64_asc", dir, i);
|
| 647 | wlan_write_file (cmd, hexKeyStr);
|
| 648 |
|
| 649 | } else if (len == 13) { // 128
|
| 650 | CHAR hexKeyStr[28] = {0};
|
| 651 | //kw 3
|
| 652 | memset (cmd, 0 , 128);
|
| 653 | sprintf (cmd, "%s/wep", dir);
|
| 654 | wlan_write_file (cmd, "2");
|
| 655 | //kw 3
|
| 656 | ascii_trans_hex (KeyStr, hexKeyStr);
|
| 657 | memset (cmd, 0 , 128);
|
| 658 | sprintf (cmd, "%s/wepkey%d_128_asc", dir, i);
|
| 659 | wlan_write_file (cmd, hexKeyStr);
|
| 660 |
|
| 661 | } else {
|
| 662 | wf_log ("wlan_set_wep_key_ascii KeyStr is bad !");
|
| 663 | return;
|
| 664 | }
|
| 665 | }
|
| 666 |
|
| 667 |
|
| 668 | static VOID wlan_add_wep (int index, const char * ifname)
|
| 669 | {
|
| 670 | CHAR wep_is_hex_0[2] = {0};
|
| 671 | CHAR KeyType[21] = {0}; //klocwork
|
| 672 | CHAR KeyName[21] = {0};
|
| 673 | CHAR KeyStr[32] = {0};
|
| 674 | CHAR cmd[256] = {0};
|
| 675 | CHAR * dir = NULL;
|
| 676 |
|
| 677 |
|
| 678 | if (strcmp (ifname, "wlan0") == 0) {
|
| 679 | dir = CONFIG_DIR;
|
| 680 | sprintf (KeyType, "Key%dType", index);
|
| 681 | sprintf (KeyName, "Key%dStr1", index);
|
| 682 |
|
| 683 |
|
| 684 | } else if (strcmp (ifname, "wlan0-va0") == 0) {
|
| 685 | dir = CONFIG_DIR_VA0;
|
| 686 | sprintf (KeyType, "Key%dType", index);
|
| 687 | sprintf (KeyName, "Key%dStr1", index);
|
| 688 |
|
| 689 |
|
| 690 | } else if (strcmp (ifname, "wlan0-va1") == 0) {
|
| 691 | dir = CONFIG_DIR_VA1;
|
| 692 | sprintf (KeyType, "m_Key%dType", index);
|
| 693 | sprintf (KeyName, "m_Key%dStr1", index);
|
| 694 | } else {
|
| 695 | wf_log ("ifcae not find!");
|
| 696 | return;
|
| 697 | }
|
| 698 |
|
| 699 | cfg_get_item (KeyType, wep_is_hex_0, sizeof (wep_is_hex_0));
|
| 700 | cfg_get_item (KeyName, KeyStr, sizeof (KeyStr));
|
| 701 |
|
| 702 | if (!strcmp (wep_is_hex_0, "0")) { //hex key
|
| 703 | memset (cmd, 0 , 256);
|
| 704 | sprintf (cmd, "%s/wep_key_type", dir);
|
| 705 | wlan_write_file (cmd, "1");
|
| 706 | wlan_set_wep_key_hex (KeyStr, index, dir);
|
| 707 | } else { //ascii key
|
| 708 | memset (cmd, 0 , 256);
|
| 709 | sprintf (cmd, "%s/wep_key_type", dir);
|
| 710 | wlan_write_file (cmd, "0");
|
| 711 |
|
| 712 | wlan_set_wep_key_ascii (KeyStr, index, dir);
|
| 713 | }
|
| 714 | }
|
| 715 |
|
| 716 | static VOID wlan_set_wep (CHAR *authMode, const char * ifname)
|
| 717 | {
|
| 718 | CHAR cmd[256] = {0};
|
| 719 | CHAR ap_primary_key_0[2] = {0};
|
| 720 | int i = 0;
|
| 721 |
|
| 722 | CHAR * dir = NULL;
|
| 723 | int index = 0;
|
| 724 |
|
| 725 | if (strcmp (ifname, "wlan0") == 0) {
|
| 726 | dir = CONFIG_DIR;
|
| 727 | cfg_get_item ("DefaultKeyID", ap_primary_key_0, sizeof (ap_primary_key_0));
|
| 728 | } else if (strcmp (ifname, "wlan0-va0") == 0) {
|
| 729 | dir = CONFIG_DIR_VA0;
|
| 730 | cfg_get_item ("DefaultKeyID", ap_primary_key_0, sizeof (ap_primary_key_0));
|
| 731 | } else if (strcmp (ifname, "wlan0-va1") == 0) {
|
| 732 | dir = CONFIG_DIR_VA1;
|
| 733 | cfg_get_item ("m_DefaultKeyID", ap_primary_key_0, sizeof (ap_primary_key_0));
|
| 734 | } else {
|
| 735 | wf_log ("ifcae not find!");
|
| 736 | return;
|
| 737 | }
|
| 738 |
|
| 739 | memset (cmd, 0 , 256);
|
| 740 | sprintf (cmd, "%s/encrypt", dir);
|
| 741 | wlan_write_file (cmd, "1");
|
| 742 |
|
| 743 | memset (cmd, 0 , 256);
|
| 744 | sprintf (cmd, "%s/wep_default_key", dir);
|
| 745 | wlan_write_file (cmd, ap_primary_key_0);
|
| 746 |
|
| 747 | index = atoi(ap_primary_key_0);
|
| 748 | if (index < 0 || index > 4) { //kw 3, wep 4 group keys
|
| 749 | wf_log("wep group key index:%d!", index);
|
| 750 | return;
|
| 751 | }
|
| 752 | wlan_add_wep(index + 1, ifname);
|
| 753 |
|
| 754 | if ( (NULL != authMode) && (!strcmp (authMode, "OPEN"))) {
|
| 755 | memset (cmd, 0 , 256);
|
| 756 | sprintf (cmd, "%s/auth_type", dir);
|
| 757 | wlan_write_file (cmd, "0");
|
| 758 |
|
| 759 | } else if ( (NULL != authMode) && (!strcmp (authMode, "SHARED"))) {
|
| 760 | memset (cmd, 0 , 256);
|
| 761 | sprintf (cmd, "%s/auth_type", dir);
|
| 762 | wlan_write_file (cmd, "1");
|
| 763 |
|
| 764 | } else {
|
| 765 | memset (cmd, 0 , 256);
|
| 766 | sprintf (cmd, "%s/auth_type", dir);
|
| 767 | wlan_write_file (cmd, "2");
|
| 768 |
|
| 769 | }
|
| 770 | }
|
| 771 |
|
| 772 | static VOID va1_set_apmode()
|
| 773 | {
|
| 774 | wlan_write_file (CONFIG_DIR_VA1"/wlan_mode", "0");
|
| 775 | }
|
| 776 |
|
| 777 | static VOID va0_set_apmode()
|
| 778 | {
|
| 779 | wlan_write_file (CONFIG_DIR_VA0"/wlan_mode", "0");
|
| 780 | }
|
| 781 |
|
| 782 | static VOID va1_set_hideSSID()
|
| 783 | {
|
| 784 | CHAR hideSSID[2] = {0};
|
| 785 | cfg_get_item ("m_HideSSID", hideSSID, sizeof (hideSSID));
|
| 786 |
|
| 787 | if (!strcmp (hideSSID, "1")) {
|
| 788 | wlan_write_file (CONFIG_DIR_VA1"/hidden_ssid", "1");
|
| 789 | } else {
|
| 790 | wlan_write_file (CONFIG_DIR_VA1"/hidden_ssid", "0");
|
| 791 | }
|
| 792 | }
|
| 793 |
|
| 794 | static VOID va0_set_hideSSID()
|
| 795 | {
|
| 796 | CHAR hideSSID[2] = {0};
|
| 797 | cfg_get_item ("HideSSID", hideSSID, sizeof (hideSSID));
|
| 798 |
|
| 799 | if (!strcmp (hideSSID, "1")) {
|
| 800 | wlan_write_file (CONFIG_DIR_VA0"/hidden_ssid", "1");
|
| 801 |
|
| 802 | } else {
|
| 803 | wlan_write_file (CONFIG_DIR_VA0"/hidden_ssid", "0");
|
| 804 | }
|
| 805 | }
|
| 806 |
|
| 807 | static VOID va1_set_maxassoc()
|
| 808 | {
|
| 809 | CHAR m_MAX_Access_num[8] = {0};
|
| 810 | CHAR MAX_Access_num[8] = {0};
|
| 811 | int m_access_num = 0;
|
| 812 | int access_num = 0;
|
| 813 | CHAR cmd[100] = {0};
|
| 814 | CHAR file_path_buf[100] = {0};
|
| 815 |
|
| 816 | cfg_get_item ("MAX_Access_num", MAX_Access_num, sizeof (MAX_Access_num));
|
| 817 | cfg_get_item ("m_MAX_Access_num", m_MAX_Access_num, sizeof (m_MAX_Access_num));
|
| 818 | //kw 3
|
| 819 | access_num = atoi(MAX_Access_num);
|
| 820 | m_access_num = atoi(m_MAX_Access_num);
|
| 821 | if ((access_num < 0 || access_num > MAX_STA_NUM) ||
|
| 822 | (m_access_num < 0 || m_access_num > MAX_STA_NUM)) {
|
| 823 | wf_log("va1_set_maxassoc:%d,%d!", access_num, m_access_num);
|
| 824 | return;
|
| 825 | }
|
| 826 |
|
| 827 | if ((access_num + m_access_num) <= MAX_STA_NUM) {
|
| 828 | wlan_write_file (CONFIG_DIR_VA1"/supported_sta_num", m_MAX_Access_num);
|
| 829 | } else {
|
| 830 | char sta_num[12] = {0}; //klocwork
|
| 831 | sprintf (sta_num, "%d", MAX_STA_NUM - access_num);
|
| 832 | wlan_write_file (CONFIG_DIR_VA1"/supported_sta_num", sta_num);
|
| 833 | }
|
| 834 | }
|
| 835 |
|
| 836 |
|
| 837 | static VOID va0_set_maxassoc()
|
| 838 | {
|
| 839 | CHAR maxAccessNum[8] = {0};
|
| 840 | CHAR max_sta_num_str[100] = {0};
|
| 841 |
|
| 842 | cfg_get_item ("MAX_Access_num", maxAccessNum, sizeof (maxAccessNum));
|
| 843 |
|
| 844 | if (atoi (maxAccessNum) < MAX_STA_NUM) {
|
| 845 | wlan_write_file (CONFIG_DIR_VA0"/supported_sta_num", maxAccessNum);
|
| 846 | } else {
|
| 847 | sprintf (max_sta_num_str, "%d", MAX_STA_NUM);
|
| 848 | wlan_write_file (CONFIG_DIR_VA0"/supported_sta_num", max_sta_num_str);
|
| 849 | }
|
| 850 | }
|
| 851 |
|
| 852 | static VOID va1_set_bss()
|
| 853 | {
|
| 854 | CHAR bssid[33] = {0};
|
| 855 | CHAR m_wifi_mac[20] = {0};
|
| 856 | CHAR cmd[20] = {0};
|
| 857 | CHAR tmpbssid[65] = {0};
|
| 858 |
|
| 859 | cfg_get_item ("m_SSID", bssid, sizeof (bssid));
|
| 860 | cfg_get_item ("m_wifi_mac", m_wifi_mac, sizeof (m_wifi_mac));
|
| 861 | wf_log (" va1 m_wifi_mac = %s", m_wifi_mac);
|
| 862 |
|
| 863 | translateStringToEcho (bssid, tmpbssid);
|
| 864 | wlan_write_file (CONFIG_DIR_VA1"/ssid", tmpbssid);
|
| 865 |
|
| 866 | if(strlen(m_wifi_mac)==0) return;
|
| 867 | sprintf (cmd, "%c%c%c%c%c%c%c%c%c%c%c%c",
|
| 868 | m_wifi_mac[0], m_wifi_mac[1], m_wifi_mac[3], m_wifi_mac[4],
|
| 869 | m_wifi_mac[6], m_wifi_mac[7], m_wifi_mac[9], m_wifi_mac[10],
|
| 870 | m_wifi_mac[12], m_wifi_mac[13], m_wifi_mac[15], m_wifi_mac[16]);
|
| 871 | wlan_write_file (CONFIG_DIR"/wlan2_addr", cmd);
|
| 872 | }
|
| 873 |
|
| 874 |
|
| 875 | static VOID va0_set_bss()
|
| 876 | {
|
| 877 | CHAR bssid[33] = {0};
|
| 878 | CHAR wifi_mac[20] = {0};
|
| 879 | CHAR cmd[20] = {0};
|
| 880 | CHAR tmpbssid[65] = {0};
|
| 881 |
|
| 882 | cfg_get_item ("SSID1", bssid, sizeof (bssid));
|
| 883 | cfg_get_item ("wifi_mac", wifi_mac, sizeof (wifi_mac));
|
| 884 |
|
| 885 | wf_log ("va0 wifi_mac = %s", wifi_mac);
|
| 886 |
|
| 887 | translateStringToEcho (bssid, tmpbssid);
|
| 888 | wlan_write_file (CONFIG_DIR_VA0"/ssid", tmpbssid);
|
| 889 |
|
| 890 | if(strlen(wifi_mac)==0) return;
|
| 891 |
|
| 892 | sprintf (cmd, "%c%c%c%c%c%c%c%c%c%c%c%c",
|
| 893 | wifi_mac[0], wifi_mac[1], wifi_mac[3], wifi_mac[4],
|
| 894 | wifi_mac[6], wifi_mac[7], wifi_mac[9], wifi_mac[10],
|
| 895 | wifi_mac[12], wifi_mac[13], wifi_mac[15], wifi_mac[16]);
|
| 896 |
|
| 897 | wlan_write_file (CONFIG_DIR"/wlan1_addr", cmd);
|
| 898 |
|
| 899 | }
|
| 900 |
|
| 901 | static void vxd_sta_para_set()
|
| 902 | {
|
| 903 | wlan_write_file (CONFIG_DIR_VXD"/wlan_mode", "1");
|
| 904 | wlan_write_file (CONFIG_DIR_VXD"/network_type", "0");
|
| 905 | }
|
| 906 |
|
| 907 | static void wlan_ap_para_set (const char* ifname)
|
| 908 | {
|
| 909 | CHAR authMode[32] = {0};
|
| 910 | CHAR psk[65] = {0};
|
| 911 | CHAR RekeyInterval[10] = {0};
|
| 912 | CHAR cmd[192] = {0};
|
| 913 | CHAR wapiType[2] = {0};
|
| 914 | CHAR EncrypType[32] = {0};
|
| 915 |
|
| 916 | CHAR *dir = NULL;
|
| 917 |
|
| 918 | if (strcmp (ifname, "wlan0") == 0) {
|
| 919 |
|
| 920 | dir = CONFIG_DIR;
|
| 921 | wlan_set_apmode();
|
| 922 | wlan_set_maxassoc();
|
| 923 | wlan_set_bss();
|
| 924 | wlan_set_hideSSID();
|
| 925 |
|
| 926 | cfg_get_item ("AuthMode", authMode, sizeof (authMode));
|
| 927 | cfg_get_item ("WPAPSK1", psk, sizeof (psk));
|
| 928 | cfg_get_item ("wapiType", wapiType, sizeof (wapiType));
|
| 929 | cfg_get_item ("EncrypType", EncrypType, sizeof (EncrypType));
|
| 930 | } else if (strcmp (ifname, "wlan0-va0") == 0) {
|
| 931 | dir = CONFIG_DIR_VA0;
|
| 932 |
|
| 933 | va0_set_apmode();
|
| 934 | va0_set_maxassoc();
|
| 935 | va0_set_bss();
|
| 936 | va0_set_hideSSID();
|
| 937 |
|
| 938 | cfg_get_item ("AuthMode", authMode, sizeof (authMode));
|
| 939 | cfg_get_item ("WPAPSK1", psk, sizeof (psk));
|
| 940 | cfg_get_item ("wapiType", wapiType, sizeof (wapiType));
|
| 941 | cfg_get_item ("EncrypType", EncrypType, sizeof (EncrypType));
|
| 942 | } else if (strcmp (ifname, "wlan0-va1") == 0) {
|
| 943 | dir = CONFIG_DIR_VA1;
|
| 944 |
|
| 945 | va1_set_apmode();
|
| 946 | va1_set_maxassoc();
|
| 947 | va1_set_bss();
|
| 948 | va1_set_hideSSID();
|
| 949 |
|
| 950 | cfg_get_item ("m_AuthMode", authMode, sizeof (authMode));
|
| 951 | cfg_get_item ("m_WPAPSK1", psk, sizeof (psk));
|
| 952 | cfg_get_item ("m_wapiType", wapiType, sizeof (wapiType));
|
| 953 | cfg_get_item ("m_EncrypType", EncrypType, sizeof (EncrypType));
|
| 954 | } else {
|
| 955 | wf_log ("ifcae not find!");
|
| 956 | return;
|
| 957 | }
|
| 958 |
|
| 959 |
|
| 960 | if (strcmp (authMode, "WAPIPSK")) {
|
| 961 | memset (cmd, 0, 192);
|
| 962 | sprintf (cmd, "%s/wapiType", dir);
|
| 963 | wlan_write_file (cmd, "0");
|
| 964 | }
|
| 965 | if (!strcmp (authMode, "WPAPSK")) {
|
| 966 | CHAR tmppsk[129] = {0};
|
| 967 | wlan_set_encrypType_WPA (ifname);
|
| 968 | memset (cmd, 0, 192);
|
| 969 | sprintf (cmd, "%s/encrypt", dir);
|
| 970 | wlan_write_file (cmd, "2");
|
| 971 |
|
| 972 | memset (cmd, 0, 192);
|
| 973 | sprintf (cmd, "%s/enable_1x", dir);
|
| 974 | wlan_write_file (cmd, "0");
|
| 975 |
|
| 976 | memset (cmd, 0, 192);
|
| 977 | sprintf (cmd, "%s/auth_type", dir);
|
| 978 | wlan_write_file (cmd, "2");
|
| 979 |
|
| 980 | memset (cmd, 0, 192);
|
| 981 | translateStringToEcho (psk, tmppsk);
|
| 982 | sprintf (cmd, "%s/wpa_psk", dir);
|
| 983 | wlan_write_file (cmd, tmppsk);
|
| 984 |
|
| 985 | #if 0
|
| 986 | cfg_get_item ("RekeyInterval", RekeyInterval, sizeof (RekeyInterval));
|
| 987 | if ( (NULL != RekeyInterval) || (strcmp (RekeyInterval, ""))) {
|
| 988 | memset (cmd, 0, 192);
|
| 989 | sprintf (cmd, "echo %s > %s/gk_rekey", RekeyInterval, dir);
|
| 990 | system (cmd);
|
| 991 | } else {
|
| 992 | memset (cmd, 0, 192);
|
| 993 | sprintf (cmd, "echo \"38400\" > %s/gk_rekey", dir);
|
| 994 | system (cmd);
|
| 995 | }
|
| 996 | #endif
|
| 997 | } else if (!strcmp (authMode, "WPA2PSK")) {
|
| 998 | CHAR tmppsk[129] = {0};
|
| 999 | wlan_set_encrypType_WPA2 (ifname);
|
| 1000 | memset (cmd, 0, 192);
|
| 1001 | sprintf (cmd, "%s/encrypt", dir);
|
| 1002 | wlan_write_file (cmd, "4");
|
| 1003 |
|
| 1004 | memset (cmd, 0, 192);
|
| 1005 | sprintf (cmd, "%s/enable_1x", dir);
|
| 1006 | wlan_write_file (cmd, "0");
|
| 1007 |
|
| 1008 | memset (cmd, 0, 192);
|
| 1009 | sprintf (cmd, "%s/auth_type", dir);
|
| 1010 | wlan_write_file (cmd, "2");
|
| 1011 |
|
| 1012 | memset (cmd, 0, 192);
|
| 1013 | translateStringToEcho (psk, tmppsk);
|
| 1014 | sprintf (cmd, "%s/wpa_psk", dir);
|
| 1015 | wlan_write_file (cmd, tmppsk);
|
| 1016 |
|
| 1017 |
|
| 1018 | #if 0
|
| 1019 |
|
| 1020 | cfg_get_item ("RekeyInterval", RekeyInterval, sizeof (RekeyInterval));
|
| 1021 | if ( (NULL != RekeyInterval) || (strcmp (RekeyInterval, ""))) {
|
| 1022 | memset (cmd, 0, 192);
|
| 1023 | sprintf (cmd, "echo %s > %s/gk_rekey", RekeyInterval, dir);
|
| 1024 | system (cmd);
|
| 1025 | } else {
|
| 1026 | memset (cmd, 0, 192);
|
| 1027 | sprintf (cmd, "echo \"38400\" > %s/gk_rekey", dir);
|
| 1028 | system (cmd);
|
| 1029 | }
|
| 1030 | #endif
|
| 1031 | }
|
| 1032 | else if (!strcmp (authMode, "WPAPSKWPA2PSK") || !strcmp (authMode, "WPA-PSK/WPA2-PSK")) {
|
| 1033 | CHAR tmppsk[129] = {0};
|
| 1034 | wlan_set_encrypType_WPAWPA2 (ifname);
|
| 1035 | memset (cmd, 0, 192);
|
| 1036 | sprintf (cmd, "%s/encrypt", dir);
|
| 1037 | wlan_write_file (cmd, "6");
|
| 1038 |
|
| 1039 | memset (cmd, 0, 192);
|
| 1040 | sprintf (cmd, "%s/enable_1x", dir);
|
| 1041 | wlan_write_file (cmd, "0");
|
| 1042 |
|
| 1043 | memset (cmd, 0, 192);
|
| 1044 | sprintf (cmd, "%s/auth_type", dir);
|
| 1045 | wlan_write_file (cmd, "2");
|
| 1046 |
|
| 1047 | memset (cmd, 0, 192);
|
| 1048 | translateStringToEcho (psk, tmppsk);
|
| 1049 | sprintf (cmd, "%s/wpa_psk", dir);
|
| 1050 | wlan_write_file (cmd, tmppsk);
|
| 1051 |
|
| 1052 | #if 0
|
| 1053 |
|
| 1054 | cfg_get_item ("RekeyInterval", RekeyInterval, sizeof (RekeyInterval));
|
| 1055 | if ( (NULL != RekeyInterval) || (strcmp (RekeyInterval, ""))) {
|
| 1056 | memset (cmd, 0, 192);
|
| 1057 | sprintf (cmd, "echo %s > %s/gk_rekey", RekeyInterval, dir);
|
| 1058 | system (cmd);
|
| 1059 | } else {
|
| 1060 | memset (cmd, 0, 192);
|
| 1061 | sprintf (cmd, "echo \"38400\" > %s/gk_rekey", dir);
|
| 1062 | system (cmd);
|
| 1063 | }
|
| 1064 | #endif
|
| 1065 | } else if (!strcmp (authMode, "WPA3Personal")) {
|
| 1066 | CHAR tmppsk[129] = {0};
|
| 1067 | wlan_set_encrypType_WPA3 (ifname);
|
| 1068 | memset (cmd, 0, 192);
|
| 1069 | sprintf (cmd, "%s/encrypt", dir);
|
| 1070 | wlan_write_file (cmd, "8");
|
| 1071 |
|
| 1072 | //memset (cmd, 0, 192);
|
| 1073 | //sprintf (cmd, "%s/enable_1x", dir);
|
| 1074 | //wlan_write_file (cmd, "0");
|
| 1075 |
|
| 1076 | memset (cmd, 0, 192);
|
| 1077 | sprintf (cmd, "%s/auth_type", dir);
|
| 1078 | wlan_write_file (cmd, "2");
|
| 1079 |
|
| 1080 | memset (cmd, 0, 192);
|
| 1081 | translateStringToEcho (psk, tmppsk);
|
| 1082 | sprintf (cmd, "%s/wpa_psk", dir);
|
| 1083 | wlan_write_file (cmd, tmppsk);
|
| 1084 |
|
| 1085 | memset (cmd, 0, 192);
|
| 1086 | sprintf (cmd, "%s/wpa11w", dir);
|
| 1087 | wlan_write_file (cmd, "2");
|
| 1088 |
|
| 1089 | memset (cmd, 0, 192);
|
| 1090 | sprintf (cmd, "%s/wpa2EnableSHA256", dir);
|
| 1091 | wlan_write_file (cmd, "1");
|
| 1092 |
|
| 1093 | } else if (!strcmp (authMode, "WPA2WPA3")) {
|
| 1094 | CHAR tmppsk[129] = {0};
|
| 1095 | wlan_set_encrypType_WPA3 (ifname);
|
| 1096 | memset (cmd, 0, 192);
|
| 1097 | sprintf (cmd, "%s/encrypt", dir);
|
| 1098 | wlan_write_file (cmd, "10");
|
| 1099 |
|
| 1100 | //memset (cmd, 0, 192);
|
| 1101 | //sprintf (cmd, "%s/enable_1x", dir);
|
| 1102 | //wlan_write_file (cmd, "0");
|
| 1103 |
|
| 1104 | memset (cmd, 0, 192);
|
| 1105 | sprintf (cmd, "%s/auth_type", dir);
|
| 1106 | wlan_write_file (cmd, "2");
|
| 1107 |
|
| 1108 | memset (cmd, 0, 192);
|
| 1109 | translateStringToEcho (psk, tmppsk);
|
| 1110 | sprintf (cmd, "%s/wpa_psk", dir);
|
| 1111 | wlan_write_file (cmd, tmppsk);
|
| 1112 |
|
| 1113 | memset (cmd, 0, 192);
|
| 1114 | sprintf (cmd, "%s/wpa11w", dir);
|
| 1115 | wlan_write_file (cmd, "1"); //PMF disable/enable/required 0/1/2
|
| 1116 |
|
| 1117 | memset (cmd, 0, 192);
|
| 1118 | sprintf (cmd, "%s/wpa2EnableSHA256", dir);
|
| 1119 | wlan_write_file (cmd, "1");
|
| 1120 |
|
| 1121 | } else if ( ( (!strcmp ("WEP", EncrypType)) && (!strcmp ("OPEN", authMode))) || (!strcmp ("SHARED", authMode)) || (!strcmp ("WEPAUTO", authMode))) { //WEP
|
| 1122 | wlan_set_wep (authMode, ifname);
|
| 1123 | } else if (!strcmp (authMode, "WAPIPSK")) {
|
| 1124 | if (strcmp (wapiType, "0") && strcmp (wapiType, "")) {
|
| 1125 | CHAR wapiPsk[65] = {0};
|
| 1126 | CHAR tmpwapiPsk[129] = {0};
|
| 1127 | cfg_get_item ("WPAPSK1", wapiPsk, sizeof (wapiPsk));
|
| 1128 |
|
| 1129 | memset (cmd, 0, 192);
|
| 1130 | translateStringToEcho (wapiPsk, tmpwapiPsk);
|
| 1131 | sprintf (cmd, "echo \"%s\" > %s/wapiPsk", tmpwapiPsk, dir);
|
| 1132 | soft_system (cmd);
|
| 1133 | perror (cmd);
|
| 1134 | memset (cmd, 0, 192);
|
| 1135 | sprintf (cmd, "echo %x > %s/wapiPsklen", strlen (wapiPsk), dir);
|
| 1136 | soft_system (cmd);
|
| 1137 | perror (cmd);
|
| 1138 | memset (cmd, 0, 192);
|
| 1139 | sprintf (cmd, "echo %s > %s/wapiType", wapiType, dir);
|
| 1140 | soft_system (cmd);
|
| 1141 | perror (cmd);
|
| 1142 | }
|
| 1143 | } else { //open
|
| 1144 | memset (cmd, 0, 192);
|
| 1145 | sprintf (cmd, "%s/encrypt", dir);
|
| 1146 | wlan_write_file (cmd, "0");
|
| 1147 |
|
| 1148 | memset (cmd, 0, 192);
|
| 1149 | sprintf (cmd, "%s/psk_enable", dir);
|
| 1150 | wlan_write_file (cmd, "0");
|
| 1151 |
|
| 1152 | memset (cmd, 0, 192);
|
| 1153 | sprintf (cmd, "%s/enable_1x", dir);
|
| 1154 | wlan_write_file (cmd, "0");
|
| 1155 |
|
| 1156 | memset (cmd, 0, 192);
|
| 1157 | sprintf (cmd, "%s/auth_type", dir);
|
| 1158 | wlan_write_file (cmd, "0");
|
| 1159 |
|
| 1160 | }
|
| 1161 | }
|
| 1162 | static void wlan_set_vxd_on()
|
| 1163 | {
|
| 1164 | wlan_write_file (CONFIG_DIR_VXD"/wlan_disabled", "0");
|
| 1165 | }
|
| 1166 | static void wlan_set_vxd_off()
|
| 1167 | {
|
| 1168 | wlan_write_file (CONFIG_DIR_VXD"/wlan_disabled", "1");
|
| 1169 | }
|
| 1170 |
|
| 1171 | static void wlan_set_va1_on()
|
| 1172 | {
|
| 1173 | wlan_write_file (CONFIG_DIR_VA1"/wlan_disabled", "0");
|
| 1174 | }
|
| 1175 |
|
| 1176 | static void wlan_set_va1_off()
|
| 1177 | {
|
| 1178 | wlan_write_file (CONFIG_DIR_VA1"/wlan_disabled", "1");
|
| 1179 | }
|
| 1180 |
|
| 1181 | static void wlan_set_va0_on()
|
| 1182 | {
|
| 1183 | wlan_write_file (CONFIG_DIR_VA0"/wlan_disabled", "0");
|
| 1184 | }
|
| 1185 |
|
| 1186 | static void wlan_set_va0_off()
|
| 1187 | {
|
| 1188 | wlan_write_file (CONFIG_DIR_VA0"/wlan_disabled", "1");
|
| 1189 | }
|
| 1190 |
|
| 1191 | static void wlan_set_ssid_on()
|
| 1192 | {
|
| 1193 | wlan_write_file (CONFIG_DIR"/wlan_disabled", "0");
|
| 1194 | }
|
| 1195 |
|
| 1196 | static void wlan0_radio_para_set()
|
| 1197 | {
|
| 1198 | wlan_set_countryCode();
|
| 1199 | wlan_80211Mode_config();
|
| 1200 | wlan_set_wifiConverage();
|
| 1201 | wlan_set_channel();
|
| 1202 | //wlan_set_rate();
|
| 1203 | // wlan_set_beaconinterval();
|
| 1204 | // wlan_set_aggregation();
|
| 1205 | // wlan_set_wmm();
|
| 1206 | //wlan_set_11nparam();
|
| 1207 | wlan_set_NoForwarding();
|
| 1208 | // wlan_set_ShortGI();
|
| 1209 | // wlan_set_dtim();
|
| 1210 | // wlan_set_fragthreshold();
|
| 1211 | // wlan_set_rtsthreshold();
|
| 1212 | }
|
| 1213 |
|
| 1214 | static void wlan0_para_set()
|
| 1215 | {
|
| 1216 | wlan_set_ssid_on();
|
| 1217 |
|
| 1218 | //set m_wifi_mac to wlan0_addr for vxd interface
|
| 1219 | wlan_ap_para_set ("wlan0");
|
| 1220 | }
|
| 1221 |
|
| 1222 | static void wlan_set_param()
|
| 1223 | {
|
| 1224 | char m_ssid_enable[8] = {0};
|
| 1225 | char wifi_sta_connection[8] = {0};
|
| 1226 |
|
| 1227 | wf_log ("[wlan0_radio_para_set]");
|
| 1228 |
|
| 1229 | cfg_get_item ("m_ssid_enable", m_ssid_enable, sizeof (m_ssid_enable));
|
| 1230 | cfg_get_item ("wifi_sta_connection", wifi_sta_connection, sizeof (wifi_sta_connection));
|
| 1231 |
|
| 1232 | wlan0_radio_para_set();
|
| 1233 | wlan0_para_set();
|
| 1234 |
|
| 1235 | #ifndef __SINGLE_AP__
|
| 1236 | wf_log ("[va0 va1 vxd para set, and set va0 open]");
|
| 1237 |
|
| 1238 | //every time poweron, need to set all para for every interface
|
| 1239 | wlan_set_va0_on();
|
| 1240 | wlan_ap_para_set ("wlan0-va0");
|
| 1241 | wlan_ap_para_set ("wlan0-va1");
|
| 1242 | vxd_sta_para_set(); //wlan_mode wlan_disabled mac network_type
|
| 1243 |
|
| 1244 | if (strcmp (m_ssid_enable, "1") == 0) {
|
| 1245 | wlan_set_va1_on();
|
| 1246 | } else {
|
| 1247 | wlan_set_va1_off();
|
| 1248 | }
|
| 1249 |
|
| 1250 | if (strcmp (wifi_sta_connection, "1") == 0) {
|
| 1251 | wlan_set_vxd_on();
|
| 1252 | } else {
|
| 1253 | wlan_set_vxd_off();
|
| 1254 | }
|
| 1255 | #endif
|
| 1256 | }
|
| 1257 | #if 0 //kw 3
|
| 1258 | //´ò¿ªÍøÇŵØÖ·¸Ä±ä֪ͨµÄ¿ª¹Ø
|
| 1259 | static void arp_br0()
|
| 1260 | {
|
| 1261 | CHAR ip_addr[20] = {0};
|
| 1262 | CHAR cmd[100] = {0};
|
| 1263 |
|
| 1264 | cfg_get_item ("lan_ipaddr", ip_addr, sizeof (ip_addr));
|
| 1265 |
|
| 1266 | if ( (NULL != ip_addr) || (strcmp (ip_addr, ""))) {
|
| 1267 | sprintf (cmd, "arping -U -c 1 -I br0 %s", ip_addr);
|
| 1268 | } else {
|
| 1269 | sprintf (cmd, "arping -U -c 1 -I br0 %s", "192.168.0.1");
|
| 1270 | }
|
| 1271 | system (cmd);
|
| 1272 | }
|
| 1273 | #endif
|
| 1274 | /* ************ ÒÔÏÂÕâÐ©Íø¿ÚÏà¹ØµÄ²Ù×÷£¬ÓÉÍøÂçÐÖúÌṩ ********** */
|
| 1275 | void stop_vxd()
|
| 1276 | {
|
| 1277 | wf_log ("stop_vxd ");
|
| 1278 | system ("ifconfig wlan0-vxd down");
|
| 1279 | }
|
| 1280 |
|
| 1281 | //wifi¶ÔÍø¿ÚµÄ²Ù×÷ÓÐ˳ÐòÒªÇ󣬲»ÄÜ·¢ÏûÏ¢¸øÖ÷¿ØÒì²½´¦Àí£¬Ö±½Óµ÷ÓÃÍøÂçÌṩ½Å±¾²Ù×÷
|
| 1282 | static void stop_va1()
|
| 1283 | {
|
| 1284 | wf_log ("stop_va1 ");
|
| 1285 | system("iwpriv wlan0-va1 clear_acl_table; \
|
| 1286 | ifconfig wlan0-va1 down");
|
| 1287 | // system ("iwpriv wlan0-va1 clear_acl_table");
|
| 1288 | // system ("landev_updown.sh \"wifilan2\" \"down\"");
|
| 1289 | }
|
| 1290 |
|
| 1291 | static void stop_va0()
|
| 1292 | {
|
| 1293 | wf_log ("stop_va0 ");
|
| 1294 | system("ifconfig wlan0-va0 down");
|
| 1295 | // system ("landev_updown.sh \"wifilan\" \"down\"");
|
| 1296 | }
|
| 1297 |
|
| 1298 | static void stop_wlan0()
|
| 1299 | {
|
| 1300 | system ("ifconfig wlan0 down");
|
| 1301 | }
|
| 1302 |
|
| 1303 | static void stop_wifi()
|
| 1304 | {
|
| 1305 | // ¹Ø±Õwlan0 µÄͬʱ£¬Èç¹û¶àSSID´¦ÓÚ¿ªÆô״̬ҲÐèÒª¹Ø±Õ
|
| 1306 | // µ«ÊÇÓпÉÄܹرÕwifiµÄͬʱ£¬Ò²»á¹Ø±Õ¶àSSID£¬ËùÒÔ´Ë´¦²»ÐèÒªÔÙÅжÏ
|
| 1307 | stop_va0();
|
| 1308 | stop_va1();
|
| 1309 | stop_vxd();
|
| 1310 | stop_wlan0();
|
| 1311 | //arp_br0();
|
| 1312 | }
|
| 1313 |
|
| 1314 | //ÖØÉèÈ«¾Ö±äÁ¿
|
| 1315 | static void renew_global_acl_table()
|
| 1316 | {
|
| 1317 | char accesscontrollist0[720] = {0};
|
| 1318 | char accesspolicy0[10] = {0};
|
| 1319 | char *acl_mac_ptr = NULL;
|
| 1320 | char *acl_mac_ptr_find = NULL;
|
| 1321 | int acl_mac_num = 0;
|
| 1322 | int acl_cn = 0;
|
| 1323 |
|
| 1324 | char acl_mac_new[MAX_STA_NUM][13] = {0};
|
| 1325 | char acl_mac[18] = {0};
|
| 1326 | char acl_mac_out[13] = {0};
|
| 1327 | int tmp_num = 0;
|
| 1328 | int i = 0;
|
| 1329 |
|
| 1330 | cfg_get_item ("AccessPolicy0", accesspolicy0, sizeof (accesspolicy0));
|
| 1331 | cfg_get_item ("AccessControlList0", accesscontrollist0, sizeof (accesscontrollist0));
|
| 1332 |
|
| 1333 | acl_mac_ptr_find = accesscontrollist0;
|
| 1334 | acl_mac_num = find_substr_num (acl_mac_ptr_find, ';');
|
| 1335 | wf_log ("acl_mac_num is %d", acl_mac_num);
|
| 1336 | tmp_num = acl_mac_num;
|
| 1337 |
|
| 1338 | if (acl_mac_num >= 1 && (strcmp (accesspolicy0, "") && strcmp (accesspolicy0, "0"))) {
|
| 1339 | acl_mac_num--;
|
| 1340 | acl_mac_ptr = accesscontrollist0;
|
| 1341 | //kw 3
|
| 1342 | strncpy (acl_mac, acl_mac_ptr, 17);
|
| 1343 | deleteCharFromStr (':', acl_mac, acl_mac_out);
|
| 1344 |
|
| 1345 | strncpy (& (acl_mac_new[0][0]), acl_mac_out, 12);
|
| 1346 | wf_log ("acl_mac_new :%s", & (acl_mac_new[0][0]));
|
| 1347 |
|
| 1348 | for (acl_cn = 0; acl_cn < acl_mac_num; acl_cn++) {
|
| 1349 | if (NULL != acl_mac_ptr && (acl_mac_ptr = strstr (acl_mac_ptr, ";")) != NULL) {
|
| 1350 | acl_mac_ptr = acl_mac_ptr + 1;
|
| 1351 | strncpy (acl_mac, acl_mac_ptr, 17);
|
| 1352 | deleteCharFromStr (':', acl_mac, acl_mac_out);
|
| 1353 |
|
| 1354 | strncpy (& (acl_mac_new[0][0]) + (acl_cn + 1) * 13, acl_mac_out, 12);
|
| 1355 | wf_log ("acl_mac_new :%s", & (acl_mac_new[0][0]) + (acl_cn + 1) * 13);
|
| 1356 | }
|
| 1357 | }
|
| 1358 |
|
| 1359 | if (strcmp (accesspolicy0, "2") == 0) {
|
| 1360 |
|
| 1361 | for (i = 0; i < g_old_acl_black_mac_num; i++) {
|
| 1362 | memset (g_old_acl_black_mac[i], 0, 13);
|
| 1363 | }
|
| 1364 | g_old_acl_black_mac_num = tmp_num;
|
| 1365 | for (i = 0; i < g_old_acl_black_mac_num; i++) {
|
| 1366 | strncpy (g_old_acl_black_mac[i], (& (acl_mac_new[0][0]) + i * 13), 12);
|
| 1367 | }
|
| 1368 | } else if (strcmp (accesspolicy0, "1") == 0) {
|
| 1369 | for (i = 0; i < g_old_acl_white_mac_num; i++) {
|
| 1370 | memset (g_old_acl_white_mac[i], 0, 13);
|
| 1371 | }
|
| 1372 | g_old_acl_white_mac_num = tmp_num;
|
| 1373 | for (i = 0; i < g_old_acl_white_mac_num; i++) {
|
| 1374 | strncpy (g_old_acl_white_mac[i], (& (acl_mac_new[0][0]) + i * 13), 12);
|
| 1375 | }
|
| 1376 |
|
| 1377 | }
|
| 1378 | } else if (acl_mac_num == 0 || (!strcmp (accesspolicy0, "0"))) {
|
| 1379 | if (!strcmp (accesspolicy0, "2")) { //acl_mac_num = 0 ÉèÖúÚÃûµ¥µ«ÊÇÎÞmac
|
| 1380 | for (i = 0; i < g_old_acl_black_mac_num; i++) {
|
| 1381 | memset (g_old_acl_black_mac[i], 0, 13);
|
| 1382 | }
|
| 1383 | g_old_acl_black_mac_num = 0;
|
| 1384 | } else if (!strcmp (accesspolicy0, "1")) { //acl_mac_num = 0 ÉèÖð×Ãûµ¥µ«ÊÇÎÞmac
|
| 1385 | for (i = 0; i < g_old_acl_white_mac_num; i++) {
|
| 1386 | memset (g_old_acl_white_mac[i], 0, 13);
|
| 1387 | }
|
| 1388 | g_old_acl_white_mac_num = 0;
|
| 1389 | } else { //ÉèÖò»ÉúЧ
|
| 1390 |
|
| 1391 | }
|
| 1392 | } else {
|
| 1393 | wf_log (" accesspolicy0 error!");
|
| 1394 | }
|
| 1395 |
|
| 1396 | if (strcmp (accesspolicy0, "")) {
|
| 1397 | strncpy (old_accesspolicy, accesspolicy0, 1);
|
| 1398 | }
|
| 1399 | }
|
| 1400 |
|
| 1401 | static void set_acl_mac_num (int acl_mac_num)
|
| 1402 | {
|
| 1403 | char command_buf[100] = {0};
|
| 1404 |
|
| 1405 | sprintf (command_buf, "echo \"%d\" > %s/macac_num", acl_mac_num, CONFIG_DIR);
|
| 1406 | soft_system (command_buf);
|
| 1407 | }
|
| 1408 |
|
| 1409 | static void reset_acl_num (char *athx)
|
| 1410 | {
|
| 1411 | char cmd_buf[100] = {0};
|
| 1412 | sprintf (cmd_buf, "/bin/iwpriv %s set_mib aclnum=0", athx);
|
| 1413 | zxic_system(cmd_buf);
|
| 1414 | }
|
| 1415 |
|
| 1416 | static void remove_all_connect_sta_from_acl_table (char* athx)
|
| 1417 | {
|
| 1418 | char exist_mac[MAX_STA_NUM][13] = {0};
|
| 1419 | int sta_num = 0;
|
| 1420 | int i = 0;
|
| 1421 | char command_buf[100] = {0};
|
| 1422 |
|
| 1423 | if (NULL == athx) {
|
| 1424 | softap_assert ("[wlan]athx is null");
|
| 1425 | return;
|
| 1426 | }
|
| 1427 | sta_num = wlan_get_mac_list (& (exist_mac[0][0]), athx);
|
| 1428 |
|
| 1429 | for (i = 0; i < sta_num; i++) {
|
| 1430 | //kw 3
|
| 1431 | memset (command_buf, 0, 100);
|
| 1432 | sprintf (command_buf, "/bin/iwpriv %s del_acl_table %s", athx, exist_mac[i]);
|
| 1433 | zxic_system(command_buf);
|
| 1434 | wf_log ("[%s]:%s", athx, command_buf);
|
| 1435 | perror (command_buf);
|
| 1436 |
|
| 1437 | }
|
| 1438 | }
|
| 1439 |
|
| 1440 | //djj modified, ²»Çå¿Õg_old_acl_black_macºÍg_old_acl_black_mac_num
|
| 1441 | static void remove_old_acl_black_mac (char* athx)
|
| 1442 | {
|
| 1443 | char command_buf[100] = {0};
|
| 1444 | int i = 0;
|
| 1445 | if (NULL == athx) {
|
| 1446 | softap_assert ("[wlan] athx is null");
|
| 1447 | return;
|
| 1448 | }
|
| 1449 | for (i = 0; i < g_old_acl_black_mac_num; i++) {
|
| 1450 | memset (command_buf, 0, 100);
|
| 1451 | sprintf (command_buf, "/bin/iwpriv %s del_acl_table %s", athx, g_old_acl_black_mac[i]);
|
| 1452 | zxic_system(command_buf);
|
| 1453 | }
|
| 1454 | }
|
| 1455 |
|
| 1456 |
|
| 1457 | //djj modified, ²»Çå¿Õg_old_acl_white_macºÍg_old_acl_white_mac_num
|
| 1458 | static void remove_old_acl_white_mac (char* athx)
|
| 1459 | {
|
| 1460 | char command_buf[100] = {0};
|
| 1461 | int i = 0;
|
| 1462 | if (NULL == athx) {
|
| 1463 | softap_assert ("athx is null");
|
| 1464 | return;
|
| 1465 | }
|
| 1466 | for (i = 0; i < g_old_acl_white_mac_num; i++) {
|
| 1467 | memset (command_buf, 0, 100);
|
| 1468 | sprintf (command_buf, "/bin/iwpriv %s del_acl_table %s", athx, g_old_acl_white_mac[i]);
|
| 1469 | zxic_system(command_buf);
|
| 1470 | wf_log ("[%s]:%s", athx, command_buf);
|
| 1471 | }
|
| 1472 | }
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 | static void remove_all_mac_from_acl_table_for_blacklist (char* athx)
|
| 1477 | {
|
| 1478 | remove_old_acl_black_mac (athx);
|
| 1479 | //remove_acl_timer_mac(athx);
|
| 1480 | }
|
| 1481 |
|
| 1482 | static void remove_all_mac_from_acl_table_for_whitelist (char* athx)
|
| 1483 | {
|
| 1484 | remove_all_connect_sta_from_acl_table (athx);
|
| 1485 | remove_old_acl_white_mac (athx);
|
| 1486 | }
|
| 1487 |
|
| 1488 | static void remove_all_mac_from_acl_table_for_nonlist (char* athx)
|
| 1489 | {
|
| 1490 | char command_buf[100] = {0};
|
| 1491 | char m_ssid_enable[2] = {0};
|
| 1492 | int i = 0;
|
| 1493 | if (NULL == athx) {
|
| 1494 | softap_assert ("athx is null");
|
| 1495 | return;
|
| 1496 | }
|
| 1497 | #if 0
|
| 1498 | if (!strcmp (old_accesspolicy, "2")) {
|
| 1499 | wf_log ("<<<old_accesspolicy is 2>>> ");
|
| 1500 | for (i = 0; i < g_old_acl_black_mac_num; i++) {
|
| 1501 | memset (command_buf, 0, 100);
|
| 1502 | sprintf (command_buf, "iwpriv %s del_acl_table %s", athx, g_old_acl_black_mac[i]);
|
| 1503 | system (command_buf);
|
| 1504 | //wf_log("remove_all_connect_sta_from_acl_table 2command_buf is %s", command_buf);
|
| 1505 | wf_log ("remove_all_mac_from_acl_table_for_nonlist old blacklist del_acl_table,%s", g_old_acl_black_mac[i]);
|
| 1506 | //perror(command_buf);
|
| 1507 | }
|
| 1508 | } else if (!strcmp (old_accesspolicy, "1")) {
|
| 1509 | wf_log ("<<<old_accesspolicy is 1 >>> ");
|
| 1510 | for (i = 0; i < g_old_acl_white_mac_num; i++) {
|
| 1511 | memset (command_buf, 0, 100);
|
| 1512 | sprintf (command_buf, "iwpriv %s del_acl_table %s", athx, g_old_acl_white_mac[i]);
|
| 1513 | system (command_buf);
|
| 1514 | //perror(command_buf);
|
| 1515 | //wf_log("remove_all_connect_sta_from_acl_table 1command_buf is %s", command_buf);
|
| 1516 | wf_log ("remove_all_mac_from_acl_table_for_nonlist old whitelist del_acl_table,%s", g_old_acl_white_mac[i]);
|
| 1517 | }
|
| 1518 | }
|
| 1519 | #else
|
| 1520 | memset (command_buf, 0, sizeof (command_buf));
|
| 1521 | sprintf (command_buf, "/bin/iwpriv %s clear_acl_table", athx);
|
| 1522 | wf_log ("cmd= %s", command_buf);
|
| 1523 | zxic_system(command_buf);
|
| 1524 | #endif
|
| 1525 | }
|
| 1526 |
|
| 1527 | static void set_accesspolicy0 (char* accesspolicy0, char* athx)
|
| 1528 | {
|
| 1529 | char command_buf[100] = {0};
|
| 1530 |
|
| 1531 | if (NULL == athx) {
|
| 1532 | softap_assert ("athx is null");
|
| 1533 | return;
|
| 1534 | }
|
| 1535 |
|
| 1536 | if (NULL == accesspolicy0) {
|
| 1537 | softap_assert ("accesspolicy0 is null");
|
| 1538 | return;
|
| 1539 | }
|
| 1540 | memset (command_buf, 0, 100);
|
| 1541 | //²»Ê¹ÓÃÎļþ·½Ê½ÉèÖÃaclmode£¬¶øÊ¹ÓÃiwpriv·½Ê½Ö±½ÓÉèÖÃ
|
| 1542 | #if 0
|
| 1543 | if (!strcmp (accesspolicy0, "1")) { //white
|
| 1544 | sprintf (command_buf, "echo \"1\" > %s/macac_enabled", CONFIG_DIR);
|
| 1545 | } else if (!strcmp (accesspolicy0, "2")) { // black
|
| 1546 | sprintf (command_buf, "echo \"2\" > %s/macac_enabled", CONFIG_DIR);
|
| 1547 | } else if (!strcmp (accesspolicy0, "0")) {
|
| 1548 | sprintf (command_buf, "echo \"0\" > %s/macac_enabled", CONFIG_DIR);
|
| 1549 | }
|
| 1550 | system (command_buf);
|
| 1551 | memset (command_buf, 0, 100);
|
| 1552 | #endif
|
| 1553 | sprintf (command_buf, "/bin/iwpriv %s set_mib aclmode=%s", athx, accesspolicy0);
|
| 1554 | zxic_system(command_buf);
|
| 1555 | wf_log ("set_acl_mode :%s", command_buf);
|
| 1556 | }
|
| 1557 |
|
| 1558 | //²»ÐèÒª¶¨Ê±ºÚÃûµ¥
|
| 1559 | static void set_acl_mode (char * athx)
|
| 1560 | {
|
| 1561 | //char accesscontrollist0[720] = {0};
|
| 1562 | char accesspolicy0[10] = {0};
|
| 1563 | char cmd_buf[100] = {0};
|
| 1564 |
|
| 1565 | cfg_get_item ("AccessPolicy0", accesspolicy0, sizeof (accesspolicy0));
|
| 1566 | //cfg_get_item("AccessControlList0",accesscontrollist0,sizeof(accesscontrollist0));
|
| 1567 |
|
| 1568 | if (strcmp (accesspolicy0, "")) {
|
| 1569 | wf_log ("accesspolicy0 :%s,old_accesspolicy:%s", accesspolicy0, old_accesspolicy);
|
| 1570 | set_accesspolicy0 (accesspolicy0, athx);
|
| 1571 | if (strcmp (accesspolicy0, "0") && strcmp (old_accesspolicy, "0") && strcmp (accesspolicy0, old_accesspolicy)) { //֮ǰÉèÖõIJ»ÊDz»ÉúЧÇÒµ±Ç°ÉèÖõÄÒ²²»ÊÇ ²»ÉúЧ Á½´ÎÉèÖà ÓÐ Çл»
|
| 1572 | wf_log ("remove_all_mac_from_acl_table_for_nonlist");
|
| 1573 | //remove_all_mac_from_acl_table_for_nonlist(athx); // after reboot, the global value is NULL, so this func doesn't work
|
| 1574 | memset (cmd_buf, 0, sizeof (cmd_buf)); //if acl mode swithed between black and white, clear acl table without doubt
|
| 1575 | sprintf (cmd_buf, "/bin/iwpriv %s clear_acl_table", athx);
|
| 1576 | zxic_system(cmd_buf);
|
| 1577 | wf_log ("set_acl_mode %s", cmd_buf);
|
| 1578 | }
|
| 1579 |
|
| 1580 | } else {
|
| 1581 | wf_log ("accesspolicy0 error");
|
| 1582 | }
|
| 1583 | }
|
| 1584 |
|
| 1585 | static void add_mac_to_acl_table (char* acl_mac_ptr, char* athx, char* accesspolicy0, char* p_acl_mac_new, char* exist_flag, int index)
|
| 1586 | {
|
| 1587 | char acl_mac[18] = {0};
|
| 1588 | char command_buf[100] = {0};
|
| 1589 | char acl_mac_out[13] = {0};
|
| 1590 | int i = 0;
|
| 1591 |
|
| 1592 | if (NULL == acl_mac_ptr) {
|
| 1593 | softap_assert ("add_mac_in_acl_table acl_mac_ptr is null");
|
| 1594 | return;
|
| 1595 | }
|
| 1596 | if (NULL == accesspolicy0) {
|
| 1597 | softap_assert ("add_mac_in_acl_table accesspolicy0 is null");
|
| 1598 | return;
|
| 1599 | }
|
| 1600 | if (NULL == p_acl_mac_new) {
|
| 1601 | softap_assert ("add_mac_in_acl_table acl_mac_new is null");
|
| 1602 | return;
|
| 1603 | }
|
| 1604 | if (NULL == athx) {
|
| 1605 | softap_assert ("add_mac_in_acl_table athx is null");
|
| 1606 | return;
|
| 1607 | }
|
| 1608 | if (NULL == exist_flag) {
|
| 1609 | softap_assert ("add_mac_in_acl_table exist_flag is null");
|
| 1610 | return;
|
| 1611 | }
|
| 1612 | strncpy (acl_mac, acl_mac_ptr, 17);
|
| 1613 | deleteCharFromStr (':', acl_mac, acl_mac_out);
|
| 1614 |
|
| 1615 | sprintf (command_buf, "/bin/iwpriv %s add_acl_table %s", athx, acl_mac_out);
|
| 1616 | zxic_system(command_buf);
|
| 1617 | perror (command_buf);
|
| 1618 |
|
| 1619 | if (!strcmp (accesspolicy0, "2")) {
|
| 1620 | for (i = 0; i < g_old_acl_black_mac_num; i++) {
|
| 1621 | if (!strcmp (g_old_acl_black_mac[i], acl_mac_out)) {//kw 3
|
| 1622 | exist_flag[i] = 0x31;
|
| 1623 | }
|
| 1624 | }
|
| 1625 | } else if (!strcmp (accesspolicy0, "1")) {
|
| 1626 | for (i = 0; i < g_old_acl_white_mac_num; i++) {
|
| 1627 | if (!strcmp (g_old_acl_white_mac[i], acl_mac_out)) {//kw 3
|
| 1628 | exist_flag[i] = 0x31;
|
| 1629 | }
|
| 1630 | }
|
| 1631 | }
|
| 1632 |
|
| 1633 | strncpy (p_acl_mac_new + index * 13, acl_mac_out, 12);
|
| 1634 | wf_log ("[%s]add_mac_in_acl_table acl_mac_new+%d is %s", athx, index, (p_acl_mac_new + index * 13));
|
| 1635 | }
|
| 1636 |
|
| 1637 | //djj modified,²»ÖØÉèÈ«¾Ö±äÁ¿g_old_acl_black_macºÍg_old_acl_black_mac_num
|
| 1638 | static void del_not_exist_elment_from_old_acl_blacklist (char* exist_flag, char* p_acl_mac_new, int tmp_num, char* athx)
|
| 1639 | {
|
| 1640 | int i = 0;
|
| 1641 | char command_buf[100] = {0};
|
| 1642 | char m_ssid_enable[8] = {0};
|
| 1643 | if (NULL == p_acl_mac_new) {
|
| 1644 | softap_assert (" acl_mac_new+index is null");
|
| 1645 | return;
|
| 1646 | }
|
| 1647 | if (NULL == exist_flag) {
|
| 1648 | softap_assert (" exist_flag is null");
|
| 1649 | return;
|
| 1650 | }
|
| 1651 | if (NULL == athx) {
|
| 1652 | softap_assert (" athx is null");
|
| 1653 | return;
|
| 1654 | }
|
| 1655 | for (i = 0; i < g_old_acl_black_mac_num; i++) {
|
| 1656 | if (exist_flag[i] != 0x31 && strcmp (g_old_acl_black_mac[i], "")) {
|
| 1657 | memset (command_buf, 0, 100);
|
| 1658 | sprintf (command_buf, "/bin/iwpriv %s del_acl_table %s", athx, g_old_acl_black_mac[i]);
|
| 1659 | zxic_system(command_buf);
|
| 1660 | wf_log ("command_buf is %s", command_buf);
|
| 1661 | }
|
| 1662 |
|
| 1663 | }
|
| 1664 |
|
| 1665 | }
|
| 1666 |
|
| 1667 | //djj modified,²»ÖØÉèÈ«¾Ö±äÁ¿g_old_acl_white_macºÍg_old_acl_white_mac_num
|
| 1668 | static void del_not_exist_elment_from_old_acl_whitelist (char* exist_flag, char* p_acl_mac_new, int tmp_num, char* athx)
|
| 1669 | {
|
| 1670 | int i = 0;
|
| 1671 | char command_buf[100] = {0};
|
| 1672 |
|
| 1673 | if (NULL == p_acl_mac_new) {
|
| 1674 | softap_assert (" acl_mac_new+index is null");
|
| 1675 | return;
|
| 1676 | }
|
| 1677 | if (NULL == exist_flag) {
|
| 1678 | softap_assert (" exist_flag is null");
|
| 1679 | return;
|
| 1680 | }
|
| 1681 | if (NULL == athx) {
|
| 1682 | softap_assert (" athx is null");
|
| 1683 | return;
|
| 1684 | }
|
| 1685 |
|
| 1686 | for (i = 0; i < g_old_acl_white_mac_num; i++) {
|
| 1687 | if (exist_flag[i] != 0x31) {
|
| 1688 | memset (command_buf, 0, 100);
|
| 1689 | sprintf (command_buf, "/bin/iwpriv %s del_acl_table %s", athx, g_old_acl_white_mac[i]);
|
| 1690 | zxic_system(command_buf);
|
| 1691 | wf_log ("del_not_exist_elment_from_old_acl_whitelist command_buf is %s", command_buf);
|
| 1692 | }
|
| 1693 | }
|
| 1694 |
|
| 1695 | }
|
| 1696 |
|
| 1697 | static void del_connect_sta_for_set_whitelist (int tmp_num, char* athx, char* p_acl_mac_new)
|
| 1698 | {
|
| 1699 | char exist_mac[MAX_STA_NUM][13] = {0};
|
| 1700 | int sta_num = 0;
|
| 1701 | int i, j = 0;
|
| 1702 | int exist_mac_flag[MAX_STA_NUM] = {0};
|
| 1703 | char command_buf[100] = {0};
|
| 1704 |
|
| 1705 | if (NULL == athx) {
|
| 1706 | softap_assert (" athx is null");
|
| 1707 | return;
|
| 1708 | }
|
| 1709 | if (NULL == p_acl_mac_new) {
|
| 1710 | softap_assert (" acl_mac_new is null");
|
| 1711 | return;
|
| 1712 | }
|
| 1713 | sta_num = wlan_get_mac_list (& (exist_mac[0][0]), athx);
|
| 1714 |
|
| 1715 | for (i = 0; i < sta_num; i++) {
|
| 1716 | for (j = 0; j < tmp_num; j++) {
|
| 1717 | if (!strcasecmp (exist_mac[i], (p_acl_mac_new + j * 13))) {//kw 3
|
| 1718 | exist_mac_flag[i] = 1;
|
| 1719 | }
|
| 1720 | }
|
| 1721 | if (!exist_mac_flag[i]) {
|
| 1722 | memset (command_buf, 0, 100);
|
| 1723 | sprintf (command_buf, "/bin/iwpriv %s del_acl_table %s", athx, exist_mac[i]);
|
| 1724 | zxic_system(command_buf);
|
| 1725 | perror (command_buf);
|
| 1726 | wf_log ("[%s]:%s", athx, exist_mac[i]);
|
| 1727 | }
|
| 1728 | }
|
| 1729 | }
|
| 1730 |
|
| 1731 | //djj modified, È¥µôold_accesspolicyÉèÖÃ
|
| 1732 | void acl_set_mac (char *athx)
|
| 1733 | {
|
| 1734 | char accesscontrollist0[720] = {0};
|
| 1735 | char accesspolicy0[10] = {0};
|
| 1736 |
|
| 1737 | char *acl_mac_ptr = NULL;
|
| 1738 | char *acl_mac_ptr_find = NULL;
|
| 1739 | int acl_mac_num = 0;
|
| 1740 | int acl_cn = 0;
|
| 1741 |
|
| 1742 | char exist_flag[MAX_STA_NUM] = {0};
|
| 1743 | char acl_mac_new[MAX_STA_NUM][13] = {0};
|
| 1744 |
|
| 1745 | int tmp_num = 0;
|
| 1746 |
|
| 1747 | cfg_get_item ("AccessPolicy0", accesspolicy0, sizeof (accesspolicy0));
|
| 1748 | cfg_get_item ("AccessControlList0", accesscontrollist0, sizeof (accesscontrollist0));
|
| 1749 |
|
| 1750 | acl_mac_ptr_find = accesscontrollist0;
|
| 1751 | acl_mac_num = find_substr_num (acl_mac_ptr_find, ';');
|
| 1752 | wf_log ("%s accesspolicy0 =%s, accesscontrollist0=%s", athx, accesspolicy0, accesscontrollist0);
|
| 1753 | wf_log ("g_old_acl_black_mac_num =%d, g_old_acl_white_mac_num=%d", g_old_acl_black_mac_num, g_old_acl_white_mac_num);
|
| 1754 |
|
| 1755 | tmp_num = acl_mac_num;
|
| 1756 |
|
| 1757 | set_acl_mode (athx); //ÉèÖÃacl mode
|
| 1758 | reset_acl_num (athx); //ÉèÖÃacl num
|
| 1759 |
|
| 1760 | if (acl_mac_num >= 1 && (strcmp (accesspolicy0, "") && strcmp (accesspolicy0, "0"))) {
|
| 1761 | acl_mac_num--;
|
| 1762 | acl_mac_ptr = accesscontrollist0;
|
| 1763 | add_mac_to_acl_table (acl_mac_ptr, athx, accesspolicy0, & (acl_mac_new[0][0]), exist_flag, 0);
|
| 1764 | for (acl_cn = 0; acl_cn < acl_mac_num; acl_cn++) {
|
| 1765 | if ( (acl_mac_ptr = strstr (acl_mac_ptr, ";")) != NULL) {
|
| 1766 | acl_mac_ptr = acl_mac_ptr + 1;
|
| 1767 | add_mac_to_acl_table (acl_mac_ptr, athx, accesspolicy0, & (acl_mac_new[0][0]), exist_flag, acl_cn + 1);
|
| 1768 | } else {//klocwork
|
| 1769 | break;
|
| 1770 | }
|
| 1771 | }
|
| 1772 | if (!strcmp (accesspolicy0, "2")) {
|
| 1773 | del_not_exist_elment_from_old_acl_blacklist (exist_flag, & (acl_mac_new[0][0]), tmp_num, athx);
|
| 1774 | //del_not_exist_elment_from_old_acl_timer_blacklist(athx);
|
| 1775 | } else if (!strcmp (accesspolicy0, "1")) {
|
| 1776 | del_not_exist_elment_from_old_acl_whitelist (exist_flag, & (acl_mac_new[0][0]), tmp_num, athx);
|
| 1777 | del_connect_sta_for_set_whitelist (tmp_num, athx, & (acl_mac_new[0][0]));
|
| 1778 | }
|
| 1779 | } else if (acl_mac_num == 0 || (!strcmp (accesspolicy0, "0"))) {
|
| 1780 | if (!strcmp (accesspolicy0, "2")) { //acl_mac_num = 0 ÉèÖúÚÃûµ¥µ«ÊÇÎÞmac
|
| 1781 | wf_log ("accesspolicy0 is 2, but acl mac num is 0");
|
| 1782 | remove_all_mac_from_acl_table_for_blacklist (athx);
|
| 1783 | } else if (!strcmp (accesspolicy0, "1")) { //acl_mac_num = 0 ÉèÖð×Ãûµ¥µ«ÊÇÎÞmac
|
| 1784 | wf_log ("accesspolicy0 is 1, but acl mac num is 0");
|
| 1785 | remove_all_mac_from_acl_table_for_whitelist (athx);
|
| 1786 | } else { //ÉèÖò»ÉúЧ
|
| 1787 | wf_log ("accesspolicy0 is 0");
|
| 1788 | remove_all_mac_from_acl_table_for_nonlist (athx);
|
| 1789 | }
|
| 1790 | } else {
|
| 1791 | wf_log ("accesspolicy0 is error");
|
| 1792 | }
|
| 1793 | }
|
| 1794 |
|
| 1795 | void open_wifi_nv_set()
|
| 1796 | {
|
| 1797 | cfg_set ("wifiSleep", "0");
|
| 1798 | cfg_set ("wifiEnabled", "1");
|
| 1799 | cfg_set ("wifi_cur_state", WIFI_OPENED);
|
| 1800 | }
|
| 1801 |
|
| 1802 | void close_wifi_nv_set()
|
| 1803 | {
|
| 1804 | cfg_set ("wifi_cur_state", WIFI_CLOSED);
|
| 1805 | cfg_set ("wifiEnabled", "0");
|
| 1806 | }
|
| 1807 |
|
| 1808 | void confirm_close_vxd()
|
| 1809 | {
|
| 1810 |
|
| 1811 | int ret = -1;
|
| 1812 | retry:
|
| 1813 | ret = wfsystem ("ifconfig wlan0-vxd |grep UP");
|
| 1814 |
|
| 1815 | if (ret == 0) {
|
| 1816 | system ("ifconfig wlan0-vxd down");
|
| 1817 | sleep (1);
|
| 1818 | goto retry;
|
| 1819 | }
|
| 1820 |
|
| 1821 | }
|
| 1822 |
|
| 1823 | static const char* to_string (int wifi_cmd)
|
| 1824 | {
|
| 1825 | switch (wifi_cmd) {
|
| 1826 | CASE_RETURN_STR (WIFI_CFG_OPEN); //´ò¿ªwifi
|
| 1827 | CASE_RETURN_STR (WIFI_CFG_CLOSE); //¹Ø±Õwifi
|
| 1828 | CASE_RETURN_STR (WIFI_CFG_OPEN_MSSID); //´ò¿ª¸±ssid
|
| 1829 | CASE_RETURN_STR (WIFI_CFG_CLOSE_MSSID); //¹Ø±Õ¸±ssid
|
| 1830 | CASE_RETURN_STR (WIFI_CFG_OPEN_VA0_VA1); //´ò¿ªÖ÷¸±ssid
|
| 1831 | CASE_RETURN_STR (WIFI_CFG_RF); //ÅäÖÃÉ䯵²ÎÊý
|
| 1832 | CASE_RETURN_STR (WIFI_CFG_AP); //ÅäÖÃAP
|
| 1833 | CASE_RETURN_STR (WIFI_CFG_MSSID); //ÅäÖø±ssid
|
| 1834 | CASE_RETURN_STR (WIFI_CFG_RESTART_APSTATION); //ÖØÆôµ½ap station
|
| 1835 | CASE_RETURN_STR (WIFI_CFG_RESTART_AP); //ÖØÆôµ½ap
|
| 1836 | CASE_RETURN_STR (WIFI_CFG_CLOSESTA_OPENMSSID); //¹Ø±Õstation£¬´ò¿ª¸±ssid
|
| 1837 | CASE_RETURN_STR (WIFI_CFG_FORCE_RESTART); //Ç¿ÖÆÖØÆôwifi
|
| 1838 | CASE_RETURN_STR (WIFI_CFG_SLEEP); //˯Ãß
|
| 1839 | }
|
| 1840 | return "UNKNOWN cmd";
|
| 1841 | }
|
| 1842 |
|
| 1843 | void clear_sta_count_nv()
|
| 1844 | {
|
| 1845 | ap_server->g_sta_num = 0;
|
| 1846 | cfg_set ("sta_count", "0");
|
| 1847 | cfg_set ("m_sta_count", "0");
|
| 1848 | }
|
| 1849 |
|
| 1850 | int wlan_system(const char * str1, const char * str2)
|
| 1851 | {
|
| 1852 |
|
| 1853 | pid_t ret = 0 ;
|
| 1854 | int len = 0;
|
| 1855 | char *buf = NULL;
|
| 1856 |
|
| 1857 | if(str1 == NULL || str2 == NULL){
|
| 1858 | softap_assert("wlan_system para is NULL");
|
| 1859 | return -1; //klocwork
|
| 1860 | }
|
| 1861 |
|
| 1862 | len = strlen(str1) + strlen(str2) + 8;
|
| 1863 |
|
| 1864 | buf = (char *)safe_malloc(len, 0);
|
| 1865 | if(NULL == buf){
|
| 1866 | wf_err("can not malloc memory len = %d", len);
|
| 1867 | return -1;
|
| 1868 | }
|
| 1869 |
|
| 1870 | sprintf(buf, "%s %s", str1, str2);
|
| 1871 | ret = zxic_system(buf);
|
| 1872 | wf_log ("[%s], ret = %d", buf, ret);
|
| 1873 | #if 0 //kw 3
|
| 1874 | wf_log ("[%s]ret = %d, WIFEXITED(ret)=%d, WEXITSTATUS(ret) =%d",str2, ret , WIFEXITED (ret), WEXITSTATUS (ret));
|
| 1875 | if (! (-1 != ret && WIFEXITED (ret) && 0 == WEXITSTATUS (ret))) {
|
| 1876 | safe_free(buf);
|
| 1877 | return -1;
|
| 1878 | }
|
| 1879 | #endif
|
| 1880 | wf_log ("[%s]ret = %d",str2, ret);
|
| 1881 | if (ret != 0) { // include WEXITSTATUS
|
| 1882 | safe_free(buf);
|
| 1883 | return -1;
|
| 1884 | }
|
| 1885 |
|
| 1886 | safe_free(buf);
|
| 1887 | return ret;
|
| 1888 | }
|
| 1889 |
|
| 1890 |
|
| 1891 | /*
|
| 1892 | just below case
|
| 1893 |
|
| 1894 | va0:va1
|
| 1895 | 0 0
|
| 1896 | 1 0
|
| 1897 | 1 1
|
| 1898 |
|
| 1899 | */
|
| 1900 | void wlan_set_state(int va0_state, int va1_state)
|
| 1901 | {
|
| 1902 | if(va0_state == WLAN_OFF){
|
| 1903 | if(0 == ap_server->ap0_state)return;
|
| 1904 | close_wifi_nv_set();
|
| 1905 | write_status (WIFISTATUS, WIFI_CLOSED);
|
| 1906 | ap_server->ap0_state = 0;
|
| 1907 | ap_server->ap1_state = 0;
|
| 1908 | }
|
| 1909 | else if(va0_state == WLAN_ON){
|
| 1910 | open_wifi_nv_set();
|
| 1911 | write_status (WIFISTATUS, WIFI_OPENED);
|
| 1912 | ap_server->ap0_state = va0_state;
|
| 1913 | ap_server->ap1_state = va1_state;
|
| 1914 | }
|
| 1915 | }
|
| 1916 |
|
| 1917 |
|
| 1918 | void wlan_basic_close(char *wifi_sta_connection, char* m_ssid_enable)
|
| 1919 | {
|
| 1920 | clear_sta_count_nv();
|
| 1921 | #ifdef __STA_FUNC__
|
| 1922 | if (strcmp (wifi_sta_connection, "1") == 0) {
|
| 1923 | wifi_station_close();
|
| 1924 | }
|
| 1925 | #endif
|
| 1926 | stop_va0();
|
| 1927 | if (1 == atoi (m_ssid_enable))
|
| 1928 | stop_va1();
|
| 1929 | if (1 == atoi (wifi_sta_connection))
|
| 1930 | stop_vxd();
|
| 1931 | stop_wlan0();
|
| 1932 | wlan_set_state(WLAN_OFF,WLAN_OFF);
|
| 1933 |
|
| 1934 | }
|
| 1935 |
|
| 1936 | void wlan_basic_open_va0_apsta(char *wifi_sta_connection)
|
| 1937 | {
|
| 1938 |
|
| 1939 | if (wlan_system(WLAN_DEAL, "open_va0") < 0) {
|
| 1940 | wlan_set_state(WLAN_OFF,WLAN_OFF);
|
| 1941 | return;
|
| 1942 | }
|
| 1943 |
|
| 1944 | wlan_set_state(WLAN_ON,WLAN_OFF);
|
| 1945 | #ifdef __STA_FUNC__
|
| 1946 | if (strcmp (wifi_sta_connection, "1") == 0) {
|
| 1947 | wlan_set_vxd_on();
|
| 1948 | wlan_station_init();
|
| 1949 | }
|
| 1950 | #endif
|
| 1951 | }
|
| 1952 |
|
| 1953 | void wlan_basic_open_va0_va1()
|
| 1954 | {
|
| 1955 |
|
| 1956 | wlan_set_va1_on();
|
| 1957 |
|
| 1958 | if (wlan_system(WLAN_DEAL,"open_va0_va1") < 0) {
|
| 1959 | wlan_set_state(WLAN_OFF,WLAN_OFF);
|
| 1960 | return;
|
| 1961 | }
|
| 1962 |
|
| 1963 | wlan_set_state(WLAN_ON,WLAN_ON);
|
| 1964 |
|
| 1965 | // Ö»ÐèÒªÉèÖø±SSIDµÄºÚ°×Ãûµ¥ --- TODO: Ö÷¸±siidµÄºÚ°×Ãûµ¥°´ÀíÓ¦¸Ã·Ö¿ª¹ÜÀí£¬ºóÐøÓÅ»¯
|
| 1966 | acl_set_mac ("wlan0-va1");
|
| 1967 | }
|
| 1968 |
|
| 1969 | /*
|
| 1970 | µ±webui´ò¿ªmssid £¬apsta´¦ÓڹرÕ״̬
|
| 1971 | ÓÉÓÚÉæ¼°µ½×î´ó½ÓÈëÊýµÄÇл»£¬ËùÒÔÐèÒªÏȹرÕva0
|
| 1972 | */
|
| 1973 | void wlan_basic_open_va1()
|
| 1974 | {
|
| 1975 |
|
| 1976 | clear_sta_count_nv();
|
| 1977 |
|
| 1978 | wlan_set_va1_on();
|
| 1979 |
|
| 1980 | if (wlan_system(WLAN_DEAL, "open_va1") < 0) {
|
| 1981 | wlan_set_state(WLAN_OFF,WLAN_OFF);
|
| 1982 | return;
|
| 1983 | }
|
| 1984 | wlan_set_state(WLAN_ON,WLAN_ON);
|
| 1985 |
|
| 1986 | acl_set_mac ("wlan0-va1");
|
| 1987 |
|
| 1988 | }
|
| 1989 | /*
|
| 1990 | //open-mssid µ±webui´ò¿ªmssid £¬apsta´¦ÓڹرÕ״̬
|
| 1991 | //ÓÉÓÚÉæ¼°µ½×î´ó½ÓÈëÊýµÄÇл»£¬ËùÒÔÐèÒªÏȹرÕva0
|
| 1992 | */
|
| 1993 | void wlan_basic_close_va1()
|
| 1994 | {
|
| 1995 | clear_sta_count_nv();
|
| 1996 |
|
| 1997 | wlan_set_va1_off();
|
| 1998 | if (wlan_system(WLAN_DEAL, "close_va1") < 0) {
|
| 1999 | wlan_set_state(WLAN_OFF,WLAN_OFF);
|
| 2000 | return;
|
| 2001 | }
|
| 2002 |
|
| 2003 | wlan_set_state(WLAN_ON,WLAN_OFF);
|
| 2004 |
|
| 2005 | }
|
| 2006 | /*
|
| 2007 | ±ØÐë¹Ø±Õmultissid,²»ÐèÒª´«µÝ²ÎÊý
|
| 2008 | webui ÔÚµ¥ap»òÕßmssidģʽÏ¿ªÆôapsta
|
| 2009 | */
|
| 2010 | void wlan_basic_restart_apsta()
|
| 2011 | {
|
| 2012 |
|
| 2013 | write_status (WIFISTATUS, WIFI_CLOSED);
|
| 2014 | wlan_set_vxd_on();
|
| 2015 | // mssid ÓпÉÄÜÊÇ¿ªÆô״̬£¬Ò²¿ÉÄÜÊǹرÕ״̬£¬µ«ÊÇÐèҪȷ±£ÊǹرÕ
|
| 2016 | if (ap_server->ap1_state == 1) {
|
| 2017 | clear_sta_count_nv();
|
| 2018 |
|
| 2019 | wlan_set_va1_off();
|
| 2020 | if (wlan_system(WLAN_DEAL, "close_va1") < 0) {
|
| 2021 | wlan_set_state(WLAN_OFF,WLAN_OFF);
|
| 2022 | return;
|
| 2023 | }
|
| 2024 | }
|
| 2025 | wlan_set_state(WLAN_ON, WLAN_OFF);
|
| 2026 | #ifdef __STA_FUNC__
|
| 2027 | wlan_station_init();
|
| 2028 | #endif
|
| 2029 | // ·¢ÏûÏ¢Á÷³ÌÔÚwlan-stationÀïÃæ£¬´Ë´¦²»ÔÙ·¢ËÍ
|
| 2030 | }
|
| 2031 |
|
| 2032 | /*
|
| 2033 | sta »á¸úËæ¶Ô·½AP µÄchannel£¬µ¼ÖÂ×ÔÉíAP channel±ä¸ü£¬¿ÉÄܵ½ÁË1~4 channel£¬ËùÒÔÔڹرÕstaºó£¬ÐèÒªÈÃ×ÔÉí
|
| 2034 | AP ¶Ôchannel ÖØÐÂÑ¡Ôñ£¬±Ü¿ª1~4 channel
|
| 2035 |
|
| 2036 | */
|
| 2037 | void wlan_trigger_autoch()
|
| 2038 | {
|
| 2039 | char wifi_lte_intr[8] = {0};
|
| 2040 | cfg_get_item ("wifi_lte_intr", wifi_lte_intr, sizeof (wifi_lte_intr));
|
| 2041 |
|
| 2042 | if (strcmp (wifi_lte_intr, "1") == 0) {
|
| 2043 | wf_log ("wifi_lte_intr:::iwpriv wlan0 autoch");
|
| 2044 | system ("iwpriv wlan0 autoch");
|
| 2045 | } else {
|
| 2046 | wf_log ("wifi_lte_intr= 0");
|
| 2047 | }
|
| 2048 | }
|
| 2049 |
|
| 2050 | /*
|
| 2051 |
|
| 2052 | closesta-openmssid µ±webui´ò¿ªmssid £¬apsta´¦ÓÚ¿ªÆô״̬
|
| 2053 | wlan-station ÒѹرÕstation
|
| 2054 |
|
| 2055 | */
|
| 2056 | void wlan_basic_closesta_openmssid()
|
| 2057 | {
|
| 2058 | clear_sta_count_nv();
|
| 2059 | write_status (WIFISTATUS, "0");//??
|
| 2060 |
|
| 2061 | wlan_set_vxd_off();
|
| 2062 | wlan_set_va1_on();
|
| 2063 | if (wlan_system(WLAN_DEAL, "close_sta_open_va1") < 0) {
|
| 2064 | wlan_set_state(WLAN_OFF,WLAN_OFF);
|
| 2065 | return;
|
| 2066 | }
|
| 2067 |
|
| 2068 | confirm_close_vxd();
|
| 2069 | wlan_set_state(WLAN_ON,WLAN_ON);
|
| 2070 | acl_set_mac ("wlan0-va1");
|
| 2071 |
|
| 2072 | wlan_trigger_autoch();
|
| 2073 |
|
| 2074 | }
|
| 2075 |
|
| 2076 | /*
|
| 2077 | restart-ap ÔÚwebui¹Ø±Õapsta£¬»Ö¸´µ½µ¥APģʽ
|
| 2078 | */
|
| 2079 | void wlan_basic_restart_ap()
|
| 2080 | {
|
| 2081 |
|
| 2082 | wlan_set_vxd_off();
|
| 2083 | system ("ifconfig wlan0-vxd down");
|
| 2084 |
|
| 2085 | wlan_trigger_autoch();
|
| 2086 | }
|
| 2087 |
|
| 2088 |
|
| 2089 | /*ÉèÖø±SSID ²ÎÊý£¬´Ëʱapsta¿Ï¶¨´¦ÓڹرÕ״̬*/
|
| 2090 | void wlan_basic_cfg_va1()
|
| 2091 | {
|
| 2092 | cfg_set ("m_sta_count", "0");
|
| 2093 | write_status (WIFISTATUS, "0");
|
| 2094 |
|
| 2095 | wlan_ap_para_set ("wlan0-va1");
|
| 2096 | #ifdef __AP_FUNC__
|
| 2097 | #ifdef __USE_AES__
|
| 2098 | wifi_encrypt_code();
|
| 2099 | #endif
|
| 2100 | #endif
|
| 2101 |
|
| 2102 | if (wlan_system(PARASET, "wlan0-va1") < 0) {
|
| 2103 | wlan_set_state(WLAN_OFF,WLAN_OFF);
|
| 2104 | return;
|
| 2105 | }
|
| 2106 |
|
| 2107 | wlan_set_state(WLAN_ON,WLAN_ON);
|
| 2108 | }
|
| 2109 |
|
| 2110 | void wlan_basic_cfg_va0(char *m_ssid_enable)
|
| 2111 | {
|
| 2112 | cfg_set ("sta_count", "0");
|
| 2113 | write_status (WIFISTATUS, "0");
|
| 2114 | wlan_ap_para_set ("wlan0-va0");
|
| 2115 | #ifdef __AP_FUNC__
|
| 2116 | #ifdef __USE_AES__
|
| 2117 | wifi_encrypt_code();
|
| 2118 | #endif
|
| 2119 | #endif
|
| 2120 | if (wlan_system(PARASET, "wlan0-va0") < 0) {
|
| 2121 | wlan_set_state(WLAN_OFF,WLAN_OFF);
|
| 2122 | return;
|
| 2123 | }
|
| 2124 |
|
| 2125 | wlan_set_state(WLAN_ON,atoi(m_ssid_enable));
|
| 2126 | }
|
| 2127 |
|
| 2128 | void wlan_basic_cfg_rf(char *wifi_sta_connection, char *m_ssid_enable)
|
| 2129 | {
|
| 2130 | clear_sta_count_nv();
|
| 2131 | #ifdef __STA_FUNC__
|
| 2132 | if (strcmp (wifi_sta_connection, "1") == 0) {
|
| 2133 | wifi_station_close();
|
| 2134 | }
|
| 2135 | #endif
|
| 2136 | write_status (WIFISTATUS, "0");
|
| 2137 | wlan0_radio_para_set();
|
| 2138 | // para set script close wlan0 va0 va1 and vxd interface, so C code no this work
|
| 2139 | if (wlan_system(PARASET, "wlan0") < 0) {
|
| 2140 | wlan_set_state(WLAN_OFF,WLAN_OFF);
|
| 2141 | return;
|
| 2142 | }
|
| 2143 |
|
| 2144 | wlan_set_state(WLAN_ON, atoi(m_ssid_enable));
|
| 2145 | #ifdef __STA_FUNC__
|
| 2146 | if (strcmp (wifi_sta_connection, "1") == 0) {
|
| 2147 | wlan_station_init();
|
| 2148 | }
|
| 2149 | #endif
|
| 2150 | }
|
| 2151 |
|
| 2152 | void wlan_basic_force_restart(char *wifi_sta_connection, char *m_ssid_enable)
|
| 2153 | {
|
| 2154 | clear_sta_count_nv();
|
| 2155 |
|
| 2156 | write_status (WIFISTATUS, "0");
|
| 2157 | #ifdef __STA_FUNC__
|
| 2158 | if (strcmp (wifi_sta_connection, "1") == 0) {
|
| 2159 | wifi_station_close();
|
| 2160 | }
|
| 2161 | #endif
|
| 2162 | stop_va0();
|
| 2163 | if (1 == atoi (m_ssid_enable))
|
| 2164 | stop_va1();
|
| 2165 | if (1 == atoi (wifi_sta_connection))
|
| 2166 | stop_vxd();
|
| 2167 | stop_wlan0();
|
| 2168 | wlan_init();
|
| 2169 | }
|
| 2170 |
|
| 2171 | void wlan_single_ap_close()
|
| 2172 | {
|
| 2173 | clear_sta_count_nv();
|
| 2174 | stop_wlan0();
|
| 2175 | wlan_set_state(WLAN_OFF,WLAN_OFF);
|
| 2176 | }
|
| 2177 | void wlan_single_ap_open()
|
| 2178 | {
|
| 2179 | if (wlan_system("/sbin/ifconfig", "wlan0 up") < 0) { //kw 3
|
| 2180 | wlan_set_state(WLAN_OFF,WLAN_OFF);
|
| 2181 | return;
|
| 2182 | }
|
| 2183 |
|
| 2184 | wlan_set_state(WLAN_ON,WLAN_OFF);
|
| 2185 | }
|
| 2186 |
|
| 2187 | void wlan_single_ap_restart()
|
| 2188 | {
|
| 2189 | clear_sta_count_nv();
|
| 2190 | write_status (WIFISTATUS, "0");
|
| 2191 | wlan_ap_para_set ("wlan0");
|
| 2192 | #ifdef __AP_FUNC__
|
| 2193 | #ifdef __USE_AES__
|
| 2194 | wifi_encrypt_code();
|
| 2195 | #endif
|
| 2196 | #endif
|
| 2197 |
|
| 2198 | if (wlan_system(PARASET1, "wlan0") < 0) {
|
| 2199 | wlan_set_state(WLAN_OFF,WLAN_OFF);
|
| 2200 | return;
|
| 2201 | }
|
| 2202 |
|
| 2203 | wlan_set_state(WLAN_ON,WLAN_OFF);
|
| 2204 | }
|
| 2205 | /**************************************************************************
|
| 2206 | * description of function: wlan deal basic require
|
| 2207 | * input parameter: pstMsg:message content
|
| 2208 | * return value: 0:success -1:error
|
| 2209 | **************************************************************************/
|
| 2210 | #ifdef __SINGLE_AP__
|
| 2211 |
|
| 2212 | void basic_deal (struct wlan_ap_server *ap_svr, int cmd)
|
| 2213 | {
|
| 2214 | wf_log ("cmd=%d(%s)", cmd, to_string(cmd));
|
| 2215 | acl_mode_set();//set white-list or black-list or none to nv
|
| 2216 | wps_off();
|
| 2217 |
|
| 2218 | switch (cmd) {
|
| 2219 | case WIFI_CFG_CLOSE:
|
| 2220 | case WIFI_CFG_SLEEP:
|
| 2221 | wlan_single_ap_close();
|
| 2222 | break;
|
| 2223 | case WIFI_CFG_OPEN:
|
| 2224 | wlan_single_ap_open();
|
| 2225 | break;
|
| 2226 | case WIFI_CFG_AP:
|
| 2227 | case WIFI_CFG_RF:
|
| 2228 | case WIFI_CFG_FORCE_RESTART:
|
| 2229 | wlan_single_ap_restart();
|
| 2230 | break;
|
| 2231 | default:
|
| 2232 | break;
|
| 2233 | }
|
| 2234 | wf_log ("cmd=%d(%s)", cmd, to_string(cmd));
|
| 2235 | }
|
| 2236 |
|
| 2237 | #else
|
| 2238 |
|
| 2239 | void basic_deal (struct wlan_ap_server *ap_svr, int cmd)
|
| 2240 | {
|
| 2241 | char wifi_sta_connection[8] = {0};
|
| 2242 | char m_ssid_enable[8] = {0};
|
| 2243 |
|
| 2244 | wf_log ("cmd=%d(%s) start=%ld", cmd, to_string(cmd), time (NULL));
|
| 2245 | cfg_get_item ("wifi_sta_connection", wifi_sta_connection, sizeof (wifi_sta_connection));
|
| 2246 | cfg_get_item ("m_ssid_enable", m_ssid_enable, sizeof (m_ssid_enable));
|
| 2247 | acl_mode_set();//set white-list or black-list or none to nv
|
| 2248 | wps_off();
|
| 2249 | wf_log ("wifi_sta_connection=%s,m_ssid_enable=%s,ap_svr->ap0_state=%d, ap_svr->ap1_state=%d",
|
| 2250 | wifi_sta_connection, m_ssid_enable, ap_svr->ap0_state, ap_svr->ap1_state, ap_svr->ap0_state, ap_svr->ap1_state);
|
| 2251 |
|
| 2252 | switch (cmd) {
|
| 2253 | case WIFI_CFG_CLOSE:
|
| 2254 | case WIFI_CFG_SLEEP:
|
| 2255 | wlan_basic_close(wifi_sta_connection, m_ssid_enable);
|
| 2256 | break;
|
| 2257 | case WIFI_CFG_OPEN://open include open main ssid and apstation,
|
| 2258 | cfg_set ("wifi_process_state", "processing");
|
| 2259 | if(0 == g_wifi_inited)
|
| 2260 | wlan_init();
|
| 2261 | else
|
| 2262 | wlan_basic_open_va0_apsta(wifi_sta_connection);
|
| 2263 | cfg_set ("wifi_process_state", "end");
|
| 2264 | break;
|
| 2265 | case WIFI_CFG_OPEN_VA0_VA1://open-mssid include open va0+va1
|
| 2266 | cfg_set ("wifi_process_state", "processing");
|
| 2267 | if(0 == g_wifi_inited)
|
| 2268 | wlan_init();
|
| 2269 | else
|
| 2270 | wlan_basic_open_va0_va1();
|
| 2271 | cfg_set ("wifi_process_state", "end");
|
| 2272 | break;
|
| 2273 | case WIFI_CFG_OPEN_MSSID:
|
| 2274 | wlan_basic_open_va1();
|
| 2275 | break;
|
| 2276 | case WIFI_CFG_CLOSE_MSSID:
|
| 2277 | wlan_basic_close_va1();
|
| 2278 | break;
|
| 2279 | case WIFI_CFG_RESTART_APSTATION:
|
| 2280 | wlan_basic_restart_apsta();
|
| 2281 | break;
|
| 2282 | case WIFI_CFG_CLOSESTA_OPENMSSID:
|
| 2283 | wlan_basic_closesta_openmssid();
|
| 2284 | break;
|
| 2285 | case WIFI_CFG_RESTART_AP:
|
| 2286 | wlan_basic_restart_ap();
|
| 2287 | break;
|
| 2288 | case WIFI_CFG_MSSID:
|
| 2289 | wlan_basic_cfg_va1();
|
| 2290 | break;
|
| 2291 | case WIFI_CFG_AP:
|
| 2292 | wlan_basic_cfg_va0(m_ssid_enable);
|
| 2293 | break;
|
| 2294 | case WIFI_CFG_RF:
|
| 2295 | wlan_basic_cfg_rf(wifi_sta_connection, m_ssid_enable);
|
| 2296 | break;
|
| 2297 | case WIFI_CFG_FORCE_RESTART:
|
| 2298 | wlan_basic_force_restart(wifi_sta_connection, m_ssid_enable);
|
| 2299 | break;
|
| 2300 | default:
|
| 2301 | break;
|
| 2302 | }
|
| 2303 | wf_log ("cmd=%d(%s) end=%ld", cmd, to_string(cmd), time (NULL));
|
| 2304 | }
|
| 2305 | #endif
|
| 2306 |
|
| 2307 | //%02X:%02X:%02X:%02X:%02X:%02X
|
| 2308 | void handle_wps_mac (MSG_BUF *pstMsg)
|
| 2309 | {
|
| 2310 | char wps_result[128] = {0};
|
| 2311 | int len = 0;
|
| 2312 |
|
| 2313 | len = wlan_readfile (WSCD_LAST_SUCCESS_ENROLLEE, g_wps_sta_mac, sizeof(g_wps_sta_mac));
|
| 2314 | if(len > 0){
|
| 2315 | if(g_wps_sta_mac[len-1] == '\n')
|
| 2316 | g_wps_sta_mac[len-1] = '\0';
|
| 2317 | wf_log ("g_wps_sta_mac = %s", g_wps_sta_mac);
|
| 2318 | }
|
| 2319 |
|
| 2320 | len = wlan_readfile (WSCD_CONFIG_STATUS, wps_result, sizeof(wps_result));
|
| 2321 | if(len > 0){
|
| 2322 | if(wps_result[len-1] == '\n')
|
| 2323 | wps_result[len-1] = '\0';
|
| 2324 | wf_log ("wps_result = %s", wps_result);
|
| 2325 | }
|
| 2326 |
|
| 2327 | //PROTOCOL_SUCCESS=3
|
| 2328 | if (strncmp (wps_result, "3",1) == 0) {
|
| 2329 | strcpy ( (CHAR*) pstMsg->aucDataBuf, "0"); // ΪÁ˼æÈݲ©Í¨£¬ÖмäÐÞ¸ÄÊÕµ½µÄmsg ÄÚÈÝ
|
| 2330 | pstMsg->usDataLen = strlen ("0") + 1;
|
| 2331 | }
|
| 2332 | }
|
| 2333 | //cov m
|
| 2334 | static char wifi_toupper(char ch)
|
| 2335 | {
|
| 2336 | if ((unsigned int)(ch - 'a') < 26u)
|
| 2337 | ch += 'A' - 'a';
|
| 2338 | return ch;
|
| 2339 | }
|
| 2340 |
|
| 2341 | LONG get_wps_sta (char * iface)
|
| 2342 | {
|
| 2343 | int i = 0;
|
| 2344 | int ssid_index = 0;
|
| 2345 | char authmode[20] = {0};
|
| 2346 | char buf[128] = {0};
|
| 2347 | char mac_tmp[18] = {0};
|
| 2348 | char *p = NULL;
|
| 2349 | char *p_tmp = NULL;
|
| 2350 | char macaddr[32] = {0};
|
| 2351 | char wps_addr[32] = {0};
|
| 2352 | LONG wps_result = ERROR;
|
| 2353 |
|
| 2354 | FILE *p_maclist = NULL;
|
| 2355 |
|
| 2356 | wf_log (" iface = %s", iface);
|
| 2357 |
|
| 2358 | #ifdef __SINGLE_AP__
|
| 2359 | if (!strcmp (iface, "wlan0"))
|
| 2360 | #else
|
| 2361 | if (!strcmp (iface, "wlan0-va0"))
|
| 2362 | #endif
|
| 2363 | {
|
| 2364 | ssid_index = 1;
|
| 2365 | cfg_get_item ("AuthMode", authmode, sizeof (authmode));
|
| 2366 | } else if (!strcmp (iface, "wlan0-va1")) {
|
| 2367 | ssid_index = 2;
|
| 2368 | cfg_get_item ("m_AuthMode", authmode, sizeof (authmode));
|
| 2369 | }
|
| 2370 |
|
| 2371 | memset (buf, 0, sizeof (buf));
|
| 2372 | sprintf (buf, "cat /proc/%s/sta_info | grep \"hwaddr\" > /tmp/wps_maclist", iface);
|
| 2373 | soft_system (buf);
|
| 2374 |
|
| 2375 | p_maclist = fopen ("/tmp/wps_maclist", "r");
|
| 2376 | if (NULL == p_maclist) {
|
| 2377 | fprintf (stderr, "can not open file /tmp/wps_maclist.");
|
| 2378 | goto END;
|
| 2379 | }
|
| 2380 |
|
| 2381 | i = 0;
|
| 2382 | memset (buf, 0, sizeof (buf));
|
| 2383 | while (! (feof (p_maclist))) {
|
| 2384 | again:
|
| 2385 | errno = 0;
|
| 2386 | while (NULL != fgets (buf, sizeof (buf), p_maclist)) { //kw 3
|
| 2387 | memset (mac_tmp, 0, 18);
|
| 2388 | if ( (p = strstr (buf, ":")) != NULL) {
|
| 2389 | p_tmp = p + 2;
|
| 2390 | strncpy (mac_tmp, p_tmp, 12);
|
| 2391 | /*
|
| 2392 | sprintf (macaddr, "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c", toupper (mac_tmp[0]), toupper (mac_tmp[1]) , toupper (mac_tmp[2]), toupper (mac_tmp[3]),
|
| 2393 | toupper (mac_tmp[4]), toupper (mac_tmp[5]), toupper (mac_tmp[6]), toupper (mac_tmp[7]),
|
| 2394 | toupper (mac_tmp[8]), toupper (mac_tmp[9]), toupper (mac_tmp[10]), toupper (mac_tmp[11]));
|
| 2395 | */
|
| 2396 | sprintf (macaddr, "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c", wifi_toupper (mac_tmp[0]), wifi_toupper (mac_tmp[1]) , wifi_toupper (mac_tmp[2]), wifi_toupper (mac_tmp[3]),
|
| 2397 | wifi_toupper (mac_tmp[4]), wifi_toupper (mac_tmp[5]), wifi_toupper (mac_tmp[6]), wifi_toupper (mac_tmp[7]),
|
| 2398 | wifi_toupper (mac_tmp[8]), wifi_toupper (mac_tmp[9]), wifi_toupper (mac_tmp[10]), wifi_toupper (mac_tmp[11]));
|
| 2399 |
|
| 2400 | wf_log ("g_wps_sta_mac=[%s], macaddr=%s", g_wps_sta_mac, macaddr);
|
| 2401 | if (strcmp (macaddr, g_wps_sta_mac) == 0) {
|
| 2402 | wps_result = OK;
|
| 2403 | goto END;
|
| 2404 | }
|
| 2405 | }
|
| 2406 | memset (buf, 0, sizeof (buf));
|
| 2407 | }
|
| 2408 |
|
| 2409 | if(errno == EINTR){ //kw 3
|
| 2410 | wf_log("fgets recv EINTR!");
|
| 2411 | goto again;
|
| 2412 | }
|
| 2413 |
|
| 2414 | }
|
| 2415 | END:
|
| 2416 | if (NULL != p_maclist)
|
| 2417 | fclose (p_maclist);
|
| 2418 | return wps_result;
|
| 2419 | }
|
| 2420 |
|
| 2421 | LONG wlan_get_wps_sta()
|
| 2422 | {
|
| 2423 | int i = 0, j = 0;
|
| 2424 | char wifi_wps_index[8] = {0};
|
| 2425 |
|
| 2426 | LONG ret = ERROR;
|
| 2427 |
|
| 2428 | cfg_get_item ("wifi_wps_index", wifi_wps_index, sizeof (wifi_wps_index));
|
| 2429 |
|
| 2430 | if (strcmp (wifi_wps_index, "1") == 0) {
|
| 2431 | #ifdef __SINGLE_AP__
|
| 2432 | ret = get_wps_sta ("wlan0");
|
| 2433 | #else
|
| 2434 | ret = get_wps_sta ("wlan0-va0");
|
| 2435 | #endif
|
| 2436 | } else if (strcmp (wifi_wps_index, "2") == 0) {
|
| 2437 | ret = get_wps_sta ("wlan0-va1");
|
| 2438 | }
|
| 2439 | return ret;
|
| 2440 | }
|
| 2441 |
|
| 2442 | static void wps_deal_invalid_para()
|
| 2443 | {
|
| 2444 | wf_log ("wps_deal_invalid_para!");
|
| 2445 |
|
| 2446 | cfg_set ("WscModeOption", "0");
|
| 2447 | write_status (WPSSTATUS, "0");
|
| 2448 | ap_server->ap0_wps_state = 0;
|
| 2449 | }
|
| 2450 |
|
| 2451 | static int validate_pin_code (unsigned long code)
|
| 2452 | {
|
| 2453 | unsigned long accum = 0;
|
| 2454 |
|
| 2455 | accum += 3 * ( (code / 10000000) % 10);
|
| 2456 | accum += 1 * ( (code / 1000000) % 10);
|
| 2457 | accum += 3 * ( (code / 100000) % 10);
|
| 2458 | accum += 1 * ( (code / 10000) % 10);
|
| 2459 | accum += 3 * ( (code / 1000) % 10);
|
| 2460 | accum += 1 * ( (code / 100) % 10);
|
| 2461 | accum += 3 * ( (code / 10) % 10);
|
| 2462 | accum += 1 * ( (code / 1) % 10);
|
| 2463 |
|
| 2464 | return (0 == (accum % 10));
|
| 2465 | }
|
| 2466 |
|
| 2467 | /**************************************************************************
|
| 2468 | * description of function: wlan deal wps require
|
| 2469 | * input parameter: pstMsg:message content
|
| 2470 | * return value: 0:success -1:error
|
| 2471 | * zhaoyong set up this function
|
| 2472 | **************************************************************************/
|
| 2473 | void wps_deal (MSG_BUF *pstMsg)
|
| 2474 | {
|
| 2475 |
|
| 2476 | char wifi_wps_index[8] = {0};
|
| 2477 | char wps_mode[8] = {0};
|
| 2478 | char wps_pin[10] = {0};
|
| 2479 |
|
| 2480 | int wps_pin_len = 0;
|
| 2481 |
|
| 2482 | wf_log ("[realtek] wps deal start");
|
| 2483 |
|
| 2484 | cfg_get_item ("wifi_wps_index", wifi_wps_index, sizeof (wifi_wps_index));
|
| 2485 | cfg_get_item ("wps_mode", wps_mode, sizeof (wps_mode));
|
| 2486 | cfg_get_item ("wps_pin", wps_pin, sizeof (wps_pin));
|
| 2487 |
|
| 2488 | wf_log (" wifi_wps_index=%s, wps_mode=%s,wps_pin=%s", wifi_wps_index, wps_mode, wps_pin);
|
| 2489 |
|
| 2490 | if (!strcmp (wps_mode, "PBC")) { //pbc
|
| 2491 | startPBCWPS();
|
| 2492 | } else if ( (!strcmp (wps_mode, "PIN")) || (!strcmp (wps_mode, "APPIN"))) { //what is APPIN?
|
| 2493 |
|
| 2494 | wf_log ("[realtek] wps_pin=%s", wps_pin);
|
| 2495 |
|
| 2496 | wps_pin_len = strlen (wps_pin);
|
| 2497 | int wps_pin_num = atoi(wps_pin);
|
| 2498 | if(wps_pin_num<0 || wps_pin_num> INT_MAX-1)
|
| 2499 | {
|
| 2500 | wps_pin_num = 0;
|
| 2501 | }
|
| 2502 | if ( ( (wps_pin_len == 8) && (validate_pin_code (wps_pin_num))) || (wps_pin_len == 4)) {
|
| 2503 | startPINWPS (wps_pin);
|
| 2504 | } else {
|
| 2505 | wps_deal_invalid_para();
|
| 2506 | }
|
| 2507 | } else {
|
| 2508 | wps_deal_invalid_para();
|
| 2509 | }
|
| 2510 | }
|
| 2511 |
|
| 2512 | void wps_up()
|
| 2513 | {
|
| 2514 | wf_log ("wps_up----");
|
| 2515 |
|
| 2516 | memset (g_wps_sta_mac, 0 , sizeof (g_wps_sta_mac));
|
| 2517 | disable_rtc_wps_timer();
|
| 2518 | write_status (WPSSTATUS, "1");
|
| 2519 | ap_server->ap0_wps_state = 1;
|
| 2520 | }
|
| 2521 |
|
| 2522 | static void wake_wps_unlock()
|
| 2523 | {
|
| 2524 | write_lockfile("/sys/power/wake_unlock", "wps_lock");
|
| 2525 | }
|
| 2526 |
|
| 2527 | void wps_down (MSG_BUF* pMsg)
|
| 2528 | {
|
| 2529 | char wps_result[8] = {0};
|
| 2530 | int result_int = -1;
|
| 2531 |
|
| 2532 | wf_log ("wps_down need to kill wscd ");
|
| 2533 |
|
| 2534 | while (!system ("ps -ef | grep \"bin/wscd\" | grep -v \"grep\"")) {
|
| 2535 | #ifdef __SINGLE_AP__
|
| 2536 | system (WIFI_SCRIPT_DIR"/kill_wps1.sh");
|
| 2537 | #else
|
| 2538 | system (WIFI_SCRIPT_DIR"/kill_wps.sh");
|
| 2539 | #endif
|
| 2540 | usleep (100);
|
| 2541 | }
|
| 2542 |
|
| 2543 | cfg_set ("WscModeOption", "0");
|
| 2544 | ap_server->ap0_wps_state = 0;
|
| 2545 |
|
| 2546 | if (pMsg != NULL) { //kw 3
|
| 2547 | strncpy (wps_result, (CHAR*) pMsg->aucDataBuf, 1);
|
| 2548 | result_int = atoi (wps_result);
|
| 2549 | }
|
| 2550 |
|
| 2551 | // wps failed (wps_result =1), wps success(wps_result = 0)
|
| 2552 | // handle wps result already write wpsstatus file, can not write again, need to fix up
|
| 2553 | if (result_int != 0)
|
| 2554 | write_status (WPSSTATUS, "0");
|
| 2555 |
|
| 2556 | wake_wps_unlock();
|
| 2557 |
|
| 2558 | wf_log ("wps_down end");
|
| 2559 | }
|
| 2560 |
|
| 2561 | void wps_off()
|
| 2562 | {
|
| 2563 | wf_log ("wps_off");
|
| 2564 |
|
| 2565 | if (ap_server->ap0_wps_state) {
|
| 2566 | while (!system ("ps -ef | grep \"bin/wscd\" | grep -v \"grep\"")) {
|
| 2567 | #ifdef __SINGLE_AP__
|
| 2568 | system (WIFI_SCRIPT_DIR"/kill_wps1.sh");
|
| 2569 | #else
|
| 2570 | system (WIFI_SCRIPT_DIR"/kill_wps.sh");
|
| 2571 |
|
| 2572 | #endif
|
| 2573 | usleep (100);
|
| 2574 | }
|
| 2575 | //wake_wps_unlock();
|
| 2576 |
|
| 2577 | cfg_set ("WscModeOption", "0");
|
| 2578 | write_status (WPSSTATUS, "0");
|
| 2579 | ap_server->ap0_wps_state = 0;
|
| 2580 |
|
| 2581 | memset (g_wps_sta_mac, 0 , sizeof (g_wps_sta_mac));
|
| 2582 | disable_rtc_wps_timer();
|
| 2583 | wf_log ("wps_off done");
|
| 2584 | } else {
|
| 2585 | wf_log ("wps already be off");
|
| 2586 | }
|
| 2587 | }
|
| 2588 |
|
| 2589 | //wifi_hal.c of realtek, in order to capture sta num of va0 and va1(if multi ssid is enabled)
|
| 2590 | int captureWlanStaInfo()
|
| 2591 | {
|
| 2592 | int staNum_va0 = 0;
|
| 2593 | int staNum_va1 = 0;
|
| 2594 | int staTotalNum = 0;
|
| 2595 | char wifi_cur_state[8] = {0};
|
| 2596 | char mutli_ssid_enable[8] = {0};
|
| 2597 | char sta_count[12] = {0};
|
| 2598 | char m_sta_count[12] = {0};
|
| 2599 | int sta_count_from_nv = 0;
|
| 2600 |
|
| 2601 | cfg_get_item ("wifi_cur_state", wifi_cur_state, sizeof (wifi_cur_state));
|
| 2602 | cfg_get_item ("m_ssid_enable", mutli_ssid_enable, sizeof (mutli_ssid_enable));
|
| 2603 |
|
| 2604 | // cfg_get_item("sta_count",sta_count,sizeof(sta_count));
|
| 2605 |
|
| 2606 | if (!strncmp (wifi_cur_state, "0", 1)) {
|
| 2607 | wf_log ("[Realtek]wifi is off, can't obtain sta info!!");
|
| 2608 | return 0;
|
| 2609 | }
|
| 2610 |
|
| 2611 | //staNum_va0 = get_vap_sta_num("wlan0-va0");
|
| 2612 | #ifdef __SINGLE_AP__
|
| 2613 | staNum_va0 = get_vap_sta_num ("wlan0");
|
| 2614 | #else
|
| 2615 | staNum_va0 = get_vap_sta_num ("wlan0-va0");
|
| 2616 | #endif
|
| 2617 | sprintf (sta_count, "%d", staNum_va0);
|
| 2618 | cfg_set ("sta_count", sta_count);
|
| 2619 | wf_log ("[Realtek] the Sta Num of Va0 = %d", staNum_va0);
|
| 2620 |
|
| 2621 | if (!strncmp (mutli_ssid_enable, "1", 1)) {
|
| 2622 | // cfg_get_item("m_sta_count",m_sta_count,sizeof(m_sta_count));
|
| 2623 | staNum_va1 = get_vap_sta_num ("wlan0-va1");
|
| 2624 | sprintf (m_sta_count, "%d", staNum_va1);
|
| 2625 | cfg_set ("m_sta_count", m_sta_count);
|
| 2626 | wf_log ("[Realtek] the Sta Num of Va1 = %d", staNum_va1);
|
| 2627 | }
|
| 2628 | #if 1 // add for kw 3 SV.TAINTED.BINOP server
|
| 2629 | if(staNum_va0 < 0 || staNum_va0 > INT_MAX-1)
|
| 2630 | {
|
| 2631 | staNum_va0 = 0;
|
| 2632 | }
|
| 2633 |
|
| 2634 | if(staNum_va1 < 0 || staNum_va1 > INT_MAX-1)
|
| 2635 | {
|
| 2636 | staNum_va1 = 0;
|
| 2637 | }
|
| 2638 | #endif
|
| 2639 | ap_server->g_sta_num = staTotalNum = staNum_va0 + staNum_va1;
|
| 2640 | wf_log ("[Realtek] staTotalNum = %d", staTotalNum);
|
| 2641 | return staTotalNum;
|
| 2642 | }
|
| 2643 |
|
| 2644 | // 1. adding wlan interface
|
| 2645 | // 2. no more use expire time as limiting condition
|
| 2646 | static int wlan_get_mac_list (char* station_mac, char* athx)
|
| 2647 | {
|
| 2648 | char buf[128] = {0};
|
| 2649 | char *p = NULL;
|
| 2650 | char *p_tmp = NULL;
|
| 2651 | char *p2 = NULL;
|
| 2652 | char *p_tmp2 = NULL;
|
| 2653 | int expiredtime_flag[35] = { -1};
|
| 2654 | char expiredtime[4] = {0};
|
| 2655 | RT_802_11_MAC_TABLE table;
|
| 2656 | /*add by myc for wifi_client list 2012-04-20 begin*/
|
| 2657 | FILE *fp2 = NULL;
|
| 2658 | FILE *fp = NULL;
|
| 2659 | FILE *fp5 = NULL;
|
| 2660 | int i = 0;
|
| 2661 | int index = 0;
|
| 2662 | char cmd_buf[100] = {0};
|
| 2663 | if (NULL == station_mac) {
|
| 2664 | softap_assert("wlan_get_mac_list station_mac is null");
|
| 2665 | return 0;
|
| 2666 | }
|
| 2667 |
|
| 2668 | wf_log ("[wlan_get_mac_list] %s", athx);
|
| 2669 | memset (&table, 0, sizeof (table));
|
| 2670 |
|
| 2671 | memset (cmd_buf, 0, 100);
|
| 2672 | sprintf (cmd_buf, "cat /proc/%s/sta_info > /tmp/acl_stalist_%s", athx, athx);
|
| 2673 | soft_system (cmd_buf);
|
| 2674 |
|
| 2675 | memset (cmd_buf, 0, 100);
|
| 2676 | sprintf (cmd_buf, "/tmp/acl_stalist_%s", athx);
|
| 2677 |
|
| 2678 | fp = fopen (cmd_buf, "r");
|
| 2679 | if (NULL == fp) {
|
| 2680 | softap_assert("can not open file /tmp/acl_stalist_%s.", athx);
|
| 2681 | return 0;
|
| 2682 | }
|
| 2683 |
|
| 2684 | memset (cmd_buf, 0, 100);
|
| 2685 | sprintf (cmd_buf, "cat /tmp/acl_stalist_%s | grep \"hwaddr\" > /tmp/acl_maclist_%s", athx, athx);
|
| 2686 | soft_system (cmd_buf);
|
| 2687 |
|
| 2688 | memset (cmd_buf, 0, 100);
|
| 2689 | sprintf (cmd_buf, "/tmp/acl_maclist_%s", athx);
|
| 2690 |
|
| 2691 | fp2 = fopen (cmd_buf, "r");
|
| 2692 | if (NULL == fp2) {
|
| 2693 | fprintf (stderr, "can not open file /tmp/acl_maclist_%s.", athx);
|
| 2694 | fclose (fp); //kw 3
|
| 2695 |
|
| 2696 | return 0;
|
| 2697 | }
|
| 2698 |
|
| 2699 | memset (cmd_buf, 0, 100);
|
| 2700 | sprintf (cmd_buf, "cat /tmp/acl_stalist_%s | grep \"expired_time\" > /tmp/acl_expiredtime_%s", athx, athx);
|
| 2701 | soft_system (cmd_buf);
|
| 2702 |
|
| 2703 | memset (cmd_buf, 0, 100);
|
| 2704 | sprintf (cmd_buf, "/tmp/acl_expiredtime_%s", athx);
|
| 2705 |
|
| 2706 | fp5 = fopen (cmd_buf, "r");
|
| 2707 |
|
| 2708 | if (NULL == fp5) {
|
| 2709 | fprintf (stderr, "can not open file /tmp/acl_expiredtime_%s", athx);
|
| 2710 | //kw 3
|
| 2711 | fclose (fp);
|
| 2712 | fclose (fp2);
|
| 2713 | return 0;
|
| 2714 | }
|
| 2715 |
|
| 2716 | memset (buf, 0, sizeof (buf));
|
| 2717 | i = 0;
|
| 2718 | while (! (feof (fp5))) {
|
| 2719 | while (fgets (buf, sizeof (buf), fp5)) {
|
| 2720 | memset (expiredtime, 0, 4);
|
| 2721 | if ( (p2 = strstr (buf, ":")) != NULL) {
|
| 2722 | //p_tmp = p-2;
|
| 2723 | p_tmp2 = p2 + 2;
|
| 2724 | strncpy (expiredtime, p_tmp2, 3);
|
| 2725 | //printf("zhouti expiredtime is %s, len is %d\n", expiredtime, strlen(expiredtime));
|
| 2726 | if (atoi (expiredtime) > 0) { //kw 3
|
| 2727 | expiredtime_flag[index] = i;
|
| 2728 | wf_log ("[wlan_get_mac_list] wlan_get_mac_list expiredtime_flag[%d] is %d", index, expiredtime_flag[index]);
|
| 2729 | index++;
|
| 2730 | }
|
| 2731 | i++;
|
| 2732 | }
|
| 2733 | memset (buf, 0, sizeof (buf));
|
| 2734 | }
|
| 2735 | }
|
| 2736 | //i = 0;
|
| 2737 | //index = 0;
|
| 2738 | memset (buf, 0, sizeof (buf));
|
| 2739 | while (! (feof (fp2))) {
|
| 2740 | while (fgets (buf, sizeof (buf), fp2)) {
|
| 2741 | //printf("zhouti table.Num state_flag[%d]11 is %dsecurity_flag is %d \n ", table.Num,state_flag[table.Num],security_flag);
|
| 2742 | if ( (p = strstr (buf, ":")) != NULL) {
|
| 2743 | //if(expiredtime_flag[index] == i)
|
| 2744 | //{
|
| 2745 | p_tmp = p + 2;
|
| 2746 | strncpy ( (station_mac + 13 * table.Num), p_tmp, 12);
|
| 2747 | //(*(station_mac[table.Num]+12)) = '\0';
|
| 2748 | wf_log ("[wlan_get_mac_list] station_mac[%d] is %s", table.Num, (station_mac + 13 * table.Num));
|
| 2749 | table.Num += 1;
|
| 2750 | //index++;
|
| 2751 | //}
|
| 2752 | //i++;
|
| 2753 | }
|
| 2754 | memset (buf, 0, sizeof (buf));
|
| 2755 | }
|
| 2756 | }
|
| 2757 |
|
| 2758 | //kw 3
|
| 2759 | fclose (fp2);
|
| 2760 | fclose (fp);
|
| 2761 | fclose (fp5);
|
| 2762 |
|
| 2763 | return table.Num;
|
| 2764 | }
|
| 2765 |
|
| 2766 |
|
| 2767 | void wlan_init (void)
|
| 2768 | {
|
| 2769 | pid_t ret = 0;
|
| 2770 | char wifi_sta_connection[8] = {0};
|
| 2771 | char m_ssid_enable[8] = {0};
|
| 2772 |
|
| 2773 | if(0 == g_wifi_inited)
|
| 2774 | g_wifi_inited = 1;
|
| 2775 |
|
| 2776 | wf_log ("wlan_init");
|
| 2777 |
|
| 2778 | cfg_get_item ("wifi_sta_connection", wifi_sta_connection, sizeof (wifi_sta_connection));
|
| 2779 | cfg_get_item ("m_ssid_enable", m_ssid_enable, sizeof (m_ssid_enable));
|
| 2780 |
|
| 2781 | //1. nvÉèÖòÎÊýµ½Îļþ
|
| 2782 | // ÎÞÂÛ¿ÚÓÐÎÞÆô¶¯£¬¾ùÉèÖúòÎÊý£¬ºóÐøÖ»ÐèÒªdown up¾Í¿ÉÒÔÁË
|
| 2783 | wlan_set_param();
|
| 2784 |
|
| 2785 | //2. ½Å±¾ÉèÖõ½Ð¾Æ¬
|
| 2786 | #ifdef __SINGLE_AP__
|
| 2787 | ret = system (INITSH1);
|
| 2788 | #else
|
| 2789 | ret = system (INITSH);
|
| 2790 | #endif
|
| 2791 | //arp_br0();
|
| 2792 | //3. ÅжÏÊÇ·ñÕý³£Æô¶¯
|
| 2793 | wf_log ("ret = %d, WIFEXITED(ret)=%d, WEXITSTATUS(ret) =%d", ret, WIFEXITED (ret), WEXITSTATUS (ret));
|
| 2794 |
|
| 2795 | if (! (-1 != ret && WIFEXITED (ret) && 0 == WEXITSTATUS (ret))) {
|
| 2796 | wlan_set_state(WLAN_OFF,WLAN_OFF);
|
| 2797 | wf_log ("Open Error");
|
| 2798 | return;
|
| 2799 | }
|
| 2800 |
|
| 2801 | //4.ÉèÖÿªÆôºóµÄnv¼°Îļþ״̬£¬È«¾Ö±äÁ¿
|
| 2802 | wlan_set_state(WLAN_ON,atoi(m_ssid_enable));
|
| 2803 |
|
| 2804 |
|
| 2805 | //5. ÉèÖúڰ×Ãûµ¥
|
| 2806 | acl_mode_set();
|
| 2807 |
|
| 2808 | #ifdef __SINGLE_AP__
|
| 2809 | acl_set_mac ("wlan0");
|
| 2810 | #else
|
| 2811 | acl_set_mac ("wlan0-va0");
|
| 2812 | if (strcmp (m_ssid_enable, "1") == 0) { //va1 ÆðÀ´Ö®ºó²Å»áÉèva1µÄacl
|
| 2813 | acl_set_mac ("wlan0-va1");
|
| 2814 | }
|
| 2815 | #ifdef __STA_FUNC__
|
| 2816 | //6. ÅжÏÊÇ·ñ¿ªÆôapsta
|
| 2817 | if (strcmp (wifi_sta_connection, "1") == 0) { // vxd ²»Ôٽű¾ÖÐÆô¶¯£¬¶øÇÒÓÉwpa_supplicant µ÷ÓÃÆðÀ´
|
| 2818 | wlan_station_init();
|
| 2819 | }
|
| 2820 | #endif
|
| 2821 | #endif
|
| 2822 | wf_log ("Open Success ");
|
| 2823 | }
|
| 2824 | void acl_set_process()
|
| 2825 | {
|
| 2826 | char m_ssid_enable[8] = {0};
|
| 2827 |
|
| 2828 | cfg_get_item ("m_ssid_enable", m_ssid_enable, sizeof (m_ssid_enable));
|
| 2829 | #ifdef __SINGLE_AP__
|
| 2830 | acl_set_mac ("wlan0");
|
| 2831 | #else
|
| 2832 | acl_set_mac ("wlan0-va0");
|
| 2833 | if (strcmp (m_ssid_enable, "1") == 0) {
|
| 2834 | acl_set_mac ("wlan0-va1");
|
| 2835 | }
|
| 2836 | #endif
|
| 2837 | renew_global_acl_table();
|
| 2838 | }
|
| 2839 |
|
| 2840 |
|
| 2841 | void wlan_get_wps_access_sta()
|
| 2842 | {
|
| 2843 | wf_log (" g_get_access_sta_count =[%d], g_wps_sta_mac=[%s]", g_get_access_sta_count, g_wps_sta_mac);
|
| 2844 |
|
| 2845 | if (wlan_get_wps_sta() == OK) {
|
| 2846 | wf_log ("wlan_get_wps_sta ok");
|
| 2847 | write_status (WPSDISPLAYSTATUS, WPS_ACTIVED);
|
| 2848 | write_status (WPSSTATUS, "2");
|
| 2849 | g_get_access_sta_count = 0;
|
| 2850 | return;
|
| 2851 | }
|
| 2852 | if (g_get_access_sta_count == ( (WPS_STATION_ACCESS_CHECK_ALL_PERIOD) / (WPS_STATION_ACCESS_CHECK_PERIOD))) {
|
| 2853 | wf_log ("g_get_access_sta_count=[%d]", g_get_access_sta_count);
|
| 2854 | write_status (WPSSTATUS, "0");
|
| 2855 | g_get_access_sta_count = 0;
|
| 2856 | return;
|
| 2857 | } else {
|
| 2858 | if (-1 == create_rtc_wps_timer (WPS_STATION_ACCESS_CHECK_PERIOD)) {
|
| 2859 | wf_log ("create wps sta check timer is fail ");
|
| 2860 | write_status (WPSSTATUS, "0");
|
| 2861 | g_get_access_sta_count = 0;
|
| 2862 | } else {
|
| 2863 | wf_log ("recreate sta check timer, g_get_access_sta_count=[%d]", g_get_access_sta_count);
|
| 2864 | g_get_access_sta_count++;
|
| 2865 | }
|
| 2866 | }
|
| 2867 | }
|
| 2868 |
|
| 2869 | void handle_wps_result (MSG_BUF *pstMsg)
|
| 2870 | {
|
| 2871 | int result_int = 1;
|
| 2872 | char result[2] = {0};
|
| 2873 |
|
| 2874 | wf_log ("g_wps_sta_mac is %s", g_wps_sta_mac);
|
| 2875 |
|
| 2876 | g_get_access_sta_count = 0;
|
| 2877 |
|
| 2878 | if (NULL == pstMsg) {
|
| 2879 | wf_log ("pstMsg is NULL");
|
| 2880 | return;
|
| 2881 | }
|
| 2882 | if (pstMsg->usDataLen > 0) {
|
| 2883 | strncpy (result, (CHAR*) pstMsg->aucDataBuf, 1);
|
| 2884 | result_int = atoi (result);
|
| 2885 | } else {
|
| 2886 | wf_log ("pstMsg buf is invalid");
|
| 2887 | }
|
| 2888 |
|
| 2889 | if ( (result_int == 0) && (strcmp (g_wps_sta_mac, "") != 0)) {
|
| 2890 | if (wlan_get_wps_sta() == OK) {
|
| 2891 | write_status (WPSDISPLAYSTATUS, WPS_ACTIVED);
|
| 2892 | write_status (WPSSTATUS, "2");
|
| 2893 | wf_log (" wlan_get_wps_sta success WPS_ACTIVED ");
|
| 2894 | } else {
|
| 2895 | wf_log ("wlan_handle_wps_success need check sta");
|
| 2896 | if (-1 == create_rtc_wps_timer (WPS_STATION_ACCESS_CHECK_PERIOD)) {
|
| 2897 | wf_log ("create wps sta check timer is fail ");
|
| 2898 | write_status (WPSSTATUS, "0");
|
| 2899 | }
|
| 2900 | }
|
| 2901 | } else {
|
| 2902 | wf_log ("wlan_handle_wps_fail ");
|
| 2903 | write_status (WPSSTATUS, "0");
|
| 2904 | }
|
| 2905 | return;
|
| 2906 | }
|
| 2907 |
|
| 2908 | void wlan_ap_open ()
|
| 2909 | {
|
| 2910 | wlan_init();
|
| 2911 | }
|
| 2912 |
|
| 2913 | /*
|
| 2914 | qrStatus
|
| 2915 | staStatus
|
| 2916 | wifiStatus
|
| 2917 | wpsdisplayStatus
|
| 2918 | wpsStatus
|
| 2919 |
|
| 2920 | this file will be created in rc file, and be inited before zte_mmi
|
| 2921 |
|
| 2922 | */
|
| 2923 | void wlan_generate_para_file()
|
| 2924 | {
|
| 2925 | // run dir
|
| 2926 | ensure_config_dir_exist("/etc_rw/wifi/");
|
| 2927 | ensure_config_dir_exist("/etc_rw/wifi/realtek/");
|
| 2928 | ensure_config_dir_exist("/etc_rw/wifi/realtek/run");
|
| 2929 | ensure_config_dir_exist("/etc_rw/wifi/realtek/rtl8192c");
|
| 2930 |
|
| 2931 | system("default_setting.sh wlan0");
|
| 2932 | system("default_setting.sh wlan0-va0");
|
| 2933 | system("default_setting.sh wlan0-va1");
|
| 2934 | system("default_setting.sh wlan0-vxd");
|
| 2935 |
|
| 2936 | }
|