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