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;
46 OAL_BLE_SCAN_FILTER_FEATURE_DEVICE_ADDRESS = 0x01, /**< device address */
47 OAL_BLE_SCAN_FILTER_FEATURE_SERVICE_DATA_CHANGED = 0x02, /**< service data changed */
48 OAL_BLE_SCAN_FILTER_FEATURE_SERVICE_UUID = 0x04, /**< service uuid */
49 OAL_BLE_SCAN_FILTER_FEATURE_SERVICE_SOLICITATION_UUID = 0x08, /**< service solicitation uuid */
50 OAL_BLE_SCAN_FILTER_FEATURE_DEVICE_NAME = 0x10, /**< device name */
51 OAL_BLE_SCAN_FILTER_FEATURE_MANUFACTURER_DATA = 0x20, /**< manufacturer data */
52 OAL_BLE_SCAN_FILTER_FEATURE_SERVICE_DATA = 0x40, /**< service data */
53 OAL_BLE_SCAN_FILTER_FEATURE_RSSI_HIGH_THRESHOLD = 0x80, /**< rssi high threshold */
54 } oal_ble_scan_filter_feature_t;
56 /** GATT value type used in response to remote read requests */
58 uint8_t value[OAL_GATT_MAX_ATTR_LEN];
65 /** GATT remote read request response type */
67 oal_gatt_value_t attr_value;
69 } oal_gatt_response_t;
75 uint8_t include_txpower;
77 uint8_t include_appearance;
80 char* manufacturer_data;
81 uint16_t manufacturer_data_len;
83 uint16_t service_data_len;
85 uint16_t service_uuid_len;
87 uint16_t solicit_uuid_len;
88 uint16_t min_interval;
89 uint16_t max_interval;
96 uint16_t tds_data_len;
97 } oal_ble_multi_adv_param_setup_t;
102 bt_address_t* device_address;
104 oal_uuid_t* service_uuid;
105 int service_uuid_len;
106 oal_uuid_t* service_uuid_mask;
107 int service_uuid_mask_len;
108 oal_uuid_t* service_solicitation_uuid;
109 int service_solicitation_uuid_len;
110 oal_uuid_t* service_solicitation_uuid_mask;
111 int service_solicitation_uuid_mask_len;
112 uint8_t* service_data;
113 int service_data_len;
114 uint8_t* service_data_mask;
115 int service_data_mask_len;
117 uint8_t* manufacturer_data;
118 int manufacturer_data_len;
119 uint8_t* manufacturer_data_mask;
120 int manufacturer_data_mask_len;
121 int rssi_high_threshold;
122 } oal_ble_scan_filter_t;
125 int list_logic_type; // list_logic_type (OR - 0x00, AND - 0x01)
126 int filt_logic_type; // filt_logic_type (OR - 0x00, AND - 0x01)
129 int dely_mode; // dely_mode (Immediate - 0x00, on found - 0x01, batched - 0x02)
132 int found_timeout_cnt;
133 } oal_ble_scan_filter_param_setup_t;
136 * @brief Enable Bluetooth Low Energy GATT Feature
138 * @remarks Application will be able to advertise and scan other Low Energy devices.
140 * @return OAL_STATUS_SUCCESS on success, otherwise non-zero error value.
141 * @retval #OAL_STATUS_SUCCESS Successful
143 * @pre OAL API must be initialized with oal_bt_init().
145 * @see gatt_disable()
147 oal_status_t gatt_enable(void);
150 * @brief Disable Bluetooth Low Energy GATT Feature
152 * @remarks Application will not be able to advertise or scan other Low Energy devices.
154 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
155 * @retval #OAL_STATUS_SUCCESS Successful
157 * @pre OAL API should be enabled with gatt_enable().
161 oal_status_t gatt_disable(void);
164 * @brief Register the GATT Server
166 * @remarks Application will register the GATT Server
168 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
169 * @retval #OAL_STATUS_SUCCESS Successful
171 * @pre OAl API should be enabled with gatt_enable().
175 oal_status_t gatts_register(oal_uuid_t* server_uuid);
178 * @brief UnRegister the GATT Server
180 * @remarks Application will unregister the GATT Server
182 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
183 * @retval #OAL_STATUS_SUCCESS Successful
185 * @pre OAl API should be enabled with gatti_enable().
187 * @see gatts_register()
189 oal_status_t gatts_unregister(int instance_id);
192 * @brief Start BLE Advertising feature
194 * @remarks Application will start advertising and behave as a peripheral device
196 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
197 * @retval #OAL_STATUS_SUCCESS Successful
199 * @pre OAl API should be enabled with gatt_enable().
203 oal_status_t gatts_start_listen(int instance_id, gboolean enable);
206 * @brief Stop BLE Advertising feature
208 * @remarks Application will stop advertising and will no longer behave as a peripheral device.
210 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
211 * @retval #OAL_STATUS_SUCCESS Successful
213 * @pre Advertising should have been started with gatts_start_advertising().
215 * @see gatts_start_listen()
217 oal_status_t gatts_stop_advertising(int instance_id);
220 * @brief Enables the Bluetooth Low Energy Multiple advertisement feature
222 * @remarks The application will be able to do multiple advertising
224 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
225 * @retval #OAL_STATUS_SUCCESS Successful
227 * @pre OAL API must be initialized with oal_bt_init().
229 * @see gatts_multi_adv_disable()
231 oal_status_t gatts_multi_adv_enable(int instance_id);
234 * @brief Disables the Bluetooth Low Energy Multiple advertisement feature
236 * @remarks The application will not be able to do multiple advertising
238 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
239 * @retval #OAL_STATUS_SUCCESS Successful
241 * @pre OAL API must be initialized with oal_bt_init().
243 * @see gatts_multi_adv_enable()
245 oal_status_t gatts_multi_adv_disable(int instance_id);
248 * @brief Updates the parameters to configure the Multiple Advertising Features
250 * @remarks The parameters like min and max interval, advertising type,
251 * channel map, tx power and timeout will be updated.
253 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
254 * @retval #OAL_STATUS_SUCCESS Successful
256 * @pre OAL API should be enabled with gatts_multi_adv_enable().
258 * @see gatts_multi_adv_enable()
260 oal_status_t gatts_multi_adv_update(int instance_id, int min_intv, int max_intv,
261 int adv_type, int chnl_map,
262 int tx_power, int timeout_s);
265 * @brief sets the filter policy for a particular advertiser in HAL layer.
267 oal_status_t gatts_set_filter_policy(int filter_policy);
270 * @brief Sets the the Multiple Advertising Data
272 * @remarks The Multiple advertising data will be set.
274 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
275 * @retval #OAL_STATUS_SUCCESS Successful
277 * @pre OAL API should be enabled with gatts_multi_adv_enable().
279 * @see gatts_multi_adv_enable()
281 oal_status_t gatts_multi_adv_set_inst_data(int instance_id,
282 oal_ble_multi_adv_param_setup_t *adv_param_setup);
285 * @brief Get current ATT MTU size of the connection
287 * @remarks The application will get current ATT MTU size of the connection
289 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
290 * @retval #OAL_STATUS_SUCCESS>-Successful
292 * @pre OAL API must be initialized with oal_bt_init().
294 * @param conn_id: active connection id (input)
295 * mtu: att mtu size of the connection (output)
297 * @see gatts_multi_adv_enable()
299 oal_status_t gatts_get_att_mtu(int conn_id, int *mtu);
302 * @brief GATT Server Add Service
304 * @remarks GATT Server will add new service in gatt server database.
306 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
307 * @retval #OAL_STATUS_SUCCESS Successful
309 * @pre Advertising should have been started with gatts_start_advertising().
311 * @see gatts_start_advertising()
313 oal_status_t gatts_add_service(int instance_id, oal_gatt_srvc_id_t *gatt_serv_id, int num_handles);
316 * @brief GATT Server Add Included Service
318 * @remarks GATT Server will add new included service in gatt server database.
320 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
321 * @retval #OAL_STATUS_SUCCESS Successful
323 * @pre Primary service should have been added with gatts_add_service().
325 * @see gatts_add_service()
327 oal_status_t gatts_add_included_services(int instance_id, int srv_handle, int incld_handle);
330 * @brief GATT Server Add Charactertistic
332 * @remarks GATT Server will add new Charactertistic in gatt server database.
334 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
335 * @retval #OAL_STATUS_SUCCESS Successful
337 * @pre Primary service should have been added with gatts_add_service().
339 * @see gatts_add_service()
341 oal_status_t gatts_add_characteristics(int instance_id, int srv_handle, oal_uuid_t* charc_uuid, int propts, int permsn);
344 * @brief GATT Server Add Descriptor
346 * @remarks GATT Server will add new Descriptor in gatt server database.
348 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
349 * @retval #OAL_STATUS_SUCCESS Successful
351 * @pre Primary service should have been added with gatts_add_service().
353 * @see gatts_add_service()
355 oal_status_t gatts_add_descriptor(int instance_id, int srv_handle, oal_uuid_t* desc_uuid, int permsn);
358 * @brief GATT Server make ready the new service for advertiment
360 * @remarks GATT Server will enable the new service for advertiment.
362 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
363 * @retval #OAL_STATUS_SUCCESS Successful
365 * @pre Primary service should have been added with gatts_add_service().
367 * @see gatts_add_service()
369 oal_status_t gatts_start_service(int innstance_id, int svc_handle, int transport);
372 * @brief GATT Server Stop the added service from advertiment
374 * @remarks GATT Server will Stop the added service from advertiment .
376 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
377 * @retval #OAL_STATUS_SUCCESS Successful
379 * @pre Primary service should have been started with gatts_start_service().
381 * @see gatts_start_service()
383 oal_status_t gatts_stop_service(int instance_id, int svc_hdl);
386 * @brief GATT Server delete the already added service
388 * @remarks GATT Server will delete the already added service in gatt server database.
390 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
391 * @retval #OAL_STATUS_SUCCESS Successful
393 * @pre Primary service should have been added with gatts_add_service().
395 * @see gatts_add_service()
397 oal_status_t gatts_delete_service(int instance_id, int svc_handle);
400 * @brief GATT Server send the indication for change in attribute value
402 * @remarks GATT Server will send the indication to client for change in attribute value .
404 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
405 * @retval #OAL_STATUS_SUCCESS Successful
407 * @pre A Client should be connected to this server.
409 * @see gatts_connect()
411 oal_status_t gatts_send_indication(int ins_id, int attr_hndl, int conn_id, int len, int confirm, char* value);
414 * @brief GATT Server Update value of the attribute associated with a GATT server instance
416 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
417 * @retval #OAL_STATUS_SUCCESS Successful
419 oal_status_t gatts_update_att_value(int ins_id, oal_gatt_value_t *value);
422 * @brief GATT Server send the response for attribute value
424 * @remarks GATT Server will send the response for attribute value asked from client .
426 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
427 * @retval #OAL_STATUS_SUCCESS Successful
429 * @pre A Client should be connected to this server.
431 * @see gatts_connect()
433 oal_status_t gatts_send_response(int conn_id, int trans_id, int resp_status, oal_gatt_response_t *response);
435 oal_status_t gatts_disconnect(int Ins_id, bt_address_t *device_address, int conId);
438 * @brief Start LE Device discovery
440 * @remarks BLE discovery will be started
442 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
443 * @retval #OAL_STATUS_SUCCESS Successful
445 * @pre OAL API should be enabled with gatt_enable().
449 oal_status_t gattc_start_le_discovery(int client_id);
451 * @brief Stop LE Device discovery
453 * @remarks BLE discovery will be stopped
455 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
456 * @retval #OAL_STATUS_SUCCESS Successful
458 * @pre BLE Discovery should be started using the gattc_start_le_discovery().
460 * @see gattc_start_le_discovery()
462 oal_status_t gattc_stop_le_discovery(int client_id);
465 * @brief Set scan parameters
467 * @remarks scan parameters will be set
469 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
470 * @retval #OAL_STATUS_SUCCESS Successful
473 oal_status_t gattc_set_le_scan_param(int scan_type, int itv, int win);
475 /** Registers a GATT client application with the stack */
476 oal_status_t gattc_register(oal_uuid_t* client_uuid);
478 oal_status_t gattc_deregister(int client_id);
480 /** Create a connection to a remote LE or dual-mode device */
481 oal_status_t gattc_connect(int client_id, bt_address_t *device_address, int isDirect);
483 oal_status_t gattc_search_service(int conn_id, oal_uuid_t *service_uuid);
485 oal_status_t gattc_get_characteristic(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id);
487 oal_status_t gattc_get_descriptor(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id,
488 oal_gatt_id_t *desc_id);
490 oal_status_t gattc_read_characteristic(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id,
491 oal_gatt_auth_req_t auth_req);
493 oal_status_t gattc_read_descriptor(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id,
494 oal_gatt_id_t *desc_id, oal_gatt_auth_req_t auth_req);
495 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,
496 int len, oal_gatt_auth_req_t auth_req, char* data);
498 oal_status_t gattc_acquire_notify(int conn_id, oal_gatt_srvc_id_t *srvc_id,
499 oal_gatt_id_t *char_id, int *fd, int *mtu);
501 oal_status_t gattc_acquire_write(int conn_id, oal_gatt_srvc_id_t *srvc_id,
502 oal_gatt_id_t *char_id, oal_gatt_auth_req_t auth_req , int *fd, int*mtu);
504 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,
505 oal_gatt_write_type_t write_type, int len, oal_gatt_auth_req_t auth_req, char* data);
507 oal_status_t gattc_disconnect(int client_id, bt_address_t *device_address, int conn_id);
509 oal_status_t gattc_unregister_scan_filter(int slot_id);
511 oal_status_t gattc_enable_scan_filter(int client_if);
513 oal_status_t gattc_disable_scan_filter(int client_if);
515 oal_status_t gattc_conn_param_update(bt_address_t * address, int min, int max, int latency, int timeout);
517 oal_status_t gattc_register_scan_filter(oal_ble_scan_filter_t* filter_data);
519 oal_status_t gattc_add_connection_info(bt_address_t *device_address, int conn_id, int server_inst_id);
521 oal_status_t gattc_register_service_changed_cb(bt_address_t *device_address);
523 oal_status_t gattc_unregister_service_changed_cb(bt_address_t *device_address);
525 oal_status_t gattc_register_for_notification(int conn_id, bt_address_t * address,
526 oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id);
528 oal_status_t gattc_deregister_for_notification(int conn_id, bt_address_t * address,
529 oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id);
531 oal_status_t gatt_send_response_acquire(int conn_id, int trans_id,
532 int status, int fd, int mtu, void *);
534 oal_status_t gattc_get_att_mtu(int conn_id, int *mtu);
536 oal_status_t gattc_configure_mtu(int conn_id, int mtu);
538 oal_status_t gatt_get_data_batching_available_packets(
539 unsigned int *available_packets);
541 oal_status_t gatt_enable_data_batching(bt_address_t * address,
542 int packet_threshold, int timeout);
544 oal_status_t gatt_disable_data_batching(bt_address_t * address);
546 #endif /* OAL_GATT_H_ */