From 00d73408dc180e9b9c5d8c2dc4ad01da5712c4e0 Mon Sep 17 00:00:00 2001 From: chrysn Date: Thu, 17 Jan 2013 17:06:22 +0100 Subject: [PATCH] porting required to get a minimal example to build with lwip stack --- address.h | 18 ++++++++++++++++++ config.h.lwip | 19 +++++++++++++++++++ debug.c | 3 +++ endian.h | 13 +++++++++++++ net.c | 3 +++ pdu.c | 3 +++ 6 files changed, 59 insertions(+) create mode 100644 config.h.lwip create mode 100644 endian.h diff --git a/address.h b/address.h index b37fe635..8122d711 100644 --- a/address.h +++ b/address.h @@ -35,6 +35,24 @@ #include #endif +#ifdef WITH_LWIP +#include + +typedef struct __coap_address_t { + unsigned char size; + struct ip_addr addr; +} __coap_address_t; + +#define coap_address_t __coap_address_t + +/* FIXME oversimplification: just assuming it's an ipv4 address instead of + * looking up the appropraite lwip function */ + +#define _coap_address_equals_impl(A, B) ((A)->addr.addr == (B)->addr.addr) + +#define _coap_is_mcast_impl(Address) 0 + +#endif /* WITH_LWIP */ #ifdef WITH_CONTIKI #include "uip.h" diff --git a/config.h.lwip b/config.h.lwip new file mode 100644 index 00000000..a26e07ef --- /dev/null +++ b/config.h.lwip @@ -0,0 +1,19 @@ +#ifndef _CONFIG_H_ +#define _CONFIG_H_ + +#include +#include + +#define WITH_LWIP 1 + +#define assert(x) LWIP_ASSERT("CoAP assert failed", x) + +/* it's just provided by libc. i hope we don't get too many of those, as + * actually we'd need autotools again to find out what environment we're + * building in */ +#define HAVE_STRNLEN 1 + +/* provide what usually resides in arpa/inet.h: ntohs and htons. maybe it'd be a better way to just have an arpa/inet.h compatibility file in lwip? */ +#define HAVE_ENDIAN_H 1 + +#endif /* _CONFIG_H_ */ diff --git a/debug.c b/debug.c index dcf771f3..18f5ed70 100644 --- a/debug.c +++ b/debug.c @@ -20,6 +20,9 @@ #ifdef HAVE_ARPA_INET_H #include #endif +#ifdef HAVE_ENDIAN_H +#include "endian.h" +#endif #ifdef HAVE_TIME_H #include diff --git a/endian.h b/endian.h new file mode 100644 index 00000000..abbc183d --- /dev/null +++ b/endian.h @@ -0,0 +1,13 @@ +/* endianness helpers for lwip port */ + +/* FIXME: i'm sure there is something in lwip we can use */ + +#include + +/* we're on little endian, ntohs & co swap */ +static inline uint16_t ntohs(uint16_t x) +{ + return (x << 8) | (x >> 8); +} + +#define htons ntohs diff --git a/net.c b/net.c index 52460519..10d52b17 100644 --- a/net.c +++ b/net.c @@ -25,6 +25,9 @@ #ifdef HAVE_ARPA_INET_H #include #endif +#ifdef HAVE_ENDIAN_H +#include "endian.h" +#endif #include "debug.h" #include "mem.h" diff --git a/pdu.c b/pdu.c index ce324731..a2655c56 100644 --- a/pdu.c +++ b/pdu.c @@ -18,6 +18,9 @@ #ifdef HAVE_ARPA_INET_H #include #endif +#ifdef HAVE_ENDIAN_H +#include "endian.h" +#endif #include "debug.h" #include "pdu.h"