Staging: otus: wrap_sec: remove casts from void*
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / staging / otus / apdbg.c
CommitLineData
4bd43f50
LR
1/*
2 * Copyright (c) 2007-2008 Atheros Communications Inc.
3 *
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.
7 *
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.
15 */
16/* */
17/* Module Name : apdbg.c */
18/* */
19/* Abstract */
20/* Debug tools */
21/* */
22/* NOTES */
23/* None */
24/* */
25/************************************************************************/
26
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>
38
39#include <linux/sockios.h>
40
b767fa1d
MT
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
4bd43f50
LR
69
70struct zdap_ioctl {
b767fa1d
MT
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 */
4bd43f50
LR
74 unsigned char data[0x100];
75};
76
77/* Declaration of macro and function for handling WEP Keys */
78
79#if 0
80
81#define SKIP_ELEM { \
b767fa1d
MT
82 while (isxdigit(*p)) \
83 p++; \
4bd43f50
LR
84}
85
86#define SKIP_DELIMETER { \
b767fa1d
MT
87 if (*p == ':' || *p == ' ') \
88 p++; \
4bd43f50
LR
89}
90
91#endif
92
cb138876
TF
93static char hex(char v)
94{
95 if (isdigit(v))
96 return v - '0';
97 else if (isxdigit(v))
98 return tolower(v) - 'a' + 10;
99 else
100 return 0;
101}
102
103static unsigned char asctohex(char *str)
104{
105 unsigned char value;
106
107 value = hex(*str) & 0x0f;
108 value = value << 4;
109 str++;
110 value |= hex(*str) & 0x0f;
111
112 return value;
113}
4bd43f50
LR
114
115char *prgname;
116
117int set_ioctl(int sock, struct ifreq *req)
118{
b767fa1d
MT
119 if (ioctl(sock, ZDAPIOCTL, req) < 0) {
120 fprintf(stderr, "%s: ioctl(SIOCGIFMAP): %s\n",
121 prgname, strerror(errno));
122 return -1;
123 }
4bd43f50 124
b767fa1d 125 return 0;
4bd43f50
LR
126}
127
128
129int read_reg(int sock, struct ifreq *req)
130{
cb138876 131 struct zdap_ioctl *zdreq = NULL;
4bd43f50 132
b767fa1d 133 if (!set_ioctl(sock, req))
cb138876 134 return -1;
4bd43f50 135
b767fa1d
MT
136 /*
137 * zdreq = (struct zdap_ioctl *)req->ifr_data;
138 * printf( "reg = %4x, value = %4x\n", zdreq->addr, zdreq->value);
139 */
4bd43f50 140
b767fa1d 141 return 0;
4bd43f50
LR
142}
143
144
145int read_mem(int sock, struct ifreq *req)
146{
cb138876 147 struct zdap_ioctl *zdreq = NULL;
b767fa1d
MT
148 int i;
149
150 if (!set_ioctl(sock, req))
151 return -1;
152
153 /*
154 * zdreq = (struct zdap_ioctl *)req->ifr_data;
155 * printf("dump mem from %x, length = %x\n", zdreq->addr, zdreq->value);
156 *
157 * for (i=0; i<zdreq->value; i++) {
158 * printf("%02x", zdreq->data[i]);
159 * printf(" ");
160 *
161 * if ((i>0) && ((i+1)%16 == 0))
162 * printf("\n");
163 * }
164 */
165
166 return 0;
4bd43f50
LR
167}
168
169
170int main(int argc, char **argv)
171{
b767fa1d
MT
172 int sock;
173 int addr, value;
174 struct ifreq req;
175 char *action = NULL;
176 struct zdap_ioctl zdreq;
177
178 prgname = argv[0];
179
180 if (argc < 3) {
181 fprintf(stderr, "%s: usage is \"%s <ifname> <operation>"
182 "[<address>] [<value>]\"\n", prgname, prgname);
fa3620c5 183 fprintf(stderr, "valid operation : read, write, mem, reg,\n");
b767fa1d
MT
184 fprintf(stderr, " : txd, rxd, rmem, wmem\n");
185 fprintf(stderr, " : dmat, regt, test\n");
186
187 fprintf(stderr, " scan, Channel Scan\n");
188 fprintf(stderr, " rts <decimal>, Set RTS Threshold\n");
189 fprintf(stderr, " frag <decimal>, Set Fragment"
190 " Threshold\n");
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"
194 " mixed mode\n");
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 "
201 "0=>HW, 1=>SW\n");
202 fprintf(stderr, " aeskey <user> <key>\n");
203 fprintf(stderr, " aesmode <mode>\n");
204 fprintf(stderr, " wlanmode <0,1> 0:Station mode, "
205 "1:PIBSS mode\n");
206 fprintf(stderr, " tal <0,1>, Get Current Tally Info, "
207 "0=>read, 1=>read and reset\n");
208
209 exit(1);
210 }
211
212 strcpy(req.ifr_name, argv[1]);
213 zdreq.addr = 0;
214 zdreq.value = 0;
215
216 /* a silly raw socket just for ioctl()ling it */
217 sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
218 if (sock < 0) {
219 fprintf(stderr, "%s: socket(): %s\n", argv[0], strerror(errno));
220 exit(1);
221 }
222
223 if (argc >= 4)
224 sscanf(argv[3], "%x", &addr);
225
226 if (argc >= 5)
227 sscanf(argv[4], "%x", &value);
228
229 zdreq.addr = addr;
230 zdreq.value = value;
231
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);
256 zdreq.addr = addr;
257 zdreq.cmd = ZM_IOCTL_TALLY;
258 } else if (!strcmp(argv[2], "rts")) {
259 sscanf(argv[3], "%d", &addr);
260 zdreq.addr = 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);
266 zdreq.addr = 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;
272
273 if (argc >= 4) {
274 unsigned char temp[29];
275 int i;
276 int keyLen;
277 int encType;
278
279 keyLen = strlen(argv[3]);
280
281 if (keyLen == 10)
282 sscanf(argv[3], "%02x%02x%02x%02x%02x",
283 &temp[0], &temp[1], &temp[2], &temp[3],
284 &temp[4]);
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]);
306 else {
307 fprintf(stderr, "Invalid key length\n");
308 exit(1);
309 }
310 zdreq.addr = keyLen/2;
311
312 for (i = 0; i < zdreq.addr; i++)
313 zdreq.data[i] = temp[i];
314 } else {
315 printf("Error : Key required!\n");
316 }
317 } else if (!strcmp(argv[2], "rate")) {
318 sscanf(argv[3], "%d", &addr);
319
320 if (addr > 28) {
321 fprintf(stderr, "Invalid rate, range:0~28\n");
322 exit(1);
323 }
324 zdreq.addr = addr;
325 zdreq.cmd = ZM_IOCTL_RATE;
326 } else if (!strcmp(argv[2], "enc")) {
327 sscanf(argv[3], "%d", &addr);
328
329 if (addr > 3) {
330 fprintf(stderr, "Invalid encryption mode, range:0~3\n");
331 exit(1);
332 }
333
334 if (addr == 2)
335 addr = 5;
336 else if (addr == 3)
337 addr = 6;
338
339 zdreq.addr = addr;
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);
345
346 if (addr != 0 && addr != 1) {
347 fprintf(stderr, "The value should be 0 or 1\n");
348 exit(0);
349 }
350
351 zdreq.addr = addr;
352 zdreq.cmd = ZM_IOCTL_GET_DEAGG_CNT;
353 } else if (!strcmp(argv[2], "durmode")) {
354 sscanf(argv[3], "%d", &addr);
355
356 if (addr != 0 && addr != 1) {
357 fprintf(stderr, "The Duration mode should be 0 or 1\n");
358 exit(0);
359 }
360
361 zdreq.addr = addr;
362 zdreq.cmd = ZM_IOCTL_DURATION_MODE;
363 } else if (!strcmp(argv[2], "aeskey")) {
364 unsigned char temp[16];
365 int i;
366
367 sscanf(argv[3], "%d", &addr);
368
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]);
374
375 for (i = 0; i < 16; i++)
376 zdreq.data[i] = temp[i];
377
378 zdreq.addr = addr;
379 zdreq.cmd = ZM_IOCTL_SET_AES_KEY;
380 } else if (!strcmp(argv[2], "aesmode")) {
381 sscanf(argv[3], "%d", &addr);
382
383 zdreq.addr = addr;
384 zdreq.cmd = ZM_IOCTL_SET_AES_MODE;
385 } else if (!strcmp(argv[2], "wlanmode")) {
386 sscanf(argv[3], "%d", &addr);
387
388 zdreq.addr = addr;
389 zdreq.cmd = ZM_IOCTL_SET_PIBSS_MODE;
cb138876 390 } else {
b767fa1d
MT
391 fprintf(stderr, "error action\n");
392 exit(1);
393 }
394
395 req.ifr_data = (char *)&zdreq;
396 set_ioctl(sock, &req);
4bd43f50
LR
397
398fail:
b767fa1d 399 exit(0);
4bd43f50
LR
400}
401