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