blob: 6c5a85ec663729ab333adef07b7cf9f3ea2cf833 [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>
Jakub Pawlowski620fd712016-05-27 16:36:24 -070022#include <vector>
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -080023#include "bt_gatt_types.h"
Satya Callojia8b49d32015-02-10 09:20:07 -080024#include "bt_common_types.h"
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -080025
Jakub Pawlowski620fd712016-05-27 16:36:24 -070026using std::vector;
27
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -080028__BEGIN_DECLS
29
30/**
31 * Buffer sizes for maximum attribute length and maximum read/write
32 * operation buffer size.
33 */
34#define BTGATT_MAX_ATTR_LEN 600
35
36/** Buffer type for unformatted reads/writes */
37typedef struct
38{
39 uint8_t value[BTGATT_MAX_ATTR_LEN];
40 uint16_t len;
41} btgatt_unformatted_value_t;
42
43/** Parameters for GATT read operations */
44typedef struct
45{
Jakub Pawlowski1d02bde2016-03-17 15:57:03 -070046 uint16_t handle;
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -080047 btgatt_unformatted_value_t value;
48 uint16_t value_type;
49 uint8_t status;
50} btgatt_read_params_t;
51
52/** Parameters for GATT write operations */
53typedef struct
54{
55 btgatt_srvc_id_t srvc_id;
Andre Eisenbach02223d12013-07-09 00:02:48 -070056 btgatt_gatt_id_t char_id;
57 btgatt_gatt_id_t descr_id;
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -080058 uint8_t status;
59} btgatt_write_params_t;
60
61/** Attribute change notification parameters */
62typedef struct
63{
64 uint8_t value[BTGATT_MAX_ATTR_LEN];
65 bt_bdaddr_t bda;
Jakub Pawlowski1d02bde2016-03-17 15:57:03 -070066 uint16_t handle;
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -080067 uint16_t len;
68 uint8_t is_notify;
69} btgatt_notify_params_t;
70
71typedef struct
72{
Satya Callojia8b49d32015-02-10 09:20:07 -080073 uint8_t client_if;
74 uint8_t action;
75 uint8_t filt_index;
76 uint16_t feat_seln;
77 uint16_t list_logic_type;
78 uint8_t filt_logic_type;
79 uint8_t rssi_high_thres;
80 uint8_t rssi_low_thres;
81 uint8_t dely_mode;
82 uint16_t found_timeout;
83 uint16_t lost_timeout;
84 uint8_t found_timeout_cnt;
85 uint16_t num_of_tracking_entries;
86} btgatt_filt_param_setup_t;
87
88typedef struct
89{
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -080090 bt_bdaddr_t *bda1;
91 bt_uuid_t *uuid1;
92 uint16_t u1;
93 uint16_t u2;
94 uint16_t u3;
95 uint16_t u4;
96 uint16_t u5;
97} btgatt_test_params_t;
98
Satya Calloji51225022015-03-31 13:58:21 -070099/* BT GATT client error codes */
100typedef enum
101{
102 BT_GATTC_COMMAND_SUCCESS = 0, /* 0 Command succeeded */
103 BT_GATTC_COMMAND_STARTED, /* 1 Command started OK. */
104 BT_GATTC_COMMAND_BUSY, /* 2 Device busy with another command */
105 BT_GATTC_COMMAND_STORED, /* 3 request is stored in control block */
106 BT_GATTC_NO_RESOURCES, /* 4 No resources to issue command */
107 BT_GATTC_MODE_UNSUPPORTED, /* 5 Request for 1 or more unsupported modes */
108 BT_GATTC_ILLEGAL_VALUE, /* 6 Illegal command /parameter value */
109 BT_GATTC_INCORRECT_STATE, /* 7 Device in wrong state for request */
110 BT_GATTC_UNKNOWN_ADDR, /* 8 Unknown remote BD address */
111 BT_GATTC_DEVICE_TIMEOUT, /* 9 Device timeout */
112 BT_GATTC_INVALID_CONTROLLER_OUTPUT,/* 10 An incorrect value was received from HCI */
113 BT_GATTC_SECURITY_ERROR, /* 11 Authorization or security failure or not authorized */
114 BT_GATTC_DELAYED_ENCRYPTION_CHECK, /*12 Delayed encryption check */
115 BT_GATTC_ERR_PROCESSING /* 12 Generic error */
116} btgattc_error_t;
117
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800118/** BT-GATT Client callback structure. */
119
120/** Callback invoked in response to register_client */
121typedef void (*register_client_callback)(int status, int client_if,
122 bt_uuid_t *app_uuid);
123
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800124/** GATT open callback invoked in response to open */
125typedef void (*connect_callback)(int conn_id, int status, int client_if, bt_bdaddr_t* bda);
126
127/** Callback invoked in response to close */
128typedef void (*disconnect_callback)(int conn_id, int status,
129 int client_if, bt_bdaddr_t* bda);
130
131/**
132 * Invoked in response to search_service when the GATT service search
133 * has been completed.
134 */
135typedef void (*search_complete_callback)(int conn_id, int status);
136
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800137/** Callback invoked in response to [de]register_for_notification */
138typedef void (*register_for_notification_callback)(int conn_id,
Jakub Pawlowski1d02bde2016-03-17 15:57:03 -0700139 int registered, int status, uint16_t handle);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800140
141/**
142 * Remote device notification callback, invoked when a remote device sends
143 * a notification or indication that a client has registered for.
144 */
145typedef void (*notify_callback)(int conn_id, btgatt_notify_params_t *p_data);
146
147/** Reports result of a GATT read operation */
148typedef void (*read_characteristic_callback)(int conn_id, int status,
149 btgatt_read_params_t *p_data);
150
151/** GATT write characteristic operation callback */
Jakub Pawlowski1d02bde2016-03-17 15:57:03 -0700152typedef void (*write_characteristic_callback)(int conn_id, int status, uint16_t handle);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800153
154/** GATT execute prepared write callback */
155typedef void (*execute_write_callback)(int conn_id, int status);
156
157/** Callback invoked in response to read_descriptor */
158typedef void (*read_descriptor_callback)(int conn_id, int status,
159 btgatt_read_params_t *p_data);
160
161/** Callback invoked in response to write_descriptor */
Jakub Pawlowski1d02bde2016-03-17 15:57:03 -0700162typedef void (*write_descriptor_callback)(int conn_id, int status, uint16_t handle);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800163
164/** Callback triggered in response to read_remote_rssi */
165typedef void (*read_remote_rssi_callback)(int client_if, bt_bdaddr_t* bda,
166 int rssi, int status);
167
Andre Eisenbach8a4b61a2014-03-25 06:30:05 -0700168/** Callback invoked when the MTU for a given connection changes */
169typedef void (*configure_mtu_callback)(int conn_id, int status, int mtu);
170
Andre Eisenbach709f2392013-12-16 16:16:54 -0800171
Andre Eisenbach9ef3c722014-03-28 14:53:33 -0700172/**
173 * Callback notifying an application that a remote device connection is currently congested
174 * and cannot receive any more data. An application should avoid sending more data until
175 * a further callback is received indicating the congestion status has been cleared.
176 */
177typedef void (*congestion_callback)(int conn_id, bool congested);
Satya Calloji51225022015-03-31 13:58:21 -0700178
Jakub Pawlowskif2e13522016-01-21 23:40:51 -0800179/** GATT get database callback */
180typedef void (*get_gatt_db_callback)(int conn_id, btgatt_db_element_t *db, int count);
181
Jakub Pawlowski83e598f2016-02-10 15:31:14 -0800182/** GATT services between start_handle and end_handle were removed */
183typedef void (*services_removed_callback)(int conn_id, uint16_t start_handle, uint16_t end_handle);
184
185/** GATT services were added */
186typedef void (*services_added_callback)(int conn_id, btgatt_db_element_t *added, int added_count);
187
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800188typedef struct {
189 register_client_callback register_client_cb;
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800190 connect_callback open_cb;
191 disconnect_callback close_cb;
192 search_complete_callback search_complete_cb;
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800193 register_for_notification_callback register_for_notification_cb;
194 notify_callback notify_cb;
195 read_characteristic_callback read_characteristic_cb;
196 write_characteristic_callback write_characteristic_cb;
197 read_descriptor_callback read_descriptor_cb;
198 write_descriptor_callback write_descriptor_cb;
199 execute_write_callback execute_write_cb;
200 read_remote_rssi_callback read_remote_rssi_cb;
Andre Eisenbach8a4b61a2014-03-25 06:30:05 -0700201 configure_mtu_callback configure_mtu_cb;
Andre Eisenbach9ef3c722014-03-28 14:53:33 -0700202 congestion_callback congestion_cb;
Jakub Pawlowskif2e13522016-01-21 23:40:51 -0800203 get_gatt_db_callback get_gatt_db_cb;
Jakub Pawlowski83e598f2016-02-10 15:31:14 -0800204 services_removed_callback services_removed_cb;
205 services_added_callback services_added_cb;
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800206} btgatt_client_callbacks_t;
207
208/** Represents the standard BT-GATT client interface. */
209
210typedef struct {
211 /** Registers a GATT client application with the stack */
212 bt_status_t (*register_client)( bt_uuid_t *uuid );
213
214 /** Unregister a client application from the stack */
215 bt_status_t (*unregister_client)(int client_if );
216
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800217 /** Create a connection to a remote LE or dual-mode device */
218 bt_status_t (*connect)( int client_if, const bt_bdaddr_t *bd_addr,
Ganesh Ganapathi Battaf9f4d102014-04-18 10:02:49 -0700219 bool is_direct, int transport );
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800220
221 /** Disconnect a remote device or cancel a pending connection */
222 bt_status_t (*disconnect)( int client_if, const bt_bdaddr_t *bd_addr,
223 int conn_id);
224
225 /** Clear the attribute cache for a given device */
226 bt_status_t (*refresh)( int client_if, const bt_bdaddr_t *bd_addr );
227
228 /**
229 * Enumerate all GATT services on a connected device.
230 * Optionally, the results can be filtered for a given UUID.
231 */
232 bt_status_t (*search_service)(int conn_id, bt_uuid_t *filter_uuid );
233
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800234 /** Read a characteristic on a remote device */
Jakub Pawlowski1d02bde2016-03-17 15:57:03 -0700235 bt_status_t (*read_characteristic)( int conn_id, uint16_t handle,
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800236 int auth_req );
237
238 /** Write a remote characteristic */
Jakub Pawlowski1d02bde2016-03-17 15:57:03 -0700239 bt_status_t (*write_characteristic)(int conn_id, uint16_t handle,
Jakub Pawlowski620fd712016-05-27 16:36:24 -0700240 int write_type, int auth_req,
241 vector<uint8_t> value);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800242
243 /** Read the descriptor for a given characteristic */
Jakub Pawlowski1d02bde2016-03-17 15:57:03 -0700244 bt_status_t (*read_descriptor)(int conn_id, uint16_t handle, int auth_req);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800245
246 /** Write a remote descriptor for a given characteristic */
Jakub Pawlowski1d02bde2016-03-17 15:57:03 -0700247 bt_status_t (*write_descriptor)( int conn_id, uint16_t handle,
Jakub Pawlowskif2479632016-03-30 22:56:06 -0700248 int auth_req, vector<uint8_t> value);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800249
250 /** Execute a prepared write operation */
251 bt_status_t (*execute_write)(int conn_id, int execute);
252
253 /**
254 * Register to receive notifications or indications for a given
255 * characteristic
256 */
257 bt_status_t (*register_for_notification)( int client_if,
Jakub Pawlowski1d02bde2016-03-17 15:57:03 -0700258 const bt_bdaddr_t *bd_addr, uint16_t handle);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800259
260 /** Deregister a previous request for notifications/indications */
261 bt_status_t (*deregister_for_notification)( int client_if,
Jakub Pawlowski1d02bde2016-03-17 15:57:03 -0700262 const bt_bdaddr_t *bd_addr, uint16_t handle);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800263
264 /** Request RSSI for a given remote device */
265 bt_status_t (*read_remote_rssi)( int client_if, const bt_bdaddr_t *bd_addr);
266
267 /** Determine the type of the remote device (LE, BR/EDR, Dual-mode) */
268 int (*get_device_type)( const bt_bdaddr_t *bd_addr );
269
Andre Eisenbach8a4b61a2014-03-25 06:30:05 -0700270 /** Configure the MTU for a given connection */
271 bt_status_t (*configure_mtu)(int conn_id, int mtu);
272
Andre Eisenbachda4eaca2014-07-16 22:58:36 -0700273 /** Request a connection parameter update */
274 bt_status_t (*conn_parameter_update)(const bt_bdaddr_t *bd_addr, int min_interval,
275 int max_interval, int latency, int timeout);
276
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800277 /** Test mode interface */
278 bt_status_t (*test_command)( int command, btgatt_test_params_t* params);
Ganesh Ganapathi Battaf9f4d102014-04-18 10:02:49 -0700279
Jakub Pawlowskif2e13522016-01-21 23:40:51 -0800280 /** Get gatt db content */
281 bt_status_t (*get_gatt_db)( int conn_id);
282
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800283} btgatt_client_interface_t;
284
285__END_DECLS
286
287#endif /* ANDROID_INCLUDE_BT_GATT_CLIENT_H */