c05272c8e6aea1351fd301ff562bd580c4c16192
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / hardware / bt_gatt_server.h
1 /*
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_SERVER_H
19 #define ANDROID_INCLUDE_BT_GATT_SERVER_H
20
21 #include <stdint.h>
22
23 #include "bt_gatt_types.h"
24
25 __BEGIN_DECLS
26
27 /** GATT value type used in response to remote read requests */
28 typedef struct
29 {
30         uint8_t           value[BTGATT_MAX_ATTR_LEN];
31         uint16_t          handle;
32         uint16_t          offset;
33         uint16_t          len;
34         uint8_t           auth_req;
35 } btgatt_value_t;
36
37 /** GATT remote read request response type */
38 typedef union
39 {
40         btgatt_value_t attr_value;
41         uint16_t            handle;
42 } btgatt_response_t;
43
44 typedef struct {
45         uint8_t  server_if;
46         bool     set_scan_rsp;
47         bool     include_name;
48         bool     include_txpower;
49         uint16_t  appearance;
50         char*    manufacturer_data;
51         uint16_t manufacturer_data_len;
52         char*    service_data;
53         uint16_t service_data_len;
54         char*    service_uuid;
55         uint16_t service_uuid_len;
56         char*    solicit_uuid;
57         uint16_t solicit_uuid_len;
58         uint16_t  min_interval;
59         uint16_t  max_interval;
60         uint8_t  adv_type;
61         uint8_t  chnl_map;
62         uint8_t  tx_power;
63         uint8_t  timeout_s;
64 } btgatt_adv_param_setup_t;
65
66
67 /** BT-GATT Server callback structure. */
68
69 /** Callback invoked in response to register_server */
70 typedef void (*register_server_callback)(int status, int server_if,
71                 bt_uuid_t *app_uuid);
72
73 /** Callback indicating that a remote device has connected or been disconnected */
74 typedef void (*connection_callback)(int conn_id, int server_if, int connected,
75                 bt_bdaddr_t *bda);
76
77 /** Callback invoked in response to create_service */
78 typedef void (*service_added_callback)(int status, int server_if,
79                 btgatt_srvc_id_t *srvc_id, int srvc_handle);
80
81 /** Callback indicating that an included service has been added to a service */
82 typedef void (*included_service_added_callback)(int status, int server_if,
83                 int srvc_handle, int incl_srvc_handle);
84
85 /** Callback invoked when a characteristic has been added to a service */
86 typedef void (*characteristic_added_callback)(int status, int server_if,
87                 bt_uuid_t *uuid, int srvc_handle, int char_handle);
88
89 /** Callback invoked when a descriptor has been added to a characteristic */
90 typedef void (*descriptor_added_callback)(int status, int server_if,
91                 bt_uuid_t *uuid, int srvc_handle, int descr_handle);
92
93 /** Callback invoked in response to start_service */
94 typedef void (*service_started_callback)(int status, int server_if,
95                 int srvc_handle);
96
97 /** Callback invoked in response to stop_service */
98 typedef void (*service_stopped_callback)(int status, int server_if,
99                 int srvc_handle);
100
101 /** Callback triggered when a service has been deleted */
102 typedef void (*service_deleted_callback)(int status, int server_if,
103                 int srvc_handle);
104
105 /**
106  * Callback invoked when indication confirmation
107  */
108 typedef void (*indication_confirmation_callback) ( int conn_id, int trans_id, int attr_handle, bt_bdaddr_t *bda);
109
110 #ifdef TIZEN_BT_HAL
111 /**
112  * Callback invoked when indication confirmation
113  */
114 typedef void (*notification_enabled_callback) (int conn_id, int trans_id, int attr_handle, bool notify, bt_bdaddr_t *bda);
115 #endif
116
117 /**
118  * Callback invoked when a remote device has requested to read a characteristic
119  * or descriptor. The application must respond by calling send_response
120  */
121 typedef void (*request_read_callback)(int conn_id, int trans_id, bt_bdaddr_t *bda,
122                 int attr_handle, int offset, bool is_long);
123
124 /**
125  * Callback invoked when a remote device has requested to write to a
126  * characteristic or descriptor.
127  */
128 typedef void (*request_write_callback)(int conn_id, int trans_id, bt_bdaddr_t *bda,
129                 int attr_handle, int offset, int length,
130                 bool need_rsp, bool is_prep, uint8_t* value);
131
132 /** Callback invoked when a previously prepared write is to be executed */
133 typedef void (*request_exec_write_callback)(int conn_id, int trans_id,
134                 bt_bdaddr_t *bda, int exec_write);
135
136 /**
137  * Callback triggered in response to send_response if the remote device
138  * sends a confirmation.
139  */
140 typedef void (*response_confirmation_callback)(int status, int handle);
141
142 /**
143  * Callback indicationg the status of a listen() operation
144  */
145 typedef void (*listen_callback)(int status, int server_if);
146
147 /** Callback invoked when multi-adv enable operation has completed */
148 typedef void (*multi_adv_enable_callback)(int server_if, int status);
149
150 /** Callback invoked when multi-adv param update operation has completed */
151 typedef void (*multi_adv_update_callback)(int server_if, int status);
152
153 /** Callback invoked when multi-adv instance data set operation has completed */
154 typedef void (*multi_adv_data_callback)(int server_if, int status);
155
156 /** Callback invoked when multi-adv disable operation has completed */
157 typedef void (*multi_adv_disable_callback)(int server_if, int status);
158
159 /** Callback invoked when the MTU for a given connection changes */
160 typedef void (*mtu_changed_callback)(int conn_id, int mtu);
161
162 typedef struct {
163         register_server_callback        register_server_cb;
164         connection_callback             connection_cb;
165         service_added_callback          service_added_cb;
166         included_service_added_callback included_service_added_cb;
167         characteristic_added_callback   characteristic_added_cb;
168         descriptor_added_callback       descriptor_added_cb;
169         service_started_callback        service_started_cb;
170         service_stopped_callback        service_stopped_cb;
171         service_deleted_callback        service_deleted_cb;
172         indication_confirmation_callback indication_confirmation_cb;
173         request_read_callback           request_read_cb;
174         request_write_callback          request_write_cb;
175         request_exec_write_callback     request_exec_write_cb;
176         response_confirmation_callback  response_confirmation_cb;
177         listen_callback                 listen_cb;
178         multi_adv_enable_callback       multi_adv_enable_cb;
179         multi_adv_update_callback       multi_adv_update_cb;
180         multi_adv_data_callback         multi_adv_data_cb;
181         multi_adv_disable_callback      multi_adv_disable_cb;
182         mtu_changed_callback            mtu_changed_cb;
183 #ifdef TIZEN_BT_HAL
184         notification_enabled_callback   notif_enabled_cb;
185 #endif
186 } btgatt_server_callbacks_t;
187
188 /** Represents the standard BT-GATT server interface. */
189 typedef struct {
190         /** Registers a GATT server application with the stack */
191         bt_status_t (*register_server)( bt_uuid_t *uuid );
192
193         /** Unregister a server application from the stack */
194         bt_status_t (*unregister_server)(int server_if );
195
196         /** Create a connection to a remote peripheral */
197         bt_status_t (*connect)(int server_if, const bt_bdaddr_t *bd_addr, bool is_direct );
198
199         /** Disconnect an established connection or cancel a pending one */
200         bt_status_t (*disconnect)(int server_if, const bt_bdaddr_t *bd_addr,
201                         int conn_id );
202
203         /** Create a new service */
204         bt_status_t (*add_service)( int server_if, btgatt_srvc_id_t *srvc_id, int num_handles);
205
206         /** Assign an included service to it's parent service */
207         bt_status_t (*add_included_service)( int server_if, int service_handle, int included_handle);
208
209         /** Add a characteristic to a service */
210         bt_status_t (*add_characteristic)( int server_if,
211                         int service_handle, bt_uuid_t *uuid,
212                         int properties, int permissions);
213
214         /** Add a descriptor to a given service */
215         bt_status_t (*add_descriptor)(int server_if, int service_handle,
216                         bt_uuid_t *uuid, int permissions);
217
218         /** Starts a local service */
219         bt_status_t (*start_service)(int server_if, int service_handle,
220                         int transport);
221
222         /** Stops a local service */
223         bt_status_t (*stop_service)(int server_if, int service_handle);
224
225         /** Delete a local service */
226         bt_status_t (*delete_service)(int server_if, int service_handle);
227
228         /** Send value indication to a remote device */
229         bt_status_t (*send_indication)(int server_if, int attribute_handle,
230                         int conn_id, int len, int confirm,
231                         char* p_value);
232
233         /** Send a response to a read/write operation */
234         bt_status_t (*send_response)(int conn_id, int trans_id,
235                         int status, btgatt_response_t *response);
236
237         /** Update GATT server attribute value */
238         bt_status_t (*update_att_value)(int server_if, int attribute_handle,
239                 int value_length, char* att_value);
240
241         /** Start or stop advertisements to listen for incoming connections */
242         bt_status_t (*listen)(int server_if, bool start);
243
244         /** Set the advertising data or scan response data */
245         bt_status_t (*set_adv_data)(int server_if, bool set_scan_rsp, bool include_name,
246                         bool include_txpower, int min_interval, int max_interval, int appearance,
247                         uint16_t manufacturer_len, char* manufacturer_data,
248                         uint16_t service_data_len, char* service_data,
249                         uint16_t service_uuid_len, char* service_uuid);
250
251         /* Setup the parameters as per spec, user manual specified values and enable multi ADV */
252         bt_status_t (*multi_adv_enable)(int server_if);
253
254         /* Update the parameters as per spec, user manual specified values and restart multi ADV */
255         bt_status_t (*multi_adv_update)(int server_if, int min_interval,int max_interval,int adv_type,
256                         int chnl_map, int tx_power, int timeout_s);
257
258         /* Setup the data for the specified instance */
259         bt_status_t (*multi_adv_set_inst_data)(btgatt_adv_param_setup_t adv_param_setup);
260
261         /* Disable the multi adv instance */
262         bt_status_t (*multi_adv_disable)(int server_if);
263
264         /* Get current att mtu size of active connection */
265         bt_status_t (*get_att_mtu)(int conn_id, int *mtu_size);
266 } btgatt_server_interface_t;
267
268 __END_DECLS
269
270 #endif /* ANDROID_INCLUDE_BT_GATT_SERVER_H */