93 #define SLIP_ESC_END 0xDC 94 #define SLIP_ESC_ESC 0xDD 98 #define SLIP_MAX_SIZE 1500 105 #ifndef SLIP_SIO_SPEED 106 #define SLIP_SIO_SPEED(sio_fd) 0 109 enum slipif_recv_state {
121 struct pbuf *rxpackets;
142 LWIP_ASSERT(
"netif != NULL", (netif != NULL));
143 LWIP_ASSERT(
"netif->state != NULL", (netif->
state != NULL));
144 LWIP_ASSERT(
"p != NULL", (p != NULL));
151 sio_send(SLIP_END, priv->sd);
153 for (q = p; q != NULL; q = q->
next) {
154 for (i = 0; i < q->
len; i++) {
159 sio_send(SLIP_ESC, priv->sd);
160 sio_send(SLIP_ESC_END, priv->sd);
164 sio_send(SLIP_ESC, priv->sd);
165 sio_send(SLIP_ESC_ESC, priv->sd);
169 sio_send(c, priv->sd);
175 sio_send(SLIP_END, priv->sd);
191 slipif_output_v4(
struct netif *netif,
struct pbuf *p,
const ip4_addr_t *ipaddr)
194 return slipif_output(netif, p);
210 slipif_output_v6(
struct netif *netif,
struct pbuf *p,
const ip6_addr_t *ipaddr)
213 return slipif_output(netif, p);
226 slipif_rxbyte(
struct netif *netif, u8_t c)
231 LWIP_ASSERT(
"netif != NULL", (netif != NULL));
232 LWIP_ASSERT(
"netif->state != NULL", (netif->
state != NULL));
236 switch (priv->state) {
237 case SLIP_RECV_NORMAL:
240 if (priv->recved > 0) {
245 LINK_STATS_INC(link.recv);
249 priv->p = priv->q = NULL;
250 priv->i = priv->recved = 0;
255 priv->state = SLIP_RECV_ESCAPE;
261 case SLIP_RECV_ESCAPE:
274 priv->state = SLIP_RECV_NORMAL;
281 if (priv->p == NULL) {
286 if (priv->p == NULL) {
287 LINK_STATS_INC(link.drop);
293 if (priv->q != NULL) {
304 ((u8_t *)priv->p->
payload)[priv->i] = c;
307 if (priv->i >= priv->p->
len) {
310 if (priv->p->
next != NULL && priv->p->
next->
len > 0) {
312 priv->p = priv->p->
next;
329 slipif_rxbyte_input(
struct netif *netif, u8_t c)
332 p = slipif_rxbyte(netif, c);
340 #if SLIP_USE_RX_THREAD 349 slipif_loop_thread(
void *nf)
352 struct netif *netif = (
struct netif *)nf;
356 if (sio_read(priv->sd, &c, 1) > 0) {
357 slipif_rxbyte_input(netif, c);
393 netif->
name[0] =
's';
394 netif->
name[1] =
'l';
396 netif->output = slipif_output_v4;
399 netif->output_ip6 = slipif_output_v6;
404 if (netif->
state != NULL) {
405 sio_num = *(u8_t*)netif->
state;
407 sio_num = netif->
num;
410 priv->sd = sio_open(sio_num);
420 priv->state = SLIP_RECV_NORMAL;
424 priv->rxpackets = NULL;
430 MIB2_INIT_NETIF(netif, snmp_ifType_slip,
SLIP_SIO_SPEED(priv->sd));
432 #if SLIP_USE_RX_THREAD 451 LWIP_ASSERT(
"netif != NULL", (netif != NULL));
452 LWIP_ASSERT(
"netif->state != NULL", (netif->
state != NULL));
456 while (sio_tryread(priv->sd, &c, 1) > 0) {
457 slipif_rxbyte_input(netif, c);
468 slipif_process_rxqueue(
struct netif *netif)
473 LWIP_ASSERT(
"netif != NULL", (netif != NULL));
474 LWIP_ASSERT(
"netif->state != NULL", (netif->
state != NULL));
478 SYS_ARCH_PROTECT(old_level);
479 while (priv->rxpackets != NULL) {
480 struct pbuf *p = priv->rxpackets;
487 priv->rxpackets = q->
next;
490 priv->rxpackets = NULL;
492 SYS_ARCH_UNPROTECT(old_level);
496 SYS_ARCH_PROTECT(old_level);
506 slipif_rxbyte_enqueue(
struct netif *netif, u8_t data)
512 p = slipif_rxbyte(netif, data);
514 SYS_ARCH_PROTECT(old_level);
515 if (priv->rxpackets != NULL) {
519 while (q->
next != NULL) {
531 SYS_ARCH_UNPROTECT(old_level);
545 slipif_received_byte(
struct netif *netif, u8_t data)
547 LWIP_ASSERT(
"netif != NULL", (netif != NULL));
548 LWIP_ASSERT(
"netif->state != NULL", (netif->
state != NULL));
549 slipif_rxbyte_enqueue(netif, data);
563 slipif_received_bytes(
struct netif *netif, u8_t *data, u8_t
len)
567 LWIP_ASSERT(
"netif != NULL", (netif != NULL));
568 LWIP_ASSERT(
"netif->state != NULL", (netif->
state != NULL));
570 for (i = 0; i <
len; i++, rxdata++) {
571 slipif_rxbyte_enqueue(netif, *rxdata);
void pbuf_realloc(struct pbuf *p, u16_t new_len)
void mem_free(void *rmem)
#define SYS_ARCH_DECL_PROTECT(lev)
#define SLIPIF_THREAD_STACKSIZE
sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio)
#define SLIP_SIO_SPEED(sio_fd)
void pbuf_cat(struct pbuf *h, struct pbuf *t)
err_t slipif_init(struct netif *netif)
void slipif_poll(struct netif *netif)
#define LWIP_DEBUGF(debug, message)
#define PBUF_POOL_BUFSIZE
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
#define SLIPIF_THREAD_NAME
#define LWIP_UNUSED_ARG(x)
u8_t pbuf_free(struct pbuf *p)
void * mem_malloc(mem_size_t size)
#define SLIPIF_THREAD_PRIO
#define PBUF_LINK_ENCAPSULATION_HLEN