xref: /nrf52832-nimble/packages/NimBLE-latest/apps/blecent/src/blecent.h (revision 042d53a763ad75cb1465103098bb88c245d95138)
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 
20 #ifndef H_BLECENT_
21 #define H_BLECENT_
22 
23 #include "nimble/ble.h"
24 #include "modlog/modlog.h"
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 struct ble_hs_adv_fields;
30 struct ble_gap_conn_desc;
31 struct ble_hs_cfg;
32 union ble_store_value;
33 union ble_store_key;
34 
35 #define BLECENT_SVC_ALERT_UUID              0x1811
36 #define BLECENT_CHR_SUP_NEW_ALERT_CAT_UUID  0x2A47
37 #define BLECENT_CHR_NEW_ALERT               0x2A46
38 #define BLECENT_CHR_SUP_UNR_ALERT_CAT_UUID  0x2A48
39 #define BLECENT_CHR_UNR_ALERT_STAT_UUID     0x2A45
40 #define BLECENT_CHR_ALERT_NOT_CTRL_PT       0x2A44
41 
42 /** Misc. */
43 void print_bytes(const uint8_t *bytes, int len);
44 void print_mbuf(const struct os_mbuf *om);
45 char *addr_str(const void *addr);
46 void print_uuid(const ble_uuid_t *uuid);
47 void print_conn_desc(const struct ble_gap_conn_desc *desc);
48 void print_adv_fields(const struct ble_hs_adv_fields *fields);
49 
50 /** Peer. */
51 struct peer_dsc {
52     SLIST_ENTRY(peer_dsc) next;
53     struct ble_gatt_dsc dsc;
54 };
55 SLIST_HEAD(peer_dsc_list, peer_dsc);
56 
57 struct peer_chr {
58     SLIST_ENTRY(peer_chr) next;
59     struct ble_gatt_chr chr;
60 
61     struct peer_dsc_list dscs;
62 };
63 SLIST_HEAD(peer_chr_list, peer_chr);
64 
65 struct peer_svc {
66     SLIST_ENTRY(peer_svc) next;
67     struct ble_gatt_svc svc;
68 
69     struct peer_chr_list chrs;
70 };
71 SLIST_HEAD(peer_svc_list, peer_svc);
72 
73 struct peer;
74 typedef void peer_disc_fn(const struct peer *peer, int status, void *arg);
75 
76 struct peer {
77     SLIST_ENTRY(peer) next;
78 
79     uint16_t conn_handle;
80 
81     /** List of discovered GATT services. */
82     struct peer_svc_list svcs;
83 
84     /** Keeps track of where we are in the service discovery process. */
85     uint16_t disc_prev_chr_val;
86     struct peer_svc *cur_svc;
87 
88     /** Callback that gets executed when service discovery completes. */
89     peer_disc_fn *disc_cb;
90     void *disc_cb_arg;
91 };
92 
93 int peer_disc_all(uint16_t conn_handle, peer_disc_fn *disc_cb,
94                   void *disc_cb_arg);
95 const struct peer_dsc *
96 peer_dsc_find_uuid(const struct peer *peer, const ble_uuid_t *svc_uuid,
97                    const ble_uuid_t *chr_uuid, const ble_uuid_t *dsc_uuid);
98 const struct peer_chr *
99 peer_chr_find_uuid(const struct peer *peer, const ble_uuid_t *svc_uuid,
100                    const ble_uuid_t *chr_uuid);
101 const struct peer_svc *
102 peer_svc_find_uuid(const struct peer *peer, const ble_uuid_t *uuid);
103 int peer_delete(uint16_t conn_handle);
104 int peer_add(uint16_t conn_handle);
105 int peer_init(int max_peers, int max_svcs, int max_chrs, int max_dscs);
106 
107 #ifdef __cplusplus
108 }
109 #endif
110 
111 #endif
112