Fix up wlan/wan/usb leds,now all leds works well wifi toggle
[tomato.git] / release / src-rt-6.x.4708 / router / rc / init.c
blob63a7e5cb4e0b40f5ec8ecfe5c30eb2fa9216e8e4
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_R6250:
576 case MODEL_R6300v2:
577 dirty |= check_nv("vlan1ports", "3 2 1 0 5*");
578 dirty |= check_nv("vlan2ports", "4 5");
579 break;
580 case MODEL_RTAC56U:
581 case MODEL_DIR868L:
582 dirty |= check_nv("vlan1ports", "0 1 2 3 5*");
583 dirty |= check_nv("vlan2ports", "4 5");
584 break;
585 case MODEL_R7000:
586 case MODEL_RTN18U:
587 case MODEL_RTAC68U:
588 case MODEL_WS880:
589 dirty |= check_nv("vlan1ports", "1 2 3 4 5*");
590 dirty |= check_nv("vlan2ports", "0 5");
591 break;
592 #endif
596 return dirty;
599 static void check_bootnv(void)
601 int dirty;
602 int hardware;
603 int model;
604 char mac[18];
606 model = get_model();
607 dirty = check_nv("wl0_leddc", "0x640000") | check_nv("wl1_leddc", "0x640000");
609 switch (model) {
610 case MODEL_WTR54GS:
611 dirty |= check_nv("vlan0hwname", "et0");
612 dirty |= check_nv("vlan1hwname", "et0");
613 break;
614 case MODEL_WBRG54:
615 dirty |= check_nv("wl0gpio0", "130");
616 break;
617 case MODEL_WR850GV1:
618 case MODEL_WR850GV2:
619 // need to cleanup some variables...
620 if ((nvram_get("t_model") == NULL) && (nvram_get("MyFirmwareVersion") != NULL)) {
621 nvram_unset("MyFirmwareVersion");
622 nvram_set("restore_defaults", "1");
624 break;
625 case MODEL_WL330GE:
626 dirty |= check_nv("wl0gpio1", "0x02");
627 break;
628 case MODEL_WL500W:
629 /* fix WL500W mac adresses for WAN port */
630 if (invalid_mac(nvram_get("et1macaddr"))) {
631 strcpy(mac, nvram_safe_get("et0macaddr"));
632 inc_mac(mac, 1);
633 dirty |= check_nv("et1macaddr", mac);
635 dirty |= check_nv("wl0gpio0", "0x88");
636 break;
637 case MODEL_WL500GP:
638 dirty |= check_nv("sdram_init", "0x0009"); // 32MB; defaults: 0x000b, 0x0009
639 dirty |= check_nv("wl0gpio0", "136");
640 break;
641 case MODEL_WL500GPv2:
642 case MODEL_WL520GU:
643 dirty |= check_nv("wl0gpio1", "136");
644 break;
645 case MODEL_WL500GD:
646 dirty |= check_nv("vlan0hwname", "et0");
647 dirty |= check_nv("vlan1hwname", "et0");
648 dirty |= check_nv("boardflags", "0x00000100"); // set BFL_ENETVLAN
649 nvram_unset("wl0gpio0");
650 break;
651 case MODEL_DIR320:
652 if (strlen(nvram_safe_get("et0macaddr")) == 12 ||
653 strlen(nvram_safe_get("il0macaddr")) == 12) {
654 dirty |= find_dir320_mac_addr();
656 if (nvram_get("vlan2hwname") != NULL) {
657 nvram_unset("vlan2hwname");
658 dirty = 1;
660 dirty |= check_nv("wandevs", "vlan1");
661 dirty |= check_nv("vlan1hwname", "et0");
662 dirty |= check_nv("wl0gpio0", "8");
663 dirty |= check_nv("wl0gpio1", "0");
664 dirty |= check_nv("wl0gpio2", "0");
665 dirty |= check_nv("wl0gpio3", "0");
666 break;
667 case MODEL_H618B:
668 dirty |= check_nv("wandevs", "vlan1");
669 dirty |= check_nv("vlan0hwname", "et0");
670 dirty |= check_nv("vlan1hwname", "et0");
671 break;
672 case MODEL_WL1600GL:
673 if (invalid_mac(nvram_get("et0macaddr"))) {
674 dirty |= find_sercom_mac_addr();
676 break;
677 case MODEL_WRT160Nv1:
678 case MODEL_WRT310Nv1:
679 case MODEL_WRT300N:
680 dirty |= check_nv("wl0gpio0", "8");
681 break;
682 #ifdef CONFIG_BCMWL5
683 case MODEL_WNR3500L:
684 dirty |= check_nv("boardflags", "0x00000710"); // needed to enable USB
685 dirty |= check_nv("vlan2hwname", "et0");
686 dirty |= check_nv("ledbh0", "7");
687 break;
688 case MODEL_WNR3500LV2:
689 dirty |= check_nv("vlan2hwname", "et0");
690 break;
691 case MODEL_WNR2000v2:
692 dirty |= check_nv("ledbh5", "8");
693 break;
694 case MODEL_WRT320N:
695 dirty |= check_nv("reset_gpio", "5");
696 dirty |= check_nv("ledbh0", "136");
697 dirty |= check_nv("ledbh1", "11");
698 /* fall through, same as RT-N16 */
699 case MODEL_RTN16:
700 dirty |= check_nv("vlan2hwname", "et0");
701 break;
702 case MODEL_HG320:
703 case MODEL_RG200E_CA:
704 case MODEL_H218N:
705 dirty |= check_nv("vlan1hwname", "et0");
706 dirty |= check_nv("vlan2hwname", "et0");
707 dirty |= check_nv("boardflags", "0x710"); // set BFL_ENETVLAN, enable VLAN
708 dirty |= check_nv("reset_gpio", "30");
709 break;
710 case MODEL_WRT610Nv2:
711 dirty |= check_nv("vlan2hwname", "et0");
712 dirty |= check_nv("pci/1/1/ledbh2", "8");
713 dirty |= check_nv("sb/1/ledbh1", "8");
714 if (invalid_mac(nvram_get("pci/1/1/macaddr"))) {
715 strcpy(mac, nvram_safe_get("et0macaddr"));
716 inc_mac(mac, 3);
717 dirty |= check_nv("pci/1/1/macaddr", mac);
719 break;
720 case MODEL_F7D3301:
721 case MODEL_F7D3302:
722 case MODEL_F7D4301:
723 case MODEL_F7D4302:
724 case MODEL_F5D8235v3:
725 if (nvram_match("sb/1/macaddr", nvram_safe_get("et0macaddr"))) {
726 strcpy(mac, nvram_safe_get("et0macaddr"));
727 inc_mac(mac, 2);
728 dirty |= check_nv("sb/1/macaddr", mac);
729 inc_mac(mac, 1);
730 dirty |= check_nv("pci/1/1/macaddr", mac);
732 case MODEL_EA6500V1:
733 dirty |= check_nv("vlan2hwname", "et0");
734 if (strncasecmp(nvram_safe_get("pci/2/1/macaddr"), "00:90:4c", 8) == 0) {
735 strcpy(mac, nvram_safe_get("et0macaddr"));
736 inc_mac(mac, 3);
737 dirty |= check_nv("pci/2/1/macaddr", mac);
739 break;
740 case MODEL_E4200:
741 dirty |= check_nv("vlan2hwname", "et0");
742 if (strncasecmp(nvram_safe_get("pci/1/1/macaddr"), "00:90:4c", 8) == 0 ||
743 strncasecmp(nvram_safe_get("sb/1/macaddr"), "00:90:4c", 8) == 0) {
744 strcpy(mac, nvram_safe_get("et0macaddr"));
745 inc_mac(mac, 2);
746 dirty |= check_nv("sb/1/macaddr", mac);
747 inc_mac(mac, 1);
748 dirty |= check_nv("pci/1/1/macaddr", mac);
750 break;
751 case MODEL_E900:
752 case MODEL_E1000v2:
753 case MODEL_E1500:
754 case MODEL_E1550:
755 case MODEL_E2500:
756 case MODEL_E3200:
757 case MODEL_WRT160Nv3:
758 case MODEL_L600N:
759 case MODEL_DIR620C1:
760 dirty |= check_nv("vlan2hwname", "et0");
761 break;
762 #endif
764 case MODEL_WRT54G:
765 if (strncmp(nvram_safe_get("pmon_ver"), "CFE", 3) != 0) return;
767 hardware = check_hw_type();
768 if (!nvram_get("boardtype") ||
769 !nvram_get("boardnum") ||
770 !nvram_get("boardflags") ||
771 !nvram_get("clkfreq") ||
772 !nvram_get("os_flash_addr") ||
773 !nvram_get("dl_ram_addr") ||
774 !nvram_get("os_ram_addr") ||
775 !nvram_get("scratch") ||
776 !nvram_get("et0macaddr") ||
777 ((hardware != HW_BCM4704_BCM5325F) && (!nvram_get("vlan0ports") || !nvram_get("vlan0hwname")))) {
778 _dprintf("Unable to find critical settings, erasing NVRAM\n");
779 mtd_erase("nvram");
780 goto REBOOT;
783 dirty |= check_nv("aa0", "3");
784 dirty |= check_nv("wl0gpio0", "136");
785 dirty |= check_nv("wl0gpio2", "0");
786 dirty |= check_nv("wl0gpio3", "0");
787 dirty |= check_nv("cctl", "0");
788 dirty |= check_nv("ccode", "0");
790 switch (hardware) {
791 case HW_BCM5325E:
792 /* Lower the DDR ram drive strength , the value will be stable for all boards
793 Latency 3 is more stable for all ddr 20050420 by honor */
794 dirty |= check_nv("sdram_init", "0x010b");
795 dirty |= check_nv("sdram_config", "0x0062");
796 if (!nvram_match("debug_clkfix", "0")) {
797 dirty |= check_nv("clkfreq", "216");
799 if (dirty) {
800 nvram_set("sdram_ncdl", "0x0");
802 dirty |= check_nv("pa0itssit", "62");
803 dirty |= check_nv("pa0b0", "0x15eb");
804 dirty |= check_nv("pa0b1", "0xfa82");
805 dirty |= check_nv("pa0b2", "0xfe66");
806 //dirty |= check_nv("pa0maxpwr", "0x4e");
807 break;
808 case HW_BCM5352E: // G v4, GS v3, v4
809 dirty |= check_nv("sdram_init", "0x010b");
810 dirty |= check_nv("sdram_config", "0x0062");
811 if (dirty) {
812 nvram_set("sdram_ncdl", "0x0");
814 dirty |= check_nv("pa0itssit", "62");
815 dirty |= check_nv("pa0b0", "0x168b");
816 dirty |= check_nv("pa0b1", "0xfabf");
817 dirty |= check_nv("pa0b2", "0xfeaf");
818 //dirty |= check_nv("pa0maxpwr", "0x4e");
819 break;
820 case HW_BCM5354G:
821 dirty |= check_nv("pa0itssit", "62");
822 dirty |= check_nv("pa0b0", "0x1326");
823 dirty |= check_nv("pa0b1", "0xFB51");
824 dirty |= check_nv("pa0b2", "0xFE87");
825 //dirty |= check_nv("pa0maxpwr", "0x4e");
826 break;
827 case HW_BCM4704_BCM5325F:
828 // nothing to do
829 break;
830 default:
831 dirty |= check_nv("pa0itssit", "62");
832 dirty |= check_nv("pa0b0", "0x170c");
833 dirty |= check_nv("pa0b1", "0xfa24");
834 dirty |= check_nv("pa0b2", "0xfe70");
835 //dirty |= check_nv("pa0maxpwr", "0x48");
836 break;
838 break;
840 } // switch (model)
842 dirty |= init_vlan_ports();
844 if (dirty) {
845 nvram_commit();
846 REBOOT: // do a simple reboot
847 sync();
848 reboot(RB_AUTOBOOT);
849 exit(0);
853 static int init_nvram(void)
855 unsigned long features;
856 int model;
857 const char *mfr;
858 const char *name;
859 const char *ver;
860 char s[256];
861 unsigned long bf;
862 unsigned long n;
864 model = get_model();
865 sprintf(s, "%d", model);
866 nvram_set("t_model", s);
868 mfr = "Broadcom";
869 name = NULL;
870 ver = NULL;
871 features = 0;
872 switch (model) {
873 case MODEL_WRT54G:
874 mfr = "Linksys";
875 name = "WRT54G/GS/GL";
876 switch (check_hw_type()) {
877 case HW_BCM4712:
878 nvram_set("gpio2", "adm_eecs");
879 nvram_set("gpio3", "adm_eesk");
880 nvram_unset("gpio4");
881 nvram_set("gpio5", "adm_eedi");
882 nvram_set("gpio6", "adm_rc");
883 break;
884 case HW_BCM4702:
885 nvram_unset("gpio2");
886 nvram_unset("gpio3");
887 nvram_unset("gpio4");
888 nvram_unset("gpio5");
889 nvram_unset("gpio6");
890 break;
891 case HW_BCM5352E:
892 nvram_set("opo", "0x0008");
893 nvram_set("ag0", "0x02");
894 // drop
895 default:
896 nvram_set("gpio2", "ses_led");
897 nvram_set("gpio3", "ses_led2");
898 nvram_set("gpio4", "ses_button");
899 features = SUP_SES | SUP_WHAM_LED;
900 break;
902 break;
903 case MODEL_WTR54GS:
904 mfr = "Linksys";
905 name = "WTR54GS";
906 if (!nvram_match("t_fix1", (char *)name)) {
907 nvram_set("lan_ifnames", "vlan0 eth1");
908 nvram_set("gpio2", "ses_button");
909 nvram_set("reset_gpio", "7");
911 nvram_set("pa0itssit", "62");
912 nvram_set("pa0b0", "0x1542");
913 nvram_set("pa0b1", "0xfacb");
914 nvram_set("pa0b2", "0xfec7");
915 //nvram_set("pa0maxpwr", "0x4c");
916 features = SUP_SES;
917 break;
918 case MODEL_WRTSL54GS:
919 mfr = "Linksys";
920 name = "WRTSL54GS";
921 features = SUP_SES | SUP_WHAM_LED;
922 break;
923 case MODEL_WHRG54S:
924 mfr = "Buffalo";
925 name = "WHR-G54S";
926 features = SUP_SES | SUP_AOSS_LED | SUP_BRAU;
927 break;
928 case MODEL_WHRHPG54:
929 case MODEL_WZRRSG54HP:
930 case MODEL_WZRHPG54:
931 mfr = "Buffalo";
932 features = SUP_SES | SUP_AOSS_LED | SUP_HPAMP;
933 switch (model) {
934 case MODEL_WZRRSG54HP:
935 name = "WZR-RS-G54HP";
936 break;
937 case MODEL_WZRHPG54:
938 name = "WZR-HP-G54";
939 break;
940 default:
941 name = "WHR-HP-G54";
942 features = SUP_SES | SUP_AOSS_LED | SUP_BRAU | SUP_HPAMP;
943 break;
946 bf = strtoul(nvram_safe_get("boardflags"), NULL, 0);
947 switch (bf) {
948 case 0x0758:
949 case 0x1758:
950 case 0x2758:
951 case 0x3758:
952 if ( nvram_is_empty("wlx_hpamp") || nvram_match("wlx_hpamp", "")) {
953 if (nvram_get_int("wl_txpwr") > 10) nvram_set("wl_txpwr", "10");
954 nvram_set("wlx_hpamp", "1");
955 nvram_set("wlx_hperx", "0");
958 n = bf;
959 if (nvram_match("wlx_hpamp", "0")) {
960 n &= ~0x2000UL;
962 else {
963 n |= 0x2000UL;
965 if (nvram_match("wlx_hperx", "0")) {
966 n |= 0x1000UL;
968 else {
969 n &= ~0x1000UL;
971 if (bf != n) {
972 sprintf(s, "0x%lX", n);
973 nvram_set("boardflags", s);
975 break;
976 default:
977 syslog(LOG_WARNING, "Unexpected: boardflag=%lX", bf);
978 break;
980 break;
981 case MODEL_WBRG54:
982 mfr = "Buffalo";
983 name = "WBR-G54";
984 break;
985 case MODEL_WBR2G54:
986 mfr = "Buffalo";
987 name = "WBR2-G54";
988 features = SUP_SES | SUP_AOSS_LED;
989 break;
990 case MODEL_WHR2A54G54:
991 mfr = "Buffalo";
992 name = "WHR2-A54G54";
993 features = SUP_SES | SUP_AOSS_LED | SUP_BRAU;
994 break;
995 case MODEL_WHR3AG54:
996 mfr = "Buffalo";
997 name = "WHR3-AG54";
998 features = SUP_SES | SUP_AOSS_LED;
999 break;
1000 case MODEL_WZRG54:
1001 mfr = "Buffalo";
1002 name = "WZR-G54";
1003 features = SUP_SES | SUP_AOSS_LED;
1004 break;
1005 case MODEL_WZRRSG54:
1006 mfr = "Buffalo";
1007 name = "WZR-RS-G54";
1008 features = SUP_SES | SUP_AOSS_LED;
1009 break;
1010 case MODEL_WVRG54NF:
1011 mfr = "Buffalo";
1012 name = "WVR-G54-NF";
1013 features = SUP_SES;
1014 break;
1015 case MODEL_WZRG108:
1016 mfr = "Buffalo";
1017 name = "WZR-G108";
1018 features = SUP_SES | SUP_AOSS_LED;
1019 break;
1020 case MODEL_RT390W:
1021 mfr = "Fuji";
1022 name = "RT390W";
1023 break;
1024 case MODEL_WR850GV1:
1025 mfr = "Motorola";
1026 name = "WR850G v1";
1027 features = SUP_NONVE;
1028 break;
1029 case MODEL_WR850GV2:
1030 mfr = "Motorola";
1031 name = "WR850G v2/v3";
1032 features = SUP_NONVE;
1033 break;
1034 case MODEL_WL500GP:
1035 mfr = "Asus";
1036 name = "WL-500gP";
1037 features = SUP_SES;
1038 #ifdef TCONFIG_USB
1039 nvram_set("usb_ohci", "-1");
1040 #endif
1041 if (!nvram_match("t_fix1", (char *)name)) {
1042 nvram_set("lan_ifnames", "vlan0 eth1 eth2 eth3"); // set to "vlan0 eth2" by DD-WRT; default: vlan0 eth1
1044 break;
1045 case MODEL_WL500W:
1046 mfr = "Asus";
1047 name = "WL-500W";
1048 features = SUP_SES | SUP_80211N;
1049 #ifdef TCONFIG_USB
1050 nvram_set("usb_ohci", "-1");
1051 #endif
1052 break;
1053 case MODEL_WL500GE:
1054 mfr = "Asus";
1055 name = "WL-550gE";
1056 // features = ?
1057 #ifdef TCONFIG_USB
1058 nvram_set("usb_uhci", "-1");
1059 #endif
1060 break;
1061 case MODEL_WX6615GT:
1062 mfr = "SparkLAN";
1063 name = "WX-6615GT";
1064 // features = ?
1065 break;
1066 case MODEL_MN700:
1067 mfr = "Microsoft";
1068 name = "MN-700";
1069 break;
1070 case MODEL_WR100:
1071 mfr = "Viewsonic";
1072 name = "WR100";
1073 break;
1074 case MODEL_WLA2G54L:
1075 mfr = "Buffalo";
1076 name = "WLA2-G54L";
1077 if (!nvram_match("t_fix1", (char *)name)) {
1078 nvram_set("lan_ifnames", "vlan0 eth1 eth2");
1079 nvram_set("wl_ifname", "eth1");
1080 nvram_set("wan_ifname", "none");
1082 break;
1083 case MODEL_TM2300:
1084 mfr = "Dell";
1085 name = "TrueMobile 2300";
1086 break;
1094 #ifndef WL_BSS_INFO_VERSION
1095 #error WL_BSS_INFO_VERSION
1096 #endif
1097 #if WL_BSS_INFO_VERSION >= 108
1099 case MODEL_WRH54G:
1100 mfr = "Linksys";
1101 name = "WRH54G";
1103 nvram_set("opo", "12");
1104 break;
1106 case MODEL_WHRG125:
1107 mfr = "Buffalo";
1108 name = "WHR-G125";
1109 features = SUP_SES | SUP_AOSS_LED | SUP_BRAU;
1111 nvram_set("opo", "0x0008");
1112 nvram_set("ag0", "0x0C");
1113 break;
1114 #ifdef CONFIG_BCMWL5
1115 case MODEL_L600N:
1116 mfr = "Rosewill";
1117 name = "L600N";
1118 features = SUP_SES | SUP_80211N;
1119 if (!nvram_match("t_fix1", (char *)name)) {
1120 #ifdef TCONFIG_USBAP
1121 nvram_set("wl1_hwaddr", nvram_safe_get("0:macaddr"));
1122 nvram_set("ehciirqt", "3");
1123 nvram_set("qtdc_pid", "48407");
1124 nvram_set("qtdc_vid", "2652");
1125 nvram_set("qtdc0_ep", "4");
1126 nvram_set("qtdc0_sz", "0");
1127 nvram_set("qtdc1_ep", "18");
1128 nvram_set("qtdc1_sz", "10");
1129 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1130 nvram_set("landevs", "vlan1 wl0 wl1");
1131 nvram_set("wl0_ifname", "wl0");
1132 nvram_set("wl1_ifname", "wl1");
1133 #else
1134 nvram_set("lan_ifnames", "vlan1 eth1");
1135 nvram_set("landevs", "vlan1 wl0");
1136 #endif
1137 nvram_set("wl_ifname", "eth1");
1138 nvram_set("wan_ifnameX", "vlan2");
1139 nvram_set("wandevs", "vlan2");
1141 break;
1142 case MODEL_DIR620C1:
1143 mfr = "D-Link";
1144 name = "Dir-620 C1";
1145 features = SUP_SES | SUP_80211N;
1146 if (!nvram_match("t_fix1", (char *)name)) {
1147 #ifdef TCONFIG_USBAP
1148 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1149 nvram_set("landevs", "vlan1 wl0 wl1");
1150 nvram_set("wl0_ifname", "eth1");
1151 nvram_set("wl1_ifname", "eth2");
1152 #else
1153 nvram_set("lan_ifnames", "vlan1 eth1");
1154 nvram_set("landevs", "vlan1 wl0");
1155 #endif
1156 nvram_set("wan_ifnameX", "vlan2");
1157 nvram_set("wl_ifname", "eth1");
1160 break;
1161 case MODEL_CW5358U:
1162 mfr = "Catchtech";
1163 name = "CW-5358U";
1164 features = SUP_SES | SUP_80211N;
1165 #ifdef TCONFIG_USB
1166 nvram_set("usb_uhci", "-1");
1167 #endif
1168 if (!nvram_match("t_fix1", (char *)name)) {
1169 nvram_set("lan_ifnames", "vlan1 eth1");
1170 nvram_set("wan_ifname", "vlan2");
1171 nvram_set("wan_ifnames", "vlan2");
1172 nvram_set("wan_ifnameX", "vlan2");
1173 nvram_set("wl_ifname", "eth1");
1175 break;
1176 case MODEL_HG320:
1177 mfr = "FiberHome";
1178 name = "HG320";
1179 features = SUP_SES | SUP_80211N;
1180 #ifdef TCONFIG_USB
1181 nvram_set("usb_uhci", "-1");
1182 #endif
1183 if (!nvram_match("t_fix1", (char *)name)) {
1184 nvram_set("lan_ifnames", "vlan1 eth1");
1185 nvram_set("wan_ifname", "vlan2");
1186 nvram_set("wan_ifnames", "vlan2");
1187 nvram_set("wan_ifnameX", "vlan2");
1188 nvram_set("wl_ifname", "eth1");
1190 break;
1191 case MODEL_RG200E_CA:
1192 mfr = "ChinaNet";
1193 name = "RG200E-CA";
1194 features = SUP_SES | SUP_80211N;
1195 #ifdef TCONFIG_USB
1196 nvram_set("usb_uhci", "-1");
1197 #endif
1198 if (!nvram_match("t_fix1", (char *)name)) {
1199 nvram_set("lan_ifnames", "vlan1 eth1");
1200 nvram_set("wan_ifname", "vlan2");
1201 nvram_set("wan_ifnames", "vlan2");
1202 nvram_set("wan_ifnameX", "vlan2");
1203 nvram_set("wl_ifname", "eth1");
1205 break;
1206 case MODEL_H218N:
1207 mfr = "ZTE";
1208 name = "H218N";
1209 features = SUP_SES | SUP_80211N;
1210 #ifdef TCONFIG_USB
1211 nvram_set("usb_uhci", "-1");
1212 #endif
1213 if (!nvram_match("t_fix1", (char *)name)) {
1214 nvram_set("lan_ifnames", "vlan1 eth1");
1215 nvram_set("wan_ifname", "vlan2");
1216 nvram_set("wan_ifnames", "vlan2");
1217 nvram_set("wan_ifnameX", "vlan2");
1218 nvram_set("wl_ifname", "eth1");
1220 break;
1221 case MODEL_TDN60:
1222 mfr = "Tenda";
1223 name = "N60";
1224 features = SUP_SES | SUP_80211N;
1225 #ifdef TCONFIG_USB
1226 nvram_set("usb_uhci", "-1");
1227 #endif
1228 if (!nvram_match("t_fix1", (char *)name)) {
1229 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1230 nvram_set("wan_ifnameX", "vlan2");
1231 nvram_set("wan_ifnames", "vlan2");
1232 nvram_set("wan_ifnameX", "vlan2");
1233 nvram_set("wl_ifnames", "eth1 eth2");
1234 nvram_set("wl_ifname", "eth1");
1235 nvram_set("wl0_ifname", "eth1");
1236 nvram_set("wl1_ifname", "eth2");
1237 nvram_set("wl0_bw_cap","3");
1238 nvram_set("wl0_chanspec","1l");
1239 nvram_set("wl1_bw_cap","7");
1240 nvram_set("wl1_chanspec","36/80");
1241 nvram_set("blink_5g_interface","eth2");
1242 //nvram_set("landevs", "vlan1 wl0 wl1");
1243 //nvram_set("wandevs", "vlan2");
1245 // fix WL mac`s
1246 nvram_set("wl0_hwaddr", nvram_safe_get("sb/1/macaddr"));
1247 nvram_set("wl1_hwaddr", nvram_safe_get("0:macaddr"));
1249 break;
1250 case MODEL_TDN6:
1251 mfr = "Tenda";
1252 name = "N6";
1253 features = SUP_SES | SUP_80211N;
1254 #ifdef TCONFIG_USB
1255 nvram_set("usb_uhci", "-1");
1256 #endif
1257 if (!nvram_match("t_fix1", (char *)name)) {
1258 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1259 nvram_set("wan_ifnameX", "vlan2");
1260 nvram_set("wan_ifnames", "vlan2");
1261 nvram_set("wan_ifnameX", "vlan2");
1262 nvram_set("wl_ifnames", "eth1 eth2");
1263 nvram_set("wl_ifname", "eth1");
1264 nvram_set("wl0_ifname", "eth1");
1265 nvram_set("wl1_ifname", "eth2");
1266 nvram_set("wl0_bw_cap","3");
1267 nvram_set("wl0_chanspec","1l");
1268 nvram_set("wl1_bw_cap","7");
1269 nvram_set("wl1_chanspec","36/80");
1270 nvram_set("blink_5g_interface","eth2");
1272 // fix WL mac`s
1273 nvram_set("wl0_hwaddr", nvram_safe_get("sb/1/macaddr"));
1274 nvram_set("wl1_hwaddr", nvram_safe_get("0:macaddr"));
1276 break;
1277 case MODEL_RTN10:
1278 case MODEL_RTN10P:
1279 mfr = "Asus";
1280 name = nvram_match("boardrev", "0x1153") ? "RT-N10P" : "RT-N10";
1281 features = SUP_SES | SUP_80211N;
1282 if (!nvram_match("t_fix1", (char *)name)) {
1283 nvram_set("lan_ifnames", "vlan0 eth1");
1284 nvram_set("wan_ifnameX", "vlan1");
1285 nvram_set("wl_ifname", "eth1");
1287 break;
1288 case MODEL_RTN10U:
1289 mfr = "Asus";
1290 name = "RT-N10U";
1291 features = SUP_SES | SUP_80211N;
1292 #ifdef TCONFIG_USB
1293 nvram_set("usb_uhci", "-1");
1294 #endif
1295 if (!nvram_match("t_fix1", (char *)name)) {
1296 nvram_set("lan_ifnames", "vlan0 eth1");
1297 nvram_set("wan_ifnameX", "vlan1");
1298 nvram_set("wl_ifname", "eth1");
1300 break;
1301 case MODEL_RTN12:
1302 mfr = "Asus";
1303 name = "RT-N12";
1304 features = SUP_SES | SUP_BRAU | SUP_80211N;
1305 if (!nvram_match("t_fix1", (char *)name)) {
1306 nvram_set("lan_ifnames", "vlan0 eth1");
1307 nvram_set("wan_ifnameX", "vlan1");
1308 nvram_set("wl_ifname", "eth1");
1310 break;
1311 case MODEL_RTN12B1:
1312 mfr = "Asus";
1313 name = "RT-N12 B1";
1314 features = SUP_80211N;
1315 if (!nvram_match("t_fix1", (char *)name)) {
1316 nvram_set("lan_ifnames", "vlan0 eth1");
1317 nvram_set("wan_ifnameX", "vlan1");
1318 nvram_set("wl_ifname", "eth1");
1320 break;
1321 case MODEL_RTN15U:
1322 mfr = "Asus";
1323 name = "RT-N15U";
1324 features = SUP_SES | SUP_80211N | SUP_1000ET;
1325 #ifdef TCONFIG_USB
1326 nvram_set("usb_uhci", "-1");
1327 #endif
1328 if (!nvram_match("t_fix1", (char *)name)) {
1329 nvram_set("lan_ifnames", "vlan1 eth1");
1330 nvram_set("wan_iface", "vlan2");
1331 nvram_set("wan_ifname", "vlan2");
1332 nvram_set("wan_ifnameX", "vlan2");
1333 nvram_set("wan_ifnames", "vlan2");
1334 nvram_set("wl_ifname", "eth1");
1336 break;
1337 case MODEL_RTN16:
1338 mfr = "Asus";
1339 name = "RT-N16";
1340 features = SUP_SES | SUP_80211N | SUP_1000ET;
1341 #ifdef TCONFIG_USB
1342 nvram_set("usb_uhci", "-1");
1343 #endif
1344 if (!nvram_match("t_fix1", (char *)name)) {
1345 nvram_set("lan_ifnames", "vlan1 eth1");
1346 nvram_set("wan_ifnameX", "vlan2");
1347 nvram_set("wl_ifname", "eth1");
1348 nvram_set("vlan_enable", "1");
1350 break;
1351 case MODEL_RTN53:
1352 case MODEL_RTN53A1:
1353 mfr = "Asus";
1354 name = nvram_match("boardrev", "0x1446") ? "RT-N53 A1" : "RT-N53";
1355 features = SUP_SES | SUP_80211N;
1356 #if defined(LINUX26) && defined(TCONFIG_USBAP)
1357 if (nvram_get_int("usb_storage") == 1) nvram_set("usb_storage", "-1");
1358 #endif
1359 if (!nvram_match("t_fix1", (char *)name)) {
1360 #ifdef TCONFIG_USBAP
1361 nvram_set("wl1_hwaddr", nvram_safe_get("0:macaddr"));
1362 nvram_set("ehciirqt", "3");
1363 nvram_set("qtdc_pid", "48407");
1364 nvram_set("qtdc_vid", "2652");
1365 nvram_set("qtdc0_ep", "4");
1366 nvram_set("qtdc0_sz", "0");
1367 nvram_set("qtdc1_ep", "18");
1368 nvram_set("qtdc1_sz", "10");
1369 nvram_set("lan_ifnames", "vlan2 eth1 eth2");
1370 nvram_set("landevs", "vlan2 wl0 wl1");
1371 nvram_set("wl1_ifname", "eth2");
1372 #else
1373 nvram_set("lan_ifnames", "vlan2 eth1");
1374 nvram_set("landevs", "vlan2 wl0");
1375 #endif
1376 nvram_set("lan_ifname", "br0");
1377 nvram_set("wl_ifname", "eth1");
1378 nvram_set("wl0_ifname", "eth1");
1379 nvram_set("wan_ifnameX", "vlan1");
1380 nvram_set("wandevs", "vlan1");
1381 nvram_unset("vlan0ports");
1383 break;
1384 #ifdef CONFIG_BCMWL6A
1385 case MODEL_RTN18U:
1386 mfr = "Asus";
1387 name = "RT-N18U";
1388 features = SUP_SES | SUP_80211N | SUP_1000ET;
1389 #ifdef TCONFIG_USB
1390 nvram_set("usb_uhci", "-1");
1391 #endif
1392 if (!nvram_match("t_fix1", (char *)name)) {
1393 nvram_set("vlan1hwname", "et0");
1394 nvram_set("vlan2hwname", "et0");
1395 nvram_set("lan_ifname", "br0");
1396 nvram_set("landevs", "vlan1 wl0");
1397 nvram_set("lan_ifnames", "vlan1 eth1");
1398 nvram_set("wan_ifnames", "vlan2");
1399 nvram_set("wan_ifnameX", "vlan2");
1400 nvram_set("wandevs", "vlan2");
1401 nvram_set("wl_ifnames", "eth1");
1402 nvram_set("wl_ifname", "eth1");
1403 nvram_set("wl0_ifname", "eth1");
1405 // fix WL mac`s
1406 nvram_set("wl0_hwaddr", nvram_safe_get("0:macaddr"));
1408 // usb3.0 settings
1409 nvram_set("usb_usb3", "1");
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 break;
1415 case MODEL_RTAC56U:
1416 mfr = "Asus";
1417 name = "RT-AC56U";
1418 features = SUP_SES | SUP_80211N | SUP_1000ET | SUP_80211AC;
1419 #ifdef TCONFIG_USB
1420 nvram_set("usb_uhci", "-1");
1421 #endif
1422 if (!nvram_match("t_fix1", (char *)name)) {
1423 nvram_set("vlan1hwname", "et0");
1424 nvram_set("vlan2hwname", "et0");
1425 nvram_set("lan_ifname", "br0");
1426 nvram_set("landevs", "vlan1 wl0 wl1");
1427 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1428 nvram_set("wan_ifnames", "vlan2");
1429 nvram_set("wan_ifnameX", "vlan2");
1430 nvram_set("wandevs", "vlan2");
1431 nvram_set("wl_ifnames", "eth1 eth2");
1432 nvram_set("wl_ifname", "eth1");
1433 nvram_set("wl0_ifname", "eth1");
1434 nvram_set("wl1_ifname", "eth2");
1436 // fix WL mac`s
1437 nvram_set("wl0_hwaddr", nvram_safe_get("0:macaddr"));
1438 nvram_set("wl1_hwaddr", nvram_safe_get("1:macaddr"));
1440 // usb3.0 settings
1441 nvram_set("usb_usb3", "1");
1442 nvram_set("xhci_ports", "1-1");
1443 nvram_set("ehci_ports", "2-1 2-2");
1444 nvram_set("ohci_ports", "3-1 3-2");
1446 // force wl1 settings
1447 nvram_set("wl1_bw", "3");
1448 nvram_set("wl1_bw_cap", "7");
1449 nvram_set("wl1_chanspec", "149/80");
1450 nvram_set("wl1_nctrlsb", "lower");
1451 nvram_set("0:ccode", "SG");
1452 nvram_set("1:ccode", "SG");
1453 nvram_set("wl_country", "SG");
1454 nvram_set("wl_country_code", "SG");
1456 break;
1457 case MODEL_RTAC68U:
1458 mfr = "Asus";
1459 name = "RT-AC68R/U";
1460 features = SUP_SES | SUP_80211N | SUP_1000ET | SUP_80211AC;
1461 #ifdef TCONFIG_USB
1462 nvram_set("usb_uhci", "-1");
1463 #endif
1464 if (!nvram_match("t_fix1", (char *)name)) {
1465 nvram_set("vlan1hwname", "et0");
1466 nvram_set("vlan2hwname", "et0");
1467 nvram_set("lan_ifname", "br0");
1468 nvram_set("landevs", "vlan1 wl0 wl1");
1469 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1470 nvram_set("wan_ifnames", "vlan2");
1471 nvram_set("wan_ifnameX", "vlan2");
1472 nvram_set("wandevs", "vlan2");
1473 nvram_set("wl_ifnames", "eth1 eth2");
1474 nvram_set("wl_ifname", "eth1");
1475 nvram_set("wl0_ifname", "eth1");
1476 nvram_set("wl1_ifname", "eth2");
1478 // fix WL mac`s
1479 nvram_set("wl0_hwaddr", nvram_safe_get("0:macaddr"));
1480 nvram_set("wl1_hwaddr", nvram_safe_get("1:macaddr"));
1482 // usb3.0 settings
1483 nvram_set("usb_usb3", "1");
1484 nvram_set("xhci_ports", "1-1");
1485 nvram_set("ehci_ports", "2-1 2-2");
1486 nvram_set("ohci_ports", "3-1 3-2");
1488 // force wl1 settings
1489 nvram_set("wl1_bw", "3");
1490 nvram_set("wl1_bw_cap", "7");
1491 nvram_set("wl1_chanspec", "149/80");
1492 nvram_set("wl1_nctrlsb", "lower");
1493 nvram_set("0:ccode", "SG");
1494 nvram_set("1:ccode", "SG");
1495 nvram_set("wl_country", "SG");
1496 nvram_set("wl_country_code", "SG");
1498 break;
1499 case MODEL_R6250:
1500 case MODEL_R6300v2:
1501 case MODEL_R7000:
1502 mfr = "Netgear";
1503 if(nvram_match("board_id", "U12H245T00_NETGEAR")) //R6250
1504 name = "R6250";
1505 else
1506 name = model == MODEL_R7000 ? "R7000" : "R6300v2"; //R7000 or R6300v2
1508 features = SUP_SES | SUP_80211N | SUP_1000ET | SUP_80211AC;
1509 #ifdef TCONFIG_USB
1510 nvram_set("usb_uhci", "-1");
1511 #endif
1512 if (!nvram_match("t_fix1", (char *)name)) {
1513 nvram_set("vlan1hwname", "et0");
1514 nvram_set("vlan2hwname", "et0");
1515 nvram_set("lan_ifname", "br0");
1516 nvram_set("landevs", "vlan1 wl0 wl1");
1517 nvram_set("lan_ifnames", "vlan1 eth2 eth3");
1518 nvram_set("wan_ifnames", "vlan2");
1519 nvram_set("wan_ifnameX", "vlan2");
1520 nvram_set("wandevs", "vlan2");
1521 nvram_set("wl_ifnames", "eth2 eth3");
1522 nvram_set("wl_ifname", "eth2");
1523 nvram_set("wl0_ifname", "eth2");
1524 nvram_set("wl1_ifname", "eth3");
1526 // fix WL mac`s
1527 nvram_set("pci/1/1/macaddr", nvram_safe_get("et0macaddr"));
1528 nvram_set("pci/2/1/macaddr", nvram_safe_get("et1macaddr"));
1530 // usb3.0 settings
1531 nvram_set("usb_usb3", "1");
1532 nvram_set("xhci_ports", "1-1");
1533 nvram_set("ehci_ports", "2-1 2-2");
1534 nvram_set("ohci_ports", "3-1 3-2");
1536 // force wl1 settings
1537 nvram_set("wl1_bw", "3");
1538 nvram_set("wl1_bw_cap", "7");
1539 nvram_set("wl1_chanspec", "149/80");
1540 nvram_set("wl1_nctrlsb", "lower");
1541 nvram_set("wl_country", "SG");
1542 nvram_set("wl_country_code", "SG");
1543 nvram_set("blink_wl", "1");
1545 // bcm4360ac_defaults - fix problem of loading driver failed with code 21
1546 nvram_set("pci/1/1/aa2g", "7");
1547 nvram_set("pci/1/1/agbg0", "71");
1548 nvram_set("pci/1/1/agbg1", "71");
1549 nvram_set("pci/1/1/agbg2", "71");
1550 nvram_set("pci/1/1/antswitch", "0");
1551 nvram_set("pci/1/1/boardflags", "0x1000");
1552 nvram_set("pci/1/1/boardflags2", "0x100002");
1553 nvram_set("pci/1/1/boardflags3", "0x10000003");
1554 nvram_set("pci/1/1/boardnum", "57359");
1555 nvram_set("pci/1/1/boardrev", "0x1150");
1556 nvram_set("pci/1/1/boardtype", "0x661");
1557 nvram_set("pci/1/1/cckbw202gpo", "0");
1558 nvram_set("pci/1/1/cckbw20ul2gpo", "0");
1559 nvram_set("pci/1/1/ccode", "EU");
1560 nvram_set("pci/1/1/devid", "0x43a1");
1561 nvram_set("pci/1/1/dot11agduphrpo", "0");
1562 nvram_set("pci/1/1/dot11agduplrpo", "0");
1563 nvram_set("pci/1/1/dot11agofdmhrbw202gpo", "0xCA86");
1564 nvram_set("pci/1/1/epagain2g", "0");
1565 nvram_set("pci/1/1/femctrl", "3");
1566 nvram_set("pci/1/1/gainctrlsph", "0");
1567 // nvram_set("pci/1/1/macaddr", "E4:F4:C6:01:47:7C");
1568 nvram_set("pci/1/1/maxp2ga0", "106");
1569 nvram_set("pci/1/1/maxp2ga1", "106");
1570 nvram_set("pci/1/1/maxp2ga2", "106");
1571 nvram_set("pci/1/1/mcsbw202gpo", "0xA976A600");
1572 nvram_set("pci/1/1/mcsbw402gpo", "0xA976A600");
1573 nvram_set("pci/1/1/measpower", "0x7f");
1574 nvram_set("pci/1/1/measpower1", "0x7f");
1575 nvram_set("pci/1/1/measpower2", "0x7f");
1576 nvram_set("pci/1/1/noiselvl2ga0", "31");
1577 nvram_set("pci/1/1/noiselvl2ga1", "31");
1578 nvram_set("pci/1/1/noiselvl2ga2", "31");
1579 nvram_set("pci/1/1/ofdmlrbw202gpo", "0");
1580 nvram_set("pci/1/1/pa2ga0", "0xFF32,0x1C30,0xFCA3");
1581 nvram_set("pci/1/1/pa2ga1", "0xFF35,0x1BE3,0xFCB0");
1582 nvram_set("pci/1/1/pa2ga2", "0xFF33,0x1BE1,0xFCB0");
1583 nvram_set("pci/1/1/papdcap2g", "0");
1584 nvram_set("pci/1/1/pdgain2g", "14");
1585 nvram_set("pci/1/1/pdoffset2g40ma0", "15");
1586 nvram_set("pci/1/1/pdoffset2g40ma1", "15");
1587 nvram_set("pci/1/1/pdoffset2g40ma2", "15");
1588 nvram_set("pci/1/1/pdoffset2g40mvalid", "1");
1589 nvram_set("pci/1/1/pdoffset40ma0", "0");
1590 nvram_set("pci/1/1/pdoffset40ma1", "0");
1591 nvram_set("pci/1/1/pdoffset40ma2", "0");
1592 nvram_set("pci/1/1/pdoffset80ma0", "0");
1593 nvram_set("pci/1/1/pdoffset80ma1", "0");
1594 nvram_set("pci/1/1/pdoffset80ma2", "0");
1595 nvram_set("pci/1/1/regrev", "66");
1596 nvram_set("pci/1/1/rpcal2g", "0x5f7");
1597 nvram_set("pci/1/1/rxgainerr2ga0", "63");
1598 nvram_set("pci/1/1/rxgainerr2ga1", "31");
1599 nvram_set("pci/1/1/rxgainerr2ga2", "31");
1600 nvram_set("pci/1/1/rxgains2gelnagaina0", "3");
1601 nvram_set("pci/1/1/rxgains2gelnagaina1", "3");
1602 nvram_set("pci/1/1/rxgains2gelnagaina2", "3");
1603 nvram_set("pci/1/1/rxgains2gtrelnabypa0", "1");
1604 nvram_set("pci/1/1/rxgains2gtrelnabypa1", "1");
1605 nvram_set("pci/1/1/rxgains2gtrelnabypa2", "1");
1606 nvram_set("pci/1/1/rxgains2gtrisoa0", "7");
1607 nvram_set("pci/1/1/rxgains2gtrisoa1", "7");
1608 nvram_set("pci/1/1/rxgains2gtrisoa2", "7");
1609 nvram_set("pci/1/1/sar2g", "18");
1610 nvram_set("pci/1/1/sromrev", "11");
1611 nvram_set("pci/1/1/subband5gver", "0x4");
1612 nvram_set("pci/1/1/subvid", "0x14e4");
1613 nvram_set("pci/1/1/tssifloor2g", "0x3ff");
1614 nvram_set("pci/1/1/tssiposslope2g", "1");
1615 nvram_set("pci/1/1/tworangetssi2g", "0");
1616 nvram_set("pci/1/1/xtalfreq", "65535");
1617 nvram_set("pci/2/1/aa2g", "7");
1618 nvram_set("pci/2/1/aa5g", "0");
1619 nvram_set("pci/2/1/aga0", "0");
1620 nvram_set("pci/2/1/aga1", "0");
1621 nvram_set("pci/2/1/aga2", "0");
1622 nvram_set("pci/2/1/agbg0", "0");
1623 nvram_set("pci/2/1/agbg1", "0");
1624 nvram_set("pci/2/1/agbg2", "0");
1625 nvram_set("pci/2/1/antswitch", "0");
1626 nvram_set("pci/2/1/boardflags", "0x30000000");
1627 nvram_set("pci/2/1/boardflags2", "0x300002");
1628 nvram_set("pci/2/1/boardflags3", "0x10000000");
1629 nvram_set("pci/2/1/boardnum", "20507");
1630 nvram_set("pci/2/1/boardrev", "0x1451");
1631 nvram_set("pci/2/1/boardtype", "0x621");
1632 nvram_set("pci/2/1/cckbw202gpo", "0");
1633 nvram_set("pci/2/1/cckbw20ul2gpo", "0");
1634 nvram_set("pci/2/1/ccode", "SG");
1635 nvram_set("pci/2/1/devid", "0x43a2");
1636 nvram_set("pci/2/1/dot11agduphrpo", "0");
1637 nvram_set("pci/2/1/dot11agduplrpo", "0");
1638 nvram_set("pci/2/1/dot11agofdmhrbw202gpo", "0");
1639 nvram_set("pci/2/1/epagain2g", "0");
1640 nvram_set("pci/2/1/epagain5g", "0");
1641 nvram_set("pci/2/1/femctrl", "3");
1642 nvram_set("pci/2/1/gainctrlsph", "0");
1643 // nvram_set("pci/2/1/macaddr", "E4:F4:C6:01:47:7B");
1644 nvram_set("pci/2/1/maxp2ga0", "76");
1645 nvram_set("pci/2/1/maxp2ga1", "76");
1646 nvram_set("pci/2/1/maxp2ga2", "76");
1647 nvram_set("pci/2/1/maxp5ga0", "106,106,106,106");
1648 nvram_set("pci/2/1/maxp5ga1", "106,106,106,106");
1649 nvram_set("pci/2/1/maxp5ga2", "106,106,106,106");
1650 nvram_set("pci/2/1/mcsbw1605ghpo", "0");
1651 nvram_set("pci/2/1/mcsbw1605glpo", "0");
1652 nvram_set("pci/2/1/mcsbw1605gmpo", "0");
1653 nvram_set("pci/2/1/mcsbw1605hpo", "0");
1654 nvram_set("pci/2/1/mcsbw202gpo", "0");
1655 nvram_set("pci/2/1/mcsbw205ghpo", "0xBA768600");
1656 nvram_set("pci/2/1/mcsbw205glpo", "0xBA768600");
1657 nvram_set("pci/2/1/mcsbw205gmpo", "0xBA768600");
1658 nvram_set("pci/2/1/mcsbw402gpo", "0");
1659 nvram_set("pci/2/1/mcsbw405ghpo", "0xBA768600");
1660 nvram_set("pci/2/1/mcsbw405glpo", "0xBA768600");
1661 nvram_set("pci/2/1/mcsbw405gmpo", "0xBA768600");
1662 nvram_set("pci/2/1/mcsbw805ghpo", "0xBA768600");
1663 nvram_set("pci/2/1/mcsbw805glpo", "0xBA768600");
1664 nvram_set("pci/2/1/mcsbw805gmpo", "0xBA768600");
1665 nvram_set("pci/2/1/mcslr5ghpo", "0");
1666 nvram_set("pci/2/1/mcslr5glpo", "0");
1667 nvram_set("pci/2/1/mcslr5gmpo", "0");
1668 nvram_set("pci/2/1/measpower", "0x7f");
1669 nvram_set("pci/2/1/measpower1", "0x7f");
1670 nvram_set("pci/2/1/measpower2", "0x7f");
1671 nvram_set("pci/2/1/noiselvl2ga0", "31");
1672 nvram_set("pci/2/1/noiselvl2ga1", "31");
1673 nvram_set("pci/2/1/noiselvl2ga2", "31");
1674 nvram_set("pci/2/1/noiselvl5ga0", "31,31,31,31");
1675 nvram_set("pci/2/1/noiselvl5ga1", "31,31,31,31");
1676 nvram_set("pci/2/1/noiselvl5ga2", "31,31,31,31");
1677 nvram_set("pci/2/1/ofdmlrbw202gpo", "0");
1678 nvram_set("pci/2/1/pa2ga0", "0xfe72,0x14c0,0xfac7");
1679 nvram_set("pci/2/1/pa2ga1", "0xfe80,0x1472,0xfabc");
1680 nvram_set("pci/2/1/pa2ga2", "0xfe82,0x14bf,0xfad9");
1681 nvram_set("pci/2/1/pa5ga0", "0xFF4C,0x1808,0xFD1B,0xFF4C,0x18CF,0xFD0C,0xFF4A,0x1920,0xFD08,0xFF4C,0x1949,0xFCF6");
1682 nvram_set("pci/2/1/pa5ga1", "0xFF4A,0x18AC,0xFD0B,0xFF44,0x1904,0xFCFF,0xFF56,0x1A09,0xFCFC,0xFF4F,0x19AB,0xFCEF");
1683 nvram_set("pci/2/1/pa5ga2", "0xFF4C,0x1896,0xFD11,0xFF43,0x192D,0xFCF5,0xFF50,0x19EE,0xFCF1,0xFF52,0x19C6,0xFCF1");
1684 nvram_set("pci/2/1/papdcap2g", "0");
1685 nvram_set("pci/2/1/papdcap5g", "0");
1686 nvram_set("pci/2/1/pdgain2g", "4");
1687 nvram_set("pci/2/1/pdgain5g", "4");
1688 nvram_set("pci/2/1/pdoffset2g40ma0", "15");
1689 nvram_set("pci/2/1/pdoffset2g40ma1", "15");
1690 nvram_set("pci/2/1/pdoffset2g40ma2", "15");
1691 nvram_set("pci/2/1/pdoffset2g40mvalid", "1");
1692 nvram_set("pci/2/1/pdoffset40ma0", "4369");
1693 nvram_set("pci/2/1/pdoffset40ma1", "4369");
1694 nvram_set("pci/2/1/pdoffset40ma2", "4369");
1695 nvram_set("pci/2/1/pdoffset80ma0", "0");
1696 nvram_set("pci/2/1/pdoffset80ma1", "0");
1697 nvram_set("pci/2/1/pdoffset80ma2", "0");
1698 nvram_set("pci/2/1/phycal_tempdelta", "255");
1699 nvram_set("pci/2/1/rawtempsense", "0x1ff");
1700 nvram_set("pci/2/1/regrev", "66");
1701 nvram_set("pci/2/1/rpcal2g", "0");
1702 nvram_set("pci/2/1/rpcal5gb0", "0x610c");
1703 nvram_set("pci/2/1/rpcal5gb1", "0x6a09");
1704 nvram_set("pci/2/1/rpcal5gb2", "0x5eff");
1705 nvram_set("pci/2/1/rpcal5gb3", "0x700c");
1706 nvram_set("pci/2/1/rxchain", "7");
1707 nvram_set("pci/2/1/rxgainerr2ga0", "63");
1708 nvram_set("pci/2/1/rxgainerr2ga1", "31");
1709 nvram_set("pci/2/1/rxgainerr2ga2", "31");
1710 nvram_set("pci/2/1/rxgainerr5ga0", "63,63,63,63");
1711 nvram_set("pci/2/1/rxgainerr5ga1", "31,31,31,31");
1712 nvram_set("pci/2/1/rxgainerr5ga2", "31,31,31,31");
1713 nvram_set("pci/2/1/rxgains2gelnagaina0", "0");
1714 nvram_set("pci/2/1/rxgains2gelnagaina1", "0");
1715 nvram_set("pci/2/1/rxgains2gelnagaina2", "0");
1716 nvram_set("pci/2/1/rxgains2gtrelnabypa0", "0");
1717 nvram_set("pci/2/1/rxgains2gtrelnabypa1", "0");
1718 nvram_set("pci/2/1/rxgains2gtrelnabypa2", "0");
1719 nvram_set("pci/2/1/rxgains2gtrisoa0", "0");
1720 nvram_set("pci/2/1/rxgains2gtrisoa1", "0");
1721 nvram_set("pci/2/1/rxgains2gtrisoa2", "0");
1722 nvram_set("pci/2/1/rxgains5gelnagaina0", "4");
1723 nvram_set("pci/2/1/rxgains5gelnagaina1", "4");
1724 nvram_set("pci/2/1/rxgains5gelnagaina2", "4");
1725 nvram_set("pci/2/1/rxgains5ghelnagaina0", "3");
1726 nvram_set("pci/2/1/rxgains5ghelnagaina1", "3");
1727 nvram_set("pci/2/1/rxgains5ghelnagaina2", "4");
1728 nvram_set("pci/2/1/rxgains5ghtrelnabypa0", "1");
1729 nvram_set("pci/2/1/rxgains5ghtrelnabypa1", "1");
1730 nvram_set("pci/2/1/rxgains5ghtrelnabypa2", "1");
1731 nvram_set("pci/2/1/rxgains5ghtrisoa0", "5");
1732 nvram_set("pci/2/1/rxgains5ghtrisoa1", "4");
1733 nvram_set("pci/2/1/rxgains5ghtrisoa2", "4");
1734 nvram_set("pci/2/1/rxgains5gmelnagaina0", "3");
1735 nvram_set("pci/2/1/rxgains5gmelnagaina1", "4");
1736 nvram_set("pci/2/1/rxgains5gmelnagaina2", "4");
1737 nvram_set("pci/2/1/rxgains5gmtrelnabypa0", "1");
1738 nvram_set("pci/2/1/rxgains5gmtrelnabypa1", "1");
1739 nvram_set("pci/2/1/rxgains5gmtrelnabypa2", "1");
1740 nvram_set("pci/2/1/rxgains5gmtrisoa0", "5");
1741 nvram_set("pci/2/1/rxgains5gmtrisoa1", "4");
1742 nvram_set("pci/2/1/rxgains5gmtrisoa2", "4");
1743 nvram_set("pci/2/1/rxgains5gtrelnabypa0", "1");
1744 nvram_set("pci/2/1/rxgains5gtrelnabypa1", "1");
1745 nvram_set("pci/2/1/rxgains5gtrelnabypa2", "1");
1746 nvram_set("pci/2/1/rxgains5gtrisoa0", "7");
1747 nvram_set("pci/2/1/rxgains5gtrisoa1", "6");
1748 nvram_set("pci/2/1/rxgains5gtrisoa2", "5");
1749 nvram_set("pci/2/1/sar2g", "18");
1750 nvram_set("pci/2/1/sar5g", "15");
1751 nvram_set("pci/2/1/sb20in40hrpo", "0");
1752 nvram_set("pci/2/1/sb20in40lrpo", "0");
1753 nvram_set("pci/2/1/sb20in80and160hr5ghpo", "0");
1754 nvram_set("pci/2/1/sb20in80and160hr5glpo", "0");
1755 nvram_set("pci/2/1/sb20in80and160hr5gmpo", "0");
1756 nvram_set("pci/2/1/sb20in80and160lr5ghpo", "0");
1757 nvram_set("pci/2/1/sb20in80and160lr5glpo", "0");
1758 nvram_set("pci/2/1/sb20in80and160lr5gmpo", "0");
1759 nvram_set("pci/2/1/sb40and80hr5ghpo", "0");
1760 nvram_set("pci/2/1/sb40and80hr5glpo", "0");
1761 nvram_set("pci/2/1/sb40and80hr5gmpo", "0");
1762 nvram_set("pci/2/1/sb40and80lr5ghpo", "0");
1763 nvram_set("pci/2/1/sb40and80lr5glpo", "0");
1764 nvram_set("pci/2/1/sb40and80lr5gmpo", "0");
1765 nvram_set("pci/2/1/sromrev", "11");
1766 nvram_set("pci/2/1/subband5gver", "0x4");
1767 nvram_set("pci/2/1/subvid", "0x14e4");
1768 nvram_set("pci/2/1/tempcorrx", "0x3f");
1769 nvram_set("pci/2/1/tempoffset", "255");
1770 nvram_set("pci/2/1/tempsense_option", "0x3");
1771 nvram_set("pci/2/1/tempsense_slope", "0xff");
1772 nvram_set("pci/2/1/temps_hysteresis", "15");
1773 nvram_set("pci/2/1/temps_period", "15");
1774 nvram_set("pci/2/1/tempthresh", "255");
1775 nvram_set("pci/2/1/tssifloor2g", "0x3ff");
1776 nvram_set("pci/2/1/tssifloor5g", "0x3ff,0x3ff,0x3ff,0x3ff");
1777 nvram_set("pci/2/1/tssiposslope2g", "1");
1778 nvram_set("pci/2/1/tssiposslope5g", "1");
1779 nvram_set("pci/2/1/tworangetssi2g", "0");
1780 nvram_set("pci/2/1/tworangetssi5g", "0");
1781 nvram_set("pci/2/1/txchain", "7");
1782 nvram_set("pci/2/1/xtalfreq", "65535");
1785 break;
1786 case MODEL_DIR868L:
1787 mfr = "D-Link";
1788 name = "DIR868L";
1789 features = SUP_SES | SUP_80211N | SUP_1000ET | SUP_80211AC;
1790 #ifdef TCONFIG_USB
1791 nvram_set("usb_uhci", "-1");
1792 #endif
1793 if (!nvram_match("t_fix1", (char *)name)) {
1794 nvram_set("vlan1hwname", "et0");
1795 nvram_set("vlan2hwname", "et0");
1796 nvram_set("lan_ifname", "br0");
1797 nvram_set("landevs", "vlan1 wl0 wl1");
1798 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1799 nvram_set("wan_ifnames", "vlan2");
1800 nvram_set("wan_ifnameX", "vlan2");
1801 nvram_set("wandevs", "vlan2");
1802 nvram_set("wl_ifnames", "eth1 eth2");
1803 nvram_set("wl_ifname", "eth1");
1804 nvram_set("wl0_ifname", "eth1");
1805 nvram_set("wl1_ifname", "eth2");
1807 // fix WL mac for 5G
1808 strcpy(s, nvram_safe_get("pci/1/1/macaddr"));
1809 inc_mac(s, +1);
1810 nvram_set("pci/2/1/macaddr", s);
1812 // usb3.0 settings
1813 nvram_set("usb_usb3", "1");
1814 nvram_set("xhci_ports", "1-1");
1815 nvram_set("ehci_ports", "2-1 2-2");
1816 nvram_set("ohci_ports", "3-1 3-2");
1818 // force wl1 settings
1819 nvram_set("wl1_bw", "3");
1820 nvram_set("wl1_bw_cap", "7");
1821 nvram_set("wl1_chanspec", "149/80");
1822 nvram_set("wl1_nctrlsb", "lower");
1823 nvram_set("wl_country", "SG");
1824 nvram_set("wl_country_code", "SG");
1826 // bcm4360ac_defaults - fix problem of loading driver failed with code 21
1827 nvram_set("pci/1/1/aa2g", "7");
1828 nvram_set("pci/1/1/agbg0", "71");
1829 nvram_set("pci/1/1/agbg1", "71");
1830 nvram_set("pci/1/1/agbg2", "71");
1831 nvram_set("pci/1/1/antswitch", "0");
1832 nvram_set("pci/1/1/boardflags", "0x1000");
1833 nvram_set("pci/1/1/boardflags2", "0x100002");
1834 nvram_set("pci/1/1/boardflags3", "0x10000003");
1835 nvram_set("pci/1/1/boardnum", "57359");
1836 nvram_set("pci/1/1/boardrev", "0x1150");
1837 nvram_set("pci/1/1/boardtype", "0x661");
1838 nvram_set("pci/1/1/cckbw202gpo", "0");
1839 nvram_set("pci/1/1/cckbw20ul2gpo", "0");
1840 nvram_set("pci/1/1/ccode", "EU");
1841 nvram_set("pci/1/1/devid", "0x43a1");
1842 nvram_set("pci/1/1/dot11agduphrpo", "0");
1843 nvram_set("pci/1/1/dot11agduplrpo", "0");
1844 nvram_set("pci/1/1/dot11agofdmhrbw202gpo", "0xCA86");
1845 nvram_set("pci/1/1/epagain2g", "0");
1846 nvram_set("pci/1/1/femctrl", "3");
1847 nvram_set("pci/1/1/gainctrlsph", "0");
1848 // nvram_set("pci/1/1/macaddr", "E4:F4:C6:01:47:7C");
1849 nvram_set("pci/1/1/maxp2ga0", "106");
1850 nvram_set("pci/1/1/maxp2ga1", "106");
1851 nvram_set("pci/1/1/maxp2ga2", "106");
1852 nvram_set("pci/1/1/mcsbw202gpo", "0xA976A600");
1853 nvram_set("pci/1/1/mcsbw402gpo", "0xA976A600");
1854 nvram_set("pci/1/1/measpower", "0x7f");
1855 nvram_set("pci/1/1/measpower1", "0x7f");
1856 nvram_set("pci/1/1/measpower2", "0x7f");
1857 nvram_set("pci/1/1/noiselvl2ga0", "31");
1858 nvram_set("pci/1/1/noiselvl2ga1", "31");
1859 nvram_set("pci/1/1/noiselvl2ga2", "31");
1860 nvram_set("pci/1/1/ofdmlrbw202gpo", "0");
1861 nvram_set("pci/1/1/pa2ga0", "0xFF32,0x1C30,0xFCA3");
1862 nvram_set("pci/1/1/pa2ga1", "0xFF35,0x1BE3,0xFCB0");
1863 nvram_set("pci/1/1/pa2ga2", "0xFF33,0x1BE1,0xFCB0");
1864 nvram_set("pci/1/1/papdcap2g", "0");
1865 nvram_set("pci/1/1/pdgain2g", "14");
1866 nvram_set("pci/1/1/pdoffset2g40ma0", "15");
1867 nvram_set("pci/1/1/pdoffset2g40ma1", "15");
1868 nvram_set("pci/1/1/pdoffset2g40ma2", "15");
1869 nvram_set("pci/1/1/pdoffset2g40mvalid", "1");
1870 nvram_set("pci/1/1/pdoffset40ma0", "0");
1871 nvram_set("pci/1/1/pdoffset40ma1", "0");
1872 nvram_set("pci/1/1/pdoffset40ma2", "0");
1873 nvram_set("pci/1/1/pdoffset80ma0", "0");
1874 nvram_set("pci/1/1/pdoffset80ma1", "0");
1875 nvram_set("pci/1/1/pdoffset80ma2", "0");
1876 nvram_set("pci/1/1/regrev", "66");
1877 nvram_set("pci/1/1/rpcal2g", "0x5f7");
1878 nvram_set("pci/1/1/rxgainerr2ga0", "63");
1879 nvram_set("pci/1/1/rxgainerr2ga1", "31");
1880 nvram_set("pci/1/1/rxgainerr2ga2", "31");
1881 nvram_set("pci/1/1/rxgains2gelnagaina0", "3");
1882 nvram_set("pci/1/1/rxgains2gelnagaina1", "3");
1883 nvram_set("pci/1/1/rxgains2gelnagaina2", "3");
1884 nvram_set("pci/1/1/rxgains2gtrelnabypa0", "1");
1885 nvram_set("pci/1/1/rxgains2gtrelnabypa1", "1");
1886 nvram_set("pci/1/1/rxgains2gtrelnabypa2", "1");
1887 nvram_set("pci/1/1/rxgains2gtrisoa0", "7");
1888 nvram_set("pci/1/1/rxgains2gtrisoa1", "7");
1889 nvram_set("pci/1/1/rxgains2gtrisoa2", "7");
1890 nvram_set("pci/1/1/sar2g", "18");
1891 nvram_set("pci/1/1/sromrev", "11");
1892 nvram_set("pci/1/1/subband5gver", "0x4");
1893 nvram_set("pci/1/1/subvid", "0x14e4");
1894 nvram_set("pci/1/1/tssifloor2g", "0x3ff");
1895 nvram_set("pci/1/1/tssiposslope2g", "1");
1896 nvram_set("pci/1/1/tworangetssi2g", "0");
1897 nvram_set("pci/1/1/xtalfreq", "65535");
1898 nvram_set("pci/2/1/aa2g", "7");
1899 nvram_set("pci/2/1/aa5g", "0");
1900 nvram_set("pci/2/1/aga0", "0");
1901 nvram_set("pci/2/1/aga1", "0");
1902 nvram_set("pci/2/1/aga2", "0");
1903 nvram_set("pci/2/1/agbg0", "0");
1904 nvram_set("pci/2/1/agbg1", "0");
1905 nvram_set("pci/2/1/agbg2", "0");
1906 nvram_set("pci/2/1/antswitch", "0");
1907 nvram_set("pci/2/1/boardflags", "0x30000000");
1908 nvram_set("pci/2/1/boardflags2", "0x300002");
1909 nvram_set("pci/2/1/boardflags3", "0x10000000");
1910 nvram_set("pci/2/1/boardnum", "20507");
1911 nvram_set("pci/2/1/boardrev", "0x1451");
1912 nvram_set("pci/2/1/boardtype", "0x621");
1913 nvram_set("pci/2/1/cckbw202gpo", "0");
1914 nvram_set("pci/2/1/cckbw20ul2gpo", "0");
1915 nvram_set("pci/2/1/ccode", "SG");
1916 nvram_set("pci/2/1/devid", "0x43a2");
1917 nvram_set("pci/2/1/dot11agduphrpo", "0");
1918 nvram_set("pci/2/1/dot11agduplrpo", "0");
1919 nvram_set("pci/2/1/dot11agofdmhrbw202gpo", "0");
1920 nvram_set("pci/2/1/epagain2g", "0");
1921 nvram_set("pci/2/1/epagain5g", "0");
1922 nvram_set("pci/2/1/femctrl", "3");
1923 nvram_set("pci/2/1/gainctrlsph", "0");
1924 // nvram_set("pci/2/1/macaddr", "E4:F4:C6:01:47:7B");
1925 nvram_set("pci/2/1/maxp2ga0", "76");
1926 nvram_set("pci/2/1/maxp2ga1", "76");
1927 nvram_set("pci/2/1/maxp2ga2", "76");
1928 nvram_set("pci/2/1/maxp5ga0", "106,106,106,106");
1929 nvram_set("pci/2/1/maxp5ga1", "106,106,106,106");
1930 nvram_set("pci/2/1/maxp5ga2", "106,106,106,106");
1931 nvram_set("pci/2/1/mcsbw1605ghpo", "0");
1932 nvram_set("pci/2/1/mcsbw1605glpo", "0");
1933 nvram_set("pci/2/1/mcsbw1605gmpo", "0");
1934 nvram_set("pci/2/1/mcsbw1605hpo", "0");
1935 nvram_set("pci/2/1/mcsbw202gpo", "0");
1936 nvram_set("pci/2/1/mcsbw205ghpo", "0xBA768600");
1937 nvram_set("pci/2/1/mcsbw205glpo", "0xBA768600");
1938 nvram_set("pci/2/1/mcsbw205gmpo", "0xBA768600");
1939 nvram_set("pci/2/1/mcsbw402gpo", "0");
1940 nvram_set("pci/2/1/mcsbw405ghpo", "0xBA768600");
1941 nvram_set("pci/2/1/mcsbw405glpo", "0xBA768600");
1942 nvram_set("pci/2/1/mcsbw405gmpo", "0xBA768600");
1943 nvram_set("pci/2/1/mcsbw805ghpo", "0xBA768600");
1944 nvram_set("pci/2/1/mcsbw805glpo", "0xBA768600");
1945 nvram_set("pci/2/1/mcsbw805gmpo", "0xBA768600");
1946 nvram_set("pci/2/1/mcslr5ghpo", "0");
1947 nvram_set("pci/2/1/mcslr5glpo", "0");
1948 nvram_set("pci/2/1/mcslr5gmpo", "0");
1949 nvram_set("pci/2/1/measpower", "0x7f");
1950 nvram_set("pci/2/1/measpower1", "0x7f");
1951 nvram_set("pci/2/1/measpower2", "0x7f");
1952 nvram_set("pci/2/1/noiselvl2ga0", "31");
1953 nvram_set("pci/2/1/noiselvl2ga1", "31");
1954 nvram_set("pci/2/1/noiselvl2ga2", "31");
1955 nvram_set("pci/2/1/noiselvl5ga0", "31,31,31,31");
1956 nvram_set("pci/2/1/noiselvl5ga1", "31,31,31,31");
1957 nvram_set("pci/2/1/noiselvl5ga2", "31,31,31,31");
1958 nvram_set("pci/2/1/ofdmlrbw202gpo", "0");
1959 nvram_set("pci/2/1/pa2ga0", "0xfe72,0x14c0,0xfac7");
1960 nvram_set("pci/2/1/pa2ga1", "0xfe80,0x1472,0xfabc");
1961 nvram_set("pci/2/1/pa2ga2", "0xfe82,0x14bf,0xfad9");
1962 nvram_set("pci/2/1/pa5ga0", "0xFF4C,0x1808,0xFD1B,0xFF4C,0x18CF,0xFD0C,0xFF4A,0x1920,0xFD08,0xFF4C,0x1949,0xFCF6");
1963 nvram_set("pci/2/1/pa5ga1", "0xFF4A,0x18AC,0xFD0B,0xFF44,0x1904,0xFCFF,0xFF56,0x1A09,0xFCFC,0xFF4F,0x19AB,0xFCEF");
1964 nvram_set("pci/2/1/pa5ga2", "0xFF4C,0x1896,0xFD11,0xFF43,0x192D,0xFCF5,0xFF50,0x19EE,0xFCF1,0xFF52,0x19C6,0xFCF1");
1965 nvram_set("pci/2/1/papdcap2g", "0");
1966 nvram_set("pci/2/1/papdcap5g", "0");
1967 nvram_set("pci/2/1/pdgain2g", "4");
1968 nvram_set("pci/2/1/pdgain5g", "4");
1969 nvram_set("pci/2/1/pdoffset2g40ma0", "15");
1970 nvram_set("pci/2/1/pdoffset2g40ma1", "15");
1971 nvram_set("pci/2/1/pdoffset2g40ma2", "15");
1972 nvram_set("pci/2/1/pdoffset2g40mvalid", "1");
1973 nvram_set("pci/2/1/pdoffset40ma0", "4369");
1974 nvram_set("pci/2/1/pdoffset40ma1", "4369");
1975 nvram_set("pci/2/1/pdoffset40ma2", "4369");
1976 nvram_set("pci/2/1/pdoffset80ma0", "0");
1977 nvram_set("pci/2/1/pdoffset80ma1", "0");
1978 nvram_set("pci/2/1/pdoffset80ma2", "0");
1979 nvram_set("pci/2/1/phycal_tempdelta", "255");
1980 nvram_set("pci/2/1/rawtempsense", "0x1ff");
1981 nvram_set("pci/2/1/regrev", "66");
1982 nvram_set("pci/2/1/rpcal2g", "0");
1983 nvram_set("pci/2/1/rpcal5gb0", "0x610c");
1984 nvram_set("pci/2/1/rpcal5gb1", "0x6a09");
1985 nvram_set("pci/2/1/rpcal5gb2", "0x5eff");
1986 nvram_set("pci/2/1/rpcal5gb3", "0x700c");
1987 nvram_set("pci/2/1/rxchain", "7");
1988 nvram_set("pci/2/1/rxgainerr2ga0", "63");
1989 nvram_set("pci/2/1/rxgainerr2ga1", "31");
1990 nvram_set("pci/2/1/rxgainerr2ga2", "31");
1991 nvram_set("pci/2/1/rxgainerr5ga0", "63,63,63,63");
1992 nvram_set("pci/2/1/rxgainerr5ga1", "31,31,31,31");
1993 nvram_set("pci/2/1/rxgainerr5ga2", "31,31,31,31");
1994 nvram_set("pci/2/1/rxgains2gelnagaina0", "0");
1995 nvram_set("pci/2/1/rxgains2gelnagaina1", "0");
1996 nvram_set("pci/2/1/rxgains2gelnagaina2", "0");
1997 nvram_set("pci/2/1/rxgains2gtrelnabypa0", "0");
1998 nvram_set("pci/2/1/rxgains2gtrelnabypa1", "0");
1999 nvram_set("pci/2/1/rxgains2gtrelnabypa2", "0");
2000 nvram_set("pci/2/1/rxgains2gtrisoa0", "0");
2001 nvram_set("pci/2/1/rxgains2gtrisoa1", "0");
2002 nvram_set("pci/2/1/rxgains2gtrisoa2", "0");
2003 nvram_set("pci/2/1/rxgains5gelnagaina0", "4");
2004 nvram_set("pci/2/1/rxgains5gelnagaina1", "4");
2005 nvram_set("pci/2/1/rxgains5gelnagaina2", "4");
2006 nvram_set("pci/2/1/rxgains5ghelnagaina0", "3");
2007 nvram_set("pci/2/1/rxgains5ghelnagaina1", "3");
2008 nvram_set("pci/2/1/rxgains5ghelnagaina2", "4");
2009 nvram_set("pci/2/1/rxgains5ghtrelnabypa0", "1");
2010 nvram_set("pci/2/1/rxgains5ghtrelnabypa1", "1");
2011 nvram_set("pci/2/1/rxgains5ghtrelnabypa2", "1");
2012 nvram_set("pci/2/1/rxgains5ghtrisoa0", "5");
2013 nvram_set("pci/2/1/rxgains5ghtrisoa1", "4");
2014 nvram_set("pci/2/1/rxgains5ghtrisoa2", "4");
2015 nvram_set("pci/2/1/rxgains5gmelnagaina0", "3");
2016 nvram_set("pci/2/1/rxgains5gmelnagaina1", "4");
2017 nvram_set("pci/2/1/rxgains5gmelnagaina2", "4");
2018 nvram_set("pci/2/1/rxgains5gmtrelnabypa0", "1");
2019 nvram_set("pci/2/1/rxgains5gmtrelnabypa1", "1");
2020 nvram_set("pci/2/1/rxgains5gmtrelnabypa2", "1");
2021 nvram_set("pci/2/1/rxgains5gmtrisoa0", "5");
2022 nvram_set("pci/2/1/rxgains5gmtrisoa1", "4");
2023 nvram_set("pci/2/1/rxgains5gmtrisoa2", "4");
2024 nvram_set("pci/2/1/rxgains5gtrelnabypa0", "1");
2025 nvram_set("pci/2/1/rxgains5gtrelnabypa1", "1");
2026 nvram_set("pci/2/1/rxgains5gtrelnabypa2", "1");
2027 nvram_set("pci/2/1/rxgains5gtrisoa0", "7");
2028 nvram_set("pci/2/1/rxgains5gtrisoa1", "6");
2029 nvram_set("pci/2/1/rxgains5gtrisoa2", "5");
2030 nvram_set("pci/2/1/sar2g", "18");
2031 nvram_set("pci/2/1/sar5g", "15");
2032 nvram_set("pci/2/1/sb20in40hrpo", "0");
2033 nvram_set("pci/2/1/sb20in40lrpo", "0");
2034 nvram_set("pci/2/1/sb20in80and160hr5ghpo", "0");
2035 nvram_set("pci/2/1/sb20in80and160hr5glpo", "0");
2036 nvram_set("pci/2/1/sb20in80and160hr5gmpo", "0");
2037 nvram_set("pci/2/1/sb20in80and160lr5ghpo", "0");
2038 nvram_set("pci/2/1/sb20in80and160lr5glpo", "0");
2039 nvram_set("pci/2/1/sb20in80and160lr5gmpo", "0");
2040 nvram_set("pci/2/1/sb40and80hr5ghpo", "0");
2041 nvram_set("pci/2/1/sb40and80hr5glpo", "0");
2042 nvram_set("pci/2/1/sb40and80hr5gmpo", "0");
2043 nvram_set("pci/2/1/sb40and80lr5ghpo", "0");
2044 nvram_set("pci/2/1/sb40and80lr5glpo", "0");
2045 nvram_set("pci/2/1/sb40and80lr5gmpo", "0");
2046 nvram_set("pci/2/1/sromrev", "11");
2047 nvram_set("pci/2/1/subband5gver", "0x4");
2048 nvram_set("pci/2/1/subvid", "0x14e4");
2049 nvram_set("pci/2/1/tempcorrx", "0x3f");
2050 nvram_set("pci/2/1/tempoffset", "255");
2051 nvram_set("pci/2/1/tempsense_option", "0x3");
2052 nvram_set("pci/2/1/tempsense_slope", "0xff");
2053 nvram_set("pci/2/1/temps_hysteresis", "15");
2054 nvram_set("pci/2/1/temps_period", "15");
2055 nvram_set("pci/2/1/tempthresh", "255");
2056 nvram_set("pci/2/1/tssifloor2g", "0x3ff");
2057 nvram_set("pci/2/1/tssifloor5g", "0x3ff,0x3ff,0x3ff,0x3ff");
2058 nvram_set("pci/2/1/tssiposslope2g", "1");
2059 nvram_set("pci/2/1/tssiposslope5g", "1");
2060 nvram_set("pci/2/1/tworangetssi2g", "0");
2061 nvram_set("pci/2/1/tworangetssi5g", "0");
2062 nvram_set("pci/2/1/txchain", "7");
2063 nvram_set("pci/2/1/xtalfreq", "65535");
2066 break;
2067 case MODEL_WS880:
2068 mfr = "Huawei";
2069 name = "WS880";
2070 features = SUP_SES | SUP_80211N | SUP_1000ET | SUP_80211AC;
2071 #ifdef TCONFIG_USB
2072 nvram_set("usb_uhci", "-1");
2073 #endif
2074 if (!nvram_match("t_fix1", (char *)name)) {
2075 nvram_set("vlan1hwname", "et0");
2076 nvram_set("vlan2hwname", "et0");
2077 nvram_set("lan_ifname", "br0");
2078 nvram_set("landevs", "vlan1 wl0 wl1");
2079 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
2080 nvram_set("wan_ifnames", "vlan2");
2081 nvram_set("wan_ifnameX", "vlan2");
2082 nvram_set("wandevs", "vlan2");
2083 nvram_set("wl_ifnames", "eth1 eth2");
2084 nvram_set("wl_ifname", "eth1");
2085 nvram_set("wl0_ifname", "eth1");
2086 nvram_set("wl1_ifname", "eth2");
2088 // fix WL mac`s
2089 strcpy(s, nvram_safe_get("et0macaddr"));
2090 inc_mac(s, +2);
2091 nvram_set("0:macaddr", s);
2092 inc_mac(s, +4);
2093 nvram_set("1:macaddr", s);
2095 // usb3.0 settings
2096 nvram_set("usb_usb3", "1");
2097 nvram_set("xhci_ports", "1-1");
2098 nvram_set("ehci_ports", "2-1 2-2");
2099 nvram_set("ohci_ports", "3-1 3-2");
2101 // misc settings
2102 nvram_set("boot_wait", "off");
2103 nvram_set("wait_time", "1");
2105 // 2.4GHz module defaults
2106 nvram_set("devpath0", "pci/1/1");
2107 nvram_set("0:aa2g", "7");
2108 nvram_set("0:ag0", "0");
2109 nvram_set("0:ag1", "0");
2110 nvram_set("0:ag2", "0");
2111 nvram_set("0:antswctl2g", "0");
2112 nvram_set("0:antswitch", "0");
2113 nvram_set("0:boardflags2", "0x00100000");
2114 nvram_set("0:boardflags", "0x80001200");
2115 nvram_set("0:boardtype", "0x59b");
2116 nvram_set("0:boardvendor", "0x14e4");
2117 nvram_set("0:cckbw202gpo", "0x0000");
2118 nvram_set("0:cckbw20ul2gpo", "0x0000");
2119 nvram_set("0:ccode", "#a");
2120 nvram_set("0:devid", "0x4332");
2121 nvram_set("0:elna2g", "2");
2122 nvram_set("0:extpagain2g", "3");
2123 nvram_set("0:ledbh0", "11");
2124 nvram_set("0:ledbh1", "11");
2125 nvram_set("0:ledbh2", "11");
2126 nvram_set("0:ledbh3", "11");
2127 nvram_set("0:ledbh12", "11");
2128 nvram_set("0:leddc", "0xffff");
2129 nvram_set("0:legofdm40duppo", "0x0");
2130 nvram_set("0:legofdmbw202gpo", "0x88888888");
2131 nvram_set("0:legofdmbw20ul2gpo", "0x88888888");
2132 nvram_set("0:maxp2ga0", "0x46");
2133 nvram_set("0:maxp2ga1", "0x46");
2134 nvram_set("0:maxp2ga2", "0x46");
2135 nvram_set("0:mcs32po", "0x0");
2136 nvram_set("0:mcsbw202gpo", "0x88888888");
2137 nvram_set("0:mcsbw20ul2gpo", "0x88888888");
2138 nvram_set("0:mcsbw402gpo", "0x88888888");
2139 nvram_set("0:pa2gw0a0", "0xfe63");
2140 nvram_set("0:pa2gw0a1", "0xfe78");
2141 nvram_set("0:pa2gw0a2", "0xfe65");
2142 nvram_set("0:pa2gw1a0", "0x1dfd");
2143 nvram_set("0:pa2gw1a1", "0x1e4a");
2144 nvram_set("0:pa2gw1a2", "0x1e74");
2145 nvram_set("0:pa2gw2a0", "0xf8c7");
2146 nvram_set("0:pa2gw2a1", "0xf8d8");
2147 nvram_set("0:pa2gw2a2", "0xf8b9");
2148 nvram_set("0:parefldovoltage", "35");
2149 nvram_set("0:pdetrange2g", "3");
2150 nvram_set("0:phycal_tempdelta", "0");
2151 nvram_set("0:regrev", "0");
2152 nvram_set("0:rxchain", "7");
2153 nvram_set("0:sromrev", "9");
2154 nvram_set("0:tempoffset", "0");
2155 nvram_set("0:temps_hysteresis", "5");
2156 nvram_set("0:temps_period", "5");
2157 nvram_set("0:tempthresh", "120");
2158 nvram_set("0:triso2g", "3");
2159 nvram_set("0:tssipos2g", "1");
2160 nvram_set("0:txchain", "7");
2161 nvram_set("0:venid", "0x14e4");
2162 nvram_set("0:xtalfreq", "20000");
2164 // 5GHz module defaults
2165 nvram_set("devpath1", "pci/2/1");
2166 nvram_set("1:aa2g", "0");
2167 nvram_set("1:aa5g", "7");
2168 nvram_set("1:agbg0", "71");
2169 nvram_set("1:agbg1", "71");
2170 nvram_set("1:agbg2", "133");
2171 nvram_set("1:antswitch", "0");
2172 nvram_set("1:boardflags2", "0x00300002");
2173 nvram_set("1:boardflags3", "0x0");
2174 nvram_set("1:boardflags", "0x30000000");
2175 nvram_set("1:boardnum", "20771");
2176 nvram_set("1:boardrev", "0x1402");
2177 nvram_set("1:boardtype", "0x621");
2178 nvram_set("1:boardvendor", "0x14e4");
2179 nvram_set("1:cckbw202gpo", "0");
2180 nvram_set("1:cckbw20ul2gpo", "0");
2181 nvram_set("1:ccode", "#a");
2182 nvram_set("1:devid", "0x43a2");
2183 nvram_set("1:dot11agduphrpo", "0");
2184 nvram_set("1:dot11agduplrpo", "0");
2185 nvram_set("1:epagain2g", "0");
2186 nvram_set("1:epagain5g", "0");
2187 nvram_set("1:femctrl", "3");
2188 nvram_set("1:gainctrlsph", "0");
2189 nvram_set("1:maxp2ga0", "76");
2190 nvram_set("1:maxp2ga1", "76");
2191 nvram_set("1:maxp2ga2", "76");
2192 nvram_set("1:maxp5ga0", "70,70,86,86");
2193 nvram_set("1:maxp5ga1", "70,70,86,86");
2194 nvram_set("1:maxp5ga2", "70,70,86,86");
2195 nvram_set("1:mcsbw402gpo", "0");
2196 nvram_set("1:mcsbw1605ghpo", "0");
2197 nvram_set("1:mcsbw1605gmpo", "0");
2198 nvram_set("1:mcsbw402gpo", "0");
2199 nvram_set("1:mcsbw1605glpo", "0x00222222");
2200 nvram_set("1:mcsbw205ghpo", "0xaa880000");
2201 nvram_set("1:mcsbw205glpo", "0x66666666");
2202 nvram_set("1:mcsbw205gmpo", "0x66666666");
2203 nvram_set("1:mcsbw405ghpo", "0xaa880000");
2204 nvram_set("1:mcsbw405glpo", "0x22222222");
2205 nvram_set("1:mcsbw405gmpo", "0x22222222");
2206 nvram_set("1:mcsbw805ghpo", "0x88880000");
2207 nvram_set("1:mcsbw805glpo", "0x00222222");
2208 nvram_set("1:mcsbw805gmpo", "0x00222222");
2209 nvram_set("1:mcslr5ghpo", "0");
2210 nvram_set("1:mcslr5glpo", "0");
2211 nvram_set("1:mcslr5gmpo", "0");
2212 nvram_set("1:measpower1", "0x7f");
2213 nvram_set("1:measpower2", "0x7f");
2214 nvram_set("1:measpower", "0x7f");
2215 nvram_set("1:noiselvl2ga0", "31");
2216 nvram_set("1:noiselvl2ga1", "31");
2217 nvram_set("1:noiselvl2ga2", "31");
2218 nvram_set("1:noiselvl5ga0", "31,31,31,31");
2219 nvram_set("1:noiselvl5ga1", "31,31,31,31");
2220 nvram_set("1:noiselvl5ga2", "31,31,31,31");
2221 nvram_set("1:ofdmlrbw202gpo", "0");
2222 nvram_set("1:pa2ga0", "0xfe72,0x14c0,0xfac7");
2223 nvram_set("1:pa2ga1", "0xfe80,0x1472,0xfabc");
2224 nvram_set("1:pa2ga2", "0xfe82,0x14bf,0xfad9");
2225 nvram_set("1:pa5ga0", "0xff31,0x1a56,0xfcc7,0xff35,0x1a8f,0xfcc1,0xff35,0x18d4,0xfcf4,0xff2d,0x18d5,0xfce8");
2226 nvram_set("1:pa5ga1", "0xff30,0x190f,0xfce6,0xff38,0x1abc,0xfcc0,0xff0f,0x1762,0xfcef,0xff18,0x1648,0xfd23");
2227 nvram_set("1:pa5ga2", "0xff32,0x18f6,0xfce8,0xff36,0x195d,0xfcdf,0xff28,0x16ae,0xfd1e,0xff28,0x166c,0xfd2b");
2228 nvram_set("1:papdcap2g", "0");
2229 nvram_set("1:papdcap5g", "0");
2230 nvram_set("1:pcieingress_war", "15");
2231 nvram_set("1:pdgain2g", "4");
2232 nvram_set("1:pdgain5g", "4");
2233 nvram_set("1:pdoffset40ma0", "0x1111");
2234 nvram_set("1:pdoffset40ma1", "0x1111");
2235 nvram_set("1:pdoffset40ma2", "0x1111");
2236 nvram_set("1:pdoffset80ma0", "0");
2237 nvram_set("1:pdoffset80ma1", "0");
2238 nvram_set("1:pdoffset80ma2", "0xfecc");
2239 nvram_set("1:phycal_tempdelta", "255");
2240 nvram_set("1:rawtempsense", "0x1ff");
2241 nvram_set("1:regrev", "0");
2242 nvram_set("1:rxchain", "7");
2243 nvram_set("1:rxgainerr2ga0", "63");
2244 nvram_set("1:rxgainerr2ga1", "31");
2245 nvram_set("1:rxgainerr2ga2", "31");
2246 nvram_set("1:rxgainerr5ga0", "63,63,63,63");
2247 nvram_set("1:rxgainerr5ga1", "31,31,31,31");
2248 nvram_set("1:rxgainerr5ga2", "31,31,31,31");
2249 nvram_set("1:rxgains2gelnagaina0", "0");
2250 nvram_set("1:rxgains2gelnagaina1", "0");
2251 nvram_set("1:rxgains2gelnagaina2", "0");
2252 nvram_set("1:rxgains2gtrisoa0", "0");
2253 nvram_set("1:rxgains2gtrisoa1", "0");
2254 nvram_set("1:rxgains2gtrisoa2", "0");
2255 nvram_set("1:rxgains5gelnagaina0", "1");
2256 nvram_set("1:rxgains5gelnagaina1", "1");
2257 nvram_set("1:rxgains5gelnagaina2", "1");
2258 nvram_set("1:rxgains5ghelnagaina0", "2");
2259 nvram_set("1:rxgains5ghelnagaina1", "2");
2260 nvram_set("1:rxgains5ghelnagaina2", "3");
2261 nvram_set("1:rxgains5ghtrelnabypa0", "1");
2262 nvram_set("1:rxgains5ghtrelnabypa1", "1");
2263 nvram_set("1:rxgains5ghtrelnabypa2", "1");
2264 nvram_set("1:rxgains5ghtrisoa0", "5");
2265 nvram_set("1:rxgains5ghtrisoa1", "4");
2266 nvram_set("1:rxgains5ghtrisoa2", "4");
2267 nvram_set("1:rxgains5gmelnagaina0", "2");
2268 nvram_set("1:rxgains5gmelnagaina1", "2");
2269 nvram_set("1:rxgains5gmelnagaina2", "3");
2270 nvram_set("1:rxgains5gmtrelnabypa0", "1");
2271 nvram_set("1:rxgains5gmtrelnabypa1", "1");
2272 nvram_set("1:rxgains5gmtrelnabypa2", "1");
2273 nvram_set("1:rxgains5gmtrisoa0", "5");
2274 nvram_set("1:rxgains5gmtrisoa1", "4");
2275 nvram_set("1:rxgains5gmtrisoa2", "4");
2276 nvram_set("1:rxgains5gtrelnabypa0", "1");
2277 nvram_set("1:rxgains5gtrelnabypa1", "1");
2278 nvram_set("1:rxgains5gtrelnabypa2", "1");
2279 nvram_set("1:rxgains5gtrisoa0", "7");
2280 nvram_set("1:rxgains5gtrisoa1", "6");
2281 nvram_set("1:rxgains5gtrisoa2", "5");
2282 nvram_set("1:sar2g", "18");
2283 nvram_set("1:sar5g", "15");
2284 nvram_set("1:sb20in40hrpo", "0");
2285 nvram_set("1:sb20in40lrpo", "0");
2286 nvram_set("1:sb20in80and160hr5ghpo", "0");
2287 nvram_set("1:sb20in80and160hr5glpo", "0");
2288 nvram_set("1:sb20in80and160hr5gmpo", "0");
2289 nvram_set("1:sb20in80and160lr5ghpo", "0");
2290 nvram_set("1:sb20in80and160lr5glpo", "0");
2291 nvram_set("1:sb20in80and160lr5gmpo", "0");
2292 nvram_set("1:sb40and80hr5ghpo", "0");
2293 nvram_set("1:sb40and80hr5glpo", "0");
2294 nvram_set("1:sb40and80hr5gmpo", "0");
2295 nvram_set("1:sb40and80lr5ghpo", "0");
2296 nvram_set("1:sb40and80lr5glpo", "0");
2297 nvram_set("1:sb40and80lr5gmpo", "0");
2298 nvram_set("1:sromrev", "11");
2299 nvram_set("1:subband5gver", "4");
2300 nvram_set("1:subvid", "0x14e4");
2301 nvram_set("1:tempcorrx", "0x3f");
2302 nvram_set("1:tempoffset", "255");
2303 nvram_set("1:temps_hysteresis", "15");
2304 nvram_set("1:temps_period", "15");
2305 nvram_set("1:tempsense_option", "0x3");
2306 nvram_set("1:tempsense_slope", "0xff");
2307 nvram_set("1:tempthresh", "255");
2308 nvram_set("1:tssiposslope2g", "1");
2309 nvram_set("1:tssiposslope5g", "1");
2310 nvram_set("1:tworangetssi2g", "0");
2311 nvram_set("1:tworangetssi5g", "0");
2312 nvram_set("1:txchain", "7");
2313 nvram_set("1:venid", "0x14e4");
2314 nvram_set("1:xtalfreq", "40000");
2316 break;
2318 #endif
2319 case MODEL_RTN66U:
2320 mfr = "Asus";
2321 #ifdef TCONFIG_AC66U
2322 name = "RT-AC66U";
2323 features = SUP_SES | SUP_80211N | SUP_1000ET | SUP_80211AC;
2324 #else
2325 name = "RT-N66U";
2326 features = SUP_SES | SUP_80211N | SUP_1000ET;
2327 #if defined(LINUX26) && defined(TCONFIG_MICROSD)
2328 if (nvram_get_int("usb_mmc") == -1) nvram_set("usb_mmc", "1");
2329 #endif
2330 #endif
2332 #ifdef TCONFIG_USB
2333 nvram_set("usb_uhci", "-1");
2334 #endif
2335 if (!nvram_match("t_fix1", (char *)name)) {
2336 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
2337 nvram_set("wan_ifnameX", "vlan2");
2338 nvram_set("wl_ifnames", "eth1 eth2");
2339 #ifdef TCONFIG_AC66U
2340 nvram_set("wl_ifname", "eth1");
2341 nvram_set("wl0_ifname", "eth1");
2342 nvram_set("wl1_ifname", "eth2");
2343 #endif
2344 nvram_set("landevs", "vlan1 wl0 wl1");
2345 nvram_set("wandevs", "vlan2");
2346 #ifndef TCONFIG_AC66U
2347 #if defined(LINUX26) && defined(TCONFIG_USB)
2348 nvram_set("usb_noled", "1-1.4"); /* SD/MMC Card */
2349 #endif
2350 #else
2351 nvram_set("wl1_bw_cap","7");
2352 nvram_set("wl1_chanspec","36/80");
2353 nvram_set("wl0_bw_cap","3");
2354 nvram_set("wl0_chanspec","1l");
2355 nvram_set("blink_5g_interface","eth2");
2357 // fix WL mac`s
2358 strcpy(s, nvram_safe_get("et0macaddr"));
2359 inc_mac(s, +2);
2360 nvram_set("wl0_hwaddr", s);
2361 inc_mac(s, +1);
2362 nvram_set("wl1_hwaddr", s);
2364 // bcm4360ac_defaults
2365 nvram_set("pci/2/1/aa2g", "0");
2366 nvram_set("pci/2/1/aa5g", "7");
2367 nvram_set("pci/2/1/aga0", "71");
2368 nvram_set("pci/2/1/aga1", "71");
2369 nvram_set("pci/2/1/aga2", "71");
2370 nvram_set("pci/2/1/agbg0", "133");
2371 nvram_set("pci/2/1/agbg1", "133");
2372 nvram_set("pci/2/1/agbg2", "133");
2373 nvram_set("pci/2/1/antswitch", "0");
2374 nvram_set("pci/2/1/cckbw202gpo", "0");
2375 nvram_set("pci/2/1/cckbw20ul2gpo", "0");
2376 nvram_set("pci/2/1/dot11agofdmhrbw202gpo", "0");
2377 nvram_set("pci/2/1/femctrl", "3");
2378 nvram_set("pci/2/1/papdcap2g", "0");
2379 nvram_set("pci/2/1/tworangetssi2g", "0");
2380 nvram_set("pci/2/1/pdgain2g", "4");
2381 nvram_set("pci/2/1/epagain2g", "0");
2382 nvram_set("pci/2/1/tssiposslope2g", "1");
2383 nvram_set("pci/2/1/gainctrlsph", "0");
2384 nvram_set("pci/2/1/papdcap5g", "0");
2385 nvram_set("pci/2/1/tworangetssi5g", "0");
2386 nvram_set("pci/2/1/pdgain5g", "4");
2387 nvram_set("pci/2/1/epagain5g", "0");
2388 nvram_set("pci/2/1/tssiposslope5g", "1");
2389 nvram_set("pci/2/1/maxp2ga0", "76");
2390 nvram_set("pci/2/1/maxp2ga1", "76");
2391 nvram_set("pci/2/1/maxp2ga2", "76");
2392 nvram_set("pci/2/1/mcsbw202gpo", "0");
2393 nvram_set("pci/2/1/mcsbw402gpo", "0");
2394 nvram_set("pci/2/1/measpower", "0x7f");
2395 nvram_set("pci/2/1/measpower1", "0x7f");
2396 nvram_set("pci/2/1/measpower2", "0x7f");
2397 nvram_set("pci/2/1/noiselvl2ga0", "31");
2398 nvram_set("pci/2/1/noiselvl2ga1", "31");
2399 nvram_set("pci/2/1/noiselvl2ga2", "31");
2400 nvram_set("pci/2/1/noiselvl5gha0", "31");
2401 nvram_set("pci/2/1/noiselvl5gha1", "31");
2402 nvram_set("pci/2/1/noiselvl5gha2", "31");
2403 nvram_set("pci/2/1/noiselvl5gla0", "31");
2404 nvram_set("pci/2/1/noiselvl5gla1", "31");
2405 nvram_set("pci/2/1/noiselvl5gla2", "31");
2406 nvram_set("pci/2/1/noiselvl5gma0", "31");
2407 nvram_set("pci/2/1/noiselvl5gma1", "31");
2408 nvram_set("pci/2/1/noiselvl5gma2", "31");
2409 nvram_set("pci/2/1/noiselvl5gua0", "31");
2410 nvram_set("pci/2/1/noiselvl5gua1", "31");
2411 nvram_set("pci/2/1/noiselvl5gua2", "31");
2412 nvram_set("pci/2/1/ofdmlrbw202gpo", "0");
2413 nvram_set("pci/2/1/pa2ga0", "0xfe72,0x14c0,0xfac7");
2414 nvram_set("pci/2/1/pa2ga1", "0xfe80,0x1472,0xfabc");
2415 nvram_set("pci/2/1/pa2ga2", "0xfe82,0x14bf,0xfad9");
2416 nvram_set("pci/2/1/pcieingress_war", "15");
2417 nvram_set("pci/2/1/phycal_tempdelta", "255");
2418 nvram_set("pci/2/1/rawtempsense", "0x1ff");
2419 nvram_set("pci/2/1/rxchain", "7");
2420 nvram_set("pci/2/1/rxgainerr2g", "0xffff");
2421 nvram_set("pci/2/1/rxgainerr5g", "0xffff,0xffff,0xffff,0xffff");
2422 nvram_set("pci/2/1/rxgains2gelnagaina0", "0");
2423 nvram_set("pci/2/1/rxgains2gelnagaina1", "0");
2424 nvram_set("pci/2/1/rxgains2gelnagaina2", "0");
2425 nvram_set("pci/2/1/rxgains2gtrelnabypa0", "0");
2426 nvram_set("pci/2/1/rxgains2gtrelnabypa1", "0");
2427 nvram_set("pci/2/1/rxgains2gtrelnabypa2", "0");
2428 nvram_set("pci/2/1/rxgains2gtrisoa0", "0");
2429 nvram_set("pci/2/1/rxgains2gtrisoa1", "0");
2430 nvram_set("pci/2/1/rxgains2gtrisoa2", "0");
2431 nvram_set("pci/2/1/sar2g", "18");
2432 nvram_set("pci/2/1/sar5g", "15");
2433 nvram_set("pci/2/1/sromrev", "11");
2434 nvram_set("pci/2/1/subband5gver", "0x4");
2435 nvram_set("pci/2/1/tempcorrx", "0x3f");
2436 nvram_set("pci/2/1/tempoffset", "255");
2437 nvram_set("pci/2/1/temps_hysteresis", "15");
2438 nvram_set("pci/2/1/temps_period", "15");
2439 nvram_set("pci/2/1/tempsense_option", "0x3");
2440 nvram_set("pci/2/1/tempsense_slope", "0xff");
2441 nvram_set("pci/2/1/tempthresh", "255");
2442 nvram_set("pci/2/1/txchain", "7");
2443 nvram_set("pci/2/1/ledbh0", "2");
2444 nvram_set("pci/2/1/ledbh1", "5");
2445 nvram_set("pci/2/1/ledbh2", "4");
2446 nvram_set("pci/2/1/ledbh3", "11");
2447 nvram_set("pci/2/1/ledbh10", "7");
2449 //force EU country for eth2
2450 nvram_set("pci/2/1/ccode", "EU");
2451 #endif // TCONFIG_AC66U
2453 break;
2454 #ifdef CONFIG_BCMWL6
2455 case MODEL_W1800R:
2456 mfr = "Tenda";
2457 name = "W1800R";
2458 features = SUP_SES | SUP_80211N | SUP_1000ET | SUP_80211AC;
2459 #ifdef TCONFIG_USB
2460 nvram_set("usb_uhci", "-1");
2461 #endif
2462 if (!nvram_match("t_fix1", (char *)name)) {
2463 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
2464 nvram_set("wan_ifnameX", "vlan2");
2465 nvram_set("wl_ifnames", "eth1 eth2");
2466 nvram_set("wl_ifname", "eth1");
2467 nvram_set("wl0_ifname", "eth2");
2468 nvram_set("wl1_ifname", "eth1");
2469 nvram_set("wl0_bw_cap","7");
2470 nvram_set("wl0_chanspec","36/80");
2471 nvram_set("wl1_bw_cap","3");
2472 nvram_set("wl1_chanspec","1l");
2473 nvram_set("blink_5g_interface","eth1");
2474 //nvram_set("landevs", "vlan1 wl0 wl1");
2475 //nvram_set("wandevs", "vlan2");
2477 // fix WL mac`s
2478 strcpy(s, nvram_safe_get("et0macaddr"));
2479 nvram_set("wl0_hwaddr", nvram_safe_get("0:macaddr"));
2480 nvram_set("wl1_hwaddr", nvram_safe_get("1:macaddr"));
2482 // fix ssid according to 5G(eth2) and 2.4G(eth1)
2483 nvram_set("wl_ssid","Tomato50");
2484 nvram_set("wl0_ssid","Tomato50");
2485 nvram_set("wl1_ssid","Tomato24");
2487 break;
2488 case MODEL_D1800H:
2489 mfr = "Buffalo";
2490 if (nvram_match("product", "WLI-H4-D1300")) {
2491 name = "WLI-H4-D1300";
2493 else if (nvram_match("product", "WZR-D1100H")) {
2494 name = "WZR-D1100H";
2496 else {
2497 name = "WZR-D1800H";
2499 features = SUP_SES | SUP_AOSS_LED | SUP_80211N | SUP_1000ET | SUP_80211AC;
2500 #ifdef TCONFIG_USB
2501 nvram_set("usb_uhci", "-1");
2502 #endif
2503 if (!nvram_match("t_fix1", (char *)name)) {
2504 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
2505 nvram_set("wan_ifnameX", "vlan2");
2506 nvram_set("wl_ifnames", "eth1 eth2");
2507 nvram_set("wl_ifname", "eth1");
2508 nvram_set("wl0_ifname", "eth2");
2509 nvram_set("wl1_ifname", "eth1");
2510 nvram_set("wl0_bw_cap","7");
2511 nvram_set("wl0_chanspec","36/80");
2512 nvram_set("wl1_bw_cap","3");
2513 nvram_set("wl1_chanspec","1l");
2514 nvram_set("blink_5g_interface","eth1");
2516 // fix WL mac`s
2517 strcpy(s, nvram_safe_get("et0macaddr"));
2518 trimstr(s);
2519 int i;
2520 for (i = 0; i < strlen(s); i ++) if ( s[i] == '-') s[i] = ':';
2521 nvram_set("et0macaddr",s);
2522 inc_mac(s, +2);
2523 nvram_set("wl0_hwaddr", s);
2524 inc_mac(s, +1);
2525 nvram_set("wl1_hwaddr", s);
2527 // fix ssid according to 5G(eth2) and 2.4G(eth1)
2528 nvram_set("wl_ssid","Tomato50");
2529 nvram_set("wl0_ssid","Tomato50");
2530 nvram_set("wl1_ssid","Tomato24");
2532 nvram_set("pci/2/1/maxp2ga0", "0x70");
2533 nvram_set("pci/2/1/maxp2ga1", "0x70");
2534 nvram_set("pci/2/1/maxp2ga2", "0x70");
2535 nvram_set("pci/2/1/maxp5ga0", "0x6A");
2536 nvram_set("pci/2/1/maxp5ga1", "0x6A");
2537 nvram_set("pci/2/1/maxp5ga2", "0x6A");
2538 nvram_set("pci/2/1/cckbw202gpo", "0x5555");
2539 nvram_set("pci/2/1/cckbw20ul2gpo", "0x5555");
2540 nvram_set("pci/2/1/legofdmbw202gpo", "0x97555555");
2541 nvram_set("pci/2/1/legofdmbw20ul2gpo", "0x97555555");
2542 nvram_set("pci/2/1/mcsbw202gpo", "0xDA755555");
2543 nvram_set("pci/2/1/mcsbw20ul2gpo", "0xDA755555");
2544 nvram_set("pci/2/1/mcsbw402gpo", "0xFC965555");
2545 nvram_set("pci/2/1/cckbw205gpo", "0x5555");
2546 nvram_set("pci/2/1/cckbw20ul5gpo", "0x5555");
2547 nvram_set("pci/2/1/legofdmbw205gpo", "0x97555555");
2548 nvram_set("pci/2/1/legofdmbw20ul5gpo", "0x97555555");
2549 nvram_set("pci/2/1/legofdmbw205gmpo", "0x77777777");
2550 nvram_set("pci/2/1/legofdmbw20ul5gmpo", "0x77777777");
2551 nvram_set("pci/2/1/legofdmbw205ghpo", "0x77777777");
2552 nvram_set("pci/2/1/legofdmbw20ul5ghpo", "0x77777777");
2553 nvram_set("pci/2/1/mcsbw205ghpo", "0x77777777");
2554 nvram_set("pci/2/1/mcsbw20ul5ghpo", "0x77777777");
2555 nvram_set("pci/2/1/mcsbw205gpo", "0xDA755555");
2556 nvram_set("pci/2/1/mcsbw20ul5gpo", "0xDA755555");
2557 nvram_set("pci/2/1/mcsbw405gpo", "0xFC965555");
2558 nvram_set("pci/2/1/mcsbw405ghpo", "0x77777777");
2559 nvram_set("pci/2/1/mcsbw405ghpo", "0x77777777");
2560 nvram_set("pci/2/1/mcs32po", "0x7777");
2561 nvram_set("pci/2/1/legofdm40duppo", "0x0000");
2562 nvram_set("pci/1/1/maxp5ga0", "104,104,104,104");
2563 nvram_set("pci/1/1/maxp5ga1", "104,104,104,104");
2564 nvram_set("pci/1/1/maxp5ga2", "104,104,104,104");
2565 nvram_set("pci/1/1/mcsbw205glpo", "0xBB975311");
2566 nvram_set("pci/1/1/mcsbw405glpo", "0xBB975311");
2567 nvram_set("pci/1/1/mcsbw805glpo", "0xBB975311");
2568 nvram_set("pci/1/1/mcsbw205gmpo", "0xBB975311");
2569 nvram_set("pci/1/1/mcsbw405gmpo", "0xBB975311");
2570 nvram_set("pci/1/1/mcsbw805gmpo", "0xBB975311");
2571 nvram_set("pci/1/1/mcsbw205ghpo", "0xBB975311");
2572 nvram_set("pci/1/1/mcsbw405ghpo", "0xBB975311");
2573 nvram_set("pci/1/1/mcsbw805ghpo", "0xBB975311");
2575 //force US country for 5G eth1, modified by bwq518
2576 nvram_set("pci/1/1/ccode", "US");
2577 nvram_set("wl1_country_code", "US");
2578 nvram_set("regulation_domain_5G", "US");
2580 break;
2581 case MODEL_EA6500V1:
2582 mfr = "Linksys";
2583 name = "EA6500v1";
2584 features = SUP_SES | SUP_80211N | SUP_1000ET | SUP_80211AC;
2585 #ifdef TCONFIG_USB
2586 nvram_set("usb_uhci", "-1");
2587 #endif
2588 if (!nvram_match("t_fix1", (char *)name)) {
2589 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
2590 nvram_set("wan_ifnameX", "vlan2");
2591 nvram_set("wl_ifnames", "eth1 eth2");
2592 nvram_set("wl_ifname", "eth1");
2593 nvram_set("wl0_ifname", "eth1");
2594 nvram_set("wl1_ifname", "eth2");
2595 nvram_set("wl0_bw_cap","7");
2596 nvram_set("wl0_chanspec","36/80");
2597 nvram_set("wl1_bw_cap","3");
2598 nvram_set("wl1_chanspec","1l");
2599 nvram_set("blink_5g_interface","eth1");
2601 // fix ssid according to 5G(eth1) and 2.4G(eth2)
2602 nvram_set("wl_ssid","Tomato50");
2603 nvram_set("wl0_ssid","Tomato50");
2604 nvram_set("wl1_ssid","Tomato24");
2606 //force US country for 5G eth1, modified by bwq518
2607 nvram_set("pci/1/1/ccode", nvram_safe_get("ccode"));
2608 nvram_set("regulation_domain_5G", nvram_safe_get("ccode"));
2610 break;
2611 #endif // CONFIG_BCMWL6
2612 case MODEL_WNR3500L:
2613 mfr = "Netgear";
2614 name = "WNR3500L/U/v2";
2615 features = SUP_SES | SUP_AOSS_LED | SUP_80211N | SUP_1000ET;
2616 if (!nvram_match("t_fix1", (char *)name)) {
2617 nvram_set("sromrev", "3");
2618 nvram_set("lan_ifnames", "vlan1 eth1");
2619 nvram_set("wan_ifnameX", "vlan2");
2620 nvram_set("wl_ifname", "eth1");
2622 break;
2623 case MODEL_WNR3500LV2:
2624 mfr = "Netgear";
2625 name = "WNR3500L v2";
2626 features = SUP_SES | SUP_AOSS_LED | SUP_80211N | SUP_1000ET;
2627 if (!nvram_match("t_fix1", (char *)name)) {
2628 nvram_set("lan_ifnames", "vlan1 eth1");
2629 nvram_set("wan_ifnameX", "vlan2");
2630 nvram_set("wl_ifname", "eth1");
2632 break;
2633 case MODEL_WNR2000v2:
2634 mfr = "Netgear";
2635 name = "WNR2000 v2";
2636 features = SUP_SES | SUP_AOSS_LED | SUP_80211N;
2637 if (!nvram_match("t_fix1", (char *)name)) {
2638 nvram_set("lan_ifnames", "vlan0 eth1");
2639 nvram_set("wan_ifnameX", "vlan1");
2640 nvram_set("wl_ifname", "eth1");
2642 break;
2643 case MODEL_F7D3301:
2644 case MODEL_F7D3302:
2645 case MODEL_F7D4301:
2646 case MODEL_F7D4302:
2647 case MODEL_F5D8235v3:
2648 mfr = "Belkin";
2649 features = SUP_SES | SUP_80211N;
2650 switch (model) {
2651 case MODEL_F7D3301:
2652 name = "Share Max N300 (F7D3301/F7D7301) v1";
2653 break;
2654 case MODEL_F7D3302:
2655 name = "Share N300 (F7D3302/F7D7302) v1";
2656 break;
2657 case MODEL_F7D4301:
2658 name = "Play Max / N600 HD (F7D4301/F7D8301) v1";
2659 break;
2660 case MODEL_F7D4302:
2661 name = "Play N600 (F7D4302/F7D8302) v1";
2662 break;
2663 case MODEL_F5D8235v3:
2664 name = "N F5D8235-4 v3";
2665 break;
2667 #ifdef TCONFIG_USB
2668 nvram_set("usb_uhci", "-1");
2669 #endif
2670 if (!nvram_match("t_fix1", (char *)name)) {
2671 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
2672 nvram_set("wan_ifnameX", "vlan2");
2673 nvram_set("landevs", "vlan1 wl0 wl1");
2674 nvram_set("wandevs", "vlan2");
2676 break;
2677 case MODEL_E900:
2678 case MODEL_E1500:
2679 mfr = "Linksys";
2680 name = nvram_safe_get("boot_hw_model");
2681 ver = nvram_safe_get("boot_hw_ver");
2682 features = SUP_SES | SUP_80211N;
2683 if (!nvram_match("t_fix1", (char *)name)) {
2684 nvram_set("lan_ifnames", "vlan1 eth1");
2685 nvram_set("wan_ifnameX", "vlan2");
2686 nvram_set("wl_ifname", "eth1");
2688 break;
2689 case MODEL_E1550:
2690 mfr = "Linksys";
2691 name = nvram_safe_get("boot_hw_model");
2692 ver = nvram_safe_get("boot_hw_ver");
2693 features = SUP_SES | SUP_80211N;
2694 #ifdef TCONFIG_USB
2695 nvram_set("usb_uhci", "-1");
2696 #endif
2697 if (!nvram_match("t_fix1", (char *)name)) {
2698 nvram_set("lan_ifnames", "vlan1 eth1");
2699 nvram_set("wan_ifnameX", "vlan2");
2700 nvram_set("wl_ifname", "eth1");
2702 break;
2703 case MODEL_E2500:
2704 mfr = "Linksys";
2705 name = nvram_safe_get("boot_hw_model");
2706 ver = nvram_safe_get("boot_hw_ver");
2707 features = SUP_SES | SUP_80211N;
2708 #if defined(LINUX26) && defined(TCONFIG_USBAP)
2709 if (nvram_get_int("usb_storage") == 1) nvram_set("usb_storage", "-1");
2710 #endif
2711 if (!nvram_match("t_fix1", (char *)name)) {
2712 #ifdef TCONFIG_USBAP
2713 nvram_set("wl1_hwaddr", nvram_safe_get("0:macaddr"));
2714 nvram_set("ehciirqt", "3");
2715 nvram_set("qtdc_pid", "48407");
2716 nvram_set("qtdc_vid", "2652");
2717 nvram_set("qtdc0_ep", "4");
2718 nvram_set("qtdc0_sz", "0");
2719 nvram_set("qtdc1_ep", "18");
2720 nvram_set("qtdc1_sz", "10");
2721 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
2722 nvram_set("landevs", "vlan1 wl0 wl1");
2723 nvram_set("wl0_ifname", "eth1");
2724 nvram_set("wl1_ifname", "eth2");
2725 #else
2726 nvram_set("lan_ifnames", "vlan1 eth1");
2727 nvram_set("landevs", "vlan1 wl0");
2728 #endif
2729 nvram_set("wan_ifnameX", "vlan2");
2730 nvram_set("wl_ifname", "eth1");
2733 break;
2734 case MODEL_E3200:
2735 mfr = "Linksys";
2736 name = nvram_safe_get("boot_hw_model");
2737 ver = nvram_safe_get("boot_hw_ver");
2738 features = SUP_SES | SUP_80211N | SUP_1000ET;
2739 #ifdef TCONFIG_USB
2740 nvram_set("usb_uhci", "-1");
2741 #endif
2742 if (!nvram_match("t_fix1", (char *)name)) {
2743 #ifdef TCONFIG_USBAP
2744 nvram_set("wl1_hwaddr", nvram_safe_get("usb/0xBD17/macaddr"));
2745 nvram_set("ehciirqt", "3");
2746 nvram_set("qtdc_pid", "48407");
2747 nvram_set("qtdc_vid", "2652");
2748 nvram_set("qtdc0_ep", "4");
2749 nvram_set("qtdc0_sz", "0");
2750 nvram_set("qtdc1_ep", "18");
2751 nvram_set("qtdc1_sz", "10");
2752 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
2753 nvram_set("landevs", "vlan1 wl0 wl1");
2754 nvram_set("wl0_ifname", "eth1");
2755 nvram_set("wl1_ifname", "eth2");
2756 #else
2757 nvram_set("lan_ifnames", "vlan1 eth1");
2758 nvram_set("landevs", "vlan1 wl0");
2759 #endif
2760 nvram_set("wl_ifname", "eth1");
2761 nvram_set("wan_ifnameX", "vlan2");
2763 break;
2764 case MODEL_E1000v2:
2765 case MODEL_WRT160Nv3:
2766 // same as M10, M20, WRT310Nv2, E1000v1
2767 mfr = "Linksys";
2768 name = nvram_safe_get("boot_hw_model");
2769 ver = nvram_safe_get("boot_hw_ver");
2770 if (nvram_match("boot_hw_model", "E100")){
2771 name = "E1000";
2773 if (nvram_match("boot_hw_model", "M10") || nvram_match("boot_hw_model", "M20")){
2774 mfr = "Cisco";
2776 features = SUP_SES | SUP_80211N | SUP_WHAM_LED;
2777 if (!nvram_match("t_fix1", (char *)name)) {
2778 nvram_set("lan_ifnames", "vlan1 eth1");
2779 nvram_set("wan_ifnameX", "vlan2");
2780 nvram_set("wl_ifname", "eth1");
2782 break;
2783 case MODEL_WRT320N:
2784 mfr = "Linksys";
2785 name = nvram_match("boardrev", "0x1307") ? "E2000" : "WRT320N";
2786 features = SUP_SES | SUP_80211N | SUP_WHAM_LED | SUP_1000ET;
2787 if (!nvram_match("t_fix1", (char *)name)) {
2788 nvram_set("lan_ifnames", "vlan1 eth1");
2789 nvram_set("wan_ifnameX", "vlan2");
2790 nvram_set("wl_ifname", "eth1");
2792 break;
2793 case MODEL_WRT610Nv2:
2794 mfr = "Linksys";
2795 name = nvram_match("boot_hw_model", "E300") ? "E3000" : "WRT610N v2";
2796 features = SUP_SES | SUP_80211N | SUP_WHAM_LED | SUP_1000ET;
2797 #ifdef TCONFIG_USB
2798 nvram_set("usb_uhci", "-1");
2799 #endif
2800 if (!nvram_match("t_fix1", (char *)name)) {
2801 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
2802 nvram_set("wan_ifnameX", "vlan2");
2803 nvram_set("wl_ifname", "eth1");
2805 break;
2806 case MODEL_E4200:
2807 mfr = "Linksys";
2808 name = "E4200 v1";
2809 features = SUP_SES | SUP_80211N | SUP_1000ET;
2810 #ifdef TCONFIG_USB
2811 nvram_set("usb_uhci", "-1");
2812 #endif
2813 if (!nvram_match("t_fix1", (char *)name)) {
2814 nvram_set("lan_ifnames", "vlan1 eth1 eth2");
2815 nvram_set("wan_ifnameX", "vlan2");
2816 nvram_set("wl_ifname", "eth1");
2818 break;
2819 #endif // CONFIG_BCMWL5
2821 case MODEL_WL330GE:
2822 mfr = "Asus";
2823 name = "WL-330gE";
2824 // The 330gE has only one wired port which can act either as WAN or LAN.
2825 // Failsafe mode is to have it start as a LAN port so you can get an IP
2826 // address via DHCP and access the router config page.
2827 if (!nvram_match("t_fix1", (char *)name)) {
2828 nvram_set("wl_ifname", "eth1");
2829 nvram_set("lan_ifnames", "eth1");
2830 nvram_set("wan_ifnameX", "eth0");
2831 nvram_set("wan_islan", "1");
2832 nvram_set("wan_proto", "disabled");
2834 break;
2835 case MODEL_WL500GPv2:
2836 mfr = "Asus";
2837 name = "WL-500gP v2";
2838 features = SUP_SES;
2839 #ifdef TCONFIG_USB
2840 nvram_set("usb_uhci", "-1");
2841 #endif
2842 break;
2843 case MODEL_WL520GU:
2844 mfr = "Asus";
2845 name = "WL-520GU";
2846 features = SUP_SES;
2847 #ifdef TCONFIG_USB
2848 nvram_set("usb_uhci", "-1");
2849 #endif
2850 break;
2851 case MODEL_WL500GD:
2852 mfr = "Asus";
2853 name = "WL-500g Deluxe";
2854 // features = SUP_SES;
2855 #ifdef TCONFIG_USB
2856 nvram_set("usb_ohci", "-1");
2857 #endif
2858 if (!nvram_match("t_fix1", (char *)name)) {
2859 nvram_set("wl_ifname", "eth1");
2860 nvram_set("lan_ifnames", "vlan0 eth1");
2861 nvram_set("wan_ifnameX", "vlan1");
2862 nvram_unset("wl0gpio0");
2864 break;
2865 case MODEL_DIR320:
2866 mfr = "D-Link";
2867 name = "DIR-320";
2868 features = SUP_SES;
2869 if (!nvram_match("t_fix1", (char *)name)) {
2870 nvram_set("wan_ifnameX", "vlan1");
2871 nvram_set("wl_ifname", "eth1");
2873 break;
2874 case MODEL_H618B:
2875 mfr = "ZTE";
2876 name = "ZXV10 H618B";
2877 features = SUP_SES | SUP_AOSS_LED;
2878 #ifdef TCONFIG_USB
2879 nvram_set("usb_uhci", "-1");
2880 #endif
2881 if (!nvram_match("t_fix1", (char *)name)) {
2882 nvram_set("lan_ifnames", "vlan0 eth1");
2883 nvram_set("wan_ifname", "vlan1");
2884 nvram_set("wan_ifnames", "vlan1");
2885 nvram_set("wan_ifnameX", "vlan1");
2886 nvram_set("wl_ifname", "eth1");
2888 break;
2889 case MODEL_WL1600GL:
2890 mfr = "Ovislink";
2891 name = "WL1600GL";
2892 features = SUP_SES;
2893 break;
2894 #endif // WL_BSS_INFO_VERSION >= 108
2895 case MODEL_WZRG300N:
2896 mfr = "Buffalo";
2897 name = "WZR-G300N";
2898 features = SUP_SES | SUP_AOSS_LED | SUP_BRAU | SUP_80211N;
2899 break;
2900 case MODEL_WRT160Nv1:
2901 case MODEL_WRT300N:
2902 mfr = "Linksys";
2903 name = (model == MODEL_WRT300N) ? "WRT300N v1" : "WRT160N v1";
2904 features = SUP_SES | SUP_80211N;
2905 if (!nvram_match("t_fix1", (char *)name)) {
2906 nvram_set("wan_ifnameX", "eth1");
2907 nvram_set("lan_ifnames", "eth0 eth2");
2909 break;
2910 case MODEL_WRT310Nv1:
2911 mfr = "Linksys";
2912 name = "WRT310N v1";
2913 features = SUP_SES | SUP_80211N | SUP_WHAM_LED | SUP_1000ET;
2914 if (!nvram_match("t_fix1", (char *)name)) {
2915 nvram_set("lan_ifnames", "vlan1 eth1");
2916 nvram_set("wan_ifnameX", "vlan2");
2917 nvram_set("wl_ifname", "eth1");
2919 break;
2922 if (name) {
2923 nvram_set("t_fix1", name);
2924 if (ver && strcmp(ver, "")) {
2925 sprintf(s, "%s %s v%s", mfr, name, ver);
2926 } else {
2927 sprintf(s, "%s %s", mfr, name);
2930 else {
2931 snprintf(s, sizeof(s), "%s %d/%s/%s/%s/%s", mfr, check_hw_type(),
2932 nvram_safe_get("boardtype"), nvram_safe_get("boardnum"), nvram_safe_get("boardrev"), nvram_safe_get("boardflags"));
2933 s[64] = 0;
2935 nvram_set("t_model_name", s);
2937 nvram_set("pa0maxpwr", "400"); // allow Tx power up tp 400 mW, needed for ND only
2939 sprintf(s, "0x%lX", features);
2940 nvram_set("t_features", s);
2943 note: set wan_ifnameX if wan_ifname needs to be overriden
2946 if (nvram_is_empty("wan_ifnameX")) {
2947 #if 1
2948 nvram_set("wan_ifnameX", ((strtoul(nvram_safe_get("boardflags"), NULL, 0) & BFL_ENETVLAN) ||
2949 (check_hw_type() == HW_BCM4712)) ? "vlan1" : "eth1");
2950 #else
2951 p = nvram_safe_get("wan_ifname");
2952 if ((*p == 0) || (nvram_match("wl_ifname", p))) {
2953 p = ((strtoul(nvram_safe_get("boardflags"), NULL, 0) & BFL_ENETVLAN) ||
2954 (check_hw_type() == HW_BCM4712)) ? "vlan1" : "eth1";
2956 nvram_set("wan_ifnameX", p);
2957 #endif
2960 //!!TB - do not force country code here to allow nvram override
2961 //nvram_set("wl_country", "JP");
2962 //nvram_set("wl_country_code", "JP");
2963 nvram_set("wan_get_dns", "");
2964 nvram_set("wan_get_domain", "");
2965 nvram_set("ppp_get_ip", "");
2966 nvram_set("action_service", "");
2967 nvram_set("jffs2_format", "0");
2968 nvram_set("rrules_radio", "-1");
2969 nvram_unset("https_crt_gen");
2970 nvram_unset("log_wmclear");
2971 #ifdef TCONFIG_IPV6
2972 nvram_set("ipv6_get_dns", "");
2973 #endif
2974 #ifdef TCONFIG_MEDIA_SERVER
2975 nvram_unset("ms_rescan");
2976 #endif
2977 if (nvram_get_int("http_id_gen") == 1) nvram_unset("http_id");
2979 nvram_unset("sch_rboot_last");
2980 nvram_unset("sch_rcon_last");
2981 nvram_unset("sch_c1_last");
2982 nvram_unset("sch_c2_last");
2983 nvram_unset("sch_c3_last");
2985 nvram_set("brau_state", "");
2986 if ((features & SUP_BRAU) == 0) nvram_set("script_brau", "");
2987 if ((features & SUP_SES) == 0) nvram_set("sesx_script", "");
2989 if ((features & SUP_1000ET) == 0) nvram_set("jumbo_frame_enable", "0");
2991 // compatibility with old versions
2992 if (nvram_match("wl_net_mode", "disabled")) {
2993 nvram_set("wl_radio", "0");
2994 nvram_set("wl_net_mode", "mixed");
2997 return 0;
3000 #ifndef TCONFIG_BCMARM
3001 /* Get the special files from nvram and copy them to disc.
3002 * These were files saved with "nvram setfile2nvram <filename>".
3003 * Better hope that they were saved with full pathname.
3005 static void load_files_from_nvram(void)
3007 char *name, *cp;
3008 int ar_loaded = 0;
3009 char buf[NVRAM_SPACE];
3011 if (nvram_getall(buf, sizeof(buf)) != 0)
3012 return;
3014 for (name = buf; *name; name += strlen(name) + 1) {
3015 if (strncmp(name, "FILE:", 5) == 0) { /* This special name marks a file to get. */
3016 if ((cp = strchr(name, '=')) == NULL)
3017 continue;
3018 *cp = 0;
3019 syslog(LOG_INFO, "Loading file '%s' from nvram", name + 5);
3020 nvram_nvram2file(name, name + 5);
3021 if (memcmp(".autorun", cp - 8, 9) == 0)
3022 ++ar_loaded;
3025 /* Start any autorun files that may have been loaded into one of the standard places. */
3026 if (ar_loaded != 0)
3027 run_nvscript(".autorun", NULL, 3);
3029 #endif
3031 #if defined(LINUX26) && defined(TCONFIG_USB)
3032 static inline void tune_min_free_kbytes(void)
3034 struct sysinfo info;
3036 memset(&info, 0, sizeof(struct sysinfo));
3037 sysinfo(&info);
3038 if (info.totalram >= 55 * 1024 * 1024) {
3039 // If we have 64MB+ RAM, tune min_free_kbytes
3040 // to reduce page allocation failure errors.
3041 f_write_string("/proc/sys/vm/min_free_kbytes", "8192", 0, 0);
3044 #endif
3046 static void sysinit(void)
3048 static int noconsole = 0;
3049 static const time_t tm = 0;
3050 int hardware;
3051 int i;
3052 DIR *d;
3053 struct dirent *de;
3054 char s[256];
3055 char t[256];
3057 mount("proc", "/proc", "proc", 0, NULL);
3058 mount("tmpfs", "/tmp", "tmpfs", 0, NULL);
3060 #ifdef LINUX26
3061 mount("devfs", "/dev", "tmpfs", MS_MGC_VAL | MS_NOATIME, NULL);
3062 mknod("/dev/null", S_IFCHR | 0666, makedev(1, 3));
3063 mknod("/dev/console", S_IFCHR | 0600, makedev(5, 1));
3064 mount("sysfs", "/sys", "sysfs", MS_MGC_VAL, NULL);
3065 mkdir("/dev/shm", 0777);
3066 mkdir("/dev/pts", 0777);
3067 mknod("/dev/pts/ptmx", S_IRWXU|S_IFCHR, makedev(5, 2));
3068 mknod("/dev/pts/0", S_IRWXU|S_IFCHR, makedev(136, 0));
3069 mknod("/dev/pts/1", S_IRWXU|S_IFCHR, makedev(136, 1));
3070 mount("devpts", "/dev/pts", "devpts", MS_MGC_VAL, NULL);
3071 #endif
3073 if (console_init()) noconsole = 1;
3075 stime(&tm);
3077 static const char *mkd[] = {
3078 "/tmp/etc", "/tmp/var", "/tmp/home", "/tmp/mnt",
3079 "/tmp/splashd", //!!Victek
3080 "/tmp/share", "/var/webmon", // !!TB
3081 "/var/log", "/var/run", "/var/tmp", "/var/lib", "/var/lib/misc",
3082 "/var/spool", "/var/spool/cron", "/var/spool/cron/crontabs",
3083 "/tmp/var/wwwext", "/tmp/var/wwwext/cgi-bin", // !!TB - CGI support
3084 NULL
3086 umask(0);
3087 for (i = 0; mkd[i]; ++i) {
3088 mkdir(mkd[i], 0755);
3090 mkdir("/var/lock", 0777);
3091 mkdir("/var/tmp/dhcp", 0777);
3092 mkdir("/home/root", 0700);
3093 chmod("/tmp", 0777);
3094 f_write("/etc/hosts", NULL, 0, 0, 0644); // blank
3095 f_write("/etc/fstab", NULL, 0, 0, 0644); // !!TB - blank
3096 simple_unlock("cron");
3097 simple_unlock("firewall");
3098 simple_unlock("restrictions");
3099 umask(022);
3101 if ((d = opendir("/rom/etc")) != NULL) {
3102 while ((de = readdir(d)) != NULL) {
3103 if (de->d_name[0] == '.') continue;
3104 snprintf(s, sizeof(s), "%s/%s", "/rom/etc", de->d_name);
3105 snprintf(t, sizeof(t), "%s/%s", "/etc", de->d_name);
3106 symlink(s, t);
3108 closedir(d);
3110 symlink("/proc/mounts", "/etc/mtab");
3112 #ifdef TCONFIG_SAMBASRV
3113 if ((d = opendir("/usr/codepages")) != NULL) {
3114 while ((de = readdir(d)) != NULL) {
3115 if (de->d_name[0] == '.') continue;
3116 snprintf(s, sizeof(s), "/usr/codepages/%s", de->d_name);
3117 snprintf(t, sizeof(t), "/usr/share/%s", de->d_name);
3118 symlink(s, t);
3120 closedir(d);
3122 #endif
3124 #ifdef LINUX26
3125 eval("hotplug2", "--coldplug");
3126 start_hotplug2();
3128 static const char *dn[] = {
3129 "null", "zero", "random", "urandom", "full", "ptmx", "nvram",
3130 NULL
3132 for (i = 0; dn[i]; ++i) {
3133 snprintf(s, sizeof(s), "/dev/%s", dn[i]);
3134 chmod(s, 0666);
3136 chmod("/dev/gpio", 0660);
3137 #endif
3139 set_action(ACT_IDLE);
3141 for (i = 0; defenv[i]; ++i) {
3142 putenv(defenv[i]);
3145 if (!noconsole) {
3146 printf("\n\nHit ENTER for console...\n\n");
3147 run_shell(1, 0);
3150 check_bootnv();
3152 #ifdef TCONFIG_IPV6
3153 // disable IPv6 by default on all interfaces
3154 f_write_string("/proc/sys/net/ipv6/conf/default/disable_ipv6", "1", 0, 0);
3155 #endif
3157 for (i = 0; i < sizeof(fatalsigs) / sizeof(fatalsigs[0]); i++) {
3158 signal(fatalsigs[i], handle_fatalsigs);
3160 signal(SIGCHLD, handle_reap);
3162 #ifdef CONFIG_BCMWL5
3163 // ctf must be loaded prior to any other modules
3164 if (nvram_invmatch("ctf_disable", "1"))
3165 modprobe("ctf");
3166 #endif
3168 #ifdef TCONFIG_EMF
3169 modprobe("emf");
3170 modprobe("igs");
3171 #endif
3173 switch (hardware = check_hw_type()) {
3174 case HW_BCM4785:
3175 modprobe("bcm57xx");
3176 break;
3177 default:
3178 modprobe("et");
3179 break;
3182 //load after initnvram as Broadcom Wl require pci/x/1/devid and pci/x/1/macaddr nvram to be set first for DIR-865L
3183 //else 5G interface will not start!
3184 //must be tested on other routers to determine if loading nvram 1st will cause problems!
3185 //load_wl();
3187 //config_loopback();
3189 // eval("nvram", "defaults", "--initcheck");
3190 restore_defaults(); // restore default if necessary
3191 init_nvram();
3193 // set the packet size
3194 if (nvram_get_int("jumbo_frame_enable")) {
3195 // only set the size here - 'enable' flag is set by the driver
3196 // eval("et", "robowr", "0x40", "0x01", "0x1F"); // (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4)
3197 eval("et", "robowr", "0x40", "0x05", nvram_safe_get("jumbo_frame_size"));
3200 //load after init_nvram
3201 load_wl();
3203 config_loopback();
3205 klogctl(8, NULL, nvram_get_int("console_loglevel"));
3207 #if defined(LINUX26) && defined(TCONFIG_USB)
3208 tune_min_free_kbytes();
3209 #endif
3210 setup_conntrack();
3211 set_host_domain_name();
3213 set_tz();
3215 eval("buttons");
3217 #ifdef CONFIG_BCMWL6
3218 eval("blink_5g");
3219 #endif
3221 if (!noconsole) xstart("console");
3223 i = nvram_get_int("sesx_led");
3224 led(LED_AMBER, (i & 1) != 0);
3225 led(LED_WHITE, (i & 2) != 0);
3226 led(LED_AOSS, (i & 4) != 0);
3227 led(LED_BRIDGE, (i & 8) != 0);
3228 led(LED_DIAG, 1);
3231 int init_main(int argc, char *argv[])
3233 int state, i;
3234 sigset_t sigset;
3236 // AB - failsafe?
3237 nvram_unset("debug_rc_svc");
3239 sysinit();
3241 sigemptyset(&sigset);
3242 for (i = 0; i < sizeof(initsigs) / sizeof(initsigs[0]); i++) {
3243 sigaddset(&sigset, initsigs[i]);
3245 sigprocmask(SIG_BLOCK, &sigset, NULL);
3247 #if defined(DEBUG_NOISY)
3248 nvram_set("debug_logeval", "1");
3249 nvram_set("debug_cprintf", "1");
3250 nvram_set("debug_cprintf_file", "1");
3251 nvram_set("debug_ddns", "1");
3252 #endif
3254 start_jffs2();
3256 state = SIGUSR2; /* START */
3258 for (;;) {
3259 TRACE_PT("main loop signal/state=%d\n", state);
3261 switch (state) {
3262 case SIGUSR1: /* USER1: service handler */
3263 exec_service();
3264 break;
3266 case SIGHUP: /* RESTART */
3267 case SIGINT: /* STOP */
3268 case SIGQUIT: /* HALT */
3269 case SIGTERM: /* REBOOT */
3270 led(LED_DIAG, 1);
3271 unlink("/var/notice/sysup");
3273 if( nvram_match( "webmon_bkp", "1" ) )
3274 xstart( "/usr/sbin/webmon_bkp", "hourly" ); // make a copy before halt/reboot router
3276 run_nvscript("script_shut", NULL, 10);
3278 stop_services();
3279 stop_wan();
3280 stop_lan();
3281 stop_vlan();
3282 stop_syslog();
3284 if ((state == SIGTERM /* REBOOT */) ||
3285 (state == SIGQUIT /* HALT */)) {
3286 remove_storage_main(1);
3287 stop_usb();
3289 shutdn(state == SIGTERM /* REBOOT */);
3290 exit(0);
3292 if (state == SIGINT /* STOP */) {
3293 break;
3296 // SIGHUP (RESTART) falls through
3298 case SIGUSR2: /* START */
3299 SET_LED(RELEASE_WAN_CONTROL);
3300 start_syslog();
3302 #ifndef TCONFIG_BCMARM
3303 load_files_from_nvram();
3304 #endif
3306 int fd = -1;
3307 fd = file_lock("usb"); // hold off automount processing
3308 start_usb();
3310 xstart("/usr/sbin/mymotd", "init");
3311 run_nvscript("script_init", NULL, 2);
3313 file_unlock(fd); // allow to process usb hotplug events
3314 #ifdef TCONFIG_USB
3316 * On RESTART some partitions can stay mounted if they are busy at the moment.
3317 * In that case USB drivers won't unload, and hotplug won't kick off again to
3318 * remount those drives that actually got unmounted. Make sure to remount ALL
3319 * partitions here by simulating hotplug event.
3321 if (state == SIGHUP /* RESTART */)
3322 add_remove_usbhost("-1", 1);
3323 #endif
3325 create_passwd();
3326 start_vlan();
3327 start_lan();
3328 start_arpbind();
3329 start_wan(BOOT);
3330 start_services();
3331 start_wl();
3333 #ifdef CONFIG_BCMWL5
3334 if (wds_enable()) {
3335 /* Restart NAS one more time - for some reason without
3336 * this the new driver doesn't always bring WDS up.
3338 stop_nas();
3339 start_nas();
3341 #endif
3343 syslog(LOG_INFO, "%s: Tomato %s", nvram_safe_get("t_model_name"), tomato_version);
3345 led(LED_DIAG, 0);
3346 notice_set("sysup", "");
3347 break;
3350 chld_reap(0); /* Periodically reap zombies. */
3351 check_services();
3352 sigwait(&sigset, &state);
3355 return 0;
3358 int reboothalt_main(int argc, char *argv[])
3360 int reboot = (strstr(argv[0], "reboot") != NULL);
3361 puts(reboot ? "Rebooting..." : "Shutting down...");
3362 fflush(stdout);
3363 sleep(1);
3364 kill(1, reboot ? SIGTERM : SIGQUIT);
3366 /* In the case we're hung, we'll get stuck and never actually reboot.
3367 * The only way out is to pull power.
3368 * So after 'reset_wait' seconds (default: 20), forcibly crash & restart.
3370 if (fork() == 0) {
3371 int wait = nvram_get_int("reset_wait") ? : 20;
3372 if ((wait < 10) || (wait > 120)) wait = 10;
3374 f_write("/proc/sysrq-trigger", "s", 1, 0 , 0); /* sync disks */
3375 sleep(wait);
3376 puts("Still running... Doing machine reset.");
3377 fflush(stdout);
3378 f_write("/proc/sysrq-trigger", "s", 1, 0 , 0); /* sync disks */
3379 sleep(1);
3380 f_write("/proc/sysrq-trigger", "b", 1, 0 , 0); /* machine reset */
3383 return 0;