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