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