summaryrefslogtreecommitdiff
path: root/src/transport/gnunet-helper-transport-bluetooth.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-helper-transport-bluetooth.c')
-rw-r--r--src/transport/gnunet-helper-transport-bluetooth.c440
1 files changed, 220 insertions, 220 deletions
diff --git a/src/transport/gnunet-helper-transport-bluetooth.c b/src/transport/gnunet-helper-transport-bluetooth.c
index cc8a6484e..343aacd19 100644
--- a/src/transport/gnunet-helper-transport-bluetooth.c
+++ b/src/transport/gnunet-helper-transport-bluetooth.c
@@ -35,7 +35,7 @@
#include <bluetooth/sdp.h>
#include <bluetooth/sdp_lib.h>
#include <errno.h>
- #include <linux/if.h>
+ #include <linux/if.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
@@ -82,7 +82,7 @@
UINT8 mac[MAC_ADDR_SIZE];
};
- /**
+ /**
* The UUID used for the SDP service.
* {31191E56-FA7E-4517-870E-71B86BBCC52F}
*/
@@ -110,7 +110,7 @@ struct HardwareInfos
#ifdef MINGW
/**
* socket handle
- */
+ */
struct GNUNET_NETWORK_Handle *handle;
/**
@@ -127,7 +127,7 @@ struct HardwareInfos
* MAC address of our own bluetooth interface.
*/
struct GNUNET_TRANSPORT_WLAN_MacAddress pl_mac;
-
+
/**
* SDP session
*/
@@ -151,7 +151,7 @@ struct SendBuffer
* destination? Always smaller than 'size'.
*/
size_t pos;
-
+
/**
* Buffered data; twice the maximum allowed message size as we add some
* headers.
@@ -161,13 +161,13 @@ struct SendBuffer
#ifdef LINUX
/**
- * Devices buffer used to keep a list with all the discoverable devices in
+ * Devices buffer used to keep a list with all the discoverable devices in
* order to send them HELLO messages one by one when it receive a broadcast message.
- */
+ */
struct BroadcastMessages
{
/* List with the discoverable devices' addresses */
- bdaddr_t devices[MAX_PORTS];
+ bdaddr_t devices[MAX_PORTS];
/* List with the open sockets */
int fds[MAX_PORTS];
@@ -175,7 +175,7 @@ struct SendBuffer
/* The number of the devices */
int size;
-
+
/* The current position */
int pos;
@@ -207,7 +207,7 @@ static struct SendBuffer write_pout;
static struct SendBuffer write_std;
-/* ****** this are the same functions as the ones used in gnunet-helper-transport-wlan.c ****** */
+/* ****** this are the same functions as the ones used in gnunet-helper-transport-wlan.c ****** */
/**
* To what multiple do we align messages? 8 byte should suffice for everyone
@@ -228,7 +228,7 @@ static struct SendBuffer write_std;
* @param cls closure
* @param message the actual message
*/
-typedef void (*MessageTokenizerCallback) (void *cls,
+typedef void (*MessageTokenizerCallback) (void *cls,
const struct
GNUNET_MessageHeader *
message);
@@ -301,7 +301,7 @@ mst_create (MessageTokenizerCallback cb,
ret->cb = cb;
ret->cb_cls = cb_cls;
ret->pos = 0;
-
+
return ret;
}
@@ -602,7 +602,7 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
if (((crc) & 0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] &&
((crc >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3])
return 0;
- return 1;
+ return 1;
}
@@ -613,7 +613,7 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
/**
* Function used to get the code of last error and to print the type of error.
*/
- static void
+ static void
print_last_error()
{
LPVOID lpMsgBuf = NULL;
@@ -644,9 +644,9 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
/**
* Function used to convert the GUID.
* @param bytes the GUID represented as a char array
- * @param uuid pointer to the GUID
+ * @param uuid pointer to the GUID
*/
- static void
+ static void
convert_guid(char *bytes, GUID * uuid)
{
int i;
@@ -664,16 +664,16 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
#ifdef LINUX
/**
* Function for assigning a port number
- *
+ *
* @param socket the socket used to bind
* @param addr pointer to the rfcomm address
- * @return 0 on success
- */
+ * @return 0 on success
+ */
static int
bind_socket (int socket, struct sockaddr_rc *addr)
{
int port, status;
-
+
/* Bind every possible port (from 0 to 30) and stop when binding doesn't fail */
//FIXME : it should start from port 1, but on my computer it doesn't work :)
for (port = 3; port <= 30; port++)
@@ -683,8 +683,8 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
if (status == 0)
return 0;
}
-
- return -1;
+
+ return -1;
}
#endif
@@ -696,7 +696,7 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
* @return 0 on success
*/
static int
- register_service (struct HardwareInfos *dev)
+ register_service (struct HardwareInfos *dev)
{
/* advertise the service */
CSADDR_INFO addr_info;
@@ -746,7 +746,7 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
wqs.lpcsaBuffer = &addr_info ;
wqs.lpBlob = 0;
- if (SOCKET_ERROR == WSASetService (&wqs , RNRSERVICE_REGISTER, 0))
+ if (SOCKET_ERROR == WSASetService (&wqs , RNRSERVICE_REGISTER, 0))
{
fprintf (stderr, "Failed to register the SDP service: ");
print_last_error();
@@ -768,7 +768,7 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
* @return 0 on success
*/
static int
- register_service (struct HardwareInfos *dev, int rc_channel)
+ register_service (struct HardwareInfos *dev, int rc_channel)
{
/**
* 1. initializations
@@ -779,17 +779,17 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
* 6. register the service record to the local SDP server
* 7. cleanup
*/
- uint8_t svc_uuid_int[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ uint8_t svc_uuid_int[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
dev->pl_mac.mac[5], dev->pl_mac.mac[4], dev->pl_mac.mac[3],
dev->pl_mac.mac[2], dev->pl_mac.mac[1], dev->pl_mac.mac[0]};
const char *service_dsc = "Bluetooth plugin services";
- const char *service_prov = "GNUnet provider";
- uuid_t root_uuid, rfcomm_uuid, svc_uuid;
+ const char *service_prov = "GNUnet provider";
+ uuid_t root_uuid, rfcomm_uuid, svc_uuid;
sdp_list_t *root_list = 0, *rfcomm_list = 0, *proto_list = 0,
*access_proto_list = 0, *svc_list = 0;
sdp_record_t *record = 0;
sdp_data_t *channel = 0;
-
+
record = sdp_record_alloc();
/* Set the general service ID */
@@ -799,8 +799,8 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
sdp_set_service_id (record, svc_uuid);
/* Make the service record publicly browsable */
- sdp_uuid16_create (&root_uuid, PUBLIC_BROWSE_GROUP);
- root_list = sdp_list_append (0, &root_uuid);
+ sdp_uuid16_create (&root_uuid, PUBLIC_BROWSE_GROUP);
+ root_list = sdp_list_append (0, &root_uuid);
sdp_set_browse_groups (record, root_list);
/* Register the RFCOMM channel */
@@ -816,10 +816,10 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
/* Set the name, provider, and description */
sdp_set_info_attr (record, dev->iface, service_prov, service_dsc);
-
+
/* Connect to the local SDP server */
dev->session = sdp_connect (BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY);
-
+
if (!dev->session)
{
fprintf (stderr, "Failed to connect to the SDP server on interface `%.*s': %s\n",
@@ -827,7 +827,7 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
//FIXME exit?
return 1;
}
-
+
/* Register the service record */
if (sdp_record_register (dev->session, record, 0) < 0)
{
@@ -836,23 +836,23 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
//FIXME exit?
return 1;
}
-
+
/* Cleanup */
- sdp_data_free (channel);
+ sdp_data_free (channel);
sdp_list_free (root_list, 0);
sdp_list_free (rfcomm_list, 0);
sdp_list_free (proto_list, 0);
sdp_list_free (access_proto_list, 0);
sdp_list_free (svc_list, 0);
sdp_record_free (record);
-
+
return 0;
}
#endif
#ifdef MINGW
/**
- * Function for searching and browsing for a service. This will return the
+ * Function for searching and browsing for a service. This will return the
* port number on which the service is running.
*
* @param dest target address
@@ -869,16 +869,16 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
GUID guid;
unsigned char uuid[] = GNUNET_BLUETOOTH_SDP_UUID;
convert_guid ((char *) uuid, &guid);
-
+
wqs = (WSAQUERYSET*)malloc (wqs_len);
ZeroMemory (wqs, wqs_len);
-
+
wqs->dwSize = sizeof (WSAQUERYSET) ;
wqs->lpServiceClassId = &guid;
wqs->dwNameSpace = NS_BTH;
wqs->dwNumberOfCsAddrs = 0;
wqs->lpszContext = (LPSTR)dest;
-
+
if (SOCKET_ERROR == WSALookupServiceBegin (wqs, LUP_FLUSHCACHE | LUP_RETURN_ALL, &h))
{
if (GetLastError() == WSASERVICE_NOT_FOUND)
@@ -894,14 +894,14 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
return -1;
}
}
-
+
/* search the sdp service */
while (!done)
{
if (SOCKET_ERROR == WSALookupServiceNext (h, LUP_FLUSHCACHE | LUP_RETURN_ALL, &wqs_len, wqs))
{
int error = WSAGetLastError();
-
+
switch (error)
{
case WSAEFAULT:
@@ -927,15 +927,15 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
channel = ((SOCKADDR_BTH*)wqs->lpcsaBuffer->RemoteAddr.lpSockaddr)->port;
}
}
-
+
free (wqs) ;
WSALookupServiceEnd (h);
-
+
return channel;
}
#else
/**
- * Function used for searching and browsing for a service. This will return the
+ * Function used for searching and browsing for a service. This will return the
* port number on which the service is running.
*
* @param dev pointer to the device struct
@@ -943,17 +943,17 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
* @return channel
*/
static int
- get_channel(struct HardwareInfos *dev, bdaddr_t dest)
+ get_channel(struct HardwareInfos *dev, bdaddr_t dest)
{
/**
* 1. detect all nearby devices
* 2. for each device:
* 2.1. connect to the SDP server running
* 2.2. get a list of service records with the specific UUID
- * 2.3. for each service record get a list of the protocol sequences and get
+ * 2.3. for each service record get a list of the protocol sequences and get
* the port number
*/
- uint8_t svc_uuid_int[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ uint8_t svc_uuid_int[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
dest.b[5], dest.b[4], dest.b[3],
dest.b[2], dest.b[1], dest.b[0]};
sdp_session_t *session = 0;
@@ -961,21 +961,21 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
uuid_t svc_uuid;
uint32_t range = 0x0000ffff;
uint8_t channel = -1;
-
+
/* Connect to the local SDP server */
- session = sdp_connect (BDADDR_ANY, &dest, 0);
+ session = sdp_connect (BDADDR_ANY, &dest, 0);
if (!session)
{
fprintf (stderr, "Failed to connect to the SDP server on interface `%.*s': %s\n",
IFNAMSIZ, dev->iface, strerror (errno));
return -1;
}
-
+
sdp_uuid128_create (&svc_uuid, &svc_uuid_int);
search_list = sdp_list_append (0, &svc_uuid);
attrid_list = sdp_list_append (0, &range);
-
- if (sdp_service_search_attr_req (session, search_list,
+
+ if (sdp_service_search_attr_req (session, search_list,
SDP_ATTR_REQ_RANGE, attrid_list, &response_list) == 0)
{
for (it = response_list; it; it = it->next)
@@ -990,24 +990,24 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
sdp_record_free (record);
}
}
-
+
sdp_list_free (search_list, 0);
sdp_list_free (attrid_list, 0);
sdp_list_free (response_list, 0);
-
+
sdp_close (session);
-
+
if (channel == -1)
fprintf (stderr, "Failed to find the listening channel for interface `%.*s': %s\n",
IFNAMSIZ, dev->iface, strerror (errno));
-
+
return channel;
}
#endif
/**
* Read from the socket and put the result into the buffer for transmission to 'stdout'.
- *
+ *
* @param sock file descriptor for reading
* @param buf buffer to read to; first bytes will be the 'struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame',
* followed by the actual payload
@@ -1015,18 +1015,18 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
* @param ri where to write radiotap_rx info
* @return number of bytes written to 'buf'
*/
-static ssize_t
-read_from_the_socket (void *sock,
+static ssize_t
+read_from_the_socket (void *sock,
unsigned char *buf, size_t buf_size,
struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *ri)
{
unsigned char tmpbuf[buf_size];
ssize_t count;
-
+
#ifdef MINGW
count = GNUNET_NETWORK_socket_recv ((struct GNUNET_NETWORK_Handle *)sock, tmpbuf, buf_size);
#else
- count = read (*((int *)sock), tmpbuf, buf_size);
+ count = read (*((int *)sock), tmpbuf, buf_size);
#endif
if (0 > count)
@@ -1041,11 +1041,11 @@ read_from_the_socket (void *sock,
return -1;
}
-
+
#ifdef LINUX
/* Get the channel used */
int len;
- struct sockaddr_rc rc_addr = { 0 };
+ struct sockaddr_rc rc_addr = { 0 };
memset (&rc_addr, 0, sizeof (rc_addr));
len = sizeof (rc_addr);
@@ -1064,9 +1064,9 @@ read_from_the_socket (void *sock,
{
count -= sizeof(uint32_t);
}
-
+
memcpy (buf, tmpbuf, count);
-
+
return count;
}
@@ -1078,7 +1078,7 @@ read_from_the_socket (void *sock,
*/
static int
open_device (struct HardwareInfos *dev)
-{
+{
#ifdef MINGW
SOCKADDR_BTH addr;
@@ -1113,30 +1113,30 @@ open_device (struct HardwareInfos *dev)
fprintf (stderr, "Failed to register a service: ");
print_last_error();
return 1;
- }
+ }
#else
int i, dev_id = -1, fd_hci;
- struct
+ struct
{
struct hci_dev_list_req list;
struct hci_dev_req dev[HCI_MAX_DEV];
} request; //used for detecting the local devices
struct sockaddr_rc rc_addr = { 0 }; //used for binding
-
+
/* Initialize the neighbour structure */
neighbours.dev_id = -1;
for (i = 0; i < MAX_PORTS; i++)
neighbours.fds[i] = -1;
-
+
/* Open a HCI socket */
fd_hci = socket (AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
- if (fd_hci < 0)
+ if (fd_hci < 0)
{
fprintf (stderr, "Failed to create HCI socket: %s\n", strerror (errno));
return -1;
}
-
+
memset (&request, 0, sizeof(request));
request.list.dev_num = HCI_MAX_DEV;
@@ -1146,7 +1146,7 @@ open_device (struct HardwareInfos *dev)
IFNAMSIZ, dev->iface, strerror (errno));
return 1;
}
-
+
/* Search for a device with dev->iface name */
for (i = 0; i < request.list.dev_num; i++)
{
@@ -1155,23 +1155,23 @@ open_device (struct HardwareInfos *dev)
memset (&dev_info, 0, sizeof(struct hci_dev_info));
dev_info.dev_id = request.dev[i].dev_id;
strncpy (dev_info.name, dev->iface, IFNAMSIZ);
-
+
if (ioctl (fd_hci, HCIGETDEVINFO, (void *) &dev_info))
{
fprintf (stderr, "ioctl(HCIGETDEVINFO) on interface `%.*s' failed: %s\n",
IFNAMSIZ, dev->iface, strerror (errno));
return 1;
}
-
+
if (strcmp (dev_info.name, dev->iface) == 0)
{
-
+
dev_id = dev_info.dev_id; //the device was found
/**
* Copy the MAC address to the device structure
*/
memcpy (&dev->pl_mac, &dev_info.bdaddr, sizeof (bdaddr_t));
-
+
/* Check if the interface is up */
if (hci_test_bit (HCI_UP, (void *) &dev_info.flags) == 0)
{
@@ -1183,55 +1183,55 @@ open_device (struct HardwareInfos *dev)
return 1;
}
}
-
+
/* Check if the device is discoverable */
if (hci_test_bit (HCI_PSCAN, (void *) &dev_info.flags) == 0 ||
hci_test_bit (HCI_ISCAN, (void *) &dev_info.flags) == 0)
{
/* Set interface Page Scan and Inqury Scan ON */
struct hci_dev_req dev_req;
-
+
memset (&dev_req, 0, sizeof (dev_req));
dev_req.dev_id = dev_info.dev_id;
dev_req.dev_opt = SCAN_PAGE | SCAN_INQUIRY;
-
+
if (ioctl (fd_hci, HCISETSCAN, (unsigned long) &dev_req))
- {
+ {
fprintf (stderr, "ioctl(HCISETSCAN) on interface `%.*s' failed: %s\n",
IFNAMSIZ, dev->iface, strerror (errno));
return 1;
}
-
+
}
break;
}
-
+
}
-
+
/* Check if the interface was not found */
if (dev_id == -1)
{
fprintf (stderr, "The interface %s was not found\n", dev->iface);
return 1;
}
-
+
/* Close the hci socket */
(void) close(fd_hci);
-
-
-
+
+
+
/* Bind the rfcomm socket to the interface */
- memset (&rc_addr, 0, sizeof (rc_addr));
+ memset (&rc_addr, 0, sizeof (rc_addr));
rc_addr.rc_family = AF_BLUETOOTH;
rc_addr.rc_bdaddr = *BDADDR_ANY;
-
+
if (bind_socket (dev->fd_rfcomm, &rc_addr) != 0)
{
fprintf (stderr, "Failed to bind interface `%.*s': %s\n", IFNAMSIZ,
dev->iface, strerror (errno));
return 1;
}
-
+
/* Register a SDP service */
if (register_service (dev, rc_addr.rc_channel) != 0)
{
@@ -1239,7 +1239,7 @@ open_device (struct HardwareInfos *dev)
dev->iface, strerror (errno));
return 1;
}
-
+
/* Switch socket in listening mode */
if (listen (dev->fd_rfcomm, 5) == -1) //FIXME: probably we need a bigger number
{
@@ -1247,7 +1247,7 @@ open_device (struct HardwareInfos *dev)
dev->iface, strerror (errno));
return 1;
}
-
+
#endif
return 0;
@@ -1266,7 +1266,7 @@ static void
mac_set (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
const struct HardwareInfos *dev)
{
- taIeeeHeader->frame_control = htons (IEEE80211_FC0_TYPE_DATA);
+ taIeeeHeader->frame_control = htons (IEEE80211_FC0_TYPE_DATA);
taIeeeHeader->addr3 = mac_bssid_gnunet;
#ifdef MINGW
@@ -1292,13 +1292,13 @@ mac_set (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
struct stat sbuf;
int ret;
- ret = snprintf (strbuf, sizeof (strbuf),
+ ret = snprintf (strbuf, sizeof (strbuf),
"/sys/class/bluetooth/%s/subsystem",
iface);
if ((ret < 0) || (ret >= sizeof (strbuf)) || (0 != stat (strbuf, &sbuf)))
{
- fprintf (stderr,
- "Did not find 802.15.1 interface `%s'. Exiting.\n",
+ fprintf (stderr,
+ "Did not find 802.15.1 interface `%s'. Exiting.\n",
iface);
exit (1);
}
@@ -1354,12 +1354,12 @@ stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
sendsize = ntohs (hdr->size);
if ( (sendsize <
sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage)) ||
- (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) )
+ (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) )
{
fprintf (stderr, "Received malformed message\n");
exit (1);
}
- sendsize -= (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) -
+ sendsize -= (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) -
sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame));
if (MAXLINE < sendsize)
{
@@ -1373,7 +1373,7 @@ stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
/* payload contains MAC address, but we don't trust it, so we'll
* overwrite it with OUR MAC address to prevent mischief */
mac_set (blueheader, dev);
- memcpy (&blueheader->addr1, &header->frame.addr1,
+ memcpy (&blueheader->addr1, &header->frame.addr1,
sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
write_pout.size = sendsize;
}
@@ -1386,19 +1386,19 @@ stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
* @param dev pointer to the socket which was added to the set
* @return 0 on success
*/
- static int
- send_broadcast (struct HardwareInfos *dev, int *sendsocket)
+ static int
+ send_broadcast (struct HardwareInfos *dev, int *sendsocket)
{
int new_device = 0;
int loops = 0;
search_for_devices:
- if ((neighbours.size == neighbours.pos && new_device == 1) || neighbours.size == 0)
- {
+ if ((neighbours.size == neighbours.pos && new_device == 1) || neighbours.size == 0)
+ {
inquiry_devices: //skip the conditions and force a inquiry for new devices
{
- /**
- * It means that I sent HELLO messages to all the devices from the list and I should search
+ /**
+ * It means that I sent HELLO messages to all the devices from the list and I should search
* for new ones or that this is the first time when I do a search.
*/
inquiry_info *devices = NULL;
@@ -1415,17 +1415,17 @@ stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
if (neighbours.dev_id == -1)
{
char addr[19] = { 0 }; //the device MAC address
-
- ba2str ((bdaddr_t *) &dev->pl_mac, addr);
+
+ ba2str ((bdaddr_t *) &dev->pl_mac, addr);
neighbours.dev_id = hci_devid (addr);
if (neighbours.dev_id < 0)
- {
+ {
fprintf (stderr, "Failed to get the device id for interface %.*s : %s\n", IFNAMSIZ,
dev->iface, strerror (errno));
return 1;
}
}
-
+
devices = malloc (max_responses * sizeof (inquiry_info));
if (devices == NULL)
{
@@ -1433,23 +1433,23 @@ stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
dev->iface);
return 1;
}
-
+
responses = hci_inquiry (neighbours.dev_id, 8, max_responses, NULL, &devices, IREQ_CACHE_FLUSH);
if (responses < 0)
{
fprintf (stderr, "Failed to inquiry on interface %.*s\n", IFNAMSIZ, dev->iface);
return 1;
}
-
+
fprintf (stderr, "LOG : Found %d devices\n", responses); //FIXME delete it after debugging stage
-
+
if (responses == 0)
{
fprintf (stderr, "LOG : No devices discoverable\n");
return 1;
}
-
- for (i = 0; i < responses; i++)
+
+ for (i = 0; i < responses; i++)
{
int j;
int found = 0;
@@ -1461,11 +1461,11 @@ stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
dev->iface);
return 2;
}
-
+
/* Search if the address already exists on the list */
for (j = 0; j < neighbours.size; j++)
{
- if (memcmp (&(devices + i)->bdaddr, &(neighbours.devices[j]), sizeof (bdaddr_t)) == 0)
+ if (memcmp (&(devices + i)->bdaddr, &(neighbours.devices[j]), sizeof (bdaddr_t)) == 0)
{
found = 1;
fprintf (stderr, "LOG : the device already exists on the list\n"); //FIXME debugging message
@@ -1481,12 +1481,12 @@ stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
fprintf (stderr, "LOG : %s was added to the list\n", addr); //FIXME debugging message
memcpy (&(neighbours.devices[neighbours.size++]), &(devices + i)->bdaddr, sizeof (bdaddr_t));
}
- }
-
+ }
+
free (devices);
}
}
-
+
int connection_successful = 0;
struct sockaddr_rc addr_rc = { 0 };
int errno_copy = 0;
@@ -1501,9 +1501,9 @@ stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
memset (&addr_rc.rc_bdaddr, 0, sizeof (addr_rc.rc_bdaddr));
memcpy (&addr_rc.rc_bdaddr, &(neighbours.devices[neighbours.pos]), sizeof (addr_rc.rc_bdaddr));
-
+
addr_rc.rc_channel = get_channel (dev, addr_rc.rc_bdaddr);
-
+
*sendsocket = socket (AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
if (connect (*sendsocket, (struct sockaddr *)&addr_rc, sizeof (addr_rc)) == 0)
{
@@ -1549,7 +1549,7 @@ stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
neighbours.pos += 1;
}
}
-
+
/* Cycle on the list */
if (neighbours.pos == neighbours.size)
{
@@ -1564,14 +1564,14 @@ stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
}
}
/* If a new device wasn't found, search an old one */
- if (connection_successful == 0)
+ if (connection_successful == 0)
{
int loop_check = neighbours.pos;
while (neighbours.fds[neighbours.pos] == -1)
{
if (neighbours.pos == neighbours.size)
neighbours.pos = 0;
-
+
if (neighbours.pos == loop_check)
{
if (errno_copy == ECONNREFUSED)
@@ -1599,7 +1599,7 @@ stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
/**
* Main function of the helper. This code accesses a bluetooth interface
- * forwards traffic in both directions between the bluetooth interface and
+ * forwards traffic in both directions between the bluetooth interface and
* stdin/stdout of this process. Error messages are written to stderr.
*
* @param argc number of arguments, must be 2
@@ -1611,7 +1611,7 @@ stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
int
main (int argc, char *argv[])
{
-#ifdef LINUX
+#ifdef LINUX
struct HardwareInfos dev;
char readbuf[MAXLINE];
int maxfd;
@@ -1632,7 +1632,7 @@ main (int argc, char *argv[])
return 254;
}
#else
- if (0 != seteuid (0))
+ if (0 != seteuid (0))
{
fprintf (stderr, "Failed to seteuid back to root: %s\n", strerror (errno));
return 254;
@@ -1710,15 +1710,15 @@ main (int argc, char *argv[])
memcpy (write_std.buf, &macmsg, sizeof (macmsg));
write_std.size = sizeof (macmsg);
}
-
-
- stdin_mst = mst_create (&stdin_send_hw, &dev);
+
+
+ stdin_mst = mst_create (&stdin_send_hw, &dev);
stdin_open = 1;
-
+
/**
- * TODO : I should make the time out of a mac endpoint smaller and check if the rate
+ * TODO : I should make the time out of a mac endpoint smaller and check if the rate
* from get_wlan_header (plugin_transport_bluetooth.c) is correct.
- */
+ */
while (1)
{
maxfd = -1;
@@ -1737,7 +1737,7 @@ main (int argc, char *argv[])
maxfd = MAX (maxfd, dev.fd_rfcomm);
}
- for (i = 0; i < crt_rfds; i++) // it can receive messages from multiple devices
+ for (i = 0; i < crt_rfds; i++) // it can receive messages from multiple devices
{
FD_SET (rfds_list[i], &rfds);
maxfd = MAX (maxfd, rfds_list[i]);
@@ -1749,22 +1749,22 @@ main (int argc, char *argv[])
maxfd = MAX (maxfd, STDOUT_FILENO);
}
if (0 < write_pout.size) //it can send messages only to one device per loop
- {
+ {
struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *frame;
/* Get the destination address */
frame = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *) write_pout.buf;
-
- if (memcmp (&frame->addr1, &dev.pl_mac,
+
+ if (memcmp (&frame->addr1, &dev.pl_mac,
sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0)
{
broadcast = 1;
- memset (&write_pout, 0, sizeof (write_pout)); //clear the buffer
- }
- else if (memcmp (&frame->addr1, &broadcast_address,
+ memset (&write_pout, 0, sizeof (write_pout)); //clear the buffer
+ }
+ else if (memcmp (&frame->addr1, &broadcast_address,
sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0)
{
fprintf (stderr, "LOG : %s has a broadcast message (pos %d, size %d)\n", dev.iface, neighbours.pos, neighbours.size); //FIXME: debugging message
-
+
if (send_broadcast(&dev, &sendsocket) != 0) //if the searching wasn't successful don't get stuck on the select stage
{
broadcast = 1;
@@ -1776,15 +1776,15 @@ main (int argc, char *argv[])
FD_SET (sendsocket, &wfds);
maxfd = MAX (maxfd, sendsocket);
}
- }
- else
+ }
+ else
{
int found = 0;
int pos = 0;
/* Search if the address already exists on the list */
for (i = 0; i < neighbours.size; i++)
{
- if (memcmp (&frame->addr1, &(neighbours.devices[i]), sizeof (bdaddr_t)) == 0)
+ if (memcmp (&frame->addr1, &(neighbours.devices[i]), sizeof (bdaddr_t)) == 0)
{
pos = i;
if (neighbours.fds[i] != -1)
@@ -1802,24 +1802,24 @@ main (int argc, char *argv[])
{
int status;
struct sockaddr_rc addr = { 0 };
-
- fprintf (stderr, "LOG : %s has a new message for %.2X:%.2X:%.2X:%.2X:%.2X:%.2X which isn't on the broadcast list\n", dev.iface,
+
+ fprintf (stderr, "LOG : %s has a new message for %.2X:%.2X:%.2X:%.2X:%.2X:%.2X which isn't on the broadcast list\n", dev.iface,
frame->addr1.mac[5], frame->addr1.mac[4], frame->addr1.mac[3],
- frame->addr1.mac[2], frame->addr1.mac[1], frame->addr1.mac[0]); //FIXME: debugging message
-
+ frame->addr1.mac[2], frame->addr1.mac[1], frame->addr1.mac[0]); //FIXME: debugging message
+
sendsocket = socket (AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
-
- if (sendsocket < 0)
+
+ if (sendsocket < 0)
{
- fprintf (stderr, "Failed to create a RFCOMM socket (sending stage): %s\n",
+ fprintf (stderr, "Failed to create a RFCOMM socket (sending stage): %s\n",
strerror (errno));
return -1;
}
-
+
memcpy (&addr.rc_bdaddr, &frame->addr1, sizeof (bdaddr_t));
addr.rc_family = AF_BLUETOOTH;
addr.rc_channel = get_channel (&dev, addr.rc_bdaddr);
-
+
int tries = 0;
connect_retry:
status = connect (sendsocket, (struct sockaddr *) &addr, sizeof (addr));
@@ -1843,7 +1843,7 @@ main (int argc, char *argv[])
memset (&write_pout, 0, sizeof (write_pout));
broadcast = 1;
}
-
+
}
else
{
@@ -1902,19 +1902,19 @@ main (int argc, char *argv[])
write_std.size = 0;
}
fprintf (stderr, "LOG : %s sends a message to STDOUT\n", dev.iface); //FIXME: debugging message
-
- }
+
+ }
if (sendsocket != -1)
{
if (FD_ISSET (sendsocket , &wfds))
{
ssize_t ret =
- write (sendsocket, write_pout.buf + write_std.pos,
+ write (sendsocket, write_pout.buf + write_std.pos,
write_pout.size - write_pout.pos);
if (0 > ret) //FIXME should I first check the error type?
{
fprintf (stderr, "Failed to write to bluetooth device: %s. Closing the socket!\n",
- strerror (errno));
+ strerror (errno));
for (i = 0; i < neighbours.size; i++)
{
if (neighbours.fds[i] == sendsocket)
@@ -1925,7 +1925,7 @@ main (int argc, char *argv[])
}
}
/* Remove the message */
- memset (&write_pout.buf + write_std.pos, 0, (write_pout.size - write_pout.pos));
+ memset (&write_pout.buf + write_std.pos, 0, (write_pout.size - write_pout.pos));
write_pout.pos = 0 ;
write_pout.size = 0;
}
@@ -1940,7 +1940,7 @@ main (int argc, char *argv[])
(unsigned int) write_pout.size);
break;
}
-
+
if (write_pout.pos == write_pout.size)
{
write_pout.pos = 0;
@@ -1956,14 +1956,14 @@ main (int argc, char *argv[])
{
if (i == STDIN_FILENO)
{
- ssize_t ret =
+ ssize_t ret =
read (i, readbuf, sizeof (readbuf));
if (0 > ret)
{
fprintf (stderr,
"Read error from STDIN: %s\n",
strerror (errno));
- break;
+ break;
}
if (0 == ret)
{
@@ -1975,18 +1975,18 @@ main (int argc, char *argv[])
mst_receive (stdin_mst, readbuf, ret);
fprintf (stderr, "LOG : %s receives a message from STDIN\n", dev.iface); //FIXME: debugging message
}
- }
- else if (i == dev.fd_rfcomm)
+ }
+ else if (i == dev.fd_rfcomm)
{
int readsocket;
struct sockaddr_rc addr = { 0 };
unsigned int opt = sizeof (addr);
-
+
readsocket = accept (dev.fd_rfcomm, (struct sockaddr *) &addr, &opt);
fprintf(stderr, "LOG : %s accepts a message\n", dev.iface); //FIXME: debugging message
if (readsocket == -1)
{
- fprintf (stderr, "Failed to accept a connection on interface: %.*s\n", IFNAMSIZ,
+ fprintf (stderr, "Failed to accept a connection on interface: %.*s\n", IFNAMSIZ,
strerror (errno));
break;
}
@@ -1994,7 +1994,7 @@ main (int argc, char *argv[])
{
FD_SET (readsocket, &rfds);
maxfd = MAX (maxfd, readsocket);
-
+
if (crt_rfds < MAX_PORTS)
rfds_list[crt_rfds++] = readsocket;
else
@@ -2004,19 +2004,19 @@ main (int argc, char *argv[])
break;
}
}
-
- }
- else
+
+ }
+ else
{
struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm;
ssize_t ret;
- fprintf (stderr, "LOG : %s reads something from the socket\n", dev.iface);//FIXME : debugging message
+ fprintf (stderr, "LOG : %s reads something from the socket\n", dev.iface);//FIXME : debugging message
rrm = (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *) write_std.buf;
ret =
read_from_the_socket ((void *)&i, (unsigned char *) &rrm->frame,
- sizeof (write_std.buf)
- - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
- + sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame),
+ sizeof (write_std.buf)
+ - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
+ + sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame),
rrm);
if (0 >= ret)
{
@@ -2041,8 +2041,8 @@ main (int argc, char *argv[])
}
if ((0 < ret) && (0 == mac_test (&rrm->frame, &dev)))
{
- write_std.size = ret
- + sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
+ write_std.size = ret
+ + sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
- sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame);
rrm->header.size = htons (write_std.size);
rrm->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
@@ -2058,7 +2058,7 @@ main (int argc, char *argv[])
sdp_close (dev.session);
(void) close (dev.fd_rfcomm);
(void) close (sendsocket);
-
+
for (i = 0; i < crt_rfds; i++)
(void) close (rfds_list[i]);
@@ -2079,13 +2079,13 @@ main (int argc, char *argv[])
struct MessageStreamTokenizer *stdin_mst;
/* check the handles */
- if (stdin_handle == INVALID_HANDLE_VALUE)
+ if (stdin_handle == INVALID_HANDLE_VALUE)
{
fprintf (stderr, "Failed to get the stdin handle\n");
ExitProcess (2);
}
- if (stdout_handle == INVALID_HANDLE_VALUE)
+ if (stdout_handle == INVALID_HANDLE_VALUE)
{
fprintf (stderr, "Failed to get the stdout handle\n");
ExitProcess (2);
@@ -2111,7 +2111,7 @@ main (int argc, char *argv[])
}
- if (open_device (&dev) == -1)
+ if (open_device (&dev) == -1)
{
fprintf (stderr, "Failed to open the device\n");
print_last_error();
@@ -2121,21 +2121,21 @@ main (int argc, char *argv[])
print_last_error();
}
ExitProcess (2);
- }
+ }
if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking (dev.handle, 1) )
{
fprintf (stderr, "Failed to change the socket mode\n");
ExitProcess (2);
}
-
+
memset (&write_std, 0, sizeof (write_std));
- memset (&write_pout, 0, sizeof (write_pout));
+ memset (&write_pout, 0, sizeof (write_pout));
stdin_open = 1;
rfds = GNUNET_NETWORK_fdset_create ();
wfds = GNUNET_NETWORK_fdset_create ();
-
+
/* Send MAC address of the bluetooth interface to STDOUT first */
{
struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg;
@@ -2146,9 +2146,9 @@ main (int argc, char *argv[])
memcpy (write_std.buf, &macmsg, sizeof (macmsg));
write_std.size = sizeof (macmsg);
}
-
-
- stdin_mst = mst_create (&stdin_send_hw, &dev);
+
+
+ stdin_mst = mst_create (&stdin_send_hw, &dev);
stdin_open = 1;
int pos = 0;
@@ -2161,13 +2161,13 @@ main (int argc, char *argv[])
stdin_pos = -1;
stdout_pos = -1;
sendsocket = NULL; //FIXME ???memleaks
-
- GNUNET_NETWORK_fdset_zero (rfds);
+
+ GNUNET_NETWORK_fdset_zero (rfds);
if ((0 == write_pout.size) && (1 == stdin_open))
{
stdin_pos = pos;
pos +=1;
- GNUNET_NETWORK_fdset_handle_set (rfds, (struct GNUNET_DISK_FileHandle*) &stdin_handle);
+ GNUNET_NETWORK_fdset_handle_set (rfds, (struct GNUNET_DISK_FileHandle*) &stdin_handle);
}
if (0 == write_std.size)
@@ -2175,7 +2175,7 @@ main (int argc, char *argv[])
pos += 1;
GNUNET_NETWORK_fdset_set (rfds, dev.handle);
}
-
+
for (i = 0; i < crt_rfds; i++)
{
pos += 1;
@@ -2189,34 +2189,34 @@ main (int argc, char *argv[])
GNUNET_NETWORK_fdset_handle_set (wfds, (struct GNUNET_DISK_FileHandle*) &stdout_handle);
// printf ("%s\n", write_std.buf);
// memset (write_std.buf, 0, write_std.size);
- // write_std.size = 0;
+ // write_std.size = 0;
}
if (0 < write_pout.size)
- {
+ {
if (strcmp (argv[1], "ff:ff:ff:ff:ff:ff") == 0) {
fprintf(stderr, "LOG: BROADCAST! Skipping the message\n");
// skip the message
broadcast = 1;
memset (write_pout.buf, 0, write_pout.size);
write_pout.size = 0;
- }
- else
+ }
+ else
{
SOCKADDR_BTH addr;
fprintf (stderr, "LOG : has a new message for %s\n", argv[1]);
sendsocket = GNUNET_NETWORK_socket_create (AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
-
- if (sendsocket == NULL)
+
+ if (sendsocket == NULL)
{
fprintf (stderr, "Failed to create RFCOMM socket: \n");
print_last_error();
ExitProcess (2);
}
-
+
memset (&addr, 0, sizeof (addr));
//addr.addressFamily = AF_BTH;
- if (SOCKET_ERROR ==
+ if (SOCKET_ERROR ==
WSAStringToAddress (argv[1], AF_BTH, NULL, (LPSOCKADDR) &addr, &addr_len))
{
fprintf (stderr, "Failed to translate the address: ");
@@ -2250,7 +2250,7 @@ main (int argc, char *argv[])
}
}
}
-
+
if (broadcast == 0)
{
int retval = GNUNET_NETWORK_socket_select (rfds, wfds, NULL, GNUNET_TIME_relative_get_forever_());
@@ -2279,7 +2279,7 @@ main (int argc, char *argv[])
fprintf (stderr, "Failed to write to STDOUT\n");
ExitProcess (2);
}
-
+
write_std.pos += ret;
if (write_std.pos == write_std.size)
{
@@ -2292,9 +2292,9 @@ main (int argc, char *argv[])
if (GNUNET_NETWORK_fdset_isset (wfds, sendsocket))
{
ssize_t ret;
- ret = GNUNET_NETWORK_socket_send (sendsocket, write_pout.buf + write_pout.pos,
+ ret = GNUNET_NETWORK_socket_send (sendsocket, write_pout.buf + write_pout.pos,
write_pout.size - write_pout.pos);
-
+
if (GNUNET_SYSERR == ret)
{
fprintf (stderr, "Failed to send to the socket. Closing the socket. Error: \n");
@@ -2317,22 +2317,22 @@ main (int argc, char *argv[])
(unsigned int) write_pout.size);
break;
}
-
+
if (write_pout.pos == write_pout.size)
{
write_pout.pos = 0;
write_pout.size = 0;
-
+
}
fprintf(stderr, "LOG : sends a message to a DEVICE\n"); //FIXME: debugging message
}
}
}
-
+
//if (GNUNET_NETWORK_fdset_isset (rfds, (struct GNUNET_NETWORK_Handle*)&stdin_handle))
if (retval == stdin_pos)
{
- //ssize_t ret;
+ //ssize_t ret;
//ret = GNUNET_NETWORK_socket_recv ((struct GNUNET_NETWORK_Handle *)&stdin_handle, readbuf, sizeof (write_pout.buf));
//ret = read (STDIN_FILENO, readbuf, sizeof (readbuf));
DWORD ret;
@@ -2356,7 +2356,7 @@ main (int argc, char *argv[])
{
fprintf (stderr, "LOG: accepting connection\n");
struct GNUNET_NETWORK_Handle *readsocket;
- readsocket = GNUNET_NETWORK_socket_accept (dev.handle, (LPSOCKADDR)&acc_addr, &addr_len);
+ readsocket = GNUNET_NETWORK_socket_accept (dev.handle, (LPSOCKADDR)&acc_addr, &addr_len);
if (readsocket == NULL)
{
fprintf (stderr, "Accept error %d: ", GetLastError());
@@ -2386,14 +2386,14 @@ main (int argc, char *argv[])
{
if (GNUNET_NETWORK_fdset_isset (rfds, rfds_list[i]))
{
- struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm;
+ struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm;
ssize_t ret;
fprintf (stderr, "LOG: reading something from the socket\n");//FIXME : debugging message
rrm = (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *) write_std.buf;
ret = read_from_the_socket (rfds_list[i], (unsigned char *) &rrm->frame,
- sizeof (write_std.buf)
- - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
- + sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame),
+ sizeof (write_std.buf)
+ - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
+ + sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame),
rrm);
if (0 >= ret)
{
@@ -2408,22 +2408,22 @@ main (int argc, char *argv[])
fprintf (stderr, "Read error from raw socket: ");
print_last_error();
break;
-
+
}
if ((0 < ret) && (0 == mac_test (&rrm->frame, &dev)))
{
- write_std.size = ret
- + sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
+ write_std.size = ret
+ + sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
- sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame);
rrm->header.size = htons (write_std.size);
rrm->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
}
break;
}
- }
+ }
}
}
-
+
mst_destroy (stdin_mst);
stdin_mst = NULL;