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