2 * Copyright (C) 2013 The Android Open Source Project
3 * Copyright (C) 2009-2014 Broadcom Corporation
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #ifndef ANDROID_INCLUDE_BT_GATT_CLIENT_H
20 #define ANDROID_INCLUDE_BT_GATT_CLIENT_H
23 #include "bt_gatt_types.h"
28 #define BT_GATTC_LE_SCAN_TYPE_PASSIVE 0x00
29 #define BT_GATTC_LE_SCAN_TYPE_ACTIVE 0x01
32 /** Buffer type for unformatted reads/writes */
34 uint8_t value[BTGATT_MAX_ATTR_LEN];
36 } btgatt_unformatted_value_t;
38 /** Parameters for GATT read operations */
40 btgatt_srvc_id_t srvc_id;
41 btgatt_gatt_id_t char_id;
42 btgatt_gatt_id_t descr_id;
43 btgatt_unformatted_value_t value;
46 } btgatt_read_params_t;
48 /** Parameters for GATT write operations */
50 btgatt_srvc_id_t srvc_id;
51 btgatt_gatt_id_t char_id;
52 btgatt_gatt_id_t descr_id;
54 } btgatt_write_params_t;
56 /** Attribute change notification parameters */
58 btgatt_srvc_id_t srvc_id;
59 btgatt_gatt_id_t char_id;
62 } btgatt_acquire_params_t;
65 /** Attribute change notification parameters */
67 uint8_t value[BTGATT_MAX_ATTR_LEN];
69 btgatt_srvc_id_t srvc_id;
70 btgatt_gatt_id_t char_id;
73 } btgatt_notify_params_t;
83 } btgatt_test_params_t;
85 /** BT-GATT Client callback structure. */
87 /** Callback invoked in response to register_client */
88 typedef void (*register_client_callback)(int status, int client_if,
91 /** Callback for scan results */
92 typedef void (*scan_result_callback)(bt_bdaddr_t* bda, uint8_t addr_type, int rssi,
93 bool is_extended, uint16_t event_type, uint8_t primary_phy, uint8_t secondary_phy,
94 uint8_t advertising_sid, int8_t tx_power, uint16_t periodic_adv_int,
95 uint8_t* adv_data, int adv_dat_len, uint8_t *scan_rsp_data, int scan_rsp_data_len);
97 /** GATT open callback invoked in response to open */
98 typedef void (*connect_callback)(int conn_id, int status, int client_if, bt_bdaddr_t* bda);
100 /** Callback invoked in response to close */
101 typedef void (*disconnect_callback)(int conn_id, int status,
102 int client_if, bt_bdaddr_t* bda);
105 * Invoked in response to search_service when the GATT service search
106 * has been completed.
108 typedef void (*search_complete_callback)(int conn_id, int status);
110 /** Reports GATT services on a remote device */
111 typedef void (*search_result_callback)(int conn_id, btgatt_srvc_id_t *srvc_id);
113 /** GATT characteristic enumeration result callback */
114 typedef void (*get_characteristic_callback)(int conn_id, int status,
115 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
118 /** GATT descriptor enumeration result callback */
119 typedef void (*get_descriptor_callback)(int conn_id, int status,
120 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
121 btgatt_gatt_id_t *descr_id);
123 /** GATT included service enumeration result callback */
124 typedef void (*get_included_service_callback)(int conn_id, int status,
125 btgatt_srvc_id_t *srvc_id, btgatt_srvc_id_t *incl_srvc_id);
127 /** Callback invoked in response to [de]register_for_notification */
128 typedef void (*register_for_notification_callback)(int conn_id,
129 int registered, int status, btgatt_srvc_id_t *srvc_id,
130 btgatt_gatt_id_t *char_id);
133 * Remote device notification callback, invoked when a remote device sends
134 * a notification or indication that a client has registered for.
136 typedef void (*notify_callback)(int conn_id, btgatt_notify_params_t *p_data);
138 /** Registers service changed callback operation */
139 typedef void (*service_changed_callback)(bt_bdaddr_t *bd_addr, int change_type, uint8_t *uuid, int conn_id, int inst_id);
141 /** Reports result of a GATT read operation */
142 typedef void (*read_characteristic_callback)(int conn_id, int status,
143 btgatt_read_params_t *p_data);
145 /** GATT write characteristic operation callback */
146 typedef void (*write_characteristic_callback)(int conn_id, int status,
147 btgatt_write_params_t *p_data);
149 /** GATT execute prepared write callback */
150 typedef void (*execute_write_callback)(int conn_id, int status);
152 /** Callback invoked in response to read_descriptor */
153 typedef void (*read_descriptor_callback)(int conn_id, int status,
154 btgatt_read_params_t *p_data);
156 /** Callback invoked in response to write_descriptor */
157 typedef void (*write_descriptor_callback)(int conn_id, int status,
158 btgatt_write_params_t *p_data);
160 /** Callback triggered in response to read_remote_rssi */
161 typedef void (*read_remote_rssi_callback)(int client_if, bt_bdaddr_t* bda,
162 int rssi, int status);
164 /** Callback invoked when the MTU for a given connection changes */
165 typedef void (*configure_mtu_callback)(int conn_id, int status, int mtu);
167 /** Callback invoked when a scan filter configuration command has completed */
168 typedef void (*scan_filter_cfg_callback)(int action, int client_if, int status, int filt_type,
171 /** Callback invoked when scan param has been added, cleared, or deleted */
172 typedef void (*scan_filter_param_callback)(int action, int client_if, int status,
175 /** Callback invoked when a scan filter configuration command has completed */
176 typedef void (*scan_filter_status_callback)(int enable, int client_if, int status);
179 * Callback notifying an application that a remote device connection is currently congested
180 * and cannot receive any more data. An application should avoid sending more data until
181 * a further callback is received indicating the congestion status has been cleared.
183 typedef void (*congestion_callback)(int conn_id, bool congested);
184 /** Callback invoked when batchscan storage config operation has completed */
185 typedef void (*batchscan_cfg_storage_callback)(int client_if, int status);
187 /** Callback invoked when batchscan enable / disable operation has completed */
188 typedef void (*batchscan_enable_disable_callback)(int action, int client_if, int status);
190 /** Callback invoked when batchscan reports are obtained */
191 typedef void (*batchscan_reports_callback)(int client_if, int status, int report_format,
192 int num_records, int data_len, uint8_t* rep_data);
194 /** Callback invoked when batchscan storage threshold limit is crossed */
195 typedef void (*batchscan_threshold_callback)(int client_if);
197 /** Track ADV VSE callback invoked when tracked device is found or lost */
198 typedef void (*track_adv_event_callback)(int client_if, int filt_index, int addr_type,
199 bt_bdaddr_t* bda, int adv_state);
201 register_client_callback register_client_cb;
202 scan_result_callback scan_result_cb;
203 connect_callback open_cb;
204 disconnect_callback close_cb;
205 search_complete_callback search_complete_cb;
206 search_result_callback search_result_cb;
207 get_characteristic_callback get_characteristic_cb;
208 get_descriptor_callback get_descriptor_cb;
209 get_included_service_callback get_included_service_cb;
210 register_for_notification_callback register_for_notification_cb;
211 notify_callback notify_cb;
212 service_changed_callback service_changed_cb;
213 read_characteristic_callback read_characteristic_cb;
214 write_characteristic_callback write_characteristic_cb;
215 read_descriptor_callback read_descriptor_cb;
216 write_descriptor_callback write_descriptor_cb;
217 execute_write_callback execute_write_cb;
218 read_remote_rssi_callback read_remote_rssi_cb;
219 configure_mtu_callback configure_mtu_cb;
220 scan_filter_cfg_callback scan_filter_cfg_cb;
221 scan_filter_param_callback scan_filter_param_cb;
222 scan_filter_status_callback scan_filter_status_cb;
223 congestion_callback congestion_cb;
224 batchscan_cfg_storage_callback batchscan_cfg_storage_cb;
225 batchscan_enable_disable_callback batchscan_enb_disable_cb;
226 batchscan_reports_callback batchscan_reports_cb;
227 batchscan_threshold_callback batchscan_threshold_cb;
228 track_adv_event_callback track_adv_event_cb;
229 } btgatt_client_callbacks_t;
231 /** Represents the standard BT-GATT client interface. */
234 /** Registers a GATT client application with the stack */
235 bt_status_t (*register_client)(bt_uuid_t *uuid);
237 /** Unregister a client application from the stack */
238 bt_status_t (*unregister_client)(int client_if);
240 /** Start or stop LE device scanning */
241 bt_status_t (*scan)(int client_if, bool start);
243 /** Create a connection to a remote LE or dual-mode device */
244 bt_status_t (*connect)(int client_if, const bt_bdaddr_t *bd_addr,
247 /** Disconnect a remote device or cancel a pending connection */
248 bt_status_t (*disconnect)(int client_if, const bt_bdaddr_t *bd_addr,
251 /** Clear the attribute cache for a given device */
252 bt_status_t (*refresh)(int client_if, const bt_bdaddr_t *bd_addr);
255 * Enumerate all GATT services on a connected device.
256 * Optionally, the results can be filtered for a given UUID.
258 bt_status_t (*search_service)(int conn_id, bt_uuid_t *filter_uuid);
261 * Enumerate included services for a given service.
262 * Set start_incl_srvc_id to NULL to get the first included service.
264 bt_status_t (*get_included_service)(int conn_id, btgatt_srvc_id_t *srvc_id,
265 btgatt_srvc_id_t *start_incl_srvc_id);
268 * Enumerate characteristics for a given service.
269 * Set start_char_id to NULL to get the first characteristic.
271 bt_status_t (*get_characteristic)(int conn_id,
272 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *start_char_id);
275 * Enumerate descriptors for a given characteristic.
276 * Set start_descr_id to NULL to get the first descriptor.
278 bt_status_t (*get_descriptor)(int conn_id,
279 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
280 btgatt_gatt_id_t *start_descr_id);
282 /** Read a characteristic on a remote device */
283 bt_status_t (*read_characteristic)(int conn_id,
284 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
287 /** Write a remote characteristic */
288 bt_status_t (*write_characteristic)(int conn_id,
289 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
290 int write_type, int len, int auth_req,
293 /** acquire fd for writing remote characterstics */
294 bt_status_t (*acquire_write)(int conn_id,
295 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
296 int auth_req, int *fd , int *mtu);
298 /** acquire fd for notifying remote characterstics */
299 bt_status_t (*acquire_notify)(int conn_id,
300 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
303 /** Read the descriptor for a given characteristic */
304 bt_status_t (*read_descriptor)(int conn_id,
305 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
306 btgatt_gatt_id_t *descr_id, int auth_req);
308 /** Write a remote descriptor for a given characteristic */
309 bt_status_t (*write_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 write_type, int len,
312 int auth_req, char* p_value);
314 /** Execute a prepared write operation */
315 bt_status_t (*execute_write)(int conn_id, int execute);
318 * Register to receive notifications or indications for a given
321 bt_status_t (*register_for_notification)(int conn_id,
322 const bt_bdaddr_t *bd_addr, btgatt_srvc_id_t *srvc_id,
323 btgatt_gatt_id_t *char_id);
325 /** Deregister a previous request for notifications/indications */
326 bt_status_t (*deregister_for_notification)(int conn_id,
327 const bt_bdaddr_t *bd_addr, btgatt_srvc_id_t *srvc_id,
328 btgatt_gatt_id_t *char_id);
330 /** Request RSSI for a given remote device */
331 bt_status_t (*read_remote_rssi)(int client_if, const bt_bdaddr_t *bd_addr);
333 /** OTA firmware download */
334 bt_status_t (*ota_fw_update)(int client_if, int conn_id, const bt_bdaddr_t *bd_addr, char* path);
336 /** Determine the type of the remote device (LE, BR/EDR, Dual-mode) */
337 int (*get_device_type)(const bt_bdaddr_t *bd_addr);
339 /** Request a connection parameter update */
340 bt_status_t (*conn_parameter_update)(bt_bdaddr_t *bd, int min_int, int max_int, int latency, int timeout);
342 /** Test mode interface */
343 bt_status_t (*test_command)(int command, btgatt_test_params_t* params);
345 /* Get current att mtu size of active connection */
346 bt_status_t (*get_att_mtu)(int conn_id, int *mtu_size);
348 /** MTU Exchange request from client */
349 bt_status_t (*configure_mtu)(int conn_id, int mtu);
351 /** Setup scan filter params */
352 bt_status_t (*scan_filter_param_setup)(int client_if, int action, int filt_index, int feat_seln,
353 int list_logic_type, int filt_logic_type, int rssi_high_thres,
354 int rssi_low_thres, int dely_mode, int found_timeout,
355 int lost_timeout, int found_timeout_cnt);
358 /** Configure a scan filter condition */
359 bt_status_t (*scan_filter_add_remove)(int client_if, int action, int filt_type,
360 int filt_index, int company_id,
361 int company_id_mask, const bt_uuid_t *p_uuid,
362 const bt_uuid_t *p_uuid_mask, const bt_bdaddr_t *bd_addr,
363 char addr_type, int data_len, char* p_data, int mask_len,
366 /** Clear all scan filter conditions for specific filter index*/
367 bt_status_t (*scan_filter_clear)(int client_if, int filt_index);
369 /** Enable / disable scan filter feature*/
370 bt_status_t (*scan_filter_enable)(int client_if, bool enable);
372 /** Sets the LE scan interval and window in units of N*0.625 msec */
374 bt_status_t (*set_scan_parameters)(int scan_type, int scan_interval, int scan_window);
376 bt_status_t (*set_scan_parameters)(int scan_interval, int scan_window);
379 /* Configure the batchscan storage */
380 bt_status_t (*batchscan_cfg_storage)(int client_if, int batch_scan_full_max,
381 int batch_scan_trunc_max, int batch_scan_notify_threshold);
383 /* Enable batchscan */
384 bt_status_t (*batchscan_enb_batch_scan)(int client_if, int scan_mode,
385 int scan_interval, int scan_window, int addr_type, int discard_rule);
387 /* Disable batchscan */
388 bt_status_t (*batchscan_dis_batch_scan)(int client_if);
390 /* Read out batchscan reports */
391 bt_status_t (*batchscan_read_reports)(int client_if, int scan_mode);
393 /** Adds a connection info in list */
394 bt_status_t (*add_connection_info)(const bt_bdaddr_t *bd_addr, int conn_id, int server_inst_id);
396 /** Get data batching available packets */
397 bt_status_t (*get_data_batching_available_packets)(unsigned int *available_packets);
399 /** Enable data batching */
400 bt_status_t (*enable_data_batching)(const bt_bdaddr_t *bd_addr, int packet_threshold, int timeout);
402 /** Disable data batching */
403 bt_status_t (*disable_data_batching)(const bt_bdaddr_t *bd_addr);
404 } btgatt_client_interface_t;
408 #endif /* ANDROID_INCLUDE_BT_GATT_CLIENT_H */