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

Last change on this file since 9354 was 9354, checked in by eko, 5 years ago

ROUTER_NETGEAR_WG602_V4 support

File size: 36.8 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
43#include <bcmnvram.h>
44#include <shutils.h>
45#include <utils.h>
46#include <bcmdevs.h>
47#include <cymac.h>
48
49static void
50check_brcm_cpu_type (void)
51{
52  FILE *fcpu;
53  char cpu_type[20];
54  char type2[30];
55
56  fcpu = fopen ("/proc/cpuinfo", "r");
57
58  if (fcpu == NULL)
59    cprintf ("Open /proc/cpuinfo fail...0\n");
60  else
61    {
62      char buf[500];
63      fgets (buf, 500, fcpu);
64      fscanf (fcpu, "%s %s %s %s %s", buf, buf, buf, cpu_type, type2);
65      if (!strcmp (type2, "BCM4704"))
66        {
67          nvram_set ("cpu_type", cpu_type);
68          fclose (fcpu);
69          return;
70        }
71      if (!strcmp (type2, "BCM4712"))
72        {
73          nvram_set ("cpu_type", cpu_type);
74          fclose (fcpu);
75          return;
76        }
77      if (!strcmp (type2, "BCM4702"))
78        {
79          nvram_set ("cpu_type", cpu_type);
80          fclose (fcpu);
81          return;
82        }
83      if (!strcmp (type2, "BCM3302"))
84        {
85          nvram_set ("cpu_type", cpu_type);
86          fclose (fcpu);
87          return;
88        }
89      fgets (buf, 500, fcpu);
90      fscanf (fcpu, "%s %s %s %s %s", buf, buf, buf, cpu_type, type2);
91      //fprintf(stderr, "cpu_type : %s\n", cpu_type);
92      fclose (fcpu);
93      if (!strcmp (cpu_type, "BCM4710") || !strcmp (cpu_type, "BCM4702"))
94        {
95          cprintf ("We got BCM4702 board...\n");
96          nvram_set ("cpu_type", cpu_type);
97        }
98      else if (!strcmp (cpu_type, "BCM3302") || !strcmp (cpu_type, "BCM4712"))
99        {
100          cprintf ("We got BCM4712 board...\n");
101          nvram_set ("cpu_type", cpu_type);
102        }
103      else
104        {
105          cprintf ("We got unknown board...\n");
106          nvram_set ("cpu_type", cpu_type);
107        }
108    }
109
110
111
112}
113
114static void
115loadWlModule (void)             //set wled params, get boardflags, set afterburner bit, load wl, unset afterburner bit
116{
117
118  int brand = getRouterBrand ();
119  char macbuf[32];
120  char eaddr[32];
121
122#ifdef HAVE_MSSID               //v24
123
124#ifndef HAVE_BUFFALO
125  nvram_set ("pa0maxpwr", "251");       //force pa0maxpwr to be 251
126#endif
127
128  if (check_hw_type () == BCM4702_CHIP)
129    nvram_unset ("wl0_abenable");
130  else
131    nvram_set ("wl0_abenable", "1");
132
133
134  switch (brand)
135    {
136    case ROUTER_LINKSYS_WRH54G:
137      nvram_set ("wl0gpio0", "135");
138      break;
139    case ROUTER_BUFFALO_WZRRSG54:
140      nvram_unset ("wl0_abenable");
141      break;
142    case ROUTER_ASUS_WL550GE:
143      nvram_set ("wl0gpio1", "0");
144      nvram_set ("wl0gpio2", "0");
145      break;
146    case ROUTER_ASUS_WL500W:
147    case ROUTER_WRT54G:
148    case ROUTER_WRT54G_V8:
149    case ROUTER_MOTOROLA:
150    case ROUTER_BUFFALO_WLAG54C:
151    case ROUTER_NETGEAR_WG602_V3:
152    case ROUTER_RT480W:
153      nvram_set ("wl0gpio0", "136");
154      break;
155    case ROUTER_WAP54G_V3:
156      nvram_set ("wl0gpio0", "0");
157      nvram_set ("wl0gpio2", "255");
158      nvram_set ("wl0gpio3", "255");
159      nvram_set ("wl0gpio5", "136");
160      break;
161    case ROUTER_ASUS_WL520GUGC:
162      nvram_set ("wl0gpio0", "0");
163      nvram_set ("wl0gpio1", "136");
164      nvram_set ("wl0gpio2", "0");
165      nvram_set ("wl0gpio3", "0");
166      break;
167    case ROUTER_LINKSYS_WTR54GS:
168    case ROUTER_WAP54G_V1:
169      nvram_set ("wl0gpio0", "136");
170      nvram_set ("wl0gpio1", "0");
171      nvram_set ("wl0gpio2", "0");
172      nvram_set ("wl0gpio3", "0");
173      break;
174    case ROUTER_BUFFALO_WBR54G:
175    case ROUTER_BUFFALO_WBR2G54S:
176    case ROUTER_WRT150N:
177    case ROUTER_WRT160N:
178    case ROUTER_WRT300N:
179    case ROUTER_WRT600N:
180    case ROUTER_WRT350N:
181      nvram_set ("wl0gpio0", "8");
182      break;
183    case ROUTER_BUFFALO_WHRG54S:
184    case ROUTER_BUFFALO_WLI_TX4_G54HP:
185      nvram_set ("wl0gpio2", "136");
186      break;
187    case ROUTER_BUFFALO_WLA2G54C:
188      nvram_set ("wl0gpio0", "0");
189      nvram_set ("wl0gpio5", "136");
190      break;
191    case ROUTER_ASUS_WL500GD:
192    case ROUTER_ASUS_WL500G_PRE:
193      nvram_unset ("wl0gpio0");
194      break;
195    case ROUTER_BELKIN_F5D7230_V2000:
196    case ROUTER_BELKIN_F5D7231:
197      nvram_set ("wl0gpio3", "136");
198      break;
199    }
200#else //v23
201
202  switch (brand)
203    {
204    case ROUTER_ASUS_WL550GE:
205      nvram_set ("wl0gpio1", "0");
206      nvram_set ("wl0gpio2", "0");
207      break;
208    case ROUTER_BUFFALO_WZRRSG54:
209    case ROUTER_BUFFALO_WBR54G:
210    case ROUTER_BUFFALO_WBR2G54S:
211      nvram_set ("wl0gpio0", "130");
212      break;
213    case ROUTER_MOTOROLA:
214    case ROUTER_WAP54G_V1:
215    case ROUTER_NETGEAR_WG602_V3:
216    case ROUTER_RT480W:
217      nvram_set ("wl0gpio0", "2");
218      break;
219    case ROUTER_BUFFALO_WLA2G54C:
220      nvram_set ("wl0gpio0", "0");
221      nvram_set ("wl0gpio5", "2");
222      break;
223    case ROUTER_WAP54G_V3:
224      nvram_set ("wl0gpio0", "0");
225      nvram_set ("wl0gpio2", "255");
226      nvram_set ("wl0gpio3", "255");
227      nvram_set ("wl0gpio5", "2");
228      break;
229    case ROUTER_ASUS_WL500GD:
230      nvram_unset ("wl0gpio0");
231      break;
232    case ROUTER_BELKIN_F5D7230_V2000:
233      nvram_set ("wl0gpio3", "2");
234      break;
235    }
236#endif
237
238  int boardflags;
239
240  switch (brand)
241    {
242    case ROUTER_WRT150N:
243    case ROUTER_WRT150NV11:
244    case ROUTER_WRT160N:
245    case ROUTER_WRT310N:
246    case ROUTER_WRT300N:
247    case ROUTER_WRT300NV11:
248    case ROUTER_WRT350N:
249    case ROUTER_BUFFALO_WZRG144NH:
250    case ROUTER_BUFFALO_WZRG300N:
251    case ROUTER_NETGEAR_WNR834B:
252    case ROUTER_NETGEAR_WNR834BV2:
253    case ROUTER_ASUS_WL500W:
254      eval ("insmod", "wl");    //load module
255      break;
256    case ROUTER_WRT600N:
257      eval ("insmod", "wl");    //load module
258      wl_hwaddr ("eth1", macbuf);
259      ether_etoa ((uchar *) macbuf, eaddr);
260      nvram_set ("wl0_hwaddr", eaddr);
261      MAC_SUB (eaddr);
262      if (!nvram_match ("et0macaddr", eaddr))
263        {
264          nvram_set ("et0macaddr", eaddr);
265          nvram_commit ();
266          kill (1, SIGTERM);
267          exit (0);
268        }
269      wl_hwaddr ("eth2", macbuf);
270      ether_etoa ((uchar *) macbuf, eaddr);
271      nvram_set ("wl1_hwaddr", eaddr);
272      break;
273    default:
274      boardflags = strtoul (nvram_safe_get ("boardflags"), NULL, 0);
275      fprintf (stderr, "boardflags are 0x%04X\n", boardflags);
276      if (boardflags == 0)      //we can try anyway
277        {
278          nvram_set ("boardflags", "0x0200");
279          eval ("insmod", "wl");        //load module
280          nvram_unset ("boardflags");
281        }
282      else if (boardflags & BFL_AFTERBURNER)    //ab flag already set
283        {
284          eval ("insmod", "wl");        //load module
285        }
286      else                      //ab flag not set
287        {
288          char bf[16];
289          sprintf (bf, "0x%04X", boardflags);
290          boardflags |= BFL_AFTERBURNER;
291          fprintf (stderr, "enable Afterburner, boardflags are 0x%04X\n",
292                   boardflags);
293          char ab[16];
294          sprintf (ab, "0x%04X", boardflags);
295          char *oldvalue = nvram_get ("boardflags");    // use the string for restoring since the Buffalo WZR-RS-G54 does await a 0x10 in the bootloader, otherwise the nvram gets deleted
296          nvram_set ("boardflags", ab); //set boardflags with AfterBurner bit on
297          eval ("insmod", "wl");        //load module
298          nvram_set ("boardflags", oldvalue);   //set back to original
299        }
300
301    }
302#ifdef HAVE_MADWIFI
303  eval ("insmod", "ath_hal");
304  eval ("insmod", "ath_pci");
305#endif
306  return;
307}
308
309
310char wanifname[8], wlifname[8];
311
312#define BCM4712_CPUTYPE "0x4712"
313
314static void
315setup_4712 (void)
316{
317  uint boardflags = strtoul (nvram_safe_get ("boardflags"), NULL, 0);
318  if (nvram_match ("cpu_type", BCM4712_CPUTYPE) ||
319      nvram_match ("cpu_type", "BCM3302") ||
320      nvram_match ("cpu_type", "BCM4712"))
321    {
322      if (boardflags & BFL_ENETVLAN)
323        {
324          cprintf ("setup_4712(): Enable VLAN\n");
325          //nvram_set("setup_4712","1");
326          strcpy (wanifname, "vlan1");
327          strcpy (wlifname, "eth1");
328          if (!strcmp (nvram_safe_get ("wan_ifname"), "eth1"))
329            {
330              //nvram_set("setup_4712","1-1");
331              nvram_set ("wan_ifname", "vlan1");
332              nvram_set ("wan_ifnames", "vlan1");
333            }
334          if (!strstr (nvram_safe_get ("lan_ifnames"), "vlan0"))
335            {
336              //nvram_set("setup_4712","1-2");
337              nvram_set ("lan_ifnames", "vlan0 eth1");
338              nvram_set ("vlan0hwname", "et0");
339              nvram_set ("vlan1hwname", "et0");
340              nvram_set ("wl0_ifname", "eth1");
341//              nvram_set ("need_commit","1");
342            }
343        }                       // VLAN enabled
344      else
345        {
346          //nvram_set("setup_4712","2");
347          cprintf ("setup_4712(): Disable VLAN, it must be in bridge mode\n");
348          nvram_set ("lan_ifnames", "eth0 eth1");
349          strcpy (wlifname, "eth1");
350          nvram_set ("wl0_ifname", "eth1");
351        }
352    }
353  else
354    {                           // 4702, 4704
355      cprintf
356        ("setup_4712(): It's a 4702 or 4704 hardware, VLAN can't be used in these 2 boards\n");
357      strcpy (wanifname, "eth1");
358      strcpy (wlifname, "eth2");
359      nvram_set ("wl0_ifname", "eth2");
360      if (!strcmp (nvram_safe_get ("wan_ifname"), ""))
361        nvram_set ("lan_ifnames", "eth0 eth1 eth2 wlanb0 wlana0");
362      else
363        nvram_set ("lan_ifnames", "eth0 eth2");
364    }
365//nvram_set ("need_commit","1");
366
367
368
369}
370
371
372int
373start_sysinit (void)
374{
375  char buf[PATH_MAX];
376  struct utsname name;
377  struct stat tmp_stat;
378  time_t tm = 0;
379  cprintf ("sysinit() proc\n");
380  /* /proc */
381  mount ("proc", "/proc", "proc", MS_MGC_VAL, NULL);
382  cprintf ("sysinit() tmp\n");
383
384  /* /tmp */
385  mount ("ramfs", "/tmp", "ramfs", MS_MGC_VAL, NULL);
386  eval ("mkdir", "/tmp/www");
387
388  cprintf ("sysinit() var\n");
389
390  /* /var */
391  mkdir ("/tmp/var", 0777);
392  mkdir ("/var/lock", 0777);
393  mkdir ("/var/lock/subsys", 0777);
394  mkdir ("/var/log", 0777);
395  mkdir ("/var/run", 0777);
396  mkdir ("/var/tmp", 0777);
397  cprintf ("sysinit() setup console\n");
398
399  eval ("/sbin/watchdog");      // system watchdog
400
401  /* Setup console */
402
403  cprintf ("sysinit() klogctl\n");
404  klogctl (8, NULL, atoi (nvram_safe_get ("console_loglevel")));
405  cprintf ("sysinit() get router\n");
406
407  int brand = getRouterBrand ();
408  led_control (LED_DIAG, LED_ON);
409  char *rname = getRouter ();
410  fprintf (stderr, "Booting device: %s\n", rname);
411
412  nvram_unset ("port_swap");
413
414  int need_reboot = 0;
415
416  switch (brand)
417    {
418    case ROUTER_BUFFALO_WZRRSG54:
419      check_brcm_cpu_type ();
420      setup_4712 ();
421      nvram_set ("lan_ifnames", "eth0 eth2");
422      nvram_set ("wan_ifname", "eth1");
423      nvram_set ("wl0_ifname", "eth2");
424      eval ("gpio", "init", "0");       //AOSS button
425      eval ("gpio", "init", "4");       //reset button
426      break;
427
428    case ROUTER_MOTOROLA:
429      nvram_set ("cpu_type", "BCM4712");
430      setup_4712 ();
431      break;
432
433    case ROUTER_RT480W:
434    case ROUTER_USR_5461:
435      setup_4712 ();
436      break;
437
438    case ROUTER_BELKIN_F5D7231:
439      nvram_set ("lan_ifnames", "vlan0 eth1");
440      nvram_set ("wan_ifname", "vlan1");
441      nvram_set ("wl0_ifname", "eth1");
442      if (nvram_match ("vlan1ports", "0 5u"))
443        nvram_set ("vlan1ports", "0 5");
444      break;
445
446    case ROUTER_RT210W:
447      nvram_set ("lan_ifnames", "eth0 eth2");
448      nvram_set ("wan_ifname", "eth1"); // fix for Belkin f5d7230 v1000 WAN problem.
449      nvram_set ("wl0_ifname", "eth2");
450
451      if (nvram_get ("et0macaddr") == NULL || nvram_get ("et0macaddr") == "")
452        {
453          nvram_set ("et0macaddr", "00:16:E3:00:00:10");        //fix for missing cfe default = dead LAN ports.
454          need_reboot = 1;
455        }
456      if (nvram_get ("et1macaddr") == NULL || nvram_get ("et1macaddr") == "")
457        {
458          nvram_set ("et1macaddr", "00:16:E3:00:00:11");
459          need_reboot = 1;
460        }
461      break;
462
463    case ROUTER_BRCM4702_GENERIC:
464      nvram_set ("lan_ifnames", "eth0 eth2");
465      nvram_set ("wan_ifname", "eth1");
466      nvram_set ("wl0_ifname", "eth2");
467
468      if (nvram_get ("et0macaddr") == NULL || nvram_get ("et0macaddr") == "")
469        {
470          nvram_set ("et0macaddr", "00:11:22:00:00:10");        //fix for missing cfe default = dead LAN ports.
471          need_reboot = 1;
472        }
473      if (nvram_get ("et1macaddr") == NULL || nvram_get ("et1macaddr") == "")
474        {
475          nvram_set ("et1macaddr", "00:11:22:00:00:11");
476          need_reboot = 1;
477        }
478      break;
479
480    case ROUTER_ASUS_WL500G:
481      nvram_set ("lan_ifnames", "eth0 eth2");
482      nvram_set ("wan_ifname", "eth1");
483      nvram_set ("wl0_ifname", "eth2");
484
485      if (nvram_get ("et0macaddr") == NULL || nvram_get ("et0macaddr") == "")
486        {
487          nvram_set ("et0macaddr", "00:0C:6E:00:00:10");        //fix for missing cfe default = dead LAN ports.
488          need_reboot = 1;
489        }
490      if (nvram_get ("et1macaddr") == NULL || nvram_get ("et1macaddr") == "")
491        {
492          nvram_set ("et1macaddr", "00:0C:6E:00:00:10");
493          need_reboot = 1;
494        }
495      break;
496
497    case ROUTER_DELL_TRUEMOBILE_2300:
498      setup_4712 ();
499      nvram_set ("wan_ifname", "eth1"); // fix for WAN problem.
500      break;
501
502    case ROUTER_BUFFALO_WBR54G: //for WLA-G54
503      nvram_set ("lan_ifnames", "eth0 eth2");
504      nvram_set ("wan_ifname", "eth1");
505      if (nvram_match ("wan_to_lan", "yes") && nvram_invmatch ("wan_proto", "disabled"))        // = no lan
506        {
507          nvram_set ("lan_ifnames", "eth2");
508          nvram_set ("wan_ifname", "eth0");
509        }
510      break;
511
512    case ROUTER_BUFFALO_WLI2_TX1_G54:
513    case ROUTER_BUFFALO_WLAG54C:
514    case ROUTER_WAP54G_V1:
515    case ROUTER_SITECOM_WL105B:
516      nvram_set ("lan_ifnames", "eth1 eth2");
517      nvram_set ("wl0_ifname", "eth2");
518      nvram_set ("wan_ifname", "eth0"); //WAN to nonexist. iface.
519      nvram_set ("port_swap", "1");
520      if (nvram_match ("wan_to_lan", "yes") && nvram_invmatch ("wan_proto", "disabled"))        // = no lan
521        {
522          nvram_set ("lan_ifnames", "eth2");
523          nvram_set ("wan_ifname", "eth1");
524        }
525      break;
526
527    case ROUTER_SITECOM_WL111:
528    case ROUTER_NETGEAR_WG602_V4:
529      nvram_set ("lan_ifnames", "eth0 eth2");
530      nvram_set ("wl0_ifname", "eth2");
531      nvram_set ("wan_ifname", "eth1");
532      break;
533
534    case ROUTER_NETGEAR_WNR834BV2:
535      nvram_set ("lan_ifnames", "eth0 eth2");
536      nvram_set ("wl0_ifname", "eth2");
537      nvram_set ("wan_ifname", "eth1");
538
539      if (nvram_get ("pci/1/1/macaddr") == NULL)
540        need_reboot = 1;
541      nvram_set ("pci/1/1/macaddr", nvram_safe_get ("et0macaddr"));
542      nvram_set ("pci/1/1/stbcpo", "0");
543      nvram_set ("pci/1/1/pa2gw1a0", "0");
544      nvram_set ("pci/1/1/pa2gw1a1", "0");
545      nvram_set ("pci/1/1/ag0", "2");
546      nvram_set ("pci/1/1/ag1", "2");
547      nvram_set ("pci/1/1/ag2", "2");
548      nvram_set ("pci/1/1/ccdpo", "0");
549      nvram_set ("pci/1/1/txpid2ga0", "71");
550      nvram_set ("pci/1/1/txpid2ga1", "79");
551      nvram_set ("pci/1/1/txpt2g", "0x38");
552      nvram_set ("pci/1/1/pa2gw0a0", "0");
553      nvram_set ("pci/1/1/pa2gw0a1", "0");
554      nvram_set ("pci/1/1/boardflags", "0x200");
555      nvram_set ("pci/1/1/boardvendor", "0x14e4");
556      nvram_set ("pci/1/1/bw40po", "0");
557      nvram_set ("pci/1/1/sromrev", "4");
558      nvram_set ("pci/1/1/venid", "0x14e4");
559      nvram_set ("pci/1/1/boardrev", "0x4b");
560      nvram_set ("pci/1/1/itt2ga0", "0");
561      nvram_set ("pci/1/1/itt2ga1", "0");
562      nvram_set ("pci/1/1/pa2gw3a0", "0");
563      nvram_set ("pci/1/1/pa2gw3a1", "0");
564      nvram_set ("pci/1/1/maxp2ga0", "0");
565      nvram_set ("pci/1/1/maxp2ga1", "0");
566      nvram_set ("pci/1/1/boardtype", "0x46d");
567      nvram_set ("pci/1/1/boardflags2", "0x0013");
568      nvram_set ("pci/1/1/ofdm2gpo", "0");
569      nvram_set ("pci/1/1/ledbh0", "0x82");
570      nvram_set ("pci/1/1/ledbh1", "-1");
571      nvram_set ("pci/1/1/ledbh2", "-1");
572      nvram_set ("pci/1/1/ledbh3", "-1");
573      nvram_set ("pci/1/1/mcs2gpo0", "0");
574      nvram_set ("pci/1/1/mcs2gpo1", "0");
575      nvram_set ("pci/1/1/mcs2gpo2", "0");
576      nvram_set ("pci/1/1/mcs2gpo3", "0");
577      nvram_set ("pci/1/1/mcs2gpo4", "0");
578      nvram_set ("pci/1/1/mcs2gpo5", "0");
579      nvram_set ("pci/1/1/mcs2gpo6", "0");
580      nvram_set ("pci/1/1/mcs2gpo7", "0");
581      nvram_set ("pci/1/1/bwduppo", "0");
582      nvram_set ("pci/1/1/aa2g", "7");
583      nvram_set ("pci/1/1/pa2gw2a0", "0");
584      nvram_set ("pci/1/1/pa2gw2a1", "0");
585      nvram_set ("pci/1/1/ccode", "all");
586      nvram_set ("pci/1/1/regrev", "0");
587      nvram_set ("pci/1/1/devid", "0x4329");
588      nvram_set ("pci/1/1/cck2gpo", "0");
589      break;
590
591    case ROUTER_MOTOROLA_WE800G:
592      nvram_set ("lan_ifnames", "eth1 eth2");
593      nvram_set ("wl0_ifname", "eth2");
594      nvram_set ("wan_ifname", "eth0"); //WAN to nonexist. iface.
595      nvram_set ("port_swap", "1");
596      eval ("gpio", "disable", "7");
597      if (nvram_match ("wan_to_lan", "yes") && nvram_invmatch ("wan_proto", "disabled"))        // = no lan
598        {
599          nvram_set ("lan_ifnames", "eth2");
600          nvram_set ("wan_ifname", "eth1");
601        }
602      break;
603
604    case ROUTER_MOTOROLA_V1:
605      nvram_set ("wan_ifname", "eth1");
606      eval ("gpio", "disable", "7");
607      break;
608
609    case ROUTER_BUFFALO_WZRG300N:
610    case ROUTER_NETGEAR_WNR834B:
611    case ROUTER_WRT150N:
612    case ROUTER_WRT160N:
613    case ROUTER_WRT300N:
614    case ROUTER_ASUS_WL500W:
615    case ROUTER_BUFFALO_WLAH_G54:
616    case ROUTER_BUFFALO_WAPM_HP_AM54G54:
617    case ROUTER_WRTSL54GS:
618    case ROUTER_MICROSOFT_MN700:
619      nvram_set ("wan_ifname", "eth1");
620      break;
621
622    case ROUTER_WRT54G1X:
623      if (check_vlan_support ())
624        {
625          nvram_set ("lan_ifnames", "vlan0 eth2");
626          nvram_set ("wan_ifname", "vlan1");
627        }
628      break;
629
630    case ROUTER_WRT350N:
631      nvram_set ("wan_ifname", "vlan2");
632      break;
633    case ROUTER_WRT600N:
634      nvram_set ("wan_ifname", "vlan2");
635      break;
636
637    case ROUTER_BUFFALO_WZRG144NH:
638      nvram_set ("wan_ifname", "vlan1");
639      break;
640
641    case ROUTER_ASUS_WL500G_PRE:
642      nvram_set ("sdram_init", "0x0009");
643//      nvram_set ("sdram_ncdl", "0x208");
644      nvram_set ("lan_ifnames", "vlan0 eth2");
645      nvram_set ("wl0_ifname", "eth2");
646      nvram_set ("wan_ifname", "vlan1");        // fix for Asus WL500gPremium WAN problem.
647      if (nvram_match ("vlan1ports", "0 5u"))
648        nvram_set ("vlan1ports", "0 5");
649      break;
650
651    case ROUTER_ASUS_WL500GD:
652    case ROUTER_ASUS_WL550GE:
653      nvram_set ("wl0_ifname", "eth1");
654      break;
655
656    case ROUTER_BUFFALO_WLA2G54C:
657    case ROUTER_WAP54G_V2:
658    case ROUTER_VIEWSONIC_WAPBR_100:
659    case ROUTER_USR_5430:
660    case ROUTER_BUFFALO_WLI_TX4_G54HP:
661    case ROUTER_BELKIN_F5D7230_V2000:
662    case ROUTER_NETGEAR_WG602_V3:
663      nvram_set ("lan_ifnames", "eth0 eth1");
664      nvram_set ("wl0_ifname", "eth1");
665      nvram_set ("wan_ifname", "eth2"); // map WAN port to nonexistant interface
666      if (nvram_match ("wan_to_lan", "yes") && nvram_invmatch ("wan_proto", "disabled"))        // = no lan
667        {
668          nvram_set ("lan_ifnames", "eth1");
669          nvram_set ("wan_ifname", "eth0");
670        }
671      break;
672
673    case ROUTER_DELL_TRUEMOBILE_2300_V2:        //we must fix cfe defaults with CR added
674      nvram_set ("vlan0hwname", "et0");
675      nvram_set ("vlan1hwname", "et0");
676      nvram_set ("et0mdcport", "0");
677      nvram_set ("et0phyaddr", "30");
678      nvram_set ("gpio2", "adm_eecs");
679      nvram_set ("gpio3", "adm_eesk");
680      nvram_set ("gpio4", "adm_eedi");
681      nvram_set ("gpio5", "adm_rc");
682      nvram_unset ("gpio6");
683      break;
684
685    case ROUTER_WRT54G_V8:
686      nvram_set ("reset_gpio", "7");
687      break;
688
689    case ROUTER_ASUS_WL520G:
690    case ROUTER_ASUS_WL500G_PRE_V2:
691    case ROUTER_WRT54G_V81:
692      if (nvram_match ("vlan1ports", "4 5u"))
693        nvram_set ("vlan1ports", "4 5");
694      break;
695
696    case ROUTER_ASUS_WL520GUGC:
697    case ROUTER_NETGEAR_WGR614L:
698      if (nvram_match ("vlan1ports", "0 5u"))
699        nvram_set ("vlan1ports", "0 5");
700      break;
701
702    case ROUTER_LINKSYS_WTR54GS:
703      eval ("gpio", "enable", "3");     //prevent reboot loop on reset
704      break;
705
706    case ROUTER_WAP54G_V3:
707      eval ("gpio", "enable", "0");     //reset gpio 0 for reset button
708//      nvram_set ("vlan0ports", "1 5*");
709//      nvram_set ("vlan1ports", "4 5");
710//      if (nvram_match ("wan_to_lan", "yes") && nvram_invmatch ("wan_proto", "disabled"))      // = no lan
711//      {
712//        nvram_set ("vlan0ports", "4 5*");
713//        nvram_set ("vlan1ports", "1 5");
714//      }
715      break;
716
717    }
718#if 0
719  /* fix il0macaddr to be lanmac+2 */
720  if (nvram_get ("il0macaddr") == NULL)
721    need_reboot = 1;
722
723  unsigned char mac[20];
724  if (nvram_match ("port_swap", "1"))
725    strcpy (mac, nvram_safe_get ("et1macaddr"));
726  else
727    strcpy (mac, nvram_safe_get ("et0macaddr"));
728  MAC_ADD (mac);
729  MAC_ADD (mac);
730  nvram_set ("il0macaddr", mac);
731#endif
732  /* ifnames */
733  strcpy (wanifname, nvram_safe_get ("wan_ifname"));
734  strcpy (wlifname, nvram_safe_get ("wl0_ifname"));
735
736
737  /* set wan_ifnames, pppoe_wan_ifname and pppoe_ifname */
738  nvram_set ("wan_ifname", wanifname);
739  nvram_set ("wan_ifnames", wanifname);
740  nvram_set ("pppoe_wan_ifname", wanifname);
741  nvram_set ("pppoe_ifname", wanifname);
742
743  /* additional boardflags adjustment */
744  switch (brand)
745    {
746    case ROUTER_BELKIN_F5D7231:
747      if (nvram_match ("boardflags", "0x388")
748          || nvram_match ("boardflags", "0x0388"))
749        nvram_set ("boardflags", "0x0f58");
750      break;
751
752    case ROUTER_BUFFALO_WLI_TX4_G54HP:
753      if (!nvram_match ("buffalo_hp", "1")
754          && (nvram_match ("boardflags", "0x1658")
755              || nvram_match ("boardflags", "0x2658")))
756        {
757          nvram_set ("buffalo_hp", "1");
758#ifndef HAVE_BUFFALO            // if HAVE_BUFFALO not used to be FCC/CE valid
759          nvram_set ("boardflags", "0x3658");   // enable high gain PA
760#endif
761        }
762      break;
763
764    case ROUTER_BUFFALO_WHRG54S:        //for HP only
765      if (!nvram_match ("buffalo_hp", "1")
766          && nvram_match ("boardflags", "0x1758"))
767        {
768          nvram_set ("buffalo_hp", "1");
769#ifndef HAVE_BUFFALO            // if HAVE_BUFFALO not used to be FCC/CE valid
770          nvram_set ("boardflags", "0x3758");   // enable high gain PA
771#endif
772        }
773      break;
774    }
775
776  if (need_reboot)
777    {
778      cprintf ("Need reboot now to set some mac addresses\n");
779      nvram_commit ();
780      kill (1, SIGTERM);
781      exit (0);
782    }
783
784  /* Modules */
785  uname (&name);
786
787
788  snprintf (buf, sizeof (buf), "/lib/modules/%s", name.release);
789  if (stat ("/proc/modules", &tmp_stat) == 0 && stat (buf, &tmp_stat) == 0)
790    {
791      char module[80], *modules, *next;
792      //modules="wl switch-core";
793      nvram_set ("portprio_support", "1");
794
795      if (check_vlan_support () && check_hw_type () != BCM5325E_CHIP)
796        {
797          switch (brand)
798            {
799            case ROUTER_WRT310N:
800            case ROUTER_WRT350N:
801            case ROUTER_WRT600N:
802            case ROUTER_BUFFALO_WZRG144NH:
803              nvram_set ("portprio_support", "0");
804              modules = "bcm57xxlsys";
805              break;
806            case ROUTER_LINKSYS_WRT55AG:
807            case ROUTER_MOTOROLA:
808            case ROUTER_BUFFALO_WBR2G54S:
809            case ROUTER_DELL_TRUEMOBILE_2300_V2:
810              modules =
811                nvram_invmatch ("ct_modules",
812                                "") ? nvram_safe_get ("ct_modules") :
813                "switch-core switch-adm";
814              break;
815
816            case ROUTER_WRT54G_V8:
817            case ROUTER_WRT54G_V81:
818            case ROUTER_LINKSYS_WRH54G:
819            case ROUTER_ASUS_WL520G:
820            case ROUTER_ASUS_WL520GUGC:
821              modules =
822                nvram_invmatch ("ct_modules",
823                                "") ? nvram_safe_get ("ct_modules") :
824                "switch-core switch-robo";
825              break;
826
827            case ROUTER_WRT54G1X:
828            case ROUTER_WRT54G:
829              eval ("insmod", "switch-core");
830              if (eval ("insmod", "switch-robo"))
831                eval ("insmod", "switch-adm");
832              break;
833
834            case ROUTER_RT480W:
835            case ROUTER_BUFFALO_WLI2_TX1_G54:
836              modules =
837                nvram_invmatch ("ct_modules",
838                                "") ? nvram_safe_get ("ct_modules") : "";
839              eval ("insmod", "switch-core");
840              if (eval ("insmod", "switch-robo"))
841                eval ("insmod", "switch-adm");
842              break;
843
844            case ROUTER_WRT54G3G:
845              modules =
846                nvram_invmatch ("ct_modules",
847                                "") ? nvram_safe_get ("ct_modules") :
848                "switch-core switch-robo pcmcia_core yenta_socket ds serial_cs usbcore usb-ohci usbserial sierra";
849              break;
850
851            default:
852
853              modules =
854                nvram_invmatch ("ct_modules",
855                                "") ? nvram_safe_get ("ct_modules") :
856                "switch-core switch-robo";
857              break;
858            }
859        }
860      else
861        {
862          switch (brand)
863            {
864            case ROUTER_WRT350N:
865            case ROUTER_WRT600N:
866            case ROUTER_BUFFALO_WZRG144NH:
867              nvram_set ("portprio_support", "0");
868              modules = "bcm57xxlsys";
869              break;
870            case ROUTER_LINKSYS_WRT55AG:
871              modules =
872                nvram_invmatch ("ct_modules",
873                                "") ? nvram_safe_get ("ct_modules") :
874                "switch-core switch-adm";
875
876              break;
877            case ROUTER_ASUS_WL500GD:
878            case ROUTER_ASUS_WL550GE:
879              modules =
880                nvram_invmatch ("ct_modules",
881                                "") ? nvram_safe_get ("ct_modules") :
882                "switch-core switch-robo";
883              break;
884            case ROUTER_BUFFALO_WZRRSG54:
885              nvram_set ("portprio_support", "0");
886              modules =
887                nvram_invmatch ("ct_modules",
888                                "") ? nvram_safe_get ("ct_modules") : "";
889              break;
890            case ROUTER_WRT54G3G:
891              if (check_vlan_support ())
892                modules =
893                  nvram_invmatch ("ct_modules",
894                                  "") ? nvram_safe_get ("ct_modules") :
895                  "switch-core switch-robo pcmcia_core yenta_socket ds";
896              else
897                {
898                  nvram_set ("portprio_support", "0");
899
900                  modules =
901                    nvram_invmatch ("ct_modules",
902                                    "") ? nvram_safe_get ("ct_modules") :
903                    "pcmcia_core yenta_socket ds";
904                }
905              break;
906
907            default:
908              if (check_vlan_support ())
909                modules =
910                  nvram_invmatch ("ct_modules",
911                                  "") ? nvram_safe_get ("ct_modules") :
912                  "switch-core switch-robo";
913              else
914                {
915                  nvram_set ("portprio_support", "0");
916                  modules =
917                    nvram_invmatch ("ct_modules",
918                                    "") ? nvram_safe_get ("ct_modules") : "";
919                }
920              break;
921            }
922        }
923      cprintf ("insmod %s\n", modules);
924
925      foreach (module, modules, next)
926      {
927#ifdef HAVE_MACBIND
928        if (nvram_match ("et0macaddr", MACBRAND))
929          eval ("insmod", module);
930#else
931
932        cprintf ("loading %s\n", module);
933        eval ("insmod", module);
934        cprintf ("done\n");
935#endif
936      }
937
938      if (check_hw_type () == BCM4702_CHIP)
939        eval ("insmod", "diag");
940
941      loadWlModule ();
942/*
943#ifdef HAVE_USB
944//load usb driver. we will add samba server, ftp server and ctorrent support in future
945      modules =
946        "usbcore usb-ohci usb-uhci ehci-hcd scsi_mod usb-storage ide-core ide-detect ide-disk ide-scsi cdrom ide-cd printer sd_mod sr_mod"
947        foreach (module, modules, next)
948      {
949        cprintf ("loading %s\n", module);
950        eval ("insmod", module);
951      }
952#endif
953*/
954
955#ifdef HAVE_USB
956
957      if (nvram_match ("usb_enable", "1"))
958        {
959          led_control (LED_USB, LED_ON);
960
961          cprintf ("loading usbcore\n");
962          eval ("insmod", "usbcore");
963
964          if (nvram_match ("usb_uhci", "1"))
965            {
966              cprintf ("loading usb-uhci\n");
967              eval ("insmod", "usb-uhci");
968            }
969
970          if (nvram_match ("usb_ohci", "1"))
971            {
972              cprintf ("loading usb-ohci\n");
973              eval ("insmod", "usb-ohci");
974            }
975
976          if (nvram_match ("usb_usb2", "1"))
977            {
978              cprintf ("loading usb2 module\n");
979              eval ("insmod", "ehci-hcd");
980            }
981
982          if (nvram_match ("usb_storage", "1"))
983            {
984              cprintf ("loading scsi_mod\n");
985              eval ("insmod", "scsi_mod");
986              cprintf ("loading sd_mod\n");
987              eval ("insmod", "sd_mod");
988              cprintf ("loading usb-storage\n");
989              eval ("insmod", "usb-storage");
990
991
992              if (nvram_match ("usb_fs_ext3", "1"))
993                {
994                  cprintf ("loading ext2\n");
995                  eval ("insmod", "ext2");
996#ifdef HAVE_USB_ADVANCED
997                  cprintf ("loading jbd\n");
998                  eval ("insmod", "jbd");
999                  cprintf ("loading ext3\n");
1000                  eval ("insmod", "ext3");
1001#endif
1002                }
1003
1004              if (nvram_match ("usb_fs_fat", "1"))
1005                {
1006                  cprintf ("loading usb_fs_fat\n");
1007                  eval ("insmod", "fat");
1008                  cprintf ("loading usb_fs_vfat\n");
1009                  eval ("insmod", "vfat");
1010                }
1011
1012//         if (nvram_match ("usb_fs_xfs", "1"))
1013//         {
1014//              cprintf ("loading usb_fs_xfs\n");
1015//              eval ("insmod", "xfs");
1016//         }             
1017            }
1018
1019          if (nvram_match ("usb_printer", "1"))
1020            {
1021              cprintf ("loading printer\n");
1022              eval ("insmod", "printer");
1023            }
1024        }
1025      else
1026        {
1027          led_control (LED_USB, LED_OFF);
1028        }
1029#endif
1030
1031    }
1032  /* Set a sane date */
1033  stime (&tm);
1034
1035  led_control (LED_POWER, LED_ON);
1036  led_control (LED_SES, LED_OFF);
1037  led_control (LED_BRIDGE, LED_OFF);
1038  led_control (LED_WLAN, LED_OFF);
1039
1040  if (brand == ROUTER_WRT54G3G)
1041    {
1042      eval ("cardmgr");
1043    }
1044
1045  cprintf ("done\n");
1046  return 0;
1047
1048}
1049static int
1050check_nv (char *name, char *value)
1051{
1052  int ret = 0;
1053  if (nvram_match ("manual_boot_nv", "1"))
1054    return 0;
1055
1056  if (!nvram_get (name))
1057    {
1058      cprintf ("ERR: Cann't find %s !.......................\n", name);
1059      nvram_set (name, value);
1060      ret++;
1061    }
1062  else if (nvram_invmatch (name, value))
1063    {
1064      cprintf ("ERR: The %s is %s, not %s !.................\n", name,
1065               nvram_safe_get (name), value);
1066      nvram_set (name, value);
1067      ret++;
1068    }
1069
1070  return ret;
1071}
1072
1073int
1074check_cfe_nv (void)
1075{
1076  int ret = 0;
1077  switch (getRouterBrand ())
1078    {
1079    case ROUTER_BUFFALO_WZRRSG54:
1080      ret += check_nv ("lan_hwnames", "et0 wl0");
1081      ret += check_nv ("wan_hwname", "et1");
1082      ret += check_nv ("vlans", "0");
1083      break;
1084    case ROUTER_BUFFALO_WBR2G54S:
1085      ret += check_nv ("aa0", "3");
1086
1087      ret += check_nv ("pa0itssit", "62");
1088      ret += check_nv ("pa0b0", "0x1136");
1089      ret += check_nv ("pa0b1", "0xfb93");
1090      ret += check_nv ("pa0b2", "0xfea5");
1091#ifndef HAVE_MSSID
1092      ret += check_nv ("pa0maxpwr", "60");
1093#endif
1094      ret += check_nv ("wl0gpio2", "0");
1095      ret += check_nv ("wl0gpio3", "0");
1096      ret += check_nv ("cctl", "0");
1097      ret += check_nv ("ccode", "0");
1098      break;
1099#ifndef HAVE_BUFFALO
1100
1101    case ROUTER_WRT54G:
1102    case ROUTER_WRT54G_V8:
1103    case ROUTER_WRT54G_V81:
1104      ret += check_nv ("aa0", "3");
1105/*      if (check_hw_type () == BCM5352E_CHIP
1106          || check_hw_type () == BCM5354G_CHIP)
1107        ret += check_nv ("ag0", "0x02");
1108      else
1109        ret += check_nv ("ag0", "255");*/
1110      if (check_hw_type () == BCM5325E_CHIP)
1111        {
1112          /* Lower the DDR ram drive strength , the value will be stable for all boards
1113             Latency 3 is more stable for all ddr 20050420 by honor */
1114
1115          ret += check_nv ("sdram_init", "0x010b");
1116          ret += check_nv ("sdram_config", "0x0062");
1117
1118          if (nvram_match ("clkfreq", "200")
1119              && nvram_match ("overclocking", "200"))
1120            {
1121              ret += check_nv ("clkfreq", "216");
1122              nvram_set ("overclocking", "216");
1123            }
1124
1125          if (ret)
1126            {
1127              nvram_set ("sdram_ncdl", "0x0");
1128
1129            }
1130          ret += check_nv ("pa0itssit", "62");
1131          ret += check_nv ("pa0b0", "0x15eb");
1132          ret += check_nv ("pa0b1", "0xfa82");
1133          ret += check_nv ("pa0b2", "0xfe66");
1134#ifndef HAVE_MSSID
1135          ret += check_nv ("pa0maxpwr", "0x4e");
1136#endif
1137        }
1138      else if (check_hw_type () == BCM5354G_CHIP)
1139        {
1140          ret += check_nv ("pa0itssit", "62");
1141          ret += check_nv ("pa0b0", "0x1326");
1142          ret += check_nv ("pa0b1", "0xFB51");
1143          ret += check_nv ("pa0b2", "0xFE87");
1144          ret += check_nv ("reset_gpio", "7");
1145        }
1146      else if (check_hw_type () == BCM4705_BCM5397_EWC_CHIP)
1147        {
1148          // nothing to do
1149        }
1150      else if (check_hw_type () == BCM4704_BCM5325F_CHIP)
1151        {
1152          //nothing to do
1153        }
1154      else
1155        {
1156          ret += check_nv ("pa0itssit", "62");
1157          ret += check_nv ("pa0b0", "0x170c");
1158          ret += check_nv ("pa0b1", "0xfa24");
1159          ret += check_nv ("pa0b2", "0xfe70");
1160#ifndef HAVE_MSSID
1161          ret += check_nv ("pa0maxpwr", "0x48");
1162#endif
1163        }
1164
1165      //ret += check_nv("gpio2", "adm_eecs");
1166      //ret += check_nv("gpio3", "adm_eesk");
1167      //ret += check_nv("gpio5", "adm_eedi");
1168      //ret += check_nv("gpio6", "adm_rc");
1169
1170      ret += check_nv ("wl0gpio2", "0");
1171      ret += check_nv ("wl0gpio3", "0");
1172
1173      ret += check_nv ("cctl", "0");
1174      ret += check_nv ("ccode", "0");
1175      break;
1176#endif
1177    }
1178  if (ret)
1179    {
1180      cprintf ("Some error found, we want to reboot!.....................\n");
1181      nvram_commit ();
1182      kill (1, SIGTERM);
1183      exit (0);
1184    }
1185
1186
1187  return ret;
1188}
1189
1190int
1191check_pmon_nv (void)
1192{
1193  return 0;
1194}
1195
1196
1197void
1198start_overclocking (void)
1199{
1200#ifdef HAVE_OVERCLOCKING
1201  cprintf ("Overclocking started\n");
1202
1203  int rev = cpu_plltype ();
1204  if (rev == 0)
1205    return;                     //unsupported
1206
1207  char *ov = nvram_get ("overclocking");
1208  if (ov == NULL)
1209    return;
1210  int clk = atoi (ov);
1211
1212  if (nvram_get ("clkfreq") == NULL)
1213    return;                     //unsupported
1214
1215
1216  char *pclk = nvram_safe_get ("clkfreq");
1217  char dup[64];
1218  strcpy (dup, pclk);
1219  int i;
1220  for (i = 0; i < strlen (dup); i++)
1221    if (dup[i] == ',')
1222      dup[i] = 0;
1223  int cclk = atoi (dup);
1224  if ((cclk < 150 && rev == 3) || (cclk < 192 && rev == 4)
1225      || (cclk < 183 && rev == 7))
1226    {
1227      cprintf ("clkfreq is %d (%s), this is unsupported\n", cclk, dup);
1228      return;                   //unsupported
1229    }
1230
1231  if (clk == cclk)
1232    {
1233      cprintf ("clkfreq identical with new setting\n");
1234      return;                   //clock already set
1235    }
1236
1237
1238  int set = 1;
1239  int clk2 = 0;
1240  char clkfr[16];
1241
1242  switch (clk)
1243    {
1244    case 150:
1245      clk2 = 75;
1246//      nvram_set ("clkfreq", "150,75");
1247      break;
1248    case 183:
1249      clk2 = 92;
1250//      nvram_set ("clkfreq", "183,92");
1251      break;
1252    case 187:
1253      clk2 = 94;
1254//      nvram_set ("clkfreq", "187,94");
1255      break;
1256    case 192:
1257      clk2 = 96;
1258//      nvram_set ("clkfreq", "192,96");
1259      break;
1260    case 198:
1261      clk2 = 98;
1262//      nvram_set ("clkfreq", "198,98");
1263      break;
1264    case 200:
1265      clk2 = 100;
1266//      nvram_set ("clkfreq", "200,100");
1267      break;
1268    case 216:
1269      clk2 = 108;
1270//      nvram_set ("clkfreq", "216,108");
1271      break;
1272    case 225:
1273      clk2 = 113;
1274//      nvram_set ("clkfreq", "225,113");
1275      break;
1276    case 228:
1277      clk2 = 114;
1278//      nvram_set ("clkfreq", "228,114");
1279      break;
1280    case 233:
1281      clk2 = 116;
1282//      nvram_set ("clkfreq", "233,116");
1283      break;
1284    case 237:
1285      clk2 = 119;
1286//     nvram_set ("clkfreq", "237,119");
1287      break;
1288    case 240:
1289      clk2 = 120;
1290//      nvram_set ("clkfreq", "240,120");
1291      break;
1292    case 250:
1293      clk2 = 125;
1294//      nvram_set ("clkfreq", "250,125");
1295      break;
1296    case 252:
1297      clk2 = 126;
1298//      nvram_set ("clkfreq", "252,126");
1299      break;
1300    case 264:
1301      clk2 = 132;
1302//      nvram_set ("clkfreq", "264,132");
1303      break;
1304    case 280:
1305      clk2 = 120;
1306//      nvram_set ("clkfreq", "280,120");
1307      break;
1308    case 300:
1309      clk2 = 120;
1310//      nvram_set ("clkfreq", "300,120");
1311      break;
1312    default:
1313      set = 0;
1314      break;
1315    }
1316
1317  if (set)
1318    {
1319      cprintf ("clock frequency adjusted from %d to %d, reboot needed\n",
1320               cclk, clk);
1321      sprintf (clkfr, "%d,%d", clk, clk2);
1322      nvram_set ("clkfreq", clkfr);
1323      nvram_commit ();
1324      cprintf ("Overclocking done, rebooting...\n");
1325      kill (1, SIGTERM);
1326      exit (0);
1327    }
1328#endif
1329}
1330
1331
1332char *
1333enable_dtag_vlan (int enable)
1334{
1335  int donothing = 0;
1336  if (nvram_match ("vdsl_state", "1") && enable)
1337    donothing = 1;
1338  if ((nvram_match ("vdsl_state", "0") || nvram_match ("vdsl_state", ""))
1339      && !enable)
1340    donothing = 1;
1341  if (enable)
1342    nvram_set ("vdsl_state", "1");
1343  else
1344    nvram_set ("vdsl_state", "0");
1345
1346  char *vlan7ports = NULL;
1347  vlan7ports = "4t 5";
1348  if (nvram_match ("vlan1ports", "4 5"))
1349    {
1350      vlan7ports = "4t 5";
1351    }
1352  if (nvram_match ("vlan1ports", "0 5"))
1353    {
1354      vlan7ports = "0t 5";
1355    }
1356  if (nvram_match ("vlan1ports", "1 5"))
1357    {
1358      vlan7ports = "1t 5";
1359    }
1360  if (nvram_match ("vlan2ports", "0 8") || nvram_match ("vlan2ports", "0 8*") || nvram_match ("vlan2ports", "0 8t"))    // special condition for Broadcom Gigabit Phy routers
1361    {
1362      char *eth = "eth1";
1363      vlan7ports = "0t 8";
1364      char *save_ports2 = nvram_safe_get ("vlan2ports");
1365      if (getRouterBrand () == ROUTER_WRT600N)
1366        eth = "eth2";
1367      if (donothing)
1368        return eth;
1369      if (enable)
1370        {
1371          nvram_set ("vlan2ports", "");
1372          nvram_set ("vlan7ports", vlan7ports);
1373        }
1374      stop_lan ();
1375      eval ("ifconfig", eth, "down");
1376      eval ("rmmod", "bcm57xxlsys");
1377      eval ("insmod", "bcm57xxlsys");
1378      eval ("ifconfig", eth, "up");
1379      start_config_vlan ();
1380      start_lan ();
1381      if (enable)
1382        {
1383          nvram_set ("vlan2ports", save_ports2);
1384          nvram_set ("vlan7ports", "");
1385        }
1386      return eth;
1387    }
1388  char tmp[200];
1389  char *eth = "eth0";
1390  FILE *in = fopen ("/proc/switch/eth1/reset", "rb");   // this condition fails almost. just one router (DLINK DIR-330) requires it
1391  if (in)
1392    {
1393      eth = "eth1";
1394      fclose (in);
1395    }
1396
1397  if (!donothing)
1398    {
1399      sprintf (tmp, "echo 1 > /proc/switch/%s/reset", eth);
1400      system2 (tmp);
1401      if (enable)
1402        {
1403          fprintf (stderr, "enable vlan port mapping %s/%s\n",
1404                   nvram_safe_get ("vlan0ports"), vlan7ports);
1405          sprintf (tmp, "echo \"%s\" > /proc/switch/%s/vlan/1/ports", "",
1406                   eth);
1407          system2 (tmp);
1408          sprintf (tmp, "echo \"%s\" > /proc/switch/%s/vlan/0/ports",
1409                   nvram_safe_get ("vlan0ports"), eth);
1410          system2 (tmp);
1411          sprintf (tmp, "echo \"%s\" > /proc/switch/%s/vlan/7/ports",
1412                   vlan7ports, eth);
1413          system2 (tmp);
1414        }
1415      else
1416        {
1417          fprintf (stderr, "disable vlan port mapping %s/%s\n",nvram_safe_get ("vlan0ports"), nvram_safe_get ("vlan1ports"));
1418          sprintf (tmp, "echo \"%s\" > /proc/switch/%s/vlan/7/ports", "",
1419                   eth);
1420          system2 (tmp);
1421          sprintf (tmp, "echo \"%s\" > /proc/switch/%s/vlan/0/ports",
1422                   nvram_safe_get ("vlan0ports"), eth);
1423          system2 (tmp);
1424          sprintf (tmp, "echo \"%s\" > /proc/switch/%s/vlan/1/ports",
1425                   nvram_safe_get ("vlan1ports"), eth);
1426          system2 (tmp);
1427        }
1428    }
1429  return eth;
1430}
1431
1432start_dtag (void)
1433{
1434  enable_dtag_vlan (1);
1435}
Note: See TracBrowser for help on using the repository browser.