#define IEEE80211_FC0_TYPE_CTL 0x04
#define IEEE80211_FC0_TYPE_DATA 0x08
-/*
- * Structure of an internet header, naked of options.
- */
-struct iph
-{
-#if __BYTE_ORDER == __LITTLE_ENDIAN
- unsigned int ip_hl:4; /* header length */
- unsigned int ip_v:4; /* version */
-#endif
-#if __BYTE_ORDER == __BIG_ENDIAN
- unsigned int ip_v:4; /* version */
- unsigned int ip_hl:4; /* header length */
-#endif
- u_int8_t ip_tos; /* type of service */
- u_short ip_len; /* total length */
- u_short ip_id; /* identification */
- u_short ip_off; /* fragment offset field */
-#define IP_RF 0x8000 /* reserved fragment flag */
-#define IP_DF 0x4000 /* dont fragment flag */
-#define IP_MF 0x2000 /* more fragments flag */
-#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
- u_int8_t ip_ttl; /* time to live */
- u_int8_t ip_p; /* protocol */
- u_short ip_sum; /* checksum */
- struct in_addr ip_src, ip_dst; /* source and dest address */
-};
-
-struct udphdr
-{
- u_int16_t source;
- u_int16_t dest;
- u_int16_t len;
- u_int16_t check;
-};
+GNUNET_NETWORK_STRUCT_BEGIN
/*
* generic definitions for IEEE 802.11 frames
u_int8_t i_addr3[IEEE80211_ADDR_LEN];
u_int8_t i_seq[2];
u_int8_t llc[4];
-#if DEBUG_wlan_ip_udp_packets_on_air > 1
- struct iph ip;
- struct udphdr udp;
-#endif
} GNUNET_PACKED;
+GNUNET_NETWORK_STRUCT_END
/**
* Encapsulation of all of the state of the plugin.
struct GNUNET_SERVER_MessageStreamTokenizer *data_tokenizer;
/**
- * stdout pipe handle for the gnunet-wlan-helper process
+ * stdout pipe handle for the gnunet-helper-transport-wlan process
*/
struct GNUNET_DISK_PipeHandle *server_stdout;
/**
- * stdout file handle for the gnunet-wlan-helper process
+ * stdout file handle for the gnunet-helper-transport-wlan process
*/
const struct GNUNET_DISK_FileHandle *server_stdout_handle;
/**
- * stdin pipe handle for the gnunet-wlan-helper process
+ * stdin pipe handle for the gnunet-helper-transport-wlan process
*/
struct GNUNET_DISK_PipeHandle *server_stdin;
/**
- * stdin file handle for the gnunet-wlan-helper process
+ * stdin file handle for the gnunet-helper-transport-wlan process
*/
const struct GNUNET_DISK_FileHandle *server_stdin_handle;
struct Sessionqueue *next;
struct Sessionqueue *prev;
struct Session *content;
+#if !HAVE_UNALIGNED_64_ACCESS
+ void *dummy; /* for alignment, see #1909 */
+#endif
};
/**
struct Session *session;
};
+
+GNUNET_NETWORK_STRUCT_BEGIN
+
+/**
+ * Header for messages which need fragmentation
+ */
+struct WlanHeader
+{
+
+ struct GNUNET_MessageHeader header;
+
+ /**
+ * checksum/error correction
+ */
+ uint32_t crc GNUNET_PACKED;
+
+ /**
+ * To whom are we talking to (set to our identity
+ * if we are still waiting for the welcome message)
+ */
+ struct GNUNET_PeerIdentity target;
+
+ /**
+ * Where the packet came from
+ */
+ struct GNUNET_PeerIdentity source;
+
+// followed by payload
+
+};
+GNUNET_NETWORK_STRUCT_END
+
/**
* Information kept for each message that is yet to
* be transmitted.
else
t += sprintf (t, " ");
- t += sprintf (t, j % 2 ? " " : "-");
+ t += sprintf (t, (j % 2) ? " " : "-");
}
t += sprintf (t, " ");
struct GNUNET_TIME_Relative next_send;
//abort if helper is not running
- if (plugin->helper_is_running == GNUNET_NO){
- return;
+ if (plugin->helper_is_running == GNUNET_NO)
+ {
+ return;
}
//cancel old task
Header->i_fc[0] = IEEE80211_FC0_TYPE_DATA;
Header->i_fc[1] = 0x00;
- memcpy (&Header->i_addr3, &mac_bssid, sizeof (mac_bssid));
+ memcpy (&Header->i_addr3, &mac_bssid_gnunet, sizeof (mac_bssid_gnunet));
memcpy (&Header->i_addr2, plugin->mac_address.mac,
sizeof (plugin->mac_address));
memcpy (&Header->i_addr1, to_mac_addr, sizeof (struct MacAddress));
tmp16 = (uint16_t *) Header->i_dur;
- *tmp16 = (uint16_t) htole16 ((size * 1000000) / rate + 290);
+ *tmp16 = (uint16_t) GNUNET_htole16 ((size * 1000000) / rate + 290);
Header->llc[0] = WLAN_LLC_DSAP_FIELD;
Header->llc[1] = WLAN_LLC_SSAP_FIELD;
-#if DEBUG_wlan_ip_udp_packets_on_air > 1
- uint crc = 0;
- uint16_t *x;
- int count;
-
- Header->ip.ip_dst.s_addr = *((uint32_t *) & to_mac_addr->mac[2]);
- Header->ip.ip_src.s_addr = *((uint32_t *) & plugin->mac_address.mac[2]);
- Header->ip.ip_v = 4;
- Header->ip.ip_hl = 5;
- Header->ip.ip_p = 17;
- Header->ip.ip_ttl = 1;
- Header->ip.ip_len = htons (size + 8);
- Header->ip.ip_sum = 0;
- x = (uint16_t *) & Header->ip;
- count = sizeof (struct iph);
- while (count > 1)
- {
- /* This is the inner loop */
- crc += (unsigned short) *x++;
- count -= 2;
- }
- /* Add left-over byte, if any */
- if (count > 0)
- crc += *(unsigned char *) x;
- crc = (crc & 0xffff) + (crc >> 16);
- Header->ip.ip_sum = htons (~(unsigned short) crc);
- Header->udp.len = htons (size - sizeof (struct ieee80211_frame));
-
-#endif
-
return GNUNET_YES;
}
/**
- * We have been notified that wlan-helper has written something to stdout.
+ * We have been notified that gnunet-helper-transport-wlan has written something to stdout.
* Handle the output, then reschedule this function to be called again once
* more is available.
*
#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
_
- ("Finished reading from wlan-helper stdout with code: %d\n"),
+ ("Finished reading from gnunet-helper-transport-wlan stdout with code: %d\n"),
bytes);
#endif
return;
}
/**
- * Start the gnunet-wlan-helper process.
+ * Start the gnunet-helper-transport-wlan process.
*
* @param plugin the transport plugin
* @return GNUNET_YES if process was started, GNUNET_SYSERR on error
static int
wlan_transport_start_wlan_helper (struct Plugin *plugin)
{
- const char *filenamehw = "gnunet-transport-wlan-helper";
- const char *filenameloopback = "gnunet-transport-wlan-helper-dummy";
+ const char *filenamehw = "gnunet-helper-transport-wlan";
+ const char *filenameloopback = "gnunet-helper-transport-wlan-dummy";
char *absolute_filename = NULL;
- if (plugin->helper_is_running == GNUNET_YES){
+ if (plugin->helper_is_running == GNUNET_YES)
+ {
#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"wlan_transport_start_wlan_helper not needed, helper already running!");
#endif
- return GNUNET_YES;
+ return GNUNET_YES;
}
- plugin->server_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
+ plugin->server_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
if (plugin->server_stdout == NULL)
return GNUNET_SYSERR;
- plugin->server_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO);
+ plugin->server_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO);
if (plugin->server_stdin == NULL)
return GNUNET_SYSERR;
{
if (GNUNET_OS_check_helper_binary (filenameloopback) == GNUNET_YES)
{
- absolute_filename = strdup (filenameloopback);
+ absolute_filename = GNUNET_strdup (filenameloopback);
}
else
{
#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Starting gnunet-wlan-helper process cmd: %s %s %i\n",
+ "Starting gnunet-helper-transport-wlan process cmd: %s %s %i\n",
filenamehw, plugin->interface, plugin->testmode);
#endif
if (GNUNET_OS_check_helper_binary (filenamehw) == GNUNET_YES)
{
plugin->server_proc =
- GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout,
+ GNUNET_OS_start_process (GNUNET_NO, plugin->server_stdin, plugin->server_stdout,
filenamehw, filenamehw, plugin->interface,
NULL);
}
else if (GNUNET_OS_check_helper_binary (filenamehw) == GNUNET_NO)
{
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
- "gnunet-transport-wlan-helper is not suid, please change it or look at the doku\n");
+ "gnunet-helper-transport-wlan is not suid, please change it or look at the doku\n");
GNUNET_break (0);
}
else
{
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
- "gnunet-transport-wlan-helper not found, please look if it exists and is the $PATH variable!\n");
+ "gnunet-helper-transport-wlan not found, please look if it exists and is the $PATH variable!\n");
GNUNET_break (0);
}
#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
- "Starting gnunet-transport-wlan-helper-dummy loopback 1 process cmd: %s %s %i\n",
+ "Starting gnunet-helper-transport-wlan-dummy loopback 1 process cmd: %s %s %i\n",
absolute_filename, plugin->interface, plugin->testmode);
#endif
plugin->server_proc =
- GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout,
+ GNUNET_OS_start_process (GNUNET_NO, plugin->server_stdin, plugin->server_stdout,
absolute_filename, absolute_filename, "1",
NULL);
if (plugin->server_proc == NULL)
{
#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
- "Starting gnunet-transport-wlan-helper-dummy loopback 2 process cmd: %s %s %i\n",
+ "Starting gnunet-helper-transport-wlan-dummy loopback 2 process cmd: %s %s %i\n",
absolute_filename, plugin->interface, plugin->testmode);
#endif
plugin->server_proc =
- GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout,
+ GNUNET_OS_start_process (GNUNET_NO, plugin->server_stdin, plugin->server_stdout,
absolute_filename, absolute_filename, "2",
NULL);
if (plugin->server_proc == NULL)
{
#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Failed to start gnunet-transport-wlan-helper process\n");
+ "Failed to start gnunet-helper-transport-wlan process\n");
#endif
return GNUNET_SYSERR;
}
#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
- "Adding server_read_task for the wlan-helper\n");
+ "Adding server_read_task for the gnunet-helper-transport-wlan\n");
#endif
plugin->server_read_task =
}
/**
- * Stops the gnunet-wlan-helper process.
+ * Stops the gnunet-helper-transport-wlan process.
*
* @param plugin the transport plugin
* @return GNUNET_YES if process was started, GNUNET_SYSERR on error
"Stoping WLAN helper process\n");
#endif
- if (plugin->helper_is_running == GNUNET_NO){
+ if (plugin->helper_is_running == GNUNET_NO)
+ {
#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
"wlan_transport_stop_wlan_helper not needed, helper already stopped!");
#endif
- return GNUNET_YES;
+ return GNUNET_YES;
}
if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK)
{
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
_
- ("Error writing to wlan healper. errno == %d, ERROR: %s\n"),
+ ("Error writing to wlan helper. errno == %d, ERROR: %s\n"),
errno, strerror (errno));
finish = GNUNET_malloc (sizeof (struct Finish_send));
finish->plugin = plugin;
{
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
_
- ("Error writing to wlan healper. errno == %d, ERROR: %s\n"),
+ ("Error writing to wlan helper. errno == %d, ERROR: %s\n"),
errno, strerror (errno));
finish = GNUNET_malloc (sizeof (struct Finish_send));
finish->plugin = plugin;
{
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
_
- ("Error writing to wlan healper. errno == %d, ERROR: %s\n"),
+ ("Error writing to wlan helper. errno == %d, ERROR: %s\n"),
errno, strerror (errno));
finish->head_of_next_write = fm->frag;
return GNUNET_SYSERR;
}
+
+/**
+ * Creates a new outbound session the transport service will use to send data to the
+ * peer
+ *
+ * @param cls the plugin
+ * @param address the address
+ * @return the session or NULL of max connections exceeded
+ */
+
+static struct Session *
+wlan_plugin_get_session (void *cls,
+ const struct GNUNET_HELLO_Address *address)
+{
+ struct Plugin *plugin = cls;
+ struct Session * s = NULL;
+
+ GNUNET_assert (plugin != NULL);
+ GNUNET_assert (address != NULL);
+
+ if (GNUNET_OK == wlan_plugin_address_suggested (plugin,
+ address->address,
+ address->address_length))
+ {
+ s = get_session (plugin, address->address, &address->peer);
+ }
+ else
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
+ _("Wlan Address len %d is wrong\n"), address->address_length);
+ return s;
+ }
+
+ return s;
+}
+
/**
* Function that can be used by the transport service to transmit
- * a message using the plugin.
+ * a message using the plugin. Note that in the case of a
+ * peer disconnecting, the continuation MUST be called
+ * prior to the disconnect notification itself. This function
+ * will be called with this peer's HELLO message to initiate
+ * a fresh connection to another peer.
*
* @param cls closure
- * @param target who should receive this message
- * @param priority how important is the message
+ * @param session which session must be used
* @param msgbuf the message to transmit
* @param msgbuf_size number of bytes in 'msgbuf'
- * @param timeout when should we time out
- * @param session which session must be used (or NULL for "any")
- * @param addr the address to use (can be NULL if the plugin
- * is "on its own" (i.e. re-use existing TCP connection))
- * @param addrlen length of the address in bytes
- * @param force_address GNUNET_YES if the plugin MUST use the given address,
- * otherwise the plugin may use other addresses or
- * existing connections (if available)
+ * @param priority how important is the message (most plugins will
+ * ignore message priority and just FIFO)
+ * @param to how long to wait at most for the transmission (does not
+ * require plugins to discard the message after the timeout,
+ * just advisory for the desired delay; most plugins will ignore
+ * this as well)
* @param cont continuation to call once the message has
* been transmitted (or if the transport is ready
* for the next transmission call; or if the
- * peer disconnected...)
+ * peer disconnected...); can be NULL
* @param cont_cls closure for cont
* @return number of bytes used (on the physical network, with overheads);
* -1 on hard errors (i.e. address invalid); 0 is a legal value
* and does NOT mean that the message was not transmitted (DV)
*/
static ssize_t
-wlan_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
- const char *msgbuf, size_t msgbuf_size, unsigned int priority,
- struct GNUNET_TIME_Relative timeout, struct Session *session,
- const void *addr, size_t addrlen, int force_address,
+wlan_plugin_send (void *cls,
+ struct Session *session,
+ const char *msgbuf, size_t msgbuf_size,
+ unsigned int priority,
+ struct GNUNET_TIME_Relative to,
GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
{
struct Plugin *plugin = cls;
struct WlanHeader *wlanheader;
GNUNET_assert (plugin != NULL);
- //check if msglen > 0
+ GNUNET_assert (session != NULL);
GNUNET_assert (msgbuf_size > 0);
- //get session if needed
- if (session == NULL)
- {
- if (wlan_plugin_address_suggested (plugin, addr, addrlen) == GNUNET_OK)
- {
- session = get_session (plugin, addr, target);
- }
- else
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
- _("Wlan Address len %d is wrong\n"), addrlen);
- return -1;
- }
- }
-
- GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan messages queued"), 1,
- GNUNET_NO);
-
//queue message:
//queue message in session
//copy msg to buffer, not fragmented / segmented yet, but with message header
wlanheader->header.size = htons (msgbuf_size + sizeof (struct WlanHeader));
wlanheader->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA);
- memcpy (&(wlanheader->target), target, sizeof (struct GNUNET_PeerIdentity));
+ memcpy (&(wlanheader->target), &session->target, sizeof (struct GNUNET_PeerIdentity));
memcpy (&(wlanheader->source), plugin->env->my_identity,
sizeof (struct GNUNET_PeerIdentity));
wlanheader->crc = 0;
newmsg->transmit_cont = cont;
newmsg->transmit_cont_cls = cont_cls;
- newmsg->timeout = GNUNET_TIME_relative_to_absolute (timeout);
+ newmsg->timeout = GNUNET_TIME_relative_to_absolute (to);
newmsg->timeout.abs_value = newmsg->timeout.abs_value - 500;
check_fragment_queue (plugin);
//FIXME not the correct size
return msgbuf_size;
-
}
+
/**
* function to free a mac endpoint
* @param plugin pointer to the plugin struct
* function to free a session
* @param plugin pointer to the plugin
* @param queue pointer to the sessionqueue element to free
- * @param free_macendpoint if GNUNET_YES and mac endpoint would be empty, free mac endpoint
+ * @param do_free_macendpoint if GNUNET_YES and mac endpoint would be empty, free mac endpoint
*/
static void
free_session (struct Plugin *plugin, struct Sessionqueue *queue,
temp_hdr = (const struct GNUNET_MessageHeader *) &wlanheader[1];
crc = ntohl (wlanheader->crc);
wlanheader->crc = 0;
- if (GNUNET_CRYPTO_crc32_n ((char *) wlanheader, ntohs (wlanheader->header.size)) != crc)
+ if (GNUNET_CRYPTO_crc32_n
+ ((char *) wlanheader, ntohs (wlanheader->header.size)) != crc)
{
//wrong crc, dispose message
GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
"Wlan message header crc was wrong: %u != %u\n",
GNUNET_CRYPTO_crc32_n ((char *) wlanheader,
- ntohs (wlanheader->header.size)), crc);
+ ntohs (wlanheader->header.size)),
+ crc);
hexdump ((void *) hdr, ntohs (hdr->size));
return;
}
GNUNET_assert (cls != NULL);
struct Session *session = (struct Session *) client;
struct Plugin *plugin = (struct Plugin *) cls;
+ struct GNUNET_ATS_Information ats[2];
- struct GNUNET_ATS_Information distance;
-
- distance.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
- distance.value = htonl (1);
+ ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
+ ats[0].value = htonl (1);
+ ats[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
+ ats[1].value = htonl (GNUNET_ATS_NET_WLAN);
#if DEBUG_wlan
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
#endif
plugin->env->receive (plugin->env->cls, &(session->target), hdr,
- (const struct GNUNET_ATS_Information *) &distance, 1,
+ (const struct GNUNET_ATS_Information *) &ats, 2,
session, (const char *) &session->mac->addr,
sizeof (session->mac->addr));
}
//check for bssid
if (memcmp
- (&(wlanIeeeHeader->i_addr3), &mac_bssid,
+ (&(wlanIeeeHeader->i_addr3), &mac_bssid_gnunet,
sizeof (struct MacAddress)) == 0)
{
//check for broadcast or mac
break;
case GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL:
//TODO more control messages
- if (ntohs (hdr->size) != sizeof (struct Wlan_Helper_Control_Message))
+ if (ntohs (hdr->size) != sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage))
{
GNUNET_break (0);
/* FIXME: restart SUID process */
api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
api->cls = plugin;
api->send = &wlan_plugin_send;
+ api->get_session = &wlan_plugin_get_session;
api->disconnect = &wlan_plugin_disconnect;
api->address_pretty_printer = &wlan_plugin_address_pretty_printer;
api->check_address = &wlan_plugin_address_suggested;