1569b110bdfbf4b8a66761f8d88d69b5f2e9ec26
[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 ucidef_set_interface_lan "eth0 eth1"
67 ;;
68 dlink,dir-825-b1)
69 ucidef_set_interface_wan "eth1"
70 ucidef_add_switch "switch0" \
71 "0:lan" "1:lan" "2:lan" "3:lan" "5@eth0"
72 ;;
73 dlink,dir-825-c1|\
74 dlink,dir-835-a1|\
75 dlink,dir-859-a1|\
76 tplink,tl-wr1043nd-v4)
77 ucidef_add_switch "switch0" \
78 "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan"
79 ;;
80 elecom,wrc-1750ghbk2-i|\
81 elecom,wrc-300ghbk2-i)
82 ucidef_add_switch "switch0" \
83 "0@eth0" "2:lan:4" "3:lan:3" "4:lan:2" "5:lan:1" "1:wan"
84 ;;
85 embeddedwireless,dorin)
86 ucidef_add_switch "switch0" \
87 "0@eth0" "1:wan" "2:lan:3" "3:lan:2"
88 ;;
89 engenius,ews511ap)
90 ucidef_set_interface_lan "eth0 eth1" "dhcp"
91 ;;
92 etactica,eg200)
93 ucidef_set_interface_lan "eth0" "dhcp"
94 ;;
95 glinet,gl-ar150|\
96 glinet,gl-ar300m-nand|\
97 glinet,gl-ar300m-nor|\
98 glinet,gl-x750|\
99 tplink,tl-wr810n-v1|\
100 tplink,tl-wr810n-v2|\
101 ubnt,routerstation)
102 ucidef_set_interfaces_lan_wan "eth1" "eth0"
103 ;;
104 glinet,gl-ar750s)
105 ucidef_add_switch "switch0" \
106 "0@eth0" "2:lan:2" "3:lan:1" "1:wan"
107 ;;
108 iodata,etg3-r|\
109 iodata,wn-ac1167dgr|\
110 iodata,wn-ac1600dgr2|\
111 iodata,wn-ag300dgr|\
112 pcs,cr5000)
113 ucidef_add_switch "switch0" \
114 "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan"
115 ;;
116 nec,wg800hp)
117 ucidef_add_switch "switch0" \
118 "0@eth0" "2:lan" "3:lan" "4:lan" "1:wan"
119 ;;
120 netgear,wndr3700|\
121 netgear,wndr3700v2|\
122 netgear,wndr3800)
123 ucidef_set_interfaces_lan_wan "eth0" "eth1"
124 ucidef_add_switch "switch0" \
125 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "5u@eth0"
126 ucidef_add_switch_attr "switch0" "blinkrate" 2
127 ucidef_add_switch_port_attr "switch0" 1 led 6
128 ucidef_add_switch_port_attr "switch0" 2 led 9
129 ucidef_add_switch_port_attr "switch0" 5 led 2
130 ;;
131 netgear,wnr612-v2|\
132 on,n150r)
133 ucidef_set_interface_wan "eth0"
134 ucidef_add_switch "switch0" \
135 "0@eth1" "1:lan" "2:lan" "3:lan:3" "4:lan:4"
136 ;;
137 phicomm,k2t)
138 ucidef_add_switch "switch0" \
139 "0@eth0" "3:lan:1" "5:lan:2" "4:wan"
140 ;;
141 rosinson,wr818)
142 ucidef_add_switch "switch0" \
143 "0@eth0" "1:lan" "2:lan" "3:wan"
144 ;;
145 tplink,archer-c7-v1|\
146 tplink,archer-c7-v2|\
147 tplink,tl-wdr4900-v2)
148 ucidef_add_switch "switch0" \
149 "0@eth1" "2:lan" "3:lan" "4:lan" "5:lan" "6@eth0" "1:wan"
150 ;;
151 buffalo,whr-g301n|\
152 tplink,tl-mr3220-v1|\
153 tplink,tl-mr3420-v1|\
154 tplink,tl-wr741nd-v4|\
155 tplink,tl-wr841-v7|\
156 tplink,tl-wr841-v9|\
157 tplink,tl-wr841-v11|\
158 ubnt,airrouter)
159 ucidef_set_interface_wan "eth0"
160 ucidef_add_switch "switch0" \
161 "0@eth1" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1"
162 ;;
163 tplink,archer-a7-v5|\
164 tplink,archer-c6-v2|\
165 tplink,archer-c7-v5|\
166 tplink,tl-wdr3600|\
167 tplink,tl-wdr4300)
168 ucidef_add_switch "switch0" \
169 "0@eth0" "2:lan:1" "3:lan:2" "4:lan:3" "5:lan:4" "1:wan"
170 ;;
171 tplink,tl-wr1043nd-v1)
172 ucidef_add_switch "switch0" \
173 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
174 ;;
175 tplink,tl-wr1043nd-v2|\
176 tplink,tl-wr1043nd-v3)
177 ucidef_add_switch "switch0" \
178 "0@eth1" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan" "6@eth0"
179 ;;
180 tplink,tl-wr2543-v1)
181 ucidef_add_switch "switch0" \
182 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "9@eth0"
183 ;;
184 tplink,tl-wr740n-v1|\
185 tplink,tl-wr740n-v3|\
186 tplink,tl-wr741-v1|\
187 tplink,tl-wr743nd-v1|\
188 tplink,tl-wr841-v5|\
189 tplink,tl-wr941-v4)
190 ucidef_set_interface_wan "eth0"
191 ucidef_add_switch "switch0" \
192 "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan"
193 ;;
194 tplink,tl-wr740nd-v4|\
195 tplink,tl-wr841-v8|\
196 tplink,tl-wr842n-v1|\
197 tplink,tl-wr842n-v2)
198 ucidef_set_interface_wan "eth0"
199 ucidef_add_switch "switch0" \
200 "0@eth1" "1:lan:4" "2:lan:1" "3:lan:2" "4:lan:3"
201 ;;
202 tplink,tl-wr941-v2)
203 ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan"
204 ;;
205 ubnt,routerstation-pro)
206 ucidef_set_interface_wan "eth0"
207 ucidef_add_switch "switch0" \
208 "0@eth1" "2:lan:3" "3:lan:2" "4:lan:1"
209 ;;
210 ubnt,nanostation-ac|\
211 ubnt,unifiac-mesh-pro|\
212 ubnt,unifiac-pro)
213 ucidef_add_switch "switch0" \
214 "0@eth0" "2:lan" "3:wan"
215 ;;
216 *)
217 ucidef_set_interfaces_lan_wan "eth0" "eth1"
218 ;;
219 esac
220 }
221
222 ath79_setup_macs()
223 {
224 local board="$1"
225
226 case "$board" in
227 avm,fritz300e)
228 lan_mac=$(fritz_tffs -n maca -i $(find_mtd_part "tffs (1)"))
229 ;;
230 avm,fritz4020)
231 lan_mac=$(fritz_tffs -n maca -i $(find_mtd_part "tffs (1)"))
232 wan_mac=$(fritz_tffs -n macb -i $(find_mtd_part "tffs (1)"))
233 ;;
234 dlink,dir-825-b1)
235 lan_mac=$(mtd_get_mac_text "caldata" 65440)
236 wan_mac=$(mtd_get_mac_text "caldata" 65460)
237 ;;
238 dlink,dir-825-c1|\
239 dlink,dir-835-a1)
240 lan_mac=$(mtd_get_mac_text "mac" 4)
241 wan_mac=$(mtd_get_mac_text "mac" 24)
242 ;;
243 dlink,dir-859-a1)
244 lan_mac=$(mtd_get_mac_ascii devdata "lanmac")
245 wan_mac=$(mtd_get_mac_ascii devdata "wanmac")
246 ;;
247 elecom,wrc-1750ghbk2-i|\
248 elecom,wrc-300ghbk2-i)
249 wan_mac=$(macaddr_add "$(mtd_get_mac_binary ART 4098)" -2)
250 ;;
251 engenius,ews511ap)
252 lan_mac=$(mtd_get_mac_text "u-boot-env" 233)
253 eth1_mac=$(macaddr_add "$lan_mac" 1)
254 ucidef_set_interface "eth0" ifname "eth0" protocol "none" macaddr "$lan_mac"
255 ucidef_set_interface "eth1" ifname "eth1" protocol "none" macaddr "$eth1_mac"
256 ;;
257 iodata,etg3-r)
258 lan_mac=$(mtd_get_mac_ascii u-boot-env ethaddr)
259 wan_mac=$(macaddr_add "$lan_mac" -1)
260 ;;
261 iodata,wn-ac1167dgr|\
262 iodata,wn-ac1600dgr2|\
263 iodata,wn-ag300dgr)
264 lan_mac=$(mtd_get_mac_ascii u-boot-env ethaddr)
265 wan_mac=$(mtd_get_mac_ascii u-boot-env wanaddr)
266 ;;
267 nec,wg800hp)
268 lan_mac=$(mtd_get_mac_text board_data 640)
269 wan_mac=$(mtd_get_mac_text board_data 1152)
270 ;;
271 netgear,wndr3700|\
272 netgear,wndr3700v2|\
273 netgear,wndr3800)
274 lan_mac=$(macaddr_setbit_la "$(mtd_get_mac_binary art 0)")
275 ;;
276 phicomm,k2t)
277 lan_mac=$(k2t_get_mac "lan_mac")
278 wan_mac=$(k2t_get_mac "wan_mac")
279 ;;
280 rosinson,wr818)
281 wan_mac=$(mtd_get_mac_binary factory 0)
282 lan_mac=$(macaddr_setbit_la "$wan_mac")
283 ;;
284 tplink,tl-wr1043nd-v4)
285 base_mac=$(mtd_get_mac_binary product-info 8)
286 wan_mac=$(macaddr_add "$base_mac" 1)
287 ;;
288 tplink,tl-wr941-v2)
289 base_mac=$(mtd_get_mac_binary u-boot 130048)
290 wan_mac=$(macaddr_add "$base_mac" 1)
291 ;;
292 ubnt,routerstation|\
293 ubnt,routerstation-pro)
294 wan_mac=$(fconfig -s -r -d $(find_mtd_part "RedBoot config") -n ar7100_esa)
295 lan_mac=$(macaddr_add "$wan_mac" 1)
296 ;;
297 wd,mynet-wifi-rangeextender)
298 lan_mac=$(nvram get et0macaddr)
299 ;;
300 esac
301
302 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
303 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
304 }
305
306 board_config_update
307 board=$(board_name)
308 ath79_setup_interfaces $board
309 ath79_setup_macs $board
310 board_config_flush
311
312 exit 0