aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Brodski <david@brodski.eu>2011-01-18 09:49:35 +0000
committerDavid Brodski <david@brodski.eu>2011-01-18 09:49:35 +0000
commitbd22cdc0099f039ca6bb9cc37a9a6b30f505354b (patch)
treedea997399d7a9826dc63841393c439620f106ee6
parent5dc55861ed30804265331edfa3284b7d632d9c30 (diff)
downloadgnunet-bd22cdc0099f039ca6bb9cc37a9a6b30f505354b.tar.gz
gnunet-bd22cdc0099f039ca6bb9cc37a9a6b30f505354b.zip
some doxygen entries and debug messages
-rw-r--r--src/transport/plugin_transport_wlan.c521
1 files changed, 321 insertions, 200 deletions
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c
index 9188ff854..9f91cbfb6 100644
--- a/src/transport/plugin_transport_wlan.c
+++ b/src/transport/plugin_transport_wlan.c
@@ -557,9 +557,8 @@ wlan_process_helper (void *cls,
557 557
558/** 558/**
559 * get the next message number, at the moment just a random one 559 * get the next message number, at the moment just a random one
560 * 560 * @return returns the next valid message-number for sending packets
561 */ 561 */
562//TODO doxigen
563uint32_t 562uint32_t
564get_next_message_id() 563get_next_message_id()
565{ 564{
@@ -568,8 +567,8 @@ get_next_message_id()
568 567
569/** 568/**
570 * start next message number generator 569 * start next message number generator
570 * (not necessary at the moment)
571 */ 571 */
572//TODO doxigen
573void 572void
574start_next_message_id() 573start_next_message_id()
575{ 574{
@@ -792,9 +791,10 @@ get_ack_timeout (struct FragmentMessage * fm){
792 return FRAGMENT_TIMEOUT; 791 return FRAGMENT_TIMEOUT;
793} 792}
794 793
795//TODO doxigen 794
796/** 795/**
797 * Function to set the timer for the next timeout of the fragment queue 796 * Function to set the timer for the next timeout of the fragment queue
797 * @param plugin the handle to the plugin struct
798 */ 798 */
799static void 799static void
800check_next_fragment_timeout(struct Plugin * const plugin) 800check_next_fragment_timeout(struct Plugin * const plugin)
@@ -879,9 +879,11 @@ get_next_queue_Session (struct Plugin * plugin){
879 return NULL; 879 return NULL;
880} 880}
881 881
882//TODO doxigen 882
883/** 883/**
884 * Function to sort the message into the message fragment queue 884 * Function to sort the message into the message fragment queue
885 * @prarm plugin the plugin struct
886 * @param message to sort into the queue
885 */ 887 */
886static void 888static void
887sort_fragment_into_queue (struct Plugin * plugin, struct FragmentMessage * fm){ 889sort_fragment_into_queue (struct Plugin * plugin, struct FragmentMessage * fm){
@@ -902,7 +904,11 @@ sort_fragment_into_queue (struct Plugin * plugin, struct FragmentMessage * fm){
902 plugin->pending_Fragment_Messages_tail,fm2,fm); 904 plugin->pending_Fragment_Messages_tail,fm2,fm);
903} 905}
904 906
905//TODO doxigen 907/**
908 * frees the space of a message in the fragment queue (send queue)
909 * @param plugin the plugin struct
910 * @param fm message to free
911 */
906static void 912static void
907free_fragment_message(struct Plugin * plugin,struct FragmentMessage * fm) 913free_fragment_message(struct Plugin * plugin,struct FragmentMessage * fm)
908{ 914{
@@ -918,9 +924,10 @@ free_fragment_message(struct Plugin * plugin,struct FragmentMessage * fm)
918 } 924 }
919} 925}
920 926
921//TODO doxigen
922/** 927/**
923 * Function to check if there is some space in the fragment queue 928 * Function to check if there is some space in the fragment queue
929 * inserts a message if space is available
930 * @param plugin the plugin struct
924 */ 931 */
925 932
926static void 933static void
@@ -963,7 +970,12 @@ check_fragment_queue (struct Plugin * plugin){
963 } 970 }
964} 971}
965 972
966//TODO doxigen 973/**
974 * Funktion to check if all fragments where send and the acks received
975 * frees the space if finished
976 * @param plugin the plugin struct
977 * @param fm the message to check
978 */
967static void 979static void
968check_finished_fragment(struct Plugin * plugin, struct FragmentMessage * fm){ 980check_finished_fragment(struct Plugin * plugin, struct FragmentMessage * fm){
969 struct AckQueue * ack; 981 struct AckQueue * ack;
@@ -1532,8 +1544,12 @@ wlan_plugin_address_to_string (void *cls,
1532 1544
1533/** 1545/**
1534 * Function to test if fragment number already exists in the fragments received 1546 * Function to test if fragment number already exists in the fragments received
1547 *
1548 * @param session session the fragment belongs to
1549 * @param fh Fragmentheader of the fragment
1550 * @return GNUNET_YES if fragment exists already, GNUNET_NO if it does not exists in the queue of the session
1535 */ 1551 */
1536//TODO doxigen 1552
1537static const int 1553static const int
1538is_double_msg(struct Session * session, struct FragmentationHeader * fh) 1554is_double_msg(struct Session * session, struct FragmentationHeader * fh)
1539{ 1555{
@@ -1550,6 +1566,11 @@ is_double_msg(struct Session * session, struct FragmentationHeader * fh)
1550 return GNUNET_NO; 1566 return GNUNET_NO;
1551} 1567}
1552 1568
1569/**
1570 * Function to insert a fragment in a queue of a session
1571 * @param session session the fragment belongs to
1572 * @param rec_queue fragment to add
1573 */
1553 1574
1554static void 1575static void
1555insert_fragment_in_queue(struct Session * session, struct RecQueue * rec_queue) 1576insert_fragment_in_queue(struct Session * session, struct RecQueue * rec_queue)
@@ -1585,8 +1606,9 @@ insert_fragment_in_queue(struct Session * session, struct RecQueue * rec_queue)
1585 1606
1586/** 1607/**
1587 * Function to dispose the fragments received for a message 1608 * Function to dispose the fragments received for a message
1609 * @param session session to free the fragments from
1588 */ 1610 */
1589//TODO doxigen 1611
1590static void 1612static void
1591free_rec_frag_queue(struct Session * session) 1613free_rec_frag_queue(struct Session * session)
1592{ 1614{
@@ -1605,8 +1627,11 @@ free_rec_frag_queue(struct Session * session)
1605 1627
1606/** 1628/**
1607 * Function to check if all fragments of a message have been received 1629 * Function to check if all fragments of a message have been received
1630 * @param plugin the plugin handle
1631 * @param session_light information of the message sender
1632 * @param session session the message belongs to
1608 */ 1633 */
1609//TODO doxigen 1634
1610static void 1635static void
1611check_rec_finished_msg (struct Plugin* plugin, struct Session_light * session_light, struct Session * session){ 1636check_rec_finished_msg (struct Plugin* plugin, struct Session_light * session_light, struct Session * session){
1612 struct RecQueue * rec_queue = session->frag_head; 1637 struct RecQueue * rec_queue = session->frag_head;
@@ -1631,7 +1656,13 @@ check_rec_finished_msg (struct Plugin* plugin, struct Session_light * session_li
1631 } 1656 }
1632 //sum should always be smaller or equal of 1657 //sum should always be smaller or equal of
1633 GNUNET_assert(sum <= packetsize); 1658 GNUNET_assert(sum <= packetsize);
1634 if (sum == packetsize){ 1659 if(sum == packetsize){
1660
1661#if DEBUG_wlan
1662 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1663 "check_rec_finished_msg: A message with fragments is complete\n");
1664#endif
1665
1635 //copy fragments together 1666 //copy fragments together
1636 msg = GNUNET_malloc(packetsize); 1667 msg = GNUNET_malloc(packetsize);
1637 rec_queue = session->frag_head; 1668 rec_queue = session->frag_head;
@@ -1649,6 +1680,13 @@ check_rec_finished_msg (struct Plugin* plugin, struct Session_light * session_li
1649 } 1680 }
1650} 1681}
1651 1682
1683/**
1684 * Function used for to process the data received from the wlan interface
1685 *
1686 * @param cls the plugin handle
1687 * @param client client which send the data (not used)
1688 * @param hdr hdr of the GNUNET_MessageHeader
1689 */
1652static void 1690static void
1653wlan_data_helper(void *cls, void * client, const struct GNUNET_MessageHeader * hdr) 1691wlan_data_helper(void *cls, void * client, const struct GNUNET_MessageHeader * hdr)
1654{ 1692{
@@ -1669,202 +1707,246 @@ wlan_data_helper(void *cls, void * client, const struct GNUNET_MessageHeader * h
1669 const struct GNUNET_MessageHeader * temp_hdr = NULL; 1707 const struct GNUNET_MessageHeader * temp_hdr = NULL;
1670 1708
1671 if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT) 1709 if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT)
1672 { 1710 {
1673 //TODO better DOS protection, error handling 1711
1674 GNUNET_assert(client != NULL); 1712#if DEBUG_wlan
1675 session_light = (struct Session_light *) client; 1713 GNUNET_log(
1676 if (session_light->session == NULL){ 1714 GNUNET_ERROR_TYPE_DEBUG,
1715 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT size: %i\n",
1716 ntohs(hdr->size));
1717#endif
1718
1719 //TODO better DOS protection, error handling
1720 GNUNET_assert(client != NULL);
1721 session_light = (struct Session_light *) client;
1722 if (session_light->session == NULL)
1723 {
1677 session_light->session = get_Session(plugin, session_light->addr); 1724 session_light->session = get_Session(plugin, session_light->addr);
1678 } 1725 }
1679 GNUNET_assert(GNUNET_HELLO_get_id( 1726 GNUNET_assert(GNUNET_HELLO_get_id(
1680 (const struct GNUNET_HELLO_Message *) &hdr[1], 1727 (const struct GNUNET_HELLO_Message *) &hdr[1],
1681 &(session_light->session->target) ) != GNUNET_SYSERR); 1728 &(session_light->session->target) ) != GNUNET_SYSERR);
1682 1729
1683 } 1730 }
1684 1731
1685 1732
1686 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA) 1733 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA)
1687 { 1734 {
1688 GNUNET_assert(client != NULL); 1735
1689 session_light = (struct Session_light *) client; 1736#if DEBUG_wlan
1690 if (session_light->session == NULL){ 1737 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1738 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_DATA size: %i\n",
1739 ntohs(hdr->size));
1740#endif
1741
1742 GNUNET_assert(client != NULL);
1743 session_light = (struct Session_light *) client;
1744 if (session_light->session == NULL)
1745 {
1691 session_light->session = search_session(plugin, session_light->addr); 1746 session_light->session = search_session(plugin, session_light->addr);
1692 } 1747 }
1693 session = session_light->session; 1748 session = session_light->session;
1694 wlanheader =(struct WlanHeader *) &hdr[1]; 1749 wlanheader = (struct WlanHeader *) &hdr[1];
1695 tempmsg = (char*) &wlanheader[1]; 1750 tempmsg = (char*) &wlanheader[1];
1696 temp_hdr = ( const struct GNUNET_MessageHeader *) &wlanheader[1]; 1751 temp_hdr = (const struct GNUNET_MessageHeader *) &wlanheader[1];
1697 1752
1698 if (getcrc32(tempmsg, wlanheader->header.size) != wlanheader->crc){ 1753 if (getcrc32(tempmsg, wlanheader->header.size) != wlanheader->crc)
1754 {
1699 //wrong crc, dispose message 1755 //wrong crc, dispose message
1700 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1756 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "WLAN message crc was wrong\n");
1701 "WLAN message crc was wrong\n");
1702 return; 1757 return;
1703 } 1758 }
1704 1759
1705 //if not in session list 1760 //if not in session list
1706 if (session == NULL){ 1761 if (session == NULL)
1762 {
1707 1763
1708 //try if it is a hello message 1764 //try if it is a hello message
1709 if (ntohs(temp_hdr->type) == GNUNET_MESSAGE_TYPE_HELLO){ 1765 if (ntohs(temp_hdr->type) == GNUNET_MESSAGE_TYPE_HELLO)
1710 session = create_session(plugin, session_light->addr); 1766 {
1711 session_light->session = session; 1767 session = create_session(plugin, session_light->addr);
1712 GNUNET_assert(GNUNET_HELLO_get_id( 1768 session_light->session = session;
1713 (const struct GNUNET_HELLO_Message *) temp_hdr, 1769 GNUNET_assert(GNUNET_HELLO_get_id(
1714 &session->target ) != GNUNET_SYSERR); 1770 (const struct GNUNET_HELLO_Message *) temp_hdr,
1715 1771 &session->target ) != GNUNET_SYSERR);
1716 } else { 1772
1717 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1773 }
1718 "WLAN client not in session list and not a hello message\n"); 1774 else
1719 return; 1775 {
1720 } 1776 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1777 "WLAN client not in session list and not a hello message\n");
1778 return;
1779 }
1721 } 1780 }
1722 //"receive" the message 1781 //"receive" the message
1723 struct GNUNET_TRANSPORT_ATS_Information distance[2]; 1782 struct GNUNET_TRANSPORT_ATS_Information distance[2];
1724 distance[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE); 1783 distance[0].type = htonl(GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
1725 distance[0].value = htonl (1); 1784 distance[0].value = htonl(1);
1726 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 1785 distance[1].type = htonl(GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
1727 distance[1].value = htonl (0); 1786 distance[1].value = htonl(0);
1728 plugin->env->receive(plugin, &session->target, 1787 plugin->env->receive(plugin, &session->target, temp_hdr,
1729 temp_hdr, (const struct GNUNET_TRANSPORT_ATS_Information *) &distance, 2, 1788 (const struct GNUNET_TRANSPORT_ATS_Information *) &distance, 2,
1730 session, session->addr, sizeof(session->addr)); 1789 session, session->addr, sizeof(session->addr));
1731 } 1790 }
1732 1791
1733 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT) 1792 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT)
1734 { 1793 {
1735 GNUNET_assert(client != NULL); 1794
1736 session_light = (struct Session_light *) client; 1795#if DEBUG_wlan
1737 if (session_light->session == NULL) 1796 GNUNET_log(
1738 { 1797 GNUNET_ERROR_TYPE_DEBUG,
1739 session_light->session = search_session(plugin, session_light->addr); 1798 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT size: %i\n",
1740 } 1799 ntohs(hdr->size));
1741 session = session_light->session; 1800#endif
1742 1801
1743 fh = (struct FragmentationHeader *) hdr; 1802 GNUNET_assert(client != NULL);
1744 tempmsg = (char*) &fh[1]; 1803 session_light = (struct Session_light *) client;
1745 1804 if (session_light->session == NULL)
1746 //if not in session list 1805 {
1747 if (session != NULL) 1806 session_light->session = search_session(plugin, session_light->addr);
1748 { 1807 }
1749 if (getcrc16(tempmsg, fh->header.size) != fh->message_crc) 1808 session = session_light->session;
1750 { 1809
1751 //wrong crc, dispose message 1810 fh = (struct FragmentationHeader *) hdr;
1752 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1811 tempmsg = (char*) &fh[1];
1753 "WLAN fragment crc was wrong\n"); 1812
1754 return; 1813 //if not in session list
1755 } 1814 if (session != NULL)
1756 else 1815 {
1757 { 1816 if (getcrc16(tempmsg, fh->header.size) != fh->message_crc)
1758 //todo fragments do not timeout 1817 {
1759 //check if message_id is rigth or it is a new msg 1818 //wrong crc, dispose message
1760 if ((session->message_id_in == ntohs(fh->message_id)) 1819 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1761 || (session->rec_size == NO_MESSAGE_OR_MESSAGE_FINISHED)) 1820 "WLAN fragment crc was wrong\n");
1762 { 1821 return;
1822 }
1823 else
1824 {
1825 //todo fragments do not timeout
1826 //check if message_id is rigth or it is a new msg
1827 if ((session->message_id_in == ntohs(fh->message_id))
1828 || (session->rec_size == NO_MESSAGE_OR_MESSAGE_FINISHED))
1829 {
1763 session->message_id_in = ntohs(fh->message_id); 1830 session->message_id_in = ntohs(fh->message_id);
1764 if (is_double_msg(session, fh) != GNUNET_YES) 1831 if (is_double_msg(session, fh) != GNUNET_YES)
1765 { 1832 {
1766 rec_queue = GNUNET_malloc(sizeof (struct RecQueue) + 1833 rec_queue
1767 ntohs(fh->header.size) - sizeof(struct FragmentationHeader)); 1834 = GNUNET_malloc(sizeof (struct RecQueue) +
1768 rec_queue->size = ntohs(fh->header.size 1835 ntohs(fh->header.size) - sizeof(struct FragmentationHeader));
1769 - sizeof(struct FragmentationHeader)); 1836 rec_queue->size = ntohs(fh->header.size
1770 rec_queue->num = ntohs(fh->fragment_off_or_num); 1837 - sizeof(struct FragmentationHeader));
1771 rec_queue->msg = (char*) &rec_queue[1]; 1838 rec_queue->num = ntohs(fh->fragment_off_or_num);
1772 //copy msg to buffer 1839 rec_queue->msg = (char*) &rec_queue[1];
1773 memcpy((char*) rec_queue->msg, tempmsg, rec_queue->size); 1840 //copy msg to buffer
1774 insert_fragment_in_queue(session, rec_queue); 1841 memcpy((char*) rec_queue->msg, tempmsg, rec_queue->size);
1775 check_rec_finished_msg(plugin, session_light, session); 1842 insert_fragment_in_queue(session, rec_queue);
1776 } 1843 check_rec_finished_msg(plugin, session_light, session);
1777 else 1844 }
1778 { 1845 else
1779 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1846 {
1780 "WLAN fragment is a clone\n"); 1847 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1781 return; 1848 "WLAN fragment is a clone\n");
1782 } 1849 return;
1783 } 1850 }
1784 else 1851 }
1785 { 1852 else
1786 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1853 {
1787 "WLAN fragment message_id and session message_id are not the same and a message is already (partly) received\n"); 1854 GNUNET_log(
1788 return; 1855 GNUNET_ERROR_TYPE_INFO,
1789 } 1856 "WLAN fragment message_id and session message_id are not the same and a message is already (partly) received\n");
1790 } 1857 return;
1791 } 1858 }
1792 else 1859 }
1793 { 1860 }
1794 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1861 else
1795 "WLAN client not in session list and it is a fragment message\n"); 1862 {
1796 return; 1863 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1797 } 1864 "WLAN client not in session list and it is a fragment message\n");
1798 1865 return;
1799 } 1866 }
1800 1867
1801 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK) 1868 }
1802 { 1869
1803 GNUNET_assert(client != NULL); 1870 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK)
1804 session_light = (struct Session_light *) client; 1871 {
1805 if (session_light->session == NULL) 1872
1806 { 1873#if DEBUG_wlan
1807 session_light->session = search_session(plugin, session_light->addr); 1874 GNUNET_log(
1808 GNUNET_assert(session_light->session != NULL); 1875 GNUNET_ERROR_TYPE_DEBUG,
1809 } 1876 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK size: %i\n",
1810 session = session_light->session; 1877 ntohs(hdr->size));
1811 fh = (struct FragmentationHeader *) &hdr[1]; 1878#endif
1812 if (fh->message_id == session->message_id_out) 1879
1813 { 1880 GNUNET_assert(client != NULL);
1814 fm = get_fragment_message_from_session(session); 1881 session_light = (struct Session_light *) client;
1815 if (fm != NULL) 1882 if (session_light->session == NULL)
1816 { 1883 {
1817 1884 session_light->session = search_session(plugin, session_light->addr);
1818 ack2 = fm->head; 1885 GNUNET_assert(session_light->session != NULL);
1819 while (ack2!=NULL){ 1886 }
1887 session = session_light->session;
1888 fh = (struct FragmentationHeader *) &hdr[1];
1889 if (fh->message_id == session->message_id_out)
1890 {
1891 fm = get_fragment_message_from_session(session);
1892 if (fm != NULL)
1893 {
1894
1895 ack2 = fm->head;
1896 while (ack2 != NULL)
1897 {
1820 // check for double 1898 // check for double
1821 if (ack2->fragment_num != fh->fragment_off_or_num) 1899 if (ack2->fragment_num != fh->fragment_off_or_num)
1822 { 1900 {
1823 // check if next ack has bigger number 1901 // check if next ack has bigger number
1824 if (ack2->fragment_num > fh->fragment_off_or_num) 1902 if (ack2->fragment_num > fh->fragment_off_or_num)
1825 { 1903 {
1826 ack = GNUNET_malloc(sizeof(struct AckQueue)); 1904 ack = GNUNET_malloc(sizeof(struct AckQueue));
1827 ack->fragment_num = fh->fragment_off_or_num; 1905 ack->fragment_num = fh->fragment_off_or_num;
1828 GNUNET_CONTAINER_DLL_insert_before(fm->head,fm->tail,ack2,ack); 1906 GNUNET_CONTAINER_DLL_insert_before(fm->head,fm->tail,ack2,ack);
1829 //check if finished 1907 //check if finished
1830 check_finished_fragment(plugin, fm); 1908 check_finished_fragment(plugin, fm);
1831 return; 1909 return;
1832 } 1910 }
1833 } 1911 }
1834 else 1912 else
1835 { 1913 {
1836 //double ack 1914 //double ack
1837 return; 1915 return;
1838 } 1916 }
1839 ack2 = ack2->next; 1917 ack2 = ack2->next;
1840 } 1918 }
1841 //GNUNET_CONTAINER_DLL_insert_tail(fm->head,fm->tail,ack); 1919 //GNUNET_CONTAINER_DLL_insert_tail(fm->head,fm->tail,ack);
1842 //should never happen but... 1920 //should never happen but...
1843 //check_finished_fragment(plugin, fm); 1921 //check_finished_fragment(plugin, fm);
1844 } 1922 }
1845 else 1923 else
1846 { 1924 {
1847 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1925 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1848 "WLAN fragment not in fragment list but id is right\n"); 1926 "WLAN fragment not in fragment list but id is right\n");
1849 return; 1927 return;
1850 } 1928 }
1851 1929
1852 }
1853
1854 }
1855 else
1856 {
1857 // TODO Wrong data?
1858 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "WLAN packet has not the right type\n");
1859 return;
1860 } 1930 }
1861 1931
1932 }
1933 else
1934 {
1935 // TODO Wrong data?
1936 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1937 "WLAN packet inside the WLAN helper packet has not the right type\n");
1938 return;
1939 }
1940
1862} 1941}
1863 1942
1864/** 1943/**
1865 * Function used for to process the data from the suid process 1944 * Function used for to process the data from the suid process
1945 *
1946 * @param cls the plugin handle
1947 * @param client which send the data (not used)
1948 * @param hdr of the GNUNET_MessageHeader
1866 */ 1949 */
1867//TODO doxigen
1868 1950
1869static void 1951static void
1870wlan_process_helper (void *cls, 1952wlan_process_helper (void *cls,
@@ -1881,6 +1963,13 @@ wlan_process_helper (void *cls,
1881 1963
1882 if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA) 1964 if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA)
1883 { 1965 {
1966#if DEBUG_wlan
1967 GNUNET_log(
1968 GNUNET_ERROR_TYPE_DEBUG,
1969 "Func wlan_process_helper got GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA size: %i\n",
1970 ntohs(hdr->size));
1971#endif
1972
1884 //call wlan_process_helper with the message inside, later with wlan: analyze signal 1973 //call wlan_process_helper with the message inside, later with wlan: analyze signal
1885 GNUNET_assert(ntohs(hdr->size) >= sizeof(struct IeeeHeader)); 1974 GNUNET_assert(ntohs(hdr->size) >= sizeof(struct IeeeHeader));
1886 wlanIeeeHeader = (struct IeeeHeader *) &hdr[1]; 1975 wlanIeeeHeader = (struct IeeeHeader *) &hdr[1];
@@ -1918,6 +2007,15 @@ wlan_process_helper (void *cls,
1918 2007
1919 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL) 2008 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL)
1920 { 2009 {
2010
2011
2012#if DEBUG_wlan
2013 GNUNET_log(
2014 GNUNET_ERROR_TYPE_DEBUG,
2015 "Func wlan_process_helper got GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL size: %i\n",
2016 ntohs(hdr->size));
2017#endif
2018
1921 //TODO more control 2019 //TODO more control
1922 //TODO use struct wlan_helper_control 2020 //TODO use struct wlan_helper_control
1923 if (ntohs(hdr->size) == sizeof(struct Wlan_Helper_Control_Message)) 2021 if (ntohs(hdr->size) == sizeof(struct Wlan_Helper_Control_Message))
@@ -1927,7 +2025,7 @@ wlan_process_helper (void *cls,
1927 GNUNET_log( 2025 GNUNET_log(
1928 GNUNET_ERROR_TYPE_DEBUG, 2026 GNUNET_ERROR_TYPE_DEBUG,
1929 "Notifying transport of address %s\n", 2027 "Notifying transport of address %s\n",
1930 wlan_plugin_address_to_string(cls, &(plugin->mac_address), hdr->size)); 2028 wlan_plugin_address_to_string(cls, &(plugin->mac_address), ntohs(hdr->size) - sizeof(struct GNUNET_MessageHeader)));
1931 plugin->env->notify_address(plugin->env->cls, "wlan", 2029 plugin->env->notify_address(plugin->env->cls, "wlan",
1932 &plugin->mac_address, sizeof(struct MacAddress), 2030 &plugin->mac_address, sizeof(struct MacAddress),
1933 GNUNET_TIME_UNIT_FOREVER_REL); 2031 GNUNET_TIME_UNIT_FOREVER_REL);
@@ -1949,6 +2047,14 @@ wlan_process_helper (void *cls,
1949 } 2047 }
1950} 2048}
1951 2049
2050/**
2051 * We have been notified that wlan-helper has written something to stdout.
2052 * Handle the output, then reschedule this function to be called again once
2053 * more is available.
2054 *
2055 * @param cls the plugin handle
2056 * @param tc the scheduling context
2057 */
1952 2058
1953static void 2059static void
1954wlan_plugin_helper_read (void *cls, 2060wlan_plugin_helper_read (void *cls,
@@ -1957,12 +2063,17 @@ wlan_plugin_helper_read (void *cls,
1957 struct Plugin *plugin = cls; 2063 struct Plugin *plugin = cls;
1958 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK; 2064 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
1959 2065
1960 char mybuf[WLAN_MTU + sizeof(struct GNUNET_MessageHeader)]; 2066#if DEBUG_wlan
1961 ssize_t bytes; 2067 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2068 "Start reading from STDIN\n");
2069#endif
1962 2070
1963 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) 2071 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
1964 return; 2072 return;
1965 2073
2074 char mybuf[WLAN_MTU + sizeof(struct GNUNET_MessageHeader)];
2075 ssize_t bytes;
2076
1966 bytes = GNUNET_DISK_file_read (plugin->server_stdout_handle, 2077 bytes = GNUNET_DISK_file_read (plugin->server_stdout_handle,
1967 mybuf, sizeof(mybuf)); 2078 mybuf, sizeof(mybuf));
1968 if (bytes <= 0) 2079 if (bytes <= 0)
@@ -2008,10 +2119,9 @@ wlan_transport_start_wlan_helper(struct Plugin *plugin, int testmode)
2008#endif 2119#endif
2009 /* Start the server process */ 2120 /* Start the server process */
2010 2121
2011 //if (testmode == 0){
2012 2122
2013 plugin->server_proc = GNUNET_OS_start_process(plugin->server_stdin, 2123 plugin->server_proc = GNUNET_OS_start_process(plugin->server_stdin,
2014 plugin->server_stdout, filename,filename, plugin->interface, ((testmode==1)?"1":"0"), NULL); 2124 plugin->server_stdout, filename,filename, plugin->interface, ((testmode==1)?"1":(testmode==2)?"2":"0"), NULL);
2015 if (plugin->server_proc == NULL) 2125 if (plugin->server_proc == NULL)
2016 { 2126 {
2017#if DEBUG_wlan 2127#if DEBUG_wlan
@@ -2020,13 +2130,7 @@ wlan_transport_start_wlan_helper(struct Plugin *plugin, int testmode)
2020#endif 2130#endif
2021 return GNUNET_SYSERR; 2131 return GNUNET_SYSERR;
2022 } 2132 }
2023 //} else if (testmode == 1){
2024 2133
2025
2026 //} else if (testmode == 2){
2027
2028
2029 //}
2030 /* Close the write end of the read pipe */ 2134 /* Close the write end of the read pipe */
2031 GNUNET_DISK_pipe_close_end(plugin->server_stdout, GNUNET_DISK_PIPE_END_WRITE); 2135 GNUNET_DISK_pipe_close_end(plugin->server_stdout, GNUNET_DISK_PIPE_END_WRITE);
2032 2136
@@ -2039,9 +2143,16 @@ wlan_transport_start_wlan_helper(struct Plugin *plugin, int testmode)
2039 GNUNET_DISK_PIPE_END_WRITE); 2143 GNUNET_DISK_PIPE_END_WRITE);
2040 2144
2041 GNUNET_assert(plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK); 2145 GNUNET_assert(plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK);
2146
2147#if DEBUG_wlan
2148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2149 "Adding server_read_task for the wlan-helper\n");
2150#endif
2151
2042 plugin->server_read_task = GNUNET_SCHEDULER_add_read_file( 2152 plugin->server_read_task = GNUNET_SCHEDULER_add_read_file(
2043 GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdout_handle, 2153 GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdout_handle,
2044 &wlan_plugin_helper_read, plugin); 2154 &wlan_plugin_helper_read, plugin);
2155
2045 return GNUNET_YES; 2156 return GNUNET_YES;
2046} 2157}
2047 2158
@@ -2057,6 +2168,11 @@ libgnunet_plugin_transport_wlan_done (void *cls)
2057 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 2168 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
2058 struct Plugin *plugin = api->cls; 2169 struct Plugin *plugin = api->cls;
2059 2170
2171#if DEBUG_wlan
2172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2173 "libgnunet_plugin_transport_wlan_done started\n");
2174#endif
2175
2060 GNUNET_assert(cls !=NULL); 2176 GNUNET_assert(cls !=NULL);
2061 2177
2062 if (plugin->consoltoken != NULL) 2178 if (plugin->consoltoken != NULL)
@@ -2081,7 +2197,7 @@ libgnunet_plugin_transport_wlan_init (void *cls)
2081 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; 2197 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
2082 struct GNUNET_TRANSPORT_PluginFunctions *api; 2198 struct GNUNET_TRANSPORT_PluginFunctions *api;
2083 struct Plugin *plugin; 2199 struct Plugin *plugin;
2084 int testmode; 2200 static unsigned long long testmode =0;
2085 2201
2086 GNUNET_assert(cls !=NULL); 2202 GNUNET_assert(cls !=NULL);
2087 2203
@@ -2093,15 +2209,15 @@ libgnunet_plugin_transport_wlan_init (void *cls)
2093 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK; 2209 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
2094 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK; 2210 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
2095 2211
2096 testmode = GNUNET_NO;
2097 if (GNUNET_CONFIGURATION_have_value (env->cfg,
2098 "transport-wlan", "TESTMODE"))
2099 {
2100 testmode = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
2101 "transport-wlan","TESTMODE");
2102 }
2103 2212
2104 if (GNUNET_CONFIGURATION_have_value (env->cfg, 2213 if (GNUNET_CONFIGURATION_have_value(env->cfg, "transport-wlan", "TESTMODE"))
2214 {
2215 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(env->cfg, "transport-wlan",
2216 "TESTMODE", &testmode))
2217 return NULL;
2218 }
2219
2220 if (GNUNET_CONFIGURATION_have_value(env->cfg,
2105 "transport-wlan", "INTERFACE")) 2221 "transport-wlan", "INTERFACE"))
2106 { 2222 {
2107 if (GNUNET_CONFIGURATION_get_value_string (env->cfg, 2223 if (GNUNET_CONFIGURATION_get_value_string (env->cfg,
@@ -2128,6 +2244,11 @@ libgnunet_plugin_transport_wlan_init (void *cls)
2128 2244
2129 start_next_message_id(); 2245 start_next_message_id();
2130 2246
2247#if DEBUG_wlan
2248 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2249 "wlan init finished\n");
2250#endif
2251
2131 return api; 2252 return api;
2132} 2253}
2133 2254