uip: Support for IEEE 802.15.4 short addresses

This commit is contained in:
kkrentz 2018-04-24 08:56:11 -07:00
parent f93c334ef1
commit 21dd6209ff
7 changed files with 34 additions and 18 deletions

View File

@ -70,11 +70,8 @@ ieee_addr_cpy_to(uint8_t *dst, uint8_t len)
if(((uint8_t *)IEEE_ADDR_LOCATION)[3] == oui_ti[0]
&& ((uint8_t *)IEEE_ADDR_LOCATION)[2] == oui_ti[1]
&& ((uint8_t *)IEEE_ADDR_LOCATION)[1] == oui_ti[2]) {
for(i = 0; i < len / 2; i++) {
dst[i] = ((uint8_t *)IEEE_ADDR_LOCATION)[len / 2 - 1 - i];
}
for(i = 0; i < len / 2; i++) {
dst[i + len / 2] = ((uint8_t *)IEEE_ADDR_LOCATION)[len - 1 - i];
for(i = 0; i < len; i++) {
dst[len - i - 1] = ((uint8_t *)IEEE_ADDR_LOCATION)[i < 4 ? i + 4 : i - 4];
}
} else {
for(i = 0; i < len; i++) {

View File

@ -193,7 +193,7 @@ slip_radio_cmd_handler(const uint8_t *data, int len)
/* this is just a test so far... just to see if it works */
uip_buf[0] = '!';
uip_buf[1] = 'M';
for(i = 0; i < 8; i++) {
for(i = 0; i < UIP_LLADDR_LEN; i++) {
uip_buf[2 + i] = uip_lladdr.addr[i];
}
uip_len = 10;

View File

@ -553,8 +553,6 @@ uip_ds6_select_src(uip_ipaddr_t *src, uip_ipaddr_t *dst)
void
uip_ds6_set_addr_iid(uip_ipaddr_t *ipaddr, uip_lladdr_t *lladdr)
{
/* We consider only links with IEEE EUI-64 identifier or
* IEEE 48-bit MAC addresses */
#if (UIP_LLADDR_LEN == 8)
memcpy(ipaddr->u8 + 8, lladdr, UIP_LLADDR_LEN);
ipaddr->u8[8] ^= 0x02;
@ -564,11 +562,19 @@ uip_ds6_set_addr_iid(uip_ipaddr_t *ipaddr, uip_lladdr_t *lladdr)
ipaddr->u8[12] = 0xfe;
memcpy(ipaddr->u8 + 13, (uint8_t *)lladdr + 3, 3);
ipaddr->u8[8] ^= 0x02;
#elif (UIP_LLADDR_LEN == 2)
/* derive IID as per RFC 6282 */
ipaddr->u8[8 + 0] = 0x00;
ipaddr->u8[8 + 1] = 0x00;
ipaddr->u8[8 + 2] = 0x00;
ipaddr->u8[8 + 3] = 0xFF;
ipaddr->u8[8 + 4] = 0xFE;
ipaddr->u8[8 + 5] = 0x00;
memcpy(ipaddr->u8 + 8 + 6, lladdr, UIP_LLADDR_LEN);
#else
#error uip-ds6.c cannot build interface address when UIP_LLADDR_LEN is not 6 or 8
#error uip-ds6.c cannot build interface address when UIP_LLADDR_LEN is not 6, 8, or 2
#endif
}
/*---------------------------------------------------------------------------*/
void
uip_ds6_set_lladdr_from_iid(uip_lladdr_t *lladdr, const uip_ipaddr_t *ipaddr)
@ -576,8 +582,10 @@ uip_ds6_set_lladdr_from_iid(uip_lladdr_t *lladdr, const uip_ipaddr_t *ipaddr)
#if (UIP_LLADDR_LEN == 8)
memcpy(lladdr, ipaddr->u8 + 8, UIP_LLADDR_LEN);
lladdr->addr[0] ^= 0x02;
#elif (UIP_LLADDR_LEN == 2)
memcpy(lladdr, ipaddr->u8 + 6, UIP_LLADDR_LEN);
#else
#error uip-ds6.c cannot build lladdr address when UIP_LLADDR_LEN is not 8
#error uip-ds6.c cannot build lladdr address when UIP_LLADDR_LEN is not 8 or 2
#endif
}

View File

@ -81,6 +81,7 @@
#include "net/ipv6/uipopt.h"
#include "net/ipv6/uipbuf.h"
#include "net/linkaddr.h"
/* For memcmp */
#include <string.h>
@ -107,14 +108,16 @@ typedef uip_ip4addr_t uip_ipaddr_t;
/*---------------------------------------------------------------------------*/
#define UIP_802154_SHORTADDR_LEN 2
#define UIP_802154_LONGADDR_LEN 8
/** \brief 16 bit 802.15.4 address */
typedef struct uip_802154_shortaddr {
uint8_t addr[2];
uint8_t addr[UIP_802154_SHORTADDR_LEN];
} uip_802154_shortaddr;
/** \brief 64 bit 802.15.4 address */
typedef struct uip_802154_longaddr {
uint8_t addr[8];
uint8_t addr[UIP_802154_LONGADDR_LEN];
} uip_802154_longaddr;
/** \brief 802.11 address */
@ -134,11 +137,15 @@ typedef struct uip_eth_addr {
#if UIP_CONF_LL_802154
/** \brief 802.15.4 address */
#if LINKADDR_SIZE == UIP_802154_LONGADDR_LEN
typedef uip_802154_longaddr uip_lladdr_t;
#define UIP_802154_SHORTADDR_LEN 2
#define UIP_802154_LONGADDR_LEN 8
#elif LINKADDR_SIZE == UIP_802154_SHORTADDR_LEN
typedef uip_802154_shortaddr uip_lladdr_t;
#else /* LINKADDR_SIZE == 8 */
#error unsupported configuration of LINKADDR_SIZE
#endif /* LINKADDR_SIZE == 8 */
/** \brief Link layer address length */
#define UIP_LLADDR_LEN UIP_802154_LONGADDR_LEN
#define UIP_LLADDR_LEN LINKADDR_SIZE
#else /*UIP_CONF_LL_802154*/
#if UIP_CONF_LL_80211
/** \brief 802.11 address */

View File

@ -95,7 +95,7 @@ slip_input_callback(void)
int j;
/* this is just a test so far... just to see if it works */
uip_buf[0] = '!';
for(j = 0; j < 8; j++) {
for(j = 0; j < UIP_LLADDR_LEN; j++) {
uip_buf[2 + j * 2] = hexchar[uip_lladdr.addr[j] >> 4];
uip_buf[3 + j * 2] = hexchar[uip_lladdr.addr[j] & 15];
}

View File

@ -183,7 +183,7 @@ border_router_cmd_handler(const uint8_t *data, int len)
/* this is just a test so far... just to see if it works */
buf[0] = '!';
buf[1] = 'M';
for(j = 0; j < 8; j++) {
for(j = 0; j < UIP_LLADDR_LEN; j++) {
buf[2 + j * 2] = hexchar[uip_lladdr.addr[j] >> 4];
buf[3 + j * 2] = hexchar[uip_lladdr.addr[j] & 15];
}

View File

@ -155,7 +155,11 @@ log_lladdr_compact(const linkaddr_t *lladdr)
if(lladdr == NULL || linkaddr_cmp(lladdr, &linkaddr_null)) {
LOG_OUTPUT("LL-NULL");
} else {
#if LINKADDR_SIZE == 8
LOG_OUTPUT("LL-%04x", UIP_HTONS(lladdr->u16[LINKADDR_SIZE/2-1]));
#elif LINKADDR_SIZE == 2
LOG_OUTPUT("LL-%04x", UIP_HTONS(lladdr->u16));
#endif
}
}
/*---------------------------------------------------------------------------*/