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