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_att_request_type_e;
47 * GATT Server Response/Indication data
50 guint8 data[BLUETOOTH_GATT_ATT_DATA_LENGTH_MAX];
53 } bluetooth_gatt_att_data_t;
56 * GATT Server service add data
62 } bluetooth_gatt_server_service_params_t;
65 * GATT Server attributes(characteristic/descriptors) add data
68 bt_gatt_permission_t permissions;
69 bt_gatt_characteristic_property_t properties;
72 } bluetooth_gatt_server_attribute_params_t;
75 * GATT Server Indication data
79 bluetooth_device_address_t device_address; /**< device address */
80 gboolean need_confirmation;
82 } bluetooth_gatt_server_indication_params_t;
85 * GATT Server connection/disconnection info
88 bluetooth_device_address_t device_address; /** < Device address */
89 int server_instance; /** < GATT Server Instance Id */
90 } bluetooth_gatt_server_connection_info_t;
93 * GATT Server Service Added info
96 int server_instance; /** < GATT Server Instance Id */
97 int service_handle; /** < GATT Server Service handle */
98 int is_primary; /** < GATT Server Is Primary Service */
99 char uuid[BLUETOOTH_UUID_STRING_MAX];
100 } bluetooth_gatt_server_service_added_info_t;
103 * GATT Server Included Service Added info
106 int server_instance; /** < GATT Server Instance Id */
107 int service_handle; /** < GATT Server Service handle */
108 int included_service_handle; /** < GATT Server Included service handle */
109 } bluetooth_gatt_server_included_service_added_info_t;
113 * GATT Server write attribute data received from Remote GATT client: Max Size is 600 bytes
116 char data[BLUETOOTH_GATT_ATT_DATA_LENGTH_MAX + 1];
117 } bluetooth_gatt_server_write_data_t;
121 * GATT Server Attribute Added Info
124 int server_instance; /** < GATT Server Instance Id */
125 int service_handle; /** < GATT Server Service handle */
126 int attr_handle; /** < GATT Server Attribute Handle (Characteristic or Descriptor) */
127 char uuid[BLUETOOTH_UUID_STRING_MAX]; /** < GATT Server Atribute UUID */
128 } bluetooth_gatt_server_attribute_added_info_t;
131 * GATT Server Service Info
134 int server_instance; /** < GATT Server Instance Id */
135 int service_handle; /** < GATT Server Service handle */
136 } bluetooth_gatt_server_service_status_t;
139 * GATT Server Read Requested Info
142 int connection_id; /** < GATT Server Connection ID */
143 int request_id; /** < GATT Server Read Request ID */
144 int attribute_handle; /** < GATT Server att handle */
145 int offset; /** < GATT Server attribute offset */
146 gboolean is_long; /** < GATT Server Is Long attribute */
147 bluetooth_device_address_t device_address; /**< Remote GATT client device address */
148 } bluetooth_gatt_server_read_requested_info_t;
151 * GATT Server Write Requested Info
154 int connection_id; /** < GATT Server Connection ID */
155 int request_id; /** < GATT Server Write Request ID */
156 int attribute_handle; /** < GATT Server Write att handle */
157 int offset; /** < GATT Server attribute offset */
158 gboolean need_resp; /** < GATT Server Write req needs response */
159 gboolean is_prep_write; /** < GATT Server Is Prepared write */
160 int length; /** < GATT Server Write attribute length */
161 bluetooth_gatt_server_write_data_t data; /** < Write attribute data */
162 bluetooth_device_address_t device_address; /** < Remote GATT client device address */
163 } bluetooth_gatt_server_write_requested_info_t;
166 * GATT Server Update Characteristic Value
169 int attribute_handle; /** < GATT Server Write att handle */
170 int length; /** < GATT Server Write attribute length */
171 bluetooth_gatt_server_write_data_t data; /** < Write attribute data */
172 } bluetooth_gatt_server_update_value_t;
175 * GATT Server Exec write Requested Info
178 int connection_id; /** < GATT Server Connection ID */
179 int request_id; /** < GATT Server Exec Write Request ID */
180 int exec_write; /** < GATT Server Exec Write */
181 bluetooth_device_address_t device_address; /** < Remote GATT client device address */
182 } bluetooth_gatt_server_exec_write_requested_info_t;
185 * GATT Server Indicate confirmed Info
188 int handle; /** < GATT Attribute handle */
189 gboolean completed; /** < GATT Server Exec Write Request ID */
190 bluetooth_device_address_t device_address; /** < Remote GATT client device address */
191 } bluetooth_gatt_server_indicate_confirmed_info_t;
194 * GATT Server Indicate confirmed Info
197 int handle; /** < GATT Attribute handle */
198 gboolean notification; /** < GATT CCCD Notification changed */
199 bluetooth_device_address_t device_address; /** < Remote GATT client device address */
200 } bluetooth_gatt_server_notification_changed_t;
203 * GATT Server response data
206 bluetooth_gatt_att_request_type_e req_type;
210 } bluetooth_gatt_server_response_params_t;
213 * GATT Server Bluedroid Specific Permission Mask
216 BLUETOOTH_PRODUCT_GATT_PERMISSION_READ = 0x01,
217 BLUETOOTH_PRODUCT_GATT_PERMISSION_ENCRYPT_READ = 0x02,
218 BLUETOOTH_PRODUCT_GATT_PERMISSION_ENCRYPT_READ_MITM = 0x04,
219 BLUETOOTH_PRODUCT_GATT_PERMISSION_WRITE = 0x10,
220 BLUETOOTH_PRODUCT_GATT_PERMISSION_ENCRYPT_WRITE = 0x20,
221 BLUETOOTH_PRODUCT_GATT_PERMISSION_ENCRYPT_WRITE_MITM = 0x40,
222 BLUETOOTH_PRODUCT_GATT_PERMISSION_WRITE_SIGNED = 0x80,
223 BLUETOOTH_PRODUCT_GATT_PERMISSION_WRITE_SIGNED_MITM = 0x100,
224 BLUETOOTH_PRODUCT_GATT_PERMISSION_INVALID = 0xffff,
225 } bt_product_gatt_permission_t;
232 } gatt_server_event_param_t;
234 typedef void (*gatt_server_cb_func_ptr)(int, gatt_server_event_param_t *, void *);
237 * @fn int bluetooth_gatt_server_init(gatt_server_cb_func_ptr callback_ptr, void *user_data)
238 * @brief Initialize GATT Server and register the callback
240 * This function is a synchronous call.
245 int bluetooth_gatt_server_init(int *instance_id, gatt_server_cb_func_ptr callback_ptr,
248 //int bluetooth_gatt_register_application(int instance_id);
249 //int bluetooth_gatt_server_init(gatt_server_cb_func_ptr callback_ptr, void *user_data);
251 int bluetooth_gatt_server_deinit(void);
253 int bluetooth_gatt_server_register(const gchar *name, int *instance_id);
255 int bluetooth_gatt_server_unregister(int instance_id);
257 int bluetooth_gatt_server_connect(bluetooth_device_address_t *addr_hex, int instance_id);
259 int bluetooth_gatt_server_disconnect(bluetooth_device_address_t *addr_hex, int instance_id);
261 int bluetooth_gatt_server_add_service(const char *svc_uuid, int type, int numhandles, int instance_id, int *service_handle);
263 int bluetooth_gatt_server_add_included_service(int instance_id, int service_handle, int included_handle);
265 int bluetooth_gatt_server_add_new_characteristic(const char *char_uuid, const bluetooth_gatt_server_attribute_params_t *param, int *char_handle);
268 int bluetooth_gatt_server_add_descriptor(const char *desc_uuid, bt_gatt_permission_t permissions, int service_handle,
269 int instance_id, int *descriptor_handle);
271 int bluetooth_gatt_server_start_service(int service_handle, int instance_id);
273 int bluetooth_gatt_server_stop_service(int service_handle, int instance_id);
275 int bluetooth_gatt_server_delete_service(int service_handle, int instance_id);
277 int bluetooth_gatt_server_send_indication(bluetooth_device_address_t *addr_hex,
278 const bluetooth_gatt_server_indication_params_t *param,
279 const bluetooth_gatt_att_data_t *att_value);
281 int bluetooth_gatt_server_send_response(const bluetooth_gatt_server_response_params_t *param,
282 const bluetooth_gatt_att_data_t *value);
284 int bluetooth_gatt_server_update_multi_adv_instance(const gchar *unique_name, int instance_id);
286 int bluetooth_gatt_server_update_characteristic(int instance_id, const bluetooth_gatt_server_update_value_t *value);
291 #endif /* __BLUETOOTH_GATT_SERVER_API_H */