diff options
author | Claudiu Olteanu <claudiu@140774ce-b5e7-0310-ab8b-a85725594a96> | 2013-07-08 16:57:37 +0000 |
---|---|---|
committer | Claudiu Olteanu <claudiu@140774ce-b5e7-0310-ab8b-a85725594a96> | 2013-07-08 16:57:37 +0000 |
commit | 25a298fc69343e06d7718e046e4c35bdce36a508 (patch) | |
tree | f65654b31476e75f98b0cfc1f0807a17f4399960 /src/transport/gnunet-helper-transport-bluetooth.c | |
parent | b1052370be3d455e7583ce35abdff4c7bfbd022c (diff) | |
download | gnunet-25a298fc69343e06d7718e046e4c35bdce36a508.tar.gz gnunet-25a298fc69343e06d7718e046e4c35bdce36a508.zip |
Implementing SDP protocol
Diffstat (limited to 'src/transport/gnunet-helper-transport-bluetooth.c')
-rw-r--r-- | src/transport/gnunet-helper-transport-bluetooth.c | 251 |
1 files changed, 191 insertions, 60 deletions
diff --git a/src/transport/gnunet-helper-transport-bluetooth.c b/src/transport/gnunet-helper-transport-bluetooth.c index 418cc9dec..a006cb7ab 100644 --- a/src/transport/gnunet-helper-transport-bluetooth.c +++ b/src/transport/gnunet-helper-transport-bluetooth.c | |||
@@ -72,6 +72,11 @@ struct HardwareInfos | |||
72 | * MAC address of our own bluetooth interface. | 72 | * MAC address of our own bluetooth interface. |
73 | */ | 73 | */ |
74 | struct GNUNET_TRANSPORT_WLAN_MacAddress pl_mac; | 74 | struct GNUNET_TRANSPORT_WLAN_MacAddress pl_mac; |
75 | |||
76 | /** | ||
77 | * SDP session | ||
78 | */ | ||
79 | sdp_session_t *session ; | ||
75 | }; | 80 | }; |
76 | 81 | ||
77 | /** | 82 | /** |
@@ -493,22 +498,21 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len) | |||
493 | 498 | ||
494 | /** | 499 | /** |
495 | * Function for assigning a port number | 500 | * Function for assigning a port number |
501 | * @param socket the socket used to bind | ||
502 | * @param addr pointer to the rfcomm address | ||
496 | * @return 0 on success | 503 | * @return 0 on success |
497 | */ | 504 | */ |
498 | static int | 505 | static int |
499 | bind_socket (int *socket) | 506 | bind_socket (int socket, struct sockaddr_rc *addr) |
500 | { | 507 | { |
501 | int port, status; | 508 | int port, status; |
502 | struct sockaddr_rc src = { 0 }; | ||
503 | |||
504 | src.rc_family = AF_BLUETOOTH; | ||
505 | src.rc_bdaddr = *BDADDR_ANY; | ||
506 | 509 | ||
507 | /* Bind every possible port (from 0 to 30) and stop when bind doesn't fail */ | 510 | /* Bind every possible port (from 0 to 30) and stop when bind doesn't fail */ |
508 | for (port = 1; port <= 30; port++) | 511 | //FIXME : it should start from port 1, but on my computer it doesn't work :) |
512 | for (port = 3; port <= 30; port++) | ||
509 | { | 513 | { |
510 | src.rc_channel = port; | 514 | addr->rc_channel = port; |
511 | status = bind(*socket, (struct sockaddr *)&src, sizeof(src)); | 515 | status = bind (socket, (struct sockaddr *) addr, sizeof (struct sockaddr_rc)); |
512 | if (status == 0) | 516 | if (status == 0) |
513 | return 0; | 517 | return 0; |
514 | } | 518 | } |
@@ -517,12 +521,14 @@ bind_socket (int *socket) | |||
517 | } | 521 | } |
518 | 522 | ||
519 | 523 | ||
520 | //TODO | ||
521 | /** | 524 | /** |
522 | * Function used for creating the service record and registering it. | 525 | * Function used for creating the service record and registering it. |
526 | * @param dev pointer to the device struct | ||
527 | * @param channel the rfcomm channel | ||
528 | * @return 0 on success | ||
523 | */ | 529 | */ |
524 | static sdp_session_t* | 530 | static int |
525 | register_service (void) | 531 | register_service (struct HardwareInfos *dev, int rc_channel) |
526 | { | 532 | { |
527 | /** | 533 | /** |
528 | * 1. initializations | 534 | * 1. initializations |
@@ -534,30 +540,153 @@ register_service (void) | |||
534 | * 7. cleanup | 540 | * 7. cleanup |
535 | */ | 541 | */ |
536 | 542 | ||
537 | //TODO: For now I will use a hard coded port number but in the end I will implement the SDP protocol | 543 | //FIXME: probably this is not the best idea. I should find a different uuid |
538 | 544 | uint8_t svc_uuid_int[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
539 | return NULL; | 545 | dev->pl_mac.mac[5], dev->pl_mac.mac[4], dev->pl_mac.mac[3], |
546 | dev->pl_mac.mac[2], dev->pl_mac.mac[1], dev->pl_mac.mac[0]}; | ||
547 | // const char *service_name = "GNUnet"; | ||
548 | const char *service_dsc = "Bluetooth plugin services"; | ||
549 | const char *service_prov = "GNUnet provider"; | ||
550 | uuid_t root_uuid, rfcomm_uuid, l2cap_uuid, svc_uuid; | ||
551 | sdp_list_t *root_list = 0, *rfcomm_list = 0, *l2cap_list = 0, | ||
552 | *proto_list = 0, *access_proto_list = 0, *svc_list = 0; | ||
553 | sdp_record_t *record = 0; | ||
554 | sdp_data_t *channel = 0; | ||
555 | |||
556 | record = sdp_record_alloc(); | ||
557 | |||
558 | /* Set the general service ID */ | ||
559 | sdp_uuid128_create (&svc_uuid, &svc_uuid_int); | ||
560 | svc_list = sdp_list_append (0, &svc_uuid); | ||
561 | sdp_set_service_classes (record, svc_list); | ||
562 | sdp_set_service_id (record, svc_uuid); | ||
563 | |||
564 | /* Make the service record publicly browsable */ | ||
565 | sdp_uuid16_create (&root_uuid, PUBLIC_BROWSE_GROUP); | ||
566 | root_list = sdp_list_append (0, &root_uuid); | ||
567 | sdp_set_browse_groups (record, root_list); | ||
568 | |||
569 | /* Register the RFCOMM channel */ | ||
570 | sdp_uuid16_create (&rfcomm_uuid, RFCOMM_UUID); | ||
571 | channel = sdp_data_alloc (SDP_UINT8, &rc_channel); | ||
572 | rfcomm_list = sdp_list_append (0, &rfcomm_uuid); | ||
573 | sdp_list_append (rfcomm_list, channel); | ||
574 | proto_list = sdp_list_append (0, rfcomm_list); | ||
575 | |||
576 | /* Set L2CAP information FIXME: probably not needed */ | ||
577 | // sdp_uuid16_create (&l2cap_uuid, L2CAP_UUID); | ||
578 | // l2cap_list = sdp_list_append (0, &l2cap_uuid); | ||
579 | //sdp_list_append (proto_list, l2cap_list); | ||
580 | |||
581 | /* Set protocol information */ | ||
582 | access_proto_list = sdp_list_append (0, proto_list); | ||
583 | sdp_set_access_protos (record, access_proto_list); | ||
584 | |||
585 | /* Set the name, provider, and description */ | ||
586 | sdp_set_info_attr (record, dev->iface, service_prov, service_dsc); | ||
587 | |||
588 | /* Connect to the local SDP server */ | ||
589 | dev->session = sdp_connect (BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY); | ||
590 | |||
591 | if (!dev->session) | ||
592 | { | ||
593 | fprintf (stderr, "Failed to connect to the SDP server on interface `%.*s': %s\n", | ||
594 | IFNAMSIZ, dev->iface, strerror (errno)); | ||
595 | //FIXME exit? | ||
596 | return 1; | ||
597 | } | ||
598 | |||
599 | /* Register the service record */ | ||
600 | if (sdp_record_register (dev->session, record, 0) < 0) | ||
601 | { | ||
602 | fprintf (stderr, "Failed to register a service record on interface `%.*s': %s\n", | ||
603 | IFNAMSIZ, dev->iface, strerror (errno)); | ||
604 | //FIXME exit? | ||
605 | return 1; | ||
606 | } | ||
607 | |||
608 | /* Cleanup */ | ||
609 | sdp_data_free (channel); | ||
610 | sdp_list_free (root_list, 0); | ||
611 | sdp_list_free (rfcomm_list, 0); | ||
612 | sdp_list_free (l2cap_list, 0); | ||
613 | sdp_list_free (proto_list, 0); | ||
614 | sdp_list_free (access_proto_list, 0); | ||
615 | sdp_list_free (svc_list, 0); | ||
616 | sdp_record_free (record); | ||
617 | |||
618 | return 0; | ||
540 | } | 619 | } |
541 | 620 | ||
542 | //TODO | ||
543 | /** | 621 | /** |
544 | * Function for searching and browsing for a service. This will return the | 622 | * Function for searching and browsing for a service. This will return the |
545 | * port number on which the service is running. | 623 | * port number on which the service is running. |
624 | * @param dev pointer to the device struct | ||
625 | * @param dest target address | ||
626 | * @return channel | ||
546 | */ | 627 | */ |
547 | |||
548 | static int | 628 | static int |
549 | searching_service (void) | 629 | get_channel(struct HardwareInfos *dev, bdaddr_t dest) |
550 | { | 630 | { |
551 | /** | 631 | /** |
552 | * 1. detect all nearby devices | 632 | * 1. detect all nearby devices //FIXME : Connect directly to the device with the service |
553 | * 2. for each device: | 633 | * 2. for each device: |
554 | * 2.1. connect to the SDP server running | 634 | * 2.1. connect to the SDP server running |
555 | * 2.2. get a list of service records with the specific UUID | 635 | * 2.2. get a list of service records with the specific UUID |
556 | * 2.3. for each service record get a list of the protocol sequences and get | 636 | * 2.3. for each service record get a list of the protocol sequences and get |
557 | * the port number | 637 | * the port number |
558 | */ | 638 | */ |
639 | uint8_t svc_uuid_int[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
640 | dest.b[5], dest.b[4], dest.b[3], | ||
641 | dest.b[2], dest.b[1], dest.b[0]}; | ||
642 | sdp_session_t *session = 0; | ||
643 | sdp_list_t *search_list = 0, *attrid_list = 0, *response_list = 0, *it = 0; | ||
644 | uuid_t svc_uuid; | ||
645 | uint32_t range = 0x0000ffff; | ||
646 | uint8_t channel = -1; | ||
559 | 647 | ||
560 | return 0; | 648 | /* Connect to the local SDP server */ |
649 | session = sdp_connect (BDADDR_ANY, &dest, 0); | ||
650 | if (!session) | ||
651 | { | ||
652 | fprintf (stderr, "Failed to connect to the SDP server on interface `%.*s': %s\n", | ||
653 | IFNAMSIZ, dev->iface, strerror (errno)); | ||
654 | //FIXME exit? | ||
655 | return -1; | ||
656 | } | ||
657 | |||
658 | sdp_uuid128_create (&svc_uuid, &svc_uuid_int); | ||
659 | search_list = sdp_list_append (0, &svc_uuid); | ||
660 | attrid_list = sdp_list_append (0, &range); | ||
661 | |||
662 | if (sdp_service_search_attr_req (session, search_list, | ||
663 | SDP_ATTR_REQ_RANGE, attrid_list, &response_list) == 0) | ||
664 | { | ||
665 | for (it = response_list; it; it = it->next) | ||
666 | { | ||
667 | sdp_record_t *record = (sdp_record_t*) it->data; | ||
668 | //TODO print some record informations to be sure everything is good | ||
669 | sdp_list_t *proto_list = 0; | ||
670 | if (sdp_get_access_protos (record, &proto_list) == 0) | ||
671 | { | ||
672 | channel = sdp_get_proto_port (proto_list, RFCOMM_UUID); | ||
673 | sdp_list_free (proto_list, 0); | ||
674 | } | ||
675 | sdp_record_free (record); | ||
676 | } | ||
677 | } | ||
678 | |||
679 | sdp_list_free (search_list, 0); | ||
680 | sdp_list_free (attrid_list, 0); | ||
681 | sdp_list_free (response_list, 0); | ||
682 | |||
683 | sdp_close (session); | ||
684 | |||
685 | if (channel == -1) | ||
686 | fprintf (stderr, "Failed to find the listening channel for interface `%.*s': %s\n", | ||
687 | IFNAMSIZ, dev->iface, strerror (errno)); | ||
688 | |||
689 | return channel; | ||
561 | } | 690 | } |
562 | 691 | ||
563 | /** | 692 | /** |
@@ -583,8 +712,6 @@ read_from_the_socket (int sock, | |||
583 | ssize_t count; | 712 | ssize_t count; |
584 | int len; | 713 | int len; |
585 | struct sockaddr_rc rc_addr = { 0 }; | 714 | struct sockaddr_rc rc_addr = { 0 }; |
586 | |||
587 | //count = recv (dev->fd_rfcomm, tmpbuf, buf_size, 0); //FIXME if I use RFCOMM | ||
588 | 715 | ||
589 | count = read (sock, tmpbuf, buf_size); | 716 | count = read (sock, tmpbuf, buf_size); |
590 | 717 | ||
@@ -631,11 +758,11 @@ open_device (struct HardwareInfos *dev) | |||
631 | { | 758 | { |
632 | /** | 759 | /** |
633 | * 1. Open a HCI socket (if RFCOMM protocol is used. If not, the HCI socket is | 760 | * 1. Open a HCI socket (if RFCOMM protocol is used. If not, the HCI socket is |
634 | * saved in dev->fd_hci. | 761 | * saved in dev->rfcomm). |
635 | * 2. Find the device id (request a list with all the devices and find the one | 762 | * 2. Find the device id (request a list with all the devices and find the one |
636 | * with the dev->iface name) | 763 | * with the dev->iface name) |
637 | * 3. If the interface is down try to get it up | 764 | * 3. If the interface is down try to get it up |
638 | * 4. TODO: Bind the RFCOMM socket to the interface using the bind_socket() method and register | 765 | * 4. Bind the RFCOMM socket to the interface using the bind_socket() method and register |
639 | * a SDP service | 766 | * a SDP service |
640 | * 5. For now use a hard coded port number(channel) value | 767 | * 5. For now use a hard coded port number(channel) value |
641 | * FIXME : if I use HCI sockets , should I enable RAW_SOCKET MODE?!?!?! | 768 | * FIXME : if I use HCI sockets , should I enable RAW_SOCKET MODE?!?!?! |
@@ -689,8 +816,11 @@ open_device (struct HardwareInfos *dev) | |||
689 | 816 | ||
690 | dev_id = dev_info.dev_id; //the device was found | 817 | dev_id = dev_info.dev_id; //the device was found |
691 | 818 | ||
692 | ba2str (&dev_info.bdaddr, addr); //get the device's MAC address | 819 | ba2str (&dev_info.bdaddr, addr); //get the device's MAC address |
693 | //TODO : copy the MAC address to the device structure | 820 | /** |
821 | * Copy the MAC address to the device structure | ||
822 | * FIXME: probably this is not the best solution | ||
823 | */ | ||
694 | memcpy (&dev->pl_mac, &dev_info.bdaddr, sizeof (bdaddr_t)); | 824 | memcpy (&dev->pl_mac, &dev_info.bdaddr, sizeof (bdaddr_t)); |
695 | 825 | ||
696 | /* Check if the interface is UP */ | 826 | /* Check if the interface is UP */ |
@@ -749,36 +879,24 @@ open_device (struct HardwareInfos *dev) | |||
749 | memset (&rc_addr, 0, sizeof (rc_addr)); | 879 | memset (&rc_addr, 0, sizeof (rc_addr)); |
750 | rc_addr.rc_family = AF_BLUETOOTH; | 880 | rc_addr.rc_family = AF_BLUETOOTH; |
751 | rc_addr.rc_bdaddr = *BDADDR_ANY; | 881 | rc_addr.rc_bdaddr = *BDADDR_ANY; |
752 | rc_addr.rc_channel = (uint8_t) HARD_CODED_PORT_NUMBER; | ||
753 | 882 | ||
754 | if (bind (dev->fd_rfcomm, (struct sockaddr *) &rc_addr, sizeof (rc_addr) != 0)) | 883 | if (bind_socket (dev->fd_rfcomm, &rc_addr) != 0) |
755 | { | 884 | { |
756 | fprintf (stderr, "Failed to bind interface `%.*s': %s\n", IFNAMSIZ, | 885 | fprintf (stderr, "Failed to bind interface `%.*s': %s\n", IFNAMSIZ, |
757 | dev->iface, strerror (errno)); | 886 | dev->iface, strerror (errno)); |
758 | return 1; | 887 | return 1; |
759 | } | 888 | } |
760 | 889 | ||
761 | /* | 890 | /* Register a SDP service */ |
762 | memset (&hci_addr, 0, sizeof (hci_addr)); | 891 | if (register_service (dev, rc_addr.rc_channel) != 0) |
763 | hci_addr.hci_family = AF_BLUETOOTH; | ||
764 | hci_addr.hci_dev = dev_id; | ||
765 | */ | ||
766 | /** | ||
767 | * FIXME hci_addr.hci_channel = HARD_CODED_PORT_NUMBER | ||
768 | * For linux kernel >= 2.6.7 the kernel automatically chooses an available port | ||
769 | * number. (getsockname() function can be used for finding out what port the kernel | ||
770 | * chose). | ||
771 | */ | ||
772 | /* | ||
773 | if (-1 == bind (dev->fd_hci, (struct sockaddr *) &hci_addr, sizeof (hci_addr))) | ||
774 | { | 892 | { |
775 | fprintf (stderr, "Failed to bind interface `%.*s': %s\n", IFNAMSIZ, | 893 | fprintf (stderr, "Failed to register a service on interface `%.*s': %s\n", IFNAMSIZ, |
776 | dev->iface, strerror (errno)); | 894 | dev->iface, strerror (errno)); |
777 | return 1; | 895 | return 1; |
778 | } | 896 | } |
779 | */ | ||
780 | 897 | ||
781 | if (listen (dev->fd_rfcomm, 5) == -1) | 898 | /* Switch socket in listening mode */ |
899 | if (listen (dev->fd_rfcomm, 5) == -1) //FIXME: probably we need a bigger number | ||
782 | { | 900 | { |
783 | fprintf (stderr, "Failed to listen on socket for interface `%.*s': %s\n", IFNAMSIZ, | 901 | fprintf (stderr, "Failed to listen on socket for interface `%.*s': %s\n", IFNAMSIZ, |
784 | dev->iface, strerror (errno)); | 902 | dev->iface, strerror (errno)); |
@@ -888,7 +1006,8 @@ stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr) | |||
888 | fprintf (stderr, "Received malformed message\n"); | 1006 | fprintf (stderr, "Received malformed message\n"); |
889 | exit (1); | 1007 | exit (1); |
890 | } | 1008 | } |
891 | sendsize -= (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame)); | 1009 | sendsize -= (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) - |
1010 | sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame)); | ||
892 | if (MAXLINE < sendsize) | 1011 | if (MAXLINE < sendsize) |
893 | { | 1012 | { |
894 | fprintf (stderr, "Packet too big for buffer\n"); | 1013 | fprintf (stderr, "Packet too big for buffer\n"); |
@@ -908,11 +1027,10 @@ stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr) | |||
908 | /** | 1027 | /** |
909 | * Main function of the helper. This code accesses a bluetooth interface | 1028 | * Main function of the helper. This code accesses a bluetooth interface |
910 | * forwards traffic in both directions between the bluetooth interface and | 1029 | * forwards traffic in both directions between the bluetooth interface and |
911 | * stdin/stdout of this | 1030 | * stdin/stdout of this process. Error messages are written to stdout. |
912 | * process. Error messages are written to stdout. | ||
913 | * | 1031 | * |
914 | * @param argc number of arguments, must be 2 | 1032 | * @param argc number of arguments, must be 2 |
915 | * @param argv arguments only argument is the name of the interface (i.e. 'mon0') | 1033 | * @param argv arguments only argument is the name of the interface (i.e. 'hci0') |
916 | * @return 0 on success (never happens, as we don't return unless aborted), 1 on error | 1034 | * @return 0 on success (never happens, as we don't return unless aborted), 1 on error |
917 | * | 1035 | * |
918 | **** same as the one from gnunet-helper-transport-wlan.c **** | 1036 | **** same as the one from gnunet-helper-transport-wlan.c **** |
@@ -931,7 +1049,7 @@ main (int argc, char *argv[]) | |||
931 | int raw_eno, i; | 1049 | int raw_eno, i; |
932 | uid_t uid; | 1050 | uid_t uid; |
933 | 1051 | ||
934 | /* assert privs so we can modify the firewall rules! */ | 1052 | /* Assert privs so we can modify the firewall rules! */ |
935 | uid = getuid (); | 1053 | uid = getuid (); |
936 | #ifdef HAVE_SETRESUID | 1054 | #ifdef HAVE_SETRESUID |
937 | if (0 != setresuid (uid, 0, 0)) | 1055 | if (0 != setresuid (uid, 0, 0)) |
@@ -947,17 +1065,16 @@ main (int argc, char *argv[]) | |||
947 | } | 1065 | } |
948 | #endif | 1066 | #endif |
949 | 1067 | ||
950 | /* make use of SGID capabilities on POSIX */ | 1068 | /* Make use of SGID capabilities on POSIX */ |
951 | memset (&dev, 0, sizeof (dev)); | 1069 | memset (&dev, 0, sizeof (dev)); |
952 | dev.fd_rfcomm = socket (AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); | 1070 | dev.fd_rfcomm = socket (AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); |
953 | //FIXME : using RFCOMM protocol : dev.fd_rfcomm = socket (AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); | ||
954 | raw_eno = errno; /* remember for later */ | 1071 | raw_eno = errno; /* remember for later */ |
955 | 1072 | ||
956 | /* now that we've dropped root rights, we can do error checking */ | 1073 | /* Now that we've dropped root rights, we can do error checking */ |
957 | if (2 != argc) | 1074 | if (2 != argc) |
958 | { | 1075 | { |
959 | fprintf (stderr, | 1076 | fprintf (stderr, "You must specify the name of the interface as the first \ |
960 | "You must specify the name of the interface as the first and only argument to this program.\n"); | 1077 | and only argument to this program.\n"); |
961 | if (-1 != dev.fd_rfcomm) | 1078 | if (-1 != dev.fd_rfcomm) |
962 | (void) close (dev.fd_rfcomm); | 1079 | (void) close (dev.fd_rfcomm); |
963 | return 1; | 1080 | return 1; |
@@ -987,7 +1104,7 @@ main (int argc, char *argv[]) | |||
987 | return 1; | 1104 | return 1; |
988 | } | 1105 | } |
989 | 1106 | ||
990 | /* drop privs */ | 1107 | /* Drop privs */ |
991 | { | 1108 | { |
992 | uid_t uid = getuid (); | 1109 | uid_t uid = getuid (); |
993 | #ifdef HAVE_SETRESUID | 1110 | #ifdef HAVE_SETRESUID |
@@ -1010,7 +1127,7 @@ main (int argc, char *argv[]) | |||
1010 | } | 1127 | } |
1011 | 1128 | ||
1012 | 1129 | ||
1013 | /* send MAC address of the bluetooth interface to STDOUT first */ | 1130 | /* Send MAC address of the bluetooth interface to STDOUT first */ |
1014 | { | 1131 | { |
1015 | struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg; | 1132 | struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg; |
1016 | 1133 | ||
@@ -1019,7 +1136,8 @@ main (int argc, char *argv[]) | |||
1019 | memcpy (&macmsg.mac, &dev.pl_mac, sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)); | 1136 | memcpy (&macmsg.mac, &dev.pl_mac, sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)); |
1020 | memcpy (write_std.buf, &macmsg, sizeof (macmsg)); | 1137 | memcpy (write_std.buf, &macmsg, sizeof (macmsg)); |
1021 | write_std.size = sizeof (macmsg); | 1138 | write_std.size = sizeof (macmsg); |
1022 | } | 1139 | } |
1140 | |||
1023 | 1141 | ||
1024 | stdin_mst = mst_create (&stdin_send_hw, &dev); | 1142 | stdin_mst = mst_create (&stdin_send_hw, &dev); |
1025 | stdin_open = 1; | 1143 | stdin_open = 1; |
@@ -1047,6 +1165,7 @@ main (int argc, char *argv[]) | |||
1047 | { | 1165 | { |
1048 | int sendsocket, status; | 1166 | int sendsocket, status; |
1049 | struct sockaddr_rc addr = { 0 }; | 1167 | struct sockaddr_rc addr = { 0 }; |
1168 | struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame frame; | ||
1050 | 1169 | ||
1051 | memset (dest, 0, sizeof (dest)); | 1170 | memset (dest, 0, sizeof (dest)); |
1052 | 1171 | ||
@@ -1059,13 +1178,22 @@ main (int argc, char *argv[]) | |||
1059 | return -1; | 1178 | return -1; |
1060 | } | 1179 | } |
1061 | 1180 | ||
1181 | /* Get the destination address */ | ||
1182 | if (write_pout.pos == 0) //FIXME: if write_pout.pos != 0, I cannot get the destination address | ||
1183 | { | ||
1184 | //FIXME : not sure if this is correct | ||
1185 | memset (&frame, 0, sizeof (frame)); | ||
1186 | memcpy (&frame, write_pout.buf + sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) | ||
1187 | - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame), | ||
1188 | sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame)); | ||
1189 | memcpy (&addr.rc_bdaddr, &frame.addr1, sizeof (bdaddr_t)); | ||
1190 | } | ||
1062 | addr.rc_family = AF_BLUETOOTH; | 1191 | addr.rc_family = AF_BLUETOOTH; |
1063 | addr.rc_channel = HARD_CODED_PORT_NUMBER2; //TODO: dinamically binding | 1192 | addr.rc_channel = get_channel (&dev, addr.rc_bdaddr); |
1064 | str2ba(dest, &addr.rc_bdaddr); //TODO: get the destination address from the message | ||
1065 | 1193 | ||
1066 | /*TODO: use a NON-BLOCKING socket | 1194 | /*TODO: use a NON-BLOCKING socket |
1067 | * sock_flags = fcntl (sendsocket, F_GETFL, 0); | 1195 | * sock_flags = fcntl (sendsocket, F_GETFL, 0); |
1068 | * fcntl( sendsocket, F_SETFL, sock_flags | O_NONBLOCK); | 1196 | * fcntl( sendsocket, F_SETFL, sock_flags | O_NONBLOCK); |
1069 | */ | 1197 | */ |
1070 | status = connect (sendsocket, (struct sockaddr *) &addr, sizeof (addr)); | 1198 | status = connect (sendsocket, (struct sockaddr *) &addr, sizeof (addr)); |
1071 | if (0 != status && errno != EAGAIN) | 1199 | if (0 != status && errno != EAGAIN) |
@@ -1200,7 +1328,10 @@ main (int argc, char *argv[]) | |||
1200 | - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame); | 1328 | - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame); |
1201 | rrm->header.size = htons (write_std.size); | 1329 | rrm->header.size = htons (write_std.size); |
1202 | rrm->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER); | 1330 | rrm->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER); |
1331 | (void) close (i); | ||
1203 | } | 1332 | } |
1333 | if (0 == ret) | ||
1334 | (void) close (i); | ||
1204 | } | 1335 | } |
1205 | } | 1336 | } |
1206 | } | 1337 | } |