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

Last change on this file since 17453 was 17453, checked in by BrainSlayer, 23 months ago

for newer versions

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