ramips: add support for PandoraBox PBR-M1
[openwrt/staging/yousong.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 a5-v11)
41 ucidef_set_interface_lan "eth0.1"
42 ucidef_add_switch "switch0" "1" "1"
43 ucidef_add_switch_vlan "switch0" "1" "0 6t"
44 ;;
45
46 3g150b | \
47 3g300m | \
48 microwrt | \
49 w150m | \
50 zte-q7 | \
51 all0256n | \
52 all5002 | \
53 all5003 | \
54 broadway | \
55 dcs-930| \
56 ht-tm02| \
57 ncs601w | \
58 wnce2001)
59 ucidef_add_switch "switch0" "1" "0"
60 ucidef_set_interface_lan "eth0"
61 ;;
62
63 3g-6200nl | \
64 mlw221 | \
65 mr-102n)
66 ucidef_set_interface_lan "eth0.2"
67 ;;
68 mlwg2)
69 ucidef_set_interface_lan "eth0.1"
70 ;;
71
72 m2m)
73 ucidef_add_switch "switch0" "4"
74 ucidef_set_interface_lan "eth0"
75 ;;
76
77 wizard8800 | \
78 wl-330n | \
79 wmr300)
80 ucidef_set_interface_lan "eth0.1"
81 ;;
82
83 b2c | \
84 nw718 | \
85 psr-680w | \
86 sl-r7205 | \
87 w502u | \
88 wr6202)
89 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
90 ;;
91
92 awapn2403)
93 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
94 ucidef_add_switch "switch0" "1" "1"
95 ucidef_add_switch_vlan "switch0" "1" "0 6t"
96 ucidef_add_switch_vlan "switch0" "2" "1 6t"
97 ;;
98
99 br-6475nd)
100 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
101 ucidef_add_switch "switch0" "1" "1"
102 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 9t"
103 ucidef_add_switch_vlan "switch0" "2" "0 9t"
104 ;;
105
106 asl26555)
107 ucidef_set_interface_lan "eth0.1"
108 ucidef_add_switch "switch0" "1" "1"
109 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
110 ;;
111
112 cf-wr800n)
113 ucidef_set_interface_lan "eth0.1"
114 ucidef_add_switch "switch0" "1" "1"
115 ucidef_add_switch_vlan "switch0" "1" "4 6t"
116 ;;
117
118 cy-swr1100)
119 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
120 ucidef_add_switch "switch0" "1" "1"
121 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 9t"
122 ucidef_add_switch_vlan "switch0" "2" "4 9t"
123 ;;
124
125 3g-6200n | \
126 ai-br100 | \
127 dir-610-a1 | \
128 dir-300-b7 | \
129 dir-320-b1 | \
130 dir-615-h1 | \
131 firewrt | \
132 pbr-m1 | \
133 hlk-rm04 | \
134 mt7621 | \
135 mt7628 | \
136 mzk-w300nh2 | \
137 mzk-750dhp | \
138 whr-300hp2 | \
139 whr-600d | \
140 wsr-600 | \
141 wsr-1166 | \
142 wt1520 | \
143 xiaomi-miwifi-mini |\
144 y1)
145 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
146 ucidef_add_switch "switch0" "1" "1"
147 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t"
148 ucidef_add_switch_vlan "switch0" "2" "4 6t"
149 ;;
150
151 whr-1166d)
152 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
153 ucidef_add_switch "switch0" "1" "1"
154 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t"
155 ucidef_add_switch_vlan "switch0" "2" "5 6t"
156 ;;
157
158 awm002-evb | \
159 awm003-evb | \
160 argus-atp52b | \
161 dir-645 | \
162 dir-860l-b1 | \
163 f5d8235-v1 | \
164 f5d8235-v2 | \
165 hg255d | \
166 rt-n14u | \
167 wrtnode | \
168 wt3020 | \
169 ur-326n4g | \
170 zbt-wa05)
171 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
172 ucidef_add_switch "switch0" "1" "1"
173 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
174 ucidef_add_switch_vlan "switch0" "2" "0 6t"
175 ;;
176
177 ur-336un)
178 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
179 ;;
180
181 br6524n | \
182 v11st-fe)
183 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
184 ucidef_add_switch "switch0" "1" "1"
185 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
186 ucidef_add_switch_vlan "switch0" "2" "0 5t"
187 ;;
188
189 ar670w | \
190 ar725w | \
191 rt-n15 | \
192 wl-351)
193 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
194 ucidef_add_switch "switch0" "1" "1"
195 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
196 ucidef_add_switch_vlan "switch0" "2" "4 5t"
197 ;;
198
199 rt-n56u)
200 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
201 ucidef_add_switch "switch0" "1" "1"
202 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 8t"
203 ucidef_add_switch_vlan "switch0" "2" "4 8t"
204 ;;
205
206 tew-691gr|\
207 tew-692gr)
208 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
209 ucidef_add_switch "switch0" "1" "1"
210 ucidef_add_switch_vlan "switch0" "1" "0t 1 2 3 4"
211 ucidef_add_switch_vlan "switch0" "2" "0t 5"
212 ;;
213
214 vocore)
215 ucidef_set_interface_lan "eth0.1"
216 ucidef_add_switch "switch0" "1" "1"
217 ucidef_add_switch_vlan "switch0" "1" "0 4 6t"
218 ;;
219
220 wcr-150gn)
221 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
222 ucidef_add_switch "switch0" "1" "1"
223 ucidef_add_switch_vlan "switch0" "1" "0 6t"
224 ucidef_add_switch_vlan "switch0" "2" "6t"
225 ;;
226
227 wr8305rt)
228 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
229 ucidef_add_switch "switch0" "1" "1"
230 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 4 6t"
231 ucidef_add_switch_vlan "switch0" "2" "4 6t"
232 ;;
233
234 y1s)
235 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
236 ucidef_add_switch "switch0" "1" "1"
237 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5 6t"
238 ucidef_add_switch_vlan "switch0" "2" "0 6t"
239 ;;
240 d105 | \
241 na930 | \
242 omni-emb-hpm|\
243 wli-tx4-ag300n)
244 ucidef_set_interface_lan "eth0"
245 ;;
246
247 e1700 | \
248 mt7620a_mt7530)
249 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
250 ucidef_add_switch "switch1" "1" "1"
251 ucidef_add_switch_vlan "switch1" "1" "0 1 2 3 6t"
252 ucidef_add_switch_vlan "switch1" "2" "4 6t"
253 ;;
254
255 wzr-agl300nh)
256 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
257 ucidef_add_switch "switch0" "1" "1"
258 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
259 ucidef_add_switch_vlan "switch0" "2" "0 5t"
260 ;;
261 *)
262 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
263 if [ -n "${RT3X5X}" ]; then
264 ramips_setup_rt3x5x_vlans
265 else
266 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
267 fi
268 ;;
269 esac
270 }
271
272 ramips_setup_macs()
273 {
274 local board="$1"
275 local lan_mac=""
276 local wan_mac=""
277
278 case $board in
279 br-6475nd)
280 lan_mac=$(cat /sys/class/net/eth0/address)
281 wan_mac=$(mtd_get_mac_binary devdata 7)
282 ;;
283
284 w306r-v20)
285 lan_mac=$(cat /sys/class/net/eth0/address)
286 wan_mac=$(macaddr_add "$lan_mac" 5)
287 ;;
288
289 tew-691gr)
290 lan_mac=$(cat /sys/class/net/eth0/address)
291 wan_mac=$(macaddr_add "$lan_mac" 3)
292 ;;
293
294 tew-692gr)
295 lan_mac=$(cat /sys/class/net/eth0/address)
296 wan_mac=$(macaddr_add "$lan_mac" 4)
297 ;;
298
299 m3 |\
300 m4 |\
301 x5 |\
302 x8)
303 lan_mac=$(cat /sys/class/net/eth0/address)
304 lan_mac=$(macaddr_add "$lan_mac" -2)
305 ;;
306
307 a5-v11 |\
308 bc2 |\
309 broadway |\
310 d105 |\
311 dir-620-a1 |\
312 esr-9753 |\
313 freestation5 |\
314 hlk-rm04 | \
315 mpr-a1 | \
316 mpr-a2 | \
317 dir-300-b7 | \
318 dir-320-b1 | \
319 psr-680w |\
320 sl-r7205 |\
321 y1 |\
322 y1s)
323 lan_mac=$(cat /sys/class/net/eth0/address)
324 lan_mac=$(macaddr_setbit_la "$lan_mac")
325 wan_mac=$(macaddr_add "$lan_mac" 1)
326 ;;
327
328 ht-tm02)
329 lan_mac=$(cat /sys/class/net/eth0/address)
330 ;;
331
332 cy-swr1100 | \
333 dir-645)
334 lan_mac=$(mtd_get_mac_ascii nvram lanmac)
335 wan_mac=$(mtd_get_mac_ascii nvram wanmac)
336 ;;
337
338 e1700)
339 wan_mac=$(mtd_get_mac_ascii config WAN_MAC_ADDR)
340 ;;
341
342 wcr-150gn)
343 wan_mac=$(mtd_get_mac_binary factory 40)
344 ;;
345
346 rt-n56u)
347 lan_mac=$(cat /sys/class/net/eth0/address)
348 lan_mac=$(macaddr_setbit_la "$lan_mac")
349 wan_mac=$(mtd_get_mac_binary factory 32772)
350 ;;
351
352 all0239-3g | \
353 carambola | \
354 freestation5 | \
355 w502u | \
356 wnce2001)
357 wan_mac=$(mtd_get_mac_binary factory 46)
358 ;;
359
360 wsr-600|whr-300hp2|whr-600d|whr-1166d)
361 wan_mac=$(mtd_get_mac_binary factory 4)
362 lan_mac=$wan_mac
363 ;;
364 wsr-1166)
365 local index="$(find_mtd_index "board_data")"
366 wan_mac="$(grep -m1 mac= "/dev/mtd${index}" | cut -d= -f2)"
367 lan_mac=$wan_mac
368 ;;
369 *)
370 lan_mac=$(cat /sys/class/net/eth0/address)
371 wan_mac=$(macaddr_add "$lan_mac" 1)
372 ;;
373
374 esac
375
376 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
377 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
378 }
379
380 board_config_update
381 board=$(ramips_board_name)
382 ramips_setup_interfaces $board
383 ramips_setup_macs $board
384 board_config_flush
385
386 exit 0