aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-helper-transport-bluetooth.c
diff options
context:
space:
mode:
authorClaudiu Olteanu <claudiu@140774ce-b5e7-0310-ab8b-a85725594a96>2013-08-04 18:37:42 +0000
committerClaudiu Olteanu <claudiu@140774ce-b5e7-0310-ab8b-a85725594a96>2013-08-04 18:37:42 +0000
commitda8d9fa827e8ec68b25c55cbe4631510854cc240 (patch)
tree09d2a86f2c8ed52da9da81607b79ec6fe505fd18 /src/transport/gnunet-helper-transport-bluetooth.c
parentb15362b6534debb8098d797cf4a847599b03228d (diff)
downloadgnunet-da8d9fa827e8ec68b25c55cbe4631510854cc240.tar.gz
gnunet-da8d9fa827e8ec68b25c55cbe4631510854cc240.zip
Fixing the comments
Diffstat (limited to 'src/transport/gnunet-helper-transport-bluetooth.c')
-rw-r--r--src/transport/gnunet-helper-transport-bluetooth.c42
1 files changed, 19 insertions, 23 deletions
diff --git a/src/transport/gnunet-helper-transport-bluetooth.c b/src/transport/gnunet-helper-transport-bluetooth.c
index 1f5add92d..3eb17de42 100644
--- a/src/transport/gnunet-helper-transport-bluetooth.c
+++ b/src/transport/gnunet-helper-transport-bluetooth.c
@@ -571,6 +571,7 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
571 571
572/** 572/**
573 * Function for assigning a port number 573 * Function for assigning a port number
574 *
574 * @param socket the socket used to bind 575 * @param socket the socket used to bind
575 * @param addr pointer to the rfcomm address 576 * @param addr pointer to the rfcomm address
576 * @return 0 on success 577 * @return 0 on success
@@ -580,7 +581,7 @@ bind_socket (int socket, struct sockaddr_rc *addr)
580{ 581{
581 int port, status; 582 int port, status;
582 583
583 /* Bind every possible port (from 0 to 30) and stop when bind doesn't fail */ 584 /* Bind every possible port (from 0 to 30) and stop when binding doesn't fail */
584 //FIXME : it should start from port 1, but on my computer it doesn't work :) 585 //FIXME : it should start from port 1, but on my computer it doesn't work :)
585 for (port = 3; port <= 30; port++) 586 for (port = 3; port <= 30; port++)
586 { 587 {
@@ -596,6 +597,7 @@ bind_socket (int socket, struct sockaddr_rc *addr)
596 597
597/** 598/**
598 * Function used for creating the service record and registering it. 599 * Function used for creating the service record and registering it.
600 *
599 * @param dev pointer to the device struct 601 * @param dev pointer to the device struct
600 * @param rc_channel the rfcomm channel 602 * @param rc_channel the rfcomm channel
601 * @return 0 on success 603 * @return 0 on success
@@ -612,12 +614,9 @@ register_service (struct HardwareInfos *dev, int rc_channel)
612 * 6. register the service record to the local SDP server 614 * 6. register the service record to the local SDP server
613 * 7. cleanup 615 * 7. cleanup
614 */ 616 */
615
616 //FIXME: probably this is not the best idea. I should find a different uuid
617 uint8_t svc_uuid_int[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 617 uint8_t svc_uuid_int[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
618 dev->pl_mac.mac[5], dev->pl_mac.mac[4], dev->pl_mac.mac[3], 618 dev->pl_mac.mac[5], dev->pl_mac.mac[4], dev->pl_mac.mac[3],
619 dev->pl_mac.mac[2], dev->pl_mac.mac[1], dev->pl_mac.mac[0]}; 619 dev->pl_mac.mac[2], dev->pl_mac.mac[1], dev->pl_mac.mac[0]};
620// const char *service_name = "GNUnet";
621 const char *service_dsc = "Bluetooth plugin services"; 620 const char *service_dsc = "Bluetooth plugin services";
622 const char *service_prov = "GNUnet provider"; 621 const char *service_prov = "GNUnet provider";
623 uuid_t root_uuid, rfcomm_uuid, svc_uuid; 622 uuid_t root_uuid, rfcomm_uuid, svc_uuid;
@@ -688,6 +687,7 @@ register_service (struct HardwareInfos *dev, int rc_channel)
688/** 687/**
689 * Function for searching and browsing for a service. This will return the 688 * Function for searching and browsing for a service. This will return the
690 * port number on which the service is running. 689 * port number on which the service is running.
690 *
691 * @param dev pointer to the device struct 691 * @param dev pointer to the device struct
692 * @param dest target address 692 * @param dest target address
693 * @return channel 693 * @return channel
@@ -758,6 +758,7 @@ get_channel(struct HardwareInfos *dev, bdaddr_t dest)
758 758
759/** 759/**
760 * Read from the socket and put the result into the buffer for transmission to 'stdout'. 760 * Read from the socket and put the result into the buffer for transmission to 'stdout'.
761 *
761 * @param sock file descriptor for reading 762 * @param sock file descriptor for reading
762 * @param buf buffer to read to; first bytes will be the 'struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame', 763 * @param buf buffer to read to; first bytes will be the 'struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame',
763 * followed by the actual payload 764 * followed by the actual payload
@@ -770,11 +771,6 @@ read_from_the_socket (int sock,
770 unsigned char *buf, size_t buf_size, 771 unsigned char *buf, size_t buf_size,
771 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *ri) 772 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *ri)
772{ 773{
773 /**
774 * 1. Read from the socket in a temporary buffer (check for errors)
775 * 2. Detect if the crc exists
776 * 3. Write the result to the buffer
777 */
778 unsigned char tmpbuf[buf_size]; 774 unsigned char tmpbuf[buf_size];
779 ssize_t count; 775 ssize_t count;
780 int len; 776 int len;
@@ -791,7 +787,7 @@ read_from_the_socket (int sock,
791 return -1; 787 return -1;
792 } 788 }
793 789
794 /* Get the channel used */ 790 /* Get the channel used */ //FIXME probably not needed anymore
795 memset (&rc_addr, 0, sizeof (rc_addr)); 791 memset (&rc_addr, 0, sizeof (rc_addr));
796 len = sizeof (rc_addr); 792 len = sizeof (rc_addr);
797 if (0 > getsockname (sock, (struct sockaddr *) &rc_addr, (socklen_t *) &len)) 793 if (0 > getsockname (sock, (struct sockaddr *) &rc_addr, (socklen_t *) &len))
@@ -828,7 +824,7 @@ open_device (struct HardwareInfos *dev)
828 { 824 {
829 struct hci_dev_list_req list; 825 struct hci_dev_list_req list;
830 struct hci_dev_req dev[HCI_MAX_DEV]; 826 struct hci_dev_req dev[HCI_MAX_DEV];
831 } request; //used for detecting the local devices 827 } request; //used for detecting the local devices
832 struct sockaddr_rc rc_addr = { 0 }; //used for binding 828 struct sockaddr_rc rc_addr = { 0 }; //used for binding
833 829
834 /* Initialize the neighbour structure */ 830 /* Initialize the neighbour structure */
@@ -880,10 +876,10 @@ open_device (struct HardwareInfos *dev)
880 */ 876 */
881 memcpy (&dev->pl_mac, &dev_info.bdaddr, sizeof (bdaddr_t)); 877 memcpy (&dev->pl_mac, &dev_info.bdaddr, sizeof (bdaddr_t));
882 878
883 /* Check if the interface is UP */ 879 /* Check if the interface is up */
884 if (hci_test_bit (HCI_UP, (void *) &dev_info.flags) == 0) 880 if (hci_test_bit (HCI_UP, (void *) &dev_info.flags) == 0)
885 { 881 {
886 /* Bring interface up */ 882 /* Bring the interface up */
887 if (ioctl (fd_hci, HCIDEVUP, dev_info.dev_id)) 883 if (ioctl (fd_hci, HCIDEVUP, dev_info.dev_id))
888 { 884 {
889 fprintf (stderr, "ioctl(HCIDEVUP) on interface `%.*s' failed: %s\n", 885 fprintf (stderr, "ioctl(HCIDEVUP) on interface `%.*s' failed: %s\n",
@@ -1035,8 +1031,8 @@ mac_test (const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
1035 1031
1036 1032
1037/** 1033/**
1038 * Process data from the stdin. Takes the message forces the sender MAC to be correct 1034 * Process data from the stdin. Takes the message, forces the sender MAC to be correct
1039 * and puts it into our buffer for transmission to the kernel. (the other device). 1035 * and puts it into our buffer for transmission to the receiver.
1040 * 1036 *
1041 * @param cls pointer to the device struct ('struct HardwareInfos*') 1037 * @param cls pointer to the device struct ('struct HardwareInfos*')
1042 * @param hdr pointer to the start of the packet 1038 * @param hdr pointer to the start of the packet
@@ -1074,12 +1070,13 @@ stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
1074 * overwrite it with OUR MAC address to prevent mischief */ 1070 * overwrite it with OUR MAC address to prevent mischief */
1075 mac_set (blueheader, dev); 1071 mac_set (blueheader, dev);
1076 memcpy (&blueheader->addr1, &header->frame.addr1, 1072 memcpy (&blueheader->addr1, &header->frame.addr1,
1077 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)); //FIXME is this correct? 1073 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
1078 write_pout.size = sendsize; 1074 write_pout.size = sendsize;
1079} 1075}
1080 1076
1081/** 1077/**
1082 * Broadcast a HELLO message for peer discovery 1078 * Broadcast a HELLO message for peer discovery
1079 *
1083 * @param dev pointer to the device struct 1080 * @param dev pointer to the device struct
1084 * @param dev pointer to the socket which was added to the set 1081 * @param dev pointer to the socket which was added to the set
1085 * @return 0 on success 1082 * @return 0 on success
@@ -1097,7 +1094,7 @@ send_broadcast (struct HardwareInfos *dev, int *sendsocket)
1097 { 1094 {
1098 /** 1095 /**
1099 * It means that I sent HELLO messages to all the devices from the list and I should search 1096 * It means that I sent HELLO messages to all the devices from the list and I should search
1100 * for another ones or that this is the first time when I do a search. 1097 * for new ones or that this is the first time when I do a search.
1101 */ 1098 */
1102 inquiry_info *devices = NULL; 1099 inquiry_info *devices = NULL;
1103 int i, responses, max_responses = MAX_PORTS; 1100 int i, responses, max_responses = MAX_PORTS;
@@ -1193,7 +1190,7 @@ send_broadcast (struct HardwareInfos *dev, int *sendsocket)
1193 /* Try to connect to a new device from the list */ 1190 /* Try to connect to a new device from the list */
1194 while (neighbours.pos < neighbours.size) 1191 while (neighbours.pos < neighbours.size)
1195 { 1192 {
1196 /* Check if we are connected to this device */ 1193 /* Check if we are already connected to this device */
1197 if (neighbours.fds[neighbours.pos] == -1) 1194 if (neighbours.fds[neighbours.pos] == -1)
1198 { 1195 {
1199 1196
@@ -1203,7 +1200,6 @@ send_broadcast (struct HardwareInfos *dev, int *sendsocket)
1203 addr_rc.rc_channel = get_channel (dev, addr_rc.rc_bdaddr); 1200 addr_rc.rc_channel = get_channel (dev, addr_rc.rc_bdaddr);
1204 1201
1205 *sendsocket = socket (AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); 1202 *sendsocket = socket (AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
1206 //TODO adauga un label aici si intoarcete de cateva ori daca nu reuseste
1207 if (connect (*sendsocket, (struct sockaddr *)&addr_rc, sizeof (addr_rc)) == 0) 1203 if (connect (*sendsocket, (struct sockaddr *)&addr_rc, sizeof (addr_rc)) == 0)
1208 { 1204 {
1209 neighbours.fds[neighbours.pos++] = *sendsocket; 1205 neighbours.fds[neighbours.pos++] = *sendsocket;
@@ -1220,7 +1216,7 @@ send_broadcast (struct HardwareInfos *dev, int *sendsocket)
1220 errno_copy = errno; //Save a copy for later 1216 errno_copy = errno; //Save a copy for later
1221 ba2str (&(neighbours.devices[neighbours.pos]), addr); 1217 ba2str (&(neighbours.devices[neighbours.pos]), addr);
1222 fprintf (stderr, "LOG : Couldn't connect on device %s, error : %s\n", addr, strerror(errno)); 1218 fprintf (stderr, "LOG : Couldn't connect on device %s, error : %s\n", addr, strerror(errno));
1223 if (errno != ECONNREFUSED) //FIXME nu merge! 1219 if (errno != ECONNREFUSED) //FIXME be sure that this works
1224 { 1220 {
1225 fprintf (stderr, "LOG : Removes %d device from the list\n", neighbours.pos); 1221 fprintf (stderr, "LOG : Removes %d device from the list\n", neighbours.pos);
1226 /* Remove the device from the list */ 1222 /* Remove the device from the list */
@@ -1298,13 +1294,13 @@ send_broadcast (struct HardwareInfos *dev, int *sendsocket)
1298/** 1294/**
1299 * Main function of the helper. This code accesses a bluetooth interface 1295 * Main function of the helper. This code accesses a bluetooth interface
1300 * forwards traffic in both directions between the bluetooth interface and 1296 * forwards traffic in both directions between the bluetooth interface and
1301 * stdin/stdout of this process. Error messages are written to stdout. 1297 * stdin/stdout of this process. Error messages are written to stderr.
1302 * 1298 *
1303 * @param argc number of arguments, must be 2 1299 * @param argc number of arguments, must be 2
1304 * @param argv arguments only argument is the name of the interface (i.e. 'hci0') 1300 * @param argv arguments only argument is the name of the interface (i.e. 'hci0')
1305 * @return 0 on success (never happens, as we don't return unless aborted), 1 on error 1301 * @return 0 on success (never happens, as we don't return unless aborted), 1 on error
1306 * 1302 *
1307 **** same as the one from gnunet-helper-transport-wlan.c **** 1303 **** similar to gnunet-helper-transport-wlan.c ****
1308 */ 1304 */
1309int 1305int
1310main (int argc, char *argv[]) 1306main (int argc, char *argv[])
@@ -1613,7 +1609,7 @@ main (int argc, char *argv[])
1613 ssize_t ret = 1609 ssize_t ret =
1614 write (sendsocket, write_pout.buf + write_std.pos, 1610 write (sendsocket, write_pout.buf + write_std.pos,
1615 write_pout.size - write_pout.pos); 1611 write_pout.size - write_pout.pos);
1616 if (0 > ret) //FIXME should I check first the error type? 1612 if (0 > ret) //FIXME should I first check the error type?
1617 { 1613 {
1618 fprintf (stderr, "Failed to write to bluetooth device: %s. Closing the socket!\n", 1614 fprintf (stderr, "Failed to write to bluetooth device: %s. Closing the socket!\n",
1619 strerror (errno)); 1615 strerror (errno));