mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 04:52:59 +01:00
drivers/at86rf2xx: move security logic to netdev
This commit is contained in:
parent
99d490a3c1
commit
4708478e98
@ -27,13 +27,9 @@
|
||||
#include "kernel_defines.h"
|
||||
#include "byteorder.h"
|
||||
#include "net/ieee802154.h"
|
||||
#if IS_USED(IEEE802154_SECURITY)
|
||||
#include "net/ieee802154_security.h"
|
||||
#endif
|
||||
#include "net/gnrc.h"
|
||||
#include "at86rf2xx_registers.h"
|
||||
#include "at86rf2xx_internal.h"
|
||||
#include "at86rf2xx_netdev.h"
|
||||
#if IS_USED(MODULE_AT86RF2XX_AES_SPI)
|
||||
#include "at86rf2xx_aes.h"
|
||||
#endif
|
||||
@ -41,78 +37,6 @@
|
||||
#define ENABLE_DEBUG 0
|
||||
#include "debug.h"
|
||||
|
||||
#if IS_USED(MODULE_AT86RF2XX_AES_SPI) && \
|
||||
IS_USED(MODULE_IEEE802154_SECURITY)
|
||||
/**
|
||||
* @brief Pass the 802.15.4 encryption key to the transceiver hardware
|
||||
*
|
||||
* @param[in] dev Abstract security device descriptor
|
||||
* @param[in] key Encryption key to be used
|
||||
* @param[in] key_size Size of the encryption key in bytes
|
||||
*/
|
||||
static void _at86rf2xx_set_key(ieee802154_sec_dev_t *dev,
|
||||
const uint8_t *key, uint8_t key_size)
|
||||
{
|
||||
(void)key_size;
|
||||
at86rf2xx_aes_key_write_encrypt((at86rf2xx_t *)dev->ctx, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Compute CBC-MAC from IEEE 802.15.4 security context
|
||||
*
|
||||
* @param[in] dev Abstract security device descriptor
|
||||
* @param[out] cipher Buffer to store cipher blocks
|
||||
* @param[in] iv Initial vector
|
||||
* @param[in] plain Input data blocks
|
||||
* @param[in] nblocks Number of blocks
|
||||
*/
|
||||
static void _at86rf2xx_cbc(const ieee802154_sec_dev_t *dev,
|
||||
uint8_t *cipher,
|
||||
uint8_t *iv,
|
||||
const uint8_t *plain,
|
||||
uint8_t nblocks)
|
||||
{
|
||||
at86rf2xx_aes_cbc_encrypt((at86rf2xx_t *)dev->ctx,
|
||||
(aes_block_t *)cipher,
|
||||
NULL,
|
||||
iv,
|
||||
(aes_block_t *)plain,
|
||||
nblocks);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Perform ECB encryption
|
||||
*
|
||||
* @param[in] dev Abstract security device descriptor
|
||||
* @param[out] cipher Output cipher blocks
|
||||
* @param[in] plain Plain blocks
|
||||
* @param[in] nblocks Number of blocks
|
||||
*/
|
||||
static void _at86rf2xx_ecb(const ieee802154_sec_dev_t *dev,
|
||||
uint8_t *cipher,
|
||||
const uint8_t *plain,
|
||||
uint8_t nblocks)
|
||||
{
|
||||
at86rf2xx_aes_ecb_encrypt((at86rf2xx_t *)dev->ctx,
|
||||
(aes_block_t *)cipher,
|
||||
NULL,
|
||||
(aes_block_t *)plain,
|
||||
nblocks);
|
||||
|
||||
}
|
||||
/**
|
||||
* @brief Struct that contains IEEE 802.15.4 security operations
|
||||
* which are implemented, using the transceiver´s hardware
|
||||
* crypto capabilities
|
||||
*/
|
||||
static const ieee802154_radio_cipher_ops_t _at86rf2xx_cipher_ops = {
|
||||
.set_key = _at86rf2xx_set_key,
|
||||
.ecb = _at86rf2xx_ecb,
|
||||
.cbc = _at86rf2xx_cbc
|
||||
};
|
||||
#endif /* IS_USED(MODULE_AT86RF2XX_AES_SPI) && \
|
||||
IS_USED(MODULE_IEEE802154_SECURITY) */
|
||||
|
||||
static void at86rf2xx_disable_clock_output(at86rf2xx_t *dev)
|
||||
{
|
||||
#if AT86RF2XX_IS_PERIPH
|
||||
@ -199,12 +123,6 @@ void at86rf2xx_reset(at86rf2xx_t *dev)
|
||||
/* clear interrupt flags */
|
||||
at86rf2xx_reg_read(dev, AT86RF2XX_REG__IRQ_STATUS);
|
||||
|
||||
#if IS_USED(MODULE_IEEE802154_SECURITY) && \
|
||||
IS_USED(MODULE_AT86RF2XX_AES_SPI)
|
||||
dev->netdev.sec_ctx.dev.cipher_ops = &_at86rf2xx_cipher_ops;
|
||||
dev->netdev.sec_ctx.dev.ctx = dev;
|
||||
#endif
|
||||
|
||||
/* State to return after receiving or transmitting */
|
||||
dev->idle_state = AT86RF2XX_PHY_STATE_RX;
|
||||
/* go into RX state */
|
||||
|
@ -39,6 +39,9 @@
|
||||
#include "at86rf2xx_netdev.h"
|
||||
#include "at86rf2xx_internal.h"
|
||||
#include "at86rf2xx_registers.h"
|
||||
#if IS_USED(IEEE802154_SECURITY)
|
||||
#include "net/ieee802154_security.h"
|
||||
#endif
|
||||
#if IS_USED(MODULE_AT86RF2XX_AES_SPI)
|
||||
#include "at86rf2xx_aes.h"
|
||||
#endif
|
||||
@ -62,6 +65,79 @@ const netdev_driver_t at86rf2xx_driver = {
|
||||
.set = _set,
|
||||
};
|
||||
|
||||
#if IS_USED(MODULE_AT86RF2XX_AES_SPI) && \
|
||||
IS_USED(MODULE_IEEE802154_SECURITY)
|
||||
/**
|
||||
* @brief Pass the 802.15.4 encryption key to the transceiver hardware
|
||||
*
|
||||
* @param[in] dev Abstract security device descriptor
|
||||
* @param[in] key Encryption key to be used
|
||||
* @param[in] key_size Size of the encryption key in bytes
|
||||
*/
|
||||
static void _at86rf2xx_set_key(ieee802154_sec_dev_t *dev,
|
||||
const uint8_t *key, uint8_t key_size)
|
||||
{
|
||||
(void)key_size;
|
||||
at86rf2xx_aes_key_write_encrypt((at86rf2xx_t *)dev->ctx, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Compute CBC-MAC from IEEE 802.15.4 security context
|
||||
*
|
||||
* @param[in] dev Abstract security device descriptor
|
||||
* @param[out] cipher Buffer to store cipher blocks
|
||||
* @param[in] iv Initial vector
|
||||
* @param[in] plain Input data blocks
|
||||
* @param[in] nblocks Number of blocks
|
||||
*/
|
||||
static void _at86rf2xx_cbc(const ieee802154_sec_dev_t *dev,
|
||||
uint8_t *cipher,
|
||||
uint8_t *iv,
|
||||
const uint8_t *plain,
|
||||
uint8_t nblocks)
|
||||
{
|
||||
at86rf2xx_aes_cbc_encrypt((at86rf2xx_t *)dev->ctx,
|
||||
(aes_block_t *)cipher,
|
||||
NULL,
|
||||
iv,
|
||||
(aes_block_t *)plain,
|
||||
nblocks);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Perform ECB encryption
|
||||
*
|
||||
* @param[in] dev Abstract security device descriptor
|
||||
* @param[out] cipher Output cipher blocks
|
||||
* @param[in] plain Plain blocks
|
||||
* @param[in] nblocks Number of blocks
|
||||
*/
|
||||
static void _at86rf2xx_ecb(const ieee802154_sec_dev_t *dev,
|
||||
uint8_t *cipher,
|
||||
const uint8_t *plain,
|
||||
uint8_t nblocks)
|
||||
{
|
||||
at86rf2xx_aes_ecb_encrypt((at86rf2xx_t *)dev->ctx,
|
||||
(aes_block_t *)cipher,
|
||||
NULL,
|
||||
(aes_block_t *)plain,
|
||||
nblocks);
|
||||
|
||||
}
|
||||
/**
|
||||
* @brief Struct that contains IEEE 802.15.4 security operations
|
||||
* which are implemented, using the transceiver´s hardware
|
||||
* crypto capabilities
|
||||
*/
|
||||
static const ieee802154_radio_cipher_ops_t _at86rf2xx_cipher_ops = {
|
||||
.set_key = _at86rf2xx_set_key,
|
||||
.ecb = _at86rf2xx_ecb,
|
||||
.cbc = _at86rf2xx_cbc
|
||||
};
|
||||
#endif /* IS_USED(MODULE_AT86RF2XX_AES_SPI) && \
|
||||
IS_USED(MODULE_IEEE802154_SECURITY) */
|
||||
|
||||
|
||||
/* SOC has radio interrupts, store reference to netdev */
|
||||
static netdev_t *at86rfmega_dev;
|
||||
static void _irq_handler(void *arg)
|
||||
@ -100,6 +176,12 @@ static int _init(netdev_t *netdev)
|
||||
netdev_ieee802154_set(&dev->netdev, NETOPT_ACK_REQ,
|
||||
&enable, sizeof(enable));
|
||||
}
|
||||
#if IS_USED(MODULE_IEEE802154_SECURITY) && \
|
||||
IS_USED(MODULE_AT86RF2XX_AES_SPI)
|
||||
dev->netdev.sec_ctx.dev.cipher_ops = &_at86rf2xx_cipher_ops;
|
||||
dev->netdev.sec_ctx.dev.ctx = dev;
|
||||
#endif
|
||||
|
||||
at86rf2xx_reset(dev);
|
||||
|
||||
/* signal link UP */
|
||||
|
Loading…
Reference in New Issue
Block a user