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