3 Copyright 2005, Broadcom Corporation
6 THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
7 KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
8 SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
9 FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
17 #include <sys/ioctl.h>
18 #include <sys/mount.h>
23 #include <sys/reboot.h>
26 #include <sys/types.h>
28 #include <sys/sysinfo.h>
33 #define SHELL "/bin/sh"
35 static int fatalsigs
[] = {
46 static int initsigs
[] = {
56 static char *defenv
[] = {
59 "PATH=/usr/bin:/bin:/usr/sbin:/sbin",
65 /* Set terminal settings to reasonable defaults */
66 static void set_term(int fd
)
72 /* set control chars */
73 tty
.c_cc
[VINTR
] = 3; /* C-c */
74 tty
.c_cc
[VQUIT
] = 28; /* C-\ */
75 tty
.c_cc
[VERASE
] = 127; /* C-? */
76 tty
.c_cc
[VKILL
] = 21; /* C-u */
77 tty
.c_cc
[VEOF
] = 4; /* C-d */
78 tty
.c_cc
[VSTART
] = 17; /* C-q */
79 tty
.c_cc
[VSTOP
] = 19; /* C-s */
80 tty
.c_cc
[VSUSP
] = 26; /* C-z */
82 /* use line dicipline 0 */
86 tty
.c_cflag
&= CBAUD
|CBAUDEX
|CSIZE
|CSTOPB
|PARENB
|PARODD
;
87 tty
.c_cflag
|= CREAD
|HUPCL
|CLOCAL
;
91 tty
.c_iflag
= ICRNL
| IXON
| IXOFF
;
94 tty
.c_oflag
= OPOST
| ONLCR
;
98 ISIG
| ICANON
| ECHO
| ECHOE
| ECHOK
| ECHOCTL
| ECHOKE
| IEXTEN
;
100 tcsetattr(fd
, TCSANOW
, &tty
);
103 static int console_init(void)
108 ioctl(0, TIOCNOTTY
, 0);
115 if ((fd
= open(_PATH_CONSOLE
, O_RDWR
)) < 0) {
116 /* Avoid debug messages is redirected to socket packet if no exist a UART chip, added by honor, 2003-12-04 */
117 open("/dev/null", O_RDONLY
);
118 open("/dev/null", O_WRONLY
);
119 open("/dev/null", O_WRONLY
);
120 perror(_PATH_CONSOLE
);
127 ioctl(0, TIOCSCTTY
, 1);
128 tcsetpgrp(0, getpgrp());
135 * Waits for a file descriptor to change status or unblocked signal
136 * @param fd file descriptor
137 * @param timeout seconds to wait before timing out or 0 for no timeout
138 * @return 1 if descriptor changed status or 0 if timed out or -1 on error
140 static int waitfor(int fd
, int timeout
)
143 struct timeval tv
= { timeout
, 0 };
147 return select(fd
+ 1, &rfds
, NULL
, NULL
, (timeout
> 0) ? &tv
: NULL
);
150 static pid_t
run_shell(int timeout
, int nowait
)
155 /* Wait for user input */
156 if (waitfor(STDIN_FILENO
, timeout
) <= 0) return 0;
158 switch (pid
= fork()) {
163 /* Reset signal handlers set for parent process */
164 for (sig
= 0; sig
< (_NSIG
-1); sig
++)
165 signal(sig
, SIG_DFL
);
169 printf("\n\nTomato %s\n\n", tomato_version
);
171 /* Now run it. The new program will take over this PID,
172 * so nothing further in init.c should be run. */
173 execve(SHELL
, (char *[]) { SHELL
, NULL
}, defenv
);
175 /* We're still here? Some error happened. */
183 waitpid(pid
, NULL
, 0);
189 int console_main(int argc
, char *argv
[])
191 for (;;) run_shell(0, 0);
196 static void shutdn(int rb
)
202 _dprintf("shutdn rb=%d\n", rb
);
205 for (i
= 0; i
< sizeof(fatalsigs
) / sizeof(fatalsigs
[0]); i
++)
206 sigaddset(&ss
, fatalsigs
[i
]);
207 for (i
= 0; i
< sizeof(initsigs
) / sizeof(initsigs
[0]); i
++)
208 sigaddset(&ss
, initsigs
[i
]);
209 sigprocmask(SIG_BLOCK
, &ss
, NULL
);
211 for (i
= 30; i
> 0; --i
) {
212 if (((act
= check_action()) == ACT_IDLE
) || (act
== ACT_REBOOT
)) break;
213 _dprintf("Busy with %d. Waiting before shutdown... %d\n", act
, i
);
216 set_action(ACT_REBOOT
);
218 // Disconnect pppd - need this for PPTP/L2TP to finish gracefully
232 umount("/jffs"); // may hang if not
238 for (i
= 4; i
> 0; --i
) {
249 reboot(rb
? RB_AUTOBOOT
: RB_HALT_SYSTEM
);
256 static void handle_fatalsigs(int sig
)
258 _dprintf("fatal sig=%d\n", sig
);
262 /* Fixed the race condition & incorrect code by using sigwait()
263 * instead of pause(). But SIGCHLD is a problem, since other
264 * code: 1) messes with it and 2) depends on CHLD being caught so
265 * that the pid gets immediately reaped instead of left a zombie.
266 * Pidof still shows the pid, even though it's in zombie state.
267 * So this SIGCHLD handler reaps and then signals the mainline by
270 static void handle_reap(int sig
)
276 static int check_nv(const char *name
, const char *value
)
279 if (!nvram_match("manual_boot_nv", "1")) {
280 if (((p
= nvram_get(name
)) == NULL
) || (strcmp(p
, value
) != 0)) {
281 _dprintf("Error: Critical variable %s is invalid. Resetting.\n", name
);
282 nvram_set(name
, value
);
289 static inline int invalid_mac(const char *mac
)
291 return (!mac
|| !(*mac
) || strncasecmp(mac
, "00:90:4c", 8) == 0);
294 static int find_sercom_mac_addr(void)
297 unsigned char m
[6], s
[18];
299 sprintf(s
, MTD_DEV(%dro
), 0);
300 if ((fp
= fopen(s
, "rb"))) {
301 fseek(fp
, 0x1ffa0, SEEK_SET
);
302 fread(m
, sizeof(m
), 1, fp
);
304 sprintf(s
, "%02X:%02X:%02X:%02X:%02X:%02X",
305 m
[0], m
[1], m
[2], m
[3], m
[4], m
[5]);
306 nvram_set("et0macaddr", s
);
307 return !invalid_mac(s
);
312 static int find_dir320_mac_addr(void)
316 int i
, part
, size
, found
= 0;
318 if (!mtd_getinfo("board_data", &part
, &size
))
320 sprintf(s
, MTD_DEV(%dro
), part
);
322 if ((fp
= fopen(s
, "rb"))) {
323 buffer
= malloc(size
);
324 memset(buffer
, 0, size
);
325 fread(buffer
, size
, 1, fp
);
326 if (!memcmp(buffer
, "RGCFG1", 6)) {
327 for (i
= 6; i
< size
- 24; i
++) {
328 if (!memcmp(buffer
+ i
, "lanmac=", 7)) {
329 memcpy(s
, buffer
+ i
+ 7, 17);
331 nvram_set("et0macaddr", s
);
334 else if (!memcmp(buffer
+ i
, "wanmac=", 7)) {
335 memcpy(s
, buffer
+ i
+ 7, 17);
337 nvram_set("il0macaddr", s
);
340 nvram_set("et0macaddr", s
);
351 strcpy(s
, nvram_safe_get("wl0_hwaddr"));
353 nvram_set("et0macaddr", s
);
358 static int init_vlan_ports(void)
361 int model
= get_model();
365 switch (check_hw_type()) {
366 case HW_BCM5352E
: // G v4, GS v3, v4
367 dirty
|= check_nv("vlan0ports", "3 2 1 0 5*");
372 dirty
|= check_nv("vlan0ports", "0 5*");
373 dirty
|= check_nv("vlan1ports", "1 5");
374 dirty
|= check_nv("vlan_enable", "1");
378 case MODEL_WL500GPv2
:
381 if (nvram_match("vlan1ports", "0 5u")) // 520GU or 330GE or WL500GE?
382 dirty
|= check_nv("vlan1ports", "0 5");
383 else if (nvram_match("vlan1ports", "4 5u"))
384 dirty
|= check_nv("vlan1ports", "4 5");
387 dirty
|= check_nv("vlan0ports", "1 2 3 4 5*");
388 dirty
|= check_nv("vlan1ports", "0 5");
392 dirty
|= (nvram_get("vlan2ports") != NULL
);
393 nvram_unset("vlan2ports");
394 dirty
|= check_nv("vlan1ports", "0 5");
396 case MODEL_WRT310Nv1
:
397 dirty
|= check_nv("vlan1ports", "1 2 3 4 8*");
398 dirty
|= check_nv("vlan2ports", "0 8");
401 dirty
|= check_nv("vlan0ports", "0 1 2 3 5*");
402 dirty
|= check_nv("vlan1ports", "4 5");
407 case MODEL_WNR3500LV2
:
410 dirty
|= check_nv("vlan1ports", "4 3 2 1 8*");
411 dirty
|= check_nv("vlan2ports", "0 8");
414 dirty
|= check_nv("vlan1ports", "1 2 3 4 8*");
415 dirty
|= check_nv("vlan2ports", "0 8");
418 dirty
|= check_nv("vlan2ports", "0 1 2 3 5*");
419 dirty
|= check_nv("vlan1ports", "4 5");
421 case MODEL_WNR2000v2
:
422 dirty
|= check_nv("vlan1ports", "4 3 2 1 5*");
423 dirty
|= check_nv("vlan2ports", "0 5");
427 case MODEL_RG200E_CA
:
428 dirty
|= check_nv("vlan1ports", "1 2 3 4 5*");
429 dirty
|= check_nv("vlan2ports", "0 5");
432 dirty
|= check_nv("vlan1ports", "4 5");
436 dirty
|= check_nv("vlan0ports", "1 2 3 4 5*");
437 dirty
|= check_nv("vlan1ports", "0 5");
441 dirty
|= check_nv("vlan0ports", "3 2 1 0 5*");
442 dirty
|= check_nv("vlan1ports", "4 5");
444 case MODEL_WRT610Nv2
:
445 case MODEL_F5D8235v3
:
446 dirty
|= check_nv("vlan1ports", "1 2 3 4 8*");
447 dirty
|= check_nv("vlan2ports", "0 8");
451 dirty
|= check_nv("vlan1ports", "3 2 1 0 8*");
452 dirty
|= check_nv("vlan2ports", "4 8");
460 dirty
|= check_nv("vlan1ports", "0 1 2 3 5*");
461 dirty
|= check_nv("vlan2ports", "4 5");
464 dirty
|= check_nv("vlan1ports", "1 2 3 4 5*");
465 dirty
|= check_nv("vlan2ports", "0 5");
470 dirty
|= check_nv("vlan1ports", "0 1 2 3 8*");
471 dirty
|= check_nv("vlan2ports", "4 8");
473 case MODEL_WRT160Nv3
:
474 if (nvram_match("vlan1ports", "1 2 3 4 5*")) {
475 // fix lan port numbering on CSE41, CSE51
476 dirty
|= check_nv("vlan1ports", "4 3 2 1 5*");
478 else if (nvram_match("vlan1ports", "1 2 3 4 8*")) {
480 dirty
|= check_nv("vlan1ports", "4 3 2 1 8*");
489 static void check_bootnv(void)
497 dirty
= check_nv("wl0_leddc", "0x640000") | check_nv("wl1_leddc", "0x640000");
501 dirty
|= check_nv("vlan0hwname", "et0");
502 dirty
|= check_nv("vlan1hwname", "et0");
505 dirty
|= check_nv("wl0gpio0", "130");
509 // need to cleanup some variables...
510 if ((nvram_get("t_model") == NULL
) && (nvram_get("MyFirmwareVersion") != NULL
)) {
511 nvram_unset("MyFirmwareVersion");
512 nvram_set("restore_defaults", "1");
516 dirty
|= check_nv("wl0gpio1", "0x02");
519 /* fix WL500W mac adresses for WAN port */
520 if (invalid_mac(nvram_get("et1macaddr"))) {
521 strcpy(mac
, nvram_safe_get("et0macaddr"));
523 dirty
|= check_nv("et1macaddr", mac
);
525 dirty
|= check_nv("wl0gpio0", "0x88");
528 dirty
|= check_nv("sdram_init", "0x0009"); // 32MB; defaults: 0x000b, 0x0009
529 dirty
|= check_nv("wl0gpio0", "136");
531 case MODEL_WL500GPv2
:
533 dirty
|= check_nv("wl0gpio1", "136");
536 dirty
|= check_nv("vlan0hwname", "et0");
537 dirty
|= check_nv("vlan1hwname", "et0");
538 dirty
|= check_nv("boardflags", "0x00000100"); // set BFL_ENETVLAN
539 nvram_unset("wl0gpio0");
542 if (strlen(nvram_safe_get("et0macaddr")) == 12 ||
543 strlen(nvram_safe_get("il0macaddr")) == 12) {
544 dirty
|= find_dir320_mac_addr();
546 if (nvram_get("vlan2hwname") != NULL
) {
547 nvram_unset("vlan2hwname");
550 dirty
|= check_nv("wandevs", "vlan1");
551 dirty
|= check_nv("vlan1hwname", "et0");
552 dirty
|= check_nv("wl0gpio0", "8");
553 dirty
|= check_nv("wl0gpio1", "0");
554 dirty
|= check_nv("wl0gpio2", "0");
555 dirty
|= check_nv("wl0gpio3", "0");
557 if (invalid_mac(nvram_get("et0macaddr"))) {
558 dirty
|= find_sercom_mac_addr();
561 case MODEL_WRT160Nv1
:
562 case MODEL_WRT310Nv1
:
564 dirty
|= check_nv("wl0gpio0", "8");
568 dirty
|= check_nv("boardflags", "0x00000710"); // needed to enable USB
569 dirty
|= check_nv("vlan2hwname", "et0");
570 dirty
|= check_nv("ledbh0", "7");
572 case MODEL_WNR3500LV2
:
573 dirty
|= check_nv("vlan2hwname", "et0");
575 case MODEL_WNR2000v2
:
576 dirty
|= check_nv("ledbh5", "8");
579 dirty
|= check_nv("reset_gpio", "5");
580 dirty
|= check_nv("ledbh0", "136");
581 dirty
|= check_nv("ledbh1", "11");
582 /* fall through, same as RT-N16 */
584 dirty
|= check_nv("vlan2hwname", "et0");
587 case MODEL_RG200E_CA
:
589 dirty
|= check_nv("vlan1hwname", "et0");
590 dirty
|= check_nv("vlan2hwname", "et0");
591 dirty
|= check_nv("reset_gpio", "30");
593 case MODEL_WRT610Nv2
:
594 dirty
|= check_nv("vlan2hwname", "et0");
595 dirty
|= check_nv("pci/1/1/ledbh2", "8");
596 dirty
|= check_nv("sb/1/ledbh1", "8");
597 if (invalid_mac(nvram_get("pci/1/1/macaddr"))) {
598 strcpy(mac
, nvram_safe_get("et0macaddr"));
600 dirty
|= check_nv("pci/1/1/macaddr", mac
);
607 case MODEL_F5D8235v3
:
608 if (nvram_match("sb/1/macaddr", nvram_safe_get("et0macaddr"))) {
609 strcpy(mac
, nvram_safe_get("et0macaddr"));
611 dirty
|= check_nv("sb/1/macaddr", mac
);
613 dirty
|= check_nv("pci/1/1/macaddr", mac
);
616 dirty
|= check_nv("vlan2hwname", "et0");
617 if (strncasecmp(nvram_safe_get("pci/1/1/macaddr"), "00:90:4c", 8) == 0 ||
618 strncasecmp(nvram_safe_get("sb/1/macaddr"), "00:90:4c", 8) == 0) {
619 strcpy(mac
, nvram_safe_get("et0macaddr"));
621 dirty
|= check_nv("sb/1/macaddr", mac
);
623 dirty
|= check_nv("pci/1/1/macaddr", mac
);
632 case MODEL_WRT160Nv3
:
633 dirty
|= check_nv("vlan2hwname", "et0");
638 if (strncmp(nvram_safe_get("pmon_ver"), "CFE", 3) != 0) return;
640 hardware
= check_hw_type();
641 if (!nvram_get("boardtype") ||
642 !nvram_get("boardnum") ||
643 !nvram_get("boardflags") ||
644 !nvram_get("clkfreq") ||
645 !nvram_get("os_flash_addr") ||
646 !nvram_get("dl_ram_addr") ||
647 !nvram_get("os_ram_addr") ||
648 !nvram_get("scratch") ||
649 !nvram_get("et0macaddr") ||
650 ((hardware
!= HW_BCM4704_BCM5325F
) && (!nvram_get("vlan0ports") || !nvram_get("vlan0hwname")))) {
651 _dprintf("Unable to find critical settings, erasing NVRAM\n");
656 dirty
|= check_nv("aa0", "3");
657 dirty
|= check_nv("wl0gpio0", "136");
658 dirty
|= check_nv("wl0gpio2", "0");
659 dirty
|= check_nv("wl0gpio3", "0");
660 dirty
|= check_nv("cctl", "0");
661 dirty
|= check_nv("ccode", "0");
665 /* Lower the DDR ram drive strength , the value will be stable for all boards
666 Latency 3 is more stable for all ddr 20050420 by honor */
667 dirty
|= check_nv("sdram_init", "0x010b");
668 dirty
|= check_nv("sdram_config", "0x0062");
669 if (!nvram_match("debug_clkfix", "0")) {
670 dirty
|= check_nv("clkfreq", "216");
673 nvram_set("sdram_ncdl", "0x0");
675 dirty
|= check_nv("pa0itssit", "62");
676 dirty
|= check_nv("pa0b0", "0x15eb");
677 dirty
|= check_nv("pa0b1", "0xfa82");
678 dirty
|= check_nv("pa0b2", "0xfe66");
679 //dirty |= check_nv("pa0maxpwr", "0x4e");
681 case HW_BCM5352E
: // G v4, GS v3, v4
682 dirty
|= check_nv("sdram_init", "0x010b");
683 dirty
|= check_nv("sdram_config", "0x0062");
685 nvram_set("sdram_ncdl", "0x0");
687 dirty
|= check_nv("pa0itssit", "62");
688 dirty
|= check_nv("pa0b0", "0x168b");
689 dirty
|= check_nv("pa0b1", "0xfabf");
690 dirty
|= check_nv("pa0b2", "0xfeaf");
691 //dirty |= check_nv("pa0maxpwr", "0x4e");
694 dirty
|= check_nv("pa0itssit", "62");
695 dirty
|= check_nv("pa0b0", "0x1326");
696 dirty
|= check_nv("pa0b1", "0xFB51");
697 dirty
|= check_nv("pa0b2", "0xFE87");
698 //dirty |= check_nv("pa0maxpwr", "0x4e");
700 case HW_BCM4704_BCM5325F
:
704 dirty
|= check_nv("pa0itssit", "62");
705 dirty
|= check_nv("pa0b0", "0x170c");
706 dirty
|= check_nv("pa0b1", "0xfa24");
707 dirty
|= check_nv("pa0b2", "0xfe70");
708 //dirty |= check_nv("pa0maxpwr", "0x48");
715 dirty
|= init_vlan_ports();
719 REBOOT
: // do a simple reboot
726 static int init_nvram(void)
728 unsigned long features
;
738 sprintf(s
, "%d", model
);
739 nvram_set("t_model", s
);
748 name
= "WRT54G/GS/GL";
749 switch (check_hw_type()) {
751 nvram_set("gpio2", "adm_eecs");
752 nvram_set("gpio3", "adm_eesk");
753 nvram_unset("gpio4");
754 nvram_set("gpio5", "adm_eedi");
755 nvram_set("gpio6", "adm_rc");
758 nvram_unset("gpio2");
759 nvram_unset("gpio3");
760 nvram_unset("gpio4");
761 nvram_unset("gpio5");
762 nvram_unset("gpio6");
765 nvram_set("opo", "0x0008");
766 nvram_set("ag0", "0x02");
769 nvram_set("gpio2", "ses_led");
770 nvram_set("gpio3", "ses_led2");
771 nvram_set("gpio4", "ses_button");
772 features
= SUP_SES
| SUP_WHAM_LED
;
779 if (!nvram_match("t_fix1", (char *)name
)) {
780 nvram_set("lan_ifnames", "vlan0 eth1");
781 nvram_set("gpio2", "ses_button");
782 nvram_set("reset_gpio", "7");
784 nvram_set("pa0itssit", "62");
785 nvram_set("pa0b0", "0x1542");
786 nvram_set("pa0b1", "0xfacb");
787 nvram_set("pa0b2", "0xfec7");
788 //nvram_set("pa0maxpwr", "0x4c");
791 case MODEL_WRTSL54GS
:
794 features
= SUP_SES
| SUP_WHAM_LED
;
799 features
= SUP_SES
| SUP_AOSS_LED
| SUP_BRAU
;
802 case MODEL_WZRRSG54HP
:
805 features
= SUP_SES
| SUP_AOSS_LED
| SUP_HPAMP
;
807 case MODEL_WZRRSG54HP
:
808 name
= "WZR-RS-G54HP";
815 features
= SUP_SES
| SUP_AOSS_LED
| SUP_BRAU
| SUP_HPAMP
;
819 bf
= strtoul(nvram_safe_get("boardflags"), NULL
, 0);
825 if (nvram_match("wlx_hpamp", "")) {
826 if (nvram_get_int("wl_txpwr") > 10) nvram_set("wl_txpwr", "10");
827 nvram_set("wlx_hpamp", "1");
828 nvram_set("wlx_hperx", "0");
832 if (nvram_match("wlx_hpamp", "0")) {
838 if (nvram_match("wlx_hperx", "0")) {
845 sprintf(s
, "0x%lX", n
);
846 nvram_set("boardflags", s
);
850 syslog(LOG_WARNING
, "Unexpected: boardflag=%lX", bf
);
861 features
= SUP_SES
| SUP_AOSS_LED
;
863 case MODEL_WHR2A54G54
:
865 name
= "WHR2-A54G54";
866 features
= SUP_SES
| SUP_AOSS_LED
| SUP_BRAU
;
871 features
= SUP_SES
| SUP_AOSS_LED
;
876 features
= SUP_SES
| SUP_AOSS_LED
;
881 features
= SUP_SES
| SUP_AOSS_LED
;
891 features
= SUP_SES
| SUP_AOSS_LED
;
900 features
= SUP_NONVE
;
904 name
= "WR850G v2/v3";
905 features
= SUP_NONVE
;
912 nvram_set("usb_ohci", "-1");
914 if (!nvram_match("t_fix1", (char *)name
)) {
915 nvram_set("lan_ifnames", "vlan0 eth1 eth2 eth3"); // set to "vlan0 eth2" by DD-WRT; default: vlan0 eth1
921 features
= SUP_SES
| SUP_80211N
;
923 nvram_set("usb_ohci", "-1");
931 nvram_set("usb_uhci", "-1");
950 if (!nvram_match("t_fix1", (char *)name
)) {
951 nvram_set("lan_ifnames", "vlan0 eth1 eth2");
952 nvram_set("wl_ifname", "eth1");
953 nvram_set("wan_ifname", "none");
958 name
= "TrueMobile 2300";
967 #ifndef WL_BSS_INFO_VERSION
968 #error WL_BSS_INFO_VERSION
970 #if WL_BSS_INFO_VERSION >= 108
976 nvram_set("opo", "12");
982 features
= SUP_SES
| SUP_AOSS_LED
| SUP_BRAU
;
984 nvram_set("opo", "0x0008");
985 nvram_set("ag0", "0x0C");
991 features
= SUP_SES
| SUP_80211N
;
993 nvram_set("usb_uhci", "-1");
995 if (!nvram_match("t_fix1", (char *)name
)) {
996 nvram_set("lan_ifnames", "vlan0 eth1");
997 nvram_set("wan_ifnameX", "vlan1");
998 nvram_set("wl_ifname", "eth1");
1004 features
= SUP_SES
| SUP_80211N
;
1006 nvram_set("usb_uhci", "-1");
1008 if (!nvram_match("t_fix1", (char *)name
)) {
1009 nvram_set("lan_ifnames", "vlan1 eth1");
1010 nvram_set("wan_ifname", "vlan2");
1011 nvram_set("wan_ifnames", "vlan2");
1012 nvram_set("wan_ifnameX", "vlan2");
1013 nvram_set("wl_ifname", "eth1");
1016 case MODEL_RG200E_CA
:
1019 features
= SUP_SES
| SUP_80211N
;
1021 nvram_set("usb_uhci", "-1");
1023 if (!nvram_match("t_fix1", (char *)name
)) {
1024 nvram_set("lan_ifnames", "vlan1 eth1");
1025 nvram_set("wan_ifname", "vlan2");
1026 nvram_set("wan_ifnames", "vlan2");
1027 nvram_set("wan_ifnameX", "vlan2");
1028 nvram_set("wl_ifname", "eth1");
1034 features
= SUP_SES
| SUP_80211N
;
1036 nvram_set("usb_uhci", "-1");
1038 if (!nvram_match("t_fix1", (char *)name
)) {
1039 nvram_set("lan_ifnames", "vlan1 eth1");
1040 nvram_set("wan_ifname", "vlan2");
1041 nvram_set("wan_ifnames", "vlan2");
1042 nvram_set("wan_ifnameX", "vlan2");
1043 nvram_set("wl_ifname", "eth1");
1049 features
= SUP_SES
| SUP_80211N
;
1050 if (!nvram_match("t_fix1", (char *)name
)) {
1051 nvram_set("lan_ifnames", "vlan0 eth1");
1052 nvram_set("wan_ifnameX", "vlan1");
1053 nvram_set("wl_ifname", "eth1");
1059 features
= SUP_SES
| SUP_80211N
;
1061 nvram_set("usb_uhci", "-1");
1063 if (!nvram_match("t_fix1", (char *)name
)) {
1064 nvram_set("lan_ifnames", "vlan0 eth1");
1065 nvram_set("wan_ifnameX", "vlan1");
1066 nvram_set("wl_ifname", "eth1");
1072 features
= SUP_SES
| SUP_BRAU
| SUP_80211N
;
1073 if (!nvram_match("t_fix1", (char *)name
)) {
1074 nvram_set("lan_ifnames", "vlan0 eth1");
1075 nvram_set("wan_ifnameX", "vlan1");
1076 nvram_set("wl_ifname", "eth1");
1082 features
= SUP_80211N
;
1083 if (!nvram_match("t_fix1", (char *)name
)) {
1084 nvram_set("lan_ifnames", "vlan0 eth1");
1085 nvram_set("wan_ifnameX", "vlan1");
1086 nvram_set("wl_ifname", "eth1");
1092 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
;
1094 nvram_set("usb_uhci", "-1");
1096 if (!nvram_match("t_fix1", (char *)name
)) {
1097 nvram_set("lan_ifnames", "vlan1 eth1");
1098 nvram_set("wan_iface", "vlan2");
1099 nvram_set("wan_ifname", "vlan2");
1100 nvram_set("wan_ifnameX", "vlan2");
1101 nvram_set("wan_ifnames", "vlan2");
1102 nvram_set("wl_ifname", "eth1");
1108 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
;
1110 nvram_set("usb_uhci", "-1");
1112 if (!nvram_match("t_fix1", (char *)name
)) {
1113 nvram_set("lan_ifnames", "vlan1 eth1");
1114 nvram_set("wan_ifnameX", "vlan2");
1115 nvram_set("wl_ifname", "eth1");
1116 nvram_set("vlan_enable", "1");
1122 features
= SUP_SES
| SUP_80211N
;
1123 #if defined(LINUX26) && defined(TCONFIG_USBAP)
1124 if (nvram_get_int("usb_storage") == 1) nvram_set("usb_storage", "-1");
1126 if (!nvram_match("t_fix1", (char *)name
)) {
1127 #ifdef TCONFIG_USBAP
1128 nvram_set("lan_ifnames", "vlan2 eth1 eth2");
1129 nvram_set("landevs", "vlan2 wl0 wl1");
1130 nvram_set("wl1_ifname", "eth2");
1132 nvram_set("lan_ifnames", "vlan2 eth1");
1133 nvram_set("landevs", "vlan2 wl0");
1135 nvram_set("wl_ifname", "eth1");
1136 nvram_set("wl0_ifname", "eth1");
1137 nvram_set("wan_ifnameX", "vlan1");
1138 nvram_set("wandevs", "vlan1");
1139 nvram_unset("vlan0ports");
1144 #ifdef CONFIG_BCMWL6
1146 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
| SUP_80211AC
;
1149 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
;
1150 #if defined(LINUX26) && defined(TCONFIG_MICROSD)
1151 if (nvram_get_int("usb_mmc") == -1) nvram_set("usb_mmc", "1");
1156 nvram_set("usb_uhci", "-1");
1158 if (!nvram_match("t_fix1", (char *)name
)) {
1159 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1160 nvram_set("wan_ifnameX", "vlan2");
1161 nvram_set("wl_ifnames", "eth1 eth2");
1162 #ifdef CONFIG_BCMWL6
1163 nvram_set("wl_ifname", "eth1");
1164 nvram_set("wl0_ifname", "eth1");
1165 nvram_set("wl1_ifname", "eth2");
1167 nvram_set("landevs", "vlan1 wl0 wl1");
1168 nvram_set("wandevs", "vlan2");
1169 #ifndef CONFIG_BCMWL6
1170 #if defined(LINUX26) && defined(TCONFIG_USB)
1171 nvram_set("usb_noled", "1-1.4"); /* SD/MMC Card */
1174 nvram_set("wl1_bw_cap","7");
1175 nvram_set("wl1_chanspec","36/80");
1176 nvram_set("wl0_bw_cap","3");
1177 nvram_set("wl0_chanspec","1l");
1178 nvram_set("blink_5g_interface","eth2");
1181 strcpy(s
, nvram_safe_get("et0macaddr"));
1183 nvram_set("wl0_hwaddr", s
);
1185 nvram_set("wl1_hwaddr", s
);
1187 // bcm4360ac_defaults
1188 nvram_set("pci/2/1/aa2g", "0");
1189 nvram_set("pci/2/1/aa5g", "7");
1190 nvram_set("pci/2/1/aga0", "71");
1191 nvram_set("pci/2/1/aga1", "71");
1192 nvram_set("pci/2/1/aga2", "71");
1193 nvram_set("pci/2/1/agbg0", "133");
1194 nvram_set("pci/2/1/agbg1", "133");
1195 nvram_set("pci/2/1/agbg2", "133");
1196 nvram_set("pci/2/1/antswitch", "0");
1197 nvram_set("pci/2/1/cckbw202gpo", "0");
1198 nvram_set("pci/2/1/cckbw20ul2gpo", "0");
1199 nvram_set("pci/2/1/dot11agofdmhrbw202gpo", "0");
1200 nvram_set("pci/2/1/femctrl", "3");
1201 nvram_set("pci/2/1/papdcap2g", "0");
1202 nvram_set("pci/2/1/tworangetssi2g", "0");
1203 nvram_set("pci/2/1/pdgain2g", "4");
1204 nvram_set("pci/2/1/epagain2g", "0");
1205 nvram_set("pci/2/1/tssiposslope2g", "1");
1206 nvram_set("pci/2/1/gainctrlsph", "0");
1207 nvram_set("pci/2/1/papdcap5g", "0");
1208 nvram_set("pci/2/1/tworangetssi5g", "0");
1209 nvram_set("pci/2/1/pdgain5g", "4");
1210 nvram_set("pci/2/1/epagain5g", "0");
1211 nvram_set("pci/2/1/tssiposslope5g", "1");
1212 nvram_set("pci/2/1/maxp2ga0", "76");
1213 nvram_set("pci/2/1/maxp2ga1", "76");
1214 nvram_set("pci/2/1/maxp2ga2", "76");
1215 nvram_set("pci/2/1/mcsbw202gpo", "0");
1216 nvram_set("pci/2/1/mcsbw402gpo", "0");
1217 nvram_set("pci/2/1/measpower", "0x7f");
1218 nvram_set("pci/2/1/measpower1", "0x7f");
1219 nvram_set("pci/2/1/measpower2", "0x7f");
1220 nvram_set("pci/2/1/noiselvl2ga0", "31");
1221 nvram_set("pci/2/1/noiselvl2ga1", "31");
1222 nvram_set("pci/2/1/noiselvl2ga2", "31");
1223 nvram_set("pci/2/1/noiselvl5gha0", "31");
1224 nvram_set("pci/2/1/noiselvl5gha1", "31");
1225 nvram_set("pci/2/1/noiselvl5gha2", "31");
1226 nvram_set("pci/2/1/noiselvl5gla0", "31");
1227 nvram_set("pci/2/1/noiselvl5gla1", "31");
1228 nvram_set("pci/2/1/noiselvl5gla2", "31");
1229 nvram_set("pci/2/1/noiselvl5gma0", "31");
1230 nvram_set("pci/2/1/noiselvl5gma1", "31");
1231 nvram_set("pci/2/1/noiselvl5gma2", "31");
1232 nvram_set("pci/2/1/noiselvl5gua0", "31");
1233 nvram_set("pci/2/1/noiselvl5gua1", "31");
1234 nvram_set("pci/2/1/noiselvl5gua2", "31");
1235 nvram_set("pci/2/1/ofdmlrbw202gpo", "0");
1236 nvram_set("pci/2/1/pa2ga0", "0xfe72,0x14c0,0xfac7");
1237 nvram_set("pci/2/1/pa2ga1", "0xfe80,0x1472,0xfabc");
1238 nvram_set("pci/2/1/pa2ga2", "0xfe82,0x14bf,0xfad9");
1239 nvram_set("pci/2/1/pcieingress_war", "15");
1240 nvram_set("pci/2/1/phycal_tempdelta", "255");
1241 nvram_set("pci/2/1/rawtempsense", "0x1ff");
1242 nvram_set("pci/2/1/rxchain", "7");
1243 nvram_set("pci/2/1/rxgainerr2g", "0xffff");
1244 nvram_set("pci/2/1/rxgainerr5g", "0xffff,0xffff,0xffff,0xffff");
1245 nvram_set("pci/2/1/rxgains2gelnagaina0", "0");
1246 nvram_set("pci/2/1/rxgains2gelnagaina1", "0");
1247 nvram_set("pci/2/1/rxgains2gelnagaina2", "0");
1248 nvram_set("pci/2/1/rxgains2gtrelnabypa0", "0");
1249 nvram_set("pci/2/1/rxgains2gtrelnabypa1", "0");
1250 nvram_set("pci/2/1/rxgains2gtrelnabypa2", "0");
1251 nvram_set("pci/2/1/rxgains2gtrisoa0", "0");
1252 nvram_set("pci/2/1/rxgains2gtrisoa1", "0");
1253 nvram_set("pci/2/1/rxgains2gtrisoa2", "0");
1254 nvram_set("pci/2/1/sar2g", "18");
1255 nvram_set("pci/2/1/sar5g", "15");
1256 nvram_set("pci/2/1/sromrev", "11");
1257 nvram_set("pci/2/1/subband5gver", "0x4");
1258 nvram_set("pci/2/1/tempcorrx", "0x3f");
1259 nvram_set("pci/2/1/tempoffset", "255");
1260 nvram_set("pci/2/1/temps_hysteresis", "15");
1261 nvram_set("pci/2/1/temps_period", "15");
1262 nvram_set("pci/2/1/tempsense_option", "0x3");
1263 nvram_set("pci/2/1/tempsense_slope", "0xff");
1264 nvram_set("pci/2/1/tempthresh", "255");
1265 nvram_set("pci/2/1/txchain", "7");
1266 nvram_set("pci/2/1/ledbh0", "2");
1267 nvram_set("pci/2/1/ledbh1", "5");
1268 nvram_set("pci/2/1/ledbh2", "4");
1269 nvram_set("pci/2/1/ledbh3", "11");
1270 nvram_set("pci/2/1/ledbh10", "7");
1272 //force EU country for eth2
1273 nvram_set("pci/2/1/ccode", "EU");
1278 name
= "W1800R"; //id, board, rev same as N66
1279 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
| SUP_80211AC
;
1281 nvram_set("usb_uhci", "-1");
1283 if (!nvram_match("t_fix1", (char *)name
)) {
1284 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1285 nvram_set("wan_ifnameX", "vlan2");
1286 nvram_set("wl_ifnames", "eth1 eth2");
1287 nvram_set("wl_ifname", "eth1");
1288 nvram_set("wl0_ifname", "eth2");
1289 nvram_set("wl1_ifname", "eth1");
1290 nvram_set("wl0_bw_cap","7");
1291 nvram_set("wl0_chanspec","36/80");
1292 nvram_set("wl1_bw_cap","3");
1293 nvram_set("wl1_chanspec","1l");
1294 nvram_set("blink_5g_interface","eth1");
1295 //nvram_set("landevs", "vlan1 wl0 wl1");
1296 //nvram_set("wandevs", "vlan2");
1299 strcpy(s
, nvram_safe_get("et0macaddr"));
1300 nvram_set("wl0_hwaddr", nvram_safe_get("0:macaddr"));
1301 nvram_set("wl1_hwaddr", nvram_safe_get("1:macaddr"));
1302 #endif // CONFIG_BCMWL6
1305 case MODEL_WNR3500L
:
1307 name
= "WNR3500L/U/v2";
1308 features
= SUP_SES
| SUP_AOSS_LED
| SUP_80211N
| SUP_1000ET
;
1309 if (!nvram_match("t_fix1", (char *)name
)) {
1310 nvram_set("sromrev", "3");
1311 nvram_set("lan_ifnames", "vlan1 eth1");
1312 nvram_set("wan_ifnameX", "vlan2");
1313 nvram_set("wl_ifname", "eth1");
1316 case MODEL_WNR3500LV2
:
1318 name
= "WNR3500L v2";
1319 features
= SUP_SES
| SUP_AOSS_LED
| SUP_80211N
| SUP_1000ET
;
1320 if (!nvram_match("t_fix1", (char *)name
)) {
1321 nvram_set("lan_ifnames", "vlan1 eth1");
1322 nvram_set("wan_ifnameX", "vlan2");
1323 nvram_set("wl_ifname", "eth1");
1326 case MODEL_WNR2000v2
:
1328 name
= "WNR2000 v2";
1329 features
= SUP_SES
| SUP_AOSS_LED
| SUP_80211N
;
1330 if (!nvram_match("t_fix1", (char *)name
)) {
1331 nvram_set("lan_ifnames", "vlan0 eth1");
1332 nvram_set("wan_ifnameX", "vlan1");
1333 nvram_set("wl_ifname", "eth1");
1340 case MODEL_F5D8235v3
:
1342 features
= SUP_SES
| SUP_80211N
;
1345 name
= "Share Max N300 (F7D3301/F7D7301) v1";
1348 name
= "Share N300 (F7D3302/F7D7302) v1";
1351 name
= "Play Max / N600 HD (F7D4301/F7D8301) v1";
1354 name
= "Play N600 (F7D4302/F7D8302) v1";
1356 case MODEL_F5D8235v3
:
1357 name
= "N F5D8235-4 v3";
1361 nvram_set("usb_uhci", "-1");
1363 if (!nvram_match("t_fix1", (char *)name
)) {
1364 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1365 nvram_set("wan_ifnameX", "vlan2");
1366 nvram_set("landevs", "vlan1 wl0 wl1");
1367 nvram_set("wandevs", "vlan2");
1373 name
= nvram_safe_get("boot_hw_model");
1374 ver
= nvram_safe_get("boot_hw_ver");
1375 features
= SUP_SES
| SUP_80211N
;
1376 if (!nvram_match("t_fix1", (char *)name
)) {
1377 nvram_set("lan_ifnames", "vlan1 eth1");
1378 nvram_set("wan_ifnameX", "vlan2");
1379 nvram_set("wl_ifname", "eth1");
1384 name
= nvram_safe_get("boot_hw_model");
1385 ver
= nvram_safe_get("boot_hw_ver");
1386 features
= SUP_SES
| SUP_80211N
;
1388 nvram_set("usb_uhci", "-1");
1390 if (!nvram_match("t_fix1", (char *)name
)) {
1391 nvram_set("lan_ifnames", "vlan1 eth1");
1392 nvram_set("wan_ifnameX", "vlan2");
1393 nvram_set("wl_ifname", "eth1");
1398 name
= nvram_safe_get("boot_hw_model");
1399 ver
= nvram_safe_get("boot_hw_ver");
1400 features
= SUP_SES
| SUP_80211N
;
1401 #if defined(LINUX26) && defined(TCONFIG_USBAP)
1402 if (nvram_get_int("usb_storage") == 1) nvram_set("usb_storage", "-1");
1404 if (!nvram_match("t_fix1", (char *)name
)) {
1405 #ifdef TCONFIG_USBAP
1406 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1407 nvram_set("landevs", "vlan1 wl0 wl1");
1408 nvram_set("wl0_ifname", "eth1");
1409 nvram_set("wl1_ifname", "eth2");
1411 nvram_set("lan_ifnames", "vlan1 eth1");
1412 nvram_set("landevs", "vlan1 wl0");
1414 nvram_set("wan_ifnameX", "vlan2");
1415 nvram_set("wl_ifname", "eth1");
1421 name
= nvram_safe_get("boot_hw_model");
1422 ver
= nvram_safe_get("boot_hw_ver");
1423 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
;
1425 nvram_set("usb_uhci", "-1");
1427 if (!nvram_match("t_fix1", (char *)name
)) {
1428 #ifdef TCONFIG_USBAP
1429 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1430 nvram_set("landevs", "vlan1 wl0 wl1");
1431 nvram_set("wl0_ifname", "eth1");
1432 nvram_set("wl1_ifname", "eth2");
1434 nvram_set("lan_ifnames", "vlan1 eth1");
1435 nvram_set("landevs", "vlan1 wl0");
1437 nvram_set("wl_ifname", "eth1");
1438 nvram_set("wan_ifnameX", "vlan2");
1442 case MODEL_WRT160Nv3
:
1443 // same as M10, M20, WRT310Nv2, E1000v1
1445 name
= nvram_safe_get("boot_hw_model");
1446 ver
= nvram_safe_get("boot_hw_ver");
1447 if (nvram_match("boot_hw_model", "E100")){
1450 if (nvram_match("boot_hw_model", "M10") || nvram_match("boot_hw_model", "M20")){
1453 features
= SUP_SES
| SUP_80211N
| SUP_WHAM_LED
;
1454 if (!nvram_match("t_fix1", (char *)name
)) {
1455 nvram_set("lan_ifnames", "vlan1 eth1");
1456 nvram_set("wan_ifnameX", "vlan2");
1457 nvram_set("wl_ifname", "eth1");
1462 name
= nvram_match("boardrev", "0x1307") ? "E2000" : "WRT320N";
1463 features
= SUP_SES
| SUP_80211N
| SUP_WHAM_LED
| SUP_1000ET
;
1464 if (!nvram_match("t_fix1", (char *)name
)) {
1465 nvram_set("lan_ifnames", "vlan1 eth1");
1466 nvram_set("wan_ifnameX", "vlan2");
1467 nvram_set("wl_ifname", "eth1");
1470 case MODEL_WRT610Nv2
:
1472 name
= nvram_match("boot_hw_model", "E300") ? "E3000" : "WRT610N v2";
1473 features
= SUP_SES
| SUP_80211N
| SUP_WHAM_LED
| SUP_1000ET
;
1475 nvram_set("usb_uhci", "-1");
1477 if (!nvram_match("t_fix1", (char *)name
)) {
1478 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1479 nvram_set("wan_ifnameX", "vlan2");
1480 nvram_set("wl_ifname", "eth1");
1486 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
;
1488 nvram_set("usb_uhci", "-1");
1490 if (!nvram_match("t_fix1", (char *)name
)) {
1491 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1492 nvram_set("wan_ifnameX", "vlan2");
1493 nvram_set("wl_ifname", "eth1");
1496 #endif // CONFIG_BCMWL5
1501 // The 330gE has only one wired port which can act either as WAN or LAN.
1502 // Failsafe mode is to have it start as a LAN port so you can get an IP
1503 // address via DHCP and access the router config page.
1504 if (!nvram_match("t_fix1", (char *)name
)) {
1505 nvram_set("wl_ifname", "eth1");
1506 nvram_set("lan_ifnames", "eth1");
1507 nvram_set("wan_ifnameX", "eth0");
1508 nvram_set("wan_islan", "1");
1509 nvram_set("wan_proto", "disabled");
1512 case MODEL_WL500GPv2
:
1514 name
= "WL-500gP v2";
1517 nvram_set("usb_uhci", "-1");
1525 nvram_set("usb_uhci", "-1");
1530 name
= "WL-500g Deluxe";
1531 // features = SUP_SES;
1533 nvram_set("usb_ohci", "-1");
1535 if (!nvram_match("t_fix1", (char *)name
)) {
1536 nvram_set("wl_ifname", "eth1");
1537 nvram_set("lan_ifnames", "vlan0 eth1");
1538 nvram_set("wan_ifnameX", "vlan1");
1539 nvram_unset("wl0gpio0");
1546 if (!nvram_match("t_fix1", (char *)name
)) {
1547 nvram_set("wan_ifnameX", "vlan1");
1548 nvram_set("wl_ifname", "eth1");
1553 name
= "ZXV10 H618B";
1554 features
= SUP_SES
| SUP_AOSS_LED
;
1556 case MODEL_WL1600GL
:
1561 #endif // WL_BSS_INFO_VERSION >= 108
1562 case MODEL_WZRG300N
:
1565 features
= SUP_SES
| SUP_AOSS_LED
| SUP_BRAU
| SUP_80211N
;
1567 case MODEL_WRT160Nv1
:
1570 name
= (model
== MODEL_WRT300N
) ? "WRT300N v1" : "WRT160N v1";
1571 features
= SUP_SES
| SUP_80211N
;
1572 if (!nvram_match("t_fix1", (char *)name
)) {
1573 nvram_set("wan_ifnameX", "eth1");
1574 nvram_set("lan_ifnames", "eth0 eth2");
1577 case MODEL_WRT310Nv1
:
1579 name
= "WRT310N v1";
1580 features
= SUP_SES
| SUP_80211N
| SUP_WHAM_LED
| SUP_1000ET
;
1581 if (!nvram_match("t_fix1", (char *)name
)) {
1582 nvram_set("lan_ifnames", "vlan1 eth1");
1583 nvram_set("wan_ifnameX", "vlan2");
1584 nvram_set("wl_ifname", "eth1");
1590 nvram_set("t_fix1", name
);
1591 if (ver
&& strcmp(ver
, "")) {
1592 sprintf(s
, "%s %s v%s", mfr
, name
, ver
);
1594 sprintf(s
, "%s %s", mfr
, name
);
1598 snprintf(s
, sizeof(s
), "%s %d/%s/%s/%s/%s", mfr
, check_hw_type(),
1599 nvram_safe_get("boardtype"), nvram_safe_get("boardnum"), nvram_safe_get("boardrev"), nvram_safe_get("boardflags"));
1602 nvram_set("t_model_name", s
);
1604 nvram_set("pa0maxpwr", "400"); // allow Tx power up tp 400 mW, needed for ND only
1606 sprintf(s
, "0x%lX", features
);
1607 nvram_set("t_features", s
);
1610 note: set wan_ifnameX if wan_ifname needs to be overriden
1613 if (nvram_is_empty("wan_ifnameX")) {
1615 nvram_set("wan_ifnameX", ((strtoul(nvram_safe_get("boardflags"), NULL
, 0) & BFL_ENETVLAN
) ||
1616 (check_hw_type() == HW_BCM4712
)) ? "vlan1" : "eth1");
1618 p
= nvram_safe_get("wan_ifname");
1619 if ((*p
== 0) || (nvram_match("wl_ifname", p
))) {
1620 p
= ((strtoul(nvram_safe_get("boardflags"), NULL
, 0) & BFL_ENETVLAN
) ||
1621 (check_hw_type() == HW_BCM4712
)) ? "vlan1" : "eth1";
1623 nvram_set("wan_ifnameX", p
);
1627 //!!TB - do not force country code here to allow nvram override
1628 //nvram_set("wl_country", "JP");
1629 //nvram_set("wl_country_code", "JP");
1630 nvram_set("wan_get_dns", "");
1631 nvram_set("wan_get_domain", "");
1632 nvram_set("ppp_get_ip", "");
1633 nvram_set("action_service", "");
1634 nvram_set("jffs2_format", "0");
1635 nvram_set("rrules_radio", "-1");
1636 nvram_unset("https_crt_gen");
1637 nvram_unset("log_wmclear");
1639 nvram_set("ipv6_get_dns", "");
1641 #ifdef TCONFIG_MEDIA_SERVER
1642 nvram_unset("ms_rescan");
1644 if (nvram_get_int("http_id_gen") == 1) nvram_unset("http_id");
1646 nvram_unset("sch_rboot_last");
1647 nvram_unset("sch_rcon_last");
1648 nvram_unset("sch_c1_last");
1649 nvram_unset("sch_c2_last");
1650 nvram_unset("sch_c3_last");
1652 nvram_set("brau_state", "");
1653 if ((features
& SUP_BRAU
) == 0) nvram_set("script_brau", "");
1654 if ((features
& SUP_SES
) == 0) nvram_set("sesx_script", "");
1656 if ((features
& SUP_1000ET
) == 0) nvram_set("jumbo_frame_enable", "0");
1658 // compatibility with old versions
1659 if (nvram_match("wl_net_mode", "disabled")) {
1660 nvram_set("wl_radio", "0");
1661 nvram_set("wl_net_mode", "mixed");
1667 /* Get the special files from nvram and copy them to disc.
1668 * These were files saved with "nvram setfile2nvram <filename>".
1669 * Better hope that they were saved with full pathname.
1671 static void load_files_from_nvram(void)
1675 char buf
[NVRAM_SPACE
];
1677 if (nvram_getall(buf
, sizeof(buf
)) != 0)
1680 for (name
= buf
; *name
; name
+= strlen(name
) + 1) {
1681 if (strncmp(name
, "FILE:", 5) == 0) { /* This special name marks a file to get. */
1682 if ((cp
= strchr(name
, '=')) == NULL
)
1685 syslog(LOG_INFO
, "Loading file '%s' from nvram", name
+ 5);
1686 nvram_nvram2file(name
, name
+ 5);
1687 if (memcmp(".autorun", cp
- 8, 9) == 0)
1691 /* Start any autorun files that may have been loaded into one of the standard places. */
1693 run_nvscript(".autorun", NULL
, 3);
1696 #if defined(LINUX26) && defined(TCONFIG_USB)
1697 static inline void tune_min_free_kbytes(void)
1699 struct sysinfo info
;
1701 memset(&info
, 0, sizeof(struct sysinfo
));
1703 if (info
.totalram
>= 55 * 1024 * 1024) {
1704 // If we have 64MB+ RAM, tune min_free_kbytes
1705 // to reduce page allocation failure errors.
1706 f_write_string("/proc/sys/vm/min_free_kbytes", "8192", 0, 0);
1711 static void sysinit(void)
1713 static int noconsole
= 0;
1714 static const time_t tm
= 0;
1722 mount("proc", "/proc", "proc", 0, NULL
);
1723 mount("tmpfs", "/tmp", "tmpfs", 0, NULL
);
1726 mount("devfs", "/dev", "tmpfs", MS_MGC_VAL
| MS_NOATIME
, NULL
);
1727 mknod("/dev/null", S_IFCHR
| 0666, makedev(1, 3));
1728 mknod("/dev/console", S_IFCHR
| 0600, makedev(5, 1));
1729 mount("sysfs", "/sys", "sysfs", MS_MGC_VAL
, NULL
);
1730 mkdir("/dev/shm", 0777);
1731 mkdir("/dev/pts", 0777);
1732 mknod("/dev/pts/ptmx", S_IRWXU
|S_IFCHR
, makedev(5, 2));
1733 mknod("/dev/pts/0", S_IRWXU
|S_IFCHR
, makedev(136, 0));
1734 mknod("/dev/pts/1", S_IRWXU
|S_IFCHR
, makedev(136, 1));
1735 mount("devpts", "/dev/pts", "devpts", MS_MGC_VAL
, NULL
);
1738 if (console_init()) noconsole
= 1;
1742 static const char *mkd
[] = {
1743 "/tmp/etc", "/tmp/var", "/tmp/home", "/tmp/mnt",
1744 "/tmp/splashd", //!!Victek
1745 "/tmp/share", "/var/webmon", // !!TB
1746 "/var/log", "/var/run", "/var/tmp", "/var/lib", "/var/lib/misc",
1747 "/var/spool", "/var/spool/cron", "/var/spool/cron/crontabs",
1748 "/tmp/var/wwwext", "/tmp/var/wwwext/cgi-bin", // !!TB - CGI support
1752 for (i
= 0; mkd
[i
]; ++i
) {
1753 mkdir(mkd
[i
], 0755);
1755 mkdir("/var/lock", 0777);
1756 mkdir("/var/tmp/dhcp", 0777);
1757 mkdir("/home/root", 0700);
1758 chmod("/tmp", 0777);
1759 f_write("/etc/hosts", NULL
, 0, 0, 0644); // blank
1760 f_write("/etc/fstab", NULL
, 0, 0, 0644); // !!TB - blank
1761 simple_unlock("cron");
1762 simple_unlock("firewall");
1763 simple_unlock("restrictions");
1766 if ((d
= opendir("/rom/etc")) != NULL
) {
1767 while ((de
= readdir(d
)) != NULL
) {
1768 if (de
->d_name
[0] == '.') continue;
1769 snprintf(s
, sizeof(s
), "%s/%s", "/rom/etc", de
->d_name
);
1770 snprintf(t
, sizeof(t
), "%s/%s", "/etc", de
->d_name
);
1775 symlink("/proc/mounts", "/etc/mtab");
1777 #ifdef TCONFIG_SAMBASRV
1778 if ((d
= opendir("/usr/codepages")) != NULL
) {
1779 while ((de
= readdir(d
)) != NULL
) {
1780 if (de
->d_name
[0] == '.') continue;
1781 snprintf(s
, sizeof(s
), "/usr/codepages/%s", de
->d_name
);
1782 snprintf(t
, sizeof(t
), "/usr/share/%s", de
->d_name
);
1790 eval("hotplug2", "--coldplug");
1793 static const char *dn
[] = {
1794 "null", "zero", "random", "urandom", "full", "ptmx", "nvram",
1797 for (i
= 0; dn
[i
]; ++i
) {
1798 snprintf(s
, sizeof(s
), "/dev/%s", dn
[i
]);
1801 chmod("/dev/gpio", 0660);
1804 set_action(ACT_IDLE
);
1806 for (i
= 0; defenv
[i
]; ++i
) {
1811 printf("\n\nHit ENTER for console...\n\n");
1818 // disable IPv6 by default on all interfaces
1819 f_write_string("/proc/sys/net/ipv6/conf/default/disable_ipv6", "1", 0, 0);
1822 for (i
= 0; i
< sizeof(fatalsigs
) / sizeof(fatalsigs
[0]); i
++) {
1823 signal(fatalsigs
[i
], handle_fatalsigs
);
1825 signal(SIGCHLD
, handle_reap
);
1827 #ifdef CONFIG_BCMWL5
1828 // ctf must be loaded prior to any other modules
1829 if (nvram_invmatch("ctf_disable", "1"))
1838 switch (hardware
= check_hw_type()) {
1840 modprobe("bcm57xx");
1851 eval("nvram", "defaults", "--initcheck");
1854 // set the packet size
1855 if (nvram_get_int("jumbo_frame_enable")) {
1856 // only set the size here - 'enable' flag is set by the driver
1857 // eval("et", "robowr", "0x40", "0x01", "0x1F"); // (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4)
1858 eval("et", "robowr", "0x40", "0x05", nvram_safe_get("jumbo_frame_size"));
1861 klogctl(8, NULL
, nvram_get_int("console_loglevel"));
1863 #if defined(LINUX26) && defined(TCONFIG_USB)
1864 tune_min_free_kbytes();
1867 set_host_domain_name();
1873 #ifdef CONFIG_BCMWL6
1877 if (!noconsole
) xstart("console");
1879 i
= nvram_get_int("sesx_led");
1880 led(LED_AMBER
, (i
& 1) != 0);
1881 led(LED_WHITE
, (i
& 2) != 0);
1882 led(LED_AOSS
, (i
& 4) != 0);
1883 led(LED_BRIDGE
, (i
& 8) != 0);
1887 int init_main(int argc
, char *argv
[])
1893 nvram_unset("debug_rc_svc");
1897 sigemptyset(&sigset
);
1898 for (i
= 0; i
< sizeof(initsigs
) / sizeof(initsigs
[0]); i
++) {
1899 sigaddset(&sigset
, initsigs
[i
]);
1901 sigprocmask(SIG_BLOCK
, &sigset
, NULL
);
1903 #if defined(DEBUG_NOISY)
1904 nvram_set("debug_logeval", "1");
1905 nvram_set("debug_cprintf", "1");
1906 nvram_set("debug_cprintf_file", "1");
1907 nvram_set("debug_ddns", "1");
1912 state
= SIGUSR2
; /* START */
1915 TRACE_PT("main loop signal/state=%d\n", state
);
1918 case SIGUSR1
: /* USER1: service handler */
1922 case SIGHUP
: /* RESTART */
1923 case SIGINT
: /* STOP */
1924 case SIGQUIT
: /* HALT */
1925 case SIGTERM
: /* REBOOT */
1927 unlink("/var/notice/sysup");
1929 if( nvram_match( "webmon_bkp", "1" ) )
1930 xstart( "/usr/sbin/webmon_bkp", "hourly" ); // make a copy before halt/reboot router
1932 run_nvscript("script_shut", NULL
, 10);
1940 if ((state
== SIGTERM
/* REBOOT */) ||
1941 (state
== SIGQUIT
/* HALT */)) {
1942 remove_storage_main(1);
1945 shutdn(state
== SIGTERM
/* REBOOT */);
1948 if (state
== SIGINT
/* STOP */) {
1952 // SIGHUP (RESTART) falls through
1954 case SIGUSR2
: /* START */
1955 SET_LED(RELEASE_WAN_CONTROL
);
1958 load_files_from_nvram();
1961 fd
= file_lock("usb"); // hold off automount processing
1964 xstart("/usr/sbin/mymotd", "init");
1965 run_nvscript("script_init", NULL
, 2);
1967 file_unlock(fd
); // allow to process usb hotplug events
1970 * On RESTART some partitions can stay mounted if they are busy at the moment.
1971 * In that case USB drivers won't unload, and hotplug won't kick off again to
1972 * remount those drives that actually got unmounted. Make sure to remount ALL
1973 * partitions here by simulating hotplug event.
1975 if (state
== SIGHUP
/* RESTART */)
1976 add_remove_usbhost("-1", 1);
1987 #ifdef CONFIG_BCMWL5
1989 /* Restart NAS one more time - for some reason without
1990 * this the new driver doesn't always bring WDS up.
1997 syslog(LOG_INFO
, "%s: Tomato %s", nvram_safe_get("t_model_name"), tomato_version
);
2000 notice_set("sysup", "");
2004 chld_reap(0); /* Periodically reap zombies. */
2006 sigwait(&sigset
, &state
);
2012 int reboothalt_main(int argc
, char *argv
[])
2014 int reboot
= (strstr(argv
[0], "reboot") != NULL
);
2015 puts(reboot
? "Rebooting..." : "Shutting down...");
2018 kill(1, reboot
? SIGTERM
: SIGQUIT
);
2020 /* In the case we're hung, we'll get stuck and never actually reboot.
2021 * The only way out is to pull power.
2022 * So after 'reset_wait' seconds (default: 20), forcibly crash & restart.
2025 int wait
= nvram_get_int("reset_wait") ? : 20;
2026 if ((wait
< 10) || (wait
> 120)) wait
= 10;
2028 f_write("/proc/sysrq-trigger", "s", 1, 0 , 0); /* sync disks */
2030 puts("Still running... Doing machine reset.");
2032 f_write("/proc/sysrq-trigger", "s", 1, 0 , 0); /* sync disks */
2034 f_write("/proc/sysrq-trigger", "b", 1, 0 , 0); /* machine reset */