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