peer_manager_internal.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /**
  2. * Copyright (c) 2015 - 2018, 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 PEER_MANAGER_INTERNAL_H__
  41. #define PEER_MANAGER_INTERNAL_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. * @file peer_manager_types.h
  53. *
  54. * @addtogroup peer_manager
  55. * @brief File containing definitions used solely inside the Peer Manager's modules.
  56. * @{
  57. */
  58. ANON_UNIONS_ENABLE;
  59. /**@brief One piece of data associated with a peer, together with its type.
  60. *
  61. * @note This type is deprecated.
  62. */
  63. typedef struct
  64. {
  65. uint16_t length_words; /**< @brief The length of the data in words. */
  66. pm_peer_data_id_t data_id; /**< @brief ID that specifies the type of data (defines which member of the union is used). */
  67. union
  68. {
  69. pm_peer_data_bonding_t * p_bonding_data; /**< @brief The exchanged bond information in addition to metadata of the bonding. */
  70. uint32_t * p_peer_rank; /**< @brief A value locally assigned to this peer. Its interpretation is up to the user. The rank is not set automatically by the Peer Manager, but it is assigned by the user using either @ref pm_peer_rank_highest or a @ref PM_PEER_DATA_FUNCTIONS function. */
  71. uint32_t * p_central_addr_res; /**< @brief Value of peer's Central Address Resolution characteristic. */
  72. bool * p_service_changed_pending; /**< @brief Whether a service changed indication should be sent to the peer. */
  73. pm_peer_data_local_gatt_db_t * p_local_gatt_db; /**< @brief Persistent information pertaining to a peer GATT client. */
  74. ble_gatt_db_srv_t * p_remote_gatt_db; /**< @brief Persistent information pertaining to a peer GATT server. */
  75. uint8_t * p_application_data; /**< @brief Arbitrary data to associate with the peer. This data can be freely used by the application. */
  76. void * p_all_data; /**< @brief Generic access pointer to the data. It is used only to handle the data without regard to type. */
  77. }; /**< @brief The data. */
  78. } pm_peer_data_t;
  79. /**@brief Immutable version of @ref pm_peer_data_t.
  80. *
  81. * @note This type is deprecated.
  82. */
  83. typedef struct
  84. {
  85. uint16_t length_words; /**< @brief The length of the data in words. */
  86. pm_peer_data_id_t data_id; /**< @brief ID that specifies the type of data (defines which member of the union is used). */
  87. union
  88. {
  89. pm_peer_data_bonding_t const * p_bonding_data; /**< @brief Immutable @ref pm_peer_data_t::p_bonding_data. */
  90. uint32_t const * p_peer_rank; /**< @brief Immutable @ref pm_peer_data_t::p_peer_rank. */
  91. uint32_t const * p_central_addr_res; /**< @brief Immutable @ref pm_peer_data_t::p_central_addr_res. */
  92. bool const * p_service_changed_pending; /**< @brief Immutable @ref pm_peer_data_t::p_service_changed_pending. */
  93. pm_peer_data_local_gatt_db_t const * p_local_gatt_db; /**< @brief Immutable @ref pm_peer_data_t::p_local_gatt_db. */
  94. ble_gatt_db_srv_t const * p_remote_gatt_db; /**< @brief Immutable @ref pm_peer_data_t::p_remote_gatt_db. */
  95. uint8_t const * p_application_data; /**< @brief Immutable @ref pm_peer_data_t::p_application_data. */
  96. void const * p_all_data; /**< @brief Immutable @ref pm_peer_data_t::p_all_data. */
  97. }; /**< @brief The data. */
  98. } pm_peer_data_const_t;
  99. ANON_UNIONS_DISABLE;
  100. /**@brief Version of @ref pm_peer_data_t that reflects the structure of peer data in flash.
  101. *
  102. * @note This type is deprecated.
  103. */
  104. typedef pm_peer_data_const_t pm_peer_data_flash_t;
  105. /**@brief Event handler for events from the @ref peer_manager module.
  106. *
  107. * @sa pm_register
  108. *
  109. * @param[in] p_event The event that has occurred.
  110. */
  111. typedef void (*pm_evt_handler_internal_t)(pm_evt_t * p_event);
  112. /**@brief Macro for calculating the flash size of bonding data.
  113. *
  114. * @return The number of words that the data takes in flash.
  115. */
  116. #define PM_BONDING_DATA_N_WORDS() BYTES_TO_WORDS(sizeof(pm_peer_data_bonding_t))
  117. /**@brief Macro for calculating the flash size of service changed pending state.
  118. *
  119. * @return The number of words that the data takes in flash.
  120. */
  121. #define PM_SC_STATE_N_WORDS() BYTES_TO_WORDS(sizeof(bool))
  122. /**@brief Macro for calculating the flash size of local GATT database data.
  123. *
  124. * @param[in] local_db_len The length, in bytes, of the database as reported by the SoftDevice.
  125. *
  126. * @return The number of words that the data takes in flash.
  127. */
  128. #define PM_LOCAL_DB_N_WORDS(local_db_len) \
  129. BYTES_TO_WORDS((local_db_len) + PM_LOCAL_DB_LEN_OVERHEAD_BYTES)
  130. /**@brief Macro for calculating the length of a local GATT database attribute array.
  131. *
  132. * @param[in] n_words The number of words that the data takes in flash.
  133. *
  134. * @return The length of the database attribute array.
  135. */
  136. #define PM_LOCAL_DB_LEN(n_words) (((n_words) * BYTES_PER_WORD) - PM_LOCAL_DB_LEN_OVERHEAD_BYTES)
  137. /**@brief Macro for calculating the flash size of remote GATT database data.
  138. *
  139. * @param[in] service_count The number of services in the service array.
  140. *
  141. * @return The number of words that the data takes in flash.
  142. */
  143. #define PM_REMOTE_DB_N_WORDS(service_count) BYTES_TO_WORDS(sizeof(ble_gatt_db_srv_t) * (service_count))
  144. /**@brief Macro for calculating the flash size of remote GATT database data.
  145. *
  146. * @param[in] n_words The length in number of words.
  147. *
  148. * @return The number of words that the data takes in flash.
  149. */
  150. #define PM_REMOTE_DB_N_SERVICES(n_words) (((n_words) * BYTES_PER_WORD) / sizeof(ble_gatt_db_srv_t))
  151. /**@brief Function for calculating the flash size of the usage index.
  152. *
  153. * @return The number of words that the data takes in flash.
  154. */
  155. #define PM_USAGE_INDEX_N_WORDS() BYTES_TO_WORDS(sizeof(uint32_t))
  156. /** @}
  157. * @endcond
  158. */
  159. #ifdef NRF_PM_DEBUG
  160. #define NRF_PM_DEBUG_CHECK(condition) \
  161. if (!(condition)) \
  162. { \
  163. __asm("bkpt #0"); \
  164. }
  165. #else
  166. // Prevent "variable set but never used" compiler warnings.
  167. #define NRF_PM_DEBUG_CHECK(condition) (void)(condition)
  168. #endif
  169. #ifdef __cplusplus
  170. }
  171. #endif
  172. #endif /* PEER_MANAGER_INTERNAL_H__ */