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 * @file
RodColeman 0:850eacf3e945 3 * Ethernet Interface Skeleton
RodColeman 0:850eacf3e945 4 *
RodColeman 0:850eacf3e945 5 */
RodColeman 0:850eacf3e945 6
RodColeman 0:850eacf3e945 7 /*
RodColeman 0:850eacf3e945 8 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
RodColeman 0:850eacf3e945 9 * All rights reserved.
RodColeman 0:850eacf3e945 10 *
RodColeman 0:850eacf3e945 11 * Redistribution and use in source and binary forms, with or without modification,
RodColeman 0:850eacf3e945 12 * are permitted provided that the following conditions are met:
RodColeman 0:850eacf3e945 13 *
RodColeman 0:850eacf3e945 14 * 1. Redistributions of source code must retain the above copyright notice,
RodColeman 0:850eacf3e945 15 * this list of conditions and the following disclaimer.
RodColeman 0:850eacf3e945 16 * 2. Redistributions in binary form must reproduce the above copyright notice,
RodColeman 0:850eacf3e945 17 * this list of conditions and the following disclaimer in the documentation
RodColeman 0:850eacf3e945 18 * and/or other materials provided with the distribution.
RodColeman 0:850eacf3e945 19 * 3. The name of the author may not be used to endorse or promote products
RodColeman 0:850eacf3e945 20 * derived from this software without specific prior written permission.
RodColeman 0:850eacf3e945 21 *
RodColeman 0:850eacf3e945 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
RodColeman 0:850eacf3e945 23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
RodColeman 0:850eacf3e945 24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
RodColeman 0:850eacf3e945 25 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
RodColeman 0:850eacf3e945 26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
RodColeman 0:850eacf3e945 27 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
RodColeman 0:850eacf3e945 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
RodColeman 0:850eacf3e945 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
RodColeman 0:850eacf3e945 30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
RodColeman 0:850eacf3e945 31 * OF SUCH DAMAGE.
RodColeman 0:850eacf3e945 32 *
RodColeman 0:850eacf3e945 33 * This file is part of the lwIP TCP/IP stack.
RodColeman 0:850eacf3e945 34 *
RodColeman 0:850eacf3e945 35 * Author: Adam Dunkels <adam@sics.se>
RodColeman 0:850eacf3e945 36 *
RodColeman 0:850eacf3e945 37 */
RodColeman 0:850eacf3e945 38
RodColeman 0:850eacf3e945 39 /*
RodColeman 0:850eacf3e945 40 * This file is a skeleton for developing Ethernet network interface
RodColeman 0:850eacf3e945 41 * drivers for lwIP. Add code to the low_level functions and do a
RodColeman 0:850eacf3e945 42 * search-and-replace for the word "ethernetif" to replace it with
RodColeman 0:850eacf3e945 43 * something that better describes your network interface.
RodColeman 0:850eacf3e945 44 */
RodColeman 0:850eacf3e945 45
RodColeman 0:850eacf3e945 46 #include "lwip/opt.h"
RodColeman 0:850eacf3e945 47
RodColeman 0:850eacf3e945 48 #if 0 /* don't build, this is only a skeleton, see previous comment */
RodColeman 0:850eacf3e945 49
RodColeman 0:850eacf3e945 50 #include "lwip/def.h"
RodColeman 0:850eacf3e945 51 #include "lwip/mem.h"
RodColeman 0:850eacf3e945 52 #include "lwip/pbuf.h"
RodColeman 0:850eacf3e945 53 #include "lwip/sys.h"
RodColeman 0:850eacf3e945 54 #include <lwip/stats.h>
RodColeman 0:850eacf3e945 55 #include <lwip/snmp.h>
RodColeman 0:850eacf3e945 56 #include "netif/etharp.h"
RodColeman 0:850eacf3e945 57 #include "netif/ppp_oe.h"
RodColeman 0:850eacf3e945 58
RodColeman 0:850eacf3e945 59 /* Define those to better describe your network interface. */
RodColeman 0:850eacf3e945 60 #define IFNAME0 'e'
RodColeman 0:850eacf3e945 61 #define IFNAME1 'n'
RodColeman 0:850eacf3e945 62
RodColeman 0:850eacf3e945 63 /**
RodColeman 0:850eacf3e945 64 * Helper struct to hold private data used to operate your ethernet interface.
RodColeman 0:850eacf3e945 65 * Keeping the ethernet address of the MAC in this struct is not necessary
RodColeman 0:850eacf3e945 66 * as it is already kept in the struct netif.
RodColeman 0:850eacf3e945 67 * But this is only an example, anyway...
RodColeman 0:850eacf3e945 68 */
RodColeman 0:850eacf3e945 69 struct ethernetif {
RodColeman 0:850eacf3e945 70 struct eth_addr *ethaddr;
RodColeman 0:850eacf3e945 71 /* Add whatever per-interface state that is needed here. */
RodColeman 0:850eacf3e945 72 };
RodColeman 0:850eacf3e945 73
RodColeman 0:850eacf3e945 74 /* Forward declarations. */
RodColeman 0:850eacf3e945 75 static void ethernetif_input(struct netif *netif);
RodColeman 0:850eacf3e945 76
RodColeman 0:850eacf3e945 77 /**
RodColeman 0:850eacf3e945 78 * In this function, the hardware should be initialized.
RodColeman 0:850eacf3e945 79 * Called from ethernetif_init().
RodColeman 0:850eacf3e945 80 *
RodColeman 0:850eacf3e945 81 * @param netif the already initialized lwip network interface structure
RodColeman 0:850eacf3e945 82 * for this ethernetif
RodColeman 0:850eacf3e945 83 */
RodColeman 0:850eacf3e945 84 static void
RodColeman 0:850eacf3e945 85 low_level_init(struct netif *netif)
RodColeman 0:850eacf3e945 86 {
RodColeman 0:850eacf3e945 87 struct ethernetif *ethernetif = netif->state;
RodColeman 0:850eacf3e945 88
RodColeman 0:850eacf3e945 89 /* set MAC hardware address length */
RodColeman 0:850eacf3e945 90 netif->hwaddr_len = ETHARP_HWADDR_LEN;
RodColeman 0:850eacf3e945 91
RodColeman 0:850eacf3e945 92 /* set MAC hardware address */
RodColeman 0:850eacf3e945 93 netif->hwaddr[0] = ;
RodColeman 0:850eacf3e945 94 ...
RodColeman 0:850eacf3e945 95 netif->hwaddr[5] = ;
RodColeman 0:850eacf3e945 96
RodColeman 0:850eacf3e945 97 /* maximum transfer unit */
RodColeman 0:850eacf3e945 98 netif->mtu = 1500;
RodColeman 0:850eacf3e945 99
RodColeman 0:850eacf3e945 100 /* device capabilities */
RodColeman 0:850eacf3e945 101 /* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
RodColeman 0:850eacf3e945 102 netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
RodColeman 0:850eacf3e945 103
RodColeman 0:850eacf3e945 104 /* Do whatever else is needed to initialize interface. */
RodColeman 0:850eacf3e945 105 }
RodColeman 0:850eacf3e945 106
RodColeman 0:850eacf3e945 107 /**
RodColeman 0:850eacf3e945 108 * This function should do the actual transmission of the packet. The packet is
RodColeman 0:850eacf3e945 109 * contained in the pbuf that is passed to the function. This pbuf
RodColeman 0:850eacf3e945 110 * might be chained.
RodColeman 0:850eacf3e945 111 *
RodColeman 0:850eacf3e945 112 * @param netif the lwip network interface structure for this ethernetif
RodColeman 0:850eacf3e945 113 * @param p the MAC packet to send (e.g. IP packet including MAC addresses and type)
RodColeman 0:850eacf3e945 114 * @return ERR_OK if the packet could be sent
RodColeman 0:850eacf3e945 115 * an err_t value if the packet couldn't be sent
RodColeman 0:850eacf3e945 116 *
RodColeman 0:850eacf3e945 117 * @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to
RodColeman 0:850eacf3e945 118 * strange results. You might consider waiting for space in the DMA queue
RodColeman 0:850eacf3e945 119 * to become availale since the stack doesn't retry to send a packet
RodColeman 0:850eacf3e945 120 * dropped because of memory failure (except for the TCP timers).
RodColeman 0:850eacf3e945 121 */
RodColeman 0:850eacf3e945 122
RodColeman 0:850eacf3e945 123 static err_t
RodColeman 0:850eacf3e945 124 low_level_output(struct netif *netif, struct pbuf *p)
RodColeman 0:850eacf3e945 125 {
RodColeman 0:850eacf3e945 126 struct ethernetif *ethernetif = netif->state;
RodColeman 0:850eacf3e945 127 struct pbuf *q;
RodColeman 0:850eacf3e945 128
RodColeman 0:850eacf3e945 129 initiate transfer();
RodColeman 0:850eacf3e945 130
RodColeman 0:850eacf3e945 131 #if ETH_PAD_SIZE
RodColeman 0:850eacf3e945 132 pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
RodColeman 0:850eacf3e945 133 #endif
RodColeman 0:850eacf3e945 134
RodColeman 0:850eacf3e945 135 for(q = p; q != NULL; q = q->next) {
RodColeman 0:850eacf3e945 136 /* Send the data from the pbuf to the interface, one pbuf at a
RodColeman 0:850eacf3e945 137 time. The size of the data in each pbuf is kept in the ->len
RodColeman 0:850eacf3e945 138 variable. */
RodColeman 0:850eacf3e945 139 send data from(q->payload, q->len);
RodColeman 0:850eacf3e945 140 }
RodColeman 0:850eacf3e945 141
RodColeman 0:850eacf3e945 142 signal that packet should be sent();
RodColeman 0:850eacf3e945 143
RodColeman 0:850eacf3e945 144 #if ETH_PAD_SIZE
RodColeman 0:850eacf3e945 145 pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
RodColeman 0:850eacf3e945 146 #endif
RodColeman 0:850eacf3e945 147
RodColeman 0:850eacf3e945 148 LINK_STATS_INC(link.xmit);
RodColeman 0:850eacf3e945 149
RodColeman 0:850eacf3e945 150 return ERR_OK;
RodColeman 0:850eacf3e945 151 }
RodColeman 0:850eacf3e945 152
RodColeman 0:850eacf3e945 153 /**
RodColeman 0:850eacf3e945 154 * Should allocate a pbuf and transfer the bytes of the incoming
RodColeman 0:850eacf3e945 155 * packet from the interface into the pbuf.
RodColeman 0:850eacf3e945 156 *
RodColeman 0:850eacf3e945 157 * @param netif the lwip network interface structure for this ethernetif
RodColeman 0:850eacf3e945 158 * @return a pbuf filled with the received packet (including MAC header)
RodColeman 0:850eacf3e945 159 * NULL on memory error
RodColeman 0:850eacf3e945 160 */
RodColeman 0:850eacf3e945 161 static struct pbuf *
RodColeman 0:850eacf3e945 162 low_level_input(struct netif *netif)
RodColeman 0:850eacf3e945 163 {
RodColeman 0:850eacf3e945 164 struct ethernetif *ethernetif = netif->state;
RodColeman 0:850eacf3e945 165 struct pbuf *p, *q;
RodColeman 0:850eacf3e945 166 u16_t len;
RodColeman 0:850eacf3e945 167
RodColeman 0:850eacf3e945 168 /* Obtain the size of the packet and put it into the "len"
RodColeman 0:850eacf3e945 169 variable. */
RodColeman 0:850eacf3e945 170 len = ;
RodColeman 0:850eacf3e945 171
RodColeman 0:850eacf3e945 172 #if ETH_PAD_SIZE
RodColeman 0:850eacf3e945 173 len += ETH_PAD_SIZE; /* allow room for Ethernet padding */
RodColeman 0:850eacf3e945 174 #endif
RodColeman 0:850eacf3e945 175
RodColeman 0:850eacf3e945 176 /* We allocate a pbuf chain of pbufs from the pool. */
RodColeman 0:850eacf3e945 177 p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
RodColeman 0:850eacf3e945 178
RodColeman 0:850eacf3e945 179 if (p != NULL) {
RodColeman 0:850eacf3e945 180
RodColeman 0:850eacf3e945 181 #if ETH_PAD_SIZE
RodColeman 0:850eacf3e945 182 pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
RodColeman 0:850eacf3e945 183 #endif
RodColeman 0:850eacf3e945 184
RodColeman 0:850eacf3e945 185 /* We iterate over the pbuf chain until we have read the entire
RodColeman 0:850eacf3e945 186 * packet into the pbuf. */
RodColeman 0:850eacf3e945 187 for(q = p; q != NULL; q = q->next) {
RodColeman 0:850eacf3e945 188 /* Read enough bytes to fill this pbuf in the chain. The
RodColeman 0:850eacf3e945 189 * available data in the pbuf is given by the q->len
RodColeman 0:850eacf3e945 190 * variable.
RodColeman 0:850eacf3e945 191 * This does not necessarily have to be a memcpy, you can also preallocate
RodColeman 0:850eacf3e945 192 * pbufs for a DMA-enabled MAC and after receiving truncate it to the
RodColeman 0:850eacf3e945 193 * actually received size. In this case, ensure the tot_len member of the
RodColeman 0:850eacf3e945 194 * pbuf is the sum of the chained pbuf len members.
RodColeman 0:850eacf3e945 195 */
RodColeman 0:850eacf3e945 196 read data into(q->payload, q->len);
RodColeman 0:850eacf3e945 197 }
RodColeman 0:850eacf3e945 198 acknowledge that packet has been read();
RodColeman 0:850eacf3e945 199
RodColeman 0:850eacf3e945 200 #if ETH_PAD_SIZE
RodColeman 0:850eacf3e945 201 pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
RodColeman 0:850eacf3e945 202 #endif
RodColeman 0:850eacf3e945 203
RodColeman 0:850eacf3e945 204 LINK_STATS_INC(link.recv);
RodColeman 0:850eacf3e945 205 } else {
RodColeman 0:850eacf3e945 206 drop packet();
RodColeman 0:850eacf3e945 207 LINK_STATS_INC(link.memerr);
RodColeman 0:850eacf3e945 208 LINK_STATS_INC(link.drop);
RodColeman 0:850eacf3e945 209 }
RodColeman 0:850eacf3e945 210
RodColeman 0:850eacf3e945 211 return p;
RodColeman 0:850eacf3e945 212 }
RodColeman 0:850eacf3e945 213
RodColeman 0:850eacf3e945 214 /**
RodColeman 0:850eacf3e945 215 * This function should be called when a packet is ready to be read
RodColeman 0:850eacf3e945 216 * from the interface. It uses the function low_level_input() that
RodColeman 0:850eacf3e945 217 * should handle the actual reception of bytes from the network
RodColeman 0:850eacf3e945 218 * interface. Then the type of the received packet is determined and
RodColeman 0:850eacf3e945 219 * the appropriate input function is called.
RodColeman 0:850eacf3e945 220 *
RodColeman 0:850eacf3e945 221 * @param netif the lwip network interface structure for this ethernetif
RodColeman 0:850eacf3e945 222 */
RodColeman 0:850eacf3e945 223 static void
RodColeman 0:850eacf3e945 224 ethernetif_input(struct netif *netif)
RodColeman 0:850eacf3e945 225 {
RodColeman 0:850eacf3e945 226 struct ethernetif *ethernetif;
RodColeman 0:850eacf3e945 227 struct eth_hdr *ethhdr;
RodColeman 0:850eacf3e945 228 struct pbuf *p;
RodColeman 0:850eacf3e945 229
RodColeman 0:850eacf3e945 230 ethernetif = netif->state;
RodColeman 0:850eacf3e945 231
RodColeman 0:850eacf3e945 232 /* move received packet into a new pbuf */
RodColeman 0:850eacf3e945 233 p = low_level_input(netif);
RodColeman 0:850eacf3e945 234 /* no packet could be read, silently ignore this */
RodColeman 0:850eacf3e945 235 if (p == NULL) return;
RodColeman 0:850eacf3e945 236 /* points to packet payload, which starts with an Ethernet header */
RodColeman 0:850eacf3e945 237 ethhdr = p->payload;
RodColeman 0:850eacf3e945 238
RodColeman 0:850eacf3e945 239 switch (htons(ethhdr->type)) {
RodColeman 0:850eacf3e945 240 /* IP or ARP packet? */
RodColeman 0:850eacf3e945 241 case ETHTYPE_IP:
RodColeman 0:850eacf3e945 242 case ETHTYPE_ARP:
RodColeman 0:850eacf3e945 243 #if PPPOE_SUPPORT
RodColeman 0:850eacf3e945 244 /* PPPoE packet? */
RodColeman 0:850eacf3e945 245 case ETHTYPE_PPPOEDISC:
RodColeman 0:850eacf3e945 246 case ETHTYPE_PPPOE:
RodColeman 0:850eacf3e945 247 #endif /* PPPOE_SUPPORT */
RodColeman 0:850eacf3e945 248 /* full packet send to tcpip_thread to process */
RodColeman 0:850eacf3e945 249 if (netif->input(p, netif)!=ERR_OK)
RodColeman 0:850eacf3e945 250 { LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
RodColeman 0:850eacf3e945 251 pbuf_free(p);
RodColeman 0:850eacf3e945 252 p = NULL;
RodColeman 0:850eacf3e945 253 }
RodColeman 0:850eacf3e945 254 break;
RodColeman 0:850eacf3e945 255
RodColeman 0:850eacf3e945 256 default:
RodColeman 0:850eacf3e945 257 pbuf_free(p);
RodColeman 0:850eacf3e945 258 p = NULL;
RodColeman 0:850eacf3e945 259 break;
RodColeman 0:850eacf3e945 260 }
RodColeman 0:850eacf3e945 261 }
RodColeman 0:850eacf3e945 262
RodColeman 0:850eacf3e945 263 /**
RodColeman 0:850eacf3e945 264 * Should be called at the beginning of the program to set up the
RodColeman 0:850eacf3e945 265 * network interface. It calls the function low_level_init() to do the
RodColeman 0:850eacf3e945 266 * actual setup of the hardware.
RodColeman 0:850eacf3e945 267 *
RodColeman 0:850eacf3e945 268 * This function should be passed as a parameter to netif_add().
RodColeman 0:850eacf3e945 269 *
RodColeman 0:850eacf3e945 270 * @param netif the lwip network interface structure for this ethernetif
RodColeman 0:850eacf3e945 271 * @return ERR_OK if the loopif is initialized
RodColeman 0:850eacf3e945 272 * ERR_MEM if private data couldn't be allocated
RodColeman 0:850eacf3e945 273 * any other err_t on error
RodColeman 0:850eacf3e945 274 */
RodColeman 0:850eacf3e945 275 err_t
RodColeman 0:850eacf3e945 276 ethernetif_init(struct netif *netif)
RodColeman 0:850eacf3e945 277 {
RodColeman 0:850eacf3e945 278 struct ethernetif *ethernetif;
RodColeman 0:850eacf3e945 279
RodColeman 0:850eacf3e945 280 LWIP_ASSERT("netif != NULL", (netif != NULL));
RodColeman 0:850eacf3e945 281
RodColeman 0:850eacf3e945 282 ethernetif = mem_malloc(sizeof(struct ethernetif));
RodColeman 0:850eacf3e945 283 if (ethernetif == NULL) {
RodColeman 0:850eacf3e945 284 LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_init: out of memory\n"));
RodColeman 0:850eacf3e945 285 return ERR_MEM;
RodColeman 0:850eacf3e945 286 }
RodColeman 0:850eacf3e945 287
RodColeman 0:850eacf3e945 288 #if LWIP_NETIF_HOSTNAME
RodColeman 0:850eacf3e945 289 /* Initialize interface hostname */
RodColeman 0:850eacf3e945 290 netif->hostname = "lwip";
RodColeman 0:850eacf3e945 291 #endif /* LWIP_NETIF_HOSTNAME */
RodColeman 0:850eacf3e945 292
RodColeman 0:850eacf3e945 293 /*
RodColeman 0:850eacf3e945 294 * Initialize the snmp variables and counters inside the struct netif.
RodColeman 0:850eacf3e945 295 * The last argument should be replaced with your link speed, in units
RodColeman 0:850eacf3e945 296 * of bits per second.
RodColeman 0:850eacf3e945 297 */
RodColeman 0:850eacf3e945 298 NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, LINK_SPEED_OF_YOUR_NETIF_IN_BPS);
RodColeman 0:850eacf3e945 299
RodColeman 0:850eacf3e945 300 netif->state = ethernetif;
RodColeman 0:850eacf3e945 301 netif->name[0] = IFNAME0;
RodColeman 0:850eacf3e945 302 netif->name[1] = IFNAME1;
RodColeman 0:850eacf3e945 303 /* We directly use etharp_output() here to save a function call.
RodColeman 0:850eacf3e945 304 * You can instead declare your own function an call etharp_output()
RodColeman 0:850eacf3e945 305 * from it if you have to do some checks before sending (e.g. if link
RodColeman 0:850eacf3e945 306 * is available...) */
RodColeman 0:850eacf3e945 307 netif->output = etharp_output;
RodColeman 0:850eacf3e945 308 netif->linkoutput = low_level_output;
RodColeman 0:850eacf3e945 309
RodColeman 0:850eacf3e945 310 ethernetif->ethaddr = (struct eth_addr *)&(netif->hwaddr[0]);
RodColeman 0:850eacf3e945 311
RodColeman 0:850eacf3e945 312 /* initialize the hardware */
RodColeman 0:850eacf3e945 313 low_level_init(netif);
RodColeman 0:850eacf3e945 314
RodColeman 0:850eacf3e945 315 return ERR_OK;
RodColeman 0:850eacf3e945 316 }
RodColeman 0:850eacf3e945 317
RodColeman 0:850eacf3e945 318 #endif /* 0 */