xref: /nrf52832-nimble/packages/NimBLE-latest/nimble/host/src/ble_gatt_priv.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_BLE_GATT_PRIV_
21 #define H_BLE_GATT_PRIV_
22 
23 #include "syscfg/syscfg.h"
24 #include "stats/stats.h"
25 #include "host/ble_gatt.h"
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 struct ble_att_read_type_adata;
31 struct ble_att_find_type_value_hinfo;
32 struct ble_att_find_info_idata;
33 struct ble_att_read_group_type_adata;
34 struct ble_att_prep_write_cmd;
35 
36 STATS_SECT_START(ble_gattc_stats)
37     STATS_SECT_ENTRY(mtu)
38     STATS_SECT_ENTRY(mtu_fail)
39     STATS_SECT_ENTRY(disc_all_svcs)
40     STATS_SECT_ENTRY(disc_all_svcs_fail)
41     STATS_SECT_ENTRY(disc_svc_uuid)
42     STATS_SECT_ENTRY(disc_svc_uuid_fail)
43     STATS_SECT_ENTRY(find_inc_svcs)
44     STATS_SECT_ENTRY(find_inc_svcs_fail)
45     STATS_SECT_ENTRY(disc_all_chrs)
46     STATS_SECT_ENTRY(disc_all_chrs_fail)
47     STATS_SECT_ENTRY(disc_chrs_uuid)
48     STATS_SECT_ENTRY(disc_chrs_uuid_fail)
49     STATS_SECT_ENTRY(disc_all_dscs)
50     STATS_SECT_ENTRY(disc_all_dscs_fail)
51     STATS_SECT_ENTRY(read)
52     STATS_SECT_ENTRY(read_fail)
53     STATS_SECT_ENTRY(read_uuid)
54     STATS_SECT_ENTRY(read_uuid_fail)
55     STATS_SECT_ENTRY(read_long)
56     STATS_SECT_ENTRY(read_long_fail)
57     STATS_SECT_ENTRY(read_mult)
58     STATS_SECT_ENTRY(read_mult_fail)
59     STATS_SECT_ENTRY(write_no_rsp)
60     STATS_SECT_ENTRY(write_no_rsp_fail)
61     STATS_SECT_ENTRY(write)
62     STATS_SECT_ENTRY(write_fail)
63     STATS_SECT_ENTRY(write_long)
64     STATS_SECT_ENTRY(write_long_fail)
65     STATS_SECT_ENTRY(write_reliable)
66     STATS_SECT_ENTRY(write_reliable_fail)
67     STATS_SECT_ENTRY(notify)
68     STATS_SECT_ENTRY(notify_fail)
69     STATS_SECT_ENTRY(indicate)
70     STATS_SECT_ENTRY(indicate_fail)
71     STATS_SECT_ENTRY(proc_timeout)
72 STATS_SECT_END
73 extern STATS_SECT_DECL(ble_gattc_stats) ble_gattc_stats;
74 
75 STATS_SECT_START(ble_gatts_stats)
76     STATS_SECT_ENTRY(svcs)
77     STATS_SECT_ENTRY(chrs)
78     STATS_SECT_ENTRY(dscs)
79     STATS_SECT_ENTRY(svc_def_reads)
80     STATS_SECT_ENTRY(svc_inc_reads)
81     STATS_SECT_ENTRY(chr_def_reads)
82     STATS_SECT_ENTRY(chr_val_reads)
83     STATS_SECT_ENTRY(chr_val_writes)
84     STATS_SECT_ENTRY(dsc_reads)
85     STATS_SECT_ENTRY(dsc_writes)
86 STATS_SECT_END
87 extern STATS_SECT_DECL(ble_gatts_stats) ble_gatts_stats;
88 
89 #define BLE_GATT_CHR_DECL_SZ_16     5
90 #define BLE_GATT_CHR_DECL_SZ_128    19
91 
92 typedef uint8_t ble_gatts_conn_flags;
93 
94 struct ble_gatts_conn {
95     struct ble_gatts_clt_cfg *clt_cfgs;
96     int num_clt_cfgs;
97 
98     uint16_t indicate_val_handle;
99 };
100 
101 /*** @client. */
102 
103 int ble_gattc_locked_by_cur_task(void);
104 void ble_gatts_indicate_fail_notconn(uint16_t conn_handle);
105 
106 void ble_gattc_rx_err(uint16_t conn_handle, uint16_t handle, uint16_t status);
107 void ble_gattc_rx_mtu(uint16_t conn_handle, int status, uint16_t chan_mtu);
108 void ble_gattc_rx_read_type_adata(uint16_t conn_handle,
109                                   struct ble_att_read_type_adata *adata);
110 void ble_gattc_rx_read_type_complete(uint16_t conn_handle, int status);
111 void ble_gattc_rx_read_rsp(uint16_t conn_handle, int status,
112                            struct os_mbuf **rxom);
113 void ble_gattc_rx_read_blob_rsp(uint16_t conn_handle, int status,
114                                 struct os_mbuf **rxom);
115 void ble_gattc_rx_read_mult_rsp(uint16_t conn_handle, int status,
116                                 struct os_mbuf **rxom);
117 void ble_gattc_rx_read_group_type_adata(
118     uint16_t conn_handle, struct ble_att_read_group_type_adata *adata);
119 void ble_gattc_rx_read_group_type_complete(uint16_t conn_handle, int rc);
120 void ble_gattc_rx_find_type_value_hinfo(
121     uint16_t conn_handle, struct ble_att_find_type_value_hinfo *hinfo);
122 void ble_gattc_rx_find_type_value_complete(uint16_t conn_handle, int status);
123 void ble_gattc_rx_write_rsp(uint16_t conn_handle);
124 void ble_gattc_rx_prep_write_rsp(uint16_t conn_handle, int status,
125                                  uint16_t handle, uint16_t offset,
126                                  struct os_mbuf **rxom);
127 void ble_gattc_rx_exec_write_rsp(uint16_t conn_handle, int status);
128 void ble_gattc_rx_indicate_rsp(uint16_t conn_handle);
129 void ble_gattc_rx_find_info_idata(uint16_t conn_handle,
130                                   struct ble_att_find_info_idata *idata);
131 void ble_gattc_rx_find_info_complete(uint16_t conn_handle, int status);
132 void ble_gattc_connection_txable(uint16_t conn_handle);
133 void ble_gattc_connection_broken(uint16_t conn_handle);
134 int32_t ble_gattc_timer(void);
135 
136 int ble_gattc_any_jobs(void);
137 int ble_gattc_init(void);
138 
139 /*** @server. */
140 #define BLE_GATTS_CLT_CFG_F_NOTIFY              0x0001
141 #define BLE_GATTS_CLT_CFG_F_INDICATE            0x0002
142 #define BLE_GATTS_CLT_CFG_F_MODIFIED            0x0080 /* Internal only. */
143 #define BLE_GATTS_CLT_CFG_F_RESERVED            0xfffc
144 
145 #define BLE_GATTS_INC_SVC_LEN_NO_UUID           4
146 #define BLE_GATTS_INC_SVC_LEN_UUID              6
147 
148 /**
149  * Contains counts of resources required by the GATT server.  The contents of
150  * this struct are generally used to populate a configuration struct before
151  * the host is initialized.
152  */
153 struct ble_gatt_resources {
154     /** Number of services. */
155     uint16_t svcs;
156 
157     /** Number of included services. */
158     uint16_t incs;
159 
160     /** Number of characteristics. */
161     uint16_t chrs;
162 
163     /** Number of descriptors. */
164     uint16_t dscs;
165 
166     /**
167      * Number of client characteristic configuration descriptors.  Each of
168      * these also contributes to the total descriptor count.
169      */
170     uint16_t cccds;
171 
172     /** Total number of ATT attributes. */
173     uint16_t attrs;
174 };
175 
176 int ble_gatts_rx_indicate_ack(uint16_t conn_handle, uint16_t chr_val_handle);
177 int ble_gatts_send_next_indicate(uint16_t conn_handle);
178 void ble_gatts_tx_notifications(void);
179 void ble_gatts_bonding_restored(uint16_t conn_handle);
180 void ble_gatts_connection_broken(uint16_t conn_handle);
181 void ble_gatts_lcl_svc_foreach(ble_gatt_svc_foreach_fn cb);
182 int ble_gatts_register_svcs(const struct ble_gatt_svc_def *svcs,
183                             ble_gatt_register_fn *register_cb,
184                             void *cb_arg);
185 
186 /*** @misc. */
187 int ble_gatts_conn_can_alloc(void);
188 int ble_gatts_conn_init(struct ble_gatts_conn *gatts_conn);
189 int ble_gatts_init(void);
190 
191 #ifdef __cplusplus
192 }
193 #endif
194 
195 #endif
196