1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Changes from Qualcomm Innovation Center are provided under the following license:
*
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted (subject to the limitations in the
* disclaimer below) provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*
*/
#ifndef ANDROID_INCLUDE_BT_GATT_SERVER_H
#define ANDROID_INCLUDE_BT_GATT_SERVER_H
#include <raw_address.h>
#include <stdint.h>
#include "bt_gatt_types.h"
__BEGIN_DECLS
/** GATT value type used in response to remote read requests */
typedef struct {
uint8_t value[BTGATT_MAX_ATTR_LEN];
uint16_t handle;
uint16_t offset;
uint16_t len;
uint8_t auth_req;
} btgatt_value_t;
/** GATT remote read request response type */
typedef union {
btgatt_value_t attr_value;
uint16_t handle;
} btgatt_response_t;
/** BT-GATT Server callback structure. */
/** Callback invoked in response to register_server */
typedef void (*register_server_callback)(int status, int server_if,
const bluetooth::Uuid& app_uuid);
/** Callback indicating that a remote device has connected or been disconnected
*/
typedef void (*connection_callback)(int conn_id, int server_if, int connected,
const RawAddress& bda);
/** Callback invoked in response to create_service */
typedef void (*service_added_callback)(int status, int server_if,
const btgatt_db_element_t* service,
size_t service_count);
/** Callback invoked in response to stop_service */
typedef void (*service_stopped_callback)(int status, int server_if,
int srvc_handle);
/** Callback triggered when a service has been deleted */
typedef void (*service_deleted_callback)(int status, int server_if,
int srvc_handle);
/**
* Callback invoked when a remote device has requested to read a characteristic
* or descriptor. The application must respond by calling send_response
*/
typedef void (*request_read_callback)(int conn_id, int trans_id,
const RawAddress& bda, int attr_handle,
int offset, bool is_long);
/**
* Callback invoked when a remote device has requested to write to a
* characteristic or descriptor.
*/
typedef void (*request_write_callback)(int conn_id, int trans_id,
const RawAddress& bda, int attr_handle,
int offset, bool need_rsp, bool is_prep,
const uint8_t* value, size_t length);
/** Callback invoked when a previously prepared write is to be executed */
typedef void (*request_exec_write_callback)(int conn_id, int trans_id,
const RawAddress& bda,
int exec_write);
/**
* Callback triggered in response to send_response if the remote device
* sends a confirmation.
*/
typedef void (*response_confirmation_callback)(int status, int handle);
/**
* Callback confirming that a notification or indication has been sent
* to a remote device.
*/
typedef void (*indication_sent_callback)(int conn_id, int status);
/**
* Callback notifying an application that a remote device connection is
* currently congested and cannot receive any more data. An application should
* avoid sending more data until a further callback is received indicating the
* congestion status has been cleared.
*/
typedef void (*congestion_callback)(int conn_id, bool congested);
/** Callback invoked when the MTU for a given connection changes */
typedef void (*mtu_changed_callback)(int conn_id, int mtu);
/** Callback invoked when the PHY for a given connection changes */
typedef void (*phy_updated_callback)(int conn_id, uint8_t tx_phy,
uint8_t rx_phy, uint8_t status);
/** Callback invoked when the connection parameters for a given connection
* changes */
typedef void (*conn_updated_callback)(int conn_id, uint16_t interval,
uint16_t latency, uint16_t timeout,
uint8_t status);
/** Callback invoked when the connection's subrate parameters for a given connection
* changes */
typedef void (*subrate_change_callback)(int conn_id, uint16_t subrate_factor,
uint16_t latency, uint16_t cont_num,
uint16_t timeout, uint8_t status);
typedef struct {
register_server_callback register_server_cb;
connection_callback connection_cb;
service_added_callback service_added_cb;
service_stopped_callback service_stopped_cb;
service_deleted_callback service_deleted_cb;
request_read_callback request_read_characteristic_cb;
request_read_callback request_read_descriptor_cb;
request_write_callback request_write_characteristic_cb;
request_write_callback request_write_descriptor_cb;
request_exec_write_callback request_exec_write_cb;
response_confirmation_callback response_confirmation_cb;
indication_sent_callback indication_sent_cb;
congestion_callback congestion_cb;
mtu_changed_callback mtu_changed_cb;
phy_updated_callback phy_updated_cb;
conn_updated_callback conn_updated_cb;
subrate_change_callback subrate_chg_cb;
} btgatt_server_callbacks_t;
/** Represents the standard BT-GATT server interface. */
typedef struct {
/** Registers a GATT server application with the stack */
bt_status_t (*register_server)(const bluetooth::Uuid& uuid,
bool eatt_support);
/** Unregister a server application from the stack */
bt_status_t (*unregister_server)(int server_if);
/** Create a connection to a remote peripheral */
bt_status_t (*connect)(int server_if, const RawAddress& bd_addr,
bool is_direct, int transport);
/** Disconnect an established connection or cancel a pending one */
bt_status_t (*disconnect)(int server_if, const RawAddress& bd_addr,
int conn_id);
/** Create a new service */
bt_status_t (*add_service)(int server_if, const btgatt_db_element_t* service,
size_t service_count);
/** Stops a local service */
bt_status_t (*stop_service)(int server_if, int service_handle);
/** Delete a local service */
bt_status_t (*delete_service)(int server_if, int service_handle);
/** Send value indication to a remote device */
bt_status_t (*send_indication)(int server_if, int attribute_handle,
int conn_id, int confirm, const uint8_t* value,
size_t length);
/** Send a response to a read/write operation */
bt_status_t (*send_response)(int conn_id, int trans_id, int status,
const btgatt_response_t& response);
bt_status_t (*set_preferred_phy)(const RawAddress& bd_addr, uint8_t tx_phy,
uint8_t rx_phy, uint16_t phy_options);
bt_status_t (*read_phy)(
const RawAddress& bd_addr,
base::Callback<void(uint8_t tx_phy, uint8_t rx_phy, uint8_t status)> cb);
} btgatt_server_interface_t;
__END_DECLS
#endif /* ANDROID_INCLUDE_BT_GATT_CLIENT_H */
|