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