Added support for encryption and decryption of the packetbuf if macros

NETSTACK_ENCRYPT and NETSTACK_DECRYPT are defined. Those are intended
to be called as functions NETSTACK_ENCRYPT() and NETSTACK_DECRYPT() to
encrypt and decrypt the packetbuf, respectively. If needed, an
initialization function by the name NETSTACK_ENCRYPTION_INIT() can
also be defined.
This commit is contained in:
Adam Dunkels 2012-11-24 17:18:59 +01:00
parent 63d205e4a2
commit cb7842bd16
3 changed files with 23 additions and 1 deletions

View File

@ -626,6 +626,12 @@ send_packet(mac_callback_t mac_callback, void *mac_callback_ptr, struct rdc_buf_
packetbuf_compact();
#ifdef NETSTACK_ENCRYPT
NETSTACK_ENCRYPT();
#endif /* NETSTACK_ENCRYPT */
transmit_len = packetbuf_totlen();
NETSTACK_RADIO.prepare(packetbuf_hdrptr(), transmit_len);
/* Remove the MAC-layer header since it will be recreated next time around. */
@ -915,7 +921,11 @@ input_packet(void)
}
/* printf("cycle_start 0x%02x 0x%02x\n", cycle_start, cycle_start % CYCLE_TIME);*/
#ifdef NETSTACK_DECRYPT
NETSTACK_DECRYPT();
#endif /* NETSTACK_DECRYPT */
if(packetbuf_totlen() > 0 && NETSTACK_FRAMER.parse() >= 0) {
#if WITH_CONTIKIMAC_HEADER

View File

@ -114,6 +114,10 @@ send_packet(mac_callback_t sent, void *ptr)
ret = MAC_TX_ERR_FATAL;
} else {
#ifdef NETSTACK_ENCRYPT
NETSTACK_ENCRYPT();
#endif /* NETSTACK_ENCRYPT */
#if NULLRDC_802154_AUTOACK
int is_broadcast;
uint8_t dsn;
@ -213,6 +217,10 @@ send_list(mac_callback_t sent, void *ptr, struct rdc_buf_list *buf_list)
static void
packet_input(void)
{
#ifdef NETSTACK_DECRYPT
NETSTACK_DECRYPT();
#endif /* NETSTACK_DECRYPT */
#if NULLRDC_802154_AUTOACK
if(packetbuf_datalen() == ACK_LEN) {
/* Ignore ack packets */

View File

@ -46,5 +46,9 @@ netstack_init(void)
NETSTACK_RDC.init();
NETSTACK_MAC.init();
NETSTACK_NETWORK.init();
#ifdef NETSTACK_ENCRYPTION_INIT
NETSTACK_ENCRYPTION_INIT();
#endif /* NETSTACK_ENCRYPTION_INIT */
}
/*---------------------------------------------------------------------------*/