source: src/router/services/sysinit/sysinit-broadcom.c @ 18836

Last change on this file since 18836 was 18836, checked in by eko, 14 months ago

typo

File size: 62.9 KB
Line 
1/*
2 * sysinit-broadcom.c
3 *
4 * Copyright (C) 2006 Sebastian Gottschall <gottschall@dd-wrt.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 *
20 * $Id:
21 */
22
23#include <stdio.h>
24#include <stdlib.h>
25#include <limits.h>
26#include <time.h>
27#include <unistd.h>
28#include <errno.h>
29#include <syslog.h>
30#include <signal.h>
31#include <string.h>
32#include <termios.h>
33#include <sys/klog.h>
34#include <sys/types.h>
35#include <sys/mount.h>
36#include <sys/reboot.h>
37#include <sys/stat.h>
38#include <sys/sysmacros.h>
39#include <sys/time.h>
40#include <sys/utsname.h>
41#include <sys/wait.h>
42#include <linux/if_ether.h>
43#include <linux/sockios.h>
44#include <net/if.h>
45
46#include <arpa/inet.h>
47#include <sys/socket.h>
48#include <linux/sockios.h>
49
50#include <bcmnvram.h>
51#include <bcmdevs.h>
52#include <shutils.h>
53#include <utils.h>
54#include <wlutils.h>
55#include <cymac.h>
56#include <services.h>
57#include "devices/wireless.c"
58
59#define sys_restart() eval("event","3","1","1")
60#define sys_reboot() eval("sync"); eval("event","3","1","15")
61
62static void check_brcm_cpu_type(void)
63{
64        FILE *fcpu;
65        char cpu_type[20];
66        char type2[30];
67
68        fcpu = fopen("/proc/cpuinfo", "r");
69
70        if (fcpu == NULL)
71                cprintf("Open /proc/cpuinfo fail...0\n");
72        else {
73                char buf[500];
74
75                fgets(buf, 500, fcpu);
76                fscanf(fcpu, "%s %s %s %s %s", buf, buf, buf, cpu_type, type2);
77                if (!strcmp(type2, "BCM4704")) {
78                        nvram_set("cpu_type", cpu_type);
79                        fclose(fcpu);
80                        return;
81                }
82                if (!strcmp(type2, "BCM4712")) {
83                        nvram_set("cpu_type", cpu_type);
84                        fclose(fcpu);
85                        return;
86                }
87                if (!strcmp(type2, "BCM4702")) {
88                        nvram_set("cpu_type", cpu_type);
89                        fclose(fcpu);
90                        return;
91                }
92                if (!strcmp(type2, "BCM3302")) {
93                        nvram_set("cpu_type", cpu_type);
94                        fclose(fcpu);
95                        return;
96                }
97                fgets(buf, 500, fcpu);
98                fscanf(fcpu, "%s %s %s %s %s", buf, buf, buf, cpu_type, type2);
99                // fprintf(stderr, "cpu_type : %s\n", cpu_type);
100                fclose(fcpu);
101                if (!strcmp(cpu_type, "BCM4710")
102                    || !strcmp(cpu_type, "BCM4702")) {
103                        cprintf("We got BCM4702 board...\n");
104                        nvram_set("cpu_type", cpu_type);
105                } else if (!strcmp(cpu_type, "BCM3302")
106                           || !strcmp(cpu_type, "BCM4712")) {
107                        cprintf("We got BCM4712 board...\n");
108                        nvram_set("cpu_type", cpu_type);
109                } else {
110                        cprintf("We got unknown board...\n");
111                        nvram_set("cpu_type", cpu_type);
112                }
113        }
114
115}
116
117static void loadWlModule(void)  // set wled params, get boardflags,
118                                        // set afterburner bit, load wl,
119                                        // unset afterburner bit
120{
121
122        int brand = getRouterBrand();
123        char macbuf[32];
124        char eaddr[32];
125
126#ifndef HAVE_BUFFALO
127        nvram_set("pa0maxpwr", "251");  // force pa0maxpwr to be 251
128#endif
129
130        if (check_hw_type() == BCM4702_CHIP)
131                nvram_unset("wl0_abenable");
132        else {
133                nvram_set("wl0_abenable", "1");
134                nvram_set("wl1_abenable", "1");
135        }
136
137        switch (brand) {
138        case ROUTER_LINKSYS_WRH54G:
139                nvram_set("wl0gpio0", "135");
140                break;
141        case ROUTER_BUFFALO_WZRRSG54:
142                nvram_unset("wl0_abenable");
143                nvram_unset("wl1_abenable");
144                break;
145        case ROUTER_ASUS_WL550GE:
146                nvram_set("wl0gpio1", "0");
147                nvram_set("wl0gpio2", "0");
148                break;
149        case ROUTER_ASUS_WL500W:
150        case ROUTER_WRT54G:
151        case ROUTER_WRT54G_V8:
152        case ROUTER_MOTOROLA:
153        case ROUTER_NETGEAR_WG602_V3:
154        case ROUTER_RT480W:
155        case ROUTER_USR_5465:
156        case ROUTER_ASUS_RTN10:
157                nvram_set("wl0gpio0", "136");
158                break;
159        case ROUTER_ASUS_RTN10U:
160                nvram_set("ledbh5", "7");
161                break;
162        case ROUTER_WAP54G_V3:
163                nvram_set("wl0gpio0", "0");
164                nvram_set("wl0gpio2", "255");
165                nvram_set("wl0gpio3", "255");
166                nvram_set("wl0gpio5", "136");
167                break;
168        case ROUTER_ASUS_WL520GUGC:
169                nvram_set("wl0gpio0", "0");
170                nvram_set("wl0gpio1", "136");
171                nvram_set("wl0gpio2", "0");
172                nvram_set("wl0gpio3", "0");
173                break;
174        case ROUTER_LINKSYS_WTR54GS:
175        case ROUTER_WAP54G_V1:
176                nvram_set("wl0gpio0", "136");
177                nvram_set("wl0gpio1", "0");
178                nvram_set("wl0gpio2", "0");
179                nvram_set("wl0gpio3", "0");
180                break;
181        case ROUTER_BUFFALO_WBR54G:
182        case ROUTER_BUFFALO_WBR2G54S:
183        case ROUTER_WRT150N:
184        case ROUTER_WRT160N:
185        case ROUTER_WRT300N:
186        case ROUTER_WRT300NV11:
187        case ROUTER_WRT310N:
188        case ROUTER_WRT350N:
189        case ROUTER_WRT600N:
190        case ROUTER_USR_5461:
191                nvram_set("wl0gpio0", "8");
192                break;
193        case ROUTER_NETGEAR_WG602_V4:
194                nvram_set("wl0gpio0", "8");
195                nvram_set("wl0gpio1", "0");
196                nvram_set("wl0gpio2", "0");
197                nvram_set("wl0gpio3", "0");
198                break;
199        case ROUTER_BUFFALO_WHRG54S:
200        case ROUTER_BUFFALO_WLI_TX4_G54HP:
201                nvram_set("wl0gpio2", "136");
202                break;
203        case ROUTER_BUFFALO_WLA2G54C:
204                nvram_set("wl0gpio0", "0");
205                nvram_set("wl0gpio5", "136");
206                break;
207        case ROUTER_ASUS_WL500GD:
208        case ROUTER_ASUS_WL500G_PRE:
209                nvram_unset("wl0gpio0");
210                break;
211        case ROUTER_BELKIN_F5D7230_V2000:
212                // case ROUTER_BELKIN_F5D7230_V3000:
213        case ROUTER_BELKIN_F5D7231:
214                nvram_set("wl0gpio3", "136");
215                break;
216        case ROUTER_NETGEAR_WGR614L:
217        case ROUTER_NETGEAR_WGR614V9:
218                nvram_set("wl0gpio5", "8");
219                break;
220        case ROUTER_BELKIN_F5D7231_V2000:
221                nvram_set("wl0gpio0", "2");
222                nvram_set("wl0gpio1", "0");
223                break;
224        case ROUTER_BUFFALO_WLAG54C:
225        case ROUTER_ASUS_WL700GE:
226                nvram_set("wl0gpio0", "135");
227                break;
228        case ROUTER_NETGEAR_WNR3500L:
229                nvram_set("ledbh0", "7");
230                break;
231        case ROUTER_WRT320N:
232                nvram_set("ledbh0", "136");
233                nvram_set("ledbh1", "11");
234                break;
235        case ROUTER_NETGEAR_WNR2000V2:
236                nvram_set("ledbh5", "8");
237                break;
238        }
239
240        int boardflags;
241
242        switch (brand) {
243        case ROUTER_WRT150N:
244        case ROUTER_WRT150NV11:
245        case ROUTER_WRT160N:
246        case ROUTER_WRT160NV3:
247        case ROUTER_ASUS_RTN16:
248        case ROUTER_BELKIN_F7D3301:
249        case ROUTER_BELKIN_F7D3302:
250        case ROUTER_BELKIN_F7D4301:
251        case ROUTER_BELKIN_F7D4302:
252        case ROUTER_BELKIN_F5D8235V3:
253        case ROUTER_WRT300N:
254        case ROUTER_WRT300NV11:
255        case ROUTER_WRT310N:
256        case ROUTER_WRT310NV2:
257        case ROUTER_WRT320N:
258        case ROUTER_WRT350N:
259        case ROUTER_BUFFALO_WZRG144NH:
260        case ROUTER_BUFFALO_WZRG300N:
261        case ROUTER_NETGEAR_WNR834B:
262        case ROUTER_NETGEAR_WNR834BV2:
263        case ROUTER_NETGEAR_WNDR3300:
264        case ROUTER_NETGEAR_WNDR3400:
265        case ROUTER_NETGEAR_WNR3500L:
266        case ROUTER_NETGEAR_WNR2000V2:
267        case ROUTER_ASUS_WL500W:
268        case ROUTER_WRT610NV2:
269        case ROUTER_DYNEX_DX_NRUTER:
270        case ROUTER_LINKSYS_E1000V2:
271        case ROUTER_LINKSYS_E2500:
272        case ROUTER_LINKSYS_E3200:
273        case ROUTER_LINKSYS_E4200:
274        case ROUTER_NETGEAR_WNDR4000:
275        case ROUTER_ASUS_RTN66:
276        case ROUTER_NETCORE_NW715P:
277
278                break;
279        case ROUTER_WRT600N:
280                fprintf(stderr, "fixing wrt600n\n");
281                wl_hwaddr("eth0", macbuf);
282                ether_etoa((uchar *) macbuf, eaddr);
283                nvram_set("wl0_hwaddr", eaddr);
284                MAC_SUB(eaddr);
285                if (!nvram_match("et0macaddr", eaddr)) {
286                        nvram_set("et0macaddr", eaddr);
287                        nvram_commit();
288//              eval("/sbin/reboot");
289//              exit( 0 );
290                }
291                eval("/sbin/ifconfig", "eth2", "hw", "ether", eaddr);
292                wl_hwaddr("eth1", macbuf);
293                ether_etoa((uchar *) macbuf, eaddr);
294                nvram_set("wl1_hwaddr", eaddr);
295                break;
296        case ROUTER_WRT610N:
297                wl_hwaddr("eth0", macbuf);
298                ether_etoa((uchar *) macbuf, eaddr);
299                nvram_set("wl0_hwaddr", eaddr);
300                wl_hwaddr("eth1", macbuf);
301                ether_etoa((uchar *) macbuf, eaddr);
302                nvram_set("wl1_hwaddr", eaddr);
303                break;
304
305        default:
306                boardflags = strtoul(nvram_safe_get("boardflags"), NULL, 0);
307                fprintf(stderr, "boardflags are 0x%04X\n", boardflags);
308                if (boardflags == 0)    // we can try anyway
309                {
310                        nvram_set("boardflags", "0x0200");
311                        insmod("wl");   // load module
312                        nvram_unset("boardflags");
313                } else if (boardflags & BFL_AFTERBURNER)        // ab flag already
314                        // set
315                {
316                        insmod("wl");   // load module
317                } else          // ab flag not set
318                {
319                        char bf[16];
320
321                        sprintf(bf, "0x%04X", boardflags);
322                        boardflags |= BFL_AFTERBURNER;
323                        fprintf(stderr,
324                                "enable Afterburner, boardflags are 0x%04X\n",
325                                boardflags);
326                        char ab[16];
327
328                        sprintf(ab, "0x%04X", boardflags);
329                        char *oldvalue = nvram_get("boardflags");       // use the
330
331                        // string for
332                        // restoring
333                        // since the
334                        // Buffalo
335                        // WZR-RS-G54
336                        // does await
337                        // a 0x10 in
338                        // the
339                        // bootloader,
340                        // otherwise
341                        // the nvram
342                        // gets
343                        // deleted
344                        nvram_set("boardflags", ab);    // set boardflags with
345                        // AfterBurner bit on
346                        insmod("wl");   // load module
347                        nvram_set("boardflags", oldvalue);      // set back to
348                        // original
349                }
350
351        }
352        detect_wireless_devices();
353        return;
354}
355
356char wanifname[8], wlifname[8];
357
358#define BCM4712_CPUTYPE "0x4712"
359
360static void setup_4712(void)
361{
362        uint boardflags = strtoul(nvram_safe_get("boardflags"), NULL, 0);
363
364        if (nvram_match("cpu_type", BCM4712_CPUTYPE) ||
365            nvram_match("cpu_type", "BCM3302") ||
366            nvram_match("cpu_type", "BCM4712")) {
367                if (boardflags & BFL_ENETVLAN) {
368                        cprintf("setup_4712(): Enable VLAN\n");
369                        // nvram_set("setup_4712","1");
370                        strcpy(wanifname, "vlan1");
371                        strcpy(wlifname, "eth1");
372                        if (!strcmp(nvram_safe_get("wan_ifname"), "eth1")) {
373                                // nvram_set("setup_4712","1-1");
374                                nvram_set("wan_ifname", "vlan1");
375                                nvram_set("wan_ifnames", "vlan1");
376                                nvram_set("wan_default", "vlan1");
377                        }
378                        if (!strstr(nvram_safe_get("lan_ifnames"), "vlan0")) {
379                                // nvram_set("setup_4712","1-2");
380                                nvram_set("lan_ifnames", "vlan0 eth1");
381                                nvram_set("vlan0hwname", "et0");
382                                nvram_set("vlan1hwname", "et0");
383                                nvram_set("wl0_ifname", "eth1");
384                                // nvram_set ("need_commit","1");
385                        }
386                }               // VLAN enabled
387                else {
388                        // nvram_set("setup_4712","2");
389                        cprintf
390                            ("setup_4712(): Disable VLAN, it must be in bridge mode\n");
391                        nvram_set("lan_ifnames", "eth0 eth1");
392                        strcpy(wlifname, "eth1");
393                        nvram_set("wl0_ifname", "eth1");
394                }
395        } else {                // 4702, 4704
396                cprintf
397                    ("setup_4712(): It's a 4702 or 4704 hardware, VLAN can't be used in these 2 boards\n");
398                strcpy(wanifname, "eth1");
399                strcpy(wlifname, "eth2");
400                nvram_set("wl0_ifname", "eth2");
401                if (!strcmp(nvram_safe_get("wan_ifname"), ""))
402                        nvram_set("lan_ifnames",
403                                  "eth0 eth1 eth2 wlanb0 wlana0");
404                else
405                        nvram_set("lan_ifnames", "eth0 eth2");
406        }
407        // nvram_set ("need_commit","1");
408
409}
410
411void start_sysinit(void)
412{
413        char buf[PATH_MAX];
414        struct utsname name;
415        struct stat tmp_stat;
416        time_t tm = 0;
417
418#ifdef HAVE_BCMMODERN
419        mknod("/dev/nvram",S_IFCHR|0644,makedev(229,0));
420        mkdir("/dev/gpio",0700);
421        mknod("/dev/gpio/in",S_IFCHR|0644,makedev(127,0));
422        mknod("/dev/gpio/out",S_IFCHR|0644,makedev(127,1));
423        mknod("/dev/gpio/outen",S_IFCHR|0644,makedev(127,2));
424        mknod("/dev/gpio/control",S_IFCHR|0644,makedev(127,3));
425        mknod("/dev/ppp",S_IFCHR|0644,makedev(108,0));
426        mknod("/dev/rtc",S_IFCHR|0644,makedev(254,0));
427        mknod("/dev/crypto",S_IFCHR|0644,makedev(10,70));
428        mkdir("/dev/usb",0700);
429#endif
430        cprintf("sysinit() setup console\n");
431#ifndef HAVE_MICRO
432        if (!nvram_match("disable_watchdog", "1"))
433                eval("watchdog");       // system watchdog
434#endif
435        /*
436         * Setup console
437         */
438
439        cprintf("sysinit() klogctl\n");
440        klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel")));
441        cprintf("sysinit() get router\n");
442
443        int brand = getRouterBrand();
444
445        led_control(LED_DIAG, LED_ON);
446        char *rname = getRouter();
447
448        fprintf(stderr, "Booting device: %s\n", rname);
449
450        nvram_unset("port_swap");
451
452        int need_reboot = 0;
453
454        struct nvram_tuple *basic_params = NULL;
455        struct nvram_tuple *extra_params = NULL;
456
457        struct nvram_tuple generic1[] = {
458                {"lan_ifnames", "eth0 eth2", 0},
459                {"wan_ifname", "eth1", 0},
460                {"wl0_ifname", "eth2", 0},
461                {0, 0, 0}
462        };
463
464        struct nvram_tuple generic1_wantolan[] = {
465                {"lan_ifnames", "eth2", 0},
466                {"wan_ifname", "eth0", 0},
467                {"wl0_ifname", "eth2", 0},
468                {0, 0, 0}
469        };
470
471        struct nvram_tuple vlan_0_1[] = {
472                {"lan_ifnames", "vlan0 eth1", 0},
473                {"wan_ifname", "vlan1", 0},
474                {"wl0_ifname", "eth1", 0},
475                {0, 0, 0}
476        };
477       
478        struct nvram_tuple vlan_1_2[] = {
479                {"lan_ifnames", "vlan1 eth1", 0},
480                {"wan_ifname", "vlan2", 0},
481                {"wl0_ifname", "eth1", 0},
482                {0, 0, 0}
483        };
484
485        switch (brand) {
486        case ROUTER_BUFFALO_WZRRSG54:
487                check_brcm_cpu_type();
488                setup_4712();
489                basic_params = generic1;
490                eval("gpio", "init", "0");      // AOSS button
491                eval("gpio", "init", "4");      // reset button
492                break;
493
494        case ROUTER_MOTOROLA:
495                nvram_set("cpu_type", "BCM4712");
496                setup_4712();
497                break;
498
499        case ROUTER_RT480W:
500                setup_4712();
501                break;
502
503        case ROUTER_BELKIN_F5D7231_V2000:
504                basic_params = vlan_0_1;
505                if (nvram_match("vlan1ports", "0 5u")) {
506                        nvram_set("vlan0ports", "3 2 1 0 5*");
507                        nvram_set("vlan1ports", "4 5");
508                }
509                break;
510
511        case ROUTER_BELKIN_F5D7231:
512        case ROUTER_USR_5461:
513        case ROUTER_NETCORE_NW618:
514                basic_params = vlan_0_1;
515                if (nvram_match("vlan1ports", "0 5u"))
516                        nvram_set("vlan1ports", "0 5");
517                break;
518
519        case ROUTER_USR_5465:
520                if (nvram_match("vlan1ports", "4 5u"))
521                        nvram_set("vlan1ports", "4 5");
522                break;
523               
524        case ROUTER_ASUS_RTN10:
525                basic_params = vlan_0_1;
526                if (nvram_match("vlan1ports", "4 5u")) {
527                        nvram_set("vlan1ports", "4 5");
528                        if(sv_valid_hwaddr(nvram_safe_get("macaddr")))  //fix mac
529                                nvram_set("et0macaddr", nvram_get("macaddr"));
530                        need_reboot = 1;
531                }
532                break;
533
534        case ROUTER_RT210W:
535        case ROUTER_ASKEY_RT220XD:
536                basic_params = generic1;
537
538                if (nvram_get("et0macaddr") == NULL
539                    || nvram_get("et0macaddr") == "") {
540                        nvram_set("et0macaddr", "00:16:E3:00:00:10");   // fix for
541                        // missing
542                        // cfe
543                        // default =
544                        // dead LAN
545                        // ports.
546                        need_reboot = 1;
547                }
548                if (nvram_get("et1macaddr") == NULL
549                    || nvram_get("et1macaddr") == "") {
550                        nvram_set("et1macaddr", "00:16:E3:00:00:11");
551                        need_reboot = 1;
552                }
553                break;
554
555        case ROUTER_BRCM4702_GENERIC:
556                basic_params = generic1;
557
558                if (nvram_get("et0macaddr") == NULL
559                    || nvram_get("et0macaddr") == "") {
560                        nvram_set("et0macaddr", "00:11:22:00:00:10");   // fix for
561                        // missing
562                        // cfe
563                        // default =
564                        // dead LAN
565                        // ports.
566                        need_reboot = 1;
567                }
568                if (nvram_get("et1macaddr") == NULL
569                    || nvram_get("et1macaddr") == "") {
570                        nvram_set("et1macaddr", "00:11:22:00:00:11");
571                        need_reboot = 1;
572                }
573                break;
574
575        case ROUTER_ASUS_WL500G:
576                basic_params = generic1;
577
578                if (nvram_get("et0macaddr") == NULL
579                    || nvram_get("et0macaddr") == "") {
580                        nvram_set("et0macaddr", "00:0C:6E:00:00:10");   // fix for
581                        // missing
582                        // cfe
583                        // default =
584                        // dead LAN
585                        // ports.
586                        need_reboot = 1;
587                }
588                if (nvram_get("et1macaddr") == NULL
589                    || nvram_get("et1macaddr") == "") {
590                        nvram_set("et1macaddr", "00:0C:6E:00:00:10");
591                        need_reboot = 1;
592                }
593                break;
594
595        case ROUTER_DELL_TRUEMOBILE_2300:
596                setup_4712();
597                nvram_set("wan_ifname", "eth1");        // fix for WAN problem.
598                break;
599
600        case ROUTER_BUFFALO_WBR54G:     // for WLA-G54
601                basic_params = generic1;
602                if (nvram_match("wan_to_lan", "yes") && nvram_invmatch("wan_proto", "disabled"))        // =
603                        //
604                        // no
605                        // lan
606                {
607                        basic_params = generic1_wantolan;
608                }
609                break;
610
611        case ROUTER_BUFFALO_WLI2_TX1_G54:
612        case ROUTER_BUFFALO_WLAG54C:
613        case ROUTER_WAP54G_V1:
614        case ROUTER_SITECOM_WL105B:
615                nvram_set("lan_ifnames", "eth1 eth2");
616                nvram_set("wl0_ifname", "eth2");
617                nvram_set("wan_ifname", "eth0");        // WAN to nonexist. iface.
618                nvram_set("port_swap", "1");
619                if (nvram_match("wan_to_lan", "yes") && nvram_invmatch("wan_proto", "disabled"))        // =
620                        //
621                        // no
622                        // lan
623                {
624                        nvram_set("lan_ifnames", "eth2");
625                        nvram_set("wan_ifname", "eth1");
626                }
627                break;
628
629        case ROUTER_SITECOM_WL111:
630                basic_params = generic1;
631                break;
632
633        case ROUTER_NETGEAR_WNR834BV2:
634                if (nvram_match("force_vlan_supp", "enabled")) {
635                        nvram_set("lan_ifnames", "vlan0 eth2");
636                        nvram_set("wan_ifname", "eth1");
637                        nvram_set("vlan0ports", "3 2 1 0 5*");
638                        nvram_set("vlan1ports", "4 5"); //dummy
639                        nvram_set("vlan0hwname", "et0");
640                } else {
641                        basic_params = generic1;
642                }
643
644                if (nvram_get("pci/1/1/macaddr") == NULL) {
645                        nvram_set("pci/1/1/macaddr",
646                                  nvram_safe_get("et0macaddr"));
647                        need_reboot = 1;
648                }
649                //params taken from firmware ver. 2.1.13 multi-region
650                struct nvram_tuple wnr834bv2_pci_1_1_params[] = {
651                        {"pa2gw1a0", "0", 0},
652                        {"stbcpo", "0", 0},
653                        {"pa2gw1a1", "0", 0},
654                        {"ag0", "2", 0},
655                        {"ag1", "2", 0},
656                        {"ag2", "2", 0},
657                        {"ccdpo", "0", 0},
658                        {"txpid2ga0", "55", 0},
659                        {"txpid2ga1", "78", 0},
660                        {"txpt2g", "0x38", 0},
661                        {"pa2gw0a0", "0", 0},
662                        {"pa2gw0a1", "0", 0},
663                        {"boardflags", "0x200", 0},
664                        {"boardvendor", "0x14e4", 0},
665                        {"bw40po", "0", 0},
666                        {"sromrev", "4", 0},
667                        {"venid", "0x14e4", 0},
668                        {"boardrev", "0x4b", 0},
669                        {"itt2ga0", "0", 0},
670                        {"itt2ga1", "0", 0},
671                        {"pa2gw3a0", "0", 0},
672                        {"pa2gw3a1", "0", 0},
673                        {"maxp2ga0", "0", 0},
674                        {"maxp2ga1", "0", 0},
675                        {"boardtype", "0x46d", 0},
676                        {"boardflags2", "3", 0},
677                        {"ofdm2gpo", "0", 0},
678                        {"ledbh0", "0x8", 0},
679                        {"ledbh1", "-1", 0},
680                        {"ledbh2", "-1", 0},
681                        {"ledbh3", "-1", 0},
682                        {"mcs2gpo0", "0", 0},
683                        {"mcs2gpo1", "0", 0},
684                        {"mcs2gpo2", "0", 0},
685                        {"mcs2gpo3", "0", 0},
686                        {"mcs2gpo4", "0", 0},
687                        {"mcs2gpo5", "0", 0},
688                        {"mcs2gpo6", "0", 0},
689                        {"mcs2gpo7", "0", 0},
690                        {"bwduppo", "0", 0},
691                        {"aa2g", "7", 0},
692                        {"pa2gw2a0", "0", 0},
693                        {"pa2gw2a1", "0", 0},
694                        {"ccode", "ALL", 0},
695                        {"regrev", "0", 0},
696                        {"devid", "0x4329", 0},
697                        {"cck2gpo", "0", 0},
698                        {0, 0, 0}
699                };
700                /*
701                 * set router's extra parameters
702                 */
703                extra_params = wnr834bv2_pci_1_1_params;
704                while (extra_params->name) {
705                        nvram_nset(extra_params->value, "pci/1/1/%s",
706                                   extra_params->name);
707                        extra_params++;
708                }
709                break;
710               
711#ifdef HAVE_BCMMODERN
712        case ROUTER_NETGEAR_WNR3500L:
713        case ROUTER_WRT320N:
714        case ROUTER_ASUS_RTN16:
715                basic_params = vlan_1_2;
716                nvram_set("vlan2hwname", "et0");
717                if (nvram_match("vlan1ports", "1 2 3 4 8*")
718                    || nvram_match("vlan2ports", "0 8u")) {
719                        nvram_set("vlan1ports", "4 3 2 1 8*");
720                        nvram_set("vlan2ports", "0 8");
721                        need_reboot = 1;
722                }
723                break;
724        case ROUTER_NETCORE_NW715P:
725                basic_params = vlan_1_2;
726                nvram_set("vlan0ports"," ");
727                nvram_set("vlan0hwname"," ");
728                break;
729        case ROUTER_BELKIN_F5D8235V3:
730                basic_params = vlan_1_2;
731                if (nvram_match("vlan1ports", "0 8")
732                    || nvram_match("vlan2ports", "1 2 3 4 8*")) {
733                        nvram_set("vlan1ports", "1 2 3 4 8*");
734                        nvram_set("vlan2ports", "0 8");
735                        need_reboot = 1;
736                }
737                break;
738
739        case ROUTER_BELKIN_F7D3301:
740        case ROUTER_BELKIN_F7D4301:
741                nvram_set("lan_ifnames", "vlan1 eth1 eth2");
742                nvram_set("wan_ifname", "vlan2");
743                if (nvram_match("vlan1ports", "4 8")
744                    || nvram_match("vlan2ports", "0 1 2 3 8*")) {
745                        nvram_set("vlan1ports", "3 2 1 0 8*");
746                        nvram_set("vlan2ports", "4 8");
747                        need_reboot = 1;
748                }
749                break;
750               
751        case ROUTER_BELKIN_F7D3302:             
752        case ROUTER_BELKIN_F7D4302:
753                nvram_set("lan_ifnames", "vlan1 eth1 eth2");
754                nvram_set("wan_ifname", "vlan2");
755                if (nvram_match("vlan1ports", "4 5*")
756                    || nvram_match("vlan2ports", "0 1 2 3 5*")) {
757                        nvram_set("vlan1ports", "0 1 2 3 5*");
758                        nvram_set("vlan2ports", "4 5");
759                        need_reboot = 1;
760                }
761                break;
762               
763        case ROUTER_NETGEAR_WNDR3400:
764                nvram_set("lan_ifnames", "vlan1 eth1 eth2");
765                nvram_set("wan_ifname", "vlan2");
766                if (nvram_match("vlan2ports", "4 5u")
767                        || nvram_match("vlan1ports", "0 1 2 3 5*")) {
768                        nvram_set("vlan1ports", "3 2 1 0 5*");
769                        nvram_set("vlan2ports", "4 5");
770                        need_reboot = 1;
771                }
772                if (startswith(nvram_safe_get("pci/1/1/macaddr"), "00:90:4")
773                    || startswith(nvram_safe_get("sb/1/macaddr"), "00:90:4")) {
774                        unsigned char mac[20];
775                        strcpy(mac, nvram_safe_get("et0macaddr"));
776                        MAC_ADD(mac);
777                        MAC_ADD(mac);
778                        nvram_set("sb/1/macaddr", mac);
779                        MAC_ADD(mac);
780                        nvram_set("pci/1/1/macaddr", mac);
781                        need_reboot = 1;
782                }
783       
784                struct nvram_tuple wndr3400_sb_1_params[] = {
785                       
786                        {"sromrev", "8", 0},
787                        {"ccode", "ALL", 0},
788                        {"regrev", "0", 0},
789                        {"ledbh0", "11", 0},
790                        {"ledbh1", "11", 0},
791                        {"ledbh2", "11", 0},
792                        {"ledbh3", "11", 0},
793                        {"ledbh9", "8", 0},
794                        {"leddc", "0xffff", 0},
795                        {"txchain", "3", 0},
796                        {"rxchain", "3", 0},
797                        {"antswitch", "0", 0},
798                        {"aa2g", "3", 0},
799                        {"ag0", "2", 0},
800                        {"ag1", "2", 0},
801                        {"itt2ga0", "0x20", 0},
802                        {"maxp2ga0", "0x48", 0},
803                        {"pa2gw0a0", "0xFEA5", 0},
804                        {"pa2gw1a0", "0x17B2", 0},
805                        {"pa2gw2a0", "0xFA73", 0},
806                        {"itt2ga1", "0x20", 0},
807                        {"maxp2ga1", "0x48", 0},
808                        {"pa2gw0a1", "0xfeba", 0},
809                        {"pa2gw1a1", "0x173c", 0},
810                        {"pa2gw2a1", "0xfa9b", 0},
811                        {"tssipos2g", "1", 0},
812                        {"extpagain2g", "2", 0},
813                        {"pdetrange2g", "2", 0},
814                        {"triso2g", "3", 0},
815                        {"antswctl2g", "2", 0},
816                        {"cck2gpo", "0x0000", 0},
817                        {"ofdm2gpo", "0x66666666", 0},
818                        {"mcs2gpo0", "0x6666", 0},
819                        {"mcs2gpo1", "0x6666", 0},
820                        {"mcs2gpo2", "0x6666", 0},
821                        {"mcs2gpo3", "0x6666", 0},
822                        {"mcs2gpo4", "0x6666", 0},
823                        {"mcs2gpo5", "0x6666", 0},
824                        {"mcs2gpo6", "0x6666", 0},
825                        {"mcs2gpo7", "0x6666", 0},
826                        {"cddpo", "0", 0},
827                        {"stbcpo", "0", 0},
828                        {"bw40po", "0", 0},
829                        {"bwduppo", "0", 0},                   
830                       
831                        {0, 0, 0}
832                };
833                /*
834                 * set router's extra parameters
835                 */
836                extra_params = wndr3400_sb_1_params;
837                while (extra_params->name) {
838                        nvram_nset(extra_params->value, "sb/1/%s",
839                                   extra_params->name);
840                        extra_params++;
841                }
842               
843                struct nvram_tuple wndr3400_pci_1_1_params[] = {
844                       
845                        {"sromrev", "8", 0},
846                        {"ccode", "ALL", 0},
847                        {"regrev", "0", 0},
848                        {"ledbh0", "8", 0},
849                        {"ledbh1", "0x11", 0},
850                        {"ledbh2", "0x11", 0},
851                        {"ledbh3", "0x11", 0},
852                        {"leddc", "0xffff", 0},
853                        {"txchain", "3", 0},
854                        {"rxchain", "3", 0},
855                        {"antswitch", "0", 0},
856                        {"cddpo", "0", 0},
857                        {"stbcpo", "0", 0},
858                        {"bw40po", "0", 0},
859                        {"bwduppo", "0", 0},
860                        {"aa5g", "3", 0},
861                        {"ag0", "2", 0},
862                        {"ag1", "2", 0},
863                        {"itt5ga0", "0x3e", 0},
864                        {"maxp5ga0", "0x4A", 0},
865                        {"maxp5gha0", "0x4A", 0},
866                        {"maxp5gla0", "0x4A", 0},
867                        {"pa5gw0a0", "0xFEF9", 0},
868                        {"pa5gw1a0", "0x164B", 0},
869                        {"pa5gw2a0", "0xFADD", 0},
870                        {"pa5glw0a0", "0xFEF9", 0},
871                        {"pa5glw1a0", "0x154B", 0},
872                        {"pa5glw2a0", "0xFAFD", 0},
873                        {"pa5ghw0a0", "0xfeda", 0},
874                        {"pa5ghw1a0", "0x1612", 0},
875                        {"pa5ghw2a0", "0xfabe", 0},
876                        {"tssipos5g", "1", 0},
877                        {"extpagain5g", "2", 0},
878                        {"pdetrange5g", "4", 0},
879                        {"triso5g", "3", 0},
880                        {"antswctl2g", "0", 0},
881                        {"antswctl5g", "0", 0},
882                        {"itt5ga1", "0x3e", 0},
883                        {"maxp5ga1", "0x4A", 0},
884                        {"maxp5gha1", "0x4A", 0},
885                        {"maxp5gla1", "0x4A", 0},
886                        {"pa5gw0a1", "0xff31", 0},
887                        {"pa5gw1a1", "0x1697", 0},
888                        {"pa5gw2a1", "0xfb08", 0},
889                        {"pa5glw0a1", "0xFF31", 0},
890                        {"pa5glw1a1", "0x1517", 0},
891                        {"pa5glw2a1", "0xFB2F", 0},
892                        {"pa5ghw0a1", "0xff18", 0},
893                        {"pa5ghw1a1", "0x1661", 0},
894                        {"pa5ghw2a1", "0xfafe", 0},
895                        {"ofdm5gpo0", "0x0000", 0},
896                        {"ofdm5gpo1", "0x2000", 0},
897                        {"ofdm5glpo0", "0x0000", 0},
898                        {"ofdm5glpo1", "0x2000", 0},
899                        {"ofdm5ghpo0", "0x0000", 0},
900                        {"ofdm5ghpo1", "0x2000", 0},
901                        {"mcs5gpo0", "0x4200", 0},
902                        {"mcs5gpo1", "0x6664", 0},
903                        {"mcs5gpo2", "0x4200", 0},
904                        {"mcs5gpo3", "0x6664", 0},
905                        {"mcs5gpo4", "0x4200", 0},
906                        {"mcs5gpo5", "0x6664", 0},
907                        {"mcs5gpo6", "0x4200", 0},
908                        {"mcs5gpo7", "0x6664", 0},
909                        {"mcs5glpo0", "0x4200", 0},
910                        {"mcs5glpo1", "0x6664", 0},
911                        {"mcs5glpo2", "0x4200", 0},
912                        {"mcs5glpo3", "0x6664", 0},
913                        {"mcs5glpo4", "0x4200", 0},
914                        {"mcs5glpo5", "0x6664", 0},
915                        {"mcs5glpo6", "0x4200", 0},
916                        {"mcs5glpo7", "0x6664", 0},
917                        {"mcs5ghpo0", "0x4200", 0},
918                        {"mcs5ghpo1", "0x6664", 0},
919                        {"mcs5ghpo2", "0x4200", 0},
920                        {"mcs5ghpo3", "0x6664", 0},
921                        {"mcs5ghpo4", "0x4200", 0},
922                        {"mcs5ghpo5", "0x6664", 0},
923                        {"mcs5ghpo6", "0x4200", 0},
924                        {"mcs5ghpo7", "0x6664", 0},
925                        {"cdd5ghpo/cdd5glpo/cdd5gpo/cdd2gpo", "0x0", 0},
926                        {"stbc5ghpo/stbc5glpo/stbc5gpo/stbc2gpo", "0x0", 0},
927                        {"bw405ghpo/bw405glpo/bw405gpo/bw402gpo", "0x2", 0},
928                        {"wdup405ghpo/wdup405glpo/wdup405gpo/wdup402gpo", "0x0", 0},
929                       
930                        {0, 0, 0}
931                };
932                /*
933                 * set router's extra parameters
934                 */
935                extra_params = wndr3400_pci_1_1_params;
936                while (extra_params->name) {
937                        nvram_nset(extra_params->value, "pci/1/1/%s",
938                                   extra_params->name);
939                        extra_params++;
940                }       
941                break;
942               
943        case ROUTER_NETGEAR_WNDR4000:
944                nvram_set("lan_ifnames", "vlan1 eth1 eth2");
945                nvram_set("wan_ifname", "vlan2");
946                if (nvram_match("vlan2ports", "4 8u")) {
947                        nvram_set("vlan2ports", "4 8");
948                        need_reboot = 1;
949                }
950                if (!sv_valid_hwaddr(nvram_safe_get("pci/1/1/macaddr"))
951                        || startswith(nvram_safe_get("pci/1/1/macaddr"), "00:90:4C")
952                    || !sv_valid_hwaddr(nvram_safe_get("sb/1/macaddr"))
953                    || startswith(nvram_safe_get("sb/1/macaddr"), "00:90:4C")) {
954                        unsigned char mac[20];
955                        strcpy(mac, nvram_safe_get("et0macaddr"));
956                        MAC_ADD(mac);
957                        MAC_ADD(mac);
958                        nvram_set("sb/1/macaddr", mac);
959                        MAC_ADD(mac);
960                        nvram_set("pci/1/1/macaddr", mac);
961                        need_reboot = 1;
962                }
963
964                struct nvram_tuple wndr4000_sb_1_params[] = {
965                                               
966                        {"aa2g", "3", 0},
967                        {"ag0", "0", 0},
968                        {"ag1", "0", 0},
969                        {"ag2", "0", 0},
970                        {"txchain", "3", 0},
971                        {"rxchain", "3", 0},
972                        {"antswitch", "0", 0},
973                        {"itt2ga0", "0x20", 0},
974                        {"itt2ga1", "0x20", 0},
975                        {"tssipos2g", "1", 0},
976                        {"extpagain2g", "3", 0},
977                        {"pdetrange2g", "5", 0},
978                        {"triso2g", "4", 0},
979                        {"antswctl2g", "2", 0},
980                        {"elna2g",  "3", 0},
981
982                        {"pa2gw0a0", "0xFEA6", 0},
983                        {"pa2gw1a0", "0x191D", 0},
984                        {"pa2gw2a0", "0xFA18", 0},
985
986                        {"pa2gw0a1", "0xFE9E", 0},
987                        {"pa2gw1a1", "0x1809", 0},
988                        {"pa2gw2a1", "0xFA4B", 0},
989
990                        {0, 0, 0}
991                };
992                /*
993                 * set router's extra parameters
994                 */
995                extra_params = wndr4000_sb_1_params;
996                while (extra_params->name) {
997                        nvram_nset(extra_params->value, "sb/1/%s",
998                                   extra_params->name);
999                        extra_params++;
1000                }
1001               
1002                struct nvram_tuple wndr4000_pci_1_1_params[] = {
1003                       
1004                        {"boardflags2", "0x04000000", 0},
1005                        {"legofdmbw20ul5ghpo", "0x11000000", 0},
1006                        {"legofdmbw205ghpo", "0x11000000", 0},
1007                        {"legofdm40duppo", "0x2222", 0},
1008                        {"aa2g", "7", 0},
1009                        {"aa5g", "7", 0},
1010                        {"ag0", "0", 0},
1011                        {"ag1", "0", 0},
1012                        {"ag2", "0", 0},
1013                        {"txchain", "7", 0},
1014                        {"rxchain", "7", 0},
1015                        {"antswitch", "0", 0},
1016                        {"tssipos2g", "1", 0},
1017                        {"extpagain2g", "0", 0},
1018                        {"pdetrange2g", "4", 0},
1019                        {"antswctl2g", "0", 0},
1020                        {"tssipos5g", "1", 0},
1021                        {"extpagain5g", "0", 0},
1022                        {"pdetrange5g", "4", 0},
1023                        {"triso5g", "1", 0},
1024                        {"antswctl5g", "0", 0},
1025                       
1026                        {"pa2gw0a0", "0xFE6D", 0},
1027                        {"pa2gw0a1", "0xFE72", 0},
1028                        {"pa2gw0a2", "0xFE74", 0},
1029                        {"pa2gw1a0", "0x1772", 0},
1030                        {"pa2gw1a1", "0x1792", 0},
1031                        {"pa2gw1a2", "0x1710", 0},
1032                        {"pa2gw2a0", "0xFA34", 0},
1033                        {"pa2gw2a1", "0xFA31", 0},
1034                        {"pa2gw2a2", "0xFA4F", 0},
1035                        {"maxp2ga0", "0x48", 0},
1036                        {"maxp2ga1", "0x48", 0},
1037                        {"maxp2ga2", "0x48", 0},                       
1038                       
1039                       
1040                        {"pa5gw0a0", "0xFE82", 0},
1041                        {"pa5gw0a1", "0xFE85", 0},
1042                        {"pa5gw0a2", "0xFE7F", 0},
1043                        {"pa5gw1a0", "0x1677", 0},
1044                        {"pa5gw1a1", "0x167C", 0},
1045                        {"pa5gw1a2", "0x1620", 0},
1046                        {"pa5gw2a0", "0xFA72", 0},
1047                        {"pa5gw2a1", "0xFA7A", 0},
1048                        {"pa5gw2a2", "0xFA88", 0},
1049                        {"maxp5ga0", "0x48", 0},
1050                        {"maxp5ga1", "0x48", 0},
1051                        {"maxp5ga2", "0x48", 0},
1052                       
1053                        {"pa5ghw0a0", "0xFE9A", 0},
1054                        {"pa5ghw0a1", "0xFE89", 0},
1055                        {"pa5ghw0a2", "0xFE98", 0},
1056                        {"pa5ghw1a0", "0x15E7", 0},
1057                        {"pa5ghw1a1", "0x15F9", 0},
1058                        {"pa5ghw1a2", "0x15CD", 0},
1059                        {"pa5ghw2a0", "0xFAAC", 0},
1060                        {"pa5ghw2a1", "0xFA94", 0},
1061                        {"pa5ghw2a2", "0xFAB2", 0},
1062                        {"maxp5gha0", "0x40", 0},
1063                        {"maxp5gha1", "0x40", 0},
1064                        {"maxp5gha2", "0x40", 0},
1065                       
1066                        {"pa5glw0a0", "0xFE97", 0},
1067                        {"pa5glw0a1", "0xFE82", 0},
1068                        {"pa5glw0a2", "0xFE84", 0},
1069                        {"pa5glw1a0", "0x162F", 0},
1070                        {"pa5glw1a1", "0x15ED", 0},
1071                        {"pa5glw1a2", "0x167F", 0},
1072                        {"pa5glw2a0", "0xFA98", 0},
1073                        {"pa5glw2a1", "0xFA99", 0},
1074                        {"pa5glw2a2", "0xFA84", 0},
1075                        {"maxp5gla0", "0x48", 0},
1076                        {"maxp5gla1", "0x48", 0},
1077                        {"maxp5gla2", "0x48", 0},
1078
1079                        {0, 0, 0}
1080                };
1081                /*
1082                 * set router's extra parameters
1083                 */
1084                extra_params = wndr4000_pci_1_1_params;
1085                while (extra_params->name) {
1086                        nvram_nset(extra_params->value, "pci/1/1/%s",
1087                                   extra_params->name);
1088                        extra_params++;
1089                }
1090                break;
1091
1092        case ROUTER_NETGEAR_WNR2000V2:
1093                basic_params = vlan_0_1;
1094                if (nvram_match("vlan0ports", "1 2 3 4 5*")
1095                    || nvram_match("vlan1ports", "0 5u")) {
1096                        nvram_set("vlan0ports", "4 3 2 1 5*");
1097                        nvram_set("vlan1ports", "0 5");
1098                        need_reboot = 1;
1099                }
1100                break;
1101
1102        case ROUTER_ASUS_RTN12:
1103                basic_params = vlan_0_1;
1104                eval("gpio", "enable", "0");
1105                if (!nvram_match("ledbh0", "0")
1106                    || !nvram_match("ledbh1", "0")) {
1107                        nvram_set("ledbh0", "0");
1108                        nvram_set("ledbh1", "0");
1109                        need_reboot = 1;
1110                }
1111                if (nvram_match("vlan0ports", "0 1 2 3 5*")
1112                    || nvram_match("vlan1ports", "4 5u")) {
1113                        nvram_set("vlan0ports", "3 2 1 0 5*");
1114                        nvram_set("vlan1ports", "4 5");
1115                        need_reboot = 1;
1116                }
1117                break;
1118
1119        case ROUTER_ASUS_RTN66:
1120                nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1121                nvram_set("wan_ifname", "vlan2");
1122                if (nvram_match("vlan2ports", "0 8u")) {
1123                        nvram_set("vlan2ports", "0 8");
1124                        need_reboot = 1;
1125                }
1126                nvram_unset("maxp2ga0");
1127                nvram_unset("maxp2ga1");
1128                nvram_unset("maxp2ga2");
1129                nvram_unset("maxp5ga0");
1130                nvram_unset("maxp5ga1");
1131                nvram_unset("maxp5ga2");
1132                nvram_unset("maxp5gha0");
1133                nvram_unset("maxp5gha1");
1134                nvram_unset("maxp5gha2");
1135                nvram_set("pci/1/1/maxp2ga0","0x64");
1136                nvram_set("pci/1/1/maxp2ga1","0x64");
1137                nvram_set("pci/1/1/maxp2ga2","0x64");
1138                nvram_set("pci/1/1/regrev","0");
1139                nvram_set("pci/1/1/ccode","ALL");
1140                nvram_set("pci/2/1/maxp5ga0","0x5C");
1141                nvram_set("pci/2/1/maxp5ga1","0x5C");
1142                nvram_set("pci/2/1/maxp5ga2","0x5C");
1143                nvram_set("pci/2/1/maxp5gha0","0x5C");
1144                nvram_set("pci/2/1/maxp5gha1","0x5C");
1145                nvram_set("pci/2/1/maxp5gha2","0x5C");
1146                nvram_set("pci/2/1/regrev","0");
1147                nvram_set("pci/2/1/ccode","ALL");
1148                break;
1149
1150        case ROUTER_WRT310NV2:
1151                basic_params = vlan_1_2;
1152                nvram_set("vlan2hwname", "et0");
1153                if (nvram_match("vlan1ports", "1 2 3 4 8*"))
1154                        nvram_set("vlan1ports", "4 3 2 1 8*");
1155                break;
1156
1157        case ROUTER_WRT160NV3:
1158                basic_params = vlan_1_2;
1159                nvram_set("vlan2hwname", "et0");
1160                //fix lan port numbering on CSE41, CSE51
1161                if (nvram_match("clkdivsf", "4")
1162                    && nvram_match("vlan1ports", "1 2 3 4 5*")) {
1163                        nvram_set("vlan1ports", "4 3 2 1 5*");
1164                }
1165                break;
1166               
1167        case ROUTER_LINKSYS_E1000V2:
1168                basic_params = vlan_1_2;
1169                break;
1170
1171        case ROUTER_LINKSYS_E2500:             
1172        case ROUTER_LINKSYS_E3200:
1173                nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1174                nvram_set("wan_ifname", "vlan2");
1175                break;
1176               
1177        case ROUTER_LINKSYS_E4200:
1178                nvram_set("lan_ifnames", "vlan1 eth1 eth2");
1179                nvram_set("wan_ifname", "vlan2");
1180                if (!sv_valid_hwaddr(nvram_safe_get("pci/1/1/macaddr"))
1181                        || startswith(nvram_safe_get("pci/1/1/macaddr"), "00:90:4C")
1182                    || !sv_valid_hwaddr(nvram_safe_get("sb/1/macaddr"))
1183                    || startswith(nvram_safe_get("sb/1/macaddr"), "00:90:4C")) {
1184                        unsigned char mac[20];
1185
1186                        strcpy(mac, nvram_safe_get("et0macaddr"));
1187                        MAC_ADD(mac);
1188                        MAC_ADD(mac);
1189                        nvram_set("sb/1/macaddr", mac);
1190                        MAC_ADD(mac);
1191                        nvram_set("pci/1/1/macaddr", mac);
1192                        need_reboot = 1;
1193                }
1194                struct nvram_tuple e4200_pci_1_1_params[] = {
1195                        {"pa2gw0a0", "0xfe8c", 0},
1196                        {"pa2gw1a0", "0x1b20", 0},
1197                        {"pa2gw2a0", "0xf98c", 0},
1198                        {"pa2gw0a1", "0xfe98", 0},
1199                        {"pa2gw1a1", "0x19ae", 0},
1200                        {"pa2gw2a1", "0xf9ab", 0},
1201                       
1202                        {"pa5gw0a0", "0xfe52", 0},
1203                        {"pa5gw1a0", "0x163e", 0},
1204                        {"pa5gw2a0", "0xfa59", 0},
1205                        {"pa5gw0a1", "0xfe63", 0},
1206                        {"pa5gw1a1", "0x1584", 0},
1207                        {"pa5gw2a1", "0xfa92", 0},
1208                        {"pa5gw0a2", "0xfe7c", 0},
1209                        {"pa5gw1a2", "0x1720", 0},
1210                        {"pa5gw2a2", "0xfa4a", 0},
1211                       
1212                        {"pa5ghw0a0", "0xfe6a", 0},
1213                        {"pa5ghw1a0", "0x163c", 0},
1214                        {"pa5ghw2a0", "0xfa69", 0},
1215                        {"pa5ghw0a1", "0xfe67", 0},
1216                        {"pa5ghw1a1", "0x160e", 0},
1217                        {"pa5ghw2a1", "0xfa6a", 0},
1218                        {"pa5ghw0a2", "0xfe76", 0},
1219                        {"pa5ghw1a2", "0x1766", 0},
1220                        {"pa5ghw2a2", "0xfa2c", 0},
1221/*                     
1222                        {"pa5glw0a0", "0", 0},
1223                        {"pa5glw1a0", "0", 0},
1224                        {"pa5glw2a0", "0", 0},
1225                        {"pa5glw0a1", "0", 0},
1226                        {"pa5glw1a1", "0", 0},
1227                        {"pa5glw2a1", "0", 0},
1228                        {"pa5glw0a2", "0", 0},
1229                        {"pa5glw1a2", "0", 0},
1230                        {"pa5glw2a2", "0", 0},
1231*/
1232
1233                        {"pa05gidx", "5", 0},
1234                        {"pa05glidx", "0", 0},
1235                        {"pa05ghidx", "7", 0},
1236                        {"pa15gidx", "0", 0},                   
1237                        {"pa15glidx", "0", 0},
1238                        {"pa15ghidx", "3", 0},
1239                        {"pa25gidx", "5", 0},
1240                        {"pa25glidx", "0", 0},
1241                        {"pa25ghidx", "9", 0},
1242
1243                        {0, 0, 0}
1244                };
1245                /*
1246                 * set router's extra parameters
1247                 */
1248                extra_params = e4200_pci_1_1_params;
1249                while (extra_params->name) {
1250                        nvram_nset(extra_params->value, "pci/1/1/%s",
1251                                   extra_params->name);
1252                        extra_params++;
1253                }
1254                break;
1255               
1256#endif         
1257
1258        case ROUTER_NETGEAR_WNDR3300:
1259                if (nvram_match("force_vlan_supp", "enabled")) {
1260                        nvram_set("lan_ifnames", "vlan0 eth2 eth3");
1261                        nvram_set("vlan0ports", "3 2 1 0 5*");
1262                        nvram_set("vlan1ports", "4 5"); //dummy
1263                        nvram_set("vlan0hwname", "et0");
1264                } else {
1265                        nvram_set("lan_ifnames", "eth0 eth2 eth3");     // dual radio
1266                }
1267                nvram_set("wan_ifname", "eth1");
1268                nvram_set("wl0_ifname", "eth2");
1269                nvram_set("wl1_ifname", "eth3");
1270                eval("gpio", "disable", "7");
1271
1272                if (nvram_get("pci/1/1/macaddr") == NULL
1273                    || nvram_get("pci/1/3/macaddr") == NULL) {
1274                        unsigned char mac[20];
1275
1276                        strcpy(mac, nvram_safe_get("et0macaddr"));
1277                        MAC_ADD(mac);
1278                        MAC_ADD(mac);
1279                        nvram_set("pci/1/1/macaddr", mac);
1280                        MAC_ADD(mac);
1281                        nvram_set("pci/1/3/macaddr", mac);
1282                        need_reboot = 1;
1283                }
1284                //params taken from firmware ver. 1.0.29 multi-region
1285                struct nvram_tuple wndr3300_pci_1_1_params[] = {
1286                        {"stbcpo", "0", 0},
1287                        {"mcs5gpo0", "0x4200", 0},
1288                        {"pa2gw1a0", "0x14EA", 0},
1289                        {"mcs5gpo1", "0x6664", 0},
1290                        {"pa2gw1a1", "0x14DA", 0},
1291                        {"mcs5gpo2", "0x4200", 0},
1292                        {"maxp5gha0", "0x4A", 0},
1293                        {"mcs5gpo3", "0x6664", 0},
1294                        {"maxp5gha1", "0x4A", 0},
1295                        {"mcs5gpo4", "0", 0},
1296                        {"mcs5gpo5", "0", 0},
1297                        {"mcs5gpo6", "0", 0},
1298                        {"aa5g", "7", 0},
1299                        {"mcs5gpo7", "0", 0},
1300                        {"pa5glw2a0", "0xFBA2", 0},
1301                        {"pa5glw2a1", "0xFBDB", 0},
1302                        {"ag0", "2", 0},
1303                        {"ag1", "2", 0},
1304                        {"ag2", "2", 0},
1305                        {"pa5gw2a0", "0xFBBA", 0},
1306                        {"pa5gw2a1", "0xFC11", 0},
1307                        {"pa5ghw2a0", "0xFBB5", 0},
1308                        {"pa5ghw2a1", "0xFBD2", 0},
1309                        {"ccdpo", "0", 0},
1310                        {"txpid2ga0", "52", 0},
1311                        {"itt5ga0", "0x3C", 0},
1312                        {"rxchain", "3", 0},
1313                        {"txpid2ga1", "51", 0},
1314                        {"itt5ga1", "0x3C", 0},
1315                        {"maxp5ga0", "0x4A", 0},
1316                        {"maxp5ga1", "0x4A", 0},
1317                        {"txpt2g", "0x48", 0},
1318                        {"pa2gw0a0", "0xFEFC", 0},
1319                        {"pa2gw0a1", "0xFF03", 0},
1320                        {"boardflags", "0x0A00", 0},
1321                        {"mcs5glpo0", "0x4200", 0},
1322                        {"pa5glw1a0", "0x120E", 0},
1323                        {"mcs5glpo1", "0x6664", 0},
1324                        {"ofdm5gpo", "0x88888888", 0},
1325                        {"pa5glw1a1", "0x12BD", 0},
1326                        {"mcs5glpo2", "0x4200", 0},
1327                        {"mcs5glpo3", "0x6664", 0},
1328                        {"mcs5glpo4", "0", 0},
1329                        {"mcs5glpo5", "0", 0},
1330                        {"mcs5glpo6", "0", 0},
1331                        {"mcs5glpo7", "0", 0},
1332                        {"boardvendor", "0x14e4", 0},
1333                        {"bw40po", "0", 0},
1334                        {"sromrev", "4", 0},
1335                        {"venid", "0x14e4", 0},
1336                        {"pa5gw1a0", "0x1337", 0},
1337                        {"pa5gw1a1", "0x14A4", 0},
1338                        {"pa5ghw1a0", "0x11C2", 0},
1339                        {"pa5ghw1a1", "0x1275", 0},
1340                        {"boardrev", "0x13", 0},
1341                        {"itt2ga0", "0x3E", 0},
1342                        {"itt2ga1", "0x3E", 0},
1343                        {"pa2gw3a0", "0", 0},
1344                        {"pa2gw3a1", "0", 0},
1345                        {"maxp2ga0", "0x4A", 0},
1346                        {"maxp2ga1", "0x4A", 0},
1347                        {"boardtype", "0x49C", 0},
1348                        {"boardflags2", "0x0014", 0},
1349                        {"ofdm2gpo", "0x66666666", 0},
1350                        {"ledbh0", "11", 0},
1351                        {"ledbh1", "11", 0},
1352                        {"pa5glw0a0", "0xFEFB", 0},
1353                        {"ledbh2", "11", 0},
1354                        {"pa5glw0a1", "0xFF5B", 0},
1355                        {"ledbh3", "11", 0},
1356                        {"ledbh4", "11", 0},
1357                        {"ledbh5", "5", 0},
1358                        {"ledbh6", "7", 0},
1359                        {"ledbh7", "11", 0},
1360                        {"mcs2gpo0", "0x6666", 0},
1361                        {"mcs2gpo1", "0x6666", 0},
1362                        {"mcs2gpo2", "0x6666", 0},
1363                        {"mcs2gpo3", "0x6666", 0},
1364                        {"txpid5gla0", "18", 0},
1365                        {"mcs2gpo4", "0", 0},
1366                        {"txpid5gla1", "14", 0},
1367                        {"mcs2gpo5", "0", 0},
1368                        {"txpt5g", "0x3C", 0},
1369                        {"mcs2gpo6", "0", 0},
1370                        {"mcs2gpo7", "0", 0},
1371                        {"mcs5ghpo0", "0x4200", 0},
1372                        {"mcs5ghpo1", "0x6664", 0},
1373                        {"bwduppo", "0", 0},
1374                        {"mcs5ghpo2", "0x4200", 0},
1375                        {"mcs5ghpo3", "0x6664", 0},
1376                        {"txchain", "3", 0},
1377                        {"mcs5ghpo4", "0", 0},
1378                        {"mcs5ghpo5", "0", 0},
1379                        {"txpid5gha0", "28", 0},
1380                        {"mcs5ghpo6", "0", 0},
1381                        {"ofdm5glpo", "0x88888888", 0},
1382                        {"txpid5gha1", "25", 0},
1383                        {"mcs5ghpo7", "0", 0},
1384                        {"antswitch", "2", 0},
1385                        {"aa2g", "7", 0},
1386                        {"pa5gw0a0", "0xFF3C", 0},
1387                        {"pa5gw0a1", "0xFFEC", 0},
1388                        {"ofdm5ghpo", "0x88888888", 0},
1389                        {"pa5ghw0a0", "0xFEE8", 0},
1390                        {"pa5ghw0a1", "0xFF72", 0},
1391                        {"leddc", "0xFFFF", 0},
1392                        {"pa2gw2a0", "0xFB44", 0},
1393                        {"pa2gw2a1", "0xFB28", 0},
1394                        {"pa5glw3a0", "0", 0},
1395                        {"pa5glw3a1", "0", 0},
1396                        {"ccode", "0", 0},
1397                        {"pa5gw3a0", "0", 0},
1398                        {"regrev", "0", 0},
1399                        {"pa5gw3a1", "0", 0},
1400                        {"devid", "0x4328", 0},
1401                        {"pa5ghw3a0", "0", 0},
1402                        {"pa5ghw3a1", "0", 0},
1403                        {"txpt5gh", "0x3C", 0},
1404                        {"cck2gpo", "0x0000", 0},
1405                        {"txpt5gl", "0x30", 0},
1406                        {"maxp5gla0", "0x4A", 0},
1407                        {"txpid5ga0", "39", 0},
1408                        {"maxp5gla1", "0x4A", 0},
1409                        {"txpid5ga1", "39", 0},
1410                        {0, 0, 0}
1411                };
1412                /*
1413                 * set router's extra parameters
1414                 */
1415                extra_params = wndr3300_pci_1_1_params;
1416                while (extra_params->name) {
1417                        nvram_nset(extra_params->value, "pci/1/1/%s",
1418                                   extra_params->name);
1419                        extra_params++;
1420                }
1421
1422                struct nvram_tuple wndr3300_pci_1_3_params[] = {
1423                        {"ag0", "0x02", 0},
1424                        {"boardflags", "0xAA48", 0},
1425                        {"ccode", "0", 0},
1426                        {"aa0", "0x03", 0},
1427                        {"devid", "0x4318", 0},
1428                        {"pa0b0", "0x14ed", 0},
1429                        {"pa0b1", "0xfac7", 0},
1430                        {"pa0b2", "0xfe8a", 0},
1431                        {"pa0itssit", "62", 0},
1432                        {"pa0maxpwr", "0x0042", 0},
1433                        {"opo", "0", 0},
1434                        {"wl0gpio0", "11", 0},
1435                        {"wl0gpio1", "11", 0},
1436                        {"wl0gpio2", "11", 0},
1437                        {"wl0gpio3", "7", 0},
1438                        {"sromrev", "2", 0},
1439                        {0, 0, 0}
1440                };
1441                /*
1442                 * set router's extra parameters
1443                 */
1444                extra_params = wndr3300_pci_1_3_params;
1445                while (extra_params->name) {
1446                        nvram_nset(extra_params->value, "pci/1/3/%s",
1447                                   extra_params->name);
1448                        extra_params++;
1449                }
1450                break;
1451
1452        case ROUTER_MOTOROLA_WE800G:
1453                nvram_set("lan_ifnames", "eth1 eth2");
1454                nvram_set("wl0_ifname", "eth2");
1455                nvram_set("wan_ifname", "eth0");        // WAN to nonexist. iface.
1456                nvram_set("port_swap", "1");
1457                eval("gpio", "disable", "7");
1458                if (nvram_match("wan_to_lan", "yes") && nvram_invmatch("wan_proto", "disabled"))        // =
1459                        //
1460                        // no
1461                        // lan
1462                {
1463                        nvram_set("lan_ifnames", "eth2");
1464                        nvram_set("wan_ifname", "eth1");
1465                }
1466                break;
1467
1468        case ROUTER_MOTOROLA_V1:
1469        case ROUTER_BUFFALO_WZRG300N:
1470        case ROUTER_NETGEAR_WNR834B:
1471        case ROUTER_WRT300N:
1472        case ROUTER_ASUS_WL500W:
1473        case ROUTER_BUFFALO_WLAH_G54:
1474        case ROUTER_BUFFALO_WAPM_HP_AM54G54:
1475        case ROUTER_MICROSOFT_MN700:
1476                nvram_set("wan_ifname", "eth1");
1477                break;
1478
1479        case ROUTER_WRT150N:
1480                nvram_set("wan_ifname", "eth1");
1481                if (nvram_match("force_vlan_supp", "enabled")) {
1482                        nvram_set("lan_ifnames", "vlan0 eth2");
1483                        nvram_set("vlan0ports", "3 2 1 0 5*");
1484                        nvram_set("vlan1ports", "4 5"); //dummy
1485                        nvram_set("vlan0hwname", "et0");
1486                } else {
1487                        nvram_set("lan_ifnames", "eth0 eth2");
1488                }
1489                break;
1490
1491        case ROUTER_WRTSL54GS:
1492        case ROUTER_WRT160N:
1493                nvram_set("wan_ifname", "eth1");
1494                if (nvram_match("force_vlan_supp", "enabled")) {
1495                        nvram_set("lan_ifnames", "vlan0 eth2");
1496                        nvram_set("vlan0ports", "0 1 2 3 5*");
1497                        nvram_set("vlan1ports", "4 5"); //dummy
1498                        nvram_set("vlan0hwname", "et0");
1499                } else {
1500                        nvram_set("lan_ifnames", "eth0 eth2");
1501                }
1502                break;
1503
1504        case ROUTER_WRT54G1X:
1505                if (check_vlan_support()) {
1506                        nvram_set("lan_ifnames", "vlan0 eth2");
1507                        nvram_set("wan_ifname", "vlan1");
1508                }
1509                break;
1510
1511        case ROUTER_WRT350N:
1512        case ROUTER_WRT310N:
1513        case ROUTER_WRT600N:
1514                nvram_set("wan_ifname", "vlan2");
1515                break;
1516
1517        case ROUTER_WRT610N:
1518                nvram_set("wan_ifname", "vlan2");
1519                nvram_set("pci/1/1/ledbh0", "11");
1520                nvram_set("pci/1/1/ledbh1", "135");
1521                nvram_set("pci/1/2/ledbh0", "11");
1522                nvram_set("pci/1/2/ledbh2", "135");
1523                nvram_set("pci/1/1/boardflags2", "0x0400");
1524                nvram_set("pci/1/2/boardflags2", "0x0602");
1525
1526                if (!nvram_match("bootnv_ver", "6")) {
1527                        if (startswith
1528                            (nvram_safe_get("pci/1/1/macaddr"), "00:90:4C")
1529                            || startswith(nvram_safe_get("pci/1/2/macaddr"),
1530                                          "00:90:4C")) {
1531                                unsigned char mac[20];
1532                                strcpy(mac, nvram_safe_get("et0macaddr"));
1533                                MAC_ADD(mac);
1534                                MAC_ADD(mac);
1535                                nvram_set("pci/1/1/macaddr", mac);
1536                                MAC_ADD(mac);
1537                                nvram_set("pci/1/2/macaddr", mac);
1538                                need_reboot = 1;
1539                        }
1540                }
1541                break;
1542
1543#ifdef HAVE_BCMMODERN           
1544        case ROUTER_WRT610NV2:
1545                nvram_set("wan_ifname", "vlan2");
1546                nvram_set("vlan2hwname", "et0");
1547                nvram_set("pci/1/1/ledbh2", "8");
1548                nvram_set("sb/1/ledbh1", "8");
1549
1550                if (startswith(nvram_safe_get("pci/1/1/macaddr"), "00:90:4C")
1551                    || startswith(nvram_safe_get("pci/1/1/macaddr"),
1552                                  "00:90:4c")) {
1553                        unsigned char mac[20];
1554                        strcpy(mac, nvram_safe_get("et0macaddr"));
1555                        MAC_ADD(mac);
1556                        MAC_ADD(mac);
1557                        MAC_ADD(mac);
1558                        nvram_set("pci/1/1/macaddr", mac);
1559                        need_reboot = 1;
1560                }
1561                break;
1562#endif
1563
1564        case ROUTER_WRT300NV11:
1565        case ROUTER_BUFFALO_WZRG144NH:
1566                nvram_set("wan_ifname", "vlan1");
1567                break;
1568
1569        case ROUTER_ASUS_WL500G_PRE:
1570        case ROUTER_ASUS_WL700GE:
1571                nvram_set("lan_ifnames", "vlan0 eth2");
1572                nvram_set("wl0_ifname", "eth2");
1573                nvram_set("wan_ifname", "vlan1");       // fix for Asus WL500gPremium
1574                //
1575                // WAN problem.
1576                if (nvram_match("vlan1ports", "0 5u")) {
1577                        nvram_set("vlan1ports", "0 5");
1578                        need_reboot = 1;
1579                }
1580                break;
1581
1582        case ROUTER_ASUS_WL500GD:
1583        case ROUTER_ASUS_WL550GE:
1584                nvram_set("wl0_ifname", "eth1");
1585                break;
1586
1587        case ROUTER_BUFFALO_WLA2G54C:
1588        case ROUTER_WAP54G_V2:
1589        case ROUTER_VIEWSONIC_WAPBR_100:
1590        case ROUTER_USR_5430:
1591        case ROUTER_BUFFALO_WLI_TX4_G54HP:
1592        case ROUTER_BELKIN_F5D7230_V2000:
1593        case ROUTER_NETGEAR_WG602_V3:
1594        case ROUTER_NETGEAR_WG602_V4:
1595        case ROUTER_ASUS_330GE:
1596                nvram_set("lan_ifnames", "eth0 eth1");
1597                nvram_set("wl0_ifname", "eth1");
1598                nvram_set("wan_ifname", "eth2");        // map WAN port to
1599                // nonexistant interface
1600                if (nvram_match("wan_to_lan", "yes") && nvram_invmatch("wan_proto", "disabled"))        // =
1601                        //
1602                        // no
1603                        // lan
1604                {
1605                        nvram_set("lan_ifnames", "eth1");
1606                        nvram_set("wan_ifname", "eth0");
1607                }
1608                break;
1609
1610        case ROUTER_BELKIN_F5D7230_V3000:
1611                if (nvram_match("vlan1ports", "4 5u"))
1612                        nvram_set("vlan1ports", "4 5");
1613                break;
1614
1615        case ROUTER_DYNEX_DX_NRUTER:
1616                nvram_set("lan_ifnames", "vlan0 eth2");
1617                nvram_set("wan_ifname", "vlan1");
1618                nvram_set("wl0_ifname", "eth2");
1619                nvram_set("pci/1/1/ledbh0", "136");
1620                if (nvram_match("vlan1ports", "\"4 5*\"")) {
1621                        nvram_set("vlan0ports", "3 2 1 0 5*");
1622                        nvram_set("vlan1ports", "4 5");
1623                        need_reboot = 1;
1624                }
1625                break;
1626
1627        case ROUTER_DELL_TRUEMOBILE_2300_V2:    // we must fix cfe defaults
1628                // with CR added
1629                nvram_set("vlan0hwname", "et0");
1630                nvram_set("vlan1hwname", "et0");
1631                nvram_set("et0mdcport", "0");
1632                nvram_set("et0phyaddr", "30");
1633                nvram_set("gpio2", "adm_eecs");
1634                nvram_set("gpio3", "adm_eesk");
1635                nvram_set("gpio4", "adm_eedi");
1636                nvram_set("gpio5", "adm_rc");
1637                nvram_unset("gpio6");
1638                break;
1639
1640        case ROUTER_ASUS_WL520G:
1641        case ROUTER_ASUS_WL500G_PRE_V2:
1642        case ROUTER_WRT54G_V81:
1643                if (nvram_match("vlan1ports", "4 5u"))
1644                        nvram_set("vlan1ports", "4 5");
1645                break;
1646
1647        case ROUTER_ASUS_WL520GUGC:
1648                if (nvram_match("vlan1ports", "0 5u"))
1649                        nvram_set("vlan1ports", "0 5");
1650                if (!nvram_get("Fix_WL520GUGC_clock")) {
1651                        nvram_set("Fix_WL520GUGC_clock", "1");
1652                        need_reboot = 1;
1653                }
1654                break;
1655
1656        case ROUTER_NETGEAR_WGR614L:
1657        case ROUTER_NETGEAR_WGR614V9:
1658                if (nvram_match("vlan1ports", "0 5u"))
1659                        nvram_set("vlan1ports", "0 5");
1660                if (nvram_match("sromrev", "2")
1661                    && nvram_match("boardrev", "0x10")
1662                    && nvram_match("boardtype", "0x48E")) {
1663                        nvram_set("sromrev", "3");      // This is a fix for WGR614L NA - which has a wrong sromrev
1664                        need_reboot = 1;
1665                }
1666                break;
1667
1668        case ROUTER_ALLNET01:
1669                nvram_set("wl0_ifname", "eth1");
1670                if (nvram_match("vlan1ports", "5u"))    //correct bad parameters
1671                {
1672                        nvram_set("vlan1ports", "4 5");
1673                        nvram_set("vlan0ports", "0 1 2 3 5*");
1674                }
1675                break;
1676
1677        case ROUTER_LINKSYS_WTR54GS:
1678                eval("gpio", "enable", "3");    // prevent reboot loop on
1679                // reset
1680                break;
1681
1682        case ROUTER_WAP54G_V3:
1683                eval("gpio", "enable", "0");    // reset gpio 0 for reset
1684                // button
1685                // nvram_set ("vlan0ports", "1 5*");
1686                // nvram_set ("vlan1ports", "4 5");
1687                // if (nvram_match ("wan_to_lan", "yes") && nvram_invmatch
1688                // ("wan_proto", "disabled")) // = no lan
1689                // {
1690                // nvram_set ("vlan0ports", "4 5*");
1691                // nvram_set ("vlan1ports", "1 5");
1692                // }
1693                break;
1694
1695        }
1696
1697#if 0
1698        /*
1699         * fix il0macaddr to be lanmac+2
1700         */
1701        if (nvram_get("il0macaddr") == NULL)
1702                need_reboot = 1;
1703
1704        unsigned char mac[20];
1705
1706        if (nvram_match("port_swap", "1"))
1707                strcpy(mac, nvram_safe_get("et1macaddr"));
1708        else
1709                strcpy(mac, nvram_safe_get("et0macaddr"));
1710        MAC_ADD(mac);
1711        MAC_ADD(mac);
1712        nvram_set("il0macaddr", mac);
1713#endif
1714
1715        /*
1716         * set router's basic parameters
1717         */
1718        while (basic_params && basic_params->name) {
1719                nvram_set(basic_params->name, basic_params->value);
1720                basic_params++;
1721        }
1722
1723        /*
1724         * ifnames
1725         */
1726        strcpy(wanifname, nvram_safe_get("wan_ifname"));
1727        strcpy(wlifname, nvram_safe_get("wl0_ifname"));
1728
1729        /*
1730         * set wan_ifnames, pppoe_wan_ifname and pppoe_ifname
1731         */
1732        nvram_set("wan_ifname", wanifname);
1733        nvram_set("wan_ifname2", wanifname);
1734        nvram_set("wan_ifnames", wanifname);
1735        nvram_set("wan_default", wanifname);
1736        nvram_set("pppoe_wan_ifname", wanifname);
1737        nvram_set("pppoe_ifname", wanifname);
1738
1739        /*
1740         * MAC address sdjustments
1741         */
1742        switch (brand) {
1743        case ROUTER_ALLNET01:
1744        case ROUTER_BELKIN_F5D7231_V2000:
1745
1746                if (!nvram_match("no_sercom", "1")) {
1747                        //fix mac
1748                        unsigned char mac[6];
1749                        FILE *in = fopen("/dev/mtdblock/0", "rb");
1750
1751                        if (in != NULL) //special sercom mac address handling
1752                        {
1753                                fseek(in, 0x1ffa0, SEEK_SET);
1754                                fread(mac, 6, 1, in);
1755                                fclose(in);
1756                                char macstr[32];
1757
1758                                sprintf(macstr, "%02X:%02X:%02X:%02X:%02X:%02X",
1759                                        (int)mac[0] & 0xff, (int)mac[1] & 0xff,
1760                                        (int)mac[2] & 0xff, (int)mac[3] & 0xff,
1761                                        (int)mac[4] & 0xff, (int)mac[5] & 0xff);
1762                                nvram_set("et0macaddr", macstr);
1763                                eval("ifconfig", "eth0", "hw", "ether", macstr);
1764                        }
1765                }
1766                break;
1767        }
1768
1769        /*
1770         * Must have stuff
1771         */
1772        switch (brand) {
1773        case ROUTER_WRT320N:
1774                if (!nvram_match("reset_gpio", "5")) {
1775                        nvram_set("reset_gpio", "5");
1776                        need_reboot = 1;
1777                }
1778                break;
1779
1780        case ROUTER_MOTOROLA_V1:
1781                eval("gpio", "disable", "7");
1782                break;
1783
1784        case ROUTER_WRT54G_V8:
1785                nvram_set("reset_gpio", "7");
1786                break;
1787               
1788        case ROUTER_ASUS_WL700GE:
1789                eval("gpio", "enable", "3");  // POWER-enable, turns on power to HDD and switch leds
1790                break;
1791        }
1792
1793        /*
1794         * additional boardflags adjustment, etc...
1795         */
1796        switch (brand) {
1797        case ROUTER_BELKIN_F5D7231:
1798                if (nvram_match("boardflags", "0x388")
1799                    || nvram_match("boardflags", "0x0388")) {
1800                        nvram_set("boardflags", "0x0f58");
1801                        need_reboot = 1;
1802                }
1803                break;
1804
1805        case ROUTER_ASKEY_RT220XD:
1806                if (nvram_match("boardflags", "0x388")
1807                    || nvram_match("boardflags", "0x0388")) {
1808                        nvram_set("boardflags", "0x0208");
1809                        need_reboot = 1;
1810                }
1811                break;
1812
1813        case ROUTER_BUFFALO_WLI_TX4_G54HP:
1814                if (!nvram_match("buffalo_hp", "1")
1815                    && (nvram_match("boardflags", "0x1658")
1816                        || nvram_match("boardflags", "0x2658"))) {
1817                        nvram_set("buffalo_hp", "1");
1818#ifndef HAVE_BUFFALO            // if HAVE_BUFFALO not used to be FCC/CE
1819                        // valid
1820                        nvram_set("boardflags", "0x3658");      // enable high gain
1821                        // PA
1822                        need_reboot = 1;
1823#endif
1824                }
1825                break;
1826
1827        case ROUTER_BUFFALO_WHRG54S:    // for HP only
1828                if (!nvram_match("buffalo_hp", "1")
1829                    && nvram_match("boardflags", "0x1758")) {
1830                        nvram_set("buffalo_hp", "1");
1831#ifndef HAVE_BUFFALO            // if HAVE_BUFFALO not used to be FCC/CE
1832                        // valid
1833                        nvram_set("boardflags", "0x3758");      // enable high gain
1834                        // PA
1835                        need_reboot = 1;
1836#endif
1837                }
1838                break;
1839
1840        case ROUTER_WRTSL54GS:
1841                if (nvram_match("force_vlan_supp", "enabled")
1842                    && nvram_match("boardflags", "0x0018")) {
1843                        nvram_set("boardflags", "0x0118");      //enable lan vlans
1844                        need_reboot = 1;
1845                } else if (!nvram_match("force_vlan_supp", "enabled")
1846                           && nvram_match("boardflags", "0x0118")) {
1847                        nvram_set("boardflags", "0x0018");      //disable vlans
1848                        need_reboot = 1;
1849                }
1850                break;
1851
1852        case ROUTER_WRT150N:
1853        case ROUTER_WRT160N:
1854                if (nvram_match("force_vlan_supp", "enabled")
1855                    && nvram_match("boardflags", "0x0010")) {
1856                        nvram_set("boardflags", "0x0110");      //enable lan vlans
1857                        need_reboot = 1;
1858                } else if (!nvram_match("force_vlan_supp", "enabled")
1859                           && nvram_match("boardflags", "0x0110")) {
1860                        nvram_set("boardflags", "0x0010");      //disable vlans
1861                        need_reboot = 1;
1862                }
1863                break;
1864
1865        case ROUTER_NETGEAR_WNR834BV2:
1866        case ROUTER_NETGEAR_WNDR3300:
1867                if (nvram_match("force_vlan_supp", "enabled")
1868                    && nvram_match("boardflags", "0x10")) {
1869                        nvram_set("boardflags", "0x110");       //enable lan vlans
1870                        need_reboot = 1;
1871                } else if (!nvram_match("force_vlan_supp", "enabled")
1872                           && nvram_match("boardflags", "0x110")) {
1873                        nvram_set("boardflags", "0x10");        //disable vlans
1874                        need_reboot = 1;
1875                }
1876                break;
1877
1878        case ROUTER_NETGEAR_WG602_V4:
1879                if (nvram_match("boardflags", "0x650")) {
1880                        nvram_set("boardflags", "0x0458");
1881                        need_reboot = 1;
1882                }
1883                break;
1884
1885        case ROUTER_NETGEAR_WNR3500L:   //usb power fix (gpio 12)
1886                if (nvram_match("boardflags", "0x00001710")) {
1887                        nvram_set("boardflags", "0x00000710");
1888                        need_reboot = 1;
1889                }
1890                break;
1891               
1892        case ROUTER_ASUS_WL500G_PRE:
1893                if (nvram_match("sdram_init", "0x000b"))
1894                        nvram_set("sdram_init", "0x0009");
1895                break;
1896                       
1897        }
1898
1899        if (need_reboot) {
1900                nvram_commit();
1901                cprintf("Need reboot now .....\n");
1902                sys_reboot();
1903        }
1904
1905        /*
1906         * Modules
1907         */
1908        uname(&name);
1909
1910        snprintf(buf, sizeof(buf), "/lib/modules/%s", name.release);
1911        if (stat("/proc/modules", &tmp_stat) == 0 && stat(buf, &tmp_stat) == 0) {
1912                char module[80], *modules, *next;
1913
1914#ifdef HAVE_ACK
1915                nvram_set("portprio_support", "0");  // no portprio support in NEWD or BCMMODERN
1916#else
1917                nvram_set("portprio_support", "1");  // only switch drivers in VINT support this
1918#endif
1919
1920                if (check_vlan_support() && check_hw_type() != BCM5325E_CHIP) {
1921                        switch (brand) {
1922                        case ROUTER_WRT310N:
1923                        case ROUTER_WRT310NV2:
1924                        case ROUTER_WRT320N:
1925                        case ROUTER_WRT350N:
1926                        case ROUTER_WRT600N:
1927                        case ROUTER_WRT610N:
1928                        case ROUTER_WRT610NV2:
1929                        case ROUTER_WRT300NV11:
1930                        case ROUTER_BUFFALO_WZRG144NH:
1931                        case ROUTER_NETGEAR_WNR3500L:
1932                        case ROUTER_ASUS_RTN16:
1933                        case ROUTER_BELKIN_F7D3301:
1934                        case ROUTER_BELKIN_F7D4301:
1935                        case ROUTER_BELKIN_F5D8235V3:
1936                        case ROUTER_LINKSYS_E3200:
1937                        case ROUTER_LINKSYS_E4200:
1938                        case ROUTER_ASUS_RTN66:
1939                        case ROUTER_NETGEAR_WNDR4000:
1940                                nvram_set("portprio_support", "0");
1941#ifdef HAVE_BCMMODERN
1942                                modules = "bcm57xx switch-core switch-robo";
1943#else
1944                                modules = "bcm57xxlsys switch-core switch-robo";
1945#endif
1946                                break;
1947                        case ROUTER_LINKSYS_WRT55AG:
1948                        case ROUTER_MOTOROLA:
1949                        case ROUTER_BUFFALO_WBR2G54S:
1950                        case ROUTER_DELL_TRUEMOBILE_2300_V2:
1951                                modules =
1952                                    nvram_invmatch("ct_modules",
1953                                                   "") ?
1954                                    nvram_safe_get("ct_modules")
1955                                    : "switch-core switch-adm";
1956                                break;
1957
1958                        case ROUTER_WRT54G_V8:
1959                        case ROUTER_WRT54G_V81:
1960                        case ROUTER_LINKSYS_WRH54G:
1961                        case ROUTER_ASUS_WL520G:
1962                        case ROUTER_ASUS_WL520GUGC:
1963                                modules =
1964                                    nvram_invmatch("ct_modules",
1965                                                   "") ?
1966                                    nvram_safe_get("ct_modules")
1967                                    : "switch-core switch-robo";
1968                                break;
1969
1970                        case ROUTER_WRT54G1X:
1971                        case ROUTER_WRT54G:
1972                                insmod("switch-core");
1973                                if (insmod("switch-robo"))
1974                                        insmod("switch-adm");
1975                                break;
1976
1977                        case ROUTER_RT480W:
1978                        case ROUTER_BUFFALO_WLI2_TX1_G54:
1979                                modules =
1980                                    nvram_invmatch("ct_modules",
1981                                                   "") ?
1982                                    nvram_safe_get("ct_modules")
1983                                    : "";
1984                                insmod("switch-core");
1985                                if (insmod("switch-robo"))
1986                                        insmod("switch-adm");
1987                                break;
1988
1989                        case ROUTER_WRT54G3G:
1990                                modules =
1991                                    nvram_invmatch("ct_modules",
1992                                                   "") ?
1993                                    nvram_safe_get("ct_modules")
1994                                    :
1995                                    "switch-core switch-robo pcmcia_core yenta_socket ds serial_cs usbcore usb-ohci usbserial sierra";
1996                                break;
1997                        case ROUTER_ASUS_RTN10:
1998                        case ROUTER_ASUS_RTN10U:
1999                        case ROUTER_ASUS_RTN53:
2000                        case ROUTER_NETCORE_NW715P:
2001                        case ROUTER_ASUS_RTN12B:
2002                        case ROUTER_LINKSYS_E1000V2:
2003                        case ROUTER_LINKSYS_E2500:
2004                                nvram_set("portprio_support", "0");
2005                                modules = "";
2006                                break;
2007                        default:
2008                                modules =
2009                                    nvram_invmatch("ct_modules",
2010                                                   "") ?
2011                                    nvram_safe_get("ct_modules")
2012                                    : "switch-core switch-robo";
2013                                break;
2014                        }
2015                } else {
2016                        switch (brand) {
2017                        case ROUTER_WRT310N:
2018                        case ROUTER_WRT310NV2:
2019                        case ROUTER_WRT320N:
2020                        case ROUTER_WRT350N:
2021                        case ROUTER_WRT600N:
2022                        case ROUTER_WRT610N:
2023                        case ROUTER_WRT610NV2:
2024                        case ROUTER_WRT300NV11:
2025                        case ROUTER_BUFFALO_WZRG144NH:
2026                        case ROUTER_NETGEAR_WNR3500L:
2027                        case ROUTER_ASUS_RTN16:
2028                        case ROUTER_ASUS_RTN66:
2029                        case ROUTER_LINKSYS_E3200:
2030                        case ROUTER_LINKSYS_E4200:
2031                        case ROUTER_NETGEAR_WNDR4000:
2032                                nvram_set("portprio_support", "0");
2033#ifdef HAVE_BCMMODERN
2034                                modules = "bcm57xx switch-core switch-robo";
2035#else
2036                                modules = "bcm57xxlsys switch-core switch-robo";
2037#endif
2038                                break;
2039                        case ROUTER_LINKSYS_WRT55AG:
2040                                modules =
2041                                    nvram_invmatch("ct_modules",
2042                                                   "") ?
2043                                    nvram_safe_get("ct_modules")
2044                                    : "switch-core switch-adm";
2045
2046                                break;
2047                        case ROUTER_ASUS_WL500GD:
2048                        case ROUTER_ASUS_WL550GE:
2049                                modules =
2050                                    nvram_invmatch("ct_modules",
2051                                                   "") ?
2052                                    nvram_safe_get("ct_modules")
2053                                    : "switch-core switch-robo";
2054                                break;
2055                        case ROUTER_BUFFALO_WZRRSG54:
2056                                nvram_set("portprio_support", "0");
2057                                modules =
2058                                    nvram_invmatch("ct_modules",
2059                                                   "") ?
2060                                    nvram_safe_get("ct_modules")
2061                                    : "";
2062                                break;
2063                        case ROUTER_WRT54G3G:
2064                                if (check_vlan_support())
2065                                        modules =
2066                                            nvram_invmatch("ct_modules",
2067                                                           "") ?
2068                                            nvram_safe_get("ct_modules") :
2069                                            "switch-core switch-robo pcmcia_core yenta_socket ds";
2070                                else {
2071                                        nvram_set("portprio_support", "0");
2072
2073                                        modules =
2074                                            nvram_invmatch("ct_modules",
2075                                                           "") ?
2076                                            nvram_safe_get("ct_modules") :
2077                                            "pcmcia_core yenta_socket ds";
2078                                }
2079                                break;
2080                        case ROUTER_ASUS_RTN10:
2081                        case ROUTER_ASUS_RTN10U:
2082                        case ROUTER_ASUS_RTN53:
2083                        case ROUTER_NETCORE_NW715P:
2084                        case ROUTER_ASUS_RTN12B:
2085                        case ROUTER_LINKSYS_E1000V2:
2086                        case ROUTER_LINKSYS_E2500:
2087                                nvram_set("portprio_support", "0");
2088                                modules = "";
2089                                break;
2090                               
2091                        default:
2092#ifndef HAVE_BCMMODERN
2093                                if (check_vlan_support())
2094                                        modules =
2095                                            nvram_invmatch("ct_modules",
2096                                                           "") ?
2097                                            nvram_safe_get("ct_modules") :
2098                                            "switch-core switch-robo";
2099                                else
2100#endif
2101                                 {
2102                                        nvram_set("portprio_support", "0");
2103                                        modules =
2104                                            nvram_invmatch("ct_modules",
2105                                                           "") ?
2106                                            nvram_safe_get("ct_modules") : "switch-core switch-robo";
2107                                }
2108                                break;
2109                        }
2110                }
2111//      fprintf( "insmod %s\n", modules );
2112
2113                foreach(module, modules, next) {
2114#ifdef HAVE_MACBIND
2115                        if (nvram_match("et0macaddr", MACBRAND))
2116                                insmod(module);
2117#else
2118
2119                        fprintf(stderr, "loading %s\n", module);
2120                        insmod(module);
2121                        cprintf("done\n");
2122#endif
2123                }
2124
2125                if (check_hw_type() == BCM4702_CHIP)
2126                        insmod("diag");
2127
2128                loadWlModule();
2129
2130        }
2131        /*
2132         * Set a sane date
2133         */
2134        stime(&tm);
2135
2136        led_control(LED_POWER, LED_ON);
2137        led_control(LED_SES, LED_OFF);
2138        led_control(LED_SES2, LED_OFF);
2139        led_control(LED_BRIDGE, LED_OFF);
2140        led_control(LED_WLAN0, LED_OFF);
2141        led_control(LED_WLAN1, LED_OFF);
2142        led_control(LED_CONNECTED, LED_OFF);
2143
2144        if (brand == ROUTER_WRT54G3G) {
2145                eval("cardmgr");
2146        }
2147
2148        cprintf("done\n");
2149        return;
2150
2151}
2152
2153static int check_nv(char *name, char *value)
2154{
2155        int ret = 0;
2156
2157        if (nvram_match("manual_boot_nv", "1"))
2158                return 0;
2159
2160        if (!nvram_get(name)) {
2161                cprintf("ERR: Cann't find %s !.......................\n", name);
2162                nvram_set(name, value);
2163                ret++;
2164        } else if (nvram_invmatch(name, value)) {
2165                cprintf("ERR: The %s is %s, not %s !.................\n", name,
2166                        nvram_safe_get(name), value);
2167                nvram_set(name, value);
2168                ret++;
2169        }
2170
2171        return ret;
2172}
2173
2174int check_cfe_nv(void)
2175{
2176        int ret = 0;
2177
2178        switch (getRouterBrand()) {
2179        case ROUTER_BUFFALO_WZRRSG54:
2180                ret += check_nv("lan_hwnames", "et0 wl0");
2181                ret += check_nv("wan_hwname", "et1");
2182                ret += check_nv("vlans", "0");
2183                break;
2184        case ROUTER_BUFFALO_WBR2G54S:
2185                ret += check_nv("aa0", "3");
2186
2187                ret += check_nv("pa0itssit", "62");
2188                ret += check_nv("pa0b0", "0x1136");
2189                ret += check_nv("pa0b1", "0xfb93");
2190                ret += check_nv("pa0b2", "0xfea5");
2191                ret += check_nv("wl0gpio2", "0");
2192                ret += check_nv("wl0gpio3", "0");
2193                ret += check_nv("cctl", "0");
2194                ret += check_nv("ccode", "0");
2195                break;
2196#ifndef HAVE_BUFFALO
2197
2198        case ROUTER_WRT54G:
2199        case ROUTER_WRT54G_V8:
2200        case ROUTER_WRT54G_V81:
2201                ret += check_nv("aa0", "3");
2202                /*
2203                 * if (check_hw_type () == BCM5352E_CHIP || check_hw_type () ==
2204                 * BCM5354G_CHIP) ret += check_nv ("ag0", "0x02"); else ret +=
2205                 * check_nv ("ag0", "255");
2206                 */
2207                if (check_hw_type() == BCM5325E_CHIP) {
2208                        /*
2209                         * Lower the DDR ram drive strength , the value will be
2210                         * stable for all boards Latency 3 is more stable for all ddr
2211                         * 20050420 by honor
2212                         */
2213
2214                        ret += check_nv("sdram_init", "0x010b");
2215                        ret += check_nv("sdram_config", "0x0062");
2216
2217                        if (nvram_match("clkfreq", "200")
2218                            && nvram_match("overclocking", "200")) {
2219                                ret += check_nv("clkfreq", "216");
2220                                nvram_set("overclocking", "216");
2221                        }
2222
2223                        if (ret) {
2224                                nvram_set("sdram_ncdl", "0x0");
2225
2226                        }
2227                        ret += check_nv("pa0itssit", "62");
2228                        ret += check_nv("pa0b0", "0x15eb");
2229                        ret += check_nv("pa0b1", "0xfa82");
2230                        ret += check_nv("pa0b2", "0xfe66");
2231                } else if (check_hw_type() == BCM5354G_CHIP) {
2232                        ret += check_nv("pa0itssit", "62");
2233                        ret += check_nv("pa0b0", "0x1326");
2234                        ret += check_nv("pa0b1", "0xFB51");
2235                        ret += check_nv("pa0b2", "0xFE87");
2236                        ret += check_nv("reset_gpio", "7");
2237                } else if (check_hw_type() == BCM4705_BCM5397_EWC_CHIP) {
2238                        // nothing to do
2239                } else if (check_hw_type() == BCM4704_BCM5325F_CHIP) {
2240                        // nothing to do
2241                } else {
2242                        ret += check_nv("pa0itssit", "62");
2243                        ret += check_nv("pa0b0", "0x170c");
2244                        ret += check_nv("pa0b1", "0xfa24");
2245                        ret += check_nv("pa0b2", "0xfe70");
2246                }
2247
2248                // ret += check_nv("gpio2", "adm_eecs");
2249                // ret += check_nv("gpio3", "adm_eesk");
2250                // ret += check_nv("gpio5", "adm_eedi");
2251                // ret += check_nv("gpio6", "adm_rc");
2252
2253                ret += check_nv("wl0gpio2", "0");
2254                ret += check_nv("wl0gpio3", "0");
2255
2256                ret += check_nv("cctl", "0");
2257                ret += check_nv("ccode", "0");
2258                break;
2259#endif
2260        }
2261        if (ret) {
2262                cprintf
2263                    ("Some error found, we want to reboot!.....................\n");
2264                nvram_commit();
2265                sys_reboot();
2266        }
2267
2268        return ret;
2269}
2270
2271int check_pmon_nv(void)
2272{
2273        return 0;
2274}
2275
2276void start_overclocking(void)
2277{
2278#ifdef HAVE_OVERCLOCKING
2279        cprintf("Overclocking started\n");
2280
2281        int rev = cpu_plltype();
2282
2283        if (rev == 0)
2284                return;         // unsupported
2285
2286        char *ov = nvram_get("overclocking");
2287
2288        if (ov == NULL)
2289                return;
2290        int clk = atoi(ov);
2291
2292        if (nvram_get("clkfreq") == NULL)
2293                return;         // unsupported
2294
2295        char *pclk = nvram_safe_get("clkfreq");
2296        char dup[64];
2297
2298        strcpy(dup, pclk);
2299        int i;
2300
2301        for (i = 0; i < strlen(dup); i++)
2302                if (dup[i] == ',')
2303                        dup[i] = 0;
2304        int cclk = atoi(dup);
2305
2306        if (clk == cclk) {
2307                cprintf("clkfreq %d MHz identical with new setting\n", clk);
2308                return;         // clock already set
2309        }
2310
2311        int set = 1;
2312        int clk2 = 0;
2313        int clk2_1 = 0;
2314        int clk2_2 = 0;
2315        char clkfr[16];
2316
2317        switch (clk) {
2318        case 150:
2319                clk2 = 75;
2320                // nvram_set ("clkfreq", "150,75");
2321//              clk2_1 = 75;
2322//              clk2_2 = 33;
2323//              // nvram_set ("clkfreq", "150,75,33");
2324                break;
2325        case 183:
2326                clk2 = 92;
2327                // nvram_set ("clkfreq", "183,92");
2328                break;
2329        case 187:
2330                clk2 = 94;
2331                // nvram_set ("clkfreq", "187,94");
2332                break;
2333        case 192:
2334                clk2 = 96;
2335                // nvram_set ("clkfreq", "192,96");
2336                break;
2337        case 198:
2338                clk2 = 98;
2339                // nvram_set ("clkfreq", "198,98");
2340                break;
2341        case 200:
2342                clk2 = 100;
2343                // nvram_set ("clkfreq", "200,100");
2344                clk2_1 = 100;
2345                clk2_2 = 33;
2346                // nvram_set ("clkfreq", "200,100,33");
2347                break;
2348        case 216:
2349                clk2 = 108;
2350                // nvram_set ("clkfreq", "216,108");
2351                break;
2352        case 225:
2353                clk2 = 113;
2354                // nvram_set ("clkfreq", "225,113");
2355                break;
2356        case 228:
2357                clk2 = 114;
2358                // nvram_set ("clkfreq", "228,114");
2359                break;
2360        case 233:
2361                clk2 = 116;
2362                // nvram_set ("clkfreq", "233,116");
2363                break;
2364        case 237:
2365                clk2 = 119;
2366                // nvram_set ("clkfreq", "237,119");
2367                break;
2368        case 240:
2369                clk2 = 120;
2370                // nvram_set ("clkfreq", "240,120");
2371                clk2_1 = 120;
2372                clk2_2 = 33;
2373                // nvram_set ("clkfreq", "240,120,33");
2374                break;
2375        case 250:
2376                clk2 = 125;
2377                // nvram_set ("clkfreq", "250,125");
2378                break;
2379        case 252:
2380                clk2 = 126;
2381                // nvram_set ("clkfreq", "252,126");
2382                clk2_1 = 126;
2383                clk2_2 = 33;
2384                // nvram_set ("clkfreq", "252,126,33");
2385                break;
2386        case 264:
2387                clk2 = 132;
2388                // nvram_set ("clkfreq", "264,132");
2389                clk2_1 = 132;
2390                clk2_2 = 33;
2391                // nvram_set ("clkfreq", "264,132,33");
2392                break;
2393        case 280:
2394                clk2 = 120;
2395                // nvram_set ("clkfreq", "280,120");
2396                break;
2397//      case 288:
2398//              clk2_1 = 144;
2399//              clk2_2 = 32;
2400//              // nvram_set ("clkfreq", "288,144,32");
2401//              break;
2402        case 300:
2403                clk2 = 120;
2404                clk2_1 = 150;
2405                clk2_2 = 37;
2406                // nvram_set ("clkfreq", "300,150,37");
2407                break;
2408        case 330:
2409                clk2_1 = 132;
2410                clk2_2 = 33;
2411                // nvram_set ("clkfreq", "330,132,33");
2412                break;
2413        default:
2414                set = 0;
2415                break;
2416        }
2417
2418        if (set) {
2419                cprintf
2420                    ("clock frequency adjusted from %d to %d, reboot needed\n",
2421                     cclk, clk);
2422                if (rev == 2)
2423                        sprintf(clkfr, "%d,%d,%d", clk, clk2_1, clk2_2);
2424                else
2425                        sprintf(clkfr, "%d,%d", clk, clk2);
2426                nvram_set("clkfreq", clkfr);
2427                nvram_commit();
2428                cprintf("Overclocking done, rebooting...\n");
2429                sys_reboot();
2430        }
2431#endif
2432}
2433
2434char *enable_dtag_vlan(int enable)
2435{
2436        int donothing = 0;
2437
2438        nvram_set("fromvdsl", "1");
2439        if (nvram_match("vdsl_state", "1") && enable)
2440                donothing = 1;
2441        if ((nvram_match("vdsl_state", "0")
2442             || nvram_match("vdsl_state", "")) && !enable)
2443                donothing = 1;
2444        if (enable)
2445                nvram_set("vdsl_state", "1");
2446        else
2447                nvram_set("vdsl_state", "0");
2448
2449        char *eth = "eth0";
2450#ifdef HAVE_MADWIFI
2451                eth = "eth0";
2452#else           
2453
2454        FILE *in = fopen("/proc/switch/eth1/reset", "rb");      // this
2455
2456        // condition
2457        // fails
2458        // almost.
2459        // just one
2460        // router
2461        // (DLINK
2462        // DIR-330)
2463        // requires
2464        // it
2465       
2466        if (in) {
2467                eth = "eth1";
2468                fclose(in);
2469        } else {
2470                FILE *in = fopen("/proc/switch/eth2/reset", "rb");
2471                if (in) {
2472                        eth = "eth2";
2473                        fclose(in);
2474                } else
2475                        eth = "eth0";
2476        }
2477#endif
2478
2479        char *lan_vlan = nvram_safe_get("lan_ifnames");
2480        char *wan_vlan = nvram_safe_get("wan_ifname"); 
2481        char *vlan_lan_ports = NULL;
2482        char *vlan_wan_ports = NULL;
2483        int lan_vlan_num = 0;
2484        int wan_vlan_num = 1;
2485       
2486
2487        if(startswith(lan_vlan, "vlan0")) {
2488                lan_vlan_num = 0;
2489        }
2490        else if(startswith(lan_vlan, "vlan1")) {
2491                lan_vlan_num = 1;
2492        }
2493        else if(startswith(lan_vlan, "vlan2")) {
2494                lan_vlan_num = 2;
2495        }
2496        else
2497                return eth;
2498       
2499        if(startswith(wan_vlan, "vlan0")) {
2500                wan_vlan_num = 0;
2501        }
2502        else if(startswith(wan_vlan, "vlan1")) {
2503                wan_vlan_num = 1;
2504        }
2505        else if(startswith(wan_vlan, "vlan2")) {
2506                wan_vlan_num = 2;
2507        }
2508        else
2509                return eth;
2510       
2511        if (wan_vlan_num == lan_vlan_num)
2512                return eth;
2513               
2514        vlan_lan_ports = nvram_nget("vlan%dports", lan_vlan_num);
2515        vlan_wan_ports = nvram_nget("vlan%dports", wan_vlan_num);
2516                       
2517       
2518        char *vlan7ports = "4t 5";;
2519               
2520        if (!strcmp(vlan_wan_ports, "4 5"))
2521                vlan7ports = "4t 5";
2522        else if (!strcmp(vlan_wan_ports, "0 5"))
2523                vlan7ports = "0t 5";
2524        else if (!strcmp(vlan_wan_ports, "1 5"))
2525                vlan7ports = "1t 5";
2526        else if (!strcmp(vlan_wan_ports, "4 8"))
2527                vlan7ports = "4t 8";
2528        else if (!strcmp(vlan_wan_ports, "0 8"))
2529                vlan7ports = "0t 8";
2530
2531        if (!donothing) {
2532                writevaproc("1","/proc/switch/%s/reset",eth);
2533                if (enable) {
2534                        fprintf(stderr, "enable vlan port mapping %s/%s\n",
2535                                vlan_lan_ports, vlan7ports);
2536                        if (!nvram_match("dtag_vlan8", "1")
2537                            || nvram_match("wan_vdsl", "0")) {
2538                                writevaproc(vlan_lan_ports,"/proc/switch/%s/vlan/%d/ports", eth, lan_vlan_num);
2539                                start_setup_vlans();
2540                                writevaproc(" ","/proc/switch/%s/vlan/%d/ports", eth, wan_vlan_num);
2541                                writevaproc(vlan7ports,"/proc/switch/%s/vlan/7/ports", eth);
2542                        } else {
2543                                writevaproc(vlan_lan_ports,"/proc/switch/%s/vlan/%d/ports", eth, lan_vlan_num);
2544                                start_setup_vlans();
2545                                writevaproc("","/proc/switch/%s/vlan/%d/ports", eth, wan_vlan_num);
2546                                writevaproc(vlan7ports,"/proc/switch/%s/vlan/7/ports", eth);
2547                                writevaproc(vlan7ports,"/proc/switch/%s/vlan/8/ports", eth);
2548                        }
2549                } else {
2550                        fprintf(stderr, "disable vlan port mapping %s/%s\n",vlan_lan_ports, vlan_wan_ports);
2551                        writevaproc(" ","/proc/switch/%s/vlan/7/ports", eth);
2552                        writevaproc(" ","/proc/switch/%s/vlan/8/ports", eth);
2553                        writevaproc(vlan_lan_ports,"/proc/switch/%s/vlan/%d/ports", eth, lan_vlan_num);
2554                        writevaproc(vlan_wan_ports,"/proc/switch/%s/vlan/%d/ports", eth, wan_vlan_num);
2555                        start_setup_vlans();
2556                }
2557        }
2558        nvram_set("fromvdsl", "0");
2559        return eth;
2560}
2561
2562void start_dtag(void)
2563{
2564        enable_dtag_vlan(1);
2565}
Note: See TracBrowser for help on using the repository browser.