Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc-2.6
[linux-2.6/kvm.git] / drivers / staging / otus / apdbg.c
blob09415a6b93cab3ecf6c67837492471c79a491dc5
1 /*
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.
16 /* */
17 /* Module Name : apdbg.c */
18 /* */
19 /* Abstract */
20 /* Debug tools */
21 /* */
22 /* NOTES */
23 /* None */
24 /* */
25 /************************************************************************/
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include <errno.h>
32 #include <ctype.h>
33 #include <sys/types.h>
34 #include <sys/socket.h>
35 #include <sys/ioctl.h>
36 #include <net/if.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
70 struct zdap_ioctl {
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 */
79 #if 0
81 #define SKIP_ELEM { \
82 while (isxdigit(*p)) \
83 p++; \
86 #define SKIP_DELIMETER { \
87 if (*p == ':' || *p == ' ') \
88 p++; \
91 #endif
93 char *prgname;
95 int set_ioctl(int sock, struct ifreq *req)
97 if (ioctl(sock, ZDAPIOCTL, req) < 0) {
98 fprintf(stderr, "%s: ioctl(SIOCGIFMAP): %s\n",
99 prgname, strerror(errno));
100 return -1;
103 return 0;
107 int read_reg(int sock, struct ifreq *req)
109 struct zdap_ioctl *zdreq = NULL;
111 if (!set_ioctl(sock, req))
112 return -1;
115 * zdreq = (struct zdap_ioctl *)req->ifr_data;
116 * printf( "reg = %4x, value = %4x\n", zdreq->addr, zdreq->value);
119 return 0;
123 int read_mem(int sock, struct ifreq *req)
125 struct zdap_ioctl *zdreq = NULL;
126 int i;
128 if (!set_ioctl(sock, req))
129 return -1;
132 * zdreq = (struct zdap_ioctl *)req->ifr_data;
133 * printf("dump mem from %x, length = %x\n", zdreq->addr, zdreq->value);
135 * for (i=0; i<zdreq->value; i++) {
136 * printf("%02x", zdreq->data[i]);
137 * printf(" ");
139 * if ((i>0) && ((i+1)%16 == 0))
140 * printf("\n");
144 return 0;
148 int main(int argc, char **argv)
150 int sock;
151 int addr, value;
152 struct ifreq req;
153 char *action = NULL;
154 struct zdap_ioctl zdreq;
156 prgname = argv[0];
158 if (argc < 3) {
159 fprintf(stderr, "%s: usage is \"%s <ifname> <operation>"
160 "[<address>] [<value>]\"\n", prgname, prgname);
161 fprintf(stderr, "valid operation : read, write, mem, reg,\n");
162 fprintf(stderr, " : txd, rxd, rmem, wmem\n");
163 fprintf(stderr, " : dmat, regt, test\n");
165 fprintf(stderr, " scan, Channel Scan\n");
166 fprintf(stderr, " rts <decimal>, Set RTS Threshold\n");
167 fprintf(stderr, " frag <decimal>, Set Fragment"
168 " Threshold\n");
169 fprintf(stderr, " rate <0-28>, 0:AUTO, 1-4:CCK,"
170 " 5-12:OFDM, 13-28:HT\n");
171 fprintf(stderr, " TBD mix <0 or 1>, Set 1 to enable"
172 " mixed mode\n");
173 fprintf(stderr, " enc, <0-3>, 0=>OPEN, 1=>WEP64, "
174 "2=>WEP128, 3=>WEP256\n");
175 fprintf(stderr, " skey <key>, Set WEP key\n");
176 fprintf(stderr, " txcnt, Get TxQ Cnt\n");
177 fprintf(stderr, " dagcnt, Get Deaggregate Cnt\n");
178 fprintf(stderr, " durmode <mode>, Set Duration Mode "
179 "0=>HW, 1=>SW\n");
180 fprintf(stderr, " aeskey <user> <key>\n");
181 fprintf(stderr, " aesmode <mode>\n");
182 fprintf(stderr, " wlanmode <0,1> 0:Station mode, "
183 "1:PIBSS mode\n");
184 fprintf(stderr, " tal <0,1>, Get Current Tally Info, "
185 "0=>read, 1=>read and reset\n");
187 exit(1);
190 strcpy(req.ifr_name, argv[1]);
191 zdreq.addr = 0;
192 zdreq.value = 0;
194 /* a silly raw socket just for ioctl()ling it */
195 sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
196 if (sock < 0) {
197 fprintf(stderr, "%s: socket(): %s\n", argv[0], strerror(errno));
198 exit(1);
201 if (argc >= 4)
202 sscanf(argv[3], "%x", &addr);
204 if (argc >= 5)
205 sscanf(argv[4], "%x", &value);
207 zdreq.addr = addr;
208 zdreq.value = value;
210 if (!strcmp(argv[2], "read"))
211 zdreq.cmd = ZM_IOCTL_REG_READ;
212 else if (!strcmp(argv[2], "mem"))
213 zdreq.cmd = ZM_IOCTL_MEM_DUMP;
214 else if (!strcmp(argv[2], "write"))
215 zdreq.cmd = ZM_IOCTL_REG_WRITE;
216 else if (!strcmp(argv[2], "reg"))
217 zdreq.cmd = ZM_IOCTL_REG_DUMP;
218 else if (!strcmp(argv[2], "txd"))
219 zdreq.cmd = ZM_IOCTL_TXD_DUMP;
220 else if (!strcmp(argv[2], "rxd"))
221 zdreq.cmd = ZM_IOCTL_RXD_DUMP;
222 else if (!strcmp(argv[2], "rmem"))
223 zdreq.cmd = ZM_IOCTL_MEM_READ;
224 else if (!strcmp(argv[2], "wmem"))
225 zdreq.cmd = ZM_IOCTL_MEM_WRITE;
226 else if (!strcmp(argv[2], "dmat"))
227 zdreq.cmd = ZM_IOCTL_DMA_TEST;
228 else if (!strcmp(argv[2], "regt"))
229 zdreq.cmd = ZM_IOCTL_REG_TEST;
230 else if (!strcmp(argv[2], "test"))
231 zdreq.cmd = ZM_IOCTL_TEST;
232 else if (!strcmp(argv[2], "tal")) {
233 sscanf(argv[3], "%d", &addr);
234 zdreq.addr = addr;
235 zdreq.cmd = ZM_IOCTL_TALLY;
236 } else if (!strcmp(argv[2], "rts")) {
237 sscanf(argv[3], "%d", &addr);
238 zdreq.addr = addr;
239 zdreq.cmd = ZM_IOCTL_RTS;
240 } else if (!strcmp(argv[2], "mix")) {
241 zdreq.cmd = ZM_IOCTL_MIX_MODE;
242 } else if (!strcmp(argv[2], "frag")) {
243 sscanf(argv[3], "%d", &addr);
244 zdreq.addr = addr;
245 zdreq.cmd = ZM_IOCTL_FRAG;
246 } else if (!strcmp(argv[2], "scan")) {
247 zdreq.cmd = ZM_IOCTL_SCAN;
248 } else if (!strcmp(argv[2], "skey")) {
249 zdreq.cmd = ZM_IOCTL_KEY;
251 if (argc >= 4) {
252 unsigned char temp[29];
253 int i;
254 int keyLen;
255 int encType;
257 keyLen = strlen(argv[3]);
259 if (keyLen == 10)
260 sscanf(argv[3], "%02x%02x%02x%02x%02x",
261 &temp[0], &temp[1], &temp[2], &temp[3],
262 &temp[4]);
263 else if (keyLen == 26)
264 sscanf(argv[3], "%02x%02x%02x%02x%02x%02x"
265 "%02x%02x%02x%02x%02x%02x%02x",
266 &temp[0], &temp[1], &temp[2], &temp[3],
267 &temp[4], &temp[5], &temp[6], &temp[7],
268 &temp[8], &temp[9], &temp[10],
269 &temp[11], &temp[12]);
270 else if (keyLen == 58)
271 sscanf(argv[3], "%02x%02x%02x%02x%02x%02x"
272 "%02x%02x%02x%02x%02x%02x%02x%02x%02x"
273 "%02x%02x%02x%02x%02x%02x%02x%02x%02x"
274 "%02x%02x%02x%02x%02x",
275 &temp[0], &temp[1], &temp[2], &temp[3],
276 &temp[4], &temp[5], &temp[6], &temp[7],
277 &temp[8], &temp[9], &temp[10],
278 &temp[11], &temp[12], &temp[13],
279 &temp[14], &temp[15], &temp[16],
280 &temp[17], &temp[18], &temp[19],
281 &temp[20], &temp[21], &temp[22],
282 &temp[23], &temp[24], &temp[25],
283 &temp[26], &temp[27], &temp[28]);
284 else {
285 fprintf(stderr, "Invalid key length\n");
286 exit(1);
288 zdreq.addr = keyLen/2;
290 for (i = 0; i < zdreq.addr; i++)
291 zdreq.data[i] = temp[i];
292 } else {
293 printf("Error : Key required!\n");
295 } else if (!strcmp(argv[2], "rate")) {
296 sscanf(argv[3], "%d", &addr);
298 if (addr > 28) {
299 fprintf(stderr, "Invalid rate, range:0~28\n");
300 exit(1);
302 zdreq.addr = addr;
303 zdreq.cmd = ZM_IOCTL_RATE;
304 } else if (!strcmp(argv[2], "enc")) {
305 sscanf(argv[3], "%d", &addr);
307 if (addr > 3) {
308 fprintf(stderr, "Invalid encryption mode, range:0~3\n");
309 exit(1);
312 if (addr == 2)
313 addr = 5;
314 else if (addr == 3)
315 addr = 6;
317 zdreq.addr = addr;
318 zdreq.cmd = ZM_IOCTL_ENCRYPTION_MODE;
319 } else if (!strcmp(argv[2], "txcnt")) {
320 zdreq.cmd = ZM_IOCTL_GET_TXCNT;
321 } else if (!strcmp(argv[2], "dagcnt")) {
322 sscanf(argv[3], "%d", &addr);
324 if (addr != 0 && addr != 1) {
325 fprintf(stderr, "The value should be 0 or 1\n");
326 exit(0);
329 zdreq.addr = addr;
330 zdreq.cmd = ZM_IOCTL_GET_DEAGG_CNT;
331 } else if (!strcmp(argv[2], "durmode")) {
332 sscanf(argv[3], "%d", &addr);
334 if (addr != 0 && addr != 1) {
335 fprintf(stderr, "The Duration mode should be 0 or 1\n");
336 exit(0);
339 zdreq.addr = addr;
340 zdreq.cmd = ZM_IOCTL_DURATION_MODE;
341 } else if (!strcmp(argv[2], "aeskey")) {
342 unsigned char temp[16];
343 int i;
345 sscanf(argv[3], "%d", &addr);
347 sscanf(argv[4], "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
348 "%02x%02x%02x%02x%02x%02x", &temp[0], &temp[1],
349 &temp[2], &temp[3], &temp[4], &temp[5], &temp[6],
350 &temp[7], &temp[8], &temp[9], &temp[10], &temp[11],
351 &temp[12], &temp[13], &temp[14], &temp[15]);
353 for (i = 0; i < 16; i++)
354 zdreq.data[i] = temp[i];
356 zdreq.addr = addr;
357 zdreq.cmd = ZM_IOCTL_SET_AES_KEY;
358 } else if (!strcmp(argv[2], "aesmode")) {
359 sscanf(argv[3], "%d", &addr);
361 zdreq.addr = addr;
362 zdreq.cmd = ZM_IOCTL_SET_AES_MODE;
363 } else if (!strcmp(argv[2], "wlanmode")) {
364 sscanf(argv[3], "%d", &addr);
366 zdreq.addr = addr;
367 zdreq.cmd = ZM_IOCTL_SET_PIBSS_MODE;
368 } else {
369 fprintf(stderr, "error action\n");
370 exit(1);
373 req.ifr_data = (char *)&zdreq;
374 set_ioctl(sock, &req);
376 fail:
377 exit(0);