root/src/router/services/tools/reset_defaults.c

Revision 12224, 2.4 kB (checked in by BrainSlayer, 6 months ago)

code formating

Line 
1 /*
2  * beep.c
3  *
4  * Copyright (C) 2008 Sebastian Gottschall <gottschall@dd-wrt.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * $Id:
21  */
22 #include <unistd.h>
23 #include <sys/types.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <stdlib.h>
27 #include <fcntl.h>
28 #include <utils.h>
29 #include <wlutils.h>
30 #include <bcmnvram.h>
31
32 static char *filter[] = { "lan_ifnames",
33         "lan_ifname",
34         "wan_ifnames",
35         "wan_ifname",
36         "et0macaddr",
37         "et1macaddr",
38         "il0macaddr",
39         "boardnum",
40         "boardtype",
41         "boardrev",
42         "melco_id",
43         "product_name",
44         "phyid_num",
45         "cardbus",
46         "CFEver",
47         "clkfreq",
48         "boardflags",
49         "boardflags2",
50         "sromrev",
51         "sdram_config",
52         "sdram_init",
53         "sdram_refresh",
54         "sdram_ncdl",
55         "boot_wait",
56         "wait_time",
57         "et0phyaddr",
58         "et0mdcport",
59         "vlan0ports",
60         "vlan1ports",
61         "vlan2ports",
62         "vlan0hwname",
63         "vlan1hwname",
64         "vlan2hwname",
65         "wl_use_coregpio",
66         "wl0gpio0",
67         "wl0gpio1",
68         "wl0gpio2",
69         "wl0gpio3",
70         "wl0gpio4",
71         "reset_gpio",
72         "af_hash",
73         "wan_ifname",
74         "lan_ifname",
75         "lan_ifnames",
76         "wan_ifnames",
77         "wan_default",
78         NULL
79 };
80
81 extern struct nvram_tuple srouter_defaults[];
82
83 static int isCritical(char *name)
84 {
85         int a = 0;
86
87         while (filter[a] != NULL) {
88                 if (!strcmp(name, filter[a++])) {
89                         return 1;
90                 }
91         }
92         return 0;
93 }
94
95 void start_defaults(void)
96 {
97         fprintf(stderr, "restore nvram to defaults\n");
98         char *buf = (char *)malloc(NVRAM_SPACE);
99         int i;
100         struct nvram_tuple *t;
101
102         nvram_getall(buf, NVRAM_SPACE);
103         char *p = buf;
104
105         //clean old values
106         while (strlen(p) != 0) {
107                 int len = strlen(p);
108
109                 for (i = 0; i < len; i++)
110                         if (p[i] == '=')
111                                 p[i] = 0;
112                 char *name = p;
113
114                 if (!isCritical(name))
115                         nvram_unset(name);
116                 p += len + 1;
117         }
118         for (t = srouter_defaults; t->name; t++) {
119                 nvram_set(t->name, t->value);
120         }
121         free(buf);
122         nvram_commit();
123 }
Note: See TracBrowser for help on using the browser.