add 802154 From: Jon Smirl --- config.in | 1 lib/Makefile | 2 - lib/hw.c | 8 +++ lib/ieee802154.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/net-features.h | 7 +++ 5 files changed, 154 insertions(+), 1 deletions(-) create mode 100644 lib/ieee802154.c diff --git a/config.in b/config.in index 69a2c48..8c89112 100644 --- a/config.in +++ b/config.in @@ -84,6 +84,7 @@ bool 'IrDA support' HAVE_HWIRDA y bool 'Econet hardware support' HAVE_HWEC y bool 'Generic EUI-64 hardware support' HAVE_HWEUI64 y bool 'InfiniBand hardware support' HAVE_HWIB y +bool 'IEEE 802.15.4 hardware support' HAVE_HW802154 y * * * Other Features. diff --git a/lib/Makefile b/lib/Makefile index 431f258..b0a607d 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -16,7 +16,7 @@ # -HWOBJS = hw.o loopback.o slip.o ether.o ax25.o ppp.o arcnet.o tr.o tunnel.o frame.o sit.o rose.o ash.o fddi.o hippi.o hdlclapb.o strip.o irda.o ec_hw.o x25.o eui64.o ib.o +HWOBJS = hw.o loopback.o slip.o ether.o ax25.o ppp.o arcnet.o tr.o tunnel.o frame.o sit.o rose.o ash.o fddi.o hippi.o hdlclapb.o strip.o irda.o ec_hw.o x25.o eui64.o ib.o ieee802154.o AFOBJS = unix.o inet.o inet6.o ax25.o ipx.o ddp.o ipx.o netrom.o af.o rose.o econet.o x25.o AFGROBJS = inet_gr.o inet6_gr.o ipx_gr.o ddp_gr.o netrom_gr.o ax25_gr.o rose_gr.o getroute.o x25_gr.o AFSROBJS = inet_sr.o inet6_sr.o netrom_sr.o ipx_sr.o setroute.o x25_sr.o diff --git a/lib/hw.c b/lib/hw.c index 7d081f6..62f4f6c 100644 --- a/lib/hw.c +++ b/lib/hw.c @@ -77,6 +77,8 @@ extern struct hwtype ib_hwtype; extern struct hwtype eui64_hwtype; +extern struct hwtype ieee802154_hwtype; + static struct hwtype *hwtypes[] = { @@ -154,6 +156,9 @@ static struct hwtype *hwtypes[] = #if HAVE_HWEUI64 &eui64_hwtype, #endif +#if HAVE_HW802154 + &ieee802154_hwtype, +#endif &unspec_hwtype, NULL }; @@ -233,6 +238,9 @@ void hwinit() #if HAVE_HWEUI64 eui64_hwtype.title = _("Generic EUI-64"); #endif +#if HAVE_HW802154 + ieee802154_hwtype.title = _("IEEE 802.15.4"); +#endif sVhwinit = 1; } diff --git a/lib/ieee802154.c b/lib/ieee802154.c new file mode 100644 index 0000000..fc62914 --- /dev/null +++ b/lib/ieee802154.c @@ -0,0 +1,137 @@ +/* + * lib/ieee802154.c This file contains an implementation of the 802.15.4 + * support functions. + * + * Version: $Id $ + * + * Copyright 2010, Jon Smirl + * + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. + */ +#include "config.h" + +#if HAVE_HW802154 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "net-support.h" +#include "pathnames.h" +#include "intl.h" +#include "util.h" + +extern struct hwtype ieee802154_hwtype; + + +/* Display an 802.15.4 address in readable format. */ +static char *pr_802154(unsigned char *ptr) +{ + static char buff[64]; + + snprintf(buff, sizeof(buff), "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", + (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377), + (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377), + (ptr[5] & 0377), (ptr[6] & 0377) + ); + return (buff); +} + + +/* Input an 802.15.4 address and convert to binary. */ +static int in_802154(char *bufp, struct sockaddr *sap) +{ + unsigned char *ptr; + char c, *orig; + int i; + unsigned val; + + sap->sa_family = ieee802154_hwtype.type; + ptr = sap->sa_data; + + i = 0; + orig = bufp; + while ((*bufp != '\0') && (i < IEEE802154_ADDR_LEN)) { + val = 0; + c = *bufp++; + if (isdigit(c)) + val = c - '0'; + else if (c >= 'a' && c <= 'f') + val = c - 'a' + 10; + else if (c >= 'A' && c <= 'F') + val = c - 'A' + 10; + else { +#ifdef DEBUG + fprintf(stderr, _("in_802154(%s): invalid 802.15.4 address!\n"), orig); +#endif + errno = EINVAL; + return (-1); + } + val <<= 4; + c = *bufp; + if (isdigit(c)) + val |= c - '0'; + else if (c >= 'a' && c <= 'f') + val |= c - 'a' + 10; + else if (c >= 'A' && c <= 'F') + val |= c - 'A' + 10; + else if (c == ':' || c == 0) + val >>= 4; + else { +#ifdef DEBUG + fprintf(stderr, _("in_802154(%s): invalid 802.15.4 address!\n"), orig); +#endif + errno = EINVAL; + return (-1); + } + if (c != 0) + bufp++; + *ptr++ = (unsigned char) (val & 0377); + i++; + + /* We might get a semicolon here - not required. */ + if (*bufp == ':') { + if (i == IEEE802154_ADDR_LEN) { +#ifdef DEBUG + fprintf(stderr, _("in_802154(%s): trailing : ignored!\n"), + orig) +#endif + ; /* nothing */ + } + bufp++; + } + } + + /* That's it. Any trailing junk? */ + if ((i == IEEE802154_ADDR_LEN) && (*bufp != '\0')) { +#ifdef DEBUG + fprintf(stderr, _("in_802154(%s): trailing junk!\n"), orig); + errno = EINVAL; + return (-1); +#endif + } +#ifdef DEBUG + fprintf(stderr, "in_802154(%s): %s\n", orig, pr_802154(sap->sa_data)); +#endif + + return (0); +} + + +struct hwtype ieee802154_hwtype = +{ + "ieee802154", NULL, /*"IEEE 802.15.4", */ ARPHRD_IEEE802154, IEEE802154_ADDR_LEN, + pr_802154, in_802154, NULL +}; + + +#endif /* HAVE_HW802154 */ diff --git a/lib/net-features.h b/lib/net-features.h index e52a3c3..865b8e9 100644 --- a/lib/net-features.h +++ b/lib/net-features.h @@ -302,6 +302,13 @@ static char *Features = "-" #endif "EUI64 " + +#if HAVE_HW802154 +"+" +#else +"-" +#endif +"802.15.4 " ;