b54b55532698951162d2fa4f02117c39a5a8980d
[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         broadway | \
45         dcs-930| \
46         ncs601w | \
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         awapn2403)
69                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
70                 ucidef_add_switch "switch0" "1" "1"
71                 ucidef_add_switch_vlan "switch0" "1" "0 6t"
72                 ucidef_add_switch_vlan "switch0" "2" "1 6t"
73                 ;;
74
75         br-6475nd)
76                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
77                 ucidef_add_switch "switch0" "1" "1"
78                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 9t"
79                 ucidef_add_switch_vlan "switch0" "2" "0 9t"
80                 ;;
81
82         asl26555)
83                 ucidef_set_interface_lan "eth0.1"
84                 ucidef_add_switch "switch0" "1" "1"
85                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
86                 ;;
87
88         cy-swr1100)
89                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
90                 ucidef_add_switch "switch0" "1" "1"
91                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 9t"
92                 ucidef_add_switch_vlan "switch0" "2" "4 9t"
93                 ;;
94
95         dir-610-a1 | \
96         dir-300-b7 | \
97         dir-320-b1 | \
98         dir-615-h1 | \
99         hlk-rm04 | \
100         mzk-w300nh2 | \
101         mzk-750dhp)
102                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
103                 ucidef_add_switch "switch0" "1" "1"
104                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t"
105                 ucidef_add_switch_vlan "switch0" "2" "4 6t"
106                 ;;
107
108         awm002-evb | \
109         argus-atp52b | \
110         dir-645 | \
111         f5d8235-v1 | \
112         f5d8235-v2 | \
113         hg255d | \
114         rt-n14u | \
115         wrtnode | \
116         ur-326n4g | \
117         zbt-wa05)
118                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
119                 ucidef_add_switch "switch0" "1" "1"
120                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
121                 ucidef_add_switch_vlan "switch0" "2" "0 6t"
122                 ;;
123
124         ur-336un)
125                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
126                 ;;
127
128         br6524n | \
129         v11st-fe)
130                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
131                 ucidef_add_switch "switch0" "1" "1"
132                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
133                 ucidef_add_switch_vlan "switch0" "2" "0 5t"
134                 ;;
135
136         ar725w | \
137         rt-n15 | \
138         wl-351)
139                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
140                 ucidef_add_switch "switch0" "1" "1"
141                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
142                 ucidef_add_switch_vlan "switch0" "2" "4 5t"
143                 ;;
144
145         rt-n56u)
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 8t"
149                 ucidef_add_switch_vlan "switch0" "2" "4 8t"
150                 ;;
151
152         tew-691gr|\
153         tew-692gr)
154                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
155                 ucidef_add_switch "switch0" "1" "1"
156                 ucidef_add_switch_vlan "switch0" "1" "0t 1 2 3 4"
157                 ucidef_add_switch_vlan "switch0" "2" "0t 5"
158                 ;;
159
160         wcr-150gn)
161                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
162                 ucidef_add_switch "switch0" "1" "1"
163                 ucidef_add_switch_vlan "switch0" "1" "0 6t"
164                 ucidef_add_switch_vlan "switch0" "2" "6t"
165                 ;;
166
167         wr8305rt)
168                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
169                 ucidef_add_switch "switch0" "1" "1"
170                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 4 6t"
171                 ucidef_add_switch_vlan "switch0" "2" "4 6t"
172                 ;;
173
174         d105 | \
175         na930 | \
176         omni-emb-hpm|\
177         wli-tx4-ag300n)
178                 ucidef_set_interface_lan "eth0"
179                 ;;
180
181         *)
182                 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
183                 if [ -n "${RT3X5X}" ]; then
184                         ramips_setup_rt3x5x_vlans
185                 else
186                         ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
187                 fi
188                 ;;
189         esac
190 }
191
192 ramips_setup_macs()
193 {
194         local board="$1"
195         local lan_mac=""
196         local wan_mac=""
197
198         case $board in
199         br-6475nd)
200                 lan_mac=$(mtd_get_mac_binary devdata 13)
201                 wan_mac=$(mtd_get_mac_binary devdata 7)
202                 ;;
203
204         w306r-v20)
205                 wan_mac=$(macaddr_add "$lan_mac" 5)
206                 ;;
207
208         tew-691gr)
209                 wan_mac=$(macaddr_add "$lan_mac" 3)
210                 ;;
211
212         tew-692gr)
213                 wan_mac=$(macaddr_add "$lan_mac" 4)
214                 ;;
215
216         m3 |\
217         m4 |\
218         x5 |\
219         x8)
220                 lan_mac=$(macaddr_add "$lan_mac" -1)
221                 ;;
222
223         dir-620-a1)
224                 lan_mac=$(macaddr_setbit_la "$lan_mac")
225                 wan_mac=$(macaddr_add "$lan_mac" 1)
226                 ;;
227
228         cy-swr1100 | \
229         dir-645)
230                 lan_mac=$(mtd_get_mac_ascii nvram lanmac)
231                 wan_mac=$(mtd_get_mac_ascii nvram wanmac)
232                 ;;
233
234         nbg-419n | \
235         wcr-150gn)
236                 wan_mac=$(mtd_get_mac_binary factory 40)
237                 ;;
238
239         rt-n56u)
240                 wan_mac=$(mtd_get_mac_binary factory 32772)
241                 ;;
242
243         all0239-3g | \
244         carambola | \
245         freestation5 | \
246         w502u | \
247         wnce2001)
248                 wan_mac=$(mtd_get_mac_binary factory 46)
249                 ;;
250
251         wl341v3)
252                 lan_mac=$(mtd_get_mac_binary board-nvram 65440)
253                 wan_mac=$(macaddr_add "$lan_mac" 1)
254                 ;;
255
256         wr8305rt)
257                 lan_mac=$(mtd_get_mac_binary factory 4)
258                 wan_mac=$(macaddr_add "$lan_mac" 1)
259                 ;;
260
261         *)
262                 lan_mac=$(cat /sys/class/net/eth0/address)
263                 wan_mac=$(macaddr_add "$lan_mac" 1)
264                 ;;
265
266         esac
267
268         [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
269         [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
270 }
271
272 [ -e /etc/config/network ] && exit 0
273
274 touch /etc/config/network
275
276 board=$(ramips_board_name)
277
278 ramips_setup_interfaces $board
279 ramips_setup_macs $board
280
281 uci commit network
282
283 exit 0