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