c0b58101c0bf7b64ffc2025b0bb85b661e78369e
[openwrt/svn-archive/archive.git] / openwrt / package / base-files / default / etc / init.d / S05nvram
1 #!/bin/sh
2 # NVRAM setup
3 #
4 # This file handles the NVRAM quirks of various hardware.
5
6 . /etc/nvram.overrides
7 alias debug=${DEBUG:-:}
8
9 remap () {
10 for type in lan wifi wan pppoe
11 do
12 for s in '' s
13 do
14 eval nvram set ${type}_ifname$s=\"$(nvram get ${type}_ifname$s|sed s/$1/$2/g)\"
15 done
16 done
17 }
18
19 nvram_default() {
20 [ -z "$(nvram get $1)" ] && nvram set "$1=$2"
21 }
22
23 nvram_set() { # for the linksys fixup part
24 [ "$(nvram get "$1")" = "$2" -a "$2" != "" ] || {
25 COMMIT=1
26 /usr/sbin/nvram set "$1=$2"
27 }
28 }
29
30 # work around braindead CFE defaults in linksys routers
31 boardtype=$(nvram get boardtype)
32 boardflags=$(($(nvram get boardflags)))
33 [ "$boardtype" = "bcm94710dev" ] && boardtype="0xdeadbeef"
34 adm_switch="$(( ($boardflags & 0x80) >> 7 ))"
35 case "$(( $boardtype ))" in
36 "$((0x708))")
37 if [ "$adm_switch" = 0 ]; then
38 nvram_set sdram_init "$(printf 0x%04x $(( $(/usr/sbin/nvram get sdram_init) | 0x0100 )))"
39 [ "$COMMIT" = 1 ] && {
40 nvram_set sdram_config 0x0062
41 nvram_set clkfreq 216
42 nvram_set sdram_ncdl 0x0
43 nvram_set pa0itssit 62
44 nvram_set pa0b0 0x15eb
45 nvram_set pa0b1 0xfa82
46 nvram_set pa0b2 0xfe66
47 nvram_set pa0maxpwr 0x4e
48 }
49 fi
50 ;;
51 "$((0x467))")
52 nvram_set sdram_init "$(printf 0x%04x $(( $(/usr/sbin/nvram get sdram_init) | 0x0100 )))"
53 [ "$COMMIT" = 1 ] && {
54 nvram_set sdram_config 0x0062
55 nvram_set sdram_ncdl 0x0
56 nvram_set pa0itssit 62
57 nvram_set pa0b0 0x168b
58 nvram_set pa0b1 0xfabf
59 nvram_set pa0b2 0xfeaf
60 nvram_set pa0maxpwr 0x4e
61 }
62 ;;
63 esac
64 [ "$COMMIT" = "1" ] && nvram commit
65
66
67 # linksys bug; remove when not using static configuration for lan
68 nvram set lan_proto="static"
69
70 # hacks for wrt54g 1.x hardware
71 [ "$(nvram get boardnum)" = "42" \
72 -a "$(nvram get boardtype)" = "bcm94710dev" ] && {
73 debug "### wrt54g 1.x hack ###"
74 nvram set vlan1hwname="et0"
75 nvram set vlan2hwname="et0"
76 remap eth0 vlan2
77 remap eth1 vlan1
78 }
79
80 # hacks for asus wl-500g deluxe
81 [ "$(nvram get boardtype)" = "bcm95365r" \
82 -a "$(nvram get boardnum)" = "45" ] && {
83 debug "### wl-500g deluxe hacks ###"
84 nvram set vlan0hwname="et0"
85 nvram set vlan1hwname="et0"
86 remap eth0.1 vlan0
87 remap eth0 vlan1
88
89 # set up the vlan*ports variables for the asus wl-500g deluxe
90 # if they don't already exist
91 nvram_default vlan0ports "1 2 3 4 5*"
92 nvram_default vlan1ports "0 5"
93 }
94
95 # hacks for asus
96 case "$(nvram get productid)" in
97 WL300g)
98 debug "### wl-300g hacks ###"
99 nvram set lan_ifnames="eth0 eth2"
100 nvram set wan_ifname="none"
101 ;;
102 WLHDD)
103 debug "### wl-hdd hacks ###"
104 nvram set lan_ifnames="eth1 eth2"
105 nvram set wan_ifname="none"
106 ;;
107 *)
108 # wl-500g defaults. these are placed here, because WL-HDD and WL-300g
109 # might have the same nvram settings.
110 [ "$(nvram get boardnum)" = "asusX" \
111 -a "$(nvram get boardtype)" = "bcm94710dev" ] && {
112 nvram_default wan_device "eth1"
113 }
114 ;;
115 esac
116
117 # hacks for wap54g hardware
118 [ "$(nvram get boardnum)" = "2" \
119 -o "$(nvram get boardnum)" = "1024" ] && {
120 debug "### wap54g hack ###"
121 nvram set wan_ifname="none"
122 }
123
124 # hacks for buffalo wla2-g54l
125 [ "$(nvram get boardnum)" = "00" \
126 -a "$(nvram get product_name)" = "Product_name" \
127 -o "$(nvram get product_name)" = "WLA2-G54L" ] && {
128 debug "### wla2-g54l hacks ###"
129 nvram set wan_ifname="none"
130 nvram set lan_ifnames="vlan0"
131 }
132
133 # needed at least for wrt54gs v1.1 and wrt54g v2.0, v2.2
134 [ \! -z "$(nvram get boardrev)" ] && {
135 nvram_default wl0id 0x4320
136 }
137
138 # defaults
139 nvram_default lan_ifname "br0"
140 nvram_default lan_ifnames "$FAILSAFE_ifnames"
141
142 nvram_default wan_ifname "vlan1"
143 nvram_default wan_device "vlan1"
144 nvram_default wan_proto "dhcp"
145
146 nvram_default wl0_ssid OpenWrt
147 nvram_default wl0_mode ap
148 nvram_default wl0_infra 1
149 nvram_default wl0_radio 1
150
151 WAN_PROTO="$(nvram get wan_proto)"
152 WAN_IFNAME="$(nvram get wan_ifname)"
153 case "$WAN_PROTO" in
154 pp*) [ "${WAN_IFNAME%%[0-9]*}" = "ppp" ] || nvram set wan_ifname=ppp0;;
155 *) [ "${WAN_IFNAME%%[0-9]*}" = "ppp" ] && nvram set wan_ifname="$(nvram get wan_device)";;
156 esac
157
158 [ "$(nvram get il0macaddr)" = "00:90:4c:5f:00:2a" ] && {
159 # if default wifi mac, set two higher than the lan mac
160 nvram set il0macaddr=$(nvram get et0macaddr|
161 awk '{OFS=FS=":";for(x=7,y=2;--x;){$x=sprintf("%02x",(y+="0x"$x)%256);y/=256}print}')
162 }
163