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

Last change on this file since 19039 was 19039, checked in by BrainSlayer, 13 months ago

led behaviour

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