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