The ANT encryption configuration module provides functionality to initialize encrypted ANT channels. The configuration consists of two steps:
The API for this module is available here: ANT encryption configuration
See ANT Message Protocol and Usage for detailed information about ANT's encryption capabilities.
To quickly get started, use the sample code from the ANT Multi Channels Encrypted example.
After defining the encryption ID and key, use the macro ANT_ENCRYPT_STACK_SETTINGS_BASE_DEF to configure the cryptographic settings for the ANT stack.
To apply this configuration to the stack, call ant_stack_encryption_config.
The following code example shows how to create a cryptographic configuration and apply it to the stack:
This module uses an extended version of ant_channel_config_t that includes an addition field (.p_crypto_settings
). This field holds a pointer to the cryptographic settings for a channel.
You must change the value of NRF_SDH_ANT_ENCRYPTED_CHANNELS in SoftDevice ANT event handler configuration so that the extended version of ant_channel_config_t is used. The value of the macro must be greater than 0.
To initialize an encrypted channel, call ant_channel_init.
The following code example shows how to configure and initialize an encrypted master channel:
If you do not want to use the extension to ant_channel_config_t, you can use the ant_channel_encrypt_config function directly to configure encryption for a channel.
See the following example code:
If your application (master or slave) needs information about the state of encryption, for example, whether a channel is encrypted, implement event handling for the encryption events. To do so, implement an application-specific event handler of type ant_encryp_user_handler_t that deals with encryption events like negotiation success, negotiation failure, or channel loss. Call ant_enc_event_handler_register to register this event handler.