Fix SVACE issues in Tizen New BT Architecture
[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 {
35     uint8_t             value[BTGATT_MAX_ATTR_LEN];
36     uint16_t            len;
37 } btgatt_unformatted_value_t;
38
39 /** Parameters for GATT read operations */
40 typedef struct
41 {
42     btgatt_srvc_id_t    srvc_id;
43     btgatt_gatt_id_t    char_id;
44     btgatt_gatt_id_t    descr_id;
45     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 */
51 typedef struct
52 {
53     btgatt_srvc_id_t    srvc_id;
54     btgatt_gatt_id_t    char_id;
55     btgatt_gatt_id_t    descr_id;
56     uint8_t             status;
57 } btgatt_write_params_t;
58
59 /** Attribute change notification parameters */
60 typedef struct
61 {
62     uint8_t             value[BTGATT_MAX_ATTR_LEN];
63     bt_bdaddr_t         bda;
64     btgatt_srvc_id_t    srvc_id;
65     btgatt_gatt_id_t    char_id;
66     uint16_t            len;
67     uint8_t             is_notify;
68 } btgatt_notify_params_t;
69
70 typedef 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 */
84 typedef void (*register_client_callback)(int status, int client_if,
85                 bt_uuid_t *app_uuid);
86
87 /** Callback for scan results */
88 typedef void (*scan_result_callback)(bt_bdaddr_t* bda, int rssi, uint8_t* adv_data);
89
90 /** GATT open callback invoked in response to open */
91 typedef void (*connect_callback)(int conn_id, int status, int client_if, bt_bdaddr_t* bda);
92
93 /** Callback invoked in response to close */
94 typedef 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  */
101 typedef void (*search_complete_callback)(int conn_id, int status);
102
103 /** Reports GATT services on a remote device */
104 typedef void (*search_result_callback)( int conn_id, btgatt_srvc_id_t *srvc_id);
105
106 /** GATT characteristic enumeration result callback */
107 typedef void (*get_characteristic_callback)(int conn_id, int status,
108                 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
109                 int char_prop);
110
111 /** GATT descriptor enumeration result callback */
112 typedef void (*get_descriptor_callback)(int conn_id, int status,
113                 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
114                 btgatt_gatt_id_t *descr_id);
115
116 /** GATT included service enumeration result callback */
117 typedef 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 */
121 typedef void (*register_for_notification_callback)(int conn_id,
122                 int registered, int status, btgatt_srvc_id_t *srvc_id,
123                 btgatt_gatt_id_t *char_id);
124
125 /**
126  * Remote device notification callback, invoked when a remote device sends
127  * a notification or indication that a client has registered for.
128  */
129 typedef void (*notify_callback)(int conn_id, btgatt_notify_params_t *p_data);
130
131 /** Reports result of a GATT read operation */
132 typedef void (*read_characteristic_callback)(int conn_id, int status,
133                 btgatt_read_params_t *p_data);
134
135 /** GATT write characteristic operation callback */
136 typedef void (*write_characteristic_callback)(int conn_id, int status,
137                 btgatt_write_params_t *p_data);
138
139 /** GATT execute prepared write callback */
140 typedef void (*execute_write_callback)(int conn_id, int status);
141
142 /** Callback invoked in response to read_descriptor */
143 typedef 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 */
147 typedef 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 */
151 typedef void (*read_remote_rssi_callback)(int client_if, bt_bdaddr_t* bda,
152                                           int rssi, int status);
153
154 /** Callback invoked when the MTU for a given connection changes */
155 typedef void (*configure_mtu_callback)(int conn_id, int status, int mtu);
156
157 /** Callback invoked when a scan filter configuration command has completed */
158 typedef void (*scan_filter_cfg_callback)(int action, int client_if, int status, int filt_type,
159                                          int avbl_space);
160
161 /** Callback invoked when scan param has been added, cleared, or deleted */
162 typedef void (*scan_filter_param_callback)(int action, int client_if, int status,
163                                          int avbl_space);
164
165 /** Callback invoked when a scan filter configuration command has completed */
166 typedef void (*scan_filter_status_callback)(int enable, int client_if, int status);
167
168 /**
169  * Callback notifying an application that a remote device connection is currently congested
170  * and cannot receive any more data. An application should avoid sending more data until
171  * a further callback is received indicating the congestion status has been cleared.
172  */
173 typedef void (*congestion_callback)(int conn_id, bool congested);
174 /** Callback invoked when batchscan storage config operation has completed */
175 typedef void (*batchscan_cfg_storage_callback)(int client_if, int status);
176
177 /** Callback invoked when batchscan enable / disable operation has completed */
178 typedef void (*batchscan_enable_disable_callback)(int action, int client_if, int status);
179
180 /** Callback invoked when batchscan reports are obtained */
181 typedef void (*batchscan_reports_callback)(int client_if, int status, int report_format,
182                                            int num_records, int data_len, uint8_t* rep_data);
183
184 /** Callback invoked when batchscan storage threshold limit is crossed */
185 typedef void (*batchscan_threshold_callback)(int client_if);
186
187 /** Track ADV VSE callback invoked when tracked device is found or lost */
188 typedef void (*track_adv_event_callback)(int client_if, int filt_index, int addr_type,
189                                              bt_bdaddr_t* bda, int adv_state);
190 typedef struct {
191         register_client_callback            register_client_cb;
192         scan_result_callback                scan_result_cb;
193         connect_callback                    open_cb;
194         disconnect_callback                 close_cb;
195         search_complete_callback            search_complete_cb;
196         search_result_callback              search_result_cb;
197         get_characteristic_callback         get_characteristic_cb;
198         get_descriptor_callback             get_descriptor_cb;
199         get_included_service_callback       get_included_service_cb;
200         register_for_notification_callback  register_for_notification_cb;
201         notify_callback                     notify_cb;
202         read_characteristic_callback        read_characteristic_cb;
203         write_characteristic_callback       write_characteristic_cb;
204         read_descriptor_callback            read_descriptor_cb;
205         write_descriptor_callback           write_descriptor_cb;
206         execute_write_callback              execute_write_cb;
207         read_remote_rssi_callback           read_remote_rssi_cb;
208         configure_mtu_callback              configure_mtu_cb;
209         scan_filter_cfg_callback            scan_filter_cfg_cb;
210         scan_filter_param_callback          scan_filter_param_cb;
211         scan_filter_status_callback         scan_filter_status_cb;
212         congestion_callback                 congestion_cb;
213         batchscan_cfg_storage_callback      batchscan_cfg_storage_cb;
214         batchscan_enable_disable_callback   batchscan_enb_disable_cb;
215         batchscan_reports_callback          batchscan_reports_cb;
216         batchscan_threshold_callback        batchscan_threshold_cb;
217         track_adv_event_callback            track_adv_event_cb;
218 } btgatt_client_callbacks_t;
219
220 /** Represents the standard BT-GATT client interface. */
221
222 typedef struct {
223     /** Registers a GATT client application with the stack */
224     bt_status_t (*register_client)( bt_uuid_t *uuid );
225
226     /** Unregister a client application from the stack */
227     bt_status_t (*unregister_client)(int client_if );
228
229     /** Start or stop LE device scanning */
230     bt_status_t (*scan)( int client_if, bool start );
231
232     /** Create a connection to a remote LE or dual-mode device */
233     bt_status_t (*connect)( int client_if, const bt_bdaddr_t *bd_addr,
234                          bool is_direct );
235
236     /** Disconnect a remote device or cancel a pending connection */
237     bt_status_t (*disconnect)( int client_if, const bt_bdaddr_t *bd_addr,
238                     int conn_id);
239
240     /** Clear the attribute cache for a given device */
241     bt_status_t (*refresh)( int client_if, const bt_bdaddr_t *bd_addr );
242
243     /**
244      * Enumerate all GATT services on a connected device.
245      * Optionally, the results can be filtered for a given UUID.
246      */
247     bt_status_t (*search_service)(int conn_id, bt_uuid_t *filter_uuid );
248
249     /**
250      * Enumerate included services for a given service.
251      * Set start_incl_srvc_id to NULL to get the first included service.
252      */
253     bt_status_t (*get_included_service)( int conn_id, btgatt_srvc_id_t *srvc_id,
254                                          btgatt_srvc_id_t *start_incl_srvc_id);
255
256     /**
257      * Enumerate characteristics for a given service.
258      * Set start_char_id to NULL to get the first characteristic.
259      */
260     bt_status_t (*get_characteristic)( int conn_id,
261                     btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *start_char_id);
262
263     /**
264      * Enumerate descriptors for a given characteristic.
265      * Set start_descr_id to NULL to get the first descriptor.
266      */
267     bt_status_t (*get_descriptor)( int conn_id,
268                     btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
269                     btgatt_gatt_id_t *start_descr_id);
270
271     /** Read a characteristic on a remote device */
272     bt_status_t (*read_characteristic)( int conn_id,
273                     btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
274                     int auth_req );
275
276     /** Write a remote characteristic */
277     bt_status_t (*write_characteristic)(int conn_id,
278                     btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
279                     int write_type, int len, int auth_req,
280                     char* p_value);
281
282     /** Read the descriptor for a given characteristic */
283     bt_status_t (*read_descriptor)(int conn_id,
284                     btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
285                     btgatt_gatt_id_t *descr_id, int auth_req);
286
287     /** Write a remote descriptor for a given characteristic */
288     bt_status_t (*write_descriptor)( int conn_id,
289                     btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
290                     btgatt_gatt_id_t *descr_id, int write_type, int len,
291                     int auth_req, char* p_value);
292
293     /** Execute a prepared write operation */
294     bt_status_t (*execute_write)(int conn_id, int execute);
295
296     /**
297      * Register to receive notifications or indications for a given
298      * characteristic
299      */
300     bt_status_t (*register_for_notification)( int client_if,
301                     const bt_bdaddr_t *bd_addr, btgatt_srvc_id_t *srvc_id,
302                     btgatt_gatt_id_t *char_id);
303
304     /** Deregister a previous request for notifications/indications */
305     bt_status_t (*deregister_for_notification)( int client_if,
306                     const bt_bdaddr_t *bd_addr, btgatt_srvc_id_t *srvc_id,
307                     btgatt_gatt_id_t *char_id);
308
309     /** Request RSSI for a given remote device */
310     bt_status_t (*read_remote_rssi)( int client_if, const bt_bdaddr_t *bd_addr);
311
312     /** OTA firmware download */
313     bt_status_t (*ota_fw_update)(int client_if, int conn_id, const bt_bdaddr_t *bd_addr, char* path);
314
315     /** Determine the type of the remote device (LE, BR/EDR, Dual-mode) */
316     int (*get_device_type)( const bt_bdaddr_t *bd_addr );
317
318     /** Request a connection parameter update */
319     bt_status_t (*conn_parameter_update)(bt_bdaddr_t *bd, int min_int, int max_int, int latency, int timeout);
320
321     /** Test mode interface */
322     bt_status_t (*test_command)( int command, btgatt_test_params_t* params);
323
324     /** MTU Exchange request from client */
325     bt_status_t (*configure_mtu)( int conn_id, int mtu);
326
327         /** Setup scan filter params */
328     bt_status_t (*scan_filter_param_setup)(int client_if, int action, int filt_index, int feat_seln,
329                                       int list_logic_type, int filt_logic_type, int rssi_high_thres,
330                                       int rssi_low_thres, int dely_mode, int found_timeout,
331                                       int lost_timeout, int found_timeout_cnt);
332
333
334     /** Configure a scan filter condition  */
335     bt_status_t (*scan_filter_add_remove)(int client_if, int action, int filt_type,
336                                    int filt_index, int company_id,
337                                    int company_id_mask, const bt_uuid_t *p_uuid,
338                                    const bt_uuid_t *p_uuid_mask, const bt_bdaddr_t *bd_addr,
339                                    char addr_type, int data_len, char* p_data, int mask_len,
340                                    char* p_mask);
341
342     /** Clear all scan filter conditions for specific filter index*/
343     bt_status_t (*scan_filter_clear)(int client_if, int filt_index);
344
345     /** Enable / disable scan filter feature*/
346     bt_status_t (*scan_filter_enable)(int client_if, bool enable);
347
348     /** Sets the LE scan interval and window in units of N*0.625 msec */
349 #ifdef TIZEN_BT_HAL
350     bt_status_t (*set_scan_parameters)(int scan_type, int scan_interval, int scan_window);
351 #else
352     bt_status_t (*set_scan_parameters)(int scan_interval, int scan_window);
353 #endif
354
355     /* Configure the batchscan storage */
356     bt_status_t (*batchscan_cfg_storage)(int client_if, int batch_scan_full_max,
357         int batch_scan_trunc_max, int batch_scan_notify_threshold);
358
359     /* Enable batchscan */
360     bt_status_t (*batchscan_enb_batch_scan)(int client_if, int scan_mode,
361         int scan_interval, int scan_window, int addr_type, int discard_rule);
362
363     /* Disable batchscan */
364     bt_status_t (*batchscan_dis_batch_scan)(int client_if);
365
366     /* Read out batchscan reports */
367     bt_status_t (*batchscan_read_reports)(int client_if, int scan_mode);
368
369 } btgatt_client_interface_t;
370
371 __END_DECLS
372
373 #endif /* ANDROID_INCLUDE_BT_GATT_CLIENT_H */