added LLSEC attributes form packetbuf to uipbuf when receiving IP packet, and a few other minor fixes
This commit is contained in:
parent
008cffe81a
commit
42dfc81af2
@ -59,7 +59,8 @@ PROCESS_THREAD(udp_client_process, ev, data)
|
||||
LOG_INFO("Sending request %u to ", count);
|
||||
LOG_INFO_6ADDR(&dest_ipaddr);
|
||||
LOG_INFO_("\n");
|
||||
snprintf(str, sizeof(str), "hello %d", count);
|
||||
/* avoid the risk of not fitting the '\0' in the string */
|
||||
snprintf(str, sizeof(str) - 1, "hello %d", count);
|
||||
simple_udp_sendto(&udp_conn, str, strlen(str), &dest_ipaddr);
|
||||
count++;
|
||||
} else {
|
||||
|
@ -2012,6 +2012,19 @@ input(void)
|
||||
callback->input_callback();
|
||||
}
|
||||
|
||||
#if LLSEC802154_USES_AUX_HEADER
|
||||
/*
|
||||
* Assuming that the last packet in packetbuf is containing
|
||||
* the LLSEC state so that it can be copied to uipbuf.
|
||||
*/
|
||||
uipbuf_set_attr(UIPBUF_ATTR_LLSEC_LEVEL,
|
||||
packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL));
|
||||
#if LLSEC802154_USES_EXPLICIT_KEYS
|
||||
uipbuf_set_attr(UIPBUF_ATTR_LLSEC_KEY_ID,
|
||||
packetbuf_attr(PACKETBUF_ATTR_KEY_INDEX));
|
||||
#endif /* LLSEC802154_USES_EXPLICIT_KEYS */
|
||||
#endif /* LLSEC802154_USES_AUX_HEADER */
|
||||
|
||||
tcpip_input();
|
||||
#if SICSLOWPAN_CONF_FRAG
|
||||
}
|
||||
|
@ -171,11 +171,9 @@ send_one_packet(void *ptr)
|
||||
packetbuf_set_attr(PACKETBUF_ATTR_MAC_ACK, 1);
|
||||
|
||||
#if LLSEC802154_ENABLED
|
||||
/* These should possibly be taken from upper layers in the future */
|
||||
packetbuf_set_attr(PACKETBUF_ATTR_SECURITY_LEVEL, CSMA_LLSEC_SECURITY_LEVEL);
|
||||
#if LLSEC802154_USES_EXPLICIT_KEYS
|
||||
/* This should possibly be taken from upper layers in the future */
|
||||
packetbuf_set_attr(PACKETBUF_ATTR_KEY_ID_MODE, CSMA_LLSEC_KEY_ID_MODE);
|
||||
packetbuf_set_attr(PACKETBUF_ATTR_KEY_INDEX, CSMA_LLSEC_KEY_INDEX);
|
||||
#endif /* LLSEC802154_USES_EXPLICIT_KEYS */
|
||||
#endif /* LLSEC802154_ENABLED */
|
||||
|
||||
|
@ -88,12 +88,14 @@ typedef struct {
|
||||
static aes_key_t keys[CSMA_LLSEC_MAXKEYS];
|
||||
|
||||
/* assumed to be 16 bytes */
|
||||
void
|
||||
csma_security_set_key(uint8_t index, uint8_t *key)
|
||||
int
|
||||
csma_security_set_key(uint8_t index, const uint8_t *key)
|
||||
{
|
||||
if(key != NULL && index < CSMA_LLSEC_MAXKEYS) {
|
||||
memcpy(keys[index].u8, key, 16);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define N_KEYS (sizeof(keys) / sizeof(aes_key))
|
||||
@ -116,7 +118,7 @@ aead(uint8_t hdrlen, int forward)
|
||||
uint8_t with_encryption;
|
||||
|
||||
key_index = LLSEC_KEY_INDEX;
|
||||
if(key_index > CSMA_LLSEC_MAXKEYS) {
|
||||
if(key_index >= CSMA_LLSEC_MAXKEYS) {
|
||||
LOG_ERR("Key not available: %u\n", key_index);
|
||||
return 0;
|
||||
}
|
||||
@ -197,8 +199,8 @@ csma_security_create_frame(void)
|
||||
LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
|
||||
LOG_INFO_(" ");
|
||||
LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
|
||||
LOG_INFO_(" %u (%u) KEY:0x%02x\n", packetbuf_datalen(), packetbuf_totlen(),
|
||||
LLSEC_KEY_INDEX);
|
||||
LOG_INFO_(" %u (%u) LV:%d, KEY:0x%02x\n", packetbuf_datalen(), packetbuf_totlen(),
|
||||
packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL), LLSEC_KEY_INDEX);
|
||||
|
||||
#if LOG_LEVEL == LOG_LEVEL_DBG
|
||||
LOG_DBG(" Payload after: (%d)", packetbuf_totlen());
|
||||
|
@ -71,6 +71,4 @@
|
||||
#define CSMA_LLSEC_MAXKEYS 1
|
||||
#endif
|
||||
|
||||
void csma_security_set_key(uint8_t index, uint8_t *key);
|
||||
|
||||
#endif /* CSMA_SECURITY_H_ */
|
||||
|
@ -83,7 +83,7 @@ int csma_security_create_frame(void);
|
||||
int csma_security_parse_frame(void);
|
||||
|
||||
/* key management for CSMA */
|
||||
void csma_security_set_key(uint8_t index, uint8_t *key);
|
||||
int csma_security_set_key(uint8_t index, const uint8_t *key);
|
||||
|
||||
|
||||
#endif /* CSMA_H_ */
|
||||
|
@ -55,6 +55,9 @@
|
||||
#if MAC_CONF_WITH_TSCH
|
||||
#include "net/mac/tsch/tsch.h"
|
||||
#endif /* MAC_CONF_WITH_TSCH */
|
||||
#if MAC_CONF_WITH_CSMA
|
||||
#include "net/mac/csma/csma.h"
|
||||
#endif
|
||||
#include "net/routing/routing.h"
|
||||
#include "net/mac/llsec802154.h"
|
||||
|
||||
@ -424,7 +427,7 @@ PT_THREAD(cmd_rpl_global_repair(struct pt *pt, shell_output_func output, char *a
|
||||
{
|
||||
PT_BEGIN(pt);
|
||||
|
||||
SHELL_OUTPUT(output, "Triggering routing global repair\n")
|
||||
SHELL_OUTPUT(output, "Triggering routing global repair\n");
|
||||
NETSTACK_ROUTING.global_repair("Shell");
|
||||
|
||||
PT_END(pt);
|
||||
@ -447,7 +450,7 @@ PT_THREAD(cmd_rpl_refresh_routes(struct pt *pt, shell_output_func output, char *
|
||||
{
|
||||
PT_BEGIN(pt);
|
||||
|
||||
SHELL_OUTPUT(output, "Triggering routes refresh\n")
|
||||
SHELL_OUTPUT(output, "Triggering routes refresh\n");
|
||||
rpl_refresh_routes("Shell");
|
||||
|
||||
PT_END(pt);
|
||||
@ -733,12 +736,9 @@ PT_THREAD(cmd_6top(struct pt *pt, shell_output_func output, char *args))
|
||||
static
|
||||
PT_THREAD(cmd_llsec_setlv(struct pt *pt, shell_output_func output, char *args))
|
||||
{
|
||||
char *next_args;
|
||||
|
||||
PT_BEGIN(pt);
|
||||
|
||||
SHELL_ARGS_INIT(args, next_args);
|
||||
|
||||
if(args == NULL) {
|
||||
SHELL_OUTPUT(output, "Default LLSEC level is %d\n",
|
||||
uipbuf_get_attr(UIPBUF_ATTR_LLSEC_LEVEL));
|
||||
@ -754,7 +754,6 @@ PT_THREAD(cmd_llsec_setlv(struct pt *pt, shell_output_func output, char *args))
|
||||
SHELL_OUTPUT(output, "LLSEC default level set %d\n", lv);
|
||||
}
|
||||
}
|
||||
SHELL_ARGS_NEXT(args, next_args);
|
||||
|
||||
PT_END(pt);
|
||||
}
|
||||
@ -775,7 +774,7 @@ PT_THREAD(cmd_llsec_setkey(struct pt *pt, shell_output_func output, char *args))
|
||||
int key;
|
||||
SHELL_ARGS_NEXT(args, next_args);
|
||||
key = atoi(args);
|
||||
if(key < 0 || key > 16) {
|
||||
if(key < 0) {
|
||||
SHELL_OUTPUT(output, "Illegal LLSEC Key index %d\n", key);
|
||||
PT_EXIT(pt);
|
||||
} else {
|
||||
@ -783,7 +782,7 @@ PT_THREAD(cmd_llsec_setkey(struct pt *pt, shell_output_func output, char *args))
|
||||
/* Get next arg (key-string) */
|
||||
SHELL_ARGS_NEXT(args, next_args);
|
||||
if(args != NULL && strlen(args) == 16) {
|
||||
csma_security_set_key(key, (uint8_t *) args);
|
||||
csma_security_set_key(key, (const uint8_t *) args);
|
||||
SHELL_OUTPUT(output, "Set key for index %d\n", key);
|
||||
} else {
|
||||
SHELL_OUTPUT(output, "Wrong length of key: '%s' (%d)\n", args, strlen(args));
|
||||
|
Loading…
Reference in New Issue
Block a user