From 282e1601efcf1f518ef4a500593e119da0ae07c8 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Fri, 2 Mar 2018 12:56:55 +0100 Subject: [PATCH] finally got zepif running --- src/netif/lowpan6.c | 2 +- src/netif/zepif.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/netif/lowpan6.c b/src/netif/lowpan6.c index 3d92db00..6d23b3f9 100644 --- a/src/netif/lowpan6.c +++ b/src/netif/lowpan6.c @@ -409,7 +409,7 @@ lowpan6_frag(struct netif *netif, struct pbuf *p, const struct ieee_802154_addr MIB2_STATS_NETIF_INC(netif, ifoutdiscards); return ERR_MEM; } - LWIP_ASSERT("this needs a pbuf in one piece", p->len == p->tot_len); + LWIP_ASSERT("this needs a pbuf in one piece", p_frag->len == p_frag->tot_len); /* Write IEEE 802.15.4 header. */ buffer = (u8_t *)p_frag->payload; diff --git a/src/netif/zepif.c b/src/netif/zepif.c index 66ecac87..1df65474 100644 --- a/src/netif/zepif.c +++ b/src/netif/zepif.c @@ -55,6 +55,7 @@ #include "netif/lowpan6.h" #include "lwip/udp.h" +#include "lwip/timeouts.h" #include /** Define this to 1 to loop back TX packets for testing */ @@ -92,6 +93,18 @@ struct zepif_state { u32_t seqno; }; +static u8_t zep_lowpan_timer_running; + +/* Helper function that calls the 6LoWPAN timer and reschedules itself */ +static void +zep_lowpan_timer(void *arg) +{ + lowpan6_tmr(); + if (zep_lowpan_timer_running) { + sys_timeout(LOWPAN6_TMR_INTERVAL, zep_lowpan_timer, arg); + } +} + /* Pass received pbufs into 6LowPAN netif */ static void zepif_udp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, @@ -138,6 +151,9 @@ zepif_udp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, if (pbuf_remove_header(p, sizeof(struct zep_hdr))) { goto err_return; } + /* TODO Check CRC? */ + /* remove CRC trailer */ + pbuf_realloc(p, p->tot_len - 2); /* Call tcpip_6lowpan_input here, not netif->input as we know the direct call * stack won't work as we could enter udp_input twice. */ @@ -259,6 +275,12 @@ zepif_init(struct netif *netif) netif->hwaddr[0] &= 0xfc; } netif->linkoutput = zepif_linkoutput; + + if (!zep_lowpan_timer_running) { + sys_timeout(LOWPAN6_TMR_INTERVAL, zep_lowpan_timer, NULL); + zep_lowpan_timer_running = 1; + } + return ERR_OK; }