ar71xx: add initial support for RB2011UAS-2HnD
[openwrt.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_board_detect() {
66         local model="$1"
67         local hwid
68         local hwver
69
70         hwid=$(tplink_get_hwid)
71         hwver=${hwid:6:2}
72         hwver="v${hwver#0}"
73
74         case "$hwid" in
75         "070300"*)
76                 model="TP-Link TL-WR703N"
77                 ;;
78         "070100"*)
79                 model="TP-Link TL-WA701N/ND"
80                 ;;
81         "074000"*)
82                 model="TP-Link TL-WR740N/ND"
83                 ;;
84         "074100"*)
85                 model="TP-Link TL-WR741N/ND"
86                 ;;
87         "074300"*)
88                 model="TP-Link TL-WR743N/ND"
89                 ;;
90         "084100"*)
91                 model="TP-Link TL-WR841N/ND"
92                 ;;
93         "084200"*)
94                 model="TP-Link TL-WR842N/ND"
95                 ;;
96         "090100"*)
97                 model="TP-Link TL-WA901N/ND"
98                 ;;
99         "094100"*)
100                 model="TP-Link TL-WR941N/ND"
101                 ;;
102         "104100"*)
103                 model="TP-Link TL-WR1041N/ND"
104                 ;;
105         "104300"*)
106                 model="TP-Link TL-WR1043N/ND"
107                 ;;
108         "254300"*)
109                 model="TP-Link TL-WR2543N/ND"
110                 ;;
111         "110101"*)
112                 model="TP-Link TL-MR11U"
113                 ;;
114         "302000"*)
115                 model="TP-Link TL-MR3020"
116                 ;;
117         "304000"*)
118                 model="TP-Link TL-MR3040"
119                 ;;
120         "322000"*)
121                 model="TP-Link TL-MR3220"
122                 ;;
123         "342000"*)
124                 model="TP-Link TL-MR3420"
125                 ;;
126         "360000"*)
127                 model="TP-Link TL-WDR3600"
128                 ;;
129         "430000"*)
130                 model="TP-Link TL-WDR4300"
131                 ;;
132         "431000"*)
133                 model="TP-Link TL-WDR4310"
134                 ;;
135         *)
136                 hwver=""
137                 ;;
138         esac
139
140         AR71XX_MODEL="$model $hwver"
141 }
142
143 ar71xx_board_detect() {
144         local machine
145         local name
146
147         machine=$(awk 'BEGIN{FS="[ \t]+:[ \t]"} /machine/ {print $2}' /proc/cpuinfo)
148
149         case "$machine" in
150         *"AirRouter")
151                 name="airrouter"
152                 ;;
153         *"ALFA Network AP96")
154                 name="alfa-ap96"
155                 ;;
156         *"ALFA Network N2/N5")
157                 name="alfa-nx"
158                 ;;
159         *ALL0258N)
160                 name="all0258n"
161                 ;;
162         *ALL0305)
163                 name="all0305"
164                 ;;
165         *ALL0315N)
166                 name="all0315n"
167                 ;;
168         *AP113)
169                 name="ap113"
170                 ;;
171         *AP121)
172                 name="ap121"
173                 ;;
174         *AP121-MINI)
175                 name="ap121-mini"
176                 ;;
177         *"AP136 reference board")
178                 name="ap136"
179                 ;;
180         *AP81)
181                 name="ap81"
182                 ;;
183         *AP83)
184                 name="ap83"
185                 ;;
186         *"Atheros AP96")
187                 name="ap96"
188                 ;;
189         *AW-NR580)
190                 name="aw-nr580"
191                 ;;
192         *"DB120 reference board")
193                 name="db120"
194                 ;;
195         *"DIR-600 rev. A1")
196                 name="dir-600-a1"
197                 ;;
198         *"DIR-615 rev. E4")
199                 name="dir-615-e4"
200                 ;;
201         *"DIR-825 rev. B1")
202                 name="dir-825-b1"
203                 ;;
204         *"DIR-825 rev. B1 OpenWrt")
205                 name="dir-825-b1-openwrt"
206                 ;;
207         *"DIR-825 rev. B1 TOSTOCK")
208                 name="dir-825-b1-tostock"
209                 ;;
210         *EAP7660D)
211                 name="eap7660d"
212                 ;;
213         *JA76PF)
214                 name="ja76pf"
215                 ;;
216         *JA76PF2)
217                 name="ja76pf2"
218                 ;;
219         *"Bullet M")
220                 name="bullet-m"
221                 ;;
222         *"Nanostation M")
223                 name="nanostation-m"
224                 ;;
225         *JWAP003)
226                 name="jwap003"
227                 ;;
228         *"Hornet-UB")
229                 name="hornet-ub"
230                 ;;
231         *LS-SR71)
232                 name="ls-sr71"
233                 ;;
234         *MZK-W04NU)
235                 name="mzk-w04nu"
236                 ;;
237         *MZK-W300NH)
238                 name="mzk-w300nh"
239                 ;;
240         *"NBG460N/550N/550NH")
241                 name="nbg460n_550n_550nh"
242                 ;;
243         *OM2P)
244                 name="om2p"
245                 ;;
246         *"OM2P LC")
247                 name="om2p-lc"
248                 ;;
249         *PB42)
250                 name="pb42"
251                 ;;
252         *"PB44 reference board")
253                 name="pb44"
254                 ;;
255         *PB92)
256                 name="pb92"
257                 ;;
258         *"RouterBOARD 411/A/AH")
259                 name="rb-411"
260                 ;;
261         *"RouterBOARD 411U")
262                 name="rb-411u"
263                 ;;
264         *"RouterBOARD 433/AH")
265                 name="rb-433"
266                 ;;
267         *"RouterBOARD 433UAH")
268                 name="rb-433u"
269                 ;;
270         *"RouterBOARD 450")
271                 name="rb-450"
272                 ;;
273         *"RouterBOARD 450G")
274                 name="rb-450g"
275                 ;;
276         *"RouterBOARD 493/AH")
277                 name="rb-493"
278                 ;;
279         *"RouterBOARD 493G")
280                 name="rb-493g"
281                 ;;
282         *"RouterBOARD 750")
283                 name="rb-750"
284                 ;;
285         *"RouterBOARD 750GL")
286                 name="rb-750gl"
287                 ;;
288         *"RouterBOARD 751")
289                 name="rb-751"
290                 ;;
291         *"RouterBOARD 751G")
292                 name="rb-751g"
293                 ;;
294         *"RouterBOARD 2011L")
295                 name="rb-2011l"
296                 ;;
297         *"RouterBOARD 2011UAS-2HnD")
298                 name="rb-2011uas-2hnd"
299                 ;;
300         *"Rocket M")
301                 name="rocket-m"
302                 ;;
303         *RouterStation)
304                 name="routerstation"
305                 ;;
306         *"RouterStation Pro")
307                 name="routerstation-pro"
308                 ;;
309         *RW2458N)
310                 name="rw2458n"
311                 ;;
312         *TEW-632BRP)
313                 name="tew-632brp"
314                 ;;
315         *TEW-673GRU)
316                 name="tew-673gru"
317                 ;;
318         *TEW-712BR)
319                 name="tew-712br"
320                 ;;
321         *"TL-WR1041N v2")
322                 name="tl-wr1041n-v2"
323                 ;;
324         *TL-WR1043ND)
325                 name="tl-wr1043nd"
326                 ;;
327         *TL-WR2543N*)
328                 name="tl-wr2543n"
329                 ;;
330         *"DIR-615 rev. C1")
331                 name="dir-615-c1"
332                 ;;
333         *TL-MR3020)
334                 name="tl-mr3020"
335                 ;;
336         *TL-MR3220)
337                 name="tl-mr3220"
338                 ;;
339         *TL-MR3420)
340                 name="tl-mr3420"
341                 ;;
342         *TL-WA901ND)
343                 name="tl-wa901nd"
344                 ;;
345         *"TL-WA901ND v2")
346                 name="tl-wa901nd-v2"
347                 ;;
348         *"TL-WDR3600/4300/4310")
349                 name="tl-wdr4300"
350                 ;;
351         *TL-WR741ND)
352                 name="tl-wr741nd"
353                 ;;
354         *"TL-WR741ND v4")
355                 name="tl-wr741nd-v4"
356                 ;;
357         *"TL-WR841N v1")
358                 name="tl-wr841n-v1"
359                 ;;
360         *"TL-WR841N/ND v7")
361                 name="tl-wr841n-v7"
362                 ;;
363         *TL-WR941ND)
364                 name="tl-wr941nd"
365                 ;;
366         *"TL-WR703N v1")
367                 name="tl-wr703n"
368                 ;;
369         *"TL-MR11U")
370                 name="tl-mr11u"
371                 ;;
372         *UniFi)
373                 name="unifi"
374                 ;;
375         *WHR-G301N)
376                 name="whr-g301n"
377                 ;;
378         *WHR-HP-GN)
379                 name="whr-hp-gn"
380                 ;;
381         *WLAE-AG300N)
382                 name="wlae-ag300n"
383                 ;;
384         *WP543)
385                 name="wp543"
386                 ;;
387         *WPE72)
388                 name="wpe72"
389                 ;;
390         *"WNDR3700/WNDR3800/WNDRMAC")
391                 wndr3700_board_detect "$machine"
392                 ;;
393         *WNR2000)
394                 name="wnr2000"
395                 ;;
396         *WRT160NL)
397                 name="wrt160nl"
398                 ;;
399         *WRT400N)
400                 name="wrt400n"
401                 ;;
402         *WZR-HP-AG300H)
403                 name="wzr-hp-ag300h"
404                 ;;
405         *WZR-HP-G300NH)
406                 name="wzr-hp-g300nh"
407                 ;;
408         *WZR-HP-G450H)
409                 name="wzr-hp-g450h"
410                 ;;
411         *WZR-HP-G300NH2)
412                 name="wzr-hp-g300nh2"
413                 ;;
414         *WHR-HP-G300N)
415                 name="whr-hp-g300n"
416                 ;;
417         *ZCN-1523H-2)
418                 name="zcn-1523h-2"
419                 ;;
420         *ZCN-1523H-5)
421                 name="zcn-1523h-5"
422                 ;;
423         *EmbWir-Dorin)
424                 name="ew-dorin"
425                 ;;
426         *EmbWir-Dorin-Router)
427                 name="ew-dorin-router"
428                 ;;
429         esac
430
431         case "$machine" in
432         *TL-WR* | *TL-WA* | *TL-MR*)
433                 tplink_board_detect "$machine"
434                 ;;
435         esac
436
437         [ -z "$name" ] && name="unknown"
438
439         [ -z "$AR71XX_BOARD_NAME" ] && AR71XX_BOARD_NAME="$name"
440         [ -z "$AR71XX_MODEL" ] && AR71XX_MODEL="$machine"
441
442         [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/"
443
444         echo "$AR71XX_BOARD_NAME" > /tmp/sysinfo/board_name
445         echo "$AR71XX_MODEL" > /tmp/sysinfo/model
446 }
447
448 ar71xx_board_name() {
449         local name
450
451         [ -f /tmp/sysinfo/board_name ] && name=$(cat /tmp/sysinfo/board_name)
452         [ -z "$name" ] && name="unknown"
453
454         echo "$name"
455 }