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