ramips: Add support for VoCore
[librecmc/librecmc.git] / target / linux / ramips / base-files / etc / uci-defaults / 02_network
1 #!/bin/sh
2
3 . /lib/functions.sh
4 . /lib/ramips.sh
5 . /lib/functions/uci-defaults.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         3g-6200n | \
65         b2c | \
66         nw718 | \
67         psr-680w | \
68         sl-r7205 | \
69         w502u | \
70         wr6202)
71                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
72                 ;;
73
74         awapn2403)
75                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
76                 ucidef_add_switch "switch0" "1" "1"
77                 ucidef_add_switch_vlan "switch0" "1" "0 6t"
78                 ucidef_add_switch_vlan "switch0" "2" "1 6t"
79                 ;;
80
81         br-6475nd)
82                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
83                 ucidef_add_switch "switch0" "1" "1"
84                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 9t"
85                 ucidef_add_switch_vlan "switch0" "2" "0 9t"
86                 ;;
87
88         asl26555)
89                 ucidef_set_interface_lan "eth0.1"
90                 ucidef_add_switch "switch0" "1" "1"
91                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
92                 ;;
93
94         cy-swr1100)
95                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
96                 ucidef_add_switch "switch0" "1" "1"
97                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 9t"
98                 ucidef_add_switch_vlan "switch0" "2" "4 9t"
99                 ;;
100
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         d105 | \
188         na930 | \
189         omni-emb-hpm|\
190         wli-tx4-ag300n)
191                 ucidef_set_interface_lan "eth0"
192                 ;;
193
194         *)
195                 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
196                 if [ -n "${RT3X5X}" ]; then
197                         ramips_setup_rt3x5x_vlans
198                 else
199                         ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
200                 fi
201                 ;;
202         esac
203 }
204
205 ramips_setup_macs()
206 {
207         local board="$1"
208         local lan_mac=""
209         local wan_mac=""
210
211         case $board in
212         br-6475nd)
213                 lan_mac=$(cat /sys/class/net/eth0/address)
214                 wan_mac=$(mtd_get_mac_binary devdata 7)
215                 ;;
216
217         w306r-v20)
218                 lan_mac=$(cat /sys/class/net/eth0/address)
219                 wan_mac=$(macaddr_add "$lan_mac" 5)
220                 ;;
221
222         tew-691gr)
223                 lan_mac=$(cat /sys/class/net/eth0/address)
224                 wan_mac=$(macaddr_add "$lan_mac" 3)
225                 ;;
226
227         tew-692gr)
228                 lan_mac=$(cat /sys/class/net/eth0/address)
229                 wan_mac=$(macaddr_add "$lan_mac" 4)
230                 ;;
231
232         m3 |\
233         m4 |\
234         x5 |\
235         x8)
236                 lan_mac=$(cat /sys/class/net/eth0/address)
237                 lan_mac=$(macaddr_add "$lan_mac" -2)
238                 ;;
239
240         bc2 |\
241         broadway |\
242         d105 |\
243         dir-620-a1 |\
244         esr-9753 |\
245         freestation5 |\
246         hlk-rm04 | \
247         mpr-a1 | \
248         mpr-a2 | \
249         dir-300-b7 | \
250         dir-320-b1 | \
251         psr-680w |\
252         sl-r7205)
253                 lan_mac=$(cat /sys/class/net/eth0/address)
254                 lan_mac=$(macaddr_setbit_la "$lan_mac")
255                 wan_mac=$(macaddr_add "$lan_mac" 1)
256                 ;;
257
258         cy-swr1100 | \
259         dir-645)
260                 lan_mac=$(mtd_get_mac_ascii nvram lanmac)
261                 wan_mac=$(mtd_get_mac_ascii nvram wanmac)
262                 ;;
263
264         wcr-150gn)
265                 wan_mac=$(mtd_get_mac_binary factory 40)
266                 ;;
267
268         rt-n56u)
269                 lan_mac=$(cat /sys/class/net/eth0/address)
270                 lan_mac=$(macaddr_setbit_la "$lan_mac")
271                 wan_mac=$(mtd_get_mac_binary factory 32772)
272                 ;;
273
274         all0239-3g | \
275         carambola | \
276         freestation5 | \
277         w502u | \
278         wnce2001)
279                 wan_mac=$(mtd_get_mac_binary factory 46)
280                 ;;
281
282         *)
283                 lan_mac=$(cat /sys/class/net/eth0/address)
284                 wan_mac=$(macaddr_add "$lan_mac" 1)
285                 ;;
286
287         esac
288
289         [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
290         [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
291 }
292
293 [ -e /etc/config/network ] && exit 0
294
295 touch /etc/config/network
296
297 board=$(ramips_board_name)
298
299 ramips_setup_interfaces $board
300 ramips_setup_macs $board
301
302 uci commit network
303
304 exit 0