2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
\r
3 * All rights reserved.
\r
5 * Redistribution and use in source and binary forms, with or without
\r
6 * modification, are permitted provided that the following conditions
\r
8 * 1. Redistributions of source code must retain the above copyright
\r
9 * notice, this list of conditions and the following disclaimer.
\r
10 * 2. Redistributions in binary form must reproduce the above copyright
\r
11 * notice, this list of conditions and the following disclaimer in the
\r
12 * documentation and/or other materials provided with the distribution.
\r
13 * 3. Neither the name of the Institute nor the names of its contributors
\r
14 * may be used to endorse or promote products derived from this software
\r
15 * without specific prior written permission.
\r
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
\r
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
\r
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
\r
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
\r
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
\r
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
\r
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
\r
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
\r
29 * This file is built upon the file: src/arch/rtxc/netif/sioslip.c
\r
31 * Author: Magnus Ivarsson <magnus.ivarsson(at)volvo.com>
\r
35 * This is an arch independent SLIP netif. The specific serial hooks must be
\r
36 * provided by another file. They are sio_open, sio_recv and sio_send
\r
39 #include "netif/slipif.h"
\r
40 #include "lwip/opt.h"
\r
41 #include "lwip/def.h"
\r
42 #include "lwip/pbuf.h"
\r
43 #include "lwip/sys.h"
\r
44 #include "lwip/stats.h"
\r
45 #include "lwip/sio.h"
\r
47 #define SLIP_END 0300
\r
48 #define SLIP_ESC 0333
\r
49 #define SLIP_ESC_END 0334
\r
50 #define SLIP_ESC_ESC 0335
\r
52 #define MAX_SIZE 1500
\r
55 * Send a pbuf doing the necessary SLIP encapsulation
\r
57 * Uses the serial layer's sio_send()
\r
60 slipif_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr)
\r
66 /* Send pbuf out on the serial I/O device. */
\r
67 sio_send(SLIP_END, netif->state);
\r
69 for (q = p; q != NULL; q = q->next) {
\r
70 for (i = 0; i < q->len; i++) {
\r
71 c = ((u8_t *)q->payload)[i];
\r
74 sio_send(SLIP_ESC, netif->state);
\r
75 sio_send(SLIP_ESC_END, netif->state);
\r
78 sio_send(SLIP_ESC, netif->state);
\r
79 sio_send(SLIP_ESC_ESC, netif->state);
\r
82 sio_send(c, netif->state);
\r
87 sio_send(SLIP_END, netif->state);
\r
92 * Handle the incoming SLIP stream character by character
\r
94 * Poll the serial layer by calling sio_recv()
\r
96 * @return The IP packet when SLIP_END is received
\r
98 static struct pbuf *
\r
99 slipif_input(struct netif *netif)
\r
102 struct pbuf *p, *q;
\r
111 c = sio_recv(netif->state);
\r
115 /* Received whole packet. */
\r
116 pbuf_realloc(q, recved);
\r
118 LINK_STATS_INC(link.recv);
\r
120 LWIP_DEBUGF(SLIP_DEBUG, ("slipif: Got packet\n"));
\r
126 c = sio_recv(netif->state);
\r
139 LWIP_DEBUGF(SLIP_DEBUG, ("slipif_input: alloc\n"));
\r
140 p = pbuf_alloc(PBUF_LINK, PBUF_POOL_BUFSIZE, PBUF_POOL);
\r
143 LINK_STATS_INC(link.drop);
\r
144 LWIP_DEBUGF(SLIP_DEBUG, ("slipif_input: no new pbuf! (DROP)\n"));
\r
153 if (p != NULL && recved < MAX_SIZE) {
\r
154 ((u8_t *)p->payload)[i] = c;
\r
159 if (p->next != NULL && p->next->len > 0)
\r
173 * The SLIP input thread.
\r
175 * Feed the IP layer with incoming packets
\r
178 slipif_loop(void *nf)
\r
181 struct netif *netif = (struct netif *)nf;
\r
184 p = slipif_input(netif);
\r
185 netif->input(p, netif);
\r
190 * SLIP netif initialization
\r
192 * Call the arch specific sio_open and remember
\r
193 * the opened device in the state field of the netif.
\r
196 slipif_init(struct netif *netif)
\r
199 LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: netif->num=%"U16_F"\n", (u16_t)netif->num));
\r
201 netif->name[0] = 's';
\r
202 netif->name[1] = 'l';
\r
203 netif->output = slipif_output;
\r
205 netif->flags = NETIF_FLAG_POINTTOPOINT;
\r
207 netif->state = sio_open(netif->num);
\r
211 sys_thread_new(slipif_loop, netif, SLIPIF_THREAD_PRIO);
\r