1/* 2 * Network services 3 * 4 * Copyright (C) 2014, Broadcom Corporation. All Rights Reserved. 5 * 6 * Permission to use, copy, modify, and/or distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 13 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 15 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 * 18 * $Id: network.c 373149 2012-12-06 07:54:50Z $ 19 */ 20 21#include <stdio.h> 22#include <stdlib.h> 23#include <errno.h> 24#include <syslog.h> 25#include <ctype.h> 26#include <string.h> 27#include <unistd.h> 28#include <sys/stat.h> 29#include <sys/ioctl.h> 30#include <sys/types.h> 31#include <sys/socket.h> 32#include <net/if.h> 33#include <netinet/in.h> 34#include <arpa/inet.h> 35#include <net/if_arp.h> 36#include <signal.h> 37 38typedef u_int64_t u64; 39typedef u_int32_t u32; 40typedef u_int16_t u16; 41typedef u_int8_t u8; 42 43#include <linux/sockios.h> 44#include <linux/types.h> 45#include <linux/ethtool.h> 46 47#include <bcmnvram.h> 48#include <netconf.h> 49#include <shutils.h> 50#include <wlutils.h> 51#include <nvparse.h> 52#include <rc.h> 53#include <bcmutils.h> 54#include <etioctl.h> 55#include <bcmparams.h> 56#include <security_ipc.h> 57#include <wlif_utils.h> 58#include <dpsta_linux.h> 59 60bool emf_enabled = FALSE; 61 62static int 63add_routes(char *prefix, char *var, char *ifname) 64{ 65 char word[80], *next; 66 char *ipaddr, *netmask, *gateway, *metric; 67 char tmp[100]; 68 69 foreach(word, nvram_safe_get(strcat_r(prefix, var, tmp)), next) { 70 dprintf("add %s\n", word); 71 72 netmask = word; 73 ipaddr = strsep(&netmask, ":"); 74 if (!ipaddr || !netmask) 75 continue; 76 gateway = netmask; 77 netmask = strsep(&gateway, ":"); 78 if (!netmask || !gateway) 79 continue; 80 metric = gateway; 81 gateway = strsep(&metric, ":"); 82 if (!gateway || !metric) 83 continue; 84 85 dprintf("add %s\n", ifname); 86 87 route_add(ifname, atoi(metric) + 1, ipaddr, gateway, netmask); 88 } 89 90 return 0; 91} 92 93static int 94del_routes(char *prefix, char *var, char *ifname) 95{ 96 char word[80], *next; 97 char *ipaddr, *netmask, *gateway, *metric; 98 char tmp[100]; 99 100 foreach(word, nvram_safe_get(strcat_r(prefix, var, tmp)), next) { 101 dprintf("add %s\n", word); 102 103 netmask = word; 104 ipaddr = strsep(&netmask, ":"); 105 if (!ipaddr || !netmask) 106 continue; 107 gateway = netmask; 108 netmask = strsep(&gateway, ":"); 109 if (!netmask || !gateway) 110 continue; 111 metric = gateway; 112 gateway = strsep(&metric, ":"); 113 if (!gateway || !metric) 114 continue; 115 116 dprintf("add %s\n", ifname); 117 118 route_del(ifname, atoi(metric) + 1, ipaddr, gateway, netmask); 119 } 120 121 return 0; 122} 123 124static int 125add_lan_routes(char *lan_ifname) 126{ 127 return add_routes("lan_", "route", lan_ifname); 128} 129 130static int 131del_lan_routes(char *lan_ifname) 132{ 133 return del_routes("lan_", "route", lan_ifname); 134} 135 136/* Set initial QoS mode for all et interfaces that are up. */ 137 138static void 139set_et_qos_mode(void) 140{ 141 int i, s, qos; 142 struct ifreq ifr; 143 struct ethtool_drvinfo info; 144 145 if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) 146 return; 147 148 qos = (strcmp(nvram_safe_get("wl_wme"), "off") != 0); 149 150 for (i = 1; i <= DEV_NUMIFS; i ++) { 151 ifr.ifr_ifindex = i; 152 if (ioctl(s, SIOCGIFNAME, &ifr)) 153 continue; 154 if (ioctl(s, SIOCGIFHWADDR, &ifr)) 155 continue; 156 if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) 157 continue; 158 if (ioctl(s, SIOCGIFFLAGS, &ifr)) 159 continue; 160 if (!(ifr.ifr_flags & IFF_UP)) 161 continue; 162 /* Set QoS for et & bcm57xx devices */ 163 memset(&info, 0, sizeof(info)); 164 info.cmd = ETHTOOL_GDRVINFO; 165 ifr.ifr_data = (caddr_t)&info; 166 if (ioctl(s, SIOCETHTOOL, &ifr) < 0) 167 continue; 168 if ((strncmp(info.driver, "et", 2) != 0) && 169 (strncmp(info.driver, "bcm57", 5) != 0)) 170 continue; 171 ifr.ifr_data = (caddr_t)&qos; 172 ioctl(s, SIOCSETCQOS, &ifr); 173 } 174 175 close(s); 176} 177 178/* 179 * Carry out a socket request including openning and closing the socket 180 * Return -1 if failed to open socket (and perror); otherwise return 181 * result of ioctl 182 */ 183static int 184soc_req(const char *name, int action, struct ifreq *ifr) 185{ 186 int s; 187 int rv = 0; 188 189 if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) { 190 perror("socket"); 191 return -1; 192 } 193 strncpy(ifr->ifr_name, name, IFNAMSIZ); 194 rv = ioctl(s, action, ifr); 195 close(s); 196 197 return rv; 198} 199 200static int 201wl_send_dif_event(const char *ifname, uint32 event) 202{ 203 static int s = -1; 204 int len, n; 205 struct sockaddr_in to; 206 char data[IFNAMSIZ + sizeof(uint32)]; 207 208 /* create a socket to receive dynamic i/f events */ 209 if (s < 0) { 210 s = socket(AF_INET, SOCK_DGRAM, 0); 211 if (s < 0) { 212 perror("socket"); 213 return -1; 214 } 215 } 216 217 /* Init the message contents to send to eapd. Specify the interface 218 * and the event that occured on the interface. 219 */ 220 strncpy(data, ifname, IFNAMSIZ); 221 *(uint32 *)(data + IFNAMSIZ) = event; 222 len = IFNAMSIZ + sizeof(uint32); 223 224 /* send to eapd */ 225 to.sin_addr.s_addr = inet_addr(EAPD_WKSP_UDP_ADDR); 226 to.sin_family = AF_INET; 227 to.sin_port = htons(EAPD_WKSP_DIF_UDP_PORT); 228 229 n = sendto(s, data, len, 0, (struct sockaddr *)&to, 230 sizeof(struct sockaddr_in)); 231 232 if (n != len) { 233 perror("udp send failed\n"); 234 return -1; 235 } 236 237 dprintf("hotplug_net(): sent event %d\n", event); 238 239 return n; 240} 241/* Check NVRam to see if "name" is explicitly enabled */ 242static inline int 243wl_vif_enabled(const char *name, char *tmp) 244{ 245 return (atoi(nvram_safe_get(strcat_r(name, "_bss_enabled", tmp)))); 246} 247 248/* Set the HW address for interface "name" if present in NVRam */ 249static void 250wl_vif_hwaddr_set(const char *name) 251{ 252 int rc; 253 char *ea; 254 char hwaddr[20]; 255 struct ifreq ifr; 256 257 snprintf(hwaddr, sizeof(hwaddr), "%s_hwaddr", name); 258 ea = nvram_get(hwaddr); 259 if (ea == NULL) { 260 fprintf(stderr, "NET: No hw addr found for %s\n", name); 261 return; 262 } 263 264 fprintf(stderr, "NET: Setting %s hw addr to %s\n", name, ea); 265 ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; 266 ether_atoe(ea, (unsigned char *)ifr.ifr_hwaddr.sa_data); 267 if ((rc = soc_req(name, SIOCSIFHWADDR, &ifr)) < 0) { 268 fprintf(stderr, "NET: Error setting hw for %s; returned %d\n", name, rc); 269 } 270} 271 272#ifdef __CONFIG_EMF__ 273void 274emf_mfdb_update(char *lan_ifname, char *lan_port_ifname, bool add) 275{ 276 char word[256], *next; 277 char *mgrp, *ifname; 278 279 /* Add/Delete MFDB entries corresponding to new interface */ 280 foreach(word, nvram_safe_get("emf_entry"), next) { 281 ifname = word; 282 mgrp = strsep(&ifname, ":"); 283 284 if ((mgrp == 0) || (ifname == 0)) 285 continue; 286 287 /* Add/Delete MFDB entry using the group addr and interface */ 288 if (strcmp(lan_port_ifname, ifname) == 0) { 289 eval("emf", ((add) ? "add" : "del"), 290 "mfdb", lan_ifname, mgrp, ifname); 291 } 292 } 293 294 return; 295} 296 297void 298emf_uffp_update(char *lan_ifname, char *lan_port_ifname, bool add) 299{ 300 char word[256], *next; 301 char *ifname; 302 303 /* Add/Delete UFFP entries corresponding to new interface */ 304 foreach(word, nvram_safe_get("emf_uffp_entry"), next) { 305 ifname = word; 306 307 if (ifname == 0) 308 continue; 309 310 /* Add/Delete UFFP entry for the interface */ 311 if (strcmp(lan_port_ifname, ifname) == 0) { 312 eval("emf", ((add) ? "add" : "del"), 313 "uffp", lan_ifname, ifname); 314 } 315 } 316 317 return; 318} 319 320void 321emf_rtport_update(char *lan_ifname, char *lan_port_ifname, bool add) 322{ 323 char word[256], *next; 324 char *ifname; 325 326 /* Add/Delete RTPORT entries corresponding to new interface */ 327 foreach(word, nvram_safe_get("emf_rtport_entry"), next) { 328 ifname = word; 329 330 if (ifname == 0) 331 continue; 332 333 /* Add/Delete RTPORT entry for the interface */ 334 if (strcmp(lan_port_ifname, ifname) == 0) { 335 eval("emf", ((add) ? "add" : "del"), 336 "rtport", lan_ifname, ifname); 337 } 338 } 339 340 return; 341} 342 343void 344start_emf(char *lan_ifname) 345{ 346 char word[256], *next; 347 char *mgrp, *ifname; 348 349 if (!nvram_match("emf_enable", "1")) 350 return; 351 352 /* Start EMF */ 353 eval("emf", "start", lan_ifname); 354 355 /* Add the static MFDB entries */ 356 foreach(word, nvram_safe_get("emf_entry"), next) { 357 ifname = word; 358 mgrp = strsep(&ifname, ":"); 359 360 if ((mgrp == 0) || (ifname == 0)) 361 continue; 362 363 /* Add MFDB entry using the group addr and interface */ 364 eval("emf", "add", "mfdb", lan_ifname, mgrp, ifname); 365 } 366 367 /* Add the UFFP entries */ 368 foreach(word, nvram_safe_get("emf_uffp_entry"), next) { 369 ifname = word; 370 if (ifname == 0) 371 continue; 372 373 /* Add UFFP entry for the interface */ 374 eval("emf", "add", "uffp", lan_ifname, ifname); 375 } 376 377 /* Add the RTPORT entries */ 378 foreach(word, nvram_safe_get("emf_rtport_entry"), next) { 379 ifname = word; 380 if (ifname == 0) 381 continue; 382 383 /* Add RTPORT entry for the interface */ 384 eval("emf", "add", "rtport", lan_ifname, ifname); 385 } 386 387 return; 388} 389 390void 391load_emf(void) 392{ 393 /* Load the EMF & IGMP Snooper modules */ 394 eval("insmod", "emf"); 395 eval("insmod", "igs"); 396 397 emf_enabled = TRUE; 398 399 return; 400} 401 402void 403unload_emf(void) 404{ 405 if (!emf_enabled) 406 return; 407 408 /* Unload the EMF & IGMP Snooper modules */ 409 eval("rmmod", "igs"); 410 eval("rmmod", "emf"); 411 412 emf_enabled = FALSE; 413 414 return; 415} 416#endif /* __CONFIG_EMF__ */ 417 418static int 419dpsta_ioctl(char *name, void *buf, int len) 420{ 421 struct ifreq ifr; 422 int ret = 0; 423 int s; 424 425 /* open socket to kernel */ 426 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { 427 perror("socket"); 428 return errno; 429 } 430 431 strncpy(ifr.ifr_name, name, IFNAMSIZ); 432 ifr.ifr_data = (caddr_t)buf; 433 if ((ret = ioctl(s, SIOCDEVPRIVATE, &ifr)) < 0) 434 perror(ifr.ifr_name); 435 436 /* cleanup */ 437 close(s); 438 return ret; 439} 440 441static bool 442l2bridge_no_ipaddr(const char *br_ifname) 443{ 444 char l2bridge[NVRAM_MAX_PARAM_LEN]; 445 446 snprintf(l2bridge, sizeof(l2bridge), "%s_l2bridge_mode", br_ifname); 447 448 /* For now, brX_l2bridge_mode only has 1 mode of On/Off for bridge IP address 449 * but it could be expanded to have other modes/flags in the future if needed 450 */ 451 return (nvram_match(l2bridge, "1") ? TRUE : FALSE); 452} 453 454void 455start_lan(void) 456{ 457 char *lan_ifname = nvram_safe_get("lan_ifname"); 458 char br_ifname[80]; 459 char name[80], *next; 460 char tmp[100]; 461 int i, s, dpsta = 0; 462 struct ifreq ifr; 463 char buf[255], *ptr; 464 char lan_stp[10]; 465 char *lan_ifnames; 466 char lan_dhcp[10]; 467 char lan_ipaddr[15]; 468 char lan_netmask[15]; 469 char lan_hwaddr[15]; 470 char hwaddr[ETHER_ADDR_LEN]; 471 dpsta_enable_info_t info = { 0 }; 472 473 /* The NVRAM variable lan_ifnames contains all the available interfaces. 474 * This is used to build the unbridged interface list. Once the unbridged list 475 * is built lan_interfaces is rebuilt with only the interfaces in the bridge 476 */ 477 478 dprintf("%s\n", lan_ifname); 479 480 /* Foxconn, added by MJ., for DLAN AUTO IP, 2010.05.18 */ 481#ifdef DLNA 482#ifdef DLNA_DEBUG 483 char auto_ip[8]; 484 strcpy(auto_ip, acosNvramConfig_get("dlna_auto_ip")); 485 cprintf("dlna_auto_ip: %s. \n", auto_ip); 486#endif 487 if(nvram_match("dlna_auto_ip", "1")) 488 { 489 if(nvram_match("auto_ip_backup", "0")) 490 {/* dlna_auto_ip changed from 0 to 1. */ 491 nvram_set("auto_ip_backup", "1"); 492 /* Set default Auto IP values. */ 493 nvram_set("tmp_lan_ipaddr", nvram_get("lan_ipaddr")); 494 nvram_set("lan_ipaddr", "169.254.146.254"); 495 496 nvram_set("tmp_lan_netmask", nvram_get("lan_netmask")); 497 nvram_set("lan_netmask", "255.255.0.0"); 498 499 nvram_set("tmp_lan_proto", nvram_get("lan_proto")); 500 nvram_set("lan_proto", "static"); 501 502 nvram_set("tmp_rip_enable", nvram_get("rip_enable")); 503 nvram_set("rip_enable", "0"); 504 505 nvram_commit(); 506 } 507 }else{/* dlna_auto_ip = 0 */ 508 if(nvram_match("auto_ip_backup", "1")) 509 {/* dlan_auto_ip changed from 1 to 0. */ 510 /* If user had changed the value, don't use tmp values.*/ 511 if(!nvram_match("tmp_lan_netmask", "null")&& 512 nvram_match(nvram_get("lan_netmask"), "255.255.0.0")){ 513 nvram_set("lan_netmask", nvram_get("tmp_lan_netmask")); 514 nvram_set("tmp_lan_netmask", "null"); 515 } 516 if(!nvram_match("tmp_lan_ipaddr", "null")&& 517 nvram_match(nvram_get("lan_ipaddr"), "169.254.146.254")){ 518 nvram_set("lan_ipaddr", nvram_get("tmp_lan_ipaddr")); 519 nvram_set("tmp_lan_ipaddr", "null"); 520 } 521 if(!nvram_match("tmp_lan_proto", "null")&& 522 nvram_match(nvram_get("lan_proto"), "static")){ 523 nvram_set("lan_proto", nvram_get("tmp_lan_proto")); 524 nvram_set("tmp_lan_proto", "null"); 525 } 526 if(!nvram_match("tmp_rip_enable", "null")&& 527 nvram_match(nvram_get("rip_enable"), "0")){ 528 nvram_set("rip_enable", nvram_get("tmp_rip_enable")); 529 nvram_set("tmp_rip_enable", "null"); 530 } 531 nvram_set("auto_ip_backup", "0"); 532 nvram_commit(); 533 } 534 } 535#ifdef DLNA_DEBUG 536 cprintf("-> netmask: %s\n", nvram_get("lan_netmask")); 537 cprintf("-> lan ip: %s\n", nvram_get("lan_ipaddr")); 538 cprintf("-> dhcp server: %s\n", nvram_get("lan_proto")); 539 cprintf("-> rip: %s\n", nvram_get("rip_enable")); 540#endif 541 542 543 //nvram_commit(); 544#endif 545 /* Foxconn, ended by MJ., for DLAN AUTO IP, 2010.05.18 */ 546 547 548 /* Create links */ 549 symlink("/sbin/rc", "/tmp/ldhclnt"); 550 551 552/*Foxconn modified start, edward zhang, 2013/07/03*/ 553#ifdef VLAN_SUPPORT 554 nvram_unset("unbridged_ifnames"); 555 /*unset some bridge nvram*/ 556 char br_ifname_tag[16] = ""; 557 char br_ifnames_tag[64] = ""; 558 559 for(i=0; i<7; i++) 560 { 561 sprintf(br_ifname_tag,"br%d_ifname",i); 562 sprintf(br_ifnames_tag,"br%d_ifnames",i); 563 nvram_unset(br_ifname_tag); 564 nvram_unset(br_ifnames_tag); 565 } 566#else 567 nvram_unset("br0_ifname"); 568 nvram_unset("br1_ifname"); 569 nvram_unset("unbridged_ifnames"); 570 nvram_unset("br0_ifnames"); 571 nvram_unset("br1_ifnames"); 572#endif 573/*Foxconn modified end, edward zhang, 2013/07/03*/ 574#if defined(__CONFIG_EXTACS__) || defined(__CONFIG_WL_ACI__) 575 nvram_unset("acs_ifnames"); 576#endif /* defined(_CONFIG_EXTACS__) || defined(__CONFIG_WL_ACI__ */ 577 /* If we're a travel router... then we need to make sure we get 578 * the primary wireless interface up before trying to attach slave 579 * interface(s) to the bridge 580 */ 581 if (nvram_match("ure_disable", "0") && nvram_match("router_disable", "0")) 582 { 583 eval("wlconf", nvram_get("wan0_ifname"), "up"); 584 } 585 586 587 /* Bring up bridged interfaces */ 588 for (i = 0; i < MAX_NO_BRIDGE; i++) { 589 if (!i) { 590 lan_ifname = nvram_safe_get("lan_ifname"); 591 snprintf(lan_stp, sizeof(lan_stp), "lan_stp"); 592 snprintf(lan_dhcp, sizeof(lan_dhcp), "lan_dhcp"); 593 snprintf(lan_ipaddr, sizeof(lan_ipaddr), "lan_ipaddr"); 594 snprintf(lan_hwaddr, sizeof(lan_hwaddr), "lan_hwaddr"); 595 snprintf(lan_netmask, sizeof(lan_netmask), "lan_netmask"); 596 lan_ifnames = nvram_safe_get("lan_ifnames"); 597 } 598 else { 599 snprintf(tmp, sizeof(tmp), "lan%x_ifname", i); 600 lan_ifname = nvram_safe_get(tmp); 601 snprintf(lan_stp, sizeof(lan_stp), "lan%x_stp", i); 602 snprintf(lan_dhcp, sizeof(lan_dhcp), "lan%x_dhcp", i); 603 snprintf(lan_ipaddr, sizeof(lan_ipaddr), "lan%x_ipaddr", i); 604 snprintf(lan_hwaddr, sizeof(lan_hwaddr), "lan%x_hwaddr", i); 605 snprintf(lan_netmask, sizeof(lan_netmask), "lan%x_netmask", i); 606 snprintf(tmp, sizeof(tmp), "lan%x_ifnames", i); 607 lan_ifnames = nvram_safe_get(tmp); 608 } 609 if (strncmp(lan_ifname, "br", 2) == 0) { 610 /* Set the bridge ifname in brX_ifname */ 611 snprintf(br_ifname, sizeof(br_ifname), "br%d_ifname", i); 612 nvram_set(br_ifname, lan_ifname); 613 614 eval("brctl", "addbr", lan_ifname); 615 616 /* Bob added start to avoid sending router solicitation packets, 09/03/2009 */ 617#ifdef INCLUDE_IPV6 618 sprintf(buf, "echo 0 > /proc/sys/net/ipv6/conf/%s/router_solicitations", lan_ifname); 619 system(buf); 620#endif 621 /* Bob added end to avoid sending router solicitation packets, 09/03/2009 */ 622 623 eval("brctl", "setfd", lan_ifname, "0"); 624 /* Foxconn modified start pling 12/05/2007, enable STP only in repeater mode */ 625 //if (nvram_match(lan_stp, "0")) 626 if (nvram_invmatch("wla_repeater", "1")) 627 /* Foxconn modified end pling 12/05/2007 */ 628 629 eval("brctl", "stp", lan_ifname, "off"); 630 else 631 eval("brctl", "stp", lan_ifname, "on"); 632#ifdef __CONFIG_EMF__ 633 if (nvram_match("emf_enable", "1")) 634 { 635 if( !strcmp(lan_ifname, "br0") ) 636 { 637 /* Add br0 to emf/igs only if IGMP proxy is enabled*/ 638 if (nvram_match("igmp_proxying_enable", "1")) 639 { 640 eval("emf", "add", "bridge", lan_ifname); 641 eval("igs", "add", "bridge", lan_ifname); 642 } 643 } 644 else 645 { 646 eval("emf", "add", "bridge", lan_ifname); 647 eval("igs", "add", "bridge", lan_ifname); 648 } 649 } 650#endif /* __CONFIG_EMF__ */ 651 memset(hwaddr, 0, sizeof(hwaddr)); 652 653 foreach(name, lan_ifnames, next) { 654 655 if (strncmp(name, "wl", 2) == 0) { 656 if (!wl_vif_enabled(name, tmp)) { 657 continue; /* Ignore disabled WL VIF */ 658 } 659 wl_vif_hwaddr_set(name); 660 } 661 662 /* Bring up interface. Ignore any bogus/unknown interfaces on the NVRAM list */ 663 //cprintf("--> ifconfig %s up\n", name); 664 /*Foxconn, add by MJ, for debugging 5G crash. */ 665#if 0 666 if(!strcmp(name, "eth2")){ 667 cprintf("give up enable eth2 for debugging.\n"); 668 continue; 669 } 670#endif 671 /*Foxconn, add-end by MJ., for debugging 5G crash. */ 672 if (ifconfig(name, IFUP | IFF_ALLMULTI, NULL, NULL)){ 673 perror("ifconfig"); 674 } 675// else 676 { 677 /* Set the logical bridge address to that of the first interface */ 678 if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) { 679 perror("socket"); 680 continue; 681 } 682 strncpy(ifr.ifr_name, name, IFNAMSIZ); 683 if (ioctl(s, SIOCGIFHWADDR, &ifr) == 0) { 684 if (memcmp(hwaddr, "\0\0\0\0\0\0", ETHER_ADDR_LEN) == 0) { 685 memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, 686 ETHER_ADDR_LEN); 687 } 688 } 689 close(s); 690 691 /* If not a wl i/f then simply add it to the bridge */ 692 if (eval("wlconf", name, "up")) { 693 if (eval("brctl", "addif", lan_ifname, name)) 694 perror("brctl"); 695 else { 696 snprintf(tmp, sizeof(tmp), "br%x_ifnames", i); 697 ptr = nvram_get(tmp); 698 if (ptr) 699 snprintf(buf, sizeof(buf), "%s %s", ptr, name); 700 else 701 strncpy(buf, name, sizeof(buf)); 702 nvram_set(tmp, buf); 703 } 704#ifdef __CONFIG_EMF__ 705 if (nvram_match("emf_enable", "1")) 706 eval("emf", "add", "iface", lan_ifname, name); 707#endif /* __CONFIG_EMF__ */ 708 } else { 709 char mode[] = "wlXXXXXXXXXX_mode"; 710 int unit = -1; 711 712 /* get the instance number of the wl i/f */ 713 wl_ioctl(name, WLC_GET_INSTANCE, &unit, sizeof(unit)); 714 715 snprintf(mode, sizeof(mode), "wl%d_mode", unit); 716 717 /* WET specific configurations */ 718 if (nvram_match(mode, "wet")) { 719 /* Receive all multicast frames in WET mode */ 720 ifconfig(name, IFUP | IFF_ALLMULTI, NULL, NULL); 721 722 /* Enable host DHCP relay */ 723 if (nvram_match("lan_dhcp", "1")) 724 wl_iovar_set(name, "wet_host_mac", ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN); 725 } 726 /* Dont attach the main wl i/f in wds */ 727 if ((strncmp(name, "wl", 2) != 0) && (nvram_match(mode, "wds"))){ 728 /* Save this interface name in unbridged_ifnames 729 * This behaviour is consistent with BEARS release 730 */ 731 ptr = nvram_get("unbridged_ifnames"); 732 if (ptr) 733 snprintf(buf, sizeof(buf), "%s %s", ptr, name); 734 else 735 strncpy(buf, name, sizeof(buf)); 736 nvram_set("unbridged_ifnames", buf); 737 continue; 738 } 739 740 /* Don't add main wl i/f when proxy sta is 741 * enabled in both bands. Instead add the 742 * dpsta interface. 743 */ 744 if (strstr(nvram_safe_get("dpsta_ifnames"), name)) { 745 /* Assign first wl i/f as dpsta hw address */ 746 if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) >= 0) { 747 strncpy(ifr.ifr_name, "dpsta", IFNAMSIZ); 748 if (ioctl(s, SIOCGIFHWADDR, &ifr) == 0 && 749 memcmp(ifr.ifr_hwaddr.sa_data, "\0\0\0\0\0\0", 750 ETHER_ADDR_LEN) == 0) { 751 strncpy(ifr.ifr_name, name, IFNAMSIZ); 752 if (ioctl(s, SIOCGIFHWADDR, &ifr) == 0) { 753 strncpy(ifr.ifr_name, "dpsta", IFNAMSIZ); 754 ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; 755 ioctl(s, SIOCSIFHWADDR, &ifr); 756 } 757 } 758 close(s); 759 } 760 761 strcpy(name, !dpsta ? "dpsta" : ""); 762 dpsta++; 763 } 764 765 eval("brctl", "addif", lan_ifname, name); 766#ifdef __CONFIG_EMF__ 767 if (nvram_match("emf_enable", "1")) 768 eval("emf", "add", "iface", lan_ifname, name); 769#endif /* __CONFIG_EMF__ */ 770 771 snprintf(tmp, sizeof(tmp), "br%x_ifnames", i); 772 ptr = nvram_get(tmp); 773 if (ptr) 774 snprintf(buf,sizeof(buf),"%s %s", ptr, name); 775 else 776 strncpy(buf, name, sizeof(buf)); 777 nvram_set(tmp, buf); 778 779 } /*if (eval("wlconf", na.....*/ 780 781 } /* if (ifconfig(name,...*/ 782 783 } /* foreach().... */ 784 785 if (memcmp(hwaddr, "\0\0\0\0\0\0", ETHER_ADDR_LEN) && 786 (s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) >= 0) { 787 strncpy(ifr.ifr_name, lan_ifname, IFNAMSIZ); 788 ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; 789 memcpy(ifr.ifr_hwaddr.sa_data, hwaddr, ETHER_ADDR_LEN); 790 ioctl(s, SIOCSIFHWADDR, &ifr); 791 close(s); 792 } 793 } /* if (strncmp(lan_ifname....*/ 794 /* specific non-bridged lan i/f */ 795 else if (strcmp(lan_ifname, "")) { 796 /* Bring up interface */ 797 ifconfig(lan_ifname, IFUP, NULL, NULL); 798 /* config wireless i/f */ 799 eval("wlconf", lan_ifname, "up"); 800 } 801 else 802 continue ; /* lanX_ifname is empty string , so donot do anything */ 803 804 /* Get current LAN hardware address */ 805 if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) >= 0) { 806 char eabuf[32]; 807 strncpy(ifr.ifr_name, lan_ifname, IFNAMSIZ); 808 if (ioctl(s, SIOCGIFHWADDR, &ifr) == 0) 809 nvram_set(lan_hwaddr, ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); 810 close(s); 811 } 812 813 /* Foxconn added start pling 03/18/2011 */ 814 /* Remove bridge DNS hijack module first. 815 * If we are in AP mode, this module will be 816 * inserted later again. 817 */ 818#ifdef AP_MODE 819#ifdef CONFIG_EXTENDER_MODE 820 if(!acosNvramConfig_match("enable_extender_mode", "1")) 821 system("/sbin/rmmod br_dns_hijack support_mode=3>/dev/null"); 822#else /* !CONFIG_EXTENDER_MODE */ 823 system("/sbin/rmmod br_dns_hijack 2>/dev/null"); 824#endif /* !CONFIG_EXTENDER_MODE */ 825#endif 826 /* Foxconn added end pling 03/18/2011 */ 827 828 if (l2bridge_no_ipaddr(lan_ifname)) { 829 ifconfig(lan_ifname, IFUP, NULL, NULL); 830 /* Launch DHCP client - AP only */ 831 } else if (nvram_match("router_disable", "1") && nvram_match(lan_dhcp, "1")) { 832 char *dhcp_argv[] = { 833 "udhcpc", 834 "-i", lan_ifname, 835 "-p", (sprintf(tmp, "/var/run/udhcpc-%s.pid", lan_ifname), tmp), 836 "-s", "/tmp/ldhclnt", 837 NULL 838 }; 839 int pid; 840 841 /* Start dhcp daemon */ 842 _eval(dhcp_argv, ">/dev/console", 0, &pid); 843 } 844/* Foxconn add start, Jenny Zhao, 03/07/2011 @Spec 2.0:AP Mode*/ 845 /* Auto IP mode. Now according to Router Spec 2.0, 846 * this is not related to UPnP/DLNA anymore, 847 * but related to "AP mode". 848 */ 849#ifdef AP_MODE 850 else if (nvram_match("enable_ap_mode", "1")) { 851 852 /* Foxconn added start pling 03/18/2011 */ 853 /* In AP mode, we need to hijack some domain names, 854 * e.g. www.routerlogin.net 855 * readyshare.routerlogin.net. 856 * etc 857 * we use 'br_dns_hijack.ko for this purpose. 858 */ 859 char command[128]; 860#ifdef SAMBA_ENABLE 861 sprintf(command, "/sbin/insmod " 862 "/lib/modules/2.6.22/kernel/lib/br_dns_hijack.ko " 863 "readyshare_dev=%s", 864 nvram_safe_get("smb_host_name")); 865#else 866 sprintf(command, "/sbin/insmod " 867 "/lib/modules/2.6.22/kernel/lib/br_dns_hijack.ko " 868 "readyshare_dev=\"\""); 869#endif 870 printf("command = '%s'\n", command); 871 system(command); 872 873 /* Insert acos_nat for logging purpose */ 874#ifdef LINUX26 875 system("/bin/mknod -m 755 /dev/acos_nat_cli c 100 0"); 876 system("/sbin/insmod /lib/modules/2.6.22/kernel/lib/acos_nat.ko"); 877#else 878 system("/sbin/insmod /lib/modules/2.4.20/kernel/net/ipv4/acos_nat/acos_nat.o"); 879#endif 880 /* Foxconn added end pling 03/18/2011 */ 881 882 /* Foxconn added start, Wins, 03/12/2011, @SamKnows */ 883//#ifdef ISP_SK 884 char cmd[64]; 885 /* Bring up WAN interface. */ 886 sprintf(cmd, "ifconfig %s up", nvram_get("wan_ifname")); 887 system(cmd); 888 /* Bridge WAN interface into br0. */ 889 sprintf(cmd, "brctl addif %s %s", nvram_get("lan_ifname"), nvram_get("wan_ifname")); 890 system(cmd); 891 /* Turn spanning tree for br0. */ 892 sprintf(cmd, "brctl stp %s on", nvram_get("lan_ifname")); 893 system(cmd); 894//#endif /* ISP_SK */ 895 /* Foxconn added end, Wins, 03/12/2011, @SamKnows */ 896 /*Foxconn add start by Hank 01/11/2013*/ 897 /*Fix can not see IPTV in AP mode*/ 898 eval("emf", "add", "iface", lan_ifname, "vlan2"); 899 /*Foxconn add end by Hank 01/11/2013*/ 900 901 /* Removed to start_services function in ap/acos/services.c */ 902 /* We should start autoipd in start_services(this function called 903 after acos_init), because 'ntpclient' be called in autoipd and 904 'set_system_time' be called in acos_init,If acos_init execute 905 after autoipd, ntp time will be recoverd by set_system_time 906 */ 907#if 0 908 if (nvram_match("ap_dyn_ip", "1")) { 909 /* Foxconn added start pling 03/16/2011 */ 910 /* Clear the NVRAM, so that heartbeat can show 911 * the Internet LED correctly. 912 */ 913 nvram_set("lan_ipaddr", "0.0.0.0"); 914 /* Foxconn added end pling 03/16/2011 */ 915 eval("autoipd"); 916 } 917 else 918#endif 919 if (!nvram_match("ap_dyn_ip", "1")) { 920 char command[128]; 921 FILE *fp; 922 char tmp[100]; 923 char word[100], *next; 924 char line[100]; 925 /* Use user-defined DNS servers if necessary */ 926 char dns[256]; 927 928 //use static settings from GUI 929 ifconfig(lan_ifname, IFUP, nvram_get("lan_ipaddr"), 930 nvram_get("lan_netmask")); /* Foxconn modified pling 03/24/2011 */ 931 sprintf (command, "route add default gw %s", nvram_get("apmode_gateway")); 932 system (command); 933 934 //Add dns 935 strcpy(dns, nvram_get("apmode_dns1")); 936 /* Open resolv.conf to read */ 937 if (!(fp = fopen("/tmp/resolv.conf", "w+"))) { 938 perror("/tmp/resolv.conf"); 939 return errno; 940 } 941 foreach(word, dns, next) 942 { 943 944 fprintf(fp, "nameserver %s\n", word); 945 } 946 fclose(fp); 947 } 948 } 949#endif 950/* Foxconn add end, Jenny Zhao, 03/07/2011 */ 951 /* Foxconn added start pling 03/01/2012 */ 952 /* In station mode, we insert br_dns_hijack 953 * module to make GUI management, USB access 954 * possible. 955 */ 956#if (defined STA_MODE) || (defined CONFIG_EXTENDER_MODE) 957 else if (nvram_match("enable_sta_mode", "1") 958#ifdef CONFIG_EXTENDER_MODE 959 || nvram_match("enable_extender_mode", "1") 960#endif 961 ) { 962 963 char command[128]; 964#ifdef SAMBA_ENABLE 965 sprintf(command, "/sbin/insmod " 966 "/lib/modules/2.6.22/kernel/lib/br_dns_hijack.ko " 967 "readyshare_dev=%s", 968 nvram_safe_get("smb_host_name")); 969#else 970 sprintf(command, "/sbin/insmod " 971 "/lib/modules/2.6.22/kernel/lib/br_dns_hijack.ko " 972 "readyshare_dev=\"\""); 973#endif 974 system(command); 975 976 /* Foxconn added start pling 03/06/2012 */ 977 /* Fix station mode static IP not work issue */ 978 if (!nvram_match("ap_dyn_ip", "1")) { 979 char command[128]; 980 FILE *fp; 981 char tmp[100]; 982 char word[100], *next; 983 char line[100]; 984 char dns[256]; 985 986 /* use static settings from GUI */ 987 ifconfig(lan_ifname, IFUP, nvram_get("lan_ipaddr"), 988 nvram_get("lan_netmask")); 989 sprintf(command, "route add default gw %s", 990 nvram_get("apmode_gateway")); 991 system(command); 992 993 /* Add dns */ 994 strcpy(dns, nvram_get("apmode_dns1")); 995 /* Open resolv.conf to read */ 996 if (!(fp = fopen("/tmp/resolv.conf", "w+"))) { 997 perror("/tmp/resolv.conf"); 998 return errno; 999 } 1000 foreach(word, dns, next) { 1001 fprintf(fp, "nameserver %s\n", word); 1002 } 1003 fclose(fp); 1004 } 1005 /* Foxconn added end pling 03/06/2012 */ 1006 } 1007#endif /* STA_MODE */ 1008 /* Foxconn added end pling 03/01/2012 */ 1009 1010 /* Handle static IP address - AP or Router */ 1011 else { 1012 /* Bring up and configure LAN interface */ 1013 ifconfig(lan_ifname, IFUP, 1014 nvram_safe_get(lan_ipaddr), nvram_safe_get(lan_netmask)); 1015 /* We are done configuration */ 1016 lan_up(lan_ifname); 1017 } 1018 1019#ifdef __CONFIG_EMF__ 1020 /* Start the EMF for this LAN */ 1021 start_emf(lan_ifname); 1022#endif /* __CONFIG_EMF__ */ 1023 } /* For loop */ 1024 1025#ifdef CONFIG_EXTENDER_MODE 1026 if(acosNvramConfig_match("enable_extender_mode", "1")) 1027 { 1028 /* Configure dpsta module */ 1029 if (dpsta) { 1030 int32 i = 0; 1031 1032 /* Enable and set the policy to in-band and cross-band 1033 * forwarding policy. 1034 */ 1035 info.enable = 1; 1036 info.policy = atoi(nvram_safe_get("dpsta_policy")); 1037 info.lan_uif = atoi(nvram_safe_get("dpsta_lan_uif")); 1038 foreach(name, nvram_safe_get("dpsta_ifnames"), next) { 1039 strcpy(info.upstream_if[i], name); 1040 i++; 1041 } 1042 dpsta_ioctl("dpsta", &info, sizeof(dpsta_enable_info_t)); 1043 1044 /* Bring up dpsta interface */ 1045 ifconfig("dpsta", IFUP, NULL, NULL); 1046 } else { 1047 info.enable = 0; 1048 dpsta_ioctl("dpsta", &info, sizeof(dpsta_enable_info_t)); 1049 ifconfig("dpsta", 0, NULL, NULL); 1050 } 1051 } 1052#endif /* CONFIG_EXTENDER_MODE */ 1053 1054 /* Set initial QoS mode for LAN ports. */ 1055 set_et_qos_mode(); 1056 1057 /* start syslogd if either log_ipaddr or log_ram_enable is set */ 1058 if (nvram_invmatch("log_ipaddr", "") || nvram_match("log_ram_enable", "1")) { 1059#if !defined(__CONFIG_BUSYBOX__) || defined(BB_SYSLOGD) 1060 char *argv[] = { 1061 "syslogd", 1062 NULL, /* -C */ 1063 NULL, NULL, /* -R host */ 1064 NULL 1065 }; 1066 int pid; 1067 int argc = 1; 1068 1069 if (nvram_match("log_ram_enable", "1")) 1070 argv[argc++] = "-C"; 1071 1072 if (nvram_invmatch("log_ipaddr", "")) { 1073 argv[argc++] = "-R"; 1074 argv[argc++] = nvram_get("log_ipaddr"); 1075 } 1076 1077 1078 _eval(argv, NULL, 0, &pid); 1079#else /* Busybox configured w/o syslogd */ 1080 cprintf("Busybox configured w/o syslogd\n"); 1081#endif 1082 } 1083 1084 dprintf("%s %s\n", 1085 nvram_safe_get("lan_ipaddr"), 1086 nvram_safe_get("lan_netmask")); 1087 1088} 1089 1090void 1091stop_lan(void) 1092{ 1093 char *lan_ifname = nvram_safe_get("lan_ifname"); 1094 char name[80], *next, signal[] = "XXXXXXXX"; 1095 char br_prefix[20]; 1096 char tmp[20]; 1097 int i = 0; 1098 char* lan_ifnames; 1099 1100 dprintf("%s\n", lan_ifname); 1101 1102 /* Stop the syslogd daemon */ 1103 eval("killall", "syslogd"); 1104 /* release the DHCP address and kill the client */ 1105 snprintf(signal, sizeof(signal), "-%d", SIGUSR2); 1106 eval("killall", signal, "udhcpc"); 1107 eval("killall", "udhcpc"); 1108 1109 /* Remove static routes */ 1110 del_lan_routes(lan_ifname); 1111 1112 /* Bring down unbridged interfaces,if any */ 1113 foreach(name, nvram_safe_get("unbridged_ifnames"), next) { 1114 eval("wlconf", name, "down"); 1115 ifconfig(name, 0, NULL, NULL); 1116 } 1117 1118 for (i = 0; i < MAX_NO_BRIDGE; i++) { 1119 if (!i) { 1120 lan_ifname = nvram_safe_get("br0_ifname"); 1121 snprintf(br_prefix, sizeof(br_prefix), "br0_ifnames"); 1122 } 1123 else { 1124 snprintf(tmp, sizeof(tmp), "br%x_ifname", i); 1125 lan_ifname = nvram_safe_get(tmp); 1126 snprintf(br_prefix, sizeof(br_prefix), "br%x_ifnames",i); 1127 } 1128 if (!strcmp(lan_ifname, "")) 1129 continue; 1130 1131 1132 /* Bring down LAN interface */ 1133#if ((defined WLAN_REPEATER) || (defined CONFIG_EXTENDER_MODE)) && (defined INCLUDE_DUAL_BAND) 1134//#if 0 /* foxconn wklin removed start, 03/24/2011 */ 1135 if(acosNvramConfig_match("enable_extender_mode", "1")) 1136 { 1137 ifconfig(lan_ifname, 0, NULL, NULL); 1138 1139 /* Bring down bridged interfaces */ 1140 if (strncmp(lan_ifname, "br", 2) == 0) { 1141 lan_ifnames = nvram_safe_get(br_prefix); 1142 foreach(name, lan_ifnames, next) { 1143 if (!strcmp(name, "dpsta")) { 1144 char dp_uif[80], *dpnext; 1145 foreach(dp_uif, nvram_safe_get("dpsta_ifnames"), 1146 dpnext) { 1147 eval("wlconf", dp_uif, "down"); 1148 ifconfig(dp_uif, 0, NULL, NULL); 1149 } 1150 } 1151 sleep(1);/*borg*/ 1152 eval("wlconf", name, "down"); 1153 ifconfig(name, 0, NULL, NULL); 1154 eval("brctl", "delif", lan_ifname, name); 1155#ifdef __CONFIG_EMF__ 1156 /* Remove ifface from emf */ 1157 if (nvram_match("emf_enable", "1")) 1158 eval("emf", "del", "iface", lan_ifname, name); 1159#endif /* __CONFIG_EMF__ */ 1160 } 1161#ifdef __CONFIG_EMF__ 1162 /* Stop the EMF for this LAN */ 1163 eval("emf", "stop", lan_ifname); 1164 /* Remove Bridge from igs */ 1165 eval("igs", "del", "bridge", lan_ifname); 1166 eval("emf", "del", "bridge", lan_ifname); 1167#endif /* __CONFIG_EMF__ */ 1168 eval("brctl", "delbr", lan_ifname); 1169 } 1170 /* Bring down specific interface */ 1171 else if (strcmp(lan_ifname, "")) 1172 eval("wlconf", lan_ifname, "down"); 1173 } 1174//#endif /* foxconn wklin removed end, 03/24/2011 */ 1175#endif /* ((defined WLAN_REPEATER) || (defined CONFIG_EXTENDER_MODE)) && (defined INCLUDE_DUAL_BAND) */ 1176 if(!acosNvramConfig_match("enable_extender_mode", "1")) 1177 { 1178 /* Foxconn add start, Jenny Zhao, 03/29/2011 @AP Mode*/ 1179 /* We should delete eth0 from br0 for router mode */ 1180 if (nvram_match("enable_ap_mode", "0")) { 1181 char cmd[64]; 1182 /* Delete WAN interface from br0. */ 1183 sprintf(cmd, "brctl delif %s %s", nvram_get("lan_ifname"), nvram_get("wan_ifname")); 1184 system(cmd); 1185 } 1186 /* Foxconn add end, Jenny Zhao, 03/29/2011 */ 1187 } 1188 } 1189 1190 unlink("/tmp/ldhclnt"); 1191 1192 dprintf("done\n"); 1193} 1194 1195#ifdef CONFIG_EXTENDER_MODE 1196/* Foxconn add start, Max Ding, 11/10/2011 @wps auto change mode */ 1197void 1198add_wl_if_for_br0(void) 1199{ 1200 char *lan_ifname = nvram_safe_get("lan_ifname"); 1201 char br_ifname[80]; 1202 char name[80], *next; 1203 char tmp[100]; 1204 int i, s, dpsta = 0; 1205 struct ifreq ifr; 1206 char buf[255], *ptr; 1207 char lan_stp[10]; 1208 char *lan_ifnames; 1209 char lan_dhcp[10]; 1210 char lan_ipaddr[15]; 1211 char lan_netmask[15]; 1212 char lan_hwaddr[15]; 1213 char hwaddr[ETHER_ADDR_LEN]; 1214 dpsta_enable_info_t info = { 0 }; 1215 1216 /* The NVRAM variable lan_ifnames contains all the available interfaces. 1217 * This is used to build the unbridged interface list. Once the unbridged list 1218 * is built lan_interfaces is rebuilt with only the interfaces in the bridge 1219 */ 1220 1221 dprintf("%s\n", lan_ifname); 1222 1223 /* Foxconn, added by MJ., for DLAN AUTO IP, 2010.05.18 */ 1224#ifdef DLNA 1225#ifdef DLNA_DEBUG 1226 char auto_ip[8]; 1227 strcpy(auto_ip, acosNvramConfig_get("dlna_auto_ip")); 1228 cprintf("dlna_auto_ip: %s. \n", auto_ip); 1229#endif 1230 if(nvram_match("dlna_auto_ip", "1")) 1231 { 1232 if(nvram_match("auto_ip_backup", "0")) 1233 {/* dlna_auto_ip changed from 0 to 1. */ 1234 nvram_set("auto_ip_backup", "1"); 1235 /* Set default Auto IP values. */ 1236 nvram_set("tmp_lan_ipaddr", nvram_get("lan_ipaddr")); 1237 nvram_set("lan_ipaddr", "169.254.146.254"); 1238 1239 nvram_set("tmp_lan_netmask", nvram_get("lan_netmask")); 1240 nvram_set("lan_netmask", "255.255.0.0"); 1241 1242 nvram_set("tmp_lan_proto", nvram_get("lan_proto")); 1243 nvram_set("lan_proto", "static"); 1244 1245 nvram_set("tmp_rip_enable", nvram_get("rip_enable")); 1246 nvram_set("rip_enable", "0"); 1247 1248 nvram_commit(); 1249 } 1250 }else{/* dlna_auto_ip = 0 */ 1251 if(nvram_match("auto_ip_backup", "1")) 1252 {/* dlan_auto_ip changed from 1 to 0. */ 1253 /* If user had changed the value, don't use tmp values.*/ 1254 if(!nvram_match("tmp_lan_netmask", "null")&& 1255 nvram_match(nvram_get("lan_netmask"), "255.255.0.0")){ 1256 nvram_set("lan_netmask", nvram_get("tmp_lan_netmask")); 1257 nvram_set("tmp_lan_netmask", "null"); 1258 } 1259 if(!nvram_match("tmp_lan_ipaddr", "null")&& 1260 nvram_match(nvram_get("lan_ipaddr"), "169.254.146.254")){ 1261 nvram_set("lan_ipaddr", nvram_get("tmp_lan_ipaddr")); 1262 nvram_set("tmp_lan_ipaddr", "null"); 1263 } 1264 if(!nvram_match("tmp_lan_proto", "null")&& 1265 nvram_match(nvram_get("lan_proto"), "static")){ 1266 nvram_set("lan_proto", nvram_get("tmp_lan_proto")); 1267 nvram_set("tmp_lan_proto", "null"); 1268 } 1269 if(!nvram_match("tmp_rip_enable", "null")&& 1270 nvram_match(nvram_get("rip_enable"), "0")){ 1271 nvram_set("rip_enable", nvram_get("tmp_rip_enable")); 1272 nvram_set("tmp_rip_enable", "null"); 1273 } 1274 nvram_set("auto_ip_backup", "0"); 1275 nvram_commit(); 1276 } 1277 } 1278#ifdef DLNA_DEBUG 1279 cprintf("-> netmask: %s\n", nvram_get("lan_netmask")); 1280 cprintf("-> lan ip: %s\n", nvram_get("lan_ipaddr")); 1281 cprintf("-> dhcp server: %s\n", nvram_get("lan_proto")); 1282 cprintf("-> rip: %s\n", nvram_get("rip_enable")); 1283#endif 1284 1285 1286 //nvram_commit(); 1287#endif 1288 /* Foxconn, ended by MJ., for DLAN AUTO IP, 2010.05.18 */ 1289 1290 1291 /* Create links */ 1292 //symlink("/sbin/rc", "/tmp/ldhclnt"); 1293 1294 1295 nvram_unset("br0_ifname"); 1296 nvram_unset("br1_ifname"); 1297 nvram_unset("unbridged_ifnames"); 1298 nvram_unset("br0_ifnames"); 1299 nvram_unset("br1_ifnames"); 1300 1301#if defined(__CONFIG_EXTACS__) || defined(__CONFIG_WL_ACI__) 1302 nvram_unset("acs_ifnames"); 1303#endif /* defined(_CONFIG_EXTACS__) || defined(__CONFIG_WL_ACI__ */ 1304 /* If we're a travel router... then we need to make sure we get 1305 * the primary wireless interface up before trying to attach slave 1306 * interface(s) to the bridge 1307 */ 1308 if (nvram_match("ure_disable", "0") && nvram_match("router_disable", "0")) 1309 { 1310 eval("wlconf", nvram_get("wan0_ifname"), "up"); 1311 } 1312 1313 1314 /* Bring up bridged interfaces */ 1315 for (i = 0; i < MAX_NO_BRIDGE; i++) { 1316 if (!i) { 1317 lan_ifname = nvram_safe_get("lan_ifname"); 1318 snprintf(lan_stp, sizeof(lan_stp), "lan_stp"); 1319 snprintf(lan_dhcp, sizeof(lan_dhcp), "lan_dhcp"); 1320 snprintf(lan_ipaddr, sizeof(lan_ipaddr), "lan_ipaddr"); 1321 snprintf(lan_hwaddr, sizeof(lan_hwaddr), "lan_hwaddr"); 1322 snprintf(lan_netmask, sizeof(lan_netmask), "lan_netmask"); 1323 lan_ifnames = nvram_safe_get("lan_ifnames"); 1324 } 1325 else { 1326 snprintf(tmp, sizeof(tmp), "lan%x_ifname", i); 1327 lan_ifname = nvram_safe_get(tmp); 1328 snprintf(lan_stp, sizeof(lan_stp), "lan%x_stp", i); 1329 snprintf(lan_dhcp, sizeof(lan_dhcp), "lan%x_dhcp", i); 1330 snprintf(lan_ipaddr, sizeof(lan_ipaddr), "lan%x_ipaddr", i); 1331 snprintf(lan_hwaddr, sizeof(lan_hwaddr), "lan%x_hwaddr", i); 1332 snprintf(lan_netmask, sizeof(lan_netmask), "lan%x_netmask", i); 1333 snprintf(tmp, sizeof(tmp), "lan%x_ifnames", i); 1334 lan_ifnames = nvram_safe_get(tmp); 1335 } 1336 if (strncmp(lan_ifname, "br", 2) == 0) { 1337 /* Set the bridge ifname in brX_ifname */ 1338 snprintf(br_ifname, sizeof(br_ifname), "br%d_ifname", i); 1339 nvram_set(br_ifname, lan_ifname); 1340 1341 //eval("brctl", "addbr", lan_ifname); 1342 1343 /* Bob added start to avoid sending router solicitation packets, 09/03/2009 */ 1344#ifdef INCLUDE_IPV6 1345 sprintf(buf, "echo 0 > /proc/sys/net/ipv6/conf/%s/router_solicitations", lan_ifname); 1346 system(buf); 1347#endif 1348 /* Bob added end to avoid sending router solicitation packets, 09/03/2009 */ 1349 1350 //eval("brctl", "setfd", lan_ifname, "0"); 1351 /* Foxconn modified by Max Ding, 09/02/2011 @repeater should enable stp */ 1352 //if (nvram_match(lan_stp, "0")) 1353 // eval("brctl", "stp", lan_ifname, "off"); 1354 //else 1355 // eval("brctl", "stp", lan_ifname, "on"); 1356#ifdef __CONFIG_EMF__ 1357 if (nvram_match("emf_enable", "1")) 1358 { 1359 if( !strcmp(lan_ifname, "br0") ) 1360 { 1361 /* Add br0 to emf/igs only if IGMP proxy is enabled*/ 1362 if (nvram_match("igmp_proxying_enable", "1")) 1363 { 1364 eval("emf", "add", "bridge", lan_ifname); 1365 eval("igs", "add", "bridge", lan_ifname); 1366 } 1367 } 1368 else 1369 { 1370 eval("emf", "add", "bridge", lan_ifname); 1371 eval("igs", "add", "bridge", lan_ifname); 1372 } 1373 } 1374#endif /* __CONFIG_EMF__ */ 1375 memset(hwaddr, 0, sizeof(hwaddr)); 1376 1377 foreach(name, lan_ifnames, next) { 1378 1379 if (strncmp(name, "wl", 2) == 0) { 1380 if (!wl_vif_enabled(name, tmp)) { 1381 continue; /* Ignore disabled WL VIF */ 1382 } 1383 wl_vif_hwaddr_set(name); 1384 } 1385 1386 /* Bring up interface. Ignore any bogus/unknown interfaces on the NVRAM list */ 1387 //cprintf("--> ifconfig %s up\n", name); 1388 /*Foxconn, add by MJ, for debugging 5G crash. */ 1389#if 0 1390 if(!strcmp(name, "eth2")){ 1391 cprintf("give up enable eth2 for debugging.\n"); 1392 continue; 1393 } 1394#endif 1395 /*Foxconn, add-end by MJ., for debugging 5G crash. */ 1396 if (ifconfig(name, IFUP | IFF_ALLMULTI, NULL, NULL)){ 1397 perror("ifconfig"); 1398 } else { 1399 /* Set the logical bridge address to that of the first interface */ 1400 if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) { 1401 perror("socket"); 1402 continue; 1403 } 1404 strncpy(ifr.ifr_name, lan_ifname, IFNAMSIZ); 1405 /* Foxconn modify start, Max Ding, 06/12/2012 @WPS switch bug */ 1406 /* WPS bug because fail to switch mode: psr-ap --> psr-psr 1407 * root cause is dpsta's hw addr is empty in the case 1408 */ 1409 if (ioctl(s, SIOCGIFHWADDR, &ifr) == 0){ 1410 if (memcmp(ifr.ifr_hwaddr.sa_data, "\0\0\0\0\0\0", ETHER_ADDR_LEN) == 0) { 1411 struct ether_addr ea; 1412 strncpy(ifr.ifr_name, name, IFNAMSIZ); 1413 if (ioctl(s, SIOCGIFHWADDR, &ifr) == 0) { 1414 /* Check nvram var lan_hwaddr first. 1415 * If it is non-zero, set the address. 1416 */ 1417 if (strcmp(nvram_safe_get(lan_hwaddr), "")) { 1418 ether_atoe(nvram_get(lan_hwaddr), 1419 (unsigned char *)&ea); 1420 memcpy(ifr.ifr_hwaddr.sa_data, &ea, 1421 ETHER_ADDR_LEN); 1422 } 1423 strncpy(ifr.ifr_name, lan_ifname, IFNAMSIZ); 1424 ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; 1425 ioctl(s, SIOCSIFHWADDR, &ifr); 1426 1427 memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN); 1428 } 1429 } 1430 else 1431 { 1432 memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN); 1433 } 1434 } 1435 /* Foxconn modify end, Max Ding, 06/12/2012 */ 1436 close(s); 1437 1438 /* If not a wl i/f then simply add it to the bridge */ 1439 if (eval("wlconf", name, "up")) { 1440 if (strcmp(name, "vlan1") && eval("brctl", "addif", lan_ifname, name))/* Foxconn modified by Max Ding, 06/12/2012 @WPS switch bug */ 1441 perror("brctl"); 1442 else { 1443 snprintf(tmp, sizeof(tmp), "br%x_ifnames", i); 1444 ptr = nvram_get(tmp); 1445 if (ptr) 1446 snprintf(buf, sizeof(buf), "%s %s", ptr, name); 1447 else 1448 strncpy(buf, name, sizeof(buf)); 1449 nvram_set(tmp, buf); 1450 } 1451#ifdef __CONFIG_EMF__ 1452 if (nvram_match("emf_enable", "1")) 1453 eval("emf", "add", "iface", lan_ifname, name); 1454#endif /* __CONFIG_EMF__ */ 1455 } else { 1456 char mode[] = "wlXXXXXXXXXX_mode"; 1457 int unit = -1; 1458 1459 /* get the instance number of the wl i/f */ 1460 wl_ioctl(name, WLC_GET_INSTANCE, &unit, sizeof(unit)); 1461 1462 snprintf(mode, sizeof(mode), "wl%d_mode", unit); 1463 1464 /* WET specific configurations */ 1465 if (nvram_match(mode, "wet")) { 1466 /* Receive all multicast frames in WET mode */ 1467 ifconfig(name, IFUP | IFF_ALLMULTI, NULL, NULL); 1468 1469 /* Enable host DHCP relay */ 1470 if (nvram_match("lan_dhcp", "1")) 1471 wl_iovar_set(name, "wet_host_mac", ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN); 1472 } 1473 /* Dont attach the main wl i/f in wds */ 1474 if ((strncmp(name, "wl", 2) != 0) && (nvram_match(mode, "wds"))){ 1475 /* Save this interface name in unbridged_ifnames 1476 * This behaviour is consistent with BEARS release 1477 */ 1478 ptr = nvram_get("unbridged_ifnames"); 1479 if (ptr) 1480 snprintf(buf, sizeof(buf), "%s %s", ptr, name); 1481 else 1482 strncpy(buf, name, sizeof(buf)); 1483 nvram_set("unbridged_ifnames", buf); 1484 continue; 1485 } 1486 1487 /* Don't add main wl i/f when proxy sta is 1488 * enabled in both bands. Instead add the 1489 * dpsta interface. 1490 */ 1491 if (strstr(nvram_safe_get("dpsta_ifnames"), name)) { 1492#if 0 /* orig */ 1493 strcpy(name, !dpsta ? "dpsta" : ""); 1494 dpsta++; 1495 1496 /* Assign hw address */ 1497 if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) >= 0) { 1498 strncpy(ifr.ifr_name, "dpsta", IFNAMSIZ); 1499 if (ioctl(s, SIOCGIFHWADDR, &ifr) == 0 && 1500 memcmp(ifr.ifr_hwaddr.sa_data, "\0\0\0\0\0\0", 1501 ETHER_ADDR_LEN) == 0) { 1502 ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; 1503 memcpy(ifr.ifr_hwaddr.sa_data, hwaddr, ETHER_ADDR_LEN); 1504 ioctl(s, SIOCSIFHWADDR, &ifr); 1505 } 1506 close(s); 1507 } 1508#else 1509 /* Assign first wl i/f as dpsta hw address */ 1510 if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) >= 0) { 1511 strncpy(ifr.ifr_name, "dpsta", IFNAMSIZ); 1512 if (ioctl(s, SIOCGIFHWADDR, &ifr) == 0 && 1513 memcmp(ifr.ifr_hwaddr.sa_data, "\0\0\0\0\0\0", 1514 ETHER_ADDR_LEN) == 0) { 1515 strncpy(ifr.ifr_name, name, IFNAMSIZ); 1516 if (ioctl(s, SIOCGIFHWADDR, &ifr) == 0) { 1517 strncpy(ifr.ifr_name, "dpsta", IFNAMSIZ); 1518 ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; 1519 ioctl(s, SIOCSIFHWADDR, &ifr); 1520 } 1521 } 1522 close(s); 1523 } 1524 1525 strcpy(name, !dpsta ? "dpsta" : ""); 1526 dpsta++; 1527#endif 1528 } 1529 1530 eval("brctl", "addif", lan_ifname, name); 1531#ifdef __CONFIG_EMF__ 1532 if (nvram_match("emf_enable", "1")) 1533 eval("emf", "add", "iface", lan_ifname, name); 1534#endif /* __CONFIG_EMF__ */ 1535 1536 snprintf(tmp, sizeof(tmp), "br%x_ifnames", i); 1537 ptr = nvram_get(tmp); 1538 if (ptr) 1539 snprintf(buf,sizeof(buf),"%s %s", ptr, name); 1540 else 1541 strncpy(buf, name, sizeof(buf)); 1542 nvram_set(tmp, buf); 1543 1544 } /*if (eval("wlconf", na.....*/ 1545 1546 } /* if (ifconfig(name,...*/ 1547 1548 } /* foreach().... */ 1549 1550 if (memcmp(hwaddr, "\0\0\0\0\0\0", ETHER_ADDR_LEN) && 1551 (s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) >= 0) { 1552 strncpy(ifr.ifr_name, lan_ifname, IFNAMSIZ); 1553 ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; 1554 memcpy(ifr.ifr_hwaddr.sa_data, hwaddr, ETHER_ADDR_LEN); 1555 ioctl(s, SIOCSIFHWADDR, &ifr); 1556 close(s); 1557 } 1558 } /* if (strncmp(lan_ifname....*/ 1559 /* specific non-bridged lan i/f */ 1560 //else if (strcmp(lan_ifname, "")) { 1561 // /* Bring up interface */ 1562 // ifconfig(lan_ifname, IFUP, NULL, NULL); 1563 // /* config wireless i/f */ 1564 // eval("wlconf", lan_ifname, "up"); 1565 //} 1566 //else 1567 // continue ; /* lanX_ifname is empty string , so donot do anything */ 1568 1569 /* Get current LAN hardware address */ 1570 if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) >= 0) { 1571 char eabuf[32]; 1572 strncpy(ifr.ifr_name, lan_ifname, IFNAMSIZ); 1573 if (ioctl(s, SIOCGIFHWADDR, &ifr) == 0) 1574 nvram_set(lan_hwaddr, ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); 1575 close(s); 1576 } 1577 1578#ifdef __CONFIG_EMF__ 1579 /* Start the EMF for this LAN */ 1580 start_emf(lan_ifname); 1581#endif /* __CONFIG_EMF__ */ 1582 } /* For loop */ 1583 1584 /* Configure dpsta module */ 1585 if (dpsta) { 1586 int32 i = 0; 1587 1588 /* Enable and set the policy to in-band and cross-band 1589 * forwarding policy. 1590 */ 1591 info.enable = 1; 1592 info.policy = atoi(nvram_safe_get("dpsta_policy")); 1593 info.lan_uif = atoi(nvram_safe_get("dpsta_lan_uif")); 1594 foreach(name, nvram_safe_get("dpsta_ifnames"), next) { 1595 strcpy(info.upstream_if[i], name); 1596 i++; 1597 } 1598 dpsta_ioctl("dpsta", &info, sizeof(dpsta_enable_info_t)); 1599 1600 /* Bring up dpsta interface */ 1601 ifconfig("dpsta", IFUP, NULL, NULL); 1602 } else { 1603 info.enable = 0; 1604 dpsta_ioctl("dpsta", &info, sizeof(dpsta_enable_info_t)); 1605 ifconfig("dpsta", 0, NULL, NULL); 1606 } 1607 1608 /* Set initial QoS mode for LAN ports. */ 1609 set_et_qos_mode(); 1610 1611 /* start syslogd if either log_ipaddr or log_ram_enable is set */ 1612 if (nvram_invmatch("log_ipaddr", "") || nvram_match("log_ram_enable", "1")) { 1613#if !defined(__CONFIG_BUSYBOX__) || defined(BB_SYSLOGD) 1614 char *argv[] = { 1615 "syslogd", 1616 NULL, /* -C */ 1617 NULL, NULL, /* -R host */ 1618 NULL 1619 }; 1620 int pid; 1621 int argc = 1; 1622 1623 if (nvram_match("log_ram_enable", "1")) 1624 argv[argc++] = "-C"; 1625 1626 if (nvram_invmatch("log_ipaddr", "")) { 1627 argv[argc++] = "-R"; 1628 argv[argc++] = nvram_get("log_ipaddr"); 1629 } 1630 1631 1632 _eval(argv, NULL, 0, &pid); 1633#else /* Busybox configured w/o syslogd */ 1634 cprintf("Busybox configured w/o syslogd\n"); 1635#endif 1636 } 1637 1638 dprintf("%s %s\n", 1639 nvram_safe_get("lan_ipaddr"), 1640 nvram_safe_get("lan_netmask")); 1641 1642} 1643 1644void 1645remove_wl_if_for_br0(void) 1646{ 1647 char *lan_ifname = nvram_safe_get("lan_ifname"); 1648 char name[80], *next, signal[] = "XXXXXXXX"; 1649 char br_prefix[20]; 1650 char tmp[20]; 1651 int i = 0; 1652 char* lan_ifnames; 1653 1654 dprintf("%s\n", lan_ifname); 1655 1656 /* Stop the syslogd daemon */ 1657 //eval("killall", "syslogd"); 1658 /* release the DHCP address and kill the client */ 1659 //snprintf(signal, sizeof(signal), "-%d", SIGUSR2); 1660 //eval("killall", signal, "udhcpc"); 1661 //eval("killall", "udhcpc"); 1662 1663 /* Remove static routes */ 1664 //del_lan_routes(lan_ifname); 1665 1666 /* Bring down unbridged interfaces,if any */ 1667 foreach(name, nvram_safe_get("unbridged_ifnames"), next) { 1668 eval("wlconf", name, "down"); 1669 ifconfig(name, 0, NULL, NULL); 1670 } 1671 1672 for (i = 0; i < MAX_NO_BRIDGE; i++) { 1673 if (!i) { 1674 lan_ifname = nvram_safe_get("br0_ifname"); 1675 snprintf(br_prefix, sizeof(br_prefix), "br0_ifnames"); 1676 } 1677 else { 1678 snprintf(tmp, sizeof(tmp), "br%x_ifname", i); 1679 lan_ifname = nvram_safe_get(tmp); 1680 snprintf(br_prefix, sizeof(br_prefix), "br%x_ifnames",i); 1681 } 1682 if (!strcmp(lan_ifname, "")) 1683 continue; 1684 1685 1686 /* Bring down LAN interface */ 1687#if (defined WLAN_REPEATER) && (defined INCLUDE_DUAL_BAND) 1688//#if 0 /* foxconn wklin removed start, 03/24/2011 */ 1689 //ifconfig(lan_ifname, 0, NULL, NULL); 1690 1691 /* Bring down bridged interfaces */ 1692 if (strncmp(lan_ifname, "br", 2) == 0) { 1693 lan_ifnames = nvram_safe_get(br_prefix); 1694 foreach(name, lan_ifnames, next) { 1695 if (!strcmp(name, "vlan1")) { 1696 continue; 1697 } 1698 if (!strcmp(name, "dpsta")) { 1699 char dp_uif[80], *dpnext; 1700 foreach(dp_uif, nvram_safe_get("dpsta_ifnames"), 1701 dpnext) { 1702 eval("wlconf", dp_uif, "down"); 1703 ifconfig(dp_uif, 0, NULL, NULL); 1704 } 1705 } 1706 sleep(1);/*borg*/ 1707 eval("wlconf", name, "down"); 1708 ifconfig(name, 0, NULL, NULL); 1709 eval("brctl", "delif", lan_ifname, name); 1710#ifdef __CONFIG_EMF__ 1711 /* Remove ifface from emf */ 1712 if (nvram_match("emf_enable", "1")) 1713 eval("emf", "del", "iface", lan_ifname, name); 1714#endif /* __CONFIG_EMF__ */ 1715 } 1716#ifdef __CONFIG_EMF__ 1717 /* Stop the EMF for this LAN */ 1718 eval("emf", "stop", lan_ifname); 1719 /* Remove Bridge from igs */ 1720 eval("igs", "del", "bridge", lan_ifname); 1721 eval("emf", "del", "bridge", lan_ifname); 1722#endif /* __CONFIG_EMF__ */ 1723 eval("brctl", "delbr", lan_ifname); 1724 } 1725 /* Bring down specific interface */ 1726 else if (strcmp(lan_ifname, "")) 1727 eval("wlconf", lan_ifname, "down"); 1728#endif /* foxconn wklin removed end, 03/24/2011 */ 1729 1730 /* Foxconn add start, Jenny Zhao, 03/29/2011 @AP Mode*/ 1731 /* We should delete eth0 from br0 for router mode */ 1732 if (nvram_match("enable_ap_mode", "0")) { 1733 char cmd[64]; 1734 /* Delete WAN interface from br0. */ 1735 sprintf(cmd, "brctl delif %s %s", nvram_get("lan_ifname"), nvram_get("wan_ifname")); 1736 system(cmd); 1737 } 1738 /* Foxconn add end, Jenny Zhao, 03/29/2011 */ 1739 } 1740 1741 unlink("/tmp/ldhclnt"); 1742 1743 dprintf("done\n"); 1744 1745} 1746/* Foxconn add end, Max Ding, 11/10/2011 */ 1747#endif /* CONFIG_EXTENDER_MODE */ 1748 1749void 1750start_wl(void) 1751{ 1752 int i; 1753 /* Foxconn modified start pling 11/26/2009 */ 1754 //char *lan_ifname = nvram_safe_get("lan_ifname"); 1755 char lan_ifname[32]; 1756 /* Foxconn modified end pling 11/26/2009 */ 1757 char name[80], *next; 1758 char tmp[100]; 1759 /* Foxconn modified start pling 11/26/2009 */ 1760 //char *lan_ifnames; 1761 char lan_ifnames[128]; 1762 /* Foxconn modified end pling 11/26/2009 */ 1763 int region; 1764 1765 /* If we're a travel router... then we need to make sure we get 1766 * the primary wireless interface up before trying to attach slave 1767 * interface(s) to the bridge 1768 */ 1769 if (nvram_match("ure_disable", "0") && nvram_match("router_disable", "0")) { 1770 /* start wlireless */ 1771 eval("wlconf", nvram_get("wan0_ifname"), "start"); 1772 } 1773 1774 /* Bring up bridged interfaces */ 1775 for(i=0; i < MAX_NO_BRIDGE; i++) { 1776 if(!i) { 1777 /* Foxconn modified start pling 11/26/2009 */ 1778 /* Use char array to keep the nvram value instead of 1779 * using pointers. 1780 */ 1781#if 0 1782 lan_ifname = nvram_safe_get("lan_ifname"); 1783 lan_ifnames = nvram_safe_get("lan_ifnames"); 1784#endif 1785 strcpy(lan_ifname, nvram_safe_get("lan_ifname")); 1786 strcpy(lan_ifnames, nvram_safe_get("lan_ifnames")); 1787 /* Foxconn modified end pling 11/26/2009 */ 1788 } 1789 else { 1790 snprintf(tmp, sizeof(tmp), "lan%x_ifname", i); 1791 /* Foxconn modified start pling 11/26/2009 */ 1792 /* Use char array to keep the nvram value instead of 1793 * using pointers. 1794 */ 1795 //lan_ifname = nvram_safe_get( tmp); 1796 strcpy(lan_ifname, nvram_safe_get( tmp)); 1797 snprintf(tmp, sizeof(tmp), "lan%x_ifnames", i); 1798 //lan_ifnames = nvram_safe_get( tmp); 1799 strcpy(lan_ifnames, nvram_safe_get( tmp)); 1800 /* Foxconn modified end pling 11/26/2009 */ 1801 } 1802 if (strncmp(lan_ifname, "br", 2) == 0) { 1803 foreach(name, lan_ifnames, next) { 1804 if (strncmp(name, "wl", 2) == 0) { 1805 if (!wl_vif_enabled(name, tmp)) { 1806 continue; /* Ignore disabled WL VIF */ 1807 } 1808 } 1809 /* If a wl i/f, start it */ 1810 eval("wlconf", name, "start"); 1811 1812 } /* foreach().... */ 1813 } /* if (strncmp(lan_ifname....*/ 1814 /* specific non-bridged lan i/f */ 1815 else if (strcmp(lan_ifname, "")) { 1816 /* start wireless i/f */ 1817 eval("wlconf", lan_ifname, "start"); 1818 } 1819 } /* For loop */ 1820 1821 /*Foxconn add start by Hank 03/07/2012*/ 1822 /*disable roam_trigger when bridge mode*/ 1823#if (defined STA_MODE) || (defined CONFIG_EXTENDER_MODE) 1824 if(nvram_match("enable_sta_mode","1")){ 1825 system("wl roam_trigger -100"); 1826 system("wl -i eth2 roam_trigger -100"); 1827 /*Foxconn add start by Hank 06/27/2012*/ 1828 /*Fix can not see ssdp packet in bridge mode*/ 1829 system("ifconfig eth1 allmulti"); 1830 system("ifconfig eth2 allmulti"); 1831 /*Foxconn add end by Hank 06/27/2012*/ 1832#ifdef CONFIG_EXTENDER_MODE 1833 } else if(nvram_match("enable_extender_mode","1")){ 1834 system("wl roam_trigger -100"); 1835 system("wl -i eth2 roam_trigger -100"); 1836 /*Foxconn add start by Hank 06/27/2012*/ 1837 /*Fix can not see ssdp packet in bridge mode*/ 1838 system("ifconfig eth1 allmulti"); 1839 system("ifconfig eth2 allmulti"); 1840 /*Foxconn add end by Hank 06/27/2012*/ 1841#endif /* CONFIG_EXTENDER_MODE */ 1842 }else{ 1843 system("wl roam_trigger 0"); 1844 system("wl -i eth2 roam_trigger 0"); 1845 } 1846#endif 1847 /*Foxconn add end by Hank 03/07/2012*/ 1848 1849 /*redesign for set country code*/ 1850 region=atoi(nvram_get("wla_region")); 1851 system("wl -i eth1 txcore -k 7 -o 7 -s 1 -c 7 -s 2 -c 7"); 1852 system("wl -i eth2 txcore -o 7 -s 1 -c 7 -s 2 -c 7 -s 3 -c 7"); /* change to MIMO mode */ 1853 if(acosNvramConfig_match("ce_dfs_ch_enable","1") && ((region == 5) || (region == 4))) 1854 { 1855 system("wl -i eth2 radarthrs 0x690 0x30 0x690 0x30 0x688 0x30 0x690 0x30 0x690 0x30 0x690 0x30"); 1856 } 1857 else if(acosNvramConfig_match("fcc_dfs_ch_enable","1") && (region == 11)) 1858 { 1859 system("wl -i eth2 radarthrs 0x690 0x30 0x690 0x30 0x688 0x30 0x690 0x30 0x690 0x30 0x690 0x30"); 1860 } 1861 else if(acosNvramConfig_match("telec_dfs_ch_enable","1") && (region == 7)) 1862 { 1863 system("wl -i eth2 radarthrs 0x690 0x30 0x690 0x30 0x688 0x30 0x690 0x30 0x690 0x30 0x690 0x30"); 1864 } 1865 1866 if(acosNvramConfig_match("ce_dfs_ch_enable","1") && ((region==14) || (region==1) || (region==5) || (region==6) || (region==12) || (region==20) || (region==22) || (region==24))) 1867 { 1868 system("wl -i eth1 country_abbrev_override 0x4544"); 1869 system("wl -i eth2 country_abbrev_override 0x4544"); 1870 } 1871 1872 system("wl -i eth1 pspretend_threshold 4"); 1873 1874 system("wl -i eth1 mfp_enable 0"); 1875 system("wl -i eth2 mfp_enable 0"); 1876 1877 if (nvram_match("enable_atf", "1")) 1878 { 1879// system("wl -i eth2 shmem 0x80 2"); 1880 eval("wl", "-i", "eth2", "frameburst", "1"); 1881 } 1882 else 1883 { 1884 eval("wl", "-i", "eth2", "frameburst", "1"); 1885 } 1886 eval("wl", "assert_type", "1"); 1887 1888 /* Foxconn added start Antony 09/18/2015 Higher the ARP/ICMP/EAPOL priority */ 1889 system("wl -i eth1 boost_pri_proto 7"); 1890 system("wl -i eth2 boost_pri_proto 7"); 1891 1892 /* Foxconn added end Antony 09/18/2015 */ 1893 /* Foxconn added start by Antony 02/26/2014 The wifi driver could receive/transmit all multicast packets */ 1894 if(nvram_match("enable_sta_mode","1")) 1895 { 1896 system("wl -i eth1 allmulti 1"); 1897 system("wl -i eth2 allmulti 1"); 1898 } 1899#ifdef CONFIG_EXTENDER_MODE 1900 if(nvram_match("enable_extender_mode","1")) 1901 { 1902 system("wl -i eth1 allmulti 1"); 1903 system("wl -i eth2 allmulti 1"); 1904 } 1905#endif /* CONFIG_EXTENDER_MODE */ 1906 else 1907 { 1908 system("wl -i eth1 allmulti 0"); 1909 system("wl -i eth2 allmulti 0"); 1910 } 1911 /* Fxoconn added end by Antony 02/26/2014 */ 1912 1913 /*Foxconn add start by Antony start 09/13/2013 Add rf support of Russia Region */ 1914 if (nvram_match("wla_region", "14")) 1915 { 1916 system("wl -i eth2 txpwr1 -o -d 14"); 1917 } 1918 else 1919 { 1920 system("wl -i eth2 txpwr1 -1"); 1921 } 1922 /*Foxconn add start by Antony end 09/13/2013 */ 1923 1924} 1925 1926#ifdef __CONFIG_NAT__ 1927static int 1928wan_prefix(char *ifname, char *prefix) 1929{ 1930 int unit; 1931 1932 if ((unit = wan_ifunit(ifname)) < 0) 1933 return -1; 1934 1935 sprintf(prefix, "wan%d_", unit); 1936 return 0; 1937} 1938 1939static int 1940add_wan_routes(char *wan_ifname) 1941{ 1942 char prefix[] = "wanXXXXXXXXXX_"; 1943 1944 /* Figure out nvram variable name prefix for this i/f */ 1945 if (wan_prefix(wan_ifname, prefix) < 0) 1946 return -1; 1947 1948 return add_routes(prefix, "route", wan_ifname); 1949} 1950 1951static int 1952del_wan_routes(char *wan_ifname) 1953{ 1954 char prefix[] = "wanXXXXXXXXXX_"; 1955 1956 /* Figure out nvram variable name prefix for this i/f */ 1957 if (wan_prefix(wan_ifname, prefix) < 0) 1958 return -1; 1959 1960 return del_routes(prefix, "route", wan_ifname); 1961} 1962 1963static int 1964wan_valid(char *ifname) 1965{ 1966 char name[80], *next; 1967 1968 foreach(name, nvram_safe_get("wan_ifnames"), next) 1969 if (ifname && !strcmp(ifname, name)) 1970 return 1; 1971 return 0; 1972} 1973 1974void 1975start_wan(void) 1976{ 1977 char *wan_ifname; 1978 char *wan_proto; 1979 int unit; 1980 char tmp[100], prefix[] = "wanXXXXXXXXXX_"; 1981 char eabuf[32]; 1982 int s; 1983 struct ifreq ifr; 1984 pid_t pid; 1985 1986 /* check if we need to setup WAN */ 1987 if (nvram_match("router_disable", "1")) 1988 return; 1989 1990 1991 /* start connection independent firewall */ 1992 start_firewall(); 1993 1994 /* Create links */ 1995 mkdir("/tmp/ppp", 0777); 1996 symlink("/sbin/rc", "/tmp/ppp/ip-up"); 1997 symlink("/sbin/rc", "/tmp/ppp/ip-down"); 1998 1999 symlink("/sbin/rc", "/tmp/udhcpc"); 2000 2001 /* Start each configured and enabled wan connection and its undelying i/f */ 2002 for (unit = 0; unit < MAX_NVPARSE; unit ++) { 2003 snprintf(prefix, sizeof(prefix), "wan%d_", unit); 2004 2005 /* make sure the connection exists and is enabled */ 2006 wan_ifname = nvram_get(strcat_r(prefix, "ifname", tmp)); 2007 if (!wan_ifname) 2008 continue; 2009 wan_proto = nvram_get(strcat_r(prefix, "proto", tmp)); 2010 if (!wan_proto || !strcmp(wan_proto, "disabled")) 2011 continue; 2012 2013 /* disable the connection if the i/f is not in wan_ifnames */ 2014 if (!wan_valid(wan_ifname)) { 2015 nvram_set(strcat_r(prefix, "proto", tmp), "disabled"); 2016 continue; 2017 } 2018 2019 dprintf("%s %s\n", wan_ifname, wan_proto); 2020 2021 /* Set i/f hardware address before bringing it up */ 2022 if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) 2023 continue; 2024 strncpy(ifr.ifr_name, wan_ifname, IFNAMSIZ); 2025 2026 /* Configure i/f only once, specially for wl i/f shared by multiple connections */ 2027 if (ioctl(s, SIOCGIFFLAGS, &ifr)) { 2028 close(s); 2029 continue; 2030 } 2031 2032 if (!(ifr.ifr_flags & IFF_UP)) { 2033 /* Sync connection nvram address and i/f hardware address */ 2034 memset(ifr.ifr_hwaddr.sa_data, 0, ETHER_ADDR_LEN); 2035 if (!nvram_invmatch(strcat_r(prefix, "hwaddr", tmp), "") || 2036 !ether_atoe(nvram_safe_get(strcat_r(prefix, "hwaddr", tmp)), 2037 (unsigned char *)ifr.ifr_hwaddr.sa_data) || 2038 !memcmp(ifr.ifr_hwaddr.sa_data, "\0\0\0\0\0\0", ETHER_ADDR_LEN)) { 2039 if (ioctl(s, SIOCGIFHWADDR, &ifr)) { 2040 close(s); 2041 continue; 2042 } 2043 nvram_set(strcat_r(prefix, "hwaddr", tmp), 2044 ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); 2045 } else { 2046 ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; 2047 ioctl(s, SIOCSIFHWADDR, &ifr); 2048 } 2049 2050 /* Bring up i/f */ 2051 ifconfig(wan_ifname, IFUP, NULL, NULL); 2052 2053 /* do wireless specific config */ 2054 if (nvram_match("ure_disable", "1")) { 2055 eval("wlconf", wan_ifname, "up"); 2056 eval("wlconf", wan_ifname, "start"); 2057 } 2058 } 2059 2060 close(s); 2061 2062 /* Set initial QoS mode again now that WAN port is ready. */ 2063 set_et_qos_mode(); 2064 2065 /* 2066 * Configure PPPoE connection. The PPPoE client will run 2067 * ip-up/ip-down scripts upon link's connect/disconnect. 2068 */ 2069 if (strcmp(wan_proto, "pppoe") == 0) { 2070 char *pppoe_argv[] = { 2071 "pppoecd", 2072 nvram_safe_get(strcat_r(prefix, "ifname", tmp)), 2073 "-u", nvram_safe_get(strcat_r(prefix, "pppoe_username", tmp)), 2074 "-p", nvram_safe_get(strcat_r(prefix, "pppoe_passwd", tmp)), 2075 "-r", nvram_safe_get(strcat_r(prefix, "pppoe_mru", tmp)), 2076 "-t", nvram_safe_get(strcat_r(prefix, "pppoe_mtu", tmp)), 2077 "-i", nvram_match(strcat_r(prefix, "pppoe_demand", tmp), "1") ? 2078 nvram_safe_get(strcat_r(prefix, "pppoe_idletime", tmp)) : "0", 2079 NULL, NULL, /* pppoe_service */ 2080 NULL, NULL, /* pppoe_ac */ 2081 NULL, /* pppoe_keepalive */ 2082 NULL, NULL, /* ppp unit requested */ 2083 NULL 2084 }, **arg; 2085 int timeout = 5; 2086 char pppunit[] = "XXXXXXXXXXXX"; 2087 2088 /* Add optional arguments */ 2089 for (arg = pppoe_argv; *arg; arg++); 2090 if (nvram_invmatch(strcat_r(prefix, "pppoe_service", tmp), "")) { 2091 *arg++ = "-s"; 2092 *arg++ = nvram_safe_get(strcat_r(prefix, "pppoe_service", tmp)); 2093 } 2094 if (nvram_invmatch(strcat_r(prefix, "pppoe_ac", tmp), "")) { 2095 *arg++ = "-a"; 2096 *arg++ = nvram_safe_get(strcat_r(prefix, "pppoe_ac", tmp)); 2097 } 2098 if (nvram_match(strcat_r(prefix, "pppoe_demand", tmp), "1") || 2099 nvram_match(strcat_r(prefix, "pppoe_keepalive", tmp), "1")) 2100 *arg++ = "-k"; 2101 snprintf(pppunit, sizeof(pppunit), "%d", unit); 2102 *arg++ = "-U"; 2103 *arg++ = pppunit; 2104 2105 /* launch pppoe client daemon */ 2106 _eval(pppoe_argv, NULL, 0, &pid); 2107 2108 /* ppp interface name is referenced from this point on */ 2109 wan_ifname = nvram_safe_get(strcat_r(prefix, "pppoe_ifname", tmp)); 2110 2111 /* Pretend that the WAN interface is up */ 2112 if (nvram_match(strcat_r(prefix, "pppoe_demand", tmp), "1")) { 2113 /* Wait for pppx to be created */ 2114 while (ifconfig(wan_ifname, IFUP, NULL, NULL) && timeout--) 2115 sleep(1); 2116 2117 /* Retrieve IP info */ 2118 if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) 2119 continue; 2120 strncpy(ifr.ifr_name, wan_ifname, IFNAMSIZ); 2121 2122 /* Set temporary IP address */ 2123 if (ioctl(s, SIOCGIFADDR, &ifr)) 2124 perror(wan_ifname); 2125 nvram_set(strcat_r(prefix, "ipaddr", tmp), inet_ntoa(sin_addr(&ifr.ifr_addr))); 2126 nvram_set(strcat_r(prefix, "netmask", tmp), "255.255.255.255"); 2127 2128 /* Set temporary P-t-P address */ 2129 if (ioctl(s, SIOCGIFDSTADDR, &ifr)) 2130 perror(wan_ifname); 2131 nvram_set(strcat_r(prefix, "gateway", tmp), inet_ntoa(sin_addr(&ifr.ifr_dstaddr))); 2132 2133 close(s); 2134 2135 /* 2136 * Preset routes so that traffic can be sent to proper pppx 2137 * even before the link is brought up. 2138 */ 2139 preset_wan_routes(wan_ifname); 2140 } 2141 } 2142 /* 2143 * Configure DHCP connection. The DHCP client will run 2144 * 'udhcpc bound'/'udhcpc deconfig' upon finishing IP address 2145 * renew and release. 2146 */ 2147 else if (strcmp(wan_proto, "dhcp") == 0) { 2148 char *wan_hostname = nvram_safe_get(strcat_r(prefix, "hostname", tmp)); 2149 char *dhcp_argv[] = { "udhcpc", 2150 "-i", wan_ifname, 2151 "-p", (sprintf(tmp, "/var/run/udhcpc%d.pid", unit), tmp), 2152 "-s", "/tmp/udhcpc", 2153 wan_hostname && *wan_hostname ? "-H" : NULL, 2154 wan_hostname && *wan_hostname ? wan_hostname : NULL, 2155 NULL 2156 }; 2157 /* Start dhcp client */ 2158 _eval(dhcp_argv, NULL, 0, &pid); 2159 } 2160 /* Configure static IP connection. */ 2161 else if (strcmp(wan_proto, "static") == 0) { 2162 /* Assign static IP address to i/f */ 2163 ifconfig(wan_ifname, IFUP, 2164 nvram_safe_get(strcat_r(prefix, "ipaddr", tmp)), 2165 nvram_safe_get(strcat_r(prefix, "netmask", tmp))); 2166 /* We are done configuration */ 2167 wan_up(wan_ifname); 2168 } 2169 2170 /* Start connection dependent firewall */ 2171 start_firewall2(wan_ifname); 2172 2173 dprintf("%s %s\n", 2174 nvram_safe_get(strcat_r(prefix, "ipaddr", tmp)), 2175 nvram_safe_get(strcat_r(prefix, "netmask", tmp))); 2176 } 2177 2178 /* Report stats */ 2179 if (nvram_invmatch("stats_server", "")) { 2180 char *stats_argv[] = { "stats", nvram_get("stats_server"), NULL }; 2181 _eval(stats_argv, NULL, 5, NULL); 2182 } 2183} 2184 2185void 2186stop_wan(void) 2187{ 2188 char name[80], *next, signal[] = "XXXX"; 2189 2190#ifdef BCMQOS 2191 del_iQosRules(); 2192#endif /* BCMQOS */ 2193 eval("killall", "stats"); 2194 eval("killall", "ntpclient"); 2195 2196 /* Shutdown and kill all possible tasks */ 2197 eval("killall", "ip-up"); 2198 eval("killall", "ip-down"); 2199 snprintf(signal, sizeof(signal), "-%d", SIGHUP); 2200 eval("killall", signal, "pppoecd"); 2201 eval("killall", "pppoecd"); 2202 snprintf(signal, sizeof(signal), "-%d", SIGUSR2); 2203 eval("killall", signal, "udhcpc"); 2204 eval("killall", "udhcpc"); 2205 2206 /* Bring down WAN interfaces */ 2207 foreach(name, nvram_safe_get("wan_ifnames"), next) 2208 ifconfig(name, 0, "0.0.0.0", NULL); 2209 2210 /* Remove dynamically created links */ 2211 unlink("/tmp/udhcpc"); 2212 2213 unlink("/tmp/ppp/ip-up"); 2214 unlink("/tmp/ppp/ip-down"); 2215 rmdir("/tmp/ppp"); 2216 2217 dprintf("done\n"); 2218} 2219 2220static int 2221add_ns(char *wan_ifname) 2222{ 2223 FILE *fp; 2224 char tmp[100], prefix[] = "wanXXXXXXXXXX_"; 2225 char word[100], *next; 2226 char line[100]; 2227 2228 /* Figure out nvram variable name prefix for this i/f */ 2229 if (wan_prefix(wan_ifname, prefix) < 0) 2230 return -1; 2231 2232 /* Open resolv.conf to read */ 2233 if (!(fp = fopen("/tmp/resolv.conf", "r+"))) { 2234 perror("/tmp/resolv.conf"); 2235 return errno; 2236 } 2237 /* Append only those not in the original list */ 2238 foreach(word, nvram_safe_get(strcat_r(prefix, "dns", tmp)), next) { 2239 fseek(fp, 0, SEEK_SET); 2240 while (fgets(line, sizeof(line), fp)) { 2241 char *token = strtok(line, " \t\n"); 2242 2243 if (!token || strcmp(token, "nameserver") != 0) 2244 continue; 2245 if (!(token = strtok(NULL, " \t\n"))) 2246 continue; 2247 2248 if (!strcmp(token, word)) 2249 break; 2250 } 2251 if (feof(fp)) 2252 fprintf(fp, "nameserver %s\n", word); 2253 } 2254 fclose(fp); 2255 2256 /* notify dnsmasq */ 2257 snprintf(tmp, sizeof(tmp), "-%d", SIGHUP); 2258 eval("killall", tmp, "dnsmasq"); 2259 2260 return 0; 2261} 2262 2263static int 2264del_ns(char *wan_ifname) 2265{ 2266 FILE *fp, *fp2; 2267 char tmp[100], prefix[] = "wanXXXXXXXXXX_"; 2268 char word[100], *next; 2269 char line[100]; 2270 2271 /* Figure out nvram variable name prefix for this i/f */ 2272 if (wan_prefix(wan_ifname, prefix) < 0) 2273 return -1; 2274 2275 /* Open resolv.conf to read */ 2276 if (!(fp = fopen("/tmp/resolv.conf", "r"))) { 2277 perror("fopen /tmp/resolv.conf"); 2278 return errno; 2279 } 2280 /* Open resolv.tmp to save updated name server list */ 2281 if (!(fp2 = fopen("/tmp/resolv.tmp", "w"))) { 2282 perror("fopen /tmp/resolv.tmp"); 2283 fclose(fp); 2284 return errno; 2285 } 2286 /* Copy updated name servers */ 2287 while (fgets(line, sizeof(line), fp)) { 2288 char *token = strtok(line, " \t\n"); 2289 2290 if (!token || strcmp(token, "nameserver") != 0) 2291 continue; 2292 if (!(token = strtok(NULL, " \t\n"))) 2293 continue; 2294 2295 foreach(word, nvram_safe_get(strcat_r(prefix, "dns", tmp)), next) 2296 if (!strcmp(word, token)) 2297 break; 2298 if (!next) 2299 fprintf(fp2, "nameserver %s\n", token); 2300 } 2301 fclose(fp); 2302 fclose(fp2); 2303 /* Use updated file as resolv.conf */ 2304 unlink("/tmp/resolv.conf"); 2305 rename("/tmp/resolv.tmp", "/tmp/resolv.conf"); 2306 2307 /* notify dnsmasq */ 2308 snprintf(tmp, sizeof(tmp), "-%d", SIGHUP); 2309 eval("killall", tmp, "dnsmasq"); 2310 2311 return 0; 2312} 2313 2314/* 2315*/ 2316#ifdef __CONFIG_IPV6__ 2317/* Start the 6to4 Tunneling interface. 2318* Return > 0: number of interfaces processed by this routine. 2319* ==0: skipped since no action is required. 2320* < 0: Error number 2321*/ 2322static int 2323start_6to4(char *wan_ifname) 2324{ 2325 int i, ret = 0; 2326 int siMode, siCount; 2327 unsigned short uw6to4ID; 2328 in_addr_t uiWANIP; 2329 char *pcLANIF, *pcWANIP, tmp[64], prefix[] = "wanXXXXXXXXXX_"; 2330 2331 /* Figure out nvram variable name prefix for this i/f */ 2332 if (wan_prefix(wan_ifname, prefix) < 0) 2333 return 0; 2334 2335 pcWANIP = nvram_safe_get(strcat_r(prefix, "ipaddr", tmp)); 2336 uiWANIP = inet_network(pcWANIP); 2337 2338 /* Check if the wan IP is private(RFC1918). 6to4 needs a global IP */ 2339 if ((uiWANIP == 0) || (uiWANIP == -1) || 2340 (uiWANIP & 0xffff0000) == 0xc0a80000 || /* 192.168.x.x */ 2341 (uiWANIP & 0xfff00000) == 0xac100000 || /* 172.16.x.x */ 2342 (uiWANIP & 0xff000000) == 0x0a000000) /* 10.x.x.x */ 2343 return 0; 2344 2345 /* Create 6to4 intrface and setup routing table */ 2346 for (i = 0, siCount = 0; i < MAX_NO_BRIDGE; i++) { 2347 if (i == 0) { 2348 pcLANIF = nvram_safe_get("lan_ifname"); 2349 siMode = atoi(nvram_safe_get("lan_ipv6_mode")); 2350 uw6to4ID = (unsigned short)atoi(nvram_safe_get("lan_ipv6_6to4id")); 2351 } 2352 else { 2353 snprintf(tmp, sizeof(tmp), "lan%x_ifname", i); 2354 pcLANIF = nvram_safe_get(tmp); 2355 snprintf(tmp, sizeof(tmp), "lan%x_ipv6_mode", i); 2356 siMode = atoi(nvram_safe_get(tmp)); 2357 snprintf(tmp, sizeof(tmp), "lan%x_ipv6_6to4id", i); 2358 uw6to4ID = (unsigned short)atoi(nvram_safe_get(tmp)); 2359 } 2360 2361 if (siMode & IPV6_6TO4_ENABLED) { 2362 /* Add the 6to4 route. */ 2363 snprintf(tmp, sizeof(tmp), "2002:%x:%x:%x::/64", 2364 (unsigned short)(uiWANIP>>16), (unsigned short)uiWANIP, uw6to4ID); 2365 ret = eval("ip", "-6", "route", "add", tmp, 2366 "dev", pcLANIF, "metric", "1"); 2367 siCount++; 2368 } 2369 } 2370 2371 if (siCount == 0) 2372 return 0; 2373 2374 /* Create 6to4 intrface and setup routing table */ 2375 { 2376 char *pc6to4IF = "v6to4"; /* The 6to4 tunneling interface name */ 2377 struct in_addr stWANIP; 2378 2379 stWANIP.s_addr = htonl(uiWANIP); 2380 2381 /* Create the tunneling interface */ 2382 ret = eval("ip", "tunnel", "add", pc6to4IF, "mode", "sit", 2383 "ttl", "64", "remote", "any", "local", inet_ntoa(stWANIP)); 2384 2385 /* Bring the device up */ 2386 ret = eval("ip", "link", "set", "dev", pc6to4IF, "up"); 2387 2388 /* Add 6to4 v4 anycast route to the global IPv6 network */ 2389 ret = eval("ip", "-6", "route", "add", "2000::/3", 2390 "via", "::192.88.99.1", "dev", pc6to4IF, "metric", "1"); 2391 } 2392 2393#ifdef __CONFIG_RADVD__ 2394 /* Restart radvd */ 2395 { 2396 char acSignal[64]; 2397 2398 snprintf(acSignal, sizeof(acSignal), "-%d", SIGHUP); 2399 ret = eval("killall", acSignal, "radvd"); 2400 } 2401#endif /* __CONFIG_RADVD__ */ 2402 2403#ifdef __CONFIG_NAT__ 2404 /* Enable IPv6 protocol=41(0x29) on v4NAT */ 2405 { 2406 char *pcWANIF; 2407 2408 pcWANIF = nvram_match("wan_proto", "pppoe")? 2409 nvram_safe_get("wan_pppoe_ifname"): nvram_safe_get("wan_ifname"); 2410 add_ipv6_filter(nvram_safe_get(pcWANIF)); 2411 } 2412#endif /* __CONFIG_NAT__ */ 2413 2414 return siCount; 2415} 2416#endif /* __CONFIG_IPV6__ */ 2417/* 2418*/ 2419 2420void 2421wan_up(char *wan_ifname) 2422{ 2423 char tmp[100], prefix[] = "wanXXXXXXXXXX_"; 2424 char *wan_proto; 2425 2426 /* Figure out nvram variable name prefix for this i/f */ 2427 if (wan_prefix(wan_ifname, prefix) < 0) 2428 return; 2429 2430 wan_proto = nvram_safe_get(strcat_r(prefix, "proto", tmp)); 2431 2432 dprintf("%s %s\n", wan_ifname, wan_proto); 2433 2434 /* Set default route to gateway if specified */ 2435 if (nvram_match(strcat_r(prefix, "primary", tmp), "1")) 2436 route_add(wan_ifname, 0, "0.0.0.0", 2437 nvram_safe_get(strcat_r(prefix, "gateway", tmp)), 2438 "0.0.0.0"); 2439 2440 /* Install interface dependent static routes */ 2441 add_wan_routes(wan_ifname); 2442 2443 /* Add dns servers to resolv.conf */ 2444 add_ns(wan_ifname); 2445 2446 /* Sync time */ 2447 start_ntpc(); 2448 2449#ifdef BCMQOS 2450 add_iQosRules(wan_ifname); 2451 start_iQos(); 2452#endif /* BCMQOS */ 2453/* 2454*/ 2455#ifdef __CONFIG_IPV6__ 2456 start_6to4(wan_ifname); 2457#endif /* __CONFIG_IPV6__ */ 2458/* 2459*/ 2460 2461 dprintf("done\n"); 2462} 2463 2464void 2465wan_down(char *wan_ifname) 2466{ 2467 char tmp[100], prefix[] = "wanXXXXXXXXXX_"; 2468 char *wan_proto; 2469 2470 /* Figure out nvram variable name prefix for this i/f */ 2471 if (wan_prefix(wan_ifname, prefix) < 0) 2472 return; 2473 2474 wan_proto = nvram_safe_get(strcat_r(prefix, "proto", tmp)); 2475 2476 printf("%s %s\n", wan_ifname, wan_proto); 2477 2478 /* Remove default route to gateway if specified */ 2479 if (nvram_match(strcat_r(prefix, "primary", tmp), "1")) 2480 route_del(wan_ifname, 0, "0.0.0.0", 2481 nvram_safe_get(strcat_r(prefix, "gateway", tmp)), 2482 "0.0.0.0"); 2483 2484 /* Remove interface dependent static routes */ 2485 del_wan_routes(wan_ifname); 2486 2487 /* Update resolv.conf */ 2488 del_ns(wan_ifname); 2489 2490 dprintf("done\n"); 2491} 2492#endif /* __CONFIG_NAT__ */ 2493 2494/* Enable WET DHCP relay for ethernet clients */ 2495static int 2496enable_dhcprelay(char *ifname) 2497{ 2498 char name[80], *next; 2499 2500 dprintf("%s\n", ifname); 2501 2502 /* WET interface is meaningful only in bridged environment */ 2503 if (strncmp(ifname, "br", 2) == 0) { 2504 foreach(name, nvram_safe_get("lan_ifnames"), next) { 2505 char mode[] = "wlXXXXXXXXXX_mode"; 2506 int unit; 2507 2508 /* make sure the interface is indeed of wl */ 2509 if (wl_probe(name)) 2510 continue; 2511 2512 /* get the instance number of the wl i/f */ 2513 wl_ioctl(name, WLC_GET_INSTANCE, &unit, sizeof(unit)); 2514 snprintf(mode, sizeof(mode), "wl%d_mode", unit); 2515 2516 /* enable DHCP relay, there should be only one WET i/f */ 2517 if (nvram_match(mode, "wet")) { 2518 uint32 ip; 2519 inet_aton(nvram_safe_get("lan_ipaddr"), (struct in_addr *)&ip); 2520 if (wl_iovar_setint(name, "wet_host_ipv4", ip)) 2521 perror("wet_host_ipv4"); 2522 break; 2523 } 2524 } 2525 } 2526 return 0; 2527} 2528 2529void 2530lan_up(char *lan_ifname) 2531{ 2532 /* Install default route to gateway - AP only */ 2533 if (nvram_match("router_disable", "1") && nvram_invmatch("lan_gateway", "")) 2534 route_add(lan_ifname, 0, "0.0.0.0", nvram_safe_get("lan_gateway"), "0.0.0.0"); 2535 2536 /* Install interface dependent static routes */ 2537 add_lan_routes(lan_ifname); 2538 2539 /* Sync time - AP only */ 2540 if (nvram_match("router_disable", "1")) 2541 start_ntpc(); 2542 2543 /* Enable WET DHCP relay if requested */ 2544 if (atoi(nvram_safe_get("dhcp_relay")) == 1) 2545 enable_dhcprelay(lan_ifname); 2546 2547 dprintf("done\n"); 2548} 2549 2550void 2551lan_down(char *lan_ifname) 2552{ 2553 /* Remove default route to gateway - AP only */ 2554 if (nvram_match("router_disable", "1") && nvram_invmatch("lan_gateway", "")) 2555 route_del(lan_ifname, 0, "0.0.0.0", nvram_safe_get("lan_gateway"), "0.0.0.0"); 2556 2557 /* Remove interface dependent static routes */ 2558 del_lan_routes(lan_ifname); 2559 2560 dprintf("done\n"); 2561} 2562 2563int 2564hotplug_net(void) 2565{ 2566 char *lan_ifname = nvram_safe_get("lan_ifname"); 2567 char *interface, *action; 2568 bool psta_if, dyn_if, add_event, remove_event; 2569 2570 dprintf("hotplug_net(): start\n"); 2571 2572 if (!(interface = getenv("INTERFACE")) || 2573 !(action = getenv("ACTION"))) 2574 return EINVAL; 2575 2576 dprintf("hotplug_net(): interface %s action %s\n", interface, action); 2577 2578#ifdef LINUX26 2579 add_event = !strcmp(action, "add"); 2580#else 2581 add_event = !strcmp(action, "register"); 2582#endif 2583 2584#ifdef LINUX26 2585 remove_event = !strcmp(action, "remove"); 2586#else 2587 remove_event = !strcmp(action, "unregister"); 2588#endif 2589 2590 psta_if = wl_wlif_is_psta(interface); 2591 dyn_if = !strncmp(interface, "wds", 3) || psta_if; 2592 2593 if (!dyn_if && !remove_event) 2594 return 0; 2595 2596 if (add_event) { 2597 /* Bring up the interface and add to the bridge */ 2598 ifconfig(interface, IFUP, NULL, NULL); 2599 2600#ifdef __CONFIG_EMF__ 2601 if (nvram_match("emf_enable", "1")) { 2602 eval("emf", "add", "iface", lan_ifname, interface); 2603 emf_mfdb_update(lan_ifname, interface, TRUE); 2604 emf_uffp_update(lan_ifname, interface, TRUE); 2605 emf_rtport_update(lan_ifname, interface, TRUE); 2606 } 2607#endif /* __CONFIG_EMF__ */ 2608 2609 /* Indicate interface create event to eapd */ 2610 if (psta_if) { 2611 dprintf("hotplug_net(): send dif event to %s\n", interface); 2612 wl_send_dif_event(interface, 0); 2613 return 0; 2614 } 2615 2616 /* Bridge WDS interfaces */ 2617 if (!strncmp(lan_ifname, "br", 2) && 2618 eval("brctl", "addif", lan_ifname, interface, "wait")) { 2619 dprintf("hotplug_net():Adding interface %s\n", interface); 2620 return 0; 2621 } 2622 2623 /* Inform driver to send up new WDS link event */ 2624 if (wl_iovar_setint(interface, "wds_enable", 1)) { 2625 dprintf("%s set wds_enable failed\n", interface); 2626 return 0; 2627 } 2628 2629 return 0; 2630 } 2631 2632 if (remove_event) { 2633 /* Indicate interface delete event to eapd */ 2634 wl_send_dif_event(interface, 1); 2635 2636#ifdef __CONFIG_EMF__ 2637 if (nvram_match("emf_enable", "1")) 2638 eval("emf", "del", "iface", lan_ifname, interface); 2639#endif /* __CONFIG_EMF__ */ 2640 } 2641 2642 return 0; 2643} 2644 2645#ifdef __CONFIG_NAT__ 2646int 2647wan_ifunit(char *wan_ifname) 2648{ 2649 int unit; 2650 char tmp[100], prefix[] = "wanXXXXXXXXXX_"; 2651 2652 if ((unit = ppp_ifunit(wan_ifname)) >= 0) 2653 return unit; 2654 else { 2655 for (unit = 0; unit < MAX_NVPARSE; unit ++) { 2656 snprintf(prefix, sizeof(prefix), "wan%d_", unit); 2657 if (nvram_match(strcat_r(prefix, "ifname", tmp), wan_ifname) && 2658 (nvram_match(strcat_r(prefix, "proto", tmp), "dhcp") || 2659 nvram_match(strcat_r(prefix, "proto", tmp), "static"))) 2660 return unit; 2661 } 2662 } 2663 return -1; 2664} 2665 2666int 2667preset_wan_routes(char *wan_ifname) 2668{ 2669 char tmp[100], prefix[] = "wanXXXXXXXXXX_"; 2670 2671 /* Figure out nvram variable name prefix for this i/f */ 2672 if (wan_prefix(wan_ifname, prefix) < 0) 2673 return -1; 2674 2675 /* Set default route to gateway if specified */ 2676 if (nvram_match(strcat_r(prefix, "primary", tmp), "1")) 2677 route_add(wan_ifname, 0, "0.0.0.0", "0.0.0.0", "0.0.0.0"); 2678 2679 /* Install interface dependent static routes */ 2680 add_wan_routes(wan_ifname); 2681 return 0; 2682} 2683 2684int 2685wan_primary_ifunit(void) 2686{ 2687 int unit; 2688 2689 for (unit = 0; unit < MAX_NVPARSE; unit ++) { 2690 char tmp[100], prefix[] = "wanXXXXXXXXXX_"; 2691 snprintf(prefix, sizeof(prefix), "wan%d_", unit); 2692 if (nvram_match(strcat_r(prefix, "primary", tmp), "1")) 2693 return unit; 2694 } 2695 2696 return 0; 2697} 2698#endif /* __CONFIG_NAT__ */ 2699/* foxconn added start, wklin, 10/17/2006 */ 2700void stop_wlan(void) 2701{ 2702 /* Foxconn modified start pling 11/26/2009 */ 2703 /* Should store the nvram value in a local variable, instead 2704 * of keeping just the pointer, since other processes 2705 * might modify NVRAM at any time. 2706 */ 2707 2708 char lan_ifname[32]; 2709 char wlif[32]; 2710 strcpy(lan_ifname, nvram_safe_get("lan_ifname")); 2711 strcpy(wlif, nvram_safe_get("wl0_ifname")); 2712 /* Foxconn modified end pling 11/26/2009 */ 2713 2714 eval("wlconf", wlif, "down"); 2715 ifconfig(wlif, 0, NULL, NULL); 2716 eval("brctl", "delif", lan_ifname, wlif); 2717 2718 /* Bring down 2nd WLAN i/f */ 2719 /* Foxconn modified start pling 12/02/2009 */ 2720 //wlif = nvram_safe_get("wl1_ifname"); 2721 strcpy(wlif, nvram_safe_get("wl1_ifname")); 2722 /* Foxconn modified end pling 12/02/2009 */ 2723 eval("wlconf", wlif, "down"); 2724 ifconfig(wlif, 0, NULL, NULL); 2725 eval("brctl", "delif", lan_ifname, wlif); 2726 2727 /* Foxconn added start pling 06/06/2007 */ 2728//#ifdef BUILD_TWC 2729/* Foxconn add start by aspen Bai, 11/13/2008 */ 2730#ifdef MULTIPLE_SSID 2731/* Foxconn add end by aspen Bai, 11/13/2008 */ 2732 if (1) /* Remove all BSSIDs from LAN */ 2733 { 2734 int bssid_num; 2735 for (bssid_num=1; bssid_num<=3; bssid_num++) 2736 { 2737 char if_name[16]; 2738 sprintf(if_name, "wl0.%d", bssid_num); 2739 ifconfig(if_name, 0, NULL, NULL); 2740 eval("brctl", "delif", lan_ifname, if_name); 2741 } 2742 for (bssid_num=1; bssid_num<=3; bssid_num++) 2743 { 2744 char if_name_5g[16]; 2745 sprintf(if_name_5g, "wl1.%d", bssid_num); 2746 ifconfig(if_name_5g, 0, NULL, NULL); 2747 eval("brctl", "delif", lan_ifname, if_name_5g); 2748 } 2749 } 2750#endif 2751 /* Foxconn added end pling 06/06/2007 */ 2752 2753 return; 2754} 2755 2756#ifdef VLAN_SUPPORT 2757void add_if_to_vlan_group(char *guest_if) 2758{ 2759 int br_num; 2760 char lanxx_ifnames[64]; 2761 char *lan_ifnames; 2762 2763 for(br_num=1; br_num < MAX_NO_BRIDGE; br_num++) 2764 { 2765 sprintf(lanxx_ifnames,"lan%d_ifnames",br_num); 2766 lan_ifnames=nvram_safe_get(lanxx_ifnames); 2767 if(strlen(lan_ifnames)) 2768 if(strstr(lan_ifnames,guest_if)) 2769 { 2770 char bridge[32]; 2771 sprintf(bridge,"br%d",br_num); 2772 eval("brctl", "delif", acosNvramConfig_get("lan_ifname"), guest_if); 2773 eval("brctl", "addif", bridge, guest_if); 2774 } 2775 2776 } 2777 2778 if(br_num==MAX_NO_BRIDGE) 2779 { 2780 eval("brctl", "delif", acosNvramConfig_get("lan_ifname"), guest_if); 2781 eval("brctl", "addif", "br0", guest_if); 2782 } 2783} 2784#endif 2785 2786void start_wlan(void) 2787{ 2788 /* Foxconn modified start pling 11/26/2009 */ 2789 /* Should store the nvram value in a local variable, instead 2790 * of keeping just the pointer, since other processes 2791 * might modify NVRAM at any time. 2792 */ 2793 char lan_ifname[32],wan_ifname[32]; 2794 char wlif[32]; 2795 strcpy(lan_ifname, nvram_safe_get("lan_ifname")); 2796 strcpy(wan_ifname, nvram_safe_get("wan_ifname")); 2797 strcpy(wlif, nvram_safe_get("wl0_ifname")); 2798 /* Foxconn modified end pling 11/26/2009 */ 2799 char wl1_ifname[32]; 2800 2801 strcpy(wl1_ifname, nvram_safe_get("wl1_ifname")); 2802 2803 /* Foxconn added start, Wins, 05/07/11, @RU_IPTV */ 2804#ifdef CONFIG_RUSSIA_IPTV 2805 char iptv_intf[32]; 2806#if defined(R8000) 2807 unsigned int iptv_intf_val = 0x00; 2808#else 2809 unsigned char iptv_intf_val = 0x00; 2810#endif 2811 int ru_iptv_en = 0; 2812 int wlan1_en = 0; 2813 int wlan2_en = 0; 2814 2815 if (nvram_match(NVRAM_IPTV_ENABLED, "1") || nvram_match("enable_vlan", "enable")) 2816 { 2817 strcpy(iptv_intf, nvram_get(NVRAM_IPTV_INTF)); 2818#if defined(R8000) 2819 sscanf(iptv_intf, "0x%04X", &iptv_intf_val); 2820#else 2821 sscanf(iptv_intf, "0x%02X", &iptv_intf_val); 2822#endif 2823 if (iptv_intf_val & IPTV_WLAN1) 2824 wlan1_en = 1; 2825 /* Foxconn modified start pling 04/20/2012 */ 2826 /* WLAN1 and WLAN2 can both bridge to WAN */ 2827 //else if (iptv_intf_val & IPTV_WLAN2) 2828 if (iptv_intf_val & IPTV_WLAN2) 2829 /* Foxconn modified end pling 04/20/2012 */ 2830 wlan2_en = 1; 2831 ru_iptv_en = 1; 2832 } 2833#endif /* CONFIG_RUSSIA_IPTV */ 2834 /* Foxconn added end, Wins, 05/07/11, @RU_IPTV */ 2835 eval("wlconf", wlif, "up"); 2836 ifconfig(wlif, IFUP, NULL, NULL); 2837 /* Foxconn modified start, Wins, 05/07/11, @RU_IPTV */ 2838#ifdef CONFIG_RUSSIA_IPTV 2839 if(!nvram_match("enable_vlan", "enable")) 2840 { 2841 if (wlan1_en) 2842 { 2843 eval("brctl", "delif", lan_ifname, wlif); /* pling added 04/03/2012 */ 2844 eval("brctl", "addif", "br1", wlif); 2845 } 2846 else 2847 { 2848 /* Foxconn Perry added start, 11/17/2014, for extender mode */ 2849#ifdef CONFIG_EXTENDER_MODE 2850 if(acosNvramConfig_match("enable_extender_mode", "1")) 2851 { 2852 ; /* not to add eth1 to bridge if extender mode is enabled. */ 2853 } else 2854#endif /* CONFIG_EXTENDER_MODE */ 2855 /* Foxconn Perry added end, 11/17/2014, for extender mode */ 2856 eval("brctl", "addif", "br0", wlif); /* pling added 04/03/2012 */ 2857 } 2858 } 2859 /* Foxconn Perry added start, 11/17/2014, for extender mode */ 2860#ifdef CONFIG_EXTENDER_MODE 2861 else if(acosNvramConfig_match("enable_extender_mode", "1")) 2862 { 2863 ; /* not to set vlan group if extender mode is enabled. */ 2864 } 2865#endif /* CONFIG_EXTENDER_MODE */ 2866 /* Foxconn Perry added end, 11/17/2014, for extender mode */ 2867#ifdef VLAN_SUPPORT 2868 else 2869 add_if_to_vlan_group(wlif); 2870#endif 2871 2872#else /* CONFIG_RUSSIA_IPTV */ 2873 /* Foxconn Perry added start, 11/17/2014, for extender mode */ 2874#ifdef CONFIG_EXTENDER_MODE 2875 if(acosNvramConfig_match("enable_extender_mode", "1")) 2876 { 2877 ; /* not to set vlan group if extender mode is enabled. */ 2878 } else 2879#endif /* CONFIG_EXTENDER_MODE */ 2880 /* Foxconn Perry added end, 11/17/2014, for extender mode */ 2881 eval("brctl", "addif", lan_ifname, wlif); 2882#endif /* CONFIG_RUSSIA_IPTV */ 2883 /* Foxconn modified end, Wins, 05/07/11, @RU_IPTV */ 2884 2885 2886 eval("wlconf", wl1_ifname, "up"); 2887 ifconfig(wl1_ifname, IFUP, NULL, NULL); 2888 /* Foxconn modified start, Wins, 05/07/11, @RU_IPTV */ 2889#ifdef CONFIG_RUSSIA_IPTV 2890 if(!nvram_match("enable_vlan", "enable")) 2891 { 2892 if (wlan2_en) 2893 { 2894 eval("brctl", "delif", lan_ifname, wl1_ifname);/* pling added 04/03/2012 */ 2895 eval("brctl", "addif", "br1", wl1_ifname); 2896 } 2897 else 2898 { 2899 /* Foxconn Perry added start, 11/17/2014, for extender mode */ 2900#ifdef CONFIG_EXTENDER_MODE 2901 if(acosNvramConfig_match("enable_extender_mode", "1")) 2902 { 2903 ; /* not to add eth1 to bridge if extender mode is enabled. */ 2904 } else 2905#endif /* CONFIG_EXTENDER_MODE */ 2906 /* Foxconn Perry added end, 11/17/2014, for extender mode */ 2907 eval("brctl", "addif", "br0", wl1_ifname); /* pling added 04/03/2012 */ 2908 } 2909 } 2910 /* Foxconn Perry added start, 11/17/2014, for extender mode */ 2911#ifdef CONFIG_EXTENDER_MODE 2912 else if(acosNvramConfig_match("enable_extender_mode", "1")) 2913 { 2914 ; /* not to set vlan group if extender mode is enabled. */ 2915 } 2916#endif /* CONFIG_EXTENDER_MODE */ 2917 /* Foxconn Perry added end, 11/17/2014, for extender mode */ 2918#ifdef VLAN_SUPPORT 2919 else 2920 add_if_to_vlan_group(wl1_ifname); 2921#endif 2922#else /* CONFIG_RUSSIA_IPTV */ 2923 /* Foxconn Perry added start, 11/17/2014, for extender mode */ 2924#ifdef CONFIG_EXTENDER_MODE 2925 if(acosNvramConfig_match("enable_extender_mode", "1")) 2926 { 2927 ; /* not to set vlan group if extender mode is enabled. */ 2928 } else 2929#endif /* CONFIG_EXTENDER_MODE */ 2930 /* Foxconn Perry added end, 11/17/2014, for extender mode */ 2931 eval("brctl", "addif", lan_ifname, wl1_ifname); 2932#endif /* CONFIG_RUSSIA_IPTV */ 2933 /* Foxconn modified end, Wins, 05/07/11, @RU_IPTV */ 2934 2935 /* Foxocnn added start pling 03/30/2010 */ 2936 /* For WiFi test case 4.2.41 */ 2937 //if(nvram_match("wifi_test", "1")) 2938 /*Foxconn add start by Hank 08/14/2012*/ 2939 /*change obss_coex by user selection*/ 2940 if(nvram_match("wl0_obss_coex","0")) 2941 eval("wl", "-i", wlif, "obss_coex", "0"); 2942 else 2943 eval("wl", "-i", wlif, "obss_coex", "1"); 2944 /*Foxconn add start by Hank 08/14/2012* 2945 /* Foxocnn added end pling 03/30/2010 */ 2946 2947 /* Foxconn added start pling 06/06/2007 */ 2948//#ifdef BUILD_TWC 2949/* Foxconn add start by aspen Bai, 11/13/2008 */ 2950#ifdef MULTIPLE_SSID 2951/* Foxconn add end by aspen Bai, 11/13/2008 */ 2952 if (1) /* Add the additional BSSIDs to LAN */ 2953 { 2954 int bssid_num; 2955 for (bssid_num=1; bssid_num<=3; bssid_num++) 2956 { 2957 //char param_name[16]; 2958 char param_name[20];/*foxconn modified water, @multi-ssid not workable..*/ 2959 char if_name[16]; 2960 sprintf(param_name, "wl0.%d_bss_enabled", bssid_num); 2961 sprintf(if_name, "wl0.%d", bssid_num); 2962 if (nvram_match(param_name, "1")) 2963 { 2964 wl_vif_hwaddr_set(if_name); 2965 ifconfig(if_name, IFUP, NULL, NULL); 2966#ifdef VLAN_SUPPORT 2967 /* Added by Foxconn Antony start 2015/06/21 for a bssid create for extender to scan newarby ap*/ 2968 if(bssid_num==2) 2969 continue; 2970 /* Added by Foxconn Antony end 2015/06/21 */ 2971 if(nvram_match("enable_vlan", "enable")) 2972 add_if_to_vlan_group(if_name); 2973 else if(nvram_match(NVRAM_IPTV_ENABLED, "1") && (bssid_num==1)) 2974 { 2975 if (iptv_intf_val & IPTV_WLAN_GUEST1) 2976 eval("brctl", "addif", wan_ifname, if_name); 2977 else 2978 eval("brctl", "addif", lan_ifname, if_name); 2979 2980 } 2981 else 2982 eval("brctl", "addif", lan_ifname, if_name); 2983#else 2984 eval("brctl", "addif", lan_ifname, if_name); 2985#endif 2986 } 2987 } 2988 for (bssid_num=1; bssid_num<=3; bssid_num++) 2989 { 2990 char param_name_5g[32]; // Foxconn modified pling 10/06/2010, 16->32 2991 char if_name_5g[16]; 2992 sprintf(param_name_5g, "wl1.%d_bss_enabled", bssid_num); 2993 sprintf(if_name_5g, "wl1.%d", bssid_num); 2994 if (nvram_match(param_name_5g, "1")) 2995 { 2996 wl_vif_hwaddr_set(if_name_5g); 2997 ifconfig(if_name_5g, IFUP, NULL, NULL); 2998 /* Added by Foxconn Antony start 2015/06/21 for a bssid create for extender to scan newarby ap*/ 2999 if(bssid_num==2) 3000 continue; 3001 /* Added by Foxconn Antony end 2015/06/21 */ 3002#ifdef VLAN_SUPPORT 3003 if(nvram_match("enable_vlan", "enable")) 3004 add_if_to_vlan_group(if_name_5g); 3005 else if(nvram_match(NVRAM_IPTV_ENABLED, "1") && (bssid_num==1)) 3006 { 3007 if (iptv_intf_val & IPTV_WLAN_GUEST2) 3008 eval("brctl", "addif", wan_ifname, if_name_5g); 3009 else 3010 eval("brctl", "addif", lan_ifname, if_name_5g); 3011 3012 } 3013 else 3014 eval("brctl", "addif", lan_ifname, if_name_5g); 3015#else 3016 eval("brctl", "addif", lan_ifname, if_name_5g); 3017#endif 3018 } 3019 } 3020 } 3021#endif 3022 /* Foxconn added end pling 06/06/2007 */ 3023 3024 /* Foxconn, add by MJ., for wifi cert. */ 3025 //if(!nvram_match("wifi_test", "1")) 3026 eval("wl", "-i", wl1_ifname, "obss_coex", "0"); /* foxconn added, zacker, 01/05/2011 */ 3027 3028 /* foxconn added start, zacker, 11/01/2010 */ 3029 { 3030 int s; 3031 struct ifreq ifr; 3032 unsigned char hwaddr[ETHER_ADDR_LEN] = ""; 3033 3034 ether_atoe(nvram_safe_get("lan_hwaddr"), hwaddr); 3035 if (memcmp(hwaddr, "\0\0\0\0\0\0", ETHER_ADDR_LEN) && 3036 (s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) >= 0) { 3037 strncpy(ifr.ifr_name, lan_ifname, IFNAMSIZ); 3038 ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; 3039 memcpy(ifr.ifr_hwaddr.sa_data, hwaddr, ETHER_ADDR_LEN); 3040 ioctl(s, SIOCSIFHWADDR, &ifr); 3041 close(s); 3042 } 3043 } 3044 /* foxconn added end, zacker, 11/01/2010 */ 3045 3046 return; 3047} 3048/* foxconn added end, wklin, 10/17/2006 */ 3049