From 55e0fec37e702297ee9f076d5fa077e3b0485426 Mon Sep 17 00:00:00 2001 From: nifi Date: Mon, 15 Mar 2010 23:04:54 +0000 Subject: [PATCH] * Changed to write keys to CC2420 RAM big-endian order * Fixed cc2420_aes_cipher() to wait for encryption to finish before reading result --- core/dev/cc2420-aes.c | 15 ++++++++++----- core/dev/cc2420-aes.h | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/core/dev/cc2420-aes.c b/core/dev/cc2420-aes.c index 3be6e9b22..132e2f61d 100644 --- a/core/dev/cc2420-aes.c +++ b/core/dev/cc2420-aes.c @@ -28,12 +28,12 @@ * * This file is part of the Contiki operating system. * - * $Id: cc2420-aes.c,v 1.3 2009/04/07 09:22:58 nifi Exp $ + * $Id: cc2420-aes.c,v 1.4 2010/03/15 23:04:54 nifi Exp $ */ /** * \file - * AES encryption/decryption functions. + * AES encryption functions. * \author * Adam Dunkels */ @@ -56,16 +56,16 @@ /*---------------------------------------------------------------------------*/ void -cc2420_aes_set_key(uint8_t *key, int index) +cc2420_aes_set_key(const uint8_t *key, int index) { uint16_t f; switch(index) { case 0: - FASTSPI_WRITE_RAM_LE(key, CC2420RAM_KEY0, KEYLEN, f); + FASTSPI_WRITE_RAM_BE(key, CC2420RAM_KEY0, KEYLEN, f); break; case 1: - FASTSPI_WRITE_RAM_LE(key, CC2420RAM_KEY1, KEYLEN, f); + FASTSPI_WRITE_RAM_BE(key, CC2420RAM_KEY1, KEYLEN, f); break; } } @@ -75,11 +75,16 @@ static void cipher16(uint8_t *data, int len) { uint16_t f; + uint8_t status; len = MIN(len, MAX_DATALEN); FASTSPI_WRITE_RAM_LE(data, CC2420RAM_SABUF, len, f); FASTSPI_STROBE(CC2420_SAES); + /* Wait for the encryption to finish */ + do { + FASTSPI_UPD_STATUS(status); + } while(status & BV(CC2420_ENC_BUSY)); FASTSPI_READ_RAM_LE(data, CC2420RAM_SABUF, len, f); } /*---------------------------------------------------------------------------*/ diff --git a/core/dev/cc2420-aes.h b/core/dev/cc2420-aes.h index ccab812f4..a8d068d19 100644 --- a/core/dev/cc2420-aes.h +++ b/core/dev/cc2420-aes.h @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: cc2420-aes.h,v 1.2 2008/07/02 09:02:39 nifi Exp $ + * $Id: cc2420-aes.h,v 1.3 2010/03/15 23:04:54 nifi Exp $ */ /** @@ -56,7 +56,7 @@ * index is given by the 'index' parameter. * */ -void cc2420_aes_set_key(uint8_t *key, int index); +void cc2420_aes_set_key(const uint8_t *key, int index); /**