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