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