blob: c23f94240819a01c54435af83c04374b5d566c64 [file] [log] [blame]
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -08001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17
18#ifndef ANDROID_INCLUDE_BT_GATT_CLIENT_H
19#define ANDROID_INCLUDE_BT_GATT_CLIENT_H
20
21#include <stdint.h>
22#include "bt_gatt_types.h"
23
24__BEGIN_DECLS
25
26/**
27 * Buffer sizes for maximum attribute length and maximum read/write
28 * operation buffer size.
29 */
30#define BTGATT_MAX_ATTR_LEN 600
31
32/** Buffer type for unformatted reads/writes */
33typedef struct
34{
35 uint8_t value[BTGATT_MAX_ATTR_LEN];
36 uint16_t len;
37} btgatt_unformatted_value_t;
38
39/** Parameters for GATT read operations */
40typedef struct
41{
42 btgatt_srvc_id_t srvc_id;
Andre Eisenbach02223d12013-07-09 00:02:48 -070043 btgatt_gatt_id_t char_id;
44 btgatt_gatt_id_t descr_id;
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -080045 btgatt_unformatted_value_t value;
46 uint16_t value_type;
47 uint8_t status;
48} btgatt_read_params_t;
49
50/** Parameters for GATT write operations */
51typedef struct
52{
53 btgatt_srvc_id_t srvc_id;
Andre Eisenbach02223d12013-07-09 00:02:48 -070054 btgatt_gatt_id_t char_id;
55 btgatt_gatt_id_t descr_id;
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -080056 uint8_t status;
57} btgatt_write_params_t;
58
59/** Attribute change notification parameters */
60typedef struct
61{
62 uint8_t value[BTGATT_MAX_ATTR_LEN];
63 bt_bdaddr_t bda;
64 btgatt_srvc_id_t srvc_id;
Andre Eisenbach02223d12013-07-09 00:02:48 -070065 btgatt_gatt_id_t char_id;
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -080066 uint16_t len;
67 uint8_t is_notify;
68} btgatt_notify_params_t;
69
70typedef struct
71{
72 bt_bdaddr_t *bda1;
73 bt_uuid_t *uuid1;
74 uint16_t u1;
75 uint16_t u2;
76 uint16_t u3;
77 uint16_t u4;
78 uint16_t u5;
79} btgatt_test_params_t;
80
81/** BT-GATT Client callback structure. */
82
83/** Callback invoked in response to register_client */
84typedef void (*register_client_callback)(int status, int client_if,
85 bt_uuid_t *app_uuid);
86
87/** Callback for scan results */
88typedef void (*scan_result_callback)(bt_bdaddr_t* bda, int rssi, uint8_t* adv_data);
89
90/** GATT open callback invoked in response to open */
91typedef void (*connect_callback)(int conn_id, int status, int client_if, bt_bdaddr_t* bda);
92
93/** Callback invoked in response to close */
94typedef void (*disconnect_callback)(int conn_id, int status,
95 int client_if, bt_bdaddr_t* bda);
96
97/**
98 * Invoked in response to search_service when the GATT service search
99 * has been completed.
100 */
101typedef void (*search_complete_callback)(int conn_id, int status);
102
103/** Reports GATT services on a remote device */
104typedef void (*search_result_callback)( int conn_id, btgatt_srvc_id_t *srvc_id);
105
106/** GATT characteristic enumeration result callback */
107typedef void (*get_characteristic_callback)(int conn_id, int status,
Andre Eisenbach02223d12013-07-09 00:02:48 -0700108 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800109 int char_prop);
110
111/** GATT descriptor enumeration result callback */
112typedef void (*get_descriptor_callback)(int conn_id, int status,
Andre Eisenbach02223d12013-07-09 00:02:48 -0700113 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
114 btgatt_gatt_id_t *descr_id);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800115
116/** GATT included service enumeration result callback */
117typedef void (*get_included_service_callback)(int conn_id, int status,
118 btgatt_srvc_id_t *srvc_id, btgatt_srvc_id_t *incl_srvc_id);
119
120/** Callback invoked in response to [de]register_for_notification */
121typedef void (*register_for_notification_callback)(int conn_id,
122 int registered, int status, btgatt_srvc_id_t *srvc_id,
Andre Eisenbach02223d12013-07-09 00:02:48 -0700123 btgatt_gatt_id_t *char_id);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800124
125/**
126 * Remote device notification callback, invoked when a remote device sends
127 * a notification or indication that a client has registered for.
128 */
129typedef void (*notify_callback)(int conn_id, btgatt_notify_params_t *p_data);
130
131/** Reports result of a GATT read operation */
132typedef void (*read_characteristic_callback)(int conn_id, int status,
133 btgatt_read_params_t *p_data);
134
135/** GATT write characteristic operation callback */
136typedef void (*write_characteristic_callback)(int conn_id, int status,
137 btgatt_write_params_t *p_data);
138
139/** GATT execute prepared write callback */
140typedef void (*execute_write_callback)(int conn_id, int status);
141
142/** Callback invoked in response to read_descriptor */
143typedef void (*read_descriptor_callback)(int conn_id, int status,
144 btgatt_read_params_t *p_data);
145
146/** Callback invoked in response to write_descriptor */
147typedef void (*write_descriptor_callback)(int conn_id, int status,
148 btgatt_write_params_t *p_data);
149
150/** Callback triggered in response to read_remote_rssi */
151typedef void (*read_remote_rssi_callback)(int client_if, bt_bdaddr_t* bda,
152 int rssi, int status);
153
Andre Eisenbach299e43c2013-08-06 19:54:25 -0700154/**
Satya Calloji20a1a052014-05-10 23:37:11 -0700155 * Callback indicating the status of a listen() operation
Andre Eisenbach299e43c2013-08-06 19:54:25 -0700156 */
157typedef void (*listen_callback)(int status, int server_if);
158
Andre Eisenbach8a4b61a2014-03-25 06:30:05 -0700159/** Callback invoked when the MTU for a given connection changes */
160typedef void (*configure_mtu_callback)(int conn_id, int status, int mtu);
161
Andre Eisenbach709f2392013-12-16 16:16:54 -0800162/** Callback invoked when a scan filter configuration command has completed */
163typedef void (*scan_filter_callback)(int action, int status);
164
Wei Wang6c2e2d32014-05-20 06:30:05 +0000165/** Callback invoked when multi-adv enable operation has completed */
166typedef void (*multi_adv_enable_callback)(int client_if, int status);
167
168/** Callback invoked when multi-adv param update operation has completed */
169typedef void (*multi_adv_update_callback)(int client_if, int status);
170
171/** Callback invoked when multi-adv instance data set operation has completed */
172typedef void (*multi_adv_data_callback)(int client_if, int status);
173
174/** Callback invoked when multi-adv disable operation has completed */
175typedef void (*multi_adv_disable_callback)(int client_if, int status);
176
Andre Eisenbach9ef3c722014-03-28 14:53:33 -0700177/**
178 * Callback notifying an application that a remote device connection is currently congested
179 * and cannot receive any more data. An application should avoid sending more data until
180 * a further callback is received indicating the congestion status has been cleared.
181 */
182typedef void (*congestion_callback)(int conn_id, bool congested);
Satya Calloji20a1a052014-05-10 23:37:11 -0700183/** Callback invoked when batchscan storage config operation has completed */
184typedef void (*batchscan_cfg_storage_callback)(int client_if, int status);
185
186/** Callback invoked when batchscan enable / disable operation has completed */
187typedef void (*batchscan_enable_disable_callback)(int action, int client_if, int status);
188
189/** Callback invoked when batchscan reports are obtained */
190typedef void (*batchscan_reports_callback)(int client_if, int status, int report_format,
191 int num_records, int data_len, uint8_t* rep_data);
192
193/** Callback invoked when batchscan storage threshold limit is crossed */
194typedef void (*batchscan_threshold_callback)(int client_if);
195
Andre Eisenbach9ef3c722014-03-28 14:53:33 -0700196
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800197typedef struct {
198 register_client_callback register_client_cb;
199 scan_result_callback scan_result_cb;
200 connect_callback open_cb;
201 disconnect_callback close_cb;
202 search_complete_callback search_complete_cb;
203 search_result_callback search_result_cb;
204 get_characteristic_callback get_characteristic_cb;
205 get_descriptor_callback get_descriptor_cb;
206 get_included_service_callback get_included_service_cb;
207 register_for_notification_callback register_for_notification_cb;
208 notify_callback notify_cb;
209 read_characteristic_callback read_characteristic_cb;
210 write_characteristic_callback write_characteristic_cb;
211 read_descriptor_callback read_descriptor_cb;
212 write_descriptor_callback write_descriptor_cb;
213 execute_write_callback execute_write_cb;
214 read_remote_rssi_callback read_remote_rssi_cb;
Andre Eisenbach299e43c2013-08-06 19:54:25 -0700215 listen_callback listen_cb;
Andre Eisenbach8a4b61a2014-03-25 06:30:05 -0700216 configure_mtu_callback configure_mtu_cb;
Andre Eisenbach709f2392013-12-16 16:16:54 -0800217 scan_filter_callback scan_filter_cb;
Wei Wang6c2e2d32014-05-20 06:30:05 +0000218 multi_adv_enable_callback multi_adv_enable_cb;
219 multi_adv_update_callback multi_adv_update_cb;
220 multi_adv_data_callback multi_adv_data_cb;
221 multi_adv_disable_callback multi_adv_disable_cb;
Andre Eisenbach9ef3c722014-03-28 14:53:33 -0700222 congestion_callback congestion_cb;
Satya Calloji20a1a052014-05-10 23:37:11 -0700223 batchscan_cfg_storage_callback batchscan_cfg_storage_cb;
224 batchscan_enable_disable_callback batchscan_enb_disable_cb;
225 batchscan_reports_callback batchscan_reports_cb;
226 batchscan_threshold_callback batchscan_threshold_cb;
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800227} btgatt_client_callbacks_t;
228
229/** Represents the standard BT-GATT client interface. */
230
231typedef struct {
232 /** Registers a GATT client application with the stack */
233 bt_status_t (*register_client)( bt_uuid_t *uuid );
234
235 /** Unregister a client application from the stack */
236 bt_status_t (*unregister_client)(int client_if );
237
238 /** Start or stop LE device scanning */
Prerepa Viswanadham45edab92014-05-09 16:09:52 -0700239 bt_status_t (*scan)( bool start );
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800240
241 /** Create a connection to a remote LE or dual-mode device */
242 bt_status_t (*connect)( int client_if, const bt_bdaddr_t *bd_addr,
Ganesh Ganapathi Battaf9f4d102014-04-18 10:02:49 -0700243 bool is_direct, int transport );
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800244
245 /** Disconnect a remote device or cancel a pending connection */
246 bt_status_t (*disconnect)( int client_if, const bt_bdaddr_t *bd_addr,
247 int conn_id);
248
Andre Eisenbach299e43c2013-08-06 19:54:25 -0700249 /** Start or stop advertisements to listen for incoming connections */
250 bt_status_t (*listen)(int client_if, bool start);
251
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800252 /** Clear the attribute cache for a given device */
253 bt_status_t (*refresh)( int client_if, const bt_bdaddr_t *bd_addr );
254
255 /**
256 * Enumerate all GATT services on a connected device.
257 * Optionally, the results can be filtered for a given UUID.
258 */
259 bt_status_t (*search_service)(int conn_id, bt_uuid_t *filter_uuid );
260
261 /**
262 * Enumerate included services for a given service.
263 * Set start_incl_srvc_id to NULL to get the first included service.
264 */
265 bt_status_t (*get_included_service)( int conn_id, btgatt_srvc_id_t *srvc_id,
266 btgatt_srvc_id_t *start_incl_srvc_id);
267
268 /**
269 * Enumerate characteristics for a given service.
270 * Set start_char_id to NULL to get the first characteristic.
271 */
272 bt_status_t (*get_characteristic)( int conn_id,
Andre Eisenbach02223d12013-07-09 00:02:48 -0700273 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *start_char_id);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800274
275 /**
276 * Enumerate descriptors for a given characteristic.
277 * Set start_descr_id to NULL to get the first descriptor.
278 */
279 bt_status_t (*get_descriptor)( int conn_id,
Andre Eisenbach02223d12013-07-09 00:02:48 -0700280 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
281 btgatt_gatt_id_t *start_descr_id);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800282
283 /** Read a characteristic on a remote device */
284 bt_status_t (*read_characteristic)( int conn_id,
Andre Eisenbach02223d12013-07-09 00:02:48 -0700285 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800286 int auth_req );
287
288 /** Write a remote characteristic */
289 bt_status_t (*write_characteristic)(int conn_id,
Andre Eisenbach02223d12013-07-09 00:02:48 -0700290 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800291 int write_type, int len, int auth_req,
292 char* p_value);
293
294 /** Read the descriptor for a given characteristic */
295 bt_status_t (*read_descriptor)(int conn_id,
Andre Eisenbach02223d12013-07-09 00:02:48 -0700296 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
297 btgatt_gatt_id_t *descr_id, int auth_req);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800298
299 /** Write a remote descriptor for a given characteristic */
300 bt_status_t (*write_descriptor)( int conn_id,
Andre Eisenbach02223d12013-07-09 00:02:48 -0700301 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
302 btgatt_gatt_id_t *descr_id, int write_type, int len,
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800303 int auth_req, char* p_value);
304
305 /** Execute a prepared write operation */
306 bt_status_t (*execute_write)(int conn_id, int execute);
307
308 /**
309 * Register to receive notifications or indications for a given
310 * characteristic
311 */
312 bt_status_t (*register_for_notification)( int client_if,
313 const bt_bdaddr_t *bd_addr, btgatt_srvc_id_t *srvc_id,
Andre Eisenbach02223d12013-07-09 00:02:48 -0700314 btgatt_gatt_id_t *char_id);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800315
316 /** Deregister a previous request for notifications/indications */
317 bt_status_t (*deregister_for_notification)( int client_if,
318 const bt_bdaddr_t *bd_addr, btgatt_srvc_id_t *srvc_id,
Andre Eisenbach02223d12013-07-09 00:02:48 -0700319 btgatt_gatt_id_t *char_id);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800320
321 /** Request RSSI for a given remote device */
322 bt_status_t (*read_remote_rssi)( int client_if, const bt_bdaddr_t *bd_addr);
323
Andre Eisenbach709f2392013-12-16 16:16:54 -0800324 /** Enable or disable scan filtering */
325 bt_status_t (*scan_filter_enable)( int enable );
326
327 /** Configure a scan filter condition */
328 bt_status_t (*scan_filter_add)(int type, int company_id, int company_mask,
329 int len, const bt_uuid_t *p_uuid, const bt_uuid_t *p_uuid_mask,
330 const bt_bdaddr_t *bd_addr, char addr_type, const char* p_value);
331
332 /** Clear all scan filter conditions */
333 bt_status_t (*scan_filter_clear)();
334
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800335 /** Determine the type of the remote device (LE, BR/EDR, Dual-mode) */
336 int (*get_device_type)( const bt_bdaddr_t *bd_addr );
337
Andre Eisenbach299e43c2013-08-06 19:54:25 -0700338 /** Set the advertising data or scan response data */
Wei Wang6c2e2d32014-05-20 06:30:05 +0000339 bt_status_t (*set_adv_data)(int client_if, bool set_scan_rsp, bool include_name,
Andre Eisenbach299e43c2013-08-06 19:54:25 -0700340 bool include_txpower, int min_interval, int max_interval, int appearance,
Wei Wanga16d11d2013-11-05 16:09:51 -0800341 uint16_t manufacturer_len, char* manufacturer_data,
342 uint16_t service_data_len, char* service_data,
343 uint16_t service_uuid_len, char* service_uuid);
Andre Eisenbach299e43c2013-08-06 19:54:25 -0700344
Andre Eisenbach8a4b61a2014-03-25 06:30:05 -0700345 /** Configure the MTU for a given connection */
346 bt_status_t (*configure_mtu)(int conn_id, int mtu);
347
Prerepa Viswanadham45edab92014-05-09 16:09:52 -0700348 /** Sets the LE scan interval and window in units of N*0.625 msec */
349 bt_status_t (*set_scan_parameters)(int scan_interval, int scan_window);
350
Wei Wang6c2e2d32014-05-20 06:30:05 +0000351 /* Setup the parameters as per spec, user manual specified values and enable multi ADV */
352 bt_status_t (*multi_adv_enable)(int client_if, int min_interval,int max_interval,int adv_type,
353 int chnl_map, int tx_power);
354
355 /* Update the parameters as per spec, user manual specified values and restart multi ADV */
356 bt_status_t (*multi_adv_update)(int client_if, int min_interval,int max_interval,int adv_type,
357 int chnl_map, int tx_power);
358
359 /* Setup the data for the specified instance */
360 bt_status_t (*multi_adv_set_inst_data)(int client_if, bool set_scan_rsp, bool include_name,
Satya Calloji20a1a052014-05-10 23:37:11 -0700361 bool incl_txpower, int appearance, uint16_t manufacturer_len,
362 char* manufacturer_data, uint16_t service_data_len,
363 char* service_data, uint16_t service_uuid_len, char* service_uuid);
Wei Wang6c2e2d32014-05-20 06:30:05 +0000364
365 /* Disable the multi adv instance */
366 bt_status_t (*multi_adv_disable)(int client_if);
367
Satya Calloji20a1a052014-05-10 23:37:11 -0700368 /* Configure the batchscan storage */
369 bt_status_t (*batchscan_cfg_storage)(int client_if, int batch_scan_full_max,
370 int batch_scan_trunc_max, int batch_scan_notify_threshold);
371
372 /* Enable batchscan */
373 bt_status_t (*batchscan_enb_batch_scan)(int client_if, int scan_mode,
374 int scan_interval, int scan_window, int addr_type, int discard_rule);
375
376 /* Disable batchscan */
377 bt_status_t (*batchscan_dis_batch_scan)(int client_if);
378
379 /* Read out batchscan reports */
380 bt_status_t (*batchscan_read_reports)(int client_if, int scan_mode);
381
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800382 /** Test mode interface */
383 bt_status_t (*test_command)( int command, btgatt_test_params_t* params);
Ganesh Ganapathi Battaf9f4d102014-04-18 10:02:49 -0700384
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800385} btgatt_client_interface_t;
386
387__END_DECLS
388
389#endif /* ANDROID_INCLUDE_BT_GATT_CLIENT_H */