gattc.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef H_BLECENT_
  7. #define H_BLECENT_
  8. #pragma once
  9. #include "modlog/modlog.h"
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. struct ble_hs_adv_fields;
  14. struct ble_gap_conn_desc;
  15. struct ble_hs_cfg;
  16. union ble_store_value;
  17. union ble_store_key;
  18. #define BLECENT_SVC_ALERT_UUID 0x1811
  19. #define BLECENT_CHR_SUP_NEW_ALERT_CAT_UUID 0x2A47
  20. #define BLECENT_CHR_NEW_ALERT 0x2A46
  21. #define BLECENT_CHR_SUP_UNR_ALERT_CAT_UUID 0x2A48
  22. #define BLECENT_CHR_UNR_ALERT_STAT_UUID 0x2A45
  23. #define BLECENT_CHR_ALERT_NOT_CTRL_PT 0x2A44
  24. /** Misc. */
  25. void print_bytes(const uint8_t *bytes, int len);
  26. void print_mbuf(const struct os_mbuf *om);
  27. char *addr_str(const void *addr);
  28. void print_uuid(const ble_uuid_t *uuid);
  29. void print_conn_desc(const struct ble_gap_conn_desc *desc);
  30. void print_adv_fields(const struct ble_hs_adv_fields *fields);
  31. /** Peer. */
  32. struct peer_dsc {
  33. SLIST_ENTRY(peer_dsc) next;
  34. struct ble_gatt_dsc dsc;
  35. };
  36. SLIST_HEAD(peer_dsc_list, peer_dsc);
  37. struct peer_chr {
  38. SLIST_ENTRY(peer_chr) next;
  39. struct ble_gatt_chr chr;
  40. struct peer_dsc_list dscs;
  41. };
  42. SLIST_HEAD(peer_chr_list, peer_chr);
  43. struct peer_svc {
  44. SLIST_ENTRY(peer_svc) next;
  45. struct ble_gatt_svc svc;
  46. struct peer_chr_list chrs;
  47. };
  48. SLIST_HEAD(peer_svc_list, peer_svc);
  49. struct peer;
  50. typedef void peer_disc_fn(const struct peer *peer, int status, void *arg);
  51. struct peer {
  52. SLIST_ENTRY(peer) next;
  53. uint16_t conn_handle;
  54. /** List of discovered GATT services. */
  55. struct peer_svc_list svcs;
  56. /** Keeps track of where we are in the service discovery process. */
  57. uint16_t disc_prev_chr_val;
  58. struct peer_svc *cur_svc;
  59. /** Callback that gets executed when service discovery completes. */
  60. peer_disc_fn *disc_cb;
  61. void *disc_cb_arg;
  62. };
  63. int peer_disc_all(uint16_t conn_handle, peer_disc_fn *disc_cb,
  64. void *disc_cb_arg);
  65. const struct peer_dsc *
  66. peer_dsc_find_uuid(const struct peer *peer, const ble_uuid_t *svc_uuid,
  67. const ble_uuid_t *chr_uuid, const ble_uuid_t *dsc_uuid);
  68. const struct peer_chr *
  69. peer_chr_find_uuid(const struct peer *peer, const ble_uuid_t *svc_uuid,
  70. const ble_uuid_t *chr_uuid);
  71. const struct peer_svc *
  72. peer_svc_find_uuid(const struct peer *peer, const ble_uuid_t *uuid);
  73. int peer_delete(uint16_t conn_handle);
  74. int peer_add(uint16_t conn_handle);
  75. int peer_init(int max_peers, int max_svcs, int max_chrs, int max_dscs);
  76. struct peer *
  77. peer_find(uint16_t conn_handle);
  78. /* Console */
  79. int scli_init(void);
  80. void ble_register_cli(void);
  81. int scli_receive_key(int *key);
  82. int cli_receive_key(int *key);
  83. int scli_receive_yesno(bool *key);
  84. void scli_reset_queue(void);
  85. #ifdef __cplusplus
  86. }
  87. #endif
  88. #endif