b9524f6d2c726bdb5721e91da566346c9e88a104
[15.05/openwrt.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
7 ramips_setup_rt3x5x_vlans()
8 {
9         if [ ! -x /sbin/swconfig ]; then
10                 # legacy default
11                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
12                 return
13         fi
14         local wanports=""
15         local lanports=""
16         for port in 5 4 3 2 1 0; do
17                 if [ `swconfig dev rt305x port $port get disable` = "1" ]; then
18                         continue
19                 fi
20                 if [ `swconfig dev rt305x port $port get lan` = "0" ]; then
21                         wanports="$port $wanports"
22                 else
23                         lanports="$port $lanports"
24                 fi
25         done
26         ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
27         ucidef_add_switch "rt305x" "1" "1"
28         ucidef_add_switch_vlan "rt305x" "1" "$lanports 6t"
29         ucidef_add_switch_vlan "rt305x" "2" "$wanports 6t"
30 }
31
32 ramips_setup_interfaces()
33 {
34         local board="$1"
35
36         ucidef_set_interface_loopback
37
38         case $board in
39         3g300m | \
40         w150m | \
41         all0256n | \
42         all5002 | \
43         all5003 | \
44         awm002-evb | \
45         broadway | \
46         dcs-930| \
47         wnce2001)
48                 ucidef_add_switch "switch0" "1" "0"
49                 ucidef_set_interface_lan "eth0"
50                 ;;
51
52         3g-6200nl | \
53         wl-330n | \
54         wmr300)
55                 ucidef_set_interface_lan "eth0.1"
56                 ;;
57
58         3g-6200n | \
59         b2c | \
60         nw718 | \
61         psr-680w | \
62         sl-r7205 | \
63         w502u | \
64         wr6202)
65                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
66                 ;;
67
68         br-6475nd)
69                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
70                 ucidef_add_switch "switch0" "1" "1"
71                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 9t"
72                 ucidef_add_switch_vlan "switch0" "2" "0 9t"
73                 ;;
74
75         asl26555)
76                 ucidef_set_interface_lan "eth0.1"
77                 ucidef_add_switch "switch0" "1" "1"
78                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
79                 ;;
80
81         cy-swr1100)
82                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
83                 ucidef_add_switch "switch0" "1" "1"
84                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 9t"
85                 ucidef_add_switch_vlan "switch0" "2" "4 9t"
86                 ;;
87
88         dir-610-a1 | \
89         dir-300-b7 | \
90         dir-320-b1 | \
91         dir-615-h1 | \
92         hlk-rm04 | \
93         mzk-w300nh2)
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 6t"
97                 ucidef_add_switch_vlan "switch0" "2" "4 6t"
98                 ;;
99
100         argus-atp52b | \
101         dir-645 | \
102         f5d8235-v1 | \
103         f5d8235-v2 | \
104         hg255d | \
105         rt-n14u | \
106         wrtnode | \
107         ur-326n4g)
108                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
109                 ucidef_add_switch "switch0" "1" "1"
110                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
111                 ucidef_add_switch_vlan "switch0" "2" "0 6t"
112                 ;;
113
114         ur-336un)
115                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
116                 ;;
117
118         br6524n | \
119         v11st-fe)
120                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
121                 ucidef_add_switch "switch0" "1" "1"
122                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
123                 ucidef_add_switch_vlan "switch0" "2" "0 5t"
124                 ;;
125
126         ar725w | \
127         rt-n15 | \
128         wl-351)
129                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
130                 ucidef_add_switch "switch0" "1" "1"
131                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
132                 ucidef_add_switch_vlan "switch0" "2" "4 5t"
133                 ;;
134
135         rt-n56u)
136                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
137                 ucidef_add_switch "switch0" "1" "1"
138                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 8t"
139                 ucidef_add_switch_vlan "switch0" "2" "4 8t"
140                 ;;
141
142         tew-691gr|\
143         tew-692gr)
144                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
145                 ucidef_add_switch "switch0" "1" "1"
146                 ucidef_add_switch_vlan "switch0" "1" "0t 1 2 3 4"
147                 ucidef_add_switch_vlan "switch0" "2" "0t 5"
148                 ;;
149
150         wcr-150gn)
151                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
152                 ucidef_add_switch "switch0" "1" "1"
153                 ucidef_add_switch_vlan "switch0" "1" "0 6t"
154                 ucidef_add_switch_vlan "switch0" "2" "6t"
155                 ;;
156
157         d105 | \
158         na930 | \
159         omni-emb-hpm|\
160         wli-tx4-ag300n)
161                 ucidef_set_interface_lan "eth0"
162                 ;;
163
164         *)
165                 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
166                 if [ -n "${RT3X5X}" ]; then
167                         ramips_setup_rt3x5x_vlans
168                 else
169                         ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
170                 fi
171                 ;;
172         esac
173 }
174
175 ramips_setup_macs()
176 {
177         local board="$1"
178         local lan_mac=""
179         local wan_mac=""
180
181         case $board in
182         *)
183                 wan_mac=$(macaddr_add "$lan_mac" 1)
184                 ;;
185
186         br-6475nd)
187                 lan_mac=$(mtd_get_mac_binary devdata 13)
188                 wan_mac=$(mtd_get_mac_binary devdata 7)
189                 ;;
190
191         w306r-v20)
192                 wan_mac=$(macaddr_add "$lan_mac" 5)
193                 ;;
194
195         tew-691gr)
196                 wan_mac=$(macaddr_add "$lan_mac" 3)
197                 ;;
198
199         tew-692gr)
200                 wan_mac=$(macaddr_add "$lan_mac" 4)
201                 ;;
202
203         m3 |\
204         m4 |\
205         x5 |\
206         x8)
207                 lan_mac=$(macaddr_add "$lan_mac" -1)
208                 ;;
209
210         dir-620-a1)
211                 lan_mac=$(macaddr_setbit_la "$lan_mac")
212                 wan_mac=$(macaddr_add "$lan_mac" 1)
213                 ;;
214
215         cy-swr1100 | \
216         dir-645)
217                 lan_mac=$(mtd_get_mac_ascii nvram lanmac)
218                 wan_mac=$(mtd_get_mac_ascii nvram wanmac)
219                 ;;
220
221         nbg-419n | \
222         wcr-150gn)
223                 wan_mac=$(mtd_get_mac_binary factory 40)
224                 ;;
225
226         rt-n56u)
227                 wan_mac=$(mtd_get_mac_binary factory 32772)
228                 ;;
229
230         all0239-3g | \
231         carambola | \
232         freestation5 | \
233         w502u | \
234         wnce2001)
235                 wan_mac=$(mtd_get_mac_binary factory 46)
236                 ;;
237
238         wl341v3)
239                 lan_mac=$(mtd_get_mac_binary board-nvram 65440)
240                 wan_mac=$(macaddr_add "$lan_mac" 1)
241                 ;;
242
243         esac
244
245         [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
246         [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
247 }
248
249 [ -e /etc/config/network ] && exit 0
250
251 touch /etc/config/network
252
253 board=$(ramips_board_name)
254
255 ramips_setup_interfaces $board
256 ramips_setup_macs $board
257
258 uci commit network
259
260 exit 0