7 * \defgroup slip Serial Line IP (SLIP) protocol
\r
10 * The SLIP protocol is a very simple way to transmit IP packets over
\r
11 * a serial line. It does not provide any framing or error control,
\r
12 * and is therefore not very widely used today.
\r
14 * This SLIP implementation requires two functions for accessing the
\r
15 * serial device: slipdev_char_poll() and slipdev_char_put(). These
\r
16 * must be implemented specifically for the system on which the SLIP
\r
17 * protocol is to be run.
\r
22 * SLIP protocol implementation
\r
23 * \author Adam Dunkels <adam@dunkels.com>
\r
27 * Copyright (c) 2001, Adam Dunkels.
\r
28 * All rights reserved.
\r
30 * Redistribution and use in source and binary forms, with or without
\r
31 * modification, are permitted provided that the following conditions
\r
33 * 1. Redistributions of source code must retain the above copyright
\r
34 * notice, this list of conditions and the following disclaimer.
\r
35 * 2. Redistributions in binary form must reproduce the above copyright
\r
36 * notice, this list of conditions and the following disclaimer in the
\r
37 * documentation and/or other materials provided with the distribution.
\r
38 * 3. The name of the author may not be used to endorse or promote
\r
39 * products derived from this software without specific prior
\r
40 * written permission.
\r
42 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
\r
43 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
\r
44 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
\r
45 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
\r
46 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
\r
48 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
\r
49 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
\r
50 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
51 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
\r
52 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
54 * This file is part of the uIP TCP/IP stack.
\r
56 * $Id: slipdev.c,v 1.1.2.3 2003/10/07 13:23:01 adam Exp $
\r
61 * This is a generic implementation of the SLIP protocol over an RS232
\r
64 * Huge thanks to Ullrich von Bassewitz <uz@cc65.org> of cc65 fame for
\r
65 * and endless supply of bugfixes, insightsful comments and
\r
66 * suggestions, and improvements to this code!
\r
71 #define SLIP_END 0300
\r
72 #define SLIP_ESC 0333
\r
73 #define SLIP_ESC_END 0334
\r
74 #define SLIP_ESC_ESC 0335
\r
76 static u8_t slip_buf[UIP_BUFSIZE];
\r
78 static u16_t len, tmplen;
\r
81 /*-----------------------------------------------------------------------------------*/
\r
83 * Send the packet in the uip_buf and uip_appdata buffers using the
\r
86 * The first 40 bytes of the packet (the IP and TCP headers) are read
\r
87 * from the uip_buf buffer, and the following bytes (the application
\r
88 * data) are read from the uip_appdata buffer.
\r
91 /*-----------------------------------------------------------------------------------*/
\r
99 slipdev_char_put(SLIP_END);
\r
102 for(i = 0; i < uip_len; ++i) {
\r
104 ptr = (u8_t *)uip_appdata;
\r
109 slipdev_char_put(SLIP_ESC);
\r
110 slipdev_char_put(SLIP_ESC_END);
\r
113 slipdev_char_put(SLIP_ESC);
\r
114 slipdev_char_put(SLIP_ESC_ESC);
\r
117 slipdev_char_put(c);
\r
121 slipdev_char_put(SLIP_END);
\r
123 /*-----------------------------------------------------------------------------------*/
\r
125 * Poll the SLIP device for an available packet.
\r
127 * This function will poll the SLIP device to see if a packet is
\r
128 * available. It uses a buffer in which all avaliable bytes from the
\r
129 * RS232 interface are read into. When a full packet has been read
\r
130 * into the buffer, the packet is copied into the uip_buf buffer and
\r
131 * the length of the packet is returned.
\r
133 * \return The length of the packet placed in the uip_buf buffer, or
\r
134 * zero if no packet is available.
\r
136 /*-----------------------------------------------------------------------------------*/
\r
142 while(slipdev_char_poll(c)) {
\r
150 /* End marker found, we copy our input buffer to the uip_buf
\r
151 buffer and return the size of the packet we copied. */
\r
152 memcpy(uip_buf, slip_buf, len);
\r
158 if(lastc == SLIP_ESC) {
\r
160 /* Previous read byte was an escape byte, so this byte will be
\r
161 interpreted differently from others. */
\r
177 if(len > UIP_BUFSIZE) {
\r
186 /*-----------------------------------------------------------------------------------*/
\r
188 * Initialize the SLIP module.
\r
190 * This function does not initialize the underlying RS232 device, but
\r
191 * only the SLIP part.
\r
193 /*-----------------------------------------------------------------------------------*/
\r
199 /*-----------------------------------------------------------------------------------*/
\r