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 extern struct nvram_tuple router_defaults
[];
38 restore_defaults_module(char *prefix
)
40 struct nvram_tuple
*t
;
42 for (t
= router_defaults
; t
->name
; t
++) {
43 if(strncmp(t
->name
, prefix
, sizeof(prefix
))!=0) continue;
44 nvram_set(t
->name
, t
->value
);
49 restore_defaults(void)
51 struct nvram_tuple
*t
;
53 char prefix
[] = "usb_pathXXXXXXXXXXXXXXXXX_", tmp
[100];
57 /* Restore defaults if told to or OS has changed */
59 restore_defaults
= !nvram_match("restore_defaults", "0");
62 fprintf(stderr
, "\n## Restoring defaults... ##\n");
64 /* Restore defaults */
65 for (t
= router_defaults
; t
->name
; t
++) {
66 if (restore_defaults
|| !nvram_get(t
->name
)) {
67 nvram_set(t
->name
, t
->value
);
71 nvram_set("os_name", "linux");
72 nvram_set("os_version", tomato_version
);
73 nvram_set("os_date", tomato_buildtime
);
76 if (!nvram_match("extendno_org", nvram_safe_get("extendno")))
78 dbg("Reset TxBF settings...\n");
79 nvram_set("extendno_org", nvram_safe_get("extendno"));
80 nvram_set("wl0_txbf", "1");
81 nvram_set("wl1_txbf", "1");
82 nvram_set("wl0_itxbf", "0");
83 nvram_set("wl1_itxbf", "1");
90 static int fatalsigs
[] = {
101 static int initsigs
[] = {
111 static char *defenv
[] = {
114 "PATH=/usr/bin:/bin:/usr/sbin:/sbin",
120 /* Set terminal settings to reasonable defaults */
121 static void set_term(int fd
)
127 /* set control chars */
128 tty
.c_cc
[VINTR
] = 3; /* C-c */
129 tty
.c_cc
[VQUIT
] = 28; /* C-\ */
130 tty
.c_cc
[VERASE
] = 127; /* C-? */
131 tty
.c_cc
[VKILL
] = 21; /* C-u */
132 tty
.c_cc
[VEOF
] = 4; /* C-d */
133 tty
.c_cc
[VSTART
] = 17; /* C-q */
134 tty
.c_cc
[VSTOP
] = 19; /* C-s */
135 tty
.c_cc
[VSUSP
] = 26; /* C-z */
137 /* use line dicipline 0 */
140 /* Make it be sane */
141 tty
.c_cflag
&= CBAUD
|CBAUDEX
|CSIZE
|CSTOPB
|PARENB
|PARODD
;
142 tty
.c_cflag
|= CREAD
|HUPCL
|CLOCAL
;
146 tty
.c_iflag
= ICRNL
| IXON
| IXOFF
;
149 tty
.c_oflag
= OPOST
| ONLCR
;
153 ISIG
| ICANON
| ECHO
| ECHOE
| ECHOK
| ECHOCTL
| ECHOKE
| IEXTEN
;
155 tcsetattr(fd
, TCSANOW
, &tty
);
158 static int console_init(void)
163 ioctl(0, TIOCNOTTY
, 0);
170 if ((fd
= open(_PATH_CONSOLE
, O_RDWR
)) < 0) {
171 /* Avoid debug messages is redirected to socket packet if no exist a UART chip, added by honor, 2003-12-04 */
172 open("/dev/null", O_RDONLY
);
173 open("/dev/null", O_WRONLY
);
174 open("/dev/null", O_WRONLY
);
175 perror(_PATH_CONSOLE
);
182 ioctl(0, TIOCSCTTY
, 1);
183 tcsetpgrp(0, getpgrp());
190 * Waits for a file descriptor to change status or unblocked signal
191 * @param fd file descriptor
192 * @param timeout seconds to wait before timing out or 0 for no timeout
193 * @return 1 if descriptor changed status or 0 if timed out or -1 on error
195 static int waitfor(int fd
, int timeout
)
198 struct timeval tv
= { timeout
, 0 };
202 return select(fd
+ 1, &rfds
, NULL
, NULL
, (timeout
> 0) ? &tv
: NULL
);
205 static pid_t
run_shell(int timeout
, int nowait
)
210 /* Wait for user input */
211 if (waitfor(STDIN_FILENO
, timeout
) <= 0) return 0;
213 switch (pid
= fork()) {
218 /* Reset signal handlers set for parent process */
219 for (sig
= 0; sig
< (_NSIG
-1); sig
++)
220 signal(sig
, SIG_DFL
);
224 printf("\n\nTomato %s\n\n", tomato_version
);
226 /* Now run it. The new program will take over this PID,
227 * so nothing further in init.c should be run. */
228 execve(SHELL
, (char *[]) { SHELL
, NULL
}, defenv
);
230 /* We're still here? Some error happened. */
238 waitpid(pid
, NULL
, 0);
244 int console_main(int argc
, char *argv
[])
246 for (;;) run_shell(0, 0);
251 static void shutdn(int rb
)
257 _dprintf("shutdn rb=%d\n", rb
);
260 for (i
= 0; i
< sizeof(fatalsigs
) / sizeof(fatalsigs
[0]); i
++)
261 sigaddset(&ss
, fatalsigs
[i
]);
262 for (i
= 0; i
< sizeof(initsigs
) / sizeof(initsigs
[0]); i
++)
263 sigaddset(&ss
, initsigs
[i
]);
264 sigprocmask(SIG_BLOCK
, &ss
, NULL
);
266 for (i
= 30; i
> 0; --i
) {
267 if (((act
= check_action()) == ACT_IDLE
) || (act
== ACT_REBOOT
)) break;
268 _dprintf("Busy with %d. Waiting before shutdown... %d\n", act
, i
);
271 set_action(ACT_REBOOT
);
273 // Disconnect pppd - need this for PPTP/L2TP to finish gracefully
287 umount("/jffs"); // may hang if not
293 for (i
= 4; i
> 0; --i
) {
304 reboot(rb
? RB_AUTOBOOT
: RB_HALT_SYSTEM
);
311 static void handle_fatalsigs(int sig
)
313 _dprintf("fatal sig=%d\n", sig
);
317 /* Fixed the race condition & incorrect code by using sigwait()
318 * instead of pause(). But SIGCHLD is a problem, since other
319 * code: 1) messes with it and 2) depends on CHLD being caught so
320 * that the pid gets immediately reaped instead of left a zombie.
321 * Pidof still shows the pid, even though it's in zombie state.
322 * So this SIGCHLD handler reaps and then signals the mainline by
325 static void handle_reap(int sig
)
331 static int check_nv(const char *name
, const char *value
)
334 if (!nvram_match("manual_boot_nv", "1")) {
335 if (((p
= nvram_get(name
)) == NULL
) || (strcmp(p
, value
) != 0)) {
336 _dprintf("Error: Critical variable %s is invalid. Resetting.\n", name
);
337 nvram_set(name
, value
);
344 static inline int invalid_mac(const char *mac
)
346 return (!mac
|| !(*mac
) || strncasecmp(mac
, "00:90:4c", 8) == 0);
349 static int find_sercom_mac_addr(void)
352 unsigned char m
[6], s
[18];
354 sprintf(s
, MTD_DEV(%dro
), 0);
355 if ((fp
= fopen(s
, "rb"))) {
356 fseek(fp
, 0x1ffa0, SEEK_SET
);
357 fread(m
, sizeof(m
), 1, fp
);
359 sprintf(s
, "%02X:%02X:%02X:%02X:%02X:%02X",
360 m
[0], m
[1], m
[2], m
[3], m
[4], m
[5]);
361 nvram_set("et0macaddr", s
);
362 return !invalid_mac(s
);
367 static int find_dir320_mac_addr(void)
371 int i
, part
, size
, found
= 0;
373 if (!mtd_getinfo("board_data", &part
, &size
))
375 sprintf(s
, MTD_DEV(%dro
), part
);
377 if ((fp
= fopen(s
, "rb"))) {
378 buffer
= malloc(size
);
379 memset(buffer
, 0, size
);
380 fread(buffer
, size
, 1, fp
);
381 if (!memcmp(buffer
, "RGCFG1", 6)) {
382 for (i
= 6; i
< size
- 24; i
++) {
383 if (!memcmp(buffer
+ i
, "lanmac=", 7)) {
384 memcpy(s
, buffer
+ i
+ 7, 17);
386 nvram_set("et0macaddr", s
);
389 else if (!memcmp(buffer
+ i
, "wanmac=", 7)) {
390 memcpy(s
, buffer
+ i
+ 7, 17);
392 nvram_set("il0macaddr", s
);
395 nvram_set("et0macaddr", s
);
406 strcpy(s
, nvram_safe_get("wl0_hwaddr"));
408 nvram_set("et0macaddr", s
);
413 static int init_vlan_ports(void)
416 int model
= get_model();
420 switch (check_hw_type()) {
421 case HW_BCM5352E
: // G v4, GS v3, v4
422 dirty
|= check_nv("vlan0ports", "3 2 1 0 5*");
427 dirty
|= check_nv("vlan0ports", "0 5*");
428 dirty
|= check_nv("vlan1ports", "1 5");
429 dirty
|= check_nv("vlan_enable", "1");
433 case MODEL_WL500GPv2
:
436 if (nvram_match("vlan1ports", "0 5u")) // 520GU or 330GE or WL500GE?
437 dirty
|= check_nv("vlan1ports", "0 5");
438 else if (nvram_match("vlan1ports", "4 5u"))
439 dirty
|= check_nv("vlan1ports", "4 5");
442 dirty
|= check_nv("vlan0ports", "1 2 3 4 5*");
443 dirty
|= check_nv("vlan1ports", "0 5");
447 dirty
|= (nvram_get("vlan2ports") != NULL
);
448 nvram_unset("vlan2ports");
449 dirty
|= check_nv("vlan0ports", "1 2 3 4 5*");
450 dirty
|= check_nv("vlan1ports", "0 5");
452 case MODEL_WRT310Nv1
:
453 dirty
|= check_nv("vlan1ports", "1 2 3 4 8*");
454 dirty
|= check_nv("vlan2ports", "0 8");
457 dirty
|= check_nv("vlan0ports", "0 1 2 3 5*");
458 dirty
|= check_nv("vlan1ports", "4 5");
463 case MODEL_WNR3500LV2
:
466 dirty
|= check_nv("vlan1ports", "4 3 2 1 8*");
467 dirty
|= check_nv("vlan2ports", "0 8");
470 dirty
|= check_nv("vlan1ports", "1 2 3 4 8*");
471 dirty
|= check_nv("vlan2ports", "0 8");
472 dirty
|= check_nv("boot_wait", "on");
473 dirty
|= check_nv("wait_time", "5");
476 dirty
|= check_nv("vlan1ports", "1 2 3 4 8*");
477 dirty
|= check_nv("vlan2ports", "0 8");
478 dirty
|= check_nv("ledbh0", "11");
479 dirty
|= check_nv("ledbh1", "11");
480 dirty
|= check_nv("ledbh2", "11");
481 dirty
|= check_nv("ledbh11", "136");
482 // must flash tt through tftp.
483 dirty
|= check_nv("boot_wait", "on");
484 dirty
|= check_nv("wait_time", "5");
487 dirty
|= check_nv("vlan2ports", "0 1 2 3 5*");
488 dirty
|= check_nv("vlan1ports", "4 5");
491 dirty
|= check_nv("vlan1ports", "4 5");
492 dirty
|= check_nv("vlan2ports", "3 2 1 0 5*");
494 case MODEL_WNR2000v2
:
495 dirty
|= check_nv("vlan1ports", "4 3 2 1 5*");
496 dirty
|= check_nv("vlan2ports", "0 5");
500 dirty
|= check_nv("vlan1ports", "1 2 3 4 5*");
501 dirty
|= check_nv("vlan2ports", "0 5");
503 case MODEL_RG200E_CA
:
504 dirty
|= check_nv("vlan2ports", "0 5");
507 dirty
|= check_nv("vlan1ports", "4 5");
511 dirty
|= check_nv("vlan0ports", "1 2 3 4 5*");
512 dirty
|= check_nv("vlan1ports", "0 5");
517 dirty
|= check_nv("vlan0ports", "3 2 1 0 5*");
518 dirty
|= check_nv("vlan1ports", "4 5");
520 case MODEL_WRT610Nv2
:
521 case MODEL_F5D8235v3
:
522 dirty
|= check_nv("vlan1ports", "1 2 3 4 8*");
523 dirty
|= check_nv("vlan2ports", "0 8");
527 dirty
|= check_nv("vlan1ports", "3 2 1 0 8*");
528 dirty
|= check_nv("vlan2ports", "4 8");
537 dirty
|= check_nv("vlan1ports", "0 1 2 3 5*");
538 dirty
|= check_nv("vlan2ports", "4 5");
542 dirty
|= check_nv("vlan1ports", "1 2 3 4 5*");
543 dirty
|= check_nv("vlan2ports", "0 5");
548 dirty
|= check_nv("vlan1ports", "0 1 2 3 8*");
549 dirty
|= check_nv("vlan2ports", "4 8");
552 dirty
|= check_nv("vlan1ports", "4 3 2 1 8*");
553 dirty
|= check_nv("vlan2ports", "4 8");
554 dirty
|= check_nv("boot_wait", "on");
555 dirty
|= check_nv("wait_time", "5");
557 case MODEL_TDN6
: //bwq518
558 dirty
|= check_nv("vlan1ports", "1 2 3 4 5*");
559 dirty
|= check_nv("vlan2ports", "0 5");
560 dirty
|= check_nv("boot_wait", "on");
561 dirty
|= check_nv("wait_time", "5");
563 case MODEL_WRT160Nv3
:
564 if (nvram_match("vlan1ports", "1 2 3 4 5*")) {
565 // fix lan port numbering on CSE41, CSE51
566 dirty
|= check_nv("vlan1ports", "4 3 2 1 5*");
568 else if (nvram_match("vlan1ports", "1 2 3 4 8*")) {
570 dirty
|= check_nv("vlan1ports", "4 3 2 1 8*");
574 #ifdef CONFIG_BCMWL6A
576 dirty
|= check_nv("vlan1ports", "0 1 2 3 5*");
577 dirty
|= check_nv("vlan2ports", "4 5");
580 dirty
|= check_nv("vlan1ports", "1 2 3 4 5*");
581 dirty
|= check_nv("vlan2ports", "0 5");
590 static void check_bootnv(void)
598 dirty
= check_nv("wl0_leddc", "0x640000") | check_nv("wl1_leddc", "0x640000");
602 dirty
|= check_nv("vlan0hwname", "et0");
603 dirty
|= check_nv("vlan1hwname", "et0");
606 dirty
|= check_nv("wl0gpio0", "130");
610 // need to cleanup some variables...
611 if ((nvram_get("t_model") == NULL
) && (nvram_get("MyFirmwareVersion") != NULL
)) {
612 nvram_unset("MyFirmwareVersion");
613 nvram_set("restore_defaults", "1");
617 dirty
|= check_nv("wl0gpio1", "0x02");
620 /* fix WL500W mac adresses for WAN port */
621 if (invalid_mac(nvram_get("et1macaddr"))) {
622 strcpy(mac
, nvram_safe_get("et0macaddr"));
624 dirty
|= check_nv("et1macaddr", mac
);
626 dirty
|= check_nv("wl0gpio0", "0x88");
629 dirty
|= check_nv("sdram_init", "0x0009"); // 32MB; defaults: 0x000b, 0x0009
630 dirty
|= check_nv("wl0gpio0", "136");
632 case MODEL_WL500GPv2
:
634 dirty
|= check_nv("wl0gpio1", "136");
637 dirty
|= check_nv("vlan0hwname", "et0");
638 dirty
|= check_nv("vlan1hwname", "et0");
639 dirty
|= check_nv("boardflags", "0x00000100"); // set BFL_ENETVLAN
640 nvram_unset("wl0gpio0");
643 if (strlen(nvram_safe_get("et0macaddr")) == 12 ||
644 strlen(nvram_safe_get("il0macaddr")) == 12) {
645 dirty
|= find_dir320_mac_addr();
647 if (nvram_get("vlan2hwname") != NULL
) {
648 nvram_unset("vlan2hwname");
651 dirty
|= check_nv("wandevs", "vlan1");
652 dirty
|= check_nv("vlan1hwname", "et0");
653 dirty
|= check_nv("wl0gpio0", "8");
654 dirty
|= check_nv("wl0gpio1", "0");
655 dirty
|= check_nv("wl0gpio2", "0");
656 dirty
|= check_nv("wl0gpio3", "0");
659 dirty
|= check_nv("wandevs", "vlan1");
660 dirty
|= check_nv("vlan0hwname", "et0");
661 dirty
|= check_nv("vlan1hwname", "et0");
664 if (invalid_mac(nvram_get("et0macaddr"))) {
665 dirty
|= find_sercom_mac_addr();
668 case MODEL_WRT160Nv1
:
669 case MODEL_WRT310Nv1
:
671 dirty
|= check_nv("wl0gpio0", "8");
675 dirty
|= check_nv("boardflags", "0x00000710"); // needed to enable USB
676 dirty
|= check_nv("vlan2hwname", "et0");
677 dirty
|= check_nv("ledbh0", "7");
679 case MODEL_WNR3500LV2
:
680 dirty
|= check_nv("vlan2hwname", "et0");
682 case MODEL_WNR2000v2
:
683 dirty
|= check_nv("ledbh5", "8");
686 dirty
|= check_nv("reset_gpio", "5");
687 dirty
|= check_nv("ledbh0", "136");
688 dirty
|= check_nv("ledbh1", "11");
689 /* fall through, same as RT-N16 */
691 dirty
|= check_nv("vlan2hwname", "et0");
694 case MODEL_RG200E_CA
:
696 dirty
|= check_nv("vlan1hwname", "et0");
697 dirty
|= check_nv("vlan2hwname", "et0");
698 dirty
|= check_nv("boardflags", "0x710"); // set BFL_ENETVLAN, enable VLAN
699 dirty
|= check_nv("reset_gpio", "30");
701 case MODEL_WRT610Nv2
:
702 dirty
|= check_nv("vlan2hwname", "et0");
703 dirty
|= check_nv("pci/1/1/ledbh2", "8");
704 dirty
|= check_nv("sb/1/ledbh1", "8");
705 if (invalid_mac(nvram_get("pci/1/1/macaddr"))) {
706 strcpy(mac
, nvram_safe_get("et0macaddr"));
708 dirty
|= check_nv("pci/1/1/macaddr", mac
);
715 case MODEL_F5D8235v3
:
716 if (nvram_match("sb/1/macaddr", nvram_safe_get("et0macaddr"))) {
717 strcpy(mac
, nvram_safe_get("et0macaddr"));
719 dirty
|= check_nv("sb/1/macaddr", mac
);
721 dirty
|= check_nv("pci/1/1/macaddr", mac
);
724 dirty
|= check_nv("vlan2hwname", "et0");
725 if (strncasecmp(nvram_safe_get("pci/2/1/macaddr"), "00:90:4c", 8) == 0) {
726 strcpy(mac
, nvram_safe_get("et0macaddr"));
728 dirty
|= check_nv("pci/2/1/macaddr", mac
);
732 dirty
|= check_nv("vlan2hwname", "et0");
733 if (strncasecmp(nvram_safe_get("pci/1/1/macaddr"), "00:90:4c", 8) == 0 ||
734 strncasecmp(nvram_safe_get("sb/1/macaddr"), "00:90:4c", 8) == 0) {
735 strcpy(mac
, nvram_safe_get("et0macaddr"));
737 dirty
|= check_nv("sb/1/macaddr", mac
);
739 dirty
|= check_nv("pci/1/1/macaddr", mac
);
748 case MODEL_WRT160Nv3
:
751 dirty
|= check_nv("vlan2hwname", "et0");
756 if (strncmp(nvram_safe_get("pmon_ver"), "CFE", 3) != 0) return;
758 hardware
= check_hw_type();
759 if (!nvram_get("boardtype") ||
760 !nvram_get("boardnum") ||
761 !nvram_get("boardflags") ||
762 !nvram_get("clkfreq") ||
763 !nvram_get("os_flash_addr") ||
764 !nvram_get("dl_ram_addr") ||
765 !nvram_get("os_ram_addr") ||
766 !nvram_get("scratch") ||
767 !nvram_get("et0macaddr") ||
768 ((hardware
!= HW_BCM4704_BCM5325F
) && (!nvram_get("vlan0ports") || !nvram_get("vlan0hwname")))) {
769 _dprintf("Unable to find critical settings, erasing NVRAM\n");
774 dirty
|= check_nv("aa0", "3");
775 dirty
|= check_nv("wl0gpio0", "136");
776 dirty
|= check_nv("wl0gpio2", "0");
777 dirty
|= check_nv("wl0gpio3", "0");
778 dirty
|= check_nv("cctl", "0");
779 dirty
|= check_nv("ccode", "0");
783 /* Lower the DDR ram drive strength , the value will be stable for all boards
784 Latency 3 is more stable for all ddr 20050420 by honor */
785 dirty
|= check_nv("sdram_init", "0x010b");
786 dirty
|= check_nv("sdram_config", "0x0062");
787 if (!nvram_match("debug_clkfix", "0")) {
788 dirty
|= check_nv("clkfreq", "216");
791 nvram_set("sdram_ncdl", "0x0");
793 dirty
|= check_nv("pa0itssit", "62");
794 dirty
|= check_nv("pa0b0", "0x15eb");
795 dirty
|= check_nv("pa0b1", "0xfa82");
796 dirty
|= check_nv("pa0b2", "0xfe66");
797 //dirty |= check_nv("pa0maxpwr", "0x4e");
799 case HW_BCM5352E
: // G v4, GS v3, v4
800 dirty
|= check_nv("sdram_init", "0x010b");
801 dirty
|= check_nv("sdram_config", "0x0062");
803 nvram_set("sdram_ncdl", "0x0");
805 dirty
|= check_nv("pa0itssit", "62");
806 dirty
|= check_nv("pa0b0", "0x168b");
807 dirty
|= check_nv("pa0b1", "0xfabf");
808 dirty
|= check_nv("pa0b2", "0xfeaf");
809 //dirty |= check_nv("pa0maxpwr", "0x4e");
812 dirty
|= check_nv("pa0itssit", "62");
813 dirty
|= check_nv("pa0b0", "0x1326");
814 dirty
|= check_nv("pa0b1", "0xFB51");
815 dirty
|= check_nv("pa0b2", "0xFE87");
816 //dirty |= check_nv("pa0maxpwr", "0x4e");
818 case HW_BCM4704_BCM5325F
:
822 dirty
|= check_nv("pa0itssit", "62");
823 dirty
|= check_nv("pa0b0", "0x170c");
824 dirty
|= check_nv("pa0b1", "0xfa24");
825 dirty
|= check_nv("pa0b2", "0xfe70");
826 //dirty |= check_nv("pa0maxpwr", "0x48");
833 dirty
|= init_vlan_ports();
837 REBOOT
: // do a simple reboot
844 static int init_nvram(void)
846 unsigned long features
;
856 sprintf(s
, "%d", model
);
857 nvram_set("t_model", s
);
866 name
= "WRT54G/GS/GL";
867 switch (check_hw_type()) {
869 nvram_set("gpio2", "adm_eecs");
870 nvram_set("gpio3", "adm_eesk");
871 nvram_unset("gpio4");
872 nvram_set("gpio5", "adm_eedi");
873 nvram_set("gpio6", "adm_rc");
876 nvram_unset("gpio2");
877 nvram_unset("gpio3");
878 nvram_unset("gpio4");
879 nvram_unset("gpio5");
880 nvram_unset("gpio6");
883 nvram_set("opo", "0x0008");
884 nvram_set("ag0", "0x02");
887 nvram_set("gpio2", "ses_led");
888 nvram_set("gpio3", "ses_led2");
889 nvram_set("gpio4", "ses_button");
890 features
= SUP_SES
| SUP_WHAM_LED
;
897 if (!nvram_match("t_fix1", (char *)name
)) {
898 nvram_set("lan_ifnames", "vlan0 eth1");
899 nvram_set("gpio2", "ses_button");
900 nvram_set("reset_gpio", "7");
902 nvram_set("pa0itssit", "62");
903 nvram_set("pa0b0", "0x1542");
904 nvram_set("pa0b1", "0xfacb");
905 nvram_set("pa0b2", "0xfec7");
906 //nvram_set("pa0maxpwr", "0x4c");
909 case MODEL_WRTSL54GS
:
912 features
= SUP_SES
| SUP_WHAM_LED
;
917 features
= SUP_SES
| SUP_AOSS_LED
| SUP_BRAU
;
920 case MODEL_WZRRSG54HP
:
923 features
= SUP_SES
| SUP_AOSS_LED
| SUP_HPAMP
;
925 case MODEL_WZRRSG54HP
:
926 name
= "WZR-RS-G54HP";
933 features
= SUP_SES
| SUP_AOSS_LED
| SUP_BRAU
| SUP_HPAMP
;
937 bf
= strtoul(nvram_safe_get("boardflags"), NULL
, 0);
943 if ( nvram_is_empty("wlx_hpamp") || nvram_match("wlx_hpamp", "")) {
944 if (nvram_get_int("wl_txpwr") > 10) nvram_set("wl_txpwr", "10");
945 nvram_set("wlx_hpamp", "1");
946 nvram_set("wlx_hperx", "0");
950 if (nvram_match("wlx_hpamp", "0")) {
956 if (nvram_match("wlx_hperx", "0")) {
963 sprintf(s
, "0x%lX", n
);
964 nvram_set("boardflags", s
);
968 syslog(LOG_WARNING
, "Unexpected: boardflag=%lX", bf
);
979 features
= SUP_SES
| SUP_AOSS_LED
;
981 case MODEL_WHR2A54G54
:
983 name
= "WHR2-A54G54";
984 features
= SUP_SES
| SUP_AOSS_LED
| SUP_BRAU
;
989 features
= SUP_SES
| SUP_AOSS_LED
;
994 features
= SUP_SES
| SUP_AOSS_LED
;
999 features
= SUP_SES
| SUP_AOSS_LED
;
1001 case MODEL_WVRG54NF
:
1003 name
= "WVR-G54-NF";
1009 features
= SUP_SES
| SUP_AOSS_LED
;
1015 case MODEL_WR850GV1
:
1018 features
= SUP_NONVE
;
1020 case MODEL_WR850GV2
:
1022 name
= "WR850G v2/v3";
1023 features
= SUP_NONVE
;
1030 nvram_set("usb_ohci", "-1");
1032 if (!nvram_match("t_fix1", (char *)name
)) {
1033 nvram_set("lan_ifnames", "vlan0 eth1 eth2 eth3"); // set to "vlan0 eth2" by DD-WRT; default: vlan0 eth1
1039 features
= SUP_SES
| SUP_80211N
;
1041 nvram_set("usb_ohci", "-1");
1049 nvram_set("usb_uhci", "-1");
1052 case MODEL_WX6615GT
:
1065 case MODEL_WLA2G54L
:
1068 if (!nvram_match("t_fix1", (char *)name
)) {
1069 nvram_set("lan_ifnames", "vlan0 eth1 eth2");
1070 nvram_set("wl_ifname", "eth1");
1071 nvram_set("wan_ifname", "none");
1076 name
= "TrueMobile 2300";
1085 #ifndef WL_BSS_INFO_VERSION
1086 #error WL_BSS_INFO_VERSION
1088 #if WL_BSS_INFO_VERSION >= 108
1094 nvram_set("opo", "12");
1100 features
= SUP_SES
| SUP_AOSS_LED
| SUP_BRAU
;
1102 nvram_set("opo", "0x0008");
1103 nvram_set("ag0", "0x0C");
1105 #ifdef CONFIG_BCMWL5
1109 features
= SUP_SES
| SUP_80211N
;
1110 if (!nvram_match("t_fix1", (char *)name
)) {
1111 #ifdef TCONFIG_USBAP
1112 nvram_set("wl1_hwaddr", nvram_safe_get("0:macaddr"));
1113 nvram_set("ehciirqt", "3");
1114 nvram_set("qtdc_pid", "48407");
1115 nvram_set("qtdc_vid", "2652");
1116 nvram_set("qtdc0_ep", "4");
1117 nvram_set("qtdc0_sz", "0");
1118 nvram_set("qtdc1_ep", "18");
1119 nvram_set("qtdc1_sz", "10");
1120 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1121 nvram_set("landevs", "vlan1 wl0 wl1");
1122 nvram_set("wl0_ifname", "wl0");
1123 nvram_set("wl1_ifname", "wl1");
1125 nvram_set("lan_ifnames", "vlan1 eth1");
1126 nvram_set("landevs", "vlan1 wl0");
1128 nvram_set("wl_ifname", "eth1");
1129 nvram_set("wan_ifnameX", "vlan2");
1130 nvram_set("wandevs", "vlan2");
1133 case MODEL_DIR620C1
:
1135 name
= "Dir-620 C1";
1136 features
= SUP_SES
| SUP_80211N
;
1137 if (!nvram_match("t_fix1", (char *)name
)) {
1138 #ifdef TCONFIG_USBAP
1139 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1140 nvram_set("landevs", "vlan1 wl0 wl1");
1141 nvram_set("wl0_ifname", "eth1");
1142 nvram_set("wl1_ifname", "eth2");
1144 nvram_set("lan_ifnames", "vlan1 eth1");
1145 nvram_set("landevs", "vlan1 wl0");
1147 nvram_set("wan_ifnameX", "vlan2");
1148 nvram_set("wl_ifname", "eth1");
1155 features
= SUP_SES
| SUP_80211N
;
1157 nvram_set("usb_uhci", "-1");
1159 if (!nvram_match("t_fix1", (char *)name
)) {
1160 nvram_set("lan_ifnames", "vlan1 eth1");
1161 nvram_set("wan_ifname", "vlan2");
1162 nvram_set("wan_ifnames", "vlan2");
1163 nvram_set("wan_ifnameX", "vlan2");
1164 nvram_set("wl_ifname", "eth1");
1170 features
= SUP_SES
| SUP_80211N
;
1172 nvram_set("usb_uhci", "-1");
1174 if (!nvram_match("t_fix1", (char *)name
)) {
1175 nvram_set("lan_ifnames", "vlan1 eth1");
1176 nvram_set("wan_ifname", "vlan2");
1177 nvram_set("wan_ifnames", "vlan2");
1178 nvram_set("wan_ifnameX", "vlan2");
1179 nvram_set("wl_ifname", "eth1");
1182 case MODEL_RG200E_CA
:
1185 features
= SUP_SES
| SUP_80211N
;
1187 nvram_set("usb_uhci", "-1");
1189 if (!nvram_match("t_fix1", (char *)name
)) {
1190 nvram_set("lan_ifnames", "vlan1 eth1");
1191 nvram_set("wan_ifname", "vlan2");
1192 nvram_set("wan_ifnames", "vlan2");
1193 nvram_set("wan_ifnameX", "vlan2");
1194 nvram_set("wl_ifname", "eth1");
1200 features
= SUP_SES
| SUP_80211N
;
1202 nvram_set("usb_uhci", "-1");
1204 if (!nvram_match("t_fix1", (char *)name
)) {
1205 nvram_set("lan_ifnames", "vlan1 eth1");
1206 nvram_set("wan_ifname", "vlan2");
1207 nvram_set("wan_ifnames", "vlan2");
1208 nvram_set("wan_ifnameX", "vlan2");
1209 nvram_set("wl_ifname", "eth1");
1215 features
= SUP_SES
| SUP_80211N
;
1217 nvram_set("usb_uhci", "-1");
1219 if (!nvram_match("t_fix1", (char *)name
)) {
1220 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1221 nvram_set("wan_ifnameX", "vlan2");
1222 nvram_set("wan_ifnames", "vlan2");
1223 nvram_set("wan_ifnameX", "vlan2");
1224 nvram_set("wl_ifnames", "eth1 eth2");
1225 nvram_set("wl_ifname", "eth1");
1226 nvram_set("wl0_ifname", "eth1");
1227 nvram_set("wl1_ifname", "eth2");
1228 nvram_set("wl0_bw_cap","3");
1229 nvram_set("wl0_chanspec","1l");
1230 nvram_set("wl1_bw_cap","7");
1231 nvram_set("wl1_chanspec","36/80");
1232 nvram_set("blink_5g_interface","eth2");
1233 //nvram_set("landevs", "vlan1 wl0 wl1");
1234 //nvram_set("wandevs", "vlan2");
1237 nvram_set("wl0_hwaddr", nvram_safe_get("sb/1/macaddr"));
1238 nvram_set("wl1_hwaddr", nvram_safe_get("0:macaddr"));
1244 features
= SUP_SES
| SUP_80211N
;
1246 nvram_set("usb_uhci", "-1");
1248 if (!nvram_match("t_fix1", (char *)name
)) {
1249 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1250 nvram_set("wan_ifnameX", "vlan2");
1251 nvram_set("wan_ifnames", "vlan2");
1252 nvram_set("wan_ifnameX", "vlan2");
1253 nvram_set("wl_ifnames", "eth1 eth2");
1254 nvram_set("wl_ifname", "eth1");
1255 nvram_set("wl0_ifname", "eth1");
1256 nvram_set("wl1_ifname", "eth2");
1257 nvram_set("wl0_bw_cap","3");
1258 nvram_set("wl0_chanspec","1l");
1259 nvram_set("wl1_bw_cap","7");
1260 nvram_set("wl1_chanspec","36/80");
1261 nvram_set("blink_5g_interface","eth2");
1264 nvram_set("wl0_hwaddr", nvram_safe_get("sb/1/macaddr"));
1265 nvram_set("wl1_hwaddr", nvram_safe_get("0:macaddr"));
1271 name
= nvram_match("boardrev", "0x1153") ? "RT-N10P" : "RT-N10";
1272 features
= SUP_SES
| SUP_80211N
;
1273 if (!nvram_match("t_fix1", (char *)name
)) {
1274 nvram_set("lan_ifnames", "vlan0 eth1");
1275 nvram_set("wan_ifnameX", "vlan1");
1276 nvram_set("wl_ifname", "eth1");
1282 features
= SUP_SES
| SUP_80211N
;
1284 nvram_set("usb_uhci", "-1");
1286 if (!nvram_match("t_fix1", (char *)name
)) {
1287 nvram_set("lan_ifnames", "vlan0 eth1");
1288 nvram_set("wan_ifnameX", "vlan1");
1289 nvram_set("wl_ifname", "eth1");
1295 features
= SUP_SES
| SUP_BRAU
| SUP_80211N
;
1296 if (!nvram_match("t_fix1", (char *)name
)) {
1297 nvram_set("lan_ifnames", "vlan0 eth1");
1298 nvram_set("wan_ifnameX", "vlan1");
1299 nvram_set("wl_ifname", "eth1");
1305 features
= SUP_80211N
;
1306 if (!nvram_match("t_fix1", (char *)name
)) {
1307 nvram_set("lan_ifnames", "vlan0 eth1");
1308 nvram_set("wan_ifnameX", "vlan1");
1309 nvram_set("wl_ifname", "eth1");
1315 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
;
1317 nvram_set("usb_uhci", "-1");
1319 if (!nvram_match("t_fix1", (char *)name
)) {
1320 nvram_set("lan_ifnames", "vlan1 eth1");
1321 nvram_set("wan_iface", "vlan2");
1322 nvram_set("wan_ifname", "vlan2");
1323 nvram_set("wan_ifnameX", "vlan2");
1324 nvram_set("wan_ifnames", "vlan2");
1325 nvram_set("wl_ifname", "eth1");
1331 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
;
1333 nvram_set("usb_uhci", "-1");
1335 if (!nvram_match("t_fix1", (char *)name
)) {
1336 nvram_set("lan_ifnames", "vlan1 eth1");
1337 nvram_set("wan_ifnameX", "vlan2");
1338 nvram_set("wl_ifname", "eth1");
1339 nvram_set("vlan_enable", "1");
1345 name
= nvram_match("boardrev", "0x1446") ? "RT-N53 A1" : "RT-N53";
1346 features
= SUP_SES
| SUP_80211N
;
1347 #if defined(LINUX26) && defined(TCONFIG_USBAP)
1348 if (nvram_get_int("usb_storage") == 1) nvram_set("usb_storage", "-1");
1350 if (!nvram_match("t_fix1", (char *)name
)) {
1351 #ifdef TCONFIG_USBAP
1352 nvram_set("wl1_hwaddr", nvram_safe_get("0:macaddr"));
1353 nvram_set("ehciirqt", "3");
1354 nvram_set("qtdc_pid", "48407");
1355 nvram_set("qtdc_vid", "2652");
1356 nvram_set("qtdc0_ep", "4");
1357 nvram_set("qtdc0_sz", "0");
1358 nvram_set("qtdc1_ep", "18");
1359 nvram_set("qtdc1_sz", "10");
1360 nvram_set("lan_ifnames", "vlan2 eth1 eth2");
1361 nvram_set("landevs", "vlan2 wl0 wl1");
1362 nvram_set("wl1_ifname", "eth2");
1364 nvram_set("lan_ifnames", "vlan2 eth1");
1365 nvram_set("landevs", "vlan2 wl0");
1367 nvram_set("lan_ifname", "br0");
1368 nvram_set("wl_ifname", "eth1");
1369 nvram_set("wl0_ifname", "eth1");
1370 nvram_set("wan_ifnameX", "vlan1");
1371 nvram_set("wandevs", "vlan1");
1372 nvram_unset("vlan0ports");
1375 #ifdef CONFIG_BCMWL6A
1379 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
| SUP_80211AC
;
1380 nvram_set("vlan1hwname", "et0");
1381 nvram_set("vlan2hwname", "et0");
1382 nvram_set("lan_ifname", "br0");
1383 nvram_set("0:ledbh3", "0x87"); // since 163.42 //
1384 nvram_set("1:ledbh10", "0x87");
1385 nvram_set("landevs", "vlan1 wl0 wl1");
1386 nvram_set("wl_ifnames", "eth1 eth2");
1387 nvram_set("wl0_vifnames", "wl0.1 wl0.2 wl0.3");
1388 nvram_set("wl1_vifnames", "wl1.1 wl1.2 wl1.3");
1390 nvram_set_int("pwr_usb_gpio", 9|GPIO_ACTIVE_LOW);
1391 nvram_set_int("pwr_usb_gpio2", 10|GPIO_ACTIVE_LOW); // Use at the first shipment of RT-AC56U.
1392 nvram_set_int("led_usb_gpio", 14|GPIO_ACTIVE_LOW); // change led gpio(usb2/usb3) to sync the outer case
1393 nvram_set_int("led_wan_gpio", 1|GPIO_ACTIVE_LOW);
1394 nvram_set_int("led_lan_gpio", 2|GPIO_ACTIVE_LOW);
1395 nvram_set_int("led_pwr_gpio", 3|GPIO_ACTIVE_LOW);
1396 nvram_set_int("led_wps_gpio", 3|GPIO_ACTIVE_LOW);
1397 nvram_set_int("led_all_gpio", 4|GPIO_ACTIVE_LOW); // actually, this is high active, and will power off all led when active; to fake LOW_ACTIVE to sync boardapi
1398 nvram_set_int("led_5g_gpio", 6|GPIO_ACTIVE_LOW); // 4352's fake led 5g
1399 nvram_set_int("led_usb3_gpio", 0|GPIO_ACTIVE_LOW); // change led gpio(usb2/usb3) to sync the outer case
1400 nvram_set_int("btn_wps_gpio", 15|GPIO_ACTIVE_LOW);
1401 nvram_set_int("btn_rst_gpio", 11|GPIO_ACTIVE_LOW);
1402 #ifdef TCONFIG_WIFI_TOG_BTN
1403 nvram_set_int("btn_wltog_gpio", 7|GPIO_ACTIVE_LOW);
1405 #ifdef TCONFIG_TURBO
1406 nvram_set_int("btn_turbo_gpio", 5);
1409 #ifdef TCONFIG_XHCIMODE
1410 nvram_set("xhci_ports", "1-1");
1411 nvram_set("ehci_ports", "2-1 2-2");
1412 nvram_set("ohci_ports", "3-1 3-2");
1414 if(nvram_get_int("usb_usb3") == 1){
1415 nvram_set("xhci_ports", "1-1");
1416 nvram_set("ehci_ports", "2-1 2-2");
1417 nvram_set("ohci_ports", "3-1 3-2");
1420 nvram_unset("xhci_ports");
1421 nvram_set("ehci_ports", "1-1 1-2");
1422 nvram_set("ohci_ports", "2-1 2-2");
1426 if(!nvram_get("ct_max"))
1427 nvram_set("ct_max", "300000");
1428 add_rc_support("mssid 2.4G 5G update usbX2");
1429 add_rc_support("switchctrl"); // broadcom: for jumbo frame only
1430 add_rc_support("manual_stb");
1431 add_rc_support("pwrctrl");
1432 add_rc_support("WIFI_LOGO");
1433 add_rc_support("nandflash");
1439 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
| SUP_80211AC
;
1441 nvram_set("usb_uhci", "-1");
1443 if (!nvram_match("t_fix1", (char *)name
)) {
1444 nvram_set("vlan1hwname", "et0");
1445 nvram_set("vlan2hwname", "et0");
1446 nvram_set("lan_ifname", "br0");
1447 nvram_set("landevs", "vlan1 wl0 wl1");
1448 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1449 nvram_set("wan_ifnames", "vlan2");
1450 nvram_set("wan_ifnameX", "vlan2");
1451 nvram_set("wandevs", "vlan2");
1452 nvram_set("wl_ifnames", "eth1 eth2");
1453 nvram_set("wl_ifname", "eth1");
1454 nvram_set("wl0_ifname", "eth1");
1455 nvram_set("wl1_ifname", "eth2");
1458 nvram_set("wl0_hwaddr", nvram_safe_get("0:macaddr"));
1459 nvram_set("wl1_hwaddr", nvram_safe_get("1:macaddr"));
1461 nvram_set("xhci_ports", "1-1");
1462 nvram_set("ehci_ports", "2-1 2-2");
1463 nvram_set("ohci_ports", "3-1 3-2");
1464 if(!nvram_get("ct_max"))
1465 nvram_set("ct_max", "300000");
1466 if (nvram_match("wl1_bw", "0"))
1468 nvram_set("wl1_bw", "3");
1470 if (nvram_match("wl1_country_code", "EU"))
1471 nvram_set("wl1_chanspec", "36/80");
1473 nvram_set("wl1_chanspec", "149/80");
1475 if ((nvram_get_int("wlopmode") == 7) || nvram_match("ATEMODE", "1"))
1476 nvram_set("usb_usb3", "1");
1482 #ifdef TCONFIG_AC66U
1484 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
| SUP_80211AC
;
1487 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
;
1488 #if defined(LINUX26) && defined(TCONFIG_MICROSD)
1489 if (nvram_get_int("usb_mmc") == -1) nvram_set("usb_mmc", "1");
1494 nvram_set("usb_uhci", "-1");
1496 if (!nvram_match("t_fix1", (char *)name
)) {
1497 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1498 nvram_set("wan_ifnameX", "vlan2");
1499 nvram_set("wl_ifnames", "eth1 eth2");
1500 #ifdef TCONFIG_AC66U
1501 nvram_set("wl_ifname", "eth1");
1502 nvram_set("wl0_ifname", "eth1");
1503 nvram_set("wl1_ifname", "eth2");
1505 nvram_set("landevs", "vlan1 wl0 wl1");
1506 nvram_set("wandevs", "vlan2");
1507 #ifndef TCONFIG_AC66U
1508 #if defined(LINUX26) && defined(TCONFIG_USB)
1509 nvram_set("usb_noled", "1-1.4"); /* SD/MMC Card */
1512 nvram_set("wl1_bw_cap","7");
1513 nvram_set("wl1_chanspec","36/80");
1514 nvram_set("wl0_bw_cap","3");
1515 nvram_set("wl0_chanspec","1l");
1516 nvram_set("blink_5g_interface","eth2");
1519 strcpy(s
, nvram_safe_get("et0macaddr"));
1521 nvram_set("wl0_hwaddr", s
);
1523 nvram_set("wl1_hwaddr", s
);
1525 // bcm4360ac_defaults
1526 nvram_set("pci/2/1/aa2g", "0");
1527 nvram_set("pci/2/1/aa5g", "7");
1528 nvram_set("pci/2/1/aga0", "71");
1529 nvram_set("pci/2/1/aga1", "71");
1530 nvram_set("pci/2/1/aga2", "71");
1531 nvram_set("pci/2/1/agbg0", "133");
1532 nvram_set("pci/2/1/agbg1", "133");
1533 nvram_set("pci/2/1/agbg2", "133");
1534 nvram_set("pci/2/1/antswitch", "0");
1535 nvram_set("pci/2/1/cckbw202gpo", "0");
1536 nvram_set("pci/2/1/cckbw20ul2gpo", "0");
1537 nvram_set("pci/2/1/dot11agofdmhrbw202gpo", "0");
1538 nvram_set("pci/2/1/femctrl", "3");
1539 nvram_set("pci/2/1/papdcap2g", "0");
1540 nvram_set("pci/2/1/tworangetssi2g", "0");
1541 nvram_set("pci/2/1/pdgain2g", "4");
1542 nvram_set("pci/2/1/epagain2g", "0");
1543 nvram_set("pci/2/1/tssiposslope2g", "1");
1544 nvram_set("pci/2/1/gainctrlsph", "0");
1545 nvram_set("pci/2/1/papdcap5g", "0");
1546 nvram_set("pci/2/1/tworangetssi5g", "0");
1547 nvram_set("pci/2/1/pdgain5g", "4");
1548 nvram_set("pci/2/1/epagain5g", "0");
1549 nvram_set("pci/2/1/tssiposslope5g", "1");
1550 nvram_set("pci/2/1/maxp2ga0", "76");
1551 nvram_set("pci/2/1/maxp2ga1", "76");
1552 nvram_set("pci/2/1/maxp2ga2", "76");
1553 nvram_set("pci/2/1/mcsbw202gpo", "0");
1554 nvram_set("pci/2/1/mcsbw402gpo", "0");
1555 nvram_set("pci/2/1/measpower", "0x7f");
1556 nvram_set("pci/2/1/measpower1", "0x7f");
1557 nvram_set("pci/2/1/measpower2", "0x7f");
1558 nvram_set("pci/2/1/noiselvl2ga0", "31");
1559 nvram_set("pci/2/1/noiselvl2ga1", "31");
1560 nvram_set("pci/2/1/noiselvl2ga2", "31");
1561 nvram_set("pci/2/1/noiselvl5gha0", "31");
1562 nvram_set("pci/2/1/noiselvl5gha1", "31");
1563 nvram_set("pci/2/1/noiselvl5gha2", "31");
1564 nvram_set("pci/2/1/noiselvl5gla0", "31");
1565 nvram_set("pci/2/1/noiselvl5gla1", "31");
1566 nvram_set("pci/2/1/noiselvl5gla2", "31");
1567 nvram_set("pci/2/1/noiselvl5gma0", "31");
1568 nvram_set("pci/2/1/noiselvl5gma1", "31");
1569 nvram_set("pci/2/1/noiselvl5gma2", "31");
1570 nvram_set("pci/2/1/noiselvl5gua0", "31");
1571 nvram_set("pci/2/1/noiselvl5gua1", "31");
1572 nvram_set("pci/2/1/noiselvl5gua2", "31");
1573 nvram_set("pci/2/1/ofdmlrbw202gpo", "0");
1574 nvram_set("pci/2/1/pa2ga0", "0xfe72,0x14c0,0xfac7");
1575 nvram_set("pci/2/1/pa2ga1", "0xfe80,0x1472,0xfabc");
1576 nvram_set("pci/2/1/pa2ga2", "0xfe82,0x14bf,0xfad9");
1577 nvram_set("pci/2/1/pcieingress_war", "15");
1578 nvram_set("pci/2/1/phycal_tempdelta", "255");
1579 nvram_set("pci/2/1/rawtempsense", "0x1ff");
1580 nvram_set("pci/2/1/rxchain", "7");
1581 nvram_set("pci/2/1/rxgainerr2g", "0xffff");
1582 nvram_set("pci/2/1/rxgainerr5g", "0xffff,0xffff,0xffff,0xffff");
1583 nvram_set("pci/2/1/rxgains2gelnagaina0", "0");
1584 nvram_set("pci/2/1/rxgains2gelnagaina1", "0");
1585 nvram_set("pci/2/1/rxgains2gelnagaina2", "0");
1586 nvram_set("pci/2/1/rxgains2gtrelnabypa0", "0");
1587 nvram_set("pci/2/1/rxgains2gtrelnabypa1", "0");
1588 nvram_set("pci/2/1/rxgains2gtrelnabypa2", "0");
1589 nvram_set("pci/2/1/rxgains2gtrisoa0", "0");
1590 nvram_set("pci/2/1/rxgains2gtrisoa1", "0");
1591 nvram_set("pci/2/1/rxgains2gtrisoa2", "0");
1592 nvram_set("pci/2/1/sar2g", "18");
1593 nvram_set("pci/2/1/sar5g", "15");
1594 nvram_set("pci/2/1/sromrev", "11");
1595 nvram_set("pci/2/1/subband5gver", "0x4");
1596 nvram_set("pci/2/1/tempcorrx", "0x3f");
1597 nvram_set("pci/2/1/tempoffset", "255");
1598 nvram_set("pci/2/1/temps_hysteresis", "15");
1599 nvram_set("pci/2/1/temps_period", "15");
1600 nvram_set("pci/2/1/tempsense_option", "0x3");
1601 nvram_set("pci/2/1/tempsense_slope", "0xff");
1602 nvram_set("pci/2/1/tempthresh", "255");
1603 nvram_set("pci/2/1/txchain", "7");
1604 nvram_set("pci/2/1/ledbh0", "2");
1605 nvram_set("pci/2/1/ledbh1", "5");
1606 nvram_set("pci/2/1/ledbh2", "4");
1607 nvram_set("pci/2/1/ledbh3", "11");
1608 nvram_set("pci/2/1/ledbh10", "7");
1610 //force EU country for eth2
1611 nvram_set("pci/2/1/ccode", "EU");
1612 #endif // TCONFIG_AC66U
1615 #ifdef CONFIG_BCMWL6
1619 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
| SUP_80211AC
;
1621 nvram_set("usb_uhci", "-1");
1623 if (!nvram_match("t_fix1", (char *)name
)) {
1624 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1625 nvram_set("wan_ifnameX", "vlan2");
1626 nvram_set("wl_ifnames", "eth1 eth2");
1627 nvram_set("wl_ifname", "eth1");
1628 nvram_set("wl0_ifname", "eth2");
1629 nvram_set("wl1_ifname", "eth1");
1630 nvram_set("wl0_bw_cap","7");
1631 nvram_set("wl0_chanspec","36/80");
1632 nvram_set("wl1_bw_cap","3");
1633 nvram_set("wl1_chanspec","1l");
1634 nvram_set("blink_5g_interface","eth1");
1635 //nvram_set("landevs", "vlan1 wl0 wl1");
1636 //nvram_set("wandevs", "vlan2");
1639 strcpy(s
, nvram_safe_get("et0macaddr"));
1640 nvram_set("wl0_hwaddr", nvram_safe_get("0:macaddr"));
1641 nvram_set("wl1_hwaddr", nvram_safe_get("1:macaddr"));
1643 // fix ssid according to 5G(eth2) and 2.4G(eth1)
1644 nvram_set("wl_ssid","Tomato50");
1645 nvram_set("wl0_ssid","Tomato50");
1646 nvram_set("wl1_ssid","Tomato24");
1651 if (nvram_match("product", "WLI-H4-D1300")) {
1652 name
= "WLI-H4-D1300";
1654 else if (nvram_match("product", "WZR-D1100H")) {
1655 name
= "WZR-D1100H";
1658 name
= "WZR-D1800H";
1660 features
= SUP_SES
| SUP_AOSS_LED
| SUP_80211N
| SUP_1000ET
| SUP_80211AC
;
1662 nvram_set("usb_uhci", "-1");
1664 if (!nvram_match("t_fix1", (char *)name
)) {
1665 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1666 nvram_set("wan_ifnameX", "vlan2");
1667 nvram_set("wl_ifnames", "eth1 eth2");
1668 nvram_set("wl_ifname", "eth1");
1669 nvram_set("wl0_ifname", "eth2");
1670 nvram_set("wl1_ifname", "eth1");
1671 nvram_set("wl0_bw_cap","7");
1672 nvram_set("wl0_chanspec","36/80");
1673 nvram_set("wl1_bw_cap","3");
1674 nvram_set("wl1_chanspec","1l");
1675 nvram_set("blink_5g_interface","eth1");
1678 strcpy(s
, nvram_safe_get("et0macaddr"));
1681 for (i
= 0; i
< strlen(s
); i
++) if ( s
[i
] == '-') s
[i
] = ':';
1682 nvram_set("et0macaddr",s
);
1684 nvram_set("wl0_hwaddr", s
);
1686 nvram_set("wl1_hwaddr", s
);
1688 // fix ssid according to 5G(eth2) and 2.4G(eth1)
1689 nvram_set("wl_ssid","Tomato50");
1690 nvram_set("wl0_ssid","Tomato50");
1691 nvram_set("wl1_ssid","Tomato24");
1693 nvram_set("pci/2/1/maxp2ga0", "0x70");
1694 nvram_set("pci/2/1/maxp2ga1", "0x70");
1695 nvram_set("pci/2/1/maxp2ga2", "0x70");
1696 nvram_set("pci/2/1/maxp5ga0", "0x6A");
1697 nvram_set("pci/2/1/maxp5ga1", "0x6A");
1698 nvram_set("pci/2/1/maxp5ga2", "0x6A");
1699 nvram_set("pci/2/1/cckbw202gpo", "0x5555");
1700 nvram_set("pci/2/1/cckbw20ul2gpo", "0x5555");
1701 nvram_set("pci/2/1/legofdmbw202gpo", "0x97555555");
1702 nvram_set("pci/2/1/legofdmbw20ul2gpo", "0x97555555");
1703 nvram_set("pci/2/1/mcsbw202gpo", "0xDA755555");
1704 nvram_set("pci/2/1/mcsbw20ul2gpo", "0xDA755555");
1705 nvram_set("pci/2/1/mcsbw402gpo", "0xFC965555");
1706 nvram_set("pci/2/1/cckbw205gpo", "0x5555");
1707 nvram_set("pci/2/1/cckbw20ul5gpo", "0x5555");
1708 nvram_set("pci/2/1/legofdmbw205gpo", "0x97555555");
1709 nvram_set("pci/2/1/legofdmbw20ul5gpo", "0x97555555");
1710 nvram_set("pci/2/1/legofdmbw205gmpo", "0x77777777");
1711 nvram_set("pci/2/1/legofdmbw20ul5gmpo", "0x77777777");
1712 nvram_set("pci/2/1/legofdmbw205ghpo", "0x77777777");
1713 nvram_set("pci/2/1/legofdmbw20ul5ghpo", "0x77777777");
1714 nvram_set("pci/2/1/mcsbw205ghpo", "0x77777777");
1715 nvram_set("pci/2/1/mcsbw20ul5ghpo", "0x77777777");
1716 nvram_set("pci/2/1/mcsbw205gpo", "0xDA755555");
1717 nvram_set("pci/2/1/mcsbw20ul5gpo", "0xDA755555");
1718 nvram_set("pci/2/1/mcsbw405gpo", "0xFC965555");
1719 nvram_set("pci/2/1/mcsbw405ghpo", "0x77777777");
1720 nvram_set("pci/2/1/mcsbw405ghpo", "0x77777777");
1721 nvram_set("pci/2/1/mcs32po", "0x7777");
1722 nvram_set("pci/2/1/legofdm40duppo", "0x0000");
1723 nvram_set("pci/1/1/maxp5ga0", "104,104,104,104");
1724 nvram_set("pci/1/1/maxp5ga1", "104,104,104,104");
1725 nvram_set("pci/1/1/maxp5ga2", "104,104,104,104");
1726 nvram_set("pci/1/1/mcsbw205glpo", "0xBB975311");
1727 nvram_set("pci/1/1/mcsbw405glpo", "0xBB975311");
1728 nvram_set("pci/1/1/mcsbw805glpo", "0xBB975311");
1729 nvram_set("pci/1/1/mcsbw205gmpo", "0xBB975311");
1730 nvram_set("pci/1/1/mcsbw405gmpo", "0xBB975311");
1731 nvram_set("pci/1/1/mcsbw805gmpo", "0xBB975311");
1732 nvram_set("pci/1/1/mcsbw205ghpo", "0xBB975311");
1733 nvram_set("pci/1/1/mcsbw405ghpo", "0xBB975311");
1734 nvram_set("pci/1/1/mcsbw805ghpo", "0xBB975311");
1736 //force US country for 5G eth1, modified by bwq518
1737 nvram_set("pci/1/1/ccode", "US");
1738 nvram_set("wl1_country_code", "US");
1739 nvram_set("regulation_domain_5G", "US");
1742 case MODEL_EA6500V1
:
1745 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
| SUP_80211AC
;
1747 nvram_set("usb_uhci", "-1");
1749 if (!nvram_match("t_fix1", (char *)name
)) {
1750 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1751 nvram_set("wan_ifnameX", "vlan2");
1752 nvram_set("wl_ifnames", "eth1 eth2");
1753 nvram_set("wl_ifname", "eth1");
1754 nvram_set("wl0_ifname", "eth1");
1755 nvram_set("wl1_ifname", "eth2");
1756 nvram_set("wl0_bw_cap","7");
1757 nvram_set("wl0_chanspec","36/80");
1758 nvram_set("wl1_bw_cap","3");
1759 nvram_set("wl1_chanspec","1l");
1760 nvram_set("blink_5g_interface","eth1");
1762 // fix ssid according to 5G(eth1) and 2.4G(eth2)
1763 nvram_set("wl_ssid","Tomato50");
1764 nvram_set("wl0_ssid","Tomato50");
1765 nvram_set("wl1_ssid","Tomato24");
1767 //force US country for 5G eth1, modified by bwq518
1768 nvram_set("pci/1/1/ccode", nvram_safe_get("ccode"));
1769 nvram_set("regulation_domain_5G", nvram_safe_get("ccode"));
1772 #endif // CONFIG_BCMWL6
1773 case MODEL_WNR3500L
:
1775 name
= "WNR3500L/U/v2";
1776 features
= SUP_SES
| SUP_AOSS_LED
| SUP_80211N
| SUP_1000ET
;
1777 if (!nvram_match("t_fix1", (char *)name
)) {
1778 nvram_set("sromrev", "3");
1779 nvram_set("lan_ifnames", "vlan1 eth1");
1780 nvram_set("wan_ifnameX", "vlan2");
1781 nvram_set("wl_ifname", "eth1");
1784 case MODEL_WNR3500LV2
:
1786 name
= "WNR3500L v2";
1787 features
= SUP_SES
| SUP_AOSS_LED
| SUP_80211N
| SUP_1000ET
;
1788 if (!nvram_match("t_fix1", (char *)name
)) {
1789 nvram_set("lan_ifnames", "vlan1 eth1");
1790 nvram_set("wan_ifnameX", "vlan2");
1791 nvram_set("wl_ifname", "eth1");
1794 case MODEL_WNR2000v2
:
1796 name
= "WNR2000 v2";
1797 features
= SUP_SES
| SUP_AOSS_LED
| SUP_80211N
;
1798 if (!nvram_match("t_fix1", (char *)name
)) {
1799 nvram_set("lan_ifnames", "vlan0 eth1");
1800 nvram_set("wan_ifnameX", "vlan1");
1801 nvram_set("wl_ifname", "eth1");
1808 case MODEL_F5D8235v3
:
1810 features
= SUP_SES
| SUP_80211N
;
1813 name
= "Share Max N300 (F7D3301/F7D7301) v1";
1816 name
= "Share N300 (F7D3302/F7D7302) v1";
1819 name
= "Play Max / N600 HD (F7D4301/F7D8301) v1";
1822 name
= "Play N600 (F7D4302/F7D8302) v1";
1824 case MODEL_F5D8235v3
:
1825 name
= "N F5D8235-4 v3";
1829 nvram_set("usb_uhci", "-1");
1831 if (!nvram_match("t_fix1", (char *)name
)) {
1832 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1833 nvram_set("wan_ifnameX", "vlan2");
1834 nvram_set("landevs", "vlan1 wl0 wl1");
1835 nvram_set("wandevs", "vlan2");
1841 name
= nvram_safe_get("boot_hw_model");
1842 ver
= nvram_safe_get("boot_hw_ver");
1843 features
= SUP_SES
| SUP_80211N
;
1844 if (!nvram_match("t_fix1", (char *)name
)) {
1845 nvram_set("lan_ifnames", "vlan1 eth1");
1846 nvram_set("wan_ifnameX", "vlan2");
1847 nvram_set("wl_ifname", "eth1");
1852 name
= nvram_safe_get("boot_hw_model");
1853 ver
= nvram_safe_get("boot_hw_ver");
1854 features
= SUP_SES
| SUP_80211N
;
1856 nvram_set("usb_uhci", "-1");
1858 if (!nvram_match("t_fix1", (char *)name
)) {
1859 nvram_set("lan_ifnames", "vlan1 eth1");
1860 nvram_set("wan_ifnameX", "vlan2");
1861 nvram_set("wl_ifname", "eth1");
1866 name
= nvram_safe_get("boot_hw_model");
1867 ver
= nvram_safe_get("boot_hw_ver");
1868 features
= SUP_SES
| SUP_80211N
;
1869 #if defined(LINUX26) && defined(TCONFIG_USBAP)
1870 if (nvram_get_int("usb_storage") == 1) nvram_set("usb_storage", "-1");
1872 if (!nvram_match("t_fix1", (char *)name
)) {
1873 #ifdef TCONFIG_USBAP
1874 nvram_set("wl1_hwaddr", nvram_safe_get("0:macaddr"));
1875 nvram_set("ehciirqt", "3");
1876 nvram_set("qtdc_pid", "48407");
1877 nvram_set("qtdc_vid", "2652");
1878 nvram_set("qtdc0_ep", "4");
1879 nvram_set("qtdc0_sz", "0");
1880 nvram_set("qtdc1_ep", "18");
1881 nvram_set("qtdc1_sz", "10");
1882 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1883 nvram_set("landevs", "vlan1 wl0 wl1");
1884 nvram_set("wl0_ifname", "eth1");
1885 nvram_set("wl1_ifname", "eth2");
1887 nvram_set("lan_ifnames", "vlan1 eth1");
1888 nvram_set("landevs", "vlan1 wl0");
1890 nvram_set("wan_ifnameX", "vlan2");
1891 nvram_set("wl_ifname", "eth1");
1897 name
= nvram_safe_get("boot_hw_model");
1898 ver
= nvram_safe_get("boot_hw_ver");
1899 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
;
1901 nvram_set("usb_uhci", "-1");
1903 if (!nvram_match("t_fix1", (char *)name
)) {
1904 #ifdef TCONFIG_USBAP
1905 nvram_set("wl1_hwaddr", nvram_safe_get("usb/0xBD17/macaddr"));
1906 nvram_set("ehciirqt", "3");
1907 nvram_set("qtdc_pid", "48407");
1908 nvram_set("qtdc_vid", "2652");
1909 nvram_set("qtdc0_ep", "4");
1910 nvram_set("qtdc0_sz", "0");
1911 nvram_set("qtdc1_ep", "18");
1912 nvram_set("qtdc1_sz", "10");
1913 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1914 nvram_set("landevs", "vlan1 wl0 wl1");
1915 nvram_set("wl0_ifname", "eth1");
1916 nvram_set("wl1_ifname", "eth2");
1918 nvram_set("lan_ifnames", "vlan1 eth1");
1919 nvram_set("landevs", "vlan1 wl0");
1921 nvram_set("wl_ifname", "eth1");
1922 nvram_set("wan_ifnameX", "vlan2");
1926 case MODEL_WRT160Nv3
:
1927 // same as M10, M20, WRT310Nv2, E1000v1
1929 name
= nvram_safe_get("boot_hw_model");
1930 ver
= nvram_safe_get("boot_hw_ver");
1931 if (nvram_match("boot_hw_model", "E100")){
1934 if (nvram_match("boot_hw_model", "M10") || nvram_match("boot_hw_model", "M20")){
1937 features
= SUP_SES
| SUP_80211N
| SUP_WHAM_LED
;
1938 if (!nvram_match("t_fix1", (char *)name
)) {
1939 nvram_set("lan_ifnames", "vlan1 eth1");
1940 nvram_set("wan_ifnameX", "vlan2");
1941 nvram_set("wl_ifname", "eth1");
1946 name
= nvram_match("boardrev", "0x1307") ? "E2000" : "WRT320N";
1947 features
= SUP_SES
| SUP_80211N
| SUP_WHAM_LED
| SUP_1000ET
;
1948 if (!nvram_match("t_fix1", (char *)name
)) {
1949 nvram_set("lan_ifnames", "vlan1 eth1");
1950 nvram_set("wan_ifnameX", "vlan2");
1951 nvram_set("wl_ifname", "eth1");
1954 case MODEL_WRT610Nv2
:
1956 name
= nvram_match("boot_hw_model", "E300") ? "E3000" : "WRT610N v2";
1957 features
= SUP_SES
| SUP_80211N
| SUP_WHAM_LED
| SUP_1000ET
;
1959 nvram_set("usb_uhci", "-1");
1961 if (!nvram_match("t_fix1", (char *)name
)) {
1962 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1963 nvram_set("wan_ifnameX", "vlan2");
1964 nvram_set("wl_ifname", "eth1");
1970 features
= SUP_SES
| SUP_80211N
| SUP_1000ET
;
1972 nvram_set("usb_uhci", "-1");
1974 if (!nvram_match("t_fix1", (char *)name
)) {
1975 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1976 nvram_set("wan_ifnameX", "vlan2");
1977 nvram_set("wl_ifname", "eth1");
1980 #endif // CONFIG_BCMWL5
1985 // The 330gE has only one wired port which can act either as WAN or LAN.
1986 // Failsafe mode is to have it start as a LAN port so you can get an IP
1987 // address via DHCP and access the router config page.
1988 if (!nvram_match("t_fix1", (char *)name
)) {
1989 nvram_set("wl_ifname", "eth1");
1990 nvram_set("lan_ifnames", "eth1");
1991 nvram_set("wan_ifnameX", "eth0");
1992 nvram_set("wan_islan", "1");
1993 nvram_set("wan_proto", "disabled");
1996 case MODEL_WL500GPv2
:
1998 name
= "WL-500gP v2";
2001 nvram_set("usb_uhci", "-1");
2009 nvram_set("usb_uhci", "-1");
2014 name
= "WL-500g Deluxe";
2015 // features = SUP_SES;
2017 nvram_set("usb_ohci", "-1");
2019 if (!nvram_match("t_fix1", (char *)name
)) {
2020 nvram_set("wl_ifname", "eth1");
2021 nvram_set("lan_ifnames", "vlan0 eth1");
2022 nvram_set("wan_ifnameX", "vlan1");
2023 nvram_unset("wl0gpio0");
2030 if (!nvram_match("t_fix1", (char *)name
)) {
2031 nvram_set("wan_ifnameX", "vlan1");
2032 nvram_set("wl_ifname", "eth1");
2037 name
= "ZXV10 H618B";
2038 features
= SUP_SES
| SUP_AOSS_LED
;
2040 nvram_set("usb_uhci", "-1");
2042 if (!nvram_match("t_fix1", (char *)name
)) {
2043 nvram_set("lan_ifnames", "vlan0 eth1");
2044 nvram_set("wan_ifname", "vlan1");
2045 nvram_set("wan_ifnames", "vlan1");
2046 nvram_set("wan_ifnameX", "vlan1");
2047 nvram_set("wl_ifname", "eth1");
2050 case MODEL_WL1600GL
:
2055 #endif // WL_BSS_INFO_VERSION >= 108
2056 case MODEL_WZRG300N
:
2059 features
= SUP_SES
| SUP_AOSS_LED
| SUP_BRAU
| SUP_80211N
;
2061 case MODEL_WRT160Nv1
:
2064 name
= (model
== MODEL_WRT300N
) ? "WRT300N v1" : "WRT160N v1";
2065 features
= SUP_SES
| SUP_80211N
;
2066 if (!nvram_match("t_fix1", (char *)name
)) {
2067 nvram_set("wan_ifnameX", "eth1");
2068 nvram_set("lan_ifnames", "eth0 eth2");
2071 case MODEL_WRT310Nv1
:
2073 name
= "WRT310N v1";
2074 features
= SUP_SES
| SUP_80211N
| SUP_WHAM_LED
| SUP_1000ET
;
2075 if (!nvram_match("t_fix1", (char *)name
)) {
2076 nvram_set("lan_ifnames", "vlan1 eth1");
2077 nvram_set("wan_ifnameX", "vlan2");
2078 nvram_set("wl_ifname", "eth1");
2084 nvram_set("t_fix1", name
);
2085 if (ver
&& strcmp(ver
, "")) {
2086 sprintf(s
, "%s %s v%s", mfr
, name
, ver
);
2088 sprintf(s
, "%s %s", mfr
, name
);
2092 snprintf(s
, sizeof(s
), "%s %d/%s/%s/%s/%s", mfr
, check_hw_type(),
2093 nvram_safe_get("boardtype"), nvram_safe_get("boardnum"), nvram_safe_get("boardrev"), nvram_safe_get("boardflags"));
2096 nvram_set("t_model_name", s
);
2098 nvram_set("pa0maxpwr", "400"); // allow Tx power up tp 400 mW, needed for ND only
2100 sprintf(s
, "0x%lX", features
);
2101 nvram_set("t_features", s
);
2104 note: set wan_ifnameX if wan_ifname needs to be overriden
2107 if (nvram_is_empty("wan_ifnameX")) {
2109 nvram_set("wan_ifnameX", ((strtoul(nvram_safe_get("boardflags"), NULL
, 0) & BFL_ENETVLAN
) ||
2110 (check_hw_type() == HW_BCM4712
)) ? "vlan1" : "eth1");
2112 p
= nvram_safe_get("wan_ifname");
2113 if ((*p
== 0) || (nvram_match("wl_ifname", p
))) {
2114 p
= ((strtoul(nvram_safe_get("boardflags"), NULL
, 0) & BFL_ENETVLAN
) ||
2115 (check_hw_type() == HW_BCM4712
)) ? "vlan1" : "eth1";
2117 nvram_set("wan_ifnameX", p
);
2121 //!!TB - do not force country code here to allow nvram override
2122 //nvram_set("wl_country", "JP");
2123 //nvram_set("wl_country_code", "JP");
2124 nvram_set("wan_get_dns", "");
2125 nvram_set("wan_get_domain", "");
2126 nvram_set("ppp_get_ip", "");
2127 nvram_set("action_service", "");
2128 nvram_set("jffs2_format", "0");
2129 nvram_set("rrules_radio", "-1");
2130 nvram_unset("https_crt_gen");
2131 nvram_unset("log_wmclear");
2133 nvram_set("ipv6_get_dns", "");
2135 #ifdef TCONFIG_MEDIA_SERVER
2136 nvram_unset("ms_rescan");
2138 if (nvram_get_int("http_id_gen") == 1) nvram_unset("http_id");
2140 nvram_unset("sch_rboot_last");
2141 nvram_unset("sch_rcon_last");
2142 nvram_unset("sch_c1_last");
2143 nvram_unset("sch_c2_last");
2144 nvram_unset("sch_c3_last");
2146 nvram_set("brau_state", "");
2147 if ((features
& SUP_BRAU
) == 0) nvram_set("script_brau", "");
2148 if ((features
& SUP_SES
) == 0) nvram_set("sesx_script", "");
2150 if ((features
& SUP_1000ET
) == 0) nvram_set("jumbo_frame_enable", "0");
2152 // compatibility with old versions
2153 if (nvram_match("wl_net_mode", "disabled")) {
2154 nvram_set("wl_radio", "0");
2155 nvram_set("wl_net_mode", "mixed");
2161 #ifndef TCONFIG_BCMARM
2162 /* Get the special files from nvram and copy them to disc.
2163 * These were files saved with "nvram setfile2nvram <filename>".
2164 * Better hope that they were saved with full pathname.
2166 static void load_files_from_nvram(void)
2170 char buf
[NVRAM_SPACE
];
2172 if (nvram_getall(buf
, sizeof(buf
)) != 0)
2175 for (name
= buf
; *name
; name
+= strlen(name
) + 1) {
2176 if (strncmp(name
, "FILE:", 5) == 0) { /* This special name marks a file to get. */
2177 if ((cp
= strchr(name
, '=')) == NULL
)
2180 syslog(LOG_INFO
, "Loading file '%s' from nvram", name
+ 5);
2181 nvram_nvram2file(name
, name
+ 5);
2182 if (memcmp(".autorun", cp
- 8, 9) == 0)
2186 /* Start any autorun files that may have been loaded into one of the standard places. */
2188 run_nvscript(".autorun", NULL
, 3);
2192 #if defined(LINUX26) && defined(TCONFIG_USB)
2193 static inline void tune_min_free_kbytes(void)
2195 struct sysinfo info
;
2197 memset(&info
, 0, sizeof(struct sysinfo
));
2199 if (info
.totalram
>= 55 * 1024 * 1024) {
2200 // If we have 64MB+ RAM, tune min_free_kbytes
2201 // to reduce page allocation failure errors.
2202 f_write_string("/proc/sys/vm/min_free_kbytes", "8192", 0, 0);
2207 static void sysinit(void)
2209 static int noconsole
= 0;
2210 static const time_t tm
= 0;
2218 mount("proc", "/proc", "proc", 0, NULL
);
2219 mount("tmpfs", "/tmp", "tmpfs", 0, NULL
);
2222 mount("devfs", "/dev", "tmpfs", MS_MGC_VAL
| MS_NOATIME
, NULL
);
2223 mknod("/dev/null", S_IFCHR
| 0666, makedev(1, 3));
2224 mknod("/dev/console", S_IFCHR
| 0600, makedev(5, 1));
2225 mount("sysfs", "/sys", "sysfs", MS_MGC_VAL
, NULL
);
2226 mkdir("/dev/shm", 0777);
2227 mkdir("/dev/pts", 0777);
2228 mknod("/dev/pts/ptmx", S_IRWXU
|S_IFCHR
, makedev(5, 2));
2229 mknod("/dev/pts/0", S_IRWXU
|S_IFCHR
, makedev(136, 0));
2230 mknod("/dev/pts/1", S_IRWXU
|S_IFCHR
, makedev(136, 1));
2231 mount("devpts", "/dev/pts", "devpts", MS_MGC_VAL
, NULL
);
2234 if (console_init()) noconsole
= 1;
2238 static const char *mkd
[] = {
2239 "/tmp/etc", "/tmp/var", "/tmp/home", "/tmp/mnt",
2240 "/tmp/splashd", //!!Victek
2241 "/tmp/share", "/var/webmon", // !!TB
2242 "/var/log", "/var/run", "/var/tmp", "/var/lib", "/var/lib/misc",
2243 "/var/spool", "/var/spool/cron", "/var/spool/cron/crontabs",
2244 "/tmp/var/wwwext", "/tmp/var/wwwext/cgi-bin", // !!TB - CGI support
2248 for (i
= 0; mkd
[i
]; ++i
) {
2249 mkdir(mkd
[i
], 0755);
2251 mkdir("/var/lock", 0777);
2252 mkdir("/var/tmp/dhcp", 0777);
2253 mkdir("/home/root", 0700);
2254 chmod("/tmp", 0777);
2255 f_write("/etc/hosts", NULL
, 0, 0, 0644); // blank
2256 f_write("/etc/fstab", NULL
, 0, 0, 0644); // !!TB - blank
2257 simple_unlock("cron");
2258 simple_unlock("firewall");
2259 simple_unlock("restrictions");
2262 if ((d
= opendir("/rom/etc")) != NULL
) {
2263 while ((de
= readdir(d
)) != NULL
) {
2264 if (de
->d_name
[0] == '.') continue;
2265 snprintf(s
, sizeof(s
), "%s/%s", "/rom/etc", de
->d_name
);
2266 snprintf(t
, sizeof(t
), "%s/%s", "/etc", de
->d_name
);
2271 symlink("/proc/mounts", "/etc/mtab");
2273 #ifdef TCONFIG_SAMBASRV
2274 if ((d
= opendir("/usr/codepages")) != NULL
) {
2275 while ((de
= readdir(d
)) != NULL
) {
2276 if (de
->d_name
[0] == '.') continue;
2277 snprintf(s
, sizeof(s
), "/usr/codepages/%s", de
->d_name
);
2278 snprintf(t
, sizeof(t
), "/usr/share/%s", de
->d_name
);
2286 eval("hotplug2", "--coldplug");
2289 static const char *dn
[] = {
2290 "null", "zero", "random", "urandom", "full", "ptmx", "nvram",
2293 for (i
= 0; dn
[i
]; ++i
) {
2294 snprintf(s
, sizeof(s
), "/dev/%s", dn
[i
]);
2297 chmod("/dev/gpio", 0660);
2300 set_action(ACT_IDLE
);
2302 for (i
= 0; defenv
[i
]; ++i
) {
2307 printf("\n\nHit ENTER for console...\n\n");
2314 // disable IPv6 by default on all interfaces
2315 f_write_string("/proc/sys/net/ipv6/conf/default/disable_ipv6", "1", 0, 0);
2318 for (i
= 0; i
< sizeof(fatalsigs
) / sizeof(fatalsigs
[0]); i
++) {
2319 signal(fatalsigs
[i
], handle_fatalsigs
);
2321 signal(SIGCHLD
, handle_reap
);
2323 #ifdef CONFIG_BCMWL5
2324 // ctf must be loaded prior to any other modules
2325 if (nvram_invmatch("ctf_disable", "1"))
2334 switch (hardware
= check_hw_type()) {
2336 modprobe("bcm57xx");
2347 // eval("nvram", "defaults", "--initcheck");
2348 restore_defaults(); // restore default if necessary
2351 // set the packet size
2352 if (nvram_get_int("jumbo_frame_enable")) {
2353 // only set the size here - 'enable' flag is set by the driver
2354 // eval("et", "robowr", "0x40", "0x01", "0x1F"); // (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4)
2355 eval("et", "robowr", "0x40", "0x05", nvram_safe_get("jumbo_frame_size"));
2358 klogctl(8, NULL
, nvram_get_int("console_loglevel"));
2360 #if defined(LINUX26) && defined(TCONFIG_USB)
2361 tune_min_free_kbytes();
2364 set_host_domain_name();
2370 #ifdef CONFIG_BCMWL6
2374 if (!noconsole
) xstart("console");
2376 i
= nvram_get_int("sesx_led");
2377 led(LED_AMBER
, (i
& 1) != 0);
2378 led(LED_WHITE
, (i
& 2) != 0);
2379 led(LED_AOSS
, (i
& 4) != 0);
2380 led(LED_BRIDGE
, (i
& 8) != 0);
2384 int init_main(int argc
, char *argv
[])
2390 nvram_unset("debug_rc_svc");
2394 sigemptyset(&sigset
);
2395 for (i
= 0; i
< sizeof(initsigs
) / sizeof(initsigs
[0]); i
++) {
2396 sigaddset(&sigset
, initsigs
[i
]);
2398 sigprocmask(SIG_BLOCK
, &sigset
, NULL
);
2400 #if defined(DEBUG_NOISY)
2401 nvram_set("debug_logeval", "1");
2402 nvram_set("debug_cprintf", "1");
2403 nvram_set("debug_cprintf_file", "1");
2404 nvram_set("debug_ddns", "1");
2409 state
= SIGUSR2
; /* START */
2412 TRACE_PT("main loop signal/state=%d\n", state
);
2415 case SIGUSR1
: /* USER1: service handler */
2419 case SIGHUP
: /* RESTART */
2420 case SIGINT
: /* STOP */
2421 case SIGQUIT
: /* HALT */
2422 case SIGTERM
: /* REBOOT */
2424 unlink("/var/notice/sysup");
2426 if( nvram_match( "webmon_bkp", "1" ) )
2427 xstart( "/usr/sbin/webmon_bkp", "hourly" ); // make a copy before halt/reboot router
2429 run_nvscript("script_shut", NULL
, 10);
2437 if ((state
== SIGTERM
/* REBOOT */) ||
2438 (state
== SIGQUIT
/* HALT */)) {
2439 remove_storage_main(1);
2442 shutdn(state
== SIGTERM
/* REBOOT */);
2445 if (state
== SIGINT
/* STOP */) {
2449 // SIGHUP (RESTART) falls through
2451 case SIGUSR2
: /* START */
2452 SET_LED(RELEASE_WAN_CONTROL
);
2455 #ifndef TCONFIG_BCMARM
2456 load_files_from_nvram();
2460 fd
= file_lock("usb"); // hold off automount processing
2463 xstart("/usr/sbin/mymotd", "init");
2464 run_nvscript("script_init", NULL
, 2);
2466 file_unlock(fd
); // allow to process usb hotplug events
2469 * On RESTART some partitions can stay mounted if they are busy at the moment.
2470 * In that case USB drivers won't unload, and hotplug won't kick off again to
2471 * remount those drives that actually got unmounted. Make sure to remount ALL
2472 * partitions here by simulating hotplug event.
2474 if (state
== SIGHUP
/* RESTART */)
2475 add_remove_usbhost("-1", 1);
2486 #ifdef CONFIG_BCMWL5
2488 /* Restart NAS one more time - for some reason without
2489 * this the new driver doesn't always bring WDS up.
2496 syslog(LOG_INFO
, "%s: Tomato %s", nvram_safe_get("t_model_name"), tomato_version
);
2499 notice_set("sysup", "");
2503 chld_reap(0); /* Periodically reap zombies. */
2505 sigwait(&sigset
, &state
);
2511 int reboothalt_main(int argc
, char *argv
[])
2513 int reboot
= (strstr(argv
[0], "reboot") != NULL
);
2514 puts(reboot
? "Rebooting..." : "Shutting down...");
2517 kill(1, reboot
? SIGTERM
: SIGQUIT
);
2519 /* In the case we're hung, we'll get stuck and never actually reboot.
2520 * The only way out is to pull power.
2521 * So after 'reset_wait' seconds (default: 20), forcibly crash & restart.
2524 int wait
= nvram_get_int("reset_wait") ? : 20;
2525 if ((wait
< 10) || (wait
> 120)) wait
= 10;
2527 f_write("/proc/sysrq-trigger", "s", 1, 0 , 0); /* sync disks */
2529 puts("Still running... Doing machine reset.");
2531 f_write("/proc/sysrq-trigger", "s", 1, 0 , 0); /* sync disks */
2533 f_write("/proc/sysrq-trigger", "b", 1, 0 , 0); /* machine reset */