peer_id.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /**
  2. * Copyright (c) 2015 - 2019, 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_ID_H__
  41. #define PEER_ID_H__
  42. #include <stdint.h>
  43. #include "sdk_errors.h"
  44. #include "ble_gap.h"
  45. #include "peer_manager_types.h"
  46. #ifdef __cplusplus
  47. extern "C" {
  48. #endif
  49. /**
  50. * @cond NO_DOXYGEN
  51. * @defgroup peer_id Peer IDs
  52. * @ingroup peer_manager
  53. * @{
  54. * @brief An internal module of @ref peer_manager. This module keeps track of which peer IDs are in
  55. * use and which are free.
  56. */
  57. /**@brief Function for initializing the module.
  58. */
  59. void peer_id_init(void);
  60. /**@brief Function for claiming an unused peer ID.
  61. *
  62. * @param peer_id The peer ID to allocate. If this is @ref PM_PEER_ID_INVALID, the first available
  63. * will be allocated.
  64. *
  65. * @return The allocated peer ID.
  66. * @retval PM_PEER_ID_INVALID If no peer ID could be allocated or module is not initialized.
  67. */
  68. pm_peer_id_t peer_id_allocate(pm_peer_id_t peer_id);
  69. /**@brief Function for marking a peer ID for deletion.
  70. *
  71. * @param peer_id The peer ID to delete.
  72. *
  73. * @retval true Deletion was successful.
  74. * @retval false Peer ID already marked for deletion, peer_id was PM_PEER_ID_INVALID, or module is
  75. * not initialized.
  76. */
  77. bool peer_id_delete(pm_peer_id_t peer_id);
  78. /**@brief Function for freeing a peer ID and clearing all data associated with it in persistent
  79. * storage.
  80. *
  81. * @param[in] peer_id Peer ID to free.
  82. */
  83. void peer_id_free(pm_peer_id_t peer_id);
  84. /**@brief Function for finding out whether a peer ID is marked for deletion.
  85. *
  86. * @param[in] peer_id The peer ID to inquire about.
  87. *
  88. * @retval true peer_id is in marked for deletion.
  89. * @retval false peer_id is not marked for deletion, or the module is not initialized.
  90. */
  91. bool peer_id_is_deleted(pm_peer_id_t peer_id);
  92. /**@brief Function for finding out whether a peer ID is in use.
  93. *
  94. * @param[in] peer_id The peer ID to inquire about.
  95. *
  96. * @retval true peer_id is in use.
  97. * @retval false peer_id is free, or the module is not initialized.
  98. */
  99. bool peer_id_is_allocated(pm_peer_id_t peer_id);
  100. /**@brief Function for getting the next peer ID in the sequence of all used peer IDs. Can be
  101. * used to loop through all used peer IDs.
  102. *
  103. * @note @ref PM_PEER_ID_INVALID is considered to be before the first and after the last ordinary
  104. * peer ID.
  105. *
  106. * @param[in] prev_peer_id The previous peer ID.
  107. *
  108. * @return The next peer ID.
  109. * @return The first used peer ID if prev_peer_id was @ref PM_PEER_ID_INVALID.
  110. * @retval PM_PEER_ID_INVALID if prev_peer_id was the last ordinary peer ID or the module is
  111. * not initialized.
  112. */
  113. pm_peer_id_t peer_id_get_next_used(pm_peer_id_t prev_peer_id);
  114. /**@brief Function for getting the next peer ID in the sequence of all peer IDs marked for deletion.
  115. * Can be used to loop through all peer IDs marked for deletion.
  116. *
  117. * @note @ref PM_PEER_ID_INVALID is considered to be before the first and after the last ordinary
  118. * peer ID.
  119. *
  120. * @param[in] prev_peer_id The previous peer ID.
  121. *
  122. * @return The next peer ID.
  123. * @return The first used peer ID if prev_peer_id was @ref PM_PEER_ID_INVALID.
  124. * @retval PM_PEER_ID_INVALID if prev_peer_id was the last ordinary peer ID or the module is
  125. * not initialized.
  126. */
  127. pm_peer_id_t peer_id_get_next_deleted(pm_peer_id_t prev_peer_id);
  128. /**@brief Function for querying the number of valid peer IDs available. I.E the number of peers
  129. * in persistent storage.
  130. *
  131. * @return The number of valid peer IDs, or 0 if module is not initialized.
  132. */
  133. uint32_t peer_id_n_ids(void);
  134. /** @}
  135. * @endcond
  136. */
  137. #ifdef __cplusplus
  138. }
  139. #endif
  140. #endif /* PEER_ID_H__ */