2 * Copyright (c) 2007-2008 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 /* Module Name : apdbg.c */
25 /************************************************************************/
33 #include <sys/types.h>
34 #include <sys/socket.h>
35 #include <sys/ioctl.h>
37 #include <netinet/in.h>
39 #include <linux/sockios.h>
41 #define ZM_IOCTL_REG_READ 0x01
42 #define ZM_IOCTL_REG_WRITE 0x02
43 #define ZM_IOCTL_MEM_DUMP 0x03
44 #define ZM_IOCTL_REG_DUMP 0x05
45 #define ZM_IOCTL_TXD_DUMP 0x06
46 #define ZM_IOCTL_RXD_DUMP 0x07
47 #define ZM_IOCTL_MEM_READ 0x0B
48 #define ZM_IOCTL_MEM_WRITE 0x0C
49 #define ZM_IOCTL_DMA_TEST 0x10
50 #define ZM_IOCTL_REG_TEST 0x11
51 #define ZM_IOCTL_TEST 0x80
52 #define ZM_IOCTL_TALLY 0x81 /* CWYang(+) */
53 #define ZM_IOCTL_RTS 0xA0
54 #define ZM_IOCTL_MIX_MODE 0xA1
55 #define ZM_IOCTL_FRAG 0xA2
56 #define ZM_IOCTL_SCAN 0xA3
57 #define ZM_IOCTL_KEY 0xA4
58 #define ZM_IOCTL_RATE 0xA5
59 #define ZM_IOCTL_ENCRYPTION_MODE 0xA6
60 #define ZM_IOCTL_GET_TXCNT 0xA7
61 #define ZM_IOCTL_GET_DEAGG_CNT 0xA8
62 #define ZM_IOCTL_DURATION_MODE 0xA9
63 #define ZM_IOCTL_SET_AES_KEY 0xAA
64 #define ZM_IOCTL_SET_AES_MODE 0xAB
65 #define ZM_IOCTL_SIGNAL_STRENGTH 0xAC /* CWYang(+) */
66 #define ZM_IOCTL_SIGNAL_QUALITY 0xAD /* CWYang(+) */
67 #define ZM_IOCTL_SET_PIBSS_MODE 0xAE
68 #define ZDAPIOCTL SIOCDEVPRIVATE
71 unsigned short cmd
; /* Command to run */
72 unsigned int addr
; /* Length of the data buffer */
73 unsigned int value
; /* Pointer to the data buffer */
74 unsigned char data
[0x100];
77 /* Declaration of macro and function for handling WEP Keys */
82 while (isxdigit(*p)) \
86 #define SKIP_DELIMETER { \
87 if (*p == ':' || *p == ' ') \
93 static char hex(char v
)
98 return tolower(v
) - 'a' + 10;
103 static unsigned char asctohex(char *str
)
107 value
= hex(*str
) & 0x0f;
110 value
|= hex(*str
) & 0x0f;
117 int set_ioctl(int sock
, struct ifreq
*req
)
119 if (ioctl(sock
, ZDAPIOCTL
, req
) < 0) {
120 fprintf(stderr
, "%s: ioctl(SIOCGIFMAP): %s\n",
121 prgname
, strerror(errno
));
129 int read_reg(int sock
, struct ifreq
*req
)
131 struct zdap_ioctl
*zdreq
= NULL
;
133 if (!set_ioctl(sock
, req
))
137 * zdreq = (struct zdap_ioctl *)req->ifr_data;
138 * printf( "reg = %4x, value = %4x\n", zdreq->addr, zdreq->value);
145 int read_mem(int sock
, struct ifreq
*req
)
147 struct zdap_ioctl
*zdreq
= NULL
;
150 if (!set_ioctl(sock
, req
))
154 * zdreq = (struct zdap_ioctl *)req->ifr_data;
155 * printf("dump mem from %x, length = %x\n", zdreq->addr, zdreq->value);
157 * for (i=0; i<zdreq->value; i++) {
158 * printf("%02x", zdreq->data[i]);
161 * if ((i>0) && ((i+1)%16 == 0))
170 int main(int argc
, char **argv
)
176 struct zdap_ioctl zdreq
;
181 fprintf(stderr
, "%s: usage is \"%s <ifname> <operation>"
182 "[<address>] [<value>]\"\n", prgname
, prgname
);
183 fprintf(stderr
, "valid operation : read, write, mem, reg, \n");
184 fprintf(stderr
, " : txd, rxd, rmem, wmem\n");
185 fprintf(stderr
, " : dmat, regt, test\n");
187 fprintf(stderr
, " scan, Channel Scan\n");
188 fprintf(stderr
, " rts <decimal>, Set RTS Threshold\n");
189 fprintf(stderr
, " frag <decimal>, Set Fragment"
191 fprintf(stderr
, " rate <0-28>, 0:AUTO, 1-4:CCK,"
192 " 5-12:OFDM, 13-28:HT\n");
193 fprintf(stderr
, " TBD mix <0 or 1>, Set 1 to enable"
195 fprintf(stderr
, " enc, <0-3>, 0=>OPEN, 1=>WEP64, "
196 "2=>WEP128, 3=>WEP256\n");
197 fprintf(stderr
, " skey <key>, Set WEP key\n");
198 fprintf(stderr
, " txcnt, Get TxQ Cnt\n");
199 fprintf(stderr
, " dagcnt, Get Deaggregate Cnt\n");
200 fprintf(stderr
, " durmode <mode>, Set Duration Mode "
202 fprintf(stderr
, " aeskey <user> <key>\n");
203 fprintf(stderr
, " aesmode <mode>\n");
204 fprintf(stderr
, " wlanmode <0,1> 0:Station mode, "
206 fprintf(stderr
, " tal <0,1>, Get Current Tally Info, "
207 "0=>read, 1=>read and reset\n");
212 strcpy(req
.ifr_name
, argv
[1]);
216 /* a silly raw socket just for ioctl()ling it */
217 sock
= socket(AF_INET
, SOCK_RAW
, IPPROTO_RAW
);
219 fprintf(stderr
, "%s: socket(): %s\n", argv
[0], strerror(errno
));
224 sscanf(argv
[3], "%x", &addr
);
227 sscanf(argv
[4], "%x", &value
);
232 if (!strcmp(argv
[2], "read"))
233 zdreq
.cmd
= ZM_IOCTL_REG_READ
;
234 else if (!strcmp(argv
[2], "mem"))
235 zdreq
.cmd
= ZM_IOCTL_MEM_DUMP
;
236 else if (!strcmp(argv
[2], "write"))
237 zdreq
.cmd
= ZM_IOCTL_REG_WRITE
;
238 else if (!strcmp(argv
[2], "reg"))
239 zdreq
.cmd
= ZM_IOCTL_REG_DUMP
;
240 else if (!strcmp(argv
[2], "txd"))
241 zdreq
.cmd
= ZM_IOCTL_TXD_DUMP
;
242 else if (!strcmp(argv
[2], "rxd"))
243 zdreq
.cmd
= ZM_IOCTL_RXD_DUMP
;
244 else if (!strcmp(argv
[2], "rmem"))
245 zdreq
.cmd
= ZM_IOCTL_MEM_READ
;
246 else if (!strcmp(argv
[2], "wmem"))
247 zdreq
.cmd
= ZM_IOCTL_MEM_WRITE
;
248 else if (!strcmp(argv
[2], "dmat"))
249 zdreq
.cmd
= ZM_IOCTL_DMA_TEST
;
250 else if (!strcmp(argv
[2], "regt"))
251 zdreq
.cmd
= ZM_IOCTL_REG_TEST
;
252 else if (!strcmp(argv
[2], "test"))
253 zdreq
.cmd
= ZM_IOCTL_TEST
;
254 else if (!strcmp(argv
[2], "tal")) {
255 sscanf(argv
[3], "%d", &addr
);
257 zdreq
.cmd
= ZM_IOCTL_TALLY
;
258 } else if (!strcmp(argv
[2], "rts")) {
259 sscanf(argv
[3], "%d", &addr
);
261 zdreq
.cmd
= ZM_IOCTL_RTS
;
262 } else if (!strcmp(argv
[2], "mix")) {
263 zdreq
.cmd
= ZM_IOCTL_MIX_MODE
;
264 } else if (!strcmp(argv
[2], "frag")) {
265 sscanf(argv
[3], "%d", &addr
);
267 zdreq
.cmd
= ZM_IOCTL_FRAG
;
268 } else if (!strcmp(argv
[2], "scan")) {
269 zdreq
.cmd
= ZM_IOCTL_SCAN
;
270 } else if (!strcmp(argv
[2], "skey")) {
271 zdreq
.cmd
= ZM_IOCTL_KEY
;
274 unsigned char temp
[29];
279 keyLen
= strlen(argv
[3]);
282 sscanf(argv
[3], "%02x%02x%02x%02x%02x",
283 &temp
[0], &temp
[1], &temp
[2], &temp
[3],
285 else if (keyLen
== 26)
286 sscanf(argv
[3], "%02x%02x%02x%02x%02x%02x"
287 "%02x%02x%02x%02x%02x%02x%02x",
288 &temp
[0], &temp
[1], &temp
[2], &temp
[3],
289 &temp
[4], &temp
[5], &temp
[6], &temp
[7],
290 &temp
[8], &temp
[9], &temp
[10],
291 &temp
[11], &temp
[12]);
292 else if (keyLen
== 58)
293 sscanf(argv
[3], "%02x%02x%02x%02x%02x%02x"
294 "%02x%02x%02x%02x%02x%02x%02x%02x%02x"
295 "%02x%02x%02x%02x%02x%02x%02x%02x%02x"
296 "%02x%02x%02x%02x%02x",
297 &temp
[0], &temp
[1], &temp
[2], &temp
[3],
298 &temp
[4], &temp
[5], &temp
[6], &temp
[7],
299 &temp
[8], &temp
[9], &temp
[10],
300 &temp
[11], &temp
[12], &temp
[13],
301 &temp
[14], &temp
[15], &temp
[16],
302 &temp
[17], &temp
[18], &temp
[19],
303 &temp
[20], &temp
[21], &temp
[22],
304 &temp
[23], &temp
[24], &temp
[25],
305 &temp
[26], &temp
[27], &temp
[28]);
307 fprintf(stderr
, "Invalid key length\n");
310 zdreq
.addr
= keyLen
/2;
312 for (i
= 0; i
< zdreq
.addr
; i
++)
313 zdreq
.data
[i
] = temp
[i
];
315 printf("Error : Key required!\n");
317 } else if (!strcmp(argv
[2], "rate")) {
318 sscanf(argv
[3], "%d", &addr
);
321 fprintf(stderr
, "Invalid rate, range:0~28\n");
325 zdreq
.cmd
= ZM_IOCTL_RATE
;
326 } else if (!strcmp(argv
[2], "enc")) {
327 sscanf(argv
[3], "%d", &addr
);
330 fprintf(stderr
, "Invalid encryption mode, range:0~3\n");
340 zdreq
.cmd
= ZM_IOCTL_ENCRYPTION_MODE
;
341 } else if (!strcmp(argv
[2], "txcnt")) {
342 zdreq
.cmd
= ZM_IOCTL_GET_TXCNT
;
343 } else if (!strcmp(argv
[2], "dagcnt")) {
344 sscanf(argv
[3], "%d", &addr
);
346 if (addr
!= 0 && addr
!= 1) {
347 fprintf(stderr
, "The value should be 0 or 1\n");
352 zdreq
.cmd
= ZM_IOCTL_GET_DEAGG_CNT
;
353 } else if (!strcmp(argv
[2], "durmode")) {
354 sscanf(argv
[3], "%d", &addr
);
356 if (addr
!= 0 && addr
!= 1) {
357 fprintf(stderr
, "The Duration mode should be 0 or 1\n");
362 zdreq
.cmd
= ZM_IOCTL_DURATION_MODE
;
363 } else if (!strcmp(argv
[2], "aeskey")) {
364 unsigned char temp
[16];
367 sscanf(argv
[3], "%d", &addr
);
369 sscanf(argv
[4], "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
370 "%02x%02x%02x%02x%02x%02x", &temp
[0], &temp
[1],
371 &temp
[2], &temp
[3], &temp
[4], &temp
[5], &temp
[6],
372 &temp
[7], &temp
[8], &temp
[9], &temp
[10], &temp
[11],
373 &temp
[12], &temp
[13], &temp
[14], &temp
[15]);
375 for (i
= 0; i
< 16; i
++)
376 zdreq
.data
[i
] = temp
[i
];
379 zdreq
.cmd
= ZM_IOCTL_SET_AES_KEY
;
380 } else if (!strcmp(argv
[2], "aesmode")) {
381 sscanf(argv
[3], "%d", &addr
);
384 zdreq
.cmd
= ZM_IOCTL_SET_AES_MODE
;
385 } else if (!strcmp(argv
[2], "wlanmode")) {
386 sscanf(argv
[3], "%d", &addr
);
389 zdreq
.cmd
= ZM_IOCTL_SET_PIBSS_MODE
;
391 fprintf(stderr
, "error action\n");
395 req
.ifr_data
= (char *)&zdreq
;
396 set_ioctl(sock
, &req
);