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

Committer:
RodColeman
Date:
Thu Sep 08 10:41:36 2011 +0000
Revision:
0:8f5825f330b0
setDataLen hacked to 180bytes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RodColeman 0:8f5825f330b0 1 /**
RodColeman 0:8f5825f330b0 2 * @file
RodColeman 0:8f5825f330b0 3 * SLIP Interface
RodColeman 0:8f5825f330b0 4 *
RodColeman 0:8f5825f330b0 5 */
RodColeman 0:8f5825f330b0 6
RodColeman 0:8f5825f330b0 7 /*
RodColeman 0:8f5825f330b0 8 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
RodColeman 0:8f5825f330b0 9 * All rights reserved.
RodColeman 0:8f5825f330b0 10 *
RodColeman 0:8f5825f330b0 11 * Redistribution and use in source and binary forms, with or without
RodColeman 0:8f5825f330b0 12 * modification, are permitted provided that the following conditions
RodColeman 0:8f5825f330b0 13 * are met:
RodColeman 0:8f5825f330b0 14 * 1. Redistributions of source code must retain the above copyright
RodColeman 0:8f5825f330b0 15 * notice, this list of conditions and the following disclaimer.
RodColeman 0:8f5825f330b0 16 * 2. Redistributions in binary form must reproduce the above copyright
RodColeman 0:8f5825f330b0 17 * notice, this list of conditions and the following disclaimer in the
RodColeman 0:8f5825f330b0 18 * documentation and/or other materials provided with the distribution.
RodColeman 0:8f5825f330b0 19 * 3. Neither the name of the Institute nor the names of its contributors
RodColeman 0:8f5825f330b0 20 * may be used to endorse or promote products derived from this software
RodColeman 0:8f5825f330b0 21 * without specific prior written permission.
RodColeman 0:8f5825f330b0 22 *
RodColeman 0:8f5825f330b0 23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
RodColeman 0:8f5825f330b0 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
RodColeman 0:8f5825f330b0 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
RodColeman 0:8f5825f330b0 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
RodColeman 0:8f5825f330b0 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
RodColeman 0:8f5825f330b0 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
RodColeman 0:8f5825f330b0 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
RodColeman 0:8f5825f330b0 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
RodColeman 0:8f5825f330b0 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
RodColeman 0:8f5825f330b0 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
RodColeman 0:8f5825f330b0 33 * SUCH DAMAGE.
RodColeman 0:8f5825f330b0 34 *
RodColeman 0:8f5825f330b0 35 * This file is built upon the file: src/arch/rtxc/netif/sioslip.c
RodColeman 0:8f5825f330b0 36 *
RodColeman 0:8f5825f330b0 37 * Author: Magnus Ivarsson <magnus.ivarsson(at)volvo.com>
RodColeman 0:8f5825f330b0 38 */
RodColeman 0:8f5825f330b0 39
RodColeman 0:8f5825f330b0 40 /*
RodColeman 0:8f5825f330b0 41 * This is an arch independent SLIP netif. The specific serial hooks must be
RodColeman 0:8f5825f330b0 42 * provided by another file. They are sio_open, sio_read/sio_tryread and sio_send
RodColeman 0:8f5825f330b0 43 */
RodColeman 0:8f5825f330b0 44
RodColeman 0:8f5825f330b0 45 #include "netif/slipif.h"
RodColeman 0:8f5825f330b0 46 #include "lwip/opt.h"
RodColeman 0:8f5825f330b0 47
RodColeman 0:8f5825f330b0 48 #if LWIP_HAVE_SLIPIF
RodColeman 0:8f5825f330b0 49
RodColeman 0:8f5825f330b0 50 #include "lwip/def.h"
RodColeman 0:8f5825f330b0 51 #include "lwip/pbuf.h"
RodColeman 0:8f5825f330b0 52 #include "lwip/sys.h"
RodColeman 0:8f5825f330b0 53 #include "lwip/stats.h"
RodColeman 0:8f5825f330b0 54 #include "lwip/snmp.h"
RodColeman 0:8f5825f330b0 55 #include "lwip/sio.h"
RodColeman 0:8f5825f330b0 56
RodColeman 0:8f5825f330b0 57 #define SLIP_BLOCK 1
RodColeman 0:8f5825f330b0 58 #define SLIP_DONTBLOCK 0
RodColeman 0:8f5825f330b0 59
RodColeman 0:8f5825f330b0 60 #define SLIP_END 0300 /* 0xC0 */
RodColeman 0:8f5825f330b0 61 #define SLIP_ESC 0333 /* 0xDB */
RodColeman 0:8f5825f330b0 62 #define SLIP_ESC_END 0334 /* 0xDC */
RodColeman 0:8f5825f330b0 63 #define SLIP_ESC_ESC 0335 /* 0xDD */
RodColeman 0:8f5825f330b0 64
RodColeman 0:8f5825f330b0 65 #define SLIP_MAX_SIZE 1500
RodColeman 0:8f5825f330b0 66
RodColeman 0:8f5825f330b0 67 enum slipif_recv_state {
RodColeman 0:8f5825f330b0 68 SLIP_RECV_NORMAL,
RodColeman 0:8f5825f330b0 69 SLIP_RECV_ESCAPE,
RodColeman 0:8f5825f330b0 70 };
RodColeman 0:8f5825f330b0 71
RodColeman 0:8f5825f330b0 72 struct slipif_priv {
RodColeman 0:8f5825f330b0 73 sio_fd_t sd;
RodColeman 0:8f5825f330b0 74 /* q is the whole pbuf chain for a packet, p is the current pbuf in the chain */
RodColeman 0:8f5825f330b0 75 struct pbuf *p, *q;
RodColeman 0:8f5825f330b0 76 enum slipif_recv_state state;
RodColeman 0:8f5825f330b0 77 u16_t i, recved;
RodColeman 0:8f5825f330b0 78 };
RodColeman 0:8f5825f330b0 79
RodColeman 0:8f5825f330b0 80 /**
RodColeman 0:8f5825f330b0 81 * Send a pbuf doing the necessary SLIP encapsulation
RodColeman 0:8f5825f330b0 82 *
RodColeman 0:8f5825f330b0 83 * Uses the serial layer's sio_send()
RodColeman 0:8f5825f330b0 84 *
RodColeman 0:8f5825f330b0 85 * @param netif the lwip network interface structure for this slipif
RodColeman 0:8f5825f330b0 86 * @param p the pbuf chaing packet to send
RodColeman 0:8f5825f330b0 87 * @param ipaddr the ip address to send the packet to (not used for slipif)
RodColeman 0:8f5825f330b0 88 * @return always returns ERR_OK since the serial layer does not provide return values
RodColeman 0:8f5825f330b0 89 */
RodColeman 0:8f5825f330b0 90 err_t
RodColeman 0:8f5825f330b0 91 slipif_output(struct netif *netif, struct pbuf *p, ip_addr_t *ipaddr)
RodColeman 0:8f5825f330b0 92 {
RodColeman 0:8f5825f330b0 93 struct slipif_priv *priv;
RodColeman 0:8f5825f330b0 94 struct pbuf *q;
RodColeman 0:8f5825f330b0 95 u16_t i;
RodColeman 0:8f5825f330b0 96 u8_t c;
RodColeman 0:8f5825f330b0 97
RodColeman 0:8f5825f330b0 98 LWIP_ASSERT("netif != NULL", (netif != NULL));
RodColeman 0:8f5825f330b0 99 LWIP_ASSERT("netif->state != NULL", (netif->state != NULL));
RodColeman 0:8f5825f330b0 100 LWIP_ASSERT("p != NULL", (p != NULL));
RodColeman 0:8f5825f330b0 101
RodColeman 0:8f5825f330b0 102 LWIP_UNUSED_ARG(ipaddr);
RodColeman 0:8f5825f330b0 103
RodColeman 0:8f5825f330b0 104 priv = netif->state;
RodColeman 0:8f5825f330b0 105
RodColeman 0:8f5825f330b0 106 /* Send pbuf out on the serial I/O device. */
RodColeman 0:8f5825f330b0 107 sio_send(SLIP_END, priv->sd);
RodColeman 0:8f5825f330b0 108
RodColeman 0:8f5825f330b0 109 for (q = p; q != NULL; q = q->next) {
RodColeman 0:8f5825f330b0 110 for (i = 0; i < q->len; i++) {
RodColeman 0:8f5825f330b0 111 c = ((u8_t *)q->payload)[i];
RodColeman 0:8f5825f330b0 112 switch (c) {
RodColeman 0:8f5825f330b0 113 case SLIP_END:
RodColeman 0:8f5825f330b0 114 sio_send(SLIP_ESC, priv->sd);
RodColeman 0:8f5825f330b0 115 sio_send(SLIP_ESC_END, priv->sd);
RodColeman 0:8f5825f330b0 116 break;
RodColeman 0:8f5825f330b0 117 case SLIP_ESC:
RodColeman 0:8f5825f330b0 118 sio_send(SLIP_ESC, priv->sd);
RodColeman 0:8f5825f330b0 119 sio_send(SLIP_ESC_ESC, priv->sd);
RodColeman 0:8f5825f330b0 120 break;
RodColeman 0:8f5825f330b0 121 default:
RodColeman 0:8f5825f330b0 122 sio_send(c, priv->sd);
RodColeman 0:8f5825f330b0 123 break;
RodColeman 0:8f5825f330b0 124 }
RodColeman 0:8f5825f330b0 125 }
RodColeman 0:8f5825f330b0 126 }
RodColeman 0:8f5825f330b0 127 sio_send(SLIP_END, priv->sd);
RodColeman 0:8f5825f330b0 128 return ERR_OK;
RodColeman 0:8f5825f330b0 129 }
RodColeman 0:8f5825f330b0 130
RodColeman 0:8f5825f330b0 131 /**
RodColeman 0:8f5825f330b0 132 * Static function for easy use of blockig or non-blocking
RodColeman 0:8f5825f330b0 133 * sio_read
RodColeman 0:8f5825f330b0 134 *
RodColeman 0:8f5825f330b0 135 * @param fd serial device handle
RodColeman 0:8f5825f330b0 136 * @param data pointer to data buffer for receiving
RodColeman 0:8f5825f330b0 137 * @param len maximum length (in bytes) of data to receive
RodColeman 0:8f5825f330b0 138 * @param block if 1, call sio_read; if 0, call sio_tryread
RodColeman 0:8f5825f330b0 139 * @return return value of sio_read of sio_tryread
RodColeman 0:8f5825f330b0 140 */
RodColeman 0:8f5825f330b0 141 static u32_t
RodColeman 0:8f5825f330b0 142 slip_sio_read(sio_fd_t fd, u8_t* data, u32_t len, u8_t block)
RodColeman 0:8f5825f330b0 143 {
RodColeman 0:8f5825f330b0 144 if (block) {
RodColeman 0:8f5825f330b0 145 return sio_read(fd, data, len);
RodColeman 0:8f5825f330b0 146 } else {
RodColeman 0:8f5825f330b0 147 return sio_tryread(fd, data, len);
RodColeman 0:8f5825f330b0 148 }
RodColeman 0:8f5825f330b0 149 }
RodColeman 0:8f5825f330b0 150
RodColeman 0:8f5825f330b0 151 /**
RodColeman 0:8f5825f330b0 152 * Handle the incoming SLIP stream character by character
RodColeman 0:8f5825f330b0 153 *
RodColeman 0:8f5825f330b0 154 * Poll the serial layer by calling sio_read() or sio_tryread().
RodColeman 0:8f5825f330b0 155 *
RodColeman 0:8f5825f330b0 156 * @param netif the lwip network interface structure for this slipif
RodColeman 0:8f5825f330b0 157 * @param block if 1, block until data is received; if 0, return when all data
RodColeman 0:8f5825f330b0 158 * from the buffer is received (multiple calls to this function will
RodColeman 0:8f5825f330b0 159 * return a complete packet, NULL is returned before - used for polling)
RodColeman 0:8f5825f330b0 160 * @return The IP packet when SLIP_END is received
RodColeman 0:8f5825f330b0 161 */
RodColeman 0:8f5825f330b0 162 static struct pbuf *
RodColeman 0:8f5825f330b0 163 slipif_input(struct netif *netif, u8_t block)
RodColeman 0:8f5825f330b0 164 {
RodColeman 0:8f5825f330b0 165 struct slipif_priv *priv;
RodColeman 0:8f5825f330b0 166 u8_t c;
RodColeman 0:8f5825f330b0 167 struct pbuf *t;
RodColeman 0:8f5825f330b0 168
RodColeman 0:8f5825f330b0 169 LWIP_ASSERT("netif != NULL", (netif != NULL));
RodColeman 0:8f5825f330b0 170 LWIP_ASSERT("netif->state != NULL", (netif->state != NULL));
RodColeman 0:8f5825f330b0 171
RodColeman 0:8f5825f330b0 172 priv = netif->state;
RodColeman 0:8f5825f330b0 173
RodColeman 0:8f5825f330b0 174 while (slip_sio_read(priv->sd, &c, 1, block) > 0) {
RodColeman 0:8f5825f330b0 175 switch (priv->state) {
RodColeman 0:8f5825f330b0 176 case SLIP_RECV_NORMAL:
RodColeman 0:8f5825f330b0 177 switch (c) {
RodColeman 0:8f5825f330b0 178 case SLIP_END:
RodColeman 0:8f5825f330b0 179 if (priv->recved > 0) {
RodColeman 0:8f5825f330b0 180 /* Received whole packet. */
RodColeman 0:8f5825f330b0 181 /* Trim the pbuf to the size of the received packet. */
RodColeman 0:8f5825f330b0 182 pbuf_realloc(priv->q, priv->recved);
RodColeman 0:8f5825f330b0 183
RodColeman 0:8f5825f330b0 184 LINK_STATS_INC(link.recv);
RodColeman 0:8f5825f330b0 185
RodColeman 0:8f5825f330b0 186 LWIP_DEBUGF(SLIP_DEBUG, ("slipif: Got packet\n"));
RodColeman 0:8f5825f330b0 187 t = priv->q;
RodColeman 0:8f5825f330b0 188 priv->p = priv->q = NULL;
RodColeman 0:8f5825f330b0 189 priv->i = priv->recved = 0;
RodColeman 0:8f5825f330b0 190 return t;
RodColeman 0:8f5825f330b0 191 }
RodColeman 0:8f5825f330b0 192 continue;
RodColeman 0:8f5825f330b0 193 case SLIP_ESC:
RodColeman 0:8f5825f330b0 194 priv->state = SLIP_RECV_ESCAPE;
RodColeman 0:8f5825f330b0 195 continue;
RodColeman 0:8f5825f330b0 196 }
RodColeman 0:8f5825f330b0 197 break;
RodColeman 0:8f5825f330b0 198 case SLIP_RECV_ESCAPE:
RodColeman 0:8f5825f330b0 199 switch (c) {
RodColeman 0:8f5825f330b0 200 case SLIP_ESC_END:
RodColeman 0:8f5825f330b0 201 c = SLIP_END;
RodColeman 0:8f5825f330b0 202 break;
RodColeman 0:8f5825f330b0 203 case SLIP_ESC_ESC:
RodColeman 0:8f5825f330b0 204 c = SLIP_ESC;
RodColeman 0:8f5825f330b0 205 break;
RodColeman 0:8f5825f330b0 206 }
RodColeman 0:8f5825f330b0 207 priv->state = SLIP_RECV_NORMAL;
RodColeman 0:8f5825f330b0 208 /* FALLTHROUGH */
RodColeman 0:8f5825f330b0 209 }
RodColeman 0:8f5825f330b0 210
RodColeman 0:8f5825f330b0 211 /* byte received, packet not yet completely received */
RodColeman 0:8f5825f330b0 212 if (priv->p == NULL) {
RodColeman 0:8f5825f330b0 213 /* allocate a new pbuf */
RodColeman 0:8f5825f330b0 214 LWIP_DEBUGF(SLIP_DEBUG, ("slipif_input: alloc\n"));
RodColeman 0:8f5825f330b0 215 priv->p = pbuf_alloc(PBUF_LINK, (PBUF_POOL_BUFSIZE - PBUF_LINK_HLEN), PBUF_POOL);
RodColeman 0:8f5825f330b0 216
RodColeman 0:8f5825f330b0 217 if (priv->p == NULL) {
RodColeman 0:8f5825f330b0 218 LINK_STATS_INC(link.drop);
RodColeman 0:8f5825f330b0 219 LWIP_DEBUGF(SLIP_DEBUG, ("slipif_input: no new pbuf! (DROP)\n"));
RodColeman 0:8f5825f330b0 220 /* don't process any further since we got no pbuf to receive to */
RodColeman 0:8f5825f330b0 221 break;
RodColeman 0:8f5825f330b0 222 }
RodColeman 0:8f5825f330b0 223
RodColeman 0:8f5825f330b0 224 if (priv->q != NULL) {
RodColeman 0:8f5825f330b0 225 /* 'chain' the pbuf to the existing chain */
RodColeman 0:8f5825f330b0 226 pbuf_cat(priv->q, priv->p);
RodColeman 0:8f5825f330b0 227 } else {
RodColeman 0:8f5825f330b0 228 /* p is the first pbuf in the chain */
RodColeman 0:8f5825f330b0 229 priv->q = priv->p;
RodColeman 0:8f5825f330b0 230 }
RodColeman 0:8f5825f330b0 231 }
RodColeman 0:8f5825f330b0 232
RodColeman 0:8f5825f330b0 233 /* this automatically drops bytes if > SLIP_MAX_SIZE */
RodColeman 0:8f5825f330b0 234 if ((priv->p != NULL) && (priv->recved <= SLIP_MAX_SIZE)) {
RodColeman 0:8f5825f330b0 235 ((u8_t *)priv->p->payload)[priv->i] = c;
RodColeman 0:8f5825f330b0 236 priv->recved++;
RodColeman 0:8f5825f330b0 237 priv->i++;
RodColeman 0:8f5825f330b0 238 if (priv->i >= priv->p->len) {
RodColeman 0:8f5825f330b0 239 /* on to the next pbuf */
RodColeman 0:8f5825f330b0 240 priv->i = 0;
RodColeman 0:8f5825f330b0 241 if (priv->p->next != NULL && priv->p->next->len > 0) {
RodColeman 0:8f5825f330b0 242 /* p is a chain, on to the next in the chain */
RodColeman 0:8f5825f330b0 243 priv->p = priv->p->next;
RodColeman 0:8f5825f330b0 244 } else {
RodColeman 0:8f5825f330b0 245 /* p is a single pbuf, set it to NULL so next time a new
RodColeman 0:8f5825f330b0 246 * pbuf is allocated */
RodColeman 0:8f5825f330b0 247 priv->p = NULL;
RodColeman 0:8f5825f330b0 248 }
RodColeman 0:8f5825f330b0 249 }
RodColeman 0:8f5825f330b0 250 }
RodColeman 0:8f5825f330b0 251 }
RodColeman 0:8f5825f330b0 252
RodColeman 0:8f5825f330b0 253 return NULL;
RodColeman 0:8f5825f330b0 254 }
RodColeman 0:8f5825f330b0 255
RodColeman 0:8f5825f330b0 256 #if !NO_SYS
RodColeman 0:8f5825f330b0 257 /**
RodColeman 0:8f5825f330b0 258 * The SLIP input thread.
RodColeman 0:8f5825f330b0 259 *
RodColeman 0:8f5825f330b0 260 * Feed the IP layer with incoming packets
RodColeman 0:8f5825f330b0 261 *
RodColeman 0:8f5825f330b0 262 * @param nf the lwip network interface structure for this slipif
RodColeman 0:8f5825f330b0 263 */
RodColeman 0:8f5825f330b0 264 static void
RodColeman 0:8f5825f330b0 265 slipif_loop_thread(void *nf)
RodColeman 0:8f5825f330b0 266 {
RodColeman 0:8f5825f330b0 267 struct pbuf *p;
RodColeman 0:8f5825f330b0 268 struct netif *netif = (struct netif *)nf;
RodColeman 0:8f5825f330b0 269
RodColeman 0:8f5825f330b0 270 while (1) {
RodColeman 0:8f5825f330b0 271 p = slipif_input(netif, SLIP_BLOCK);
RodColeman 0:8f5825f330b0 272 if (p != NULL) {
RodColeman 0:8f5825f330b0 273 if (netif->input(p, netif) != ERR_OK) {
RodColeman 0:8f5825f330b0 274 pbuf_free(p);
RodColeman 0:8f5825f330b0 275 p = NULL;
RodColeman 0:8f5825f330b0 276 }
RodColeman 0:8f5825f330b0 277 }
RodColeman 0:8f5825f330b0 278 }
RodColeman 0:8f5825f330b0 279 }
RodColeman 0:8f5825f330b0 280 #endif /* !NO_SYS */
RodColeman 0:8f5825f330b0 281
RodColeman 0:8f5825f330b0 282 /**
RodColeman 0:8f5825f330b0 283 * SLIP netif initialization
RodColeman 0:8f5825f330b0 284 *
RodColeman 0:8f5825f330b0 285 * Call the arch specific sio_open and remember
RodColeman 0:8f5825f330b0 286 * the opened device in the state field of the netif.
RodColeman 0:8f5825f330b0 287 *
RodColeman 0:8f5825f330b0 288 * @param netif the lwip network interface structure for this slipif
RodColeman 0:8f5825f330b0 289 * @return ERR_OK if serial line could be opened,
RodColeman 0:8f5825f330b0 290 * ERR_MEM if no memory could be allocated,
RodColeman 0:8f5825f330b0 291 * ERR_IF is serial line couldn't be opened
RodColeman 0:8f5825f330b0 292 *
RodColeman 0:8f5825f330b0 293 * @note netif->num must contain the number of the serial port to open
RodColeman 0:8f5825f330b0 294 * (0 by default)
RodColeman 0:8f5825f330b0 295 */
RodColeman 0:8f5825f330b0 296 err_t
RodColeman 0:8f5825f330b0 297 slipif_init(struct netif *netif)
RodColeman 0:8f5825f330b0 298 {
RodColeman 0:8f5825f330b0 299 struct slipif_priv *priv;
RodColeman 0:8f5825f330b0 300
RodColeman 0:8f5825f330b0 301 LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: netif->num=%"U16_F"\n", (u16_t)netif->num));
RodColeman 0:8f5825f330b0 302
RodColeman 0:8f5825f330b0 303 /* Allocate private data */
RodColeman 0:8f5825f330b0 304 priv = mem_malloc(sizeof(struct slipif_priv));
RodColeman 0:8f5825f330b0 305 if (!priv) {
RodColeman 0:8f5825f330b0 306 return ERR_MEM;
RodColeman 0:8f5825f330b0 307 }
RodColeman 0:8f5825f330b0 308
RodColeman 0:8f5825f330b0 309 netif->name[0] = 's';
RodColeman 0:8f5825f330b0 310 netif->name[1] = 'l';
RodColeman 0:8f5825f330b0 311 netif->output = slipif_output;
RodColeman 0:8f5825f330b0 312 netif->mtu = SLIP_MAX_SIZE;
RodColeman 0:8f5825f330b0 313 netif->flags |= NETIF_FLAG_POINTTOPOINT;
RodColeman 0:8f5825f330b0 314
RodColeman 0:8f5825f330b0 315 /* Try to open the serial port (netif->num contains the port number). */
RodColeman 0:8f5825f330b0 316 priv->sd = sio_open(netif->num);
RodColeman 0:8f5825f330b0 317 if (!priv->sd) {
RodColeman 0:8f5825f330b0 318 /* Opening the serial port failed. */
RodColeman 0:8f5825f330b0 319 mem_free(priv);
RodColeman 0:8f5825f330b0 320 return ERR_IF;
RodColeman 0:8f5825f330b0 321 }
RodColeman 0:8f5825f330b0 322
RodColeman 0:8f5825f330b0 323 /* Initialize private data */
RodColeman 0:8f5825f330b0 324 priv->p = NULL;
RodColeman 0:8f5825f330b0 325 priv->q = NULL;
RodColeman 0:8f5825f330b0 326 priv->state = SLIP_RECV_NORMAL;
RodColeman 0:8f5825f330b0 327 priv->i = 0;
RodColeman 0:8f5825f330b0 328 priv->recved = 0;
RodColeman 0:8f5825f330b0 329
RodColeman 0:8f5825f330b0 330 netif->state = priv;
RodColeman 0:8f5825f330b0 331
RodColeman 0:8f5825f330b0 332 /* initialize the snmp variables and counters inside the struct netif
RodColeman 0:8f5825f330b0 333 * ifSpeed: no assumption can be made without knowing more about the
RodColeman 0:8f5825f330b0 334 * serial line!
RodColeman 0:8f5825f330b0 335 */
RodColeman 0:8f5825f330b0 336 NETIF_INIT_SNMP(netif, snmp_ifType_slip, 0);
RodColeman 0:8f5825f330b0 337
RodColeman 0:8f5825f330b0 338 /* Create a thread to poll the serial line. */
RodColeman 0:8f5825f330b0 339 sys_thread_new(SLIPIF_THREAD_NAME, slipif_loop_thread, netif,
RodColeman 0:8f5825f330b0 340 SLIPIF_THREAD_STACKSIZE, SLIPIF_THREAD_PRIO);
RodColeman 0:8f5825f330b0 341 return ERR_OK;
RodColeman 0:8f5825f330b0 342 }
RodColeman 0:8f5825f330b0 343
RodColeman 0:8f5825f330b0 344 /**
RodColeman 0:8f5825f330b0 345 * Polls the serial device and feeds the IP layer with incoming packets.
RodColeman 0:8f5825f330b0 346 *
RodColeman 0:8f5825f330b0 347 * @param netif The lwip network interface structure for this slipif
RodColeman 0:8f5825f330b0 348 */
RodColeman 0:8f5825f330b0 349 void
RodColeman 0:8f5825f330b0 350 slipif_poll(struct netif *netif)
RodColeman 0:8f5825f330b0 351 {
RodColeman 0:8f5825f330b0 352 struct pbuf *p;
RodColeman 0:8f5825f330b0 353 struct slipif_priv *priv;
RodColeman 0:8f5825f330b0 354
RodColeman 0:8f5825f330b0 355 LWIP_ASSERT("netif != NULL", (netif != NULL));
RodColeman 0:8f5825f330b0 356 LWIP_ASSERT("netif->state != NULL", (netif->state != NULL));
RodColeman 0:8f5825f330b0 357
RodColeman 0:8f5825f330b0 358 priv = netif->state;
RodColeman 0:8f5825f330b0 359
RodColeman 0:8f5825f330b0 360 while ((p = slipif_input(netif, SLIP_DONTBLOCK)) != NULL) {
RodColeman 0:8f5825f330b0 361 if (netif->input(p, netif) != ERR_OK) {
RodColeman 0:8f5825f330b0 362 pbuf_free(p);
RodColeman 0:8f5825f330b0 363 }
RodColeman 0:8f5825f330b0 364 }
RodColeman 0:8f5825f330b0 365 }
RodColeman 0:8f5825f330b0 366
RodColeman 0:8f5825f330b0 367 #endif /* LWIP_HAVE_SLIPIF */