|
Lines 70-75
Link Here
|
| 70 |
static void wi_printbool __P((struct wi_req *)); |
70 |
static void wi_printbool __P((struct wi_req *)); |
| 71 |
static void wi_printhex __P((struct wi_req *)); |
71 |
static void wi_printhex __P((struct wi_req *)); |
| 72 |
static void wi_dumpinfo __P((char *)); |
72 |
static void wi_dumpinfo __P((char *)); |
|
|
73 |
static void wi_setkeys __P((char *, char *, int)); |
| 74 |
static void wi_printkeys __P((struct wi_req *)); |
| 73 |
static void usage __P((char *)); |
75 |
static void usage __P((char *)); |
| 74 |
|
76 |
|
| 75 |
static void wi_getval(iface, wreq) |
77 |
static void wi_getval(iface, wreq) |
|
Lines 236-241
Link Here
|
| 236 |
return; |
238 |
return; |
| 237 |
} |
239 |
} |
| 238 |
|
240 |
|
|
|
241 |
static int wi_hex2int(c) |
| 242 |
char c; |
| 243 |
{ |
| 244 |
if (c >= '0' && c <= '9') |
| 245 |
return (c - '0'); |
| 246 |
if (c >= 'A' && c <= 'F') |
| 247 |
return (c - 'A' + 10); |
| 248 |
if (c >= 'a' && c <= 'f') |
| 249 |
return (c - 'a' + 10); |
| 250 |
|
| 251 |
return (0); |
| 252 |
} |
| 253 |
|
| 254 |
static void wi_str2key(s, k) |
| 255 |
char *s; |
| 256 |
struct wi_key *k; |
| 257 |
{ |
| 258 |
int n, i; |
| 259 |
char *p; |
| 260 |
|
| 261 |
/* Is this a hex string? */ |
| 262 |
if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) { |
| 263 |
/* Yes, convert to int. */ |
| 264 |
n = 0; |
| 265 |
p = (char *)&k->wi_keydat[0]; |
| 266 |
for (i = 2; i < strlen(s); i+= 2) { |
| 267 |
*p++ = (wi_hex2int(s[i]) << 4) + wi_hex2int(s[i + 1]); |
| 268 |
n++; |
| 269 |
} |
| 270 |
k->wi_keylen = n; |
| 271 |
} else { |
| 272 |
/* No, just copy it in. */ |
| 273 |
bcopy(s, k->wi_keydat, strlen(s)); |
| 274 |
k->wi_keylen = strlen(s); |
| 275 |
} |
| 276 |
|
| 277 |
return; |
| 278 |
} |
| 279 |
|
| 280 |
static void wi_setkeys(iface, key, idx) |
| 281 |
char *iface; |
| 282 |
char *key; |
| 283 |
int idx; |
| 284 |
{ |
| 285 |
struct wi_req wreq; |
| 286 |
struct wi_ltv_keys *keys; |
| 287 |
struct wi_key *k; |
| 288 |
|
| 289 |
bzero((char *)&wreq, sizeof(wreq)); |
| 290 |
wreq.wi_len = WI_MAX_DATALEN; |
| 291 |
wreq.wi_type = WI_RID_WEP_AVAIL; |
| 292 |
|
| 293 |
wi_getval(iface, &wreq); |
| 294 |
if (wreq.wi_val[0] == 0) |
| 295 |
err(1, "no WEP option available on this card"); |
| 296 |
|
| 297 |
bzero((char *)&wreq, sizeof(wreq)); |
| 298 |
wreq.wi_len = WI_MAX_DATALEN; |
| 299 |
wreq.wi_type = WI_RID_DEFLT_CRYPT_KEYS; |
| 300 |
|
| 301 |
wi_getval(iface, &wreq); |
| 302 |
keys = (struct wi_ltv_keys *)&wreq; |
| 303 |
|
| 304 |
if (strlen(key) > 14) { |
| 305 |
err(1, "encryption key must be no " |
| 306 |
"more than 14 characters long"); |
| 307 |
} |
| 308 |
|
| 309 |
if (idx > 3) |
| 310 |
err(1, "only 4 encryption keys available"); |
| 311 |
|
| 312 |
k = &keys->wi_keys[idx]; |
| 313 |
wi_str2key(key, k); |
| 314 |
|
| 315 |
wreq.wi_len = (sizeof(struct wi_ltv_keys) / 2) + 1; |
| 316 |
wreq.wi_type = WI_RID_DEFLT_CRYPT_KEYS; |
| 317 |
wi_setval(iface, &wreq); |
| 318 |
|
| 319 |
return; |
| 320 |
} |
| 321 |
|
| 322 |
static void wi_printkeys(wreq) |
| 323 |
struct wi_req *wreq; |
| 324 |
{ |
| 325 |
int i, j; |
| 326 |
struct wi_key *k; |
| 327 |
struct wi_ltv_keys *keys; |
| 328 |
char *ptr; |
| 329 |
|
| 330 |
keys = (struct wi_ltv_keys *)wreq; |
| 331 |
|
| 332 |
for (i = 0; i < 4; i++) { |
| 333 |
k = &keys->wi_keys[i]; |
| 334 |
ptr = (char *)k->wi_keydat; |
| 335 |
for (j = 0; j < k->wi_keylen; j++) { |
| 336 |
if (ptr[i] == '\0') |
| 337 |
ptr[i] = ' '; |
| 338 |
} |
| 339 |
ptr[j] = '\0'; |
| 340 |
printf("[ %s ]", ptr); |
| 341 |
} |
| 342 |
|
| 343 |
return; |
| 344 |
}; |
| 345 |
|
| 239 |
void wi_printwords(wreq) |
346 |
void wi_printwords(wreq) |
| 240 |
struct wi_req *wreq; |
347 |
struct wi_req *wreq; |
| 241 |
{ |
348 |
{ |
|
Lines 283-288
Link Here
|
| 283 |
#define WI_BOOL 0x02 |
390 |
#define WI_BOOL 0x02 |
| 284 |
#define WI_WORDS 0x03 |
391 |
#define WI_WORDS 0x03 |
| 285 |
#define WI_HEXBYTES 0x04 |
392 |
#define WI_HEXBYTES 0x04 |
|
|
393 |
#define WI_KEYSTRUCT 0x05 |
| 286 |
|
394 |
|
| 287 |
struct wi_table { |
395 |
struct wi_table { |
| 288 |
int wi_code; |
396 |
int wi_code; |
|
Lines 304-310
Link Here
|
| 304 |
{ WI_RID_PROMISC, WI_BOOL, "Promiscuous mode:\t\t\t" }, |
412 |
{ WI_RID_PROMISC, WI_BOOL, "Promiscuous mode:\t\t\t" }, |
| 305 |
{ WI_RID_PORTTYPE, WI_WORDS, "Port type (1=BSS, 3=ad-hoc):\t\t"}, |
413 |
{ WI_RID_PORTTYPE, WI_WORDS, "Port type (1=BSS, 3=ad-hoc):\t\t"}, |
| 306 |
{ WI_RID_MAC_NODE, WI_HEXBYTES, "MAC address:\t\t\t\t"}, |
414 |
{ WI_RID_MAC_NODE, WI_HEXBYTES, "MAC address:\t\t\t\t"}, |
| 307 |
{ WI_RID_TX_RATE, WI_WORDS, "TX rate:\t\t\t\t"}, |
415 |
{ WI_RID_TX_RATE, WI_WORDS, "TX rate (selection):\t\t\t"}, |
|
|
416 |
{ WI_RID_CUR_TX_RATE, WI_WORDS, "TX rate (actual speed):\t\t\t"}, |
| 308 |
{ WI_RID_RTS_THRESH, WI_WORDS, "RTS/CTS handshake threshold:\t\t"}, |
417 |
{ WI_RID_RTS_THRESH, WI_WORDS, "RTS/CTS handshake threshold:\t\t"}, |
| 309 |
{ WI_RID_CREATE_IBSS, WI_BOOL, "Create IBSS:\t\t\t\t" }, |
418 |
{ WI_RID_CREATE_IBSS, WI_BOOL, "Create IBSS:\t\t\t\t" }, |
| 310 |
{ WI_RID_SYSTEM_SCALE, WI_WORDS, "Access point density:\t\t\t" }, |
419 |
{ WI_RID_SYSTEM_SCALE, WI_WORDS, "Access point density:\t\t\t" }, |
|
Lines 313-325
Link Here
|
| 313 |
{ 0, NULL } |
422 |
{ 0, NULL } |
| 314 |
}; |
423 |
}; |
| 315 |
|
424 |
|
|
|
425 |
static struct wi_table wi_crypt_table[] = { |
| 426 |
{ WI_RID_ENCRYPTION, WI_BOOL, "WEP encryption:\t\t\t\t" }, |
| 427 |
{ WI_RID_TX_CRYPT_KEY, WI_WORDS, "TX encryption key:\t\t\t" }, |
| 428 |
{ WI_RID_DEFLT_CRYPT_KEYS, WI_KEYSTRUCT, "Encryption keys:\t\t\t" }, |
| 429 |
{ 0, NULL } |
| 430 |
}; |
| 431 |
|
| 316 |
static void wi_dumpinfo(iface) |
432 |
static void wi_dumpinfo(iface) |
| 317 |
char *iface; |
433 |
char *iface; |
| 318 |
{ |
434 |
{ |
| 319 |
struct wi_req wreq; |
435 |
struct wi_req wreq; |
| 320 |
int i; |
436 |
int i, has_wep; |
| 321 |
struct wi_table *w; |
437 |
struct wi_table *w; |
| 322 |
|
438 |
|
|
|
439 |
bzero((char *)&wreq, sizeof(wreq)); |
| 440 |
|
| 441 |
wreq.wi_len = WI_MAX_DATALEN; |
| 442 |
wreq.wi_type = WI_RID_WEP_AVAIL; |
| 443 |
|
| 444 |
wi_getval(iface, &wreq); |
| 445 |
has_wep = wreq.wi_val[0]; |
| 446 |
|
| 323 |
w = wi_table; |
447 |
w = wi_table; |
| 324 |
|
448 |
|
| 325 |
for (i = 0; w[i].wi_type; i++) { |
449 |
for (i = 0; w[i].wi_type; i++) { |
|
Lines 345-354
Link Here
|
| 345 |
break; |
469 |
break; |
| 346 |
default: |
470 |
default: |
| 347 |
break; |
471 |
break; |
| 348 |
printf("\n"); |
472 |
printf("\n"); |
| 349 |
} |
473 |
} |
| 350 |
|
474 |
|
|
|
475 |
if (has_wep) { |
| 476 |
w = wi_crypt_table; |
| 477 |
for (i = 0; w[i].wi_type; i++) { |
| 478 |
bzero((char *)&wreq, sizeof(wreq)); |
| 479 |
|
| 480 |
wreq.wi_len = WI_MAX_DATALEN; |
| 481 |
wreq.wi_type = w[i].wi_code; |
| 482 |
|
| 483 |
wi_getval(iface, &wreq); |
| 484 |
printf("%s", w[i].wi_str); |
| 485 |
switch(w[i].wi_type) { |
| 486 |
case WI_STRING: |
| 487 |
wi_printstr(&wreq); |
| 488 |
break; |
| 489 |
case WI_WORDS: |
| 490 |
if (wreq.wi_type == WI_RID_TX_CRYPT_KEY) |
| 491 |
wreq.wi_val[0]++; |
| 492 |
wi_printwords(&wreq); |
| 493 |
break; |
| 494 |
case WI_BOOL: |
| 495 |
wi_printbool(&wreq); |
| 496 |
break; |
| 497 |
case WI_HEXBYTES: |
| 498 |
wi_printhex(&wreq); |
| 499 |
break; |
| 500 |
case WI_KEYSTRUCT: |
| 501 |
wi_printkeys(&wreq); |
| 502 |
break; |
| 503 |
default: |
| 504 |
break; |
| 505 |
} |
| 506 |
printf("\n"); |
| 507 |
} |
| 508 |
} |
| 509 |
|
| 351 |
return; |
510 |
return; |
| 352 |
} |
511 |
} |
| 353 |
|
512 |
|
|
Lines 426-436
Link Here
|
| 426 |
fprintf(stderr, "\t%s -i iface -p port type\n", p); |
585 |
fprintf(stderr, "\t%s -i iface -p port type\n", p); |
| 427 |
fprintf(stderr, "\t%s -i iface -a access point density\n", p); |
586 |
fprintf(stderr, "\t%s -i iface -a access point density\n", p); |
| 428 |
fprintf(stderr, "\t%s -i iface -m mac address\n", p); |
587 |
fprintf(stderr, "\t%s -i iface -m mac address\n", p); |
|
|
588 |
fprintf(stderr, "\t%s -i iface -e 0|1\n", p); |
| 589 |
fprintf(stderr, "\t%s -i iface -k encryption key [-v 1|2|3|4]\n", p); |
| 429 |
fprintf(stderr, "\t%s -i iface -d max data length\n", p); |
590 |
fprintf(stderr, "\t%s -i iface -d max data length\n", p); |
| 430 |
fprintf(stderr, "\t%s -i iface -r RTS threshold\n", p); |
591 |
fprintf(stderr, "\t%s -i iface -r RTS threshold\n", p); |
| 431 |
fprintf(stderr, "\t%s -i iface -f frequency\n", p); |
592 |
fprintf(stderr, "\t%s -i iface -f frequency\n", p); |
| 432 |
fprintf(stderr, "\t%s -i iface -P 0|1t\n", p); |
593 |
fprintf(stderr, "\t%s -i iface -P 0|1t\n", p); |
| 433 |
fprintf(stderr, "\t%s -i iface -S max sleep duration\n", p); |
594 |
fprintf(stderr, "\t%s -i iface -S max sleep duration\n", p); |
|
|
595 |
fprintf(stderr, "\t%s -i iface -T 1|2|3|4\n", p); |
| 434 |
|
596 |
|
| 435 |
exit(1); |
597 |
exit(1); |
| 436 |
} |
598 |
} |
|
Lines 442-450
Link Here
|
| 442 |
int ch; |
604 |
int ch; |
| 443 |
char *iface = NULL; |
605 |
char *iface = NULL; |
| 444 |
char *p = argv[0]; |
606 |
char *p = argv[0]; |
|
|
607 |
char *key = NULL; |
| 608 |
int modifier = 0; |
| 445 |
|
609 |
|
| 446 |
while((ch = getopt(argc, argv, |
610 |
while((ch = getopt(argc, argv, |
| 447 |
"hoc:d:f:i:p:r:q:t:n:s:m:P:S:")) != -1) { |
611 |
"hoc:d:e:f:i:k:p:r:q:t:n:s:m:v:P:S:T:")) != -1) { |
| 448 |
switch(ch) { |
612 |
switch(ch) { |
| 449 |
case 'o': |
613 |
case 'o': |
| 450 |
wi_dumpstats(iface); |
614 |
wi_dumpstats(iface); |
|
Lines 461-470
Link Here
|
| 461 |
wi_setword(iface, WI_RID_MAX_DATALEN, atoi(optarg)); |
625 |
wi_setword(iface, WI_RID_MAX_DATALEN, atoi(optarg)); |
| 462 |
exit(0); |
626 |
exit(0); |
| 463 |
break; |
627 |
break; |
|
|
628 |
case 'e': |
| 629 |
wi_setword(iface, WI_RID_ENCRYPTION, atoi(optarg)); |
| 630 |
exit(0); |
| 631 |
break; |
| 464 |
case 'f': |
632 |
case 'f': |
| 465 |
wi_setword(iface, WI_RID_OWN_CHNL, atoi(optarg)); |
633 |
wi_setword(iface, WI_RID_OWN_CHNL, atoi(optarg)); |
| 466 |
exit(0); |
634 |
exit(0); |
| 467 |
break; |
635 |
break; |
|
|
636 |
case 'k': |
| 637 |
key = optarg; |
| 638 |
break; |
| 468 |
case 'p': |
639 |
case 'p': |
| 469 |
wi_setword(iface, WI_RID_PORTTYPE, atoi(optarg)); |
640 |
wi_setword(iface, WI_RID_PORTTYPE, atoi(optarg)); |
| 470 |
exit(0); |
641 |
exit(0); |
|
Lines 497-506
Link Here
|
| 497 |
wi_setword(iface, WI_RID_MAX_SLEEP, atoi(optarg)); |
668 |
wi_setword(iface, WI_RID_MAX_SLEEP, atoi(optarg)); |
| 498 |
exit(0); |
669 |
exit(0); |
| 499 |
break; |
670 |
break; |
|
|
671 |
case 'T': |
| 672 |
wi_setword(iface, |
| 673 |
WI_RID_TX_CRYPT_KEY, atoi(optarg) - 1); |
| 674 |
exit(0); |
| 675 |
break; |
| 500 |
case 'P': |
676 |
case 'P': |
| 501 |
wi_setword(iface, WI_RID_PM_ENABLED, atoi(optarg)); |
677 |
wi_setword(iface, WI_RID_PM_ENABLED, atoi(optarg)); |
| 502 |
exit(0); |
678 |
exit(0); |
| 503 |
break; |
679 |
break; |
|
|
680 |
case 'v': |
| 681 |
modifier = atoi(optarg); |
| 682 |
modifier--; |
| 683 |
break; |
| 504 |
case 'h': |
684 |
case 'h': |
| 505 |
default: |
685 |
default: |
| 506 |
usage(p); |
686 |
usage(p); |
|
Lines 510-515
Link Here
|
| 510 |
|
690 |
|
| 511 |
if (iface == NULL) |
691 |
if (iface == NULL) |
| 512 |
usage(p); |
692 |
usage(p); |
|
|
693 |
|
| 694 |
if (key != NULL) { |
| 695 |
wi_setkeys(iface, key, modifier); |
| 696 |
exit(0); |
| 697 |
} |
| 513 |
|
698 |
|
| 514 |
wi_dumpinfo(iface); |
699 |
wi_dumpinfo(iface); |