2 * Open Adaptation Layer (OAL)
4 * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
23 #include <oal-manager.h>
25 #define OAL_GATT_MAX_ATTR_LEN 600
26 #define GATTC_READ_VALUE_TYPE_VALUE 0x0000 /* Attribute value itself */
27 #define GATTC_READ_VALUE_TYPE_AGG_FORMAT 0x2905 /* Characteristic Aggregate Format*/
30 OAL_GATT_WRITE_NO_RSP = 1,
32 } oal_gatt_write_type_t;
35 OAL_GATT_AUTH_REQ_NONE = 0,
36 OAL_GATT_AUTH_REQ_NO_MITM, /* unauthenticated encryption */
37 OAL_GATT_AUTH_REQ_MITM, /* authenticated encryption */
38 OAL_GATT_AUTH_REQ_SIGNED_NO_MITM,
39 OAL_GATT_AUTH_REQ_SIGNED_MITM,
40 } oal_gatt_auth_req_t;
42 /** GATT value type used in response to remote read requests */
44 uint8_t value[OAL_GATT_MAX_ATTR_LEN];
51 /** GATT remote read request response type */
53 oal_gatt_value_t attr_value;
55 } oal_gatt_response_t;
61 uint8_t include_txpower;
63 char* manufacturer_data;
64 uint16_t manufacturer_data_len;
66 uint16_t service_data_len;
68 uint16_t service_uuid_len;
70 uint16_t solicit_uuid_len;
71 uint16_t min_interval;
72 uint16_t max_interval;
77 } oal_ble_multi_adv_param_setup_t;
80 * @brief Enable Bluetooth Low Energy GATT Feature
82 * @remarks Application will be able to advertise and scan other Low Energy devices.
84 * @return OAL_STATUS_SUCCESS on success, otherwise non-zero error value.
85 * @retval #OAL_STATUS_SUCCESS Successful
87 * @pre OAL API must be initialized with oal_bt_init().
91 oal_status_t gatt_enable(void);
94 * @brief Disable Bluetooth Low Energy GATT Feature
96 * @remarks Application will not be able to advertise or scan other Low Energy devices.
98 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
99 * @retval #OAL_STATUS_SUCCESS Successful
101 * @pre OAL API should be enabled with gatt_enable().
105 oal_status_t gatt_disable(void);
108 * @brief Register the GATT Server
110 * @remarks Application will register the GATT Server
112 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
113 * @retval #OAL_STATUS_SUCCESS Successful
115 * @pre OAl API should be enabled with gatt_enable().
119 oal_status_t gatts_register(oal_uuid_t* server_uuid);
122 * @brief UnRegister the GATT Server
124 * @remarks Application will unregister the GATT Server
126 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
127 * @retval #OAL_STATUS_SUCCESS Successful
129 * @pre OAl API should be enabled with gatti_enable().
131 * @see gatts_register()
133 oal_status_t gatts_unregister(int instance_id);
136 * @brief Start BLE Advertising feature
138 * @remarks Application will start advertising and behave as a peripheral device
140 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
141 * @retval #OAL_STATUS_SUCCESS Successful
143 * @pre OAl API should be enabled with gatt_enable().
147 oal_status_t gatts_start_listen(int instance_id, gboolean enable);
150 * @brief Stop BLE Advertising feature
152 * @remarks Application will stop advertising and will no longer behave as a peripheral device.
154 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
155 * @retval #OAL_STATUS_SUCCESS Successful
157 * @pre Advertising should have been started with gatts_start_advertising().
159 * @see gatts_start_listen()
161 oal_status_t gatts_stop_advertising(int instance_id);
164 * @brief Enables the Bluetooth Low Energy Multiple advertisement feature
166 * @remarks The application will be able to do multiple advertising
168 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
169 * @retval #OAL_STATUS_SUCCESS Successful
171 * @pre OAL API must be initialized with oal_bt_init().
173 * @see gatts_multi_adv_disable()
175 oal_status_t gatts_multi_adv_enable(int instance_id);
178 * @brief Disables the Bluetooth Low Energy Multiple advertisement feature
180 * @remarks The application will not be able to do multiple advertising
182 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
183 * @retval #OAL_STATUS_SUCCESS Successful
185 * @pre OAL API must be initialized with oal_bt_init().
187 * @see gatts_multi_adv_enable()
189 oal_status_t gatts_multi_adv_disable(int instance_id);
192 * @brief Updates the parameters to configure the Multiple Advertising Features
194 * @remarks The parameters like min and max interval, advertising type,
195 * channel map, tx power and timeout will be updated.
197 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
198 * @retval #OAL_STATUS_SUCCESS Successful
200 * @pre OAL API should be enabled with gatts_multi_adv_enable().
202 * @see gatts_multi_adv_enable()
204 oal_status_t gatts_multi_adv_update(int instance_id, int min_intv, int max_intv,
205 int adv_type, int chnl_map,
206 int tx_power, int timeout_s);
209 * @brief Sets the the Multiple Advertising Data
211 * @remarks The Multiple advertising data will be set.
213 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
214 * @retval #OAL_STATUS_SUCCESS Successful
216 * @pre OAL API should be enabled with gatts_multi_adv_enable().
218 * @see gatts_multi_adv_enable()
220 oal_status_t gatts_multi_adv_set_inst_data(int instance_id,
221 oal_ble_multi_adv_param_setup_t *adv_param_setup);
224 * @brief Get current ATT MTU size of the connection
226 * @remarks The application will get current ATT MTU size of the connection
228 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
229 * @retval #OAL_STATUS_SUCCESS>-Successful
231 * @pre OAL API must be initialized with oal_bt_init().
233 * @param conn_id: active connection id (input)
234 * mtu: att mtu size of the connection (output)
236 * @see gatts_multi_adv_enable()
238 oal_status_t gatts_get_att_mtu(int conn_id, int *mtu);
241 * @brief GATT Server Add Service
243 * @remarks GATT Server will add new service in gatt server database.
245 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
246 * @retval #OAL_STATUS_SUCCESS Successful
248 * @pre Advertising should have been started with gatts_start_advertising().
250 * @see gatts_start_advertising()
252 oal_status_t gatts_add_service(int instance_id, oal_gatt_srvc_id_t *gatt_serv_id, int num_handles);
255 * @brief GATT Server Add Included Service
257 * @remarks GATT Server will add new included service in gatt server database.
259 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
260 * @retval #OAL_STATUS_SUCCESS Successful
262 * @pre Primary service should have been added with gatts_add_service().
264 * @see gatts_add_service()
266 oal_status_t gatts_add_included_services(int instance_id, int srv_handle, int incld_handle);
269 * @brief GATT Server Add Charactertistic
271 * @remarks GATT Server will add new Charactertistic in gatt server database.
273 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
274 * @retval #OAL_STATUS_SUCCESS Successful
276 * @pre Primary service should have been added with gatts_add_service().
278 * @see gatts_add_service()
280 oal_status_t gatts_add_characteristics(int instance_id, int srv_handle, oal_uuid_t* charc_uuid, int propts, int permsn);
283 * @brief GATT Server Add Descriptor
285 * @remarks GATT Server will add new Descriptor in gatt server database.
287 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
288 * @retval #OAL_STATUS_SUCCESS Successful
290 * @pre Primary service should have been added with gatts_add_service().
292 * @see gatts_add_service()
294 oal_status_t gatts_add_descriptor(int instance_id, int srv_handle, oal_uuid_t* desc_uuid, int permsn);
297 * @brief GATT Server make ready the new service for advertiment
299 * @remarks GATT Server will enable the new service for advertiment.
301 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
302 * @retval #OAL_STATUS_SUCCESS Successful
304 * @pre Primary service should have been added with gatts_add_service().
306 * @see gatts_add_service()
308 oal_status_t gatts_start_service(int innstance_id, int svc_handle, int transport);
311 * @brief GATT Server Stop the added service from advertiment
313 * @remarks GATT Server will Stop the added service from advertiment .
315 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
316 * @retval #OAL_STATUS_SUCCESS Successful
318 * @pre Primary service should have been started with gatts_start_service().
320 * @see gatts_start_service()
322 oal_status_t gatts_stop_service(int instance_id, int svc_hdl);
325 * @brief GATT Server delete the already added service
327 * @remarks GATT Server will delete the already added service in gatt server database.
329 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
330 * @retval #OAL_STATUS_SUCCESS Successful
332 * @pre Primary service should have been added with gatts_add_service().
334 * @see gatts_add_service()
336 oal_status_t gatts_delete_service(int instance_id, int svc_handle);
339 * @brief GATT Server send the indication for change in attribute value
341 * @remarks GATT Server will send the indication to client for change in attribute value .
343 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
344 * @retval #OAL_STATUS_SUCCESS Successful
346 * @pre A Client should be connected to this server.
348 * @see gatts_connect()
350 oal_status_t gatts_send_indication(int ins_id, int attr_hndl, int conn_id, int len, int confirm, char* value);
353 * @brief GATT Server Update value of the attribute associated with a GATT server instance
355 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
356 * @retval #OAL_STATUS_SUCCESS Successful
358 oal_status_t gatts_update_att_value(int ins_id, oal_gatt_value_t *value);
361 * @brief GATT Server send the response for attribute value
363 * @remarks GATT Server will send the response for attribute value asked from client .
365 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
366 * @retval #OAL_STATUS_SUCCESS Successful
368 * @pre A Client should be connected to this server.
370 * @see gatts_connect()
372 oal_status_t gatts_send_response(int conn_id, int trans_id, int resp_status, oal_gatt_response_t *response);
374 oal_status_t gatts_disconnect(int Ins_id, bt_address_t *device_address, int conId);
377 * @brief Start LE Device discovery
379 * @remarks BLE discovery will be started
381 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
382 * @retval #OAL_STATUS_SUCCESS Successful
384 * @pre OAL API should be enabled with gatt_enable().
388 oal_status_t gattc_start_le_discovery(int client_id);
390 * @brief Stop LE Device discovery
392 * @remarks BLE discovery will be stopped
394 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
395 * @retval #OAL_STATUS_SUCCESS Successful
397 * @pre BLE Discovery should be started using the gattc_start_le_discovery().
399 * @see gattc_start_le_discovery()
401 oal_status_t gattc_stop_le_discovery(int client_id);
404 * @brief Set scan parameters
406 * @remarks scan parameters will be set
408 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
409 * @retval #OAL_STATUS_SUCCESS Successful
412 oal_status_t gattc_set_le_scan_param(int scan_type, int itv, int win);
414 /** Registers a GATT client application with the stack */
415 oal_status_t gattc_register(oal_uuid_t* client_uuid);
417 oal_status_t gattc_deregister(int client_id);
419 /** Create a connection to a remote LE or dual-mode device */
420 oal_status_t gattc_connect(int client_id, bt_address_t *device_address, int isDirect);
422 oal_status_t gattc_search_service(int conn_id, oal_uuid_t *service_uuid);
424 oal_status_t gattc_get_characteristic(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id);
426 oal_status_t gattc_get_descriptor(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id,
427 oal_gatt_id_t *desc_id);
429 oal_status_t gattc_read_characteristic(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id,
430 oal_gatt_auth_req_t auth_req);
432 oal_status_t gattc_read_descriptor(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id,
433 oal_gatt_id_t *desc_id, oal_gatt_auth_req_t auth_req);
434 oal_status_t gattc_write_characteristic(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id, oal_gatt_write_type_t write_type,
435 int len, oal_gatt_auth_req_t auth_req, char* data);
437 oal_status_t gattc_acquire_notify(int conn_id, oal_gatt_srvc_id_t *srvc_id,
438 oal_gatt_id_t *char_id, int *fd, int *mtu);
440 oal_status_t gattc_acquire_write(int conn_id, oal_gatt_srvc_id_t *srvc_id,
441 oal_gatt_id_t *char_id, oal_gatt_auth_req_t auth_req , int *fd, int*mtu);
443 oal_status_t gattc_write_descriptor(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id, oal_gatt_id_t *desc_id,
444 oal_gatt_write_type_t write_type, int len, oal_gatt_auth_req_t auth_req, char* data);
446 oal_status_t gattc_disconnect(int client_id, bt_address_t *device_address, int conn_id);
448 oal_status_t gattc_conn_param_update(bt_address_t * address, int min, int max, int latency, int timeout);
450 oal_status_t gattc_register_for_notification(int client_id, bt_address_t * address,
451 oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id);
453 oal_status_t gattc_deregister_for_notification(int client_id, bt_address_t * address,
454 oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id);
456 oal_status_t gatt_send_response_acquire(int conn_id, int trans_id,
457 int status, int fd, int mtu, void *);
459 #endif /* OAL_GATT_H_ */