4 * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Anupam Roy <anupam.r@samsung.com>
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.
23 /*******************************************************************************
25 * Description: GATT Profile Bluetooth Interface
27 *******************************************************************************/
29 #include <hardware/bluetooth.h>
30 #include <hardware/bt_gatt.h>
38 #include "bt-hal-log.h"
39 #include "bt-hal-msg.h"
40 #include "bt-hal-utils.h"
42 #include "bt-hal-adapter-le.h"
43 #include "bt-hal-gatt-server.h"
44 #include "bt-hal-gatt-client.h"
45 #include "bt_gatt_types.h"
47 /* Advertising report event types */
48 #define BT_LE_ADV_IND 0x00
49 #define BT_LE_ADV_DIRECT_IND 0x01
50 #define BT_LE_ADV_SCAN_IND 0x02
51 #define BT_LE_ADV_NONCONN_IND 0x03
52 #define BT_LE_ADV_SCAN_RSP 0x04
54 #define BT_HAL_ADV_DATA_MAX_SIZE 31
55 #define BT_HAL_GATTC_READ_VALUE_TYPE_VALUE 0x0000 /* Attribute value itself */
62 uint8_t data[BT_HAL_ADV_DATA_MAX_SIZE * 2];
64 } bt_hal_le_adv_info_t;
66 /****************************************** Global Variables ******************************************/
67 const btgatt_callbacks_t *bt_gatt_callbacks = NULL;
69 extern btgatt_client_interface_t btgatt_client_interface;
70 extern btgatt_server_interface_t btgatt_server_interface;
72 static GSList *adv_ind_list = NULL;
73 /****************************************** Forward Declarations *************************************/
74 static void __bt_handle_gatt_client_registered(void *buf, uint16_t len);
75 static void __bt_hal_handle_gatt_client_scan_result(void *buf, uint16_t len);
76 static void __bt_handle_gatt_client_connected(void *buf, uint16_t len);
77 static void __bt_handle_gatt_client_disconnected(void *buf, uint16_t len);
78 static void __bt_handle_gatt_client_search_result(void *buf, uint16_t len);
79 static void __bt_handle_gatt_client_search_complete(void *buf, uint16_t len);
80 static void __bt_handle_gatt_client_search_char_result(void *buf, uint16_t len);
81 static void __bt_handle_gatt_client_search_desc_result(void *buf, uint16_t len);
82 static void __bt_handle_gatt_client_read_charac(void *buf, uint16_t len);
83 static void __bt_handle_gatt_client_read_desc(void *buf, uint16_t len);
84 static void __bt_handle_gatt_client_write_char(void *buf, uint16_t len);
85 static void __bt_handle_gatt_client_write_desc(void *buf, uint16_t len);
86 /*****************************************************************************************************/
88 static bool interface_ready(void)
90 return bt_gatt_callbacks != NULL;
93 static void __bt_hal_handle_server_instance_initialized(void *buf, uint16_t len)
95 struct hal_ev_server_instance_registered *ev = buf;
97 if (bt_gatt_callbacks->server->register_server_cb)
98 bt_gatt_callbacks->server->register_server_cb(ev->status, ev->server_instance, (bt_uuid_t*)&ev->app_uuid);
101 static void __bt_hal_handle_multi_adv_data_set(void *buf, uint16_t len)
103 struct hal_ev_multi_adv_data_set *ev = buf;
105 if (bt_gatt_callbacks->server->multi_adv_data_cb)
106 bt_gatt_callbacks->server->multi_adv_data_cb(ev->server_instance, ev->status);
109 static void __bt_hal_handle_multi_adv_data_update(void *buf, uint16_t len)
111 struct hal_ev_multi_adv_update *ev = buf;
113 if (bt_gatt_callbacks->server->multi_adv_update_cb)
114 bt_gatt_callbacks->server->multi_adv_update_cb(ev->server_instance, ev->status);
117 static void __bt_hal_handle_multi_adv_enable(void *buf, uint16_t len)
119 struct hal_ev_multi_adv_enable *ev = buf;
121 if (bt_gatt_callbacks->server->multi_adv_enable_cb)
122 bt_gatt_callbacks->server->multi_adv_enable_cb(ev->server_instance, ev->status);
125 static void __bt_hal_handle_multi_adv_disable(void *buf, uint16_t len)
127 struct hal_ev_multi_adv_disable *ev = buf;
129 if (bt_gatt_callbacks->server->multi_adv_disable_cb)
130 bt_gatt_callbacks->server->multi_adv_disable_cb(ev->server_instance, ev->status);
133 /* Same callback for both Enable and DIsable */
134 static void __bt_hal_handle_legacy_adv_status(void *buf, uint16_t len)
136 struct hal_ev_legacy_adv_status *ev = buf;
138 if (bt_gatt_callbacks->server->listen_cb)
139 bt_gatt_callbacks->server->listen_cb(ev->status, ev->server_instance);
142 static void __bt_hal_handle_service_added(void *buf, uint16_t len)
144 struct hal_ev_gatt_service_added *ev = buf;
145 btgatt_srvc_id_t srvc_id;
147 memset(&srvc_id, 0x00, sizeof(btgatt_srvc_id_t));
148 srvc_id.is_primary = ev->is_primary;
149 srvc_id.id.inst_id = ev->server_instance;
150 memcpy(srvc_id.id.uuid.uu, ev->svc_uuid, sizeof(ev->svc_uuid));
152 if (bt_gatt_callbacks->server->service_added_cb)
153 bt_gatt_callbacks->server->service_added_cb(ev->status, ev->server_instance,
154 &srvc_id, ev->service_handle);
157 static void __bt_hal_handle_char_added(void *buf, uint16_t len)
159 struct hal_ev_gatt_char_added *ev = buf;
162 memcpy(uuid.uu, ev->char_uuid, sizeof(ev->char_uuid));
164 if (bt_gatt_callbacks->server->characteristic_added_cb)
165 bt_gatt_callbacks->server->characteristic_added_cb(ev->status, ev->server_instance,
166 &uuid, ev->service_handle, ev->char_handle);
169 static void __bt_hal_handle_desc_added(void *buf, uint16_t len)
171 struct hal_ev_gatt_desc_added *ev = buf;
174 memcpy(uuid.uu, ev->desc_uuid, sizeof(ev->desc_uuid));
176 if (bt_gatt_callbacks->server->descriptor_added_cb)
177 bt_gatt_callbacks->server->descriptor_added_cb(ev->status, ev->server_instance,
178 &uuid, ev->service_handle, ev->desc_handle);
181 static void __bt_hal_handle_service_started(void *buf, uint16_t len)
183 struct hal_ev_gatt_service_started *ev = buf;
185 if (bt_gatt_callbacks->server->service_started_cb)
186 bt_gatt_callbacks->server->service_started_cb(ev->status, ev->server_instance,
190 static void __bt_hal_handle_service_deleted(void *buf, uint16_t len)
192 struct hal_ev_gatt_service_deleted *ev = buf;
194 if (bt_gatt_callbacks->server->service_deleted_cb)
195 bt_gatt_callbacks->server->service_deleted_cb(ev->status, ev->server_instance,
199 static void __bt_hal_handle_gatt_server_connected(void *buf, uint16_t len)
201 struct hal_ev_gatt_server_connected *ev = buf;
204 memcpy(bd_addr.address, ev->bdaddr, 6);
206 if (bt_gatt_callbacks->server->connection_cb)
207 bt_gatt_callbacks->server->connection_cb(ev->conn_id, ev->server_instance,
208 ev->connected, &bd_addr);
211 static void __bt_hal_handle_gatt_server_read_requested(void *buf, uint16_t len)
213 struct hal_ev_gatt_server_read_req *ev = buf;
216 memcpy(bd_addr.address, ev->bdaddr, 6);
218 if (bt_gatt_callbacks->server->request_read_cb)
219 bt_gatt_callbacks->server->request_read_cb(ev->conn_id, ev->trans_id, &bd_addr,
220 ev->att_handle, ev->offset, ev->is_long);
223 static void __bt_hal_handle_gatt_server_write_requested(void *buf, uint16_t len)
225 struct hal_ev_gatt_server_write_req *ev = buf;
227 if (bt_gatt_callbacks->server->request_write_cb)
228 bt_gatt_callbacks->server->request_write_cb(ev->conn_id, ev->trans_id,
229 (bt_bdaddr_t *) ev->bdaddr,
230 ev->att_handle, ev->offset,
231 ev->length, ev->need_rsp,
232 ev->is_prep, ev->value);
235 static void __bt_hal_handle_gatt_server_indicate_confirmed(void *buf, uint16_t len)
237 struct hal_ev_gatt_server_indicate_cfm *ev = buf;
240 if (bt_gatt_callbacks->server->indication_confirmation_cb)
241 bt_gatt_callbacks->server->indication_confirmation_cb(ev->conn_id, ev->trans_id,
242 ev->att_handle, (bt_bdaddr_t *) ev->bdaddr);
246 static void __bt_hal_gatt_events(int message, void *buf, uint16_t len)
249 /* Check if GATT interface is Ready */
250 if (!interface_ready())
254 case HAL_EV_SERVER_INSTANCE_INITIALIZED: {
255 __bt_hal_handle_server_instance_initialized(buf, len);
258 case HAL_EV_MULTI_ADV_ENABLE: {
259 __bt_hal_handle_multi_adv_enable(buf, len);
262 case HAL_EV_MULTI_ADV_DISABLE: {
263 __bt_hal_handle_multi_adv_disable(buf, len);
266 case HAL_EV_MULTI_ADV_DATA_SET: {
267 __bt_hal_handle_multi_adv_data_set(buf, len);
270 case HAL_EV_MULTI_ADV_UPDATE: {
271 __bt_hal_handle_multi_adv_data_update(buf, len);
274 case HAL_EV_LEGACY_ADV_ENABLE: {
275 __bt_hal_handle_legacy_adv_status(buf, len);
278 case HAL_EV_GATT_CLIENT_REGISTERED: {
279 __bt_handle_gatt_client_registered(buf, len);
282 case HAL_EV_GATT_CLIENT_SCAN_RESULT: {
283 __bt_hal_handle_gatt_client_scan_result(buf, len);
286 case HAL_EV_GATT_SERVICE_ADDED: {
287 __bt_hal_handle_service_added(buf, len);
290 case HAL_EV_GATT_CHAR_ADDED: {
291 __bt_hal_handle_char_added(buf, len);
294 case HAL_EV_GATT_DESC_ADDED: {
295 __bt_hal_handle_desc_added(buf, len);
298 case HAL_EV_GATT_SERVICE_STARTED: {
299 __bt_hal_handle_service_started(buf, len);
302 case HAL_EV_GATT_SERVICE_DELETED: {
303 __bt_hal_handle_service_deleted(buf, len);
306 case HAL_EV_GATT_SERVER_CONNECTED: {
307 __bt_hal_handle_gatt_server_connected(buf, len);
310 case HAL_EV_GATT_READ_REQUESTED: {
311 __bt_hal_handle_gatt_server_read_requested(buf, len);
314 case HAL_EV_GATT_WRITE_REQUESTED: {
315 __bt_hal_handle_gatt_server_write_requested(buf, len);
318 case HAL_EV_GATT_INDICATE_CFM: {
319 __bt_hal_handle_gatt_server_indicate_confirmed(buf, len);
322 case HAL_EV_GATT_CLIENT_CONNECTED: {
323 __bt_handle_gatt_client_connected(buf, len);
326 case HAL_EV_GATT_CLIENT_DISCONNECTED: {
327 __bt_handle_gatt_client_disconnected(buf, len);
330 case HAL_EV_GATT_CLIENT_SEARCH_RESULT: {
331 __bt_handle_gatt_client_search_result(buf, len);
334 case HAL_EV_GATT_CLIENT_SEARCH_COMPLETE: {
335 __bt_handle_gatt_client_search_complete(buf, len);
338 case HAL_EV_GATT_CLIENT_CHARAC_SEARCH_RESULT: {
339 __bt_handle_gatt_client_search_char_result(buf, len);
342 case HAL_EV_GATT_CLIENT_DESC_SEARCH_RESULT: {
343 __bt_handle_gatt_client_search_desc_result(buf, len);
346 case HAL_EV_GATT_CLIENT_READ_CHARAC: {
347 __bt_handle_gatt_client_read_charac(buf, len);
350 case HAL_EV_GATT_CLIENT_READ_DESC: {
351 __bt_handle_gatt_client_read_desc(buf, len);
354 case HAL_EV_GATT_CLIENT_WRITE_CHARAC: {
355 __bt_handle_gatt_client_write_char(buf, len);
358 case HAL_EV_GATT_CLIENT_WRITE_DESC: {
359 __bt_handle_gatt_client_write_desc(buf, len);
363 DBG("Event Currently not handled!!");
369 /************************************* GATT CLIENT EVENTS ****************************************/
370 static void __bt_handle_gatt_client_registered(void *buf, uint16_t len)
372 struct hal_ev_gatt_client_registered *ev = buf;
375 memcpy(uuid.uu, ev->app_uuid, 16);
376 if (bt_gatt_callbacks->client->register_client_cb)
377 bt_gatt_callbacks->client->register_client_cb(
378 ev->status, ev->client_if, &uuid);
381 static void __bt_hal_send_le_scan_result_event(bt_hal_le_adv_info_t *adv_info)
385 str2bt_bdaddr_t(adv_info->addr, &bd_addr);
386 if (bt_gatt_callbacks->client->scan_result_cb)
387 bt_gatt_callbacks->client->scan_result_cb(
388 &bd_addr, adv_info->rssi, adv_info->data);
391 static void __bt_handle_gatt_client_connected(void *buf, uint16_t len)
393 struct hal_ev_gatt_client_connected *ev = buf;
396 memcpy(bd_addr.address, ev->bdaddr, 6);
397 if (bt_gatt_callbacks->client->open_cb)
398 bt_gatt_callbacks->client->open_cb(ev->conn_id,
399 ev->status, ev->client_if, &bd_addr);
402 static void __bt_handle_gatt_client_disconnected(void *buf, uint16_t len)
404 struct hal_ev_gatt_client_connected *ev = buf;
407 memcpy(bd_addr.address, ev->bdaddr, 6);
408 if (bt_gatt_callbacks->client->close_cb)
409 bt_gatt_callbacks->client->close_cb(ev->conn_id,
410 ev->status, ev->client_if, &bd_addr);
413 static void __bt_handle_gatt_client_search_result(void *buf, uint16_t len)
415 struct hal_ev_gatt_client_search_result *ev = buf;
416 btgatt_srvc_id_t gatt_srvc_id;
418 gatt_srvc_id.is_primary = ev->is_primary;
419 gatt_srvc_id.id.inst_id = ev->inst_id;
420 memcpy(gatt_srvc_id.id.uuid.uu, ev->uuid, 16);
422 if (bt_gatt_callbacks->client->search_result_cb)
423 bt_gatt_callbacks->client->search_result_cb(ev->conn_id,
427 static void __bt_handle_gatt_client_search_complete(void *buf, uint16_t len)
429 struct hal_ev_gatt_client_search_complete *ev = buf;
431 if (bt_gatt_callbacks->client->search_complete_cb)
432 bt_gatt_callbacks->client->search_complete_cb(ev->conn_id,
436 static void __bt_handle_gatt_client_search_char_result(void *buf, uint16_t len)
438 struct hal_ev_gatt_client_char_search_result *ev = buf;
439 btgatt_srvc_id_t gatt_srvc_id;
440 btgatt_gatt_id_t gatt_char_id;
442 gatt_srvc_id.is_primary = ev->is_primary;
443 gatt_srvc_id.id.inst_id = ev->inst_id;
444 memcpy(gatt_srvc_id.id.uuid.uu, ev->svc_uuid, 16);
446 if (BT_STATUS_SUCCESS == ev->status) {
447 memcpy(gatt_char_id.uuid.uu, ev->char_uuid, 16);
448 gatt_char_id.inst_id = ev->inst_id;
451 if (bt_gatt_callbacks->client->get_characteristic_cb)
452 bt_gatt_callbacks->client->get_characteristic_cb(ev->conn_id,
453 ev->status, &gatt_srvc_id, &gatt_char_id, ev->char_prop);
456 static void __bt_handle_gatt_client_search_desc_result(void *buf, uint16_t len)
458 struct hal_ev_gatt_client_desc_search_result *ev = buf;
459 btgatt_srvc_id_t gatt_srvc_id;
460 btgatt_gatt_id_t gatt_char_id;
461 btgatt_gatt_id_t gatt_desc_id;
464 gatt_srvc_id.is_primary = ev->is_primary;
465 gatt_srvc_id.id.inst_id = ev->inst_id;
466 memcpy(gatt_srvc_id.id.uuid.uu, ev->svc_uuid, 16);
468 memcpy(gatt_char_id.uuid.uu, ev->char_uuid, 16);
469 gatt_char_id.inst_id = ev->inst_id;
471 if (BT_STATUS_SUCCESS == ev->status) {
472 memcpy(gatt_desc_id.uuid.uu, ev->desc_uuid, 16);
473 gatt_desc_id.inst_id = ev->inst_id;
476 if (bt_gatt_callbacks->client->get_descriptor_cb)
477 bt_gatt_callbacks->client->get_descriptor_cb(ev->conn_id,
478 ev->status, &gatt_srvc_id, &gatt_char_id, &gatt_desc_id);
481 static void __bt_handle_gatt_client_read_charac(void *buf, uint16_t len)
483 struct hal_ev_gatt_client_read_data *ev = buf;
484 btgatt_read_params_t char_read_parm;
486 char_read_parm.srvc_id.is_primary = ev->is_primary;
487 char_read_parm.srvc_id.id.inst_id = ev->inst_id;
488 memcpy(char_read_parm.srvc_id.id.uuid.uu, ev->svc_uuid, 16);
490 char_read_parm.char_id.inst_id = ev->inst_id;
491 memcpy(char_read_parm.char_id.uuid.uu, ev->char_uuid, 16);
493 char_read_parm.value.len = ev->len;
495 memcpy(char_read_parm.value.value, ev->value, ev->len);
496 char_read_parm.value_type = BT_HAL_GATTC_READ_VALUE_TYPE_VALUE;
499 if (bt_gatt_callbacks->client->read_characteristic_cb)
500 bt_gatt_callbacks->client->read_characteristic_cb(ev->conn_id,
501 ev->status, &char_read_parm);
504 static void __bt_handle_gatt_client_read_desc(void *buf, uint16_t len)
506 struct hal_ev_gatt_client_read_data *ev = buf;
507 btgatt_read_params_t desc_read_parm;
509 desc_read_parm.srvc_id.is_primary = ev->is_primary;
510 desc_read_parm.srvc_id.id.inst_id = ev->inst_id;
511 memcpy(desc_read_parm.srvc_id.id.uuid.uu, ev->svc_uuid, 16);
513 desc_read_parm.char_id.inst_id = ev->inst_id;
514 memcpy(desc_read_parm.char_id.uuid.uu, ev->char_uuid, 16);
516 desc_read_parm.descr_id.inst_id = ev->inst_id;
517 memcpy(desc_read_parm.descr_id.uuid.uu, ev->desc_uuid, 16);
519 desc_read_parm.value.len = ev->len;
521 memcpy(desc_read_parm.value.value, ev->value, ev->len);
522 desc_read_parm.value_type = BT_HAL_GATTC_READ_VALUE_TYPE_VALUE;
525 if (bt_gatt_callbacks->client->read_descriptor_cb)
526 bt_gatt_callbacks->client->read_descriptor_cb(ev->conn_id,
527 ev->status, &desc_read_parm);
530 static void __bt_handle_gatt_client_write_char(void *buf, uint16_t len)
532 struct hal_ev_gatt_client_write_result *ev = buf;
533 btgatt_write_params_t char_write_parm;
535 char_write_parm.srvc_id.is_primary = ev->is_primary;
536 char_write_parm.srvc_id.id.inst_id = ev->inst_id;
537 memcpy(char_write_parm.srvc_id.id.uuid.uu, ev->svc_uuid, 16);
539 char_write_parm.char_id.inst_id = ev->inst_id;
540 memcpy(char_write_parm.char_id.uuid.uu, ev->char_uuid, 16);
542 if (bt_gatt_callbacks->client->write_characteristic_cb)
543 bt_gatt_callbacks->client->write_characteristic_cb(ev->conn_id,
544 ev->status, &char_write_parm);
547 static void __bt_handle_gatt_client_write_desc(void *buf, uint16_t len)
549 struct hal_ev_gatt_client_write_result *ev = buf;
550 btgatt_write_params_t desc_write_parm;
552 desc_write_parm.srvc_id.is_primary = ev->is_primary;
553 desc_write_parm.srvc_id.id.inst_id = ev->inst_id;
554 memcpy(desc_write_parm.srvc_id.id.uuid.uu, ev->svc_uuid, 16);
556 desc_write_parm.char_id.inst_id = ev->inst_id;
557 memcpy(desc_write_parm.char_id.uuid.uu, ev->char_uuid, 16);
559 desc_write_parm.descr_id.inst_id = ev->inst_id;
560 memcpy(desc_write_parm.descr_id.uuid.uu, ev->desc_uuid, 16);
562 if (bt_gatt_callbacks->client->write_descriptor_cb)
563 bt_gatt_callbacks->client->write_descriptor_cb(ev->conn_id,
564 ev->status, &desc_write_parm);
567 static bt_hal_le_adv_info_t *__bt_hal_get_adv_ind_info(char *addr)
574 for (l = adv_ind_list; NULL != l; l = g_slist_next(l)) {
575 bt_hal_le_adv_info_t *adv_info = l->data;
580 if (!g_strcmp0(adv_info->addr, addr))
587 static int __bt_hal_add_adv_ind_info(bt_hal_le_adv_info_t *adv_info)
592 if (__bt_hal_get_adv_ind_info(adv_info->addr) != NULL) {
593 DBG("Adv info already present");
597 adv_ind_list = g_slist_append(adv_ind_list, adv_info);
601 static gboolean __bt_hal_adv_scan_req_timeout_cb(gpointer user_data)
603 bt_hal_le_adv_info_t *adv_info = user_data;
605 __bt_hal_send_le_scan_result_event(adv_info);
606 adv_ind_list = g_slist_remove(adv_ind_list, adv_info);
611 static void __bt_hal_handle_gatt_client_scan_result(void *buf, uint16_t len)
615 struct hal_ev_gatt_client_scan_result *ev = buf;
616 bt_hal_le_adv_info_t *adv_info;
619 memcpy(bd_addr.address, ev->bd_addr, 6);
620 bt_bdaddr_t2str(&bd_addr, address);
621 data_len = (ev->len < BT_HAL_ADV_DATA_MAX_SIZE) ? ev->len : BT_HAL_ADV_DATA_MAX_SIZE;
622 if (data_len == 0 && ev->adv_type != BT_LE_ADV_SCAN_RSP) {
623 ERR("Unexpected: Data len is 0");
627 if (ev->adv_type == BT_LE_ADV_SCAN_RSP) { /* SCAN_RSP */
628 adv_info = __bt_hal_get_adv_ind_info(address);
630 /* Copy scan response data in data field and send event */
631 memcpy(&(adv_info->data[adv_info->data_len]), ev->adv_data, data_len);
632 __bt_hal_send_le_scan_result_event(adv_info);
633 adv_ind_list = g_slist_remove(adv_ind_list, adv_info);
634 if (adv_info->timer_id)
635 g_source_remove(adv_info->timer_id);
642 adv_info = g_malloc0(sizeof(bt_hal_le_adv_info_t));
644 ERR("Not enough memory");
648 g_strlcpy(adv_info->addr, address, 18);
649 adv_info->addr_type = ev->addr_type;
650 adv_info->adv_type = ev->adv_type;
651 adv_info->rssi = ev->rssi;
652 adv_info->data_len = data_len;
653 memcpy(adv_info->data, ev->adv_data, data_len);
656 if (_bt_hal_gatt_client_get_le_scan_type() == BT_GATTC_LE_SCAN_TYPE_PASSIVE) {
657 __bt_hal_send_le_scan_result_event(adv_info);
662 if (__bt_hal_add_adv_ind_info(adv_info))
663 adv_info->timer_id = g_timeout_add(1000,
664 __bt_hal_adv_scan_req_timeout_cb,
668 /*******************************************************************************
670 ** Function gatt_init
672 ** Description Initializes the GATT interface
674 ** Returns bt_status_t
676 *******************************************************************************/
677 static bt_status_t gatt_init(const btgatt_callbacks_t* callbacks)
679 bt_gatt_callbacks = callbacks;
680 DBG("Register A2DP Src events callback function");
681 _bt_hal_register_gatt_le_dbus_handler_cb(__bt_hal_gatt_events);
682 _bt_hal_register_gatt_server_handler_cb(__bt_hal_gatt_events);
683 _bt_hal_register_gatt_client_handler_cb(__bt_hal_gatt_events);
684 _bt_hal_register_event_handler_cb(HAL_GATT, __bt_hal_gatt_events);
686 return BT_STATUS_SUCCESS;
689 /*******************************************************************************
691 ** Function gatt_cleanup
693 ** Description Closes the GATT interface
697 *******************************************************************************/
698 static void gatt_cleanup(void)
700 _bt_hal_unregister_gatt_le_dbus_handler_cb();
701 _bt_hal_unregister_gatt_client_handler_cb();
702 _bt_hal_unregister_gatt_server_handler_cb();
703 _bt_hal_unregister_event_handler_cb(HAL_GATT);
705 if (bt_gatt_callbacks)
706 bt_gatt_callbacks = NULL;
709 static const btgatt_interface_t btgatt_interface = {
710 sizeof(btgatt_interface),
715 &btgatt_client_interface,
716 &btgatt_server_interface,
719 /*******************************************************************************
721 ** Function bt_get_gatt_interface
723 ** Description Get the gatt callback interface
725 ** Returns btgatt_interface_t
727 *******************************************************************************/
728 const btgatt_interface_t *bt_get_gatt_interface()
730 return &btgatt_interface;