ff8fbc079de6c7fb187dda8bdff4f582530896ee
[openwrt/openwrt.git] / target / linux / ramips / base-files / etc / board.d / 02_network
1 #!/bin/sh
2
3 . /lib/functions.sh
4 . /lib/ramips.sh
5 . /lib/functions/uci-defaults-new.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 mlw221)
55 ucidef_set_interface_lan "eth0.2"
56 ;;
57
58 wizard8800 | \
59 wl-330n | \
60 wmr300)
61 ucidef_set_interface_lan "eth0.1"
62 ;;
63
64 b2c | \
65 nw718 | \
66 psr-680w | \
67 sl-r7205 | \
68 w502u | \
69 wr6202)
70 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
71 ;;
72
73 awapn2403)
74 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
75 ucidef_add_switch "switch0" "1" "1"
76 ucidef_add_switch_vlan "switch0" "1" "0 6t"
77 ucidef_add_switch_vlan "switch0" "2" "1 6t"
78 ;;
79
80 br-6475nd)
81 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
82 ucidef_add_switch "switch0" "1" "1"
83 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 9t"
84 ucidef_add_switch_vlan "switch0" "2" "0 9t"
85 ;;
86
87 asl26555)
88 ucidef_set_interface_lan "eth0.1"
89 ucidef_add_switch "switch0" "1" "1"
90 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
91 ;;
92
93 cy-swr1100)
94 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
95 ucidef_add_switch "switch0" "1" "1"
96 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 9t"
97 ucidef_add_switch_vlan "switch0" "2" "4 9t"
98 ;;
99
100 ht-tm02)
101 ucidef_set_interface_lan "eth0.1"
102 ucidef_add_switch "switch0" "1" "1"
103 ucidef_add_switch_vlan "switch0" "1" "4 6t"
104 ;;
105
106 3g-6200n | \
107 dir-610-a1 | \
108 dir-300-b7 | \
109 dir-320-b1 | \
110 dir-615-h1 | \
111 hlk-rm04 | \
112 mzk-w300nh2 | \
113 mzk-750dhp | \
114 wt1520)
115 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
116 ucidef_add_switch "switch0" "1" "1"
117 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t"
118 ucidef_add_switch_vlan "switch0" "2" "4 6t"
119 ;;
120
121 awm002-evb | \
122 awm003-evb | \
123 argus-atp52b | \
124 dir-645 | \
125 f5d8235-v1 | \
126 f5d8235-v2 | \
127 hg255d | \
128 rt-n14u | \
129 wrtnode | \
130 wt3020 | \
131 ur-326n4g | \
132 zbt-wa05)
133 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
134 ucidef_add_switch "switch0" "1" "1"
135 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
136 ucidef_add_switch_vlan "switch0" "2" "0 6t"
137 ;;
138
139 ur-336un)
140 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
141 ;;
142
143 br6524n | \
144 v11st-fe)
145 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
146 ucidef_add_switch "switch0" "1" "1"
147 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
148 ucidef_add_switch_vlan "switch0" "2" "0 5t"
149 ;;
150
151 ar725w | \
152 rt-n15 | \
153 wl-351)
154 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
155 ucidef_add_switch "switch0" "1" "1"
156 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
157 ucidef_add_switch_vlan "switch0" "2" "4 5t"
158 ;;
159
160 rt-n56u)
161 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
162 ucidef_add_switch "switch0" "1" "1"
163 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 8t"
164 ucidef_add_switch_vlan "switch0" "2" "4 8t"
165 ;;
166
167 tew-691gr|\
168 tew-692gr)
169 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
170 ucidef_add_switch "switch0" "1" "1"
171 ucidef_add_switch_vlan "switch0" "1" "0t 1 2 3 4"
172 ucidef_add_switch_vlan "switch0" "2" "0t 5"
173 ;;
174
175 vocore)
176 ucidef_set_interface_lan "eth0.1"
177 ucidef_add_switch "switch0" "1" "1"
178 ucidef_add_switch_vlan "switch0" "1" "0 4 6t"
179 ;;
180
181 wcr-150gn)
182 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
183 ucidef_add_switch "switch0" "1" "1"
184 ucidef_add_switch_vlan "switch0" "1" "0 6t"
185 ucidef_add_switch_vlan "switch0" "2" "6t"
186 ;;
187
188 wr8305rt)
189 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
190 ucidef_add_switch "switch0" "1" "1"
191 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 4 6t"
192 ucidef_add_switch_vlan "switch0" "2" "4 6t"
193 ;;
194
195 y1 |\
196 y1s)
197 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
198 ucidef_add_switch "switch0" "1" "1"
199 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5 6t"
200 ucidef_add_switch_vlan "switch0" "2" "0 6t"
201 ;;
202 d105 | \
203 na930 | \
204 omni-emb-hpm|\
205 wli-tx4-ag300n)
206 ucidef_set_interface_lan "eth0"
207 ;;
208
209 *)
210 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
211 if [ -n "${RT3X5X}" ]; then
212 ramips_setup_rt3x5x_vlans
213 else
214 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
215 fi
216 ;;
217 esac
218 }
219
220 ramips_setup_macs()
221 {
222 local board="$1"
223 local lan_mac=""
224 local wan_mac=""
225
226 case $board in
227 br-6475nd)
228 lan_mac=$(cat /sys/class/net/eth0/address)
229 wan_mac=$(mtd_get_mac_binary devdata 7)
230 ;;
231
232 w306r-v20)
233 lan_mac=$(cat /sys/class/net/eth0/address)
234 wan_mac=$(macaddr_add "$lan_mac" 5)
235 ;;
236
237 tew-691gr)
238 lan_mac=$(cat /sys/class/net/eth0/address)
239 wan_mac=$(macaddr_add "$lan_mac" 3)
240 ;;
241
242 tew-692gr)
243 lan_mac=$(cat /sys/class/net/eth0/address)
244 wan_mac=$(macaddr_add "$lan_mac" 4)
245 ;;
246
247 m3 |\
248 m4 |\
249 x5 |\
250 x8)
251 lan_mac=$(cat /sys/class/net/eth0/address)
252 lan_mac=$(macaddr_add "$lan_mac" -2)
253 ;;
254
255 bc2 |\
256 broadway |\
257 d105 |\
258 dir-620-a1 |\
259 esr-9753 |\
260 freestation5 |\
261 hlk-rm04 | \
262 mpr-a1 | \
263 mpr-a2 | \
264 ht-tm02 | \
265 dir-300-b7 | \
266 dir-320-b1 | \
267 psr-680w |\
268 sl-r7205 |\
269 y1 |\
270 y1s)
271 lan_mac=$(cat /sys/class/net/eth0/address)
272 lan_mac=$(macaddr_setbit_la "$lan_mac")
273 wan_mac=$(macaddr_add "$lan_mac" 1)
274 ;;
275
276 cy-swr1100 | \
277 dir-645)
278 lan_mac=$(mtd_get_mac_ascii nvram lanmac)
279 wan_mac=$(mtd_get_mac_ascii nvram wanmac)
280 ;;
281
282 wcr-150gn)
283 wan_mac=$(mtd_get_mac_binary factory 40)
284 ;;
285
286 rt-n56u)
287 lan_mac=$(cat /sys/class/net/eth0/address)
288 lan_mac=$(macaddr_setbit_la "$lan_mac")
289 wan_mac=$(mtd_get_mac_binary factory 32772)
290 ;;
291
292 all0239-3g | \
293 carambola | \
294 freestation5 | \
295 w502u | \
296 wnce2001)
297 wan_mac=$(mtd_get_mac_binary factory 46)
298 ;;
299
300 *)
301 lan_mac=$(cat /sys/class/net/eth0/address)
302 wan_mac=$(macaddr_add "$lan_mac" 1)
303 ;;
304
305 esac
306
307 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
308 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
309 }
310
311 board_config_update
312 board=$(ramips_board_name)
313 ramips_setup_interfaces $board
314 ramips_setup_macs $board
315 board_config_flush
316
317 exit 0