ble_conn_params.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. *
  11. */
  12. /** @file
  13. *
  14. * @defgroup ble_sdk_lib_conn_params Connection Parameters Negotiation
  15. * @{
  16. * @ingroup ble_sdk_lib
  17. * @brief Module for initiating and executing a connection parameters negotiation procedure.
  18. */
  19. #ifndef BLE_CONN_PARAMS_H__
  20. #define BLE_CONN_PARAMS_H__
  21. #include <stdint.h>
  22. #include "ble.h"
  23. #include "ble_srv_common.h"
  24. /**@brief Connection Parameters Module event type. */
  25. typedef enum
  26. {
  27. BLE_CONN_PARAMS_EVT_FAILED , /**< Negotiation procedure failed. */
  28. BLE_CONN_PARAMS_EVT_SUCCEEDED /**< Negotiation procedure succeeded. */
  29. } ble_conn_params_evt_type_t;
  30. /**@brief Connection Parameters Module event. */
  31. typedef struct
  32. {
  33. ble_conn_params_evt_type_t evt_type; /**< Type of event. */
  34. } ble_conn_params_evt_t;
  35. /**@brief Connection Parameters Module event handler type. */
  36. typedef void (*ble_conn_params_evt_handler_t) (ble_conn_params_evt_t * p_evt);
  37. /**@brief Connection Parameters Module init structure. This contains all options and data needed for
  38. * initialization of the connection parameters negotiation module. */
  39. typedef struct
  40. {
  41. 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. */
  42. 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). */
  43. 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. */
  44. uint8_t max_conn_params_update_count; /**< Number of attempts before giving up the negotiation. */
  45. 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. */
  46. bool disconnect_on_fail; /**< Set to TRUE if a failed connection parameters update shall cause an automatic disconnection, set to FALSE otherwise. */
  47. ble_conn_params_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Connection Parameters. */
  48. ble_srv_error_handler_t error_handler; /**< Function to be called in case of an error. */
  49. } ble_conn_params_init_t;
  50. /**@brief Function for initializing the Connection Parameters module.
  51. *
  52. * @note If the negotiation procedure should be triggered when notification/indication of
  53. * any characteristic is enabled by the peer, then this function must be called after
  54. * having initialized the services.
  55. *
  56. * @param[in] p_init This contains information needed to initialize this module.
  57. *
  58. * @return NRF_SUCCESS on successful initialization, otherwise an error code.
  59. */
  60. uint32_t ble_conn_params_init(const ble_conn_params_init_t * p_init);
  61. /**@brief Function for stopping the Connection Parameters module.
  62. *
  63. * @details This function is intended to be used by the application to clean up the connection
  64. * parameters update module. This will stop the connection parameters update timer if
  65. * running, thereby preventing any impending connection parameters update procedure. This
  66. * function must be called by the application when it needs to clean itself up (for
  67. * example, before disabling the bluetooth SoftDevice) so that an unwanted timer expiry
  68. * event can be avoided.
  69. *
  70. * @return NRF_SUCCESS on successful initialization, otherwise an error code.
  71. */
  72. uint32_t ble_conn_params_stop(void);
  73. /**@brief Function for changing the current connection parameters to a new set.
  74. *
  75. * @details Use this function to change the connection parameters to a new set of parameter
  76. * (ie different from the ones given at init of the module).
  77. * This function is usefull for scenario where most of the time the application
  78. * needs a relatively big connection interval, and just sometimes, for a temporary
  79. * period requires shorter connection interval, for example to transfer a higher
  80. * amount of data.
  81. * If the given parameters does not match the current connection's parameters
  82. * this function initiates a new negotiation.
  83. *
  84. * @param[in] new_params This contains the new connections parameters to setup.
  85. *
  86. * @return NRF_SUCCESS on successful initialization, otherwise an error code.
  87. */
  88. uint32_t ble_conn_params_change_conn_params(ble_gap_conn_params_t *new_params);
  89. /**@brief Function for handling the Application's BLE Stack events.
  90. *
  91. * @details Handles all events from the BLE stack that are of interest to this module.
  92. *
  93. * @param[in] p_ble_evt The event received from the BLE stack.
  94. */
  95. void ble_conn_params_on_ble_evt(ble_evt_t * p_ble_evt);
  96. #endif // BLE_CONN_PARAMS_H__
  97. /** @} */