peer_id.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* Copyright (c) 2015 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. #ifndef PEER_ID_H__
  13. #define PEER_ID_H__
  14. #include <stdint.h>
  15. #include "sdk_errors.h"
  16. #include "ble_gap.h"
  17. #include "peer_manager_types.h"
  18. /**
  19. * @cond NO_DOXYGEN
  20. * @defgroup peer_id Peer IDs
  21. * @ingroup peer_manager
  22. * @{
  23. * @brief An internal module of @ref peer_manager. This module keeps track of which peer IDs are in
  24. * use and which are free.
  25. */
  26. /**@brief Function for initializing the module.
  27. */
  28. void peer_id_init(void);
  29. /**@brief Function for claiming an unused peer ID.
  30. *
  31. * @param peer_id The peer ID to allocate. If this is @ref PM_PEER_ID_INVALID, the first available
  32. * will be allocated.
  33. *
  34. * @return The allocated peer ID.
  35. * @retval PM_PEER_ID_INVALID If no peer ID could be allocated or module is not initialized.
  36. */
  37. pm_peer_id_t peer_id_allocate(pm_peer_id_t peer_id);
  38. /**@brief Function for marking a peer ID for deletion.
  39. *
  40. * @param peer_id The peer ID to delete.
  41. *
  42. * @retval true Deletion was successful.
  43. * @retval false Peer ID already marked for deletion, peer_id was PM_PEER_ID_INVALID, or module is
  44. * not initialized.
  45. */
  46. bool peer_id_delete(pm_peer_id_t peer_id);
  47. /**@brief Function for freeing a peer ID and clearing all data associated with it in persistent
  48. * storage.
  49. *
  50. * @param[in] peer_id Peer ID to free.
  51. */
  52. void peer_id_free(pm_peer_id_t peer_id);
  53. /**@brief Function for finding out whether a peer ID is marked for deletion.
  54. *
  55. * @param[in] peer_id The peer ID to inquire about.
  56. *
  57. * @retval true peer_id is in marked for deletion.
  58. * @retval false peer_id is not marked for deletion, or the module is not initialized.
  59. */
  60. bool peer_id_is_deleted(pm_peer_id_t peer_id);
  61. /**@brief Function for finding out whether a peer ID is in use.
  62. *
  63. * @param[in] peer_id The peer ID to inquire about.
  64. *
  65. * @retval true peer_id is in use.
  66. * @retval false peer_id is free, or the module is not initialized.
  67. */
  68. bool peer_id_is_allocated(pm_peer_id_t peer_id);
  69. /**@brief Function for getting the next peer ID in the sequence of all used peer IDs. Can be
  70. * used to loop through all used peer IDs.
  71. *
  72. * @note @ref PM_PEER_ID_INVALID is considered to be before the first and after the last ordinary
  73. * peer ID.
  74. *
  75. * @param[in] prev_peer_id The previous peer ID.
  76. *
  77. * @return The next peer ID.
  78. * @return The first used peer ID if prev_peer_id was @ref PM_PEER_ID_INVALID.
  79. * @retval PM_PEER_ID_INVALID if prev_peer_id was the last ordinary peer ID or the module is
  80. * not initialized.
  81. */
  82. pm_peer_id_t peer_id_get_next_used(pm_peer_id_t prev_peer_id);
  83. /**@brief Function for getting the next peer ID in the sequence of all peer IDs marked for deletion.
  84. * Can be used to loop through all peer IDs marked for deletion.
  85. *
  86. * @note @ref PM_PEER_ID_INVALID is considered to be before the first and after the last ordinary
  87. * peer ID.
  88. *
  89. * @param[in] prev_peer_id The previous peer ID.
  90. *
  91. * @return The next peer ID.
  92. * @return The first used peer ID if prev_peer_id was @ref PM_PEER_ID_INVALID.
  93. * @retval PM_PEER_ID_INVALID if prev_peer_id was the last ordinary peer ID or the module is
  94. * not initialized.
  95. */
  96. pm_peer_id_t peer_id_get_next_deleted(pm_peer_id_t prev_peer_id);
  97. /**@brief Function for querying the number of valid peer IDs available. I.E the number of peers
  98. * in persistent storage.
  99. *
  100. * @return The number of valid peer IDs, or 0 if module is not initialized.
  101. */
  102. uint32_t peer_id_n_ids(void);
  103. /** @}
  104. * @endcond
  105. */
  106. #endif /* PEER_ID_H__ */