ath79: Add support for Ubiquiti Nanostation M (XW)
[openwrt/openwrt.git] / target / linux / ath79 / base-files / etc / board.d / 02_network
1 #!/bin/sh
2
3 . /lib/functions/system.sh
4 . /lib/functions/uci-defaults.sh
5 . /lib/functions/k2t.sh
6
7 ath79_setup_interfaces()
8 {
9 local board="$1"
10
11 case "$board" in
12 avm,fritz300e|\
13 devolo,dvl1200i|\
14 devolo,dvl1750c|\
15 devolo,dvl1750i|\
16 ocedo,koala|\
17 ocedo,raccoon|\
18 pcs,cap324|\
19 pisen,wmm003n|\
20 pqi,air-pen|\
21 tplink,re450-v2|\
22 tplink,tl-mr10u|\
23 tplink,tl-mr3020-v1|\
24 tplink,tl-mr3040-v2|\
25 tplink,tl-wa901nd-v2|\
26 tplink,tl-wr703n|\
27 ubnt,bullet-m|\
28 ubnt,bullet-m-xw|\
29 ubnt,lap-120|\
30 ubnt,nanostation-ac-loco|\
31 ubnt,rocket-m|\
32 ubnt,unifiac-lite|\
33 ubnt,unifiac-mesh|\
34 ubnt,unifi|\
35 wd,mynet-wifi-rangeextender|\
36 winchannel,wb2000)
37 ucidef_set_interface_lan "eth0"
38 ;;
39 avm,fritz4020|\
40 pcs,cr3000|\
41 tplink,archer-c58-v1|\
42 tplink,archer-c59-v1)
43 ucidef_set_interface_wan "eth0"
44 ucidef_add_switch "switch0" \
45 "0@eth1" "1:lan:1" "2:lan:4" "3:lan:3" "4:lan:2"
46 ;;
47 buffalo,bhr-4grv|\
48 buffalo,wzr-hp-g450h)
49 ucidef_add_switch "switch0" \
50 "0@eth0" "2:lan" "3:lan" "4:lan" "5:lan" "1:wan"
51 ;;
52 buffalo,bhr-4grv2)
53 ucidef_add_switch "switch0" \
54 "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan" "6@eth0"
55 ;;
56 buffalo,wzr-hp-ag300h)
57 ucidef_set_interface_wan "eth1"
58 ucidef_add_switch "switch0" \
59 "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1"
60 ;;
61 buffalo,wzr-hp-g302h-a1a0)
62 ucidef_add_switch "switch0" \
63 "0@eth0" "1:lan:1" "3:lan:4" "4:lan:3" "5:lan:2" "2:wan"
64 ;;
65 devolo,dvl1200e|\
66 devolo,dvl1750e)
67 ucidef_set_interface_lan "eth0 eth1"
68 ;;
69 dlink,dir-825-b1)
70 ucidef_set_interface_wan "eth1"
71 ucidef_add_switch "switch0" \
72 "0:lan" "1:lan" "2:lan" "3:lan" "5@eth0"
73 ;;
74 dlink,dir-825-c1|\
75 dlink,dir-835-a1|\
76 dlink,dir-859-a1|\
77 tplink,archer-c2-v3|\
78 tplink,tl-wr1043nd-v4)
79 ucidef_add_switch "switch0" \
80 "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan"
81 ;;
82 elecom,wrc-1750ghbk2-i|\
83 elecom,wrc-300ghbk2-i)
84 ucidef_add_switch "switch0" \
85 "0@eth0" "2:lan:4" "3:lan:3" "4:lan:2" "5:lan:1" "1:wan"
86 ;;
87 embeddedwireless,dorin)
88 ucidef_add_switch "switch0" \
89 "0@eth0" "1:wan" "2:lan:3" "3:lan:2"
90 ;;
91 engenius,ews511ap)
92 ucidef_set_interface_lan "eth0 eth1" "dhcp"
93 ;;
94 etactica,eg200)
95 ucidef_set_interface_lan "eth0" "dhcp"
96 ;;
97 glinet,gl-ar150|\
98 glinet,gl-ar300m-nand|\
99 glinet,gl-ar300m-nor|\
100 glinet,gl-x750|\
101 tplink,tl-wr810n-v1|\
102 tplink,tl-wr810n-v2|\
103 ubnt,routerstation)
104 ucidef_set_interfaces_lan_wan "eth1" "eth0"
105 ;;
106 glinet,gl-ar750s)
107 ucidef_add_switch "switch0" \
108 "0@eth0" "2:lan:2" "3:lan:1" "1:wan"
109 ;;
110 iodata,etg3-r|\
111 iodata,wn-ac1167dgr|\
112 iodata,wn-ac1600dgr|\
113 iodata,wn-ac1600dgr2|\
114 iodata,wn-ag300dgr|\
115 pcs,cr5000)
116 ucidef_add_switch "switch0" \
117 "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan"
118 ;;
119 nec,wg800hp)
120 ucidef_add_switch "switch0" \
121 "0@eth0" "2:lan" "3:lan" "4:lan" "1:wan"
122 ;;
123 netgear,wndr3700|\
124 netgear,wndr3700v2|\
125 netgear,wndr3800)
126 ucidef_set_interfaces_lan_wan "eth0" "eth1"
127 ucidef_add_switch "switch0" \
128 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "5u@eth0"
129 ucidef_add_switch_attr "switch0" "blinkrate" 2
130 ucidef_add_switch_port_attr "switch0" 1 led 6
131 ucidef_add_switch_port_attr "switch0" 2 led 9
132 ucidef_add_switch_port_attr "switch0" 5 led 2
133 ;;
134 netgear,wnr612-v2|\
135 on,n150r|\
136 tplink,tl-wr841-v7)
137 ucidef_set_interface_wan "eth0"
138 ucidef_add_switch "switch0" \
139 "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan"
140 ;;
141 phicomm,k2t)
142 ucidef_add_switch "switch0" \
143 "0@eth0" "3:lan:1" "5:lan:2" "4:wan"
144 ;;
145 rosinson,wr818)
146 ucidef_add_switch "switch0" \
147 "0@eth0" "1:lan" "2:lan" "3:wan"
148 ;;
149 tplink,archer-c5-v1|\
150 tplink,archer-c7-v1|\
151 tplink,archer-c7-v2|\
152 tplink,tl-wdr4900-v2)
153 ucidef_add_switch "switch0" \
154 "0@eth1" "2:lan" "3:lan" "4:lan" "5:lan" "6@eth0" "1:wan"
155 ;;
156 buffalo,whr-g301n|\
157 tplink,tl-mr3220-v1|\
158 tplink,tl-mr3420-v1|\
159 tplink,tl-wr841-v9|\
160 tplink,tl-wr841-v11|\
161 ubnt,airrouter)
162 ucidef_set_interface_wan "eth0"
163 ucidef_add_switch "switch0" \
164 "0@eth1" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1"
165 ;;
166 tplink,archer-a7-v5|\
167 tplink,archer-c6-v2|\
168 tplink,archer-c7-v4|\
169 tplink,archer-c7-v5|\
170 tplink,tl-wdr3600|\
171 tplink,tl-wdr4300)
172 ucidef_add_switch "switch0" \
173 "0@eth0" "2:lan:1" "3:lan:2" "4:lan:3" "5:lan:4" "1:wan"
174 ;;
175 tplink,tl-wr1043nd-v1)
176 ucidef_add_switch "switch0" \
177 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
178 ;;
179 tplink,tl-wr1043nd-v2|\
180 tplink,tl-wr1043nd-v3)
181 ucidef_add_switch "switch0" \
182 "0@eth1" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan" "6@eth0"
183 ;;
184 tplink,tl-wr2543-v1)
185 ucidef_add_switch "switch0" \
186 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "9@eth0"
187 ;;
188 tplink,tl-wr740n-v1|\
189 tplink,tl-wr740n-v3|\
190 tplink,tl-wr741-v1|\
191 tplink,tl-wr743nd-v1|\
192 tplink,tl-wr841-v5|\
193 tplink,tl-wr941-v4)
194 ucidef_set_interface_wan "eth0"
195 ucidef_add_switch "switch0" \
196 "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan"
197 ;;
198 tplink,tl-wr740n-v4|\
199 tplink,tl-wr741nd-v4|\
200 tplink,tl-wr841-v8|\
201 tplink,tl-wr842n-v1|\
202 tplink,tl-wr842n-v2)
203 ucidef_set_interface_wan "eth0"
204 ucidef_add_switch "switch0" \
205 "0@eth1" "1:lan:4" "2:lan:1" "3:lan:2" "4:lan:3"
206 ;;
207 tplink,tl-wr941-v2)
208 ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan"
209 ;;
210 ubnt,routerstation-pro)
211 ucidef_set_interface_wan "eth0"
212 ucidef_add_switch "switch0" \
213 "0@eth1" "2:lan:3" "3:lan:2" "4:lan:1"
214 ;;
215 ubnt,nanostation-m-xw)
216 ucidef_add_switch "switch0" \
217 "0@eth0" "5:lan" "1:wan"
218 ;;
219 ubnt,nanostation-ac|\
220 ubnt,unifiac-mesh-pro|\
221 ubnt,unifiac-pro)
222 ucidef_add_switch "switch0" \
223 "0@eth0" "2:lan" "3:wan"
224 ;;
225 xiaomi,mi-router-4q)
226 ucidef_set_interface_wan "eth0"
227 ucidef_add_switch "switch0" \
228 "0@eth1" "3:lan:1" "4:lan:2"
229 ;;
230 *)
231 ucidef_set_interfaces_lan_wan "eth0" "eth1"
232 ;;
233 esac
234 }
235
236 ath79_setup_macs()
237 {
238 local board="$1"
239
240 case "$board" in
241 avm,fritz300e)
242 lan_mac=$(fritz_tffs -n maca -i $(find_mtd_part "tffs (1)"))
243 ;;
244 avm,fritz4020)
245 lan_mac=$(fritz_tffs -n maca -i $(find_mtd_part "tffs (1)"))
246 wan_mac=$(fritz_tffs -n macb -i $(find_mtd_part "tffs (1)"))
247 ;;
248 dlink,dir-825-b1)
249 lan_mac=$(mtd_get_mac_text "caldata" 65440)
250 wan_mac=$(mtd_get_mac_text "caldata" 65460)
251 ;;
252 dlink,dir-825-c1|\
253 dlink,dir-835-a1)
254 lan_mac=$(mtd_get_mac_text "mac" 4)
255 wan_mac=$(mtd_get_mac_text "mac" 24)
256 ;;
257 dlink,dir-859-a1)
258 lan_mac=$(mtd_get_mac_ascii devdata "lanmac")
259 wan_mac=$(mtd_get_mac_ascii devdata "wanmac")
260 ;;
261 elecom,wrc-1750ghbk2-i|\
262 elecom,wrc-300ghbk2-i)
263 wan_mac=$(macaddr_add "$(mtd_get_mac_binary ART 4098)" -2)
264 ;;
265 engenius,ews511ap)
266 lan_mac=$(mtd_get_mac_text "u-boot-env" 233)
267 eth1_mac=$(macaddr_add "$lan_mac" 1)
268 ucidef_set_interface "eth0" ifname "eth0" protocol "none" macaddr "$lan_mac"
269 ucidef_set_interface "eth1" ifname "eth1" protocol "none" macaddr "$eth1_mac"
270 ;;
271 iodata,etg3-r)
272 lan_mac=$(mtd_get_mac_ascii u-boot-env ethaddr)
273 wan_mac=$(macaddr_add "$lan_mac" -1)
274 ;;
275 iodata,wn-ac1167dgr|\
276 iodata,wn-ac1600dgr|\
277 iodata,wn-ac1600dgr2|\
278 iodata,wn-ag300dgr)
279 lan_mac=$(mtd_get_mac_ascii u-boot-env ethaddr)
280 wan_mac=$(mtd_get_mac_ascii u-boot-env wanaddr)
281 ;;
282 nec,wg800hp)
283 lan_mac=$(mtd_get_mac_text board_data 640)
284 wan_mac=$(mtd_get_mac_text board_data 1152)
285 ;;
286 netgear,wndr3700|\
287 netgear,wndr3700v2|\
288 netgear,wndr3800)
289 lan_mac=$(macaddr_setbit_la "$(mtd_get_mac_binary art 0)")
290 ;;
291 phicomm,k2t)
292 lan_mac=$(k2t_get_mac "lan_mac")
293 wan_mac=$(k2t_get_mac "wan_mac")
294 ;;
295 rosinson,wr818)
296 wan_mac=$(mtd_get_mac_binary factory 0)
297 lan_mac=$(macaddr_setbit_la "$wan_mac")
298 ;;
299 tplink,archer-c7-v4)
300 base_mac=$(mtd_get_mac_binary config 8)
301 wan_mac=$(macaddr_add "$base_mac" 1)
302 ;;
303 tplink,tl-wr1043nd-v4)
304 base_mac=$(mtd_get_mac_binary product-info 8)
305 wan_mac=$(macaddr_add "$base_mac" 1)
306 ;;
307 tplink,tl-wr941-v2)
308 base_mac=$(mtd_get_mac_binary u-boot 130048)
309 wan_mac=$(macaddr_add "$base_mac" 1)
310 ;;
311 ubnt,routerstation|\
312 ubnt,routerstation-pro)
313 wan_mac=$(fconfig -s -r -d $(find_mtd_part "RedBoot config") -n ar7100_esa)
314 lan_mac=$(macaddr_add "$wan_mac" 1)
315 ;;
316 wd,mynet-wifi-rangeextender)
317 lan_mac=$(nvram get et0macaddr)
318 ;;
319 esac
320
321 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
322 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
323 }
324
325 board_config_update
326 board=$(board_name)
327 ath79_setup_interfaces $board
328 ath79_setup_macs $board
329 board_config_flush
330
331 exit 0