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