2 * Copyright (C) 2013 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #ifndef ANDROID_INCLUDE_BT_GATT_SERVER_H
19 #define ANDROID_INCLUDE_BT_GATT_SERVER_H
23 #include "bt_gatt_types.h"
27 /** GATT value type used in response to remote read requests */
29 uint8_t value[BTGATT_MAX_ATTR_LEN];
36 /** GATT remote read request response type */
38 btgatt_value_t attr_value;
48 bool include_appearance;
51 char* manufacturer_data;
52 uint16_t manufacturer_data_len;
54 uint16_t service_data_len;
56 uint16_t service_uuid_len;
58 uint16_t solicit_uuid_len;
59 uint16_t min_interval;
60 uint16_t max_interval;
65 } btgatt_adv_param_setup_t;
68 /** BT-GATT Server callback structure. */
70 /** Callback invoked in response to register_server */
71 typedef void (*register_server_callback)(int status, int server_if,
74 /** Callback indicating that a remote device has connected or been disconnected */
75 typedef void (*connection_callback)(int conn_id, int server_if, int connected,
78 /** Callback invoked in response to create_service */
79 typedef void (*service_added_callback)(int status, int server_if,
80 btgatt_srvc_id_t *srvc_id, int srvc_handle);
82 /** Callback indicating that an included service has been added to a service */
83 typedef void (*included_service_added_callback)(int status, int server_if,
84 int srvc_handle, int incl_srvc_handle);
86 /** Callback invoked when a characteristic has been added to a service */
87 typedef void (*characteristic_added_callback)(int status, int server_if,
88 bt_uuid_t *uuid, int srvc_handle, int char_handle);
90 /** Callback invoked when a descriptor has been added to a characteristic */
91 typedef void (*descriptor_added_callback)(int status, int server_if,
92 bt_uuid_t *uuid, int srvc_handle, int descr_handle);
94 /** Callback invoked in response to start_service */
95 typedef void (*service_started_callback)(int status, int server_if,
98 /** Callback invoked in response to stop_service */
99 typedef void (*service_stopped_callback)(int status, int server_if,
102 /** Callback triggered when a service has been deleted */
103 typedef void (*service_deleted_callback)(int status, int server_if,
107 * Callback invoked when indication confirmation
109 typedef void (*indication_confirmation_callback) (int conn_id, int trans_id, int attr_handle, bt_bdaddr_t *bda);
113 * Callback invoked when indication confirmation
115 typedef void (*notification_enabled_callback) (int conn_id, int trans_id, int attr_handle, bool notify, bt_bdaddr_t *bda);
119 * Callback invoked when a remote device has requested to read a characteristic
120 * or descriptor. The application must respond by calling send_response
122 typedef void (*request_read_callback)(int conn_id, int trans_id, bt_bdaddr_t *bda,
123 int attr_handle, int offset, bool is_long);
126 * Callback invoked when a remote device has requested to write to a
127 * characteristic or descriptor.
129 typedef void (*request_write_callback)(int conn_id, int trans_id, bt_bdaddr_t *bda,
130 int attr_handle, int offset, int length,
131 bool need_rsp, bool is_prep, uint8_t* value);
134 * Callback invoked when a remote device has requested to acqiore write to a
137 typedef void (*request_acquire_write_callback)(int mtu, int conn_id, int trans_id,
138 int attr_handle, bt_bdaddr_t *bda);
140 typedef void (*request_acquire_notify_callback)(int fd, int conn_id, int trans_id,
144 /** Callback invoked when a previously prepared write is to be executed */
145 typedef void (*request_exec_write_callback)(int conn_id, int trans_id,
146 bt_bdaddr_t *bda, int exec_write);
151 * Callback triggered in response to send_response if the remote device
152 * sends a confirmation.
154 typedef void (*response_confirmation_callback)(int status, int handle);
157 * Callback indicationg the status of a listen() operation
159 typedef void (*listen_callback)(int status, int server_if);
161 /** Callback invoked when multi-adv enable operation has completed */
162 typedef void (*multi_adv_enable_callback)(int server_if, int status);
164 /** Callback invoked when multi-adv param update operation has completed */
165 typedef void (*multi_adv_update_callback)(int server_if, int status);
167 /** Callback invoked when multi-adv instance data set operation has completed */
168 typedef void (*multi_adv_data_callback)(int server_if, int status);
170 /** Callback invoked when multi-adv disable operation has completed */
171 typedef void (*multi_adv_disable_callback)(int server_if, int status);
173 /** Callback invoked when the MTU for a given connection changes */
174 typedef void (*mtu_changed_callback)(int conn_id, int mtu);
177 register_server_callback register_server_cb;
178 connection_callback connection_cb;
179 service_added_callback service_added_cb;
180 included_service_added_callback included_service_added_cb;
181 characteristic_added_callback characteristic_added_cb;
182 descriptor_added_callback descriptor_added_cb;
183 service_started_callback service_started_cb;
184 service_stopped_callback service_stopped_cb;
185 service_deleted_callback service_deleted_cb;
186 indication_confirmation_callback indication_confirmation_cb;
187 request_read_callback request_read_cb;
188 request_write_callback request_write_cb;
189 request_exec_write_callback request_exec_write_cb;
190 response_confirmation_callback response_confirmation_cb;
191 listen_callback listen_cb;
192 multi_adv_enable_callback multi_adv_enable_cb;
193 multi_adv_update_callback multi_adv_update_cb;
194 multi_adv_data_callback multi_adv_data_cb;
195 multi_adv_disable_callback multi_adv_disable_cb;
196 mtu_changed_callback mtu_changed_cb;
198 notification_enabled_callback notif_enabled_cb;
200 request_acquire_write_callback request_acquire_write_cb;
201 request_acquire_notify_callback request_acquire_notify_cb;
202 } btgatt_server_callbacks_t;
204 /** Represents the standard BT-GATT server interface. */
206 /** Registers a GATT server application with the stack */
207 bt_status_t (*register_server)(bt_uuid_t *uuid);
209 /** Unregister a server application from the stack */
210 bt_status_t (*unregister_server)(int server_if);
212 /** Create a connection to a remote peripheral */
213 bt_status_t (*connect)(int server_if, const bt_bdaddr_t *bd_addr, bool is_direct);
215 /** Disconnect an established connection or cancel a pending one */
216 bt_status_t (*disconnect)(int server_if, const bt_bdaddr_t *bd_addr,
219 /** Create a new service */
220 bt_status_t (*add_service)(int server_if, btgatt_srvc_id_t *srvc_id, int num_handles);
222 /** Assign an included service to it's parent service */
223 bt_status_t (*add_included_service)(int server_if, int service_handle, int included_handle);
225 /** Add a characteristic to a service */
226 bt_status_t (*add_characteristic)(int server_if,
227 int service_handle, bt_uuid_t *uuid,
228 int properties, int permissions);
230 /** Add a descriptor to a given service */
231 bt_status_t (*add_descriptor)(int server_if, int service_handle,
232 bt_uuid_t *uuid, int permissions);
234 /** Starts a local service */
235 bt_status_t (*start_service)(int server_if, int service_handle,
238 /** Stops a local service */
239 bt_status_t (*stop_service)(int server_if, int service_handle);
241 /** Delete a local service */
242 bt_status_t (*delete_service)(int server_if, int service_handle);
244 /** Send value indication to a remote device */
245 bt_status_t (*send_indication)(int server_if, int attribute_handle,
246 int conn_id, int len, int confirm,
249 /** Send a response to a read/write operation */
250 bt_status_t (*send_response)(int conn_id, int trans_id,
251 int status, btgatt_response_t *response);
253 /** Update GATT server attribute value */
254 bt_status_t (*update_att_value)(int server_if, int attribute_handle,
255 int value_length, char* att_value);
257 /** Start or stop advertisements to listen for incoming connections */
258 bt_status_t (*listen)(int server_if, bool start);
260 /** Set the advertising data or scan response data */
261 bt_status_t (*set_adv_data)(int server_if, bool set_scan_rsp, bool include_name,
262 bool include_txpower, int min_interval, int max_interval, int appearance,
263 uint16_t manufacturer_len, char* manufacturer_data,
264 uint16_t service_data_len, char* service_data,
265 uint16_t service_uuid_len, char* service_uuid);
267 /* Setup the parameters as per spec, user manual specified values and enable multi ADV */
268 bt_status_t (*multi_adv_enable)(int server_if);
270 /* Update the parameters as per spec, user manual specified values and restart multi ADV */
271 bt_status_t (*multi_adv_update)(int server_if, int min_interval, int max_interval, int adv_type,
272 int chnl_map, int tx_power, int timeout_s);
274 /* Set the filter_policy value in the HAL Layer */
275 bt_status_t (*set_filter_policy)(int filter_policy);
277 /* Setup the data for the specified instance */
278 bt_status_t (*multi_adv_set_inst_data)(btgatt_adv_param_setup_t adv_param_setup);
280 /* Disable the multi adv instance */
281 bt_status_t (*multi_adv_disable)(int server_if);
283 /* Get current att mtu size of active connection */
284 bt_status_t (*get_att_mtu)(int conn_id, int *mtu_size);
286 /** Send a response to a acquire write/notify operation */
287 bt_status_t (*send_response_acquire)(int conn_id, int trans_id,
288 int status, int fd, int mtu, void *);
289 } btgatt_server_interface_t;
293 #endif /* ANDROID_INCLUDE_BT_GATT_SERVER_H */