diff options
Diffstat (limited to 'src/transport/gnunet-transport-wlan-helper.c')
-rw-r--r-- | src/transport/gnunet-transport-wlan-helper.c | 205 |
1 files changed, 203 insertions, 2 deletions
diff --git a/src/transport/gnunet-transport-wlan-helper.c b/src/transport/gnunet-transport-wlan-helper.c index 87c140825..4332e9a0d 100644 --- a/src/transport/gnunet-transport-wlan-helper.c +++ b/src/transport/gnunet-transport-wlan-helper.c | |||
@@ -27,11 +27,23 @@ | |||
27 | * This program serves as the mediator between the wlan interface and | 27 | * This program serves as the mediator between the wlan interface and |
28 | * gnunet | 28 | * gnunet |
29 | */ | 29 | */ |
30 | #include "gnunet-transport-wlan-helper.h" | 30 | |
31 | |||
32 | #include "platform.h" | ||
33 | #include "gnunet_constants.h" | ||
34 | #include "gnunet_os_lib.h" | ||
35 | #include "gnunet_transport_plugin.h" | ||
36 | #include "transport.h" | ||
31 | #include "plugin_transport_wlan.h" | 37 | #include "plugin_transport_wlan.h" |
38 | #include "gnunet_common.h" | ||
39 | #include "gnunet-transport-wlan-helper.h" | ||
32 | #include "ieee80211_radiotap.h" | 40 | #include "ieee80211_radiotap.h" |
33 | |||
34 | #include <pcap.h> | 41 | #include <pcap.h> |
42 | #include <stdio.h> | ||
43 | #include <stdlib.h> | ||
44 | #include <sys/stat.h> | ||
45 | |||
46 | |||
35 | 47 | ||
36 | 48 | ||
37 | 49 | ||
@@ -380,11 +392,200 @@ int ieee80211_radiotap_iterator_next( | |||
380 | return -ENOENT; | 392 | return -ENOENT; |
381 | } | 393 | } |
382 | 394 | ||
395 | #define FIFO_FILE1 "MYFIFOin" | ||
396 | #define FIFO_FILE2 "MYFIFOout" | ||
397 | #define MAXLINE 5000 | ||
398 | |||
399 | int closeprog = 0; | ||
400 | |||
401 | void sigfunc(int sig) | ||
402 | { | ||
403 | |||
404 | if(sig != SIGINT || sig != SIGTERM || sig != SIGKILL) | ||
405 | return; | ||
406 | else | ||
407 | { | ||
408 | closeprog = 1; | ||
409 | } | ||
410 | } | ||
411 | |||
412 | |||
413 | |||
414 | int | ||
415 | testmode(int argc, char *argv[]) | ||
416 | { | ||
417 | struct stat st; | ||
418 | int erg; | ||
419 | int first; | ||
420 | FILE *fpin; | ||
421 | FILE *fpout; | ||
422 | pid_t pid; | ||
423 | |||
424 | signal(SIGINT,sigfunc); | ||
425 | signal(SIGTERM,sigfunc); | ||
426 | signal(SIGKILL,sigfunc); | ||
427 | |||
428 | //make the fifos if needed | ||
429 | if (stat(FIFO_FILE1, &st) != 0) | ||
430 | { | ||
431 | if (stat(FIFO_FILE2, &st) != 0) | ||
432 | { | ||
433 | perror("FIFO 2 exists, but FIFO 1 not"); | ||
434 | exit(1); | ||
435 | } | ||
436 | first = 1; | ||
437 | umask(0); | ||
438 | erg = mknod(FIFO_FILE1, S_IFIFO | 0666, 0); | ||
439 | erg = mknod(FIFO_FILE2, S_IFIFO | 0666, 0); | ||
440 | |||
441 | if ((fpin = fopen(FIFO_FILE1, "r")) == NULL) | ||
442 | { | ||
443 | perror("fopen"); | ||
444 | exit(1); | ||
445 | } | ||
446 | if ((fpout = fopen(FIFO_FILE2, "w")) == NULL) | ||
447 | { | ||
448 | perror("fopen"); | ||
449 | exit(1); | ||
450 | } | ||
451 | } | ||
452 | else | ||
453 | { | ||
454 | first = 0; | ||
455 | if (stat(FIFO_FILE2, &st) == 0) | ||
456 | { | ||
457 | perror("FIFO 1 exists, but FIFO 2 not"); | ||
458 | exit(1); | ||
459 | } | ||
460 | if ((fpout = fopen(FIFO_FILE1, "w")) == NULL) | ||
461 | { | ||
462 | perror("fopen"); | ||
463 | exit(1); | ||
464 | } | ||
465 | if ((fpin = fopen(FIFO_FILE2, "r")) == NULL) | ||
466 | { | ||
467 | perror("fopen"); | ||
468 | exit(1); | ||
469 | } | ||
470 | |||
471 | } | ||
472 | |||
473 | // fork | ||
474 | |||
475 | if ((pid = fork()) < 0) | ||
476 | { | ||
477 | perror("FORK ERROR"); | ||
478 | |||
479 | //clean up | ||
480 | if (first == 1) | ||
481 | { | ||
482 | unlink(FIFO_FILE1); | ||
483 | unlink(FIFO_FILE2); | ||
484 | } | ||
485 | fclose(fpin); | ||
486 | fclose(fpout); | ||
487 | return -3; | ||
488 | } | ||
489 | else if (pid == 0) // CHILD PROCESS | ||
490 | { | ||
491 | int rv = 0; | ||
492 | int readc = 0; | ||
493 | int pos = 0; | ||
494 | char line[MAXLINE]; | ||
495 | |||
496 | while (closeprog == 0) | ||
497 | { | ||
498 | readc = 0; | ||
499 | |||
500 | while (readc < sizeof( struct RadiotapHeader) + sizeof(struct GNUNET_MessageHeader)){ | ||
501 | if ((rv = read(STDIN_FILENO, line, MAXLINE)) < 0) | ||
502 | { | ||
503 | perror("READ ERROR FROM STDIN"); | ||
504 | } | ||
505 | readc += rv; | ||
506 | } | ||
507 | |||
508 | pos = 0; | ||
509 | |||
510 | fwrite(&line[pos], 1, sizeof(struct GNUNET_MessageHeader), fpout); | ||
511 | |||
512 | pos += sizeof(struct GNUNET_MessageHeader); | ||
513 | |||
514 | //do not send radiotap header | ||
515 | pos += sizeof( struct RadiotapHeader); | ||
516 | |||
517 | while (pos < readc) | ||
518 | { | ||
519 | pos += fwrite(&line[pos], 1, readc - pos, fpout); | ||
520 | } | ||
521 | } | ||
522 | |||
523 | |||
524 | //clean up | ||
525 | fclose(fpout); | ||
526 | } | ||
527 | else // PARENT PROCESS | ||
528 | { | ||
529 | int rv = 0; | ||
530 | ssize_t pos = 0; | ||
531 | char line[MAXLINE]; | ||
532 | struct Wlan_Helper_Control_Message macmsg; | ||
533 | |||
534 | |||
535 | //Send random mac address | ||
536 | macmsg.mac.mac[0] = 0x13; | ||
537 | macmsg.mac.mac[1] = 0x22; | ||
538 | macmsg.mac.mac[2] = 0x33; | ||
539 | macmsg.mac.mac[3] = 0x44; | ||
540 | macmsg.mac.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 255); | ||
541 | macmsg.mac.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 255); | ||
542 | macmsg.hdr.size = sizeof(struct Wlan_Helper_Control_Message); | ||
543 | |||
544 | pos = 0; | ||
545 | while (pos < sizeof(struct Wlan_Helper_Control_Message)) | ||
546 | { | ||
547 | pos += write(STDOUT_FILENO, &macmsg + pos, sizeof(struct Wlan_Helper_Control_Message) - pos); | ||
548 | } | ||
549 | |||
550 | while (closeprog == 0) | ||
551 | { | ||
552 | if ((rv = fread(line, 1, MAXLINE, fpin)) < 0) | ||
553 | { | ||
554 | perror("READ ERROR FROM fpin"); | ||
555 | } | ||
556 | |||
557 | pos = 0; | ||
558 | while (pos < rv) | ||
559 | { | ||
560 | pos += write(STDOUT_FILENO, &line[pos], rv - pos); | ||
561 | } | ||
562 | } | ||
563 | |||
564 | |||
565 | //clean up | ||
566 | fclose(fpin); | ||
567 | |||
568 | if (first == 1) | ||
569 | { | ||
570 | unlink(FIFO_FILE1); | ||
571 | unlink(FIFO_FILE2); | ||
572 | } | ||
573 | } | ||
574 | |||
575 | // Write the input to the output | ||
576 | |||
577 | return (0); | ||
578 | } | ||
383 | 579 | ||
384 | 580 | ||
385 | int | 581 | int |
386 | main(int argc, char *argv[]) | 582 | main(int argc, char *argv[]) |
387 | { | 583 | { |
584 | if ((argc==3) && (strstr(argv[2],"1"))) | ||
585 | { | ||
586 | return testmode(argc, argv); | ||
587 | } | ||
588 | |||
388 | u8 u8aSendBuffer[500]; | 589 | u8 u8aSendBuffer[500]; |
389 | char szErrbuf[PCAP_ERRBUF_SIZE]; | 590 | char szErrbuf[PCAP_ERRBUF_SIZE]; |
390 | int nCaptureHeaderLength = 0, n80211HeaderLength = 0, nLinkEncap = 0; | 591 | int nCaptureHeaderLength = 0, n80211HeaderLength = 0, nLinkEncap = 0; |