aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-transport-wlan-helper.h2
-rw-r--r--src/transport/plugin_transport_wlan.c454
-rw-r--r--src/transport/plugin_transport_wlan.h20
-rw-r--r--src/transport/test_plugin_transport_wlan_dummy.c28
4 files changed, 291 insertions, 213 deletions
diff --git a/src/transport/gnunet-transport-wlan-helper.h b/src/transport/gnunet-transport-wlan-helper.h
index c6230bad8..e4d13275c 100644
--- a/src/transport/gnunet-transport-wlan-helper.h
+++ b/src/transport/gnunet-transport-wlan-helper.h
@@ -36,7 +36,7 @@
36#include <unistd.h> 36#include <unistd.h>
37#include <getopt.h> 37#include <getopt.h>
38#include <pcap.h> 38#include <pcap.h>
39#include <endian.h> 39//#include <endian.h>
40#include <pcap.h> 40#include <pcap.h>
41 41
42 42
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c
index 98caaa4f1..8a4201863 100644
--- a/src/transport/plugin_transport_wlan.c
+++ b/src/transport/plugin_transport_wlan.c
@@ -73,12 +73,13 @@ struct WelcomeMessage
73 struct GNUNET_MessageHeader header; 73 struct GNUNET_MessageHeader header;
74 74
75 /** 75 /**
76 * Identity of the node connecting (TCP client) 76 * Identit*mac_y of the node connecting (TCP client)
77 */ 77 */
78 struct GNUNET_PeerIdentity clientIdentity; 78 struct GNUNET_PeerIdentity clientIdentity;
79 79
80}; 80};
81 81
82
82/** 83/**
83 * Encapsulation of all of the state of the plugin. 84 * Encapsulation of all of the state of the plugin.
84 */ 85 */
@@ -160,7 +161,7 @@ struct Plugin
160 /** 161 /**
161 * The mac_address of the wlan card given to us by the helper. 162 * The mac_address of the wlan card given to us by the helper.
162 */ 163 */
163 char *mac_address; 164 struct MacAddress mac_address;
164 165
165 /** 166 /**
166 * Sessions currently pending for transmission 167 * Sessions currently pending for transmission
@@ -227,6 +228,8 @@ struct AckQueue
227 int fragment_num; //TODO change it to offset if better 228 int fragment_num; //TODO change it to offset if better
228}; 229};
229 230
231
232
230/** 233/**
231 * Queue for the fragments received 234 * Queue for the fragments received
232 */ 235 */
@@ -545,6 +548,9 @@ static void
545free_rec_frag_queue(struct Session * session); 548free_rec_frag_queue(struct Session * session);
546 549
547static void 550static void
551wlan_data_helper(void *cls, void * client, const struct GNUNET_MessageHeader * hdr);
552
553static void
548wlan_process_helper (void *cls, 554wlan_process_helper (void *cls,
549 void *client, 555 void *client,
550 const struct GNUNET_MessageHeader *hdr); 556 const struct GNUNET_MessageHeader *hdr);
@@ -588,7 +594,7 @@ search_session(struct Plugin *plugin, const uint8_t * addr)
588 while (queue != NULL) 594 while (queue != NULL)
589 { 595 {
590 // content is never NULL 596 // content is never NULL
591 GNUNET_assert (queue->content == NULL); 597 GNUNET_assert (queue->content != NULL);
592 char * addr2 = queue->content->addr; 598 char * addr2 = queue->content->addr;
593 if (memcmp(addr, addr2, 6) == 0) 599 if (memcmp(addr, addr2, 6) == 0)
594 { 600 {
@@ -1013,6 +1019,7 @@ do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1013 struct GNUNET_MessageHeader * msgheader = NULL; 1019 struct GNUNET_MessageHeader * msgheader = NULL;
1014 struct GNUNET_MessageHeader * msgheader2 = NULL; 1020 struct GNUNET_MessageHeader * msgheader2 = NULL;
1015 struct FragmentationHeader fragheader; 1021 struct FragmentationHeader fragheader;
1022 struct FragmentationHeader * fragheaderptr = NULL;
1016 uint16_t size = 0; 1023 uint16_t size = 0;
1017 const char * copystart = NULL; 1024 const char * copystart = NULL;
1018 uint16_t copysize = 0; 1025 uint16_t copysize = 0;
@@ -1169,7 +1176,8 @@ do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1169 if (fm->message_size > WLAN_MTU){ 1176 if (fm->message_size > WLAN_MTU){
1170 fragheader.message_crc = htons(getcrc16(copystart, copysize)); 1177 fragheader.message_crc = htons(getcrc16(copystart, copysize));
1171 memcpy(&ieeewlanheader[1],&fragheader, sizeof(struct FragmentationHeader)); 1178 memcpy(&ieeewlanheader[1],&fragheader, sizeof(struct FragmentationHeader));
1172 memcpy(&ieeewlanheader[1] + sizeof(struct FragmentationHeader),copystart,copysize); 1179 fragheaderptr = (struct FragmentationHeader *) &ieeewlanheader[1];
1180 memcpy(&fragheaderptr[1],copystart,copysize);
1173 } else { 1181 } else {
1174 memcpy(&ieeewlanheader[1],copystart,copysize); 1182 memcpy(&ieeewlanheader[1],copystart,copysize);
1175 } 1183 }
@@ -1314,6 +1322,8 @@ wlan_plugin_send (void *cls,
1314 newmsg->timeout = GNUNET_TIME_relative_to_absolute(timeout); 1322 newmsg->timeout = GNUNET_TIME_relative_to_absolute(timeout);
1315 newmsg->message_size = msgbuf_size + sizeof(struct WlanHeader); 1323 newmsg->message_size = msgbuf_size + sizeof(struct WlanHeader);
1316 1324
1325 session->pending_message = newmsg;
1326
1317 check_fragment_queue(plugin); 1327 check_fragment_queue(plugin);
1318 //FIXME not the correct size 1328 //FIXME not the correct size
1319 return msgbuf_size; 1329 return msgbuf_size;
@@ -1357,7 +1367,7 @@ wlan_plugin_disconnect(void *cls, const struct GNUNET_PeerIdentity *target)
1357 while (queue != NULL) 1367 while (queue != NULL)
1358 { 1368 {
1359 // content is never NULL 1369 // content is never NULL
1360 GNUNET_assert (queue->content == NULL); 1370 GNUNET_assert (queue->content != NULL);
1361 if (memcmp(target, &(queue->content->target), 1371 if (memcmp(target, &(queue->content->target),
1362 sizeof(struct GNUNET_PeerIdentity)) == 0) 1372 sizeof(struct GNUNET_PeerIdentity)) == 0)
1363 { 1373 {
@@ -1633,12 +1643,225 @@ check_rec_finished_msg (struct Plugin* plugin, struct Session_light * session_li
1633 } 1643 }
1634 free_rec_frag_queue(session); 1644 free_rec_frag_queue(session);
1635 //call wlan_process_helper to process the message 1645 //call wlan_process_helper to process the message
1636 wlan_process_helper (plugin, session_light, (struct GNUNET_MessageHeader*) msg); 1646 wlan_data_helper (plugin, session_light, (struct GNUNET_MessageHeader*) msg);
1637 1647
1638 GNUNET_free(msg); 1648 GNUNET_free(msg);
1639 } 1649 }
1640} 1650}
1641 1651
1652static void
1653wlan_data_helper(void *cls, void * client, const struct GNUNET_MessageHeader * hdr)
1654{
1655 struct Plugin *plugin = cls;
1656 struct Session * session = NULL;
1657 struct Session_light * session_light = NULL;
1658
1659 struct WlanHeader * wlanheader = NULL;
1660 struct FragmentationHeader * fh = NULL;
1661 struct FragmentMessage * fm = NULL;
1662
1663 const char * tempmsg = NULL;
1664
1665 struct AckQueue * ack = NULL;
1666 struct AckQueue * ack2 = NULL;
1667
1668 struct RecQueue * rec_queue = NULL;
1669 const struct GNUNET_MessageHeader * temp_hdr = NULL;
1670
1671 if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT)
1672 {
1673 //TODO better DOS protection, error handling
1674 GNUNET_assert(client != NULL);
1675 session_light = (struct Session_light *) client;
1676 if (session_light->session == NULL){
1677 session_light->session = get_Session(plugin, session_light->addr);
1678 }
1679 GNUNET_assert(GNUNET_HELLO_get_id(
1680 (const struct GNUNET_HELLO_Message *) &hdr[1],
1681 &(session_light->session->target) ) != GNUNET_SYSERR);
1682
1683 }
1684
1685
1686 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA)
1687 {
1688 GNUNET_assert(client != NULL);
1689 session_light = (struct Session_light *) client;
1690 if (session_light->session == NULL){
1691 session_light->session = search_session(plugin, session_light->addr);
1692 }
1693 session = session_light->session;
1694 wlanheader =(struct WlanHeader *) &hdr[1];
1695 tempmsg = (char*) &wlanheader[1];
1696 temp_hdr = ( const struct GNUNET_MessageHeader *) &wlanheader[1];
1697
1698 if (getcrc32(tempmsg, wlanheader->header.size) != wlanheader->crc){
1699 //wrong crc, dispose message
1700 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1701 "WLAN message crc was wrong\n");
1702 return;
1703 }
1704
1705 //if not in session list
1706 if (session == NULL){
1707
1708 //try if it is a hello message
1709 if (ntohs(temp_hdr->type) == GNUNET_MESSAGE_TYPE_HELLO){
1710 session = create_session(plugin, session_light->addr);
1711 session_light->session = session;
1712 GNUNET_assert(GNUNET_HELLO_get_id(
1713 (const struct GNUNET_HELLO_Message *) temp_hdr,
1714 &session->target ) != GNUNET_SYSERR);
1715
1716 } else {
1717 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1718 "WLAN client not in session list and not a hello message\n");
1719 return;
1720 }
1721 }
1722 //"receive" the message
1723 struct GNUNET_TRANSPORT_ATS_Information distance[2];
1724 distance[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
1725 distance[0].value = htonl (1);
1726 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
1727 distance[1].value = htonl (0);
1728
1729 plugin->env->receive(plugin, &session->target,
1730 temp_hdr, (const struct GNUNET_TRANSPORT_ATS_Information *) &distance, 2,
1731 session, session->addr, sizeof(session->addr));
1732 }
1733
1734 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT)
1735 {
1736 GNUNET_assert(client != NULL);
1737 session_light = (struct Session_light *) client;
1738 if (session_light->session == NULL)
1739 {
1740 session_light->session = search_session(plugin, session_light->addr);
1741 }
1742 session = session_light->session;
1743
1744 fh = (struct FragmentationHeader *) hdr;
1745 tempmsg = (char*) &fh[1];
1746
1747 //if not in session list
1748 if (session != NULL)
1749 {
1750 if (getcrc16(tempmsg, fh->header.size) != fh->message_crc)
1751 {
1752 //wrong crc, dispose message
1753 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1754 "WLAN fragment crc was wrong\n");
1755 return;
1756 }
1757 else
1758 {
1759 //todo fragments do not timeout
1760 //check if message_id is rigth or it is a new msg
1761 if ((session->message_id_in == ntohs(fh->message_id))
1762 || (session->rec_size == NO_MESSAGE_OR_MESSAGE_FINISHED))
1763 {
1764 session->message_id_in = ntohs(fh->message_id);
1765 if (is_double_msg(session, fh) != GNUNET_YES)
1766 {
1767 rec_queue = GNUNET_malloc(sizeof (struct RecQueue) +
1768 ntohs(fh->header.size) - sizeof(struct FragmentationHeader));
1769 rec_queue->size = ntohs(fh->header.size
1770 - sizeof(struct FragmentationHeader));
1771 rec_queue->num = ntohs(fh->fragment_off_or_num);
1772 rec_queue->msg = (char*) &rec_queue[1];
1773 //copy msg to buffer
1774 memcpy((char*) rec_queue->msg, tempmsg, rec_queue->size);
1775 insert_fragment_in_queue(session, rec_queue);
1776 check_rec_finished_msg(plugin, session_light, session);
1777 }
1778 else
1779 {
1780 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1781 "WLAN fragment is a clone\n");
1782 return;
1783 }
1784 }
1785 else
1786 {
1787 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1788 "WLAN fragment message_id and session message_id are not the same and a message is already (partly) received\n");
1789 return;
1790 }
1791 }
1792 }
1793 else
1794 {
1795 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1796 "WLAN client not in session list and it is a fragment message\n");
1797 return;
1798 }
1799
1800 }
1801
1802 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK)
1803 {
1804 GNUNET_assert(client != NULL);
1805 session_light = (struct Session_light *) client;
1806 if (session_light->session == NULL)
1807 {
1808 session_light->session = search_session(plugin, session_light->addr);
1809 GNUNET_assert(session_light->session != NULL);
1810 }
1811 session = session_light->session;
1812 fh = (struct FragmentationHeader *) &hdr[1];
1813 if (fh->message_id == session->message_id_out)
1814 {
1815 fm = get_fragment_message_from_session(session);
1816 if (fm != NULL)
1817 {
1818
1819 ack2 = fm->head;
1820 while (ack2!=NULL){
1821 // check for double
1822 if (ack2->fragment_num != fh->fragment_off_or_num)
1823 {
1824 // check if next ack has bigger number
1825 if (ack2->fragment_num > fh->fragment_off_or_num)
1826 {
1827 ack = GNUNET_malloc(sizeof(struct AckQueue));
1828 ack->fragment_num = fh->fragment_off_or_num;
1829 GNUNET_CONTAINER_DLL_insert_before(fm->head,fm->tail,ack2,ack);
1830 //check if finished
1831 check_finished_fragment(plugin, fm);
1832 return;
1833 }
1834 }
1835 else
1836 {
1837 //double ack
1838 return;
1839 }
1840 ack2 = ack2->next;
1841 }
1842 //GNUNET_CONTAINER_DLL_insert_tail(fm->head,fm->tail,ack);
1843 //should never happen but...
1844 //check_finished_fragment(plugin, fm);
1845 }
1846 else
1847 {
1848 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1849 "WLAN fragment not in fragment list but id is right\n");
1850 return;
1851 }
1852
1853 }
1854
1855 }
1856 else
1857 {
1858 // TODO Wrong data?
1859 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "WLAN packet has not the right type\n");
1860 return;
1861 }
1862
1863}
1864
1642/** 1865/**
1643 * Function used for to process the data from the suid process 1866 * Function used for to process the data from the suid process
1644 */ 1867 */
@@ -1651,16 +1874,9 @@ wlan_process_helper (void *cls,
1651{ 1874{
1652 struct Plugin *plugin = cls; 1875 struct Plugin *plugin = cls;
1653 struct IeeeHeader * wlanIeeeHeader = NULL; 1876 struct IeeeHeader * wlanIeeeHeader = NULL;
1654 struct Session * session = NULL; 1877 struct Session_light * session_light = NULL;
1655 struct WlanHeader * wlanheader = NULL;
1656 struct FragmentationHeader * fh = NULL;
1657 struct FragmentMessage * fm = NULL;
1658 struct RecQueue * rec_queue = NULL;
1659 const struct GNUNET_MessageHeader * temp_hdr = NULL; 1878 const struct GNUNET_MessageHeader * temp_hdr = NULL;
1660 const char * tempmsg = NULL; 1879
1661 struct Session_light * session_light;
1662 struct AckQueue * ack;
1663 struct AckQueue * ack2;
1664 int pos = 0; 1880 int pos = 0;
1665 1881
1666 1882
@@ -1671,227 +1887,50 @@ wlan_process_helper (void *cls,
1671 wlanIeeeHeader = (struct IeeeHeader *) &hdr[1]; 1887 wlanIeeeHeader = (struct IeeeHeader *) &hdr[1];
1672 1888
1673 session_light = GNUNET_malloc(sizeof(struct Session_light)); 1889 session_light = GNUNET_malloc(sizeof(struct Session_light));
1674 memcpy(session_light->addr, wlanIeeeHeader->mac3, 6); 1890 memcpy(session_light->addr, &(wlanIeeeHeader->mac3), sizeof(struct MacAddress));
1675 session_light->session = search_session(plugin, session_light->addr); 1891 session_light->session = search_session(plugin, session_light->addr);
1676 1892
1677 //process only if it is an broadcast or for this computer both with the gnunet bssid 1893 //process only if it is an broadcast or for this computer both with the gnunet bssid
1678 //check for bssid 1894 //check for bssid
1679 if (memcmp(wlanIeeeHeader->mac2, macbc, sizeof(macbc))) 1895 if (memcmp(&(wlanIeeeHeader->mac2), macbc, sizeof(struct MacAddress)))
1680 { 1896 {
1681 //check for broadcast or mac 1897 //check for broadcast or mac
1682 if (memcmp(wlanIeeeHeader->mac1, bc_all_mac, sizeof(bc_all_mac)) 1898 if (memcmp(&(wlanIeeeHeader->mac1), bc_all_mac, sizeof(struct MacAddress))
1683 || memcmp(wlanIeeeHeader->mac1, plugin->mac_address, 1899 || memcmp(&(wlanIeeeHeader->mac1), &(plugin->mac_address),
1684 sizeof(plugin->mac_address))) 1900 sizeof(struct MacAddress)))
1685 { 1901 {
1686 // process the inner data 1902 // process the inner data
1687 pos = 0; 1903 pos = 0;
1688 temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1]; 1904 temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1];
1689 while (pos < hdr->size) 1905 while (pos < hdr->size)
1690 { 1906 {
1691 wlan_process_helper(plugin, &session_light, 1907 wlan_data_helper(plugin, &session_light, temp_hdr);
1692 temp_hdr);
1693 pos += temp_hdr->size + sizeof(struct GNUNET_MessageHeader); 1908 pos += temp_hdr->size + sizeof(struct GNUNET_MessageHeader);
1694 } 1909 }
1695 } 1910 }
1696 } 1911 }
1697 1912
1698 } 1913 //clean up
1699 1914 GNUNET_free(session_light);
1700
1701 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT)
1702 {
1703 //TODO better DOS protection, error handling
1704 GNUNET_assert(client != NULL);
1705 session_light = (struct Session_light *) client;
1706 if (session_light->session == NULL){
1707 session_light->session = get_Session(plugin, session_light->addr);
1708 }
1709 GNUNET_assert(GNUNET_HELLO_get_id(
1710 (const struct GNUNET_HELLO_Message *) &hdr[1],
1711 &(session_light->session->target) ) != GNUNET_SYSERR);
1712
1713 }
1714
1715
1716 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA)
1717 {
1718 GNUNET_assert(client != NULL);
1719 session_light = (struct Session_light *) client;
1720 if (session_light->session == NULL){
1721 session_light->session = search_session(plugin, session_light->addr);
1722 }
1723 session = session_light->session;
1724 wlanheader =(struct WlanHeader *) &hdr[1];
1725 tempmsg = (char*) &wlanheader[1];
1726 temp_hdr = ( const struct GNUNET_MessageHeader *) &wlanheader[1];
1727
1728 if (getcrc32(tempmsg, wlanheader->header.size) != wlanheader->crc){
1729 //wrong crc, dispose message
1730 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1731 "WLAN message crc was wrong\n");
1732 return;
1733 }
1734
1735 //if not in session list
1736 if (session == NULL){
1737
1738 //try if it is a hello message
1739 if (ntohs(temp_hdr->type) == GNUNET_MESSAGE_TYPE_HELLO){
1740 session = create_session(plugin, session_light->addr);
1741 session_light->session = session;
1742 GNUNET_assert(GNUNET_HELLO_get_id(
1743 (const struct GNUNET_HELLO_Message *) temp_hdr,
1744 &session->target ) != GNUNET_SYSERR);
1745
1746 } else {
1747 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1748 "WLAN client not in session list and not a hello message\n");
1749 return;
1750 }
1751 }
1752 //"receive" the message
1753 struct GNUNET_TRANSPORT_ATS_Information distance[2];
1754 distance[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
1755 distance[0].value = htonl (1);
1756 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
1757 distance[1].value = htonl (0);
1758
1759 plugin->env->receive(plugin, &session->target,
1760 temp_hdr, (const struct GNUNET_TRANSPORT_ATS_Information *) &distance, 2,
1761 session, session->addr, sizeof(session->addr));
1762 }
1763
1764 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT)
1765 {
1766 GNUNET_assert(client != NULL);
1767 session_light = (struct Session_light *) client;
1768 if (session_light->session == NULL)
1769 {
1770 session_light->session = search_session(plugin, session_light->addr);
1771 }
1772 session = session_light->session;
1773
1774 fh = (struct FragmentationHeader *) hdr;
1775 tempmsg = (char*) &fh[1];
1776
1777 //if not in session list
1778 if (session != NULL)
1779 {
1780 if (getcrc16(tempmsg, fh->header.size) != fh->message_crc)
1781 {
1782 //wrong crc, dispose message
1783 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1784 "WLAN fragment crc was wrong\n");
1785 return;
1786 }
1787 else
1788 {
1789 //todo fragments do not timeout
1790 //check if message_id is rigth or it is a new msg
1791 if ((session->message_id_in == ntohs(fh->message_id))
1792 || (session->rec_size == NO_MESSAGE_OR_MESSAGE_FINISHED))
1793 {
1794 session->message_id_in = ntohs(fh->message_id);
1795 if (is_double_msg(session, fh) != GNUNET_YES)
1796 {
1797 rec_queue = GNUNET_malloc(sizeof (struct RecQueue) +
1798 ntohs(fh->header.size) - sizeof(struct FragmentationHeader));
1799 rec_queue->size = ntohs(fh->header.size
1800 - sizeof(struct FragmentationHeader));
1801 rec_queue->num = ntohs(fh->fragment_off_or_num);
1802 rec_queue->msg = (char*) &rec_queue[1];
1803 //copy msg to buffer
1804 memcpy((char*) rec_queue->msg, tempmsg, rec_queue->size);
1805 insert_fragment_in_queue(session, rec_queue);
1806 check_rec_finished_msg(plugin, session_light, session);
1807 }
1808 else
1809 {
1810 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1811 "WLAN fragment is a clone\n");
1812 return;
1813 }
1814 }
1815 else
1816 {
1817 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1818 "WLAN fragment message_id and session message_id are not the same and a message is already (partly) received\n");
1819 return;
1820 }
1821 }
1822 }
1823 else
1824 {
1825 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1826 "WLAN client not in session list and it is a fragment message\n");
1827 return;
1828 }
1829 1915
1830 } 1916 }
1831 1917
1832 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK)
1833 {
1834 GNUNET_assert(client != NULL);
1835 session_light = (struct Session_light *) client;
1836 if (session_light->session == NULL)
1837 {
1838 session_light->session = search_session(plugin, session_light->addr);
1839 }
1840 session = session_light->session;
1841 fh = (struct FragmentationHeader *) &hdr[1];
1842 if (fh->message_id == session->message_id_out)
1843 {
1844 fm = get_fragment_message_from_session(session);
1845 if (fm != NULL)
1846 {
1847 ack = GNUNET_malloc(sizeof(struct AckQueue));
1848 ack->fragment_num = fh->fragment_off_or_num;
1849 ack2 = fm->head;
1850 while (ack2!=NULL){
1851 if (ack2->fragment_num != ack->fragment_num)
1852 {
1853 if (ack2->fragment_num > ack->fragment_num)
1854 {
1855 GNUNET_CONTAINER_DLL_insert_before(fm->head,fm->tail,ack2,ack);
1856 //check if finished
1857 check_finished_fragment(plugin, fm);
1858 }
1859 }
1860 else
1861 {
1862 //double ack
1863 return;
1864 }
1865 ack2 = ack2->next;
1866 }
1867 GNUNET_CONTAINER_DLL_insert_tail(fm->head,fm->tail,ack);
1868 //should never happen but...
1869 check_finished_fragment(plugin, fm);
1870 }
1871 else
1872 {
1873 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1874 "WLAN fragment not in fragment list but id is right\n");
1875 return;
1876 }
1877 1918
1878 }
1879
1880 }
1881 1919
1882 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL) 1920 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL)
1883 { 1921 {
1884 //TODO more control 1922 //TODO more control
1885 if (ntohs(hdr->size) == 6) 1923 //TODO use struct wlan_helper_control
1924 if (ntohs(hdr->size) == sizeof(struct Wlan_Helper_Control_Message))
1886 { 1925 {
1887 plugin->mac_address = GNUNET_malloc(6); 1926 //plugin->mac_address = GNUNET_malloc(sizeof(struct MacAddress));
1888 memcpy(plugin->mac_address, &hdr[1], 6); 1927 memcpy(&(plugin->mac_address), &hdr[1], sizeof(struct MacAddress));
1889 GNUNET_log( 1928 GNUNET_log(
1890 GNUNET_ERROR_TYPE_DEBUG, 1929 GNUNET_ERROR_TYPE_DEBUG,
1891 "Notifying transport of address %s\n", 1930 "Notifying transport of address %s\n",
1892 wlan_plugin_address_to_string(cls, plugin->mac_address, hdr->size)); 1931 wlan_plugin_address_to_string(cls, &(plugin->mac_address), hdr->size));
1893 plugin->env->notify_address(plugin->env->cls, "wlan", 1932 plugin->env->notify_address(plugin->env->cls, "wlan",
1894 &plugin->mac_address, sizeof(plugin->mac_address), 1933 &plugin->mac_address, sizeof(struct MacAddress),
1895 GNUNET_TIME_UNIT_FOREVER_REL); 1934 GNUNET_TIME_UNIT_FOREVER_REL);
1896 } 1935 }
1897 else 1936 else
@@ -1906,7 +1945,7 @@ wlan_process_helper (void *cls,
1906 else 1945 else
1907 { 1946 {
1908 // TODO Wrong data? 1947 // TODO Wrong data?
1909 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "WLAN packet has not the right type\n"); 1948 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "WLAN helper packet has not the right type\n");
1910 return; 1949 return;
1911 } 1950 }
1912} 1951}
@@ -2068,7 +2107,6 @@ libgnunet_plugin_transport_wlan_done (void *cls)
2068 2107
2069 GNUNET_SERVER_mst_destroy(plugin->consoltoken); 2108 GNUNET_SERVER_mst_destroy(plugin->consoltoken);
2070 2109
2071 GNUNET_free_non_null(plugin->mac_address);
2072 GNUNET_free (plugin); 2110 GNUNET_free (plugin);
2073 GNUNET_free (api); 2111 GNUNET_free (api);
2074 return NULL; 2112 return NULL;
diff --git a/src/transport/plugin_transport_wlan.h b/src/transport/plugin_transport_wlan.h
index 3c206a496..dd770e53e 100644
--- a/src/transport/plugin_transport_wlan.h
+++ b/src/transport/plugin_transport_wlan.h
@@ -32,6 +32,20 @@
32typedef unsigned int uint32_t; 32typedef unsigned int uint32_t;
33typedef unsigned short uint16_t; 33typedef unsigned short uint16_t;
34 34
35
36struct MacAddress
37{
38 char mac[6];
39};
40
41struct Wlan_Helper_Control_Message
42{
43 struct GNUNET_MessageHeader hdr;
44 struct MacAddress mac ;
45};
46
47
48
35/* Wlan IEEE80211 header default */ 49/* Wlan IEEE80211 header default */
36//Informations (in German) http://www.umtslink.at/content/WLAN_macheader-196.html 50//Informations (in German) http://www.umtslink.at/content/WLAN_macheader-196.html
37static const uint8_t u8aIeeeHeader[] = 51static const uint8_t u8aIeeeHeader[] =
@@ -74,18 +88,18 @@ struct IeeeHeader
74 /** 88 /**
75 * first mac byte 1 89 * first mac byte 1
76 */ 90 */
77 uint8_t mac1[6]; 91 struct MacAddress mac1;
78 92
79 93
80 /** 94 /**
81 * second mac 95 * second mac
82 */ 96 */
83 uint8_t mac2[6]; 97 struct MacAddress mac2;
84 98
85 /** 99 /**
86 * third mac 100 * third mac
87 */ 101 */
88 uint8_t mac3[6]; 102 struct MacAddress mac3;
89 103
90 /** 104 /**
91 * Wlan Sequence Control 105 * Wlan Sequence Control
diff --git a/src/transport/test_plugin_transport_wlan_dummy.c b/src/transport/test_plugin_transport_wlan_dummy.c
index db50bd125..b4fd46610 100644
--- a/src/transport/test_plugin_transport_wlan_dummy.c
+++ b/src/transport/test_plugin_transport_wlan_dummy.c
@@ -119,6 +119,15 @@ main(int argc, char *argv[])
119 if ((pid = fork()) < 0) 119 if ((pid = fork()) < 0)
120 { 120 {
121 perror("FORK ERROR"); 121 perror("FORK ERROR");
122
123 //clean up
124 if (first == 1)
125 {
126 unlink(FIFO_FILE1);
127 unlink(FIFO_FILE2);
128 }
129 fclose(fpin);
130 fclose(fpout);
122 return -3; 131 return -3;
123 } 132 }
124 else if (pid == 0) // CHILD PROCESS 133 else if (pid == 0) // CHILD PROCESS
@@ -164,12 +173,29 @@ main(int argc, char *argv[])
164 int rv = 0; 173 int rv = 0;
165 ssize_t pos = 0; 174 ssize_t pos = 0;
166 char line[MAXLINE]; 175 char line[MAXLINE];
176 struct Wlan_Helper_Control_Message macmsg;
177
178
179 //Send random mac address
180 macmsg.mac.mac[0] = 0x13;
181 macmsg.mac.mac[1] = 0x22;
182 macmsg.mac.mac[2] = 0x33;
183 macmsg.mac.mac[3] = 0x44;
184 macmsg.mac.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 255);
185 macmsg.mac.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 255);
186 macmsg.hdr.size = sizeof(struct Wlan_Helper_Control_Message);
187
188 pos = 0;
189 while (pos < sizeof(struct Wlan_Helper_Control_Message))
190 {
191 pos += write(STDOUT_FILENO, &macmsg + pos, sizeof(struct Wlan_Helper_Control_Message) - pos);
192 }
167 193
168 while (closeprog == 0) 194 while (closeprog == 0)
169 { 195 {
170 if ((rv = fread(line, 1, MAXLINE, fpin)) < 0) 196 if ((rv = fread(line, 1, MAXLINE, fpin)) < 0)
171 { 197 {
172 perror("READ ERROR FROM STDIN"); 198 perror("READ ERROR FROM fpin");
173 } 199 }
174 200
175 pos = 0; 201 pos = 0;