Fix iOS GM connection issue
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / hardware / bt_gatt_client.h
1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  * Copyright (C) 2009-2014 Broadcom Corporation
4  *
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18
19 #ifndef ANDROID_INCLUDE_BT_GATT_CLIENT_H
20 #define ANDROID_INCLUDE_BT_GATT_CLIENT_H
21
22 #include <stdint.h>
23 #include "bt_gatt_types.h"
24
25 __BEGIN_DECLS
26
27 #ifdef TIZEN_BT_HAL
28 #define BT_GATTC_LE_SCAN_TYPE_PASSIVE   0x00
29 #define BT_GATTC_LE_SCAN_TYPE_ACTIVE    0x01
30 #endif
31
32 /** Buffer type for unformatted reads/writes */
33 typedef struct {
34         uint8_t             value[BTGATT_MAX_ATTR_LEN];
35         uint16_t            len;
36 } btgatt_unformatted_value_t;
37
38 /** Parameters for GATT read operations */
39 typedef struct {
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;
44         uint16_t            value_type;
45         uint8_t             status;
46 } btgatt_read_params_t;
47
48 /** Parameters for GATT write operations */
49 typedef struct {
50         btgatt_srvc_id_t    srvc_id;
51         btgatt_gatt_id_t    char_id;
52         btgatt_gatt_id_t    descr_id;
53         uint8_t             status;
54 } btgatt_write_params_t;
55
56 /** Attribute change notification parameters */
57 typedef struct {
58         btgatt_srvc_id_t    srvc_id;
59         btgatt_gatt_id_t    char_id;
60         int fd;
61         uint8_t             status;
62 } btgatt_acquire_params_t;
63
64
65 /** Attribute change notification parameters */
66 typedef struct {
67         uint8_t             value[BTGATT_MAX_ATTR_LEN];
68         bt_bdaddr_t         bda;
69         btgatt_srvc_id_t    srvc_id;
70         btgatt_gatt_id_t    char_id;
71         uint16_t            len;
72         uint8_t             is_notify;
73 } btgatt_notify_params_t;
74
75 typedef struct {
76         bt_bdaddr_t        *bda1;
77         bt_uuid_t          *uuid1;
78         uint16_t            u1;
79         uint16_t            u2;
80         uint16_t            u3;
81         uint16_t            u4;
82         uint16_t            u5;
83 } btgatt_test_params_t;
84
85 /** BT-GATT Client callback structure. */
86
87 /** Callback invoked in response to register_client */
88 typedef void (*register_client_callback)(int status, int client_if,
89                 bt_uuid_t *app_uuid);
90
91 /** Callback for scan results */
92 typedef void (*scan_result_callback)(bt_bdaddr_t* bda, int rssi, uint8_t* adv_data);
93
94 /** GATT open callback invoked in response to open */
95 typedef void (*connect_callback)(int conn_id, int status, int client_if, bt_bdaddr_t* bda);
96
97 /** Callback invoked in response to close */
98 typedef void (*disconnect_callback)(int conn_id, int status,
99                 int client_if, bt_bdaddr_t* bda);
100
101 /**
102  * Invoked in response to search_service when the GATT service search
103  * has been completed.
104  */
105 typedef void (*search_complete_callback)(int conn_id, int status);
106
107 /** Reports GATT services on a remote device */
108 typedef void (*search_result_callback)(int conn_id, btgatt_srvc_id_t *srvc_id);
109
110 /** GATT characteristic enumeration result callback */
111 typedef void (*get_characteristic_callback)(int conn_id, int status,
112                 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
113                 int char_prop);
114
115 /** GATT descriptor enumeration result callback */
116 typedef void (*get_descriptor_callback)(int conn_id, int status,
117                 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
118                 btgatt_gatt_id_t *descr_id);
119
120 /** GATT included service enumeration result callback */
121 typedef void (*get_included_service_callback)(int conn_id, int status,
122                 btgatt_srvc_id_t *srvc_id, btgatt_srvc_id_t *incl_srvc_id);
123
124 /** Callback invoked in response to [de]register_for_notification */
125 typedef void (*register_for_notification_callback)(int conn_id,
126                 int registered, int status, btgatt_srvc_id_t *srvc_id,
127                 btgatt_gatt_id_t *char_id);
128
129 /**
130  * Remote device notification callback, invoked when a remote device sends
131  * a notification or indication that a client has registered for.
132  */
133 typedef void (*notify_callback)(int conn_id, btgatt_notify_params_t *p_data);
134
135 /** Reports result of a GATT read operation */
136 typedef void (*read_characteristic_callback)(int conn_id, int status,
137                 btgatt_read_params_t *p_data);
138
139 /** GATT write characteristic operation callback */
140 typedef void (*write_characteristic_callback)(int conn_id, int status,
141                 btgatt_write_params_t *p_data);
142
143 /** GATT execute prepared write callback */
144 typedef void (*execute_write_callback)(int conn_id, int status);
145
146 /** Callback invoked in response to read_descriptor */
147 typedef void (*read_descriptor_callback)(int conn_id, int status,
148                 btgatt_read_params_t *p_data);
149
150 /** Callback invoked in response to write_descriptor */
151 typedef void (*write_descriptor_callback)(int conn_id, int status,
152                 btgatt_write_params_t *p_data);
153
154 /** Callback triggered in response to read_remote_rssi */
155 typedef void (*read_remote_rssi_callback)(int client_if, bt_bdaddr_t* bda,
156                 int rssi, int status);
157
158 /** Callback invoked when the MTU for a given connection changes */
159 typedef void (*configure_mtu_callback)(int conn_id, int status, int mtu);
160
161 /** Callback invoked when a scan filter configuration command has completed */
162 typedef void (*scan_filter_cfg_callback)(int action, int client_if, int status, int filt_type,
163                 int avbl_space);
164
165 /** Callback invoked when scan param has been added, cleared, or deleted */
166 typedef void (*scan_filter_param_callback)(int action, int client_if, int status,
167                 int avbl_space);
168
169 /** Callback invoked when a scan filter configuration command has completed */
170 typedef void (*scan_filter_status_callback)(int enable, int client_if, int status);
171
172 /**
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  */
177 typedef void (*congestion_callback)(int conn_id, bool congested);
178 /** Callback invoked when batchscan storage config operation has completed */
179 typedef void (*batchscan_cfg_storage_callback)(int client_if, int status);
180
181 /** Callback invoked when batchscan enable / disable operation has completed */
182 typedef void (*batchscan_enable_disable_callback)(int action, int client_if, int status);
183
184 /** Callback invoked when batchscan reports are obtained */
185 typedef void (*batchscan_reports_callback)(int client_if, int status, int report_format,
186                 int num_records, int data_len, uint8_t* rep_data);
187
188 /** Callback invoked when batchscan storage threshold limit is crossed */
189 typedef void (*batchscan_threshold_callback)(int client_if);
190
191 /** Track ADV VSE callback invoked when tracked device is found or lost */
192 typedef void (*track_adv_event_callback)(int client_if, int filt_index, int addr_type,
193                 bt_bdaddr_t* bda, int adv_state);
194 typedef struct {
195         register_client_callback            register_client_cb;
196         scan_result_callback                scan_result_cb;
197         connect_callback                    open_cb;
198         disconnect_callback                 close_cb;
199         search_complete_callback            search_complete_cb;
200         search_result_callback              search_result_cb;
201         get_characteristic_callback         get_characteristic_cb;
202         get_descriptor_callback             get_descriptor_cb;
203         get_included_service_callback       get_included_service_cb;
204         register_for_notification_callback  register_for_notification_cb;
205         notify_callback                     notify_cb;
206         read_characteristic_callback        read_characteristic_cb;
207         write_characteristic_callback       write_characteristic_cb;
208         read_descriptor_callback            read_descriptor_cb;
209         write_descriptor_callback           write_descriptor_cb;
210         execute_write_callback              execute_write_cb;
211         read_remote_rssi_callback           read_remote_rssi_cb;
212         configure_mtu_callback              configure_mtu_cb;
213         scan_filter_cfg_callback            scan_filter_cfg_cb;
214         scan_filter_param_callback          scan_filter_param_cb;
215         scan_filter_status_callback         scan_filter_status_cb;
216         congestion_callback                 congestion_cb;
217         batchscan_cfg_storage_callback      batchscan_cfg_storage_cb;
218         batchscan_enable_disable_callback   batchscan_enb_disable_cb;
219         batchscan_reports_callback          batchscan_reports_cb;
220         batchscan_threshold_callback        batchscan_threshold_cb;
221         track_adv_event_callback            track_adv_event_cb;
222 } btgatt_client_callbacks_t;
223
224 /** Represents the standard BT-GATT client interface. */
225
226 typedef struct {
227         /** Registers a GATT client application with the stack */
228         bt_status_t (*register_client)(bt_uuid_t *uuid);
229
230         /** Unregister a client application from the stack */
231         bt_status_t (*unregister_client)(int client_if);
232
233         /** Start or stop LE device scanning */
234         bt_status_t (*scan)(int client_if, bool start);
235
236         /** Create a connection to a remote LE or dual-mode device */
237         bt_status_t (*connect)(int client_if, const bt_bdaddr_t *bd_addr,
238                         bool is_direct);
239
240         /** Disconnect a remote device or cancel a pending connection */
241         bt_status_t (*disconnect)(int client_if, const bt_bdaddr_t *bd_addr,
242                         int conn_id);
243
244         /** Clear the attribute cache for a given device */
245         bt_status_t (*refresh)(int client_if, const bt_bdaddr_t *bd_addr);
246
247         /**
248          * Enumerate all GATT services on a connected device.
249          * Optionally, the results can be filtered for a given UUID.
250          */
251         bt_status_t (*search_service)(int conn_id, bt_uuid_t *filter_uuid);
252
253         /**
254          * Enumerate included services for a given service.
255          * Set start_incl_srvc_id to NULL to get the first included service.
256          */
257         bt_status_t (*get_included_service)(int conn_id, btgatt_srvc_id_t *srvc_id,
258                         btgatt_srvc_id_t *start_incl_srvc_id);
259
260         /**
261          * Enumerate characteristics for a given service.
262          * Set start_char_id to NULL to get the first characteristic.
263          */
264         bt_status_t (*get_characteristic)(int conn_id,
265                         btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *start_char_id);
266
267         /**
268          * Enumerate descriptors for a given characteristic.
269          * Set start_descr_id to NULL to get the first descriptor.
270          */
271         bt_status_t (*get_descriptor)(int conn_id,
272                         btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
273                         btgatt_gatt_id_t *start_descr_id);
274
275         /** Read a characteristic on a remote device */
276         bt_status_t (*read_characteristic)(int conn_id,
277                         btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
278                         int auth_req);
279
280         /** Write a remote characteristic */
281         bt_status_t (*write_characteristic)(int conn_id,
282                         btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
283                         int write_type, int len, int auth_req,
284                         char* p_value);
285
286         /** acquire fd for writing remote characterstics */
287         bt_status_t (*acquire_write)(int conn_id,
288                         btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
289                          int auth_req, int *fd , int *mtu);
290
291         /** acquire fd for notifying remote characterstics */
292         bt_status_t (*acquire_notify)(int conn_id,
293                         btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
294                          int *fd, int *mtu);
295
296         /** Read the descriptor for a given characteristic */
297         bt_status_t (*read_descriptor)(int conn_id,
298                         btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
299                         btgatt_gatt_id_t *descr_id, int auth_req);
300
301         /** Write a remote descriptor for a given characteristic */
302         bt_status_t (*write_descriptor)(int conn_id,
303                         btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
304                         btgatt_gatt_id_t *descr_id, int write_type, int len,
305                         int auth_req, char* p_value);
306
307         /** Execute a prepared write operation */
308         bt_status_t (*execute_write)(int conn_id, int execute);
309
310         /**
311          * Register to receive notifications or indications for a given
312          * characteristic
313          */
314         bt_status_t (*register_for_notification)(int client_if,
315                         const bt_bdaddr_t *bd_addr, btgatt_srvc_id_t *srvc_id,
316                         btgatt_gatt_id_t *char_id);
317
318         /** Deregister a previous request for notifications/indications */
319         bt_status_t (*deregister_for_notification)(int client_if,
320                         const bt_bdaddr_t *bd_addr, btgatt_srvc_id_t *srvc_id,
321                         btgatt_gatt_id_t *char_id);
322
323         /** Request RSSI for a given remote device */
324         bt_status_t (*read_remote_rssi)(int client_if, const bt_bdaddr_t *bd_addr);
325
326         /** OTA firmware download */
327         bt_status_t (*ota_fw_update)(int client_if, int conn_id, const bt_bdaddr_t *bd_addr, char* path);
328
329         /** Determine the type of the remote device (LE, BR/EDR, Dual-mode) */
330         int (*get_device_type)(const bt_bdaddr_t *bd_addr);
331
332         /** Request a connection parameter update */
333         bt_status_t (*conn_parameter_update)(bt_bdaddr_t *bd, int min_int, int max_int, int latency, int timeout);
334
335         /** Test mode interface */
336         bt_status_t (*test_command)(int command, btgatt_test_params_t* params);
337
338         /** MTU Exchange request from client */
339         bt_status_t (*configure_mtu)(int conn_id, int mtu);
340
341         /** Setup scan filter params */
342         bt_status_t (*scan_filter_param_setup)(int client_if, int action, int filt_index, int feat_seln,
343                         int list_logic_type, int filt_logic_type, int rssi_high_thres,
344                         int rssi_low_thres, int dely_mode, int found_timeout,
345                         int lost_timeout, int found_timeout_cnt);
346
347
348         /** Configure a scan filter condition  */
349         bt_status_t (*scan_filter_add_remove)(int client_if, int action, int filt_type,
350                         int filt_index, int company_id,
351                         int company_id_mask, const bt_uuid_t *p_uuid,
352                         const bt_uuid_t *p_uuid_mask, const bt_bdaddr_t *bd_addr,
353                         char addr_type, int data_len, char* p_data, int mask_len,
354                         char* p_mask);
355
356         /** Clear all scan filter conditions for specific filter index*/
357         bt_status_t (*scan_filter_clear)(int client_if, int filt_index);
358
359         /** Enable / disable scan filter feature*/
360         bt_status_t (*scan_filter_enable)(int client_if, bool enable);
361
362         /** Sets the LE scan interval and window in units of N*0.625 msec */
363 #ifdef TIZEN_BT_HAL
364         bt_status_t (*set_scan_parameters)(int scan_type, int scan_interval, int scan_window);
365 #else
366         bt_status_t (*set_scan_parameters)(int scan_interval, int scan_window);
367 #endif
368
369         /* Configure the batchscan storage */
370         bt_status_t (*batchscan_cfg_storage)(int client_if, int batch_scan_full_max,
371                         int batch_scan_trunc_max, int batch_scan_notify_threshold);
372
373         /* Enable batchscan */
374         bt_status_t (*batchscan_enb_batch_scan)(int client_if, int scan_mode,
375                         int scan_interval, int scan_window, int addr_type, int discard_rule);
376
377         /* Disable batchscan */
378         bt_status_t (*batchscan_dis_batch_scan)(int client_if);
379
380         /* Read out batchscan reports */
381         bt_status_t (*batchscan_read_reports)(int client_if, int scan_mode);
382
383         /** Adds a connection info in list */
384         bt_status_t (*add_connection_info)(const bt_bdaddr_t *bd_addr, int conn_id, int server_inst_id);
385 } btgatt_client_interface_t;
386
387 __END_DECLS
388
389 #endif /* ANDROID_INCLUDE_BT_GATT_CLIENT_H */