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