ReactOS 0.4.16-dev-297-gc569aee
slipif.c File Reference
#include "netif/slipif.h"
#include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/pbuf.h"
#include "lwip/stats.h"
#include "lwip/snmp.h"
#include "lwip/sys.h"
#include "lwip/sio.h"
Include dependency graph for slipif.c:

Go to the source code of this file.

Classes

struct  slipif_priv
 

Macros

#define SLIP_END   0xC0 /* 0300: start and end of every packet */
 
#define SLIP_ESC   0xDB /* 0333: escape start (one byte escaped data follows) */
 
#define SLIP_ESC_END   0xDC /* 0334: following escape: original byte is 0xC0 (END) */
 
#define SLIP_ESC_ESC   0xDD /* 0335: following escape: original byte is 0xDB (ESC) */
 
#define SLIP_MAX_SIZE   1500
 
#define SLIP_SIO_SPEED(sio_fd)   0
 

Enumerations

enum  slipif_recv_state { SLIP_RECV_NORMAL , SLIP_RECV_ESCAPE }
 

Functions

static err_t slipif_output (struct netif *netif, struct pbuf *p)
 
static struct pbufslipif_rxbyte (struct netif *netif, u8_t c)
 
static void slipif_rxbyte_input (struct netif *netif, u8_t c)
 
err_t slipif_init (struct netif *netif)
 
void slipif_poll (struct netif *netif)
 

Detailed Description

SLIP Interface

Definition in file slipif.c.

Macro Definition Documentation

◆ SLIP_END

#define SLIP_END   0xC0 /* 0300: start and end of every packet */

Definition at line 72 of file slipif.c.

◆ SLIP_ESC

#define SLIP_ESC   0xDB /* 0333: escape start (one byte escaped data follows) */

Definition at line 73 of file slipif.c.

◆ SLIP_ESC_END

#define SLIP_ESC_END   0xDC /* 0334: following escape: original byte is 0xC0 (END) */

Definition at line 74 of file slipif.c.

◆ SLIP_ESC_ESC

#define SLIP_ESC_ESC   0xDD /* 0335: following escape: original byte is 0xDB (ESC) */

Definition at line 75 of file slipif.c.

◆ SLIP_MAX_SIZE

#define SLIP_MAX_SIZE   1500

Maximum packet size that is received by this netif

Definition at line 79 of file slipif.c.

◆ SLIP_SIO_SPEED

#define SLIP_SIO_SPEED (   sio_fd)    0

Define this to the interface speed for SNMP (sio_fd is the sio_fd_t returned by sio_open). The default value of zero means 'unknown'.

Definition at line 87 of file slipif.c.

Enumeration Type Documentation

◆ slipif_recv_state

Enumerator
SLIP_RECV_NORMAL 
SLIP_RECV_ESCAPE 

Definition at line 90 of file slipif.c.

90 {
93};
@ SLIP_RECV_NORMAL
Definition: slipif.c:91
@ SLIP_RECV_ESCAPE
Definition: slipif.c:92

Function Documentation

◆ slipif_output()

static err_t slipif_output ( struct netif netif,
struct pbuf p 
)
static

Send a pbuf doing the necessary SLIP encapsulation

Uses the serial layer's sio_send()

Parameters
netifthe lwip network interface structure for this slipif
pthe pbuf chain packet to send
Returns
always returns ERR_OK since the serial layer does not provide return values

Definition at line 116 of file slipif.c.

117{
118 struct slipif_priv *priv;
119 struct pbuf *q;
120 u16_t i;
121 u8_t c;
122
123 LWIP_ASSERT("netif != NULL", (netif != NULL));
124 LWIP_ASSERT("netif->state != NULL", (netif->state != NULL));
125 LWIP_ASSERT("p != NULL", (p != NULL));
126
127 LWIP_DEBUGF(SLIP_DEBUG, ("slipif_output: sending %"U16_F" bytes\n", p->tot_len));
128 priv = (struct slipif_priv *)netif->state;
129
130 /* Send pbuf out on the serial I/O device. */
131 /* Start with packet delimiter. */
132 sio_send(SLIP_END, priv->sd);
133
134 for (q = p; q != NULL; q = q->next) {
135 for (i = 0; i < q->len; i++) {
136 c = ((u8_t *)q->payload)[i];
137 switch (c) {
138 case SLIP_END:
139 /* need to escape this byte (0xC0 -> 0xDB, 0xDC) */
140 sio_send(SLIP_ESC, priv->sd);
141 sio_send(SLIP_ESC_END, priv->sd);
142 break;
143 case SLIP_ESC:
144 /* need to escape this byte (0xDB -> 0xDB, 0xDD) */
145 sio_send(SLIP_ESC, priv->sd);
146 sio_send(SLIP_ESC_ESC, priv->sd);
147 break;
148 default:
149 /* normal byte - no need for escaping */
150 sio_send(c, priv->sd);
151 break;
152 }
153 }
154 }
155 /* End with packet delimiter. */
156 sio_send(SLIP_END, priv->sd);
157 return ERR_OK;
158}
#define NULL
Definition: types.h:112
#define U16_F
Definition: cc.h:19
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:158
#define LWIP_ASSERT(message, assertion)
Definition: debug.h:116
void sio_send(u8_t c, sio_fd_t fd)
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
const GLubyte * c
Definition: glext.h:8905
GLfloat GLfloat p
Definition: glext.h:8902
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
uint8_t u8_t
Definition: arch.h:125
uint16_t u16_t
Definition: arch.h:127
@ ERR_OK
Definition: err.h:55
#define SLIP_DEBUG
Definition: opt.h:3519
#define c
Definition: ke_i.h:80
#define SLIP_ESC
Definition: slipif.c:73
#define SLIP_ESC_END
Definition: slipif.c:74
#define SLIP_ESC_ESC
Definition: slipif.c:75
#define SLIP_END
Definition: slipif.c:72
struct define * next
Definition: compiler.c:65
Definition: netif.h:269
void * state
Definition: netif.h:332
Definition: pbuf.h:186
sio_fd_t sd
Definition: slipif.c:96

◆ slipif_rxbyte()

static struct pbuf * slipif_rxbyte ( struct netif netif,
u8_t  c 
)
static

Handle the incoming SLIP stream character by character

Parameters
netifthe lwip network interface structure for this slipif
creceived character (multiple calls to this function will return a complete packet, NULL is returned before - used for polling)
Returns
The IP packet when SLIP_END is received

Definition at line 207 of file slipif.c.

208{
209 struct slipif_priv *priv;
210 struct pbuf *t;
211
212 LWIP_ASSERT("netif != NULL", (netif != NULL));
213 LWIP_ASSERT("netif->state != NULL", (netif->state != NULL));
214
215 priv = (struct slipif_priv *)netif->state;
216
217 switch (priv->state) {
218 case SLIP_RECV_NORMAL:
219 switch (c) {
220 case SLIP_END:
221 if (priv->recved > 0) {
222 /* Received whole packet. */
223 /* Trim the pbuf to the size of the received packet. */
224 pbuf_realloc(priv->q, priv->recved);
225
226 LINK_STATS_INC(link.recv);
227
228 LWIP_DEBUGF(SLIP_DEBUG, ("slipif: Got packet (%"U16_F" bytes)\n", priv->recved));
229 t = priv->q;
230 priv->p = priv->q = NULL;
231 priv->i = priv->recved = 0;
232 return t;
233 }
234 return NULL;
235 case SLIP_ESC:
236 priv->state = SLIP_RECV_ESCAPE;
237 return NULL;
238 default:
239 break;
240 } /* end switch (c) */
241 break;
242 case SLIP_RECV_ESCAPE:
243 /* un-escape END or ESC bytes, leave other bytes
244 (although that would be a protocol error) */
245 switch (c) {
246 case SLIP_ESC_END:
247 c = SLIP_END;
248 break;
249 case SLIP_ESC_ESC:
250 c = SLIP_ESC;
251 break;
252 default:
253 break;
254 }
255 priv->state = SLIP_RECV_NORMAL;
256 break;
257 default:
258 break;
259 } /* end switch (priv->state) */
260
261 /* byte received, packet not yet completely received */
262 if (priv->p == NULL) {
263 /* allocate a new pbuf */
264 LWIP_DEBUGF(SLIP_DEBUG, ("slipif_input: alloc\n"));
266
267 if (priv->p == NULL) {
268 LINK_STATS_INC(link.drop);
269 LWIP_DEBUGF(SLIP_DEBUG, ("slipif_input: no new pbuf! (DROP)\n"));
270 /* don't process any further since we got no pbuf to receive to */
271 return NULL;
272 }
273
274 if (priv->q != NULL) {
275 /* 'chain' the pbuf to the existing chain */
276 pbuf_cat(priv->q, priv->p);
277 } else {
278 /* p is the first pbuf in the chain */
279 priv->q = priv->p;
280 }
281 }
282
283 /* this automatically drops bytes if > SLIP_MAX_SIZE */
284 if ((priv->p != NULL) && (priv->recved <= SLIP_MAX_SIZE)) {
285 ((u8_t *)priv->p->payload)[priv->i] = c;
286 priv->recved++;
287 priv->i++;
288 if (priv->i >= priv->p->len) {
289 /* on to the next pbuf */
290 priv->i = 0;
291 if (priv->p->next != NULL && priv->p->next->len > 0) {
292 /* p is a chain, on to the next in the chain */
293 priv->p = priv->p->next;
294 } else {
295 /* p is a single pbuf, set it to NULL so next time a new
296 * pbuf is allocated */
297 priv->p = NULL;
298 }
299 }
300 }
301 return NULL;
302}
const WCHAR * link
Definition: db.cpp:997
switch(r->id)
Definition: btrfs.c:3046
GLdouble GLdouble t
Definition: gl.h:2047
#define PBUF_LINK_HLEN
Definition: opt.h:1581
#define PBUF_LINK_ENCAPSULATION_HLEN
Definition: opt.h:1590
#define PBUF_POOL_BUFSIZE
Definition: opt.h:1599
void pbuf_realloc(struct pbuf *p, u16_t new_len)
Definition: pbuf.c:402
void pbuf_cat(struct pbuf *h, struct pbuf *t)
Definition: pbuf.c:855
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
Definition: pbuf.c:224
@ PBUF_POOL
Definition: pbuf.h:167
@ PBUF_LINK
Definition: pbuf.h:102
#define SLIP_MAX_SIZE
Definition: slipif.c:79
#define LINK_STATS_INC(x)
Definition: stats.h:384
struct pbuf * p
Definition: slipif.c:98
u16_t recved
Definition: slipif.c:100
struct pbuf * q
Definition: slipif.c:98
u8_t state
Definition: slipif.c:99
u16_t i
Definition: slipif.c:100

Referenced by slipif_rxbyte_input().

◆ slipif_rxbyte_input()

static void slipif_rxbyte_input ( struct netif netif,
u8_t  c 
)
static

Like slipif_rxbyte, but passes completed packets to netif->input

Parameters
netifThe lwip network interface structure for this slipif
creceived character

Definition at line 310 of file slipif.c.

311{
312 struct pbuf *p;
314 if (p != NULL) {
315 if (netif->input(p, netif) != ERR_OK) {
316 pbuf_free(p);
317 }
318 }
319}
u8_t pbuf_free(struct pbuf *p)
Definition: pbuf.c:727
static struct pbuf * slipif_rxbyte(struct netif *netif, u8_t c)
Definition: slipif.c:207
netif_input_fn input
Definition: netif.h:297

Referenced by slipif_poll().