Official mbed lwIP library (version 1.4.0)

Dependents:   LwIPNetworking NetServicesMin EthernetInterface EthernetInterface_RSF ... more

Legacy Networking Libraries

This is an mbed 2 networking library. For mbed OS 5, lwip has been integrated with built-in networking interfaces. The networking libraries have been revised to better support additional network stacks and thread safety here.

This library is based on the code of lwIP v1.4.0

Copyright (c) 2001, 2002 Swedish Institute of Computer Science.
All rights reserved. 

Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
   this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
   derived from this software without specific prior written permission. 

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
OF SUCH DAMAGE.
Committer:
mbed_official
Date:
Mon Mar 14 16:15:36 2016 +0000
Revision:
20:08f08bfc3f3d
Parent:
0:51ac1d130fd4
Synchronized with git revision fec574a5ed6db26aca1b13992ff271bf527d4a0d

Full URL: https://github.com/mbedmicro/mbed/commit/fec574a5ed6db26aca1b13992ff271bf527d4a0d/

Increased allocated netbufs to handle DTLS handshakes

Who changed what in which revision?

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