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

Last change on this file since 17788 was 17788, checked in by BrainSlayer, 19 months ago

adjusted region dependend defaults

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