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