| 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 |
extern void load_defaults(void); |
|---|
| 95 |
extern void free_defaults(void); |
|---|
| 96 |
|
|---|
| 97 |
void start_defaults(void) |
|---|
| 98 |
{ |
|---|
| 99 |
fprintf(stderr, "restore nvram to defaults\n"); |
|---|
| 100 |
char *buf = (char *)malloc(NVRAM_SPACE); |
|---|
| 101 |
int i; |
|---|
| 102 |
struct nvram_tuple *t; |
|---|
| 103 |
|
|---|
| 104 |
nvram_getall(buf, NVRAM_SPACE); |
|---|
| 105 |
char *p = buf; |
|---|
| 106 |
|
|---|
| 107 |
//clean old values |
|---|
| 108 |
while (strlen(p) != 0) { |
|---|
| 109 |
int len = strlen(p); |
|---|
| 110 |
|
|---|
| 111 |
for (i = 0; i < len; i++) |
|---|
| 112 |
if (p[i] == '=') |
|---|
| 113 |
p[i] = 0; |
|---|
| 114 |
char *name = p; |
|---|
| 115 |
|
|---|
| 116 |
if (!isCritical(name)) |
|---|
| 117 |
nvram_unset(name); |
|---|
| 118 |
p += len + 1; |
|---|
| 119 |
} |
|---|
| 120 |
load_defaults(); |
|---|
| 121 |
for (t = srouter_defaults; t->name; t++) { |
|---|
| 122 |
nvram_set(t->name, t->value); |
|---|
| 123 |
} |
|---|
| 124 |
free_defaults(); |
|---|
| 125 |
free(buf); |
|---|
| 126 |
nvram_commit(); |
|---|
| 127 |
} |
|---|