ralink: set the mac addr via the dts file
[openwrt/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 argus-atp52b | \
60 b2c | \
61 nw718 | \
62 psr-680w | \
63 sl-r7205 | \
64 w502u | \
65 wr6202)
66 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
67 ;;
68
69 asl26555)
70 ucidef_set_interface_lan "eth0.1"
71 ucidef_add_switch "switch0" "1" "1"
72 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
73 ;;
74
75 dir-645)
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 6t"
79 ucidef_add_switch_vlan "switch0" "2" "0 6t"
80 ;;
81
82 dir-610-a1 | \
83 dir-300-b7 | \
84 dir-320-b1 | \
85 dir-615-h1 | \
86 mzk-w300nh2)
87 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
88 ucidef_add_switch "switch0" "1" "1"
89 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t"
90 ucidef_add_switch_vlan "switch0" "2" "4 6t"
91 ;;
92
93 f5d8235-v1 | \
94 f5d8235-v2 | \
95 hg255d | \
96 ur-326n4g)
97 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
98 ucidef_add_switch "switch0" "1" "1"
99 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
100 ucidef_add_switch_vlan "switch0" "2" "0 6t"
101 ;;
102
103 ur-336un)
104 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
105 ;;
106
107 br6524n | \
108 v11st-fe)
109 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
110 ucidef_add_switch "switch0" "1" "1"
111 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
112 ucidef_add_switch_vlan "switch0" "2" "0 5t"
113 ;;
114
115 rt-n15 | \
116 wl-351)
117 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
118 ucidef_add_switch "switch0" "1" "1"
119 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
120 ucidef_add_switch_vlan "switch0" "2" "4 5t"
121 ;;
122
123 rt-n56u)
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 8t"
127 ucidef_add_switch_vlan "switch0" "2" "4 8t"
128 ;;
129
130 tew-691gr|\
131 tew-692gr)
132 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
133 ucidef_add_switch "switch0" "1" "1"
134 ucidef_add_switch_vlan "switch0" "1" "0t 1 2 3 4"
135 ucidef_add_switch_vlan "switch0" "2" "0t 5"
136 ;;
137
138 wcr-150gn)
139 ucidef_set_interfaces_lan_wan "eth0.2" "eth0.1"
140 ;;
141
142 d105 | \
143 omni-emb-hpm|\
144 wli-tx4-ag300n)
145 ucidef_set_interface_lan "eth0"
146 ;;
147
148 *)
149 RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
150 if [ -n "${RT3X5X}" ]; then
151 ramips_setup_rt3x5x_vlans
152 else
153 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
154 fi
155 ;;
156 esac
157 }
158
159 ramips_setup_macs()
160 {
161 local board="$1"
162 local lan_mac=""
163 local wan_mac=""
164
165 case $board in
166 *)
167 wan_mac=$(macaddr_add "$lan_mac" 1)
168 ;;
169
170 w306r-v20)
171 wan_mac=$(macaddr_add "$lan_mac" 5)
172 ;;
173
174 tew-691gr)
175 wan_mac=$(macaddr_add "$lan_mac" 3)
176 ;;
177
178 tew-692gr)
179 wan_mac=$(macaddr_add "$lan_mac" 4)
180 ;;
181
182 m3 |\
183 m4 |\
184 x5 |\
185 x8)
186 lan_mac=$(macaddr_add "$lan_mac" -1)
187 ;;
188
189 dir-620-a1)
190 lan_mac=$(macaddr_setbit_la "$lan_mac")
191 wan_mac=$(macaddr_add "$lan_mac" 1)
192 ;;
193
194 dir-645)
195 lan_mac=$(mtd_get_mac_ascii nvram lanmac)
196 wan_mac=$(mtd_get_mac_ascii nvram wanmac)
197 ;;
198
199 nbg-419n | \
200 wcr-150gn)
201 wan_mac=$(mtd_get_mac_binary factory 40)
202 ;;
203
204 rt-n56u)
205 wan_mac=$(mtd_get_mac_binary factory 32772)
206 ;;
207
208 all0239-3g | \
209 carambola | \
210 freestation5 | \
211 w502u | \
212 wnce2001)
213 wan_mac=$(mtd_get_mac_binary factory 46)
214 ;;
215
216 wl341v3)
217 lan_mac=$(mtd_get_mac_binary board-nvram 65440)
218 wan_mac=$(macaddr_add "$lan_mac" 1)
219 ;;
220
221 esac
222
223 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
224 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
225 }
226
227 [ -e /etc/config/network ] && exit 0
228
229 touch /etc/config/network
230
231 board=$(ramips_board_name)
232
233 ramips_setup_interfaces $board
234 ramips_setup_macs $board
235
236 uci commit network
237
238 exit 0