ar71xx: add user-space support for GL.iNet v1
[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 *"GL-CONNECT INET v1")
326 name="gl-inet"
327 ;;
328 *JA76PF)
329 name="ja76pf"
330 ;;
331 *JA76PF2)
332 name="ja76pf2"
333 ;;
334 *"Bullet M")
335 name="bullet-m"
336 ;;
337 *"Nanostation M")
338 name="nanostation-m"
339 ;;
340 *JWAP003)
341 name="jwap003"
342 ;;
343 *"Hornet-UB")
344 local size
345 size=$(awk '/firmware/ { print $2 }' /proc/mtd)
346
347 if [ "x$size" = "x00790000" ]; then
348 name="hornet-ub"
349 fi
350
351 if [ "x$size" = "x00f90000" ]; then
352 name="hornet-ub-x2"
353 fi
354 ;;
355 *LS-SR71)
356 name="ls-sr71"
357 ;;
358 *MR600v2)
359 name="mr600v2"
360 ;;
361 *MR600)
362 name="mr600"
363 ;;
364 *"My Net N600")
365 name="mynet-n600"
366 ;;
367 *"My Net N750")
368 name="mynet-n750"
369 ;;
370 *"WD My Net Wi-Fi Range Extender")
371 name="mynet-rext"
372 ;;
373 *MZK-W04NU)
374 name="mzk-w04nu"
375 ;;
376 *MZK-W300NH)
377 name="mzk-w300nh"
378 ;;
379 *"NBG460N/550N/550NH")
380 name="nbg460n_550n_550nh"
381 ;;
382 *"Zyxel NBG6716")
383 name="nbg6716"
384 ;;
385 *OM2P)
386 name="om2p"
387 ;;
388 *OM2Pv2)
389 name="om2pv2"
390 ;;
391 *"OM2P HS")
392 name="om2p-hs"
393 ;;
394 *"OM2P HSv2")
395 name="om2p-hsv2"
396 ;;
397 *"OM2P LC")
398 name="om2p-lc"
399 ;;
400 *PB42)
401 name="pb42"
402 ;;
403 *"PB44 reference board")
404 name="pb44"
405 ;;
406 *PB92)
407 name="pb92"
408 ;;
409 *"RouterBOARD 411/A/AH")
410 name="rb-411"
411 ;;
412 *"RouterBOARD 411U")
413 name="rb-411u"
414 ;;
415 *"RouterBOARD 433/AH")
416 name="rb-433"
417 ;;
418 *"RouterBOARD 433UAH")
419 name="rb-433u"
420 ;;
421 *"RouterBOARD 435G")
422 name="rb-435g"
423 ;;
424 *"RouterBOARD 450")
425 name="rb-450"
426 ;;
427 *"RouterBOARD 450G")
428 name="rb-450g"
429 ;;
430 *"RouterBOARD 493/AH")
431 name="rb-493"
432 ;;
433 *"RouterBOARD 493G")
434 name="rb-493g"
435 ;;
436 *"RouterBOARD 750")
437 name="rb-750"
438 ;;
439 *"RouterBOARD 750GL")
440 name="rb-750gl"
441 ;;
442 *"RouterBOARD 751")
443 name="rb-751"
444 ;;
445 *"RouterBOARD 751G")
446 name="rb-751g"
447 ;;
448 *"RouterBOARD 911G-2HPnD")
449 name="rb-911g-2hpnd"
450 ;;
451 *"RouterBOARD 911G-5HPnD")
452 name="rb-911g-5hpnd"
453 ;;
454 *"RouterBOARD 912UAG-2HPnD")
455 name="rb-912uag-2hpnd"
456 ;;
457 *"RouterBOARD 912UAG-5HPnD")
458 name="rb-912uag-5hpnd"
459 ;;
460 *"RouterBOARD 951G-2HnD")
461 name="rb-951g-2hnd"
462 ;;
463 *"RouterBOARD 951Ui-2HnD")
464 name="rb-951ui-2hnd"
465 ;;
466 *"RouterBOARD 2011L")
467 name="rb-2011l"
468 ;;
469 *"RouterBOARD 2011UAS")
470 name="rb-2011uas"
471 ;;
472 *"RouterBOARD 2011UiAS")
473 name="rb-2011uias"
474 ;;
475 *"RouterBOARD 2011UAS-2HnD")
476 name="rb-2011uas-2hnd"
477 ;;
478 *"RouterBOARD SXT Lite2")
479 name="rb-sxt2n"
480 ;;
481 *"RouterBOARD SXT Lite5")
482 name="rb-sxt5n"
483 ;;
484 *"Rocket M")
485 name="rocket-m"
486 ;;
487 *RouterStation)
488 name="routerstation"
489 ;;
490 *"RouterStation Pro")
491 name="routerstation-pro"
492 ;;
493 *RW2458N)
494 name="rw2458n"
495 ;;
496 *TEW-632BRP)
497 name="tew-632brp"
498 ;;
499 *TEW-673GRU)
500 name="tew-673gru"
501 ;;
502 *TEW-712BR)
503 name="tew-712br"
504 ;;
505 *TEW-732BR)
506 name="tew-732br"
507 ;;
508 *"TL-WR1041N v2")
509 name="tl-wr1041n-v2"
510 ;;
511 *TL-WR1043ND)
512 name="tl-wr1043nd"
513 ;;
514 *"TL-WR1043ND v2")
515 name="tl-wr1043nd-v2"
516 ;;
517 *TL-WR2543N*)
518 name="tl-wr2543n"
519 ;;
520 *"DIR-615 rev. C1")
521 name="dir-615-c1"
522 ;;
523 *TL-MR3020)
524 name="tl-mr3020"
525 ;;
526 *TL-MR3040)
527 name="tl-mr3040"
528 ;;
529 *"TL-MR3040 v2")
530 name="tl-mr3040-v2"
531 ;;
532 *TL-MR3220)
533 name="tl-mr3220"
534 ;;
535 *"TL-MR3220 v2")
536 name="tl-mr3220-v2"
537 ;;
538 *TL-MR3420)
539 name="tl-mr3420"
540 ;;
541 *"TL-MR3420 v2")
542 name="tl-mr3420-v2"
543 ;;
544 *TL-WA750RE)
545 name="tl-wa750re"
546 ;;
547 *"TL-WA7510N v1")
548 name="tl-wa7510n"
549 ;;
550 *TL-WA850RE)
551 name="tl-wa850re"
552 ;;
553 *"TL-WA830RE v2")
554 name="tl-wa830re-v2"
555 ;;
556 *"TL-WA801ND v2")
557 name="tl-wa801nd-v2"
558 ;;
559 *TL-WA901ND)
560 name="tl-wa901nd"
561 ;;
562 *"TL-WA901ND v2")
563 name="tl-wa901nd-v2"
564 ;;
565 *"TL-WA901ND v3")
566 name="tl-wa901nd-v3"
567 ;;
568 *"TL-WDR3500")
569 name="tl-wdr3500"
570 ;;
571 *"TL-WDR3600/4300/4310")
572 name="tl-wdr4300"
573 ;;
574 *"TL-WDR4900 v2")
575 name="tl-wdr4900-v2"
576 ;;
577 *TL-WR741ND)
578 name="tl-wr741nd"
579 ;;
580 *"TL-WR741ND v4")
581 name="tl-wr741nd-v4"
582 ;;
583 *"TL-WR841N v1")
584 name="tl-wr841n-v1"
585 ;;
586 *"TL-WR841N/ND v7")
587 name="tl-wr841n-v7"
588 ;;
589 *"TL-WR841N/ND v8")
590 name="tl-wr841n-v8"
591 ;;
592 *"TL-WR841N/ND v9")
593 name="tl-wr841n-v9"
594 ;;
595 *"TL-WR842N/ND v2")
596 name="tl-wr842n-v2"
597 ;;
598 *TL-WR941ND)
599 name="tl-wr941nd"
600 ;;
601 *"TL-WR703N v1")
602 name="tl-wr703n"
603 ;;
604 *"TL-WR710N v1")
605 name="tl-wr710n"
606 ;;
607 *"TL-WR720N v3")
608 name="tl-wr720n-v3"
609 ;;
610 *"TL-MR10U")
611 name="tl-mr10u"
612 ;;
613 *"TL-MR11U")
614 name="tl-mr11u"
615 ;;
616 *"TL-MR13U")
617 name="tl-mr13u"
618 ;;
619 *UniFi)
620 name="unifi"
621 ;;
622 *"UniFi AP Pro")
623 name="uap-pro"
624 ;;
625 *WHR-G301N)
626 name="whr-g301n"
627 ;;
628 *WHR-HP-GN)
629 name="whr-hp-gn"
630 ;;
631 *WLAE-AG300N)
632 name="wlae-ag300n"
633 ;;
634 *"UniFiAP Outdoor")
635 name="unifi-outdoor"
636 ;;
637 *WP543)
638 name="wp543"
639 ;;
640 *WPE72)
641 name="wpe72"
642 ;;
643 *WNDAP360)
644 name="wndap360"
645 ;;
646 *"WNDR3700/WNDR3800/WNDRMAC")
647 wndr3700_board_detect "$machine"
648 ;;
649 *"WNDR4300")
650 name="wndr4300"
651 ;;
652 *"WNR2000 V3")
653 name="wnr2000-v3"
654 ;;
655 *WNR2000)
656 name="wnr2000"
657 ;;
658 *WNR2200)
659 name="wnr2200"
660 ;;
661 *"WNR612 V2")
662 name="wnr612-v2"
663 ;;
664 *WRT160NL)
665 name="wrt160nl"
666 ;;
667 *WRT400N)
668 name="wrt400n"
669 ;;
670 *"WZR-HP-AG300H/WZR-600DHP")
671 name="wzr-hp-ag300h"
672 ;;
673 *WZR-HP-G300NH)
674 name="wzr-hp-g300nh"
675 ;;
676 *WZR-HP-G450H)
677 name="wzr-hp-g450h"
678 ;;
679 *WZR-HP-G300NH2)
680 name="wzr-hp-g300nh2"
681 ;;
682 *WHR-HP-G300N)
683 name="whr-hp-g300n"
684 ;;
685 *ZCN-1523H-2)
686 name="zcn-1523h-2"
687 ;;
688 *ZCN-1523H-5)
689 name="zcn-1523h-5"
690 ;;
691 *EmbWir-Dorin)
692 name="ew-dorin"
693 ;;
694 *EmbWir-Dorin-Router)
695 name="ew-dorin-router"
696 ;;
697 "8devices Carambola2"*)
698 name="carambola2"
699 ;;
700 *"Sitecom WLR-8100")
701 name="wlr8100"
702 ;;
703 *"BHU BXU2000n-2 rev. A1")
704 name="bxu2000n-2-a1"
705 ;;
706 *"HiWiFi HC6361")
707 name="hiwifi-hc6361"
708 ;;
709 esac
710
711 case "$machine" in
712 *TL-WR* | *TL-WA* | *TL-MR* | *TL-WD*)
713 tplink_board_detect "$machine"
714 ;;
715 esac
716
717 [ -z "$name" ] && name="unknown"
718
719 [ -z "$AR71XX_BOARD_NAME" ] && AR71XX_BOARD_NAME="$name"
720 [ -z "$AR71XX_MODEL" ] && AR71XX_MODEL="$machine"
721
722 [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/"
723
724 echo "$AR71XX_BOARD_NAME" > /tmp/sysinfo/board_name
725 echo "$AR71XX_MODEL" > /tmp/sysinfo/model
726 }
727
728 ar71xx_board_name() {
729 local name
730
731 [ -f /tmp/sysinfo/board_name ] && name=$(cat /tmp/sysinfo/board_name)
732 [ -z "$name" ] && name="unknown"
733
734 echo "$name"
735 }