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