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 "netCfg.h"
tax 0:66300c77c6e9 25 #if NET_ETH
tax 0:66300c77c6e9 26
tax 0:66300c77c6e9 27 #include "mbed.h"
tax 0:66300c77c6e9 28
tax 0:66300c77c6e9 29 Ethernet *pEth = NULL;
tax 0:66300c77c6e9 30 #ifdef __cplusplus
tax 0:66300c77c6e9 31 extern "C" {
tax 0:66300c77c6e9 32 #endif
tax 0:66300c77c6e9 33
tax 0:66300c77c6e9 34 #include "lwip/opt.h"
tax 0:66300c77c6e9 35
tax 0:66300c77c6e9 36 #include "lwip/def.h"
tax 0:66300c77c6e9 37 #include "lwip/pbuf.h"
tax 0:66300c77c6e9 38 #include "lwip/sys.h"
tax 0:66300c77c6e9 39 #include "lwip/stats.h"
tax 0:66300c77c6e9 40 #include "netif/etharp.h"
tax 0:66300c77c6e9 41 #include "string.h"
tax 0:66300c77c6e9 42
tax 0:66300c77c6e9 43 //#include "eth_drv.h"
tax 0:66300c77c6e9 44
tax 0:66300c77c6e9 45 #define IFNAME0 'E'
tax 0:66300c77c6e9 46 #define IFNAME1 'X'
tax 0:66300c77c6e9 47
tax 0:66300c77c6e9 48 #define min(x,y) (((x)<(y))?(x):(y))
tax 0:66300c77c6e9 49
tax 0:66300c77c6e9 50 struct netif* eth_netif;
tax 0:66300c77c6e9 51
tax 0:66300c77c6e9 52 static err_t eth_output(struct netif *netif, struct pbuf *p) {
tax 0:66300c77c6e9 53 #if ETH_PAD_SIZE
tax 0:66300c77c6e9 54 pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
tax 0:66300c77c6e9 55 #endif
tax 0:66300c77c6e9 56
tax 0:66300c77c6e9 57 do {
tax 0:66300c77c6e9 58 pEth->write((const char *)p->payload, p->len);
tax 0:66300c77c6e9 59 } while((p = p->next)!=NULL);
tax 0:66300c77c6e9 60
tax 0:66300c77c6e9 61 pEth->send();
tax 0:66300c77c6e9 62
tax 0:66300c77c6e9 63 #if ETH_PAD_SIZE
tax 0:66300c77c6e9 64 pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
tax 0:66300c77c6e9 65 #endif
tax 0:66300c77c6e9 66
tax 0:66300c77c6e9 67 LINK_STATS_INC(link.xmit);
tax 0:66300c77c6e9 68 return ERR_OK;
tax 0:66300c77c6e9 69 }
tax 0:66300c77c6e9 70
tax 0:66300c77c6e9 71 /*
tax 0:66300c77c6e9 72 void show(char *buf, int size) {
tax 0:66300c77c6e9 73 printf("Destination: %02hx:%02hx:%02hx:%02hx:%02hx:%02hx\n",
tax 0:66300c77c6e9 74 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
tax 0:66300c77c6e9 75 printf("Source: %02hx:%02hx:%02hx:%02hx:%02hx:%02hx\n",
tax 0:66300c77c6e9 76 buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]);
tax 0:66300c77c6e9 77
tax 0:66300c77c6e9 78 printf("Type %hd\n", htons((short)buf[12]));
tax 0:66300c77c6e9 79
tax 0:66300c77c6e9 80 // hexview(buf, size);
tax 0:66300c77c6e9 81 }
tax 0:66300c77c6e9 82 */
tax 0:66300c77c6e9 83
tax 0:66300c77c6e9 84 void eth_poll() {
tax 0:66300c77c6e9 85 struct eth_hdr *ethhdr;
tax 0:66300c77c6e9 86 struct pbuf *frame, *p;
tax 0:66300c77c6e9 87 int len, read;
tax 0:66300c77c6e9 88
tax 0:66300c77c6e9 89 while((len = pEth->receive()) != 0) {
tax 0:66300c77c6e9 90 frame = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
tax 0:66300c77c6e9 91 if(frame == NULL) {
tax 0:66300c77c6e9 92 return;
tax 0:66300c77c6e9 93 }
tax 0:66300c77c6e9 94 p = frame;
tax 0:66300c77c6e9 95 /* no packet could be read, silently ignore this */
tax 0:66300c77c6e9 96 if (p == NULL) return;
tax 0:66300c77c6e9 97 do {
tax 0:66300c77c6e9 98 read = pEth->read((char *)p->payload, p->len);
tax 0:66300c77c6e9 99 p = p->next;
tax 0:66300c77c6e9 100 } while(p != NULL && read != 0);
tax 0:66300c77c6e9 101
tax 0:66300c77c6e9 102 #if ETH_PAD_SIZE
tax 0:66300c77c6e9 103 pbuf_header(p, ETH_PAD_SIZE);
tax 0:66300c77c6e9 104 #endif
tax 0:66300c77c6e9 105
tax 0:66300c77c6e9 106 ethhdr = (struct eth_hdr *)(frame->payload);
tax 0:66300c77c6e9 107
tax 0:66300c77c6e9 108 // show((char*)ethhdr, 13);
tax 0:66300c77c6e9 109
tax 0:66300c77c6e9 110 /*
tax 0:66300c77c6e9 111 switch(htons(ethhdr->type)) {
tax 0:66300c77c6e9 112
tax 0:66300c77c6e9 113 case ETHTYPE_IP:
tax 0:66300c77c6e9 114 etharp_ip_input(gnetif, frame);
tax 0:66300c77c6e9 115 pbuf_header(frame, -((s16_t) sizeof(struct eth_hdr)));
tax 0:66300c77c6e9 116 gnetif->input(frame, gnetif);
tax 0:66300c77c6e9 117 break;
tax 0:66300c77c6e9 118
tax 0:66300c77c6e9 119 case ETHTYPE_ARP:
tax 0:66300c77c6e9 120 etharp_arp_input(gnetif, (struct eth_addr *)(gnetif->hwaddr), frame);
tax 0:66300c77c6e9 121 break;
tax 0:66300c77c6e9 122
tax 0:66300c77c6e9 123 default:
tax 0:66300c77c6e9 124 break;
tax 0:66300c77c6e9 125 }*/
tax 0:66300c77c6e9 126
tax 0:66300c77c6e9 127
tax 0:66300c77c6e9 128
tax 0:66300c77c6e9 129 //ethernet_input(frame, gnetif);
tax 0:66300c77c6e9 130
tax 0:66300c77c6e9 131 switch (htons(ethhdr->type)) {
tax 0:66300c77c6e9 132 /* IP or ARP packet? */
tax 0:66300c77c6e9 133 case ETHTYPE_IP:
tax 0:66300c77c6e9 134 case ETHTYPE_ARP:
tax 0:66300c77c6e9 135 #if PPPOE_SUPPORT
tax 0:66300c77c6e9 136 /* PPPoE packet? */
tax 0:66300c77c6e9 137 case ETHTYPE_PPPOEDISC:
tax 0:66300c77c6e9 138 case ETHTYPE_PPPOE:
tax 0:66300c77c6e9 139 #endif /* PPPOE_SUPPORT */
tax 0:66300c77c6e9 140 /* full packet send to tcpip_thread to process */
tax 0:66300c77c6e9 141 //if (netif->input(p, gnetif)!=ERR_OK)
tax 0:66300c77c6e9 142 if (ethernet_input(frame, eth_netif)!=ERR_OK)
tax 0:66300c77c6e9 143 { LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
tax 0:66300c77c6e9 144 pbuf_free(frame);
tax 0:66300c77c6e9 145 frame = NULL;
tax 0:66300c77c6e9 146 }
tax 0:66300c77c6e9 147 break;
tax 0:66300c77c6e9 148
tax 0:66300c77c6e9 149 default:
tax 0:66300c77c6e9 150 pbuf_free(frame);
tax 0:66300c77c6e9 151 frame = NULL;
tax 0:66300c77c6e9 152 break;
tax 0:66300c77c6e9 153 }
tax 0:66300c77c6e9 154
tax 0:66300c77c6e9 155 /* pbuf_free(frame); */
tax 0:66300c77c6e9 156 }
tax 0:66300c77c6e9 157
tax 0:66300c77c6e9 158
tax 0:66300c77c6e9 159
tax 0:66300c77c6e9 160
tax 0:66300c77c6e9 161 }
tax 0:66300c77c6e9 162
tax 0:66300c77c6e9 163 err_t eth_init(struct netif *netif) {
tax 0:66300c77c6e9 164 LWIP_ASSERT("netif != NULL", (netif != NULL));
tax 0:66300c77c6e9 165
tax 0:66300c77c6e9 166 NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, 0x2EA);
tax 0:66300c77c6e9 167
tax 0:66300c77c6e9 168 /* maximum transfer unit */
tax 0:66300c77c6e9 169 netif->mtu = 0x2EA;
tax 0:66300c77c6e9 170
tax 0:66300c77c6e9 171 /* device capabilities */
tax 0:66300c77c6e9 172 /* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
tax 0:66300c77c6e9 173 netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP | NETIF_FLAG_IGMP;
tax 0:66300c77c6e9 174
tax 0:66300c77c6e9 175 netif->state = NULL;
tax 0:66300c77c6e9 176 eth_netif = netif;
tax 0:66300c77c6e9 177
tax 0:66300c77c6e9 178 netif->name[0] = IFNAME0;
tax 0:66300c77c6e9 179 netif->name[1] = IFNAME1;
tax 0:66300c77c6e9 180
tax 0:66300c77c6e9 181 /* We directly use etharp_output() here to save a function call.
tax 0:66300c77c6e9 182 * You can instead declare your own function an call etharp_output()
tax 0:66300c77c6e9 183 * from it if you have to do some checks before sending (e.g. if link
tax 0:66300c77c6e9 184 * is available...) */
tax 0:66300c77c6e9 185 netif->output = etharp_output;
tax 0:66300c77c6e9 186 netif->linkoutput = eth_output;
tax 0:66300c77c6e9 187
tax 0:66300c77c6e9 188 pEth = new Ethernet();
tax 0:66300c77c6e9 189
tax 0:66300c77c6e9 190 return ERR_OK;
tax 0:66300c77c6e9 191 }
tax 0:66300c77c6e9 192
tax 0:66300c77c6e9 193 void eth_free()
tax 0:66300c77c6e9 194 {
tax 0:66300c77c6e9 195 if(pEth)
tax 0:66300c77c6e9 196 delete pEth;
tax 0:66300c77c6e9 197 pEth = NULL;
tax 0:66300c77c6e9 198 }
tax 0:66300c77c6e9 199
tax 0:66300c77c6e9 200 void eth_address(char* mac) {
tax 0:66300c77c6e9 201 pEth->address(mac);
tax 0:66300c77c6e9 202 }
tax 0:66300c77c6e9 203
tax 0:66300c77c6e9 204 #ifdef __cplusplus
tax 0:66300c77c6e9 205 };
tax 0:66300c77c6e9 206 #endif
tax 0:66300c77c6e9 207
tax 0:66300c77c6e9 208 #endif