2d75954db59a92c84348bb6f72e79f26d50013b1
[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 cybertan_get_hw_magic() {
57 local part
58
59 part=$(find_mtd_part firmware)
60 [ -z "$part" ] && return 1
61
62 dd bs=8 count=1 skip=0 if=$part 2>/dev/null | hexdump -v -n 8 -e '1/1 "%02x"'
63 }
64
65 tplink_get_hwid() {
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=16 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
72 }
73
74 tplink_get_mid() {
75 local part
76
77 part=$(find_mtd_part firmware)
78 [ -z "$part" ] && return 1
79
80 dd if=$part bs=4 count=1 skip=17 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
81 }
82
83 tplink_board_detect() {
84 local model="$1"
85 local hwid
86 local hwver
87
88 hwid=$(tplink_get_hwid)
89 mid=$(tplink_get_mid)
90 hwver=${hwid:6:2}
91 hwver="v${hwver#0}"
92
93 case "$hwid" in
94 "015000"*)
95 model="EasyLink EL-M150"
96 ;;
97 "015300"*)
98 model="EasyLink EL-MINI"
99 ;;
100 "3C0001"*)
101 model="OOLITE"
102 ;;
103 "070300"*)
104 model="TP-Link TL-WR703N"
105 ;;
106 "071000"*)
107 model="TP-Link TL-WR710N"
108 ;;
109 "072001"*)
110 model="TP-Link TL-WR720N"
111 ;;
112 "070100"*)
113 model="TP-Link TL-WA701N/ND"
114 ;;
115 "073000"*)
116 model="TP-Link TL-WA730RE"
117 ;;
118 "074000"*)
119 model="TP-Link TL-WR740N/ND"
120 ;;
121 "074100"*)
122 model="TP-Link TL-WR741N/ND"
123 ;;
124 "074300"*)
125 model="TP-Link TL-WR743N/ND"
126 ;;
127 "075000"*)
128 model="TP-Link TL-WA750RE"
129 ;;
130 "751000"*)
131 model="TP-Link TL-WA7510N"
132 ;;
133 "080100"*)
134 model="TP-Link TL-WA801N/ND"
135 ;;
136 "083000"*)
137 model="TP-Link TL-WA830RE"
138 ;;
139 "084100"*)
140 model="TP-Link TL-WR841N/ND"
141 ;;
142 "084200"*)
143 model="TP-Link TL-WR842N/ND"
144 ;;
145 "085000"*)
146 model="TP-Link TL-WA850RE"
147 ;;
148 "086000"*)
149 model="TP-Link TL-WA860RE"
150 ;;
151 "090100"*)
152 model="TP-Link TL-WA901N/ND"
153 ;;
154 "094100"*)
155 if [ "$hwid" == "09410002" -a "$mid" == "00420001" ]; then
156 model="Rosewill RNX-N360RT"
157 hwver=""
158 else
159 model="TP-Link TL-WR941N/ND"
160 fi
161 ;;
162 "104100"*)
163 model="TP-Link TL-WR1041N/ND"
164 ;;
165 "104300"*)
166 model="TP-Link TL-WR1043N/ND"
167 ;;
168 "254300"*)
169 model="TP-Link TL-WR2543N/ND"
170 ;;
171 "001001"*)
172 model="TP-Link TL-MR10U"
173 ;;
174 "001101"*)
175 model="TP-Link TL-MR11U"
176 ;;
177 "001301"*)
178 model="TP-Link TL-MR13U"
179 ;;
180 "302000"*)
181 model="TP-Link TL-MR3020"
182 ;;
183 "304000"*)
184 model="TP-Link TL-MR3040"
185 ;;
186 "322000"*)
187 model="TP-Link TL-MR3220"
188 ;;
189 "342000"*)
190 model="TP-Link TL-MR3420"
191 ;;
192 "350000"*)
193 model="TP-Link TL-WDR3500"
194 ;;
195 "360000"*)
196 model="TP-Link TL-WDR3600"
197 ;;
198 "430000"*)
199 model="TP-Link TL-WDR4300"
200 ;;
201 "430080"*)
202 iw reg set IL
203 model="TP-Link TL-WDR4300 (IL)"
204 ;;
205 "431000"*)
206 model="TP-Link TL-WDR4310"
207 ;;
208 "49000002")
209 model="TP-Link TL-WDR4900"
210 ;;
211 "453000"*)
212 model="MERCURY MW4530R"
213 ;;
214 *)
215 hwver=""
216 ;;
217 esac
218
219 AR71XX_MODEL="$model $hwver"
220 }
221
222 ar71xx_board_detect() {
223 local machine
224 local name
225
226 machine=$(awk 'BEGIN{FS="[ \t]+:[ \t]"} /machine/ {print $2}' /proc/cpuinfo)
227
228 case "$machine" in
229 *"Oolite V1.0")
230 name="oolite"
231 ;;
232 *"AirRouter")
233 name="airrouter"
234 ;;
235 *"ALFA Network AP96")
236 name="alfa-ap96"
237 ;;
238 *"ALFA Network N2/N5")
239 name="alfa-nx"
240 ;;
241 *ALL0258N)
242 name="all0258n"
243 ;;
244 *ALL0305)
245 name="all0305"
246 ;;
247 *ALL0315N)
248 name="all0315n"
249 ;;
250 *AP113)
251 name="ap113"
252 ;;
253 *AP121)
254 name="ap121"
255 ;;
256 *AP121-MINI)
257 name="ap121-mini"
258 ;;
259 *"AP132 reference board")
260 name="ap132"
261 ;;
262 *"AP136-010 reference board")
263 name="ap136-010"
264 ;;
265 *"AP136-020 reference board")
266 name="ap136-020"
267 ;;
268 *"AP135-020 reference board")
269 name="ap135-020"
270 ;;
271 *AP81)
272 name="ap81"
273 ;;
274 *AP83)
275 name="ap83"
276 ;;
277 *"Archer C7")
278 name="archer-c7"
279 ;;
280 *"Atheros AP96")
281 name="ap96"
282 ;;
283 *AW-NR580)
284 name="aw-nr580"
285 ;;
286 *CAP4200AG)
287 name="cap4200ag"
288 ;;
289 *"DB120 reference board")
290 name="db120"
291 ;;
292 *"DIR-505 rev. A1")
293 name="dir-505-a1"
294 ;;
295 *"DIR-600 rev. A1")
296 name="dir-600-a1"
297 ;;
298 *"DIR-615 rev. E1")
299 name="dir-615-e1"
300 ;;
301 *"DIR-615 rev. E4")
302 name="dir-615-e4"
303 ;;
304 *"DIR-825 rev. B1")
305 name="dir-825-b1"
306 ;;
307 *"DIR-825 rev. C1")
308 name="dir-825-c1"
309 ;;
310 *"DIR-835 rev. A1")
311 name="dir-835-a1"
312 ;;
313 *"Dragino v2")
314 name="dragino2"
315 ;;
316 *EAP7660D)
317 name="eap7660d"
318 ;;
319 *EL-M150)
320 name="el-m150"
321 ;;
322 *EL-MINI)
323 name="el-mini"
324 ;;
325 *JA76PF)
326 name="ja76pf"
327 ;;
328 *JA76PF2)
329 name="ja76pf2"
330 ;;
331 *"Bullet M")
332 name="bullet-m"
333 ;;
334 *"Nanostation M")
335 name="nanostation-m"
336 ;;
337 *JWAP003)
338 name="jwap003"
339 ;;
340 *"Hornet-UB")
341 local size
342 size=$(awk '/firmware/ { print $2 }' /proc/mtd)
343
344 if [ "x$size" = "x00790000" ]; then
345 name="hornet-ub"
346 fi
347
348 if [ "x$size" = "x00f90000" ]; then
349 name="hornet-ub-x2"
350 fi
351 ;;
352 *LS-SR71)
353 name="ls-sr71"
354 ;;
355 *MR600v2)
356 name="mr600v2"
357 ;;
358 *MR600)
359 name="mr600"
360 ;;
361 *"My Net N600")
362 name="mynet-n600"
363 ;;
364 *"My Net N750")
365 name="mynet-n750"
366 ;;
367 *"WD My Net Wi-Fi Range Extender")
368 name="mynet-rext"
369 ;;
370 *MZK-W04NU)
371 name="mzk-w04nu"
372 ;;
373 *MZK-W300NH)
374 name="mzk-w300nh"
375 ;;
376 *"NBG460N/550N/550NH")
377 name="nbg460n_550n_550nh"
378 ;;
379 *"Zyxel NBG6716")
380 name="nbg6716"
381 ;;
382 *OM2P)
383 name="om2p"
384 ;;
385 *OM2Pv2)
386 name="om2pv2"
387 ;;
388 *"OM2P HS")
389 name="om2p-hs"
390 ;;
391 *"OM2P HSv2")
392 name="om2p-hsv2"
393 ;;
394 *"OM2P LC")
395 name="om2p-lc"
396 ;;
397 *PB42)
398 name="pb42"
399 ;;
400 *"PB44 reference board")
401 name="pb44"
402 ;;
403 *PB92)
404 name="pb92"
405 ;;
406 *"RouterBOARD 411/A/AH")
407 name="rb-411"
408 ;;
409 *"RouterBOARD 411U")
410 name="rb-411u"
411 ;;
412 *"RouterBOARD 433/AH")
413 name="rb-433"
414 ;;
415 *"RouterBOARD 433UAH")
416 name="rb-433u"
417 ;;
418 *"RouterBOARD 435G")
419 name="rb-435g"
420 ;;
421 *"RouterBOARD 450")
422 name="rb-450"
423 ;;
424 *"RouterBOARD 450G")
425 name="rb-450g"
426 ;;
427 *"RouterBOARD 493/AH")
428 name="rb-493"
429 ;;
430 *"RouterBOARD 493G")
431 name="rb-493g"
432 ;;
433 *"RouterBOARD 750")
434 name="rb-750"
435 ;;
436 *"RouterBOARD 750GL")
437 name="rb-750gl"
438 ;;
439 *"RouterBOARD 751")
440 name="rb-751"
441 ;;
442 *"RouterBOARD 751G")
443 name="rb-751g"
444 ;;
445 *"RouterBOARD 911G-2HPnD")
446 name="rb-911g-2hpnd"
447 ;;
448 *"RouterBOARD 911G-5HPnD")
449 name="rb-911g-5hpnd"
450 ;;
451 *"RouterBOARD 912UAG-2HPnD")
452 name="rb-912uag-2hpnd"
453 ;;
454 *"RouterBOARD 912UAG-5HPnD")
455 name="rb-912uag-5hpnd"
456 ;;
457 *"RouterBOARD 951G-2HnD")
458 name="rb-951g-2hnd"
459 ;;
460 *"RouterBOARD 951Ui-2HnD")
461 name="rb-951ui-2hnd"
462 ;;
463 *"RouterBOARD 2011L")
464 name="rb-2011l"
465 ;;
466 *"RouterBOARD 2011UAS")
467 name="rb-2011uas"
468 ;;
469 *"RouterBOARD 2011UiAS")
470 name="rb-2011uias"
471 ;;
472 *"RouterBOARD 2011UAS-2HnD")
473 name="rb-2011uas-2hnd"
474 ;;
475 *"RouterBOARD SXT Lite2")
476 name="rb-sxt2n"
477 ;;
478 *"RouterBOARD SXT Lite5")
479 name="rb-sxt5n"
480 ;;
481 *"Rocket M")
482 name="rocket-m"
483 ;;
484 *RouterStation)
485 name="routerstation"
486 ;;
487 *"RouterStation Pro")
488 name="routerstation-pro"
489 ;;
490 *RW2458N)
491 name="rw2458n"
492 ;;
493 *TEW-632BRP)
494 name="tew-632brp"
495 ;;
496 *TEW-673GRU)
497 name="tew-673gru"
498 ;;
499 *TEW-712BR)
500 name="tew-712br"
501 ;;
502 *TEW-732BR)
503 name="tew-732br"
504 ;;
505 *"TL-WR1041N v2")
506 name="tl-wr1041n-v2"
507 ;;
508 *TL-WR1043ND)
509 name="tl-wr1043nd"
510 ;;
511 *"TL-WR1043ND v2")
512 name="tl-wr1043nd-v2"
513 ;;
514 *TL-WR2543N*)
515 name="tl-wr2543n"
516 ;;
517 *"DIR-615 rev. C1")
518 name="dir-615-c1"
519 ;;
520 *TL-MR3020)
521 name="tl-mr3020"
522 ;;
523 *TL-MR3040)
524 name="tl-mr3040"
525 ;;
526 *"TL-MR3040 v2")
527 name="tl-mr3040-v2"
528 ;;
529 *TL-MR3220)
530 name="tl-mr3220"
531 ;;
532 *"TL-MR3220 v2")
533 name="tl-mr3220-v2"
534 ;;
535 *TL-MR3420)
536 name="tl-mr3420"
537 ;;
538 *"TL-MR3420 v2")
539 name="tl-mr3420-v2"
540 ;;
541 *TL-WA750RE)
542 name="tl-wa750re"
543 ;;
544 *"TL-WA7510N v1")
545 name="tl-wa7510n"
546 ;;
547 *TL-WA850RE)
548 name="tl-wa850re"
549 ;;
550 *"TL-WA830RE v2")
551 name="tl-wa830re-v2"
552 ;;
553 *"TL-WA801ND v2")
554 name="tl-wa801nd-v2"
555 ;;
556 *TL-WA901ND)
557 name="tl-wa901nd"
558 ;;
559 *"TL-WA901ND v2")
560 name="tl-wa901nd-v2"
561 ;;
562 *"TL-WA901ND v3")
563 name="tl-wa901nd-v3"
564 ;;
565 *"TL-WDR3500")
566 name="tl-wdr3500"
567 ;;
568 *"TL-WDR3600/4300/4310")
569 name="tl-wdr4300"
570 ;;
571 *"TL-WDR4900 v2")
572 name="tl-wdr4900-v2"
573 ;;
574 *TL-WR741ND)
575 name="tl-wr741nd"
576 ;;
577 *"TL-WR741ND v4")
578 name="tl-wr741nd-v4"
579 ;;
580 *"TL-WR841N v1")
581 name="tl-wr841n-v1"
582 ;;
583 *"TL-WR841N/ND v7")
584 name="tl-wr841n-v7"
585 ;;
586 *"TL-WR841N/ND v8")
587 name="tl-wr841n-v8"
588 ;;
589 *"TL-WR841N/ND v9")
590 name="tl-wr841n-v9"
591 ;;
592 *"TL-WR842N/ND v2")
593 name="tl-wr842n-v2"
594 ;;
595 *TL-WR941ND)
596 name="tl-wr941nd"
597 ;;
598 *"TL-WR703N v1")
599 name="tl-wr703n"
600 ;;
601 *"TL-WR710N v1")
602 name="tl-wr710n"
603 ;;
604 *"TL-WR720N v3")
605 name="tl-wr720n-v3"
606 ;;
607 *"TL-MR10U")
608 name="tl-mr10u"
609 ;;
610 *"TL-MR11U")
611 name="tl-mr11u"
612 ;;
613 *"TL-MR13U")
614 name="tl-mr13u"
615 ;;
616 *UniFi)
617 name="unifi"
618 ;;
619 *"UniFi AP Pro")
620 name="uap-pro"
621 ;;
622 *WHR-G301N)
623 name="whr-g301n"
624 ;;
625 *WHR-HP-GN)
626 name="whr-hp-gn"
627 ;;
628 *WLAE-AG300N)
629 name="wlae-ag300n"
630 ;;
631 *"UniFiAP Outdoor")
632 name="unifi-outdoor"
633 ;;
634 *WP543)
635 name="wp543"
636 ;;
637 *WPE72)
638 name="wpe72"
639 ;;
640 *WNDAP360)
641 name="wndap360"
642 ;;
643 *"WNDR3700/WNDR3800/WNDRMAC")
644 wndr3700_board_detect "$machine"
645 ;;
646 *"WNDR4300")
647 name="wndr4300"
648 ;;
649 *"WNR2000 V3")
650 name="wnr2000-v3"
651 ;;
652 *WNR2000)
653 name="wnr2000"
654 ;;
655 *WNR2200)
656 name="wnr2200"
657 ;;
658 *"WNR612 V2")
659 name="wnr612-v2"
660 ;;
661 *WRT160NL)
662 name="wrt160nl"
663 ;;
664 *WRT400N)
665 name="wrt400n"
666 ;;
667 *"WZR-HP-AG300H/WZR-600DHP")
668 name="wzr-hp-ag300h"
669 ;;
670 *WZR-HP-G300NH)
671 name="wzr-hp-g300nh"
672 ;;
673 *WZR-HP-G450H)
674 name="wzr-hp-g450h"
675 ;;
676 *WZR-HP-G300NH2)
677 name="wzr-hp-g300nh2"
678 ;;
679 *WHR-HP-G300N)
680 name="whr-hp-g300n"
681 ;;
682 *ZCN-1523H-2)
683 name="zcn-1523h-2"
684 ;;
685 *ZCN-1523H-5)
686 name="zcn-1523h-5"
687 ;;
688 *EmbWir-Dorin)
689 name="ew-dorin"
690 ;;
691 *EmbWir-Dorin-Router)
692 name="ew-dorin-router"
693 ;;
694 "8devices Carambola2"*)
695 name="carambola2"
696 ;;
697 *"Sitecom WLR-8100")
698 name="wlr8100"
699 ;;
700 *"BHU BXU2000n-2 rev. A1")
701 name="bxu2000n-2-a1"
702 ;;
703 *"HiWiFi HC6361")
704 name="hiwifi-hc6361"
705 ;;
706 esac
707
708 case "$machine" in
709 *TL-WR* | *TL-WA* | *TL-MR* | *TL-WD*)
710 tplink_board_detect "$machine"
711 ;;
712 esac
713
714 [ -z "$name" ] && name="unknown"
715
716 [ -z "$AR71XX_BOARD_NAME" ] && AR71XX_BOARD_NAME="$name"
717 [ -z "$AR71XX_MODEL" ] && AR71XX_MODEL="$machine"
718
719 [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/"
720
721 echo "$AR71XX_BOARD_NAME" > /tmp/sysinfo/board_name
722 echo "$AR71XX_MODEL" > /tmp/sysinfo/model
723 }
724
725 ar71xx_board_name() {
726 local name
727
728 [ -f /tmp/sysinfo/board_name ] && name=$(cat /tmp/sysinfo/board_name)
729 [ -z "$name" ] && name="unknown"
730
731 echo "$name"
732 }