Modified version of NetServices. Fixes an issue where connections failed should the HTTP response status line be received in a packet on its own prior to any further headers. Changes are made to the HTTPClient.cpp file's readHeaders method.

Committer:
andrewbonney
Date:
Fri Apr 08 14:39:41 2011 +0000
Revision:
0:ec559500a63f

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewbonney 0:ec559500a63f 1
andrewbonney 0:ec559500a63f 2 /*
andrewbonney 0:ec559500a63f 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
andrewbonney 0:ec559500a63f 4
andrewbonney 0:ec559500a63f 5 Permission is hereby granted, free of charge, to any person obtaining a copy
andrewbonney 0:ec559500a63f 6 of this software and associated documentation files (the "Software"), to deal
andrewbonney 0:ec559500a63f 7 in the Software without restriction, including without limitation the rights
andrewbonney 0:ec559500a63f 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
andrewbonney 0:ec559500a63f 9 copies of the Software, and to permit persons to whom the Software is
andrewbonney 0:ec559500a63f 10 furnished to do so, subject to the following conditions:
andrewbonney 0:ec559500a63f 11
andrewbonney 0:ec559500a63f 12 The above copyright notice and this permission notice shall be included in
andrewbonney 0:ec559500a63f 13 all copies or substantial portions of the Software.
andrewbonney 0:ec559500a63f 14
andrewbonney 0:ec559500a63f 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
andrewbonney 0:ec559500a63f 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
andrewbonney 0:ec559500a63f 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
andrewbonney 0:ec559500a63f 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
andrewbonney 0:ec559500a63f 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
andrewbonney 0:ec559500a63f 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
andrewbonney 0:ec559500a63f 21 THE SOFTWARE.
andrewbonney 0:ec559500a63f 22 */
andrewbonney 0:ec559500a63f 23
andrewbonney 0:ec559500a63f 24 #include "netCfg.h"
andrewbonney 0:ec559500a63f 25 #if NET_ETH
andrewbonney 0:ec559500a63f 26
andrewbonney 0:ec559500a63f 27 #include "mbed.h"
andrewbonney 0:ec559500a63f 28
andrewbonney 0:ec559500a63f 29 Ethernet *pEth = NULL;
andrewbonney 0:ec559500a63f 30 #ifdef __cplusplus
andrewbonney 0:ec559500a63f 31 extern "C" {
andrewbonney 0:ec559500a63f 32 #endif
andrewbonney 0:ec559500a63f 33
andrewbonney 0:ec559500a63f 34 #include "lwip/opt.h"
andrewbonney 0:ec559500a63f 35
andrewbonney 0:ec559500a63f 36 #include "lwip/def.h"
andrewbonney 0:ec559500a63f 37 #include "lwip/pbuf.h"
andrewbonney 0:ec559500a63f 38 #include "lwip/sys.h"
andrewbonney 0:ec559500a63f 39 #include "lwip/stats.h"
andrewbonney 0:ec559500a63f 40 #include "netif/etharp.h"
andrewbonney 0:ec559500a63f 41 #include "string.h"
andrewbonney 0:ec559500a63f 42
andrewbonney 0:ec559500a63f 43 //#include "eth_drv.h"
andrewbonney 0:ec559500a63f 44
andrewbonney 0:ec559500a63f 45 #define IFNAME0 'E'
andrewbonney 0:ec559500a63f 46 #define IFNAME1 'X'
andrewbonney 0:ec559500a63f 47
andrewbonney 0:ec559500a63f 48 #define min(x,y) (((x)<(y))?(x):(y))
andrewbonney 0:ec559500a63f 49
andrewbonney 0:ec559500a63f 50 struct netif* eth_netif;
andrewbonney 0:ec559500a63f 51
andrewbonney 0:ec559500a63f 52 static err_t eth_output(struct netif *netif, struct pbuf *p) {
andrewbonney 0:ec559500a63f 53 #if ETH_PAD_SIZE
andrewbonney 0:ec559500a63f 54 pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
andrewbonney 0:ec559500a63f 55 #endif
andrewbonney 0:ec559500a63f 56
andrewbonney 0:ec559500a63f 57 do {
andrewbonney 0:ec559500a63f 58 pEth->write((const char *)p->payload, p->len);
andrewbonney 0:ec559500a63f 59 } while((p = p->next)!=NULL);
andrewbonney 0:ec559500a63f 60
andrewbonney 0:ec559500a63f 61 pEth->send();
andrewbonney 0:ec559500a63f 62
andrewbonney 0:ec559500a63f 63 #if ETH_PAD_SIZE
andrewbonney 0:ec559500a63f 64 pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
andrewbonney 0:ec559500a63f 65 #endif
andrewbonney 0:ec559500a63f 66
andrewbonney 0:ec559500a63f 67 LINK_STATS_INC(link.xmit);
andrewbonney 0:ec559500a63f 68 return ERR_OK;
andrewbonney 0:ec559500a63f 69 }
andrewbonney 0:ec559500a63f 70
andrewbonney 0:ec559500a63f 71 /*
andrewbonney 0:ec559500a63f 72 void show(char *buf, int size) {
andrewbonney 0:ec559500a63f 73 printf("Destination: %02hx:%02hx:%02hx:%02hx:%02hx:%02hx\n",
andrewbonney 0:ec559500a63f 74 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
andrewbonney 0:ec559500a63f 75 printf("Source: %02hx:%02hx:%02hx:%02hx:%02hx:%02hx\n",
andrewbonney 0:ec559500a63f 76 buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]);
andrewbonney 0:ec559500a63f 77
andrewbonney 0:ec559500a63f 78 printf("Type %hd\n", htons((short)buf[12]));
andrewbonney 0:ec559500a63f 79
andrewbonney 0:ec559500a63f 80 // hexview(buf, size);
andrewbonney 0:ec559500a63f 81 }
andrewbonney 0:ec559500a63f 82 */
andrewbonney 0:ec559500a63f 83
andrewbonney 0:ec559500a63f 84 void eth_poll() {
andrewbonney 0:ec559500a63f 85 struct eth_hdr *ethhdr;
andrewbonney 0:ec559500a63f 86 struct pbuf *frame, *p;
andrewbonney 0:ec559500a63f 87 int len, read;
andrewbonney 0:ec559500a63f 88
andrewbonney 0:ec559500a63f 89 while((len = pEth->receive()) != 0) {
andrewbonney 0:ec559500a63f 90 frame = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
andrewbonney 0:ec559500a63f 91 if(frame == NULL) {
andrewbonney 0:ec559500a63f 92 return;
andrewbonney 0:ec559500a63f 93 }
andrewbonney 0:ec559500a63f 94 p = frame;
andrewbonney 0:ec559500a63f 95 /* no packet could be read, silently ignore this */
andrewbonney 0:ec559500a63f 96 if (p == NULL) return;
andrewbonney 0:ec559500a63f 97 do {
andrewbonney 0:ec559500a63f 98 read = pEth->read((char *)p->payload, p->len);
andrewbonney 0:ec559500a63f 99 p = p->next;
andrewbonney 0:ec559500a63f 100 } while(p != NULL && read != 0);
andrewbonney 0:ec559500a63f 101
andrewbonney 0:ec559500a63f 102 #if ETH_PAD_SIZE
andrewbonney 0:ec559500a63f 103 pbuf_header(p, ETH_PAD_SIZE);
andrewbonney 0:ec559500a63f 104 #endif
andrewbonney 0:ec559500a63f 105
andrewbonney 0:ec559500a63f 106 ethhdr = (struct eth_hdr *)(frame->payload);
andrewbonney 0:ec559500a63f 107
andrewbonney 0:ec559500a63f 108 // show((char*)ethhdr, 13);
andrewbonney 0:ec559500a63f 109
andrewbonney 0:ec559500a63f 110 /*
andrewbonney 0:ec559500a63f 111 switch(htons(ethhdr->type)) {
andrewbonney 0:ec559500a63f 112
andrewbonney 0:ec559500a63f 113 case ETHTYPE_IP:
andrewbonney 0:ec559500a63f 114 etharp_ip_input(gnetif, frame);
andrewbonney 0:ec559500a63f 115 pbuf_header(frame, -((s16_t) sizeof(struct eth_hdr)));
andrewbonney 0:ec559500a63f 116 gnetif->input(frame, gnetif);
andrewbonney 0:ec559500a63f 117 break;
andrewbonney 0:ec559500a63f 118
andrewbonney 0:ec559500a63f 119 case ETHTYPE_ARP:
andrewbonney 0:ec559500a63f 120 etharp_arp_input(gnetif, (struct eth_addr *)(gnetif->hwaddr), frame);
andrewbonney 0:ec559500a63f 121 break;
andrewbonney 0:ec559500a63f 122
andrewbonney 0:ec559500a63f 123 default:
andrewbonney 0:ec559500a63f 124 break;
andrewbonney 0:ec559500a63f 125 }*/
andrewbonney 0:ec559500a63f 126
andrewbonney 0:ec559500a63f 127
andrewbonney 0:ec559500a63f 128
andrewbonney 0:ec559500a63f 129 //ethernet_input(frame, gnetif);
andrewbonney 0:ec559500a63f 130
andrewbonney 0:ec559500a63f 131 switch (htons(ethhdr->type)) {
andrewbonney 0:ec559500a63f 132 /* IP or ARP packet? */
andrewbonney 0:ec559500a63f 133 case ETHTYPE_IP:
andrewbonney 0:ec559500a63f 134 case ETHTYPE_ARP:
andrewbonney 0:ec559500a63f 135 #if PPPOE_SUPPORT
andrewbonney 0:ec559500a63f 136 /* PPPoE packet? */
andrewbonney 0:ec559500a63f 137 case ETHTYPE_PPPOEDISC:
andrewbonney 0:ec559500a63f 138 case ETHTYPE_PPPOE:
andrewbonney 0:ec559500a63f 139 #endif /* PPPOE_SUPPORT */
andrewbonney 0:ec559500a63f 140 /* full packet send to tcpip_thread to process */
andrewbonney 0:ec559500a63f 141 //if (netif->input(p, gnetif)!=ERR_OK)
andrewbonney 0:ec559500a63f 142 if (ethernet_input(frame, eth_netif)!=ERR_OK)
andrewbonney 0:ec559500a63f 143 { LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
andrewbonney 0:ec559500a63f 144 pbuf_free(frame);
andrewbonney 0:ec559500a63f 145 frame = NULL;
andrewbonney 0:ec559500a63f 146 }
andrewbonney 0:ec559500a63f 147 break;
andrewbonney 0:ec559500a63f 148
andrewbonney 0:ec559500a63f 149 default:
andrewbonney 0:ec559500a63f 150 pbuf_free(frame);
andrewbonney 0:ec559500a63f 151 frame = NULL;
andrewbonney 0:ec559500a63f 152 break;
andrewbonney 0:ec559500a63f 153 }
andrewbonney 0:ec559500a63f 154
andrewbonney 0:ec559500a63f 155 /* pbuf_free(frame); */
andrewbonney 0:ec559500a63f 156 }
andrewbonney 0:ec559500a63f 157
andrewbonney 0:ec559500a63f 158
andrewbonney 0:ec559500a63f 159
andrewbonney 0:ec559500a63f 160
andrewbonney 0:ec559500a63f 161 }
andrewbonney 0:ec559500a63f 162
andrewbonney 0:ec559500a63f 163 err_t eth_init(struct netif *netif) {
andrewbonney 0:ec559500a63f 164 LWIP_ASSERT("netif != NULL", (netif != NULL));
andrewbonney 0:ec559500a63f 165
andrewbonney 0:ec559500a63f 166 NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, 0x2EA);
andrewbonney 0:ec559500a63f 167
andrewbonney 0:ec559500a63f 168 /* maximum transfer unit */
andrewbonney 0:ec559500a63f 169 netif->mtu = 0x2EA;
andrewbonney 0:ec559500a63f 170
andrewbonney 0:ec559500a63f 171 /* device capabilities */
andrewbonney 0:ec559500a63f 172 /* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
andrewbonney 0:ec559500a63f 173 netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP | NETIF_FLAG_IGMP;
andrewbonney 0:ec559500a63f 174
andrewbonney 0:ec559500a63f 175 netif->state = NULL;
andrewbonney 0:ec559500a63f 176 eth_netif = netif;
andrewbonney 0:ec559500a63f 177
andrewbonney 0:ec559500a63f 178 netif->name[0] = IFNAME0;
andrewbonney 0:ec559500a63f 179 netif->name[1] = IFNAME1;
andrewbonney 0:ec559500a63f 180
andrewbonney 0:ec559500a63f 181 /* We directly use etharp_output() here to save a function call.
andrewbonney 0:ec559500a63f 182 * You can instead declare your own function an call etharp_output()
andrewbonney 0:ec559500a63f 183 * from it if you have to do some checks before sending (e.g. if link
andrewbonney 0:ec559500a63f 184 * is available...) */
andrewbonney 0:ec559500a63f 185 netif->output = etharp_output;
andrewbonney 0:ec559500a63f 186 netif->linkoutput = eth_output;
andrewbonney 0:ec559500a63f 187
andrewbonney 0:ec559500a63f 188 if (!pEth) pEth = new Ethernet(); // only create Ethernet object if required
andrewbonney 0:ec559500a63f 189
andrewbonney 0:ec559500a63f 190 return ERR_OK;
andrewbonney 0:ec559500a63f 191 }
andrewbonney 0:ec559500a63f 192
andrewbonney 0:ec559500a63f 193 void eth_free()
andrewbonney 0:ec559500a63f 194 {
andrewbonney 0:ec559500a63f 195 if(pEth)
andrewbonney 0:ec559500a63f 196 delete pEth;
andrewbonney 0:ec559500a63f 197 pEth = NULL;
andrewbonney 0:ec559500a63f 198 }
andrewbonney 0:ec559500a63f 199
andrewbonney 0:ec559500a63f 200 void eth_address(char* mac) {
andrewbonney 0:ec559500a63f 201 pEth->address(mac);
andrewbonney 0:ec559500a63f 202 }
andrewbonney 0:ec559500a63f 203
andrewbonney 0:ec559500a63f 204 Ethernet* eth_interface() {
andrewbonney 0:ec559500a63f 205 return pEth;
andrewbonney 0:ec559500a63f 206 }
andrewbonney 0:ec559500a63f 207
andrewbonney 0:ec559500a63f 208 #ifdef __cplusplus
andrewbonney 0:ec559500a63f 209 };
andrewbonney 0:ec559500a63f 210 #endif
andrewbonney 0:ec559500a63f 211
andrewbonney 0:ec559500a63f 212 #endif