ble_conn_params.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /**
  2. * Copyright (c) 2012 - 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. /** @file
  41. *
  42. * @defgroup ble_conn_params Connection Parameters Negotiation
  43. * @{
  44. * @ingroup ble_sdk_lib
  45. * @brief Module for initiating and executing a connection parameters negotiation procedure.
  46. */
  47. #ifndef BLE_CONN_PARAMS_H__
  48. #define BLE_CONN_PARAMS_H__
  49. #include <stdint.h>
  50. #include "ble.h"
  51. #include "ble_srv_common.h"
  52. #include "sdk_errors.h"
  53. #ifdef __cplusplus
  54. extern "C" {
  55. #endif
  56. /**@brief Connection Parameters Module event type. */
  57. typedef enum
  58. {
  59. BLE_CONN_PARAMS_EVT_FAILED, //!< Negotiation procedure failed.
  60. BLE_CONN_PARAMS_EVT_SUCCEEDED //!< Negotiation procedure succeeded.
  61. } ble_conn_params_evt_type_t;
  62. /**@brief Connection Parameters Module event. */
  63. typedef struct
  64. {
  65. ble_conn_params_evt_type_t evt_type; //!< Type of event.
  66. uint16_t conn_handle; //!< Connection the event refers to.
  67. } ble_conn_params_evt_t;
  68. /**@brief Connection Parameters Module event handler type. */
  69. typedef void (*ble_conn_params_evt_handler_t) (ble_conn_params_evt_t * p_evt);
  70. /**@brief Connection Parameters Module init structure. This contains all options and data needed for
  71. * initialization of the connection parameters negotiation module. */
  72. typedef struct
  73. {
  74. ble_gap_conn_params_t * p_conn_params; //!< Pointer to the connection parameters desired by the application. When calling ble_conn_params_init, if this parameter is set to NULL, the connection parameters will be fetched from host.
  75. uint32_t first_conn_params_update_delay; //!< Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (in number of timer ticks).
  76. uint32_t next_conn_params_update_delay; //!< Time between each call to sd_ble_gap_conn_param_update after the first (in number of timer ticks). Recommended value 30 seconds as per BLUETOOTH SPECIFICATION Version 4.0.
  77. uint8_t max_conn_params_update_count; //!< Number of attempts before giving up the negotiation.
  78. uint16_t start_on_notify_cccd_handle; //!< If procedure is to be started when notification is started, set this to the handle of the corresponding CCCD. Set to BLE_GATT_HANDLE_INVALID if procedure is to be started on connect event.
  79. bool disconnect_on_fail; //!< Set to TRUE if a failed connection parameters update shall cause an automatic disconnection, set to FALSE otherwise.
  80. ble_conn_params_evt_handler_t evt_handler; //!< Event handler to be called for handling events in the Connection Parameters.
  81. ble_srv_error_handler_t error_handler; //!< Function to be called in case of an error.
  82. } ble_conn_params_init_t;
  83. /**@brief Function for initializing the Connection Parameters module.
  84. *
  85. * @note If the negotiation procedure should be triggered when notification/indication of
  86. * any characteristic is enabled by the peer, then this function must be called after
  87. * having initialized the services.
  88. *
  89. * @param[in] p_init This contains information needed to initialize this module.
  90. *
  91. * @retval NRF_SUCCESS Successful initialization.
  92. * @retval NRF_ERROR_INVALID_ADDR The provided Connection Parameters pointer is invalid.
  93. * @retval NRF_ERROR_INVALID_PARAM The provided Connection Parameters are not valid.
  94. * @retval NRF_ERROR_NULL @p p_init was NULL.
  95. * @retval NRF_ERROR_INTERNAL An unexpected error occurred.
  96. */
  97. ret_code_t ble_conn_params_init(const ble_conn_params_init_t * p_init);
  98. /**@brief Function for stopping the Connection Parameters module.
  99. *
  100. * @details This function is intended to be used by the application to clean up the connection
  101. * parameters update module. This will stop the connection parameters update timer if
  102. * running, thereby preventing any impending connection parameters update procedure. This
  103. * function must be called by the application when it needs to clean itself up (for
  104. * example, before disabling the bluetooth SoftDevice) so that an unwanted timer expiry
  105. * event can be avoided.
  106. *
  107. * @retval NRF_SUCCESS Successfully stopped module.
  108. * @retval NRF_ERROR_BUSY Could not complete operation at this time. Try again later.
  109. Note that some timers may have been disabled.
  110. * @retval NRF_ERROR_INTERNAL An unexpected error occurred.
  111. */
  112. ret_code_t ble_conn_params_stop(void);
  113. /**@brief Function for changing the current connection parameters to a new set.
  114. *
  115. * @details Use this function to change the connection parameters to a new set of parameter
  116. * (ie different from the ones given at init of the module).
  117. * This function is useful for scenario where most of the time the application
  118. * needs a relatively big connection interval, and just sometimes, for a temporary
  119. * period requires shorter connection interval, for example to transfer a higher
  120. * amount of data.
  121. * If the given parameters does not match the current connection's parameters
  122. * this function initiates a new negotiation.
  123. *
  124. * @param[in] conn_handle The connection to change connection parameters on.
  125. * @param[in] p_new_params This contains the new connections parameters to setup.
  126. *
  127. * @retval NRF_SUCCESS Successfully started Connection Parameter update procedure.
  128. * @retval NRF_ERROR_INVALID_ADDR The provided Connection Parameters pointer is invalid.
  129. * @retval NRF_ERROR_INVALID_PARAM The provided Connection Parameters are not valid.
  130. * @retval BLE_ERROR_INVALID_CONN_HANDLE The provided connection handle is invalid.
  131. * @retval NRF_ERROR_INVALID_STATE The connection is not in a state where this operation can
  132. * performed.
  133. * @retval NRF_ERROR_BUSY Could not start operation at this time. Try again later.
  134. * @retval NRF_ERROR_NO_MEM The SoftDevice lacks the memory to perform the action.
  135. */
  136. ret_code_t ble_conn_params_change_conn_params(uint16_t conn_handle,
  137. ble_gap_conn_params_t * p_new_params);
  138. #ifdef __cplusplus
  139. }
  140. #endif
  141. #endif // BLE_CONN_PARAMS_H__
  142. /** @} */