Committer:
mbed714
Date:
Sat Sep 18 23:05:49 2010 +0000
Revision:
0:d616ece2d859

        

Who changed what in which revision?

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