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