esp_central.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Unlicense OR CC0-1.0
  5. */
  6. #ifndef H_ESP_CENTRAL_
  7. #define H_ESP_CENTRAL_
  8. #include "modlog/modlog.h"
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. #define PEER_ADDR_VAL_SIZE 6
  13. /** Misc. */
  14. void print_bytes(const uint8_t *bytes, int len);
  15. void print_mbuf(const struct os_mbuf *om);
  16. void print_mbuf_data(const struct os_mbuf *om);
  17. char *addr_str(const void *addr);
  18. void print_uuid(const ble_uuid_t *uuid);
  19. void print_conn_desc(const struct ble_gap_conn_desc *desc);
  20. void print_adv_fields(const struct ble_hs_adv_fields *fields);
  21. void ext_print_adv_report(const void *param);
  22. /** Peer. */
  23. struct peer_dsc {
  24. SLIST_ENTRY(peer_dsc) next;
  25. struct ble_gatt_dsc dsc;
  26. };
  27. SLIST_HEAD(peer_dsc_list, peer_dsc);
  28. struct peer_chr {
  29. SLIST_ENTRY(peer_chr) next;
  30. struct ble_gatt_chr chr;
  31. struct peer_dsc_list dscs;
  32. };
  33. SLIST_HEAD(peer_chr_list, peer_chr);
  34. struct peer_svc {
  35. SLIST_ENTRY(peer_svc) next;
  36. struct ble_gatt_svc svc;
  37. struct peer_chr_list chrs;
  38. };
  39. SLIST_HEAD(peer_svc_list, peer_svc);
  40. struct peer;
  41. typedef void peer_disc_fn(const struct peer *peer, int status, void *arg);
  42. /**
  43. * @brief The callback function for the devices traversal.
  44. *
  45. * @param peer
  46. * @param arg
  47. * @return int 0, continue; Others, stop the traversal.
  48. *
  49. */
  50. typedef int peer_traverse_fn(const struct peer *peer, void *arg);
  51. struct peer {
  52. SLIST_ENTRY(peer) next;
  53. uint16_t conn_handle;
  54. uint8_t peer_addr[PEER_ADDR_VAL_SIZE];
  55. /** List of discovered GATT services. */
  56. struct peer_svc_list svcs;
  57. /** Keeps track of where we are in the service discovery process. */
  58. uint16_t disc_prev_chr_val;
  59. struct peer_svc *cur_svc;
  60. /** Callback that gets executed when service discovery completes. */
  61. peer_disc_fn *disc_cb;
  62. void *disc_cb_arg;
  63. };
  64. void peer_traverse_all(peer_traverse_fn *trav_cb, void *arg);
  65. int peer_disc_svc_by_uuid(uint16_t conn_handle, const ble_uuid_t *uuid, peer_disc_fn *disc_cb,
  66. void *disc_cb_arg);
  67. int peer_disc_all(uint16_t conn_handle, peer_disc_fn *disc_cb,
  68. void *disc_cb_arg);
  69. const struct peer_dsc *
  70. peer_dsc_find_uuid(const struct peer *peer, const ble_uuid_t *svc_uuid,
  71. const ble_uuid_t *chr_uuid, const ble_uuid_t *dsc_uuid);
  72. const struct peer_chr *
  73. peer_chr_find_uuid(const struct peer *peer, const ble_uuid_t *svc_uuid,
  74. const ble_uuid_t *chr_uuid);
  75. const struct peer_svc *
  76. peer_svc_find_uuid(const struct peer *peer, const ble_uuid_t *uuid);
  77. int peer_delete(uint16_t conn_handle);
  78. int peer_add(uint16_t conn_handle);
  79. int peer_init(int max_peers, int max_svcs, int max_chrs, int max_dscs);
  80. struct peer *
  81. peer_find(uint16_t conn_handle);
  82. #if MYNEWT_VAL(ENC_ADV_DATA)
  83. int peer_set_addr(uint16_t conn_handle, uint8_t *peer_addr);
  84. #endif
  85. #ifdef __cplusplus
  86. }
  87. #endif
  88. #endif