|
Arduino LMIC 6.0.1
Arduino LoRaWAN(r) MAC in C
|
Linkage to secure element implementations. More...
Macros | |
| #define | LMIC_SecureElement_DECLARE_DRIVER_FNS(a_driver) |
| Declare secure element functions for a given driver. | |
Typedefs | |
| typedef 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. | |
| typedef LMIC_SecureElement_Error_t LMIC_ABI_STD | LMIC_SecureElement_createJoinRequest_t(uint8_t *pJoinRequestBytes, LMIC_SecureElement_JoinFormat_t joinFormat) |
| Create a join request. | |
| typedef 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. | |
| typedef 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. | |
| typedef 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. | |
| typedef 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]. | |
| typedef LMIC_SecureElement_Error_t LMIC_ABI_STD | LMIC_SecureElement_getAppEUI_t(LMIC_SecureElement_EUI_t *pAppEUI) |
| Get application EUI. | |
| typedef LMIC_SecureElement_Error_t LMIC_ABI_STD | LMIC_SecureElement_getAppKey_t(LMIC_SecureElement_Aes128Key_t *pAppKey) |
| Get application key. | |
| typedef 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. | |
| typedef LMIC_SecureElement_Error_t LMIC_ABI_STD | LMIC_SecureElement_getDevEUI_t(LMIC_SecureElement_EUI_t *pDevEUI) |
| Get device EUI. | |
| typedef 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. | |
| typedef uint8_t LMIC_ABI_STD | LMIC_SecureElement_getRandomU1_t(void) |
| Return a random integer uniformly distributed in [0..255]. | |
| typedef uint16_t LMIC_ABI_STD | LMIC_SecureElement_getRandomU2_t(void) |
| Return a random integer uniformly distributed in [0..65535]. | |
| typedef LMIC_SecureElement_Error_t LMIC_ABI_STD | LMIC_SecureElement_initialize_t(void) |
| Initialize the Secure Element. | |
| typedef LMIC_SecureElement_Error_t LMIC_ABI_STD | LMIC_SecureElement_setAppEUI_t(const LMIC_SecureElement_EUI_t *pAppEUI) |
| Set application EUI. | |
| typedef LMIC_SecureElement_Error_t LMIC_ABI_STD | LMIC_SecureElement_setAppKey_t(const LMIC_SecureElement_Aes128Key_t *pAppKey) |
| Set application key. | |
| typedef 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. | |
| typedef LMIC_SecureElement_Error_t LMIC_ABI_STD | LMIC_SecureElement_setDevEUI_t(const LMIC_SecureElement_EUI_t *pDevEUI) |
| Set device EUI. | |
| typedef 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. | |
| typedef 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. | |
Linkage to secure element implementations.
Function types are used to enforce consistency between the API wrappers and driver implementations. We follow MCCI's convention of declaring function types rather than pointer-to-function types; this lets one type name be used both for declaring pointers to functions and for declaring that a given function implements a given API.
Given that consistency, we further define macros that will generate all prototypes for a given driver's methods using consistent names (LMIC_SecureElement_DECLARE_DRIVER_FNS).
The framework implementation currently requires that the secure element driver be selected at compile time. However, the architecture allows an alternate implementation using pointers and dynamic linkage.
| #define LMIC_SecureElement_DECLARE_DRIVER_FNS | ( | a_driver | ) |
Declare secure element functions for a given driver.
| a_driver | Fragment of driver name to insert in function names, e.g Default. |
The parameter is macro-expanded and then substituted to declare each of the interface functions for the specified driver.
This expands to a series of function declarations:
| typedef 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.
| pKey | [in] Encryption key (16 bytes). |
| pInput | [in] Clear text (16 bytes). |
| pOutput | [out] Cipher text (16 bytes). |
This API is used for beacon calculations and other pseudo-random operations. Key, input buffer, output buffer are all 16 bytes long. pOutput and pInput may be the same buffer; otherwise they must point to non-overlapping regions of memory. pKey must not overlap pOutput. None of pKey, pInput, pOutput may be NULL.
| LMIC_SecureElement_Error_OK | if the encryption was performed |
| LMIC_SecureElement_Error_InvalidParameter | if any of the parameters is invalid. |
| typedef LMIC_SecureElement_Error_t LMIC_ABI_STD LMIC_SecureElement_createJoinRequest_t(uint8_t *pJoinRequestBytes, LMIC_SecureElement_JoinFormat_t joinFormat) |
Create a join request.
| pJoinRequestBytes | [out] Buffer to be filled with the join request. |
| joinFormat | [in] Join type selector. |
The buffer at * pJoinRequestBytes must be at least sizeof(LMIC_SecureElement_JoinRequest_t::bytes) long; it is filled with a JoinRequest message, encrypted with the keys suitable to the specified context. joinFormat is provided for future use in LoRaWAN 1.1 systems; it selects the keys to be used and the format of the message. It shall be set to LMIC_SecureElement_JoinFormat_JoinRequest10.
| LMIC_SecureElement_Error_InvalidParameter | indicates that iKey was not valid. |
| typedef 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.
| pJoinAcceptBytes | [in] Buffer with raw join accept message |
| nJoinAcceptBytes | [in] Number of bytes |
| pJoinAcceptClearText | [out] Buffer to be filled with decrypted message; same size as pJoinAcceptBytes. |
| joinFormat | [in] Type used on message that triggered this join accept. |
The Join-Accept message is decoded using the keys designated by the joinFormat, and the clear text is placed in pJoinAcceptClearText.
The LMIC presently only supports LoRaWAN 1.0.3, so joinFormat must be LMIC_SecureElement_JoinFormat_JoinRequest10.
| typedef 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.
| pPhyPayload | [in] Pointer to MHDR byte of received PHY message. |
| nPhyPayload | [in] Number of bytes, including the MIC. |
| devAddr | [in] Device address |
| FCntDown | [in] The downlink frame counter to be used with this message |
| iKey | [in] Key discriminator. |
| pClearTextBuffer | [out] Buffer to be used for the output data. Must be nPhyPayload - 4 bytes long. |
The payload is decrypted and placed in pClearTextBuffer. The MIC is assumed to be valid. The output buffer must be nBuffer - 4 bytes long (the MIC is not appended). ClearTextdBuffer may be the same as pPhyPayload, in which case the update is done in-place if possible. Otherwise the input and output blocks shall be strictly non-overlapping.
| typedef 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.
| pMessage | [in] Pointer to MHDR byte of message to encode. |
| nMessage | [in] Number of bytes, not including the MIC. |
| iPayload | [in] Index of payload field in the message. |
| pCipherTextBuffer | [in] Pointer to buffer to receive phy message. |
| iKey | [in] Key discriminator. |
The output buffer must be nBuffer + 4 bytes long. FCntUp in the message may be ignored by the Secure Element and replaced by SE's idea of the uplink frame count. SE will increment its internal FCntUp. To implement NbTrans > 1, caller shall cache the encoded message and retransmit it, rather than re-encoding it. pCipherTextBuffer may be the same as pMessage; in this case the update is done in-place if possible. Otherwise the blocks shall be strictly non-overlapping.
| typedef 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].
| buffer | [out] Pointer to buffer to be filled. |
| nBuffer | [in] Number of bytes to be filled. |
nBuffer is limited to 255, for maximum implementation flexibility.
| typedef LMIC_SecureElement_Error_t LMIC_ABI_STD LMIC_SecureElement_getAppEUI_t(LMIC_SecureElement_EUI_t *pAppEUI) |
Get application EUI.
| pAppEUI | [out] application EUI for this secure element. |
| typedef LMIC_SecureElement_Error_t LMIC_ABI_STD LMIC_SecureElement_getAppKey_t(LMIC_SecureElement_Aes128Key_t *pAppKey) |
Get application key.
| pAppKey | [out] Points to buffer to be filled with application key. |
| typedef 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.
| pAppSKey | [out] set to the value of the application session key. |
| iKey | [in] key discriminator. |
| typedef LMIC_SecureElement_Error_t LMIC_ABI_STD LMIC_SecureElement_getDevEUI_t(LMIC_SecureElement_EUI_t *pDevEUI) |
Get device EUI.
| pDevEUI | [out] device EUI. |
| typedef 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.
| pNwkSKey | [in] provides the value of the network session key. |
| iKey | [in] key discriminator. |
| typedef LMIC_SecureElement_Error_t LMIC_ABI_STD LMIC_SecureElement_initialize_t(void) |
Initialize the Secure Element.
| typedef LMIC_SecureElement_Error_t LMIC_ABI_STD LMIC_SecureElement_setAppEUI_t(const LMIC_SecureElement_EUI_t *pAppEUI) |
Set application EUI.
| pAppEUI | [in] application EUI for this secure element. |
| typedef LMIC_SecureElement_Error_t LMIC_ABI_STD LMIC_SecureElement_setAppKey_t(const LMIC_SecureElement_Aes128Key_t *pAppKey) |
Set application key.
| pAppKey | [in] Points to 16-byte application key. |
| typedef 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.
| pAppSKey | [in] session key to be associated with iKey. |
| iKey | [in] key discriminator. |
| typedef LMIC_SecureElement_Error_t LMIC_ABI_STD LMIC_SecureElement_setDevEUI_t(const LMIC_SecureElement_EUI_t *pDevEUI) |
Set device EUI.
| pDevEUI | [in] Device key for this secure element. |
| typedef 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.
| pNwkSKey | [in] session key to be associated with iKey. |
| iKey | [in] key discriminator. |
| typedef 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.
| pPhyPayload | [in] Pointer to MHDR byte of received PHY message. |
| nPhyPayload | [in] Number of bytes, including the MIC. |
| devAddr | [in] Device address |
| FCntDown | [in] The downlink frame counter to be used with this message |
| iKey | [in] Key discriminator. |
The MIC code for the message is calculated using the appropriate key and algorithm.