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

Last change on this file since 18848 was 18848, checked in by eko, 15 months ago

Linksys-Cisco E900 support

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