1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006 OpenWrt.org
7 [ -e /etc/config/network ] && {
18 append batch "delete network.eth0.${1}${N}"
19 append batch "set network.eth0_${id}=switch_vlan${N}"
20 append batch "set network.eth0_${id}.device=eth0${N}"
21 append batch "set network.eth0_${id}.vlan=${id}${N}"
22 append batch "set network.eth0_${id}.ports='${ports}'${N}"
37 logger -t netconfig "migrating switch config to new format ..."
38 echo "$batch${N}commit network" | uci batch
47 [ -e /sbin/swconfig ] && cpuport=$(swconfig dev switch0 help 2>/dev/null | sed -ne "s|.*cpu @ \([0-9]*\).*|\1|p")
50 if grep -E 'mtd0: 000(6|a)0000' /proc/mtd 2>&- >&-; then
52 echo boardtype=wgt634u
54 strings "$(find_mtd_part nvram)"
56 ) | awk -v cpuport="$cpuport" '
57 function macinc(mac, maca, i, result) {
59 for (i = 1; i <= 6; i++) maca[i] = "0x" maca[i]
60 if (++maca[6] > 0xff) {
64 for (i = 1; i <= 6; i++) {
65 if (i != 1) result = result ":"
66 result = result sprintf("%02x", maca[i])
73 c["lan_ifname"]="eth0.1"
74 c["wan_ifname"]="eth0.2"
75 c["vlan1ports"]="1 2 3 4 5t"
76 c["vlan2ports"]="0 5t"
77 getline < "/proc/diag/model"
79 for (i = 0; i < 6; i++) {
80 if (mac_check != "") mac_check = mac_check ":"
81 mac_check = mac_check "[0-9a-fA-F][0-9a-fA-F]"
84 c["vlan1ports"]="1 2 3 4 8t"
85 c["vlan2ports"]="0 8t"
89 ($1 == "boardnum") || ($1 == "boardtype") || ($1 == "boardflags") || ($1 ~ /macaddr/) || \
90 ($1 ~ /^vlan[0-9]{1,2}ports$/) {
95 if (((nvram["vlan0ports"] ~ /^0 1 2 3 8/ ) && (nvram["vlan1ports"] ~ /^4 8/ && (cpuport == "8"))) || \
96 ((nvram["vlan1ports"] ~ /^0 1 2 3 8/ ) && (nvram["vlan2ports"] ~ /^4 8/ && (cpuport == "8")))) {
97 c["vlan1ports"] = "0 1 2 3 8t"
98 c["vlan2ports"] = "4 8t"
100 if (((nvram["vlan0ports"] ~ /^0 1 2 3 5/ ) && (nvram["vlan1ports"] ~ /^4 5/ && (cpuport == "5"))) || \
101 ((nvram["vlan1ports"] ~ /^0 1 2 3 5/ ) && (nvram["vlan2ports"] ~ /^4 5/ && (cpuport == "5")))) {
102 c["vlan1ports"] = "0 1 2 3 5t"
103 c["vlan2ports"] = "4 5t"
105 if ((model == "ASUS WL-HDD") || (model == "ASUS WL-300g") || (model == "Linksys WAP54G V1")) {
107 c["lan_ifname"] = "eth1"
109 if (model == "ASUS WL-330gE") {
111 c["lan_ifname"] = "eth0.1"
112 c["vlan1ports"] = "4 5t"
115 if ((model == "ASUS WL-500g") || (model == "Microsoft MN-700")) {
116 c["wan_ifname"] = "eth1"
117 c["lan_ifname"] = "eth0"
119 if ((model == "ASUS WL-500g Premium V2") || (model == "Dell TrueMobile 2300 v2") || (model == "Buffalo WHR-G125")) {
120 c["vlan1ports"] = "0 1 2 3 5t"
121 c["vlan2ports"] = "4 5t"
123 if (model == "Dell TrueMobile 2300") {
124 c["lan_ifname"] = "eth0"
125 c["wan_ifname"] = "eth1"
126 c["vlan1ports"] = "0 1 2 3 4 5"
129 if (nvram["boardtype"] == "bcm94710r4") {
131 c["lan_ifname"] = "eth0"
132 c["wan_ifname"] = "eth1"
134 if ((nvram["boardtype"] == "wgt634u") || (nvram["boardtype"] == "0x0467")) {
135 c["vlan1ports"] = "0 1 2 3 5t"
136 c["vlan2ports"] = "4 5t"
138 if ((nvram["boardtype"] == "0x042f") || (nvram["boardtype"] == "0x0472")) {
139 if (nvram["boardnum"] == "45") {
141 c["vlan1ports"] = "1 2 3 4 5t"
142 c["vlan2ports"] = "0 5t"
145 c["vlan1ports"] = "0 1 2 3 4 5"
147 c["lan_ifname"] = "eth0"
148 c["wan_ifname"] = "eth1"
150 # MAC addresses on 4704 tend to be screwed up. Add a workaround here
151 if (nvram["et0macaddr"] ~ mac_check) {
152 c["lan_macaddr"] = nvram["et0macaddr"]
153 c["wan_macaddr"] = macinc(c["lan_macaddr"])
157 # Buffalo WBR-B11 and Buffalo WBR-G54
158 if (nvram["boardtype"] == "bcm94710ap") {
159 c["vlan1ports"] = "0 1 2 3 4 5"
161 c["lan_ifname"] = "eth0"
162 c["wan_ifname"] = "eth1"
166 if ((nvram["boardnum"] == "2") || \
167 (nvram["boardnum"] == "1024")) {
168 c["lan_ifname"]="eth0"
173 if ((nvram["boardum"] == "2") && \
174 (nvram["GemtekPmonVer"] == "1")) {
175 c["lan_ifname"]="eth0"
180 # These are actually same as defaults above. For some reason this script applies
181 # Generic BCM94704 settings instead so we revert to proper settings here.
182 # Hopefully someone will fix this properly soon.
183 if (model == "ASUS WL-700gE") {
184 c["lan_ifname"]="eth0.1"
185 c["wan_ifname"]="eth0.2"
186 c["vlan1ports"]="1 2 3 4 5t"
187 c["vlan2ports"]="0 5t"
189 if ((model == "Motorola WR850G V2/V3") || (model == "Siemens SE505 V2")) {
190 c["vlan1ports"]="0 1 2 3 5t"
191 c["vlan2ports"]="4 5t"
193 if (model == "ASUS WL-500W") {
194 c["lan_ifname"] = "eth0"
195 c["wan_ifname"] = "eth1"
196 c["vlan1ports"] = "0 1 2 3 4 5"
199 if (model == "OvisLink WL-1600GL") {
200 c["lan_ifname"] = "eth0.1"
201 c["wan_ifname"] = "eth0.2"
202 c["vlan1ports"] = "0 1 2 3 5t"
203 c["vlan2ports"] = "4 5t"
205 if (model == "SimpleTech SimpleShare NAS") {
206 c["lan_ifname"] = "eth0"
211 print "local vlan1ports=\"" c["vlan1ports"] "\";"
212 print "local vlan2ports=\"" c["vlan2ports"] "\";"
213 print "local lan_ifname=\"" c["lan_ifname"] "\";"
214 print "local lan_macaddr=\"" c["lan_macaddr"] "\";"
215 print "local wan_ifname=\"" c["wan_ifname"] "\";"
216 print "local wan_macaddr=\"" c["wan_macaddr"] "\";"
219 . /lib/functions/uci-defaults.sh
221 touch /etc/config/network
225 [ -n "$vlan1ports" -o -n "$vlan2ports" ] && {
226 local cfg=`ucidef_add_switch "switch0" 1 1`
227 [ -n "$cfg" ] && uci rename network.$cfg=eth0
228 [ -n "$vlan1ports" ] && {
229 cfg=`ucidef_add_switch_vlan "switch0" 1 "$vlan1ports"`
230 [ -n "$cfg" ] && uci rename network.$cfg=eth0_1
232 [ -n "$vlan2ports" ] && {
233 cfg=`ucidef_add_switch_vlan "switch0" 2 "$vlan2ports"`
234 [ -n "$cfg" ] && uci rename network.$cfg=eth0_2
238 ucidef_set_interface_loopback
240 ucidef_set_interface_lan "$lan_ifname"
241 [ -n "$lan_macaddr" ] && ucidef_set_interface_macaddr lan "$lan_macaddr"
243 [ -n "$wan_ifname" ] && {
244 ucidef_set_interface_wan "$wan_ifname"
245 [ -n "$wan_macaddr" ] && ucidef_set_interface_macaddr wan "$wan_macaddr"