a870396a0284feeef6f6d1a9c44fdbce91cefee2
[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 "934100"*)
215 model="NC-LINK SMART-300"
216 ;;
217 "c50000"*)
218 model="TP-Link Archer C5"
219 ;;
220 "750000"*|\
221 "c70000"*)
222 model="TP-Link Archer C7"
223 ;;
224 *)
225 hwver=""
226 ;;
227 esac
228
229 AR71XX_MODEL="$model $hwver"
230 }
231
232 tplink_pharos_get_model_string() {
233 local part
234 part=$(find_mtd_part 'product-info')
235 [ -z "$part" ] && return 1
236
237 # The returned string will end with \r\n, but we don't remove it here
238 # to simplify matching against it in the sysupgrade image check
239 dd if=$part bs=1 skip=4360 2>/dev/null | head -n 1
240 }
241
242 tplink_pharos_board_detect() {
243 local model_string="$(tplink_pharos_get_model_string | tr -d '\r')"
244 local oIFS="$IFS"; IFS=":"; set -- $model_string; IFS="$oIFS"
245 local model
246
247 case "$1" in
248 'CPE210(TP-LINK|UN|N300-2)')
249 model='TP-Link CPE210'
250 ;;
251 'CPE220(TP-LINK|UN|N300-2)')
252 model='TP-Link CPE220'
253 ;;
254 'CPE510(TP-LINK|UN|N300-5)')
255 model='TP-Link CPE510'
256 ;;
257 'CPE520(TP-LINK|UN|N300-5)')
258 model='TP-Link CPE520'
259 ;;
260 esac
261
262 [ -n "$model" ] && AR71XX_MODEL="$model v$2"
263 }
264
265 ar71xx_board_detect() {
266 local machine
267 local name
268
269 machine=$(awk 'BEGIN{FS="[ \t]+:[ \t]"} /machine/ {print $2}' /proc/cpuinfo)
270
271 case "$machine" in
272 *"Oolite V1.0")
273 name="oolite"
274 ;;
275 *"AC1750DB")
276 name="f9k1115v2"
277 ;;
278 *"AirGateway")
279 name="airgateway"
280 ;;
281 *"AirRouter")
282 name="airrouter"
283 ;;
284 *"ALFA Network AP96")
285 name="alfa-ap96"
286 ;;
287 *"ALFA Network N2/N5")
288 name="alfa-nx"
289 ;;
290 *ALL0258N)
291 name="all0258n"
292 ;;
293 *ALL0305)
294 name="all0305"
295 ;;
296 *ALL0315N)
297 name="all0315n"
298 ;;
299 *AP113)
300 name="ap113"
301 ;;
302 *AP121)
303 name="ap121"
304 ;;
305 *AP121-MINI)
306 name="ap121-mini"
307 ;;
308 *"AP132 reference board")
309 name="ap132"
310 ;;
311 *"AP136-010 reference board")
312 name="ap136-010"
313 ;;
314 *"AP136-020 reference board")
315 name="ap136-020"
316 ;;
317 *"AP135-020 reference board")
318 name="ap135-020"
319 ;;
320 *AP81)
321 name="ap81"
322 ;;
323 *AP83)
324 name="ap83"
325 ;;
326 *"Archer C5")
327 name="archer-c5"
328 ;;
329 *"Archer C7")
330 name="archer-c7"
331 ;;
332 *"Atheros AP96")
333 name="ap96"
334 ;;
335 *AW-NR580)
336 name="aw-nr580"
337 ;;
338 *CAP4200AG)
339 name="cap4200ag"
340 ;;
341 *"CPE210/220/510/520")
342 name="cpe510"
343 tplink_pharos_board_detect
344 ;;
345 *"DB120 reference board")
346 name="db120"
347 ;;
348 *"DGL-5500 rev. A1")
349 name="dgl-5500-a1"
350 ;;
351 *"DHP-1565 rev. A1")
352 name="dhp-1565-a1"
353 ;;
354 *"DIR-505 rev. A1")
355 name="dir-505-a1"
356 ;;
357 *"DIR-600 rev. A1")
358 name="dir-600-a1"
359 ;;
360 *"DIR-615 rev. E1")
361 name="dir-615-e1"
362 ;;
363 *"DIR-615 rev. E4")
364 name="dir-615-e4"
365 ;;
366 *"DIR-825 rev. B1")
367 name="dir-825-b1"
368 ;;
369 *"DIR-825 rev. C1")
370 name="dir-825-c1"
371 ;;
372 *"DIR-835 rev. A1")
373 name="dir-835-a1"
374 ;;
375 *"Dragino v2")
376 name="dragino2"
377 ;;
378 *"EAP300 v2")
379 name="eap300v2"
380 ;;
381 *EAP7660D)
382 name="eap7660d"
383 ;;
384 *EL-M150)
385 name="el-m150"
386 ;;
387 *EL-MINI)
388 name="el-mini"
389 ;;
390 *"GL-CONNECT INET v1")
391 name="gl-inet"
392 ;;
393 *"EnGenius ESR1750")
394 name="esr1750"
395 ;;
396 *"EnGenius ESR900")
397 name="esr900"
398 ;;
399 *JA76PF)
400 name="ja76pf"
401 ;;
402 *JA76PF2)
403 name="ja76pf2"
404 ;;
405 *"Bullet M")
406 name="bullet-m"
407 ;;
408 *"Loco M XW")
409 name="loco-m-xw"
410 ;;
411 *"Nanostation M")
412 name="nanostation-m"
413 ;;
414 *"Nanostation M XW")
415 name="nanostation-m-xw"
416 ;;
417 *JWAP003)
418 name="jwap003"
419 ;;
420 *"Hornet-UB")
421 local size
422 size=$(awk '/firmware/ { print $2 }' /proc/mtd)
423
424 if [ "x$size" = "x00790000" ]; then
425 name="hornet-ub"
426 fi
427
428 if [ "x$size" = "x00f90000" ]; then
429 name="hornet-ub-x2"
430 fi
431 ;;
432 *LS-SR71)
433 name="ls-sr71"
434 ;;
435 *MR600v2)
436 name="mr600v2"
437 ;;
438 *MR600)
439 name="mr600"
440 ;;
441 *MR900)
442 name="mr900"
443 ;;
444 *MR900v2)
445 name="mr900v2"
446 ;;
447 *"My Net N600")
448 name="mynet-n600"
449 ;;
450 *"My Net N750")
451 name="mynet-n750"
452 ;;
453 *"WD My Net Wi-Fi Range Extender")
454 name="mynet-rext"
455 ;;
456 *MZK-W04NU)
457 name="mzk-w04nu"
458 ;;
459 *MZK-W300NH)
460 name="mzk-w300nh"
461 ;;
462 *"NBG460N/550N/550NH")
463 name="nbg460n_550n_550nh"
464 ;;
465 *"Zyxel NBG6716")
466 name="nbg6716"
467 ;;
468 *OM2P)
469 name="om2p"
470 ;;
471 *OM2Pv2)
472 name="om2pv2"
473 ;;
474 *"OM2P HS")
475 name="om2p-hs"
476 ;;
477 *"OM2P HSv2")
478 name="om2p-hsv2"
479 ;;
480 *"OM2P LC")
481 name="om2p-lc"
482 ;;
483 *OM5P)
484 name="om5p"
485 ;;
486 *PB42)
487 name="pb42"
488 ;;
489 *"PB44 reference board")
490 name="pb44"
491 ;;
492 *PB92)
493 name="pb92"
494 ;;
495 *"Qihoo 360 C301")
496 name="qihoo-c301"
497 ;;
498 *"RouterBOARD 411/A/AH")
499 name="rb-411"
500 ;;
501 *"RouterBOARD 411U")
502 name="rb-411u"
503 ;;
504 *"RouterBOARD 433/AH")
505 name="rb-433"
506 ;;
507 *"RouterBOARD 433UAH")
508 name="rb-433u"
509 ;;
510 *"RouterBOARD 435G")
511 name="rb-435g"
512 ;;
513 *"RouterBOARD 450")
514 name="rb-450"
515 ;;
516 *"RouterBOARD 450G")
517 name="rb-450g"
518 ;;
519 *"RouterBOARD 493/AH")
520 name="rb-493"
521 ;;
522 *"RouterBOARD 493G")
523 name="rb-493g"
524 ;;
525 *"RouterBOARD 750")
526 name="rb-750"
527 ;;
528 *"RouterBOARD 750GL")
529 name="rb-750gl"
530 ;;
531 *"RouterBOARD 751")
532 name="rb-751"
533 ;;
534 *"RouterBOARD 751G")
535 name="rb-751g"
536 ;;
537 *"RouterBOARD 911G-2HPnD")
538 name="rb-911g-2hpnd"
539 ;;
540 *"RouterBOARD 911G-5HPnD")
541 name="rb-911g-5hpnd"
542 ;;
543 *"RouterBOARD 912UAG-2HPnD")
544 name="rb-912uag-2hpnd"
545 ;;
546 *"RouterBOARD 912UAG-5HPnD")
547 name="rb-912uag-5hpnd"
548 ;;
549 *"RouterBOARD 951G-2HnD")
550 name="rb-951g-2hnd"
551 ;;
552 *"RouterBOARD 951Ui-2HnD")
553 name="rb-951ui-2hnd"
554 ;;
555 *"RouterBOARD 2011L")
556 name="rb-2011l"
557 ;;
558 *"RouterBOARD 2011UAS")
559 name="rb-2011uas"
560 ;;
561 *"RouterBOARD 2011UiAS")
562 name="rb-2011uias"
563 ;;
564 *"RouterBOARD 2011UAS-2HnD")
565 name="rb-2011uas-2hnd"
566 ;;
567 *"RouterBOARD 2011UiAS-2HnD")
568 name="rb-2011uias-2hnd"
569 ;;
570 *"RouterBOARD SXT Lite2")
571 name="rb-sxt2n"
572 ;;
573 *"RouterBOARD SXT Lite5")
574 name="rb-sxt5n"
575 ;;
576 *"Rocket M")
577 name="rocket-m"
578 ;;
579 *RouterStation)
580 name="routerstation"
581 ;;
582 *"RouterStation Pro")
583 name="routerstation-pro"
584 ;;
585 *RW2458N)
586 name="rw2458n"
587 ;;
588 *"SMART-300")
589 name="smart-300"
590 ;;
591 *TEW-632BRP)
592 name="tew-632brp"
593 ;;
594 *TEW-673GRU)
595 name="tew-673gru"
596 ;;
597 *TEW-712BR)
598 name="tew-712br"
599 ;;
600 *TEW-732BR)
601 name="tew-732br"
602 ;;
603 *"TL-WR1041N v2")
604 name="tl-wr1041n-v2"
605 ;;
606 *TL-WR1043ND)
607 name="tl-wr1043nd"
608 ;;
609 *"TL-WR1043ND v2")
610 name="tl-wr1043nd-v2"
611 ;;
612 *TL-WR2543N*)
613 name="tl-wr2543n"
614 ;;
615 *"DIR-615 rev. C1")
616 name="dir-615-c1"
617 ;;
618 *TL-MR3020)
619 name="tl-mr3020"
620 ;;
621 *TL-MR3040)
622 name="tl-mr3040"
623 ;;
624 *"TL-MR3040 v2")
625 name="tl-mr3040-v2"
626 ;;
627 *TL-MR3220)
628 name="tl-mr3220"
629 ;;
630 *"TL-MR3220 v2")
631 name="tl-mr3220-v2"
632 ;;
633 *TL-MR3420)
634 name="tl-mr3420"
635 ;;
636 *"TL-MR3420 v2")
637 name="tl-mr3420-v2"
638 ;;
639 *"TL-WA701ND v2")
640 name="tl-wa701nd-v2"
641 ;;
642 *TL-WA750RE)
643 name="tl-wa750re"
644 ;;
645 *"TL-WA7510N v1")
646 name="tl-wa7510n"
647 ;;
648 *TL-WA850RE)
649 name="tl-wa850re"
650 ;;
651 *TL-WA860RE)
652 name="tl-wa860re"
653 ;;
654 *"TL-WA830RE v2")
655 name="tl-wa830re-v2"
656 ;;
657 *"TL-WA801ND v2")
658 name="tl-wa801nd-v2"
659 ;;
660 *TL-WA901ND)
661 name="tl-wa901nd"
662 ;;
663 *"TL-WA901ND v2")
664 name="tl-wa901nd-v2"
665 ;;
666 *"TL-WA901ND v3")
667 name="tl-wa901nd-v3"
668 ;;
669 *"TL-WDR3500")
670 name="tl-wdr3500"
671 ;;
672 *"TL-WDR3600/4300/4310")
673 name="tl-wdr4300"
674 ;;
675 *"TL-WDR4900 v2")
676 name="tl-wdr4900-v2"
677 ;;
678 *TL-WR741ND)
679 name="tl-wr741nd"
680 ;;
681 *"TL-WR741ND v4")
682 name="tl-wr741nd-v4"
683 ;;
684 *"TL-WR841N v1")
685 name="tl-wr841n-v1"
686 ;;
687 *"TL-WR841N/ND v7")
688 name="tl-wr841n-v7"
689 ;;
690 *"TL-WR841N/ND v8")
691 name="tl-wr841n-v8"
692 ;;
693 *"TL-WR841N/ND v9")
694 name="tl-wr841n-v9"
695 ;;
696 *"TL-WR842N/ND v2")
697 name="tl-wr842n-v2"
698 ;;
699 *TL-WR941ND)
700 name="tl-wr941nd"
701 ;;
702 *"TL-WR703N v1")
703 name="tl-wr703n"
704 ;;
705 *"TL-WR710N v1")
706 name="tl-wr710n"
707 ;;
708 *"TL-WR720N v3")
709 name="tl-wr720n-v3"
710 ;;
711 *"TL-MR10U")
712 name="tl-mr10u"
713 ;;
714 *"TL-MR11U")
715 name="tl-mr11u"
716 ;;
717 *"TL-MR13U")
718 name="tl-mr13u"
719 ;;
720 *"Tube2H")
721 name="tube2h"
722 ;;
723 *UniFi)
724 name="unifi"
725 ;;
726 *"UniFi AP Pro")
727 name="uap-pro"
728 ;;
729 *WHR-G301N)
730 name="whr-g301n"
731 ;;
732 *WHR-HP-GN)
733 name="whr-hp-gn"
734 ;;
735 *WLAE-AG300N)
736 name="wlae-ag300n"
737 ;;
738 *"UniFiAP Outdoor")
739 name="unifi-outdoor"
740 ;;
741 *"UniFiAP Outdoor+")
742 name="unifi-outdoor-plus"
743 ;;
744 *WP543)
745 name="wp543"
746 ;;
747 *WPE72)
748 name="wpe72"
749 ;;
750 *WNDAP360)
751 name="wndap360"
752 ;;
753 *"WNDR3700/WNDR3800/WNDRMAC")
754 wndr3700_board_detect "$machine"
755 ;;
756 *"R6100")
757 name="r6100"
758 ;;
759 *"WNDR3700v4")
760 name="wndr3700v4"
761 ;;
762 *"WNDR4300")
763 name="wndr4300"
764 ;;
765 *"WNR2000 V4")
766 name="wnr2000-v4"
767 ;;
768 *"WNR2000 V3")
769 name="wnr2000-v3"
770 ;;
771 *WNR2000)
772 name="wnr2000"
773 ;;
774 *WNR2200)
775 name="wnr2200"
776 ;;
777 *"WNR612 V2")
778 name="wnr612-v2"
779 ;;
780 *WRT160NL)
781 name="wrt160nl"
782 ;;
783 *WRT400N)
784 name="wrt400n"
785 ;;
786 *"WZR-450HP2")
787 name="wzr-450hp2"
788 ;;
789 *"WZR-HP-AG300H/WZR-600DHP")
790 name="wzr-hp-ag300h"
791 ;;
792 *WZR-HP-G300NH)
793 name="wzr-hp-g300nh"
794 ;;
795 *WZR-HP-G450H)
796 name="wzr-hp-g450h"
797 ;;
798 *WZR-HP-G300NH2)
799 name="wzr-hp-g300nh2"
800 ;;
801 *WHR-HP-G300N)
802 name="whr-hp-g300n"
803 ;;
804 *ZCN-1523H-2)
805 name="zcn-1523h-2"
806 ;;
807 *ZCN-1523H-5)
808 name="zcn-1523h-5"
809 ;;
810 *EmbWir-Dorin)
811 name="ew-dorin"
812 ;;
813 *EmbWir-Dorin-Router)
814 name="ew-dorin-router"
815 ;;
816 "8devices Carambola2"*)
817 name="carambola2"
818 ;;
819 *"Sitecom WLR-8100")
820 name="wlr8100"
821 ;;
822 *"BHU BXU2000n-2 rev. A1")
823 name="bxu2000n-2-a1"
824 ;;
825 *"HiWiFi HC6361")
826 name="hiwifi-hc6361"
827 ;;
828 esac
829
830 [ -z "$AR71XX_MODEL" ] && [ "${machine:0:8}" = 'TP-LINK ' ] && \
831 tplink_board_detect "$machine"
832
833 [ -z "$name" ] && name="unknown"
834
835 [ -z "$AR71XX_BOARD_NAME" ] && AR71XX_BOARD_NAME="$name"
836 [ -z "$AR71XX_MODEL" ] && AR71XX_MODEL="$machine"
837
838 [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/"
839
840 echo "$AR71XX_BOARD_NAME" > /tmp/sysinfo/board_name
841 echo "$AR71XX_MODEL" > /tmp/sysinfo/model
842 }
843
844 ar71xx_board_name() {
845 local name
846
847 [ -f /tmp/sysinfo/board_name ] && name=$(cat /tmp/sysinfo/board_name)
848 [ -z "$name" ] && name="unknown"
849
850 echo "$name"
851 }