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