AA: ar71xx: TP-LINK also has a family TL-WDR
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / base-files / lib / ar71xx.sh
1 #!/bin/sh
2 #
3 # Copyright (C) 2009-2011 OpenWrt.org
4 #
5
6 AR71XX_BOARD_NAME=
7 AR71XX_MODEL=
8
9 ar71xx_get_mtd_offset_size_format() {
10 local mtd="$1"
11 local offset="$2"
12 local size="$3"
13 local format="$4"
14 local dev
15
16 dev=$(find_mtd_part $mtd)
17 [ -z "$dev" ] && return
18
19 dd if=$dev bs=1 skip=$offset count=$size 2>/dev/null | hexdump -v -e "1/1 \"$format\""
20 }
21
22 ar71xx_get_mtd_part_magic() {
23 local mtd="$1"
24 ar71xx_get_mtd_offset_size_format "$mtd" 0 4 %02x
25 }
26
27 wndr3700_board_detect() {
28 local machine="$1"
29 local magic
30 local name
31
32 name="wndr3700"
33
34 magic="$(ar71xx_get_mtd_part_magic firmware)"
35 case $magic in
36 "33373030")
37 machine="NETGEAR WNDR3700"
38 ;;
39 "33373031")
40 local model
41 model=$(ar71xx_get_mtd_offset_size_format art 56 10 %c)
42 if [ -z "$model" ] || [ "$model" = $'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' ]; then
43 machine="NETGEAR WNDR3700v2"
44 elif [ -z "$model" ] || [ "$model" = $'\xff\xff\xff\xff\xff\xff\xff\xff\xffN' ]; then
45 machine="NETGEAR WNDRMAC"
46 else
47 machine="NETGEAR $model"
48 fi
49 ;;
50 esac
51
52 AR71XX_BOARD_NAME="$name"
53 AR71XX_MODEL="$machine"
54 }
55
56 tplink_get_hwid() {
57 local part
58
59 part=$(find_mtd_part firmware)
60 [ -z "$part" ] && return 1
61
62 dd if=$part bs=4 count=1 skip=16 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
63 }
64
65 tplink_board_detect() {
66 local model="$1"
67 local hwid
68 local hwver
69
70 hwid=$(tplink_get_hwid)
71 hwver=${hwid:6:2}
72 hwver="v${hwver#0}"
73
74 case "$hwid" in
75 "070300"*)
76 model="TP-Link TL-WR703N"
77 ;;
78 "070100"*)
79 model="TP-Link TL-WA701N/ND"
80 ;;
81 "074000"*)
82 model="TP-Link TL-WR740N/ND"
83 ;;
84 "074100"*)
85 model="TP-Link TL-WR741N/ND"
86 ;;
87 "074300"*)
88 model="TP-Link TL-WR743N/ND"
89 ;;
90 "084100"*)
91 model="TP-Link TL-WR841N/ND"
92 ;;
93 "084200"*)
94 model="TP-Link TL-WR842N/ND"
95 ;;
96 "090100"*)
97 model="TP-Link TL-WA901N/ND"
98 ;;
99 "094100"*)
100 model="TP-Link TL-WR941N/ND"
101 ;;
102 "104100"*)
103 model="TP-Link TL-WR1041N/ND"
104 ;;
105 "104300"*)
106 model="TP-Link TL-WR1043N/ND"
107 ;;
108 "254300"*)
109 model="TP-Link TL-WR2543N/ND"
110 ;;
111 "110101"*)
112 model="TP-Link TL-MR11U"
113 ;;
114 "302000"*)
115 model="TP-Link TL-MR3020"
116 ;;
117 "304000"*)
118 model="TP-Link TL-MR3040"
119 ;;
120 "322000"*)
121 model="TP-Link TL-MR3220"
122 ;;
123 "342000"*)
124 model="TP-Link TL-MR3420"
125 ;;
126 "360000"*)
127 model="TP-Link TL-WDR3600"
128 ;;
129 "430000"*)
130 model="TP-Link TL-WDR4300"
131 ;;
132 "431000"*)
133 model="TP-Link TL-WDR4310"
134 ;;
135 *)
136 hwver=""
137 ;;
138 esac
139
140 AR71XX_MODEL="$model $hwver"
141 }
142
143 ar71xx_board_detect() {
144 local machine
145 local name
146
147 machine=$(awk 'BEGIN{FS="[ \t]+:[ \t]"} /machine/ {print $2}' /proc/cpuinfo)
148
149 case "$machine" in
150 *"AirRouter")
151 name="airrouter"
152 ;;
153 *"ALFA Network AP96")
154 name="alfa-ap96"
155 ;;
156 *"ALFA Network N2/N5")
157 name="alfa-nx"
158 ;;
159 *ALL0258N)
160 name="all0258n"
161 ;;
162 *ALL0305)
163 name="all0305"
164 ;;
165 *ALL0315N)
166 name="all0315n"
167 ;;
168 *AP113)
169 name="ap113"
170 ;;
171 *AP121)
172 name="ap121"
173 ;;
174 *AP121-MINI)
175 name="ap121-mini"
176 ;;
177 *"AP136 reference board")
178 name="ap136"
179 ;;
180 *AP81)
181 name="ap81"
182 ;;
183 *AP83)
184 name="ap83"
185 ;;
186 *"Atheros AP96")
187 name="ap96"
188 ;;
189 *AW-NR580)
190 name="aw-nr580"
191 ;;
192 *CAP4200AG)
193 name="cap4200ag"
194 ;;
195 *"DB120 reference board")
196 name="db120"
197 ;;
198 *"DIR-600 rev. A1")
199 name="dir-600-a1"
200 ;;
201 *"DIR-615 rev. E4")
202 name="dir-615-e4"
203 ;;
204 *"DIR-825 rev. B1")
205 name="dir-825-b1"
206 ;;
207 *EAP7660D)
208 name="eap7660d"
209 ;;
210 *JA76PF)
211 name="ja76pf"
212 ;;
213 *JA76PF2)
214 name="ja76pf2"
215 ;;
216 *"Bullet M")
217 name="bullet-m"
218 ;;
219 *"Nanostation M")
220 name="nanostation-m"
221 ;;
222 *JWAP003)
223 name="jwap003"
224 ;;
225 *"Hornet-UB")
226 name="hornet-ub"
227 ;;
228 *LS-SR71)
229 name="ls-sr71"
230 ;;
231 *MR600)
232 name="mr600"
233 ;;
234 *MZK-W04NU)
235 name="mzk-w04nu"
236 ;;
237 *MZK-W300NH)
238 name="mzk-w300nh"
239 ;;
240 *"NBG460N/550N/550NH")
241 name="nbg460n_550n_550nh"
242 ;;
243 *OM2P)
244 name="om2p"
245 ;;
246 *"OM2P HS")
247 name="om2p-hs"
248 ;;
249 *"OM2P LC")
250 name="om2p-lc"
251 ;;
252 *PB42)
253 name="pb42"
254 ;;
255 *"PB44 reference board")
256 name="pb44"
257 ;;
258 *PB92)
259 name="pb92"
260 ;;
261 *"RouterBOARD 411/A/AH")
262 name="rb-411"
263 ;;
264 *"RouterBOARD 411U")
265 name="rb-411u"
266 ;;
267 *"RouterBOARD 433/AH")
268 name="rb-433"
269 ;;
270 *"RouterBOARD 433UAH")
271 name="rb-433u"
272 ;;
273 *"RouterBOARD 435G")
274 name="rb-435g"
275 ;;
276 *"RouterBOARD 450")
277 name="rb-450"
278 ;;
279 *"RouterBOARD 450G")
280 name="rb-450g"
281 ;;
282 *"RouterBOARD 493/AH")
283 name="rb-493"
284 ;;
285 *"RouterBOARD 493G")
286 name="rb-493g"
287 ;;
288 *"RouterBOARD 750")
289 name="rb-750"
290 ;;
291 *"RouterBOARD 750GL")
292 name="rb-750gl"
293 ;;
294 *"RouterBOARD 751")
295 name="rb-751"
296 ;;
297 *"RouterBOARD 751G")
298 name="rb-751g"
299 ;;
300 *"RouterBOARD 2011L")
301 name="rb-2011l"
302 ;;
303 *"RouterBOARD 2011UAS-2HnD")
304 name="rb-2011uas-2hnd"
305 ;;
306 *"Rocket M")
307 name="rocket-m"
308 ;;
309 *RouterStation)
310 name="routerstation"
311 ;;
312 *"RouterStation Pro")
313 name="routerstation-pro"
314 ;;
315 *RW2458N)
316 name="rw2458n"
317 ;;
318 *TEW-632BRP)
319 name="tew-632brp"
320 ;;
321 *TEW-673GRU)
322 name="tew-673gru"
323 ;;
324 *TEW-712BR)
325 name="tew-712br"
326 ;;
327 *"TL-WR1041N v2")
328 name="tl-wr1041n-v2"
329 ;;
330 *TL-WR1043ND)
331 name="tl-wr1043nd"
332 ;;
333 *TL-WR2543N*)
334 name="tl-wr2543n"
335 ;;
336 *"DIR-615 rev. C1")
337 name="dir-615-c1"
338 ;;
339 *TL-MR3020)
340 name="tl-mr3020"
341 ;;
342 *TL-MR3040)
343 name="tl-mr3040"
344 ;;
345 *TL-MR3220)
346 name="tl-mr3220"
347 ;;
348 *TL-MR3420)
349 name="tl-mr3420"
350 ;;
351 *TL-WA7510N)
352 name="tl-wa7510n"
353 ;;
354 *TL-WA901ND)
355 name="tl-wa901nd"
356 ;;
357 *"TL-WA901ND v2")
358 name="tl-wa901nd-v2"
359 ;;
360 *"TL-WDR3600/4300/4310")
361 name="tl-wdr4300"
362 ;;
363 *TL-WR741ND)
364 name="tl-wr741nd"
365 ;;
366 *"TL-WR741ND v4")
367 name="tl-wr741nd-v4"
368 ;;
369 *"TL-WR841N v1")
370 name="tl-wr841n-v1"
371 ;;
372 *"TL-WR841N/ND v7")
373 name="tl-wr841n-v7"
374 ;;
375 *"TL-WR841N/ND v8")
376 name="tl-wr841n-v8"
377 ;;
378 *TL-WR941ND)
379 name="tl-wr941nd"
380 ;;
381 *"TL-WR703N v1")
382 name="tl-wr703n"
383 ;;
384 *"TL-MR11U")
385 name="tl-mr11u"
386 ;;
387 *UniFi)
388 name="unifi"
389 ;;
390 *WHR-G301N)
391 name="whr-g301n"
392 ;;
393 *WHR-HP-GN)
394 name="whr-hp-gn"
395 ;;
396 *WLAE-AG300N)
397 name="wlae-ag300n"
398 ;;
399 *"UniFiAP Outdoor")
400 name="unifi-outdoor"
401 ;;
402 *WP543)
403 name="wp543"
404 ;;
405 *WPE72)
406 name="wpe72"
407 ;;
408 *"WNDR3700/WNDR3800/WNDRMAC")
409 wndr3700_board_detect "$machine"
410 ;;
411 *WNR2000)
412 name="wnr2000"
413 ;;
414 *WRT160NL)
415 name="wrt160nl"
416 ;;
417 *WRT400N)
418 name="wrt400n"
419 ;;
420 *WZR-HP-AG300H)
421 name="wzr-hp-ag300h"
422 ;;
423 *WZR-HP-G300NH)
424 name="wzr-hp-g300nh"
425 ;;
426 *WZR-HP-G450H)
427 name="wzr-hp-g450h"
428 ;;
429 *WZR-HP-G300NH2)
430 name="wzr-hp-g300nh2"
431 ;;
432 *WHR-HP-G300N)
433 name="whr-hp-g300n"
434 ;;
435 *ZCN-1523H-2)
436 name="zcn-1523h-2"
437 ;;
438 *ZCN-1523H-5)
439 name="zcn-1523h-5"
440 ;;
441 *EmbWir-Dorin)
442 name="ew-dorin"
443 ;;
444 *EmbWir-Dorin-Router)
445 name="ew-dorin-router"
446 ;;
447 esac
448
449 case "$machine" in
450 *TL-WR* | *TL-WA* | *TL-MR* | *TL-WD*)
451 tplink_board_detect "$machine"
452 ;;
453 esac
454
455 [ -z "$name" ] && name="unknown"
456
457 [ -z "$AR71XX_BOARD_NAME" ] && AR71XX_BOARD_NAME="$name"
458 [ -z "$AR71XX_MODEL" ] && AR71XX_MODEL="$machine"
459
460 [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/"
461
462 echo "$AR71XX_BOARD_NAME" > /tmp/sysinfo/board_name
463 echo "$AR71XX_MODEL" > /tmp/sysinfo/model
464 }
465
466 ar71xx_board_name() {
467 local name
468
469 [ -f /tmp/sysinfo/board_name ] && name=$(cat /tmp/sysinfo/board_name)
470 [ -z "$name" ] && name="unknown"
471
472 echo "$name"
473 }