ramips: ethernet mac cleanup
[openwrt/staging/wigyori.git] / target / linux / ramips / base-files / etc / uci-defaults / 02_network
1 #!/bin/sh
2
3 . /lib/functions.sh
4 . /lib/ramips.sh
5 . /lib/functions/uci-defaults.sh
6 . /lib/functions/system.sh
7
8 ramips_setup_rt3x5x_vlans()
9 {
10 if [ ! -x /sbin/swconfig ]; then
11 # legacy default
12 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
13 return
14 fi
15 local wanports=""
16 local lanports=""
17 for port in 5 4 3 2 1 0; do
18 if [ `swconfig dev rt305x port $port get disable` = "1" ]; then
19 continue
20 fi
21 if [ `swconfig dev rt305x port $port get lan` = "0" ]; then
22 wanports="$port $wanports"
23 else
24 lanports="$port $lanports"
25 fi
26 done
27 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
28 ucidef_add_switch "rt305x" "1" "1"
29 ucidef_add_switch_vlan "rt305x" "1" "$lanports 6t"
30 ucidef_add_switch_vlan "rt305x" "2" "$wanports 6t"
31 }
32
33 ramips_setup_interfaces()
34 {
35 local board="$1"
36
37 ucidef_set_interface_loopback
38
39 case $board in
40 3g300m | \
41 w150m | \
42 all0256n | \
43 all5002 | \
44 all5003 | \
45 broadway | \
46 dcs-930| \
47 ncs601w | \
48 wnce2001)
49 ucidef_add_switch "switch0" "1" "0"
50 ucidef_set_interface_lan "eth0"
51 ;;
52
53 3g-6200nl | \
54 wl-330n | \
55 wmr300)
56 ucidef_set_interface_lan "eth0.1"
57 ;;
58
59 3g-6200n | \
60 b2c | \
61 nw718 | \
62 psr-680w | \
63 sl-r7205 | \
64 w502u | \
65 wr6202)
66 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
67 ;;
68
69 awapn2403)
70 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
71 ucidef_add_switch "switch0" "1" "1"
72 ucidef_add_switch_vlan "switch0" "1" "0 6t"
73 ucidef_add_switch_vlan "switch0" "2" "1 6t"
74 ;;
75
76 br-6475nd)
77 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
78 ucidef_add_switch "switch0" "1" "1"
79 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 9t"
80 ucidef_add_switch_vlan "switch0" "2" "0 9t"
81 ;;
82
83 asl26555)
84 ucidef_set_interface_lan "eth0.1"
85 ucidef_add_switch "switch0" "1" "1"
86 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
87 ;;
88
89 cy-swr1100)
90 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
91 ucidef_add_switch "switch0" "1" "1"
92 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 9t"
93 ucidef_add_switch_vlan "switch0" "2" "4 9t"
94 ;;
95
96 dir-610-a1 | \
97 dir-300-b7 | \
98 dir-320-b1 | \
99 dir-615-h1 | \
100 hlk-rm04 | \
101 mzk-w300nh2 | \
102 mzk-750dhp)
103 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
104 ucidef_add_switch "switch0" "1" "1"
105 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t"
106 ucidef_add_switch_vlan "switch0" "2" "4 6t"
107 ;;
108
109 awm002-evb | \
110 awm003-evb | \
111 argus-atp52b | \
112 dir-645 | \
113 f5d8235-v1 | \
114 f5d8235-v2 | \
115 hg255d | \
116 rt-n14u | \
117 wrtnode | \
118 ur-326n4g | \
119 zbt-wa05)
120 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
121 ucidef_add_switch "switch0" "1" "1"
122 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
123 ucidef_add_switch_vlan "switch0" "2" "0 6t"
124 ;;
125
126 ur-336un)
127 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
128 ;;
129
130 br6524n | \
131 v11st-fe)
132 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
133 ucidef_add_switch "switch0" "1" "1"
134 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
135 ucidef_add_switch_vlan "switch0" "2" "0 5t"
136 ;;
137
138 ar725w | \
139 rt-n15 | \
140 wl-351)
141 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
142 ucidef_add_switch "switch0" "1" "1"
143 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
144 ucidef_add_switch_vlan "switch0" "2" "4 5t"
145 ;;
146
147 rt-n56u)
148 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
149 ucidef_add_switch "switch0" "1" "1"
150 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 8t"
151 ucidef_add_switch_vlan "switch0" "2" "4 8t"
152 ;;
153
154 tew-691gr|\
155 tew-692gr)
156 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
157 ucidef_add_switch "switch0" "1" "1"
158 ucidef_add_switch_vlan "switch0" "1" "0t 1 2 3 4"
159 ucidef_add_switch_vlan "switch0" "2" "0t 5"
160 ;;
161
162 wcr-150gn)
163 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
164 ucidef_add_switch "switch0" "1" "1"
165 ucidef_add_switch_vlan "switch0" "1" "0 6t"
166 ucidef_add_switch_vlan "switch0" "2" "6t"
167 ;;
168
169 wr8305rt)
170 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
171 ucidef_add_switch "switch0" "1" "1"
172 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 4 6t"
173 ucidef_add_switch_vlan "switch0" "2" "4 6t"
174 ;;
175
176 d105 | \
177 na930 | \
178 omni-emb-hpm|\
179 wli-tx4-ag300n)
180 ucidef_set_interface_lan "eth0"
181 ;;
182
183 *)
184 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
185 if [ -n "${RT3X5X}" ]; then
186 ramips_setup_rt3x5x_vlans
187 else
188 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
189 fi
190 ;;
191 esac
192 }
193
194 ramips_setup_macs()
195 {
196 local board="$1"
197 local lan_mac=""
198 local wan_mac=""
199
200 case $board in
201 br-6475nd)
202 lan_mac=$(cat /sys/class/net/eth0/address)
203 wan_mac=$(mtd_get_mac_binary devdata 7)
204 ;;
205
206 w306r-v20)
207 lan_mac=$(cat /sys/class/net/eth0/address)
208 wan_mac=$(macaddr_add "$lan_mac" 5)
209 ;;
210
211 tew-691gr)
212 lan_mac=$(cat /sys/class/net/eth0/address)
213 wan_mac=$(macaddr_add "$lan_mac" 3)
214 ;;
215
216 tew-692gr)
217 lan_mac=$(cat /sys/class/net/eth0/address)
218 wan_mac=$(macaddr_add "$lan_mac" 4)
219 ;;
220
221 m3 |\
222 m4 |\
223 x5 |\
224 x8)
225 lan_mac=$(cat /sys/class/net/eth0/address)
226 lan_mac=$(macaddr_add "$lan_mac" -2)
227 ;;
228
229 bc2 |\
230 broadway |\
231 d105 |\
232 dir-620-a1 |\
233 esr-9753 |\
234 freestation5 |\
235 hlk-rm04 | \
236 mpr-a1 | \
237 mpr-a2 | \
238 dir-300-b7 | \
239 dir-320-b1 | \
240 psr-680w |\
241 sl-r7205)
242 lan_mac=$(cat /sys/class/net/eth0/address)
243 lan_mac=$(macaddr_setbit_la "$lan_mac")
244 wan_mac=$(macaddr_add "$lan_mac" 1)
245 ;;
246
247 cy-swr1100 | \
248 dir-645)
249 lan_mac=$(mtd_get_mac_ascii nvram lanmac)
250 wan_mac=$(mtd_get_mac_ascii nvram wanmac)
251 ;;
252
253 wcr-150gn)
254 wan_mac=$(mtd_get_mac_binary factory 40)
255 ;;
256
257 rt-n56u)
258 lan_mac=$(cat /sys/class/net/eth0/address)
259 lan_mac=$(macaddr_setbit_la "$lan_mac")
260 wan_mac=$(mtd_get_mac_binary factory 32772)
261 ;;
262
263 all0239-3g | \
264 carambola | \
265 freestation5 | \
266 w502u | \
267 wnce2001)
268 wan_mac=$(mtd_get_mac_binary factory 46)
269 ;;
270
271 *)
272 lan_mac=$(cat /sys/class/net/eth0/address)
273 wan_mac=$(macaddr_add "$lan_mac" 1)
274 ;;
275
276 esac
277
278 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
279 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
280 }
281
282 [ -e /etc/config/network ] && exit 0
283
284 touch /etc/config/network
285
286 board=$(ramips_board_name)
287
288 ramips_setup_interfaces $board
289 ramips_setup_macs $board
290
291 uci commit network
292
293 exit 0