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