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