#include "platform.h"
#include "gnunet_private_config.h"
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
#include <bluetooth/rfcomm.h>
#include <bluetooth/sdp.h>
#include <bluetooth/sdp_lib.h>
#include <errno.h>
#include <linux/if.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "plugin_transport_wlan.h"
#include "gnunet_protocols.h"
Go to the source code of this file.
Data Structures | |
struct | HardwareInfos |
struct for storing the information of the hardware. More... | |
struct | SendBuffer |
IO buffer used for buffering data in transit (to wireless or to stdout). More... | |
struct | MessageStreamTokenizer |
Handle to a message stream tokenizer. More... | |
Macros | |
#define | MAX_PORTS 30 |
Maximum number of ports assignable for RFCOMMM protocol. More... | |
#define | MAXLINE 4096 |
Maximum size of a message allowed in either direction (used for our receive and sent buffers). More... | |
#define | MAX_LOOPS 5 |
Maximum number of loops without inquiring for new devices. More... | |
#define | BLUEZ_DEVNAME_SIZE 8 |
In bluez library, the maximum name length of a device is 8. More... | |
#define | ALIGN_FACTOR 8 |
To what multiple do we align messages? 8 byte should suffice for everyone for now. More... | |
#define | MIN_BUFFER_SIZE sizeof(struct GNUNET_MessageHeader) |
Smallest supported message. More... | |
Typedefs | |
typedef void(* | MessageTokenizerCallback) (void *cls, const struct GNUNET_MessageHeader *message) |
Functions with this signature are called whenever a complete message is received by the tokenizer. More... | |
Functions | |
static struct MessageStreamTokenizer * | mst_create (MessageTokenizerCallback cb, void *cb_cls) |
Create a message stream tokenizer. More... | |
static int | mst_receive (struct MessageStreamTokenizer *mst, const char *buf, size_t size) |
Add incoming data to the receive buffer and call the callback for all complete messages. More... | |
static void | mst_destroy (struct MessageStreamTokenizer *mst) |
Destroys a tokenizer. More... | |
static unsigned long | calc_crc_osdep (const unsigned char *buf, size_t len) |
Calculate crc32, the start of the calculation. More... | |
static int | check_crc_buf_osdep (const unsigned char *buf, size_t len) |
Calculate and check crc of the bluetooth packet. More... | |
static int | register_service (struct HardwareInfos *dev, int rc_channel) |
Function used for creating the service record and registering it. More... | |
static int | get_channel (struct HardwareInfos *dev, bdaddr_t dest) |
Function used for searching and browsing for a service. More... | |
static ssize_t | read_from_the_socket (void *sock, unsigned char *buf, size_t buf_size, struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *ri) |
Read from the socket and put the result into the buffer for transmission to 'stdout'. More... | |
static int | open_device (struct HardwareInfos *dev) |
Open the bluetooth interface for reading/writing. More... | |
static void | mac_set (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader, const struct HardwareInfos *dev) |
Set the header to sane values to make attacks more difficult. More... | |
static int | mac_test (const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader, const struct HardwareInfos *dev) |
Test incoming packets mac for being our own. More... | |
static void | stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr) |
Process data from the stdin. More... | |
int | main (int argc, char *argv[]) |
Main function of the helper. More... | |
Variables | |
static struct SendBuffer | write_pout |
Buffer for data read from stdin to be transmitted to the bluetooth device. More... | |
static struct SendBuffer | write_std |
Buffer for data read from the bluetooth device to be transmitted to stdout. More... | |
#define MAX_PORTS 30 |
Maximum number of ports assignable for RFCOMMM protocol.
Definition at line 49 of file gnunet-helper-transport-bluetooth.c.
#define MAXLINE 4096 |
Maximum size of a message allowed in either direction (used for our receive and sent buffers).
Definition at line 55 of file gnunet-helper-transport-bluetooth.c.
#define MAX_LOOPS 5 |
Maximum number of loops without inquiring for new devices.
Definition at line 61 of file gnunet-helper-transport-bluetooth.c.
#define BLUEZ_DEVNAME_SIZE 8 |
In bluez library, the maximum name length of a device is 8.
Definition at line 66 of file gnunet-helper-transport-bluetooth.c.
#define ALIGN_FACTOR 8 |
To what multiple do we align messages? 8 byte should suffice for everyone for now.
Definition at line 176 of file gnunet-helper-transport-bluetooth.c.
#define MIN_BUFFER_SIZE sizeof(struct GNUNET_MessageHeader) |
Smallest supported message.
Definition at line 181 of file gnunet-helper-transport-bluetooth.c.
typedef void(* MessageTokenizerCallback) (void *cls, const struct GNUNET_MessageHeader *message) |
Functions with this signature are called whenever a complete message is received by the tokenizer.
cls | closure |
message | the actual message |
Definition at line 191 of file gnunet-helper-transport-bluetooth.c.
|
static |
Create a message stream tokenizer.
cb | function to call on completed messages |
cb_cls | closure for cb |
Definition at line 241 of file gnunet-helper-transport-bluetooth.c.
References MessageStreamTokenizer::cb, MessageStreamTokenizer::cb_cls, MIN_BUFFER_SIZE, and ret.
Referenced by main().
|
static |
Add incoming data to the receive buffer and call the callback for all complete messages.
mst | tokenizer to use |
buf | input data to add |
size | number of bytes in buf |
Definition at line 278 of file gnunet-helper-transport-bluetooth.c.
References ALIGN_FACTOR, buf, MessageStreamTokenizer::cb, MessageStreamTokenizer::cb_cls, MessageStreamTokenizer::curr_buf, delta, do_align(), GNUNET_memcpy, GNUNET_MIN, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, MessageStreamTokenizer::hdr, MessageStreamTokenizer::off, MessageStreamTokenizer::pos, ret, GNUNET_MessageHeader::size, and size.
Referenced by main().
|
static |
Destroys a tokenizer.
mst | tokenizer to destroy |
Definition at line 456 of file gnunet-helper-transport-bluetooth.c.
References MessageStreamTokenizer::hdr.
Referenced by main().
|
static |
Calculate crc32, the start of the calculation.
buf | buffer to calc the crc |
len | len of the buffer |
Definition at line 471 of file gnunet-helper-transport-bluetooth.c.
Referenced by check_crc_buf_osdep().
|
static |
Calculate and check crc of the bluetooth packet.
buf | buffer of the packet, with len + 4 bytes of data, the last 4 bytes being the checksum |
len | length of the payload in data |
Definition at line 557 of file gnunet-helper-transport-bluetooth.c.
References buf, calc_crc_osdep(), and len.
Referenced by read_from_the_socket().
|
static |
Function used for creating the service record and registering it.
dev | pointer to the device struct |
rc_channel | the rfcomm channel |
Definition at line 609 of file gnunet-helper-transport-bluetooth.c.
References HardwareInfos::iface, GNUNET_TRANSPORT_WLAN_MacAddress::mac, HardwareInfos::pl_mac, record(), and HardwareInfos::session.
Referenced by open_device().
|
static |
Function used for searching and browsing for a service.
This will return the port number on which the service is running.
dev | pointer to the device struct |
dest | target address |
Definition at line 703 of file gnunet-helper-transport-bluetooth.c.
References warningfilter::dest, HardwareInfos::iface, and record().
Referenced by main().
|
static |
Read from the socket and put the result into the buffer for transmission to 'stdout'.
sock | file descriptor for reading |
buf | buffer to read to; first bytes will be the 'struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame', followed by the actual payload |
buf_size | size of the buffer |
ri | where to write radiotap_rx info |
Definition at line 780 of file gnunet-helper-transport-bluetooth.c.
References buf, check_crc_buf_osdep(), GNUNET_memcpy, len, and GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage::ri_channel.
Referenced by main().
|
static |
Open the bluetooth interface for reading/writing.
dev | pointer to the device struct |
Copy the MAC address to the device structure
Definition at line 836 of file gnunet-helper-transport-bluetooth.c.
References BLUEZ_DEVNAME_SIZE, HardwareInfos::fd_rfcomm, GNUNET_memcpy, HardwareInfos::iface, list, MAX_PORTS, neighbours, HardwareInfos::pl_mac, register_service(), and request.
Referenced by main().
|
static |
Set the header to sane values to make attacks more difficult.
taIeeeHeader | pointer to the header of the packet |
dev | pointer to the Hardware_Infos struct |
copy from gnunet-helper-transport-wlan.c ****
Definition at line 1007 of file gnunet-helper-transport-bluetooth.c.
References GNUNET_TRANSPORT_WLAN_Ieee80211Frame::addr2, GNUNET_TRANSPORT_WLAN_Ieee80211Frame::addr3, GNUNET_TRANSPORT_WLAN_Ieee80211Frame::frame_control, IEEE80211_FC0_TYPE_DATA, mac_bssid_gnunet, and HardwareInfos::pl_mac.
Referenced by stdin_send_hw().
|
static |
Test incoming packets mac for being our own.
taIeeeHeader | buffer of the packet |
dev | the Hardware_Infos struct |
same as the one from gnunet-helper-transport-wlan.c ****
Definition at line 1058 of file gnunet-helper-transport-bluetooth.c.
References GNUNET_TRANSPORT_WLAN_Ieee80211Frame::addr1, GNUNET_TRANSPORT_WLAN_Ieee80211Frame::addr3, all_zeros, bc_all_mac, MAC_ADDR_SIZE, mac_bssid_gnunet, and HardwareInfos::pl_mac.
Referenced by main().
|
static |
Process data from the stdin.
Takes the message, forces the sender MAC to be correct and puts it into our buffer for transmission to the receiver.
cls | pointer to the device struct ('struct HardwareInfos*') |
hdr | pointer to the start of the packet |
same as the one from gnunet-helper-transport-wlan.c ****
Definition at line 1086 of file gnunet-helper-transport-bluetooth.c.
References GNUNET_TRANSPORT_WLAN_Ieee80211Frame::addr1, SendBuffer::buf, GNUNET_TRANSPORT_WLAN_RadiotapSendMessage::frame, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER, GNUNET_TRANSPORT_WLAN_RadiotapSendMessage::header, mac_set(), MAXLINE, GNUNET_MessageHeader::size, SendBuffer::size, GNUNET_MessageHeader::type, and write_pout.
Referenced by main().
int main | ( | int | argc, |
char * | argv[] | ||
) |
Main function of the helper.
This code accesses a bluetooth interface forwards traffic in both directions between the bluetooth interface and stdin/stdout of this process. Error messages are written to stderr.
argc | number of arguments, must be 2 |
argv | arguments only argument is the name of the interface (e.g. 'hci0') |
similar to gnunet-helper-transport-wlan.c ****
Definition at line 1384 of file gnunet-helper-transport-bluetooth.c.
References GNUNET_TRANSPORT_WLAN_Ieee80211Frame::addr1, SendBuffer::buf, HardwareInfos::fd_rfcomm, GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage::frame, get_channel(), GNUNET_memcpy, GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER, GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL, GNUNET_NETWORK_fdset_create(), GNUNET_NETWORK_fdset_handle_set(), GNUNET_NETWORK_fdset_isset(), GNUNET_NETWORK_fdset_set(), GNUNET_NETWORK_fdset_zero(), GNUNET_NETWORK_socket_accept(), GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_connect(), GNUNET_NETWORK_socket_create(), GNUNET_NETWORK_socket_select(), GNUNET_NETWORK_socket_send(), GNUNET_NETWORK_socket_set_blocking(), GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_relative_get_forever_(), GNUNET_TRANSPORT_WLAN_HelperControlMessage::hdr, GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage::header, HardwareInfos::iface, GNUNET_TRANSPORT_WLAN_MacAddress::mac, GNUNET_TRANSPORT_WLAN_HelperControlMessage::mac, mac_test(), MAX_PORTS, MAXLINE, mst_create(), mst_destroy(), mst_receive(), neighbours, open_device(), HardwareInfos::pl_mac, SendBuffer::pos, read_from_the_socket(), ret, HardwareInfos::session, GNUNET_MessageHeader::size, SendBuffer::size, GNUNET_CONTAINER_MultiPeerMap::size, status, stdin_mst, stdin_send_hw(), GNUNET_MessageHeader::type, write_pout, and write_std.
|
static |
Buffer for data read from stdin to be transmitted to the bluetooth device.
Definition at line 1 of file gnunet-helper-transport-bluetooth.c.
Referenced by main(), stdin_send(), and stdin_send_hw().
|
static |
Buffer for data read from the bluetooth device to be transmitted to stdout.
Definition at line 1 of file gnunet-helper-transport-bluetooth.c.
Referenced by file_in_send(), and main().