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