framer-802154: Conditional compilation of security-related code
This commit is contained in:
parent
fb6d2270ab
commit
124dde25f3
3 changed files with 27 additions and 3 deletions
|
@ -63,6 +63,7 @@
|
||||||
|
|
||||||
#include "sys/cc.h"
|
#include "sys/cc.h"
|
||||||
#include "net/mac/frame802154.h"
|
#include "net/mac/frame802154.h"
|
||||||
|
#include "net/llsec/llsec802154.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -120,6 +121,7 @@ field_len(frame802154_t *p, field_length_t *flen)
|
||||||
flen->dest_addr_len = addr_len(p->fcf.dest_addr_mode & 3);
|
flen->dest_addr_len = addr_len(p->fcf.dest_addr_mode & 3);
|
||||||
flen->src_addr_len = addr_len(p->fcf.src_addr_mode & 3);
|
flen->src_addr_len = addr_len(p->fcf.src_addr_mode & 3);
|
||||||
|
|
||||||
|
#if LLSEC802154_SECURITY_LEVEL
|
||||||
/* Aux security header */
|
/* Aux security header */
|
||||||
if(p->fcf.security_enabled & 1) {
|
if(p->fcf.security_enabled & 1) {
|
||||||
flen->aux_sec_len = 5;
|
flen->aux_sec_len = 5;
|
||||||
|
@ -143,6 +145,7 @@ field_len(frame802154_t *p, field_length_t *flen)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#endif /* LLSEC802154_SECURITY_LEVEL */
|
||||||
}
|
}
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -220,6 +223,7 @@ frame802154_create(frame802154_t *p, uint8_t *buf)
|
||||||
buf[pos++] = p->src_addr[c - 1];
|
buf[pos++] = p->src_addr[c - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LLSEC802154_SECURITY_LEVEL
|
||||||
/* Aux header */
|
/* Aux header */
|
||||||
if(flen.aux_sec_len) {
|
if(flen.aux_sec_len) {
|
||||||
/* TODO Support key identifier mode !=0 */
|
/* TODO Support key identifier mode !=0 */
|
||||||
|
@ -227,6 +231,7 @@ frame802154_create(frame802154_t *p, uint8_t *buf)
|
||||||
memcpy(buf + pos, p->aux_hdr.frame_counter.u8, 4);
|
memcpy(buf + pos, p->aux_hdr.frame_counter.u8, 4);
|
||||||
pos += 4;
|
pos += 4;
|
||||||
}
|
}
|
||||||
|
#endif /* LLSEC802154_SECURITY_LEVEL */
|
||||||
|
|
||||||
return (int)pos;
|
return (int)pos;
|
||||||
}
|
}
|
||||||
|
@ -329,6 +334,7 @@ frame802154_parse(uint8_t *data, int len, frame802154_t *pf)
|
||||||
pf->src_pid = 0;
|
pf->src_pid = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LLSEC802154_SECURITY_LEVEL
|
||||||
if(fcf.security_enabled) {
|
if(fcf.security_enabled) {
|
||||||
pf->aux_hdr.security_control.security_level = p[0] & 7;
|
pf->aux_hdr.security_control.security_level = p[0] & 7;
|
||||||
pf->aux_hdr.security_control.key_id_mode = (p[0] >> 3) & 3;
|
pf->aux_hdr.security_control.key_id_mode = (p[0] >> 3) & 3;
|
||||||
|
@ -342,6 +348,7 @@ frame802154_parse(uint8_t *data, int len, frame802154_t *pf)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif /* LLSEC802154_SECURITY_LEVEL */
|
||||||
|
|
||||||
/* header length */
|
/* header length */
|
||||||
c = p - data;
|
c = p - data;
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
|
|
||||||
#include "net/mac/framer-802154.h"
|
#include "net/mac/framer-802154.h"
|
||||||
#include "net/mac/frame802154.h"
|
#include "net/mac/frame802154.h"
|
||||||
|
#include "net/llsec/llsec802154.h"
|
||||||
#include "net/packetbuf.h"
|
#include "net/packetbuf.h"
|
||||||
#include "lib/random.h"
|
#include "lib/random.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -102,9 +103,6 @@ create_frame(int type, int do_create)
|
||||||
|
|
||||||
/* Build the FCF. */
|
/* Build the FCF. */
|
||||||
params.fcf.frame_type = packetbuf_attr(PACKETBUF_ATTR_FRAME_TYPE);
|
params.fcf.frame_type = packetbuf_attr(PACKETBUF_ATTR_FRAME_TYPE);
|
||||||
if(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL)) {
|
|
||||||
params.fcf.security_enabled = 1;
|
|
||||||
}
|
|
||||||
params.fcf.frame_pending = packetbuf_attr(PACKETBUF_ATTR_PENDING);
|
params.fcf.frame_pending = packetbuf_attr(PACKETBUF_ATTR_PENDING);
|
||||||
if(linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &linkaddr_null)) {
|
if(linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &linkaddr_null)) {
|
||||||
params.fcf.ack_required = 0;
|
params.fcf.ack_required = 0;
|
||||||
|
@ -116,10 +114,15 @@ create_frame(int type, int do_create)
|
||||||
/* Insert IEEE 802.15.4 (2006) version bits. */
|
/* Insert IEEE 802.15.4 (2006) version bits. */
|
||||||
params.fcf.frame_version = FRAME802154_IEEE802154_2006;
|
params.fcf.frame_version = FRAME802154_IEEE802154_2006;
|
||||||
|
|
||||||
|
#if LLSEC802154_SECURITY_LEVEL
|
||||||
|
if(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL)) {
|
||||||
|
params.fcf.security_enabled = 1;
|
||||||
|
}
|
||||||
/* Setting security-related attributes */
|
/* Setting security-related attributes */
|
||||||
params.aux_hdr.security_control.security_level = packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL);
|
params.aux_hdr.security_control.security_level = packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL);
|
||||||
params.aux_hdr.frame_counter.u16[0] = packetbuf_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1);
|
params.aux_hdr.frame_counter.u16[0] = packetbuf_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1);
|
||||||
params.aux_hdr.frame_counter.u16[1] = packetbuf_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3);
|
params.aux_hdr.frame_counter.u16[1] = packetbuf_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3);
|
||||||
|
#endif /* LLSEC802154_SECURITY_LEVEL */
|
||||||
|
|
||||||
/* Increment and set the data sequence number. */
|
/* Increment and set the data sequence number. */
|
||||||
if(!do_create) {
|
if(!do_create) {
|
||||||
|
@ -241,10 +244,12 @@ parse(void)
|
||||||
/* packetbuf_set_attr(PACKETBUF_ATTR_RELIABLE, frame.fcf.ack_required);*/
|
/* packetbuf_set_attr(PACKETBUF_ATTR_RELIABLE, frame.fcf.ack_required);*/
|
||||||
packetbuf_set_attr(PACKETBUF_ATTR_PACKET_ID, frame.seq);
|
packetbuf_set_attr(PACKETBUF_ATTR_PACKET_ID, frame.seq);
|
||||||
|
|
||||||
|
#if LLSEC802154_SECURITY_LEVEL
|
||||||
/* Setting security-related attributes */
|
/* Setting security-related attributes */
|
||||||
packetbuf_set_attr(PACKETBUF_ATTR_SECURITY_LEVEL, frame.aux_hdr.security_control.security_level);
|
packetbuf_set_attr(PACKETBUF_ATTR_SECURITY_LEVEL, frame.aux_hdr.security_control.security_level);
|
||||||
packetbuf_set_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1, frame.aux_hdr.frame_counter.u16[0]);
|
packetbuf_set_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1, frame.aux_hdr.frame_counter.u16[0]);
|
||||||
packetbuf_set_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3, frame.aux_hdr.frame_counter.u16[1]);
|
packetbuf_set_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3, frame.aux_hdr.frame_counter.u16[1]);
|
||||||
|
#endif /* LLSEC802154_SECURITY_LEVEL */
|
||||||
|
|
||||||
PRINTF("15.4-IN: %2X", frame.fcf.frame_type);
|
PRINTF("15.4-IN: %2X", frame.fcf.frame_type);
|
||||||
PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
|
PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
|
||||||
|
|
|
@ -54,6 +54,7 @@
|
||||||
|
|
||||||
#include "contiki-conf.h"
|
#include "contiki-conf.h"
|
||||||
#include "net/linkaddr.h"
|
#include "net/linkaddr.h"
|
||||||
|
#include "net/llsec/llsec802154.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief The size of the packetbuf, in bytes
|
* \brief The size of the packetbuf, in bytes
|
||||||
|
@ -357,9 +358,11 @@ enum {
|
||||||
PACKETBUF_ATTR_NUM_REXMIT,
|
PACKETBUF_ATTR_NUM_REXMIT,
|
||||||
PACKETBUF_ATTR_PENDING,
|
PACKETBUF_ATTR_PENDING,
|
||||||
PACKETBUF_ATTR_FRAME_TYPE,
|
PACKETBUF_ATTR_FRAME_TYPE,
|
||||||
|
#if LLSEC802154_SECURITY_LEVEL
|
||||||
PACKETBUF_ATTR_SECURITY_LEVEL,
|
PACKETBUF_ATTR_SECURITY_LEVEL,
|
||||||
PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1,
|
PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1,
|
||||||
PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3,
|
PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3,
|
||||||
|
#endif /* LLSEC802154_SECURITY_LEVEL */
|
||||||
|
|
||||||
/* Scope 2 attributes: used between end-to-end nodes. */
|
/* Scope 2 attributes: used between end-to-end nodes. */
|
||||||
PACKETBUF_ATTR_HOPS,
|
PACKETBUF_ATTR_HOPS,
|
||||||
|
@ -377,6 +380,15 @@ enum {
|
||||||
PACKETBUF_ATTR_MAX
|
PACKETBUF_ATTR_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Define surrogates when 802.15.4 security is off */
|
||||||
|
#if !LLSEC802154_SECURITY_LEVEL
|
||||||
|
enum {
|
||||||
|
PACKETBUF_ATTR_SECURITY_LEVEL,
|
||||||
|
PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1,
|
||||||
|
PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3
|
||||||
|
};
|
||||||
|
#endif /* LLSEC802154_SECURITY_LEVEL */
|
||||||
|
|
||||||
#define PACKETBUF_NUM_ADDRS 4
|
#define PACKETBUF_NUM_ADDRS 4
|
||||||
#define PACKETBUF_NUM_ATTRS (PACKETBUF_ATTR_MAX - PACKETBUF_NUM_ADDRS)
|
#define PACKETBUF_NUM_ATTRS (PACKETBUF_ATTR_MAX - PACKETBUF_NUM_ADDRS)
|
||||||
#define PACKETBUF_ADDR_FIRST PACKETBUF_ADDR_SENDER
|
#define PACKETBUF_ADDR_FIRST PACKETBUF_ADDR_SENDER
|
||||||
|
|
Loading…
Reference in a new issue