33 #define FIFO_FILE1 "/tmp/test-transport/api-wlan-p1/WLAN_FIFO_in"
38 #define FIFO_FILE2 "/tmp/test-transport/api-wlan-p1/WLAN_FIFO_out"
136 sendsize = ntohs (hdr->
size);
141 fprintf (stderr,
"%s",
"Received malformed message\n");
150 fprintf (stderr,
"%s",
"Packet too big for buffer\n");
153 memset (&newheader, 0,
sizeof(newheader));
154 newheader.
header.
size = htons (payload_size +
sizeof(newheader));
182 sendsize = ntohs (hdr->
size);
185 fprintf (stderr,
"%s",
"Packet too big for buffer\n");
226 ((0 != strcmp (argv[1],
"1")) && (0 != strcmp (argv[1],
"2"))))
231 "This program must be started with the operating mode (1 or 2) as the only argument.\n");
240 fprintf (stderr,
"Failed to create directory for file `%s'\n",
FIFO_FILE1);
243 if (0 == strcmp (argv[1],
"1"))
248 if ((0 != erg) && (EEXIST != errno))
250 "Error in mkfifo(%s): %s\n",
260 if ((0 != erg) && (EEXIST != errno))
262 "Error in mkfifo(%s): %s\n",
268 if (0 == strcmp (argv[1],
"1"))
275 "fopen of read FIFO_FILE1 failed: %s\n",
279 if (NULL == (fpout = fopen (
FIFO_FILE2,
"w")))
287 "fopen of write FIFO_FILE2 failed: %s\n",
295 if (NULL == (fpout = fopen (
FIFO_FILE1,
"w")))
303 "fopen of write FIFO_FILE1 failed: %s\n",
311 "fopen of read FIFO_FILE2 failed: %s\n",
317 fdpin = fileno (fpin);
319 if (fdpin >= FD_SETSIZE)
322 "File fdpin number too large (%d > %u)\n",
324 (
unsigned int) FD_SETSIZE);
328 fdpout = fileno (fpout);
331 if (fdpout >= FD_SETSIZE)
334 "File fdpout number too large (%d > %u)\n",
336 (
unsigned int) FD_SETSIZE);
352 macaddr.
mac[0] = 0x13;
353 macaddr.
mac[1] = 0x22;
354 macaddr.
mac[2] = 0x33;
355 macaddr.
mac[3] = 0x44;
371 FD_SET (STDIN_FILENO, &rfds);
372 maxfd = MAX (STDIN_FILENO, maxfd);
376 FD_SET (fdpin, &rfds);
377 maxfd = MAX (fdpin, maxfd);
383 FD_SET (STDOUT_FILENO, &wfds);
384 maxfd = MAX (maxfd, STDOUT_FILENO);
388 FD_SET (fdpout, &wfds);
389 maxfd = MAX (maxfd, fdpout);
392 retval = select (maxfd + 1, &rfds, &wfds, NULL, &tv);
393 if ((-1 == retval) && (EINTR == errno))
397 fprintf (stderr,
"select failed: %s\n", strerror (errno));
402 if (FD_ISSET (STDOUT_FILENO, &wfds))
404 ret = write (STDOUT_FILENO,
411 "Write ERROR to STDOUT_FILENO: %s\n",
427 if (FD_ISSET (fdpout, &wfds))
437 "Write ERROR to fdpout failed: %s\n",
452 if (FD_ISSET (STDIN_FILENO, &rfds))
454 readsize = read (STDIN_FILENO, readbuf,
sizeof(readbuf));
460 "Error reading from STDIN_FILENO: %s\n",
463 else if (0 < readsize)
478 if (FD_ISSET (fdpin, &rfds))
480 readsize = read (fdpin, readbuf,
sizeof(readbuf));
484 fprintf (stderr,
"Error reading from fdpin: %s\n", strerror (errno));
487 else if (0 < readsize)
507 if (NULL != file_in_mst)
static int ret
Return value of the commandline.
static int end
Set if we are to shutdown all services (including ARM).
static struct GNUNET_SCHEDULER_Task * st
The shutdown task.
struct GNUNET_MessageStreamTokenizer * stdin_mst
Tokenizer for the data we get from stdin.
static struct SendBuffer write_std
Buffer for data read from the bluetooth device to be transmitted to stdout.
static struct SendBuffer write_pout
Buffer for data read from stdin to be transmitted to the bluetooth device.
int main(int argc, char *argv[])
Main function of a program that pretends to be a WLAN card.
static int closeprog
Flag set to 1 if we are to terminate, otherwise 0.
static int file_in_send(void *cls, const struct GNUNET_MessageHeader *hdr)
We read a full message from stdin.
static int send_mac_to_plugin(char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac)
Create control message for plugin.
#define FIFO_FILE1
Name of the fifo to use for IPC with the other dummy process.
#define MAXLINE
Maximum size of a message allowed in either direction (used for our receive and sent buffers).
static int stdin_send(void *cls, const struct GNUNET_MessageHeader *hdr)
We got a message from the FIFO, check it, convert the message type to the output forward and copy it ...
#define FIFO_FILE2
Name of the fifo to use for IPC with the other dummy process.
static void sigfunc(int sig)
We're being killed, clean up.
Constants for network protocols.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
@ GNUNET_CRYPTO_QUALITY_STRONG
High-quality operations are desired.
@ GNUNET_CRYPTO_QUALITY_NONCE
Randomness for IVs etc.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER
Type of data messages from the plugin to the gnunet-wlan-helper.
#define GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL
Control message between the gnunet-wlan-helper and the daemon (with the MAC).
#define GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER
Type of data messages from the gnunet-wlan-helper to the plugin.
enum GNUNET_GenericReturnValue GNUNET_MST_from_buffer(struct GNUNET_MessageStreamTokenizer *mst, const char *buf, size_t size, int purge, int one_shot)
Add incoming data to the receive buffer and call the callback for all complete messages.
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
header for transport plugin and the helper for wlan
Handle to a message stream tokenizer.
Format of a WLAN Control Message.
struct GNUNET_MessageHeader hdr
Message header.
struct GNUNET_TRANSPORT_WLAN_MacAddress mac
MAC Address of the local WLAN interface.
Message from the WLAN helper to the plugin: we have received the given message with the given perform...
struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame frame
IEEE Frame.
struct GNUNET_MessageHeader header
Type is 'GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER'.
Message from the plugin to the WLAN helper: send the given message with the given connection paramete...
struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame frame
IEEE Frame to transmit (the sender MAC address will be overwritten by the helper as it does not trust...
IO buffer used for buffering data in transit (to wireless or to stdout).
size_t pos
How many bytes that were stored in 'buf' did we already write to the destination? Always smaller than...
size_t size
How many bytes of data are stored in 'buf' for transmission right now? Data always starts at offset 0...
char buf[4096 *2]
Buffered data; twice the maximum allowed message size as we add some headers.