4 # This file handles the NVRAM quirks of various hardware.
6 . /etc/network.overrides
7 alias debug=${DEBUG:-:}
10 [ "$(/usr/bin/head -c4 /dev/mtdblock/1 | /usr/bin/tail -c3)" = "ELF" ] && exit
13 for type in lan wifi wan pppoe
17 eval nvram set ${type}_ifname$s=\"$(nvram get ${type}_ifname$s|sed s/$1/$2/g)\"
23 [ -z "$(nvram get $1)" ] && nvram set "$1=$2"
26 nvram_set() { # for the linksys fixup part
27 [ "$(nvram get "$1")" = "$2" -a "$2" != "" ] || {
29 /usr/sbin/nvram set "$1=$2"
33 # work around braindead CFE defaults in linksys routers
34 boardtype=$(nvram get boardtype)
35 boardflags=$(($(nvram get boardflags)))
36 [ "$boardtype" = "bcm94710dev" ] && boardtype="0xdeadbeef"
37 adm_switch="$(( ($boardflags & 0x80) >> 7 ))"
38 case "$(( $boardtype ))" in
40 if [ "$adm_switch" = 0 ]; then
41 nvram_set sdram_init "$(printf 0x%04x $(( $(/usr/sbin/nvram get sdram_init) | 0x0100 )))"
42 [ "$COMMIT" = 1 ] && {
43 nvram_set sdram_config 0x0062
45 nvram_set sdram_ncdl 0x0
46 nvram_set pa0itssit 62
47 nvram_set pa0b0 0x15eb
48 nvram_set pa0b1 0xfa82
49 nvram_set pa0b2 0xfe66
50 nvram_set pa0maxpwr 0x4e
55 nvram_set sdram_init "$(printf 0x%04x $(( $(/usr/sbin/nvram get sdram_init) | 0x0100 )))"
56 [ "$COMMIT" = 1 ] && {
57 nvram_set sdram_config 0x0062
58 nvram_set sdram_ncdl 0x0
59 nvram_set pa0itssit 62
60 nvram_set pa0b0 0x168b
61 nvram_set pa0b1 0xfabf
62 nvram_set pa0b2 0xfeaf
63 nvram_set pa0maxpwr 0x4e
67 [ "$COMMIT" = "1" ] && nvram commit
70 # linksys bug; remove when not using static configuration for lan
71 nvram set lan_proto="static"
73 # hacks for wrt54g 1.x hardware
74 [ "$(nvram get boardnum)" = "42" \
75 -a "$(nvram get boardtype)" = "bcm94710dev" ] && {
76 debug "### wrt54g 1.x hack ###"
77 nvram set vlan1hwname="et0"
78 nvram set vlan2hwname="et0"
83 # hacks for asus wl-500g deluxe
84 [ "$(nvram get boardtype)" = "bcm95365r" \
85 -a "$(nvram get boardnum)" = "45" ] && {
86 debug "### wl-500g deluxe hacks ###"
87 nvram set vlan0hwname="et0"
88 nvram set vlan1hwname="et0"
92 # set up the vlan*ports variables for the asus wl-500g deluxe
93 # if they don't already exist
94 nvram_default vlan0ports "1 2 3 4 5*"
95 nvram_default vlan1ports "0 5"
99 case "$(nvram get productid)" in
101 debug "### wl-300g hacks ###"
102 nvram set lan_ifnames="eth0 eth2"
103 nvram set wan_ifname="none"
106 debug "### wl-hdd hacks ###"
107 nvram set lan_ifnames="eth1 eth2"
108 nvram set wan_ifname="none"
111 # wl-500g defaults. these are placed here, because WL-HDD and WL-300g
112 # might have the same nvram settings.
113 [ "$(nvram get boardnum)" = "asusX" \
114 -a "$(nvram get boardtype)" = "bcm94710dev" ] && {
115 nvram_default wan_device "eth1"
120 # hacks for wap54g hardware
121 [ "$(nvram get boardnum)" = "2" \
122 -o "$(nvram get boardnum)" = "1024" ] && {
123 debug "### wap54g hack ###"
124 nvram set wan_ifname="none"
127 # hacks for buffalo wla2-g54l
128 [ "$(nvram get boardnum)" = "00" \
129 -a "$(nvram get product_name)" = "Product_name" \
130 -o "$(nvram get product_name)" = "WLA2-G54L" ] && {
131 debug "### wla2-g54l hacks ###"
132 nvram set wan_ifname="none"
133 nvram set lan_ifnames="vlan0"
136 # needed at least for wrt54gs v1.1 and wrt54g v2.0, v2.2
137 [ \! -z "$(nvram get boardrev)" ] && {
138 nvram_default wl0id 0x4320
142 nvram_default lan_ifname "br0"
143 nvram_default lan_ifnames "$FAILSAFE_ifnames"
145 nvram_default wan_ifname "vlan1"
146 nvram_default wan_device "vlan1"
147 nvram_default wan_proto "dhcp"
149 nvram_default wl0_ssid OpenWrt
150 nvram_default wl0_mode ap
151 nvram_default wl0_infra 1
152 nvram_default wl0_radio 1
154 WAN_PROTO="$(nvram get wan_proto)"
155 WAN_IFNAME="$(nvram get wan_ifname)"
157 pp*) [ "${WAN_IFNAME%%[0-9]*}" = "ppp" ] || nvram set wan_ifname=ppp0;;
158 *) [ "${WAN_IFNAME%%[0-9]*}" = "ppp" ] && nvram set wan_ifname="$(nvram get wan_device)";;
161 [ "$(nvram get il0macaddr)" = "00:90:4c:5f:00:2a" ] && {
162 # if default wifi mac, set two higher than the lan mac
163 nvram set il0macaddr=$(nvram get et0macaddr|
164 awk '{OFS=FS=":";for(x=7,y=2;--x;){$x=sprintf("%02x",(y+="0x"$x)%256);y/=256}print}')