From 4774fe46243d403180e941c8ee1b3e2f3b2e930a Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Fri, 24 Mar 2017 11:59:30 -0400 Subject: [PATCH] ieee802154: Updated to match nuttx ieee802154 changes --- ieee802154/Makefile | 3 + ieee802154/common/ieee802154_addrparse.c | 133 ++++++++++++---------- ieee802154/common/ieee802154_addrstore.c | 75 ++++++++---- ieee802154/common/ieee802154_addrtostr.c | 10 +- ieee802154/common/ieee802154_getcca.c | 9 +- ieee802154/common/ieee802154_getchan.c | 9 +- ieee802154/common/ieee802154_setcca.c | 9 +- ieee802154/common/ieee802154_setchan.c | 7 +- ieee802154/common/ieee802154_setdevmode.c | 7 +- ieee802154/common/ieee802154_seteaddr.c | 7 +- ieee802154/common/ieee802154_setpanid.c | 7 +- ieee802154/common/ieee802154_setpromisc.c | 7 +- ieee802154/common/ieee802154_setsaddr.c | 7 +- ieee802154/coord/coord_main.c | 2 +- ieee802154/i8sak/i8sak_main.c | 27 ++--- include/ieee802154/ieee802154.h | 15 +-- 16 files changed, 192 insertions(+), 142 deletions(-) diff --git a/ieee802154/Makefile b/ieee802154/Makefile index 8c340caf9..55daf61c1 100644 --- a/ieee802154/Makefile +++ b/ieee802154/Makefile @@ -66,3 +66,6 @@ clean: $(foreach SDIR, $(SUBDIRS), $(SDIR)_clean) distclean: $(foreach SDIR, $(SUBDIRS), $(SDIR)_distclean) -include Make.dep + +.PHONY: preconfig +preconfig: diff --git a/ieee802154/common/ieee802154_addrparse.c b/ieee802154/common/ieee802154_addrparse.c index 91ee37d12..5ca114b1c 100644 --- a/ieee802154/common/ieee802154_addrparse.c +++ b/ieee802154/common/ieee802154_addrparse.c @@ -41,84 +41,97 @@ #include #include #include -#include -#include +#include +#include +#include "ieee802154/ieee802154.h" int ieee802154_addrparse(FAR struct ieee802154_packet_s *packet, FAR struct ieee802154_addr_s *dest, FAR struct ieee802154_addr_s *src) { - uint8_t fc1, fc2, daddr, saddr; + uint16_t frame_ctrl; int index=3; /* read fc */ - fc1 = packet->data[0]; - fc2 = packet->data[1]; - daddr = fc2 & IEEE802154_FC2_DADDR; - saddr = fc2 & IEEE802154_FC2_SADDR; + + frame_ctrl = packet->data[0]; + frame_ctrl |= packet->data[1] << 8; + + dest->ia_mode = (frame_ctrl & IEEE802154_FRAMECTRL_DADDR) + >> IEEE802154_FRAMECTRL_SHIFT_DADDR; + + + src->ia_mode = (frame_ctrl & IEEE802154_FRAMECTRL_SADDR) + >> IEEE802154_FRAMECTRL_SHIFT_SADDR; /* decode dest addr */ - if(daddr == IEEE802154_DADDR_SHORT) + switch (dest->ia_mode) { - memcpy(&dest->ia_panid, packet->data+index, 2); - index += 2; /* skip dest pan id */ - memcpy(&dest->ia_saddr, packet->data+index, 2); - index += 2; /* skip dest addr */ - dest->ia_len = 2; - } - else if(daddr == IEEE802154_DADDR_EXT) - { - memcpy(&dest->ia_panid, packet->data+index, 2); - index += 2; /* skip dest pan id */ - memcpy(dest->ia_eaddr, packet->data+index, 8); - index += 8; /* skip dest addr */ - dest->ia_len = 8; - } - else if(daddr == IEEE802154_DADDR_NONE) - { - dest->ia_len = 0; - } - else - { - return -EINVAL; + case IEEE802154_ADDRMODE_SHORT: + { + memcpy(&dest->ia_panid, packet->data+index, 2); + index += 2; /* skip dest pan id */ + memcpy(&dest->ia_saddr, packet->data+index, 2); + index += 2; /* skip dest addr */ + } + break; + + case IEEE802154_ADDRMODE_EXTENDED: + { + memcpy(&dest->ia_panid, packet->data+index, 2); + index += 2; /* skip dest pan id */ + memcpy(dest->ia_eaddr, packet->data+index, 8); + index += 8; /* skip dest addr */ + } + break; + + case IEEE802154_ADDRMODE_NONE: + break; + + default: + return -EINVAL; } - /* decode source pan id according to compression */ - if( (saddr == IEEE802154_SADDR_SHORT) || (saddr == IEEE802154_SADDR_EXT) ) - { - if(fc1 & IEEE802154_FC1_INTRA) - { - src->ia_panid = dest->ia_panid; - } - else - { - memcpy(&src->ia_panid, packet->data+index, 2); - index += 2; /*skip dest pan id*/ - } - } + if ((src->ia_mode == IEEE802154_ADDRMODE_SHORT) || + (src->ia_mode == IEEE802154_ADDRMODE_EXTENDED)) + { + /* If PANID compression, src PAN ID is same as dest */ + + if(frame_ctrl & IEEE802154_FRAMECTRL_INTRA) + { + src->ia_panid = dest->ia_panid; + } + else + { + memcpy(&src->ia_panid, packet->data+index, 2); + index += 2; /*skip dest pan id*/ + } + } /* decode source addr */ - if(saddr == IEEE802154_SADDR_SHORT) + switch (src->ia_mode) { - memcpy(&src->ia_saddr, packet->data+index, 2); - index += 2; /* skip dest addr */ - src->ia_len = 2; - } - else if(saddr == IEEE802154_SADDR_EXT) - { - memcpy(src->ia_eaddr, packet->data+index, 8); - index += 8; /* skip dest addr */ - src->ia_len = 8; - } - else if(saddr == IEEE802154_SADDR_NONE) - { - src->ia_len = 0; - } - else - { - return -EINVAL; + case IEEE802154_ADDRMODE_SHORT: + { + memcpy(&src->ia_saddr, packet->data+index, 2); + index += 2; /* skip src addr */ + } + break; + + case IEEE802154_ADDRMODE_EXTENDED: + { + memcpy(src->ia_eaddr, packet->data+index, 8); + index += 8; /* skip src addr */ + } + break; + + case IEEE802154_ADDRMODE_NONE: + break; + + default: + return -EINVAL; } return index; diff --git a/ieee802154/common/ieee802154_addrstore.c b/ieee802154/common/ieee802154_addrstore.c index 6b3aef2df..362244f9f 100644 --- a/ieee802154/common/ieee802154_addrstore.c +++ b/ieee802154/common/ieee802154_addrstore.c @@ -41,38 +41,55 @@ #include #include #include -#include -#include +#include +#include +#include "ieee802154/ieee802154.h" int ieee802154_addrstore(FAR struct ieee802154_packet_s *packet, FAR struct ieee802154_addr_s *dest, FAR struct ieee802154_addr_s *src) { + uint16_t frame_ctrl; int index=3; //skip fc and seq + /* Get the frame control word so we can manipulate it */ + + frame_ctrl = packet->data[0]; + frame_ctrl |= packet->data[1] << 8; + + + /* Clear the destination address mode */ + + frame_ctrl &= ~IEEE802154_FRAMECTRL_DADDR; + /* encode dest addr */ - if(dest == NULL || dest->ia_len == 0) + if(dest == NULL || dest->ia_mode == IEEE802154_ADDRMODE_NONE) { - packet->data[1] = (packet->data[1] & ~IEEE802154_FC2_DADDR) | IEEE802154_DADDR_NONE; + /* Set the destination address mode to none */ + + frame_ctrl |= IEEE802154_ADDRMODE_NONE << IEEE802154_FRAMECTRL_SHIFT_DADDR; } else { memcpy(packet->data+index, &dest->ia_panid, 2); index += 2; /* skip dest pan id */ - if(dest->ia_len == 2) + + /* Set the dest address mode field */ + + frame_ctrl |= dest->ia_mode << IEEE802154_FRAMECTRL_SHIFT_DADDR; + + if(dest->ia_mode == IEEE802154_ADDRMODE_SHORT) { memcpy(packet->data+index, &dest->ia_saddr, 2); index += 2; /* skip dest addr */ - packet->data[1] = (packet->data[1] & ~IEEE802154_FC2_DADDR) | IEEE802154_DADDR_SHORT; } - else if(dest->ia_len == 8) + else if(dest->ia_mode == IEEE802154_ADDRMODE_EXTENDED) { memcpy(packet->data+index, &dest->ia_panid, 2); index += 2; /* skip dest pan id */ memcpy(packet->data+index, dest->ia_eaddr, 8); index += 8; /* skip dest addr */ - packet->data[1] = (packet->data[1] & ~IEEE802154_FC2_DADDR) | IEEE802154_DADDR_EXT; } else { @@ -80,42 +97,57 @@ int ieee802154_addrstore(FAR struct ieee802154_packet_s *packet, } } - packet->data[0] &= ~IEEE802154_FC1_INTRA; - if( (dest != NULL && dest->ia_len != 0) && (src != NULL && src->ia_len != 0) ) + /* Clear the PAN ID Compression Field */ + + frame_ctrl &= ~IEEE802154_FRAMECTRL_INTRA; + + if( (dest != NULL && dest->ia_mode != IEEE802154_ADDRMODE_NONE) && + (src != NULL && src->ia_mode != IEEE802154_ADDRMODE_NONE) ) { /* we have both adresses, encode source pan id according to compression */ + if( dest->ia_panid == src->ia_panid) { - packet->data[0] |= IEEE802154_FC1_INTRA; + frame_ctrl |= IEEE802154_FRAMECTRL_INTRA; } } + /* Clear the source address mode */ + + frame_ctrl &= ~IEEE802154_FRAMECTRL_SADDR; + /* encode source addr */ - if(src == NULL || src->ia_len==0) + if(src == NULL || src->ia_mode == IEEE802154_ADDRMODE_NONE) { - packet->data[1] = (packet->data[1] & ~IEEE802154_FC2_SADDR) | IEEE802154_SADDR_NONE; + /* Set the source address mode to none */ + + frame_ctrl |= IEEE802154_ADDRMODE_NONE << IEEE802154_FRAMECTRL_SHIFT_SADDR; } else { - /*add src pan id if it was not compressed before*/ - if(!(packet->data[0] & IEEE802154_FC1_INTRA)) + /* add src pan id if it was not compressed before */ + + if(!(frame_ctrl & IEEE802154_FRAMECTRL_INTRA)) { memcpy(packet->data+index, &src->ia_panid, 2); index += 2; /*skip src pan id*/ } - if(src->ia_len == 2) + + /* Set the source address mode field */ + + frame_ctrl |= src->ia_mode << IEEE802154_FRAMECTRL_SHIFT_SADDR; + + if(src->ia_mode == IEEE802154_ADDRMODE_SHORT) { memcpy(packet->data+index, &src->ia_saddr, 2); index += 2; /* skip src addr */ - packet->data[1] = (packet->data[1] & ~IEEE802154_FC2_SADDR) | IEEE802154_SADDR_SHORT; } - else if(src->ia_len == 8) + else if(src->ia_mode == IEEE802154_ADDRMODE_EXTENDED) { memcpy(packet->data+index, src->ia_eaddr, 8); index += 8; /* skip src addr */ - packet->data[1] = (packet->data[1] & ~IEEE802154_FC2_SADDR) | IEEE802154_SADDR_EXT; } else { @@ -123,6 +155,9 @@ int ieee802154_addrstore(FAR struct ieee802154_packet_s *packet, } } + /* Copy the frame control word back to the buffer */ + + memcpy(packet->data, &frame_ctrl, 2); + return index; } - diff --git a/ieee802154/common/ieee802154_addrtostr.c b/ieee802154/common/ieee802154_addrtostr.c index 743b2fd55..24b33f318 100644 --- a/ieee802154/common/ieee802154_addrtostr.c +++ b/ieee802154/common/ieee802154_addrtostr.c @@ -40,8 +40,8 @@ #include #include #include -#include -#include +#include +#include "ieee802154/ieee802154.h" int ieee802154_addrtostr(FAR char *buf, int len, FAR struct ieee802154_addr_s *addr) { @@ -51,11 +51,11 @@ int ieee802154_addrtostr(FAR char *buf, int len, FAR struct ieee802154_addr_s *a uint16_t panid = addr->ia_panid; #endif - if(addr->ia_len == 0) + if(addr->ia_mode == IEEE802154_ADDRMODE_NONE) { return snprintf(buf, len, "none"); } - else if(addr->ia_len == 2) + else if(addr->ia_mode == IEEE802154_ADDRMODE_SHORT) { #ifndef CONFIG_BIG_ENDIAN uint16_t saddr = ((addr->ia_saddr & 0xff)<<8) | ((addr->ia_saddr>>8) & 0xff); @@ -64,7 +64,7 @@ int ieee802154_addrtostr(FAR char *buf, int len, FAR struct ieee802154_addr_s *a #endif return snprintf(buf, len, "%04X/%04X", panid, saddr); } - else if(addr->ia_len == 8) + else if(addr->ia_mode == IEEE802154_ADDRMODE_EXTENDED) { int i; int off = snprintf(buf, len, "%04X/", panid); diff --git a/ieee802154/common/ieee802154_getcca.c b/ieee802154/common/ieee802154_getcca.c index 5df88e617..ed1846635 100644 --- a/ieee802154/common/ieee802154_getcca.c +++ b/ieee802154/common/ieee802154_getcca.c @@ -42,15 +42,16 @@ #include #include #include -#include -#include +#include +#include +#include "ieee802154/ieee802154.h" int ieee802154_getcca(int fd, FAR struct ieee802154_cca_s *cca) { - int ret = ioctl(fd, MAC854IOCGCCA, (unsigned long)cca ); + int ret = ioctl(fd, PHY802154IOC_GET_CCA, (unsigned long)cca ); if (ret<0) { - printf("MAC854IOCGCCA failed\n"); + printf("PHY802154IOC_GET_CCA failed\n"); } return ret; } diff --git a/ieee802154/common/ieee802154_getchan.c b/ieee802154/common/ieee802154_getchan.c index 93bede8a2..6454802cd 100644 --- a/ieee802154/common/ieee802154_getchan.c +++ b/ieee802154/common/ieee802154_getchan.c @@ -42,15 +42,16 @@ #include #include #include -#include -#include +#include +#include +#include "ieee802154/ieee802154.h" int ieee802154_getchan(int fd, FAR uint8_t *chan) { - int ret = ioctl(fd, MAC854IOCGCHAN, (unsigned long)chan ); + int ret = ioctl(fd, PHY802154IOC_GET_CHAN, (unsigned long)chan ); if (ret<0) { - printf("MAC854IOCGCHAN failed\n"); + printf("PHY802154IOC_GET_CHAN failed\n"); } return ret; } diff --git a/ieee802154/common/ieee802154_setcca.c b/ieee802154/common/ieee802154_setcca.c index 32515b879..5af949201 100644 --- a/ieee802154/common/ieee802154_setcca.c +++ b/ieee802154/common/ieee802154_setcca.c @@ -42,15 +42,16 @@ #include #include #include -#include -#include +#include +#include +#include "ieee802154/ieee802154.h" int ieee802154_setcca(int fd, FAR struct ieee802154_cca_s *cca) { - int ret = ioctl(fd, MAC854IOCSCCA, (unsigned long)cca ); + int ret = ioctl(fd, PHY802154IOC_SET_CCA, (unsigned long)cca ); if (ret<0) { - printf("MAC854IOCSCCA failed\n"); + printf("PHY802154IOC_SET_CCA failed\n"); } return ret; } diff --git a/ieee802154/common/ieee802154_setchan.c b/ieee802154/common/ieee802154_setchan.c index b1f1d3d50..d91556039 100644 --- a/ieee802154/common/ieee802154_setchan.c +++ b/ieee802154/common/ieee802154_setchan.c @@ -42,14 +42,15 @@ #include #include #include -#include +#include +#include "ieee802154/ieee802154.h" int ieee802154_setchan(int fd, uint8_t chan) { - int ret = ioctl(fd, MAC854IOCSCHAN, (unsigned long)chan ); + int ret = ioctl(fd, PHY802154IOC_SET_CHAN, (unsigned long)chan ); if (ret<0) { - printf("MAC854IOCSCHAN failed\n"); + printf("PHY802154IOC_SET_CHAN failed\n"); } return ret; } diff --git a/ieee802154/common/ieee802154_setdevmode.c b/ieee802154/common/ieee802154_setdevmode.c index 6eae328b4..8b4d6f297 100644 --- a/ieee802154/common/ieee802154_setdevmode.c +++ b/ieee802154/common/ieee802154_setdevmode.c @@ -42,14 +42,15 @@ #include #include #include -#include +#include +#include "ieee802154/ieee802154.h" int ieee802154_setdevmode(int fd, uint8_t devmode) { - int ret = ioctl(fd, MAC854IOCSDEVMODE, (unsigned long)devmode ); + int ret = ioctl(fd, PHY802154IOC_SET_DEVMODE, (unsigned long)devmode ); if (ret<0) { - printf("MAC854IOCSDEVMODE failed\n"); + printf("PHY802154IOC_SET_DEVMODE failed\n"); } return ret; } diff --git a/ieee802154/common/ieee802154_seteaddr.c b/ieee802154/common/ieee802154_seteaddr.c index 251f4234a..1eafcb8d0 100644 --- a/ieee802154/common/ieee802154_seteaddr.c +++ b/ieee802154/common/ieee802154_seteaddr.c @@ -42,14 +42,15 @@ #include #include #include -#include +#include +#include "ieee802154/ieee802154.h" int ieee802154_seteaddr(int fd, uint8_t *eaddr) { - int ret = ioctl(fd, MAC854IOCSEADDR, (unsigned long)eaddr ); + int ret = ioctl(fd, PHY802154IOC_SET_EADDR, (unsigned long)eaddr ); if (ret<0) { - printf("MAC854IOCSEADDR failed\n"); + printf("PHY802154IOC_SET_EADDR failed\n"); } return ret; } diff --git a/ieee802154/common/ieee802154_setpanid.c b/ieee802154/common/ieee802154_setpanid.c index 4fd2a862c..270a96cdd 100644 --- a/ieee802154/common/ieee802154_setpanid.c +++ b/ieee802154/common/ieee802154_setpanid.c @@ -42,14 +42,15 @@ #include #include #include -#include +#include +#include "ieee802154/ieee802154.h" int ieee802154_setpanid(int fd, uint16_t panid) { - int ret = ioctl(fd, MAC854IOCSPANID, (unsigned long)panid ); + int ret = ioctl(fd, PHY802154IOC_SET_PANID, (unsigned long)panid ); if (ret<0) { - printf("MAC854IOCSPANID failed\n"); + printf("PHY802154IOC_SET_PANID failed\n"); } return ret; } diff --git a/ieee802154/common/ieee802154_setpromisc.c b/ieee802154/common/ieee802154_setpromisc.c index 1ba2cc9c1..abd5f932e 100644 --- a/ieee802154/common/ieee802154_setpromisc.c +++ b/ieee802154/common/ieee802154_setpromisc.c @@ -43,14 +43,15 @@ #include #include #include -#include +#include +#include "ieee802154/ieee802154.h" int ieee802154_setpromisc(int fd, bool promisc) { - int ret = ioctl(fd, MAC854IOCSPROMISC, (unsigned long)promisc ); + int ret = ioctl(fd, PHY802154IOC_SET_PROMISC, (unsigned long)promisc ); if (ret<0) { - printf("MAC854IOCSPROMISC failed\n"); + printf("PHY802154IOC_SET_PROMISC failed\n"); } return ret; } diff --git a/ieee802154/common/ieee802154_setsaddr.c b/ieee802154/common/ieee802154_setsaddr.c index a820c77fe..6d924c141 100644 --- a/ieee802154/common/ieee802154_setsaddr.c +++ b/ieee802154/common/ieee802154_setsaddr.c @@ -42,14 +42,15 @@ #include #include #include -#include +#include +#include "ieee802154/ieee802154.h" int ieee802154_setsaddr(int fd, uint16_t saddr) { - int ret = ioctl(fd, MAC854IOCSSADDR, (unsigned long)saddr ); + int ret = ioctl(fd, PHY802154IOC_SET_SADDR, (unsigned long)saddr ); if (ret<0) { - printf("MAC854IOCSSADDR failed\n"); + printf("PHY802154IOC_SET_SADDR failed\n"); } return ret; } diff --git a/ieee802154/coord/coord_main.c b/ieee802154/coord/coord_main.c index 1ef7d174a..6d3665db8 100644 --- a/ieee802154/coord/coord_main.c +++ b/ieee802154/coord/coord_main.c @@ -68,7 +68,7 @@ #include #include -#include +#include #include diff --git a/ieee802154/i8sak/i8sak_main.c b/ieee802154/i8sak/i8sak_main.c index b4dbc025c..5704646a3 100644 --- a/ieee802154/i8sak/i8sak_main.c +++ b/ieee802154/i8sak/i8sak_main.c @@ -59,9 +59,10 @@ #include #include #include -#include -#include -#include +#include +#include +#include +#include "ieee802154/ieee802154.h" /**************************************************************************** * Definitions @@ -97,7 +98,7 @@ int energy_scan(int fd) printf("Device is not an IEEE 802.15.4 interface!\n"); return ret; } - ret = ioctl(fd, MAC854IOCGED, (unsigned long)&energy); + ret = ioctl(fd, PHY802154IOC_ENERGYDETECT, (unsigned long)&energy); if (ret<0) { printf("Device is not an IEEE 802.15.4 interface!\n"); @@ -153,10 +154,10 @@ static int status(int fd) /* Get information */ - ret = ioctl(fd, MAC854IOCGPANID, (unsigned long)&panid); + ret = ioctl(fd, PHY802154IOC_GET_PANID, (unsigned long)&panid); if (ret) { - printf("MAC854IOCGPANID failed\n"); + printf("PHY802154IOC_GET_PANID failed\n"); return ret; } @@ -166,22 +167,22 @@ static int status(int fd) return ret; } - ret = ioctl(fd, MAC854IOCGSADDR, (unsigned long)&saddr); + ret = ioctl(fd, PHY802154IOC_GET_SADDR, (unsigned long)&saddr); if (ret) { - printf("MAC854IOCGSADDR failed\n"); + printf("PHY802154IOC_GET_SADDR failed\n"); return ret; } - ret = ioctl(fd, MAC854IOCGEADDR, (unsigned long)&eaddr[0]); + ret = ioctl(fd, PHY802154IOC_GET_EADDR, (unsigned long)&eaddr[0]); if (ret) { - printf("MAC854IOCGEADR failed\n"); + printf("PHY802154IOC_GET_EADDR failed\n"); return ret; } - ret = ioctl(fd, MAC854IOCGPROMISC, (unsigned long)&promisc); + ret = ioctl(fd, PHY802154IOC_GET_PROMISC, (unsigned long)&promisc); if (ret) { - printf("MAC854IOCGPROMISC failed\n"); + printf("PHY802154IOC_GET_PROMISC failed\n"); return ret; } ret = ieee802154_getcca(fd, &cca); @@ -548,7 +549,7 @@ data_error: gTxPacket.data[gTxPacket.len++] = 0x03; //mac command, no ack, no panid compression gTxPacket.data[gTxPacket.len++] = 0x00; //short destination address, no source address gTxPacket.data[gTxPacket.len++] = 0; //seq - dest.ia_len = 2; + dest.ia_mode = IEEE802154_ADDRMODE_SHORT; dest.ia_panid = 0xFFFF; dest.ia_saddr = 0xFFFF; diff --git a/include/ieee802154/ieee802154.h b/include/ieee802154/ieee802154.h index d506ded7a..0fceb7430 100644 --- a/include/ieee802154/ieee802154.h +++ b/include/ieee802154/ieee802154.h @@ -38,19 +38,8 @@ #include #include - -struct ieee802154_addr_s -{ - uint8_t ia_len; /* structure length NOT including panid, so 2/8*/ - uint16_t ia_panid; - union { - uint16_t _ia_saddr; - uint8_t _ia_eaddr[8]; - } ia_addr; -#define ia_saddr ia_addr._ia_saddr -#define ia_eaddr ia_addr._ia_eaddr -}; -#define IEEE802154_ADDRSTRLEN 22 /* (4+1+8*2) */ +#include +#include int ieee802154_setchan (int fd, uint8_t chan); int ieee802154_getchan (int fd, FAR uint8_t *chan);