ar71xx: add TP-LINK TL-MR10U
[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_get_mid() {
66 local part
67
68 part=$(find_mtd_part firmware)
69 [ -z "$part" ] && return 1
70
71 dd if=$part bs=4 count=1 skip=17 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
72 }
73
74 tplink_board_detect() {
75 local model="$1"
76 local hwid
77 local hwver
78
79 hwid=$(tplink_get_hwid)
80 mid=$(tplink_get_mid)
81 hwver=${hwid:6:2}
82 hwver="v${hwver#0}"
83
84 case "$hwid" in
85 "070300"*)
86 model="TP-Link TL-WR703N"
87 ;;
88 "072001"*)
89 model="TP-Link TL-WR720N"
90 ;;
91 "070100"*)
92 model="TP-Link TL-WA701N/ND"
93 ;;
94 "074000"*)
95 model="TP-Link TL-WR740N/ND"
96 ;;
97 "074100"*)
98 model="TP-Link TL-WR741N/ND"
99 ;;
100 "074300"*)
101 model="TP-Link TL-WR743N/ND"
102 ;;
103 "080100"*)
104 model="TP-Link TL-WA801N/ND"
105 ;;
106 "083000"*)
107 model="TP-Link TL-WA830RE"
108 ;;
109 "084100"*)
110 model="TP-Link TL-WR841N/ND"
111 ;;
112 "084200"*)
113 model="TP-Link TL-WR842N/ND"
114 ;;
115 "090100"*)
116 model="TP-Link TL-WA901N/ND"
117 ;;
118 "094100"*)
119 if [ "$hwid" == "09410002" -a "$mid" == "00420001" ]; then
120 model="Rosewill RNX-N360RT"
121 hwver=""
122 else
123 model="TP-Link TL-WR941N/ND"
124 fi
125 ;;
126 "104100"*)
127 model="TP-Link TL-WR1041N/ND"
128 ;;
129 "104300"*)
130 model="TP-Link TL-WR1043N/ND"
131 ;;
132 "254300"*)
133 model="TP-Link TL-WR2543N/ND"
134 ;;
135 "100101"*)
136 model="TP-Link TL-MR10U"
137 ;;
138 "110101"*)
139 model="TP-Link TL-MR11U"
140 ;;
141 "302000"*)
142 model="TP-Link TL-MR3020"
143 ;;
144 "304000"*)
145 model="TP-Link TL-MR3040"
146 ;;
147 "322000"*)
148 model="TP-Link TL-MR3220"
149 ;;
150 "342000"*)
151 model="TP-Link TL-MR3420"
152 ;;
153 "350000"*)
154 model="TP-Link TL-WDR3500"
155 ;;
156 "360000"*)
157 model="TP-Link TL-WDR3600"
158 ;;
159 "430000"*)
160 model="TP-Link TL-WDR4300"
161 ;;
162 "431000"*)
163 model="TP-Link TL-WDR4310"
164 ;;
165 *)
166 hwver=""
167 ;;
168 esac
169
170 AR71XX_MODEL="$model $hwver"
171 }
172
173 ar71xx_board_detect() {
174 local machine
175 local name
176
177 machine=$(awk 'BEGIN{FS="[ \t]+:[ \t]"} /machine/ {print $2}' /proc/cpuinfo)
178
179 case "$machine" in
180 *"AirRouter")
181 name="airrouter"
182 ;;
183 *"ALFA Network AP96")
184 name="alfa-ap96"
185 ;;
186 *"ALFA Network N2/N5")
187 name="alfa-nx"
188 ;;
189 *ALL0258N)
190 name="all0258n"
191 ;;
192 *ALL0305)
193 name="all0305"
194 ;;
195 *ALL0315N)
196 name="all0315n"
197 ;;
198 *AP113)
199 name="ap113"
200 ;;
201 *AP121)
202 name="ap121"
203 ;;
204 *AP121-MINI)
205 name="ap121-mini"
206 ;;
207 *"AP132 reference board")
208 name="ap132"
209 ;;
210 *"AP136-010 reference board")
211 name="ap136-010"
212 ;;
213 *"AP136-020 reference board")
214 name="ap136-020"
215 ;;
216 *"AP135-020 reference board")
217 name="ap135-020"
218 ;;
219 *AP81)
220 name="ap81"
221 ;;
222 *AP83)
223 name="ap83"
224 ;;
225 *"Atheros AP96")
226 name="ap96"
227 ;;
228 *AW-NR580)
229 name="aw-nr580"
230 ;;
231 *CAP4200AG)
232 name="cap4200ag"
233 ;;
234 *"DB120 reference board")
235 name="db120"
236 ;;
237 *"DIR-600 rev. A1")
238 name="dir-600-a1"
239 ;;
240 *"DIR-615 rev. E4")
241 name="dir-615-e4"
242 ;;
243 *"DIR-825 rev. B1")
244 name="dir-825-b1"
245 ;;
246 *"DIR-825 rev. C1")
247 name="dir-825-c1"
248 ;;
249 *"DIR-835 rev. A1")
250 name="dir-835-a1"
251 ;;
252 *EAP7660D)
253 name="eap7660d"
254 ;;
255 *JA76PF)
256 name="ja76pf"
257 ;;
258 *JA76PF2)
259 name="ja76pf2"
260 ;;
261 *"Bullet M")
262 name="bullet-m"
263 ;;
264 *"Nanostation M")
265 name="nanostation-m"
266 ;;
267 *JWAP003)
268 name="jwap003"
269 ;;
270 *"Hornet-UB")
271 name="hornet-ub"
272 ;;
273 *LS-SR71)
274 name="ls-sr71"
275 ;;
276 *MR600v2)
277 name="mr600v2"
278 ;;
279 *MR600)
280 name="mr600"
281 ;;
282 *MZK-W04NU)
283 name="mzk-w04nu"
284 ;;
285 *MZK-W300NH)
286 name="mzk-w300nh"
287 ;;
288 *"NBG460N/550N/550NH")
289 name="nbg460n_550n_550nh"
290 ;;
291 *OM2P)
292 name="om2p"
293 ;;
294 *"OM2P HS")
295 name="om2p-hs"
296 ;;
297 *"OM2P LC")
298 name="om2p-lc"
299 ;;
300 *PB42)
301 name="pb42"
302 ;;
303 *"PB44 reference board")
304 name="pb44"
305 ;;
306 *PB92)
307 name="pb92"
308 ;;
309 *"RouterBOARD 411/A/AH")
310 name="rb-411"
311 ;;
312 *"RouterBOARD 411U")
313 name="rb-411u"
314 ;;
315 *"RouterBOARD 433/AH")
316 name="rb-433"
317 ;;
318 *"RouterBOARD 433UAH")
319 name="rb-433u"
320 ;;
321 *"RouterBOARD 435G")
322 name="rb-435g"
323 ;;
324 *"RouterBOARD 450")
325 name="rb-450"
326 ;;
327 *"RouterBOARD 450G")
328 name="rb-450g"
329 ;;
330 *"RouterBOARD 493/AH")
331 name="rb-493"
332 ;;
333 *"RouterBOARD 493G")
334 name="rb-493g"
335 ;;
336 *"RouterBOARD 750")
337 name="rb-750"
338 ;;
339 *"RouterBOARD 750GL")
340 name="rb-750gl"
341 ;;
342 *"RouterBOARD 751")
343 name="rb-751"
344 ;;
345 *"RouterBOARD 751G")
346 name="rb-751g"
347 ;;
348 *"RouterBOARD 951G-2HnD")
349 name="rb-951g-2hnd"
350 ;;
351 *"RouterBOARD 2011L")
352 name="rb-2011l"
353 ;;
354 *"RouterBOARD 2011UAS-2HnD")
355 name="rb-2011uas-2hnd"
356 ;;
357 *"Rocket M")
358 name="rocket-m"
359 ;;
360 *RouterStation)
361 name="routerstation"
362 ;;
363 *"RouterStation Pro")
364 name="routerstation-pro"
365 ;;
366 *RW2458N)
367 name="rw2458n"
368 ;;
369 *TEW-632BRP)
370 name="tew-632brp"
371 ;;
372 *TEW-673GRU)
373 name="tew-673gru"
374 ;;
375 *TEW-712BR)
376 name="tew-712br"
377 ;;
378 *"TL-WR1041N v2")
379 name="tl-wr1041n-v2"
380 ;;
381 *TL-WR1043ND)
382 name="tl-wr1043nd"
383 ;;
384 *TL-WR2543N*)
385 name="tl-wr2543n"
386 ;;
387 *"DIR-615 rev. C1")
388 name="dir-615-c1"
389 ;;
390 *TL-MR3020)
391 name="tl-mr3020"
392 ;;
393 *TL-MR3040)
394 name="tl-mr3040"
395 ;;
396 *TL-MR3220)
397 name="tl-mr3220"
398 ;;
399 *"TL-MR3220 v2")
400 name="tl-mr3220-v2"
401 ;;
402 *TL-MR3420)
403 name="tl-mr3420"
404 ;;
405 *"TL-MR3420 v2")
406 name="tl-mr3420-v2"
407 ;;
408 *TL-WA7510N)
409 name="tl-wa7510n"
410 ;;
411 *TL-WA901ND)
412 name="tl-wa901nd"
413 ;;
414 *"TL-WA901ND v2")
415 name="tl-wa901nd-v2"
416 ;;
417 *"TL-WDR3500")
418 name="tl-wdr3500"
419 ;;
420 *"TL-WDR3600/4300/4310")
421 name="tl-wdr4300"
422 ;;
423 *TL-WR741ND)
424 name="tl-wr741nd"
425 ;;
426 *"TL-WR741ND v4")
427 name="tl-wr741nd-v4"
428 ;;
429 *"TL-WR841N v1")
430 name="tl-wr841n-v1"
431 ;;
432 *"TL-WR841N/ND v7")
433 name="tl-wr841n-v7"
434 ;;
435 *"TL-WR841N/ND v8")
436 name="tl-wr841n-v8"
437 ;;
438 *TL-WR941ND)
439 name="tl-wr941nd"
440 ;;
441 *"TL-WR703N v1")
442 name="tl-wr703n"
443 ;;
444 *"TL-WR720N v3")
445 name="tl-wr720n-v3"
446 ;;
447 *"TL-MR11U")
448 name="tl-mr11u"
449 ;;
450 *UniFi)
451 name="unifi"
452 ;;
453 *"UniFi AP Pro")
454 name="uap-pro"
455 ;;
456 *WHR-G301N)
457 name="whr-g301n"
458 ;;
459 *WHR-HP-GN)
460 name="whr-hp-gn"
461 ;;
462 *WLAE-AG300N)
463 name="wlae-ag300n"
464 ;;
465 *"UniFiAP Outdoor")
466 name="unifi-outdoor"
467 ;;
468 *WP543)
469 name="wp543"
470 ;;
471 *WPE72)
472 name="wpe72"
473 ;;
474 *WNDAP360)
475 name="wndap360"
476 ;;
477 *"WNDR3700/WNDR3800/WNDRMAC")
478 wndr3700_board_detect "$machine"
479 ;;
480 *"WNDR4300")
481 name="wndr4300"
482 ;;
483 *"WNR2000 V3")
484 name="wnr2000-v3"
485 ;;
486 *WNR2000)
487 name="wnr2000"
488 ;;
489 *WRT160NL)
490 name="wrt160nl"
491 ;;
492 *WRT400N)
493 name="wrt400n"
494 ;;
495 *"WZR-HP-AG300H/WZR-600DHP")
496 name="wzr-hp-ag300h"
497 ;;
498 *WZR-HP-G300NH)
499 name="wzr-hp-g300nh"
500 ;;
501 *WZR-HP-G450H)
502 name="wzr-hp-g450h"
503 ;;
504 *WZR-HP-G300NH2)
505 name="wzr-hp-g300nh2"
506 ;;
507 *WHR-HP-G300N)
508 name="whr-hp-g300n"
509 ;;
510 *ZCN-1523H-2)
511 name="zcn-1523h-2"
512 ;;
513 *ZCN-1523H-5)
514 name="zcn-1523h-5"
515 ;;
516 *EmbWir-Dorin)
517 name="ew-dorin"
518 ;;
519 *EmbWir-Dorin-Router)
520 name="ew-dorin-router"
521 ;;
522 esac
523
524 case "$machine" in
525 *TL-WR* | *TL-WA* | *TL-MR* | *TL-WD*)
526 tplink_board_detect "$machine"
527 ;;
528 esac
529
530 [ -z "$name" ] && name="unknown"
531
532 [ -z "$AR71XX_BOARD_NAME" ] && AR71XX_BOARD_NAME="$name"
533 [ -z "$AR71XX_MODEL" ] && AR71XX_MODEL="$machine"
534
535 [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/"
536
537 echo "$AR71XX_BOARD_NAME" > /tmp/sysinfo/board_name
538 echo "$AR71XX_MODEL" > /tmp/sysinfo/model
539 }
540
541 ar71xx_board_name() {
542 local name
543
544 [ -f /tmp/sysinfo/board_name ] && name=$(cat /tmp/sysinfo/board_name)
545 [ -z "$name" ] && name="unknown"
546
547 echo "$name"
548 }