02cd6824d094e35b86120fd17f3bf0335e38a1c2
[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         y1s)
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 3 4 5 6t"
225                 ucidef_add_switch_vlan "switch0" "2" "0 6t"
226                 ;;
227         zbt-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                 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
235                 if [ -n "${RT3X5X}" ]; then
236                         ramips_setup_rt3x5x_vlans
237                 else
238                         ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
239                 fi
240                 ;;
241         esac
242 }
243
244 ramips_setup_macs()
245 {
246         local board="$1"
247         local lan_mac=""
248         local wan_mac=""
249
250         case $board in
251         a5-v11|\
252         bc2|\
253         broadway|\
254         d105|\
255         dir-300-b7|\
256         dir-320-b1|\
257         dir-620-a1|\
258         esr-9753|\
259         freestation5|\
260         hlk-rm04|\
261         mpr-a1|\
262         mpr-a2|\
263         psr-680w|\
264         sl-r7205|\
265         y1|\
266         y1s)
267                 lan_mac=$(cat /sys/class/net/eth0/address)
268                 lan_mac=$(macaddr_setbit_la "$lan_mac")
269                 wan_mac=$(macaddr_add "$lan_mac" 1)
270                 ;;
271         all0239-3g|\
272         carambola|\
273         freestation5|\
274         w502u|\
275         wnce2001)
276                 wan_mac=$(mtd_get_mac_binary factory 46)
277                 ;;
278         br-6475nd)
279                 lan_mac=$(cat /sys/class/net/eth0/address)
280                 wan_mac=$(mtd_get_mac_binary devdata 7)
281                 ;;
282         cy-swr1100|\
283         dir-645)
284                 lan_mac=$(mtd_get_mac_ascii nvram lanmac)
285                 wan_mac=$(mtd_get_mac_ascii nvram wanmac)
286                 ;;
287         e1700)
288                 wan_mac=$(mtd_get_mac_ascii config WAN_MAC_ADDR)
289                 ;;
290         ht-tm02)
291                 lan_mac=$(cat /sys/class/net/eth0/address)
292                 ;;
293         m3|\
294         m4|\
295         x5|\
296         x8)
297                 lan_mac=$(cat /sys/class/net/eth0/address)
298                 lan_mac=$(macaddr_add "$lan_mac" -2)
299                 ;;
300         oy-0001)
301                 lan_mac=$(mtd_get_mac_binary factory 40)
302                 wan_mac=$(mtd_get_mac_binary factory 46)
303                 ;;
304         rt-n56u)
305                 lan_mac=$(cat /sys/class/net/eth0/address)
306                 lan_mac=$(macaddr_setbit_la "$lan_mac")
307                 wan_mac=$(mtd_get_mac_binary factory 32772)
308                 ;;
309         tew-691gr)
310                 lan_mac=$(cat /sys/class/net/eth0/address)
311                 wan_mac=$(macaddr_add "$lan_mac" 3)
312                 ;;
313         tew-692gr)
314                 lan_mac=$(cat /sys/class/net/eth0/address)
315                 wan_mac=$(macaddr_add "$lan_mac" 4)
316                 ;;
317         w306r-v20)
318                 lan_mac=$(cat /sys/class/net/eth0/address)
319                 wan_mac=$(macaddr_add "$lan_mac" 5)
320                 ;;
321         wcr-150gn)
322                 wan_mac=$(mtd_get_mac_binary factory 40)
323                 ;;
324         whr-1166d|\
325         whr-300hp2|\
326         whr-600d|\
327         wsr-600)
328                 wan_mac=$(mtd_get_mac_binary factory 4)
329                 lan_mac=$wan_mac
330                 ;;
331         wsr-1166)
332                 local index="$(find_mtd_index "board_data")"
333                 wan_mac="$(grep -m1 mac= "/dev/mtd${index}" | cut -d= -f2)"
334                 lan_mac=$wan_mac
335                 ;;
336         *)
337                 lan_mac=$(cat /sys/class/net/eth0/address)
338                 wan_mac=$(macaddr_add "$lan_mac" 1)
339                 ;;
340         esac
341
342         [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
343         [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
344 }
345
346 board_config_update
347 board=$(ramips_board_name)
348 ramips_setup_interfaces $board
349 ramips_setup_macs $board
350 board_config_flush
351
352 exit 0