update #4 - router
[tomato.git] / release / src / router / rc / init.c
blob12e74dcff4f03f27832f4ee293dbf25fa12e38d5
1 /*
3 Copyright 2005, Broadcom Corporation
4 All Rights Reserved.
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.
13 #include "rc.h"
15 #include <termios.h>
16 #include <dirent.h>
17 #include <sys/ioctl.h>
18 #include <sys/mount.h>
19 #include <time.h>
20 #include <errno.h>
21 #include <paths.h>
22 #include <sys/wait.h>
23 #include <sys/reboot.h>
24 #include <sys/klog.h>
25 #ifdef LINUX26
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <sys/sysinfo.h>
29 #endif
30 #include <wlutils.h>
31 #include <bcmdevs.h>
33 #define SHELL "/bin/sh"
35 extern struct nvram_tuple router_defaults[];
37 void
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);
48 static void
49 restore_defaults(void)
51 struct nvram_tuple *t;
52 int restore_defaults;
53 char prefix[] = "usb_pathXXXXXXXXXXXXXXXXX_", tmp[100];
54 int unit;
55 int model;
57 /* Restore defaults if told to or OS has changed */
58 if(!restore_defaults)
59 restore_defaults = !nvram_match("restore_defaults", "0");
61 if (restore_defaults)
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);
75 #ifdef TCONFIG_BCMARM
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");
84 nvram_commit();
86 #endif
90 static int fatalsigs[] = {
91 SIGILL,
92 SIGABRT,
93 SIGFPE,
94 SIGPIPE,
95 SIGBUS,
96 SIGSYS,
97 SIGTRAP,
98 SIGPWR
101 static int initsigs[] = {
102 SIGHUP,
103 SIGUSR1,
104 SIGUSR2,
105 SIGINT,
106 SIGQUIT,
107 SIGALRM,
108 SIGTERM
111 static char *defenv[] = {
112 "TERM=vt100",
113 "HOME=/",
114 "PATH=/usr/bin:/bin:/usr/sbin:/sbin",
115 "SHELL=" SHELL,
116 "USER=root",
117 NULL
120 /* Set terminal settings to reasonable defaults */
121 static void set_term(int fd)
123 struct termios tty;
125 tcgetattr(fd, &tty);
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 */
138 tty.c_line = 0;
140 /* Make it be sane */
141 tty.c_cflag &= CBAUD|CBAUDEX|CSIZE|CSTOPB|PARENB|PARODD;
142 tty.c_cflag |= CREAD|HUPCL|CLOCAL;
145 /* input modes */
146 tty.c_iflag = ICRNL | IXON | IXOFF;
148 /* output modes */
149 tty.c_oflag = OPOST | ONLCR;
151 /* local modes */
152 tty.c_lflag =
153 ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE | IEXTEN;
155 tcsetattr(fd, TCSANOW, &tty);
158 static int console_init(void)
160 int fd;
162 /* Clean up */
163 ioctl(0, TIOCNOTTY, 0);
164 close(0);
165 close(1);
166 close(2);
167 setsid();
169 /* Reopen console */
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);
176 return errno;
178 dup2(fd, 0);
179 dup2(fd, 1);
180 dup2(fd, 2);
182 ioctl(0, TIOCSCTTY, 1);
183 tcsetpgrp(0, getpgrp());
184 set_term(0);
186 return 0;
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)
197 fd_set rfds;
198 struct timeval tv = { timeout, 0 };
200 FD_ZERO(&rfds);
201 FD_SET(fd, &rfds);
202 return select(fd + 1, &rfds, NULL, NULL, (timeout > 0) ? &tv : NULL);
205 static pid_t run_shell(int timeout, int nowait)
207 pid_t pid;
208 int sig;
210 /* Wait for user input */
211 if (waitfor(STDIN_FILENO, timeout) <= 0) return 0;
213 switch (pid = fork()) {
214 case -1:
215 perror("fork");
216 return 0;
217 case 0:
218 /* Reset signal handlers set for parent process */
219 for (sig = 0; sig < (_NSIG-1); sig++)
220 signal(sig, SIG_DFL);
222 /* Reopen console */
223 console_init();
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. */
231 perror(SHELL);
232 exit(errno);
233 default:
234 if (nowait) {
235 return pid;
237 else {
238 waitpid(pid, NULL, 0);
239 return 0;
244 int console_main(int argc, char *argv[])
246 for (;;) run_shell(0, 0);
248 return 0;
251 static void shutdn(int rb)
253 int i;
254 int act;
255 sigset_t ss;
257 _dprintf("shutdn rb=%d\n", rb);
259 sigemptyset(&ss);
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);
269 sleep(1);
271 set_action(ACT_REBOOT);
273 // Disconnect pppd - need this for PPTP/L2TP to finish gracefully
274 stop_pptp();
275 stop_l2tp();
277 _dprintf("TERM\n");
278 kill(-1, SIGTERM);
279 sleep(3);
280 sync();
282 _dprintf("KILL\n");
283 kill(-1, SIGKILL);
284 sleep(1);
285 sync();
287 umount("/jffs"); // may hang if not
288 sleep(1);
290 if (rb != -1) {
291 led(LED_WLAN, 0);
292 if (rb == 0) {
293 for (i = 4; i > 0; --i) {
294 led(LED_DMZ, 1);
295 led(LED_WHITE, 1);
296 usleep(250000);
297 led(LED_DMZ, 0);
298 led(LED_WHITE, 0);
299 usleep(250000);
304 reboot(rb ? RB_AUTOBOOT : RB_HALT_SYSTEM);
306 do {
307 sleep(1);
308 } while (1);
311 static void handle_fatalsigs(int sig)
313 _dprintf("fatal sig=%d\n", sig);
314 shutdn(-1);
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
323 * raising ALRM.
325 static void handle_reap(int sig)
327 chld_reap(sig);
328 raise(SIGALRM);
331 static int check_nv(const char *name, const char *value)
333 const char *p;
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);
338 return 1;
341 return 0;
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)
351 FILE *fp;
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);
358 fclose(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);
364 return 0;
367 static int find_dir320_mac_addr(void)
369 FILE *fp;
370 char *buffer, s[18];
371 int i, part, size, found = 0;
373 if (!mtd_getinfo("board_data", &part, &size))
374 goto out;
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);
385 s[17] = 0;
386 nvram_set("et0macaddr", s);
387 found = 1;
389 else if (!memcmp(buffer + i, "wanmac=", 7)) {
390 memcpy(s, buffer + i + 7, 17);
391 s[17] = 0;
392 nvram_set("il0macaddr", s);
393 if (!found) {
394 inc_mac(s, -1);
395 nvram_set("et0macaddr", s);
397 found = 1;
401 free(buffer);
402 fclose(fp);
404 out:
405 if (!found) {
406 strcpy(s, nvram_safe_get("wl0_hwaddr"));
407 inc_mac(s, -2);
408 nvram_set("et0macaddr", s);
410 return 1;
413 static int init_vlan_ports(void)
415 int dirty = 0;
416 int model = get_model();
418 switch (model) {
419 case MODEL_WRT54G:
420 switch (check_hw_type()) {
421 case HW_BCM5352E: // G v4, GS v3, v4
422 dirty |= check_nv("vlan0ports", "3 2 1 0 5*");
423 break;
425 break;
426 case MODEL_WTR54GS:
427 dirty |= check_nv("vlan0ports", "0 5*");
428 dirty |= check_nv("vlan1ports", "1 5");
429 dirty |= check_nv("vlan_enable", "1");
430 break;
431 case MODEL_WL500GP:
432 case MODEL_WL500GE:
433 case MODEL_WL500GPv2:
434 case MODEL_WL520GU:
435 case MODEL_WL330GE:
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");
440 break;
441 case MODEL_WL500GD:
442 dirty |= check_nv("vlan0ports", "1 2 3 4 5*");
443 dirty |= check_nv("vlan1ports", "0 5");
444 break;
445 case MODEL_DIR320:
446 case MODEL_H618B:
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");
451 break;
452 case MODEL_WRT310Nv1:
453 dirty |= check_nv("vlan1ports", "1 2 3 4 8*");
454 dirty |= check_nv("vlan2ports", "0 8");
455 break;
456 case MODEL_WL1600GL:
457 dirty |= check_nv("vlan0ports", "0 1 2 3 5*");
458 dirty |= check_nv("vlan1ports", "4 5");
459 break;
460 #ifdef CONFIG_BCMWL5
461 case MODEL_WNR3500L:
462 case MODEL_WRT320N:
463 case MODEL_WNR3500LV2:
464 case MODEL_RTN16:
465 case MODEL_RTN66U:
466 dirty |= check_nv("vlan1ports", "4 3 2 1 8*");
467 dirty |= check_nv("vlan2ports", "0 8");
468 break;
469 case MODEL_W1800R:
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");
474 break;
475 case MODEL_D1800H:
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");
485 break;
486 case MODEL_RTN53:
487 dirty |= check_nv("vlan2ports", "0 1 2 3 5*");
488 dirty |= check_nv("vlan1ports", "4 5");
489 break;
490 case MODEL_RTN53A1:
491 dirty |= check_nv("vlan1ports", "4 5");
492 dirty |= check_nv("vlan2ports", "3 2 1 0 5*");
493 break;
494 case MODEL_WNR2000v2:
495 dirty |= check_nv("vlan1ports", "4 3 2 1 5*");
496 dirty |= check_nv("vlan2ports", "0 5");
497 break;
498 case MODEL_HG320:
499 case MODEL_H218N:
500 dirty |= check_nv("vlan1ports", "1 2 3 4 5*");
501 dirty |= check_nv("vlan2ports", "0 5");
502 break;
503 case MODEL_RG200E_CA:
504 dirty |= check_nv("vlan2ports", "0 5");
505 break;
506 case MODEL_RTN10:
507 dirty |= check_nv("vlan1ports", "4 5");
508 break;
509 case MODEL_RTN10U:
510 case MODEL_CW5358U:
511 dirty |= check_nv("vlan0ports", "1 2 3 4 5*");
512 dirty |= check_nv("vlan1ports", "0 5");
513 break;
514 case MODEL_RTN10P:
515 case MODEL_RTN12:
516 case MODEL_RTN12B1:
517 dirty |= check_nv("vlan0ports", "3 2 1 0 5*");
518 dirty |= check_nv("vlan1ports", "4 5");
519 break;
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");
524 break;
525 case MODEL_F7D3301:
526 case MODEL_F7D4301:
527 dirty |= check_nv("vlan1ports", "3 2 1 0 8*");
528 dirty |= check_nv("vlan2ports", "4 8");
529 break;
530 case MODEL_E900:
531 case MODEL_E1500:
532 case MODEL_E1550:
533 case MODEL_E2500:
534 case MODEL_F7D3302:
535 case MODEL_F7D4302:
536 case MODEL_DIR620C1:
537 dirty |= check_nv("vlan1ports", "0 1 2 3 5*");
538 dirty |= check_nv("vlan2ports", "4 5");
539 break;
540 case MODEL_E1000v2:
541 case MODEL_L600N:
542 dirty |= check_nv("vlan1ports", "1 2 3 4 5*");
543 dirty |= check_nv("vlan2ports", "0 5");
544 break;
545 case MODEL_RTN15U:
546 case MODEL_E3200:
547 case MODEL_E4200:
548 dirty |= check_nv("vlan1ports", "0 1 2 3 8*");
549 dirty |= check_nv("vlan2ports", "4 8");
550 break;
551 case MODEL_TDN60:
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");
556 break;
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");
562 break;
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*")) {
569 // WRT310Nv2 ?
570 dirty |= check_nv("vlan1ports", "4 3 2 1 8*");
572 break;
573 #endif
574 #ifdef CONFIG_BCMWL6A
575 case MODEL_RTAC56U:
576 dirty |= check_nv("vlan1ports", "0 1 2 3 5*");
577 dirty |= check_nv("vlan2ports", "4 5");
578 break;
579 case MODEL_RTAC68U:
580 dirty |= check_nv("vlan1ports", "1 2 3 4 5*");
581 dirty |= check_nv("vlan2ports", "0 5");
582 break;
583 #endif
587 return dirty;
590 static void check_bootnv(void)
592 int dirty;
593 int hardware;
594 int model;
595 char mac[18];
597 model = get_model();
598 dirty = check_nv("wl0_leddc", "0x640000") | check_nv("wl1_leddc", "0x640000");
600 switch (model) {
601 case MODEL_WTR54GS:
602 dirty |= check_nv("vlan0hwname", "et0");
603 dirty |= check_nv("vlan1hwname", "et0");
604 break;
605 case MODEL_WBRG54:
606 dirty |= check_nv("wl0gpio0", "130");
607 break;
608 case MODEL_WR850GV1:
609 case MODEL_WR850GV2:
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");
615 break;
616 case MODEL_WL330GE:
617 dirty |= check_nv("wl0gpio1", "0x02");
618 break;
619 case MODEL_WL500W:
620 /* fix WL500W mac adresses for WAN port */
621 if (invalid_mac(nvram_get("et1macaddr"))) {
622 strcpy(mac, nvram_safe_get("et0macaddr"));
623 inc_mac(mac, 1);
624 dirty |= check_nv("et1macaddr", mac);
626 dirty |= check_nv("wl0gpio0", "0x88");
627 break;
628 case MODEL_WL500GP:
629 dirty |= check_nv("sdram_init", "0x0009"); // 32MB; defaults: 0x000b, 0x0009
630 dirty |= check_nv("wl0gpio0", "136");
631 break;
632 case MODEL_WL500GPv2:
633 case MODEL_WL520GU:
634 dirty |= check_nv("wl0gpio1", "136");
635 break;
636 case MODEL_WL500GD:
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");
641 break;
642 case MODEL_DIR320:
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");
649 dirty = 1;
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");
657 break;
658 case MODEL_H618B:
659 dirty |= check_nv("wandevs", "vlan1");
660 dirty |= check_nv("vlan0hwname", "et0");
661 dirty |= check_nv("vlan1hwname", "et0");
662 break;
663 case MODEL_WL1600GL:
664 if (invalid_mac(nvram_get("et0macaddr"))) {
665 dirty |= find_sercom_mac_addr();
667 break;
668 case MODEL_WRT160Nv1:
669 case MODEL_WRT310Nv1:
670 case MODEL_WRT300N:
671 dirty |= check_nv("wl0gpio0", "8");
672 break;
673 #ifdef CONFIG_BCMWL5
674 case MODEL_WNR3500L:
675 dirty |= check_nv("boardflags", "0x00000710"); // needed to enable USB
676 dirty |= check_nv("vlan2hwname", "et0");
677 dirty |= check_nv("ledbh0", "7");
678 break;
679 case MODEL_WNR3500LV2:
680 dirty |= check_nv("vlan2hwname", "et0");
681 break;
682 case MODEL_WNR2000v2:
683 dirty |= check_nv("ledbh5", "8");
684 break;
685 case MODEL_WRT320N:
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 */
690 case MODEL_RTN16:
691 dirty |= check_nv("vlan2hwname", "et0");
692 break;
693 case MODEL_HG320:
694 case MODEL_RG200E_CA:
695 case MODEL_H218N:
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");
700 break;
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"));
707 inc_mac(mac, 3);
708 dirty |= check_nv("pci/1/1/macaddr", mac);
710 break;
711 case MODEL_F7D3301:
712 case MODEL_F7D3302:
713 case MODEL_F7D4301:
714 case MODEL_F7D4302:
715 case MODEL_F5D8235v3:
716 if (nvram_match("sb/1/macaddr", nvram_safe_get("et0macaddr"))) {
717 strcpy(mac, nvram_safe_get("et0macaddr"));
718 inc_mac(mac, 2);
719 dirty |= check_nv("sb/1/macaddr", mac);
720 inc_mac(mac, 1);
721 dirty |= check_nv("pci/1/1/macaddr", mac);
723 case MODEL_EA6500V1:
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"));
727 inc_mac(mac, 3);
728 dirty |= check_nv("pci/2/1/macaddr", mac);
730 break;
731 case MODEL_E4200:
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"));
736 inc_mac(mac, 2);
737 dirty |= check_nv("sb/1/macaddr", mac);
738 inc_mac(mac, 1);
739 dirty |= check_nv("pci/1/1/macaddr", mac);
741 break;
742 case MODEL_E900:
743 case MODEL_E1000v2:
744 case MODEL_E1500:
745 case MODEL_E1550:
746 case MODEL_E2500:
747 case MODEL_E3200:
748 case MODEL_WRT160Nv3:
749 case MODEL_L600N:
750 case MODEL_DIR620C1:
751 dirty |= check_nv("vlan2hwname", "et0");
752 break;
753 #endif
755 case MODEL_WRT54G:
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");
770 mtd_erase("nvram");
771 goto REBOOT;
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");
781 switch (hardware) {
782 case HW_BCM5325E:
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");
790 if (dirty) {
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");
798 break;
799 case HW_BCM5352E: // G v4, GS v3, v4
800 dirty |= check_nv("sdram_init", "0x010b");
801 dirty |= check_nv("sdram_config", "0x0062");
802 if (dirty) {
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");
810 break;
811 case HW_BCM5354G:
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");
817 break;
818 case HW_BCM4704_BCM5325F:
819 // nothing to do
820 break;
821 default:
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");
827 break;
829 break;
831 } // switch (model)
833 dirty |= init_vlan_ports();
835 if (dirty) {
836 nvram_commit();
837 REBOOT: // do a simple reboot
838 sync();
839 reboot(RB_AUTOBOOT);
840 exit(0);
844 static int init_nvram(void)
846 unsigned long features;
847 int model;
848 const char *mfr;
849 const char *name;
850 const char *ver;
851 char s[256];
852 unsigned long bf;
853 unsigned long n;
855 model = get_model();
856 sprintf(s, "%d", model);
857 nvram_set("t_model", s);
859 mfr = "Broadcom";
860 name = NULL;
861 ver = NULL;
862 features = 0;
863 switch (model) {
864 case MODEL_WRT54G:
865 mfr = "Linksys";
866 name = "WRT54G/GS/GL";
867 switch (check_hw_type()) {
868 case HW_BCM4712:
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");
874 break;
875 case HW_BCM4702:
876 nvram_unset("gpio2");
877 nvram_unset("gpio3");
878 nvram_unset("gpio4");
879 nvram_unset("gpio5");
880 nvram_unset("gpio6");
881 break;
882 case HW_BCM5352E:
883 nvram_set("opo", "0x0008");
884 nvram_set("ag0", "0x02");
885 // drop
886 default:
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;
891 break;
893 break;
894 case MODEL_WTR54GS:
895 mfr = "Linksys";
896 name = "WTR54GS";
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");
907 features = SUP_SES;
908 break;
909 case MODEL_WRTSL54GS:
910 mfr = "Linksys";
911 name = "WRTSL54GS";
912 features = SUP_SES | SUP_WHAM_LED;
913 break;
914 case MODEL_WHRG54S:
915 mfr = "Buffalo";
916 name = "WHR-G54S";
917 features = SUP_SES | SUP_AOSS_LED | SUP_BRAU;
918 break;
919 case MODEL_WHRHPG54:
920 case MODEL_WZRRSG54HP:
921 case MODEL_WZRHPG54:
922 mfr = "Buffalo";
923 features = SUP_SES | SUP_AOSS_LED | SUP_HPAMP;
924 switch (model) {
925 case MODEL_WZRRSG54HP:
926 name = "WZR-RS-G54HP";
927 break;
928 case MODEL_WZRHPG54:
929 name = "WZR-HP-G54";
930 break;
931 default:
932 name = "WHR-HP-G54";
933 features = SUP_SES | SUP_AOSS_LED | SUP_BRAU | SUP_HPAMP;
934 break;
937 bf = strtoul(nvram_safe_get("boardflags"), NULL, 0);
938 switch (bf) {
939 case 0x0758:
940 case 0x1758:
941 case 0x2758:
942 case 0x3758:
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");
949 n = bf;
950 if (nvram_match("wlx_hpamp", "0")) {
951 n &= ~0x2000UL;
953 else {
954 n |= 0x2000UL;
956 if (nvram_match("wlx_hperx", "0")) {
957 n |= 0x1000UL;
959 else {
960 n &= ~0x1000UL;
962 if (bf != n) {
963 sprintf(s, "0x%lX", n);
964 nvram_set("boardflags", s);
966 break;
967 default:
968 syslog(LOG_WARNING, "Unexpected: boardflag=%lX", bf);
969 break;
971 break;
972 case MODEL_WBRG54:
973 mfr = "Buffalo";
974 name = "WBR-G54";
975 break;
976 case MODEL_WBR2G54:
977 mfr = "Buffalo";
978 name = "WBR2-G54";
979 features = SUP_SES | SUP_AOSS_LED;
980 break;
981 case MODEL_WHR2A54G54:
982 mfr = "Buffalo";
983 name = "WHR2-A54G54";
984 features = SUP_SES | SUP_AOSS_LED | SUP_BRAU;
985 break;
986 case MODEL_WHR3AG54:
987 mfr = "Buffalo";
988 name = "WHR3-AG54";
989 features = SUP_SES | SUP_AOSS_LED;
990 break;
991 case MODEL_WZRG54:
992 mfr = "Buffalo";
993 name = "WZR-G54";
994 features = SUP_SES | SUP_AOSS_LED;
995 break;
996 case MODEL_WZRRSG54:
997 mfr = "Buffalo";
998 name = "WZR-RS-G54";
999 features = SUP_SES | SUP_AOSS_LED;
1000 break;
1001 case MODEL_WVRG54NF:
1002 mfr = "Buffalo";
1003 name = "WVR-G54-NF";
1004 features = SUP_SES;
1005 break;
1006 case MODEL_WZRG108:
1007 mfr = "Buffalo";
1008 name = "WZR-G108";
1009 features = SUP_SES | SUP_AOSS_LED;
1010 break;
1011 case MODEL_RT390W:
1012 mfr = "Fuji";
1013 name = "RT390W";
1014 break;
1015 case MODEL_WR850GV1:
1016 mfr = "Motorola";
1017 name = "WR850G v1";
1018 features = SUP_NONVE;
1019 break;
1020 case MODEL_WR850GV2:
1021 mfr = "Motorola";
1022 name = "WR850G v2/v3";
1023 features = SUP_NONVE;
1024 break;
1025 case MODEL_WL500GP:
1026 mfr = "Asus";
1027 name = "WL-500gP";
1028 features = SUP_SES;
1029 #ifdef TCONFIG_USB
1030 nvram_set("usb_ohci", "-1");
1031 #endif
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
1035 break;
1036 case MODEL_WL500W:
1037 mfr = "Asus";
1038 name = "WL-500W";
1039 features = SUP_SES | SUP_80211N;
1040 #ifdef TCONFIG_USB
1041 nvram_set("usb_ohci", "-1");
1042 #endif
1043 break;
1044 case MODEL_WL500GE:
1045 mfr = "Asus";
1046 name = "WL-550gE";
1047 // features = ?
1048 #ifdef TCONFIG_USB
1049 nvram_set("usb_uhci", "-1");
1050 #endif
1051 break;
1052 case MODEL_WX6615GT:
1053 mfr = "SparkLAN";
1054 name = "WX-6615GT";
1055 // features = ?
1056 break;
1057 case MODEL_MN700:
1058 mfr = "Microsoft";
1059 name = "MN-700";
1060 break;
1061 case MODEL_WR100:
1062 mfr = "Viewsonic";
1063 name = "WR100";
1064 break;
1065 case MODEL_WLA2G54L:
1066 mfr = "Buffalo";
1067 name = "WLA2-G54L";
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");
1073 break;
1074 case MODEL_TM2300:
1075 mfr = "Dell";
1076 name = "TrueMobile 2300";
1077 break;
1085 #ifndef WL_BSS_INFO_VERSION
1086 #error WL_BSS_INFO_VERSION
1087 #endif
1088 #if WL_BSS_INFO_VERSION >= 108
1090 case MODEL_WRH54G:
1091 mfr = "Linksys";
1092 name = "WRH54G";
1094 nvram_set("opo", "12");
1095 break;
1097 case MODEL_WHRG125:
1098 mfr = "Buffalo";
1099 name = "WHR-G125";
1100 features = SUP_SES | SUP_AOSS_LED | SUP_BRAU;
1102 nvram_set("opo", "0x0008");
1103 nvram_set("ag0", "0x0C");
1104 break;
1105 #ifdef CONFIG_BCMWL5
1106 case MODEL_L600N:
1107 mfr = "Rosewill";
1108 name = "L600N";
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");
1124 #else
1125 nvram_set("lan_ifnames", "vlan1 eth1");
1126 nvram_set("landevs", "vlan1 wl0");
1127 #endif
1128 nvram_set("wl_ifname", "eth1");
1129 nvram_set("wan_ifnameX", "vlan2");
1130 nvram_set("wandevs", "vlan2");
1132 break;
1133 case MODEL_DIR620C1:
1134 mfr = "D-Link";
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");
1143 #else
1144 nvram_set("lan_ifnames", "vlan1 eth1");
1145 nvram_set("landevs", "vlan1 wl0");
1146 #endif
1147 nvram_set("wan_ifnameX", "vlan2");
1148 nvram_set("wl_ifname", "eth1");
1151 break;
1152 case MODEL_CW5358U:
1153 mfr = "Catchtech";
1154 name = "CW-5358U";
1155 features = SUP_SES | SUP_80211N;
1156 #ifdef TCONFIG_USB
1157 nvram_set("usb_uhci", "-1");
1158 #endif
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");
1166 break;
1167 case MODEL_HG320:
1168 mfr = "FiberHome";
1169 name = "HG320";
1170 features = SUP_SES | SUP_80211N;
1171 #ifdef TCONFIG_USB
1172 nvram_set("usb_uhci", "-1");
1173 #endif
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");
1181 break;
1182 case MODEL_RG200E_CA:
1183 mfr = "ChinaNet";
1184 name = "RG200E-CA";
1185 features = SUP_SES | SUP_80211N;
1186 #ifdef TCONFIG_USB
1187 nvram_set("usb_uhci", "-1");
1188 #endif
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");
1196 break;
1197 case MODEL_H218N:
1198 mfr = "ZTE";
1199 name = "H218N";
1200 features = SUP_SES | SUP_80211N;
1201 #ifdef TCONFIG_USB
1202 nvram_set("usb_uhci", "-1");
1203 #endif
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");
1211 break;
1212 case MODEL_TDN60:
1213 mfr = "Tenda";
1214 name = "N60";
1215 features = SUP_SES | SUP_80211N;
1216 #ifdef TCONFIG_USB
1217 nvram_set("usb_uhci", "-1");
1218 #endif
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");
1236 // fix WL mac`s
1237 nvram_set("wl0_hwaddr", nvram_safe_get("sb/1/macaddr"));
1238 nvram_set("wl1_hwaddr", nvram_safe_get("0:macaddr"));
1240 break;
1241 case MODEL_TDN6:
1242 mfr = "Tenda";
1243 name = "N6";
1244 features = SUP_SES | SUP_80211N;
1245 #ifdef TCONFIG_USB
1246 nvram_set("usb_uhci", "-1");
1247 #endif
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");
1263 // fix WL mac`s
1264 nvram_set("wl0_hwaddr", nvram_safe_get("sb/1/macaddr"));
1265 nvram_set("wl1_hwaddr", nvram_safe_get("0:macaddr"));
1267 break;
1268 case MODEL_RTN10:
1269 case MODEL_RTN10P:
1270 mfr = "Asus";
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");
1278 break;
1279 case MODEL_RTN10U:
1280 mfr = "Asus";
1281 name = "RT-N10U";
1282 features = SUP_SES | SUP_80211N;
1283 #ifdef TCONFIG_USB
1284 nvram_set("usb_uhci", "-1");
1285 #endif
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");
1291 break;
1292 case MODEL_RTN12:
1293 mfr = "Asus";
1294 name = "RT-N12";
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");
1301 break;
1302 case MODEL_RTN12B1:
1303 mfr = "Asus";
1304 name = "RT-N12 B1";
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");
1311 break;
1312 case MODEL_RTN15U:
1313 mfr = "Asus";
1314 name = "RT-N15U";
1315 features = SUP_SES | SUP_80211N | SUP_1000ET;
1316 #ifdef TCONFIG_USB
1317 nvram_set("usb_uhci", "-1");
1318 #endif
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");
1327 break;
1328 case MODEL_RTN16:
1329 mfr = "Asus";
1330 name = "RT-N16";
1331 features = SUP_SES | SUP_80211N | SUP_1000ET;
1332 #ifdef TCONFIG_USB
1333 nvram_set("usb_uhci", "-1");
1334 #endif
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");
1341 break;
1342 case MODEL_RTN53:
1343 case MODEL_RTN53A1:
1344 mfr = "Asus";
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");
1349 #endif
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");
1363 #else
1364 nvram_set("lan_ifnames", "vlan2 eth1");
1365 nvram_set("landevs", "vlan2 wl0");
1366 #endif
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");
1374 break;
1375 #ifdef CONFIG_BCMWL6A
1376 case MODEL_RTAC56U:
1377 mfr = "Asus";
1378 name = "RT-AC56U";
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);
1404 #endif
1405 #ifdef TCONFIG_TURBO
1406 nvram_set_int("btn_turbo_gpio", 5);
1407 #endif
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");
1413 #else
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");
1419 else{
1420 nvram_unset("xhci_ports");
1421 nvram_set("ehci_ports", "1-1 1-2");
1422 nvram_set("ohci_ports", "2-1 2-2");
1424 #endif
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");
1435 break;
1436 case MODEL_RTAC68U:
1437 mfr = "Asus";
1438 name = "RT-AC68U";
1439 features = SUP_SES | SUP_80211N | SUP_1000ET | SUP_80211AC;
1440 #ifdef TCONFIG_USB
1441 nvram_set("usb_uhci", "-1");
1442 #endif
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");
1457 // fix WL mac`s
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");
1472 else
1473 nvram_set("wl1_chanspec", "149/80");
1475 if ((nvram_get_int("wlopmode") == 7) || nvram_match("ATEMODE", "1"))
1476 nvram_set("usb_usb3", "1");
1478 break;
1479 #endif
1480 case MODEL_RTN66U:
1481 mfr = "Asus";
1482 #ifdef TCONFIG_AC66U
1483 name = "RT-AC66U";
1484 features = SUP_SES | SUP_80211N | SUP_1000ET | SUP_80211AC;
1485 #else
1486 name = "RT-N66U";
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");
1490 #endif
1491 #endif
1493 #ifdef TCONFIG_USB
1494 nvram_set("usb_uhci", "-1");
1495 #endif
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");
1504 #endif
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 */
1510 #endif
1511 #else
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");
1518 // fix WL mac`s
1519 strcpy(s, nvram_safe_get("et0macaddr"));
1520 inc_mac(s, +2);
1521 nvram_set("wl0_hwaddr", s);
1522 inc_mac(s, +1);
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
1614 break;
1615 #ifdef CONFIG_BCMWL6
1616 case MODEL_W1800R:
1617 mfr = "Tenda";
1618 name = "W1800R";
1619 features = SUP_SES | SUP_80211N | SUP_1000ET | SUP_80211AC;
1620 #ifdef TCONFIG_USB
1621 nvram_set("usb_uhci", "-1");
1622 #endif
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");
1638 // fix WL mac`s
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");
1648 break;
1649 case MODEL_D1800H:
1650 mfr = "Buffalo";
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";
1657 else {
1658 name = "WZR-D1800H";
1660 features = SUP_SES | SUP_AOSS_LED | SUP_80211N | SUP_1000ET | SUP_80211AC;
1661 #ifdef TCONFIG_USB
1662 nvram_set("usb_uhci", "-1");
1663 #endif
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");
1677 // fix WL mac`s
1678 strcpy(s, nvram_safe_get("et0macaddr"));
1679 trimstr(s);
1680 int i;
1681 for (i = 0; i < strlen(s); i ++) if ( s[i] == '-') s[i] = ':';
1682 nvram_set("et0macaddr",s);
1683 inc_mac(s, +2);
1684 nvram_set("wl0_hwaddr", s);
1685 inc_mac(s, +1);
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");
1741 break;
1742 case MODEL_EA6500V1:
1743 mfr = "Linksys";
1744 name = "EA6500v1";
1745 features = SUP_SES | SUP_80211N | SUP_1000ET | SUP_80211AC;
1746 #ifdef TCONFIG_USB
1747 nvram_set("usb_uhci", "-1");
1748 #endif
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"));
1771 break;
1772 #endif // CONFIG_BCMWL6
1773 case MODEL_WNR3500L:
1774 mfr = "Netgear";
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");
1783 break;
1784 case MODEL_WNR3500LV2:
1785 mfr = "Netgear";
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");
1793 break;
1794 case MODEL_WNR2000v2:
1795 mfr = "Netgear";
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");
1803 break;
1804 case MODEL_F7D3301:
1805 case MODEL_F7D3302:
1806 case MODEL_F7D4301:
1807 case MODEL_F7D4302:
1808 case MODEL_F5D8235v3:
1809 mfr = "Belkin";
1810 features = SUP_SES | SUP_80211N;
1811 switch (model) {
1812 case MODEL_F7D3301:
1813 name = "Share Max N300 (F7D3301/F7D7301) v1";
1814 break;
1815 case MODEL_F7D3302:
1816 name = "Share N300 (F7D3302/F7D7302) v1";
1817 break;
1818 case MODEL_F7D4301:
1819 name = "Play Max / N600 HD (F7D4301/F7D8301) v1";
1820 break;
1821 case MODEL_F7D4302:
1822 name = "Play N600 (F7D4302/F7D8302) v1";
1823 break;
1824 case MODEL_F5D8235v3:
1825 name = "N F5D8235-4 v3";
1826 break;
1828 #ifdef TCONFIG_USB
1829 nvram_set("usb_uhci", "-1");
1830 #endif
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");
1837 break;
1838 case MODEL_E900:
1839 case MODEL_E1500:
1840 mfr = "Linksys";
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");
1849 break;
1850 case MODEL_E1550:
1851 mfr = "Linksys";
1852 name = nvram_safe_get("boot_hw_model");
1853 ver = nvram_safe_get("boot_hw_ver");
1854 features = SUP_SES | SUP_80211N;
1855 #ifdef TCONFIG_USB
1856 nvram_set("usb_uhci", "-1");
1857 #endif
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");
1863 break;
1864 case MODEL_E2500:
1865 mfr = "Linksys";
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");
1871 #endif
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");
1886 #else
1887 nvram_set("lan_ifnames", "vlan1 eth1");
1888 nvram_set("landevs", "vlan1 wl0");
1889 #endif
1890 nvram_set("wan_ifnameX", "vlan2");
1891 nvram_set("wl_ifname", "eth1");
1894 break;
1895 case MODEL_E3200:
1896 mfr = "Linksys";
1897 name = nvram_safe_get("boot_hw_model");
1898 ver = nvram_safe_get("boot_hw_ver");
1899 features = SUP_SES | SUP_80211N | SUP_1000ET;
1900 #ifdef TCONFIG_USB
1901 nvram_set("usb_uhci", "-1");
1902 #endif
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");
1917 #else
1918 nvram_set("lan_ifnames", "vlan1 eth1");
1919 nvram_set("landevs", "vlan1 wl0");
1920 #endif
1921 nvram_set("wl_ifname", "eth1");
1922 nvram_set("wan_ifnameX", "vlan2");
1924 break;
1925 case MODEL_E1000v2:
1926 case MODEL_WRT160Nv3:
1927 // same as M10, M20, WRT310Nv2, E1000v1
1928 mfr = "Linksys";
1929 name = nvram_safe_get("boot_hw_model");
1930 ver = nvram_safe_get("boot_hw_ver");
1931 if (nvram_match("boot_hw_model", "E100")){
1932 name = "E1000";
1934 if (nvram_match("boot_hw_model", "M10") || nvram_match("boot_hw_model", "M20")){
1935 mfr = "Cisco";
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");
1943 break;
1944 case MODEL_WRT320N:
1945 mfr = "Linksys";
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");
1953 break;
1954 case MODEL_WRT610Nv2:
1955 mfr = "Linksys";
1956 name = nvram_match("boot_hw_model", "E300") ? "E3000" : "WRT610N v2";
1957 features = SUP_SES | SUP_80211N | SUP_WHAM_LED | SUP_1000ET;
1958 #ifdef TCONFIG_USB
1959 nvram_set("usb_uhci", "-1");
1960 #endif
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");
1966 break;
1967 case MODEL_E4200:
1968 mfr = "Linksys";
1969 name = "E4200 v1";
1970 features = SUP_SES | SUP_80211N | SUP_1000ET;
1971 #ifdef TCONFIG_USB
1972 nvram_set("usb_uhci", "-1");
1973 #endif
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");
1979 break;
1980 #endif // CONFIG_BCMWL5
1982 case MODEL_WL330GE:
1983 mfr = "Asus";
1984 name = "WL-330gE";
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");
1995 break;
1996 case MODEL_WL500GPv2:
1997 mfr = "Asus";
1998 name = "WL-500gP v2";
1999 features = SUP_SES;
2000 #ifdef TCONFIG_USB
2001 nvram_set("usb_uhci", "-1");
2002 #endif
2003 break;
2004 case MODEL_WL520GU:
2005 mfr = "Asus";
2006 name = "WL-520GU";
2007 features = SUP_SES;
2008 #ifdef TCONFIG_USB
2009 nvram_set("usb_uhci", "-1");
2010 #endif
2011 break;
2012 case MODEL_WL500GD:
2013 mfr = "Asus";
2014 name = "WL-500g Deluxe";
2015 // features = SUP_SES;
2016 #ifdef TCONFIG_USB
2017 nvram_set("usb_ohci", "-1");
2018 #endif
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");
2025 break;
2026 case MODEL_DIR320:
2027 mfr = "D-Link";
2028 name = "DIR-320";
2029 features = SUP_SES;
2030 if (!nvram_match("t_fix1", (char *)name)) {
2031 nvram_set("wan_ifnameX", "vlan1");
2032 nvram_set("wl_ifname", "eth1");
2034 break;
2035 case MODEL_H618B:
2036 mfr = "ZTE";
2037 name = "ZXV10 H618B";
2038 features = SUP_SES | SUP_AOSS_LED;
2039 #ifdef TCONFIG_USB
2040 nvram_set("usb_uhci", "-1");
2041 #endif
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");
2049 break;
2050 case MODEL_WL1600GL:
2051 mfr = "Ovislink";
2052 name = "WL1600GL";
2053 features = SUP_SES;
2054 break;
2055 #endif // WL_BSS_INFO_VERSION >= 108
2056 case MODEL_WZRG300N:
2057 mfr = "Buffalo";
2058 name = "WZR-G300N";
2059 features = SUP_SES | SUP_AOSS_LED | SUP_BRAU | SUP_80211N;
2060 break;
2061 case MODEL_WRT160Nv1:
2062 case MODEL_WRT300N:
2063 mfr = "Linksys";
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");
2070 break;
2071 case MODEL_WRT310Nv1:
2072 mfr = "Linksys";
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");
2080 break;
2083 if (name) {
2084 nvram_set("t_fix1", name);
2085 if (ver && strcmp(ver, "")) {
2086 sprintf(s, "%s %s v%s", mfr, name, ver);
2087 } else {
2088 sprintf(s, "%s %s", mfr, name);
2091 else {
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"));
2094 s[64] = 0;
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")) {
2108 #if 1
2109 nvram_set("wan_ifnameX", ((strtoul(nvram_safe_get("boardflags"), NULL, 0) & BFL_ENETVLAN) ||
2110 (check_hw_type() == HW_BCM4712)) ? "vlan1" : "eth1");
2111 #else
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);
2118 #endif
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");
2132 #ifdef TCONFIG_IPV6
2133 nvram_set("ipv6_get_dns", "");
2134 #endif
2135 #ifdef TCONFIG_MEDIA_SERVER
2136 nvram_unset("ms_rescan");
2137 #endif
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");
2158 return 0;
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)
2168 char *name, *cp;
2169 int ar_loaded = 0;
2170 char buf[NVRAM_SPACE];
2172 if (nvram_getall(buf, sizeof(buf)) != 0)
2173 return;
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)
2178 continue;
2179 *cp = 0;
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)
2183 ++ar_loaded;
2186 /* Start any autorun files that may have been loaded into one of the standard places. */
2187 if (ar_loaded != 0)
2188 run_nvscript(".autorun", NULL, 3);
2190 #endif
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));
2198 sysinfo(&info);
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);
2205 #endif
2207 static void sysinit(void)
2209 static int noconsole = 0;
2210 static const time_t tm = 0;
2211 int hardware;
2212 int i;
2213 DIR *d;
2214 struct dirent *de;
2215 char s[256];
2216 char t[256];
2218 mount("proc", "/proc", "proc", 0, NULL);
2219 mount("tmpfs", "/tmp", "tmpfs", 0, NULL);
2221 #ifdef LINUX26
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);
2232 #endif
2234 if (console_init()) noconsole = 1;
2236 stime(&tm);
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
2245 NULL
2247 umask(0);
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");
2260 umask(022);
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);
2267 symlink(s, t);
2269 closedir(d);
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);
2279 symlink(s, t);
2281 closedir(d);
2283 #endif
2285 #ifdef LINUX26
2286 eval("hotplug2", "--coldplug");
2287 start_hotplug2();
2289 static const char *dn[] = {
2290 "null", "zero", "random", "urandom", "full", "ptmx", "nvram",
2291 NULL
2293 for (i = 0; dn[i]; ++i) {
2294 snprintf(s, sizeof(s), "/dev/%s", dn[i]);
2295 chmod(s, 0666);
2297 chmod("/dev/gpio", 0660);
2298 #endif
2300 set_action(ACT_IDLE);
2302 for (i = 0; defenv[i]; ++i) {
2303 putenv(defenv[i]);
2306 if (!noconsole) {
2307 printf("\n\nHit ENTER for console...\n\n");
2308 run_shell(1, 0);
2311 check_bootnv();
2313 #ifdef TCONFIG_IPV6
2314 // disable IPv6 by default on all interfaces
2315 f_write_string("/proc/sys/net/ipv6/conf/default/disable_ipv6", "1", 0, 0);
2316 #endif
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"))
2326 modprobe("ctf");
2327 #endif
2329 #ifdef TCONFIG_EMF
2330 modprobe("emf");
2331 modprobe("igs");
2332 #endif
2334 switch (hardware = check_hw_type()) {
2335 case HW_BCM4785:
2336 modprobe("bcm57xx");
2337 break;
2338 default:
2339 modprobe("et");
2340 break;
2343 load_wl();
2345 config_loopback();
2347 // eval("nvram", "defaults", "--initcheck");
2348 restore_defaults(); // restore default if necessary
2349 init_nvram();
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();
2362 #endif
2363 setup_conntrack();
2364 set_host_domain_name();
2366 set_tz();
2368 eval("buttons");
2370 #ifdef CONFIG_BCMWL6
2371 eval("blink_5g");
2372 #endif
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);
2381 led(LED_DIAG, 1);
2384 int init_main(int argc, char *argv[])
2386 int state, i;
2387 sigset_t sigset;
2389 // AB - failsafe?
2390 nvram_unset("debug_rc_svc");
2392 sysinit();
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");
2405 #endif
2407 start_jffs2();
2409 state = SIGUSR2; /* START */
2411 for (;;) {
2412 TRACE_PT("main loop signal/state=%d\n", state);
2414 switch (state) {
2415 case SIGUSR1: /* USER1: service handler */
2416 exec_service();
2417 break;
2419 case SIGHUP: /* RESTART */
2420 case SIGINT: /* STOP */
2421 case SIGQUIT: /* HALT */
2422 case SIGTERM: /* REBOOT */
2423 led(LED_DIAG, 1);
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);
2431 stop_services();
2432 stop_wan();
2433 stop_lan();
2434 stop_vlan();
2435 stop_syslog();
2437 if ((state == SIGTERM /* REBOOT */) ||
2438 (state == SIGQUIT /* HALT */)) {
2439 remove_storage_main(1);
2440 stop_usb();
2442 shutdn(state == SIGTERM /* REBOOT */);
2443 exit(0);
2445 if (state == SIGINT /* STOP */) {
2446 break;
2449 // SIGHUP (RESTART) falls through
2451 case SIGUSR2: /* START */
2452 SET_LED(RELEASE_WAN_CONTROL);
2453 start_syslog();
2455 #ifndef TCONFIG_BCMARM
2456 load_files_from_nvram();
2457 #endif
2459 int fd = -1;
2460 fd = file_lock("usb"); // hold off automount processing
2461 start_usb();
2463 xstart("/usr/sbin/mymotd", "init");
2464 run_nvscript("script_init", NULL, 2);
2466 file_unlock(fd); // allow to process usb hotplug events
2467 #ifdef TCONFIG_USB
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);
2476 #endif
2478 create_passwd();
2479 start_vlan();
2480 start_lan();
2481 start_arpbind();
2482 start_wan(BOOT);
2483 start_services();
2484 start_wl();
2486 #ifdef CONFIG_BCMWL5
2487 if (wds_enable()) {
2488 /* Restart NAS one more time - for some reason without
2489 * this the new driver doesn't always bring WDS up.
2491 stop_nas();
2492 start_nas();
2494 #endif
2496 syslog(LOG_INFO, "%s: Tomato %s", nvram_safe_get("t_model_name"), tomato_version);
2498 led(LED_DIAG, 0);
2499 notice_set("sysup", "");
2500 break;
2503 chld_reap(0); /* Periodically reap zombies. */
2504 check_services();
2505 sigwait(&sigset, &state);
2508 return 0;
2511 int reboothalt_main(int argc, char *argv[])
2513 int reboot = (strstr(argv[0], "reboot") != NULL);
2514 puts(reboot ? "Rebooting..." : "Shutting down...");
2515 fflush(stdout);
2516 sleep(1);
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.
2523 if (fork() == 0) {
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 */
2528 sleep(wait);
2529 puts("Still running... Doing machine reset.");
2530 fflush(stdout);
2531 f_write("/proc/sysrq-trigger", "s", 1, 0 , 0); /* sync disks */
2532 sleep(1);
2533 f_write("/proc/sysrq-trigger", "b", 1, 0 , 0); /* machine reset */
2536 return 0;