ar71xx: AP136 user-space support
[openwrt/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 "430000"*)
127 model="TP-Link TL-WDR4300"
128 ;;
129 *)
130 hwver=""
131 ;;
132 esac
133
134 AR71XX_MODEL="$model $hwver"
135 }
136
137 ar71xx_board_detect() {
138 local machine
139 local name
140
141 machine=$(awk 'BEGIN{FS="[ \t]+:[ \t]"} /machine/ {print $2}' /proc/cpuinfo)
142
143 case "$machine" in
144 *"AirRouter")
145 name="airrouter"
146 ;;
147 *"ALFA Network AP96")
148 name="alfa-ap96"
149 ;;
150 *"ALFA Network N2/N5")
151 name="alfa-nx"
152 ;;
153 *ALL0258N)
154 name="all0258n"
155 ;;
156 *AP113)
157 name="ap113"
158 ;;
159 *AP121)
160 name="ap121"
161 ;;
162 *AP121-MINI)
163 name="ap121-mini"
164 ;;
165 *"AP136 reference board")
166 name="ap136"
167 ;;
168 *AP81)
169 name="ap81"
170 ;;
171 *AP83)
172 name="ap83"
173 ;;
174 *"Atheros AP96")
175 name="ap96"
176 ;;
177 *AW-NR580)
178 name="aw-nr580"
179 ;;
180 *"DB120 reference board")
181 name="db120"
182 ;;
183 *"DIR-600 rev. A1")
184 name="dir-600-a1"
185 ;;
186 *"DIR-615 rev. E4")
187 name="dir-615-e4"
188 ;;
189 *"DIR-825 rev. B1")
190 name="dir-825-b1"
191 ;;
192 *EAP7660D)
193 name="eap7660d"
194 ;;
195 *JA76PF)
196 name="ja76pf"
197 ;;
198 *JA76PF2)
199 name="ja76pf2"
200 ;;
201 *"Bullet M")
202 name="bullet-m"
203 ;;
204 *"Nanostation M")
205 name="nanostation-m"
206 ;;
207 *JWAP003)
208 name="jwap003"
209 ;;
210 *"Hornet-UB")
211 name="hornet-ub"
212 ;;
213 *LS-SR71)
214 name="ls-sr71"
215 ;;
216 *MZK-W04NU)
217 name="mzk-w04nu"
218 ;;
219 *MZK-W300NH)
220 name="mzk-w300nh"
221 ;;
222 *"NBG460N/550N/550NH")
223 name="nbg460n_550n_550nh"
224 ;;
225 *OM2P)
226 name="om2p"
227 ;;
228 *PB42)
229 name="pb42"
230 ;;
231 *PB44)
232 name="pb44"
233 ;;
234 *PB92)
235 name="pb92"
236 ;;
237 *"RouterBOARD 411/A/AH")
238 name="rb-411"
239 ;;
240 *"RouterBOARD 411U")
241 name="rb-411u"
242 ;;
243 *"RouterBOARD 433/AH")
244 name="rb-433"
245 ;;
246 *"RouterBOARD 433UAH")
247 name="rb-433u"
248 ;;
249 *"RouterBOARD 450")
250 name="rb-450"
251 ;;
252 *"RouterBOARD 450G")
253 name="rb-450g"
254 ;;
255 *"RouterBOARD 493/AH")
256 name="rb-493"
257 ;;
258 *"RouterBOARD 493G")
259 name="rb-493g"
260 ;;
261 *"RouterBOARD 750")
262 name="rb-750"
263 ;;
264 *"RouterBOARD 750GL")
265 name="rb-750gl"
266 ;;
267 *"RouterBOARD 751")
268 name="rb-751"
269 ;;
270 *"RouterBOARD 751G")
271 name="rb-751g"
272 ;;
273 *"Rocket M")
274 name="rocket-m"
275 ;;
276 *RouterStation)
277 name="routerstation"
278 ;;
279 *"RouterStation Pro")
280 name="routerstation-pro"
281 ;;
282 *RW2458N)
283 name="rw2458n"
284 ;;
285 *TEW-632BRP)
286 name="tew-632brp"
287 ;;
288 *TEW-673GRU)
289 name="tew-673gru"
290 ;;
291 *"TL-WR1041N v2")
292 name="tl-wr1041n-v2"
293 ;;
294 *TL-WR1043ND)
295 name="tl-wr1043nd"
296 ;;
297 *TL-WR2543N*)
298 name="tl-wr2543n"
299 ;;
300 *"DIR-615 rev. C1")
301 name="dir-615-c1"
302 ;;
303 *TL-MR3020)
304 name="tl-mr3020"
305 ;;
306 *TL-MR3220)
307 name="tl-mr3220"
308 ;;
309 *TL-MR3420)
310 name="tl-mr3420"
311 ;;
312 *TL-WA901ND)
313 name="tl-wa901nd"
314 ;;
315 *"TL-WA901ND v2")
316 name="tl-wa901nd-v2"
317 ;;
318 *TL-WDR4300)
319 name="tl-wdr4300"
320 ;;
321 *TL-WR741ND)
322 name="tl-wr741nd"
323 ;;
324 *"TL-WR741ND v4")
325 name="tl-wr741nd-v4"
326 ;;
327 *"TL-WR841N v1")
328 name="tl-wr841n-v1"
329 ;;
330 *"TL-WR841N/ND v7")
331 name="tl-wr841n-v7"
332 ;;
333 *TL-WR941ND)
334 name="tl-wr941nd"
335 ;;
336 *"TL-WR703N v1")
337 name="tl-wr703n"
338 ;;
339 *"TL-MR11U")
340 name="tl-mr11u"
341 ;;
342 *UniFi)
343 name="unifi"
344 ;;
345 *WHR-G301N)
346 name="whr-g301n"
347 ;;
348 *WHR-HP-GN)
349 name="whr-hp-gn"
350 ;;
351 *WP543)
352 name="wp543"
353 ;;
354 *WPE72)
355 name="wpe72"
356 ;;
357 *"WNDR3700/WNDR3800/WNDRMAC")
358 wndr3700_board_detect "$machine"
359 ;;
360 *WNR2000)
361 name="wnr2000"
362 ;;
363 *WRT160NL)
364 name="wrt160nl"
365 ;;
366 *WRT400N)
367 name="wrt400n"
368 ;;
369 *WZR-HP-AG300H)
370 name="wzr-hp-ag300h"
371 ;;
372 *WZR-HP-G300NH)
373 name="wzr-hp-g300nh"
374 ;;
375 *WZR-HP-G450H)
376 name="wzr-hp-g450h"
377 ;;
378 *WZR-HP-G300NH2)
379 name="wzr-hp-g300nh2"
380 ;;
381 *WHR-HP-G300N)
382 name="whr-hp-g300n"
383 ;;
384 *ZCN-1523H-2)
385 name="zcn-1523h-2"
386 ;;
387 *ZCN-1523H-5)
388 name="zcn-1523h-5"
389 ;;
390 *EmbWir-Dorin)
391 name="ew-dorin"
392 ;;
393 esac
394
395 case "$machine" in
396 *TL-WR* | *TL-WA* | *TL-MR*)
397 tplink_board_detect "$machine"
398 ;;
399 esac
400
401 [ -z "$name" ] && name="unknown"
402
403 [ -z "$AR71XX_BOARD_NAME" ] && AR71XX_BOARD_NAME="$name"
404 [ -z "$AR71XX_MODEL" ] && AR71XX_MODEL="$machine"
405
406 [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/"
407
408 echo "$AR71XX_BOARD_NAME" > /tmp/sysinfo/board_name
409 echo "$AR71XX_MODEL" > /tmp/sysinfo/model
410 }
411
412 ar71xx_board_name() {
413 local name
414
415 [ -f /tmp/sysinfo/board_name ] && name=$(cat /tmp/sysinfo/board_name)
416 [ -z "$name" ] && name="unknown"
417
418 echo "$name"
419 }