diff options
author | David Brodski <david@brodski.eu> | 2011-05-23 23:14:47 +0000 |
---|---|---|
committer | David Brodski <david@brodski.eu> | 2011-05-23 23:14:47 +0000 |
commit | 5cdc9eb4091dfbfd1d65c4aaf1e3dfdd4b5b6316 (patch) | |
tree | a610fd026af2cde16c0140ca70be37f5913d6a43 /src/transport/plugin_transport_wlan.c | |
parent | 57e5f310b699c0b91dabac940e04ef4b152ee2a3 (diff) | |
download | gnunet-5cdc9eb4091dfbfd1d65c4aaf1e3dfdd4b5b6316.tar.gz gnunet-5cdc9eb4091dfbfd1d65c4aaf1e3dfdd4b5b6316.zip |
Some bugfixes, udp packets can now be send over wlan, unrel test added, clean up
Diffstat (limited to 'src/transport/plugin_transport_wlan.c')
-rw-r--r-- | src/transport/plugin_transport_wlan.c | 251 |
1 files changed, 211 insertions, 40 deletions
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index 26eda2b97..25af40b7c 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c | |||
@@ -34,7 +34,8 @@ | |||
34 | #include "plugin_transport_wlan.h" | 34 | #include "plugin_transport_wlan.h" |
35 | #include "gnunet_common.h" | 35 | #include "gnunet_common.h" |
36 | #include "gnunet_crypto_lib.h" | 36 | #include "gnunet_crypto_lib.h" |
37 | #include "wlan/ieee80211.h" | 37 | //#include "wlan/ieee80211.h" |
38 | //#include <netinet/ip.h> | ||
38 | 39 | ||
39 | #include <string.h> | 40 | #include <string.h> |
40 | 41 | ||
@@ -43,7 +44,7 @@ | |||
43 | /** | 44 | /** |
44 | * Max size of packet from helper | 45 | * Max size of packet from helper |
45 | */ | 46 | */ |
46 | #define WLAN_MTU 3000 | 47 | #define WLAN_MTU 2100 |
47 | 48 | ||
48 | /** | 49 | /** |
49 | * Time until retransmission of a fragment in ms | 50 | * Time until retransmission of a fragment in ms |
@@ -60,8 +61,9 @@ | |||
60 | 61 | ||
61 | #define HALLO_BEACON_SCALING_FACTOR 900 | 62 | #define HALLO_BEACON_SCALING_FACTOR 900 |
62 | 63 | ||
63 | #define DEBUG_wlan GNUNET_YES | 64 | #define DEBUG_wlan GNUNET_NO |
64 | #define DEBUG_wlan_retransmission GNUNET_NO | 65 | #define DEBUG_wlan_retransmission GNUNET_NO |
66 | #define DEBUG_wlan_ip_udp_packets_on_air GNUNET_NO | ||
65 | 67 | ||
66 | #define MESSAGE_LENGHT_UNKNOWN -1 | 68 | #define MESSAGE_LENGHT_UNKNOWN -1 |
67 | //#define NO_MESSAGE_OR_MESSAGE_FINISHED -2 | 69 | //#define NO_MESSAGE_OR_MESSAGE_FINISHED -2 |
@@ -73,6 +75,68 @@ | |||
73 | */ | 75 | */ |
74 | #define LEARNED_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 6) | 76 | #define LEARNED_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 6) |
75 | 77 | ||
78 | #define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */ | ||
79 | |||
80 | #define IEEE80211_FC0_VERSION_MASK 0x03 | ||
81 | #define IEEE80211_FC0_VERSION_SHIFT 0 | ||
82 | #define IEEE80211_FC0_VERSION_0 0x00 | ||
83 | #define IEEE80211_FC0_TYPE_MASK 0x0c | ||
84 | #define IEEE80211_FC0_TYPE_SHIFT 2 | ||
85 | #define IEEE80211_FC0_TYPE_MGT 0x00 | ||
86 | #define IEEE80211_FC0_TYPE_CTL 0x04 | ||
87 | #define IEEE80211_FC0_TYPE_DATA 0x08 | ||
88 | |||
89 | /* | ||
90 | * Structure of an internet header, naked of options. | ||
91 | */ | ||
92 | struct iph | ||
93 | { | ||
94 | #if __BYTE_ORDER == __LITTLE_ENDIAN | ||
95 | unsigned int ip_hl:4; /* header length */ | ||
96 | unsigned int ip_v:4; /* version */ | ||
97 | #endif | ||
98 | #if __BYTE_ORDER == __BIG_ENDIAN | ||
99 | unsigned int ip_v:4; /* version */ | ||
100 | unsigned int ip_hl:4; /* header length */ | ||
101 | #endif | ||
102 | u_int8_t ip_tos; /* type of service */ | ||
103 | u_short ip_len; /* total length */ | ||
104 | u_short ip_id; /* identification */ | ||
105 | u_short ip_off; /* fragment offset field */ | ||
106 | #define IP_RF 0x8000 /* reserved fragment flag */ | ||
107 | #define IP_DF 0x4000 /* dont fragment flag */ | ||
108 | #define IP_MF 0x2000 /* more fragments flag */ | ||
109 | #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ | ||
110 | u_int8_t ip_ttl; /* time to live */ | ||
111 | u_int8_t ip_p; /* protocol */ | ||
112 | u_short ip_sum; /* checksum */ | ||
113 | struct in_addr ip_src, ip_dst; /* source and dest address */ | ||
114 | }; | ||
115 | |||
116 | struct udphdr | ||
117 | { | ||
118 | u_int16_t source; | ||
119 | u_int16_t dest; | ||
120 | u_int16_t len; | ||
121 | u_int16_t check; | ||
122 | }; | ||
123 | |||
124 | /* | ||
125 | * generic definitions for IEEE 802.11 frames | ||
126 | */ | ||
127 | struct ieee80211_frame { | ||
128 | u_int8_t i_fc[2]; | ||
129 | u_int8_t i_dur[2]; | ||
130 | u_int8_t i_addr1[IEEE80211_ADDR_LEN]; | ||
131 | u_int8_t i_addr2[IEEE80211_ADDR_LEN]; | ||
132 | u_int8_t i_addr3[IEEE80211_ADDR_LEN]; | ||
133 | u_int8_t i_seq[2]; | ||
134 | #if DEBUG_wlan_ip_udp_packets_on_air | ||
135 | u_int8_t llc[4]; | ||
136 | struct iph ip; | ||
137 | struct udphdr udp; | ||
138 | #endif | ||
139 | } GNUNET_PACKED; | ||
76 | /** | 140 | /** |
77 | * Initial handshake message for a session. | 141 | * Initial handshake message for a session. |
78 | */ | 142 | */ |
@@ -583,6 +647,54 @@ static void | |||
583 | do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 647 | do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
584 | 648 | ||
585 | /** | 649 | /** |
650 | * Generates a nice hexdump of a memory area. | ||
651 | * | ||
652 | * \param mem pointer to memory to dump | ||
653 | * \param length how many bytes to dump | ||
654 | */ | ||
655 | void hexdump(void *mem, unsigned length) | ||
656 | { | ||
657 | char line[80]; | ||
658 | char *src = (char*)mem; | ||
659 | |||
660 | printf( | ||
661 | "dumping %u bytes from %p\r\n" | ||
662 | " 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF\r\n" | ||
663 | , length, src | ||
664 | ); | ||
665 | unsigned i; | ||
666 | int j; | ||
667 | |||
668 | for (i=0; i<length; i+=16, src+=16) { | ||
669 | char *t = line; | ||
670 | |||
671 | t += sprintf(t, "%04x: ", i); | ||
672 | for ( j=0; j<16; j++) { | ||
673 | if (i+j < length) | ||
674 | t += sprintf(t, "%02X", src[j] & 0xff); | ||
675 | else | ||
676 | t += sprintf(t, " "); | ||
677 | t += sprintf(t, j%2 ? " " : "-"); | ||
678 | } | ||
679 | |||
680 | t += sprintf(t, " "); | ||
681 | for (j=0; j<16; j++) { | ||
682 | if (i+j < length) { | ||
683 | if (isprint((unsigned char)src[j])) | ||
684 | t += sprintf(t, "%c", src[j]); | ||
685 | else | ||
686 | t += sprintf(t, "."); | ||
687 | } else { | ||
688 | t += sprintf(t, " "); | ||
689 | } | ||
690 | } | ||
691 | |||
692 | t += sprintf(t, "\r\n"); | ||
693 | printf("%s", line); | ||
694 | } | ||
695 | } | ||
696 | |||
697 | /** | ||
586 | * Sets a bit active in the bitArray. Increment bit-specific | 698 | * Sets a bit active in the bitArray. Increment bit-specific |
587 | * usage counter on disk only if below 4bit max (==15). | 699 | * usage counter on disk only if below 4bit max (==15). |
588 | * | 700 | * |
@@ -892,9 +1004,8 @@ set_next_send(struct Plugin * const plugin) | |||
892 | } | 1004 | } |
893 | else | 1005 | else |
894 | { | 1006 | { |
895 | plugin->server_write_delay_task | 1007 | plugin->server_write_delay_task = GNUNET_SCHEDULER_add_delayed(next_send, |
896 | = GNUNET_SCHEDULER_add_delayed(next_send, | 1008 | &delay_fragment_task, plugin); |
897 | &delay_fragment_task, plugin); | ||
898 | } | 1009 | } |
899 | } | 1010 | } |
900 | 1011 | ||
@@ -919,7 +1030,6 @@ get_next_queue_session(struct Plugin * plugin) | |||
919 | GNUNET_assert(session != NULL); | 1030 | GNUNET_assert(session != NULL); |
920 | pm = session->pending_message; | 1031 | pm = session->pending_message; |
921 | 1032 | ||
922 | |||
923 | #if DEBUG_wlan | 1033 | #if DEBUG_wlan |
924 | if (pm == NULL) | 1034 | if (pm == NULL) |
925 | { | 1035 | { |
@@ -1195,7 +1305,7 @@ getWlanHeader(struct ieee80211_frame * Header, | |||
1195 | uint16_t * tmp16; | 1305 | uint16_t * tmp16; |
1196 | const int rate = 11000000; | 1306 | const int rate = 11000000; |
1197 | 1307 | ||
1198 | Header->i_fc[0] = 0x08; | 1308 | Header->i_fc[0] = IEEE80211_FC0_TYPE_DATA; |
1199 | Header->i_fc[1] = 0x00; | 1309 | Header->i_fc[1] = 0x00; |
1200 | memcpy(&Header->i_addr3, &mac_bssid, sizeof(mac_bssid)); | 1310 | memcpy(&Header->i_addr3, &mac_bssid, sizeof(mac_bssid)); |
1201 | memcpy(&Header->i_addr2, plugin->mac_address.mac, sizeof(plugin->mac_address)); | 1311 | memcpy(&Header->i_addr2, plugin->mac_address.mac, sizeof(plugin->mac_address)); |
@@ -1204,6 +1314,36 @@ getWlanHeader(struct ieee80211_frame * Header, | |||
1204 | tmp16 = (uint16_t*) Header->i_dur; | 1314 | tmp16 = (uint16_t*) Header->i_dur; |
1205 | *tmp16 = (uint16_t) htole16((size * 1000000) / rate + 290); | 1315 | *tmp16 = (uint16_t) htole16((size * 1000000) / rate + 290); |
1206 | 1316 | ||
1317 | #if DEBUG_wlan_ip_udp_packets_on_air | ||
1318 | uint crc = 0; | ||
1319 | uint16_t * x; | ||
1320 | int count; | ||
1321 | Header->ip.ip_dst.s_addr = *((uint32_t*) &to_mac_addr->mac[2]); | ||
1322 | Header->ip.ip_src.s_addr = *((uint32_t*) &plugin->mac_address.mac[2]); | ||
1323 | Header->ip.ip_v = 4; | ||
1324 | Header->ip.ip_hl = 5; | ||
1325 | Header->ip.ip_p = 17; | ||
1326 | Header->ip.ip_ttl = 1; | ||
1327 | Header->ip.ip_len = htons(size + 8); | ||
1328 | Header->ip.ip_sum = 0; | ||
1329 | x =(uint16_t *) &Header->ip; | ||
1330 | count = sizeof(struct iph); | ||
1331 | while (count > 1) { | ||
1332 | /* This is the inner loop */ | ||
1333 | crc += (unsigned short) * x++; | ||
1334 | count -= 2; | ||
1335 | } | ||
1336 | /* Add left-over byte, if any */ | ||
1337 | if( count > 0 ) | ||
1338 | crc += * (unsigned char *) x; | ||
1339 | crc = (crc & 0xffff) + (crc >> 16); | ||
1340 | Header->ip.ip_sum = htons(~ (unsigned short) crc); | ||
1341 | Header->llc[0] = 6; | ||
1342 | Header->llc[1] = 6; | ||
1343 | Header->udp.len = htons(size - sizeof(struct ieee80211_frame)); | ||
1344 | |||
1345 | #endif | ||
1346 | |||
1207 | return GNUNET_YES; | 1347 | return GNUNET_YES; |
1208 | } | 1348 | } |
1209 | 1349 | ||
@@ -1219,8 +1359,8 @@ getWlanHeader(struct ieee80211_frame * Header, | |||
1219 | uint32_t | 1359 | uint32_t |
1220 | getcrc32(const char *msgbuf, size_t msgbuf_size) | 1360 | getcrc32(const char *msgbuf, size_t msgbuf_size) |
1221 | { | 1361 | { |
1222 | //TODO calc some crc | 1362 | |
1223 | return 0; | 1363 | return GNUNET_CRYPTO_crc32_n(msgbuf, msgbuf_size);; |
1224 | } | 1364 | } |
1225 | 1365 | ||
1226 | /** | 1366 | /** |
@@ -1350,8 +1490,7 @@ send_ack(struct Plugin * plugin, struct AckSendQueue * ack) | |||
1350 | 1490 | ||
1351 | //TODO DOXIGEN | 1491 | //TODO DOXIGEN |
1352 | static void | 1492 | static void |
1353 | finish_sending(void *cls, | 1493 | finish_sending(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1354 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1355 | { | 1494 | { |
1356 | struct Finish_send * finish = cls; | 1495 | struct Finish_send * finish = cls; |
1357 | struct Plugin * plugin; | 1496 | struct Plugin * plugin; |
@@ -1366,19 +1505,17 @@ finish_sending(void *cls, | |||
1366 | GNUNET_free (finish); | 1505 | GNUNET_free (finish); |
1367 | return; | 1506 | return; |
1368 | } | 1507 | } |
1369 | bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle, | 1508 | bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, |
1370 | finish->msgheader, | 1509 | finish->msgheader, finish->size); |
1371 | finish->size); | ||
1372 | GNUNET_assert (bytes != GNUNET_SYSERR); | 1510 | GNUNET_assert (bytes != GNUNET_SYSERR); |
1373 | 1511 | ||
1374 | if (bytes != finish->size) | 1512 | if (bytes != finish->size) |
1375 | { | 1513 | { |
1376 | finish->msgheader = finish->msgheader + bytes; | 1514 | finish->msgheader = finish->msgheader + bytes; |
1377 | finish->size = finish->size - bytes; | 1515 | finish->size = finish->size - bytes; |
1378 | plugin->server_write_task | 1516 | plugin->server_write_task = GNUNET_SCHEDULER_add_write_file( |
1379 | = GNUNET_SCHEDULER_add_write_file(GNUNET_TIME_UNIT_FOREVER_REL, | 1517 | GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdin_handle, |
1380 | plugin->server_stdin_handle, | 1518 | &finish_sending, finish); |
1381 | &finish_sending, finish); | ||
1382 | } | 1519 | } |
1383 | else | 1520 | else |
1384 | { | 1521 | { |
@@ -1508,6 +1645,7 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1508 | ieeewlanheader = (struct ieee80211_frame *) &radioHeader[1]; | 1645 | ieeewlanheader = (struct ieee80211_frame *) &radioHeader[1]; |
1509 | getWlanHeader(ieeewlanheader, &(fm->session->addr), plugin, size); | 1646 | getWlanHeader(ieeewlanheader, &(fm->session->addr), plugin, size); |
1510 | 1647 | ||
1648 | |||
1511 | //could be faster if content is just send and not copyed before | 1649 | //could be faster if content is just send and not copyed before |
1512 | //fragmentheader is needed | 1650 | //fragmentheader is needed |
1513 | fragheader.message_crc = htons(getcrc16(copystart, copysize)); | 1651 | fragheader.message_crc = htons(getcrc16(copystart, copysize)); |
@@ -1710,8 +1848,12 @@ wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target, | |||
1710 | wlanheader->header.size = htons(msgbuf_size + sizeof(struct WlanHeader)); | 1848 | wlanheader->header.size = htons(msgbuf_size + sizeof(struct WlanHeader)); |
1711 | wlanheader->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA); | 1849 | wlanheader->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA); |
1712 | memcpy(&(wlanheader->target), target, sizeof(struct GNUNET_PeerIdentity)); | 1850 | memcpy(&(wlanheader->target), target, sizeof(struct GNUNET_PeerIdentity)); |
1713 | wlanheader->crc = htonl(getcrc32(msgbuf, msgbuf_size)); | 1851 | wlanheader->crc = 0; |
1714 | memcpy(&wlanheader[1], msgbuf, msgbuf_size); | 1852 | memcpy(&wlanheader[1], msgbuf, msgbuf_size); |
1853 | wlanheader->crc = htonl(getcrc32((char*) wlanheader, msgbuf_size + sizeof(struct WlanHeader))); | ||
1854 | //GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Wlan message Header crc: %u, %u\n",getcrc32((char*) wlanheader, msgbuf_size + sizeof(struct WlanHeader)), wlanheader->crc); | ||
1855 | //hexdump(newmsg->msg, msgbuf_size + sizeof(struct WlanHeader)); | ||
1856 | |||
1715 | newmsg->transmit_cont = cont; | 1857 | newmsg->transmit_cont = cont; |
1716 | newmsg->transmit_cont_cls = cont_cls; | 1858 | newmsg->transmit_cont_cls = cont_cls; |
1717 | newmsg->timeout = GNUNET_TIME_relative_to_absolute(timeout); | 1859 | newmsg->timeout = GNUNET_TIME_relative_to_absolute(timeout); |
@@ -1813,6 +1955,7 @@ get_fragment_message_from_session_and_id(struct Plugin * plugin, | |||
1813 | struct Session_id_fragment_triple triple; | 1955 | struct Session_id_fragment_triple triple; |
1814 | triple.session = session; | 1956 | triple.session = session; |
1815 | triple.message_id = message_id; | 1957 | triple.message_id = message_id; |
1958 | triple.fm = NULL; | ||
1816 | GNUNET_CONTAINER_heap_iterate(plugin->pending_Fragment_Messages, | 1959 | GNUNET_CONTAINER_heap_iterate(plugin->pending_Fragment_Messages, |
1817 | &search_fragment_message_from_session_and_id, &triple); | 1960 | &search_fragment_message_from_session_and_id, &triple); |
1818 | return triple.fm; | 1961 | return triple.fm; |
@@ -1914,8 +2057,8 @@ free_session(struct Plugin * plugin, struct Sessionqueue * queue) | |||
1914 | { | 2057 | { |
1915 | plugin->pendingsessions--; | 2058 | plugin->pendingsessions--; |
1916 | GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head, | 2059 | GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head, |
1917 | plugin->pending_Sessions_tail, | 2060 | plugin->pending_Sessions_tail, |
1918 | pendingsession); | 2061 | pendingsession); |
1919 | GNUNET_free(pendingsession); | 2062 | GNUNET_free(pendingsession); |
1920 | 2063 | ||
1921 | GNUNET_assert (check == 0); | 2064 | GNUNET_assert (check == 0); |
@@ -1954,9 +2097,9 @@ free_session(struct Plugin * plugin, struct Sessionqueue * queue) | |||
1954 | GNUNET_free(pm); | 2097 | GNUNET_free(pm); |
1955 | } | 2098 | } |
1956 | 2099 | ||
1957 | GNUNET_CONTAINER_DLL_remove(plugin->sessions, | 2100 | GNUNET_CONTAINER_DLL_remove(plugin->sessions, |
1958 | plugin->sessions_tail, | 2101 | plugin->sessions_tail, |
1959 | queue); | 2102 | queue); |
1960 | GNUNET_free(queue->content); | 2103 | GNUNET_free(queue->content); |
1961 | GNUNET_free(queue); | 2104 | GNUNET_free(queue); |
1962 | plugin->session_count--; | 2105 | plugin->session_count--; |
@@ -2031,7 +2174,6 @@ wlan_plugin_address_pretty_printer(void *cls, const char *type, | |||
2031 | asc(asc_cls, ret); | 2174 | asc(asc_cls, ret); |
2032 | } | 2175 | } |
2033 | 2176 | ||
2034 | |||
2035 | /** | 2177 | /** |
2036 | * Function to test if fragment number already exists in the fragments received | 2178 | * Function to test if fragment number already exists in the fragments received |
2037 | * | 2179 | * |
@@ -2044,7 +2186,6 @@ is_double_msg(struct Receive_Message_Queue * rx_msg, | |||
2044 | struct FragmentationHeader * fh) | 2186 | struct FragmentationHeader * fh) |
2045 | { | 2187 | { |
2046 | 2188 | ||
2047 | |||
2048 | return testBit((char *) &rx_msg->received_fragments, ntohs( | 2189 | return testBit((char *) &rx_msg->received_fragments, ntohs( |
2049 | fh->fragment_off_or_num)); | 2190 | fh->fragment_off_or_num)); |
2050 | 2191 | ||
@@ -2108,6 +2249,7 @@ wlan_data_message_handler(void *cls, void *client, | |||
2108 | const char * tempmsg; | 2249 | const char * tempmsg; |
2109 | const struct GNUNET_MessageHeader * temp_hdr; | 2250 | const struct GNUNET_MessageHeader * temp_hdr; |
2110 | struct GNUNET_PeerIdentity tmptarget; | 2251 | struct GNUNET_PeerIdentity tmptarget; |
2252 | int crc; | ||
2111 | 2253 | ||
2112 | if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA) | 2254 | if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA) |
2113 | { | 2255 | { |
@@ -2136,13 +2278,14 @@ wlan_data_message_handler(void *cls, void *client, | |||
2136 | 2278 | ||
2137 | tempmsg = (char*) &wlanheader[1]; | 2279 | tempmsg = (char*) &wlanheader[1]; |
2138 | temp_hdr = (const struct GNUNET_MessageHeader *) &wlanheader[1]; | 2280 | temp_hdr = (const struct GNUNET_MessageHeader *) &wlanheader[1]; |
2139 | 2281 | crc = ntohl(wlanheader->crc); | |
2140 | if (getcrc32(tempmsg, ntohs(wlanheader->header.size)) != ntohl( | 2282 | wlanheader->crc = 0; |
2141 | wlanheader->crc)) | 2283 | if (getcrc32((char *) wlanheader, ntohs(wlanheader->header.size)) != crc) |
2142 | { | 2284 | { |
2143 | //wrong crc, dispose message | 2285 | //wrong crc, dispose message |
2144 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 2286 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
2145 | "Wlan message Header crc was wrong\n"); | 2287 | "Wlan message Header crc was wrong: %u != %u\n",getcrc32((char *) wlanheader, ntohs(wlanheader->header.size)), crc); |
2288 | hexdump((void *)hdr, ntohs(hdr->size)); | ||
2146 | return; | 2289 | return; |
2147 | } | 2290 | } |
2148 | 2291 | ||
@@ -2877,7 +3020,8 @@ wlan_plugin_helper_read(void *cls, | |||
2877 | static int | 3020 | static int |
2878 | wlan_transport_start_wlan_helper(struct Plugin *plugin, int testmode) | 3021 | wlan_transport_start_wlan_helper(struct Plugin *plugin, int testmode) |
2879 | { | 3022 | { |
2880 | const char * filename = "gnunet-transport-wlan-helper"; | 3023 | const char * filenamehw = "gnunet-transport-wlan-helper"; |
3024 | const char * filenameloopback = "gnunet-transport-wlan-helper-dummy"; | ||
2881 | plugin->server_stdout = GNUNET_DISK_pipe(GNUNET_YES, GNUNET_NO, GNUNET_YES); | 3025 | plugin->server_stdout = GNUNET_DISK_pipe(GNUNET_YES, GNUNET_NO, GNUNET_YES); |
2882 | if (plugin->server_stdout == NULL) | 3026 | if (plugin->server_stdout == NULL) |
2883 | return GNUNET_SYSERR; | 3027 | return GNUNET_SYSERR; |
@@ -2886,16 +3030,43 @@ wlan_transport_start_wlan_helper(struct Plugin *plugin, int testmode) | |||
2886 | if (plugin->server_stdin == NULL) | 3030 | if (plugin->server_stdin == NULL) |
2887 | return GNUNET_SYSERR; | 3031 | return GNUNET_SYSERR; |
2888 | 3032 | ||
3033 | |||
3034 | /* Start the server process */ | ||
3035 | |||
3036 | if (testmode == 0) | ||
3037 | { | ||
3038 | |||
2889 | #if DEBUG_wlan | 3039 | #if DEBUG_wlan |
2890 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 3040 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2891 | "Starting gnunet-wlan-helper process cmd: %s %s %i\n", filename, | 3041 | "Starting gnunet-wlan-helper process cmd: %s %s %i\n", filenamehw, |
2892 | plugin->interface, testmode); | 3042 | plugin->interface, testmode); |
2893 | #endif | 3043 | #endif |
2894 | /* Start the server process */ | ||
2895 | 3044 | ||
2896 | plugin->server_proc = GNUNET_OS_start_process(plugin->server_stdin, | 3045 | plugin->server_proc = GNUNET_OS_start_process(plugin->server_stdin, |
2897 | plugin->server_stdout, filename, filename, plugin->interface, ((testmode | 3046 | plugin->server_stdout, filenamehw, filenamehw, plugin->interface, NULL); |
2898 | == 1) ? "1" : (testmode == 2) ? "2" : "0"), NULL); | 3047 | } |
3048 | else if (testmode == 1) | ||
3049 | { | ||
3050 | |||
3051 | #if DEBUG_wlan | ||
3052 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
3053 | "Starting gnunet-wlan-helper loopback 1 process cmd: %s %s %i\n", filenameloopback, | ||
3054 | plugin->interface, testmode); | ||
3055 | #endif | ||
3056 | |||
3057 | plugin->server_proc = GNUNET_OS_start_process(plugin->server_stdin, | ||
3058 | plugin->server_stdout, filenameloopback, filenameloopback, "1", NULL); | ||
3059 | } | ||
3060 | else if (testmode == 2) | ||
3061 | { | ||
3062 | #if DEBUG_wlan | ||
3063 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
3064 | "Starting gnunet-wlan-helper loopback 2 process cmd: %s %s %i\n", filenameloopback, | ||
3065 | plugin->interface, testmode); | ||
3066 | #endif | ||
3067 | plugin->server_proc = GNUNET_OS_start_process(plugin->server_stdin, | ||
3068 | plugin->server_stdout, filenameloopback, filenameloopback, "2", NULL); | ||
3069 | } | ||
2899 | if (plugin->server_proc == NULL) | 3070 | if (plugin->server_proc == NULL) |
2900 | { | 3071 | { |
2901 | #if DEBUG_wlan | 3072 | #if DEBUG_wlan |
@@ -2951,9 +3122,11 @@ libgnunet_plugin_transport_wlan_done(void *cls) | |||
2951 | #endif | 3122 | #endif |
2952 | 3123 | ||
2953 | 3124 | ||
2954 | GNUNET_OS_process_close(plugin->server_proc); | ||
2955 | GNUNET_DISK_pipe_close(plugin->server_stdout); | 3125 | GNUNET_DISK_pipe_close(plugin->server_stdout); |
2956 | GNUNET_DISK_pipe_close(plugin->server_stdin); | 3126 | GNUNET_DISK_pipe_close(plugin->server_stdin); |
3127 | GNUNET_OS_process_kill(plugin->server_proc,9); | ||
3128 | GNUNET_OS_process_close(plugin->server_proc); | ||
3129 | |||
2957 | 3130 | ||
2958 | GNUNET_assert (cls !=NULL); | 3131 | GNUNET_assert (cls !=NULL); |
2959 | //free sessions | 3132 | //free sessions |
@@ -2980,7 +3153,6 @@ libgnunet_plugin_transport_wlan_done(void *cls) | |||
2980 | plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK; | 3153 | plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK; |
2981 | } | 3154 | } |
2982 | 3155 | ||
2983 | |||
2984 | if (plugin->suid_tokenizer != NULL) | 3156 | if (plugin->suid_tokenizer != NULL) |
2985 | GNUNET_SERVER_mst_destroy(plugin->suid_tokenizer); | 3157 | GNUNET_SERVER_mst_destroy(plugin->suid_tokenizer); |
2986 | 3158 | ||
@@ -3051,7 +3223,6 @@ libgnunet_plugin_transport_wlan_init(void *cls) | |||
3051 | api->address_pretty_printer = &wlan_plugin_address_pretty_printer; | 3223 | api->address_pretty_printer = &wlan_plugin_address_pretty_printer; |
3052 | api->check_address = &wlan_plugin_address_suggested; | 3224 | api->check_address = &wlan_plugin_address_suggested; |
3053 | api->address_to_string = &wlan_plugin_address_to_string; | 3225 | api->address_to_string = &wlan_plugin_address_to_string; |
3054 | |||
3055 | //read config | 3226 | //read config |
3056 | 3227 | ||
3057 | if (GNUNET_CONFIGURATION_have_value(env->cfg, "transport-wlan", "TESTMODE")) | 3228 | if (GNUNET_CONFIGURATION_have_value(env->cfg, "transport-wlan", "TESTMODE")) |