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