From: David Brodski Date: Tue, 19 Apr 2011 11:15:25 +0000 (+0000) Subject: Cleanup and working version with hardware X-Git-Tag: initial-import-from-subversion-38251~18657 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=10e27ef7411f47f290887a9cfe040cc171d1dff3;p=oweals%2Fgnunet.git Cleanup and working version with hardware --- diff --git a/src/transport/gnunet-transport-wlan-helper.c b/src/transport/gnunet-transport-wlan-helper.c index aaa34284d..2cb14b4c6 100644 --- a/src/transport/gnunet-transport-wlan-helper.c +++ b/src/transport/gnunet-transport-wlan-helper.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -259,7 +260,6 @@ usage() "1 = first loopback file\n" "2 = second loopback file\n" "\n"); - exit(1); } static unsigned long @@ -412,7 +412,7 @@ static int linux_read(struct Hardware_Infos * dev, unsigned char *buf, int count, struct Radiotap_rx * ri) { - unsigned char tmpbuf[4096]; + unsigned char tmpbuf[4096 * 4]; int caplen, n, got_signal, got_noise, got_channel, fcs_removed; @@ -604,14 +604,15 @@ linux_read(struct Hardware_Infos * dev, unsigned char *buf, int count, static int linux_write(struct Hardware_Infos * dev, unsigned char *buf, unsigned int count) { - int ret, usedrtap = 0; - unsigned short int *p_rtlen; + int ret; + //int usedrtap; + //unsigned short int *p_rtlen; - unsigned char * u8aRadiotap = buf; + //unsigned char * u8aRadiotap = buf; /* Pointer to the radiotap header length field for later use. */ - p_rtlen = (unsigned short int*) (u8aRadiotap + 2); - usedrtap = 0; + //p_rtlen = (unsigned short int*) (u8aRadiotap + 2); + //usedrtap = 0; ret = write(dev->fd_out, buf, count); if (ret < 0) @@ -628,21 +629,21 @@ linux_write(struct Hardware_Infos * dev, unsigned char *buf, unsigned int count) } /* radiotap header length is stored little endian on all systems */ - if (usedrtap) - ret -= letoh16(*p_rtlen); + /*if (usedrtap) + ret -= letoh16(*p_rtlen); - if (ret < 0) - { - if (errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS || errno - == ENOMEM) - { - usleep(10000); - return (0); - } + if (ret < 0) + { + if (errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS || errno + == ENOMEM) + { + usleep(10000); + return (0); + } - perror("write failed"); - return (-1); - } + perror("write failed"); + return (-1); + }*/ return (ret); } @@ -672,12 +673,7 @@ openraw(struct Hardware_Infos * dev, char * iface, int fd, int * arptype, sll.sll_family = AF_PACKET; sll.sll_ifindex = ifr.ifr_ifindex; - switch (dev->drivertype) - { - default: - sll.sll_protocol = htons(ETH_P_ALL); - break; - } + sll.sll_protocol = htons(ETH_P_ALL); /* lookup the hardware type */ @@ -886,12 +882,12 @@ mac_test(unsigned char * buf, struct Hardware_Infos * dev) u8aIeeeHeader = (struct ieee80211_frame *) buf; if (0 == memcmp(u8aIeeeHeader->i_addr3, &mac_bssid, 6)) { - if (0 == memcmp(u8aIeeeHeader->i_addr2, dev->pl_mac, 6)) + if (0 == memcmp(u8aIeeeHeader->i_addr1, dev->pl_mac, 6)) { return 0; } - if (0 == memcmp(u8aIeeeHeader->i_addr2, &bc_all_mac, 6)) + if (0 == memcmp(u8aIeeeHeader->i_addr1, &bc_all_mac, 6)) { return 0; } @@ -912,7 +908,7 @@ mac_set(unsigned char * buf, struct Hardware_Infos * dev) struct ieee80211_frame * u8aIeeeHeader; u8aIeeeHeader = (struct ieee80211_frame *) buf; - u8aIeeeHeader->i_fc[0] = 0x80; + u8aIeeeHeader->i_fc[0] = 0x08; u8aIeeeHeader->i_fc[1] = 0x00; memcpy(u8aIeeeHeader->i_addr2, dev->pl_mac, 6); @@ -954,8 +950,7 @@ stdin_send_hw(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) exit(1); } - if (sendsize < sizeof(struct ieee80211_frame) + sizeof(struct WlanHeader) - + sizeof(struct FragmentationHeader) + if (sendsize < sizeof(struct ieee80211_frame) + sizeof(struct GNUNET_MessageHeader)) { fprintf(stderr, "Function stdin_send: packet too small\n"); @@ -970,9 +965,7 @@ stdin_send_hw(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) case DT_MAC80211_RT: memcpy(write_pout->buf, u8aRadiotap, sizeof(u8aRadiotap)); - memcpy(write_pout->buf + sizeof(u8aRadiotap), write_pout->buf - + sizeof(struct Radiotap_Send) + sizeof(struct GNUNET_MessageHeader), - sendsize); + memcpy(write_pout->buf + sizeof(u8aRadiotap), &header[1], sendsize); wlanheader = write_pout->buf + sizeof(u8aRadiotap); mac_set(wlanheader, dev); @@ -1067,12 +1060,15 @@ int hardwaremode(int argc, char *argv[]) { + uid_t uid; struct Hardware_Infos dev; - struct ifreq ifreq; + //struct ifreq ifreq; struct Radiotap_rx * rxinfo; uint8_t * mac = dev.pl_mac; int fdpin, fdpout; + struct GNUNET_MessageHeader * header; + signal(SIGINT, &sigfunc_hw); signal(SIGTERM, &sigfunc_hw); @@ -1081,9 +1077,16 @@ hardwaremode(int argc, char *argv[]) return 1; } - printf("Device %s -> Ethernet %02x:%02x:%02x:%02x:%02x:%02x\n", - ifreq.ifr_name, (int) mac[0], (int) mac[1], (int) mac[2], (int) mac[3], - (int) mac[4], (int) mac[5]); + uid = getuid(); + //if (0 != setresuid(uid, uid, uid)) + //{ + // fprintf(stderr, "Failed to setresuid: %s\n", strerror(errno)); + /* not critical, continue anyway */ + //} + + /*printf("Device %s -> Ethernet %02x:%02x:%02x:%02x:%02x:%02x\n", + ifreq.ifr_name, (int) mac[0], (int) mac[1], (int) mac[2], (int) mac[3], + (int) mac[4], (int) mac[5]);*/ //return 0; @@ -1127,10 +1130,10 @@ hardwaremode(int argc, char *argv[]) while (0 == closeprog) { - write_pout.size = maketest(write_pout.buf, &dev); - tv.tv_sec = 2; - tv.tv_usec = 0; - select(0, NULL, NULL, NULL, &tv); + //write_pout.size = maketest(write_pout.buf, &dev); + //tv.tv_sec = 2; + //tv.tv_usec = 0; + //select(0, NULL, NULL, NULL, &tv); maxfd = 0; @@ -1147,8 +1150,8 @@ hardwaremode(int argc, char *argv[]) } if (0 == write_std.size) { - //FD_SET(fdpin, &rfds); - //maxfd = fdpin; + FD_SET(fdpin, &rfds); + maxfd = fdpin; } FD_ZERO(&wfds); // if there is something to write @@ -1253,12 +1256,13 @@ hardwaremode(int argc, char *argv[]) if (FD_ISSET(fdpin, &rfds)) { - rxinfo = (struct Radiotap_rx *) (write_pout.buf + rxinfo = (struct Radiotap_rx *) (write_std.buf + sizeof(struct GNUNET_MessageHeader)); - datastart = (unsigned char *) readbuf + sizeof(struct Radiotap_rx) + datastart = (unsigned char *) write_std.buf + + sizeof(struct Radiotap_rx) + sizeof(struct GNUNET_MessageHeader); - readsize = linux_read(&dev, datastart, sizeof(readbuf) + readsize = linux_read(&dev, datastart, sizeof(write_std.buf) - sizeof(struct Radiotap_rx) - sizeof(struct GNUNET_MessageHeader), rxinfo); @@ -1273,8 +1277,20 @@ hardwaremode(int argc, char *argv[]) if (1 == mac_test(datastart, &dev)) { // mac wrong - write_pout.pos = 0; - write_pout.size = 0; + write_std.pos = 0; + write_std.size = 0; + } + else + { + header = (struct GNUNET_MessageHeader *) write_std.buf; + write_std.size = readsize + + sizeof(struct GNUNET_MessageHeader) + + sizeof(struct Radiotap_rx); + header->size = htons(write_std.size); + header->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); + fprintf(stderr, "Got packet with size: %u, size std %u\n", + readsize, write_std.size); + } } else @@ -1297,6 +1313,7 @@ hardwaremode(int argc, char *argv[]) int main(int argc, char *argv[]) { + int ret = 0; if (3 != argc) { fprintf( @@ -1309,11 +1326,12 @@ main(int argc, char *argv[]) if (strstr(argv[2], "1") || strstr(argv[2], "2")) { - return testmode(argc, argv); + ret = testmode(argc, argv); } else { - return hardwaremode(argc, argv); + + ret = hardwaremode(argc, argv); } #if 0 @@ -1578,6 +1596,8 @@ main(int argc, char *argv[]) } #endif - return (0); + + return ret; + maketest(NULL, NULL); } diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index 0564e9127..f8178f101 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c @@ -60,7 +60,7 @@ #define HALLO_BEACON_SCALING_FACTOR 900 -#define DEBUG_wlan GNUNET_NO +#define DEBUG_wlan GNUNET_YES #define DEBUG_wlan_retransmission GNUNET_NO #define MESSAGE_LENGHT_UNKNOWN -1 @@ -811,12 +811,14 @@ set_next_beacon_time(struct Plugin * const plugin) } //TODO doxigen -static struct GNUNET_TIME_Relative -get_next_frag_timeout(struct FragmentMessage * fm) -{ - return GNUNET_TIME_relative_min(GNUNET_TIME_absolute_get_remaining( - fm->next_ack), GNUNET_TIME_absolute_get_remaining(fm->timeout)); -} +/* + static struct GNUNET_TIME_Relative + get_next_frag_timeout(struct FragmentMessage * fm) + { + return GNUNET_TIME_relative_min(GNUNET_TIME_absolute_get_remaining( + fm->next_ack), GNUNET_TIME_absolute_get_remaining(fm->timeout)); + } + */ //TODO doxigen /** @@ -838,7 +840,8 @@ static void set_next_send(struct Plugin * const plugin) { struct FragmentMessage * fm; - struct GNUNET_TIME_Relative next_send = GNUNET_TIME_UNIT_FOREVER_REL; + struct GNUNET_TIME_Relative next_send; + struct GNUNET_TIME_Absolute next_send_tmp; //cancel old task if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK) @@ -861,15 +864,11 @@ set_next_send(struct Plugin * const plugin) next_send = GNUNET_TIME_absolute_get_remaining(plugin->beacon_time); if (fm != NULL) { - if (GNUNET_CONTAINER_node_get_cost(fm->node) != 0) - { - next_send = GNUNET_TIME_relative_min(next_send, - get_next_frag_timeout(fm)); - } - else - { - next_send = GNUNET_TIME_UNIT_ZERO; - } + next_send_tmp.abs_value = GNUNET_CONTAINER_heap_node_get_cost( + fm->node); + next_send = GNUNET_TIME_relative_min(next_send, + GNUNET_TIME_absolute_get_remaining(next_send_tmp)); + } } @@ -898,10 +897,12 @@ get_next_queue_session(struct Plugin * plugin) struct Sessionqueue * sessionqueue_alt; struct PendingMessage * pm; sessionqueue = plugin->pending_Sessions; + while (sessionqueue != NULL) { session = sessionqueue->content; + GNUNET_assert(session != NULL); pm = session->pending_message; #if DEBUG_wlan @@ -912,6 +913,7 @@ get_next_queue_session(struct Plugin * plugin) session); } #endif + GNUNET_assert(pm != NULL); //check for message timeout @@ -1025,7 +1027,10 @@ check_fragment_queue(struct Plugin * plugin) fm->message_id_out = get_next_message_id(); fm->ack_bitfield = 0; fm->node = GNUNET_CONTAINER_heap_insert( - plugin->pending_Fragment_Messages, fm, 0); + plugin->pending_Fragment_Messages, fm, + GNUNET_TIME_absolute_get().abs_value); + + GNUNET_assert(session !=NULL); if (pm->transmit_cont != NULL) { @@ -1093,8 +1098,6 @@ check_finished_fragment(struct Plugin * plugin, struct FragmentMessage * fm) free_fragment_message(plugin, fm); - - check_fragment_queue(plugin); } @@ -1170,13 +1173,21 @@ getRadiotapHeader(struct Plugin * plugin, struct Session * session, */ static int getWlanHeader(struct ieee80211_frame * Header, - const struct MacAddress * to_mac_addr, struct Plugin * plugin) + const struct MacAddress * to_mac_addr, struct Plugin * plugin, + unsigned int size) { - Header->i_fc[0] = 0x80; + uint16_t * tmp16; + const int rate = 11000000; + + Header->i_fc[0] = 0x08; Header->i_fc[1] = 0x00; memcpy(&Header->i_addr3, &mac_bssid, sizeof(mac_bssid)); memcpy(&Header->i_addr2, plugin->mac_address.mac, sizeof(plugin->mac_address)); - memcpy(&Header->i_addr1, to_mac_addr, 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); + return GNUNET_YES; } @@ -1241,7 +1252,7 @@ send_hello_beacon(struct Plugin * plugin) radioHeader = (struct Radiotap_Send*) &msgheader[1]; getRadiotapHeader(plugin, NULL, radioHeader); ieeewlanheader = (struct ieee80211_frame*) &radioHeader[1]; - getWlanHeader(ieeewlanheader, &bc_all_mac, plugin); + getWlanHeader(ieeewlanheader, &bc_all_mac, plugin, size); msgheader2 = (struct GNUNET_MessageHeader*) &ieeewlanheader[1]; msgheader2->size = htons(GNUNET_HELLO_size(*(plugin->env->our_hello)) @@ -1297,7 +1308,7 @@ send_ack(struct Plugin * plugin, struct AckSendQueue * ack) radioHeader = (struct Radiotap_Send*) &msgheader[1]; getRadiotapHeader(plugin, ack->session, radioHeader); ieeewlanheader = (struct ieee80211_frame*) &radioHeader[1]; - getWlanHeader(ieeewlanheader, &ack->session->addr, plugin); + getWlanHeader(ieeewlanheader, &ack->session->addr, plugin, size); msgheader2 = (struct FragmentationAckHeader*) &ieeewlanheader[1]; msgheader2->header.size = htons(sizeof(struct FragmentationAckHeader)); @@ -1488,7 +1499,7 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) getRadiotapHeader(plugin, session, radioHeader); ieeewlanheader = (struct ieee80211_frame *) &radioHeader[1]; - getWlanHeader(ieeewlanheader, &fm->session->addr, plugin); + getWlanHeader(ieeewlanheader, &(fm->session->addr), plugin, size); //could be faster if content is just send and not copyed before //fragmentheader is needed @@ -1528,6 +1539,7 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) // if fragments have opimized timeouts //sort_fragment_into_queue(plugin,fm); + #if DEBUG_wlan_retransmission GNUNET_log( GNUNET_ERROR_TYPE_DEBUG, @@ -1537,6 +1549,12 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) fm->timeout)); #endif } + else + { + GNUNET_CONTAINER_heap_update_cost( + plugin->pending_Fragment_Messages, fm->node, + GNUNET_TIME_absolute_get().abs_value); + } if (bytes != size) { @@ -1556,7 +1574,6 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } else { - GNUNET_assert(bytes == size); GNUNET_free(msgheader); set_next_send(plugin); } @@ -1858,6 +1875,9 @@ free_session(struct Plugin * plugin, struct Sessionqueue * queue) struct PendingMessage * pm; struct Receive_Message_Queue * receive_queue; struct Plugin_Session_pair pair; + int check = 0; + + GNUNET_assert(queue != NULL); //session found //is this session pending for send @@ -1869,7 +1889,14 @@ free_session(struct Plugin * plugin, struct Sessionqueue * queue) GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions, plugin->pending_Sessions_tail, pendingsession); GNUNET_free(pendingsession); - break; + + if (check == 1) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Session is more then once in pending session\n"); + } + + check = 1; } pendingsession = pendingsession->next; } @@ -1904,8 +1931,8 @@ free_session(struct Plugin * plugin, struct Sessionqueue * queue) GNUNET_free(pm); } - GNUNET_free(queue->content); GNUNET_CONTAINER_DLL_remove(plugin->sessions, plugin->sessions_tail, queue); + GNUNET_free(queue->content); GNUNET_free(queue); plugin->session_count--; @@ -2681,7 +2708,7 @@ wlan_process_helper(void *cls, void *client, hdr->size), sizeof(struct ieee80211_frame) + sizeof(struct GNUNET_MessageHeader)); #endif - GNUNET_break (0); + //GNUNET_break (0); /* FIXME: restart SUID process */ return; } @@ -2892,6 +2919,7 @@ libgnunet_plugin_transport_wlan_done(void *cls) struct GNUNET_TRANSPORT_PluginFunctions *api = cls; struct Plugin *plugin = api->cls; struct Sessionqueue * queue = plugin->sessions; + struct Sessionqueue * queue_next; struct FragmentMessage * fm; #if DEBUG_wlan @@ -2907,17 +2935,23 @@ libgnunet_plugin_transport_wlan_done(void *cls) if (plugin->data_tokenizer != NULL) GNUNET_SERVER_mst_destroy(plugin->data_tokenizer); + fm = (struct FragmentMessage *) GNUNET_CONTAINER_heap_peek( + plugin->pending_Fragment_Messages); - fm = (struct FragmentMessage *) GNUNET_CONTAINER_heap_peek(plugin->pending_Fragment_Messages); - while (fm != NULL){ - free_fragment_message(plugin, fm); - fm = (struct FragmentMessage *) GNUNET_CONTAINER_heap_peek(plugin->pending_Fragment_Messages); - } + while (fm != NULL) + { + free_fragment_message(plugin, fm); + fm = (struct FragmentMessage *) GNUNET_CONTAINER_heap_peek( + plugin->pending_Fragment_Messages); + } //free sessions while (queue != NULL) { + queue_next = queue->next; free_session(plugin, queue); + queue = queue_next; + } GNUNET_free_non_null(plugin->interface); diff --git a/src/transport/test_transport_api_wlan_peer1.conf b/src/transport/test_transport_api_wlan_peer1.conf index ecfcebf64..683093ff7 100644 --- a/src/transport/test_transport_api_wlan_peer1.conf +++ b/src/transport/test_transport_api_wlan_peer1.conf @@ -8,8 +8,8 @@ AUTOSTART = NO AUTOSTART = NO [transport-wlan] -INTERFACE = wlan0 -TESTMODE = 1 +INTERFACE = mon0 +TESTMODE = 0 #PREFIX = gdbserver :2345 [hostlist] @@ -45,6 +45,7 @@ PORT = 12365 UNIXPATH = /tmp/gnunet-p1-service-transport.sock #PREFIX = xterm -T transport2 -e gdb --command=cmd --args #PREFIX = valgrind --leak-check=full --show-reachable=yes --main-stacksize=104857600 +#PREFIX = valgrind --leak-check=full --show-reachable=yes #PREFIX = valgrind --leak-check=full #PREFIX = valgrind --tool=massif #PREFIX = gdbserver :2345 diff --git a/src/transport/test_transport_api_wlan_peer2.conf b/src/transport/test_transport_api_wlan_peer2.conf index eff0c2516..22824e090 100644 --- a/src/transport/test_transport_api_wlan_peer2.conf +++ b/src/transport/test_transport_api_wlan_peer2.conf @@ -8,8 +8,8 @@ AUTOSTART = NO AUTOSTART = NO [transport-wlan] -INTERFACE = wlan1 -TESTMODE = 2 +INTERFACE = mon1 +TESTMODE = 0 #PREFIX = gdbserver :2346 [hostlist] @@ -45,6 +45,7 @@ PORT = 22365 UNIXPATH = /tmp/gnunet-p2-service-transport.sock #PREFIX = xterm -T transport1 -e gdb --command=cmd --args #PREFIX = valgrind --leak-check=full --show-reachable=yes --main-stacksize=104857600 +#PREFIX = valgrind --leak-check=full --show-reachable=yes #PREFIX = valgrind --leak-check=full #PREFIX = valgrind --tool=massif #PREFIX = gdbserver :2346