ant_encrypt_negotiation_slave.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /**
  2. * Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #ifndef ANT_ENCRYPT_NEGOTIATION_SLAVE_H__
  41. #define ANT_ENCRYPT_NEGOTIATION_SLAVE_H__
  42. /**@file
  43. *
  44. * @defgroup ant_encrypt_negotiation_slave ANT encryption negotiation
  45. * @{
  46. * @ingroup ant_sdk_utils
  47. *
  48. * @brief Encryption negotiation for encrypted ANT slave channels.
  49. *
  50. * After pairing, the slave starts negotiating the encryption with the master. After
  51. * successful negotiation, the slave can decrypt messages from the master, and all
  52. * future messages are sent encrypted.
  53. *
  54. */
  55. #include <stdint.h>
  56. #include "nrf_sdh_ant.h"
  57. #include "ant_encrypt_config.h"
  58. #ifdef __cplusplus
  59. extern "C" {
  60. #endif
  61. /** Encryption negotiation states for a slave channel. */
  62. typedef enum
  63. {
  64. ANT_ENC_CHANNEL_STAT_NOT_TRACKING, ///< Not tracking the master.
  65. ANT_ENC_CHANNEL_STAT_TRACKING_ENCRYPTED, ///< Tracking the master, but cannot decrypt messages.
  66. ANT_ENC_CHANNEL_STAT_NEGOTIATING, ///< Encryption has been enabled and negotiation is in progress.
  67. ANT_ENC_CHANNEL_STAT_TRACKING_DECRYPTED, ///< Tracking the master and can decrypt messages.
  68. ANT_ENC_CHANNEL_STAT_TRACKING_UNSUPPORTED ///< Tracking unsupported on this channel.
  69. } ant_encrypt_tracking_state_t;
  70. /**
  71. * @brief Function for setting the encryption negotiation state of a slave ANT channel.
  72. *
  73. * This function should be used by the @ref ant_encrypt_config module.
  74. *
  75. * @param[in] channel_number ANT channel number.
  76. * @param[in] state State to set.
  77. */
  78. void ant_channel_encryp_tracking_state_set(uint8_t channel_number,
  79. ant_encrypt_tracking_state_t state);
  80. /**
  81. * @brief Function for getting the encryption negotiation state of a slave ANT channel.
  82. *
  83. * @param[in] channel_number ANT channel number.
  84. */
  85. ant_encrypt_tracking_state_t ant_channel_encryp_tracking_state_get(uint8_t channel_number);
  86. /**
  87. * @brief Function for initializing the module.
  88. *
  89. * This function initializes internal states of the module. It should
  90. * only be used by the @ref ant_encrypt_config module.
  91. *
  92. */
  93. void ant_channel_encryp_negotiation_slave_init(void);
  94. /**
  95. * @brief Function for setting the configuration for the slave channel.
  96. *
  97. * This function saves the channel's encryption configuration to a lookup table (LUT) for
  98. * future usage. The configuration can then be used to enable encryption.
  99. *
  100. * This function is intended to be used by the @ref ant_encrypt_config module.
  101. *
  102. * @param[in] channel_number ANT channel number.
  103. * @param[in] p_crypto_config Pointer to the encryption configuration.
  104. */
  105. void ant_slave_channel_encrypt_config(uint8_t channel_number,
  106. ant_encrypt_channel_settings_t const * const p_crypto_config);
  107. /**
  108. * @brief Function for handling ANT encryption negotiation on slave nodes.
  109. *
  110. * This function should be used directly in the ANT event dispatching process. It
  111. * tries to enable slave channel encryption for all slave channels that are declared
  112. * as encrypted channels (if appropriate master channels are found).
  113. *
  114. * This function should be used by the @ref ant_encrypt_config module.
  115. *
  116. * @param[in] p_ant_evt Pointer to the ANT stack event message structure.
  117. */
  118. void ant_slave_encrypt_negotiation(ant_evt_t * p_ant_evt);
  119. /**
  120. * @}
  121. */
  122. #ifdef __cplusplus
  123. }
  124. #endif
  125. #endif // ANT_ENCRYPT_NEGOTIATION_SLAVE_H__