ramips: add support for Airlink101 AR670W
[openwrt/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 whr-1166d | \
123 wt1520)
124 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
125 ucidef_add_switch "switch0" "1" "1"
126 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t"
127 ucidef_add_switch_vlan "switch0" "2" "4 6t"
128 ;;
129
130 awm002-evb | \
131 awm003-evb | \
132 argus-atp52b | \
133 dir-645 | \
134 f5d8235-v1 | \
135 f5d8235-v2 | \
136 hg255d | \
137 rt-n14u | \
138 wrtnode | \
139 wt3020 | \
140 ur-326n4g | \
141 zbt-wa05)
142 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
143 ucidef_add_switch "switch0" "1" "1"
144 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
145 ucidef_add_switch_vlan "switch0" "2" "0 6t"
146 ;;
147
148 ur-336un)
149 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
150 ;;
151
152 br6524n | \
153 v11st-fe)
154 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
155 ucidef_add_switch "switch0" "1" "1"
156 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
157 ucidef_add_switch_vlan "switch0" "2" "0 5t"
158 ;;
159
160 ar670w | \
161 ar725w | \
162 rt-n15 | \
163 wl-351)
164 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
165 ucidef_add_switch "switch0" "1" "1"
166 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
167 ucidef_add_switch_vlan "switch0" "2" "4 5t"
168 ;;
169
170 rt-n56u)
171 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
172 ucidef_add_switch "switch0" "1" "1"
173 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 8t"
174 ucidef_add_switch_vlan "switch0" "2" "4 8t"
175 ;;
176
177 tew-691gr|\
178 tew-692gr)
179 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
180 ucidef_add_switch "switch0" "1" "1"
181 ucidef_add_switch_vlan "switch0" "1" "0t 1 2 3 4"
182 ucidef_add_switch_vlan "switch0" "2" "0t 5"
183 ;;
184
185 vocore)
186 ucidef_set_interface_lan "eth0.1"
187 ucidef_add_switch "switch0" "1" "1"
188 ucidef_add_switch_vlan "switch0" "1" "0 4 6t"
189 ;;
190
191 wcr-150gn)
192 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
193 ucidef_add_switch "switch0" "1" "1"
194 ucidef_add_switch_vlan "switch0" "1" "0 6t"
195 ucidef_add_switch_vlan "switch0" "2" "6t"
196 ;;
197
198 wr8305rt)
199 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
200 ucidef_add_switch "switch0" "1" "1"
201 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 4 6t"
202 ucidef_add_switch_vlan "switch0" "2" "4 6t"
203 ;;
204
205 y1 |\
206 y1s)
207 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
208 ucidef_add_switch "switch0" "1" "1"
209 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5 6t"
210 ucidef_add_switch_vlan "switch0" "2" "0 6t"
211 ;;
212 d105 | \
213 na930 | \
214 omni-emb-hpm|\
215 wli-tx4-ag300n)
216 ucidef_set_interface_lan "eth0"
217 ;;
218
219 mt7620a_mt7530)
220 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
221 ucidef_add_switch "switch1" "1" "1"
222 ucidef_add_switch_vlan "switch1" "1" "0 1 2 3 6t"
223 ucidef_add_switch_vlan "switch1" "2" "4 6t"
224 ;;
225
226 *)
227 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
228 if [ -n "${RT3X5X}" ]; then
229 ramips_setup_rt3x5x_vlans
230 else
231 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
232 fi
233 ;;
234 esac
235 }
236
237 ramips_setup_macs()
238 {
239 local board="$1"
240 local lan_mac=""
241 local wan_mac=""
242
243 case $board in
244 br-6475nd)
245 lan_mac=$(cat /sys/class/net/eth0/address)
246 wan_mac=$(mtd_get_mac_binary devdata 7)
247 ;;
248
249 w306r-v20)
250 lan_mac=$(cat /sys/class/net/eth0/address)
251 wan_mac=$(macaddr_add "$lan_mac" 5)
252 ;;
253
254 tew-691gr)
255 lan_mac=$(cat /sys/class/net/eth0/address)
256 wan_mac=$(macaddr_add "$lan_mac" 3)
257 ;;
258
259 tew-692gr)
260 lan_mac=$(cat /sys/class/net/eth0/address)
261 wan_mac=$(macaddr_add "$lan_mac" 4)
262 ;;
263
264 m3 |\
265 m4 |\
266 x5 |\
267 x8)
268 lan_mac=$(cat /sys/class/net/eth0/address)
269 lan_mac=$(macaddr_add "$lan_mac" -2)
270 ;;
271
272 a5-v11 |\
273 bc2 |\
274 broadway |\
275 d105 |\
276 dir-620-a1 |\
277 esr-9753 |\
278 freestation5 |\
279 hlk-rm04 | \
280 mpr-a1 | \
281 mpr-a2 | \
282 ht-tm02 | \
283 dir-300-b7 | \
284 dir-320-b1 | \
285 psr-680w |\
286 sl-r7205 |\
287 y1 |\
288 y1s)
289 lan_mac=$(cat /sys/class/net/eth0/address)
290 lan_mac=$(macaddr_setbit_la "$lan_mac")
291 wan_mac=$(macaddr_add "$lan_mac" 1)
292 ;;
293
294 cy-swr1100 | \
295 dir-645)
296 lan_mac=$(mtd_get_mac_ascii nvram lanmac)
297 wan_mac=$(mtd_get_mac_ascii nvram wanmac)
298 ;;
299
300 wcr-150gn)
301 wan_mac=$(mtd_get_mac_binary factory 40)
302 ;;
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
310 all0239-3g | \
311 carambola | \
312 freestation5 | \
313 w502u | \
314 wnce2001)
315 wan_mac=$(mtd_get_mac_binary factory 46)
316 ;;
317
318 *)
319 lan_mac=$(cat /sys/class/net/eth0/address)
320 wan_mac=$(macaddr_add "$lan_mac" 1)
321 ;;
322
323 esac
324
325 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
326 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
327 }
328
329 board_config_update
330 board=$(ramips_board_name)
331 ramips_setup_interfaces $board
332 ramips_setup_macs $board
333 board_config_flush
334
335 exit 0