security_dispatcher.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 SECURITY_DISPATCHER_H__
  41. #define SECURITY_DISPATCHER_H__
  42. #include <stdint.h>
  43. #include "sdk_errors.h"
  44. #include "ble.h"
  45. #include "ble_gap.h"
  46. #include "peer_manager_types.h"
  47. #ifdef __cplusplus
  48. extern "C" {
  49. #endif
  50. /**
  51. * @cond NO_DOXYGEN
  52. * @defgroup security_dispatcher Security Dispatcher
  53. * @ingroup peer_manager
  54. * @{
  55. * @brief An internal module of @ref peer_manager. A module for streamlining pairing, bonding, and
  56. * encryption, including flash storage of shared data.
  57. *
  58. */
  59. /**@brief Function for initializing the Security Dispatcher module.
  60. *
  61. * @retval NRF_SUCCESS Initialization was successful.
  62. * @retval NRF_ERROR_INTERNAL An unexpected fatal error occurred.
  63. */
  64. ret_code_t smd_init(void);
  65. /**@brief Function for dispatching SoftDevice events to the Security Dispatcher module.
  66. *
  67. * @param[in] ble_evt The SoftDevice event.
  68. */
  69. void smd_ble_evt_handler(ble_evt_t const * ble_evt);
  70. /**@brief Function for providing security configuration for a link.
  71. *
  72. * @details This function is optional, and must be called in reply to a @ref
  73. * PM_EVT_CONN_SEC_CONFIG_REQ event, before the Peer Manager event handler returns. If it
  74. * is not called in time, a default configuration is used. See @ref pm_conn_sec_config_t
  75. * for the value of the default.
  76. *
  77. * @param[in] conn_handle The connection to set the configuration for.
  78. * @param[in] p_conn_sec_config The configuration.
  79. */
  80. void smd_conn_sec_config_reply(uint16_t conn_handle, pm_conn_sec_config_t * p_conn_sec_config);
  81. /**@brief Function for providing pairing and bonding parameters to use for the current pairing
  82. * procedure on a connection.
  83. *
  84. * @note If this function returns an @ref NRF_ERROR_NULL, @ref NRF_ERROR_INVALID_PARAM, @ref
  85. * BLE_ERROR_INVALID_CONN_HANDLE, or @ref NRF_ERROR_STORAGE_FULL, this function can be called
  86. * again after corrective action.
  87. *
  88. * @note To reject a request, call this function with NULL p_sec_params.
  89. *
  90. * @param[in] conn_handle The connection handle of the connection the pairing is happening on.
  91. * @param[in] p_sec_params The security parameters to use for this link.
  92. * @param[in] p_public_key A pointer to the public key to use if using LESC, or NULL.
  93. *
  94. * @retval NRF_SUCCESS Success.
  95. * @retval NRF_ERROR_INVALID_STATE No parameters have been requested on that conn_handle, or
  96. * the link is disconnecting.
  97. * @retval NRF_ERROR_INVALID_PARAM Invalid combination of parameters (not including conn_handle).
  98. * @retval NRF_ERROR_TIMEOUT There has been an SMP timeout, so no more SMP operations
  99. * can be performed on this link.
  100. * @retval BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle.
  101. * @retval NRF_ERROR_BUSY No write buffer. Reattempt later.
  102. * @retval NRF_ERROR_INTERNAL A fatal error occurred.
  103. */
  104. ret_code_t smd_params_reply(uint16_t conn_handle,
  105. ble_gap_sec_params_t * p_sec_params,
  106. ble_gap_lesc_p256_pk_t * p_public_key);
  107. /**@brief Function for initiating security on the link, with the specified parameters.
  108. *
  109. * @note If the connection is a peripheral connection, this will send a security request to the
  110. * master, but the master is not obligated to initiate pairing or encryption in response.
  111. * @note If the connection is a central connection and a key is available, the parameters will be
  112. * used to determine whether to re-pair or to encrypt using the existing key. If no key is
  113. * available, pairing will be started.
  114. *
  115. * @param[in] conn_handle Handle of the connection to initiate pairing on.
  116. * @param[in] p_sec_params The security parameters to use for this link. As a central, this can
  117. * be NULL to reject a slave security request.
  118. * @param[in] force_repairing Whether to force a pairing procedure to happen regardless of whether
  119. * an encryption key already exists. This argument is only relevant for
  120. * the central role. Recommended value: false
  121. *
  122. * @retval NRF_SUCCESS Success.
  123. * @retval NRF_ERROR_NULL p_sec_params was NULL (peripheral only).
  124. * @retval NRF_ERROR_INVALID_STATE A security procedure is already in progress on the link,
  125. * or the link is disconnecting.
  126. * @retval NRF_ERROR_INVALID_PARAM Invalid combination of parameters (not including conn_handle).
  127. * @retval NRF_ERROR_INVALID_DATA Peer is bonded, but no LTK was found, and repairing was
  128. * not requested.
  129. * @retval NRF_ERROR_BUSY Unable to initiate procedure at this time.
  130. * @retval NRF_ERROR_TIMEOUT There has been an SMP timeout, so no more SMP operations
  131. * can be performed on this link.
  132. * @retval BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle.
  133. * @retval NRF_ERROR_INTERNAL No more available peer IDs.
  134. */
  135. ret_code_t smd_link_secure(uint16_t conn_handle,
  136. ble_gap_sec_params_t * p_sec_params,
  137. bool force_repairing);
  138. /** @}
  139. * @endcond
  140. */
  141. #ifdef __cplusplus
  142. }
  143. #endif
  144. #endif /* SECURITY_DISPATCHER_H__ */