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_t;
55 /** GATT value type used in response to remote read requests */
57 uint8_t value[OAL_GATT_MAX_ATTR_LEN];
64 /** GATT remote read request response type */
66 oal_gatt_value_t attr_value;
68 } oal_gatt_response_t;
74 uint8_t include_txpower;
76 char* manufacturer_data;
77 uint16_t manufacturer_data_len;
79 uint16_t service_data_len;
81 uint16_t service_uuid_len;
83 uint16_t solicit_uuid_len;
84 uint16_t min_interval;
85 uint16_t max_interval;
90 } oal_ble_multi_adv_param_setup_t;
95 bt_address_t* device_address;
97 oal_uuid_t* service_uuid;
99 oal_uuid_t* service_uuid_mask;
100 int service_uuid_mask_len;
101 oal_uuid_t* service_solicitation_uuid;
102 int service_solicitation_uuid_len;
103 oal_uuid_t* service_solicitation_uuid_mask;
104 int service_solicitation_uuid_mask_len;
105 uint8_t* service_data;
106 int service_data_len;
107 uint8_t* service_data_mask;
108 int service_data_mask_len;
110 uint8_t* manufacturer_data;
111 int manufacturer_data_len;
112 uint8_t* manufacturer_data_mask;
113 int manufacturer_data_mask_len;
114 } oal_ble_scan_filter_t;
117 int list_logic_type; // list_logic_type (OR - 0x00, AND - 0x01)
118 int filt_logic_type; // filt_logic_type (OR - 0x00, AND - 0x01)
121 int dely_mode; // dely_mode (Immediate - 0x00, on found - 0x01, batched - 0x02)
124 int found_timeout_cnt;
125 } oal_ble_scan_filter_param_setup_t;
128 * @brief Enable Bluetooth Low Energy GATT Feature
130 * @remarks Application will be able to advertise and scan other Low Energy devices.
132 * @return OAL_STATUS_SUCCESS on success, otherwise non-zero error value.
133 * @retval #OAL_STATUS_SUCCESS Successful
135 * @pre OAL API must be initialized with oal_bt_init().
137 * @see gatt_disable()
139 oal_status_t gatt_enable(void);
142 * @brief Disable Bluetooth Low Energy GATT Feature
144 * @remarks Application will not be able to advertise or scan other Low Energy devices.
146 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
147 * @retval #OAL_STATUS_SUCCESS Successful
149 * @pre OAL API should be enabled with gatt_enable().
153 oal_status_t gatt_disable(void);
156 * @brief Register the GATT Server
158 * @remarks Application will register the GATT Server
160 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
161 * @retval #OAL_STATUS_SUCCESS Successful
163 * @pre OAl API should be enabled with gatt_enable().
167 oal_status_t gatts_register(oal_uuid_t* server_uuid);
170 * @brief UnRegister the GATT Server
172 * @remarks Application will unregister the GATT Server
174 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
175 * @retval #OAL_STATUS_SUCCESS Successful
177 * @pre OAl API should be enabled with gatti_enable().
179 * @see gatts_register()
181 oal_status_t gatts_unregister(int instance_id);
184 * @brief Start BLE Advertising feature
186 * @remarks Application will start advertising and behave as a peripheral device
188 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
189 * @retval #OAL_STATUS_SUCCESS Successful
191 * @pre OAl API should be enabled with gatt_enable().
195 oal_status_t gatts_start_listen(int instance_id, gboolean enable);
198 * @brief Stop BLE Advertising feature
200 * @remarks Application will stop advertising and will no longer behave as a peripheral device.
202 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
203 * @retval #OAL_STATUS_SUCCESS Successful
205 * @pre Advertising should have been started with gatts_start_advertising().
207 * @see gatts_start_listen()
209 oal_status_t gatts_stop_advertising(int instance_id);
212 * @brief Enables the Bluetooth Low Energy Multiple advertisement feature
214 * @remarks The application will be able to do multiple advertising
216 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
217 * @retval #OAL_STATUS_SUCCESS Successful
219 * @pre OAL API must be initialized with oal_bt_init().
221 * @see gatts_multi_adv_disable()
223 oal_status_t gatts_multi_adv_enable(int instance_id);
226 * @brief Disables the Bluetooth Low Energy Multiple advertisement feature
228 * @remarks The application will not be able to do multiple advertising
230 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
231 * @retval #OAL_STATUS_SUCCESS Successful
233 * @pre OAL API must be initialized with oal_bt_init().
235 * @see gatts_multi_adv_enable()
237 oal_status_t gatts_multi_adv_disable(int instance_id);
240 * @brief Updates the parameters to configure the Multiple Advertising Features
242 * @remarks The parameters like min and max interval, advertising type,
243 * channel map, tx power and timeout will be updated.
245 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
246 * @retval #OAL_STATUS_SUCCESS Successful
248 * @pre OAL API should be enabled with gatts_multi_adv_enable().
250 * @see gatts_multi_adv_enable()
252 oal_status_t gatts_multi_adv_update(int instance_id, int min_intv, int max_intv,
253 int adv_type, int chnl_map,
254 int tx_power, int timeout_s);
257 * @brief sets the filter policy for a particular advertiser in HAL layer.
259 oal_status_t gatts_set_filter_policy(int filter_policy);
262 * @brief Sets the the Multiple Advertising Data
264 * @remarks The Multiple advertising data will be set.
266 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
267 * @retval #OAL_STATUS_SUCCESS Successful
269 * @pre OAL API should be enabled with gatts_multi_adv_enable().
271 * @see gatts_multi_adv_enable()
273 oal_status_t gatts_multi_adv_set_inst_data(int instance_id,
274 oal_ble_multi_adv_param_setup_t *adv_param_setup);
277 * @brief Get current ATT MTU size of the connection
279 * @remarks The application will get current ATT MTU size of the connection
281 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
282 * @retval #OAL_STATUS_SUCCESS>-Successful
284 * @pre OAL API must be initialized with oal_bt_init().
286 * @param conn_id: active connection id (input)
287 * mtu: att mtu size of the connection (output)
289 * @see gatts_multi_adv_enable()
291 oal_status_t gatts_get_att_mtu(int conn_id, int *mtu);
294 * @brief GATT Server Add Service
296 * @remarks GATT Server will add new service in gatt server database.
298 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
299 * @retval #OAL_STATUS_SUCCESS Successful
301 * @pre Advertising should have been started with gatts_start_advertising().
303 * @see gatts_start_advertising()
305 oal_status_t gatts_add_service(int instance_id, oal_gatt_srvc_id_t *gatt_serv_id, int num_handles);
308 * @brief GATT Server Add Included Service
310 * @remarks GATT Server will add new included service in gatt server database.
312 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
313 * @retval #OAL_STATUS_SUCCESS Successful
315 * @pre Primary service should have been added with gatts_add_service().
317 * @see gatts_add_service()
319 oal_status_t gatts_add_included_services(int instance_id, int srv_handle, int incld_handle);
322 * @brief GATT Server Add Charactertistic
324 * @remarks GATT Server will add new Charactertistic in gatt server database.
326 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
327 * @retval #OAL_STATUS_SUCCESS Successful
329 * @pre Primary service should have been added with gatts_add_service().
331 * @see gatts_add_service()
333 oal_status_t gatts_add_characteristics(int instance_id, int srv_handle, oal_uuid_t* charc_uuid, int propts, int permsn);
336 * @brief GATT Server Add Descriptor
338 * @remarks GATT Server will add new Descriptor in gatt server database.
340 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
341 * @retval #OAL_STATUS_SUCCESS Successful
343 * @pre Primary service should have been added with gatts_add_service().
345 * @see gatts_add_service()
347 oal_status_t gatts_add_descriptor(int instance_id, int srv_handle, oal_uuid_t* desc_uuid, int permsn);
350 * @brief GATT Server make ready the new service for advertiment
352 * @remarks GATT Server will enable the new service for advertiment.
354 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
355 * @retval #OAL_STATUS_SUCCESS Successful
357 * @pre Primary service should have been added with gatts_add_service().
359 * @see gatts_add_service()
361 oal_status_t gatts_start_service(int innstance_id, int svc_handle, int transport);
364 * @brief GATT Server Stop the added service from advertiment
366 * @remarks GATT Server will Stop the added service from advertiment .
368 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
369 * @retval #OAL_STATUS_SUCCESS Successful
371 * @pre Primary service should have been started with gatts_start_service().
373 * @see gatts_start_service()
375 oal_status_t gatts_stop_service(int instance_id, int svc_hdl);
378 * @brief GATT Server delete the already added service
380 * @remarks GATT Server will delete the already added service in gatt server database.
382 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
383 * @retval #OAL_STATUS_SUCCESS Successful
385 * @pre Primary service should have been added with gatts_add_service().
387 * @see gatts_add_service()
389 oal_status_t gatts_delete_service(int instance_id, int svc_handle);
392 * @brief GATT Server send the indication for change in attribute value
394 * @remarks GATT Server will send the indication to client for change in attribute value .
396 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
397 * @retval #OAL_STATUS_SUCCESS Successful
399 * @pre A Client should be connected to this server.
401 * @see gatts_connect()
403 oal_status_t gatts_send_indication(int ins_id, int attr_hndl, int conn_id, int len, int confirm, char* value);
406 * @brief GATT Server Update value of the attribute associated with a GATT server instance
408 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
409 * @retval #OAL_STATUS_SUCCESS Successful
411 oal_status_t gatts_update_att_value(int ins_id, oal_gatt_value_t *value);
414 * @brief GATT Server send the response for attribute value
416 * @remarks GATT Server will send the response for attribute value asked from client .
418 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
419 * @retval #OAL_STATUS_SUCCESS Successful
421 * @pre A Client should be connected to this server.
423 * @see gatts_connect()
425 oal_status_t gatts_send_response(int conn_id, int trans_id, int resp_status, oal_gatt_response_t *response);
427 oal_status_t gatts_disconnect(int Ins_id, bt_address_t *device_address, int conId);
430 * @brief Start LE Device discovery
432 * @remarks BLE discovery will be started
434 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
435 * @retval #OAL_STATUS_SUCCESS Successful
437 * @pre OAL API should be enabled with gatt_enable().
441 oal_status_t gattc_start_le_discovery(int client_id);
443 * @brief Stop LE Device discovery
445 * @remarks BLE discovery will be stopped
447 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
448 * @retval #OAL_STATUS_SUCCESS Successful
450 * @pre BLE Discovery should be started using the gattc_start_le_discovery().
452 * @see gattc_start_le_discovery()
454 oal_status_t gattc_stop_le_discovery(int client_id);
457 * @brief Set scan parameters
459 * @remarks scan parameters will be set
461 * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
462 * @retval #OAL_STATUS_SUCCESS Successful
465 oal_status_t gattc_set_le_scan_param(int scan_type, int itv, int win);
467 /** Registers a GATT client application with the stack */
468 oal_status_t gattc_register(oal_uuid_t* client_uuid);
470 oal_status_t gattc_deregister(int client_id);
472 /** Create a connection to a remote LE or dual-mode device */
473 oal_status_t gattc_connect(int client_id, bt_address_t *device_address, int isDirect);
475 oal_status_t gattc_search_service(int conn_id, oal_uuid_t *service_uuid);
477 oal_status_t gattc_get_characteristic(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id);
479 oal_status_t gattc_get_descriptor(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id,
480 oal_gatt_id_t *desc_id);
482 oal_status_t gattc_read_characteristic(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id,
483 oal_gatt_auth_req_t auth_req);
485 oal_status_t gattc_read_descriptor(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id,
486 oal_gatt_id_t *desc_id, oal_gatt_auth_req_t auth_req);
487 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,
488 int len, oal_gatt_auth_req_t auth_req, char* data);
490 oal_status_t gattc_acquire_notify(int conn_id, oal_gatt_srvc_id_t *srvc_id,
491 oal_gatt_id_t *char_id, int *fd, int *mtu);
493 oal_status_t gattc_acquire_write(int conn_id, oal_gatt_srvc_id_t *srvc_id,
494 oal_gatt_id_t *char_id, oal_gatt_auth_req_t auth_req , int *fd, int*mtu);
496 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,
497 oal_gatt_write_type_t write_type, int len, oal_gatt_auth_req_t auth_req, char* data);
499 oal_status_t gattc_disconnect(int client_id, bt_address_t *device_address, int conn_id);
501 oal_status_t gattc_unregister_scan_filter(int slot_id);
503 oal_status_t gattc_enable_scan_filter(int client_if);
505 oal_status_t gattc_disable_scan_filter(int client_if);
507 oal_status_t gattc_conn_param_update(bt_address_t * address, int min, int max, int latency, int timeout);
509 oal_status_t gattc_register_scan_filter(oal_ble_scan_filter_t* filter_data);
511 oal_status_t gattc_register_for_notification(int client_id, bt_address_t * address,
512 oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id);
514 oal_status_t gattc_deregister_for_notification(int client_id, bt_address_t * address,
515 oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id);
517 oal_status_t gatt_send_response_acquire(int conn_id, int trans_id,
518 int status, int fd, int mtu, void *);
520 #endif /* OAL_GATT_H_ */