52 #include "net/nbr-table.h"
57 #define WITH_ENCRYPTION (LLSEC802154_SECURITY_LEVEL & (1 << 2))
59 #ifdef NONCORESEC_CONF_KEY
60 #define NONCORESEC_KEY NONCORESEC_CONF_KEY
62 #define NONCORESEC_KEY { 0x00 , 0x01 , 0x02 , 0x03 , \
63 0x04 , 0x05 , 0x06 , 0x07 , \
64 0x08 , 0x09 , 0x0A , 0x0B , \
65 0x0C , 0x0D , 0x0E , 0x0F }
68 #define SECURITY_HEADER_LENGTH 5
73 #define PRINTF(...) printf(__VA_ARGS__)
79 static uint8_t key[16] = NONCORESEC_KEY;
80 NBR_TABLE(
struct anti_replay_info, anti_replay_table);
83 static const uint8_t *
84 get_extended_address(
const linkaddr_t *addr)
85 #if LINKADDR_SIZE == 2
88 static linkaddr_extended_t
template = { { 0x00 , 0x00 , 0x00 ,
89 0xFF , 0xFE , 0x00 , 0x00 , 0x00 } };
91 template.u16[3] = LLSEC802154_HTONS(addr->u16);
102 send(mac_callback_t sent,
void *ptr)
104 packetbuf_set_attr(PACKETBUF_ATTR_FRAME_TYPE, FRAME802154_DATAFRAME);
105 packetbuf_set_attr(PACKETBUF_ATTR_SECURITY_LEVEL, LLSEC802154_SECURITY_LEVEL);
107 NETSTACK_MAC.send(sent, ptr);
111 on_frame_created(
void)
119 CCM_STAR.mic(get_extended_address(&
linkaddr_node_addr), dataptr + data_len, LLSEC802154_MIC_LENGTH);
131 uint8_t generated_mic[LLSEC802154_MIC_LENGTH];
132 uint8_t *received_mic;
133 const linkaddr_t *sender;
134 struct anti_replay_info* info;
136 if(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL) != LLSEC802154_SECURITY_LEVEL) {
137 PRINTF(
"noncoresec: received frame with wrong security level\n");
140 sender = packetbuf_addr(PACKETBUF_ADDR_SENDER);
142 PRINTF(
"noncoresec: frame from ourselves\n");
149 CCM_STAR.ctr(get_extended_address(sender));
151 CCM_STAR.mic(get_extended_address(sender), generated_mic, LLSEC802154_MIC_LENGTH);
154 if(memcmp(generated_mic, received_mic, LLSEC802154_MIC_LENGTH) != 0) {
155 PRINTF(
"noncoresec: received nonauthentic frame %"PRIu32
"\n",
160 info = nbr_table_get_from_lladdr(anti_replay_table, sender);
162 info = nbr_table_add_lladdr(anti_replay_table, sender);
164 PRINTF(
"noncoresec: could not get nbr_table_item\n");
179 if(!nbr_table_lock(anti_replay_table, info)) {
180 nbr_table_remove(anti_replay_table, info);
181 PRINTF(
"noncoresec: could not lock\n");
188 PRINTF(
"noncoresec: received replayed frame %"PRIu32
"\n",
194 NETSTACK_NETWORK.input();
200 return SECURITY_HEADER_LENGTH + LLSEC802154_MIC_LENGTH;
204 bootstrap(llsec_on_bootstrapped_t on_bootstrapped)
206 AES_128.set_key(key);
207 nbr_table_register(anti_replay_table,
NULL);
linkaddr_t linkaddr_node_addr
The Rime address of the node.
802.15.4 frame creation and parsing functions
void anti_replay_init_info(struct anti_replay_info *info)
Initializes the anti-replay information about the sender.
void anti_replay_set_counter(void)
Sets the frame counter packetbuf attributes.
int anti_replay_was_replayed(struct anti_replay_info *info)
Checks if received frame was replayed.
Header file for the Rime buffer (packetbuf) management
802.15.4 security implementation, which uses a network-wide key
#define NULL
The null pointer.
void packetbuf_set_datalen(uint16_t len)
Set the length of the data in the packetbuf.
uint16_t packetbuf_datalen(void)
Get the length of the data in the packetbuf.
The structure of a link layer security driver.
int linkaddr_cmp(const linkaddr_t *addr1, const linkaddr_t *addr2)
Compare two Rime addresses.
Common functionality of 802.15.4-compliant llsec_drivers.
void * packetbuf_dataptr(void)
Get a pointer to the data in the packetbuf.
uint32_t anti_replay_get_counter(void)
Gets the frame counter from packetbuf.
Interface to anti-replay mechanisms.
Include file for the Contiki low-layer network stack (NETSTACK)
Header file for the Rime address representation