I have a problem getting this to work. Server only recieves half of the data being sent. Whats wrong

Dependencies:   mbed

Committer:
tax
Date:
Tue Mar 29 13:20:15 2011 +0000
Revision:
0:66300c77c6e9

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tax 0:66300c77c6e9 1
tax 0:66300c77c6e9 2 /*
tax 0:66300c77c6e9 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
tax 0:66300c77c6e9 4
tax 0:66300c77c6e9 5 Permission is hereby granted, free of charge, to any person obtaining a copy
tax 0:66300c77c6e9 6 of this software and associated documentation files (the "Software"), to deal
tax 0:66300c77c6e9 7 in the Software without restriction, including without limitation the rights
tax 0:66300c77c6e9 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
tax 0:66300c77c6e9 9 copies of the Software, and to permit persons to whom the Software is
tax 0:66300c77c6e9 10 furnished to do so, subject to the following conditions:
tax 0:66300c77c6e9 11
tax 0:66300c77c6e9 12 The above copyright notice and this permission notice shall be included in
tax 0:66300c77c6e9 13 all copies or substantial portions of the Software.
tax 0:66300c77c6e9 14
tax 0:66300c77c6e9 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
tax 0:66300c77c6e9 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
tax 0:66300c77c6e9 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
tax 0:66300c77c6e9 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
tax 0:66300c77c6e9 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
tax 0:66300c77c6e9 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
tax 0:66300c77c6e9 21 THE SOFTWARE.
tax 0:66300c77c6e9 22 */
tax 0:66300c77c6e9 23
tax 0:66300c77c6e9 24 #include "EthernetNetIf.h"
tax 0:66300c77c6e9 25
tax 0:66300c77c6e9 26 #include "netif/etharp.h"
tax 0:66300c77c6e9 27 #include "lwip/dhcp.h"
tax 0:66300c77c6e9 28 #include "lwip/dns.h"
tax 0:66300c77c6e9 29 #include "lwip/igmp.h"
tax 0:66300c77c6e9 30
tax 0:66300c77c6e9 31 #include "drv/eth/eth_drv.h"
tax 0:66300c77c6e9 32 #include "mbed.h"
tax 0:66300c77c6e9 33
tax 0:66300c77c6e9 34 #define __DEBUG
tax 0:66300c77c6e9 35 #include "dbg/dbg.h"
tax 0:66300c77c6e9 36
tax 0:66300c77c6e9 37 #include "netCfg.h"
tax 0:66300c77c6e9 38 #if NET_ETH
tax 0:66300c77c6e9 39
tax 0:66300c77c6e9 40 EthernetNetIf::EthernetNetIf() : LwipNetIf(), m_ethArpTimer(), m_dhcpCoarseTimer(), m_dhcpFineTimer(), m_igmpTimer(), m_pNetIf(NULL),
tax 0:66300c77c6e9 41 m_netmask(255,255,255,255), m_gateway(), m_hostname(NULL)
tax 0:66300c77c6e9 42 {
tax 0:66300c77c6e9 43 m_hostname = NULL;
tax 0:66300c77c6e9 44 m_pNetIf = new netif;
tax 0:66300c77c6e9 45 m_useDhcp = true;
tax 0:66300c77c6e9 46 }
tax 0:66300c77c6e9 47
tax 0:66300c77c6e9 48 EthernetNetIf::EthernetNetIf(IpAddr ip, IpAddr netmask, IpAddr gateway, IpAddr dns) : LwipNetIf(), m_ethArpTimer(), m_dhcpCoarseTimer(), m_dhcpFineTimer(), m_igmpTimer(), m_pNetIf(NULL), m_hostname(NULL) //W/o DHCP
tax 0:66300c77c6e9 49 {
tax 0:66300c77c6e9 50 m_hostname = NULL;
tax 0:66300c77c6e9 51 m_netmask = netmask;
tax 0:66300c77c6e9 52 m_gateway = gateway;
tax 0:66300c77c6e9 53 m_ip = ip;
tax 0:66300c77c6e9 54 m_pNetIf = new netif;
tax 0:66300c77c6e9 55 dns_setserver(0, &dns.getStruct());
tax 0:66300c77c6e9 56 m_useDhcp = false;
tax 0:66300c77c6e9 57 }
tax 0:66300c77c6e9 58
tax 0:66300c77c6e9 59 EthernetNetIf::~EthernetNetIf()
tax 0:66300c77c6e9 60 {
tax 0:66300c77c6e9 61 if(m_pNetIf)
tax 0:66300c77c6e9 62 {
tax 0:66300c77c6e9 63 igmp_stop(m_pNetIf); //Stop IGMP processing
tax 0:66300c77c6e9 64 netif_set_down(m_pNetIf);
tax 0:66300c77c6e9 65 netif_remove(m_pNetIf);
tax 0:66300c77c6e9 66 delete m_pNetIf;
tax 0:66300c77c6e9 67 eth_free();
tax 0:66300c77c6e9 68 }
tax 0:66300c77c6e9 69 }
tax 0:66300c77c6e9 70
tax 0:66300c77c6e9 71 EthernetErr EthernetNetIf::setup(int timeout_ms /*= 15000*/)
tax 0:66300c77c6e9 72 {
tax 0:66300c77c6e9 73 LwipNetIf::init();
tax 0:66300c77c6e9 74 //m_ethArpTicker.attach_us(&etharp_tmr, ARP_TMR_INTERVAL * 1000); // = 5s in etharp.h
tax 0:66300c77c6e9 75 m_ethArpTimer.start();
tax 0:66300c77c6e9 76 if(m_useDhcp)
tax 0:66300c77c6e9 77 {
tax 0:66300c77c6e9 78 //m_dhcpCoarseTicker.attach(&dhcp_coarse_tmr, DHCP_COARSE_TIMER_SECS); // = 60s in dhcp.h
tax 0:66300c77c6e9 79 //m_dhcpFineTicker.attach_us(&dhcp_fine_tmr, DHCP_FINE_TIMER_MSECS * 1000); // = 500ms in dhcp.h
tax 0:66300c77c6e9 80 m_dhcpCoarseTimer.start();
tax 0:66300c77c6e9 81 m_dhcpFineTimer.start();
tax 0:66300c77c6e9 82 }
tax 0:66300c77c6e9 83 m_pNetIf->hwaddr_len = ETHARP_HWADDR_LEN; //6
tax 0:66300c77c6e9 84 eth_address((char *)m_pNetIf->hwaddr);
tax 0:66300c77c6e9 85
tax 0:66300c77c6e9 86 DBG("HW Addr is : %02x:%02x:%02x:%02x:%02x:%02x.\n",
tax 0:66300c77c6e9 87 m_pNetIf->hwaddr[0], m_pNetIf->hwaddr[1], m_pNetIf->hwaddr[2],
tax 0:66300c77c6e9 88 m_pNetIf->hwaddr[3], m_pNetIf->hwaddr[4], m_pNetIf->hwaddr[5]);
tax 0:66300c77c6e9 89
tax 0:66300c77c6e9 90 m_pNetIf = netif_add(m_pNetIf, &(m_ip.getStruct()), &(m_netmask.getStruct()), &(m_gateway.getStruct()), NULL, eth_init, ip_input);//ethernet_input);// ip_input);
tax 0:66300c77c6e9 91 //m_pNetIf->hostname = "mbedDG";//(char *)m_hostname; //Not used for now
tax 0:66300c77c6e9 92 netif_set_default(m_pNetIf);
tax 0:66300c77c6e9 93
tax 0:66300c77c6e9 94 //DBG("\r\nStarting DHCP.\r\n");
tax 0:66300c77c6e9 95
tax 0:66300c77c6e9 96 if(m_useDhcp)
tax 0:66300c77c6e9 97 {
tax 0:66300c77c6e9 98 dhcp_start(m_pNetIf);
tax 0:66300c77c6e9 99 DBG("DHCP Started, waiting for IP...\n");
tax 0:66300c77c6e9 100 }
tax 0:66300c77c6e9 101 else
tax 0:66300c77c6e9 102 {
tax 0:66300c77c6e9 103 netif_set_up(m_pNetIf);
tax 0:66300c77c6e9 104 }
tax 0:66300c77c6e9 105
tax 0:66300c77c6e9 106 Timer timeout;
tax 0:66300c77c6e9 107 timeout.start();
tax 0:66300c77c6e9 108 while( !netif_is_up(m_pNetIf) ) //Wait until device is up
tax 0:66300c77c6e9 109 {
tax 0:66300c77c6e9 110 if(m_useDhcp)
tax 0:66300c77c6e9 111 {
tax 0:66300c77c6e9 112 if(m_dhcpFineTimer.read_ms()>=DHCP_FINE_TIMER_MSECS)
tax 0:66300c77c6e9 113 {
tax 0:66300c77c6e9 114 m_dhcpFineTimer.reset();
tax 0:66300c77c6e9 115 dhcp_fine_tmr();
tax 0:66300c77c6e9 116 }
tax 0:66300c77c6e9 117 if(m_dhcpCoarseTimer.read()>=DHCP_COARSE_TIMER_SECS)
tax 0:66300c77c6e9 118 {
tax 0:66300c77c6e9 119 m_dhcpCoarseTimer.reset();
tax 0:66300c77c6e9 120 dhcp_coarse_tmr();
tax 0:66300c77c6e9 121 }
tax 0:66300c77c6e9 122 }
tax 0:66300c77c6e9 123 poll();
tax 0:66300c77c6e9 124 if( timeout.read_ms() > timeout_ms )
tax 0:66300c77c6e9 125 {
tax 0:66300c77c6e9 126 //Abort
tax 0:66300c77c6e9 127 if(m_useDhcp)
tax 0:66300c77c6e9 128 dhcp_stop(m_pNetIf);
tax 0:66300c77c6e9 129 else
tax 0:66300c77c6e9 130 netif_set_down(m_pNetIf);
tax 0:66300c77c6e9 131 DBG("\r\nTimeout.\r\n");
tax 0:66300c77c6e9 132 return ETH_TIMEOUT;
tax 0:66300c77c6e9 133 }
tax 0:66300c77c6e9 134 }
tax 0:66300c77c6e9 135
tax 0:66300c77c6e9 136 #if LWIP_IGMP
tax 0:66300c77c6e9 137 igmp_start(m_pNetIf); //Start IGMP processing
tax 0:66300c77c6e9 138 #endif
tax 0:66300c77c6e9 139
tax 0:66300c77c6e9 140 m_ip = IpAddr(&(m_pNetIf->ip_addr));
tax 0:66300c77c6e9 141
tax 0:66300c77c6e9 142 DBG("Connected, IP : %d.%d.%d.%d\n", m_ip[0], m_ip[1], m_ip[2], m_ip[3]);
tax 0:66300c77c6e9 143
tax 0:66300c77c6e9 144 return ETH_OK;
tax 0:66300c77c6e9 145 }
tax 0:66300c77c6e9 146
tax 0:66300c77c6e9 147 void EthernetNetIf::poll()
tax 0:66300c77c6e9 148 {
tax 0:66300c77c6e9 149 if(m_ethArpTimer.read_ms()>=ARP_TMR_INTERVAL)
tax 0:66300c77c6e9 150 {
tax 0:66300c77c6e9 151 m_ethArpTimer.reset();
tax 0:66300c77c6e9 152 etharp_tmr();
tax 0:66300c77c6e9 153 }
tax 0:66300c77c6e9 154 #if LWIP_IGMP
tax 0:66300c77c6e9 155 if(m_igmpTimer.read_ms()>=IGMP_TMR_INTERVAL)
tax 0:66300c77c6e9 156 {
tax 0:66300c77c6e9 157 m_igmpTimer.reset();
tax 0:66300c77c6e9 158 igmp_tmr();
tax 0:66300c77c6e9 159 }
tax 0:66300c77c6e9 160 #endif
tax 0:66300c77c6e9 161 LwipNetIf::poll();
tax 0:66300c77c6e9 162 eth_poll();
tax 0:66300c77c6e9 163 }
tax 0:66300c77c6e9 164
tax 0:66300c77c6e9 165 #endif