aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-09-24 08:44:05 +0000
committerChristian Grothoff <christian@grothoff.org>2010-09-24 08:44:05 +0000
commitf5db837f7992ea5276bbee9f74bc3a622dd0e354 (patch)
treed239b2595dda12f814f429a9a2a469d76f9ec8de /src
parentffc8efb1039f1a96c415ddeec1854aec9d09e896 (diff)
downloadgnunet-f5db837f7992ea5276bbee9f74bc3a622dd0e354.tar.gz
gnunet-f5db837f7992ea5276bbee9f74bc3a622dd0e354.zip
fixing warnings
Diffstat (limited to 'src')
-rw-r--r--src/transport/plugin_transport_wlan.c154
-rw-r--r--src/transport/plugin_transport_wlan.h188
2 files changed, 177 insertions, 165 deletions
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c
index bebfe7ea4..9980c72e9 100644
--- a/src/transport/plugin_transport_wlan.c
+++ b/src/transport/plugin_transport_wlan.c
@@ -34,6 +34,10 @@
34#include "gnunet_common.h" 34#include "gnunet_common.h"
35 35
36#define PROTOCOL_PREFIX "wlan" 36#define PROTOCOL_PREFIX "wlan"
37
38/**
39 * Max size of packet from helper
40 */
37#define WLAN_MTU 3000 41#define WLAN_MTU 3000
38 42
39#define DEBUG_wlan GNUNET_NO 43#define DEBUG_wlan GNUNET_NO
@@ -183,7 +187,7 @@ struct Session
183 * To whom are we talking to (set to our identity 187 * To whom are we talking to (set to our identity
184 * if we are still waiting for the welcome message) 188 * if we are still waiting for the welcome message)
185 */ 189 */
186 struct GNUNET_PeerIdentity * target; 190 struct GNUNET_PeerIdentity target;
187 191
188 /** 192 /**
189 * encapsulation of the data 193 * encapsulation of the data
@@ -247,7 +251,6 @@ struct PendingMessage
247 */ 251 */
248 const char *msg; 252 const char *msg;
249 253
250
251 /** 254 /**
252 * Continuation function to call once the message 255 * Continuation function to call once the message
253 * has been sent. Can be NULL if there is no 256 * has been sent. Can be NULL if there is no
@@ -281,54 +284,71 @@ struct PendingMessage
281/** 284/**
282 * Header for messages which need fragmentation 285 * Header for messages which need fragmentation
283 */ 286 */
284 287struct WlanHeader
285struct FragmentationHeader
286{ 288{
287 289
290 struct GNUNET_MessageHeader header;
291
288 /** 292 /**
289 * To whom are we talking to (set to our identity 293 * checksum/error correction
290 * if we are still waiting for the welcome message)
291 */ 294 */
292 struct GNUNET_PeerIdentity * target GNUNET_PACKED; 295 uint32_t crc GNUNET_PACKED;
293 296
294 /** 297 /**
295 * number of message, to distinguish between the messages 298 * To whom are we talking to (set to our identity
299 * if we are still waiting for the welcome message)
296 */ 300 */
301 struct GNUNET_PeerIdentity target;
302
303 // followed by payload
304
305};
306
307/**
308 * Header for messages which need fragmentation
309 */
310struct FragmentationHeader
311{
297 312
298 uint16_t message_num GNUNET_PACKED; 313 struct GNUNET_MessageHeader header;
299 314
300 /** 315 /**
301 * number of this fragment, for fragmentation/segmentation 316 * To whom are we talking to (set to our identity
317 * if we are still waiting for the welcome message)
302 */ 318 */
303 uint16_t fregment_num GNUNET_PACKED; 319 // struct GNUNET_PeerIdentity target GNUNET_PACKED;
304
305 320
306 /** 321 /**
307 * number of fregments in this message 322 * ID of message, to distinguish between the messages, picked randomly.
308 */ 323 */
309 uint16_t ack_message_num GNUNET_PACKED; 324 uint32_t message_id GNUNET_PACKED;
310 325
311 /** 326 /**
312 * number of this fragment, for fragmentation/segmentation 327 * number of this fragment, for fragmentation/segmentation
313 */ 328 */
314 uint16_t ack_fregment_num GNUNET_PACKED; 329 uint16_t fragment_num GNUNET_PACKED;
315 330
316 /** 331 /**
317 * Flags 332 * CRC of fragment (for error checking)
318 * 0x1 ack
319 * 0x2 has data (not only ack)
320 * 0x4 last fragment of message
321 * 0x8 new message
322 */ 333 */
334 uint16_t message_crc GNUNET_PACKED;
323 335
324 uint32_t flags GNUNET_PACKED; 336 /**
325 337 * Flags
338 * // 0x1 ack => Use two different message types in header.type! (FRAG_MESSAGE; FRAG_ACK)
339 * // 0x2 has data (not only ack)
340 * // 0x4 last fragment of message
341 * // 0x8 new message
342 */
343 // uint32_t flags GNUNET_PACKED;
326 344
327 /** 345 /**
328 * checksum/error correction 346 * checksum/error correction
329 */ 347 */
348 // uint32_t crc GNUNET_PACKED;
349
350 // followed by payload unless ACK
330 351
331 uint32_t crc GNUNET_PACKED;
332}; 352};
333 353
334enum { ACK_FRAGMENT = 1, DATA_FRAGMENT = 2, LAST_FRAGMENT = 4, NEW_MESSAGE = 8 }; 354enum { ACK_FRAGMENT = 1, DATA_FRAGMENT = 2, LAST_FRAGMENT = 4, NEW_MESSAGE = 8 };
@@ -346,7 +366,7 @@ static int wlan_plugin_address_suggested (void *cls,
346//TODO add other possibilities to find the right session (are there other?) 366//TODO add other possibilities to find the right session (are there other?)
347static struct Session * 367static struct Session *
348get_Session (struct Plugin *plugin, 368get_Session (struct Plugin *plugin,
349 char * addr) 369 const char * addr)
350{ 370{
351 struct Sessionqueue * queue = plugin->all_Sessions; 371 struct Sessionqueue * queue = plugin->all_Sessions;
352 struct Sessionqueue * lastitem = NULL; 372 struct Sessionqueue * lastitem = NULL;
@@ -354,11 +374,12 @@ get_Session (struct Plugin *plugin,
354 while (queue != NULL){ 374 while (queue != NULL){
355 // content is never NULL 375 // content is never NULL
356 GNUNET_assert (queue->content == NULL); 376 GNUNET_assert (queue->content == NULL);
357 char * addr2 = (queue->content)->addr; 377 char * addr2 = queue->content->addr;
358 if (memcmp(addr, addr2, 6) == 0){ 378 if (memcmp(addr, addr2, 6) == 0)
359 //sesion found 379 {
360 return queue->content; 380 //sesion found
361 } 381 return queue->content;
382 }
362 // try next 383 // try next
363 lastitem = queue; 384 lastitem = queue;
364 queue = queue->next; 385 queue = queue->next;
@@ -375,8 +396,8 @@ get_Session (struct Plugin *plugin,
375 } 396 }
376 397
377 queue->content = GNUNET_malloc (sizeof (struct Session)); 398 queue->content = GNUNET_malloc (sizeof (struct Session));
378 (queue->content)->plugin = plugin; 399 queue->content->plugin = plugin;
379 memcpy((queue->content)->addr, addr, 6); 400 memcpy(queue->content->addr, addr, 6);
380 401
381 //queue welcome 402 //queue welcome
382 struct WelcomeMessage welcome; 403 struct WelcomeMessage welcome;
@@ -446,7 +467,6 @@ static void
446do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 467do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
447{ 468{
448 struct Plugin * plugin = cls; 469 struct Plugin * plugin = cls;
449 char * msg;
450 ssize_t bytes; 470 ssize_t bytes;
451 471
452 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) 472 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
@@ -456,7 +476,7 @@ do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
456 struct Sessionqueue * queue; 476 struct Sessionqueue * queue;
457 struct PendingMessage * pm; 477 struct PendingMessage * pm;
458 struct IeeeHeader * wlanheader; 478 struct IeeeHeader * wlanheader;
459 struct RadiotapHeader * RadioHeader; 479 struct RadiotapHeader * radioHeader;
460 struct GNUNET_MessageHeader * msgheader; 480 struct GNUNET_MessageHeader * msgheader;
461 uint16_t size = 0; 481 uint16_t size = 0;
462 482
@@ -481,25 +501,22 @@ do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
481 size = pm->message_size + sizeof(struct RadiotapHeader) 501 size = pm->message_size + sizeof(struct RadiotapHeader)
482 + sizeof(struct IeeeHeader) + sizeof(struct GNUNET_MessageHeader) 502 + sizeof(struct IeeeHeader) + sizeof(struct GNUNET_MessageHeader)
483 + sizeof(struct FragmentationHeader); 503 + sizeof(struct FragmentationHeader);
484 msg = GNUNET_malloc(size); 504 msgheader = GNUNET_malloc(size);
485
486 msgheader = msg;
487 msgheader->size = pm->message_size + sizeof(struct RadiotapHeader) + sizeof(struct IeeeHeader); 505 msgheader->size = pm->message_size + sizeof(struct RadiotapHeader) + sizeof(struct IeeeHeader);
488 msgheader->type = GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA; 506 msgheader->type = GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA;
489 507
490 RadioHeader = &msgheader[1]; 508 radioHeader = (struct RadiotapHeader*) &msgheader[1];
491 getRadiotapHeader(RadioHeader); 509 getRadiotapHeader(radioHeader);
492 510
493 wlanheader = &RadioHeader[1]; 511 wlanheader = (struct IeeeHeader *) &radioHeader[1];
494 getWlanHeader(wlanheader); 512 getWlanHeader(wlanheader);
495 513
496 bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msg, size); 514 bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msgheader, size);
497 } else { 515 } else {
498 //remove message 516 //remove message
499 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, 517 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
500 session->pending_messages_tail, 518 session->pending_messages_tail,
501 pm); 519 pm);
502 GNUNET_free(pm->msg);
503 GNUNET_free(pm); 520 GNUNET_free(pm);
504 521
505 } 522 }
@@ -582,23 +599,19 @@ process_pending_messages (struct Plugin * plugin)
582 */ 599 */
583static ssize_t 600static ssize_t
584wlan_plugin_send (void *cls, 601wlan_plugin_send (void *cls,
585 const struct GNUNET_PeerIdentity * target, 602 const struct GNUNET_PeerIdentity * target,
586 const char *msgbuf, 603 const char *msgbuf,
587 size_t msgbuf_size, 604 size_t msgbuf_size,
588 unsigned int priority, 605 unsigned int priority,
589 struct GNUNET_TIME_Relative timeout, 606 struct GNUNET_TIME_Relative timeout,
590 struct Session *session, 607 struct Session *session,
591 const void *addr, 608 const void *addr,
592 size_t addrlen, 609 size_t addrlen,
593 int force_address, 610 int force_address,
594 GNUNET_TRANSPORT_TransmitContinuation cont, 611 GNUNET_TRANSPORT_TransmitContinuation cont,
595 void *cont_cls) 612 void *cont_cls)
596{ 613{
597 int bytes_sent = 0;
598 char * msg;
599
600 struct Plugin * plugin = cls; 614 struct Plugin * plugin = cls;
601
602 struct PendingMessage * newmsg = NULL; 615 struct PendingMessage * newmsg = NULL;
603 616
604 //check if msglen > 0 617 //check if msglen > 0
@@ -617,17 +630,17 @@ wlan_plugin_send (void *cls,
617 } 630 }
618 631
619 //TODO target "problem" not solved 632 //TODO target "problem" not solved
620 session->target = target; 633 session->target = *target;
621 634
622 //queue message: 635 //queue message:
623 //first queue session 636 //first queue session
624 queue_Session(plugin, session); 637 queue_Session(plugin, session);
625 638
626 //queue message in session 639 //queue message in session
627 newmsg = GNUNET_malloc(sizeof(struct PendingMessage)); 640 newmsg = GNUNET_malloc(sizeof(struct PendingMessage) + msgbuf_size);
628 newmsg->msg = GNUNET_malloc(msgbuf_size); 641 newmsg->msg = (const char*) &newmsg[1];
629 //copy msg to buffer, not fragmented / segmented yet 642 //copy msg to buffer, not fragmented / segmented yet
630 memcpy(newmsg->msg, msgbuf, msgbuf_size); 643 memcpy(&newmsg[1], msgbuf, msgbuf_size);
631 newmsg->transmit_cont = cont; 644 newmsg->transmit_cont = cont;
632 newmsg->transmit_cont_cls = cont_cls; 645 newmsg->transmit_cont_cls = cont_cls;
633 newmsg->timeout = GNUNET_TIME_relative_to_absolute(timeout); 646 newmsg->timeout = GNUNET_TIME_relative_to_absolute(timeout);
@@ -839,19 +852,18 @@ wlan_process_helper (void *cls,
839 852
840 853
841static void 854static void
842wlan_plugin_helper_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 855wlan_plugin_helper_read (void *cls,
856 const struct GNUNET_SCHEDULER_TaskContext *tc)
843{ 857{
844 struct Plugin *plugin = cls; 858 struct Plugin *plugin = cls;
845 char mybuf[WLAN_MTU]; //max size of packet from helper 859 char mybuf[WLAN_MTU];
846 ssize_t bytes; 860 ssize_t bytes;
847 //memset(&mybuf, 0, sizeof(mybuf)); //?
848 861
849 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) 862 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
850 return; 863 return;
851 864 bytes = GNUNET_DISK_file_read (plugin->server_stdout_handle,
852 bytes = GNUNET_DISK_file_read(plugin->server_stdout_handle, &mybuf, sizeof(mybuf)); 865 mybuf, sizeof(mybuf));
853 866 if (bytes <= 0)
854 if (bytes < 1)
855 { 867 {
856#if DEBUG_TCP_NAT 868#if DEBUG_TCP_NAT
857 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 869 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -859,8 +871,8 @@ wlan_plugin_helper_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *t
859#endif 871#endif
860 return; 872 return;
861 } 873 }
862 874 GNUNET_SERVER_mst_receive(plugin->consoltoken, NULL,
863 GNUNET_SERVER_mst_receive(plugin->consoltoken,NULL,&mybuf,bytes,0, GNUNET_NO); 875 mybuf, bytes, 0, GNUNET_NO);
864 876
865} 877}
866 878
@@ -876,11 +888,11 @@ static int
876wlan_transport_start_wlan_helper(struct Plugin *plugin) 888wlan_transport_start_wlan_helper(struct Plugin *plugin)
877{ 889{
878 890
879 plugin->server_stdout = (GNUNET_YES, GNUNET_NO, GNUNET_YES); 891 plugin->server_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
880 if (plugin->server_stdout == NULL) 892 if (plugin->server_stdout == NULL)
881 return GNUNET_SYSERR; 893 return GNUNET_SYSERR;
882 894
883 plugin->server_stdin = GNUNET_DISK_pipe(GNUNET_YES, GNUNET_YES, GNUNET_NO); 895 plugin->server_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO);
884 if (plugin->server_stdin == NULL) 896 if (plugin->server_stdin == NULL)
885 return GNUNET_SYSERR; 897 return GNUNET_SYSERR;
886 898
diff --git a/src/transport/plugin_transport_wlan.h b/src/transport/plugin_transport_wlan.h
index c870e4d65..dc30b5ff3 100644
--- a/src/transport/plugin_transport_wlan.h
+++ b/src/transport/plugin_transport_wlan.h
@@ -30,13 +30,14 @@ typedef unsigned int uint32_t;
30typedef unsigned short uint16_t; 30typedef unsigned short uint16_t;
31 31
32/* Wlan IEEE80211 header default */ 32/* Wlan IEEE80211 header default */
33static const uint8_t u8aIeeeHeader[] = { 33static const uint8_t u8aIeeeHeader[] =
34 0x08, 0x01, 0x00, 0x00, 34 {
35 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 35 0x08, 0x01, 0x00, 0x00,
36 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, 36 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
37 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, 37 0x13, 0x22, 0x33, 0x44, 0x55, 0x66,
38 0x10, 0x86, 38 0x13, 0x22, 0x33, 0x44, 0x55, 0x66,
39}; 39 0x10, 0x86,
40 };
40 41
41/** 42/**
42 * Wlan header 43 * Wlan header
@@ -44,103 +45,102 @@ static const uint8_t u8aIeeeHeader[] = {
44 45
45struct IeeeHeader 46struct IeeeHeader
46{ 47{
47 /** 48 /**
48 * Wlan flags 49 * Wlan flags
49 */ 50 */
50 uint8_t flags[4] GNUNET_PACKED; 51 uint32_t flags;
51 52
52 /** 53 /**
53 * first mac 54 * first mac
54 */ 55 */
55 uint8_t mac1[6] GNUNET_PACKED; 56 uint8_t mac1[6];
56 57
57 /** 58 /**
58 * second mac 59 * second mac
59 */ 60 */
60 uint8_t mac2[6] GNUNET_PACKED; 61 uint8_t mac2[6];
61 62
62 /** 63 /**
63 * third mac 64 * third mac
64 */ 65 */
65 uint8_t mac3[6] GNUNET_PACKED; 66 uint8_t mac3[6];
66 67
67 /** 68 /**
68 * Wlan flags2 69 * Wlan flags2
69 */ 70 */
70 uint8_t flags2[2] GNUNET_PACKED; 71 uint16_t flags2;
71}; 72};
72 73
73/* this is the template radiotap header we send packets out with */ 74/* this is the template radiotap header we send packets out with */
74 75
75static const uint8_t u8aRadiotapHeader[] = { 76static const uint8_t u8aRadiotapHeader[] =
76 77 {
77 0x00, 0x00, // <-- radiotap version 78 0x00, 0x00, // <-- radiotap version
78 0x19, 0x00, // <- radiotap header length 79 0x19, 0x00, // <- radiotap header length
79 0x6f, 0x08, 0x00, 0x00, // <-- bitmap 80 0x6f, 0x08, 0x00, 0x00, // <-- bitmap
80 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // <-- timestamp 81 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // <-- timestamp
81 0x00, // <-- flags (Offset +0x10) 82 0x00, // <-- flags (Offset +0x10)
82 0x6c, // <-- rate (0ffset +0x11) 83 0x6c, // <-- rate (0ffset +0x11)
83 0x71, 0x09, 0xc0, 0x00, // <-- channel 84 0x71, 0x09, 0xc0, 0x00, // <-- channel
84 0xde, // <-- antsignal 85 0xde, // <-- antsignal
85 0x00, // <-- antnoise 86 0x00, // <-- antnoise
86 0x01, // <-- antenna 87 0x01, // <-- antenna
87
88}; 88};
89 89
90/** 90/**
91 * Radiotap Header 91 * Radiotap Header
92 */ 92 */
93
94struct RadiotapHeader 93struct RadiotapHeader
95{ 94{
96 /** 95 /**
97 * radiotap version 96 * radiotap version
98 */ 97 */
99 uint8_t version[2] GNUNET_PACKED; 98 uint16_t version GNUNET_PACKED;
100 99
101 /** 100 /**
102 * radiotap header length 101 * radiotap header length
103 */ 102 */
104 uint8_t lenght[2] GNUNET_PACKED; 103 uint16_t length GNUNET_PACKED;
105 104
106 /** 105 /**
107 * bitmap 106 * bitmap
108 */ 107 */
109 uint8_t bitmap[4] GNUNET_PACKED; 108 uint32_t bitmap GNUNET_PACKED;
110 109
111 /** 110 /**
112 * timestamp 111 * timestamp
113 */ 112 */
114 uint8_t timestamp[8] GNUNET_PACKED; 113 uint64_t timestamp GNUNET_PACKED;
115 114
116 /** 115 /**
117 * radiotap flags 116 * radiotap flags
118 */ 117 */
119 uint8_t flags GNUNET_PACKED; 118 uint8_t flags;
120 119
121 /** 120 /**
122 * wlan send rate 121 * wlan send rate
123 */ 122 */
124 uint8_t rate GNUNET_PACKED; 123 uint8_t rate;
125 124
126 /** 125 // FIXME: unaligned here, is this OK?
127 * Wlan channel 126 /**
128 */ 127 * Wlan channel
129 uint8_t channel[4] GNUNET_PACKED; 128 */
130 129 uint32_t channel GNUNET_PACKED;
131 /** 130
132 * antsignal 131 /**
133 */ 132 * antsignal
134 uint8_t antsignal GNUNET_PACKED; 133 */
135 134 uint8_t antsignal;
136 /** 135
137 * antnoise 136 /**
138 */ 137 * antnoise
139 uint8_t antnoise GNUNET_PACKED; 138 */
140 139 uint8_t antnoise;
141 /** 140
142 * antenna 141 /**
143 */ 142 * antenna
144 uint8_t antenna GNUNET_PACKED; 143 */
144 uint8_t antenna;
145}; 145};
146 146