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("vlan2ports", "0 1 2 3 5*");
415 dirty
|= check_nv("vlan1ports", "4 5");
417 case MODEL_WNR2000v2
:
418 dirty
|= check_nv("vlan1ports", "4 3 2 1 5*");
419 dirty
|= check_nv("vlan2ports", "0 5");
421 case MODEL_RG200E_CA
:
422 dirty
|= check_nv("vlan0ports", "4 3 2 1 5*");
423 dirty
|= check_nv("vlan1ports", "0 5");
426 dirty
|= check_nv("vlan1ports", "4 5");
430 dirty
|= check_nv("vlan1ports", "1 2 3 4 5*");
431 dirty
|= check_nv("vlan2ports", "0 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");
466 dirty
|= check_nv("vlan1ports", "0 1 2 3 8*");
467 dirty
|= check_nv("vlan2ports", "4 8");
469 case MODEL_WRT160Nv3
:
470 if (nvram_match("vlan1ports", "1 2 3 4 5*")) {
471 // fix lan port numbering on CSE41, CSE51
472 dirty
|= check_nv("vlan1ports", "4 3 2 1 5*");
474 else if (nvram_match("vlan1ports", "1 2 3 4 8*")) {
476 dirty
|= check_nv("vlan1ports", "4 3 2 1 8*");
485 static void check_bootnv(void)
493 dirty
= check_nv("wl0_leddc", "0x640000") | check_nv("wl1_leddc", "0x640000");
497 dirty
|= check_nv("vlan0hwname", "et0");
498 dirty
|= check_nv("vlan1hwname", "et0");
501 dirty
|= check_nv("wl0gpio0", "130");
504 dirty
|= check_nv("wl0gpio1", "0x02");
508 // need to cleanup some variables...
509 if ((nvram_get("t_model") == NULL
) && (nvram_get("MyFirmwareVersion") != NULL
)) {
510 nvram_unset("MyFirmwareVersion");
511 nvram_set("restore_defaults", "1");
515 /* fix WL500W mac adresses for WAN port */
516 if (invalid_mac(nvram_get("et1macaddr"))) {
517 strcpy(mac
, nvram_safe_get("et0macaddr"));
519 dirty
|= check_nv("et1macaddr", mac
);
521 dirty
|= check_nv("wl0gpio0", "0x88");
524 dirty
|= check_nv("sdram_init", "0x0009"); // 32MB; defaults: 0x000b, 0x0009
525 dirty
|= check_nv("wl0gpio0", "136");
527 case MODEL_WL500GPv2
:
529 dirty
|= check_nv("wl0gpio1", "136");
532 dirty
|= check_nv("vlan0hwname", "et0");
533 dirty
|= check_nv("vlan1hwname", "et0");
534 dirty
|= check_nv("boardflags", "0x00000100"); // set BFL_ENETVLAN
535 nvram_unset("wl0gpio0");
538 if (strlen(nvram_safe_get("et0macaddr")) == 12 ||
539 strlen(nvram_safe_get("il0macaddr")) == 12) {
540 dirty
|= find_dir320_mac_addr();
542 if (nvram_get("vlan2hwname") != NULL
) {
543 nvram_unset("vlan2hwname");
546 dirty
|= check_nv("wandevs", "vlan1");
547 dirty
|= check_nv("vlan1hwname", "et0");
548 dirty
|= check_nv("wl0gpio0", "8");
549 dirty
|= check_nv("wl0gpio1", "0");
550 dirty
|= check_nv("wl0gpio2", "0");
551 dirty
|= check_nv("wl0gpio3", "0");
553 if (invalid_mac(nvram_get("et0macaddr"))) {
554 dirty
|= find_sercom_mac_addr();
557 case MODEL_WRT160Nv1
:
558 case MODEL_WRT310Nv1
:
560 dirty
|= check_nv("wl0gpio0", "8");
564 dirty
|= check_nv("boardflags", "0x00000710"); // needed to enable USB
565 dirty
|= check_nv("vlan2hwname", "et0");
566 dirty
|= check_nv("ledbh0", "7");
568 case MODEL_WNR3500LV2
:
569 dirty
|= check_nv("vlan2hwname", "et0");
571 case MODEL_WNR2000v2
:
572 dirty
|= check_nv("ledbh5", "8");
575 dirty
|= check_nv("reset_gpio", "5");
576 dirty
|= check_nv("ledbh0", "136");
577 dirty
|= check_nv("ledbh1", "11");
578 /* fall through, same as RT-N16 */
580 dirty
|= check_nv("vlan2hwname", "et0");
582 case MODEL_WRT610Nv2
:
583 dirty
|= check_nv("vlan2hwname", "et0");
584 dirty
|= check_nv("pci/1/1/ledbh2", "8");
585 dirty
|= check_nv("sb/1/ledbh1", "8");
586 if (invalid_mac(nvram_get("pci/1/1/macaddr"))) {
587 strcpy(mac
, nvram_safe_get("et0macaddr"));
589 dirty
|= check_nv("pci/1/1/macaddr", mac
);
596 case MODEL_F5D8235v3
:
597 if (nvram_match("sb/1/macaddr", nvram_safe_get("et0macaddr"))) {
598 strcpy(mac
, nvram_safe_get("et0macaddr"));
600 dirty
|= check_nv("sb/1/macaddr", mac
);
602 dirty
|= check_nv("pci/1/1/macaddr", mac
);
605 dirty
|= check_nv("vlan2hwname", "et0");
606 if (strncasecmp(nvram_safe_get("pci/1/1/macaddr"), "00:90:4c", 8) == 0 ||
607 strncasecmp(nvram_safe_get("sb/1/macaddr"), "00:90:4c", 8) == 0) {
608 strcpy(mac
, nvram_safe_get("et0macaddr"));
610 dirty
|= check_nv("sb/1/macaddr", mac
);
612 dirty
|= check_nv("pci/1/1/macaddr", mac
);
621 case MODEL_WRT160Nv3
:
622 dirty
|= check_nv("vlan2hwname", "et0");
627 if (strncmp(nvram_safe_get("pmon_ver"), "CFE", 3) != 0) return;
629 hardware
= check_hw_type();
630 if (!nvram_get("boardtype") ||
631 !nvram_get("boardnum") ||
632 !nvram_get("boardflags") ||
633 !nvram_get("clkfreq") ||
634 !nvram_get("os_flash_addr") ||
635 !nvram_get("dl_ram_addr") ||
636 !nvram_get("os_ram_addr") ||
637 !nvram_get("scratch") ||
638 !nvram_get("et0macaddr") ||
639 ((hardware
!= HW_BCM4704_BCM5325F
) && (!nvram_get("vlan0ports") || !nvram_get("vlan0hwname")))) {
640 _dprintf("Unable to find critical settings, erasing NVRAM\n");
645 dirty
|= check_nv("aa0", "3");
646 dirty
|= check_nv("wl0gpio0", "136");
647 dirty
|= check_nv("wl0gpio2", "0");
648 dirty
|= check_nv("wl0gpio3", "0");
649 dirty
|= check_nv("cctl", "0");
650 dirty
|= check_nv("ccode", "0");
654 /* Lower the DDR ram drive strength , the value will be stable for all boards
655 Latency 3 is more stable for all ddr 20050420 by honor */
656 dirty
|= check_nv("sdram_init", "0x010b");
657 dirty
|= check_nv("sdram_config", "0x0062");
658 if (!nvram_match("debug_clkfix", "0")) {
659 dirty
|= check_nv("clkfreq", "216");
662 nvram_set("sdram_ncdl", "0x0");
664 dirty
|= check_nv("pa0itssit", "62");
665 dirty
|= check_nv("pa0b0", "0x15eb");
666 dirty
|= check_nv("pa0b1", "0xfa82");
667 dirty
|= check_nv("pa0b2", "0xfe66");
668 //dirty |= check_nv("pa0maxpwr", "0x4e");
670 case HW_BCM5352E
: // G v4, GS v3, v4
671 dirty
|= check_nv("sdram_init", "0x010b");
672 dirty
|= check_nv("sdram_config", "0x0062");
674 nvram_set("sdram_ncdl", "0x0");
676 dirty
|= check_nv("pa0itssit", "62");
677 dirty
|= check_nv("pa0b0", "0x168b");
678 dirty
|= check_nv("pa0b1", "0xfabf");
679 dirty
|= check_nv("pa0b2", "0xfeaf");
680 //dirty |= check_nv("pa0maxpwr", "0x4e");
683 dirty
|= check_nv("pa0itssit", "62");
684 dirty
|= check_nv("pa0b0", "0x1326");
685 dirty
|= check_nv("pa0b1", "0xFB51");
686 dirty
|= check_nv("pa0b2", "0xFE87");
687 //dirty |= check_nv("pa0maxpwr", "0x4e");
689 case HW_BCM4704_BCM5325F
:
693 dirty
|= check_nv("pa0itssit", "62");
694 dirty
|= check_nv("pa0b0", "0x170c");
695 dirty
|= check_nv("pa0b1", "0xfa24");
696 dirty
|= check_nv("pa0b2", "0xfe70");
697 //dirty |= check_nv("pa0maxpwr", "0x48");
704 dirty
|= init_vlan_ports();
708 REBOOT
: // do a simple reboot
715 static int init_nvram(void)
717 unsigned long features
;
727 sprintf(s
, "%d", model
);
728 nvram_set("t_model", s
);
737 name
= "WRT54G/GS/GL";
738 switch (check_hw_type()) {
740 nvram_set("gpio2", "adm_eecs");
741 nvram_set("gpio3", "adm_eesk");
742 nvram_unset("gpio4");
743 nvram_set("gpio5", "adm_eedi");
744 nvram_set("gpio6", "adm_rc");
747 nvram_unset("gpio2");
748 nvram_unset("gpio3");
749 nvram_unset("gpio4");
750 nvram_unset("gpio5");
751 nvram_unset("gpio6");
754 nvram_set("opo", "0x0008");
755 nvram_set("ag0", "0x02");
758 nvram_set("gpio2", "ses_led");
759 nvram_set("gpio3", "ses_led2");
760 nvram_set("gpio4", "ses_button");
761 features
= SUP_SES
| SUP_WHAM_LED
;
768 if (!nvram_match("t_fix1", (char *)name
)) {
769 nvram_set("lan_ifnames", "vlan0 eth1");
770 nvram_set("gpio2", "ses_button");
771 nvram_set("reset_gpio", "7");
773 nvram_set("pa0itssit", "62");
774 nvram_set("pa0b0", "0x1542");
775 nvram_set("pa0b1", "0xfacb");
776 nvram_set("pa0b2", "0xfec7");
777 //nvram_set("pa0maxpwr", "0x4c");
780 case MODEL_WRTSL54GS
:
783 features
= SUP_SES
| SUP_WHAM_LED
;
788 features
= SUP_SES
| SUP_AOSS_LED
| SUP_BRAU
;
791 case MODEL_WZRRSG54HP
:
794 features
= SUP_SES
| SUP_AOSS_LED
| SUP_HPAMP
;
796 case MODEL_WZRRSG54HP
:
797 name
= "WZR-RS-G54HP";
804 features
= SUP_SES
| SUP_AOSS_LED
| SUP_BRAU
| SUP_HPAMP
;
808 bf
= strtoul(nvram_safe_get("boardflags"), NULL
, 0);
814 if (nvram_match("wlx_hpamp", "")) {
815 if (nvram_get_int("wl_txpwr") > 10) nvram_set("wl_txpwr", "10");
816 nvram_set("wlx_hpamp", "1");
817 nvram_set("wlx_hperx", "0");
821 if (nvram_match("wlx_hpamp", "0")) {
827 if (nvram_match("wlx_hperx", "0")) {
834 sprintf(s
, "0x%lX", n
);
835 nvram_set("boardflags", s
);
839 syslog(LOG_WARNING
, "Unexpected: boardflag=%lX", bf
);
850 features
= SUP_SES
| SUP_AOSS_LED
;
852 case MODEL_WHR2A54G54
:
854 name
= "WHR2-A54G54";
855 features
= SUP_SES
| SUP_AOSS_LED
| SUP_BRAU
;
860 features
= SUP_SES
| SUP_AOSS_LED
;
865 features
= SUP_SES
| SUP_AOSS_LED
;
870 features
= SUP_SES
| SUP_AOSS_LED
;
880 features
= SUP_SES
| SUP_AOSS_LED
;
889 features
= SUP_NONVE
;
893 name
= "WR850G v2/v3";
894 features
= SUP_NONVE
;
901 nvram_set("usb_ohci", "-1");
903 if (!nvram_match("t_fix1", (char *)name
)) {
904 nvram_set("lan_ifnames", "vlan0 eth1 eth2 eth3"); // set to "vlan0 eth2" by DD-WRT; default: vlan0 eth1
910 features
= SUP_SES
| SUP_80211N
;
912 nvram_set("usb_ohci", "-1");
920 nvram_set("usb_uhci", "-1");
939 if (!nvram_match("t_fix1", (char *)name
)) {
940 nvram_set("lan_ifnames", "vlan0 eth1 eth2");
941 nvram_set("wl_ifname", "eth1");
942 nvram_set("wan_ifname", "none");
947 name
= "TrueMobile 2300";
956 #ifndef WL_BSS_INFO_VERSION
957 #error WL_BSS_INFO_VERSION
959 #if WL_BSS_INFO_VERSION >= 108
965 nvram_set("opo", "12");
971 features
= SUP_SES
| SUP_AOSS_LED
| SUP_BRAU
;
973 nvram_set("opo", "0x0008");
974 nvram_set("ag0", "0x0C");
980 features
= SUP_SES
| SUP_80211N
;
982 nvram_set("usb_uhci", "-1");
984 if (!nvram_match("t_fix1", (char *)name
)) {
985 nvram_set("lan_ifnames", "vlan0 eth1");
986 nvram_set("wan_ifnameX", "vlan1");
987 nvram_set("wl_ifname", "eth1");
993 features
= SUP_SES
| SUP_80211N
;
995 nvram_set("usb_uhci", "-1");
997 if (!nvram_match("t_fix1", (char *)name
)) {
998 nvram_set("lan_ifnames", "vlan0 eth1");
999 nvram_set("wan_ifnameX", "vlan1");
1000 nvram_set("wl_ifname", "eth1");
1003 case MODEL_RG200E_CA
:
1006 features
= SUP_SES
| SUP_80211N
;
1008 nvram_set("usb_uhci", "-1");
1010 if (!nvram_match("t_fix1", (char *)name
)) {
1011 nvram_set("lan_ifnames", "vlan0 eth1");
1012 nvram_set("wan_ifnameX", "vlan1");
1013 nvram_set("wl_ifname", "eth1");
1019 features
= SUP_SES
| SUP_80211N
;
1020 if (!nvram_match("t_fix1", (char *)name
)) {
1021 nvram_set("lan_ifnames", "vlan0 eth1");
1022 nvram_set("wan_ifnameX", "vlan1");
1023 nvram_set("wl_ifname", "eth1");
1029 features
= SUP_SES
| SUP_80211N
;
1031 nvram_set("usb_uhci", "-1");
1033 if (!nvram_match("t_fix1", (char *)name
)) {
1034 nvram_set("lan_ifnames", "vlan0 eth1");
1035 nvram_set("wan_ifnameX", "vlan1");
1036 nvram_set("wl_ifname", "eth1");
1042 features
= SUP_SES
| SUP_BRAU
| SUP_80211N
;
1043 if (!nvram_match("t_fix1", (char *)name
)) {
1044 nvram_set("lan_ifnames", "vlan0 eth1");
1045 nvram_set("wan_ifnameX", "vlan1");
1046 nvram_set("wl_ifname", "eth1");
1052 features
= SUP_80211N
;
1053 if (!nvram_match("t_fix1", (char *)name
)) {
1054 nvram_set("lan_ifnames", "vlan0 eth1");
1055 nvram_set("wan_ifnameX", "vlan1");
1056 nvram_set("wl_ifname", "eth1");
1062 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
;
1064 nvram_set("usb_uhci", "-1");
1066 if (!nvram_match("t_fix1", (char *)name
)) {
1067 nvram_set("lan_ifnames", "vlan1 eth1");
1068 nvram_set("wan_iface", "vlan2");
1069 nvram_set("wan_ifname", "vlan2");
1070 nvram_set("wan_ifnameX", "vlan2");
1071 nvram_set("wan_ifnames", "vlan2");
1072 nvram_set("wl_ifname", "eth1");
1078 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
;
1080 nvram_set("usb_uhci", "-1");
1082 if (!nvram_match("t_fix1", (char *)name
)) {
1083 nvram_set("lan_ifnames", "vlan1 eth1");
1084 nvram_set("wan_ifnameX", "vlan2");
1085 nvram_set("wl_ifname", "eth1");
1086 nvram_set("vlan_enable", "1");
1092 features
= SUP_SES
| SUP_80211N
;
1093 #if defined(LINUX26) && defined(TCONFIG_USBAP)
1094 if (nvram_get_int("usb_storage") == 1) nvram_set("usb_storage", "-1");
1096 if (!nvram_match("t_fix1", (char *)name
)) {
1097 #ifdef TCONFIG_USBAP
1098 nvram_set("lan_ifnames", "vlan2 eth1 eth2");
1099 nvram_set("landevs", "vlan2 wl0 wl1");
1100 nvram_set("wl1_ifname", "eth2");
1102 nvram_set("lan_ifnames", "vlan2 eth1");
1103 nvram_set("landevs", "vlan2 wl0");
1105 nvram_set("wl_ifname", "eth1");
1106 nvram_set("wl0_ifname", "eth1");
1107 nvram_set("wan_ifnameX", "vlan1");
1108 nvram_set("wandevs", "vlan1");
1109 nvram_unset("vlan0ports");
1115 features
= SUP_SES
| SUP_80211N
;
1116 #if defined(LINUX26) && defined(TCONFIG_USBAP)
1117 if (nvram_get_int("usb_storage") == 1) nvram_set("usb_storage", "-1");
1119 if (!nvram_match("t_fix1", (char *)name
)) {
1120 #ifdef TCONFIG_USBAP
1121 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1122 nvram_set("landevs", "vlan1 wl0 wl1");
1123 nvram_set("wl0_ifname", "wl0");
1124 nvram_set("wl1_ifname", "wl1");
1126 nvram_set("lan_ifnames", "vlan1 eth1");
1127 nvram_set("landevs", "vlan1 wl0");
1129 nvram_set("wl_ifname", "eth1");
1130 nvram_set("wan_ifnameX", "vlan2");
1131 nvram_set("wandevs", "vlan2");
1132 nvram_set("vlan2hwname", "et0");
1133 nvram_set("gpio7", "wps_led");
1134 nvram_set("gpio8", "usb_led");
1135 nvram_set("gpio10", "wlan_button");
1136 nvram_set("gpio20", "wps_button");
1137 nvram_set("gpio21", "reset_button");
1138 nvram_set("gpio22", "wombo_reset");
1139 nvram_set("clkfreq", "500,200,100");
1140 nvram_set("sdram_init", "0x0000");
1141 nvram_set("xtalfreq", "20000");
1142 nvram_set("boot_wait", "on");
1143 nvram_set("wait_time", "3");
1144 nvram_set("boardflags2", "0x0");
1145 nvram_set("boardpwrctl", "0xC00");
1146 nvram_set("boardtype", "0x0550");
1147 nvram_set("watchdog", "0");
1153 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
;
1155 nvram_set("usb_uhci", "-1");
1156 #if defined(LINUX26) && defined(TCONFIG_USB_EXTRAS)
1157 if (nvram_get_int("usb_mmc") == -1) nvram_set("usb_mmc", "0");
1160 if (!nvram_match("t_fix1", (char *)name
)) {
1161 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1162 nvram_set("wan_ifnameX", "vlan2");
1163 nvram_set("wl_ifnames", "eth1 eth2");
1164 nvram_set("landevs", "vlan1 wl0 wl1");
1165 nvram_set("wandevs", "vlan2");
1166 #if defined(LINUX26) && defined(TCONFIG_USB)
1167 nvram_set("usb_noled", "1-1.4"); /* SD/MMC Card */
1171 case MODEL_WNR3500L
:
1173 name
= "WNR3500L/U/v2";
1174 features
= SUP_SES
| SUP_AOSS_LED
| SUP_80211N
| SUP_1000ET
;
1175 if (!nvram_match("t_fix1", (char *)name
)) {
1176 nvram_set("sromrev", "3");
1177 nvram_set("lan_ifnames", "vlan1 eth1");
1178 nvram_set("wan_ifnameX", "vlan2");
1179 nvram_set("wl_ifname", "eth1");
1182 case MODEL_WNR3500LV2
:
1184 name
= "WNR3500L v2";
1185 features
= SUP_SES
| SUP_AOSS_LED
| SUP_80211N
| SUP_1000ET
;
1186 if (!nvram_match("t_fix1", (char *)name
)) {
1187 nvram_set("lan_ifnames", "vlan1 eth1");
1188 nvram_set("wan_ifnameX", "vlan2");
1189 nvram_set("wl_ifname", "eth1");
1192 case MODEL_WNR2000v2
:
1194 name
= "WNR2000 v2";
1195 features
= SUP_SES
| SUP_AOSS_LED
| SUP_80211N
;
1196 if (!nvram_match("t_fix1", (char *)name
)) {
1197 nvram_set("lan_ifnames", "vlan0 eth1");
1198 nvram_set("wan_ifnameX", "vlan1");
1199 nvram_set("wl_ifname", "eth1");
1206 case MODEL_F5D8235v3
:
1208 features
= SUP_SES
| SUP_80211N
;
1211 name
= "Share Max N300 (F7D3301/F7D7301) v1";
1214 name
= "Share N300 (F7D3302/F7D7302) v1";
1217 name
= "Play Max / N600 HD (F7D4301/F7D8301) v1";
1220 name
= "Play N600 (F7D4302/F7D8302) v1";
1222 case MODEL_F5D8235v3
:
1223 name
= "N F5D8235-4 v3";
1227 nvram_set("usb_uhci", "-1");
1229 if (!nvram_match("t_fix1", (char *)name
)) {
1230 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1231 nvram_set("wan_ifnameX", "vlan2");
1232 nvram_set("landevs", "vlan1 wl0 wl1");
1233 nvram_set("wandevs", "vlan2");
1239 name
= nvram_safe_get("boot_hw_model");
1240 ver
= nvram_safe_get("boot_hw_ver");
1241 features
= SUP_SES
| SUP_80211N
;
1242 if (!nvram_match("t_fix1", (char *)name
)) {
1243 nvram_set("lan_ifnames", "vlan1 eth1");
1244 nvram_set("wan_ifnameX", "vlan2");
1245 nvram_set("wl_ifname", "eth1");
1250 name
= nvram_safe_get("boot_hw_model");
1251 ver
= nvram_safe_get("boot_hw_ver");
1252 features
= SUP_SES
| SUP_80211N
;
1254 nvram_set("usb_uhci", "-1");
1256 if (!nvram_match("t_fix1", (char *)name
)) {
1257 nvram_set("lan_ifnames", "vlan1 eth1");
1258 nvram_set("wan_ifnameX", "vlan2");
1259 nvram_set("wl_ifname", "eth1");
1264 name
= nvram_safe_get("boot_hw_model");
1265 ver
= nvram_safe_get("boot_hw_ver");
1266 features
= SUP_SES
| SUP_80211N
;
1267 #if defined(LINUX26) && defined(TCONFIG_USBAP)
1268 if (nvram_get_int("usb_storage") == 1) nvram_set("usb_storage", "-1");
1270 if (!nvram_match("t_fix1", (char *)name
)) {
1271 #ifdef TCONFIG_USBAP
1272 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1273 nvram_set("landevs", "vlan1 wl0 wl1");
1274 nvram_set("wl0_ifname", "eth1");
1275 nvram_set("wl1_ifname", "eth2");
1277 nvram_set("lan_ifnames", "vlan1 eth1");
1278 nvram_set("landevs", "vlan1 wl0");
1280 nvram_set("wan_ifnameX", "vlan2");
1281 nvram_set("wl_ifname", "eth1");
1287 name
= nvram_safe_get("boot_hw_model");
1288 ver
= nvram_safe_get("boot_hw_ver");
1289 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
;
1291 nvram_set("usb_uhci", "-1");
1293 if (!nvram_match("t_fix1", (char *)name
)) {
1294 #ifdef TCONFIG_USBAP
1295 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1296 nvram_set("landevs", "vlan1 wl0 wl1");
1297 nvram_set("wl0_ifname", "eth1");
1298 nvram_set("wl1_ifname", "eth2");
1300 nvram_set("lan_ifnames", "vlan1 eth1");
1301 nvram_set("landevs", "vlan1 wl0");
1303 nvram_set("wl_ifname", "eth1");
1304 nvram_set("wan_ifnameX", "vlan2");
1308 case MODEL_WRT160Nv3
:
1309 // same as M10, M20, WRT310Nv2, E1000v1
1311 name
= nvram_safe_get("boot_hw_model");
1312 ver
= nvram_safe_get("boot_hw_ver");
1313 if (nvram_match("boot_hw_model", "E100")){
1316 if (nvram_match("boot_hw_model", "M10") || nvram_match("boot_hw_model", "M20")){
1319 features
= SUP_SES
| SUP_80211N
| SUP_WHAM_LED
;
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");
1328 name
= nvram_match("boardrev", "0x1307") ? "E2000" : "WRT320N";
1329 features
= SUP_SES
| SUP_80211N
| SUP_WHAM_LED
| SUP_1000ET
;
1330 if (!nvram_match("t_fix1", (char *)name
)) {
1331 nvram_set("lan_ifnames", "vlan1 eth1");
1332 nvram_set("wan_ifnameX", "vlan2");
1333 nvram_set("wl_ifname", "eth1");
1336 case MODEL_WRT610Nv2
:
1338 name
= nvram_match("boot_hw_model", "E300") ? "E3000" : "WRT610N v2";
1339 features
= SUP_SES
| SUP_80211N
| SUP_WHAM_LED
| SUP_1000ET
;
1341 nvram_set("usb_uhci", "-1");
1343 if (!nvram_match("t_fix1", (char *)name
)) {
1344 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1345 nvram_set("wan_ifnameX", "vlan2");
1346 nvram_set("wl_ifname", "eth1");
1352 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
;
1354 nvram_set("usb_uhci", "-1");
1356 if (!nvram_match("t_fix1", (char *)name
)) {
1357 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1358 nvram_set("wan_ifnameX", "vlan2");
1359 nvram_set("wl_ifname", "eth1");
1362 #endif // CONFIG_BCMWL5
1367 // The 330gE has only one wired port which can act either as WAN or LAN.
1368 // Failsafe mode is to have it start as a LAN port so you can get an IP
1369 // address via DHCP and access the router config page.
1370 if (!nvram_match("t_fix1", (char *)name
)) {
1371 nvram_set("wl_ifname", "eth1");
1372 nvram_set("lan_ifnames", "eth1");
1373 nvram_set("wan_ifnameX", "eth0");
1374 nvram_set("wan_islan", "1");
1375 nvram_set("wan_proto", "disabled");
1378 case MODEL_WL500GPv2
:
1380 name
= "WL-500gP v2";
1383 nvram_set("usb_uhci", "-1");
1391 nvram_set("usb_uhci", "-1");
1396 name
= "WL-500g Deluxe";
1397 // features = SUP_SES;
1399 nvram_set("usb_ohci", "-1");
1401 if (!nvram_match("t_fix1", (char *)name
)) {
1402 nvram_set("wl_ifname", "eth1");
1403 nvram_set("lan_ifnames", "vlan0 eth1");
1404 nvram_set("wan_ifnameX", "vlan1");
1405 nvram_unset("wl0gpio0");
1412 if (!nvram_match("t_fix1", (char *)name
)) {
1413 nvram_set("wan_ifnameX", "vlan1");
1414 nvram_set("wl_ifname", "eth1");
1419 name
= "ZXV10 H618B";
1420 features
= SUP_SES
| SUP_AOSS_LED
;
1422 case MODEL_WL1600GL
:
1427 #endif // WL_BSS_INFO_VERSION >= 108
1428 case MODEL_WZRG300N
:
1431 features
= SUP_SES
| SUP_AOSS_LED
| SUP_BRAU
| SUP_80211N
;
1433 case MODEL_WRT160Nv1
:
1436 name
= (model
== MODEL_WRT300N
) ? "WRT300N v1" : "WRT160N v1";
1437 features
= SUP_SES
| SUP_80211N
;
1438 if (!nvram_match("t_fix1", (char *)name
)) {
1439 nvram_set("wan_ifnameX", "eth1");
1440 nvram_set("lan_ifnames", "eth0 eth2");
1443 case MODEL_WRT310Nv1
:
1445 name
= "WRT310N v1";
1446 features
= SUP_SES
| SUP_80211N
| SUP_WHAM_LED
| SUP_1000ET
;
1447 if (!nvram_match("t_fix1", (char *)name
)) {
1448 nvram_set("lan_ifnames", "vlan1 eth1");
1449 nvram_set("wan_ifnameX", "vlan2");
1450 nvram_set("wl_ifname", "eth1");
1456 nvram_set("t_fix1", name
);
1457 /* Don't show the version information if it's empty (null or empty string) */
1458 if (ver
== NULL
|| strcmp(ver
, "") == 0) {
1459 sprintf(s
, "%s %s", mfr
, name
);
1461 sprintf(s
, "%s %s v%s", mfr
, name
, ver
);
1465 snprintf(s
, sizeof(s
), "%s %d/%s/%s/%s/%s", mfr
, check_hw_type(),
1466 nvram_safe_get("boardtype"), nvram_safe_get("boardnum"), nvram_safe_get("boardrev"), nvram_safe_get("boardflags"));
1470 nvram_set("t_model_name", s
);
1472 nvram_set("pa0maxpwr", "400"); // allow Tx power up tp 400 mW, needed for ND only
1474 sprintf(s
, "0x%lX", features
);
1475 nvram_set("t_features", s
);
1478 note: set wan_ifnameX if wan_ifname needs to be overriden
1481 if (nvram_is_empty("wan_ifnameX")) {
1483 nvram_set("wan_ifnameX", ((strtoul(nvram_safe_get("boardflags"), NULL
, 0) & BFL_ENETVLAN
) ||
1484 (check_hw_type() == HW_BCM4712
)) ? "vlan1" : "eth1");
1486 p
= nvram_safe_get("wan_ifname");
1487 if ((*p
== 0) || (nvram_match("wl_ifname", p
))) {
1488 p
= ((strtoul(nvram_safe_get("boardflags"), NULL
, 0) & BFL_ENETVLAN
) ||
1489 (check_hw_type() == HW_BCM4712
)) ? "vlan1" : "eth1";
1491 nvram_set("wan_ifnameX", p
);
1495 //!!TB - do not force country code here to allow nvram override
1496 //nvram_set("wl_country", "JP");
1497 //nvram_set("wl_country_code", "JP");
1498 nvram_set("wan_get_dns", "");
1499 nvram_set("wan_get_domain", "");
1500 nvram_set("ppp_get_ip", "");
1501 nvram_set("action_service", "");
1502 nvram_set("jffs2_format", "0");
1503 nvram_set("rrules_radio", "-1");
1504 nvram_unset("https_crt_gen");
1505 nvram_unset("log_wmclear");
1507 nvram_set("ipv6_get_dns", "");
1509 #ifdef TCONFIG_MEDIA_SERVER
1510 nvram_unset("ms_rescan");
1512 if (nvram_get_int("http_id_gen") == 1) nvram_unset("http_id");
1514 nvram_unset("sch_rboot_last");
1515 nvram_unset("sch_rcon_last");
1516 nvram_unset("sch_c1_last");
1517 nvram_unset("sch_c2_last");
1518 nvram_unset("sch_c3_last");
1520 nvram_set("brau_state", "");
1521 if ((features
& SUP_BRAU
) == 0) nvram_set("script_brau", "");
1522 if ((features
& SUP_SES
) == 0) nvram_set("sesx_script", "");
1524 if ((features
& SUP_1000ET
) == 0) nvram_set("jumbo_frame_enable", "0");
1526 // compatibility with old versions
1527 if (nvram_match("wl_net_mode", "disabled")) {
1528 nvram_set("wl_radio", "0");
1529 nvram_set("wl_net_mode", "mixed");
1535 /* Get the special files from nvram and copy them to disc.
1536 * These were files saved with "nvram setfile2nvram <filename>".
1537 * Better hope that they were saved with full pathname.
1539 static void load_files_from_nvram(void)
1543 char buf
[NVRAM_SPACE
];
1545 if (nvram_getall(buf
, sizeof(buf
)) != 0)
1548 for (name
= buf
; *name
; name
+= strlen(name
) + 1) {
1549 if (strncmp(name
, "FILE:", 5) == 0) { /* This special name marks a file to get. */
1550 if ((cp
= strchr(name
, '=')) == NULL
)
1553 syslog(LOG_INFO
, "Loading file '%s' from nvram", name
+ 5);
1554 nvram_nvram2file(name
, name
+ 5);
1555 if (memcmp(".autorun", cp
- 8, 9) == 0)
1559 /* Start any autorun files that may have been loaded into one of the standard places. */
1561 run_nvscript(".autorun", NULL
, 3);
1564 #if defined(LINUX26) && defined(TCONFIG_USB)
1565 static inline void tune_min_free_kbytes(void)
1567 struct sysinfo info
;
1569 memset(&info
, 0, sizeof(struct sysinfo
));
1571 if (info
.totalram
>= 55 * 1024 * 1024) {
1572 // If we have 64MB+ RAM, tune min_free_kbytes
1573 // to reduce page allocation failure errors.
1574 f_write_string("/proc/sys/vm/min_free_kbytes", "8192", 0, 0);
1579 static void sysinit(void)
1581 static int noconsole
= 0;
1582 static const time_t tm
= 0;
1591 mount("proc", "/proc", "proc", 0, NULL
);
1592 mount("tmpfs", "/tmp", "tmpfs", 0, NULL
);
1595 mount("devfs", "/dev", "tmpfs", MS_MGC_VAL
| MS_NOATIME
, NULL
);
1596 mknod("/dev/null", S_IFCHR
| 0666, makedev(1, 3));
1597 mknod("/dev/console", S_IFCHR
| 0600, makedev(5, 1));
1598 mount("sysfs", "/sys", "sysfs", MS_MGC_VAL
, NULL
);
1599 mkdir("/dev/shm", 0777);
1600 mkdir("/dev/pts", 0777);
1601 mknod("/dev/pts/ptmx", S_IRWXU
|S_IFCHR
, makedev(5, 2));
1602 mknod("/dev/pts/0", S_IRWXU
|S_IFCHR
, makedev(136, 0));
1603 mknod("/dev/pts/1", S_IRWXU
|S_IFCHR
, makedev(136, 1));
1604 mount("devpts", "/dev/pts", "devpts", MS_MGC_VAL
, NULL
);
1607 if (console_init()) noconsole
= 1;
1611 static const char *mkd
[] = {
1612 "/tmp/etc", "/tmp/var", "/tmp/home", "/tmp/mnt",
1613 "/tmp/splashd", //!!Victek
1614 "/tmp/share", "/var/webmon", // !!TB
1615 "/var/log", "/var/log/nginx", "/var/run", "/var/tmp", "/var/lib", "/var/lib/misc",
1616 "/var/spool", "/var/spool/cron", "/var/spool/cron/crontabs",
1617 "/tmp/var/wwwext", "/tmp/var/wwwext/cgi-bin", // !!TB - CGI support
1621 for (i
= 0; mkd
[i
]; ++i
) {
1622 mkdir(mkd
[i
], 0755);
1624 mkdir("/var/lock", 0777);
1625 mkdir("/var/tmp/dhcp", 0777);
1626 mkdir("/home/root", 0700);
1627 chmod("/tmp", 0777);
1628 f_write("/etc/hosts", NULL
, 0, 0, 0644); // blank
1629 f_write("/etc/fstab", NULL
, 0, 0, 0644); // !!TB - blank
1630 simple_unlock("cron");
1631 simple_unlock("firewall");
1632 simple_unlock("restrictions");
1635 if ((d
= opendir("/rom/etc")) != NULL
) {
1636 while ((de
= readdir(d
)) != NULL
) {
1637 if (de
->d_name
[0] == '.') continue;
1638 snprintf(s
, sizeof(s
), "%s/%s", "/rom/etc", de
->d_name
);
1639 snprintf(t
, sizeof(t
), "%s/%s", "/etc", de
->d_name
);
1644 symlink("/proc/mounts", "/etc/mtab");
1646 #ifdef TCONFIG_SAMBASRV
1647 if ((d
= opendir("/usr/codepages")) != NULL
) {
1648 while ((de
= readdir(d
)) != NULL
) {
1649 if (de
->d_name
[0] == '.') continue;
1650 snprintf(s
, sizeof(s
), "/usr/codepages/%s", de
->d_name
);
1651 snprintf(t
, sizeof(t
), "/usr/share/%s", de
->d_name
);
1659 eval("hotplug2", "--coldplug");
1662 static const char *dn
[] = {
1663 "null", "zero", "random", "urandom", "full", "ptmx", "nvram",
1666 for (i
= 0; dn
[i
]; ++i
) {
1667 snprintf(s
, sizeof(s
), "/dev/%s", dn
[i
]);
1670 chmod("/dev/gpio", 0660);
1673 set_action(ACT_IDLE
);
1675 for (i
= 0; defenv
[i
]; ++i
) {
1680 printf("\n\nHit ENTER for console...\n\n");
1687 // disable IPv6 by default on all interfaces
1688 f_write_string("/proc/sys/net/ipv6/conf/default/disable_ipv6", "1", 0, 0);
1691 for (i
= 0; i
< sizeof(fatalsigs
) / sizeof(fatalsigs
[0]); i
++) {
1692 signal(fatalsigs
[i
], handle_fatalsigs
);
1694 signal(SIGCHLD
, handle_reap
);
1696 switch (model
= get_model()) {
1697 case MODEL_WR850GV1
:
1698 case MODEL_WR850GV2
:
1699 // need to cleanup some variables...
1700 if ((nvram_get("t_model") == NULL
) && (nvram_get("MyFirmwareVersion") != NULL
)) {
1701 nvram_unset("MyFirmwareVersion");
1702 nvram_set("restore_defaults", "1");
1707 #ifdef CONFIG_BCMWL5
1708 // ctf must be loaded prior to any other modules
1709 if (nvram_invmatch("ctf_disable", "1"))
1718 switch (hardware
= check_hw_type()) {
1720 modprobe("bcm57xx");
1731 eval("nvram", "defaults", "--initcheck");
1734 // set the packet size
1735 if (nvram_get_int("jumbo_frame_enable")) {
1736 // only set the size here - 'enable' flag is set by the driver
1737 // eval("et", "robowr", "0x40", "0x01", "0x1F"); // (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4)
1738 eval("et", "robowr", "0x40", "0x05", nvram_safe_get("jumbo_frame_size"));
1741 klogctl(8, NULL
, nvram_get_int("console_loglevel"));
1743 #if defined(LINUX26) && defined(TCONFIG_USB)
1744 tune_min_free_kbytes();
1747 set_host_domain_name();
1753 if (!noconsole
) xstart("console");
1755 i
= nvram_get_int("sesx_led");
1756 led(LED_AMBER
, (i
& 1) != 0);
1757 led(LED_WHITE
, (i
& 2) != 0);
1758 led(LED_AOSS
, (i
& 4) != 0);
1759 led(LED_BRIDGE
, (i
& 8) != 0);
1763 int init_main(int argc
, char *argv
[])
1769 nvram_unset("debug_rc_svc");
1773 sigemptyset(&sigset
);
1774 for (i
= 0; i
< sizeof(initsigs
) / sizeof(initsigs
[0]); i
++) {
1775 sigaddset(&sigset
, initsigs
[i
]);
1777 sigprocmask(SIG_BLOCK
, &sigset
, NULL
);
1779 #if defined(DEBUG_NOISY)
1780 nvram_set("debug_logeval", "1");
1781 nvram_set("debug_cprintf", "1");
1782 nvram_set("debug_cprintf_file", "1");
1783 nvram_set("debug_ddns", "1");
1788 state
= SIGUSR2
; /* START */
1791 TRACE_PT("main loop signal/state=%d\n", state
);
1794 case SIGUSR1
: /* USER1: service handler */
1798 case SIGHUP
: /* RESTART */
1799 case SIGINT
: /* STOP */
1800 case SIGQUIT
: /* HALT */
1801 case SIGTERM
: /* REBOOT */
1803 unlink("/var/notice/sysup");
1805 run_nvscript("script_shut", NULL
, 10);
1813 if ((state
== SIGTERM
/* REBOOT */) ||
1814 (state
== SIGQUIT
/* HALT */)) {
1815 remove_storage_main(1);
1818 shutdn(state
== SIGTERM
/* REBOOT */);
1821 if (state
== SIGINT
/* STOP */) {
1825 // SIGHUP (RESTART) falls through
1827 case SIGUSR2
: /* START */
1828 SET_LED(RELEASE_WAN_CONTROL
);
1831 load_files_from_nvram();
1834 fd
= file_lock("usb"); // hold off automount processing
1837 run_nvscript("script_init", NULL
, 2);
1839 file_unlock(fd
); // allow to process usb hotplug events
1842 * On RESTART some partitions can stay mounted if they are busy at the moment.
1843 * In that case USB drivers won't unload, and hotplug won't kick off again to
1844 * remount those drives that actually got unmounted. Make sure to remount ALL
1845 * partitions here by simulating hotplug event.
1847 if (state
== SIGHUP
/* RESTART */)
1848 add_remove_usbhost("-1", 1);
1859 #ifdef CONFIG_BCMWL5
1861 /* Restart NAS one more time - for some reason without
1862 * this the new driver doesn't always bring WDS up.
1869 syslog(LOG_INFO
, "%s: Tomato %s", nvram_safe_get("t_model_name"), tomato_version
);
1872 notice_set("sysup", "");
1876 chld_reap(0); /* Periodically reap zombies. */
1878 sigwait(&sigset
, &state
);
1884 int reboothalt_main(int argc
, char *argv
[])
1886 int reboot
= (strstr(argv
[0], "reboot") != NULL
);
1887 puts(reboot
? "Rebooting..." : "Shutting down...");
1890 kill(1, reboot
? SIGTERM
: SIGQUIT
);
1892 /* In the case we're hung, we'll get stuck and never actually reboot.
1893 * The only way out is to pull power.
1894 * So after 'reset_wait' seconds (default: 20), forcibly crash & restart.
1897 int wait
= nvram_get_int("reset_wait") ? : 20;
1898 if ((wait
< 10) || (wait
> 120)) wait
= 10;
1900 f_write("/proc/sysrq-trigger", "s", 1, 0 , 0); /* sync disks */
1902 puts("Still running... Doing machine reset.");
1904 f_write("/proc/sysrq-trigger", "s", 1, 0 , 0); /* sync disks */
1906 f_write("/proc/sysrq-trigger", "b", 1, 0 , 0); /* machine reset */