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 } bluetooth_gatt_acquire_notify_info_t;
190 * GATT Server Update Characteristic Value
193 int attribute_handle; /** < GATT Server Write att handle */
194 int length; /** < GATT Server Write attribute length */
195 bluetooth_gatt_server_write_data_t data; /** < Write attribute data */
196 } bluetooth_gatt_server_update_value_t;
199 * GATT Server Exec write Requested Info
202 int connection_id; /** < GATT Server Connection ID */
203 int request_id; /** < GATT Server Exec Write Request ID */
204 int exec_write; /** < GATT Server Exec Write */
205 bluetooth_device_address_t device_address; /** < Remote GATT client device address */
206 } bluetooth_gatt_server_exec_write_requested_info_t;
209 * GATT Server Indicate confirmed Info
212 int handle; /** < GATT Attribute handle */
213 gboolean completed; /** < GATT Server Exec Write Request ID */
214 bluetooth_device_address_t device_address; /** < Remote GATT client device address */
215 } bluetooth_gatt_server_indicate_confirmed_info_t;
218 * GATT Server Indicate confirmed Info
221 int handle; /** < GATT Attribute handle */
222 gboolean notification; /** < GATT CCCD Notification changed */
223 bluetooth_device_address_t device_address; /** < Remote GATT client device address */
224 } bluetooth_gatt_server_notification_changed_t;
227 * GATT Server response data
230 bluetooth_gatt_att_request_type_e req_type;
234 } bluetooth_gatt_server_response_params_t;
237 * GATT Server acquire response data
240 bluetooth_gatt_att_request_type_e req_type;
244 } bluetooth_gatt_server_acquire_response_params_t;
247 * GATT Server Bluedroid Specific Permission Mask
250 BLUETOOTH_PRODUCT_GATT_PERMISSION_READ = 0x01,
251 BLUETOOTH_PRODUCT_GATT_PERMISSION_ENCRYPT_READ = 0x02,
252 BLUETOOTH_PRODUCT_GATT_PERMISSION_ENCRYPT_READ_MITM = 0x04,
253 BLUETOOTH_PRODUCT_GATT_PERMISSION_WRITE = 0x10,
254 BLUETOOTH_PRODUCT_GATT_PERMISSION_ENCRYPT_WRITE = 0x20,
255 BLUETOOTH_PRODUCT_GATT_PERMISSION_ENCRYPT_WRITE_MITM = 0x40,
256 BLUETOOTH_PRODUCT_GATT_PERMISSION_WRITE_SIGNED = 0x80,
257 BLUETOOTH_PRODUCT_GATT_PERMISSION_WRITE_SIGNED_MITM = 0x100,
258 BLUETOOTH_PRODUCT_GATT_PERMISSION_INVALID = 0xffff,
259 } bt_product_gatt_permission_t;
266 } gatt_server_event_param_t;
268 typedef void (*gatt_server_cb_func_ptr)(int, gatt_server_event_param_t *, void *);
271 * @fn int bluetooth_gatt_server_init(gatt_server_cb_func_ptr callback_ptr, void *user_data)
272 * @brief Initialize GATT Server and register the callback
274 * This function is a synchronous call.
279 int bluetooth_gatt_server_init(int *instance_id, gatt_server_cb_func_ptr callback_ptr,
282 //int bluetooth_gatt_register_application(int instance_id);
283 //int bluetooth_gatt_server_init(gatt_server_cb_func_ptr callback_ptr, void *user_data);
285 int bluetooth_gatt_server_deinit(void);
287 int bluetooth_gatt_server_register(const gchar *name, int *instance_id);
289 int bluetooth_gatt_server_unregister(int instance_id);
291 int bluetooth_gatt_server_connect(bluetooth_device_address_t *addr_hex, int instance_id);
293 int bluetooth_gatt_server_disconnect(bluetooth_device_address_t *addr_hex, int instance_id);
295 int bluetooth_gatt_server_add_service(const char *svc_uuid, int type, int numhandles, int instance_id, int *service_handle);
297 int bluetooth_gatt_server_add_included_service(int instance_id, int service_handle, int included_handle);
299 int bluetooth_gatt_server_add_new_characteristic(const char *char_uuid, const bluetooth_gatt_server_attribute_params_t *param, int *char_handle);
302 int bluetooth_gatt_server_add_descriptor(const char *desc_uuid, bt_gatt_permission_t permissions, int service_handle,
303 int instance_id, int *descriptor_handle);
305 int bluetooth_gatt_server_start_service(int service_handle, int instance_id);
307 int bluetooth_gatt_server_stop_service(int service_handle, int instance_id);
309 int bluetooth_gatt_server_delete_service(int service_handle, int instance_id);
311 int bluetooth_gatt_server_send_indication(bluetooth_device_address_t *addr_hex,
312 bluetooth_gatt_server_indication_params_t *param,
313 const bluetooth_gatt_att_data_t *att_value);
315 int bluetooth_gatt_server_send_response(const bluetooth_gatt_server_response_params_t *param,
316 const bluetooth_gatt_att_data_t *value);
318 int bluetooth_gatt_server_update_multi_adv_instance(const gchar *unique_name, int instance_id);
320 int bluetooth_gatt_server_update_characteristic(int instance_id, const bluetooth_gatt_server_update_value_t *value);
325 #endif /* __BLUETOOTH_GATT_SERVER_API_H */