ramips: Add support for the GnuBee Personal Cloud Two
[openwrt/openwrt.git] / target / linux / ramips / base-files / etc / board.d / 02_network
1 #!/bin/sh
2
3 . /lib/functions.sh
4 . /lib/functions/uci-defaults.sh
5 . /lib/functions/system.sh
6
7 ramips_setup_rt3x5x_vlans()
8 {
9 if [ ! -x /sbin/swconfig ]; then
10 # legacy default
11 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
12 return
13 fi
14 local wanports=""
15 local lanports=""
16 for port in 5 4 3 2 1 0; do
17 if [ `swconfig dev rt305x port $port get disable` = "1" ]; then
18 continue
19 fi
20 if [ `swconfig dev rt305x port $port get lan` = "0" ]; then
21 wanports="$port:wan $wanports"
22 else
23 lanports="$port:lan $lanports"
24 fi
25 done
26 ucidef_add_switch "rt305x" $lanports $wanports "6t@eth0"
27 }
28
29 ramips_setup_interfaces()
30 {
31 local board="$1"
32
33 case $board in
34 11acnas|\
35 w2914nsv2|\
36 zbt-we2026)
37 ucidef_add_switch "switch0" \
38 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4:wan:5" "6@eth0"
39 ;;
40 3g150b|\
41 3g300m|\
42 a5-v11|\
43 all0256n-4M|\
44 all0256n-8M|\
45 all5002|\
46 all5003|\
47 broadway|\
48 dcs-930|\
49 dcs-930l-b1|\
50 ht-tm02|\
51 linkits7688 | \
52 m2m|\
53 microwrt|\
54 mpr-a2|\
55 ncs601w|\
56 omega2 | \
57 omega2p | \
58 timecloud|\
59 w150m|\
60 widora,neo-16m|\
61 widora,neo-32m|\
62 wnce2001|\
63 zbt-cpe102|\
64 zte-q7)
65 ucidef_add_switch "switch0"
66 ucidef_add_switch_attr "switch0" "enable" "false"
67 ucidef_set_interface_lan "eth0"
68 ;;
69 mlw221|\
70 mr-102n)
71 ucidef_set_interface_lan "eth0.2"
72 ;;
73 3g-6200n|\
74 ai-br100|\
75 alfa-network,ac1200rm|\
76 d240|\
77 db-wrt01|\
78 dir-300-b7|\
79 dir-320-b1|\
80 dir-610-a1|\
81 dir-615-h1|\
82 ew1200|\
83 firewrt|\
84 hc5661a|\
85 hc5962|\
86 hlk-rm04|\
87 k2p|\
88 kn|\
89 kn_rc|\
90 mac1200rv2|\
91 miwifi-mini|\
92 miwifi-nano|\
93 mt7621|\
94 mt7628|\
95 mzk-750dhp|\
96 mzk-w300nh2|\
97 d-team,newifi-d2|\
98 nixcore-x1-8M|\
99 nixcore-x1-16M|\
100 oy-0001|\
101 pbr-m1|\
102 psg1208|\
103 psg1218a|\
104 r6220|\
105 rt-n12p|\
106 sap-g3200u3|\
107 sk-wb8|\
108 u7621-06-256M-16M|\
109 vr500|\
110 wf-2881|\
111 witi|\
112 wl-wn575a3|\
113 wndr3700v5|\
114 wt1520-4M|\
115 wt1520-8M|\
116 youku-yk1|\
117 zbt-ape522ii|\
118 zbt-we1326|\
119 zbtlink,zbt-we3526|\
120 zbt-we826-16M|\
121 zbt-we826-32M|\
122 zbt-wg2626|\
123 zbt-wg3526-16M|\
124 zbt-wg3526-32M|\
125 zbt-wr8305rt)
126 ucidef_add_switch "switch0" \
127 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
128 ;;
129 mir3g)
130 ucidef_add_switch "switch0" \
131 "2:lan:2" "3:lan:1" "1:wan" "6t@eth0"
132 ;;
133 psg1218b)
134 ucidef_add_switch "switch0" \
135 "0:lan:3" "1:lan:2" "2:lan:1" "3:wan" "6@eth0"
136 ;;
137 whr-300hp2|\
138 whr-600d|\
139 wsr-1166|\
140 wsr-600)
141 ucidef_add_switch "switch0" \
142 "0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "4:wan:5" "6@eth0"
143 ;;
144 ar670w|\
145 ar725w|\
146 rt-ac51u)
147 ucidef_add_switch "switch0" \
148 "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "6t@eth0"
149 ;;
150 rt-n15|\
151 wl-351)
152 ucidef_add_switch "switch0" \
153 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0"
154 ;;
155 asl26555-8M|\
156 asl26555-16M|\
157 rp-n53)
158 ucidef_add_switch "switch0" \
159 "1:lan" "2:lan" "3:lan" "4:lan" "6t@eth0"
160 ;;
161 atp-52b|\
162 awm002-evb-4M|\
163 awm002-evb-8M|\
164 c20i|\
165 dir-645|\
166 f5d8235-v2|\
167 gl-mt300a|\
168 gl-mt300n|\
169 gl-mt750|\
170 hg255d|\
171 jhr-n805r|\
172 jhr-n825r|\
173 jhr-n926r|\
174 mzk-wdpr|\
175 rb750gr3|\
176 rt-n14u|\
177 tplink,c20-v4|\
178 tplink,c50-v3|\
179 tplink,tl-mr3420-v5|\
180 tl-wr840n-v4|\
181 tl-wr840n-v5|\
182 tl-wr841n-v13|\
183 u7628-01-128M-16M|\
184 ubnt-erx|\
185 ubnt-erx-sfp|\
186 ur-326n4g|\
187 wrtnode|\
188 wrtnode2p | \
189 wrtnode2r | \
190 wt3020-4M|\
191 wt3020-8M|\
192 zbt-wa05)
193 ucidef_add_switch "switch0" \
194 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "6@eth0"
195 ;;
196 c50|\
197 tplink,c20-v1)
198 ucidef_add_switch "switch0" \
199 "1:lan:3" "2:lan:4" "3:lan:1" "4:lan:2" "0:wan" "6@eth0"
200 ;;
201 dir-860l-b1)
202 ucidef_add_switch "switch0" \
203 "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "0:wan" "6@eth0"
204 ;;
205 gb-pc1)
206 ucidef_add_switch "switch0" \
207 "0:lan" "4:lan" "6@eth0"
208 ;;
209 gb-pc2)
210 ucidef_add_switch "switch0" \
211 "4:lan" "0:wan" "6@eth0"
212 ;;
213 gl-mt300n-v2)
214 ucidef_add_switch "switch0" \
215 "1:lan" "0:wan" "6@eth0"
216 ;;
217 awapn2403)
218 ucidef_add_switch "switch0" \
219 "0:lan" "1:wan" "6@eth0"
220 ;;
221 b2c|\
222 nw718|\
223 psr-680w|\
224 sl-r7205|\
225 ur-336un|\
226 w502u|\
227 wr6202)
228 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
229 ;;
230 br-6475nd)
231 ucidef_add_switch "switch0" \
232 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "9@eth0"
233 ;;
234 c108|\
235 cf-wr800n)
236 ucidef_add_switch "switch0" \
237 "4:lan" "6t@eth0"
238 ;;
239 cy-swr1100)
240 ucidef_add_switch "switch0" \
241 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "9@eth0"
242 ;;
243 cs-qr10|\
244 d105|\
245 dch-m225|\
246 ex2700|\
247 ex3700|\
248 hpm|\
249 mzk-ex300np|\
250 mzk-ex750np|\
251 na930|\
252 pbr-d1|\
253 u25awf-h1|\
254 wli-tx4-ag300n|\
255 wmdr-143n|\
256 wmr-300|\
257 wn3000rpv3|\
258 wrh-300cr)
259 ucidef_set_interface_lan "eth0"
260 ;;
261 duzun-dm06)
262 ucidef_add_switch "switch0" \
263 "1:lan" "0:wan" "6@eth0"
264 ;;
265 e1700|\
266 mt7620a_mt7530)
267 ucidef_add_switch "switch1" \
268 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
269 ;;
270 hc5*61|\
271 y1s)
272 ucidef_add_switch "switch0" \
273 "1:lan" "2:lan" "3:lan" "4:lan" "5:lan" "0:wan" "6@eth0"
274 ;;
275 kn_rf)
276 ucidef_add_switch "switch0" \
277 "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "6@eth0"
278 ;;
279 kng_rc)
280 ucidef_add_switch "switch1" \
281 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "7t@eth0"
282 ;;
283 mlwg2|\
284 wizard8800|\
285 wl-330n)
286 ucidef_set_interface_lan "eth0.1"
287 ;;
288 mr200)
289 ucidef_add_switch "switch0" \
290 "0:lan" "1:lan" "2:lan" "3:lan" "6t@eth0"
291 ucidef_set_interface_wan "usb0"
292 ;;
293 mzk-dp150n|\
294 vocore-8M|\
295 vocore-16M)
296 ucidef_add_switch "switch0" \
297 "0:lan" "4:lan" "6t@eth0"
298 ;;
299 newifi-d1)
300 ucidef_add_switch "switch0" \
301 "1:lan:2" "2:lan:1" "4:wan" "6@eth0"
302 ;;
303 re350-v1)
304 ucidef_add_switch "switch0" \
305 "0:lan" "6@eth0"
306 ;;
307 re6500)
308 ucidef_add_switch "switch0" \
309 "0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "6@eth0"
310 ;;
311 rt-n56u)
312 ucidef_add_switch "switch0" \
313 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "8@eth0"
314 ;;
315 tew-638apb-v2)
316 ucidef_add_switch "switch0" \
317 "4:lan" "6@eth0"
318 ;;
319 tew-691gr|\
320 tew-692gr|\
321 wlr-6000)
322 ucidef_add_switch "switch0" \
323 "1:lan" "2:lan" "3:lan" "4:lan" "5:wan" "0@eth0"
324 ;;
325 vonets,var11n-300)
326 ucidef_add_switch "switch0" \
327 "0:lan" "4:wan" "6@eth0"
328 ;;
329 vocore2|\
330 vocore2lite)
331 ucidef_add_switch "switch0" \
332 "0:lan" "2:lan" "6t@eth0"
333 ;;
334 f5d8235-v1|\
335 tew-714tru|\
336 v11st-fe|\
337 wzr-agl300nh)
338 ucidef_add_switch "switch0" \
339 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
340 ;;
341 wcr-1166ds)
342 ucidef_add_switch "switch0" \
343 "3:lan" "4:wan" "6@eth0"
344 ;;
345 wcr-150gn|\
346 we1026-5g-16m)
347 ucidef_add_switch "switch0" \
348 "0:lan" "6t@eth0"
349 ;;
350 whr-1166d)
351 ucidef_add_switch "switch0" \
352 "0:lan" "1:lan" "2:lan" "3:lan" "5:wan" "6@eth0"
353 ;;
354 wizfi630a)
355 ucidef_add_switch "switch0" \
356 "1:lan" "2:lan" "0:wan" "6@eth0"
357 ;;
358 zbtlink,zbt-we1226|\
359 y1)
360 ucidef_add_switch "switch0" \
361 "0:lan:2" "1:lan:1" "4:wan" "6@eth0"
362 ;;
363 *)
364 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
365 if [ -n "${RT3X5X}" ]; then
366 ramips_setup_rt3x5x_vlans
367 else
368 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
369 fi
370 ;;
371 esac
372 }
373
374 ramips_setup_macs()
375 {
376 local board="$1"
377 local lan_mac=""
378 local wan_mac=""
379
380 case $board in
381 a5-v11|\
382 ht-tm02|\
383 wmdr-143n)
384 lan_mac=$(cat /sys/class/net/eth0/address)
385 ;;
386 all0239-3g|\
387 carambola|\
388 freestation5|\
389 w502u|\
390 wnce2001)
391 wan_mac=$(mtd_get_mac_binary factory 46)
392 ;;
393 bc2|\
394 broadway|\
395 d105|\
396 dir-300-b7|\
397 dir-320-b1|\
398 dir-620-a1|\
399 esr-9753|\
400 freestation5|\
401 hlk-rm04|\
402 mpr-a1|\
403 psr-680w|\
404 sl-r7205|\
405 y1|\
406 y1s)
407 lan_mac=$(cat /sys/class/net/eth0/address)
408 lan_mac=$(macaddr_setbit_la "$lan_mac")
409 wan_mac=$(macaddr_add "$lan_mac" 1)
410 ;;
411 br-6475nd)
412 lan_mac=$(cat /sys/class/net/eth0/address)
413 wan_mac=$(mtd_get_mac_binary devdata 7)
414 ;;
415 cy-swr1100|\
416 dch-m225)
417 lan_mac=$(mtd_get_mac_ascii factory lanmac)
418 ;;
419 dir-645)
420 lan_mac=$(mtd_get_mac_ascii nvram lanmac)
421 wan_mac=$(mtd_get_mac_ascii nvram wanmac)
422 ;;
423 dir-860l-b1)
424 lan_mac=$(mtd_get_mac_ascii factory lanmac)
425 wan_mac=$(mtd_get_mac_ascii factory wanmac)
426 ;;
427 e1700)
428 wan_mac=$(mtd_get_mac_ascii config WAN_MAC_ADDR)
429 ;;
430 gl-mt300n-v2)
431 wan_mac=$(mtd_get_mac_binary factory 4)
432 ;;
433 hc5*61|\
434 hc5661a|\
435 hc5962)
436 lan_mac=`mtd_get_mac_ascii bdinfo "Vfac_mac "`
437 [ -n "$lan_mac" ] || lan_mac=$(cat /sys/class/net/eth0/address)
438 wan_mac=$(macaddr_add "$lan_mac" 1)
439 ;;
440 kn_rc|\
441 kn_rf|\
442 kng_rc)
443 wan_mac=$(mtd_get_mac_binary factory 40)
444 ;;
445 linkits7688)
446 wan_mac=$(mtd_get_mac_binary factory 4)
447 lan_mac=$(mtd_get_mac_binary factory 46)
448 ;;
449 mac1200rv2)
450 lan_mac=$(mtd_get_mac_binary factory_info 13)
451 wan_mac=$(macaddr_add "$lan_mac" 1)
452 ;;
453 mir3g)
454 lan_mac=$(mtd_get_mac_binary Factory 0xe006)
455 ;;
456 miwifi-mini)
457 wan_mac=$(cat /sys/class/net/eth0/address)
458 lan_mac=$(macaddr_setbit_la "$wan_mac")
459 ;;
460 m3|\
461 m4-4M|\
462 m4-8M|\
463 x5|\
464 x8)
465 lan_mac=$(cat /sys/class/net/eth0/address)
466 lan_mac=$(macaddr_add "$lan_mac" -2)
467 ;;
468 newifi-d1)
469 lan_mac=$(cat /sys/class/net/eth0/address)
470 lan_mac=$(macaddr_add "$lan_mac" 2)
471 ;;
472 omega2|\
473 omega2p)
474 wan_mac=$(mtd_get_mac_binary factory 4)
475 lan_mac=$(mtd_get_mac_binary factory 46)
476 ;;
477 oy-0001)
478 lan_mac=$(mtd_get_mac_binary factory 40)
479 wan_mac=$(mtd_get_mac_binary factory 46)
480 ;;
481 r6220)
482 wan_mac=$(mtd_get_mac_binary factory 4)
483 lan_mac=$(macaddr_add "$wan_mac" 1)
484 ;;
485 rt-n56u)
486 lan_mac=$(cat /sys/class/net/eth0/address)
487 lan_mac=$(macaddr_setbit_la "$lan_mac")
488 wan_mac=$(mtd_get_mac_binary factory 32772)
489 ;;
490 sk-wb8)
491 wan_mac=$(mtd_get_mac_binary factory 57350)
492 ;;
493 tew-691gr)
494 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 4)" 3)
495 ;;
496 tew-692gr)
497 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 4)" 1)
498 ;;
499 tiny-ac)
500 lan_mac=$(mtd_get_mac_ascii u-boot-env LAN_MAC_ADDR)
501 wan_mac=$(mtd_get_mac_ascii u-boot-env WAN_MAC_ADDR)
502 ;;
503 vr500)
504 lan_mac=$(mtd_get_mac_binary factory 57344)
505 wan_mac=$(mtd_get_mac_binary factory 57350)
506 ;;
507 w306r-v20)
508 lan_mac=$(cat /sys/class/net/eth0/address)
509 wan_mac=$(macaddr_add "$lan_mac" 5)
510 ;;
511 wcr-1166ds|\
512 wsr-1166)
513 local index="$(find_mtd_index "board_data")"
514 wan_mac="$(grep -m1 mac= "/dev/mtd${index}" | cut -d= -f2)"
515 lan_mac=$wan_mac
516 ;;
517 wcr-150gn)
518 wan_mac=$(mtd_get_mac_binary factory 40)
519 ;;
520 whr-1166d|\
521 whr-300hp2|\
522 whr-600d|\
523 wsr-600)
524 wan_mac=$(mtd_get_mac_binary factory 4)
525 lan_mac=$wan_mac
526 ;;
527 wizfi630a)
528 lan_mac=$(mtd_get_mac_binary factory 4)
529 wan_mac=$(mtd_get_mac_binary factory 40)
530 ;;
531 wlr-6000)
532 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 32772)" 2)
533 ;;
534 *)
535 lan_mac=$(cat /sys/class/net/eth0/address)
536 wan_mac=$(macaddr_add "$lan_mac" 1)
537 ;;
538 esac
539
540 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
541 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
542 }
543
544 board_config_update
545 board=$(board_name)
546 ramips_setup_interfaces $board
547 ramips_setup_macs $board
548 board_config_flush
549
550 exit 0