source: src/router/services/sysinit/sysinit.c @ 18799

Last change on this file since 18799 was 18799, checked in by BrainSlayer, 14 months ago

wasp vlan config

File size: 65.6 KB
Line 
1/*
2 * sysinit.c
3 *
4 * Copyright (C) 2007 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.
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
34#include <sys/klog.h>
35#include <sys/types.h>
36#include <sys/mount.h>
37#include <sys/reboot.h>
38#include <sys/stat.h>
39#include <sys/sysmacros.h>
40#include <sys/time.h>
41#include <sys/utsname.h>
42#include <sys/wait.h>
43#include <dirent.h>
44
45#include <epivers.h>
46#include <bcmnvram.h>
47#include <mtd.h>
48#include <shutils.h>
49#include <rc.h>
50#include <netconf.h>
51#include <nvparse.h>
52#include <bcmdevs.h>
53
54#include <wlutils.h>
55#include <utils.h>
56#include <cyutils.h>
57#include <code_pattern.h>
58#include <cy_conf.h>
59// #include <mkfiles.h>
60#include <typedefs.h>
61#include <bcmnvram.h>
62#include <bcmutils.h>
63#include <shutils.h>
64#include <wlutils.h>
65#include <cy_conf.h>
66#include <cymac.h>
67#include <glob.h>
68// #include <ledcontrol.h>
69
70#define WL_IOCTL(name, cmd, buf, len) (ret = wl_ioctl((name), (cmd), (buf), (len)))
71
72#define TXPWR_MAX 251
73#define TXPWR_DEFAULT 28
74
75void start_restore_defaults(void);
76static void rc_signal(int sig);
77extern void start_overclocking(void);
78extern int check_cfe_nv(void);
79extern int check_pmon_nv(void);
80static void unset_nvram(void);
81void start_nvram(void);
82
83extern struct nvram_tuple *srouter_defaults;
84extern void load_defaults(void);
85extern void free_defaults(void);
86
87extern int usb_add_ufd(void);
88
89extern int f_exists(const char *path);
90
91int endswith(char *str, char *cmp)
92{
93        int cmp_len, str_len, i;
94
95        cmp_len = strlen(cmp);
96        str_len = strlen(str);
97        if (cmp_len > str_len)
98                return (0);
99        for (i = 0; i < cmp_len; i++) {
100                if (str[(str_len - 1) - i] != cmp[(cmp_len - 1) - i])
101                        return (0);
102        }
103        return (1);
104}
105
106#ifdef HAVE_MACBIND
107#include "../../../opt/mac.h"
108#endif
109
110void runStartup(char *folder, char *extension)
111{
112        struct dirent **entry;
113        struct stat filestat;
114        DIR *directory;
115        int num, n = 0;
116        char fullname[128];
117
118        directory = opendir(folder);
119        if (directory == NULL) {
120                return;
121        }
122        closedir(directory);
123
124        num = scandir(folder, &entry, 0, alphasort);
125        if (num < 0)
126                return;
127        // list all files in this directory
128        while (n < num) {
129                if (!strcmp(extension, "K**") && strlen(entry[n]->d_name) > 3 && startswith(entry[n]->d_name, "K") && strspn(entry[n]->d_name, "K1234567890") == 3) {   // K* scripts
130                        sprintf(fullname, "%s/%s", folder, entry[n]->d_name);
131                        if (!stat(fullname, &filestat)
132                            && (filestat.st_mode & S_IXUSR))
133                                sysprintf("%s 2>&1 > /dev/null", fullname);
134                        free(entry[n]);
135                        n++;
136                        continue;
137                }
138                if (!strcmp(extension, "S**") && strlen(entry[n]->d_name) > 3 && startswith(entry[n]->d_name, "S") && strspn(entry[n]->d_name, "S1234567890") == 3) {   // S* scripts
139                        sprintf(fullname, "%s/%s", folder, entry[n]->d_name);
140                        if (!stat(fullname, &filestat)
141                            && (filestat.st_mode & S_IXUSR))
142                                sysprintf("%s 2>&1 > /dev/null", fullname);
143                        free(entry[n]);
144                        n++;
145                        continue;
146                }
147                if (endswith(entry[n]->d_name, extension)) {
148#ifdef HAVE_REGISTER
149                        if (!isregistered_real()) {
150                                if (endswith
151                                    (entry[n]->d_name, "wdswatchdog.startup")) {
152                                        free(entry[n]);
153                                        n++;
154                                        continue;
155                                }
156                                if (endswith
157                                    (entry[n]->d_name, "schedulerb.startup")) {
158                                        free(entry[n]);
159                                        n++;
160                                        continue;
161                                }
162                                if (endswith
163                                    (entry[n]->d_name,
164                                     "proxywatchdog.startup")) {
165                                        free(entry[n]);
166                                        n++;
167                                        continue;
168                                }
169                        }
170#endif
171                        sysprintf("%s/%s 2>&1 > /dev/null", folder,
172                                  entry[n]->d_name);
173                        // execute script
174                }
175                free(entry[n]);
176                n++;
177        }
178        free(entry);
179        return;
180}
181
182#if defined(HAVE_BUFFALO) || defined(HAVE_BUFFALO_BL_DEFAULTS)
183
184extern void *getUEnv(char *name);
185
186static void buffalo_defaults(int force)
187{
188        char *pincode = getUEnv("pincode");
189        if (pincode && nvram_get("pincode") == NULL) {
190                nvram_set("pincode", pincode);
191        }
192        if (nvram_get("ath0_akm") == NULL || force) {
193                char *region = getUEnv("region");
194                if (!region
195                    || (strcmp(region, "AP") && strcmp(region, "TW")
196                        && strcmp(region, "RU")
197                        && strcmp(region, "KR")
198                        && strcmp(region, "CH"))) {
199                        {
200                                char *mode_ex =
201                                    getUEnv
202                                    ("DEF-p_wireless_ath0_11bg-authmode_ex");
203                                if (!mode_ex)
204                                        mode_ex =
205                                            getUEnv
206                                            ("DEF-p_wireless_ath00_11bg-authmode_ex");
207                                if (mode_ex && !strcmp(mode_ex, "mixed-psk")) {
208                                        char *mode =
209                                            getUEnv
210                                            ("DEF-p_wireless_ath0_11bg-authmode");
211                                        if (!mode)
212                                                mode =
213                                                    getUEnv
214                                                    ("DEF-p_wireless_ath00_11bg-authmode");
215                                        if (!mode)
216                                                return;
217                                        if (!strcmp(mode, "psk")) {
218                                                nvram_set("ath0_akm",
219                                                          "psk psk2");
220                                                nvram_set("ath0_security_mode",
221                                                          "psk psk2");
222                                        }
223                                        if (!strcmp(mode, "psk2")) {
224                                                nvram_set("ath0_akm",
225                                                          "psk psk2");
226                                                nvram_set("ath0_security_mode",
227                                                          "psk psk2");
228                                        }
229                                } else {
230                                        char *mode =
231                                            getUEnv
232                                            ("DEF-p_wireless_ath0_11bg-authmode");
233                                        if (!mode)
234                                                mode =
235                                                    getUEnv
236                                                    ("DEF-p_wireless_ath00_11bg-authmode");
237                                        if (mode) {
238                                                nvram_set("ath0_akm", mode);
239                                                nvram_set("ath0_security_mode",
240                                                          mode);
241                                        } else
242                                                return;
243                                }
244
245                                char *crypto =
246                                    getUEnv("DEF-p_wireless_ath0_11bg-crypto");
247                                if (!crypto)
248                                        crypto =
249                                            getUEnv
250                                            ("DEF-p_wireless_ath00_11bg-crypto");
251                                if (crypto)
252                                        nvram_set("ath0_crypto", crypto);
253                                char *wpapsk =
254                                    getUEnv("DEF-p_wireless_ath0_11bg-wpapsk");
255                                if (!wpapsk)
256                                        wpapsk =
257                                            getUEnv
258                                            ("DEF-p_wireless_ath00_11bg-wpapsk");
259                                if (wpapsk)
260                                        nvram_set("ath0_wpa_psk", wpapsk);
261                        }
262#ifdef HAVE_WZRHPAG300NH
263                        {
264                                char *mode_ex =
265                                    getUEnv
266                                    ("DEF-p_wireless_ath1_11a-authmode_ex");
267                                if (!mode_ex)
268                                        mode_ex =
269                                            getUEnv
270                                            ("DEF-p_wireless_ath10_11a-authmode_ex");
271                                if (mode_ex && !strcmp(mode_ex, "mixed-psk")) {
272                                        char *mode =
273                                            getUEnv
274                                            ("DEF-p_wireless_ath1_11a-authmode");
275                                        if (!mode)
276                                                mode =
277                                                    getUEnv
278                                                    ("DEF-p_wireless_ath10_11a-authmode");
279                                        if (!mode)
280                                                return;
281                                        if (!strcmp(mode, "psk")) {
282                                                nvram_set("ath1_akm",
283                                                          "psk psk2");
284                                                nvram_set("ath1_security_mode",
285                                                          "psk psk2");
286                                        }
287                                        if (!strcmp(mode, "psk2")) {
288                                                nvram_set("ath1_akm",
289                                                          "psk psk2");
290                                                nvram_set("ath1_security_mode",
291                                                          "psk psk2");
292                                        }
293                                } else {
294                                        char *mode =
295                                            getUEnv
296                                            ("DEF-p_wireless_ath1_11a-authmode");
297                                        if (!mode)
298                                                mode =
299                                                    getUEnv
300                                                    ("DEF-p_wireless_ath10_11a-authmode");
301                                        if (mode) {
302                                                nvram_set("ath1_akm", mode);
303                                                nvram_set("ath1_security_mode",
304                                                          mode);
305                                        } else
306                                                return;
307                                }
308
309                                char *crypto =
310                                    getUEnv("DEF-p_wireless_ath1_11a-crypto");
311                                if (!crypto)
312                                        crypto =
313                                            getUEnv
314                                            ("DEF-p_wireless_ath10_11a-crypto");
315                                if (crypto)
316                                        nvram_set("ath1_crypto", crypto);
317                                char *wpapsk =
318                                    getUEnv("DEF-p_wireless_ath1_11a-wpapsk");
319                                if (!wpapsk)
320                                        wpapsk =
321                                            getUEnv
322                                            ("DEF-p_wireless_ath10_11a-wpapsk");
323                                if (wpapsk)
324                                        nvram_set("ath1_wpa_psk", wpapsk);
325                        }
326                }
327                struct ifreq ifr;
328                int s;
329
330                if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) {
331                        char eabuf[32];
332
333                        strncpy(ifr.ifr_name, "eth0", IFNAMSIZ);
334                        ioctl(s, SIOCGIFHWADDR, &ifr);
335                        close(s);
336                        unsigned char *edata =
337                            (unsigned char *)ifr.ifr_hwaddr.sa_data;
338                        sprintf(eabuf, "BUFFALO-%02X%02X%02X_G",
339                                edata[3] & 0xff, edata[4] & 0xff,
340                                edata[5] & 0xff);
341                        nvram_set("ath0_ssid", eabuf);
342                        sprintf(eabuf, "BUFFALO-%02X%02X%02X_A",
343                                edata[3] & 0xff, edata[4] & 0xff,
344                                edata[5] & 0xff);
345                        nvram_set("ath1_ssid", eabuf);
346                }
347#else
348                }
349                struct ifreq ifr;
350                int s;
351
352                if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) {
353                        char eabuf[32];
354
355                        strncpy(ifr.ifr_name, "eth0", IFNAMSIZ);
356                        ioctl(s, SIOCGIFHWADDR, &ifr);
357                        close(s);
358                        unsigned char *edata =
359                            (unsigned char *)ifr.ifr_hwaddr.sa_data;
360                        sprintf(eabuf, "%02X%02X%02X%02X%02X%02X",
361                                edata[0] & 0xff, edata[1] & 0xff,
362                                edata[2] & 0xff, edata[3] & 0xff,
363                                edata[4] & 0xff, edata[5] & 0xff);
364                        nvram_set("ath0_ssid", eabuf);
365                }
366#endif
367
368                region = getUEnv("region");
369                if (region == NULL) {
370                        region = "US";
371                }
372                if (!strcmp(region, "US")) {
373                        nvram_set("ath0_regdomain", "UNITED_STATES");
374                } else if (!strcmp(region, "EU")) {
375                        nvram_set("ath0_regdomain", "GERMANY");
376                } else if (!strcmp(region, "JP")) {
377                        nvram_set("ath0_regdomain", "JAPAN");
378                } else if (!strcmp(region, "AP")) {
379                        nvram_set("ath0_regdomain", "SINGAPORE");
380                } else if (!strcmp(region, "RU")) {
381                        nvram_set("ath0_regdomain", "RUSSIA");
382                } else if (!strcmp(region, "TW")) {
383                        nvram_set("ath0_regdomain", "TAIWAN");
384                } else if (!strcmp(region, "CH")) {
385                        nvram_set("ath0_regdomain", "CHINA");
386                } else if (!strcmp(region, "KR")) {
387                        nvram_set("ath0_regdomain", "KOREA_REPUBLIC");
388                }
389#ifdef HAVE_WZRHPAG300NH
390                if (!strcmp(region, "US")) {
391                        nvram_set("ath1_regdomain", "UNITED_STATES");
392                } else if (!strcmp(region, "EU")) {
393                        nvram_set("ath1_regdomain", "GERMANY");
394                } else if (!strcmp(region, "JP")) {
395                        nvram_set("ath1_regdomain", "JAPAN");
396                } else if (!strcmp(region, "RU")) {
397                        nvram_set("ath1_regdomain", "RUSSIA");
398                } else if (!strcmp(region, "AP")) {
399                        nvram_set("ath1_regdomain", "SINGAPORE");
400                } else if (!strcmp(region, "TW")) {
401                        nvram_set("ath1_regdomain", "TAIWAN");
402                } else if (!strcmp(region, "CH")) {
403                        nvram_set("ath1_regdomain", "CHINA");
404                } else if (!strcmp(region, "KR")) {
405                        nvram_set("ath1_regdomain", "KOREA_REPUBLIC");
406                }
407#endif
408                if (!strcmp(region, "AP") || !strcmp(region, "CH")
409                        || !strcmp(region, "KR")
410                        || !strcmp(region, "TW")
411                        || !strcmp(region, "RU"))
412                        nvram_set("wps_status", "0");
413                else
414                        nvram_set("wps_status", "1");
415#ifdef HAVE_SPOTPASS
416                system("startservice spotpass_defaults");
417#endif
418        }
419}
420#endif
421/*
422 * SeG dd-wrt addition for module startup scripts
423 */
424void start_modules(void)
425{
426        runStartup("/etc/config", ".startup");
427
428#ifdef HAVE_RB500
429        runStartup("/usr/local/etc/config", ".startup");        // if available
430#elif HAVE_X86
431        runStartup("/usr/local/etc/config", ".startup");        // if available
432#else
433        runStartup("/jffs/etc/config", ".startup");     // if available
434        runStartup("/mmc/etc/config", ".startup");      // if available
435#endif
436        return;
437}
438
439void start_wanup(void)
440{
441        runStartup("/etc/config", ".wanup");
442#ifdef HAVE_RB500
443        runStartup("/usr/local/etc/config", ".wanup");  // if available
444#elif HAVE_X86
445        runStartup("/usr/local/etc/config", ".wanup");  // if available
446#else
447        runStartup("/jffs/etc/config", ".wanup");       // if available
448        runStartup("/mmc/etc/config", ".wanup");        // if available
449        runStartup("/tmp/etc/config", ".wanup");        // if available
450#endif
451        return;
452}
453
454void start_run_rc_startup(void)
455{
456        DIR *directory;
457        int count = 36;         // 36 * 5 s = 180s
458
459        create_rc_file(RC_STARTUP);
460
461        if (f_exists("/tmp/.rc_startup"))
462                system("/tmp/.rc_startup");
463
464        while (count > 0) {
465                directory = opendir("/opt/etc/init.d");
466                if (directory == NULL) {
467                        sleep(5);
468                        count--;
469                } else {
470                        closedir(directory);
471                        runStartup("/opt/etc/init.d", "S**");   // if available; run S** startup scripts
472                        return;
473                }
474        }
475}
476
477void start_run_rc_shutdown(void)
478{
479        runStartup("/opt/etc/init.d", "K**");   // if available; run K** shutdown scripts
480        create_rc_file(RC_SHUTDOWN);
481        if (f_exists("/tmp/.rc_shutdown"))
482                system("/tmp/.rc_shutdown");
483        return;
484}
485
486int create_rc_file(char *name)
487{
488        FILE *fp;
489        char *p = nvram_safe_get(name);
490        char tmp_file[100] = { 0 };
491
492        if ((void *)0 == name || 0 == p[0])
493                return -1;
494
495        snprintf(tmp_file, 100, "/tmp/.%s", name);
496        unlink(tmp_file);
497
498        fp = fopen(tmp_file, "w");
499        if (fp) {
500                if (strlen(p) <= 2 || memcmp("#!", p, 2))
501                        fprintf(fp, "#!/bin/sh\n");
502                // filter Windows <cr>ud
503                while (*p) {
504                        if (*p != 0x0d)
505                                fprintf(fp, "%c", *p);
506                        p++;
507                }
508                fclose(fp);
509        }
510        chmod(tmp_file, 0700);
511
512        return 0;
513}
514
515static void ses_cleanup(void)
516{
517        /*
518         * well known event to cleanly initialize state machine
519         */
520        nvram_set("ses_event", "2");
521
522        /*
523         * Delete lethal dynamically generated variables
524         */
525        nvram_unset("ses_bridge_disable");
526}
527
528static void ses_restore_defaults(void)
529{
530        char tmp[100], prefix[] = "wlXXXXXXXXXX_ses_";
531        int i;
532
533        /*
534         * Delete dynamically generated variables
535         */
536        for (i = 0; i < MAX_NVPARSE; i++) {
537                sprintf(prefix, "wl%d_ses_", i);
538                nvram_unset(strcat_r(prefix, "ssid", tmp));
539                nvram_unset(strcat_r(prefix, "closed", tmp));
540                nvram_unset(strcat_r(prefix, "wpa_psk", tmp));
541                nvram_unset(strcat_r(prefix, "auth", tmp));
542                nvram_unset(strcat_r(prefix, "wep", tmp));
543                nvram_unset(strcat_r(prefix, "auth_mode", tmp));
544                nvram_unset(strcat_r(prefix, "crypto", tmp));
545                nvram_unset(strcat_r(prefix, "akm", tmp));
546        }
547}
548
549void start_restore_defaults(void)
550{
551
552#ifdef HAVE_RB500
553        struct nvram_tuple generic[] = {
554                {"lan_ifname", "br0", 0},
555                {"lan_ifnames",
556                 "eth1 eth2 eth3 eth4 eth5 eth6 eth7 eth8 ath0 ath1 ath2 ath3 ath4 ath5",
557                 0},
558                {"wan_ifname", "eth0", 0},
559                {"wan_ifnames", "eth0", 0},
560                {0, 0, 0}
561        };
562#elif HAVE_GEMTEK
563        struct nvram_tuple generic[] = {
564                {"lan_ifname", "br0", 0},
565                {"lan_ifnames", "eth1 ath0", 0},
566                {"wan_ifname", "eth0", 0},
567                {"wan_ifnames", "eth0", 0},
568                {0, 0, 0}
569        };
570#elif HAVE_EAP9550
571        struct nvram_tuple generic[] = {
572                {"lan_ifname", "br0", 0},
573                {"lan_ifnames", "eth2 ra0",
574                 0},
575                {"wan_ifname2", "eth2", 0},
576                {"wan_ifname", "eth2", 0},
577                {"wan_default", "eth2", 0},
578                {"wan_ifnames", "eth2", 0},
579                {0, 0, 0}
580        };
581#elif HAVE_RT2880
582        struct nvram_tuple generic[] = {
583                {"lan_ifname", "br0", 0},
584                {"lan_ifnames", "vlan1 vlan2 ra0",
585                 0},
586                {"wan_ifname2", "vlan2", 0},
587                {"wan_ifname", "vlan2", 0},
588                {"wan_default", "vlan2", 0},
589                {"wan_ifnames", "vlan2", 0},
590                {0, 0, 0}
591        };
592#elif HAVE_GATEWORX
593#if defined(HAVE_XIOCOM) || defined(HAVE_MI424WR)
594        struct nvram_tuple generic[] = {
595                {"lan_ifname", "br0", 0},
596                {"lan_ifnames", "ixp1 ath0 ath1 ath2 ath3",
597                 0},
598                {"wan_ifname2", "ixp0", 0},
599                {"wan_ifname", "ixp0", 0},
600                {"wan_default", "ixp0", 0},
601                {"wan_ifnames", "ixp0", 0},
602                {0, 0, 0}
603        };
604#else
605        struct nvram_tuple generic[] = {
606                {"lan_ifname", "br0", 0},
607                {"lan_ifnames", "ixp0 ath0 ath1 ath2 ath3",
608                 0},
609                {"wan_ifname2", "ixp1", 0},
610                {"wan_ifname", "ixp1", 0},
611                {"wan_default", "ixp1", 0},
612                {"wan_ifnames", "ixp1", 0},
613                {0, 0, 0}
614        };
615#endif
616#elif HAVE_X86
617        struct nvram_tuple generic[] = {
618                {"lan_ifname", "br0", 0},
619#ifdef HAVE_NOWIFI
620                {"lan_ifnames",
621                 "eth1 eth2 eth3 eth4 eth5 eth6 eth7 eth8 eth9 eth10",
622                 0},
623#else
624#ifdef HAVE_GW700
625                {"lan_ifnames",
626                 "eth0 eth2 eth3 eth4 eth5 eth6 eth7 eth8 eth9 eth10 ath0 ath1 ath2 ath3 ath5 ath6 ath7 ath8",
627                 0},
628#else
629                {"lan_ifnames",
630                 "eth1 eth2 eth3 eth4 eth5 eth6 eth7 eth8 eth9 eth10 ath0 ath1 ath2 ath3 ath5 ath6 ath7 ath8",
631                 0},
632#endif
633#endif
634#ifdef HAVE_GW700
635                {"wan_ifname", "eth1", 0},
636                {"wan_ifname2", "eth1", 0},
637                {"wan_ifnames", "eth1", 0},
638#else
639                {"wan_ifname", "eth0", 0},
640                {"wan_ifname2", "eth0", 0},
641                {"wan_ifnames", "eth0", 0},
642#endif
643                {0, 0, 0}
644        };
645#elif HAVE_XSCALE
646        struct nvram_tuple generic[] = {
647                {"lan_ifname", "br0", 0},
648                {"lan_ifnames",
649                 "ixp0.1 ixp0.2 ath0 ath1",
650                 0},
651                {"wan_ifname", "ixp1", 0},
652                {"wan_ifname2", "ixp1", 0},
653                {"wan_ifnames", "ixp1", 0},
654                {"wan_default", "ixp1", 0},
655                {0, 0, 0}
656        };
657#elif HAVE_LAGUNA
658        struct nvram_tuple generic[] = {
659                {"lan_ifname", "br0", 0},
660                {"lan_ifnames",
661                 "eth0 eth1 ath0 ath1 ath2 ath3",
662                 0},
663                {"wan_ifname", "eth0", 0},
664                {"wan_ifname2", "eth0", 0},
665                {"wan_ifnames", "eth0", 0},
666                {"wan_default", "eth0", 0},
667                {0, 0, 0}
668        };
669#elif HAVE_MAGICBOX
670        struct nvram_tuple generic[] = {
671                {"lan_ifname", "br0", 0},
672                {"lan_ifnames", "eth1 ath0",
673                 0},
674                {"wan_ifname", "eth0", 0},
675                {"wan_ifname2", "eth0", 0},
676                {"wan_ifnames", "eth0", 0},
677                {"wan_default", "eth0", 0},
678                {0, 0, 0}
679        };
680#elif HAVE_RB600
681        struct nvram_tuple generic[] = {
682                {"lan_ifname", "br0", 0},
683                {"lan_ifnames",
684                 "eth0 eth1 eth2 eth3 eth4 eth5 eth6 eth7 eth8 ath0 ath1 ath2 ath3 ath4 ath5 ath6 ath7",
685                 0},
686                {"wan_ifname", "eth0", 0},
687                {"wan_ifname2", "eth0", 0},
688                {"wan_ifnames", "eth0", 0},
689                {"wan_default", "eth0", 0},
690                {0, 0, 0}
691        };
692#elif HAVE_FONERA
693        struct nvram_tuple generic[] = {
694                {"lan_ifname", "br0", 0},
695                {"lan_ifnames", "vlan0 ath0", 0},
696                {"wan_ifname", "", 0},
697                {"wan_ifname2", "", 0},
698                {"wan_default", "", 0},
699                {"wan_ifnames", "eth0 vlan1", 0},
700                {0, 0, 0}
701        };
702#elif HAVE_BWRG1000
703        struct nvram_tuple generic[] = {
704                {"lan_ifname", "br0", 0},
705                {"lan_ifnames", "vlan0 vlan2 ath0", 0},
706                {"wan_ifname", "vlan2", 0},
707                {"wan_ifname2", "vlan2", 0},
708                {"wan_ifnames", "vlan2", 0},
709                {"wan_default", "vlan2", 0},
710                {0, 0, 0}
711        };
712#elif HAVE_SOLO51
713        struct nvram_tuple generic[] = {
714                {"lan_ifname", "br0", 0},
715                {"lan_ifnames", "vlan0 vlan2 ath0", 0},
716                {"wan_ifname", "vlan0", 0},
717                {"wan_ifname2", "vlan0", 0},
718                {"wan_ifnames", "vlan0", 0},
719                {"wan_default", "vlan0", 0},
720                {0, 0, 0}
721        };
722#elif HAVE_BS2
723        struct nvram_tuple generic[] = {
724                {"lan_ifname", "br0", 0},
725                {"lan_ifnames", "eth0 ath0 ath1", 0},
726                {"wan_ifname", "eth0", 0},
727                {"wan_ifname2", "eth0", 0},
728                {"wan_ifnames", "eth0", 0},
729                {"wan_default", "eth0", 0},
730                {0, 0, 0}
731        };
732#elif HAVE_NS2
733        struct nvram_tuple generic[] = {
734                {"lan_ifname", "br0", 0},
735                {"lan_ifnames", "eth0 ath0 ath1", 0},
736                {"wan_ifname", "eth0", 0},
737                {"wan_ifname2", "eth0", 0},
738                {"wan_ifnames", "eth0", 0},
739                {"wan_default", "eth0", 0},
740                {0, 0, 0}
741        };
742#elif HAVE_LC2
743        struct nvram_tuple generic[] = {
744                {"lan_ifname", "br0", 0},
745                {"lan_ifnames", "eth0 ath0 ath1", 0},
746                {"wan_ifname", "eth0", 0},
747                {"wan_ifname2", "eth0", 0},
748                {"wan_ifnames", "eth0", 0},
749                {"wan_default", "eth0", 0},
750                {0, 0, 0}
751        };
752#elif HAVE_PICO2
753        struct nvram_tuple generic[] = {
754                {"lan_ifname", "br0", 0},
755                {"lan_ifnames", "eth0 ath0 ath1", 0},
756                {"wan_ifname", "eth0", 0},
757                {"wan_ifname2", "eth0", 0},
758                {"wan_ifnames", "eth0", 0},
759                {"wan_default", "eth0", 0},
760                {0, 0, 0}
761        };
762#elif HAVE_PICO2HP
763        struct nvram_tuple generic[] = {
764                {"lan_ifname", "br0", 0},
765                {"lan_ifnames", "eth0 ath0 ath1", 0},
766                {"wan_ifname", "eth0", 0},
767                {"wan_ifname2", "eth0", 0},
768                {"wan_ifnames", "eth0", 0},
769                {"wan_default", "eth0", 0},
770                {0, 0, 0}
771        };
772#elif HAVE_MS2
773        struct nvram_tuple generic[] = {
774                {"lan_ifname", "br0", 0},
775                {"lan_ifnames", "eth0 ath0 ath1", 0},
776                {"wan_ifname", "eth0", 0},
777                {"wan_ifname2", "eth0", 0},
778                {"wan_ifnames", "eth0", 0},
779                {"wan_default", "eth0", 0},
780                {0, 0, 0}
781        };
782#elif HAVE_BS2HP
783        struct nvram_tuple generic[] = {
784                {"lan_ifname", "br0", 0},
785                {"lan_ifnames", "eth0 ath0 ath1", 0},
786                {"wan_ifname", "eth0", 0},
787                {"wan_ifname2", "eth0", 0},
788                {"wan_ifnames", "eth0", 0},
789                {"wan_default", "eth0", 0},
790                {0, 0, 0}
791        };
792#elif HAVE_LS2
793        struct nvram_tuple generic[] = {
794                {"lan_ifname", "br0", 0},
795                {"lan_ifnames", "vlan0 vlan2 ath0", 0},
796                {"wan_ifname", "vlan0", 0},
797                {"wan_ifname2", "vlan0", 0},
798                {"wan_ifnames", "vlan0", 0},
799                {"wan_default", "vlan0", 0},
800                {0, 0, 0}
801        };
802#elif HAVE_RS
803        struct nvram_tuple generic[] = {
804                {"lan_ifname", "br0", 0},
805                {"lan_ifnames", "eth0 eth1 ath0 ath1 ath2", 0},
806                {"wan_ifname", "eth0", 0},
807                {"wan_ifname2", "eth0", 0},
808                {"wan_ifnames", "eth0", 0},
809                {"wan_default", "eth0", 0},
810                {0, 0, 0}
811        };
812#elif HAVE_WR941
813        struct nvram_tuple generic[] = {
814                {"lan_ifname", "br0", 0},
815                {"lan_ifnames", "vlan0 vlan1 ath0", 0},
816                {"wan_ifname", "vlan1", 0},
817                {"wan_ifname2", "vlan1", 0},
818                {"wan_ifnames", "vlan1", 0},
819                {"wan_default", "vlan1", 0},
820                {0, 0, 0}
821        };
822#elif HAVE_WA901v1
823        struct nvram_tuple generic[] = {
824                {"lan_ifname", "br0", 0},
825                {"lan_ifnames", "eth1 ath0", 0},
826                {"wan_ifname", "eth1", 0},
827                {"wan_ifname2", "eth1", 0},
828                {"wan_ifnames", "eth1", 0},
829                {"wan_default", "eth1", 0},
830                {0, 0, 0}
831        };
832#elif HAVE_WR703
833        struct nvram_tuple generic[] = {
834                {"lan_ifname", "br0", 0},
835                {"lan_ifnames", "eth1 ath0", 0},
836                {"wan_ifname", "eth1", 0},
837                {"wan_ifname2", "eth1", 0},
838                {"wan_ifnames", "eth1", 0},
839                {"wan_default", "eth1", 0},
840                {0, 0, 0}
841        };
842#elif HAVE_WR741
843        struct nvram_tuple generic[] = {
844                {"lan_ifname", "br0", 0},
845                {"lan_ifnames", "eth0 eth1 ath0", 0},
846                {"wan_ifname", "eth0", 0},
847                {"wan_ifname2", "eth0", 0},
848                {"wan_ifnames", "eth0", 0},
849                {"wan_default", "eth0", 0},
850                {0, 0, 0}
851        };
852#elif HAVE_WR1043
853        struct nvram_tuple generic[] = {
854                {"lan_ifname", "br0", 0},
855                {"lan_ifnames", "vlan1 vlan2 ath0", 0},
856                {"wan_ifname", "vlan2", 0},
857                {"wan_ifname2", "vlan2", 0},
858                {"wan_ifnames", "vlan2", 0},
859                {"wan_default", "vlan2", 0},
860                {0, 0, 0}
861        };
862#elif HAVE_AP83
863        struct nvram_tuple generic[] = {
864                {"lan_ifname", "br0", 0},
865                {"lan_ifnames", "eth0 eth1 ath0", 0},
866                {"wan_ifname", "eth1", 0},
867                {"wan_ifname2", "eth1", 0},
868                {"wan_ifnames", "eth1", 0},
869                {"wan_default", "eth1", 0},
870                {0, 0, 0}
871        };
872#elif HAVE_AP94
873        struct nvram_tuple generic[] = {
874                {"lan_ifname", "br0", 0},
875                {"lan_ifnames", "eth0 eth1 ath0", 0},
876                {"wan_ifname", "eth1", 0},
877                {"wan_ifname2", "eth1", 0},
878                {"wan_ifnames", "eth1", 0},
879                {"wan_default", "eth1", 0},
880                {0, 0, 0}
881        };
882#elif HAVE_UBNTM
883        struct nvram_tuple generic[] = {
884                {"lan_ifname", "br0", 0},
885                {"lan_ifnames", "eth0 eth1 ath0", 0},
886                {"wan_ifname", "", 0},
887                {"wan_ifname2", "", 0},
888                {"wan_ifnames", "", 0},
889                {"wan_default", "", 0},
890                {0, 0, 0}
891        };
892#elif HAVE_HORNET
893        struct nvram_tuple generic[] = {
894                {"lan_ifname", "br0", 0},
895                {"lan_ifnames", "eth0 eth1 ath0", 0},
896                {"wan_ifname", "eth1", 0},
897                {"wan_ifname2", "eth1", 0},
898                {"wan_ifnames", "eth1", 0},
899                {"wan_default", "eth1", 0},
900                {0, 0, 0}
901        };
902#elif HAVE_WNR2000
903        struct nvram_tuple generic[] = {
904                {"lan_ifname", "br0", 0},
905                {"lan_ifnames", "eth0 eth1 ath0", 0},
906                {"wan_ifname", "", 0},
907                {"wan_ifname2", "", 0},
908                {"wan_ifnames", "", 0},
909                {"wan_default", "", 0},
910                {0, 0, 0}
911        };
912#elif HAVE_WASP
913        struct nvram_tuple generic[] = {
914                {"lan_ifname", "br0", 0},
915                {"lan_ifnames", "vlan1 vlan2 ath0", 0},
916                {"wan_ifname", "", 0},
917                {"wan_ifname2", "", 0},
918                {"wan_ifnames", "", 0},
919                {"wan_default", "", 0},
920                {0, 0, 0}
921        };
922#elif HAVE_WHRHPGN
923        struct nvram_tuple generic[] = {
924                {"lan_ifname", "br0", 0},
925                {"lan_ifnames", "eth0 eth1 ath0", 0},
926                {"wan_ifname", "", 0},
927                {"wan_ifname2", "", 0},
928                {"wan_ifnames", "", 0},
929                {"wan_default", "", 0},
930                {0, 0, 0}
931        };
932#elif HAVE_DIR615E
933        struct nvram_tuple generic[] = {
934                {"lan_ifname", "br0", 0},
935                {"lan_ifnames", "eth0 eth1 ath0", 0},
936                {"wan_ifname", "", 0},
937                {"wan_ifname2", "", 0},
938                {"wan_ifnames", "", 0},
939                {"wan_default", "", 0},
940                {0, 0, 0}
941        };
942#elif HAVE_JA76PF
943        struct nvram_tuple generic[] = {
944                {"lan_ifname", "br0", 0},
945                {"lan_ifnames", "eth0 eth1 ath0", 0},
946                {"wan_ifname", "eth1", 0},
947                {"wan_ifname2", "eth1", 0},
948                {"wan_ifnames", "eth1", 0},
949                {"wan_default", "eth1", 0},
950                {0, 0, 0}
951        };
952#elif HAVE_ALFAAP94
953        struct nvram_tuple generic[] = {
954                {"lan_ifname", "br0", 0},
955                {"lan_ifnames", "eth0 eth1 ath0 ath1 ath2", 0},
956                {"wan_ifname", "eth1", 0},
957                {"wan_ifname2", "eth1", 0},
958                {"wan_ifnames", "eth1", 0},
959                {"wan_default", "eth1", 0},
960                {0, 0, 0}
961        };
962#elif HAVE_WZRG450
963        struct nvram_tuple generic[] = {
964                {"lan_ifname", "br0", 0},
965                {"lan_ifnames", "vlan1 ath0", 0},
966                {"wan_ifname", "vlan2", 0},
967                {"wan_ifname2", "vlan2", 0},
968                {"wan_ifnames", "vlan2", 0},
969                {"wan_default", "vlan2", 0},
970                {0, 0, 0}
971        };
972#elif HAVE_WZRHPAG300NH
973        struct nvram_tuple generic[] = {
974                {"lan_ifname", "br0", 0},
975                {"lan_ifnames", "eth0 eth1 ath0 ath1", 0},
976                {"wan_ifname", "eth1", 0},
977                {"wan_ifname2", "eth1", 0},
978                {"wan_ifnames", "eth1", 0},
979                {"wan_default", "eth1", 0},
980                {0, 0, 0}
981        };
982#elif HAVE_JWAP003
983        struct nvram_tuple generic[] = {
984                {"lan_ifname", "br0", 0},
985                {"lan_ifnames", "eth0 eth1 ath0", 0},
986                {"wan_ifname", "eth1", 0},
987                {"wan_ifname2", "eth1", 0},
988                {"wan_ifnames", "eth1", 0},
989                {"wan_default", "eth1", 0},
990                {0, 0, 0}
991        };
992#elif HAVE_JJAP93
993        struct nvram_tuple generic[] = {
994                {"lan_ifname", "br0", 0},
995                {"lan_ifnames", "eth0 ath0", 0},
996                {"wan_ifname", "", 0},
997                {"wan_ifname2", "", 0},
998                {"wan_ifnames", "", 0},
999                {"wan_default", "", 0},
1000                {0, 0, 0}
1001        };
1002#elif HAVE_JJAP005
1003        struct nvram_tuple generic[] = {
1004                {"lan_ifname", "br0", 0},
1005                {"lan_ifnames", "eth0 eth1 ath0", 0},
1006                {"wan_ifname", "eth1", 0},
1007                {"wan_ifname2", "eth1", 0},
1008                {"wan_ifnames", "eth1", 0},
1009                {"wan_default", "eth1", 0},
1010                {0, 0, 0}
1011        };
1012#elif HAVE_JJAP501
1013        struct nvram_tuple generic[] = {
1014                {"lan_ifname", "br0", 0},
1015                {"lan_ifnames", "eth0 eth1 ath0", 0},
1016                {"wan_ifname", "eth1", 0},
1017                {"wan_ifname2", "eth1", 0},
1018                {"wan_ifnames", "eth1", 0},
1019                {"wan_default", "eth1", 0},
1020                {0, 0, 0}
1021        };
1022#elif HAVE_AC722
1023        struct nvram_tuple generic[] = {
1024                {"lan_ifname", "br0", 0},
1025                {"lan_ifnames", "eth0 eth1 ath0", 0},
1026                {"wan_ifname", "eth1", 0},
1027                {"wan_ifname2", "eth1", 0},
1028                {"wan_ifnames", "eth1", 0},
1029                {"wan_default", "eth1", 0},
1030                {0, 0, 0}
1031        };
1032#elif HAVE_AC622
1033        struct nvram_tuple generic[] = {
1034                {"lan_ifname", "br0", 0},
1035                {"lan_ifnames", "eth0 eth1 ath0", 0},
1036                {"wan_ifname", "eth1", 0},
1037                {"wan_ifname2", "eth1", 0},
1038                {"wan_ifnames", "eth1", 0},
1039                {"wan_default", "eth1", 0},
1040                {0, 0, 0}
1041        };
1042#elif HAVE_LSX
1043        struct nvram_tuple generic[] = {
1044                {"lan_ifname", "br0", 0},
1045                {"lan_ifnames", "eth0 ath0", 0},
1046                {"wan_ifname", "", 0},
1047                {"wan_ifname2", "", 0},
1048                {"wan_ifnames", "", 0},
1049                {"wan_default", "", 0},
1050                {0, 0, 0}
1051        };
1052#elif HAVE_DANUBE
1053        struct nvram_tuple generic[] = {
1054                {"lan_ifname", "br0", 0},
1055                {"lan_ifnames", "eth0 ath0", 0},
1056                {"wan_ifname", "nas0", 0},
1057                {"wan_ifname2", "nas0", 0},
1058                {"wan_ifnames", "nas0", 0},
1059                {"wan_default", "nas0", 0},
1060                {0, 0, 0}
1061        };
1062#elif HAVE_WBD222
1063        struct nvram_tuple generic[] = {
1064                {"lan_ifname", "br0", 0},
1065                {"lan_ifnames", "eth0 eth1 eth2 ath0 ath1 ath2", 0},
1066                {"wan_ifname", "eth0", 0},
1067                {"wan_ifname2", "eth0", 0},
1068                {"wan_ifnames", "eth0", 0},
1069                {"wan_default", "eth0", 0},
1070                {0, 0, 0}
1071        };
1072#elif HAVE_STORM
1073        struct nvram_tuple generic[] = {
1074                {"lan_ifname", "br0", 0},
1075                {"lan_ifnames", "eth0 ath0", 0},
1076                {"wan_ifname", "", 0},
1077                {"wan_ifname2", "", 0},
1078                {"wan_ifnames", "", 0},
1079                {"wan_default", "", 0},
1080                {0, 0, 0}
1081        };
1082#elif HAVE_OPENRISC
1083        struct nvram_tuple generic[] = {
1084                {"lan_ifname", "br0", 0},
1085                {"lan_ifnames", "eth0 eth1 eth2 eth3 ath0", 0},
1086                {"wan_ifname", "", 0},
1087                {"wan_ifname2", "", 0},
1088                {"wan_ifnames", "", 0},
1089                {"wan_default", "", 0},
1090                {0, 0, 0}
1091        };
1092#elif HAVE_WP54G
1093        struct nvram_tuple generic[] = {
1094                {"lan_ifname", "br0", 0},
1095                {"lan_ifnames", "eth0 ath0", 0},
1096                {"wan_ifname", "eth1", 0},
1097                {"wan_ifname2", "eth1", 0},
1098                {"wan_ifnames", "eth1", 0},
1099                {"wan_default", "eth1", 0},
1100                {0, 0, 0}
1101        };
1102#elif HAVE_NP28G
1103        struct nvram_tuple generic[] = {
1104                {"lan_ifname", "br0", 0},
1105                {"lan_ifnames", "eth0 ath0", 0},
1106                {"wan_ifname", "eth1", 0},
1107                {"wan_ifname2", "eth1", 0},
1108                {"wan_ifnames", "eth1", 0},
1109                {"wan_default", "eth1", 0},
1110                {0, 0, 0}
1111        };
1112#elif HAVE_ADM5120
1113        struct nvram_tuple generic[] = {
1114                {"lan_ifname", "br0", 0},
1115                {"lan_ifnames", "eth0 ath0", 0},
1116                {"wan_ifname", "", 0},
1117                {"wan_ifname2", "", 0},
1118                {"wan_ifnames", "", 0},
1119                {"wan_default", "", 0},
1120                {0, 0, 0}
1121        };
1122#elif HAVE_LS5
1123        struct nvram_tuple generic[] = {
1124                {"lan_ifname", "br0", 0},
1125                {"lan_ifnames", "ath0", 0},
1126                {"wan_ifname", "eth0", 0},
1127                {"wan_ifname2", "eth0", 0},
1128                {"wan_ifnames", "eth0", 0},
1129                {"wan_default", "eth0", 0},
1130                {0, 0, 0}
1131        };
1132#elif HAVE_WHRAG108
1133        struct nvram_tuple generic[] = {
1134                {"lan_ifname", "br0", 0},
1135                {"lan_ifnames", "eth0 ath0 ath1", 0},
1136                {"wan_ifname2", "eth1", 0},
1137                {"wan_ifname", "eth1", 0},
1138                {"wan_ifnames", "eth1", 0},
1139                {"wan_default", "eth1", 0},
1140                {0, 0, 0}
1141        };
1142#elif HAVE_PB42
1143        struct nvram_tuple generic[] = {
1144                {"lan_ifname", "br0", 0},
1145                {"lan_ifnames", "eth1 ath0 ath1", 0},
1146                {"wan_ifname2", "eth0", 0},
1147                {"wan_ifname", "eth0", 0},
1148                {"wan_ifnames", "eth0", 0},
1149                {"wan_default", "eth0", 0},
1150                {0, 0, 0}
1151        };
1152#elif HAVE_TW6600
1153        struct nvram_tuple generic[] = {
1154                {"lan_ifname", "br0", 0},
1155                {"lan_ifnames", "ath0 ath1", 0},
1156                {"wan_ifname2", "eth0", 0},
1157                {"wan_ifname", "eth0", 0},
1158                {"wan_ifnames", "eth0", 0},
1159                {"wan_default", "eth0", 0},
1160                {0, 0, 0}
1161        };
1162#elif HAVE_CA8PRO
1163        struct nvram_tuple generic[] = {
1164                {"lan_ifname", "br0", 0},
1165                {"lan_ifnames", "vlan0 ath0", 0},
1166                {"wan_ifname", "vlan1", 0},
1167                {"wan_ifname2", "vlan1", 0},
1168                {"wan_ifnames", "vlan1", 0},
1169                {"wan_default", "vlan1", 0},
1170                {0, 0, 0}
1171        };
1172#elif HAVE_CA8
1173        struct nvram_tuple generic[] = {
1174                {"lan_ifname", "br0", 0},
1175                {"lan_ifnames", "ath0", 0},
1176                {"wan_ifname", "eth0", 0},
1177                {"wan_ifname2", "eth0", 0},
1178                {"wan_ifnames", "eth0", 0},
1179                {"wan_default", "eth0", 0},
1180                {0, 0, 0}
1181        };
1182#else
1183        struct nvram_tuple generic[] = {
1184                {"lan_ifname", "br0", 0},
1185                {"lan_ifnames", "eth0 eth2 eth3 eth4", 0},
1186                {"wan_ifname", "eth1", 0},
1187                {"wan_ifname2", "eth1", 0},
1188                {"wan_ifnames", "eth1", 0},
1189                {"wan_default", "eth1", 0},
1190                {0, 0, 0}
1191        };
1192        struct nvram_tuple vlan[] = {
1193                {"lan_ifname", "br0", 0},
1194                {"lan_ifnames", "vlan0 eth1 eth2 eth3", 0},
1195                {"wan_ifname", "vlan1", 0},
1196                {"wan_ifname2", "vlan1", 0},
1197                {"wan_ifnames", "vlan1", 0},
1198                {"wan_default", "vlan1", 0},
1199                {0, 0, 0}
1200        };
1201
1202        struct nvram_tuple wrt350vlan[] = {
1203                {"lan_ifname", "br0", 0},
1204                {"lan_ifnames", "vlan1 eth0", 0},
1205                {"wan_ifname", "vlan2", 0},
1206                {"wan_ifname2", "vlan2", 0},
1207                {"wan_ifnames", "vlan2", 0},
1208                {"wan_default", "vlan2", 0},
1209                {0, 0, 0}
1210        };
1211
1212        struct nvram_tuple wnr3500vlan[] = {
1213                {"lan_ifname", "br0", 0},
1214                {"lan_ifnames", "vlan1 eth1", 0},
1215                {"wan_ifname", "vlan2", 0},
1216                {"wan_ifname2", "vlan2", 0},
1217                {"wan_ifnames", "vlan2", 0},
1218                {"wan_default", "vlan2", 0},
1219                {0, 0, 0}
1220        };
1221
1222        struct nvram_tuple wrt320vlan[] = {
1223                {"lan_ifname", "br0", 0},
1224                {"lan_ifnames", "vlan1 eth1", 0},
1225                {"wan_ifname", "vlan2", 0},
1226                {"wan_ifname2", "vlan2", 0},
1227                {"wan_ifnames", "vlan2", 0},
1228                {"wan_default", "vlan2", 0},
1229                {0, 0, 0}
1230        };
1231
1232        struct nvram_tuple wrt30011vlan[] = {
1233                {"lan_ifname", "br0", 0},
1234                {"lan_ifnames", "vlan0 eth0", 0},
1235                {"wan_ifname", "vlan1", 0},
1236                {"wan_ifname2", "vlan1", 0},
1237                {"wan_ifnames", "vlan1", 0},
1238                {"wan_default", "vlan1", 0},
1239                {0, 0, 0}
1240        };
1241
1242        struct nvram_tuple wrt600vlan[] = {
1243                {"lan_ifname", "br0", 0},
1244                {"lan_ifnames", "vlan0 eth0 eth1", 0},
1245                {"wan_ifname", "vlan2", 0},
1246                {"wan_ifname2", "vlan2", 0},
1247                {"wan_ifnames", "vlan2", 0},
1248                {"wan_default", "vlan2", 0},
1249                {0, 0, 0}
1250        };
1251
1252        struct nvram_tuple wrt60011vlan[] = {
1253                {"lan_ifname", "br0", 0},
1254                {"lan_ifnames", "vlan1 eth0 eth1", 0},
1255                {"wan_ifname", "vlan2", 0},
1256                {"wan_ifname2", "vlan2", 0},
1257                {"wan_ifnames", "vlan2", 0},
1258                {"wan_default", "vlan2", 0},
1259                {0, 0, 0}
1260        };
1261
1262        struct nvram_tuple wrt6102vlan[] = {
1263                {"lan_ifname", "br0", 0},
1264                {"lan_ifnames", "vlan1 eth1 eth2", 0},
1265                {"wan_ifname", "vlan2", 0},
1266                {"wan_ifname2", "vlan2", 0},
1267                {"wan_ifnames", "vlan2", 0},
1268                {"wan_default", "vlan2", 0},
1269                {0, 0, 0}
1270        };
1271
1272        struct nvram_tuple rt53nvlan[] = {
1273                {"lan_ifname", "br0", 0},
1274                {"lan_ifnames", "vlan2 eth1 eth2", 0},
1275                {"wan_ifname", "vlan1", 0},
1276                {"wan_ifname2", "vlan1", 0},
1277                {"wan_ifnames", "vlan1", 0},
1278                {"wan_default", "vlan1", 0},
1279                {0, 0, 0}
1280        };
1281
1282        struct nvram_tuple wzr144nhvlan[] = {
1283                {"lan_ifname", "br0", 0},
1284                {"lan_ifnames", "vlan2 eth0", 0},
1285                {"wan_ifname", "vlan1", 0},
1286                {"wan_ifname2", "vlan1", 0},
1287                {"wan_ifnames", "vlan1", 0},
1288                {"wan_default", "vlan1", 0},
1289                {0, 0, 0}
1290        };
1291
1292        struct nvram_tuple generic_2[] = {
1293                {"lan_ifname", "br0", 0},
1294                {"lan_ifnames", "eth1 eth2", 0},
1295                {"wan_ifname", "eth0", 0},
1296                {"wan_ifname2", "eth0", 0},
1297                {"wan_ifnames", "eth0", 0},
1298                {"wan_default", "eth0", 0},
1299                {0, 0, 0}
1300        };
1301
1302        struct nvram_tuple generic_3[] = {
1303                {"lan_ifname", "br0", 0},
1304                {"lan_ifnames", "eth0 eth1", 0},
1305                {"wan_ifname", "eth2", 0},
1306                {"wan_ifname2", "eth2", 0},
1307                {"wan_ifnames", "eth2", 0},
1308                {"wan_default", "eth2", 0},
1309                {0, 0, 0}
1310        };
1311#endif
1312
1313        struct nvram_tuple *linux_overrides;
1314        struct nvram_tuple *t, *u;
1315        int restore_defaults = 0;
1316
1317        // uint boardflags;
1318
1319        /*
1320         * Restore defaults if told to.
1321         *
1322         * Note: an intentional side effect is that when upgrading from a
1323         * firmware without the sv_restore_defaults var, defaults will also be
1324         * restored.
1325         */
1326        char *et0mac = nvram_safe_get("et0macaddr");
1327        char *et1mac = nvram_safe_get("et1macaddr");
1328
1329        // unsigned char mac[20];
1330        // if (getRouterBrand () == ROUTER_BUFFALO_WZRG144NH)
1331        // {
1332        // if (nvram_get ("il0macaddr") == NULL)
1333        // {
1334        // strcpy (mac, et0mac);
1335        // MAC_ADD (mac);
1336        // nvram_set ("il0macaddr", mac);
1337        // }
1338        // }
1339        load_defaults();
1340#ifdef HAVE_RB500
1341        linux_overrides = generic;
1342        int brand = getRouterBrand();
1343#elif HAVE_XSCALE
1344        linux_overrides = generic;
1345        int brand = getRouterBrand();
1346
1347        if (nvram_invmatch("sv_restore_defaults", "0")) // ||
1348                // nvram_invmatch("os_name",
1349                // "linux"))
1350        {
1351                restore_defaults = 1;
1352        }
1353#elif HAVE_X86
1354        linux_overrides = generic;
1355        int brand = getRouterBrand();
1356
1357        if (nvram_invmatch("sv_restore_defaults", "0")) // ||
1358                // nvram_invmatch("os_name",
1359                // "linux"))
1360        {
1361                restore_defaults = 1;
1362        }
1363#elif HAVE_MAGICBOX
1364        linux_overrides = generic;
1365        int brand = getRouterBrand();
1366
1367        if (nvram_invmatch("sv_restore_defaults", "0")) // ||
1368                // nvram_invmatch("os_name",
1369                // "linux"))
1370        {
1371                restore_defaults = 1;
1372        }
1373#elif HAVE_LAGUNA
1374        linux_overrides = generic;
1375        int brand = getRouterBrand();
1376
1377        if (nvram_invmatch("sv_restore_defaults", "0")) // ||
1378                // nvram_invmatch("os_name",
1379                // "linux"))
1380        {
1381                restore_defaults = 1;
1382        }
1383#elif HAVE_RB600
1384        linux_overrides = generic;
1385        int brand = getRouterBrand();
1386
1387        if (nvram_invmatch("sv_restore_defaults", "0")) // ||
1388                // nvram_invmatch("os_name",
1389                // "linux"))
1390        {
1391                restore_defaults = 1;
1392        }
1393#elif HAVE_GATEWORX
1394        linux_overrides = generic;
1395        int brand = getRouterBrand();
1396
1397        if (nvram_invmatch("sv_restore_defaults", "0")) // ||
1398                // nvram_invmatch("os_name",
1399                // "linux"))
1400        {
1401                restore_defaults = 1;
1402        }
1403#elif HAVE_FONERA
1404        linux_overrides = generic;
1405        int brand = getRouterBrand();
1406
1407        if (nvram_invmatch("sv_restore_defaults", "0")) // ||
1408                // nvram_invmatch("os_name",
1409                // "linux"))
1410        {
1411                restore_defaults = 1;
1412        }
1413#elif HAVE_SOLO51
1414        linux_overrides = generic;
1415        int brand = getRouterBrand();
1416
1417        if (nvram_invmatch("sv_restore_defaults", "0")) // ||
1418                // nvram_invmatch("os_name",
1419                // "linux"))
1420        {
1421                restore_defaults = 1;
1422        }
1423#elif HAVE_RT2880
1424        linux_overrides = generic;
1425        int brand = getRouterBrand();
1426
1427        if (nvram_invmatch("sv_restore_defaults", "0")) // ||
1428                // nvram_invmatch("os_name",
1429                // "linux"))
1430        {
1431                restore_defaults = 1;
1432        }
1433#elif HAVE_LS2
1434        linux_overrides = generic;
1435        int brand = getRouterBrand();
1436
1437        if (nvram_invmatch("sv_restore_defaults", "0")) // ||
1438                // nvram_invmatch("os_name",
1439                // "linux"))
1440        {
1441                restore_defaults = 1;
1442        }
1443#elif HAVE_LS5
1444        linux_overrides = generic;
1445        int brand = getRouterBrand();
1446
1447        if (nvram_invmatch("sv_restore_defaults", "0")) // ||
1448                // nvram_invmatch("os_name",
1449                // "linux"))
1450        {
1451                restore_defaults = 1;
1452        }
1453#elif HAVE_WHRAG108
1454        linux_overrides = generic;
1455        int brand = getRouterBrand();
1456
1457        if (nvram_invmatch("sv_restore_defaults", "0")) // ||
1458                // nvram_invmatch("os_name",
1459                // "linux"))
1460        {
1461                restore_defaults = 1;
1462        }
1463#elif HAVE_TW6600
1464        linux_overrides = generic;
1465        int brand = getRouterBrand();
1466
1467        if (nvram_invmatch("sv_restore_defaults", "0")) // ||
1468                // nvram_invmatch("os_name",
1469                // "linux"))
1470        {
1471                restore_defaults = 1;
1472        }
1473#elif HAVE_PB42
1474        linux_overrides = generic;
1475        int brand = getRouterBrand();
1476
1477        if (nvram_invmatch("sv_restore_defaults", "0")) // ||
1478                // nvram_invmatch("os_name",
1479                // "linux"))
1480        {
1481                restore_defaults = 1;
1482        }
1483#elif HAVE_LSX
1484        linux_overrides = generic;
1485        int brand = getRouterBrand();
1486
1487        if (nvram_invmatch("sv_restore_defaults", "0")) // ||
1488                // nvram_invmatch("os_name",
1489                // "linux"))
1490        {
1491                restore_defaults = 1;
1492        }
1493#elif HAVE_DANUBE
1494        linux_overrides = generic;
1495        int brand = getRouterBrand();
1496
1497        if (nvram_invmatch("sv_restore_defaults", "0")) // ||
1498                // nvram_invmatch("os_name",
1499                // "linux"))
1500        {
1501                restore_defaults = 1;
1502        }
1503#elif HAVE_OPENRISC
1504        linux_overrides = generic;
1505        int brand = getRouterBrand();
1506
1507        if (nvram_invmatch("sv_restore_defaults", "0")) // ||
1508                // nvram_invmatch("os_name",
1509                // "linux"))
1510        {
1511                restore_defaults = 1;
1512        }
1513#elif HAVE_STORM
1514        linux_overrides = generic;
1515        int brand = getRouterBrand();
1516
1517        if (nvram_invmatch("sv_restore_defaults", "0")) // ||
1518                // nvram_invmatch("os_name",
1519                // "linux"))
1520        {
1521                restore_defaults = 1;
1522        }
1523#elif HAVE_ADM5120
1524        linux_overrides = generic;
1525        int brand = getRouterBrand();
1526
1527        if (nvram_invmatch("sv_restore_defaults", "0")) // ||
1528                // nvram_invmatch("os_name",
1529                // "linux"))
1530        {
1531                restore_defaults = 1;
1532        }
1533#elif HAVE_CA8
1534        linux_overrides = generic;
1535        int brand = getRouterBrand();
1536
1537        if (nvram_invmatch("sv_restore_defaults", "0")) // ||
1538                // nvram_invmatch("os_name",
1539                // "linux"))
1540        {
1541                restore_defaults = 1;
1542        }
1543#elif HAVE_GEMTEK
1544        linux_overrides = generic;
1545        int brand = getRouterBrand();
1546#else
1547        int brand = getRouterBrand();
1548
1549        if (nvram_invmatch("sv_restore_defaults", "0")) // ||
1550                // nvram_invmatch("os_name",
1551                // "linux"))
1552        {
1553                // nvram_unset("sv_restore_defaults");
1554                restore_defaults = 1;
1555        }
1556        if (nvram_match("product_name", "INSPECTION")) {
1557                nvram_unset("product_name");
1558                restore_defaults = 1;
1559        }
1560        if (nvram_get("router_name") == NULL)
1561                restore_defaults = 1;
1562
1563        if (restore_defaults) {
1564                cprintf("Restoring defaults...\n");
1565#ifdef HAVE_MICRO
1566                /*
1567                 * adjust ip_conntrack_max based on available memory size
1568                 * some routers that can run micro only have 16MB memory
1569                 */
1570                FILE *fmem = fopen("/proc/meminfo", "r");
1571                char line[128];
1572                unsigned long msize = 0;
1573
1574                if (fmem != NULL) {
1575                        fgets(line, sizeof(line), fmem);        //eat first line
1576                        fgets(line, sizeof(line), fmem);
1577                        if (sscanf(line, "%*s %lu", &msize) == 1) {
1578                                if (msize > (8 * 1024 * 1024)) {
1579                                        nvram_set("ip_conntrack_max", "4096");
1580                                        nvram_set("ip_conntrack_tcp_timeouts",
1581                                                  "3600");
1582                                }
1583                        }
1584                        fclose(fmem);
1585                }
1586#endif
1587                /*
1588                 * these unsets are important for routers where we can't erase nvram
1589                 * and only software restore defaults
1590                 */
1591                nvram_unset("wan_to_lan");
1592                nvram_unset("wl_vifs");
1593                nvram_unset("wl0_vifs");
1594        }
1595        // }
1596
1597        /*
1598         * Delete dynamically generated variables
1599         */
1600        /*
1601         * Choose default lan/wan i/f list.
1602         */
1603        char *ds;
1604
1605        switch (brand) {
1606#ifndef HAVE_BUFFALO
1607        case ROUTER_WRTSL54GS:
1608        case ROUTER_WRT150N:
1609        case ROUTER_WRT160N:
1610        case ROUTER_WRT300N:
1611        case ROUTER_NETGEAR_WNR834B:
1612        case ROUTER_NETGEAR_WNR834BV2:
1613        case ROUTER_NETGEAR_WNDR3300:
1614        case ROUTER_ASUS_WL500G:
1615        case ROUTER_ASUS_WL500W:
1616#endif
1617        case ROUTER_BUFFALO_WZRG300N:
1618        case ROUTER_BUFFALO_WLAH_G54:
1619        case ROUTER_BUFFALO_WAPM_HP_AM54G54:
1620        case ROUTER_BUFFALO_WZRRSG54:
1621        case ROUTER_ASKEY_RT220XD:
1622                linux_overrides = generic;
1623                break;
1624#ifndef HAVE_BUFFALO
1625        case ROUTER_ASUS_WL500GD:
1626        case ROUTER_ASUS_WL550GE:
1627        case ROUTER_BELKIN_F5D7230_V3000:
1628                linux_overrides = vlan;
1629                break;
1630        case ROUTER_NETGEAR_WNR3500L:
1631                linux_overrides = wnr3500vlan;
1632                break;
1633        case ROUTER_WRT160NV3:
1634        case ROUTER_WRT320N:
1635        case ROUTER_WRT310NV2:
1636                linux_overrides = wrt320vlan;
1637                break;
1638        case ROUTER_WRT350N:
1639                linux_overrides = wrt350vlan;
1640                break;
1641        case ROUTER_WRT310N:
1642                linux_overrides = wrt350vlan;
1643                break;
1644        case ROUTER_WRT300NV11:
1645                linux_overrides = wrt30011vlan;
1646                break;
1647        case ROUTER_WRT600N:
1648                if (nvram_match("switch_type", "BCM5395"))
1649                        linux_overrides = wrt60011vlan;
1650                else
1651                        linux_overrides = wrt600vlan;
1652                break;
1653        case ROUTER_WRT610N:
1654                linux_overrides = wrt60011vlan;
1655                break;
1656        case ROUTER_WRT610NV2:
1657        case ROUTER_LINKSYS_E1000V2:
1658        case ROUTER_LINKSYS_E2500:
1659        case ROUTER_LINKSYS_E3200:
1660        case ROUTER_LINKSYS_E4200:
1661        case ROUTER_NETGEAR_WNDR4000:
1662        case ROUTER_ASUS_RTN66:
1663                linux_overrides = wrt6102vlan;
1664                break;
1665        case ROUTER_ASUS_RTN53:
1666                linux_overrides = rt53nvlan;
1667                break;
1668#endif
1669        case ROUTER_BUFFALO_WZRG144NH:
1670                linux_overrides = wzr144nhvlan;
1671                break;
1672#ifndef HAVE_BUFFALO
1673        case ROUTER_MOTOROLA_WE800G:
1674        case ROUTER_WAP54G_V1:
1675        case ROUTER_SITECOM_WL105B:
1676#endif
1677        case ROUTER_BUFFALO_WLI2_TX1_G54:
1678        case ROUTER_BUFFALO_WLAG54C:
1679                linux_overrides = generic_2;
1680                break;
1681#ifndef HAVE_BUFFALO
1682        case ROUTER_WAP54G_V2:
1683        case ROUTER_VIEWSONIC_WAPBR_100:
1684        case ROUTER_USR_5430:
1685        case ROUTER_BELKIN_F5D7230_V2000:
1686        case ROUTER_NETGEAR_WG602_V3:
1687        case ROUTER_NETGEAR_WG602_V4:
1688#endif
1689        case ROUTER_BUFFALO_WLA2G54C:
1690        case ROUTER_BUFFALO_WLI_TX4_G54HP:
1691                linux_overrides = generic_3;
1692                break;
1693#ifndef HAVE_BUFFALO
1694        case ROUTER_RT480W:
1695        case ROUTER_RT210W:
1696#endif
1697        case ROUTER_BRCM4702_GENERIC:
1698                ds = nvram_safe_get("dhcp_start");
1699                if (ds != NULL && strlen(ds) > 3) {
1700                        fprintf(stderr, "cleaning nvram variables\n");
1701                        for (t = srouter_defaults; t->name; t++) {
1702                                nvram_unset(t->name);
1703                        }
1704                        restore_defaults = 1;
1705                }
1706
1707                /*
1708                 * ds = nvram_safe_get ("http_passwd"); if (ds == NULL || strlen
1709                 * (ds) == 0) //fix for empty default password { nvram_set
1710                 * ("http_passwd", "admin"); } ds = nvram_safe_get ("language");
1711                 * if (ds != NULL && strlen (ds) < 3) { nvram_set ("language",
1712                 * "english"); }
1713                 */
1714                // fall through
1715        default:
1716                if (check_vlan_support())
1717                        linux_overrides = vlan;
1718                else
1719                        linux_overrides = generic;
1720                break;
1721        }
1722#endif
1723        /*
1724         * int i; for (i=0;i<4;i++)
1725         * nvram_set(linux_overrides[i].name,linux_overrides[i].value);
1726         */
1727
1728        /*
1729         * Restore defaults
1730         */
1731#ifdef HAVE_FON
1732        int reset = 0;
1733        char *rev = nvram_safe_get("fon_revision");
1734
1735        if (rev == NULL || strlen(rev) == 0)
1736                reset = 1;
1737        if (strlen(rev) > 0) {
1738                int n = atoi(rev);
1739
1740                if (atoi(srouter_defaults[0].value) != n)
1741                        reset = 1;
1742        }
1743        if (reset) {
1744                for (t = srouter_defaults; t->name; t++) {
1745                        for (u = linux_overrides; u && u->name; u++) {
1746                                if (!strcmp(t->name, u->name)) {
1747                                        nvram_set(u->name, u->value);
1748                                        break;
1749                                }
1750                        }
1751                        if (!u || !u->name)
1752                                nvram_set(t->name, t->value);
1753                }
1754        }
1755#endif
1756#ifdef HAVE_GATEWORX
1757        if (restore_defaults) {
1758                eval("erase", "nvram");
1759        }
1760#elif HAVE_XSCALE
1761        if (restore_defaults)
1762                eval("rm", "-f", "/etc/nvram/*");       // delete nvram database
1763#endif
1764#ifdef HAVE_MAGICBOX
1765        if (restore_defaults) {
1766                eval("rm", "-f", "/tmp/nvram/*");       // delete nvram database
1767                eval("rm", "-f", "/tmp/nvram/.lock");   // delete nvram database
1768                eval("erase", "nvram");
1769        }
1770#endif
1771#ifdef HAVE_RB600
1772        if (restore_defaults) {
1773                eval("rm", "-f", "/tmp/nvram/*");       // delete nvram database
1774                eval("rm", "-f", "/tmp/nvram/.lock");   // delete nvram database
1775                eval("erase", "nvram");
1776        }
1777#endif
1778#ifdef HAVE_RT2880
1779        if (restore_defaults) {
1780                eval("erase", "nvram");
1781        }
1782#endif
1783#ifdef HAVE_LAGUNA
1784        if (restore_defaults) {
1785                eval("erase", "nvram");
1786        }
1787#endif
1788#ifdef HAVE_FONERA
1789        if (restore_defaults) {
1790                eval("erase", "nvram");
1791        }
1792#endif
1793#ifdef HAVE_SOLO51
1794        if (restore_defaults) {
1795                eval("erase", "nvram");
1796        }
1797#endif
1798#ifdef HAVE_LS2
1799        if (restore_defaults) {
1800                eval("erase", "nvram");
1801        }
1802#endif
1803#ifdef HAVE_LS5
1804        if (restore_defaults) {
1805                eval("erase", "nvram");
1806        }
1807#endif
1808#ifdef HAVE_WHRAG108
1809        if (restore_defaults) {
1810                eval("erase", "nvram");
1811        }
1812#endif
1813#ifdef HAVE_TW6600
1814        if (restore_defaults) {
1815                eval("erase", "nvram");
1816        }
1817#endif
1818        int nvcnt = 0;
1819
1820#ifndef HAVE_MADWIFI
1821        int icnt = get_wl_instances();
1822#else
1823        int icnt = getdevicecount();
1824#endif
1825#if defined(HAVE_BUFFALO) || defined(HAVE_BUFFALO_BL_DEFAULTS)
1826        buffalo_defaults(restore_defaults);
1827#endif
1828        // if (!nvram_match("default_init","1"))
1829        {
1830                for (t = srouter_defaults; t->name; t++) {
1831                        if (restore_defaults || !nvram_get(t->name)) {
1832                                for (u = linux_overrides; u && u->name; u++) {
1833                                        if (!strcmp(t->name, u->name)) {
1834                                                nvcnt++;
1835                                                nvram_set(u->name, u->value);
1836                                                break;
1837                                        }
1838                                }
1839                                if (!u || !u->name) {
1840                                        nvcnt++;
1841                                        nvram_set(t->name, t->value);
1842                                        if (icnt == 1 && startswith(t->name, "wl1_"))   //unset wl1_xx if we have single radio only
1843                                                nvram_unset(t->name);
1844                                }
1845                        }
1846                }
1847        }
1848        free_defaults();
1849        if (strlen(nvram_safe_get("http_username")) == 0) {
1850                nvram_set("http_username", zencrypt("root"));
1851                nvram_set("http_passwd", zencrypt("admin"));
1852        }
1853#ifndef HAVE_FON
1854        if (restore_defaults) {
1855                switch (brand) {
1856                case ROUTER_ASUS_WL520G:
1857                case ROUTER_ASUS_WL500G_PRE_V2:
1858                case ROUTER_BELKIN_F5D7230_V3000:
1859                case ROUTER_USR_5465:
1860                        nvram_set("vlan0ports", "0 1 2 3 5*");
1861                        nvram_set("vlan1ports", "4 5");
1862                        break;
1863                case ROUTER_LINKSYS_WTR54GS:
1864                        nvram_set("vlan0ports", "0 5*");
1865                        nvram_set("vlan1ports", "1 5");
1866                        break;
1867                case ROUTER_ASUS_WL550GE:
1868                        nvram_set("vlan0ports", "1 2 3 4 5*");
1869                        nvram_set("vlan1ports", "0 5");
1870                        break;
1871                case ROUTER_MOTOROLA:
1872                case ROUTER_WRT54G_V8:
1873                case ROUTER_ASUS_RTN12:
1874                        nvram_set("vlan0ports", "3 2 1 0 5*");
1875                        nvram_set("vlan1ports", "4 5");
1876                        break;
1877                case ROUTER_ASUS_RTN12B:
1878                        nvram_set("vlan0ports", "3 2 1 0 5*");
1879                        nvram_set("vlan1ports", "4 5");
1880                        break;
1881                case ROUTER_LINKSYS_WRH54G:
1882                case ROUTER_ASUS_WL500GD:
1883                case ROUTER_BUFFALO_WBR2G54S:
1884                        nvram_set("vlan0ports", "4 3 2 1 5*");
1885                        nvram_set("vlan1ports", "0 5");
1886                        break;
1887                case ROUTER_USR_5461:
1888                        nvram_set("vlan0ports", "4 1 2 3 5*");
1889                        nvram_set("vlan1ports", "0 5");
1890                        break;
1891                default:
1892                        if (nvram_match("boardnum", "WAP54GV3_8M_0614")) {
1893                                nvram_set("vlan0ports", "3 2 1 0 5*");
1894                                nvram_set("vlan1ports", "4 5");
1895                        }
1896                        break;
1897                }
1898#ifdef HAVE_SPUTNIK
1899                nvram_set("lan_ipaddr", "192.168.180.1");
1900#elif HAVE_BUFFALO
1901                nvram_set("lan_ipaddr", "192.168.11.1");
1902#else
1903                nvram_set("lan_ipaddr", "192.168.1.1");
1904#endif
1905        }
1906#else
1907        if (restore_defaults) {
1908                nvram_set("lan_ipaddr", "192.168.10.1");
1909        }
1910#endif
1911#ifdef HAVE_SKYTRON
1912        if (restore_defaults) {
1913                nvram_set("lan_ipaddr", "192.168.0.1");
1914        }
1915#endif
1916        if (brand == ROUTER_WRT600N) {
1917                if (nvram_match("switch_type", "BCM5395") && nvram_match("vlan0ports", "1 2 3 4 8*"))   // fix for WRT600N
1918                        // v1.1 (BCM5395 does
1919                        // not suppport vid
1920                        // 0, so gemtek
1921                        // internally
1922                        // configured vid 1
1923                        // as lan)
1924                {
1925                        nvram_set("vlan0ports", " ");
1926                        nvram_set("vlan1ports", "1 2 3 4 8*");
1927                        nvram_set("vlan2ports", "0 8*");
1928                        nvram_set("vlan0hwname", " ");
1929                        nvram_set("vlan1hwname", "et0");
1930                        nvram_set("landevs", "vlan1 wl0 wl1");
1931                        nvram_set("lan_ifnames", "vlan1 eth0 eth1");
1932                } else {
1933                        if (!nvram_get("vlan0ports")
1934                            || nvram_match("vlan0ports", "")) {
1935                                nvram_set("vlan0ports", "1 2 3 4 8*");
1936                                nvram_set("vlan2ports", "0 8*");
1937                        }
1938                        if (!nvram_get("vlan2ports")
1939                            || nvram_match("vlan2ports", "")) {
1940                                nvram_set("vlan0ports", "1 2 3 4 8*");
1941                                nvram_set("vlan2ports", "0 8*");
1942                        }
1943                }
1944        } else if (brand == ROUTER_WRT610N || brand == ROUTER_WRT610NV2) {
1945                if (!nvram_get("vlan1ports") || nvram_match("vlan1ports", "")) {
1946                        nvram_set("vlan1ports", "1 2 3 4 8*");
1947                        nvram_set("vlan2ports", "0 8");
1948                }
1949                if (!nvram_get("vlan2ports") || nvram_match("vlan2ports", "")) {
1950                        nvram_set("vlan1ports", "1 2 3 4 8*");
1951                        nvram_set("vlan2ports", "0 8");
1952                }
1953        } else if (brand == ROUTER_WRT350N) {
1954
1955                if (!nvram_get("vlan1ports") || nvram_match("vlan1ports", "")) {
1956                        nvram_set("vlan1ports", "1 2 3 4 8*");
1957                        nvram_set("vlan2ports", "0 8");
1958                }
1959                if (!nvram_get("vlan2ports") || nvram_match("vlan2ports", "")) {
1960                        nvram_set("vlan1ports", "1 2 3 4 8*");
1961                        nvram_set("vlan2ports", "0 8");
1962                }
1963
1964        } else if (brand == ROUTER_WRT310N) {
1965
1966                if (!nvram_get("vlan1ports") || nvram_match("vlan1ports", "")) {
1967                        nvram_set("vlan1ports", "1 2 3 4 8*");
1968                        nvram_set("vlan2ports", "0 8");
1969                }
1970                if (!nvram_get("vlan2ports") || nvram_match("vlan2ports", "")) {
1971                        nvram_set("vlan1ports", "1 2 3 4 8*");
1972                        nvram_set("vlan2ports", "0 8");
1973                }
1974
1975        } else if (brand == ROUTER_WRT300NV11) {
1976
1977                if (!nvram_get("vlan0ports") || nvram_match("vlan0ports", "")) {
1978                        nvram_set("vlan0ports", "1 2 3 4 5*");
1979                        nvram_set("vlan1ports", "0 5");
1980                }
1981                if (!nvram_get("vlan1ports") || nvram_match("vlan1ports", "")) {
1982                        nvram_set("vlan0ports", "1 2 3 4 5*");
1983                        nvram_set("vlan1ports", "0 5");
1984                }
1985
1986        } else if (brand == ROUTER_ASUS_RTN66) {
1987
1988                if (!nvram_get("vlan1ports") || nvram_match("vlan1ports", "")) {
1989                        nvram_set("vlan1ports", "1 2 3 4 8*");
1990                        nvram_set("vlan2ports", "0 8u");
1991                }
1992                if (!nvram_get("vlan2ports") || nvram_match("vlan2ports", "")) {
1993                        nvram_set("vlan1ports", "1 2 3 4 8*");
1994                        nvram_set("vlan2ports", "0 8u");
1995                }
1996
1997        } else if (brand == ROUTER_ASUS_RTN53) {
1998
1999                if (!nvram_get("vlan1ports") || nvram_match("vlan1ports", "")) {
2000                        nvram_set("vlan1ports", "0 5");
2001                        nvram_set("vlan2ports", "1 2 3 4 5*");
2002                }
2003                if (!nvram_get("vlan2ports") || nvram_match("vlan2ports", "")) {
2004                        nvram_set("vlan1ports", "0 5");
2005                        nvram_set("vlan2ports", "1 2 3 4 5*");
2006                }
2007
2008        } else if (brand == ROUTER_BUFFALO_WZRG144NH) {
2009                if (!nvram_get("vlan1ports") || nvram_match("vlan1ports", "")) {
2010                        nvram_set("vlan1ports", "4 8");
2011                        nvram_set("vlan2ports", "0 1 2 3 8*");
2012                }
2013                if (!nvram_get("vlan2ports") || nvram_match("vlan2ports", "")) {
2014                        nvram_set("vlan1ports", "4 8");
2015                        nvram_set("vlan2ports", "0 1 2 3 8*");
2016                }
2017
2018        } else {
2019                if (!nvram_get("vlan0hwname") || nvram_match("vlan0hwname", ""))
2020                        nvram_set("vlan0hwname", "et0");
2021                if (!nvram_get("vlan1hwname") || nvram_match("vlan1hwname", ""))
2022                        nvram_set("vlan1hwname", "et0");
2023
2024                switch (brand) {
2025                case ROUTER_MOTOROLA:
2026                case ROUTER_MOTOROLA_V1:
2027                case ROUTER_MOTOROLA_WE800G:
2028                case ROUTER_RT210W:
2029                        if (et0mac != NULL)
2030                                nvram_set("et0macaddr", et0mac);
2031                        if (et1mac != NULL)
2032                                nvram_set("et1macaddr", et1mac);
2033                        break;
2034                }
2035
2036                if (!nvram_get("vlan0ports") || nvram_match("vlan0ports", "")) {
2037                        switch (brand) {
2038                        case ROUTER_NETGEAR_WNR3500L:
2039                        case ROUTER_WRT320N:
2040                                nvram_unset("vlan0hwname");
2041                                break;
2042                        case ROUTER_LINKSYS_WTR54GS:
2043                                nvram_set("vlan0ports", "0 5*");
2044                                break;
2045                        case ROUTER_ASUS_WL500G_PRE:
2046                        case ROUTER_ASUS_WL700GE:
2047                                nvram_set("vlan0ports", "1 2 3 4 5*");
2048                                break;
2049                        case ROUTER_MOTOROLA:
2050                        case ROUTER_WRT54G_V8:
2051                        case ROUTER_BELKIN_F5D7231_V2000:
2052                                nvram_set("vlan0ports", "3 2 1 0 5*");
2053                                break;
2054                        case ROUTER_LINKSYS_WRT55AG:
2055                        case ROUTER_RT480W:
2056                        case ROUTER_DELL_TRUEMOBILE_2300_V2:
2057                        case ROUTER_ASUS_WL520G:
2058                        case ROUTER_ASUS_WL500G_PRE_V2:
2059                        case ROUTER_WRT54G_V81:
2060                        case ROUTER_BELKIN_F5D7230_V3000:
2061                        case ROUTER_USR_5465:
2062                                nvram_set("vlan0ports", "0 1 2 3 5*");
2063                                break;
2064                        case ROUTER_LINKSYS_WRH54G:
2065                        case ROUTER_ASUS_WL500GD:
2066                        case ROUTER_BUFFALO_WBR2G54S:
2067                                nvram_set("vlan0ports", "4 3 2 1 5*");
2068                                break;
2069                        case ROUTER_USR_5461:
2070                                nvram_set("vlan0ports", "4 1 2 3 5*");
2071                                break;
2072                        default:
2073                                if (nvram_match("bootnv_ver", "4")
2074                                    || nvram_match("boardnum",
2075                                                   "WAP54GV3_8M_0614"))
2076                                        nvram_set("vlan0ports", "3 2 1 0 5*");
2077                                else
2078                                        nvram_set("vlan0ports", "1 2 3 4 5*");
2079                                break;
2080                        }
2081                }
2082
2083                if (!nvram_get("vlan1ports") || nvram_match("vlan1ports", "")) {
2084                        switch (brand) {
2085                        case ROUTER_NETGEAR_WNR3500L:
2086                        case ROUTER_WRT320N:
2087                                nvram_set("vlan2ports", "0 8");
2088                                break;
2089                        case ROUTER_LINKSYS_WTR54GS:
2090                                nvram_set("vlan1ports", "1 5");
2091                                break;
2092                        case ROUTER_ASUS_WL500G_PRE:
2093                        case ROUTER_LINKSYS_WRH54G:
2094                        case ROUTER_USR_5461:
2095                                nvram_set("vlan1ports", "0 5");
2096                                break;
2097                        case ROUTER_MOTOROLA:
2098                        case ROUTER_WRT54G_V8:
2099                        case ROUTER_WRT54G_V81:
2100                        case ROUTER_LINKSYS_WRT55AG:
2101                        case ROUTER_RT480W:
2102                        case ROUTER_DELL_TRUEMOBILE_2300_V2:
2103                        case ROUTER_ASUS_WL520G:
2104                        case ROUTER_ASUS_WL500G_PRE_V2:
2105                        case ROUTER_BELKIN_F5D7230_V3000:
2106                        case ROUTER_BELKIN_F5D7231_V2000:
2107                        case ROUTER_USR_5465:
2108                                nvram_set("vlan1ports", "4 5");
2109                                break;
2110                        default:
2111                                if (nvram_match("bootnv_ver", "4")
2112                                    || nvram_match("boardnum",
2113                                                   "WAP54GV3_8M_0614"))
2114                                        nvram_set("vlan1ports", "4 5");
2115                                else
2116                                        nvram_set("vlan1ports", "0 5");
2117                                break;
2118                        }
2119                }
2120
2121        }
2122
2123        if (restore_defaults) { //hack for VLAN page display for some routers: lan is on vlan1, wan is on vlan2
2124                if (strlen(nvram_safe_get("vlan1ports")) == 10) {
2125                        nvram_set("port0vlans", "2");
2126                        nvram_set("port1vlans", "1");
2127                        nvram_set("port2vlans", "1");
2128                        nvram_set("port3vlans", "1");
2129                        nvram_set("port4vlans", "1");
2130                        nvram_set("port5vlans", "1 2 16");
2131                }
2132        }
2133
2134        if (brand == ROUTER_WRT54G || brand == ROUTER_WRT54G1X
2135            || brand == ROUTER_LINKSYS_WRT55AG) {
2136                if (!nvram_get("aa0"))
2137                        nvram_set("aa0", "3");
2138                if (!nvram_get("ag0"))
2139                        nvram_set("ag0", "255");
2140                if (!nvram_get("gpio2"))
2141                        nvram_set("gpio2", "adm_eecs");
2142                if (!nvram_get("gpio3"))
2143                        nvram_set("gpio3", "adm_eesk");
2144                if (!nvram_get("gpio5"))
2145                        nvram_set("gpio5", "adm_eedi");
2146                if (!nvram_get("gpio6"))
2147                        nvram_set("gpio6", "adm_rc");
2148                if (!nvram_get("boardrev") || nvram_match("boardrev", ""))
2149                        nvram_set("boardrev", "0x10");
2150                if (!nvram_get("boardflags") || nvram_match("boardflags", ""))
2151                        nvram_set("boardflags", "0x0388");
2152                if (!nvram_get("boardflags2"))
2153                        nvram_set("boardflags2", "0");
2154        }
2155
2156        if (restore_defaults &&
2157            (brand == ROUTER_ASUS_RTN10 || brand == ROUTER_ASUS_RTN12
2158             || brand == ROUTER_ASUS_RTN10U || brand == ROUTER_ASUS_RTN53
2159             || brand == ROUTER_ASUS_RTN12B || brand == ROUTER_ASUS_RTN16)) {
2160                nvram_set("wl0_txpwr", "17");
2161        }
2162
2163        if (restore_defaults && (brand == ROUTER_LINKSYS_E4200)) {
2164                nvram_set("wl0_txpwr", "100");
2165                nvram_set("wl1_txpwr", "100");
2166        }
2167#ifndef HAVE_BUFFALO
2168        if (restore_defaults && brand == ROUTER_BUFFALO_WHRG54S
2169            && nvram_match("DD_BOARD", "Buffalo WHR-HP-G54")) {
2170                nvram_set("wl0_txpwr", "28");
2171        }
2172#endif
2173        if (restore_defaults && brand == ROUTER_BUFFALO_WLI_TX4_G54HP) {
2174                nvram_set("wl0_txpwr", "28");
2175        }
2176
2177        /*
2178         * Always set OS defaults
2179         */
2180        nvram_set("os_name", "linux");
2181        nvram_set("os_version", EPI_VERSION_STR);
2182
2183#ifdef HAVE_SPUTNIK_APD
2184        /*
2185         * Added for Sputnik Agent
2186         */
2187        nvram_unset("sputnik_mjid");
2188        nvram_unset("sputnik_rereg");
2189#endif
2190#ifdef HAVE_FREERADIUS
2191        nvram_unset("cert_running");
2192#endif
2193        nvram_unset("probe_blacklist");
2194
2195        if (nvram_get("overclocking") == NULL) {
2196                char *clk = nvram_safe_get("clkfreq");
2197                char dup[64];
2198
2199                strcpy(dup, clk);
2200                int j;
2201                for (j = 0; j < strlen(dup); j++)
2202                        if (dup[j] == ',')
2203                                dup[j] = 0;
2204
2205                nvram_set("overclocking", dup);
2206        }
2207        cprintf("start overclocking\n");
2208        start_overclocking();
2209        cprintf("done()");
2210        if (nvram_get("http_username") != NULL) {
2211                if (nvram_match("http_username", "")) {
2212#ifdef HAVE_POWERNOC
2213                        nvram_set("http_username", "bJz7PcC1rCRJQ");    // admin
2214#else
2215                        nvram_set("http_username", "bJ/GddyoJuiU2");    // root
2216#endif
2217                }
2218        }
2219        if (atoi(nvram_safe_get("nvram_ver")) < 3) {
2220                nvram_set("nvram_ver", "3");
2221                nvram_set("block_multicast", "1");
2222        }
2223        nvram_set("gozila_action", "0");
2224        nvram_set("generate_key", "0");
2225        nvram_set("clone_wan_mac", "0");
2226        nvram_unset("flash_active");
2227
2228        cprintf("check CFE nv\n");
2229        if (check_now_boot() == PMON_BOOT)
2230                check_pmon_nv();
2231        else
2232                check_cfe_nv();
2233        cprintf("restore defaults\n");
2234
2235        glob_t globbuf;
2236        char globstring[1024];
2237        char firststyle[32] = "";
2238        int globresult;
2239
2240        sprintf(globstring, "/www/style/*");
2241        globresult = glob(globstring, GLOB_NOSORT, NULL, &globbuf);
2242        int i, found = 0;
2243        for (i = 0; i < globbuf.gl_pathc; i++) {
2244                char *style;
2245                style = strrchr(globbuf.gl_pathv[i], '/') + 1;
2246#ifdef HAVE_PWC
2247                if (strcmp(style, "pwc"))
2248#endif
2249                        if (firststyle[0] == '\0')
2250                                strcpy(firststyle, style);
2251
2252                if (!strcmp(nvram_get("router_style"), style)) {
2253                        found = 1;
2254                }
2255        }
2256        if (found == 0 && firststyle[0] != '\0') {
2257                fprintf(stderr, "[SET ROUTER STYLE] %s\n", firststyle);
2258                nvram_set("router_style", firststyle);
2259                if (!restore_defaults) {
2260                        nvram_commit();
2261                }
2262        }
2263        globfree(&globbuf);
2264
2265        /*
2266         * Commit values
2267         */
2268        if (restore_defaults) {
2269                int i;
2270
2271                unset_nvram();
2272                nvram_commit();
2273                cprintf("done\n");
2274                for (i = 0; i < MAX_NVPARSE; i++) {
2275                        del_wds_wsec(0, i);
2276                        del_wds_wsec(1, i);
2277                }
2278        }
2279}
2280
2281void start_drivers(void)
2282{
2283        /*
2284         * #ifdef HAVE_USB //load usb driver. we will add samba server, ftp
2285         * server and ctorrent support in future modules = "usbcore usb-ohci
2286         * usb-uhci ehci-hcd scsi_mod usb-storage ide-core ide-detect
2287         * ide-disk ide-scsi cdrom ide-cd printer sd_mod sr_mod" foreach
2288         * (module, modules, next) { cprintf ("loading %s\n", module);
2289         * insmod(module); } #endif
2290         */
2291
2292#ifdef HAVE_USB
2293
2294        fprintf(stderr, "[USB] checking...\n");
2295        if (nvram_match("usb_enable", "1")) {
2296                led_control(USB_POWER, LED_ON);
2297                led_control(LED_USB, LED_ON);
2298
2299                insmod("nls_base");
2300                insmod("usb-common");
2301                cprintf("loading usbcore\n");
2302                insmod("usbcore");
2303
2304                cprintf("loading usb2 module\n");
2305                insmod("ehci-hcd");
2306
2307                cprintf("loading usb-uhci\n");
2308                insmod("usb-uhci");
2309                insmod("uhci-hcd");
2310
2311                cprintf("loading usb-ohci\n");
2312                insmod("usb-ohci");
2313                insmod("ohci-hcd");
2314
2315                insmod("xhci-hcd");
2316                insmod("dwc_otg");      // usb
2317                insmod("usb-libusual");
2318
2319                if (nvram_match("usb_storage", "1")) {
2320                        cprintf("loading scsi_mod\n");
2321                        insmod("scsi_mod");
2322                        insmod("scsi_wait_scan");
2323                        cprintf("loading sd_mod\n");
2324                        insmod("sd_mod");
2325                        cprintf("loading cdrom drivers\n");
2326                        insmod("cdrom");
2327                        insmod("sr_mod");
2328                        cprintf("loading usb-storage\n");
2329                        insmod("usb-storage");
2330                }
2331
2332                if (nvram_match("usb_printer", "1")) {
2333                        cprintf("loading printer\n");
2334                        insmod("printer");
2335                        insmod("usblp");
2336                }
2337#ifdef HAVE_USBIP
2338                if (nvram_match("usb_ip", "1")) {
2339                        cprintf("loading usb over ip drivers\n");
2340                        insmod("usbip_common_mod");
2341                        insmod("usbip");
2342
2343                        insmod("usbip-core");
2344                        insmod("usbip-host");
2345                        eval("usbipd", "-D");
2346                }
2347#endif
2348                mount("devpts", "/proc/bus/usb", "usbfs", MS_MGC_VAL, NULL);
2349//   Mounting is done by hotplug event!         
2350//              if( nvram_match("usb_automnt", "1") && nvram_match("usb_storage", "1")) {
2351//                      printf(stderr, "[USB] check for drives....\n");
2352//                      usb_add_ufd();
2353//              }
2354        } else {
2355                eval("stopservice", "samba3");
2356                eval("stopservice", "ftpsrv");
2357                sysprintf("umount /%s",
2358                          nvram_default_get("usb_mntpoint", "mnt"));
2359                eval("rmmod", "usblp");
2360                eval("rmmod", "printer");
2361                eval("rmmod", "usb-storage");
2362                eval("rmmod", "sr_mod");
2363                eval("rmmod", "cdrom");
2364                eval("rmmod", "sd_mod");
2365                eval("rmmod", "scsi_wait_scan");
2366                eval("rmmod", "scsi_mod");
2367                eval("rmmod", "usb-ohci");
2368                eval("rmmod", "ohci-hcd");
2369                eval("rmmod", "uhci-hcd");
2370                eval("rmmod", "usb-uhci");
2371                eval("rmmod", "ehci-hcd");
2372                eval("rmmod", "usbcore");
2373/* unload filesystems */
2374/* xfs */
2375                eval("rmmod", "xfs");
2376/* fat */
2377                eval("rmmod", "msdos");
2378                eval("rmmod", "vfat");
2379                eval("rmmod", "fat");
2380                eval("rmmod", "nls_utf8");
2381                eval("rmmod", "nls_iso8859-2");
2382                eval("rmmod", "nls_iso8859-1");
2383                eval("rmmod", "nls_cp437");
2384                eval("rmmod", "nls_cp932");
2385                eval("rmmod", "nls_cp936");
2386                eval("rmmod", "nls_cp950");
2387                eval("rmmod", "nls_base");
2388//
2389/* ext3 */
2390#ifdef HAVE_USB_ADVANCED
2391                eval("rmmod", "ext3");
2392                eval("rmmod", "jbd");
2393#endif
2394/* ext2 */
2395                eval("rmmod", "ext2");
2396                eval("rmmod", "mbcache");
2397/* ntfs-3g */
2398#ifdef HAVE_NTFS3G
2399                eval("rmmod", "fuse");
2400#endif
2401
2402                led_control(USB_POWER, LED_OFF);
2403
2404                led_control(LED_USB, LED_OFF);
2405        }
2406#endif
2407
2408}
2409
2410/*
2411 * States
2412 */
2413enum {
2414        RESTART,
2415        STOP,
2416        START,
2417        TIMER,
2418        USER,
2419        IDLE,
2420};
2421static int state = START;
2422static int signalled = -1;
2423
2424/*
2425 * Signal handling
2426 */
2427static void rc_signal(int sig)
2428{
2429        if (state == IDLE) {
2430                if (sig == SIGHUP) {
2431                        printf("signalling RESTART\n");
2432                        signalled = RESTART;
2433                } else if (sig == SIGUSR2) {
2434                        printf("signalling START\n");
2435                        signalled = START;
2436                } else if (sig == SIGINT) {
2437                        printf("signalling STOP\n");
2438                        signalled = STOP;
2439                } else if (sig == SIGALRM) {
2440                        printf("signalling TIMER\n");
2441                        signalled = TIMER;
2442                } else if (sig == SIGUSR1) {    // Receive from WEB
2443                        printf("signalling USER1\n");
2444                        signalled = USER;
2445                }
2446
2447        }
2448}
2449
2450/*
2451 * Timer procedure
2452 */
2453int do_timer(void)
2454{
2455        // do_ntp();
2456        return 0;
2457}
2458
2459#define CONVERT_NV(old, new) \
2460        if(nvram_get(old)) \
2461                nvram_set(new, nvram_safe_get(old));
2462
2463void start_nvram(void)
2464{
2465        int i = 0;
2466
2467        /*
2468         * broadcom 3.11.48.7 change some nvram name
2469         */
2470
2471        nvram_unset("wl0_hwaddr");      // When disbale wireless, we must get
2472        //
2473        // null wireless mac */
2474
2475        nvram_set("wan_get_dns", "");
2476        nvram_set("filter_id", "1");
2477        nvram_set("wl_active_add_mac", "0");
2478        nvram_set("ddns_change", "");
2479        nvram_unset("action_service");
2480        nvram_set("wan_get_domain", "");
2481
2482        // if(!nvram_get("wl_macmode1")){
2483        // if(nvram_match("wl_macmode","disabled"))
2484        // nvram_set("wl_macmode1","disabled");
2485        // else
2486        // nvram_set("wl_macmode1","other");
2487        // }
2488        if (nvram_match("wl_gmode", "5"))       // Mixed mode had been
2489                // changed to 5
2490                nvram_set("wl_gmode", "1");
2491
2492        if (nvram_match("wl_gmode", "4"))       // G-ONLY mode had been
2493                // changed to 2, after 1.40.1
2494                // for WiFi G certication
2495                nvram_set("wl_gmode", "2");
2496
2497        // nvram_set("wl_country","Worldwide"); // The country always Worldwide
2498
2499        nvram_set("ping_ip", "");
2500        nvram_set("ping_times", "");
2501        // nvram_set ("traceroute_ip", "");
2502
2503        nvram_set("filter_port", "");   // The name have been disbaled from
2504        // 1.41.3
2505
2506#ifdef HAVE_UPNP
2507        if ((nvram_match("restore_defaults", "1"))
2508            || (nvram_match("upnpcas", "1"))) {
2509                nvram_set("upnp_clear", "1");
2510        } else {
2511                char s[32];
2512                char *nv;
2513
2514                for (i = 0; i < MAX_NVPARSE; ++i) {
2515                        sprintf(s, "forward_port%d", i);
2516                        if ((nv = nvram_get(s)) != NULL) {
2517                                if (strstr(nv, "msmsgs"))
2518                                        nvram_unset(s);
2519                        }
2520                }
2521        }
2522        nvram_set("upnp_wan_proto", "");
2523#endif
2524
2525        /*
2526         * The tkip and aes already are changed to wl_crypto from v3.63.3.0
2527         */
2528        if (nvram_match("wl_wep", "tkip")) {
2529                nvram_set("wl_crypto", "tkip");
2530        } else if (nvram_match("wl_wep", "aes")) {
2531                nvram_set("wl_crypto", "aes");
2532        } else if (nvram_match("wl_wep", "tkip+aes")) {
2533                nvram_set("wl_crypto", "tkip+aes");
2534        }
2535
2536        if (nvram_match("wl_wep", "restricted"))
2537                nvram_set("wl_wep", "enabled"); // the nas need this value,
2538        // the "restricted" is no
2539        // longer need. (20040624 by
2540        // honor)
2541
2542#ifdef HAVE_SET_BOOT
2543        if (!nvram_match("boot_wait_web", "0"))
2544                nvram_set("boot_wait_web", "1");
2545#endif
2546#ifndef HAVE_BUFFALO
2547        if (check_hw_type() == BCM5352E_CHIP) {
2548                nvram_set("opo", "0");  // OFDM power reducement in quarter
2549                // dbm (2 dbm in this case)
2550                nvram_set("ag0", "0");  // Antenna Gain definition in dbm
2551        }
2552#endif
2553
2554        if (nvram_match("svqos_port1bw", "full"))
2555                nvram_set("svqos_port1bw", "FULL");
2556        if (nvram_match("svqos_port2bw", "full"))
2557                nvram_set("svqos_port2bw", "FULL");
2558        if (nvram_match("svqos_port3bw", "full"))
2559                nvram_set("svqos_port3bw", "FULL");
2560        if (nvram_match("svqos_port4bw", "full"))
2561                nvram_set("svqos_port4bw", "FULL");
2562        // dirty fix for WBR2 units
2563
2564        // clean old filter_servicesX to free nvram
2565        nvram_unset("filter_services0");
2566        nvram_unset("filter_services1");
2567        nvram_unset("filter_services2");
2568        nvram_unset("filter_services3");
2569        nvram_unset("filter_services4");
2570        nvram_unset("filter_services5");
2571        nvram_unset("filter_services6");
2572        nvram_unset("filter_services7");
2573
2574        nvram_unset("vdsl_state");      // important (this value should never
2575        //
2576        // be commited, but if this will fix
2577        // the vlan7 issue)
2578        nvram_unset("fromvdsl");        // important (this value should never be
2579        // commited, but if this will fix the vlan7
2580        // issue)
2581
2582        nvram_unset("do_reboot");       //for GUI, see broadcom.c
2583
2584#ifdef DIST
2585        nvram_set("dist_type", DIST);
2586#endif
2587
2588        {
2589
2590#ifdef DIST
2591#ifndef HAVE_TW6600
2592#ifdef HAVE_MICRO
2593                // if dist_type micro, check styles, and force to elegant if needed
2594
2595#ifdef HAVE_ROUTERSTYLE
2596                char *style = nvram_safe_get("router_style");
2597
2598                if (!strstr("blue cyan elegant green orange red yellow", style))
2599#endif
2600                {
2601                        nvram_set("router_style", "elegant");
2602                }
2603#endif
2604#endif
2605#endif
2606        }
2607
2608#ifdef HAVE_WIVIZ
2609        if (!strlen(nvram_safe_get("hopseq"))
2610            || !strlen(nvram_safe_get("hopdwell"))) {
2611                nvram_set("hopdwell", "1000");
2612                nvram_set("hopseq", "0");
2613        }
2614#endif
2615        nvram_unset("lasthour");
2616#ifdef HAVE_AQOS
2617        //filter hostapd shaping rules
2618       
2619        char *qos_mac = nvram_safe_get("svqos_macs");
2620
2621        if (strlen(qos_mac) > 0) {
2622                char *newqos = malloc(strlen(qos_mac) + 254);
2623                memset(newqos, 0, strlen(qos_mac)+254);
2624
2625                char level[32], level2[32], data[32], type[32], level3[32];
2626
2627                do {
2628                        if (sscanf
2629                            (qos_mac, "%31s %31s %31s %31s %31s |", data, level,
2630                             level2, type, level3) < 5)
2631                                break;
2632
2633                        if(!strcmp(level3, "|"))
2634                                strcpy(level3, "0");
2635
2636                        if (strcmp(type, "hostapd") && strcmp(type, "pppd")) {
2637                                if (strlen(newqos) > 0)
2638                                        sprintf(newqos, "%s %s %s %s %s %s |",
2639                                                newqos, data, level, level2,
2640                                                type, level3);
2641                                else
2642                                        sprintf(newqos, "%s %s %s %s %s |", data,
2643                                                level, level2, type, level3);
2644
2645                        }
2646                }
2647                while ((qos_mac = strpbrk(++qos_mac, "|")) && qos_mac++);
2648                nvram_set("svqos_macs", newqos);
2649                free(newqos);
2650        }
2651       
2652        char *qos_ip = nvram_safe_get("svqos_ips");
2653
2654        if (strlen(qos_ip) > 0) {
2655                char *newip = malloc(strlen(qos_ip) + 254);
2656                memset(newip, 0, strlen(qos_ip)+254);
2657               
2658                char data[32], level[32], level2[32], level3[32];
2659               
2660                do {
2661                        if (sscanf(qos_ip, "%31s %31s %31s %31s |", data, level, level2, level3) < 4)
2662                                break;
2663                       
2664                        if (!strcmp(level3, "|"))
2665                                strcpy(level3, "0");
2666                       
2667                        if (strlen(newip) > 0)
2668                                sprintf(newip, "%s %s %s %s %s |", newip, data, level, level2, level3);
2669                        else
2670                                sprintf(newip, "%s %s %s %s |", data, level, level2, level3);
2671                }
2672                while ((qos_ip = strpbrk(++qos_ip, "|")) && qos_ip++);
2673                nvram_set("svqos_ips", newip);
2674                free(newip);
2675        }
2676       
2677#endif
2678        return;
2679}
2680
2681static void unset_nvram(void)
2682{
2683#ifndef MPPPOE_SUPPORT
2684        nvram_safe_unset("ppp_username_1");
2685        nvram_safe_unset("ppp_passwd_1");
2686        nvram_safe_unset("ppp_idletime_1");
2687        nvram_safe_unset("ppp_demand_1");
2688        nvram_safe_unset("ppp_redialperiod_1");
2689        nvram_safe_unset("ppp_service_1");
2690        nvram_safe_unset("mpppoe_enable");
2691        nvram_safe_unset("mpppoe_dname");
2692#endif
2693#ifndef HAVE_HTTPS
2694        nvram_safe_unset("remote_mgt_https");
2695#endif
2696#ifndef HSIAB_SUPPORT
2697        nvram_safe_unset("hsiab_mode");
2698        nvram_safe_unset("hsiab_provider");
2699        nvram_safe_unset("hsiab_device_id");
2700        nvram_safe_unset("hsiab_device_password");
2701        nvram_safe_unset("hsiab_admin_url");
2702        nvram_safe_unset("hsiab_registered");
2703        nvram_safe_unset("hsiab_configured");
2704        nvram_safe_unset("hsiab_register_ops");
2705        nvram_safe_unset("hsiab_session_ops");
2706        nvram_safe_unset("hsiab_config_ops");
2707        nvram_safe_unset("hsiab_manual_reg_ops");
2708        nvram_safe_unset("hsiab_proxy_host");
2709        nvram_safe_unset("hsiab_proxy_port");
2710        nvram_safe_unset("hsiab_conf_time");
2711        nvram_safe_unset("hsiab_stats_time");
2712        nvram_safe_unset("hsiab_session_time");
2713        nvram_safe_unset("hsiab_sync");
2714        nvram_safe_unset("hsiab_config");
2715#endif
2716
2717#ifndef HEARTBEAT_SUPPORT
2718        nvram_safe_unset("hb_server_ip");
2719        nvram_safe_unset("hb_server_domain");
2720#endif
2721
2722#ifndef PARENTAL_CONTROL_SUPPORT
2723        nvram_safe_unset("artemis_enable");
2724        nvram_safe_unset("artemis_SVCGLOB");
2725        nvram_safe_unset("artemis_HB_DB");
2726        nvram_safe_unset("artemis_provisioned");
2727#endif
2728
2729#ifndef WL_STA_SUPPORT
2730        // nvram_safe_unset("wl_ap_ssid");
2731        // nvram_safe_unset("wl_ap_ip");
2732#endif
2733
2734#ifdef HAVE_3G
2735        // make sure we dial in mode 5 with 3g first!
2736        nvram_unset("3gnetmodetoggle");
2737#endif
2738
2739}
Note: See TracBrowser for help on using the repository browser.