Experimental HTTPClient with proxy support

Committer:
igorsk
Date:
Wed Jun 29 16:01:58 2011 +0000
Revision:
0:b56b6a05cad4

        

Who changed what in which revision?

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