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_CLIENT_H
19 #define ANDROID_INCLUDE_BT_GATT_CLIENT_H
22 #include "bt_gatt_types.h"
27 * Buffer sizes for maximum attribute length and maximum read/write
28 * operation buffer size.
30 #define BTGATT_MAX_ATTR_LEN 600
32 /** Buffer type for unformatted reads/writes */
35 uint8_t value[BTGATT_MAX_ATTR_LEN];
37 } btgatt_unformatted_value_t;
39 /** Parameters for GATT read operations */
42 btgatt_srvc_id_t srvc_id;
43 btgatt_gatt_id_t char_id;
44 btgatt_gatt_id_t descr_id;
45 btgatt_unformatted_value_t value;
48 } btgatt_read_params_t;
50 /** Parameters for GATT write operations */
53 btgatt_srvc_id_t srvc_id;
54 btgatt_gatt_id_t char_id;
55 btgatt_gatt_id_t descr_id;
57 } btgatt_write_params_t;
59 /** Attribute change notification parameters */
62 uint8_t value[BTGATT_MAX_ATTR_LEN];
64 btgatt_srvc_id_t srvc_id;
65 btgatt_gatt_id_t char_id;
68 } btgatt_notify_params_t;
79 } btgatt_test_params_t;
81 /** BT-GATT Client callback structure. */
83 /** Callback invoked in response to register_client */
84 typedef void (*register_client_callback)(int status, int client_if,
87 /** Callback for scan results */
88 typedef void (*scan_result_callback)(bt_bdaddr_t* bda, int rssi, uint8_t* adv_data);
90 /** GATT open callback invoked in response to open */
91 typedef void (*connect_callback)(int conn_id, int status, int client_if, bt_bdaddr_t* bda);
93 /** Callback invoked in response to close */
94 typedef void (*disconnect_callback)(int conn_id, int status,
95 int client_if, bt_bdaddr_t* bda);
98 * Invoked in response to search_service when the GATT service search
101 typedef void (*search_complete_callback)(int conn_id, int status);
103 /** Reports GATT services on a remote device */
104 typedef void (*search_result_callback)( int conn_id, btgatt_srvc_id_t *srvc_id);
106 /** GATT characteristic enumeration result callback */
107 typedef void (*get_characteristic_callback)(int conn_id, int status,
108 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
111 /** GATT descriptor enumeration result callback */
112 typedef void (*get_descriptor_callback)(int conn_id, int status,
113 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
114 btgatt_gatt_id_t *descr_id);
116 /** GATT included service enumeration result callback */
117 typedef void (*get_included_service_callback)(int conn_id, int status,
118 btgatt_srvc_id_t *srvc_id, btgatt_srvc_id_t *incl_srvc_id);
120 /** Callback invoked in response to [de]register_for_notification */
121 typedef void (*register_for_notification_callback)(int conn_id,
122 int registered, int status, btgatt_srvc_id_t *srvc_id,
123 btgatt_gatt_id_t *char_id);
126 * Remote device notification callback, invoked when a remote device sends
127 * a notification or indication that a client has registered for.
129 typedef void (*notify_callback)(int conn_id, btgatt_notify_params_t *p_data);
131 /** Reports result of a GATT read operation */
132 typedef void (*read_characteristic_callback)(int conn_id, int status,
133 btgatt_read_params_t *p_data);
135 /** GATT write characteristic operation callback */
136 typedef void (*write_characteristic_callback)(int conn_id, int status,
137 btgatt_write_params_t *p_data);
139 /** GATT execute prepared write callback */
140 typedef void (*execute_write_callback)(int conn_id, int status);
142 /** Callback invoked in response to read_descriptor */
143 typedef void (*read_descriptor_callback)(int conn_id, int status,
144 btgatt_read_params_t *p_data);
146 /** Callback invoked in response to write_descriptor */
147 typedef void (*write_descriptor_callback)(int conn_id, int status,
148 btgatt_write_params_t *p_data);
150 /** Callback triggered in response to read_remote_rssi */
151 typedef void (*read_remote_rssi_callback)(int client_if, bt_bdaddr_t* bda,
152 int rssi, int status);
155 * Callback indicating the status of a listen() operation
157 typedef void (*listen_callback)(int status, int server_if);
159 /** Callback invoked when the MTU for a given connection changes */
160 typedef void (*configure_mtu_callback)(int conn_id, int status, int mtu);
162 /** Callback invoked when a scan filter configuration command has completed */
163 typedef void (*scan_filter_cfg_callback)(int action, int client_if, int status, int filt_type,
166 /** Callback invoked when scan param has been added, cleared, or deleted */
167 typedef void (*scan_filter_param_callback)(int action, int client_if, int status,
170 /** Callback invoked when a scan filter configuration command has completed */
171 typedef void (*scan_filter_status_callback)(int enable, int client_if, int status);
173 /** Callback invoked when multi-adv enable operation has completed */
174 typedef void (*multi_adv_enable_callback)(int client_if, int status);
176 /** Callback invoked when multi-adv param update operation has completed */
177 typedef void (*multi_adv_update_callback)(int client_if, int status);
179 /** Callback invoked when multi-adv instance data set operation has completed */
180 typedef void (*multi_adv_data_callback)(int client_if, int status);
182 /** Callback invoked when multi-adv disable operation has completed */
183 typedef void (*multi_adv_disable_callback)(int client_if, int status);
186 * Callback notifying an application that a remote device connection is currently congested
187 * and cannot receive any more data. An application should avoid sending more data until
188 * a further callback is received indicating the congestion status has been cleared.
190 typedef void (*congestion_callback)(int conn_id, bool congested);
191 /** Callback invoked when batchscan storage config operation has completed */
192 typedef void (*batchscan_cfg_storage_callback)(int client_if, int status);
194 /** Callback invoked when batchscan enable / disable operation has completed */
195 typedef void (*batchscan_enable_disable_callback)(int action, int client_if, int status);
197 /** Callback invoked when batchscan reports are obtained */
198 typedef void (*batchscan_reports_callback)(int client_if, int status, int report_format,
199 int num_records, int data_len, uint8_t* rep_data);
201 /** Callback invoked when batchscan storage threshold limit is crossed */
202 typedef void (*batchscan_threshold_callback)(int client_if);
204 /** Track ADV VSE callback invoked when tracked device is found or lost */
205 typedef void (*track_adv_event_callback)(int client_if, int filt_index, int addr_type,
206 bt_bdaddr_t* bda, int adv_state);
209 register_client_callback register_client_cb;
210 scan_result_callback scan_result_cb;
211 connect_callback open_cb;
212 disconnect_callback close_cb;
213 search_complete_callback search_complete_cb;
214 search_result_callback search_result_cb;
215 get_characteristic_callback get_characteristic_cb;
216 get_descriptor_callback get_descriptor_cb;
217 get_included_service_callback get_included_service_cb;
218 register_for_notification_callback register_for_notification_cb;
219 notify_callback notify_cb;
220 read_characteristic_callback read_characteristic_cb;
221 write_characteristic_callback write_characteristic_cb;
222 read_descriptor_callback read_descriptor_cb;
223 write_descriptor_callback write_descriptor_cb;
224 execute_write_callback execute_write_cb;
225 read_remote_rssi_callback read_remote_rssi_cb;
226 listen_callback listen_cb;
227 configure_mtu_callback configure_mtu_cb;
228 scan_filter_cfg_callback scan_filter_cfg_cb;
229 scan_filter_param_callback scan_filter_param_cb;
230 scan_filter_status_callback scan_filter_status_cb;
231 multi_adv_enable_callback multi_adv_enable_cb;
232 multi_adv_update_callback multi_adv_update_cb;
233 multi_adv_data_callback multi_adv_data_cb;
234 multi_adv_disable_callback multi_adv_disable_cb;
235 congestion_callback congestion_cb;
236 batchscan_cfg_storage_callback batchscan_cfg_storage_cb;
237 batchscan_enable_disable_callback batchscan_enb_disable_cb;
238 batchscan_reports_callback batchscan_reports_cb;
239 batchscan_threshold_callback batchscan_threshold_cb;
240 track_adv_event_callback track_adv_event_cb;
241 } btgatt_client_callbacks_t;
243 /** Represents the standard BT-GATT client interface. */
246 /** Registers a GATT client application with the stack */
247 bt_status_t (*register_client)( bt_uuid_t *uuid );
249 /** Unregister a client application from the stack */
250 bt_status_t (*unregister_client)(int client_if );
252 /** Start or stop LE device scanning */
253 bt_status_t (*scan)( bool start );
255 /** Create a connection to a remote LE or dual-mode device */
256 bt_status_t (*connect)( int client_if, const bt_bdaddr_t *bd_addr,
257 bool is_direct, int transport );
259 /** Disconnect a remote device or cancel a pending connection */
260 bt_status_t (*disconnect)( int client_if, const bt_bdaddr_t *bd_addr,
263 /** Start or stop advertisements to listen for incoming connections */
264 bt_status_t (*listen)(int client_if, bool start);
266 /** Clear the attribute cache for a given device */
267 bt_status_t (*refresh)( int client_if, const bt_bdaddr_t *bd_addr );
270 * Enumerate all GATT services on a connected device.
271 * Optionally, the results can be filtered for a given UUID.
273 bt_status_t (*search_service)(int conn_id, bt_uuid_t *filter_uuid );
276 * Enumerate included services for a given service.
277 * Set start_incl_srvc_id to NULL to get the first included service.
279 bt_status_t (*get_included_service)( int conn_id, btgatt_srvc_id_t *srvc_id,
280 btgatt_srvc_id_t *start_incl_srvc_id);
283 * Enumerate characteristics for a given service.
284 * Set start_char_id to NULL to get the first characteristic.
286 bt_status_t (*get_characteristic)( int conn_id,
287 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *start_char_id);
290 * Enumerate descriptors for a given characteristic.
291 * Set start_descr_id to NULL to get the first descriptor.
293 bt_status_t (*get_descriptor)( int conn_id,
294 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
295 btgatt_gatt_id_t *start_descr_id);
297 /** Read a characteristic on a remote device */
298 bt_status_t (*read_characteristic)( int conn_id,
299 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
302 /** Write a remote characteristic */
303 bt_status_t (*write_characteristic)(int conn_id,
304 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
305 int write_type, int len, int auth_req,
308 /** Read the descriptor for a given characteristic */
309 bt_status_t (*read_descriptor)(int conn_id,
310 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
311 btgatt_gatt_id_t *descr_id, int auth_req);
313 /** Write a remote descriptor for a given characteristic */
314 bt_status_t (*write_descriptor)( int conn_id,
315 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
316 btgatt_gatt_id_t *descr_id, int write_type, int len,
317 int auth_req, char* p_value);
319 /** Execute a prepared write operation */
320 bt_status_t (*execute_write)(int conn_id, int execute);
323 * Register to receive notifications or indications for a given
326 bt_status_t (*register_for_notification)( int client_if,
327 const bt_bdaddr_t *bd_addr, btgatt_srvc_id_t *srvc_id,
328 btgatt_gatt_id_t *char_id);
330 /** Deregister a previous request for notifications/indications */
331 bt_status_t (*deregister_for_notification)( int client_if,
332 const bt_bdaddr_t *bd_addr, btgatt_srvc_id_t *srvc_id,
333 btgatt_gatt_id_t *char_id);
335 /** Request RSSI for a given remote device */
336 bt_status_t (*read_remote_rssi)( int client_if, const bt_bdaddr_t *bd_addr);
338 /** Setup scan filter params */
339 bt_status_t (*scan_filter_param_setup)(int client_if, int action, int filt_index, int feat_seln,
340 int list_logic_type, int filt_logic_type, int rssi_high_thres,
341 int rssi_low_thres, int dely_mode, int found_timeout,
342 int lost_timeout, int found_timeout_cnt);
345 /** Configure a scan filter condition */
346 bt_status_t (*scan_filter_add_remove)(int client_if, int action, int filt_type,
347 int filt_index, int company_id,
348 int company_id_mask, const bt_uuid_t *p_uuid,
349 const bt_uuid_t *p_uuid_mask, const bt_bdaddr_t *bd_addr,
350 char addr_type, int data_len, char* p_data, int mask_len,
353 /** Clear all scan filter conditions for specific filter index*/
354 bt_status_t (*scan_filter_clear)(int client_if, int filt_index);
356 /** Enable / disable scan filter feature*/
357 bt_status_t (*scan_filter_enable)(int client_if, bool enable);
359 /** Determine the type of the remote device (LE, BR/EDR, Dual-mode) */
360 int (*get_device_type)( const bt_bdaddr_t *bd_addr );
362 /** Set the advertising data or scan response data */
363 bt_status_t (*set_adv_data)(int client_if, bool set_scan_rsp, bool include_name,
364 bool include_txpower, int min_interval, int max_interval, int appearance,
365 uint16_t manufacturer_len, char* manufacturer_data,
366 uint16_t service_data_len, char* service_data,
367 uint16_t service_uuid_len, char* service_uuid);
369 /** Configure the MTU for a given connection */
370 bt_status_t (*configure_mtu)(int conn_id, int mtu);
372 /** Request a connection parameter update */
373 bt_status_t (*conn_parameter_update)(const bt_bdaddr_t *bd_addr, int min_interval,
374 int max_interval, int latency, int timeout);
376 /** Sets the LE scan interval and window in units of N*0.625 msec */
377 bt_status_t (*set_scan_parameters)(int scan_interval, int scan_window);
379 /* Setup the parameters as per spec, user manual specified values and enable multi ADV */
380 bt_status_t (*multi_adv_enable)(int client_if, int min_interval,int max_interval,int adv_type,
381 int chnl_map, int tx_power, int timeout_s);
383 /* Update the parameters as per spec, user manual specified values and restart multi ADV */
384 bt_status_t (*multi_adv_update)(int client_if, int min_interval,int max_interval,int adv_type,
385 int chnl_map, int tx_power, int timeout_s);
387 /* Setup the data for the specified instance */
388 bt_status_t (*multi_adv_set_inst_data)(int client_if, bool set_scan_rsp, bool include_name,
389 bool incl_txpower, int appearance, int manufacturer_len,
390 char* manufacturer_data, int service_data_len,
391 char* service_data, int service_uuid_len, char* service_uuid);
393 /* Disable the multi adv instance */
394 bt_status_t (*multi_adv_disable)(int client_if);
396 /* Configure the batchscan storage */
397 bt_status_t (*batchscan_cfg_storage)(int client_if, int batch_scan_full_max,
398 int batch_scan_trunc_max, int batch_scan_notify_threshold);
400 /* Enable batchscan */
401 bt_status_t (*batchscan_enb_batch_scan)(int client_if, int scan_mode,
402 int scan_interval, int scan_window, int addr_type, int discard_rule);
404 /* Disable batchscan */
405 bt_status_t (*batchscan_dis_batch_scan)(int client_if);
407 /* Read out batchscan reports */
408 bt_status_t (*batchscan_read_reports)(int client_if, int scan_mode);
410 /** Test mode interface */
411 bt_status_t (*test_command)( int command, btgatt_test_params_t* params);
413 } btgatt_client_interface_t;
417 #endif /* ANDROID_INCLUDE_BT_GATT_CLIENT_H */