b51f3a7c637a5ed82cde993104b872463008bad6
[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 else
45 machine="NETGEAR $model"
46 fi
47 ;;
48 esac
49
50 AR71XX_BOARD_NAME="$name"
51 AR71XX_MODEL="$machine"
52 }
53
54 tplink_get_hwid() {
55 local part
56
57 part=$(find_mtd_part firmware)
58 [ -z "$part" ] && return 1
59
60 dd if=$part bs=4 count=1 skip=16 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
61 }
62
63 tplink_board_detect() {
64 local model="$1"
65 local hwid
66 local hwver
67
68 hwid=$(tplink_get_hwid)
69 hwver=${hwid:6:2}
70 hwver="v${hwver#0}"
71
72 case "$hwid" in
73 "070300"*)
74 model="TP-Link TL-WR703N"
75 ;;
76 "070100"*)
77 model="TP-Link TL-WA701N/ND"
78 ;;
79 "074000"*)
80 model="TP-Link TL-WR740N/ND"
81 ;;
82 "074100"*)
83 model="TP-Link TL-WR741N/ND"
84 ;;
85 "074300"*)
86 model="TP-Link TL-WR743N/ND"
87 ;;
88 "084100"*)
89 model="TP-Link TL-WR841N/ND"
90 ;;
91 "084200"*)
92 model="TP-Link TL-WR842N/ND"
93 ;;
94 "090100"*)
95 model="TP-Link TL-WA901N/ND"
96 ;;
97 "094100"*)
98 model="TP-Link TL-WR941N/ND"
99 ;;
100 "104300"*)
101 model="TP-Link TL-WR1043N/ND"
102 ;;
103 "254300"*)
104 model="TP-Link TL-WR2543N/ND"
105 ;;
106 "110101"*)
107 model="TP-Link TL-MR11U"
108 ;;
109 "302000"*)
110 model="TP-Link TL-MR3020"
111 ;;
112 "322000"*)
113 model="TP-Link TL-MR3220"
114 ;;
115 "342000"*)
116 model="TP-Link TL-MR3420"
117 ;;
118 *)
119 hwver=""
120 ;;
121 esac
122
123 AR71XX_MODEL="$model $hwver"
124 }
125
126 ar71xx_board_detect() {
127 local machine
128 local name
129
130 machine=$(awk 'BEGIN{FS="[ \t]+:[ \t]"} /machine/ {print $2}' /proc/cpuinfo)
131
132 case "$machine" in
133 *"AirRouter")
134 name="airrouter"
135 ;;
136 *"ALFA Network AP96")
137 name="alfa-ap96"
138 ;;
139 *"ALFA Network N2/N5")
140 name="alfa-nx"
141 ;;
142 *ALL0258N)
143 name="all0258n"
144 ;;
145 *AP113)
146 name="ap113"
147 ;;
148 *AP121)
149 name="ap121"
150 ;;
151 *AP121-MINI)
152 name="ap121-mini"
153 ;;
154 *AP81)
155 name="ap81"
156 ;;
157 *AP83)
158 name="ap83"
159 ;;
160 *"Atheros AP96")
161 name="ap96"
162 ;;
163 *AW-NR580)
164 name="aw-nr580"
165 ;;
166 *"DB120 reference board")
167 name="db120"
168 ;;
169 *"DIR-600 rev. A1")
170 name="dir-600-a1"
171 ;;
172 *"DIR-615 rev. E4")
173 name="dir-615-e4"
174 ;;
175 *"DIR-825 rev. B1")
176 name="dir-825-b1"
177 ;;
178 *EAP7660D)
179 name="eap7660d"
180 ;;
181 *JA76PF)
182 name="ja76pf"
183 ;;
184 *JA76PF2)
185 name="ja76pf2"
186 ;;
187 *"Bullet M")
188 name="bullet-m"
189 ;;
190 *"Nanostation M")
191 name="nanostation-m"
192 ;;
193 *JWAP003)
194 name="jwap003"
195 ;;
196 *"Hornet-UB")
197 name="hornet-ub"
198 ;;
199 *LS-SR71)
200 name="ls-sr71"
201 ;;
202 *MZK-W04NU)
203 name="mzk-w04nu"
204 ;;
205 *MZK-W300NH)
206 name="mzk-w300nh"
207 ;;
208 *"NBG460N/550N/550NH")
209 name="nbg460n_550n_550nh"
210 ;;
211 *OM2P)
212 name="om2p"
213 ;;
214 *PB42)
215 name="pb42"
216 ;;
217 *PB44)
218 name="pb44"
219 ;;
220 *PB92)
221 name="pb92"
222 ;;
223 *"RouterBOARD 411/A/AH")
224 name="rb-411"
225 ;;
226 *"RouterBOARD 411U")
227 name="rb-411u"
228 ;;
229 *"RouterBOARD 433/AH")
230 name="rb-433"
231 ;;
232 *"RouterBOARD 433UAH")
233 name="rb-433u"
234 ;;
235 *"RouterBOARD 450")
236 name="rb-450"
237 ;;
238 *"RouterBOARD 450G")
239 name="rb-450g"
240 ;;
241 *"RouterBOARD 493/AH")
242 name="rb-493"
243 ;;
244 *"RouterBOARD 493G")
245 name="rb-493g"
246 ;;
247 *"RouterBOARD 750")
248 name="rb-750"
249 ;;
250 *"Rocket M")
251 name="rocket-m"
252 ;;
253 *RouterStation)
254 name="routerstation"
255 ;;
256 *"RouterStation Pro")
257 name="routerstation-pro"
258 ;;
259 *RW2458N)
260 name="rw2458n"
261 ;;
262 *TEW-632BRP)
263 name="tew-632brp"
264 ;;
265 *TEW-673GRU)
266 name="tew-673gru"
267 ;;
268 *TL-WR1043ND)
269 name="tl-wr1043nd"
270 ;;
271 *TL-WR2543N*)
272 name="tl-wr2543n"
273 ;;
274 *"DIR-615 rev. C1")
275 name="dir-615-c1"
276 ;;
277 *TL-MR3020)
278 name="tl-mr3020"
279 ;;
280 *TL-MR3220)
281 name="tl-mr3220"
282 ;;
283 *TL-MR3420)
284 name="tl-mr3420"
285 ;;
286 *TL-WA901ND)
287 name="tl-wa901nd"
288 ;;
289 *"TL-WA901ND v2")
290 name="tl-wa901nd-v2"
291 ;;
292 *TL-WR741ND)
293 name="tl-wr741nd"
294 ;;
295 *"TL-WR741ND v4")
296 name="tl-wr741nd-v4"
297 ;;
298 *"TL-WR841N v1")
299 name="tl-wr841n-v1"
300 ;;
301 *"TL-WR841N/ND v7")
302 name="tl-wr841n-v7"
303 ;;
304 *TL-WR941ND)
305 name="tl-wr941nd"
306 ;;
307 *"TL-WR703N v1")
308 name="tl-wr703n"
309 ;;
310 *"TL-MR11U")
311 name="tl-mr11u"
312 ;;
313 *UniFi)
314 name="unifi"
315 ;;
316 *WHR-G301N)
317 name="whr-g301n"
318 ;;
319 *WHR-HP-GN)
320 name="whr-hp-gn"
321 ;;
322 *WP543)
323 name="wp543"
324 ;;
325 *WPE72)
326 name="wpe72"
327 ;;
328 *"WNDR3700/WNDR3800/WNDRMAC")
329 wndr3700_board_detect "$machine"
330 ;;
331 *WNR2000)
332 name="wnr2000"
333 ;;
334 *WRT160NL)
335 name="wrt160nl"
336 ;;
337 *WRT400N)
338 name="wrt400n"
339 ;;
340 *WZR-HP-AG300H)
341 name="wzr-hp-ag300h"
342 ;;
343 *WZR-HP-G300NH)
344 name="wzr-hp-g300nh"
345 ;;
346 *WZR-HP-G450H)
347 name="wzr-hp-g450h"
348 ;;
349 *WZR-HP-G300NH2)
350 name="wzr-hp-g300nh2"
351 ;;
352 *WHR-HP-G300N)
353 name="whr-hp-g300n"
354 ;;
355 *ZCN-1523H-2)
356 name="zcn-1523h-2"
357 ;;
358 *ZCN-1523H-5)
359 name="zcn-1523h-5"
360 ;;
361 esac
362
363 case "$machine" in
364 *TL-WR* | *TL-WA* | *TL-MR*)
365 tplink_board_detect "$machine"
366 ;;
367 esac
368
369 [ -z "$name" ] && name="unknown"
370
371 [ -z "$AR71XX_BOARD_NAME" ] && AR71XX_BOARD_NAME="$name"
372 [ -z "$AR71XX_MODEL" ] && AR71XX_MODEL="$machine"
373
374 [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/"
375
376 echo "$AR71XX_BOARD_NAME" > /tmp/sysinfo/board_name
377 echo "$AR71XX_MODEL" > /tmp/sysinfo/model
378 }
379
380 ar71xx_board_name() {
381 local name
382
383 [ -f /tmp/sysinfo/board_name ] && name=$(cat /tmp/sysinfo/board_name)
384 [ -z "$name" ] && name="unknown"
385
386 echo "$name"
387 }
This page took 0.063792 seconds and 3 git commands to generate.