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