From 77f7d990485b45c40a0d81c253b14b1d0ff8ecb8 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Wed, 11 Mar 2015 09:28:35 +0100 Subject: [PATCH] PPP, PPPoS, add pppos_input_tcpip() input helper function for !NO_SYS users --- src/include/netif/ppp/pppos.h | 5 +++++ src/netif/ppp/pppos.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/include/netif/ppp/pppos.h b/src/include/netif/ppp/pppos.h index f6747da0..df434d5d 100644 --- a/src/include/netif/ppp/pppos.h +++ b/src/include/netif/ppp/pppos.h @@ -103,6 +103,11 @@ struct pppos_pcb_s { ppp_pcb *pppos_create(struct netif *pppif, sio_fd_t fd, ppp_link_status_cb_fn link_status_cb, void *ctx_cb); +#if !NO_SYS +/* Pass received raw characters to PPPoS to be decoded through lwIP TCPIP thread. */ +err_t pppos_input_tcpip(ppp_pcb *ppp, u_char *s, int l); +#endif /* !NO_SYS */ + /* PPP over Serial: this is the input function to be called for received data. */ void pppos_input(ppp_pcb *ppp, u_char* data, int len); diff --git a/src/netif/ppp/pppos.c b/src/netif/ppp/pppos.c index bb4badb3..e1483042 100644 --- a/src/netif/ppp/pppos.c +++ b/src/netif/ppp/pppos.c @@ -528,6 +528,33 @@ pppos_destroy(ppp_pcb *ppp, void *ctx) } #if !NO_SYS +/** Pass received raw characters to PPPoS to be decoded through lwIP TCPIP thread. + * + * @param pcb PPP descriptor index, returned by pppos_create() + * @param data received data + * @param len length of received data + */ +err_t +pppos_input_tcpip(ppp_pcb *ppp, u_char *s, int l) +{ + struct pbuf *p, *n; + u8_t *cur; + + p = pbuf_alloc(PBUF_RAW, l, PBUF_POOL); + if (!p) { + return ERR_MEM; + } + + cur = s; + for (n = p; n; n = n->next) { + MEMCPY(n->payload, cur, n->len); + cur += n->len; + } + + return tcpip_input(p, ppp_netif(ppp)); +} + +/* called from TCPIP thread */ static err_t pppos_input_sys(struct pbuf *p, struct netif *inp) { ppp_pcb *ppp = (ppp_pcb*)inp->state; struct pbuf *n; @@ -565,7 +592,7 @@ PACK_STRUCT_END * thread safe. You should also avoid calling pppos_input() if PPPoS session * is not started yet. * - * @param pcb PPP descriptor index, returned by ppp_new() + * @param pcb PPP descriptor index, returned by pppos_create() * @param data received data * @param len length of received data */