DolphinV4 API  1.6.1.0
Security example



This example shows how to convert a non secure message into a secure message. The secure message will be sent in the air. The secure message contains encrypted data, the rolling code and the CMAC. The example sends a secure message every second.



Application file - main.c

/************************************************************************-
EVA Board:
EVA320-2/EOP350
Input PIN:
-
Output PIN:
SCLKDIO_1
Indicates the sending of the telegram
Description:
This example shows how to convert a non secure message into a secure message.
The secure message will be sent in the air.
The secure message contains encrypted data, the rolling code and the CMAC.
The example sends a secure message every second.
Notes:
The rolling code will be incremented by the sec_convertToSecure function.
-************************************************************************/
#include "EO3100I_API.h"
#include "EO3100I_CFG.h"
#include <string.h>
#define ledTxOn(); io_setDigital(SCLKDIO_1,1);
#define ledTxOff(); io_setDigital(SCLKDIO_1,0);
code uint8 VERSION_APP[] = {0xE0,'V','E','R','S','I','O','N',1,0,1,0,'A','S','E','C','U','R','I','T','Y','S','E','N','D','E','R',0x00,0xE0};
uint8 const u8key[16] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};
uint8 const u8subkey1[16] = {0xfb, 0xee, 0xd6, 0x18, 0x35, 0x71, 0x33, 0x66, 0x7c, 0x85, 0xe0, 0x8f, 0x72, 0x36, 0xa8, 0xde};
uint8 const u8subkey2[16] = {0xf7, 0xdd, 0xac, 0x30, 0x6a, 0xe2, 0x66, 0xcc, 0xf9, 0x0b, 0xc1, 0x1e, 0xe4, 0x6d, 0x51, 0x3b};
uint8 xdata message[RADIO_BUFF_LENGTH2];
uint8 xdata messageSecure[RADIO_BUFF_LENGTH2];
void main()
{
SECU_TYPE secuInfo;
MESSAGE_TYPE DataMsg;
MESSAGE_TYPE DataMsgSecure;
uint32 u32RLC;
//Configuration in EO3100I_cfg.h
mainInit();
// Initialisation of the non secure message
DataMsg.u8Data = &message[0]; // Assign a buffer to the non secure message
DataMsg.u8SourceIdLength = 4; // 32-bit Id
DataMsg.u16MaxLength = RADIO_BUFF_LENGTH2; // Buffer length
DataMsg.u32SourceId = 0; // ASIC ID will be used
DataMsg.u32DestinationId = BROADCAST_ID; // Message to any receiver
DataMsg.u8OptLength = 0; // No optional data
DataMsg.u8Choice = RADIO_CHOICE_NON_SEC; // This R-ORG is not included in the secure message DATA bytes
DataMsg.u16Length = 4;
// Whatever DATA to be encrypted
message[0] = 0x00;
message[1] = 0x01;
message[2] = 0x02;
message[3] = 0x03;
// Prepare the secure message
DataMsgSecure.u8Data = &messageSecure[0]; // Assign message buffer
DataMsgSecure.u8SourceIdLength = 4; // use 32 bit Id for EEP-Data-Message
DataMsgSecure.u32DestinationId = BROADCAST_ID;
DataMsgSecure.u8OptLength = 0;
// Prepare the format of the secure message
secuInfo.u8SLF = 0xB3; // Security layer format byte : | RLC_ALGO (2-bits) | RLC_TX (1-bit) | MAC_ALGO (2-bits) | DATA_ENC (3-bits) |. 0xB3 = 3-byte RLC, sending RLC, 4-byte CMAC, VAES encryption
secuInfo.u8KeySize = 16; // Size of the key in bytes.
u32RLC = 0x00000000; // Initial rolling code
memcpy(&secuInfo.u8Key[0] , &u8key[0] ,16); // Encryption/decryption key.
memcpy(&secuInfo.u8CMACsubkey1[0], &u8subkey1[0],16);
memcpy(&secuInfo.u8CMACsubkey2[0], &u8subkey2[0],16);
// In every new loop the rolling code changes. This produces a change in the encrypted information and CMAC
while(1)
{
// Transform the non-secure message into a secure message. Transformation happens according to the secuInfo.
// This function increments the RLC as well.
sec_convertToSecure(&DataMsg, &DataMsgSecure, &secuInfo, &u32RLC);
// Convert the message into a telegram that can be sent
misc_messageToRadio2(&DataMsgSecure, &rTel2, NULL);
// Switch on the LED to indicate sending
ledTxOn();
// Send the secure telegram
while (radio_sendTelegram2(&rTel2, NULL) == BUFF_FULL)
ledTxOff();
// 1 second pause
time_wait(1000);
}
}



Config file - EO3100I_CFG.h

// Generated on 2013-06-07 16:58:05 by DolphinAPIConfigurator 1.1.0.20
#ifndef _EO3100I_CFG_H_INCLUDED
#define _EO3100I_CFG_H_INCLUDED
void startupInit();
void mainInit();
//*********************RADIO PARAM***************************
#define RADIO_BUFF_NUM 10
#define RADIO_MATURITY_TIME 100
extern volatile RADIO_BUFFER_TYPE xdata gRadioBuff[RADIO_BUFF_NUM];
//*********************IO PARAM******************************
extern uint8 code io_param[];
#endif //_EO3100I_CFG_H_INCLUDED



Config file - EO3100I_CFG.c

// Generated on 2013-10-01 16:24:21 by DolphinV4 API Configurator 1.2.0.27
#include "EO3100I_API.h"
#include "EO3100I_CFG.h"
//*********************API INIT***************************
//Note: Function is called from startup.a51. Global variables are not yet initialized!
void startupInit()
{
io_init(io_param);
}
void mainInit()
{
radio_init(RADIO_BUFF_NUM, RADIO_MATURITY_TIME);
}
//*********************RADIO PARAM***************************
volatile RADIO_BUFFER_TYPE xdata gRadioBuff[RADIO_BUFF_NUM];
//*********************IO PARAM******************************
uint8 code io_param[] = {
0x07, //IDX_GPIO_CONF
0x00, //IDX_GPIO0_CONF
0x0D, //IDX_GPIO0_PULL_CONF
0x02, //IDX_GPIO0_DIR
0x00, //IDX_GPIO1_AN
0x00, //IDX_GPIO1_CONF0
0x00, //IDX_GPIO1_CONF1
0x03, //IDX_GPIO1_DIG_CONF
0x00, //IDX_GPIO1_DIR
0xFF, //IDX_GPIO1_PULL
0x0C, //IDX_GPIO2_CONF
0x00, //IDX_GPIO2_DIR
0x00, //IDX_GPIO0
0x00, //IDX_GPIO1
0x00, //IDX_GPIO2
};
// I/O Configuration overview
//
// Pin : Interface Direction Pull InitValue Interrupt
// SCSEDIO0 : Digital I/O In Up 0 No
// SCLKDIO1 : Digital I/O Out None 0 No
// WSDADIO2 : Digital I/O In Up 0 No
// RSDADIO3 : Digital I/O In Up 0 No
// ADIO0 : Digital I/O In Up 0 No
// ADIO1 : Digital I/O In Up 0 No
// ADIO2 : Digital I/O In Up 0 No
// ADIO3 : Digital I/O In Up 0 No
// ADIO4 : Digital I/O In Up 0 No
// ADIO5 : Digital I/O In Up 0 No
// ADIO6 : Digital I/O In Up 0 No
// ADIO7 : Digital I/O In Up 0 No
// WXIDIO : Digital I/O In Up 0 No
// WXODIO : Digital I/O In Up 0 No
// WAKE0 : Digital I/O In None 0 No
// WAKE1 : Digital I/O In None 0 No