[lantiq] update /etc/uci-defaults/*
[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 *"RouterBOARD 750GL")
251 name="rb-750gl"
252 ;;
253 *"Rocket M")
254 name="rocket-m"
255 ;;
256 *RouterStation)
257 name="routerstation"
258 ;;
259 *"RouterStation Pro")
260 name="routerstation-pro"
261 ;;
262 *RW2458N)
263 name="rw2458n"
264 ;;
265 *TEW-632BRP)
266 name="tew-632brp"
267 ;;
268 *TEW-673GRU)
269 name="tew-673gru"
270 ;;
271 *TL-WR1043ND)
272 name="tl-wr1043nd"
273 ;;
274 *TL-WR2543N*)
275 name="tl-wr2543n"
276 ;;
277 *"DIR-615 rev. C1")
278 name="dir-615-c1"
279 ;;
280 *TL-MR3020)
281 name="tl-mr3020"
282 ;;
283 *TL-MR3220)
284 name="tl-mr3220"
285 ;;
286 *TL-MR3420)
287 name="tl-mr3420"
288 ;;
289 *TL-WA901ND)
290 name="tl-wa901nd"
291 ;;
292 *"TL-WA901ND v2")
293 name="tl-wa901nd-v2"
294 ;;
295 *TL-WR741ND)
296 name="tl-wr741nd"
297 ;;
298 *"TL-WR741ND v4")
299 name="tl-wr741nd-v4"
300 ;;
301 *"TL-WR841N v1")
302 name="tl-wr841n-v1"
303 ;;
304 *"TL-WR841N/ND v7")
305 name="tl-wr841n-v7"
306 ;;
307 *TL-WR941ND)
308 name="tl-wr941nd"
309 ;;
310 *"TL-WR703N v1")
311 name="tl-wr703n"
312 ;;
313 *"TL-MR11U")
314 name="tl-mr11u"
315 ;;
316 *UniFi)
317 name="unifi"
318 ;;
319 *WHR-G301N)
320 name="whr-g301n"
321 ;;
322 *WHR-HP-GN)
323 name="whr-hp-gn"
324 ;;
325 *WP543)
326 name="wp543"
327 ;;
328 *WPE72)
329 name="wpe72"
330 ;;
331 *"WNDR3700/WNDR3800/WNDRMAC")
332 wndr3700_board_detect "$machine"
333 ;;
334 *WNR2000)
335 name="wnr2000"
336 ;;
337 *WRT160NL)
338 name="wrt160nl"
339 ;;
340 *WRT400N)
341 name="wrt400n"
342 ;;
343 *WZR-HP-AG300H)
344 name="wzr-hp-ag300h"
345 ;;
346 *WZR-HP-G300NH)
347 name="wzr-hp-g300nh"
348 ;;
349 *WZR-HP-G450H)
350 name="wzr-hp-g450h"
351 ;;
352 *WZR-HP-G300NH2)
353 name="wzr-hp-g300nh2"
354 ;;
355 *WHR-HP-G300N)
356 name="whr-hp-g300n"
357 ;;
358 *ZCN-1523H-2)
359 name="zcn-1523h-2"
360 ;;
361 *ZCN-1523H-5)
362 name="zcn-1523h-5"
363 ;;
364 esac
365
366 case "$machine" in
367 *TL-WR* | *TL-WA* | *TL-MR*)
368 tplink_board_detect "$machine"
369 ;;
370 esac
371
372 [ -z "$name" ] && name="unknown"
373
374 [ -z "$AR71XX_BOARD_NAME" ] && AR71XX_BOARD_NAME="$name"
375 [ -z "$AR71XX_MODEL" ] && AR71XX_MODEL="$machine"
376
377 [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/"
378
379 echo "$AR71XX_BOARD_NAME" > /tmp/sysinfo/board_name
380 echo "$AR71XX_MODEL" > /tmp/sysinfo/model
381 }
382
383 ar71xx_board_name() {
384 local name
385
386 [ -f /tmp/sysinfo/board_name ] && name=$(cat /tmp/sysinfo/board_name)
387 [ -z "$name" ] && name="unknown"
388
389 echo "$name"
390 }
This page took 0.074061 seconds and 5 git commands to generate.