CC2420: Added GET_LOCK/RELEASE_LOCK to set_key & encrypt
This commit is contained in:
parent
c6a98f2968
commit
75d2914aaf
1 changed files with 43 additions and 35 deletions
|
@ -433,41 +433,6 @@ wait_for_transmission(void)
|
|||
&& RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (RTIMER_SECOND / 10)));
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
init_security(void)
|
||||
{
|
||||
/* only use key 0 */
|
||||
setreg(CC2420_SECCTRL0, 0);
|
||||
setreg(CC2420_SECCTRL1, 0);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
set_key(uint8_t *key)
|
||||
{
|
||||
write_ram(key, CC2420RAM_KEY0, 16, WRITE_RAM_REVERSE);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
encrypt(uint8_t *plaintext_and_result)
|
||||
{
|
||||
write_ram(plaintext_and_result,
|
||||
CC2420RAM_SABUF,
|
||||
16,
|
||||
WRITE_RAM_IN_ORDER);
|
||||
|
||||
strobe(CC2420_SAES);
|
||||
while(get_status() & BV(CC2420_ENC_BUSY));
|
||||
|
||||
read_ram(plaintext_and_result, CC2420RAM_SABUF, 16);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
const struct aes_128_driver cc2420_aes_128_driver = {
|
||||
set_key,
|
||||
encrypt
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t locked, lock_on, lock_off;
|
||||
|
||||
static void
|
||||
on(void)
|
||||
{
|
||||
|
@ -477,6 +442,7 @@ on(void)
|
|||
ENERGEST_ON(ENERGEST_TYPE_LISTEN);
|
||||
receive_on = 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
off(void)
|
||||
{
|
||||
|
@ -495,6 +461,7 @@ off(void)
|
|||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t locked, lock_on, lock_off;
|
||||
#define GET_LOCK() locked++
|
||||
static void RELEASE_LOCK(void) {
|
||||
if(locked == 1) {
|
||||
|
@ -511,6 +478,47 @@ static void RELEASE_LOCK(void) {
|
|||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
init_security(void)
|
||||
{
|
||||
/* only use key 0 */
|
||||
setreg(CC2420_SECCTRL0, 0);
|
||||
setreg(CC2420_SECCTRL1, 0);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
set_key(uint8_t *key)
|
||||
{
|
||||
GET_LOCK();
|
||||
|
||||
write_ram(key, CC2420RAM_KEY0, 16, WRITE_RAM_REVERSE);
|
||||
|
||||
RELEASE_LOCK();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
encrypt(uint8_t *plaintext_and_result)
|
||||
{
|
||||
GET_LOCK();
|
||||
|
||||
write_ram(plaintext_and_result,
|
||||
CC2420RAM_SABUF,
|
||||
16,
|
||||
WRITE_RAM_IN_ORDER);
|
||||
|
||||
strobe(CC2420_SAES);
|
||||
while(get_status() & BV(CC2420_ENC_BUSY));
|
||||
|
||||
read_ram(plaintext_and_result, CC2420RAM_SABUF, 16);
|
||||
|
||||
RELEASE_LOCK();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
const struct aes_128_driver cc2420_aes_128_driver = {
|
||||
set_key,
|
||||
encrypt
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
set_txpower(uint8_t power)
|
||||
{
|
||||
uint16_t reg;
|
||||
|
|
Loading…
Reference in a new issue