IPv6: added uipbuf attributes similar to packetbuf

This commit is contained in:
Joakim Eriksson 2017-12-08 13:38:30 +01:00
parent 3e41a7d3e4
commit 941ddf35b8
2 changed files with 87 additions and 3 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, RISE SICS
* Copyright (c) 2017, RISE SICS, Yanzi Networks
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -31,7 +31,14 @@
*/
#include "contiki.h"
#include "uip.h"
#include "net/ipv6/uipbuf.h"
#include <string.h>
/*---------------------------------------------------------------------------*/
static uint16_t uipbuf_attrs[UIPBUF_ATTR_MAX];
/*---------------------------------------------------------------------------*/
/* Get the next header given the buffer - start indicates that this is
start of the IPv6 header - needs to be set to 0 when in an ext hdr */
uint8_t*
@ -54,7 +61,7 @@ uipbuf_get_next_header(uint8_t *buffer, uint16_t size, uint8_t *protocol, uint8_
return buffer + ext_len;
}
}
/*---------------------------------------------------------------------------*/
/* Get the final header given the buffer - that is assumed to be at start
of an IPv6 header */
uint8_t*
@ -69,3 +76,53 @@ uipbuf_get_last_header(uint8_t *buffer, uint16_t size, uint8_t *protocol)
}
return nbuf;
}
/*---------------------------------------------------------------------------*/
/**
* Common functions for uipbuf (attributes, etc).
*
*/
/*---------------------------------------------------------------------------*/
uint16_t
uipbuf_get_attr(uint8_t type)
{
if(type < UIPBUF_ATTR_MAX) {
return uipbuf_attrs[type];
}
return 0;
}
/*---------------------------------------------------------------------------*/
int
uipbuf_set_attr(uint8_t type, uint16_t value)
{
if(type < UIPBUF_ATTR_MAX) {
uipbuf_attrs[type] = value;
return 1;
}
return 0;
}
/*---------------------------------------------------------------------------*/
void
uipbuf_clear_attr(void)
{
memset(uipbuf_attrs, 0, sizeof(uipbuf_attrs));
}
/*---------------------------------------------------------------------------*/
void
uipbuf_set_attr_flag(uint16_t flag)
{
/* Assume only 16-bits for flags now */
uipbuf_attrs[UIPBUF_ATTR_FLAGS] |= flag;
}
/*---------------------------------------------------------------------------*/
void
uipbuf_clr_attr_flag(uint16_t flag)
{
uipbuf_attrs[UIPBUF_ATTR_FLAGS] &= ~flag;
}
/*---------------------------------------------------------------------------*/
uint16_t
uipbuf_is_attr_flag(uint16_t flag)
{
return (uipbuf_attrs[UIPBUF_ATTR_FLAGS] & flag) > 0;
}
/*---------------------------------------------------------------------------*/

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, RISE SICS
* Copyright (c) 2017, RISE SICS, Yanzi Networks
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -30,6 +30,9 @@
*
*/
#ifndef UIPBUF_H_
#define UIPBUF_H_
#include "contiki.h"
/* Get the next header given the buffer - start indicates that this is
@ -39,3 +42,27 @@ uint8_t* uipbuf_get_next_header(uint8_t *buffer, uint16_t size, uint8_t *protoco
/* Get the final header given the buffer - that is assumed to be at start
of an IPv6 header */
uint8_t* uipbuf_get_last_header(uint8_t *buffer, uint16_t size, uint8_t *protocol);
/* Attributes relating to the current packet in uipbuf */
uint16_t uipbuf_get_attr(uint8_t type);
void uipbuf_set_attr_flag(uint16_t flag);
void uipbuf_clr_attr_flag(uint16_t flag);
uint16_t uipbuf_is_attr_flag(uint16_t flag);
int uipbuf_set_attr(uint8_t type, uint16_t value);
void uipbuf_clear_attr(void);
/* These flags will be used for being */
#define UIPBUF_ATTR_FLAGS_6LOWPAN_NO_NHC_COMPRESSION 0x01
#define UIPBUF_ATTR_FLAGS_6LOWPAN_NO_PREFIX_COMPRESSION 0x02
enum {
UIPBUF_ATTR_LLSEC_LEVEL,
UIPBUF_ATTR_LLSEC_KEY_ID,
UIPBUF_ATTR_INTERFACE_ID,
UIPBUF_ATTR_PHYSICAL_NETWORK_ID,
UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS,
UIPBUF_ATTR_FLAGS,
UIPBUF_ATTR_MAX
};
#endif /* UIPBUF_H_ */