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 } bluetooth_gatt_server_indication_params_t;
87 * GATT Server connection/disconnection info
90 bluetooth_device_address_t device_address; /** < Device address */
91 int server_instance; /** < GATT Server Instance Id */
92 } bluetooth_gatt_server_connection_info_t;
95 * GATT Server Service Added info
98 int server_instance; /** < GATT Server Instance Id */
99 int service_handle; /** < GATT Server Service handle */
100 int is_primary; /** < GATT Server Is Primary Service */
101 char uuid[BLUETOOTH_UUID_STRING_MAX];
102 } bluetooth_gatt_server_service_added_info_t;
105 * GATT Server Included Service Added info
108 int server_instance; /** < GATT Server Instance Id */
109 int service_handle; /** < GATT Server Service handle */
110 int included_service_handle; /** < GATT Server Included service handle */
111 } bluetooth_gatt_server_included_service_added_info_t;
115 * GATT Server write attribute data received from Remote GATT client: Max Size is 600 bytes
118 char data[BLUETOOTH_GATT_ATT_DATA_LENGTH_MAX + 1];
119 } bluetooth_gatt_server_write_data_t;
123 * GATT Server Attribute Added Info
126 int server_instance; /** < GATT Server Instance Id */
127 int service_handle; /** < GATT Server Service handle */
128 int attr_handle; /** < GATT Server Attribute Handle (Characteristic or Descriptor) */
129 char uuid[BLUETOOTH_UUID_STRING_MAX]; /** < GATT Server Atribute UUID */
130 } bluetooth_gatt_server_attribute_added_info_t;
133 * GATT Server Service Info
136 int server_instance; /** < GATT Server Instance Id */
137 int service_handle; /** < GATT Server Service handle */
138 } bluetooth_gatt_server_service_status_t;
141 * GATT Server Read Requested Info
144 int connection_id; /** < GATT Server Connection ID */
145 int request_id; /** < GATT Server Read Request ID */
146 int attribute_handle; /** < GATT Server att handle */
147 int offset; /** < GATT Server attribute offset */
148 gboolean is_long; /** < GATT Server Is Long attribute */
149 bluetooth_device_address_t device_address; /**< Remote GATT client device address */
150 } bluetooth_gatt_server_read_requested_info_t;
153 * GATT Server Write Requested Info
156 int connection_id; /** < GATT Server Connection ID */
157 int request_id; /** < GATT Server Write Request ID */
158 int attribute_handle; /** < GATT Server Write att handle */
159 int offset; /** < GATT Server attribute offset */
160 gboolean need_resp; /** < GATT Server Write req needs response */
161 gboolean is_prep_write; /** < GATT Server Is Prepared write */
162 int length; /** < GATT Server Write attribute length */
163 bluetooth_gatt_server_write_data_t data; /** < Write attribute data */
164 bluetooth_device_address_t device_address; /** < Remote GATT client device address */
165 } bluetooth_gatt_server_write_requested_info_t;
168 * GATT Server Write Requested Info
171 int connection_id; /** < GATT Server Connection ID */
172 int request_id; /** < GATT Server Write Request ID */
173 int attribute_handle; /** < GATT Server Write att handle */
174 int offset; /** < GATT Server attribute offset */
175 char address[BLUETOOTH_ADDRESS_STRING_LENGTH];
176 } bluetooth_gatt_server_acquire_write_info_t;;
180 * GATT Server Update Characteristic Value
183 int attribute_handle; /** < GATT Server Write att handle */
184 int length; /** < GATT Server Write attribute length */
185 bluetooth_gatt_server_write_data_t data; /** < Write attribute data */
186 } bluetooth_gatt_server_update_value_t;
189 * GATT Server Exec write Requested Info
192 int connection_id; /** < GATT Server Connection ID */
193 int request_id; /** < GATT Server Exec Write Request ID */
194 int exec_write; /** < GATT Server Exec Write */
195 bluetooth_device_address_t device_address; /** < Remote GATT client device address */
196 } bluetooth_gatt_server_exec_write_requested_info_t;
199 * GATT Server Indicate confirmed Info
202 int handle; /** < GATT Attribute handle */
203 gboolean completed; /** < GATT Server Exec Write Request ID */
204 bluetooth_device_address_t device_address; /** < Remote GATT client device address */
205 } bluetooth_gatt_server_indicate_confirmed_info_t;
208 * GATT Server Indicate confirmed Info
211 int handle; /** < GATT Attribute handle */
212 gboolean notification; /** < GATT CCCD Notification changed */
213 bluetooth_device_address_t device_address; /** < Remote GATT client device address */
214 } bluetooth_gatt_server_notification_changed_t;
217 * GATT Server response data
220 bluetooth_gatt_att_request_type_e req_type;
224 } bluetooth_gatt_server_response_params_t;
227 * GATT Server acquire response data
230 bluetooth_gatt_att_request_type_e req_type;
234 } bluetooth_gatt_server_acquire_response_params_t;
237 * GATT Server Bluedroid Specific Permission Mask
240 BLUETOOTH_PRODUCT_GATT_PERMISSION_READ = 0x01,
241 BLUETOOTH_PRODUCT_GATT_PERMISSION_ENCRYPT_READ = 0x02,
242 BLUETOOTH_PRODUCT_GATT_PERMISSION_ENCRYPT_READ_MITM = 0x04,
243 BLUETOOTH_PRODUCT_GATT_PERMISSION_WRITE = 0x10,
244 BLUETOOTH_PRODUCT_GATT_PERMISSION_ENCRYPT_WRITE = 0x20,
245 BLUETOOTH_PRODUCT_GATT_PERMISSION_ENCRYPT_WRITE_MITM = 0x40,
246 BLUETOOTH_PRODUCT_GATT_PERMISSION_WRITE_SIGNED = 0x80,
247 BLUETOOTH_PRODUCT_GATT_PERMISSION_WRITE_SIGNED_MITM = 0x100,
248 BLUETOOTH_PRODUCT_GATT_PERMISSION_INVALID = 0xffff,
249 } bt_product_gatt_permission_t;
256 } gatt_server_event_param_t;
258 typedef void (*gatt_server_cb_func_ptr)(int, gatt_server_event_param_t *, void *);
261 * @fn int bluetooth_gatt_server_init(gatt_server_cb_func_ptr callback_ptr, void *user_data)
262 * @brief Initialize GATT Server and register the callback
264 * This function is a synchronous call.
269 int bluetooth_gatt_server_init(int *instance_id, gatt_server_cb_func_ptr callback_ptr,
272 //int bluetooth_gatt_register_application(int instance_id);
273 //int bluetooth_gatt_server_init(gatt_server_cb_func_ptr callback_ptr, void *user_data);
275 int bluetooth_gatt_server_deinit(void);
277 int bluetooth_gatt_server_register(const gchar *name, int *instance_id);
279 int bluetooth_gatt_server_unregister(int instance_id);
281 int bluetooth_gatt_server_connect(bluetooth_device_address_t *addr_hex, int instance_id);
283 int bluetooth_gatt_server_disconnect(bluetooth_device_address_t *addr_hex, int instance_id);
285 int bluetooth_gatt_server_add_service(const char *svc_uuid, int type, int numhandles, int instance_id, int *service_handle);
287 int bluetooth_gatt_server_add_included_service(int instance_id, int service_handle, int included_handle);
289 int bluetooth_gatt_server_add_new_characteristic(const char *char_uuid, const bluetooth_gatt_server_attribute_params_t *param, int *char_handle);
292 int bluetooth_gatt_server_add_descriptor(const char *desc_uuid, bt_gatt_permission_t permissions, int service_handle,
293 int instance_id, int *descriptor_handle);
295 int bluetooth_gatt_server_start_service(int service_handle, int instance_id);
297 int bluetooth_gatt_server_stop_service(int service_handle, int instance_id);
299 int bluetooth_gatt_server_delete_service(int service_handle, int instance_id);
301 int bluetooth_gatt_server_send_indication(bluetooth_device_address_t *addr_hex,
302 const bluetooth_gatt_server_indication_params_t *param,
303 const bluetooth_gatt_att_data_t *att_value);
305 int bluetooth_gatt_server_send_response(const bluetooth_gatt_server_response_params_t *param,
306 const bluetooth_gatt_att_data_t *value);
308 int bluetooth_gatt_server_update_multi_adv_instance(const gchar *unique_name, int instance_id);
310 int bluetooth_gatt_server_update_characteristic(int instance_id, const bluetooth_gatt_server_update_value_t *value);
315 #endif /* __BLUETOOTH_GATT_SERVER_API_H */