blob: cf4fabed29ca795eec63789e93690e377f9465b0 [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/**
155 * Callback indicationg the status of a listen() operation
156 */
157typedef void (*listen_callback)(int status, int server_if);
158
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800159typedef struct {
160 register_client_callback register_client_cb;
161 scan_result_callback scan_result_cb;
162 connect_callback open_cb;
163 disconnect_callback close_cb;
164 search_complete_callback search_complete_cb;
165 search_result_callback search_result_cb;
166 get_characteristic_callback get_characteristic_cb;
167 get_descriptor_callback get_descriptor_cb;
168 get_included_service_callback get_included_service_cb;
169 register_for_notification_callback register_for_notification_cb;
170 notify_callback notify_cb;
171 read_characteristic_callback read_characteristic_cb;
172 write_characteristic_callback write_characteristic_cb;
173 read_descriptor_callback read_descriptor_cb;
174 write_descriptor_callback write_descriptor_cb;
175 execute_write_callback execute_write_cb;
176 read_remote_rssi_callback read_remote_rssi_cb;
Andre Eisenbach299e43c2013-08-06 19:54:25 -0700177 listen_callback listen_cb;
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800178} btgatt_client_callbacks_t;
179
180/** Represents the standard BT-GATT client interface. */
181
182typedef struct {
183 /** Registers a GATT client application with the stack */
184 bt_status_t (*register_client)( bt_uuid_t *uuid );
185
186 /** Unregister a client application from the stack */
187 bt_status_t (*unregister_client)(int client_if );
188
189 /** Start or stop LE device scanning */
190 bt_status_t (*scan)( int client_if, bool start );
191
192 /** Create a connection to a remote LE or dual-mode device */
193 bt_status_t (*connect)( int client_if, const bt_bdaddr_t *bd_addr,
194 bool is_direct );
195
196 /** Disconnect a remote device or cancel a pending connection */
197 bt_status_t (*disconnect)( int client_if, const bt_bdaddr_t *bd_addr,
198 int conn_id);
199
Andre Eisenbach299e43c2013-08-06 19:54:25 -0700200 /** Start or stop advertisements to listen for incoming connections */
201 bt_status_t (*listen)(int client_if, bool start);
202
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800203 /** Clear the attribute cache for a given device */
204 bt_status_t (*refresh)( int client_if, const bt_bdaddr_t *bd_addr );
205
206 /**
207 * Enumerate all GATT services on a connected device.
208 * Optionally, the results can be filtered for a given UUID.
209 */
210 bt_status_t (*search_service)(int conn_id, bt_uuid_t *filter_uuid );
211
212 /**
213 * Enumerate included services for a given service.
214 * Set start_incl_srvc_id to NULL to get the first included service.
215 */
216 bt_status_t (*get_included_service)( int conn_id, btgatt_srvc_id_t *srvc_id,
217 btgatt_srvc_id_t *start_incl_srvc_id);
218
219 /**
220 * Enumerate characteristics for a given service.
221 * Set start_char_id to NULL to get the first characteristic.
222 */
223 bt_status_t (*get_characteristic)( int conn_id,
Andre Eisenbach02223d12013-07-09 00:02:48 -0700224 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *start_char_id);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800225
226 /**
227 * Enumerate descriptors for a given characteristic.
228 * Set start_descr_id to NULL to get the first descriptor.
229 */
230 bt_status_t (*get_descriptor)( int conn_id,
Andre Eisenbach02223d12013-07-09 00:02:48 -0700231 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
232 btgatt_gatt_id_t *start_descr_id);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800233
234 /** Read a characteristic on a remote device */
235 bt_status_t (*read_characteristic)( int conn_id,
Andre Eisenbach02223d12013-07-09 00:02:48 -0700236 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800237 int auth_req );
238
239 /** Write a remote characteristic */
240 bt_status_t (*write_characteristic)(int conn_id,
Andre Eisenbach02223d12013-07-09 00:02:48 -0700241 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800242 int write_type, int len, int auth_req,
243 char* p_value);
244
245 /** Read the descriptor for a given characteristic */
246 bt_status_t (*read_descriptor)(int conn_id,
Andre Eisenbach02223d12013-07-09 00:02:48 -0700247 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
248 btgatt_gatt_id_t *descr_id, int auth_req);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800249
250 /** Write a remote descriptor for a given characteristic */
251 bt_status_t (*write_descriptor)( int conn_id,
Andre Eisenbach02223d12013-07-09 00:02:48 -0700252 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
253 btgatt_gatt_id_t *descr_id, int write_type, int len,
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800254 int auth_req, char* p_value);
255
256 /** Execute a prepared write operation */
257 bt_status_t (*execute_write)(int conn_id, int execute);
258
259 /**
260 * Register to receive notifications or indications for a given
261 * characteristic
262 */
263 bt_status_t (*register_for_notification)( int client_if,
264 const bt_bdaddr_t *bd_addr, btgatt_srvc_id_t *srvc_id,
Andre Eisenbach02223d12013-07-09 00:02:48 -0700265 btgatt_gatt_id_t *char_id);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800266
267 /** Deregister a previous request for notifications/indications */
268 bt_status_t (*deregister_for_notification)( int client_if,
269 const bt_bdaddr_t *bd_addr, btgatt_srvc_id_t *srvc_id,
Andre Eisenbach02223d12013-07-09 00:02:48 -0700270 btgatt_gatt_id_t *char_id);
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800271
272 /** Request RSSI for a given remote device */
273 bt_status_t (*read_remote_rssi)( int client_if, const bt_bdaddr_t *bd_addr);
274
275 /** Determine the type of the remote device (LE, BR/EDR, Dual-mode) */
276 int (*get_device_type)( const bt_bdaddr_t *bd_addr );
277
Andre Eisenbach299e43c2013-08-06 19:54:25 -0700278 /** Set the advertising data or scan response data */
279 bt_status_t (*set_adv_data)(int server_if, bool set_scan_rsp, bool include_name,
280 bool include_txpower, int min_interval, int max_interval, int appearance,
Wei Wang7a8778a2013-11-05 16:09:51 -0800281 uint16_t manufacturer_len, char* manufacturer_data,
282 uint16_t service_data_len, char* service_data,
283 uint16_t service_uuid_len, char* service_uuid);
Andre Eisenbach299e43c2013-08-06 19:54:25 -0700284
Ganesh Ganapathi Battafefb3342013-02-05 15:23:45 -0800285 /** Test mode interface */
286 bt_status_t (*test_command)( int command, btgatt_test_params_t* params);
287} btgatt_client_interface_t;
288
289__END_DECLS
290
291#endif /* ANDROID_INCLUDE_BT_GATT_CLIENT_H */