Netservices modded to read fragmented HTTP respsonse/payload from special purpose server - 180 bytes only

Committer:
RodColeman
Date:
Thu Sep 08 10:48:09 2011 +0000
Revision:
0:850eacf3e945
revised fixed length to 178 bytes

Who changed what in which revision?

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