4 * Contact: Anupam Roy (anupam.r@samsung.com)
6 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 #ifndef __BLUETOOTH_GATT_SERVER_API_H
23 #define __BLUETOOTH_GATT_SERVER_API_H
29 #include <bluetooth-api.h>
31 #define BLUETOOTH_GATT_ATT_DATA_LENGTH_MAX 610 /**< GATT ATT value max len */
38 * GATT Server Request type
41 BLUETOOTH_GATT_REQUEST_TYPE_READ = 0x00, /* Read Requested */
42 BLUETOOTH_GATT_REQUEST_TYPE_WRITE = 0x01, /* Write Requested */
43 BLUETOOTH_GATT_REQUEST_TYPE_EXEC_WRITE = 0x02, /* Exec Write Requested */
44 BLUETOOTH_GATT_REQUEST_TYPE_ACQUIRE_WRITE = 0x03,
45 BLUETOOTH_GATT_REQUEST_TYPE_ACQUIRE_NOTIFY = 0x04
46 } bluetooth_gatt_att_request_type_e;
49 * GATT Server Response/Indication data
52 guint8 data[BLUETOOTH_GATT_ATT_DATA_LENGTH_MAX];
55 } bluetooth_gatt_att_data_t;
58 * GATT Server service add data
64 } bluetooth_gatt_server_service_params_t;
67 * GATT Server attributes(characteristic/descriptors) add data
70 bt_gatt_permission_t permissions;
71 bt_gatt_characteristic_property_t properties;
74 } bluetooth_gatt_server_attribute_params_t;
77 * GATT Server Indication data
81 bluetooth_device_address_t device_address; /**< device address */
82 gboolean need_confirmation;
84 int fd; /**< handle fd if existing */
85 } bluetooth_gatt_server_indication_params_t;
88 * GATT Server connection/disconnection info
91 bluetooth_device_address_t device_address; /** < Device address */
92 int server_instance; /** < GATT Server Instance Id */
93 } bluetooth_gatt_server_connection_info_t;
96 * GATT Server Service Added info
99 int server_instance; /** < GATT Server Instance Id */
100 int service_handle; /** < GATT Server Service handle */
101 int is_primary; /** < GATT Server Is Primary Service */
102 char uuid[BLUETOOTH_UUID_STRING_MAX];
103 } bluetooth_gatt_server_service_added_info_t;
106 * GATT Server Included Service Added info
109 int server_instance; /** < GATT Server Instance Id */
110 int service_handle; /** < GATT Server Service handle */
111 int included_service_handle; /** < GATT Server Included service handle */
112 } bluetooth_gatt_server_included_service_added_info_t;
116 * GATT Server write attribute data received from Remote GATT client: Max Size is 600 bytes
119 char data[BLUETOOTH_GATT_ATT_DATA_LENGTH_MAX + 1];
120 } bluetooth_gatt_server_write_data_t;
124 * GATT Server Attribute Added Info
127 int server_instance; /** < GATT Server Instance Id */
128 int service_handle; /** < GATT Server Service handle */
129 int attr_handle; /** < GATT Server Attribute Handle (Characteristic or Descriptor) */
130 char uuid[BLUETOOTH_UUID_STRING_MAX]; /** < GATT Server Atribute UUID */
131 } bluetooth_gatt_server_attribute_added_info_t;
134 * GATT Server Service Info
137 int server_instance; /** < GATT Server Instance Id */
138 int service_handle; /** < GATT Server Service handle */
139 } bluetooth_gatt_server_service_status_t;
142 * GATT Server Read Requested Info
145 int connection_id; /** < GATT Server Connection ID */
146 int request_id; /** < GATT Server Read Request ID */
147 int attribute_handle; /** < GATT Server att handle */
148 int offset; /** < GATT Server attribute offset */
149 gboolean is_long; /** < GATT Server Is Long attribute */
150 bluetooth_device_address_t device_address; /**< Remote GATT client device address */
151 } bluetooth_gatt_server_read_requested_info_t;
154 * GATT Server Write Requested Info
157 int connection_id; /** < GATT Server Connection ID */
158 int request_id; /** < GATT Server Write Request ID */
159 int attribute_handle; /** < GATT Server Write att handle */
160 int offset; /** < GATT Server attribute offset */
161 gboolean need_resp; /** < GATT Server Write req needs response */
162 gboolean is_prep_write; /** < GATT Server Is Prepared write */
163 int length; /** < GATT Server Write attribute length */
164 bluetooth_gatt_server_write_data_t data; /** < Write attribute data */
165 bluetooth_device_address_t device_address; /** < Remote GATT client device address */
166 } bluetooth_gatt_server_write_requested_info_t;
169 * GATT Server Write Requested Info
172 int connection_id; /** < GATT Server Connection ID */
173 int request_id; /** < GATT Server Write Request ID */
174 int attribute_handle; /** < GATT Server Write att handle */
175 int offset; /** < GATT Server attribute offset */
176 char address[BLUETOOTH_ADDRESS_STRING_LENGTH];
177 } bluetooth_gatt_server_acquire_write_info_t;;
187 char address[BLUETOOTH_ADDRESS_STRING_LENGTH];
188 } bluetooth_gatt_acquire_notify_info_t;
191 * GATT Server Update Characteristic Value
194 int attribute_handle; /** < GATT Server Write att handle */
195 int length; /** < GATT Server Write attribute length */
196 bluetooth_gatt_server_write_data_t data; /** < Write attribute data */
197 } bluetooth_gatt_server_update_value_t;
200 * GATT Server Exec write Requested Info
203 int connection_id; /** < GATT Server Connection ID */
204 int request_id; /** < GATT Server Exec Write Request ID */
205 int exec_write; /** < GATT Server Exec Write */
206 bluetooth_device_address_t device_address; /** < Remote GATT client device address */
207 } bluetooth_gatt_server_exec_write_requested_info_t;
210 * GATT Server Indicate confirmed Info
213 int handle; /** < GATT Attribute handle */
214 gboolean completed; /** < GATT Server Exec Write Request ID */
215 bluetooth_device_address_t device_address; /** < Remote GATT client device address */
216 } bluetooth_gatt_server_indicate_confirmed_info_t;
219 * GATT Server Indicate confirmed Info
222 int handle; /** < GATT Attribute handle */
223 gboolean notification; /** < GATT CCCD Notification changed */
224 bluetooth_device_address_t device_address; /** < Remote GATT client device address */
225 } bluetooth_gatt_server_notification_changed_t;
228 * GATT Server response data
231 bluetooth_gatt_att_request_type_e req_type;
235 } bluetooth_gatt_server_response_params_t;
238 * GATT Server acquire response data
241 bluetooth_gatt_att_request_type_e req_type;
245 } bluetooth_gatt_server_acquire_response_params_t;
248 * GATT Server Bluedroid Specific Permission Mask
251 BLUETOOTH_PRODUCT_GATT_PERMISSION_READ = 0x01,
252 BLUETOOTH_PRODUCT_GATT_PERMISSION_ENCRYPT_READ = 0x02,
253 BLUETOOTH_PRODUCT_GATT_PERMISSION_ENCRYPT_READ_MITM = 0x04,
254 BLUETOOTH_PRODUCT_GATT_PERMISSION_WRITE = 0x10,
255 BLUETOOTH_PRODUCT_GATT_PERMISSION_ENCRYPT_WRITE = 0x20,
256 BLUETOOTH_PRODUCT_GATT_PERMISSION_ENCRYPT_WRITE_MITM = 0x40,
257 BLUETOOTH_PRODUCT_GATT_PERMISSION_WRITE_SIGNED = 0x80,
258 BLUETOOTH_PRODUCT_GATT_PERMISSION_WRITE_SIGNED_MITM = 0x100,
259 BLUETOOTH_PRODUCT_GATT_PERMISSION_INVALID = 0xffff,
260 } bt_product_gatt_permission_t;
267 } gatt_server_event_param_t;
269 typedef void (*gatt_server_cb_func_ptr)(int, gatt_server_event_param_t *, void *);
272 * @fn int bluetooth_gatt_server_init(gatt_server_cb_func_ptr callback_ptr, void *user_data)
273 * @brief Initialize GATT Server and register the callback
275 * This function is a synchronous call.
280 int bluetooth_gatt_server_init(int *instance_id, gatt_server_cb_func_ptr callback_ptr,
283 //int bluetooth_gatt_register_application(int instance_id);
284 //int bluetooth_gatt_server_init(gatt_server_cb_func_ptr callback_ptr, void *user_data);
286 int bluetooth_gatt_server_deinit(void);
288 int bluetooth_gatt_server_register(const gchar *name, int *instance_id);
290 int bluetooth_gatt_server_unregister(int instance_id);
292 int bluetooth_gatt_server_connect(bluetooth_device_address_t *addr_hex, int instance_id);
294 int bluetooth_gatt_server_disconnect(bluetooth_device_address_t *addr_hex, int instance_id);
296 int bluetooth_gatt_server_add_service(const char *svc_uuid, int type, int numhandles, int instance_id, int *service_handle);
298 int bluetooth_gatt_server_add_included_service(int instance_id, int service_handle, int included_handle);
300 int bluetooth_gatt_server_add_new_characteristic(const char *char_uuid, const bluetooth_gatt_server_attribute_params_t *param, int *char_handle);
303 int bluetooth_gatt_server_add_descriptor(const char *desc_uuid, bt_gatt_permission_t permissions, int service_handle,
304 int instance_id, int *descriptor_handle);
306 int bluetooth_gatt_server_start_service(int service_handle, int instance_id);
308 int bluetooth_gatt_server_stop_service(int service_handle, int instance_id);
310 int bluetooth_gatt_server_delete_service(int service_handle, int instance_id);
312 int bluetooth_gatt_server_send_indication(bluetooth_device_address_t *addr_hex,
313 bluetooth_gatt_server_indication_params_t *param,
314 const bluetooth_gatt_att_data_t *att_value);
316 int bluetooth_gatt_server_send_response(const bluetooth_gatt_server_response_params_t *param,
317 const bluetooth_gatt_att_data_t *value);
319 int bluetooth_gatt_server_update_multi_adv_instance(const gchar *unique_name, int instance_id);
321 int bluetooth_gatt_server_update_characteristic(int instance_id, const bluetooth_gatt_server_update_value_t *value);
326 #endif /* __BLUETOOTH_GATT_SERVER_API_H */