Arduino LMIC 6.0.1
Arduino LoRaWAN(r) MAC in C
Loading...
Searching...
No Matches
lmic_secure_element_api.h
Go to the documentation of this file.
1/*
2
3Module: lmic_secure_element_api.h
4
5Function:
6 The API type
7
8Copyright & License:
9 See accompanying LICENSE file.
10
11Author:
12 Terry Moore, MCCI May 2020
13
14*/
15
17
18#ifndef _lmic_secure_element_api_h_
19#define _lmic_secure_element_api_h_
20
21#ifndef _lmic_secure_element_interface_h_
23#endif
24
27
28/****************************************************************************\
29| The configuration. For now, we don't support anything other than
30| static binding.
31\****************************************************************************/
32
33#if defined(_DOXYGEN_)
42# define LMIC_CFG_SecureElement_DRIVER Default
43
57# define LMIC_ENABLE_SecureElement_STATIC 1
58#endif
59
60#if ! defined(LMIC_CFG_SecureElement_DRIVER)
61# define LMIC_CFG_SecureElement_DRIVER Default
62#endif
63
64#if ! defined(LMIC_ENABLE_SecureElement_STATIC)
65# define LMIC_ENABLE_SecureElement_STATIC 1
66#endif
67
68/****************************************************************************\
69| The portable API functions.
70\****************************************************************************/
71
72#if ! LMIC_ENABLE_SecureElement_STATIC
73# error "This version only supports static binding to the secure element."
74#endif
75
76/*
77|| Declare external linkage for the APIs
78*/
79#if ! LMIC_ENABLE_SecureElement_STATIC
80LMIC_SecureElement_initialize_t LMIC_SecureElement_initialize;
81LMIC_SecureElement_getRandomU1_t LMIC_SecureElement_getRandomU1;
82LMIC_SecureElement_getRandomU2_t LMIC_SecureElement_getRandomU2;
83LMIC_SecureElement_fillRandomBuffer_t LMIC_SecureElement_fillRandomBuffer;
84LMIC_SecureElement_setAppKey_t LMIC_SecureElement_setAppKey;
85LMIC_SecureElement_getAppKey_t LMIC_SecureElement_getAppKey;
86LMIC_SecureElement_setAppEUI_t LMIC_SecureElement_setAppEUI;
87LMIC_SecureElement_getAppEUI_t LMIC_SecureElement_getAppEUI;
88LMIC_SecureElement_setDevEUI_t LMIC_SecureElement_setDevEUI;
89LMIC_SecureElement_getDevEUI_t LMIC_SecureElement_getDevEUI;
90LMIC_SecureElement_setNwkSKey_t LMIC_SecureElement_setNwkSKey;
91LMIC_SecureElement_getNwkSKey_t LMIC_SecureElement_getNwkSKey;
92LMIC_SecureElement_setAppSKey_t LMIC_SecureElement_setAppSKey;
93LMIC_SecureElement_getAppSKey_t LMIC_SecureElement_getAppSKey;
94LMIC_SecureElement_createJoinRequest_t LMIC_SecureElement_createJoinRequest;
95LMIC_SecureElement_decodeJoinAccept_t LMIC_SecureElement_decodeJoinAccept;
96LMIC_SecureElement_encodeMessage_t LMIC_SecureElement_encodeMessage;
97LMIC_SecureElement_verifyMIC_t LMIC_SecureElement_verifyMIC;
98LMIC_SecureElement_decodeMessage_t LMIC_SecureElement_decodeMessage;
99LMIC_SecureElement_aes128Encrypt_t LMIC_SecureElement_aes128Encrypt;
100#else // LMIC_ENABLE_SecureElement_STATIC
101
102/*
103|| Use static linkage for the APIs.
104*/
105
130#define LMIC_SecureElement_METHOD_(a_driver, a_fn) \
131 (LMIC_SecureElement_##a_driver##_##a_fn)
132
158#define LMIC_SecureElement_METHOD(a_driver, a_fn) \
159 LMIC_SecureElement_METHOD_(a_driver, a_fn)
160
164
166static inline
168LMIC_SecureElement_initialize(void) {
170}
171
173static inline
174uint8_t LMIC_ABI_STD
175LMIC_SecureElement_getRandomU1(void) {
177}
178
180static inline
181uint16_t LMIC_ABI_STD
182LMIC_SecureElement_getRandomU2(void) {
184}
185
187static inline
189LMIC_SecureElement_fillRandomBuffer(uint8_t *buffer, uint8_t nBuffer) {
190 return LMIC_SecureElement_METHOD(LMIC_CFG_SecureElement_DRIVER, fillRandomBuffer)(buffer, nBuffer);
191}
192
194static inline
196LMIC_SecureElement_setAppKey(const LMIC_SecureElement_Aes128Key_t *pAppKey) {
198}
199
201static inline
203LMIC_SecureElement_getAppKey(LMIC_SecureElement_Aes128Key_t *pAppKey) {
205}
206
208static inline
210LMIC_SecureElement_setAppEUI(const LMIC_SecureElement_EUI_t *pAppEUI) {
212}
213
215static inline
217LMIC_SecureElement_getAppEUI(LMIC_SecureElement_EUI_t *pAppEUI) {
219}
220
222static inline
224LMIC_SecureElement_setDevEUI(const LMIC_SecureElement_EUI_t *pDevEUI) {
226}
227
229static inline
231LMIC_SecureElement_getDevEUI(LMIC_SecureElement_EUI_t *pDevEUI) {
233}
234
236static inline
238LMIC_SecureElement_setNwkSKey(const LMIC_SecureElement_Aes128Key_t *pNwkSKey, LMIC_SecureElement_KeySelector_t iKey) {
239 return LMIC_SecureElement_METHOD(LMIC_CFG_SecureElement_DRIVER, setNwkSKey)(pNwkSKey, iKey);
240}
241
243static inline
245LMIC_SecureElement_getNwkSKey(LMIC_SecureElement_Aes128Key_t *pNwkSKey, LMIC_SecureElement_KeySelector_t iKey) {
246 return LMIC_SecureElement_METHOD(LMIC_CFG_SecureElement_DRIVER, getNwkSKey)(pNwkSKey, iKey);
247}
248
250static inline
252LMIC_SecureElement_setAppSKey(const LMIC_SecureElement_Aes128Key_t *pAppSKey, LMIC_SecureElement_KeySelector_t iKey) {
253 return LMIC_SecureElement_METHOD(LMIC_CFG_SecureElement_DRIVER, setAppSKey)(pAppSKey, iKey);
254}
255
257static inline
259LMIC_SecureElement_getAppSKey(LMIC_SecureElement_Aes128Key_t *pAppSKey, LMIC_SecureElement_KeySelector_t iKey) {
260 return LMIC_SecureElement_METHOD(LMIC_CFG_SecureElement_DRIVER, getAppSKey)(pAppSKey, iKey);
261}
262
264static inline
266LMIC_SecureElement_createJoinRequest(
267 uint8_t *pJoinRequestBytes, LMIC_SecureElement_JoinFormat_t joinFormat
268) {
269 return LMIC_SecureElement_METHOD(LMIC_CFG_SecureElement_DRIVER, createJoinRequest)(pJoinRequestBytes, joinFormat);
270}
271
273static inline
275LMIC_SecureElement_decodeJoinAccept(
276 const uint8_t *pJoinAcceptBytes, uint8_t nJoinAcceptBytes,
277 uint8_t *pJoinAcceptClearText,
279) {
281 pJoinAcceptBytes, nJoinAcceptBytes, pJoinAcceptClearText, joinFormat
282 );
283}
284
286static inline
288LMIC_SecureElement_encodeMessage(const uint8_t *pMessage, uint8_t nMessage, uint8_t iPayload, uint8_t *pCipherTextBuffer, LMIC_SecureElement_KeySelector_t iKey) {
290 pMessage, nMessage, iPayload, pCipherTextBuffer, iKey
291 );
292}
293
295static inline
297LMIC_SecureElement_verifyMIC(
298 const uint8_t *pPhyPayload,
299 uint8_t nPhyPayload,
300 uint32_t devAddr,
301 uint32_t FCntDown,
303) {
305 pPhyPayload, nPhyPayload, devAddr, FCntDown, iKey
306 );
307}
308
310static inline
312LMIC_SecureElement_decodeMessage(
313 const uint8_t *pPhyPayload, uint8_t nPhyPayload,
314 uint32_t devAddr, uint32_t FCntDown,
316 uint8_t *pClearTextBuffer
317) {
319 pPhyPayload, nPhyPayload, devAddr, FCntDown, iKey, pClearTextBuffer
320 );
321}
322
324static inline
326LMIC_SecureElement_aes128Encrypt(const uint8_t *pKey, const uint8_t *pInput, uint8_t *pOutput) {
328 pKey, pInput, pOutput
329 );
330}
331
332#endif // LMIC_ENABLE_SecureElement_STATIC
333
334LMIC_END_DECLS
335
336// end group lmic_se
338
339#endif // _lmic_secure_element_api_h_
LMIC_SecureElement_Error_t LMIC_ABI_STD LMIC_SecureElement_aes128Encrypt_t(const uint8_t *pKey, const uint8_t *pInput, uint8_t *pOutput)
Perform an AES128 encryption.
Definition lmic_secure_element_interface.h:465
LMIC_SecureElement_Error_t LMIC_ABI_STD LMIC_SecureElement_setDevEUI_t(const LMIC_SecureElement_EUI_t *pDevEUI)
Set device EUI.
Definition lmic_secure_element_interface.h:301
LMIC_SecureElement_Error_t LMIC_ABI_STD LMIC_SecureElement_setAppSKey_t(const LMIC_SecureElement_Aes128Key_t *pAppSKey, LMIC_SecureElement_KeySelector_t iKey)
Set application session key.
Definition lmic_secure_element_interface.h:269
uint16_t LMIC_ABI_STD LMIC_SecureElement_getRandomU2_t(void)
Return a random integer uniformly distributed in [0..65535].
Definition lmic_secure_element_interface.h:208
LMIC_SecureElement_Error_t LMIC_ABI_STD LMIC_SecureElement_decodeMessage_t(const uint8_t *pPhyPayload, uint8_t nPhyPayload, uint32_t devAddr, uint32_t FCntDown, LMIC_SecureElement_KeySelector_t iKey, uint8_t *pClearTextBuffer)
Decode an application message.
Definition lmic_secure_element_interface.h:442
LMIC_SecureElement_Error_t LMIC_ABI_STD LMIC_SecureElement_getAppEUI_t(LMIC_SecureElement_EUI_t *pAppEUI)
Get application EUI.
Definition lmic_secure_element_interface.h:312
LMIC_SecureElement_Error_t LMIC_ABI_STD LMIC_SecureElement_fillRandomBuffer_t(uint8_t *buffer, uint8_t nBuffer)
Fill buffer with random independently distributed integers, each in [0..255].
Definition lmic_secure_element_interface.h:219
LMIC_SecureElement_Error_t LMIC_ABI_STD LMIC_SecureElement_encodeMessage_t(const uint8_t *pMessage, uint8_t nMessage, uint8_t iPayload, uint8_t *pCipherTextBuffer, LMIC_SecureElement_KeySelector_t iKey)
Encode an application uplink message.
Definition lmic_secure_element_interface.h:393
LMIC_SecureElement_Error_t LMIC_ABI_STD LMIC_SecureElement_verifyMIC_t(const uint8_t *pPhyPayload, uint8_t nPhyPayload, uint32_t devAddr, uint32_t FCntDown, LMIC_SecureElement_KeySelector_t iKey)
Verify the MIC of a downlink message.
Definition lmic_secure_element_interface.h:413
uint8_t LMIC_ABI_STD LMIC_SecureElement_getRandomU1_t(void)
Return a random integer uniformly distributed in [0..255].
Definition lmic_secure_element_interface.h:204
LMIC_SecureElement_Error_t LMIC_ABI_STD LMIC_SecureElement_setAppKey_t(const LMIC_SecureElement_Aes128Key_t *pAppKey)
Set application key.
Definition lmic_secure_element_interface.h:227
LMIC_SecureElement_Error_t LMIC_ABI_STD LMIC_SecureElement_initialize_t(void)
Initialize the Secure Element.
Definition lmic_secure_element_interface.h:200
LMIC_SecureElement_Error_t LMIC_ABI_STD LMIC_SecureElement_decodeJoinAccept_t(const uint8_t *pJoinAcceptBytes, uint8_t nJoinAcceptBytes, uint8_t *pJoinAcceptClearText, LMIC_SecureElement_JoinFormat_t joinFormat)
Decode a join accept message; capture keys.
Definition lmic_secure_element_interface.h:367
LMIC_SecureElement_Error_t LMIC_ABI_STD LMIC_SecureElement_setNwkSKey_t(const LMIC_SecureElement_Aes128Key_t *pNwkSKey, LMIC_SecureElement_KeySelector_t iKey)
Set network session key.
Definition lmic_secure_element_interface.h:247
LMIC_SecureElement_Error_t LMIC_ABI_STD LMIC_SecureElement_getAppSKey_t(LMIC_SecureElement_Aes128Key_t *pAppSKey, LMIC_SecureElement_KeySelector_t iKey)
Get application session key.
Definition lmic_secure_element_interface.h:281
LMIC_SecureElement_Error_t LMIC_ABI_STD LMIC_SecureElement_createJoinRequest_t(uint8_t *pJoinRequestBytes, LMIC_SecureElement_JoinFormat_t joinFormat)
Create a join request.
Definition lmic_secure_element_interface.h:343
LMIC_SecureElement_Error_t LMIC_ABI_STD LMIC_SecureElement_getDevEUI_t(LMIC_SecureElement_EUI_t *pDevEUI)
Get device EUI.
Definition lmic_secure_element_interface.h:292
#define LMIC_SecureElement_DECLARE_DRIVER_FNS(a_driver)
Declare secure element functions for a given driver.
Definition lmic_secure_element_interface.h:497
LMIC_SecureElement_Error_t LMIC_ABI_STD LMIC_SecureElement_getAppKey_t(LMIC_SecureElement_Aes128Key_t *pAppKey)
Get application key.
Definition lmic_secure_element_interface.h:237
LMIC_SecureElement_Error_t LMIC_ABI_STD LMIC_SecureElement_getNwkSKey_t(LMIC_SecureElement_Aes128Key_t *pNwkSKey, LMIC_SecureElement_KeySelector_t iKey)
Get network session key.
Definition lmic_secure_element_interface.h:259
LMIC_SecureElement_Error_t LMIC_ABI_STD LMIC_SecureElement_setAppEUI_t(const LMIC_SecureElement_EUI_t *pAppEUI)
Set application EUI.
Definition lmic_secure_element_interface.h:321
struct LMIC_SecureElement_EUI_s LMIC_SecureElement_EUI_t
an object to carry a 64-bit EUI.
uint8_t LMIC_SecureElement_KeySelector_t
Controlled-width type for LMIC_SecureElement_KeySelector_e.
Definition lmic_secure_element_interface.h:117
#define LMIC_CFG_SecureElement_DRIVER
Select the secure-element driver.
Definition lmic_secure_element_api.h:42
#define LMIC_SecureElement_METHOD(a_driver, a_fn)
Generate a method function name.
Definition lmic_secure_element_api.h:158
struct LMIC_SecureElement_Aes128Key_s LMIC_SecureElement_Aes128Key_t
an object to carry an AES128 (16-byte) key.
uint8_t LMIC_SecureElement_JoinFormat_t
Controlled-width type for LMIC_SecureElement_JoinFormat_e.
Definition lmic_secure_element_interface.h:163
enum LMIC_SecureElement_Error_e LMIC_SecureElement_Error_t
Controlled-width type for LMIC_SecureElement_Error_e.
Definition lmic_secure_element_interface.h:75