blecent.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. #ifndef H_BLECENT_
  20. #define H_BLECENT_
  21. #include "nimble/ble.h"
  22. #include "modlog/modlog.h"
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. struct ble_hs_adv_fields;
  27. struct ble_gap_conn_desc;
  28. struct ble_hs_cfg;
  29. union ble_store_value;
  30. union ble_store_key;
  31. #define BLECENT_SVC_ALERT_UUID 0x1811
  32. #define BLECENT_CHR_SUP_NEW_ALERT_CAT_UUID 0x2A47
  33. #define BLECENT_CHR_NEW_ALERT 0x2A46
  34. #define BLECENT_CHR_SUP_UNR_ALERT_CAT_UUID 0x2A48
  35. #define BLECENT_CHR_UNR_ALERT_STAT_UUID 0x2A45
  36. #define BLECENT_CHR_ALERT_NOT_CTRL_PT 0x2A44
  37. /** Misc. */
  38. void print_bytes(const uint8_t *bytes, int len);
  39. void print_mbuf(const struct os_mbuf *om);
  40. char *addr_str(const void *addr);
  41. void print_uuid(const ble_uuid_t *uuid);
  42. void print_conn_desc(const struct ble_gap_conn_desc *desc);
  43. void print_adv_fields(const struct ble_hs_adv_fields *fields);
  44. /** Peer. */
  45. struct peer_dsc {
  46. SLIST_ENTRY(peer_dsc) next;
  47. struct ble_gatt_dsc dsc;
  48. };
  49. SLIST_HEAD(peer_dsc_list, peer_dsc);
  50. struct peer_chr {
  51. SLIST_ENTRY(peer_chr) next;
  52. struct ble_gatt_chr chr;
  53. struct peer_dsc_list dscs;
  54. };
  55. SLIST_HEAD(peer_chr_list, peer_chr);
  56. struct peer_svc {
  57. SLIST_ENTRY(peer_svc) next;
  58. struct ble_gatt_svc svc;
  59. struct peer_chr_list chrs;
  60. };
  61. SLIST_HEAD(peer_svc_list, peer_svc);
  62. struct peer;
  63. typedef void peer_disc_fn(const struct peer *peer, int status, void *arg);
  64. struct peer {
  65. SLIST_ENTRY(peer) next;
  66. uint16_t conn_handle;
  67. /** List of discovered GATT services. */
  68. struct peer_svc_list svcs;
  69. /** Keeps track of where we are in the service discovery process. */
  70. uint16_t disc_prev_chr_val;
  71. struct peer_svc *cur_svc;
  72. /** Callback that gets executed when service discovery completes. */
  73. peer_disc_fn *disc_cb;
  74. void *disc_cb_arg;
  75. };
  76. int peer_disc_all(uint16_t conn_handle, peer_disc_fn *disc_cb,
  77. void *disc_cb_arg);
  78. const struct peer_dsc *
  79. peer_dsc_find_uuid(const struct peer *peer, const ble_uuid_t *svc_uuid,
  80. const ble_uuid_t *chr_uuid, const ble_uuid_t *dsc_uuid);
  81. const struct peer_chr *
  82. peer_chr_find_uuid(const struct peer *peer, const ble_uuid_t *svc_uuid,
  83. const ble_uuid_t *chr_uuid);
  84. const struct peer_svc *
  85. peer_svc_find_uuid(const struct peer *peer, const ble_uuid_t *uuid);
  86. int peer_delete(uint16_t conn_handle);
  87. int peer_add(uint16_t conn_handle);
  88. int peer_init(int max_peers, int max_svcs, int max_chrs, int max_dscs);
  89. #ifdef __cplusplus
  90. }
  91. #endif
  92. #endif