4 * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
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 #include "bt-service-common.h"
24 #include "bt-service-core-adapter.h"
25 #include "bt-service-event-receiver.h"
26 #include "bt-request-handler.h"
27 #include "bluetooth-api.h"
29 #include "bluetooth-api.h"
30 #include "bt-internal-types.h"
31 #include "bt-service-util.h"
32 #include "bt-service-common.h"
33 #include "bt-service-event.h"
35 #include "bt-internal-types.h"
36 #include "bt-service-gatt.h"
37 #include "bt-service-gatt.h"
38 #include "bt-service-core-device.h"
39 #include "bt-service-core-adapter-le.h"
40 #ifdef TIZEN_GATT_CLIENT
41 #include "bluetooth-gatt-client-api.h"
44 #include <oal-hardware.h>
45 #include <oal-manager.h>
46 #include <oal-event.h>
47 #include <oal-adapter-mgr.h>
48 #include <oal-device-mgr.h>
51 #define BT_GATT_TRANSPORT_LE 0
52 #define BT_GATT_TRANSPORT_BR_EDR 1
53 #define BT_GATT_TRANSPORT_LE_BR_EDR 2
54 #define BT_UUID_STRING_MAX 64
55 #define BT_SENDER_MAX_LENGTH 50
56 #define MAX_APPS_SUPPORTED 11 /* Slot 0 is not used */
57 #define BT_DEFAULT_ATT_MTU 23
59 #ifdef TIZEN_GATT_CLIENT
66 #define UUID_MAX_LEN 50
69 #define BDADDR_ANY (&(bluetooth_device_address_t) {{0, 0, 0, 0, 0, 0} })
71 #ifdef TIZEN_GATT_CLIENT
72 char uuid_list[NUM_UUID][BT_UUID_STRING_MAX] = {"0000b00b-0000-0000-f065-080080fa49b5", /* Used by BLEAPP */
73 "0000b00b-1111-1111-0123-456789ab0cd2", /* Used by BLEAPP */
74 "0000b00b-2222-1111-0123-456789ab0cd2",
75 "0000b00b-3333-1111-0123-456789ab0cd2",
76 "0000b00b-4444-1111-0123-456789ab0cd2",
77 "0000b00b-5555-1111-0123-456789ab0cd2",
78 "0000b00b-6666-1111-0123-456789ab0cd2",
79 "0000b00b-7777-1111-0123-456789ab0cd2",
80 "0000b00b-8888-1111-0123-456789ab0cd2",
81 "0000b00b-9999-1111-0123-456789ab0cd2",
82 "0000b00b-aaaa-1111-0123-456789ab0cd2",
83 "0000b00b-bbbb-1111-0123-456789ab0cd2",
84 "0000b00b-cccc-1111-0123-456789ab0cd2",
85 "0000b00b-dddd-1111-0123-456789ab0cd2",
86 "0000b00b-eeee-1111-0123-456789ab0cd2",
87 "0000b00b-ffff-1111-0123-456789ab0cd2",
88 "0000b00c-0000-1111-0123-456789ab0cd2",
89 "0000b00c-1111-1111-0123-456789ab0cd2",
90 "0000b00c-2222-1111-0123-456789ab0cd2",
91 "0000b00c-3333-1111-0123-456789ab0cd2"};
93 char uuid_list[NUM_UUID][BT_UUID_STRING_MAX] = {"0000b00b-0000-0000-f065-080080fa49b5", /* Used by BLEAPP */
94 "0000b00b-1111-1111-0123-456789ab0cd2", /* Used by BLEAPP */
95 "0000b00b-2222-1111-0123-456789ab0cd2",
96 "0000b00b-3333-1111-0123-456789ab0cd2",
97 "0000b00b-4444-1111-0123-456789ab0cd2",
98 "0000b00b-5555-1111-0123-456789ab0cd2",
99 "0000b00b-6666-1111-0123-456789ab0cd2",
100 "0000b00b-7777-1111-0123-456789ab0cd2",
101 "0000b00b-8888-1111-0123-456789ab0cd2",
102 "0000b00b-9999-1111-0123-456789ab0cd2"};
105 #ifdef TIZEN_GATT_CLIENT
106 /* Reserved GATT client Instance UUID. This is used only internally by bt-service */
107 #define DEFAULT_GATT_CLIENT_UUID "0000a00a-1111-1111-0123-456789abcdef"
109 static int gatt_default_client = -1;
112 gboolean is_registered;
113 bluetooth_device_address_t addr;
114 unsigned char svc_uuid[BLUETOOTH_UUID_HEX_MAX_LEN];
116 unsigned char char_uuid[BLUETOOTH_UUID_HEX_MAX_LEN];
118 } bt_gatt_notif_reg_info_t;
120 struct gatt_out_conn_info_t {
121 int client_id; /* This value unique identifies a GATT Client instance */
122 char *addr; /* Remote GATT Server address */
125 /* Linked List of outgoing gatt connection list
126 Note: This is valid only for local GATT client */
127 static GSList *outgoing_gatt_conn_list = NULL;
129 /* GATT Server Info(Local Client) List Structure */
130 struct gatt_server_info_t {
131 int connection_id; /* This value will uniquely identify a GATT client-server connection */
132 int client_id; /* This value unique identifies a GATT Client instance */
133 char *addr; /* Remote GATT Server address */
136 /* Linked List of connected Remote GATT Servers */
137 static GSList *gatt_server_info_list = NULL;
141 unsigned char uuid[BLUETOOTH_UUID_HEX_MAX_LEN]; /* If any service added */
142 } bt_gatt_svc_changed_info_t;
147 // bluetooth_device_address_t address; /* Remote BLE Device Address */
148 GSList *services; /* List of all services of above remote device */
149 int count; /* Number of services browsed from remote device */
150 bt_gatt_svc_changed_info_t info;
151 } bt_gatt_service_info_list_t;
154 unsigned char uuid[BLUETOOTH_UUID_HEX_MAX_LEN];
158 GSList *included_svcs;
159 gboolean is_removed; /* 0 => Service is added, 1=> removed */
160 } bt_gatt_service_info_t;
163 unsigned char uuid[BLUETOOTH_UUID_HEX_MAX_LEN];
167 unsigned char val[BLUETOOTH_GATT_ATT_DATA_LENGTH_MAX];
169 } bt_gatt_char_info_t;
172 unsigned char uuid[BLUETOOTH_UUID_HEX_MAX_LEN];
175 unsigned char val[BLUETOOTH_GATT_ATT_DATA_LENGTH_MAX];
176 } bt_gatt_descriptor_info_t;
179 unsigned char uuid[BLUETOOTH_UUID_HEX_MAX_LEN];
181 } bt_gatt_included_service_info_t;
183 static GSList *list_gatt_info = NULL;
187 /* App Information structure */
190 char sender[BT_SENDER_MAX_LENGTH];
191 char uuid[BT_UUID_STRING_MAX];
194 bluetooth_advertising_data_t adv_data; /* Will store adv data for specific slot */
196 bluetooth_scan_resp_data_t scan_rsp; /* Will store scan rsp data for specific slot */
198 gboolean is_initialized;
199 GSList *service_handles;
200 #ifdef TIZEN_GATT_CLIENT
201 int client_id; /* GATT Client instance ID */
202 bluetooth_device_address_t address; /* Remote BLE Device Address */
203 gboolean is_watcher_enabled;
205 } bt_service_app_info_t;
207 /* GATT Server Request Info Structure */
208 struct gatt_server_req_info {
209 int connection_id; /* This value will uniquely identify a GATT client-server connection */
210 int request_id; /* This is an unique transaction ID assigned against each request by stack */
211 int attribute_handle; /* GATT server attribute handle */
212 int offset; /* GATT server attribute offset on which request is invoked by GATT client */
213 bluetooth_gatt_att_request_type_e request_type; /* Read or Write request */
214 char *addr; /* Remote GATT client address */
217 /* GATT Client Info List Structure */
218 struct gatt_client_info_t {
219 int connection_id; /* This value will uniquely identify a GATT client-server connection */
220 int instance_id; /* This value unique identifies a GATT server instance */
221 char *addr; /* Remote GATT client address */
224 /* GATT Indicate confirm result */
225 struct gatt_indicate_cfm_result_info_t {
226 int result; /* Result of event */
227 char *addr; /* Remote GATT client address */
228 int att_hdl; /* Characteristic Attribute handle */
229 int completed; /* 1 if last event, otheriwse 0 */
232 /* Request Search Utility method */
233 static struct gatt_server_req_info *__bt_gatt_server_find_request_info(int request_id,
234 bluetooth_gatt_att_request_type_e req_type);
236 static int __bt_gatt_send_indication_to_all_connected_clients(bluetooth_gatt_att_data_t *data,
237 bluetooth_gatt_server_indication_params_t *param);
239 static void __bt_remove_all_service_handles(bt_service_app_info_t *app_info);
241 static void __bt_free_service_info(bt_gatt_service_info_t *service_info);
243 static int __bt_unregister_gatt_client_instance(int client_if);
245 static void __bt_service_reset_gatt_data(void);
247 #ifdef TIZEN_GATT_CLIENT
248 static void __bt_handle_client_instance_registered(event_gattc_register_t *data);
249 static void __bt_handle_client_connected(event_gattc_conn_t *event_data);
250 static void __bt_handle_client_disconnected(event_gattc_conn_t *event_data);
251 static void __bt_handle_client_service_search_completed(event_gattc_conn_status_t *event_data);
252 static void __bt_handle_client_service_search_result(event_gattc_service_result_t *event_data);
253 static void __bt_handle_client_characteristic_search_result(
254 event_gattc_characteristic_result_t *event_data);
255 static void __bt_handle_client_descriptor_search_result(event_gattc_descriptor_result_t *event_data);
256 static void __bt_handle_client_characteristic_read_data(event_gattc_read_data *event_data);
257 static void __bt_handle_client_descriptor_read_data(event_gattc_read_data *event_data);
258 static void __bt_handle_client_characteristic_write_data(event_gattc_write_data *event_data);
259 static void __bt_handle_client_descriptor_write_data(event_gattc_write_data *event_data);
260 static void __bt_hanlde_le_device_disconnection(event_dev_conn_status_t *event_data);
261 static void __bt_handle_client_notification_registered(event_gattc_regdereg_notify_t *event_data,
262 gboolean is_registered);
263 static void __bt_handle_client_notification_data(event_gattc_notify_data *event_data);
264 static void __bt_handle_client_service_changed_ind(event_gattc_service_changed_data *event_data);
265 static void __bt_handle_client_mtu_exchange_completed(event_gattc_mtu_configured_t *event_data);
268 static int __bt_unregister_gatt_server_instance(int server_instance);
271 struct gatt_mtu_info_t {
272 char *addr; /* Remote GATT Server address */
276 static GSList *gatt_mtu_info_list = NULL;
278 static struct gatt_mtu_info_t *__bt_find_mtu_gatt_device(char *address);
279 static void __bt_remove_mtu_gatt_device(char *address);
280 static void __bt_add_mtu_gatt_device(char *address);
281 static void __bt_update_mtu_gatt_device(char *address, int mtu);
283 /* Linked List of GATT requests from Remote GATT Clients */
284 static GSList *gatt_server_requests = NULL;
286 /* Linked List of connected Remote GATT clients */
287 static GSList *gatt_client_info_list = NULL;
289 /* Number of clients to be notified to */
290 static int num_indicate_clients;
292 /* List of applications */
293 static bt_service_app_info_t numapps[MAX_APPS_SUPPORTED];
295 static void __bt_gatt_handle_pending_request_info(int result,
296 int service_function, void *data, unsigned int size);
298 static void __bt_handle_server_instance_registered(event_gatts_register_t *data);
300 static void __bt_gatt_event_handler(int event_type, gpointer event_data);
307 void _bt_check_adv_app_termination(const char *name)
309 bt_service_app_info_t *app = NULL;
311 int apps[MAX_APPS_SUPPORTED] = { 0, };
313 ret_if(NULL == name);
315 memset(&apps, -1, sizeof(apps));
317 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
320 /* Search for a app which has same sender and stop adv is running */
321 if (!strncasecmp(app->sender, name, strlen(name)) && app->is_initialized == TRUE) {
322 BT_DBG("Match found, name: %s", name);
324 /* TODO 2: Need to manage app info as list, not array.
325 This loop always run for MAX count if any apps are terminated.
328 /* Save instances of all apps that need to be unregistered */
329 if (app->instance_id != -1) {
331 /* Unregister all service handles with stack */
332 __bt_remove_all_service_handles(app);
334 /* If Advertising is enabled, stop it */
335 if (app->adv_handle != 0) {
336 BT_INFO("Stop advertising on instance ID [%d]", app->instance_id);
337 /* Disable adv if running */
338 BT_INFO("Disable Advertising Adv Handle [%d] sender [%s]",
339 app->adv_handle, name);
340 _bt_set_advertising(app->sender, app->adv_handle, FALSE, FALSE);
343 apps[app->instance_id] = BT_GATT_SERVER; /* App holds a GATT server Instance */
344 } else if (app->client_id != -1) {
346 apps[app->client_id] = BT_GATT_CLIENT; /* App holds a GATT client Instance */
351 /* Unregister all apps one by one */
352 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
353 if (apps[k] == BT_GATT_SERVER) {
354 BT_INFO("Unregister server app[%d]", k);
355 /* Unregister server instance */
356 __bt_unregister_gatt_server_instance(k);
357 } else if (apps[k] == BT_GATT_CLIENT) {
358 BT_INFO("Unregister client app[%d]", k);
359 /* Unregister client instance */
360 __bt_unregister_gatt_client_instance(k);
365 static int __bt_gatt_send_indication_to_all_connected_clients(bluetooth_gatt_att_data_t *data,
366 bluetooth_gatt_server_indication_params_t *param)
369 int ret = OAL_STATUS_SUCCESS;
370 int result = OAL_STATUS_INTERNAL_ERROR;
372 BT_INFO("Current total number of connected clients [%d]", g_slist_length(gatt_client_info_list));
373 for (l = gatt_client_info_list; l != NULL; l = l->next) {
374 struct gatt_client_info_t *info = l->data;
377 BT_INFO("GATT Remote client address [%s] connection Id [%d]", info->addr, info->connection_id);
379 ret = gatts_send_indication(param->instance_id, param->atrribute_handle,
380 info->connection_id, data->length,
381 param->need_confirmation, (char *)(&data->data[0]));
383 BT_INFO("Send Indication to GATT client [%s] result: [%d]", info->addr, ret);
384 if (ret == OAL_STATUS_SUCCESS) {
385 BT_INFO("Send Indication sent successfully to GATT client [%s]", info->addr);
387 num_indicate_clients++;
391 BT_INFO("Indication sending done for total number of clients [%d]", num_indicate_clients);
395 static struct gatt_server_req_info *__bt_gatt_server_find_request_info(int request_id,
396 bluetooth_gatt_att_request_type_e req_type)
400 for (l = gatt_server_requests; l != NULL; l = l->next) {
401 struct gatt_server_req_info *req_info = l->data;
403 if (req_info && req_info->request_id == request_id && req_info->request_type == req_type) {
404 BT_INFO("GATT Server request info found Req ID [%d] handle [%d] conn ID [%d]",
405 req_info->request_id, req_info->attribute_handle, req_info->connection_id);
409 BT_ERR("Gatt Request not found");
413 void _bt_get_adv_handle_from_instance(int server_inst, int *adv_handle)
417 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
418 if (numapps[k].is_initialized == 1 && numapps[k].instance_id == server_inst) {
419 *adv_handle = numapps[k].adv_handle;
425 #ifdef TIZEN_GATT_CLIENT
426 char * _bt_gatt_get_default_gatt_client_uuid(void)
428 return g_strdup(DEFAULT_GATT_CLIENT_UUID);
432 static void __bt_register_default_gatt_client()
437 uuid_str = _bt_gatt_get_default_gatt_client_uuid();
438 _bt_string_to_uuid(uuid_str, (service_uuid_t*)&uuid);
440 BT_INFO("Register Default GATT client uuid [%s]", uuid_str);
442 if (OAL_STATUS_SUCCESS != gattc_register(&uuid)) /* for only Smart Control */
443 BT_ERR("gattc register failed");
449 int _bt_gatt_init(void)
451 const char *stack_name = NULL;
455 if (OAL_STATUS_SUCCESS != gatt_enable()) {
456 BT_ERR("gatt Init failed");
457 return BLUETOOTH_ERROR_INTERNAL;
460 /* Register gatt event handler */
461 _bt_service_register_event_handler_callback(BT_GATT_MODULE, __bt_gatt_event_handler);
463 __bt_service_reset_gatt_data();
465 stack_name = oal_get_stack_name();
467 if (stack_name && g_strcmp0(stack_name, "bluez") == 0) {
468 /*In the platform, defacult gatt client should be registered */
469 __bt_register_default_gatt_client();
473 return BLUETOOTH_ERROR_NONE;
476 static void __bt_service_reset_gatt_data(void)
480 BT_INFO("Rest numapp");
483 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
484 numapps[k].is_initialized = 0;
485 numapps[k].instance_id = -1;
486 numapps[k].adv_handle = 0;
487 numapps[k].adv_instance = -1;
488 memset(numapps[k].sender, 0x00, sizeof(numapps[k].sender));
489 memset(numapps[k].uuid, 0x00, sizeof(numapps[k].uuid));
490 memset(numapps[k].adv_data.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX);
491 memset(numapps[k].scan_rsp.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX);
492 numapps[k].adv_data_len = 0;
493 numapps[k].scan_rsp_len = 0;
496 numapps[k].client_id = -1;
497 memset(numapps[k].address.addr, 0x00, BLUETOOTH_ADDRESS_LENGTH);
498 numapps[k].is_watcher_enabled = FALSE;
502 void _bt_gatt_deinit(void)
504 BT_INFO("GATT deinit");
506 /* Un-register the default gatt client before */
507 __bt_unregister_gatt_client_instance(gatt_default_client);
509 if (OAL_STATUS_SUCCESS != gatt_disable())
510 BT_ERR("gatt deinit failed");
512 /* Un-register gatt event handler */
513 _bt_service_unregister_event_handler_callback(BT_GATT_MODULE);
515 __bt_service_reset_gatt_data();
518 void _bt_update_adv_handle(const char *sender, int adv_handle)
521 BT_DBG("Sender [%s] Adv handle [%d]", sender, adv_handle);
522 bt_service_app_info_t *info = NULL;
524 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
526 /* Do not update client instance */
527 if (info->instance_id == -1)
529 /* Search for a app which has same sender and adv handle as 0 */
530 if (!g_strcmp0(info->sender, sender) && info->adv_handle == 0)
531 info->adv_handle = adv_handle;
535 int _bt_is_sender_gatt_server_with_no_adv(const char *sender, int adv_handle)
538 BT_DBG("Sender [%s] Adv handle [%d]", sender, adv_handle);
539 bt_service_app_info_t *info = NULL;
541 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
543 /* Search for a app which has same sender and adv handle as 0
544 It is possible that same sender but different adv handle */
545 if (!g_strcmp0(info->sender, sender) && info->adv_handle == 0) {
546 //info->adv_handle = adv_handle;
547 return info->instance_id;
553 int _bt_get_allocated_server_instance(const char *sender, int adv_handle, gboolean use_reserved_slot)
556 BT_DBG("Sender [%s] Adv handle [%d]", sender, adv_handle);
557 bt_service_app_info_t *info = NULL;
559 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
562 /* Exact matching of Adv handle + sender combination */
563 if (!g_strcmp0(info->sender, sender) && info->adv_handle == adv_handle)
564 return info->instance_id;
566 if (!g_strcmp0(info->sender, sender) && info->adv_handle == -1)
567 return info->instance_id;
573 char * _bt_get_sender_and_handle(int server_instance, int *adv_handle)
576 bt_service_app_info_t *info = NULL;
578 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
581 if (info->instance_id == server_instance && info->adv_handle != 0) {
582 *adv_handle = info->adv_handle;
583 BT_DBG("Server instance [%d] Adv handle [%d] Sender [%s]", server_instance, *adv_handle, info->sender);
584 return g_strdup(info->sender);
590 void _bt_set_new_adv_data(bluetooth_advertising_data_t *adv, int len, int instance)
594 bt_service_app_info_t *info = NULL;
595 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
598 if (info->instance_id == instance) {
599 memcpy(info->adv_data.data, &adv->data, len);
605 void _bt_set_new_scan_rsp_data(bluetooth_scan_resp_data_t *scan, int len, int instance)
609 bt_service_app_info_t *info = NULL;
610 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
613 if (info->instance_id == instance) {
614 memcpy(info->scan_rsp.data, &scan->data, len);
620 void _bt_get_previous_adv_data(bluetooth_advertising_data_t *adv, int *len, int instance)
623 bt_service_app_info_t *info = NULL;
625 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
628 if (info->instance_id == instance) {
629 memcpy(&adv->data, info->adv_data.data, info->adv_data_len);
630 *len = info->adv_data_len;
636 void _bt_get_previous_scan_rsp_data(bluetooth_scan_resp_data_t *scan, int *len, int instance)
640 bt_service_app_info_t *info = NULL;
642 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
645 if (info->instance_id == instance) {
646 memcpy(&scan->data, info->scan_rsp.data, info->scan_rsp_len);
647 *len = info->scan_rsp_len;
653 static int __bt_unregister_gatt_client_instance(int client_if)
655 int ret = OAL_STATUS_SUCCESS;
658 BT_INFO("DeAllocate client instance ID [%d]", client_if);
660 /* Reset data: instance_id parameter could be either for GATT Server or for GATT client */
661 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
662 if (numapps[k].client_id == client_if) {
663 BT_INFO("This is a GATT client app, unregister: Slot [%d] vacant", k);
664 numapps[k].client_id = -1;
665 numapps[k].is_initialized = FALSE;
666 memset(numapps[k].sender, 0x00, sizeof(numapps[k].sender));
667 memset(numapps[k].uuid, 0x00, sizeof(numapps[k].uuid));
668 memset(&numapps[k].address.addr, 0x00, sizeof(bluetooth_device_address_t));
670 /* Its a GATT Client Instance */
671 ret = gattc_deregister(client_if);
672 if (ret != OAL_STATUS_SUCCESS) {
673 BT_ERR("DeAllocate GATT Client instance with stack Fail ret: %d", ret);
674 return BLUETOOTH_ERROR_INTERNAL;
679 return BLUETOOTH_ERROR_NONE;
682 static int __bt_unregister_gatt_server_instance(int server_instance)
684 int ret = OAL_STATUS_SUCCESS;
687 /* Unregister the server instance */
688 ret = gatts_unregister(server_instance);
689 if (ret != OAL_STATUS_SUCCESS) {
690 BT_ERR("DeAllocate server instance with stack Fail ret: %d", ret);
691 return BLUETOOTH_ERROR_INTERNAL;
693 BT_INFO("DeAllocated server instance with stack successful..");
696 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
697 if (numapps[k].instance_id == server_instance) {
698 numapps[k].is_initialized = 0;
699 numapps[k].instance_id = -1;
700 numapps[k].adv_handle = 0;
701 numapps[k].adv_instance = -1;
702 memset(numapps[k].sender, 0x00, sizeof(numapps[k].sender));
703 memset(numapps[k].uuid, 0x00, sizeof(numapps[k].uuid));
704 memset(numapps[k].adv_data.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX);
705 memset(numapps[k].scan_rsp.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX);
706 numapps[k].adv_data_len = 0;
707 numapps[k].scan_rsp_len = 0;
711 BT_DBG("Going8 to reset numapp block num [%d]", k);
712 return BLUETOOTH_ERROR_NONE;
715 static void __bt_remove_all_service_handles(bt_service_app_info_t *app_info)
719 int ret = OAL_STATUS_SUCCESS;
722 if (app_info == NULL)
725 count = g_slist_length(app_info->service_handles);
726 BT_INFO("Before handle removal: current count [%d]", count);
728 for (l = app_info->service_handles; l != NULL;) {
733 BT_INFO("Server Handle to be Removed [%d] Instance ID [%d]", *handle, app_info->instance_id);
734 if (_bt_gatt_server_stop_service(app_info->sender, *handle, app_info->instance_id) != BLUETOOTH_ERROR_NONE)
737 ret = gatts_delete_service(app_info->instance_id, *handle);
738 if (ret != OAL_STATUS_SUCCESS) {
739 BT_ERR("ret: %d", ret);
742 app_info->service_handles = g_slist_remove(app_info->service_handles, handle);
745 count = g_slist_length(app_info->service_handles);
746 BT_INFO("After deleting current count [%d]", count);
752 int _bt_unregister_server_instance(const char *sender, int adv_handle)
754 BT_INFO("Unregister Allocated server instance request Sender [%s] Adv handle [%d]", sender, adv_handle);
755 int result = BLUETOOTH_ERROR_NONE;
756 int apps[MAX_APPS_SUPPORTED];
760 memset(&apps, -1, sizeof(apps));
762 if (adv_handle == 0) {
763 BT_DBG("Its a direct GATT Server app request to unregister");
764 /* Unregister server instance for each app with same sender (case: GATT Server with multiple adv handle) */
765 bt_service_app_info_t *info = NULL;
767 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
770 /* Exact matching of sender */
771 if (!g_strcmp0(info->sender, sender)) {
772 BT_INFO("Unregister GATT server instance [%d]", info->instance_id);
773 /* Unregister all service handles with stack */
774 __bt_remove_all_service_handles(info);
776 /* Disable adv if running */
777 BT_INFO("Disable Advertising Adv Handle [%d] sender [%s]",
778 info->adv_handle, sender);
779 _bt_set_advertising(sender, info->adv_handle, FALSE, FALSE);
781 /* Save all instances which need to be unregistered */
782 apps[info->instance_id] = 1;
786 BT_DBG("Its an Internal unregister request by adv application");
787 server_instance = _bt_get_allocated_server_instance(sender, adv_handle, FALSE);
788 BT_DBG("Its an Internal unregister request by adv application: Adv disabled srv instance [%d]", server_instance);
789 if (server_instance == -1) {
790 BT_ERR("No allocated server instance to be removed");
791 return BLUETOOTH_ERROR_INVALID_PARAM;
793 if (!numapps[server_instance].service_handles) {
794 BT_INFO("There are no Service handles with this app, safe to unregister");
795 /* Unregister server instance only if this sender does not have any gatt services in it */
796 result = __bt_unregister_gatt_server_instance(server_instance);
798 numapps[server_instance].adv_handle = 0;
799 memset(numapps[server_instance].adv_data.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX);
800 numapps[server_instance].adv_data_len = 0;
801 memset(numapps[server_instance].scan_rsp.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX);
802 numapps[server_instance].scan_rsp_len = 0;
807 /* Unregister all apps one by one */
808 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
810 BT_INFO("Unregister app[%d]", k);
811 /* Unregister server instance */
812 __bt_unregister_gatt_server_instance(k);
819 int _bt_register_server_instance(const char *sender, int adv_handle)
821 int ret = OAL_STATUS_SUCCESS;
822 char *uuid_string = NULL;
827 BT_INFO("###Check on which instance Server instance can be initialized....");
828 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
829 if (numapps[k].is_initialized == 1) {
830 BT_INFO("Instance ID [%d] is already in use..Check next slot", numapps[k].instance_id);
833 BT_INFO("Time to register GATT Server..UUID to be used is [%s] slot [%d]", uuid_list[slot-1], slot);
839 BT_ERR("No Slot if free for GATT Server registration..");
840 return BLUETOOTH_ERROR_REGISTRATION_FAILED;
843 uuid_string = g_malloc0(BT_UUID_STRING_MAX);
844 _bt_string_to_uuid(uuid_list[slot-1], (service_uuid_t*)&uuid);
845 g_strlcpy(uuid_string, uuid_list[slot-1], BT_UUID_STRING_MAX);
846 BT_INFO("Copied UUID string [%s]", uuid_string);
848 /* Register GATT Server */
849 ret = gatts_register(&uuid);
850 if (ret != OAL_STATUS_SUCCESS) {
851 BT_ERR("ret: %d", ret);
853 return BLUETOOTH_ERROR_INTERNAL;
855 BT_INFO("GATT Server registration call successfully accepted by OAL..wait for Instance Initialized event from OAL..");
856 /* Return & wait for GATT Server Instance Initialization event */
857 memset(numapps[slot].sender, 0x00, sizeof(numapps[slot].sender));
858 memset(numapps[slot].uuid, 0x00, sizeof(numapps[slot].uuid));
860 g_strlcpy(numapps[slot].sender, sender, sizeof(numapps[slot].sender));
861 g_strlcpy(numapps[slot].uuid, uuid_string, sizeof(numapps[slot].uuid));
863 numapps[slot].is_initialized = 0; /* Set initialization from app registered callback */
864 numapps[slot].adv_handle = adv_handle;
867 return BLUETOOTH_ERROR_NONE;
871 static void __bt_gatt_handle_pending_request_info(int result,
872 int service_function, void *data, unsigned int size)
876 invocation_info_t *req_info = NULL;
877 ret_if(data == NULL);
879 for (l = _bt_get_invocation_list(); l != NULL; ) {
882 if (req_info == NULL || req_info->service_function != service_function)
885 switch (service_function) {
887 case BT_GATT_SERVER_REGISTER: {
888 bt_service_app_info_t *param = (bt_service_app_info_t*)data;
889 BT_DBG("Sender [%s] Request Sender [%s]", param->sender, req_info->sender);
890 if (!g_strcmp0(req_info->sender, param->sender)) {
891 BT_DBG("GATT Server app found [%s]", req_info->sender);
893 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
894 g_array_append_vals(out_param, ¶m->instance_id, sizeof(int));
895 _bt_service_method_return(req_info->context, out_param, result);
897 g_free(req_info->user_data);
898 _bt_free_info_from_invocation_list(req_info);
899 g_array_free(out_param, TRUE);
903 case BT_GATT_SERVER_START_SERVICE:
904 case BT_GATT_SERVER_DELETE_SERVICE: {
905 bt_service_app_info_t *param = (bt_service_app_info_t*)data;
906 BT_DBG("Sender [%s] Request Sender [%s]", param->sender, req_info->sender);
908 int *saved_instance_id = (int*)req_info->user_data;
909 if (!g_strcmp0(req_info->sender, param->sender) && param->instance_id == *saved_instance_id) {
910 BT_DBG("GATT Server app found [%s] Instance ID [%d] Reply DBUS",
911 req_info->sender, *saved_instance_id);
913 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
914 g_array_append_vals(out_param, &saved_instance_id, sizeof(int));
915 _bt_service_method_return(req_info->context, out_param, result);
917 g_free(req_info->user_data);
918 _bt_free_info_from_invocation_list(req_info);
919 g_array_free(out_param, TRUE);
923 case BT_GATT_SERVER_ADD_SERVICE:
924 case BT_GATT_SERVER_ADD_DESCRIPTOR:
925 case BT_GATT_SERVER_ADD_CHARACTERISTIC: {
926 int *handle = (int*)data;
927 BT_DBG("Characteristic added: Handle [%d]", *handle);
928 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
930 g_array_append_vals(out_param, handle, sizeof(int));
931 _bt_service_method_return(req_info->context, out_param, result);
933 g_free(req_info->user_data);
934 _bt_free_info_from_invocation_list(req_info);
935 g_array_free(out_param, TRUE);
940 case BT_DISCONNECT_LE: {
941 #ifdef TIZEN_GATT_CLIENT
942 char *addr = (char*)req_info->user_data;
943 bluetooth_device_address_t address;
945 if (!g_strcmp0(addr, (char*)data)) {
946 BT_INFO("GATT Client connect-disconnect call pending for app [%s] addr [%s]",
947 req_info->sender, addr);
948 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
949 _bt_convert_addr_string_to_type(address.addr, addr);
951 g_array_append_vals(out_param, (bluetooth_device_address_t*)&address,
952 sizeof(bluetooth_device_address_t));
953 _bt_service_method_return(req_info->context, out_param, result);
955 g_free(req_info->user_data);
956 _bt_free_info_from_invocation_list(req_info);
957 g_array_free(out_param, TRUE);
960 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
962 g_array_append_vals(out_param, (bluetooth_device_address_t*)data,
963 sizeof(bluetooth_device_address_t));
964 _bt_service_method_return(req_info->context, out_param, result);
966 g_free(req_info->user_data);
967 _bt_free_info_from_invocation_list(req_info);
969 g_array_free(out_param, TRUE);
973 #ifdef TIZEN_GATT_CLIENT
974 case BT_GATT_CLIENT_REGISTER: {
975 bt_service_app_info_t *param = (bt_service_app_info_t*)data;
976 BT_DBG("Sender [%s] Request Sender [%s]", param->sender, req_info->sender);
977 if (!g_strcmp0(req_info->sender, param->sender)) {
978 BT_DBG("GATT Client app found [%s] created client ID [%d]",
979 req_info->sender, param->client_id);
981 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
982 g_array_append_vals(out_param, ¶m->client_id, sizeof(int));
983 _bt_service_method_return(req_info->context, out_param, result);
985 g_free(req_info->user_data);
986 _bt_free_info_from_invocation_list(req_info);
987 g_array_free(out_param, TRUE);
991 case BT_GATT_GET_PRIMARY_SERVICES: {
992 bt_services_browse_info_t *param = (bt_services_browse_info_t*)data;
993 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
994 _bt_convert_addr_type_to_string(address,
995 (unsigned char *)(¶m->device_addr.addr));
997 BT_DBG("Request Sender [%s] address [%s]", req_info->sender, address);
999 /* Match address to determine same request */
1000 if (!g_strcmp0((char*)req_info->user_data, address)) {
1001 BT_DBG("GATT Client app found [%s] Remote address [%s]",
1002 req_info->sender, address);
1004 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
1005 g_array_append_vals(out_param, param,
1006 sizeof(bt_services_browse_info_t));
1008 //g_array_append_vals(out_param, ¶m->client_id, sizeof(int));
1009 _bt_service_method_return(req_info->context, out_param, result);
1011 g_free(req_info->user_data);
1012 _bt_free_info_from_invocation_list(req_info);
1013 g_array_free(out_param, TRUE);
1018 case BT_GATT_GET_SERVICE_PROPERTIES: {
1019 bt_char_browse_info_t param;
1020 memcpy((void*)¶m, data, sizeof(bt_char_browse_info_t));
1021 //bt_char_browse_info_t *param = (bt_char_browse_info_t*)data;
1022 BT_DBG("Request Sender [%s]", req_info->sender);
1023 bluetooth_gatt_client_svc_prop_info_t *prop = (bluetooth_gatt_client_svc_prop_info_t*)req_info->user_data;
1025 /* Match both address and service properties to determine same request */
1026 if (!memcmp(param.device_addr.addr,
1027 prop->device_address.addr,
1028 sizeof(bluetooth_device_address_t)) &&
1029 !memcmp(param.svc_uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) &&
1030 param.svc_inst_id == prop->svc.instance_id) {
1031 BT_DBG("Returning Service properties");
1033 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
1034 g_array_append_vals(out_param, ¶m, sizeof(bt_char_browse_info_t));
1035 _bt_service_method_return(req_info->context, out_param, result);
1037 g_free(req_info->user_data);
1038 _bt_free_info_from_invocation_list(req_info);
1039 g_array_free(out_param, TRUE);
1043 case BT_GATT_GET_CHARACTERISTIC_PROPERTIES: {
1044 bt_descriptor_browse_info_t *param = (bt_descriptor_browse_info_t*)data;
1046 BT_DBG("Request Sender [%s]", req_info->sender);
1047 bluetooth_gatt_client_char_prop_info_t *prop = (bluetooth_gatt_client_char_prop_info_t*)req_info->user_data;
1049 /* Match both address, service properties &char properties to determine same request */
1050 if (!memcmp(param->device_addr.addr,
1051 prop->device_address.addr,
1052 sizeof(bluetooth_device_address_t)) &&
1053 !memcmp(param->svc_uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) &&
1054 param->svc_inst_id == prop->svc.instance_id &&
1055 !memcmp(param->char_uuid, prop->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) &&
1056 param->char_inst_id == prop->characteristic.instance_id) {
1057 BT_DBG("Returning Characteristic properties");
1058 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
1059 g_array_append_vals(out_param, param, sizeof(bt_descriptor_browse_info_t));
1060 _bt_service_method_return(req_info->context, out_param, result);
1062 g_free(req_info->user_data);
1063 _bt_free_info_from_invocation_list(req_info);
1064 g_array_free(out_param, TRUE);
1068 case BT_GATT_WATCH_CHARACTERISTIC: {
1069 bt_gatt_notif_reg_info_t *param = (bt_gatt_notif_reg_info_t*)data;
1070 bluetooth_gatt_client_char_prop_info_t *prop = (bluetooth_gatt_client_char_prop_info_t*)req_info->user_data;
1071 BT_DBG("Request Sender [%s]", req_info->sender);
1072 /* Match both address, service properties &char properties to determine same request */
1073 if (!memcmp(param->addr.addr,
1074 prop->device_address.addr,
1075 sizeof(bluetooth_device_address_t)) &&
1076 !memcmp(param->svc_uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) &&
1077 param->svc_inst == prop->svc.instance_id &&
1078 !memcmp(param->char_uuid, prop->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) &&
1079 param->char_inst == prop->characteristic.instance_id) {
1080 BT_INFO("Characteristic Watch Successful: Is registered [%d]",
1081 param->is_registered);
1082 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
1083 g_array_append_vals(out_param, param, sizeof(bt_gatt_notif_reg_info_t));
1084 _bt_service_method_return(req_info->context, out_param, result);
1085 g_free(req_info->user_data);
1086 _bt_free_info_from_invocation_list(req_info);
1087 g_array_free(out_param, TRUE);
1091 case BT_GATT_READ_CHARACTERISTIC:
1092 case BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE: {
1093 bluetooth_gatt_client_char_prop_info_t *param = (bluetooth_gatt_client_char_prop_info_t*)data;
1094 BT_DBG("Request Sender [%s]", req_info->sender);
1096 char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
1097 bluetooth_gatt_client_char_prop_info_t *prop = (bluetooth_gatt_client_char_prop_info_t*)req_info->user_data;
1098 _bt_convert_addr_type_to_string(addr, prop->device_address.addr);
1100 if (!memcmp(param, prop, sizeof(bluetooth_gatt_client_char_prop_info_t))) {
1101 BT_DBG("Gatt Char read or write request matched for address [%s]", addr);
1102 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
1103 g_array_append_vals(out_param, param, sizeof(bluetooth_gatt_client_char_prop_info_t));
1104 _bt_service_method_return(req_info->context, out_param, result);
1106 g_free(req_info->user_data);
1107 _bt_free_info_from_invocation_list(req_info);
1108 g_array_free(out_param, TRUE);
1113 case BT_GATT_READ_DESCRIPTOR_VALUE:
1114 case BT_GATT_WRITE_DESCRIPTOR_VALUE: {
1115 bluetooth_gatt_client_desc_prop_info_t *param = (bluetooth_gatt_client_desc_prop_info_t*)data;
1116 BT_DBG("Request Sender [%s]", req_info->sender);
1118 char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
1119 bluetooth_gatt_client_desc_prop_info_t *prop = (bluetooth_gatt_client_desc_prop_info_t*)req_info->user_data;
1120 _bt_convert_addr_type_to_string(addr, prop->device_address.addr);
1122 if (!memcmp(param, prop, sizeof(bluetooth_gatt_client_desc_prop_info_t))) {
1123 BT_DBG("Descriptor read or write request matched for address [%s]", addr);
1124 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
1125 g_array_append_vals(out_param, param, sizeof(bluetooth_gatt_client_desc_prop_info_t));
1126 _bt_service_method_return(req_info->context, out_param, result);
1128 g_free(req_info->user_data);
1129 _bt_free_info_from_invocation_list(req_info);
1130 g_array_free(out_param, TRUE);
1135 case BT_REQ_ATT_MTU: {
1136 char *addr = (char*)req_info->user_data;
1137 bluetooth_device_address_t address;
1139 if (!g_strcmp0(addr, (char*)data)) {
1140 BT_DBG("GATT Client BT_REQ_ATT_MTU call pending for app [%s] addr [%s]",
1141 req_info->sender, addr);
1142 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
1143 _bt_convert_addr_string_to_type(address.addr, addr);
1145 g_array_append_vals(out_param, (bluetooth_device_address_t*)&address,
1146 sizeof(bluetooth_device_address_t));
1147 _bt_service_method_return(req_info->context, out_param, result);
1149 g_free(req_info->user_data);
1150 _bt_free_info_from_invocation_list(req_info);
1151 g_array_free(out_param, TRUE);
1161 static void __bt_handle_server_instance_registered(event_gatts_register_t *data)
1163 bt_service_app_info_t *info = NULL;
1165 char *uuid_string = g_malloc0(BT_UUID_STRING_MAX);
1167 _bt_uuid_to_string(&(data->server_uuid), uuid_string);
1168 BT_INFO("Instance ID is Intialized [%d] UUID initialized [%s]", data->server_inst, uuid_string);
1170 /* Check if the just registered Instance ID belongs to BLEAPP or GATT Server */
1171 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1174 if (g_strcmp0(info->uuid, uuid_string) == 0) {
1175 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1176 info->is_initialized = TRUE;
1177 info->instance_id = data->server_inst;
1178 info->adv_instance = data->server_inst;
1179 __bt_gatt_handle_pending_request_info(BLUETOOTH_ERROR_NONE, BT_GATT_SERVER_REGISTER,
1180 (void*)info, sizeof(bt_service_app_info_t));
1184 g_free(uuid_string);
1187 static void __bt_handle_gatt_server_service_added(event_gatts_srvc_prm_t *event)
1189 int result = BLUETOOTH_ERROR_NONE;
1193 bt_service_app_info_t *info = NULL;
1196 char *uuid_str = g_malloc0(BT_UUID_STRING_MAX);
1197 _bt_uuid_to_string(&(event->gatt_srvc_id.id.uuid), uuid_str);
1198 BT_INFO("GATT Added Service UUID: [%s] Server Ins [%d] Service hdl [%d] Is Primary [%d]\n",
1199 uuid_str, event->gatt_srvc_stat.server_inst, svc_handle, event->gatt_srvc_id.is_prmry);
1201 if (event->gatt_srvc_stat.status != OAL_STATUS_SUCCESS) {
1202 result = BLUETOOTH_ERROR_INTERNAL;
1203 svc_handle = 0; /* Service handle set to 0 indicates.
1204 0 is reserved by BT SIG, cant be used by app*/
1206 svc_handle = event->gatt_srvc_stat.servic_hndl;
1208 BT_INFO("GATT Added Service Status [%d] Server Ins [%d] Service hdl [%d] Is Primary [%d]\n",
1209 event->gatt_srvc_stat.status, event->gatt_srvc_stat.server_inst, svc_handle, event->gatt_srvc_id.is_prmry);
1211 /* Check if the just registered Instance ID belongs to BLEAPP or GATT Server */
1212 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1215 if (info->instance_id == event->gatt_srvc_stat.server_inst) {
1216 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1217 __bt_gatt_handle_pending_request_info(result, BT_GATT_SERVER_ADD_SERVICE,
1218 (int*)&svc_handle, sizeof(int));
1220 /* Add Service Handle */
1221 if (svc_handle > 0) {
1222 handle = g_malloc0(sizeof(int));
1223 *handle = svc_handle;
1224 numapps[event->gatt_srvc_stat.server_inst].service_handles = g_slist_append(numapps[event->gatt_srvc_stat.server_inst].service_handles, handle);
1225 count = g_slist_length(numapps[event->gatt_srvc_stat.server_inst].service_handles);
1226 BT_INFO("Added Service handle [%d] to list..current count [%d]", svc_handle, count);
1235 static void __bt_handle_gatt_server_characteristic_added(event_gatts_srvc_charctr_t *event)
1237 int result = BLUETOOTH_ERROR_NONE;
1239 bt_service_app_info_t *info = NULL;
1241 char *uuid_str = g_malloc0(BT_UUID_STRING_MAX);
1243 BT_INFO("GATT Server Char added status [%d]", event->gatt_srvc_stat.status);
1244 BT_INFO("GATT Server_inst: [%d]", event->gatt_srvc_stat.server_inst);
1245 BT_INFO("GATT Service Handle: [%d]", event->gatt_srvc_stat.servic_hndl);
1246 BT_INFO("GATT Add characteristic Status: [%d]", event->gatt_srvc_stat.status);
1247 BT_INFO("GATT Service characteristic Handle: [%d]", event->charctr_hndl);
1249 if (event->gatt_srvc_stat.status != OAL_STATUS_SUCCESS) {
1250 result = BLUETOOTH_ERROR_INTERNAL;
1251 char_handle = 0; /* characteristic handle set to 0 indicates.
1252 0 is reserved by BT SIG, cant be used by app*/
1254 char_handle = event->charctr_hndl;
1257 /* Check if the just registered Instance ID belongs to BLEAPP or GATT Server */
1258 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1261 if (info->instance_id == event->gatt_srvc_stat.server_inst) {
1262 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1263 __bt_gatt_handle_pending_request_info(result, BT_GATT_SERVER_ADD_CHARACTERISTIC,
1264 (int*)&char_handle, sizeof(int));
1270 _bt_uuid_to_string(&(event->charctr_uuid), uuid_str);
1271 BT_INFO("GATT Added Characteristic: UUID: [%s]", uuid_str);
1276 static void __bt_handle_gatt_server_descriptor_added(event_gatts_srvc_descr_t* event)
1278 int result = BLUETOOTH_ERROR_NONE;
1280 bt_service_app_info_t *info = NULL;
1282 char *uuid_str = g_malloc0(BT_UUID_STRING_MAX);
1284 BT_INFO("GATT Server Descriptor added status [%d]", event->gatt_srvc_stat.status);
1285 BT_INFO("GATT Server_inst: [%d]", event->gatt_srvc_stat.server_inst);
1286 BT_INFO("GATT Service Handle: [%d]", event->gatt_srvc_stat.servic_hndl);
1287 BT_INFO("GATT Add Descriptor Status: [%d]", event->gatt_srvc_stat.status);
1288 BT_INFO("GATT Service Descriptor Handle: [%d]", event->descrptr_hndl);
1290 if (event->gatt_srvc_stat.status != OAL_STATUS_SUCCESS) {
1291 result = BLUETOOTH_ERROR_INTERNAL;
1292 desc_handle = 0; /* Service handle set to 0 indicates.
1293 0 is reserved by BT SIG, cant be used by app*/
1295 desc_handle = event->descrptr_hndl;
1297 /* Check if the just registered Instance ID belongs to BLEAPP or GATT Server */
1298 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1301 if (info->instance_id == event->gatt_srvc_stat.server_inst) {
1302 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1303 __bt_gatt_handle_pending_request_info(result, BT_GATT_SERVER_ADD_DESCRIPTOR,
1304 (int*)&desc_handle, sizeof(int));
1309 _bt_uuid_to_string(&(event->descrptr_uuid), uuid_str);
1310 BT_INFO("GATT Added Descriptor: UUID: [%s]", uuid_str);
1315 static void __bt_handle_gatt_server_service_started(event_gatts_srvc_t *event)
1317 bt_service_app_info_t *info = NULL;
1318 int result = BLUETOOTH_ERROR_NONE;
1320 BT_INFO("GATT Server Service Started..");
1323 BT_INFO("GATT Server_inst: [%d]", event->server_inst);
1324 BT_INFO("GATT Service Handle: [%d]", event->servic_hndl);
1325 BT_INFO("GATT Service Started Status: [%d]", event->status);
1327 if (event->status != OAL_STATUS_SUCCESS) {
1328 BT_ERR("GATT Server Service Start Failed Err: [%d]", event->status);
1329 result = BLUETOOTH_ERROR_INTERNAL;
1332 /* Check if the just registered Instance ID belongs to requester */
1333 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1336 if (info->instance_id == event->server_inst) {
1337 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1338 __bt_gatt_handle_pending_request_info(result, BT_GATT_SERVER_START_SERVICE,
1339 (void*)info, sizeof(bt_service_app_info_t));
1345 static void __bt_handle_gatt_server_service_stopped(event_gatts_srvc_t *event)
1347 int result = BLUETOOTH_ERROR_NONE;
1348 bt_service_app_info_t *info = NULL;
1350 BT_INFO("GATT Server Service Stopped..");
1352 BT_INFO("GATT Server_inst: [%d]", event->server_inst);
1353 BT_INFO("GATT Service Handle: [%d]", event->servic_hndl);
1354 BT_INFO("GATT Service Stopped Status: [%d]", event->status);
1356 if (event->status != OAL_STATUS_SUCCESS) {
1357 BT_ERR("GATT Server Service Stop Failed Err: [%d]", event->status);
1358 result = BLUETOOTH_ERROR_INTERNAL;
1361 /* Check if the just registered Instance ID belongs to requester */
1362 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1365 if (info->instance_id == event->server_inst) {
1366 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1367 __bt_gatt_handle_pending_request_info(result, BT_GATT_SERVER_STOP_SERVICE,
1368 (void*)info, sizeof(bt_service_app_info_t));
1374 static void __bt_handle_gatt_server_service_deleted(event_gatts_srvc_t *event)
1376 int result = BLUETOOTH_ERROR_NONE;
1377 bt_service_app_info_t *info = NULL;
1379 BT_INFO("GATT Server Service Deleted..");
1381 BT_INFO("GATT Server_inst: [%d]", event->server_inst);
1382 BT_INFO("GATT Service Handle: [%d]", event->servic_hndl);
1383 BT_INFO("GATT Service Deleted Status: [%d]", event->status);
1385 if (event->status != OAL_STATUS_SUCCESS) {
1386 BT_ERR("GATT Server Service Delete Failed Err: [%d]", event->status);
1387 result = BLUETOOTH_ERROR_INTERNAL;
1390 /* Check if the just registered Instance ID belongs to requester */
1391 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1394 if (info->instance_id == event->server_inst) {
1395 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1396 __bt_gatt_handle_pending_request_info(result, BT_GATT_SERVER_DELETE_SERVICE,
1397 (void*)info, sizeof(bt_service_app_info_t));
1403 struct gatt_client_info_t *_bt_find_remote_gatt_client_info(char *address)
1406 struct gatt_client_info_t *info = NULL;
1407 for (l = gatt_client_info_list; l != NULL; l = g_slist_next(l)) {
1408 info = (struct gatt_client_info_t*)l->data;
1412 if (!g_strcmp0(info->addr, address)) {
1413 BT_DBG("Remote GATT client found addr[%s]", info->addr);
1420 static struct gatt_client_info_t *__bt_find_remote_gatt_client_info_from_conn_id(int conn_id)
1423 struct gatt_client_info_t *info = NULL;
1425 for (l = gatt_client_info_list; l != NULL; l = g_slist_next(l)) {
1426 info = (struct gatt_client_info_t*)l->data;
1430 if (info->connection_id == conn_id) {
1431 BT_INFO("Remote GATT client found addr[%s]", info->addr);
1438 #ifdef TIZEN_GATT_CLIENT
1439 struct gatt_server_info_t *_bt_find_remote_gatt_server_info(char *address)
1442 struct gatt_server_info_t *info = NULL;
1443 for (l = gatt_server_info_list; l != NULL; l = g_slist_next(l)) {
1444 info = (struct gatt_server_info_t*)l->data;
1448 if (!g_strcmp0(info->addr, address)) {
1449 BT_DBG("Remote GATT Server found addr[%s]", info->addr);
1456 static struct gatt_out_conn_info_t* __bt_find_gatt_outgoing_conn_info(char *address)
1459 struct gatt_out_conn_info_t *info = NULL;
1460 for (l = outgoing_gatt_conn_list; l != NULL; l = g_slist_next(l)) {
1461 info = (struct gatt_out_conn_info_t*)l->data;
1465 if (!g_strcmp0(info->addr, address)) {
1466 BT_INFO("Outgoing connection info found addr[%s]", info->addr);
1474 #ifdef TIZEN_GATT_CLIENT
1475 static void __bt_handle_gatt_server_connection_state(event_gatts_conn_t *event)
1477 int result = BLUETOOTH_ERROR_NONE;
1478 struct gatt_client_info_t *client_info = NULL;
1479 struct gatt_server_info_t *server_info = NULL;
1480 bluetooth_device_address_t dev_addr;
1481 GVariant *param = NULL;
1484 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1486 memcpy(dev_addr.addr, event->address.addr, 6);
1488 /* REPLY dbus Context to application which called BT_CONNECT_LE. There is status
1490 _bt_convert_addr_type_to_string(address,
1491 (unsigned char *)dev_addr.addr);
1493 if (event->status != OAL_STATUS_SUCCESS)
1494 result = BLUETOOTH_ERROR_INTERNAL;
1496 __bt_gatt_handle_pending_request_info(result, BT_CONNECT_LE,
1497 address, BT_ADDRESS_STRING_SIZE);
1499 BT_INFO("GATT Server Connedted: Remote Client addr[%s] Server Instance [%d] Connection ID [%d]",
1500 address, event->server_inst, event->conn_id);
1503 /* Check if device is already in connected list */
1504 client_info = _bt_find_remote_gatt_client_info(address);
1507 BT_INFO("Conn Info absent: But no need to Send Local GATT Server Connected event to apps");
1509 param = g_variant_new("(is)", result, address);
1511 /* Send event to application */
1512 _bt_send_event(BT_DEVICE_EVENT,
1513 BLUETOOTH_EVENT_GATT_SERVER_CONNECTED, /* Local device is GATT server */
1516 /* Save client connection info */
1517 client_info = g_new0(struct gatt_client_info_t, 1);
1518 client_info->addr = g_strdup(address);
1519 BT_INFO("Added GATT client addr[%s]", client_info->addr);
1520 client_info->connection_id = event->conn_id;
1521 client_info->instance_id = event->server_inst;
1522 gatt_client_info_list = g_slist_append(gatt_client_info_list, client_info);
1523 BT_INFO("Total num of connected Remote GATT Clients [%d]", g_slist_length(gatt_client_info_list));
1525 /* Save server connection info */
1526 server_info = g_new0(struct gatt_server_info_t, 1);
1527 server_info->addr = g_strdup(address);
1528 server_info->client_id = -1;
1529 BT_INFO("Added GATT server addr[%s]", server_info->addr);
1530 server_info->connection_id = event->conn_id;
1531 gatt_server_info_list = g_slist_append(gatt_server_info_list, server_info);
1532 BT_INFO("Total num of connected Remote GATT Servers [%d]", g_slist_length(gatt_server_info_list));
1534 ret = gattc_add_connection_info((bt_address_t *)&dev_addr, event->conn_id, event->server_inst);
1535 if (ret != OAL_STATUS_SUCCESS) {
1536 BT_ERR("gattc register server instance failed");
1540 __bt_add_mtu_gatt_device(address);
1545 /* GATT Server Dis connected */
1546 static void __bt_handle_gatt_server_disconnection_state(event_gatts_conn_t *event)
1548 int result = BLUETOOTH_ERROR_NONE;
1549 struct gatt_client_info_t *client_info = NULL;
1550 struct gatt_server_info_t *server_info = NULL;
1551 bluetooth_device_address_t dev_addr;
1552 GVariant *param = NULL;
1553 char address[BT_ADDRESS_STRING_SIZE];
1555 memcpy(dev_addr.addr, event->address.addr, 6);
1557 /* REPLY dbus Context to application which called BT_DISCONNECT_LE. There is status
1559 _bt_convert_addr_type_to_string(address,
1560 (unsigned char *)dev_addr.addr);
1562 if (event->status != OAL_STATUS_SUCCESS)
1563 result = BLUETOOTH_ERROR_INTERNAL;
1565 if (NULL == _bt_get_request_info_data(BT_DISCONNECT_LE, address)) {
1566 if (NULL != _bt_get_request_info_data(BT_CONNECT_LE, address)) {
1567 result = BLUETOOTH_ERROR_INTERNAL;
1569 __bt_gatt_handle_pending_request_info(result, BT_CONNECT_LE,
1570 address, BT_ADDRESS_STRING_SIZE);
1572 BT_ERR("Failed to connect Local GATT Server Remote Client addr[%s]", address);
1576 __bt_gatt_handle_pending_request_info(result, BT_DISCONNECT_LE,
1577 address, BT_ADDRESS_STRING_SIZE);
1580 BT_INFO("Local GATT Server DisConnected: Remote Client addr[%s] Server Instance [%d] Connection ID [%d]",
1581 address, event->server_inst, event->conn_id);
1582 /* Remove Connection info */
1583 client_info = _bt_find_remote_gatt_client_info(address);
1585 BT_INFO("No need to Send Local GATT Server Disconnected event to apps, just remove remote client info");
1587 param = g_variant_new("(is)", result, address);
1588 /* Send event to application */
1589 _bt_send_event(BT_DEVICE_EVENT,
1590 BLUETOOTH_EVENT_GATT_SERVER_DISCONNECTED, /* Local device is GATT server */
1593 /* Remove server info from list */
1594 server_info = _bt_find_remote_gatt_server_info(address);
1596 gatt_server_info_list = g_slist_remove(gatt_server_info_list, server_info);
1598 BT_INFO("Can not find conn info, already removed!");
1600 /* Remove client info from List */
1601 gatt_client_info_list = g_slist_remove(gatt_client_info_list, client_info);
1602 BT_INFO("Total num of connected GATT clients [%d]", g_slist_length(gatt_client_info_list));
1603 g_free(client_info->addr);
1604 g_free(client_info);
1607 __bt_remove_mtu_gatt_device(address);
1611 static void __bt_handle_gatt_server_connection_state(event_gatts_conn_t *event)
1613 int result = BLUETOOTH_ERROR_NONE;
1614 struct gatt_client_info_t *conn_info = NULL;
1615 bt_service_app_info_t *info = NULL;
1616 bluetooth_device_address_t dev_addr;
1617 GVariant *param = NULL;
1620 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1622 memcpy(dev_addr.addr, event->address.addr, 6);
1625 /* Check if the just registered Instance ID belongs to BLEAPP or GATT Server */
1626 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1629 if (info->instance_id == event->server_inst) {
1630 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1631 __bt_gatt_handle_pending_request_info(result, BT_CONNECT_LE,
1632 (bluetooth_device_address_t*)&dev_addr, sizeof(bluetooth_device_address_t));
1638 /* Send event to BT-API */
1639 _bt_convert_addr_type_to_string(address,
1640 (unsigned char *)dev_addr.addr);
1642 BT_INFO("GATT Server Connedted: Remote Client addr[%s] Server Instance [%d] Connection ID [%d]",
1643 address, event->server_inst, event->conn_id);
1646 /* Check if device is already in connected list */
1647 conn_info = _bt_find_remote_gatt_client_info(address);
1650 param = g_variant_new("(is)", result, address);
1651 /* Send event to application */
1652 _bt_send_event(BT_GATT_SERVER_EVENT,
1653 BLUETOOTH_EVENT_GATT_CONNECTED,
1656 /* Save Connection info */
1657 conn_info = g_new0(struct gatt_client_info_t, 1);
1658 conn_info->addr = g_strdup(address);
1659 BT_INFO("Added GATT client addr[%s]", conn_info->addr);
1660 conn_info->connection_id = event->conn_id;
1661 conn_info->instance_id = event->server_inst;
1662 gatt_client_info_list = g_slist_append(gatt_client_info_list, conn_info);
1663 BT_INFO("Total num of connected GATT clients [%d]", g_slist_length(gatt_client_info_list));
1669 /* GATT Server Dis connected */
1670 static void __bt_handle_gatt_server_disconnection_state(event_gatts_conn_t *event)
1672 int result = BLUETOOTH_ERROR_NONE;
1673 struct gatt_client_info_t *conn_info = NULL;
1674 bluetooth_device_address_t dev_addr;
1675 bt_service_app_info_t *info = NULL;
1676 GVariant *param = NULL;
1679 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1681 memcpy(dev_addr.addr, event->address.addr, 6);
1683 /* Check if the just registered Instance ID belongs to BLEAPP or GATT Server */
1684 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1687 if (info->instance_id == event->server_inst) {
1688 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1689 __bt_gatt_handle_pending_request_info(result, BT_DISCONNECT_LE,
1690 (bluetooth_device_address_t*)&dev_addr, sizeof(bluetooth_device_address_t));
1696 /* Send event to BT-API */
1697 _bt_convert_addr_type_to_string(address,
1698 (unsigned char *)dev_addr.addr);
1700 BT_INFO("GATT Server DisConnected: Remote Client addr[%s] Server Instance [%d] Connection ID [%d]",
1701 address, event->server_inst, event->conn_id);
1703 param = g_variant_new("(is)", result, address);
1704 /* Send event to application */
1705 _bt_send_event(BT_GATT_SERVER_EVENT,
1706 BLUETOOTH_EVENT_GATT_DISCONNECTED,
1709 /* Remove Connection info */
1710 conn_info = _bt_find_remote_gatt_client_info(address);
1712 BT_INFO("Remove GATT client info from List..");
1713 /* Remove info from List */
1714 gatt_client_info_list = g_slist_remove(gatt_client_info_list, conn_info);
1715 BT_INFO("Total num of connected GATT clients [%d]", g_slist_length(gatt_client_info_list));
1716 g_free(conn_info->addr);
1725 static void __bt_handle_gatt_server_acquire_write_requested(event_gatts_srvc_acquire_attr_t *event)
1727 GVariant *param = NULL;
1728 int result = BLUETOOTH_ERROR_NONE;
1729 struct gatt_server_req_info *req_info = NULL;
1730 bluetooth_device_address_t dev_addr;
1731 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
1733 BT_INFO("GATT Server ACQUIRE Write Req Connection ID: [%d]", event->attr_trans.conn_id);
1734 BT_INFO("GATT Server ACQUIRE Write Req Transaction ID:[%d]", event->attr_trans.trans_id);
1735 BT_INFO("GATT Server ACQUIRE Write Req Attribute Handle: [%d]", event->attr_trans.attr_handle);
1737 //address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1738 memcpy(dev_addr.addr, event->address.addr, 6);
1740 req_info = g_new0(struct gatt_server_req_info, 1);
1741 req_info->request_id = event->attr_trans.trans_id;
1742 req_info->attribute_handle = event->attr_trans.attr_handle;
1743 req_info->connection_id = event->attr_trans.conn_id;
1744 req_info->request_type = BLUETOOTH_GATT_REQUEST_TYPE_ACQUIRE_WRITE;
1745 gatt_server_requests = g_slist_append(gatt_server_requests, req_info);
1747 _bt_convert_addr_type_to_string(address,
1748 (unsigned char *)dev_addr.addr);
1750 param = g_variant_new("(iiiiiis)", result,
1751 event->attr_trans.conn_id,
1752 event->attr_trans.trans_id,
1753 event->attr_trans.attr_handle,
1754 event->mtu, event->attr_trans.offset, address);
1755 BT_INFO("GATT Server ACQUIRE Write Req Attribute remote address : [%s]", address);
1757 _bt_send_event(BT_GATT_SERVER_EVENT,
1758 BLUETOOTH_EVENT_GATT_SERVER_ACQUIRE_WRITE,
1763 static void __bt_handle_gatt_server_acquire_notify_requested(event_gatts_srvc_acquire_attr_t *event)
1765 GVariant *param = NULL;
1766 int result = BLUETOOTH_ERROR_NONE;
1767 struct gatt_server_req_info *req_info = NULL;
1768 bluetooth_device_address_t dev_addr;
1769 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
1771 BT_INFO("GATT Server ACQUIRE Notify Req Connection ID: [%d]", event->attr_trans.conn_id);
1772 BT_INFO("GATT Server ACQUIRE Notify Req Transaction ID:[%d]", event->attr_trans.trans_id);
1773 BT_INFO("GATT Server ACQUIRE Notify Req Attribute Handle: [%d]", event->attr_trans.attr_handle);
1774 BT_INFO("GATT Server ACQUIRE notify Req address : [%s]", address);
1776 memcpy(dev_addr.addr, event->address.addr, 6);
1777 _bt_convert_addr_type_to_string(address,
1778 (unsigned char *)dev_addr.addr);
1779 BT_INFO("GATT Server ACQUIRE notify Req remote address : [%s]", address);
1781 req_info = g_new0(struct gatt_server_req_info, 1);
1782 req_info->request_id = event->attr_trans.trans_id;
1783 req_info->attribute_handle = event->attr_trans.attr_handle;
1784 req_info->connection_id = event->attr_trans.conn_id;
1785 req_info->request_type = BLUETOOTH_GATT_REQUEST_TYPE_ACQUIRE_NOTIFY;
1786 gatt_server_requests = g_slist_append(gatt_server_requests, req_info);
1788 param = g_variant_new("(iiiiiis)", result,
1789 event->attr_trans.conn_id,
1790 event->attr_trans.trans_id,
1791 event->attr_trans.attr_handle,
1792 event->mtu, event->attr_trans.offset,
1795 BT_INFO("GATT Server ACQUIRE Notify Req Attribute : ");
1797 _bt_send_event(BT_GATT_SERVER_EVENT,
1798 BLUETOOTH_EVENT_GATT_SERVER_ACQUIRE_NOTIFY,
1802 static void __bt_handle_gatt_server_write_requested(event_gatts_srvc_write_attr_t *event)
1805 bluetooth_device_address_t dev_addr;
1806 GVariant *param = NULL;
1807 int result = BLUETOOTH_ERROR_NONE;
1809 gboolean is_prepare_write;
1811 GVariant *data = NULL;
1813 struct gatt_server_req_info *req_info = NULL;
1814 BT_INFO("GATT Server Write Requested");
1816 memcpy(dev_addr.addr, event->address.addr, 6);
1818 BT_INFO("GATT Server Write Req Connection ID: [%d]", event->attr_trans.conn_id);
1819 BT_INFO("GATT Server Write Req Transaction ID:[%d]", event->attr_trans.trans_id);
1820 BT_INFO("GATT Server Write Req Attribute Handle: [%d]", event->attr_trans.attr_handle);
1821 BT_INFO("GATT Server Write Req Attribute Offset: [%d]", event->attr_trans.offset);
1822 BT_INFO("GATT Server Write Req value length [%d]", event->length);
1823 BT_INFO("GATT Server Write Req needs response: [%d]", event->need_rsp);
1824 BT_INFO("GATT Server Write Req Is Prep: [%d]", event->is_prep);
1826 if (event->length <= 0) {
1827 BT_INFO("GATT Server write requested, but length of attr value is 0");
1831 need_resp = event->need_rsp;
1832 is_prepare_write = event->is_prep;
1834 write_val = g_memdup(&event->value[0], event->length);
1836 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1837 _bt_convert_addr_type_to_string(address,
1838 (unsigned char *)dev_addr.addr);
1840 BT_INFO("GATT Server Write Request from remote client [%s]", address);
1842 if (event->length > 0) {
1843 for (i = 0; i < event->length; i++)
1844 BT_DBG("Data[%d] = [0x%x]", i, event->value[i]);
1846 /* Save Write Request Info */
1847 req_info = g_new0(struct gatt_server_req_info, 1);
1848 req_info->request_id = event->attr_trans.trans_id;
1849 req_info->attribute_handle = event->attr_trans.attr_handle;
1850 req_info->connection_id = event->attr_trans.conn_id;
1851 req_info->addr = address;
1852 req_info->offset = event->attr_trans.offset;
1853 req_info->request_type = BLUETOOTH_GATT_REQUEST_TYPE_WRITE;
1854 gatt_server_requests = g_slist_append(gatt_server_requests, req_info);
1856 data = g_variant_new_from_data(
1857 G_VARIANT_TYPE_BYTESTRING,
1862 param = g_variant_new("(iiiiiibbsn@ay)", result,
1863 event->attr_trans.conn_id,
1864 event->attr_trans.trans_id,
1865 event->attr_trans.attr_handle,
1866 event->attr_trans.offset,
1874 _bt_send_event(BT_GATT_SERVER_EVENT,
1875 BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED,
1881 static void __bt_handle_gatt_server_read_requested(event_gatts_srvc_read_attr_t *event)
1883 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1884 bluetooth_device_address_t dev_addr;
1885 int result = BLUETOOTH_ERROR_NONE;
1886 struct gatt_server_req_info *req_info = NULL;
1887 GVariant *param = NULL;
1889 BT_INFO("GATT Server Read Requested");
1891 memcpy(dev_addr.addr, event->address.addr, 6);
1893 BT_INFO("GATT Server-Client Connection ID: [%d]", event->attr_trans.conn_id);
1894 BT_INFO("GATT Server-Client Transaction ID: [%d]", event->attr_trans.trans_id);
1895 BT_INFO("GATT Server Attribute Handle: [%d]", event->attr_trans.attr_handle);
1896 BT_INFO("GATT Server Attribute Offset for read: [%d]", event->attr_trans.offset);
1897 BT_INFO("GATT Server Attribute is long: [%d]", event->is_long);
1899 is_long = event->is_long;
1901 /* Save Read Request Info */
1902 req_info = g_new0(struct gatt_server_req_info, 1);
1903 req_info->request_id = event->attr_trans.trans_id;
1904 req_info->attribute_handle = event->attr_trans.attr_handle;
1905 req_info->connection_id = event->attr_trans.conn_id;
1906 req_info->addr = address;
1907 req_info->offset = event->attr_trans.offset;
1908 req_info->request_type = BLUETOOTH_GATT_REQUEST_TYPE_READ;
1909 gatt_server_requests = g_slist_append(gatt_server_requests, req_info);
1911 /* Send event to BT-API */
1912 _bt_convert_addr_type_to_string(address,
1913 (unsigned char *)dev_addr.addr);
1915 BT_INFO("GATT Server Read Request from remote client [%s]", address);
1917 param = g_variant_new("(iiiiibs)", result,
1918 event->attr_trans.conn_id,
1919 event->attr_trans.trans_id,
1920 event->attr_trans.attr_handle,
1921 event->attr_trans.offset,
1925 _bt_send_event(BT_GATT_SERVER_EVENT,
1926 BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED,
1930 static void __bt_handle_gatt_server_indicate_confirmed(event_gatts_ind_cnfrm_t *event)
1932 bluetooth_device_address_t dev_addr;
1933 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1934 int cur_connected_clients;
1935 static int recvd = 0;
1936 gboolean completed = 0;
1937 GVariant *param = NULL;
1939 /* OAL event does provide error, so MW assumes event will never contain wrong data,
1940 incase of any issues, check with OAL */
1941 int result = BLUETOOTH_ERROR_NONE;
1943 memcpy(dev_addr.addr, event->address.addr, 6);
1944 _bt_convert_addr_type_to_string(address,
1945 (unsigned char *)dev_addr.addr);
1947 BT_INFO("Indication sent to GATT client [%s] conn_ ID [%d] transaction ID [%d] Att handle [%d]",
1948 address, event->conn_id, event->trans_id, event->attr_handle);
1951 cur_connected_clients = g_slist_length(gatt_client_info_list);
1952 BT_INFO("Number of connected clients during sending Indication [%d] & current connected count [%d]",
1953 num_indicate_clients, cur_connected_clients);
1956 if (recvd == num_indicate_clients) {
1957 BT_INFO("Gatt indication confirm event for last GATT client.. [%s]", address);
1958 completed = 1; /* Last event */
1959 recvd = 0; /* Reset */
1960 num_indicate_clients = 0;
1963 param = g_variant_new("(isib)",
1969 /* Send event to BT-API */
1970 _bt_send_event(BT_GATT_SERVER_EVENT,
1971 BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_COMPLETED,
1974 BT_INFO("Received Indication confirm for client number [%d]", recvd);
1978 /* Tizen Platform Specific */
1979 static void __bt_handle_gatt_server_notification_changed(event_gatts_notif_t *event)
1981 bluetooth_device_address_t dev_addr;
1982 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1983 GVariant *param = NULL;
1986 /* OAL event does provide error, so MW assumes event will never contain wrong data,
1987 incase of any issues, check with OAL */
1988 int result = BLUETOOTH_ERROR_NONE;
1990 memcpy(dev_addr.addr, event->address.addr, 6);
1991 _bt_convert_addr_type_to_string(address,
1992 (unsigned char *)dev_addr.addr);
1994 BT_INFO("notification_changed [%s] conn_ ID [%d] transaction ID [%d] Att handle [%d] Notify[%d]",
1995 address, event->conn_id, event->trans_id, event->attr_handle, event->notify);
1997 /* Set Notifcation status */
1998 notify = event->notify;
2000 param = g_variant_new("(isib)",
2006 /* Send event to BT-API */
2007 _bt_send_event(BT_GATT_SERVER_EVENT,
2008 BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED,
2014 static void __bt_handle_gatt_mtu_changed_event(event_gatts_mtu_changed_t *event)
2016 int result = BLUETOOTH_ERROR_NONE;
2017 struct gatt_client_info_t *conn_info = NULL;
2018 GVariant *param = NULL;
2021 conn_info = __bt_find_remote_gatt_client_info_from_conn_id(event->conn_id);
2022 if (conn_info == NULL) {
2023 BT_ERR("Cant find connection Information");
2026 BT_INFO("Got connection Info GATT client [%s] MTU Size [%d]",
2027 conn_info->addr, event->mtu_size);
2029 __bt_update_mtu_gatt_device(conn_info->addr, event->mtu_size);
2031 param = g_variant_new("(isqy)",
2037 /* Send event to BT-API */
2038 _bt_send_event(BT_GATT_SERVER_EVENT,
2039 BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED,
2043 static void __bt_gatt_event_handler(int event_type, gpointer event_data)
2045 BT_INFO("OAL event = 0x%x, \n", event_type);
2046 switch (event_type) {
2047 case OAL_EVENT_BLE_SERVER_INSTANCE_INITIALISED: {
2048 BT_INFO("OAL Event: Server Instance Registered");
2049 /* GATT Server Registered event is handled in MAIN thread context */
2050 __bt_handle_server_instance_registered((event_gatts_register_t *)event_data);
2053 case OAL_EVENT_GATTS_SERVICE_ADDED: {
2054 BT_INFO("OAL Event: GATT Service added");
2055 __bt_handle_gatt_server_service_added((event_gatts_srvc_prm_t *)event_data);
2058 case OAL_EVENT_GATTS_CHARACTERISTIC_ADDED: {
2059 BT_INFO("OAL Event: GATT characteristic added");
2060 __bt_handle_gatt_server_characteristic_added((event_gatts_srvc_charctr_t *)event_data);
2063 case OAL_EVENT_GATTS_DESCRIPTOR_ADDED: {
2064 BT_INFO("OAL Event: GATT descriptor added");
2065 __bt_handle_gatt_server_descriptor_added((event_gatts_srvc_descr_t *)event_data);
2068 case OAL_EVENT_GATTS_SERVICE_STARTED: {
2069 BT_INFO("OAL Event: GATT Service started");
2070 __bt_handle_gatt_server_service_started((event_gatts_srvc_t *)event_data);
2073 case OAL_EVENT_GATTS_SERVICE_STOPED: {
2074 BT_INFO("OAL Event: GATT Service stopped");
2075 __bt_handle_gatt_server_service_stopped((event_gatts_srvc_t *)event_data);
2078 case OAL_EVENT_GATTS_SERVICE_DELETED: {
2079 BT_INFO("OAL Event: GATT Service deleted");
2080 __bt_handle_gatt_server_service_deleted((event_gatts_srvc_t *) event_data);
2083 case OAL_EVENT_GATTS_CONNECTION_COMPLETED: {
2084 BT_INFO("OAL Event: GATT Server Connected");
2085 __bt_handle_gatt_server_connection_state((event_gatts_conn_t *)event_data);
2088 case OAL_EVENT_GATTS_DISCONNECTION_COMPLETED: {
2089 BT_INFO("OAL Event: GATT Server Disconnected");
2090 __bt_handle_gatt_server_disconnection_state((event_gatts_conn_t *)event_data);
2093 case OAL_EVENT_GATTS_REQUEST_READ: {
2094 BT_INFO("OAL Event: GATT Server Read Request");
2095 __bt_handle_gatt_server_read_requested((event_gatts_srvc_read_attr_t *)event_data);
2098 case OAL_EVENT_GATTS_REQUEST_WRITE: {
2099 BT_INFO("OAL Event: GATT Server Write Request");
2100 __bt_handle_gatt_server_write_requested((event_gatts_srvc_write_attr_t *)event_data);
2103 case OAL_EVENT_GATTS_REQUEST_ACQUIRE_WRITE: {
2104 BT_INFO("OAL Event: GATT Server Acquire Write Request");
2105 __bt_handle_gatt_server_acquire_write_requested((event_gatts_srvc_acquire_attr_t*)event_data);
2108 case OAL_EVENT_GATTS_REQUEST_ACQUIRE_NOTIFY: {
2109 BT_INFO("OAL Event: GATT ServerAcquire Notify Request");
2110 __bt_handle_gatt_server_acquire_notify_requested((event_gatts_srvc_acquire_attr_t*)event_data);
2113 case OAL_EVENT_GATTS_IND_CONFIRM: {
2114 BT_INFO("OAL Event: GATT Server Indication confirmed");
2115 __bt_handle_gatt_server_indicate_confirmed((event_gatts_ind_cnfrm_t *)event_data);
2118 case OAL_EVENT_GATTS_NOTIFICATION: { /* Tizen Platform Specific */
2119 BT_INFO("OAL Event: GATT Server DisConnected");
2120 __bt_handle_gatt_server_notification_changed((event_gatts_notif_t *)event_data);
2123 case OAL_EVENT_GATTS_MTU_CHANGED: {
2124 BT_INFO("OAL Event: GATT Server MTU changed event callback");
2125 __bt_handle_gatt_mtu_changed_event((event_gatts_mtu_changed_t *)event_data);
2128 #ifdef TIZEN_GATT_CLIENT
2129 case OAL_EVENT_GATTC_REGISTRATION: {
2130 BT_INFO("OAL Event: GATT Client instance Registered");
2131 __bt_handle_client_instance_registered((event_gattc_register_t *) event_data);
2134 case OAL_EVENT_GATTC_CONNECTION_COMPLETED: {
2135 BT_INFO("OAL Event: GATT Client Connected");
2136 __bt_handle_client_connected((event_gattc_conn_t *) event_data);
2139 case OAL_EVENT_GATTC_DISCONNECTION_COMPLETED: {
2140 BT_INFO("OAL Event: GATT Client DisConnected");
2141 __bt_handle_client_disconnected((event_gattc_conn_t *) event_data);
2144 case OAL_EVENT_GATTC_SERVICE_SEARCH_RESULT: {
2145 BT_INFO("OAL Event: GATT Client Service Search Result");
2146 __bt_handle_client_service_search_result((event_gattc_service_result_t *) event_data);
2149 case OAL_EVENT_GATTC_SERVICE_SEARCH_DONE: {
2150 BT_INFO("OAL Event: GATT Client Service Completed");
2151 __bt_handle_client_service_search_completed((event_gattc_conn_status_t *) event_data);
2154 case OAL_EVENT_GATTC_CHARAC_SERACH_RESULT: {
2155 BT_INFO("OAL Event: GATT Client Characteristic Search Result");
2156 __bt_handle_client_characteristic_search_result((event_gattc_characteristic_result_t *) event_data);
2159 case OAL_EVENT_GATTC_DESC_SERACH_RESULT: {
2160 BT_INFO("OAL Event: GATT Client Descriptor Search Result");
2161 __bt_handle_client_descriptor_search_result((event_gattc_descriptor_result_t *) event_data);
2164 case OAL_EVENT_GATTC_READ_CHARAC: {
2165 BT_INFO("OAL Event: GATT Client Characteristic Read Data");
2166 __bt_handle_client_characteristic_read_data((event_gattc_read_data *) event_data);
2169 case OAL_EVENT_GATTC_READ_DESCR: {
2170 BT_INFO("OAL Event: GATT Client Descriptor Read Data");
2171 __bt_handle_client_descriptor_read_data((event_gattc_read_data *) event_data);
2174 case OAL_EVENT_GATTC_WRITE_CHARAC: {
2175 BT_INFO("OAL Event: GATT Client Characteristic Write Data");
2176 __bt_handle_client_characteristic_write_data((event_gattc_write_data *) event_data);
2179 case OAL_EVENT_GATTC_WRITE_DESCR: {
2180 BT_INFO("OAL Event: GATT Client Descriptor Write Data");
2181 __bt_handle_client_descriptor_write_data((event_gattc_write_data *) event_data);
2184 case OAL_EVENT_DEVICE_LE_DISCONNECTED: {
2185 BT_INFO("OAL Event: LE device disconnected");
2186 __bt_hanlde_le_device_disconnection((event_dev_conn_status_t *)event_data);
2189 case OAL_EVENT_GATTC_NOTIFICATION_REGISTERED: {
2190 BT_INFO("OAL Event: GATT Client Notification Registered");
2191 __bt_handle_client_notification_registered((event_gattc_regdereg_notify_t *) event_data, TRUE);
2194 case OAL_EVENT_GATTC_NOTIFICATION_DEREGISTERED: {
2195 BT_INFO("OAL Event: GATT Client Notification Registered");
2196 __bt_handle_client_notification_registered((event_gattc_regdereg_notify_t *) event_data, FALSE);
2199 case OAL_EVENT_GATTC_NOTIFY_DATA: {
2200 BT_INFO("OAL Event: GATT Client Notification Data");
2201 __bt_handle_client_notification_data((event_gattc_notify_data *) event_data);
2204 case OAL_EVENT_GATTC_SERVICE_CHANGED_IND: {
2205 BT_INFO("OAL Event: GATT Client service changed indication");
2206 __bt_handle_client_service_changed_ind((event_gattc_service_changed_data *)event_data);
2209 case OAL_EVENT_GATTC_MTU_EXCHANGE_COMPLETED: {
2210 BT_INFO("OAL Event: GATT Client MTU Exchange Complete");
2211 __bt_handle_client_mtu_exchange_completed((event_gattc_mtu_configured_t *) event_data);
2220 int _bt_gatt_server_add_service(char *sender, int service_type,
2221 int num_handles, char *svc_uuid, int instance_id)
2223 BT_CHECK_PARAMETER(svc_uuid, return);
2224 BT_CHECK_PARAMETER(sender, return);
2225 int ret = OAL_STATUS_SUCCESS;
2227 oal_gatt_srvc_id_t svc_data;
2229 svc_data.is_prmry = service_type;
2230 svc_data.id.inst_id = instance_id;
2232 BT_INFO("Service UUID [%s] Num handles [%d] Instance ID [%d]", svc_uuid, num_handles, instance_id);
2233 _bt_string_to_uuid(svc_uuid, (service_uuid_t*)&svc_data.id.uuid);
2235 ret = gatts_add_service(instance_id, &svc_data, num_handles);
2236 if (ret != OAL_STATUS_SUCCESS) {
2237 BT_ERR("ret: %d", ret);
2238 return BLUETOOTH_ERROR_INTERNAL;
2241 return BLUETOOTH_ERROR_NONE;
2245 int _bt_gatt_server_add_included_service(char *sender, int instance_id,
2246 int service_handle, int included_svc_handle)
2248 BT_CHECK_PARAMETER(sender, return);
2249 int ret = OAL_STATUS_SUCCESS;
2251 ret = gatts_add_included_services(instance_id, service_handle, included_svc_handle);
2252 if (ret != OAL_STATUS_SUCCESS) {
2253 BT_ERR("ret: %d", ret);
2254 return BLUETOOTH_ERROR_INTERNAL;
2256 return BLUETOOTH_ERROR_NONE;
2259 int _bt_gatt_server_add_characteristic(char *sender, char *char_uuid,
2260 bluetooth_gatt_server_attribute_params_t *param)
2262 BT_CHECK_PARAMETER(char_uuid, return);
2263 BT_CHECK_PARAMETER(sender, return);
2264 BT_CHECK_PARAMETER(param, return);
2265 int ret = OAL_STATUS_SUCCESS;
2267 oal_uuid_t uuid = {{0} };
2269 BT_INFO("Char UUID [%s] Instance ID [%d]", char_uuid, param->instance_id);
2270 _bt_string_to_uuid(char_uuid, (service_uuid_t*)&uuid);
2272 BT_INFO("Char permission From API [0x%x]", param->permissions);
2274 ret = gatts_add_characteristics(param->instance_id, param->service_handle, &uuid,
2275 param->properties, (int)param->permissions);
2276 if (ret != OAL_STATUS_SUCCESS) {
2277 BT_ERR("ret: %d", ret);
2278 return BLUETOOTH_ERROR_INTERNAL;
2280 return BLUETOOTH_ERROR_NONE;
2283 int _bt_gatt_server_add_descriptor(char *sender, char *desc_uuid,
2284 bt_gatt_permission_t *param, int service_handle, int instance_id)
2286 BT_CHECK_PARAMETER(desc_uuid, return);
2287 BT_CHECK_PARAMETER(sender, return);
2288 BT_CHECK_PARAMETER(param, return);
2289 int ret = OAL_STATUS_SUCCESS;
2291 oal_uuid_t uuid = {{0} };
2293 BT_INFO("Descriptor UUID [%s] Instance ID [%d] Service handle [%d]",
2294 desc_uuid, service_handle, instance_id);
2296 _bt_string_to_uuid(desc_uuid, (service_uuid_t*)&uuid);
2298 BT_INFO("Descriptor permission From API [0x%x]", *param);
2299 ret = gatts_add_descriptor(instance_id, service_handle, &uuid, (int)*param);
2301 if (ret != OAL_STATUS_SUCCESS) {
2302 BT_ERR("ret: %d", ret);
2303 return BLUETOOTH_ERROR_INTERNAL;
2305 return BLUETOOTH_ERROR_NONE;
2308 int _bt_gatt_server_start_service(char *sender, int service_handle, int instance_id)
2310 BT_CHECK_PARAMETER(sender, return);
2311 int ret = OAL_STATUS_SUCCESS;
2313 ret = gatts_start_service(instance_id, service_handle, BT_GATT_TRANSPORT_LE);
2314 if (ret != OAL_STATUS_SUCCESS) {
2315 BT_ERR("ret: %d", ret);
2316 return BLUETOOTH_ERROR_INTERNAL;
2318 return BLUETOOTH_ERROR_NONE;
2321 int _bt_gatt_server_stop_service(char *sender, int service_handle, int instance_id)
2323 BT_CHECK_PARAMETER(sender, return);
2324 int ret = OAL_STATUS_SUCCESS;
2326 ret = gatts_stop_service(instance_id, service_handle);
2327 if (ret != OAL_STATUS_SUCCESS) {
2328 BT_ERR("ret: %d", ret);
2329 return BLUETOOTH_ERROR_INTERNAL;
2331 return BLUETOOTH_ERROR_NONE;
2334 int _bt_gatt_server_delete_service(char *sender, int service_handle, int instance_id)
2336 BT_CHECK_PARAMETER(sender, return);
2337 int ret = OAL_STATUS_SUCCESS;
2341 ret = gatts_delete_service(instance_id, service_handle);
2342 if (ret != OAL_STATUS_SUCCESS) {
2343 BT_ERR("ret: %d", ret);
2344 return BLUETOOTH_ERROR_INTERNAL;
2347 /* Remove the Service Handle */
2348 for (l = numapps[instance_id].service_handles; l != NULL;) {
2350 l = g_slist_next(l);
2351 if (handle && *handle == service_handle) {
2352 BT_INFO("Remove Service handle [%d]", *handle);
2353 numapps[instance_id].service_handles = g_slist_remove(numapps[instance_id].service_handles, handle);
2359 return BLUETOOTH_ERROR_NONE;
2362 int _bt_gatt_server_send_response(char *sender, bluetooth_gatt_att_data_t *data,
2363 bluetooth_gatt_server_response_params_t *param)
2365 BT_CHECK_PARAMETER(sender, return);
2366 BT_CHECK_PARAMETER(data, return);
2367 BT_CHECK_PARAMETER(param, return);
2368 struct gatt_server_req_info *req_info = NULL;
2369 int ret = OAL_STATUS_SUCCESS;
2371 oal_gatt_response_t response;
2373 BT_INFO("GATT Server Response: Req Type [%d] req_id [%d] status [%d] auth_req [%d] offset[%d] data len[%d]",
2374 param->req_type, param->request_id,
2375 param->response_status, param->auth_req,
2376 data->offset, data->length);
2378 /* Search for matching Request in List */
2379 req_info = __bt_gatt_server_find_request_info(param->request_id, param->req_type);
2381 BT_ERR("GATT Server Req Info not found for current response..return Error");
2382 return BLUETOOTH_ERROR_NOT_IN_OPERATION;
2385 memset(&response, 0x00, sizeof(oal_gatt_response_t));
2387 response.handle = req_info->attribute_handle;
2388 response.attr_value.auth_req = param->auth_req;
2389 response.attr_value.handle = req_info->attribute_handle;
2390 response.attr_value.offset = data->offset;
2391 response.attr_value.len = data->length;
2392 memcpy(&response.attr_value.value, &data->data, data->length);
2395 ret = gatts_send_response(req_info->connection_id, param->request_id,
2396 param->response_status, &response);
2398 if (ret != OAL_STATUS_SUCCESS) {
2399 BT_ERR("ret: %d", ret);
2400 return BLUETOOTH_ERROR_INTERNAL;
2403 BT_INFO("GATT Server Response successfully sent");
2404 /* Remove GATT server request from list */
2405 gatt_server_requests = g_slist_remove(gatt_server_requests, req_info);
2406 g_free(req_info->addr);
2408 return BLUETOOTH_ERROR_NONE;
2411 int _bt_gatt_server_acquire_send_response(char *sender, bluetooth_gatt_server_acquire_response_params_t *param , void *fd_list)
2413 BT_CHECK_PARAMETER(sender, return);
2414 BT_CHECK_PARAMETER(param, return);
2415 struct gatt_server_req_info *req_info = NULL;
2416 int ret = OAL_STATUS_SUCCESS;
2419 BT_INFO("GATT acquire Server Response: Req Type [%d] req_id [%d] fd [%d] mtu[%d]",
2420 param->req_type, param->request_id,
2424 /* Search for matching Request in List */
2425 req_info = __bt_gatt_server_find_request_info(param->request_id, param->req_type);
2427 BT_ERR("GATT acquire Server Req Info not found for current response..return Error");
2428 return BLUETOOTH_ERROR_NOT_IN_OPERATION;
2431 ret = gatt_send_response_acquire(req_info->connection_id, param->request_id, 0, param->fd, param->mtu, fd_list);
2433 if (ret != OAL_STATUS_SUCCESS) {
2434 BT_ERR("ret: %d", ret);
2435 return BLUETOOTH_ERROR_INTERNAL;
2438 BT_INFO("GATT acquire Server Response successfully sent");
2439 /* Remove GATT server request from list */
2440 gatt_server_requests = g_slist_remove(gatt_server_requests, req_info);
2441 g_free(req_info->addr);
2443 return BLUETOOTH_ERROR_NONE;
2448 int _bt_gatt_server_send_indication(char *sender, bluetooth_device_address_t *dev_addr,
2449 bluetooth_gatt_att_data_t *data,
2450 bluetooth_gatt_server_indication_params_t *param)
2452 BT_CHECK_PARAMETER(sender, return);
2453 BT_CHECK_PARAMETER(data, return);
2454 BT_CHECK_PARAMETER(param, return);
2456 gboolean all_send = FALSE;
2457 int ret = OAL_STATUS_SUCCESS;
2458 struct gatt_client_info_t *conn;
2460 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2461 _bt_convert_addr_type_to_string(address, dev_addr->addr);
2463 if (memcmp(dev_addr->addr, BDADDR_ANY, 6) == 0) {
2464 BT_INFO("GATT Server: Send Indication to all connected GATT clients..");
2467 BT_INFO("GATT Server: Send Indication to connected GATT client addr [%s]", address);
2470 /* Attempt to send Notification/Indication to all Connected GATT clients */
2472 ret = __bt_gatt_send_indication_to_all_connected_clients(data, param);
2473 if (ret != OAL_STATUS_SUCCESS) {
2474 BT_ERR("ret: %d", ret);
2476 return BLUETOOTH_ERROR_INTERNAL;
2480 conn = _bt_find_remote_gatt_client_info(address);
2482 ret = gatts_send_indication(param->instance_id, param->atrribute_handle,
2483 conn->connection_id, data->length,
2484 param->need_confirmation, (char *)(&data->data[0]));
2486 if (ret != OAL_STATUS_SUCCESS) {
2487 BT_ERR("ret: %d", ret);
2488 BT_INFO("Indication failed to send to Remote GATT Client [%s]", address);
2490 return BLUETOOTH_ERROR_INTERNAL;
2492 BT_INFO("Indication sent to Remote GATT Client [%s] wait for Notification completed event from OAL", address);
2494 num_indicate_clients = 1;
2495 return BLUETOOTH_ERROR_NONE;
2497 BT_ERR("Remote GATT client [%s] is not connected..Cant send Indication!!", address);
2499 return BLUETOOTH_ERROR_NOT_CONNECTED;
2502 return BLUETOOTH_ERROR_NONE;
2505 int _bt_gatt_server_update_attribute_value(char *sender, int instance_id,
2506 bluetooth_gatt_server_update_value_t *param)
2508 BT_CHECK_PARAMETER(sender, return);
2509 BT_CHECK_PARAMETER(param, return);
2510 int ret = OAL_STATUS_SUCCESS;
2512 oal_gatt_value_t value;
2513 BT_INFO("GATT Server Update value: Instance ID [%d] attr handle [%d] Value len [%d]",
2514 instance_id, param->attribute_handle, param->length);
2517 memset(&value, 0x00, sizeof(oal_gatt_value_t));
2519 value.handle = param->attribute_handle;
2520 value.len = param->length;
2521 memcpy(&value.value, ¶m->data.data, param->length);
2523 ret = gatts_update_att_value(instance_id, &value);
2525 if (ret != OAL_STATUS_SUCCESS) {
2526 BT_ERR("ret: %d", ret);
2527 return BLUETOOTH_ERROR_INTERNAL;
2530 BT_INFO("GATT Server Update Attribute Value successfully");
2531 return BLUETOOTH_ERROR_NONE;
2534 int _bt_request_att_mtu(bluetooth_device_address_t *device_address,
2537 struct gatt_server_info_t *conn_info = NULL;
2539 int ret = OAL_STATUS_SUCCESS;
2541 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
2542 _bt_convert_addr_type_to_string(addr, device_address->addr);
2544 /* Check if remote GATT Server is connected or not */
2545 conn_info = _bt_find_remote_gatt_server_info(addr);
2547 BT_INFO("GATT Server [%s] is connected, conn Id [%d]",
2548 conn_info->addr, conn_info->connection_id);
2550 BT_ERR("GATT Server is not yet connected..");
2552 return BLUETOOTH_ERROR_NOT_CONNECTED;
2555 ret = gattc_configure_mtu(conn_info->connection_id, mtu);
2556 if (ret != OAL_STATUS_SUCCESS) {
2557 BT_ERR("ret: %d", ret);
2559 return BLUETOOTH_ERROR_INTERNAL;
2563 return BLUETOOTH_ERROR_NONE;
2566 int _bt_get_att_mtu(bluetooth_device_address_t *address,
2569 BT_CHECK_PARAMETER(address, return);
2570 BT_CHECK_PARAMETER(mtu, return);
2571 struct gatt_client_info_t *conn_info = NULL;
2572 char addr[BT_ADDRESS_STRING_SIZE] = { 0 };
2573 int ret = OAL_STATUS_SUCCESS;
2576 _bt_convert_addr_type_to_string(addr, address->addr);
2578 BT_INFO("Get current MTU size for the remote client:DevAddress:[%s]", addr);
2580 conn_info = _bt_find_remote_gatt_client_info(addr);
2582 BT_INFO("GATT Client [%s] is connected, conn Id [%d] Instance ID [%d]",
2583 conn_info->addr, conn_info->connection_id, conn_info->instance_id);
2585 BT_ERR("GATT Client [%s] is not yet connected..", addr);
2586 return BLUETOOTH_ERROR_NOT_CONNECTED;
2589 ret = gatts_get_att_mtu(conn_info->connection_id, &stack_mtu);
2590 if (ret != OAL_STATUS_SUCCESS) {
2591 BT_ERR("ret: %d", ret);
2592 return BLUETOOTH_ERROR_INTERNAL;
2595 BT_INFO("ATT MTU received from OAL [%d]", stack_mtu);
2596 *mtu = (unsigned int)stack_mtu;
2599 BT_ERR("MTU value is zero, GATT Client [%s] is not yet connected..", addr);
2600 return BLUETOOTH_ERROR_NOT_CONNECTED;
2603 return BLUETOOTH_ERROR_NONE;
2606 #ifdef TIZEN_GATT_CLIENT
2607 /* GATT Client utility static functions */
2608 static bt_gatt_service_info_list_t *__bt_get_service_info_list(int conn_id)
2611 bt_gatt_service_info_list_t *info = NULL;
2613 for (l = list_gatt_info; l != NULL; l = g_slist_next(l)) {
2614 info = (bt_gatt_service_info_list_t *)l->data;
2618 if (info->conn_id == conn_id)
2625 static bt_gatt_service_info_t *__bt_find_matching_service(
2626 bt_gatt_service_info_list_t *svc_list, oal_gatt_srvc_id_t *svc)
2629 bt_gatt_service_info_t *info = NULL;
2631 for (l = svc_list->services; l != NULL; l = g_slist_next(l)) {
2632 info = (bt_gatt_service_info_t *)l->data;
2636 /* Match UUID and instance ID */
2637 if (!memcmp(&svc->id.uuid.uuid, &info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN)
2638 && (svc->id.inst_id == info->inst_id)) {
2645 static bt_gatt_char_info_t *__bt_find_matching_charc(
2646 bt_gatt_service_info_t *svc_info, oal_gatt_id_t *charc)
2649 bt_gatt_char_info_t *info = NULL;
2651 for (l = svc_info->chars; l != NULL; l = g_slist_next(l)) {
2652 info = (bt_gatt_char_info_t *)l->data;
2656 /* Match UUID and instance ID */
2657 if (!memcmp(&charc->uuid.uuid, &info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN)
2658 && (charc->inst_id == info->inst_id)) {
2665 static bt_gatt_descriptor_info_t *__bt_find_matching_desc(
2666 bt_gatt_char_info_t *char_info, oal_gatt_id_t *desc)
2669 bt_gatt_descriptor_info_t *info = NULL;
2671 for (l = char_info->descs; l != NULL; l = g_slist_next(l)) {
2672 info = (bt_gatt_descriptor_info_t *)l->data;
2676 /* Match UUID and instance ID */
2677 if (!memcmp(&desc->uuid, &info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN)
2678 && (desc->inst_id == info->inst_id)) {
2686 static struct gatt_server_info_t *__bt_find_remote_gatt_server_info_from_conn_id(int conn_id)
2689 struct gatt_server_info_t *info = NULL;
2691 for (l = gatt_server_info_list; l != NULL; l = g_slist_next(l)) {
2692 info = (struct gatt_server_info_t*)l->data;
2696 if (info->connection_id == conn_id) {
2697 BT_INFO("Remote GATT server found addr[%s]", info->addr);
2704 static bt_gatt_service_info_t* __bt_find_removed_service(bt_gatt_service_info_list_t *svc_list)
2707 bt_gatt_service_info_t *info = NULL;
2709 for (l = svc_list->services; l != NULL; l = g_slist_next(l)) {
2710 info = (bt_gatt_service_info_t*)l->data;
2714 /* Service is marked a removed */
2715 if (info->is_removed == 1)
2721 static void __bt_remove_service_info_from_list(bt_gatt_service_info_t *svc_info)
2727 bt_gatt_char_info_t *charc = NULL;
2728 bt_gatt_included_service_info_t *incl = NULL;
2729 bt_gatt_descriptor_info_t *desc = NULL;
2731 /* Remove all Characteristic and Descriptors within characteristic */
2732 for (l = svc_info->chars; l != NULL;) {
2733 charc = (bt_gatt_char_info_t*)l->data;
2734 l = g_slist_next(l); /* Incase if l is removed, saving next to l */
2739 /* Inside Characteristic */
2740 for (l1 = charc->descs; l1 != NULL;) {
2742 desc = (bt_gatt_descriptor_info_t*)l1->data;
2743 l1 = g_slist_next(l1);
2748 /* Remove Descriptor */
2749 charc->descs = g_slist_remove(charc->descs, desc);
2752 /* Remove Characteristic */
2753 svc_info->chars = g_slist_remove(svc_info->chars, charc);
2757 /* Remove all Included Services */
2758 for (l2 = svc_info->included_svcs; l2 != NULL;) {
2759 incl = (bt_gatt_included_service_info_t*)l2->data;
2760 l2 = g_slist_next(l2); /* Incase if l is removed, saving next to l */
2765 /* Remove included service */
2766 svc_info->included_svcs = g_slist_remove(svc_info->included_svcs, incl);
2773 static void __bt_build_service_browse_info(int conn_id,
2774 bt_services_browse_info_t* info)
2777 bt_gatt_service_info_list_t *svc_info_list;
2778 bt_gatt_service_info_t *svc_info;
2780 service_uuid_t uuid;
2781 struct gatt_server_info_t *conn_info = NULL;
2783 char uuid_string[BLUETOOTH_UUID_STRING_MAX];
2785 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(conn_id);
2790 _bt_convert_addr_string_to_type(info->device_addr.addr, conn_info->addr);
2792 svc_info_list = __bt_get_service_info_list(conn_id);
2796 info->count = g_slist_length(svc_info_list->services);
2797 BT_DBG("Total services present in the svc info list for this conn id [%d] is [%d]",
2798 conn_id, info->count);
2800 for (l = svc_info_list->services; l != NULL; l = g_slist_next(l)) {
2801 svc_info = (bt_gatt_service_info_t*)l->data;
2802 if (svc_info == NULL)
2805 memcpy(&uuid.uuid, &svc_info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
2806 _bt_uuid_to_string(&uuid, uuid_string);
2808 BT_INFO("[%d] %s [%s]", count, uuid_string, _bt_convert_uuid_to_string(uuid_string));
2810 /* Fill UUID of service */
2811 g_strlcpy(info->uuids[count], uuid_string,
2812 BLUETOOTH_UUID_STRING_MAX);
2814 /* Fill instance ID of service */
2815 info->inst_id[count] = svc_info->inst_id;
2817 /* Fill primary service or not info */
2818 info->primary[count] = svc_info->is_primary;
2820 /* Increment count of services browsed */
2825 static void __bt_build_char_browse_info(int conn_id,
2826 bt_gatt_service_info_t *svc_info,
2827 bt_char_browse_info_t* info)
2830 bt_gatt_char_info_t *char_info;
2831 service_uuid_t uuid;
2833 struct gatt_server_info_t *conn_info = NULL;
2835 char uuid_string[BLUETOOTH_UUID_STRING_MAX];
2837 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(conn_id);
2841 /* Fill default data, this will be required even in case of failure */
2842 _bt_convert_addr_string_to_type(info->device_addr.addr, conn_info->addr);
2843 memcpy(&info->svc_uuid, svc_info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
2844 info->svc_inst_id = svc_info->inst_id;
2846 if (!svc_info->chars) {
2847 BT_ERR("No Chars browsed for address [%s]", conn_info->addr);
2851 info->count = g_slist_length(svc_info->chars);
2853 for (l = svc_info->chars; l != NULL; l = g_slist_next(l)) {
2854 char_info = (bt_gatt_char_info_t*)l->data;
2855 if (char_info == NULL)
2858 memcpy(&uuid.uuid, &char_info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
2859 _bt_uuid_to_string(&uuid, uuid_string);
2861 /* Fill UUID of characteristic */
2862 g_strlcpy(info->uuids[count], uuid_string,
2863 BLUETOOTH_UUID_STRING_MAX);
2865 /* Fill instance ID of characteristic */
2866 info->inst_id[count] = char_info->inst_id;
2868 /* Fill property of characteristic */
2869 info->props[count] = char_info->props;
2871 /* Increment count of services browsed */
2874 BT_DBG("Total characteristics browsed [%d]", count);
2877 static void __bt_build_descriptor_browse_info(int conn_id,
2878 bt_gatt_service_info_t *svc_info,
2879 bt_gatt_char_info_t *char_info,
2880 bt_descriptor_browse_info_t* info)
2883 bt_gatt_descriptor_info_t *desc_info;
2885 service_uuid_t uuid;
2886 struct gatt_server_info_t *conn_info = NULL;
2888 char uuid_string[BLUETOOTH_UUID_STRING_MAX];
2890 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(conn_id);
2892 /* Fill default data, this will be required even in case of failure */
2893 _bt_convert_addr_string_to_type(info->device_addr.addr, conn_info->addr);
2894 memcpy(&info->svc_uuid, svc_info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
2895 info->svc_inst_id = svc_info->inst_id;
2896 memcpy(&info->char_uuid, char_info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
2897 info->char_inst_id = char_info->inst_id;
2899 /* Fill property of the parent characteristic of this descriptor */
2900 info->char_props_map = char_info->props;
2902 info->count = g_slist_length(char_info->descs);
2904 if (!char_info->descs) {
2905 BT_ERR("No Descriptors browsed for address [%s]", conn_info->addr);
2909 for (l = char_info->descs; l != NULL; l = g_slist_next(l)) {
2910 desc_info = (bt_gatt_descriptor_info_t*)l->data;
2911 if (desc_info == NULL)
2914 memcpy(&uuid.uuid, &desc_info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
2915 _bt_uuid_to_string(&uuid, uuid_string);
2917 /* Fill UUID of Descriptor */
2918 g_strlcpy(info->uuids[count], uuid_string,
2919 BLUETOOTH_UUID_STRING_MAX);
2921 /* Fill instance ID of Descriptor */
2922 info->inst_id[count] = desc_info->inst_id;
2925 /* Increment count of Descriptor browsed */
2929 BT_INFO("Total descriptors browsed [%d]", count);
2932 static void __bt_free_service_info(bt_gatt_service_info_t *svc)
2934 GSList *ll, *lll, *llll;
2935 bt_gatt_char_info_t *chr = NULL;
2936 bt_gatt_descriptor_info_t *desc = NULL;
2937 bt_gatt_included_service_info_t *incl_svc = NULL;
2939 BT_DBG("Service info Is Prim[%d] Inst ID [%d]", svc->is_primary, svc->inst_id);
2940 /* Delete all chars and its descriptors */
2941 for (ll = svc->chars; ll != NULL; ) {
2942 chr = (bt_gatt_char_info_t *)ll->data;
2943 ll = g_slist_next(ll);
2947 for (lll = chr->descs; lll != NULL; ) {
2948 desc = (bt_gatt_descriptor_info_t *)lll->data;
2949 lll = g_slist_next(lll);
2952 chr->descs = g_slist_remove(chr->descs, desc);
2955 svc->chars = g_slist_remove(svc->chars, chr);
2959 /* Delete all included services */
2960 for (llll = svc->included_svcs; llll != NULL; ) {
2961 incl_svc = (bt_gatt_included_service_info_t *)llll->data;
2962 llll = g_slist_next(llll);
2963 if (incl_svc == NULL)
2965 svc->included_svcs = g_slist_remove(svc->included_svcs, incl_svc);
2970 static void __bt_cleanup_remote_services(struct gatt_server_info_t *conn_info)
2972 bt_gatt_service_info_list_t *svc_info_list = NULL;
2973 bt_gatt_service_info_t *svc = NULL;
2976 svc_info_list = __bt_get_service_info_list(conn_info->connection_id);
2977 if (!svc_info_list) {
2978 BT_INFO("Could not find Svc Info list for the connection ID [%d]",
2979 conn_info->connection_id);
2983 BT_INFO("Start Cleanup of all services. Num Services [%d]", g_slist_length(svc_info_list->services));
2984 for (l = svc_info_list->services; l != NULL; ) {
2985 svc = (bt_gatt_service_info_t *)l->data;
2986 l = g_slist_next(l);
2990 __bt_free_service_info(svc);
2991 svc_info_list->services = g_slist_remove(svc_info_list->services, svc);
2995 list_gatt_info = g_slist_remove(list_gatt_info, svc_info_list);
2996 g_free(svc_info_list);
2999 int _bt_register_gatt_client_instance(const char *sender,
3000 bluetooth_device_address_t *address)
3002 int ret = OAL_STATUS_SUCCESS;
3003 char *uuid_string = NULL;
3008 /* App should ensure that it should not send */
3009 BT_INFO("### Check on which instance GATT Client instance can be initialized....");
3010 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
3011 if (numapps[k].is_initialized == 1) {
3012 BT_INFO("Instance ID [%d] is already in use..Check next slot",
3013 numapps[k].instance_id);
3016 BT_INFO("Time to register GATT client instancer..UUID to be used is [%s] slot [%d]",
3017 uuid_list[slot-1], slot);
3023 BT_ERR("No Slot if free for GATT Client registration..");
3024 return BLUETOOTH_ERROR_REGISTRATION_FAILED;
3027 uuid_string = g_malloc0(BT_UUID_STRING_MAX);
3028 _bt_string_to_uuid(uuid_list[slot-1], (service_uuid_t*)&uuid);
3029 g_strlcpy(uuid_string, uuid_list[slot-1], BT_UUID_STRING_MAX);
3030 BT_INFO("Copied UUID string [%s]", uuid_string);
3032 /* Register GATT Client */
3033 ret = gattc_register(&uuid);
3034 if (ret != OAL_STATUS_SUCCESS) {
3035 BT_ERR("ret: %d", ret);
3036 g_free(uuid_string);
3037 return BLUETOOTH_ERROR_INTERNAL;
3040 BT_INFO("GATT Client registration call successfully accepted by OAL..wait for Instance Initialized event from OAL..");
3042 /* Return & wait for GATT Client Instance Initialization event */
3043 memset(numapps[slot].sender, 0x00, sizeof(numapps[slot].sender));
3044 memset(numapps[slot].uuid, 0x00, sizeof(numapps[slot].uuid));
3046 g_strlcpy(numapps[slot].sender, sender, sizeof(numapps[slot].sender));
3047 g_strlcpy(numapps[slot].uuid, uuid_string, sizeof(numapps[slot].uuid));
3049 /* Address is saved here. When event comes, sender + address are matched for replying pending
3050 request. It is impossible for same sender to have requests with two same addresses */
3051 memcpy(&numapps[slot].address.addr, address->addr, sizeof(bluetooth_device_address_t));
3053 BT_INFO("Slot [%d] occupied", slot);
3054 numapps[slot].is_initialized = TRUE; /* Set initialization to true here itself */
3056 g_free(uuid_string);
3057 return BLUETOOTH_ERROR_NONE;
3063 /* GATT client events */
3064 static void __bt_handle_client_instance_registered(event_gattc_register_t *data)
3066 bt_service_app_info_t *info = NULL;
3068 char *uuid_string = g_malloc0(BT_UUID_STRING_MAX);
3070 _bt_uuid_to_string(&(data->client_uuid), uuid_string);
3071 BT_INFO("CLient ID is Initialized [%d] UUID initialized [%s]", data->client_if, uuid_string);
3073 /* Platform GATT client framwork does not use Default GATT client instance
3074 This GATT client instance is never deregistred in the lifetime of bt-service */
3075 if (g_strcmp0(uuid_string, DEFAULT_GATT_CLIENT_UUID) == 0) {
3076 BT_INFO("Default client Instance Registered");
3077 gatt_default_client = data->client_if;
3078 g_free(uuid_string);
3082 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
3085 if (g_strcmp0(info->uuid, uuid_string) == 0) {
3086 BT_INFO("Found GATT client.. sender [%s] Slot [%d] occupied", info->sender, k);
3087 info->is_initialized = TRUE;
3088 info->client_id = data->client_if;
3089 __bt_gatt_handle_pending_request_info(BLUETOOTH_ERROR_NONE, BT_GATT_CLIENT_REGISTER,
3090 (void*)info, sizeof(bt_service_app_info_t));
3094 g_free(uuid_string);
3097 static void __bt_handle_client_connected(event_gattc_conn_t *event_data)
3099 int result = BLUETOOTH_ERROR_NONE;
3100 struct gatt_server_info_t *conn_info = NULL;
3101 struct gatt_out_conn_info_t *out_conn_info = NULL;
3103 GVariant *param = NULL;
3105 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
3106 _bt_convert_addr_type_to_string(address,
3107 (unsigned char *)event_data->address.addr);
3109 if (event_data->status != OAL_STATUS_SUCCESS)
3110 result = BLUETOOTH_ERROR_INTERNAL;
3112 /* DBUS Return fo BT_CONNECT_LE for all the apps */
3113 __bt_gatt_handle_pending_request_info(result, BT_CONNECT_LE, address,
3114 BT_ADDRESS_STRING_SIZE);
3116 BT_INFO("Local GATT Client Connected: Remote addr[%s] Client Interface [%d] Connection ID [%d] status[%d]",
3117 address, event_data->client_if, event_data->conn_id, event_data->status);
3119 if (result == BLUETOOTH_ERROR_NONE) {
3120 /* Check if device is already in connected list */
3121 conn_info = _bt_find_remote_gatt_server_info(address);
3124 /* Send event to BT-API */
3125 param = g_variant_new("(is)", result, address);
3126 _bt_send_event(BT_DEVICE_EVENT,
3127 BLUETOOTH_EVENT_GATT_CLIENT_CONNECTED, /* Local device is GATT client */
3130 /* Save Connection info */
3131 conn_info = g_new0(struct gatt_server_info_t, 1);
3132 conn_info->addr = g_strdup(address);
3133 conn_info->client_id = event_data->client_if;
3134 conn_info->connection_id = event_data->conn_id;
3135 gatt_server_info_list = g_slist_append(gatt_server_info_list, conn_info);
3136 BT_DBG("Total num of connected Remote GATT server devices [%d]",
3137 g_slist_length(gatt_server_info_list));
3140 BT_INFO("Do a Internal refresh");
3141 if (OAL_STATUS_SUCCESS != gattc_refresh(conn_info->client_id, &event_data->address))
3142 BT_ERR("GATT database refresh failed!!");
3144 BT_INFO("GATT database refresh Success!!");
3147 BT_ERR("Local GATT Client connected event for addr[%s], but device is in connected list already", address);
3149 __bt_add_mtu_gatt_device(address);
3151 BT_ERR("GATT Client Connection failed!!");
3153 /* If outgoing connection Info is present, then remove it */
3154 out_conn_info = __bt_find_gatt_outgoing_conn_info(address);
3155 if (out_conn_info) {
3156 BT_ERR("Outgoing Client connect request was sent");
3157 outgoing_gatt_conn_list = g_slist_remove(outgoing_gatt_conn_list, out_conn_info);
3158 g_free(out_conn_info->addr);
3159 g_free(out_conn_info);
3164 static void __bt_handle_client_disconnected(event_gattc_conn_t *event_data)
3166 int result = BLUETOOTH_ERROR_NONE;
3168 struct gatt_server_info_t *conn_info = NULL;
3169 struct gatt_out_conn_info_t *out_conn_info = NULL;
3171 GVariant *param = NULL;
3173 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
3174 _bt_convert_addr_type_to_string(address,
3175 (unsigned char *)event_data->address.addr);
3177 if (event_data->status != OAL_STATUS_SUCCESS)
3178 result = BLUETOOTH_ERROR_INTERNAL;
3180 if (NULL == _bt_get_request_info_data(BT_DISCONNECT_LE, address)) {
3181 if (NULL != _bt_get_request_info_data(BT_CONNECT_LE, address)) {
3182 result = BLUETOOTH_ERROR_INTERNAL;
3183 __bt_gatt_handle_pending_request_info(result, BT_CONNECT_LE,
3184 address, BT_ADDRESS_STRING_SIZE);
3185 BT_ERR("Failed to connect Local GATT Remote addr[%s]", address);
3190 /* DBUS Return for BT_DISCONNECT_LE for all the apps */
3191 __bt_gatt_handle_pending_request_info(result, BT_DISCONNECT_LE, address,
3192 BT_ADDRESS_STRING_SIZE);
3194 BT_INFO("Local GATT Client DisConnected: Remote addr[%s] Client Interface [%d] Connection ID [%d] status [%d]",
3195 address, event_data->client_if, event_data->conn_id, event_data->status);
3197 /* Remove Connection info */
3198 conn_info = _bt_find_remote_gatt_server_info(address);
3201 param = g_variant_new("(is)", result, address);
3202 /* Send event to application */
3203 _bt_send_event(BT_DEVICE_EVENT,
3204 BLUETOOTH_EVENT_GATT_CLIENT_DISCONNECTED,
3207 BT_INFO("Remove GATT server info from List..");
3208 /* Remove all services from info list_gatt_info */
3209 __bt_cleanup_remote_services(conn_info);
3211 /* Remove info from List */
3212 gatt_server_info_list = g_slist_remove(gatt_server_info_list, conn_info);
3213 BT_INFO("Total num of connected GATT servers [%d]", g_slist_length(gatt_server_info_list));
3214 g_free(conn_info->addr);
3217 BT_INFO("Can not find conn info, already removed!");
3219 __bt_remove_mtu_gatt_device(address);
3221 /* If outgoing connection Info is present, then remove it */
3222 out_conn_info = __bt_find_gatt_outgoing_conn_info(address);
3223 if (out_conn_info) {
3224 BT_ERR("Client Disconnected event, but outgoing connect request was sent");
3225 outgoing_gatt_conn_list = g_slist_remove(outgoing_gatt_conn_list, out_conn_info);
3226 g_free(out_conn_info->addr);
3227 g_free(out_conn_info);
3233 static void __bt_handle_client_service_search_result(
3234 event_gattc_service_result_t *event_data)
3236 /* Pre: status is never fail from OAL */
3238 /* Find service list from address */
3239 bt_gatt_service_info_list_t *svc_info_list;
3240 bt_gatt_service_info_t *svc_info;
3242 svc_info_list = __bt_get_service_info_list(event_data->conn_status.conn_id);
3243 if (!svc_info_list) {
3244 BT_DBG("Service info list not present for connection ID %d, means first time browse", event_data->conn_status.conn_id);
3245 /* Means for this conn_id, no services are ever browsed, first time,
3246 create service info list for this conn_id */
3247 svc_info_list = g_malloc0(sizeof(bt_gatt_service_info_list_t));
3248 svc_info_list->conn_id = event_data->conn_status.conn_id;
3249 list_gatt_info = g_slist_append(list_gatt_info, svc_info_list);
3252 /* send list and current service's uuid and instance id to find it */
3253 svc_info = __bt_find_matching_service(svc_info_list, &event_data->srvc_id);
3256 /* If not found, check if service changed, if yes, means this is a new service added
3257 in remote GATT device, update uuid info in svc info list structure, to be used when
3258 search is completed */
3260 if (svc_info_list->info.is_changed) {
3261 BT_DBG("Service Changed indication already found for connection ID %d", event_data->conn_status.conn_id);
3262 memcpy(svc_info_list->info.uuid, event_data->srvc_id.id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3264 /* Create and add new service in service list */
3265 svc_info = g_malloc0(sizeof(bt_gatt_service_info_t));
3266 memcpy(svc_info->uuid, event_data->srvc_id.id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3267 svc_info->inst_id = event_data->srvc_id.id.inst_id;
3268 svc_info->is_primary = event_data->srvc_id.is_prmry;
3269 svc_info_list->services = g_slist_append(svc_info_list->services, svc_info);
3270 BT_DBG("Service created and added in Svc info list or connection ID %d", event_data->conn_status.conn_id);
3272 /* If returned matching service info, then just update service_rmeoved value inside it to 0 */
3273 svc_info->is_removed = 0;
3277 static void __bt_handle_client_service_search_completed(
3278 event_gattc_conn_status_t *event_data)
3280 struct gatt_server_info_t *conn_info = NULL;
3281 bt_gatt_service_info_list_t *svc_info_list;
3282 bt_gatt_service_info_t *svc_info;
3283 bt_services_browse_info_t browse_info;
3284 unsigned char uuid_empty[BLUETOOTH_UUID_HEX_MAX_LEN];
3286 memset(&uuid_empty, 0x00, BLUETOOTH_UUID_HEX_MAX_LEN);
3287 memset(&browse_info, 0x00, sizeof(bt_services_browse_info_t));
3288 BT_INFO("Primary Services browsing completed status[%d] conn ID [%d]",
3289 event_data->status, event_data->conn_id);
3291 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(event_data->conn_id);
3293 svc_info_list = __bt_get_service_info_list(event_data->conn_id);
3294 if (!svc_info_list) {
3295 BT_ERR("No services browsed ever for addr [%s]", conn_info->addr);
3297 /* Just build response and return ERROR */
3298 __bt_build_service_browse_info(event_data->conn_id, &browse_info);
3300 __bt_gatt_handle_pending_request_info(BLUETOOTH_ERROR_INTERNAL,
3301 BT_GATT_GET_PRIMARY_SERVICES, &browse_info,
3302 sizeof(bt_services_browse_info_t));
3306 /* If fail, then send event with error */
3307 if (event_data->status != OAL_STATUS_SUCCESS) {
3308 /* Just build response and return ERROR */
3309 __bt_build_service_browse_info(event_data->conn_id, &browse_info);
3311 __bt_gatt_handle_pending_request_info(BLUETOOTH_ERROR_INTERNAL,
3312 BT_GATT_GET_PRIMARY_SERVICES, &browse_info,
3313 sizeof(bt_services_browse_info_t));
3317 /* If success, then find service info list from address */
3319 /* If svc_changed == 1 and uuid valid, means a new service is added*/
3320 if (svc_info_list->info.is_changed && !memcmp(uuid_empty, svc_info_list->info.uuid, BLUETOOTH_UUID_HEX_MAX_LEN)) {
3321 /* TODO: Send event -Service added with instance ID and UUID of newly added service */
3322 BT_INFO("new service added");
3324 BT_INFO("TODO new service added");
3327 /* If svc_changed == 1 and uuid invalid, then a service is removed */
3328 if (svc_info_list->info.is_changed && memcmp(uuid_empty, svc_info_list->info.uuid, BLUETOOTH_UUID_HEX_MAX_LEN)) {
3329 /* Scan through the service info list to find service with is_removed = 1*/
3330 svc_info = __bt_find_removed_service(svc_info_list);
3332 /* TODO Send event - Service removed with instance ID and UUID of just rmeoved service */
3334 /* Remove that service info from service info list */
3335 svc_info_list->services = g_slist_remove(svc_info_list->services, svc_info);
3337 /* Delete that service completely from svc_info list*/
3338 __bt_remove_service_info_from_list(svc_info);
3342 /* Reset svc_changed = 0, and reset UUID = all 0's */
3343 svc_info_list->info.is_changed = 0;
3344 memset(&svc_info_list->info.uuid, 0x00, BLUETOOTH_UUID_HEX_MAX_LEN);
3346 /* Build Reply and send to service browse primary services request of pending apps */
3347 __bt_build_service_browse_info(event_data->conn_id, &browse_info);
3349 __bt_gatt_handle_pending_request_info(BLUETOOTH_ERROR_NONE,
3350 BT_GATT_GET_PRIMARY_SERVICES, &browse_info,
3351 sizeof(bt_services_browse_info_t));
3355 static void __bt_handle_client_characteristic_search_result(
3356 event_gattc_characteristic_result_t *event_data)
3358 bt_gatt_service_info_list_t *svc_info_list;
3359 bt_gatt_service_info_t *svc_info;
3360 bt_gatt_char_info_t *char_info;
3361 bt_char_browse_info_t browse_info;
3363 memset(&browse_info, 0x00, sizeof(bt_char_browse_info_t));
3366 if (event_data->conn_status.status == OAL_STATUS_SUCCESS) {
3367 /* Find service info list from address */
3368 svc_info_list = __bt_get_service_info_list(event_data->conn_status.conn_id);
3369 if (svc_info_list == NULL) {
3370 BT_ERR("svc_info_list is NULL");
3375 /* Find matching service info from svc info list */
3376 svc_info = __bt_find_matching_service(svc_info_list, &event_data->srvc_id);
3377 if (svc_info == NULL) {
3378 BT_ERR("svc_info is NULL");
3382 /* Find Matching char from service info in event */
3383 char_info = __bt_find_matching_charc(svc_info, &event_data->char_id);
3385 /* If not found, then add new characteristic and return */
3387 BT_DBG("Add new characteristic");
3388 char_info = g_malloc0(sizeof(bt_gatt_char_info_t));
3389 memcpy(char_info->uuid, event_data->char_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3391 char_info->inst_id = event_data->char_id.inst_id;
3392 char_info->props = event_data->char_prop;
3393 svc_info->chars = g_slist_append(svc_info->chars, char_info);
3395 /* If found, then return */
3396 BT_DBG("update char property as Characteristic browsed is already present");
3397 char_info->props |= event_data->char_prop;
3400 /* If Not success: Means Charc browse is completed */
3401 /* Find char list from service in event */
3402 /* Find service list from address */
3403 svc_info_list = __bt_get_service_info_list(event_data->conn_status.conn_id);
3404 if (svc_info_list == NULL) {
3405 BT_ERR("svc_info_list is NULL");
3409 /* Find service info from service in event */
3410 svc_info = __bt_find_matching_service(svc_info_list, &event_data->srvc_id);
3411 if (svc_info == NULL) {
3412 BT_ERR("svc_info is NULL");
3416 /* Build char list from service in event */
3417 __bt_build_char_browse_info(event_data->conn_status.conn_id,
3418 svc_info, &browse_info);
3420 /* Create response and return by sending event*/
3421 /* Build Reply and send to service browse All Included services request of pending apps */
3422 __bt_gatt_handle_pending_request_info(BLUETOOTH_ERROR_NONE,
3423 BT_GATT_GET_SERVICE_PROPERTIES,
3425 sizeof(bt_char_browse_info_t));
3429 static void __bt_handle_client_descriptor_search_result(
3430 event_gattc_descriptor_result_t *event_data)
3432 bt_gatt_service_info_list_t *svc_info_list;
3433 bt_gatt_service_info_t *svc_info;
3434 bt_gatt_char_info_t *char_info;
3435 bt_gatt_descriptor_info_t *desc_info;
3436 bt_descriptor_browse_info_t browse_info;
3438 BT_INFO("descriptor search result status [%d]", event_data->conn_status.status);
3440 memset(&browse_info, 0x00, sizeof(bt_descriptor_browse_info_t));
3443 if (event_data->conn_status.status == OAL_STATUS_SUCCESS) {
3444 /* Find service list from address */
3445 svc_info_list = __bt_get_service_info_list(event_data->conn_status.conn_id);
3446 if (svc_info_list == NULL) {
3447 BT_ERR("svc_info_list is NULL");
3451 svc_info = __bt_find_matching_service(svc_info_list, &event_data->srvc_id);
3452 if (svc_info == NULL) {
3453 BT_ERR("svc_info is NULL");
3457 char_info = __bt_find_matching_charc(svc_info, &event_data->char_id);
3458 if (char_info == NULL) {
3459 BT_ERR("char_info is NULL");
3463 desc_info = __bt_find_matching_desc(char_info, &event_data->descr_id);
3464 /* If not found, add new descriptor and return */
3466 desc_info = g_malloc0(sizeof(bt_gatt_descriptor_info_t));
3467 memcpy(desc_info->uuid, event_data->descr_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3469 desc_info->inst_id = event_data->descr_id.inst_id;
3470 char_info->descs = g_slist_append(char_info->descs, desc_info);
3473 /* If found, then return */
3474 BT_INFO("Characteristic browsed is already presesnt");
3477 /* If Not success */
3478 /* Find service list from address */
3479 /* Find included service list from service in event */
3480 /* Create response and return by sending event*/
3481 svc_info_list = __bt_get_service_info_list(event_data->conn_status.conn_id);
3482 if (svc_info_list == NULL) {
3483 BT_ERR("svc_info_list is NULL");
3487 /* Find service info from service in event */
3488 svc_info = __bt_find_matching_service(svc_info_list, &event_data->srvc_id);
3489 if (svc_info == NULL) {
3490 BT_ERR("svc_info is NULL");
3494 /* Find char info from char in event */
3495 char_info = __bt_find_matching_charc(svc_info, &event_data->char_id);
3496 if (char_info == NULL) {
3497 BT_ERR("char_info is NULL");
3501 /* Build descriptor list from char in event */
3502 __bt_build_descriptor_browse_info(event_data->conn_status.conn_id,
3503 svc_info, char_info, &browse_info);
3506 __bt_gatt_handle_pending_request_info(BLUETOOTH_ERROR_NONE,
3507 BT_GATT_GET_CHARACTERISTIC_PROPERTIES,
3509 sizeof(bt_descriptor_browse_info_t));
3513 static void __bt_handle_client_characteristic_read_data(
3514 event_gattc_read_data *event_data)
3516 int result = BLUETOOTH_ERROR_NONE;
3517 struct gatt_server_info_t *conn_info = NULL;
3518 bluetooth_gatt_client_char_prop_info_t read_info;
3520 /* Read Information data structures */
3521 GVariant *param = NULL;
3522 GVariant *data = NULL;
3523 GVariant *data_svc_uuid = NULL;
3524 GVariant *data_char_uuid = NULL;
3525 char *read_val = NULL;
3526 char *svc_uuid = NULL;
3527 char *char_uuid = NULL;
3530 //memset(&read_info, 0x00, sizeof(bt_gatt_handle_property_t));
3531 memset(&read_info, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3533 /* Extract Address from conn_id of event data */
3534 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(
3535 event_data->uuid_status.conn_status.conn_id);
3537 BT_INFO("Characteristic Read result from addr [%s] status [%d]",
3538 conn_info->addr, event_data->uuid_status.conn_status.status);
3540 /* Fill char in buffer */
3541 memcpy(&read_info.characteristic.uuid,
3542 event_data->uuid_status.char_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3543 read_info.characteristic.instance_id = event_data->uuid_status.char_id.inst_id;
3545 /* Fill Service in buffer */
3546 memcpy(&read_info.svc.uuid,
3547 event_data->uuid_status.srvc_id.id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3548 read_info.svc.instance_id = event_data->uuid_status.srvc_id.id.inst_id;
3550 /* Fill remote device address */
3551 _bt_convert_addr_string_to_type(read_info.device_address.addr, conn_info->addr);
3553 /* Fill data and reply to all apps waiting for Read result on the same characteristic
3554 Note: Even in case of failure, address, handles and result code should be returned */
3555 if (event_data->uuid_status.conn_status.status != OAL_STATUS_SUCCESS)
3556 result = BLUETOOTH_ERROR_INTERNAL;
3558 if (event_data->data_len > 0) {
3560 // for (i = 0; i < event_data->data_len; i++)
3561 // BT_INFO("Data[%d] = [0x%x]", i, event_data->data[i]);
3564 read_val = g_memdup(&event_data->data[0], event_data->data_len);
3566 data = g_variant_new_from_data(
3567 G_VARIANT_TYPE_BYTESTRING,
3569 event_data->data_len,
3572 BT_ERR("Characteristic Read success, but no data!!!");
3574 data = g_variant_new_from_data(
3575 G_VARIANT_TYPE_BYTESTRING,
3582 svc_uuid = g_memdup(&event_data->uuid_status.srvc_id.id.uuid.uuid[0], uuid_len);
3584 data_svc_uuid = g_variant_new_from_data(
3585 G_VARIANT_TYPE_BYTESTRING,
3591 char_uuid = g_memdup(&event_data->uuid_status.char_id.uuid.uuid[0], uuid_len);
3593 data_char_uuid = g_variant_new_from_data(
3594 G_VARIANT_TYPE_BYTESTRING,
3599 param = g_variant_new("(isn@ayin@ayin@ay)", result,
3603 event_data->uuid_status.srvc_id.id.inst_id,
3606 event_data->uuid_status.char_id.inst_id,
3607 event_data->data_len,
3611 _bt_send_event(BT_GATT_CLIENT_EVENT,
3612 BLUETOOTH_EVENT_GATT_READ_CHAR,
3615 /* Send DBUS return */
3616 __bt_gatt_handle_pending_request_info(result,
3617 BT_GATT_READ_CHARACTERISTIC,
3619 sizeof(bluetooth_gatt_client_char_prop_info_t));
3630 static void __bt_handle_client_descriptor_read_data(
3631 event_gattc_read_data *event_data)
3633 int result = BLUETOOTH_ERROR_NONE;
3634 struct gatt_server_info_t *conn_info = NULL;
3635 bluetooth_gatt_client_desc_prop_info_t read_info;
3637 /* Read Information data structures */
3638 GVariant *param = NULL;
3639 GVariant *data = NULL;
3640 GVariant *data_svc_uuid = NULL;
3641 GVariant *data_char_uuid = NULL;
3642 GVariant *data_desc_uuid = NULL;
3643 char *read_val = NULL;
3644 char *svc_uuid = NULL;
3645 char *char_uuid = NULL;
3646 char *desc_uuid = NULL;
3651 memset(&read_info, 0x00, sizeof(bluetooth_gatt_client_desc_prop_info_t));
3653 /* Extract Address from conn_id of event data */
3654 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(
3655 event_data->uuid_status.conn_status.conn_id);
3657 BT_INFO("Descriptor Read result from addr [%s] status [%d]",
3658 conn_info->addr, event_data->uuid_status.conn_status.status);
3660 /* Fill descriptor informations in buffer */
3661 memcpy(&read_info.descriptor.uuid,
3662 event_data->uuid_status.descr_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3663 read_info.descriptor.instance_id = event_data->uuid_status.descr_id.inst_id;
3665 /* Fill Characteristic informations in buffer */
3666 memcpy(&read_info.characteristic.uuid,
3667 event_data->uuid_status.char_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3668 read_info.characteristic.instance_id = event_data->uuid_status.char_id.inst_id;
3670 /* Fill Service informations in buffer */
3671 memcpy(&read_info.svc.uuid,
3672 event_data->uuid_status.srvc_id.id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3673 read_info.svc.instance_id = event_data->uuid_status.srvc_id.id.inst_id;
3675 /* Fill remote device address */
3676 _bt_convert_addr_string_to_type(read_info.device_address.addr, conn_info->addr);
3678 /* Fill data and reply to all apps waiting for Read result on the same characteristic */
3679 if (event_data->uuid_status.conn_status.status != OAL_STATUS_SUCCESS)
3680 result = BLUETOOTH_ERROR_INTERNAL;
3682 BT_INFO("desc data len:%d", event_data->data_len);
3683 if (event_data->data_len > 0) {
3685 for (i = 0; i < event_data->data_len; i++)
3686 BT_DBG("Data[%d] = [0x%x]", i, event_data->data[i]);
3689 read_val = g_memdup(&event_data->data[0], event_data->data_len);
3691 data = g_variant_new_from_data(
3692 G_VARIANT_TYPE_BYTESTRING,
3694 event_data->data_len,
3697 BT_INFO("Descriptor Read success, but no data!!!");
3699 data = g_variant_new_from_data(
3700 G_VARIANT_TYPE_BYTESTRING,
3706 svc_uuid = g_memdup(&event_data->uuid_status.srvc_id.id.uuid.uuid[0], uuid_len);
3708 data_svc_uuid = g_variant_new_from_data(
3709 G_VARIANT_TYPE_BYTESTRING,
3715 char_uuid = g_memdup(&event_data->uuid_status.char_id.uuid.uuid[0], uuid_len);
3717 data_char_uuid = g_variant_new_from_data(
3718 G_VARIANT_TYPE_BYTESTRING,
3724 desc_uuid = g_memdup(&event_data->uuid_status.descr_id.uuid.uuid[0], uuid_len);
3726 data_desc_uuid = g_variant_new_from_data(
3727 G_VARIANT_TYPE_BYTESTRING,
3732 param = g_variant_new("(isn@ayin@ayin@ayin@ay)", result,
3736 event_data->uuid_status.srvc_id.id.inst_id,
3739 event_data->uuid_status.char_id.inst_id,
3742 event_data->uuid_status.descr_id.inst_id,
3743 event_data->data_len,
3747 _bt_send_event(BT_GATT_CLIENT_EVENT,
3748 BLUETOOTH_EVENT_GATT_READ_DESC,
3751 BT_INFO("Send DBUS rpely for GATT Read Descriptor");
3752 /* Send DBUS return */
3753 __bt_gatt_handle_pending_request_info(result,
3754 BT_GATT_READ_DESCRIPTOR_VALUE,
3756 sizeof(bluetooth_gatt_client_desc_prop_info_t));
3767 static void __bt_handle_client_characteristic_write_data(
3768 event_gattc_write_data *event_data)
3770 int result = BLUETOOTH_ERROR_NONE;
3771 struct gatt_server_info_t *conn_info = NULL;
3772 bluetooth_gatt_client_char_prop_info_t write_info;
3774 /* Read Information data structures */
3775 GVariant *param = NULL;
3776 GVariant *data_svc_uuid = NULL;
3777 GVariant *data_char_uuid = NULL;
3778 char *svc_uuid = NULL;
3779 char *char_uuid = NULL;
3783 memset(&write_info, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3785 /* Extract Address from conn_id of event data */
3786 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(
3787 event_data->conn_status.conn_id);
3789 BT_INFO("Characteristic Write callback from addr [%s] status [%d]",
3790 conn_info->addr, event_data->conn_status.status);
3792 /* Fill char in buffer */
3793 memcpy(&write_info.characteristic.uuid,
3794 event_data->char_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3795 write_info.characteristic.instance_id = event_data->char_id.inst_id;
3797 /* Fill Service in buffer */
3798 memcpy(&write_info.svc.uuid,
3799 event_data->srvc_id.id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3800 write_info.svc.instance_id = event_data->srvc_id.id.inst_id;
3802 /* Fill remote device address */
3803 _bt_convert_addr_string_to_type(write_info.device_address.addr, conn_info->addr);
3805 if (event_data->conn_status.status != OAL_STATUS_SUCCESS) {
3806 result = BLUETOOTH_ERROR_INTERNAL;
3812 svc_uuid = g_memdup(&event_data->srvc_id.id.uuid.uuid[0], uuid_len);
3814 data_svc_uuid = g_variant_new_from_data(
3815 G_VARIANT_TYPE_BYTESTRING,
3821 char_uuid = g_memdup(&event_data->char_id.uuid.uuid[0], uuid_len);
3823 data_char_uuid = g_variant_new_from_data(
3824 G_VARIANT_TYPE_BYTESTRING,
3829 param = g_variant_new("(isn@ayin@ayi)", result,
3833 event_data->srvc_id.id.inst_id,
3836 event_data->char_id.inst_id);
3839 _bt_send_event(BT_GATT_CLIENT_EVENT,
3840 BLUETOOTH_EVENT_GATT_WRITE_CHAR,
3849 /* Send DBUS return */
3850 __bt_gatt_handle_pending_request_info(result,
3851 BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE,
3853 sizeof(bluetooth_gatt_client_char_prop_info_t));
3857 static void __bt_handle_client_descriptor_write_data(
3858 event_gattc_write_data *event_data)
3860 int result = BLUETOOTH_ERROR_NONE;
3861 struct gatt_server_info_t *conn_info = NULL;
3862 bluetooth_gatt_client_desc_prop_info_t write_info;
3864 /* Write Information data structures */
3865 GVariant *param = NULL;
3866 GVariant *data_svc_uuid = NULL;
3867 GVariant *data_char_uuid = NULL;
3868 GVariant *data_desc_uuid = NULL;
3869 char *svc_uuid = NULL;
3870 char *char_uuid = NULL;
3871 char *desc_uuid = NULL;
3875 memset(&write_info, 0x00, sizeof(bluetooth_gatt_client_desc_prop_info_t));
3877 /* Extract Address from conn_id of event data */
3878 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(
3879 event_data->conn_status.conn_id);
3881 if (NULL == conn_info) {
3883 BT_INFO("Failed to get the conn info for conn_id [%d]", event_data->conn_status.conn_id);
3887 BT_INFO("Descriptor Write callback from addr [%s] status [%d]",
3888 conn_info->addr, event_data->conn_status.status);
3890 /* Fill descriptor informations in buffer */
3891 memcpy(&write_info.descriptor.uuid,
3892 event_data->descr_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3893 write_info.descriptor.instance_id = event_data->descr_id.inst_id;
3895 /* Fill Characteristic informations in buffer */
3896 memcpy(&write_info.characteristic.uuid,
3897 event_data->char_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3898 write_info.characteristic.instance_id = event_data->char_id.inst_id;
3900 /* Fill Service informations in buffer */
3901 memcpy(&write_info.svc.uuid,
3902 event_data->srvc_id.id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3903 write_info.svc.instance_id = event_data->srvc_id.id.inst_id;
3905 /* Fill remote device address */
3906 _bt_convert_addr_string_to_type(write_info.device_address.addr, conn_info->addr);
3908 if (event_data->conn_status.status != OAL_STATUS_SUCCESS) {
3909 result = BLUETOOTH_ERROR_INTERNAL;
3915 svc_uuid = g_memdup(&event_data->srvc_id.id.uuid.uuid[0], uuid_len);
3917 data_svc_uuid = g_variant_new_from_data(
3918 G_VARIANT_TYPE_BYTESTRING,
3924 char_uuid = g_memdup(&event_data->char_id.uuid.uuid[0], uuid_len);
3926 data_char_uuid = g_variant_new_from_data(
3927 G_VARIANT_TYPE_BYTESTRING,
3933 desc_uuid = g_memdup(&event_data->descr_id.uuid.uuid[0], uuid_len);
3935 data_desc_uuid = g_variant_new_from_data(
3936 G_VARIANT_TYPE_BYTESTRING,
3941 param = g_variant_new("(isn@ayin@ayin@ayi)", result,
3945 event_data->srvc_id.id.inst_id,
3948 event_data->char_id.inst_id,
3951 event_data->descr_id.inst_id);
3954 _bt_send_event(BT_GATT_CLIENT_EVENT,
3955 BLUETOOTH_EVENT_GATT_WRITE_DESC,
3966 /* Send DBUS return */
3967 __bt_gatt_handle_pending_request_info(result,
3968 BT_GATT_WRITE_DESCRIPTOR_VALUE,
3970 sizeof(bluetooth_gatt_client_desc_prop_info_t));
3973 static void __bt_hanlde_le_device_disconnection(event_dev_conn_status_t *event_data)
3975 int result = BLUETOOTH_ERROR_INTERNAL;
3976 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
3978 _bt_convert_addr_type_to_string(address, (unsigned char *)event_data->address.addr);
3980 /* DBUS Return with fail of pending BT_CONNECT_LE for all the apps */
3981 BT_INFO("Local GATT Client disconnected: Remote addr[%s] ", address);
3983 __bt_gatt_handle_pending_request_info(result, BT_CONNECT_LE, address,
3984 BT_ADDRESS_STRING_SIZE);
3988 static void __bt_handle_client_notification_registered(
3989 event_gattc_regdereg_notify_t *event_data,
3990 gboolean is_registered)
3992 int result = BLUETOOTH_ERROR_NONE;
3993 struct gatt_server_info_t *conn_info = NULL;
3994 bt_gatt_notif_reg_info_t notif_info;
3997 memset(¬if_info, 0x00, sizeof(bt_gatt_notif_reg_info_t));
3999 BT_INFO("Client Interface [%d] status [%d]",
4000 event_data->conn_id,
4001 event_data->status);
4003 /* Extract Address from conn_id of event data */
4004 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(event_data->conn_id);
4006 BT_INFO("Connection Info is not present, return");
4009 BT_INFO("Notification Registered for addr [%s]", conn_info->addr);
4011 /* Fill svc informations in buffer */
4012 memcpy(¬if_info.svc_uuid,
4013 event_data->srvc_id.id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4014 notif_info.svc_inst = event_data->srvc_id.id.inst_id;
4016 /* Fill char in buffer */
4017 memcpy(¬if_info.char_uuid,
4018 event_data->char_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4019 notif_info.char_inst = event_data->char_id.inst_id;
4021 /* Fill remote device address */
4022 _bt_convert_addr_string_to_type(notif_info.addr.addr, conn_info->addr);
4024 notif_info.is_registered = is_registered;
4026 if (event_data->status != OAL_STATUS_SUCCESS)
4027 result = BLUETOOTH_ERROR_INTERNAL;
4029 /* Send DBUS Return for BT_GATT_WATCH_CHARACTERISTIC */
4030 __bt_gatt_handle_pending_request_info(result,
4031 BT_GATT_WATCH_CHARACTERISTIC,
4033 sizeof(bt_gatt_notif_reg_info_t));
4036 static void __bt_handle_client_notification_data(event_gattc_notify_data *event_data)
4038 /* No status in this event from OAL */
4039 int result = BLUETOOTH_ERROR_NONE;
4041 /* Read Information data structures */
4042 GVariant *param = NULL;
4043 GVariant *data = NULL;
4044 GVariant *data_svc_uuid = NULL;
4045 GVariant *data_char_uuid = NULL;
4046 char *read_val = NULL;
4047 char *svc_uuid = NULL;
4048 char *char_uuid = NULL;
4054 BT_INFO("Notifcation of charc data changed");
4056 if (event_data->data_len > 0) {
4058 for (i = 0; i < event_data->data_len; i++)
4059 BT_INFO("Data[%d] = [0x%x]", i, event_data->data[i]);
4062 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
4063 _bt_convert_addr_type_to_string(addr,
4064 (unsigned char *)&(event_data->address.addr));
4067 read_val = g_memdup(&event_data->data[0], event_data->data_len);
4069 data = g_variant_new_from_data(
4070 G_VARIANT_TYPE_BYTESTRING,
4072 event_data->data_len,
4075 svc_uuid = g_memdup(&event_data->srvc_id.id.uuid.uuid[0], uuid_len);
4077 data_svc_uuid = g_variant_new_from_data(
4078 G_VARIANT_TYPE_BYTESTRING,
4084 char_uuid = g_memdup(&event_data->char_id.uuid.uuid[0], uuid_len);
4086 data_char_uuid = g_variant_new_from_data(
4087 G_VARIANT_TYPE_BYTESTRING,
4093 param = g_variant_new("(isn@ayin@ayin@ay)", result,
4097 event_data->srvc_id.id.inst_id,
4100 event_data->char_id.inst_id,
4101 event_data->data_len,
4105 _bt_send_event(BT_GATT_CLIENT_EVENT,
4106 BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED,
4109 BT_ERR("No Data!!");
4122 static void __bt_handle_client_service_changed_ind(event_gattc_service_changed_data *event_data)
4124 bt_gatt_service_info_list_t *svc_info_list;
4126 bt_gatt_service_info_t *svc_info;
4127 GVariant *param = NULL;
4128 char *address_str = NULL;
4129 char *uuid_str = NULL;
4131 svc_info_list = __bt_get_service_info_list(event_data->conn_id);
4132 if (svc_info_list == NULL) {
4133 BT_ERR("svc_info_list is NULL");
4137 if (event_data->change_type) {
4138 /* Add service UUID in list */
4139 svc_info = g_malloc0(sizeof(bt_gatt_service_info_t));
4140 memcpy(svc_info->uuid, event_data->uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4141 svc_info->inst_id = event_data->inst_id;
4142 svc_info->is_primary = 1; // TODO: Need to check is_primary is required or not
4143 svc_info_list->services = g_slist_append(svc_info_list->services, svc_info);
4144 BT_DBG("Service created and added in Svc info list or connection ID %d", event_data->conn_id);
4146 /* Remove service UUID in list */
4147 for (l = svc_info_list->services; l != NULL; l = g_slist_next(l)) {
4148 svc_info = (bt_gatt_service_info_t *)l->data;
4149 if (svc_info == NULL)
4152 if (!memcmp(svc_info->uuid, event_data->uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN)) {
4153 svc_info_list->services = g_slist_remove(svc_info_list->services, svc_info);
4154 __bt_free_service_info(svc_info);
4160 address_str = g_malloc0(BT_ADDRESS_STRING_SIZE);
4161 uuid_str = g_malloc0(BT_UUID_STRING_MAX);
4162 _bt_convert_addr_type_to_string(address_str, event_data->address.addr);
4163 _bt_uuid_to_string(&event_data->uuid, uuid_str);
4165 param = g_variant_new("(iiss)", event_data->inst_id, event_data->change_type, address_str, uuid_str);
4167 _bt_send_event(BT_GATT_CLIENT_EVENT,
4168 BLUETOOTH_EVENT_GATT_CLIENT_SERVICE_CHANGED,
4170 g_free(address_str);
4174 gboolean _bt_is_remote_gatt_device_connected(bluetooth_device_address_t *address)
4177 struct gatt_server_info_t *conn_info = NULL;
4178 gboolean connected = FALSE;
4180 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
4181 _bt_convert_addr_type_to_string(addr,
4182 (unsigned char *)&(address->addr));
4184 BT_DBG("Check GATT connection status of [%s]", addr);
4185 /* Check if device is already in connected list */
4186 conn_info = _bt_find_remote_gatt_server_info(addr);
4189 BT_DBG("Remote GATT Server device [%s] is Connected", conn_info->addr);
4192 struct gatt_client_info_t *client_info = NULL;
4194 BT_INFO("Remote GATT Server Device [%s] is not Connected", addr);
4196 /* Check if device is already in connected list */
4197 client_info = _bt_find_remote_gatt_client_info(addr);
4200 BT_DBG("Remote Client device [%s] is Connected", client_info->addr);
4203 BT_INFO("Remote GATT Client Device [%s] is not Connected", addr);
4211 void _bt_handle_invocation_context(int function_name, void *data)
4213 switch (function_name) {
4215 __bt_gatt_handle_pending_request_info(BLUETOOTH_ERROR_NONE, BT_CONNECT_LE,
4216 (char *)data, BT_ADDRESS_STRING_SIZE);
4223 int _bt_connect_le_device(bluetooth_device_address_t *address,
4224 int auto_connect, int client_id)
4226 struct gatt_server_info_t *conn_info = NULL;
4227 struct gatt_out_conn_info_t *out_conn_info = NULL;
4229 invocation_info_t *req_info = NULL;
4230 int ret = OAL_STATUS_SUCCESS;
4232 char *remote_address = NULL;
4234 BT_CHECK_PARAMETER(address, return);
4236 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4237 _bt_convert_addr_type_to_string(addr, address->addr);
4238 BT_DBG("GATT Client connect request for address [%s] client instance [%d]",
4242 /* Check if Remote Device is already under connection progress */
4243 req_info = _bt_get_request_info_data_from_function_name(BT_CONNECT_LE);
4245 remote_address = (char*)req_info->user_data;
4246 if (remote_address && !strcasecmp(remote_address, addr)) {/* Address matched */
4247 BT_DBG("Already Connection ongoing for same remote GATT Server address [%s]", remote_address);
4248 /* Return and wait for events to be sent to all apps */
4250 return BLUETOOTH_ERROR_IN_PROGRESS;
4254 /* Check if remote GATT Server is connected or not */
4255 conn_info = _bt_find_remote_gatt_server_info(addr);
4257 BT_ERR("GATT Server is already connected..");
4259 return BLUETOOTH_ERROR_ALREADY_CONNECT;
4262 /* TODO Check Requirement of holding Advertisement before initiating LE connect */
4264 /* Check if app sent 0 client id for connection, in such case, use default gatt client ID */
4265 if (client_id == 0) {
4266 /* GATT CLient connect request sent by an app without any client instance [0] */
4267 BT_DBG("Assign default GATT client id [%d]", gatt_default_client);
4268 client_id = gatt_default_client;
4271 BT_INFO("Connect using CLient ID [%d]", client_id);
4272 ret = gattc_connect(client_id, (bt_address_t*)(address), auto_connect);
4274 if (ret != OAL_STATUS_SUCCESS) {
4275 BT_ERR("gattc_connect is failed. ret: %d", ret);
4277 return BLUETOOTH_ERROR_INTERNAL;
4280 /* Mark this as outgoing connection */
4281 out_conn_info = g_new0(struct gatt_out_conn_info_t, 1);
4282 out_conn_info->addr = g_strdup(addr);
4283 out_conn_info->client_id = client_id;
4284 BT_INFO("Added outgoing connection info addr[%s]", out_conn_info->addr);
4285 outgoing_gatt_conn_list = g_slist_append(outgoing_gatt_conn_list, out_conn_info);
4288 return BLUETOOTH_ERROR_NONE;
4291 int _bt_gatt_get_primary_services(char *address)
4293 BT_CHECK_PARAMETER(address, return);
4294 struct gatt_server_info_t *conn_info = NULL;
4295 invocation_info_t *req_info = NULL;
4296 int ret = OAL_STATUS_SUCCESS;
4299 /* Check if any app is already browsing primary services on the same remote GATT Server */
4300 req_info = _bt_get_request_info_data(BT_GATT_GET_PRIMARY_SERVICES, address);
4302 BT_INFO("Already Primary Service Browsing ongoing for same rmeote GATT Server");
4303 /* Return and wait for events to be sent to all apps */
4304 return BLUETOOTH_ERROR_NONE;
4307 /* Check if remote GATT Server is connected or not */
4308 conn_info = _bt_find_remote_gatt_server_info(address);
4310 BT_INFO("GATT Server [%s] is connected, conn Id [%d]",
4311 conn_info->addr, conn_info->connection_id);
4313 BT_ERR("GATT Server is not yet connected..");
4314 return BLUETOOTH_ERROR_NOT_CONNECTED;
4317 /* Send Primary Service Browsing request to stack */
4318 ret = gattc_search_service(conn_info->connection_id, NULL);
4319 if (ret != OAL_STATUS_SUCCESS) {
4320 BT_ERR("ret: %d", ret);
4321 return BLUETOOTH_ERROR_INTERNAL;
4323 return BLUETOOTH_ERROR_NONE;
4326 int _bt_gatt_get_all_characteristic(bluetooth_gatt_client_svc_prop_info_t *svc)
4328 BT_CHECK_PARAMETER(svc, return);
4329 struct gatt_server_info_t *conn_info = NULL;
4330 invocation_info_t *req_info = NULL;
4331 bluetooth_gatt_client_svc_prop_info_t *prop;
4332 oal_gatt_srvc_id_t srvc_id;
4333 int ret = OAL_STATUS_SUCCESS;
4336 /* Check if any app is already browsing characteristics of the same service on the same remote GATT Server */
4337 req_info = _bt_get_request_info_data_from_function_name(BT_GATT_GET_SERVICE_PROPERTIES);
4339 prop = (bluetooth_gatt_client_svc_prop_info_t*)req_info->user_data;
4340 if (prop && !memcmp(svc->device_address.addr, prop->device_address.addr, sizeof(bluetooth_device_address_t))
4341 && !memcmp(prop->svc.uuid, svc->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN)
4342 && prop->svc.instance_id == svc->svc.instance_id) {
4343 BT_INFO("Already Properties browsing for Primary Service ongoing for same remote GATT Server");
4344 /* Return and wait for events to be sent to all apps */
4345 return BLUETOOTH_ERROR_NONE;
4349 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4350 _bt_convert_addr_type_to_string(addr, svc->device_address.addr);
4352 /* Check if remote GATT Server is connected or not */
4353 conn_info = _bt_find_remote_gatt_server_info(addr);
4355 BT_DBG("GATT Server [%s] is connected, conn Id [%d]",
4356 conn_info->addr, conn_info->connection_id);
4358 BT_ERR("GATT Server is not yet connected..");
4360 return BLUETOOTH_ERROR_NOT_CONNECTED;
4363 srvc_id.is_prmry = TRUE;
4364 srvc_id.id.inst_id = svc->svc.instance_id;
4365 memcpy(srvc_id.id.uuid.uuid, svc->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4367 /* Search All Characteristic */
4368 ret = gattc_get_characteristic(conn_info->connection_id, &srvc_id, NULL);
4369 if (ret != OAL_STATUS_SUCCESS) {
4370 BT_ERR("ret: %d", ret);
4372 return BLUETOOTH_ERROR_INTERNAL;
4375 return BLUETOOTH_ERROR_NONE;
4378 int _bt_gatt_get_all_characteristic_properties(
4379 bluetooth_gatt_client_char_prop_info_t *chr)
4381 struct gatt_server_info_t *conn_info = NULL;
4382 invocation_info_t *req_info = NULL;
4383 bluetooth_gatt_client_char_prop_info_t *prop;
4384 oal_gatt_srvc_id_t srvc_id;
4385 oal_gatt_id_t char_id;
4386 int ret = OAL_STATUS_SUCCESS;
4389 BT_CHECK_PARAMETER(chr, return);
4391 /* Check if any app is already browsing descriptors of the same char of
4392 particular service on the same remote GATT Server */
4393 req_info = _bt_get_request_info_data_from_function_name(BT_GATT_GET_CHARACTERISTIC_PROPERTIES);
4395 prop = (bluetooth_gatt_client_char_prop_info_t*)req_info->user_data;
4396 if (prop && !memcmp(chr->device_address.addr, prop->device_address.addr, sizeof(bluetooth_device_address_t)) /* Address matched */
4397 && !memcmp(chr->svc.uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Service UUID matched */
4398 && chr->svc.instance_id == prop->svc.instance_id /* Service Instance ID matched */
4399 && !memcmp(chr->characteristic.uuid, prop->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Characteristic UUID matched */
4400 && chr->characteristic.instance_id == prop->characteristic.instance_id) { /* Characteristic Instance ID matched */
4401 BT_INFO("Already Properties browsing for Characteristic ongoing for same remote GATT Server");
4402 /* Return and wait for events to be sent to all apps */
4403 return BLUETOOTH_ERROR_NONE;
4407 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4408 _bt_convert_addr_type_to_string(addr, chr->device_address.addr);
4410 /* Check if remote GATT Server is connected or not */
4411 conn_info = _bt_find_remote_gatt_server_info(addr);
4413 BT_DBG("GATT Server [%s] is connected, conn Id [%d]",
4414 conn_info->addr, conn_info->connection_id);
4416 BT_ERR("GATT Server is not yet connected..");
4418 return BLUETOOTH_ERROR_NOT_CONNECTED;
4421 srvc_id.is_prmry = TRUE;
4422 srvc_id.id.inst_id = chr->svc.instance_id;
4423 memcpy(srvc_id.id.uuid.uuid, chr->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4425 char_id.inst_id = chr->characteristic.instance_id;
4426 memcpy(char_id.uuid.uuid, chr->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4428 /* Search All Descriptors */
4429 ret = gattc_get_descriptor(conn_info->connection_id, &srvc_id, &char_id, NULL);
4430 if (ret != OAL_STATUS_SUCCESS) {
4431 BT_ERR("ret: %d", ret);
4433 return BLUETOOTH_ERROR_INTERNAL;
4436 return BLUETOOTH_ERROR_NONE;
4439 int _bt_gatt_read_characteristic_value(
4440 bluetooth_gatt_client_char_prop_info_t *chr)
4442 struct gatt_server_info_t *conn_info = NULL;
4443 invocation_info_t *req_info = NULL;
4444 bluetooth_gatt_client_char_prop_info_t *prop;
4445 oal_gatt_srvc_id_t srvc_id;
4446 oal_gatt_id_t char_id;
4447 int ret = OAL_STATUS_SUCCESS;
4450 BT_CHECK_PARAMETER(chr, return);
4452 /* Check if any app is already Reading characteristic of the same char of
4453 particular service on the same remote GATT Server */
4454 req_info = _bt_get_request_info_data_from_function_name(BT_GATT_READ_CHARACTERISTIC);
4456 prop = (bluetooth_gatt_client_char_prop_info_t*)req_info->user_data;
4457 if (prop && !memcmp(chr->device_address.addr, prop->device_address.addr, sizeof(bluetooth_device_address_t)) /* Address matched */
4458 && memcmp(chr->svc.uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Service UUID matched */
4459 && chr->svc.instance_id == prop->svc.instance_id /* Service Instance ID matched */
4460 && memcmp(chr->characteristic.uuid, prop->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Characteristic UUID matched */
4461 && chr->characteristic.instance_id == prop->characteristic.instance_id) { /* Characteristic Instance ID matched */
4462 BT_INFO("Already Characteristic value Read operation in progress for same remote GATT Server");
4463 /* Return and wait for events to be sent to all apps */
4464 return BLUETOOTH_ERROR_NONE;
4468 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4469 _bt_convert_addr_type_to_string(addr, chr->device_address.addr);
4471 /* Check if remote GATT Server is connected or not */
4472 conn_info = _bt_find_remote_gatt_server_info(addr);
4474 BT_DBG("GATT Server [%s] is connected, conn Id [%d]",
4475 conn_info->addr, conn_info->connection_id);
4477 BT_ERR("GATT Server is not yet connected..");
4479 return BLUETOOTH_ERROR_NOT_CONNECTED;
4482 srvc_id.is_prmry = TRUE;
4483 srvc_id.id.inst_id = chr->svc.instance_id;
4484 memcpy(srvc_id.id.uuid.uuid, chr->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4486 char_id.inst_id = chr->characteristic.instance_id;
4487 memcpy(char_id.uuid.uuid, chr->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4489 /* Search All Descriptors */
4490 ret = gattc_read_characteristic(conn_info->connection_id, &srvc_id, &char_id, OAL_GATT_AUTH_REQ_NONE);
4491 if (ret != OAL_STATUS_SUCCESS) {
4492 BT_ERR("ret: %d", ret);
4494 return BLUETOOTH_ERROR_INTERNAL;
4497 return BLUETOOTH_ERROR_NONE;
4500 int _bt_gatt_read_descriptor_value(
4501 bluetooth_gatt_client_desc_prop_info_t *desc)
4503 struct gatt_server_info_t *conn_info = NULL;
4504 invocation_info_t *req_info = NULL;
4505 bluetooth_gatt_client_desc_prop_info_t *prop;
4506 oal_gatt_srvc_id_t srvc_id;
4507 oal_gatt_id_t char_id;
4508 oal_gatt_id_t desc_id;
4509 int ret = OAL_STATUS_SUCCESS;
4512 BT_CHECK_PARAMETER(desc, return);
4514 /* Check if any app is already Reading descriptors of the same char of
4515 particular service on the same remote GATT Server */
4516 req_info = _bt_get_request_info_data_from_function_name(BT_GATT_READ_DESCRIPTOR_VALUE);
4518 prop = (bluetooth_gatt_client_desc_prop_info_t*)req_info->user_data;
4519 if (prop && !memcmp(desc->device_address.addr, prop->device_address.addr, sizeof(bluetooth_device_address_t)) /* Address matched */
4520 && memcmp(desc->svc.uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Service UUID matched */
4521 && desc->svc.instance_id == prop->svc.instance_id /* Service Instance ID matched */
4522 && memcmp(desc->characteristic.uuid, prop->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Characteristic UUID matched */
4523 && desc->characteristic.instance_id == prop->characteristic.instance_id /* Characteristic Instance ID matched */
4524 && memcmp(desc->descriptor.uuid, prop->descriptor.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Descriptor UUID matched */
4525 && desc->descriptor.instance_id == prop->descriptor.instance_id) { /* Descriptor Instance ID matched */
4526 BT_INFO("Already Descriptor value Read operation in progress for same remote GATT Server");
4527 /* Return and wait for events to be sent to all apps */
4528 return BLUETOOTH_ERROR_NONE;
4532 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4533 _bt_convert_addr_type_to_string(addr, desc->device_address.addr);
4535 /* Check if remote GATT Server is connected or not */
4536 conn_info = _bt_find_remote_gatt_server_info(addr);
4538 BT_DBG("GATT Server [%s] is connected, conn Id [%d]",
4539 conn_info->addr, conn_info->connection_id);
4541 BT_ERR("GATT Server is not yet connected..");
4543 return BLUETOOTH_ERROR_NOT_CONNECTED;
4546 srvc_id.is_prmry = TRUE;
4547 srvc_id.id.inst_id = desc->svc.instance_id;
4548 memcpy(srvc_id.id.uuid.uuid, desc->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4550 char_id.inst_id = desc->characteristic.instance_id;
4551 memcpy(char_id.uuid.uuid, desc->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4553 desc_id.inst_id = desc->descriptor.instance_id;
4554 memcpy(desc_id.uuid.uuid, desc->descriptor.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4556 /* Search All Descriptors */
4557 ret = gattc_read_descriptor(conn_info->connection_id, &srvc_id, &char_id,
4558 &desc_id, OAL_GATT_AUTH_REQ_NONE);
4559 if (ret != OAL_STATUS_SUCCESS) {
4560 BT_ERR("ret: %d", ret);
4562 return BLUETOOTH_ERROR_INTERNAL;
4565 return BLUETOOTH_ERROR_NONE;
4569 int _bt_gatt_acquire_notify(bluetooth_gatt_client_char_prop_info_t *chr, int *fd, int *mtu)
4571 struct gatt_server_info_t *conn_info = NULL;
4572 oal_gatt_srvc_id_t srvc_id;
4573 oal_gatt_id_t char_id;
4574 int ret = OAL_STATUS_SUCCESS;
4577 BT_CHECK_PARAMETER(chr, return);
4579 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4580 _bt_convert_addr_type_to_string(addr, chr->device_address.addr);
4582 /* Check if remote GATT Server is connected or not */
4583 conn_info = _bt_find_remote_gatt_server_info(addr);
4585 BT_DBG("GATT Server [%s] is connected, conn Id [%d]",
4586 conn_info->addr, conn_info->connection_id);
4588 BT_ERR("GATT Server is not yet connected..");
4590 return BLUETOOTH_ERROR_NOT_CONNECTED;
4593 srvc_id.is_prmry = TRUE;
4594 srvc_id.id.inst_id = chr->svc.instance_id;
4595 memcpy(srvc_id.id.uuid.uuid, chr->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4597 char_id.inst_id = chr->characteristic.instance_id;
4598 memcpy(char_id.uuid.uuid, chr->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4600 ret = gattc_acquire_notify(conn_info->connection_id, &srvc_id, &char_id, fd, mtu);
4602 if (ret != OAL_STATUS_SUCCESS) {
4603 BT_ERR("ret: %d", ret);
4605 return BLUETOOTH_ERROR_INTERNAL;
4607 BT_INFO("GATT characterstics FD [%d] mtu[%d]", *fd, *mtu);
4609 return BLUETOOTH_ERROR_NONE;
4613 int _bt_gatt_acquire_write(bluetooth_gatt_client_char_prop_info_t *chr, int *fd, int *mtu)
4616 struct gatt_server_info_t *conn_info = NULL;
4617 oal_gatt_srvc_id_t srvc_id;
4618 oal_gatt_id_t char_id;
4619 int ret = OAL_STATUS_SUCCESS;
4622 BT_CHECK_PARAMETER(chr, return);
4624 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4625 _bt_convert_addr_type_to_string(addr, chr->device_address.addr);
4627 /* Check if remote GATT Server is connected or not */
4628 conn_info = _bt_find_remote_gatt_server_info(addr);
4630 BT_DBG("GATT Server [%s] is connected, conn Id [%d]",
4631 conn_info->addr, conn_info->connection_id);
4633 BT_ERR("GATT Server is not yet connected..");
4635 return BLUETOOTH_ERROR_NOT_CONNECTED;
4638 srvc_id.is_prmry = TRUE;
4639 srvc_id.id.inst_id = chr->svc.instance_id;
4640 memcpy(srvc_id.id.uuid.uuid, chr->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4642 char_id.inst_id = chr->characteristic.instance_id;
4643 memcpy(char_id.uuid.uuid, chr->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4645 ret = gattc_acquire_write(conn_info->connection_id, &srvc_id, &char_id,
4646 OAL_GATT_AUTH_REQ_NONE, fd, mtu);
4647 if (ret != OAL_STATUS_SUCCESS) {
4648 BT_ERR("ret: %d", ret);
4650 return BLUETOOTH_ERROR_INTERNAL;
4652 BT_INFO("GATT characterstics FD [%d] mtu [%d]", *fd, *mtu);
4654 return BLUETOOTH_ERROR_NONE;
4659 /* Write Characteristic */
4660 int _bt_gatt_write_characteristic_value_by_type(
4661 bluetooth_gatt_client_char_prop_info_t *chr,
4662 bluetooth_gatt_att_data_t *data,
4663 bluetooth_gatt_write_type_e write_type)
4665 struct gatt_server_info_t *conn_info = NULL;
4666 invocation_info_t *req_info = NULL;
4667 bluetooth_gatt_client_char_prop_info_t *prop;
4668 oal_gatt_srvc_id_t srvc_id;
4669 oal_gatt_id_t char_id;
4670 int ret = OAL_STATUS_SUCCESS;
4674 BT_CHECK_PARAMETER(chr, return);
4675 BT_CHECK_PARAMETER(data, return);
4679 /* Check if any app is already writing same char of
4680 particular service on the same remote GATT Server */
4681 req_info = _bt_get_request_info_data_from_function_name(BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE);
4683 prop = (bluetooth_gatt_client_char_prop_info_t*)req_info->user_data;
4684 if (prop && !memcmp(chr->device_address.addr, prop->device_address.addr, sizeof(bluetooth_device_address_t)) /* Address matched */
4685 && memcmp(chr->svc.uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Service UUID matched */
4686 && chr->svc.instance_id == prop->svc.instance_id /* Service Instance ID matched */
4687 && memcmp(chr->characteristic.uuid, prop->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Characteristic UUID matched */
4688 && chr->characteristic.instance_id == prop->characteristic.instance_id) { /* Characteristic Instance ID matched */
4689 BT_INFO("Already Characteristic Write Value operation in progress for same remote GATT Server");
4690 /* Return and wait for events to be sent to all apps */
4691 return BLUETOOTH_ERROR_NONE;
4695 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4696 _bt_convert_addr_type_to_string(addr, chr->device_address.addr);
4698 /* Check if remote GATT Server is connected or not */
4699 conn_info = _bt_find_remote_gatt_server_info(addr);
4701 BT_INFO("GATT Server [%s] is connected, conn Id [%d]",
4702 conn_info->addr, conn_info->connection_id);
4704 BT_ERR("GATT Server is not yet connected..");
4706 return BLUETOOTH_ERROR_NOT_CONNECTED;
4709 srvc_id.is_prmry = TRUE;
4710 srvc_id.id.inst_id = chr->svc.instance_id;
4711 memcpy(srvc_id.id.uuid.uuid, chr->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4713 char_id.inst_id = chr->characteristic.instance_id;
4714 memcpy(char_id.uuid.uuid, chr->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4716 /* Write CHar value */
4718 BT_INFO("Connection ID [%d] write type [%d] data length [%d]", conn_info->connection_id, write_type, data->length);
4719 for (k = 0; k < data->length; k++)
4720 BT_INFO("Data[%d] [0x%x]", k, data->data[k]);
4722 ret = gattc_write_characteristic(conn_info->connection_id,
4724 (oal_gatt_write_type_t)write_type, data->length,
4725 OAL_GATT_AUTH_REQ_NONE, (char *)(&data->data[0]));
4726 if (ret != OAL_STATUS_SUCCESS) {
4727 BT_ERR("ret: %d", ret);
4729 return BLUETOOTH_ERROR_INTERNAL;
4732 return BLUETOOTH_ERROR_NONE;
4735 /* Write Descriptor */
4736 int _bt_gatt_write_descriptor_value_by_type(
4737 bluetooth_gatt_client_desc_prop_info_t *desc,
4738 bluetooth_gatt_att_data_t *data,
4739 bluetooth_gatt_write_type_e write_type)
4741 struct gatt_server_info_t *conn_info = NULL;
4742 invocation_info_t *req_info = NULL;
4743 bluetooth_gatt_client_desc_prop_info_t *prop;
4744 oal_gatt_srvc_id_t srvc_id;
4745 oal_gatt_id_t char_id;
4746 oal_gatt_id_t desc_id;
4747 int ret = OAL_STATUS_SUCCESS;
4751 BT_CHECK_PARAMETER(desc, return);
4752 BT_CHECK_PARAMETER(data, return);
4756 /* Check if any app is already writing on same Descriptor of the same char of
4757 particular service on the same remote GATT Server */
4758 req_info = _bt_get_request_info_data_from_function_name(BT_GATT_WRITE_DESCRIPTOR_VALUE);
4760 prop = (bluetooth_gatt_client_desc_prop_info_t*)req_info->user_data;
4761 if (prop && !memcmp(desc->device_address.addr, prop->device_address.addr, sizeof(bluetooth_device_address_t)) /* Address matched */
4762 && memcmp(desc->svc.uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Service UUID matched */
4763 && desc->svc.instance_id == prop->svc.instance_id /* Service Instance ID matched */
4764 && memcmp(desc->characteristic.uuid, prop->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Characteristic UUID matched */
4765 && desc->characteristic.instance_id == prop->characteristic.instance_id /* Characteristic Instance ID matched */
4766 && memcmp(desc->descriptor.uuid, prop->descriptor.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Descriptor UUID matched */
4767 && desc->descriptor.instance_id == prop->descriptor.instance_id) { /* Descriptor Instance ID matched */
4768 BT_INFO("Already Descriptor value Write operation in progress for same remote GATT Server");
4769 /* Return and wait for events to be sent to all apps */
4770 return BLUETOOTH_ERROR_NONE;
4774 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4775 _bt_convert_addr_type_to_string(addr, desc->device_address.addr);
4777 /* Check if remote GATT Server is connected or not */
4778 conn_info = _bt_find_remote_gatt_server_info(addr);
4780 BT_INFO("GATT Server [%s] is connected, conn Id [%d]",
4781 conn_info->addr, conn_info->connection_id);
4783 BT_ERR("GATT Server is not yet connected..");
4785 return BLUETOOTH_ERROR_NOT_CONNECTED;
4788 srvc_id.is_prmry = TRUE;
4789 srvc_id.id.inst_id = desc->svc.instance_id;
4790 memcpy(srvc_id.id.uuid.uuid, desc->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4792 char_id.inst_id = desc->characteristic.instance_id;
4793 memcpy(char_id.uuid.uuid, desc->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4795 desc_id.inst_id = desc->descriptor.instance_id;
4796 memcpy(desc_id.uuid.uuid, desc->descriptor.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4799 BT_INFO("Connection ID [%d] write type [%d] data length [%d]", conn_info->connection_id, write_type, data->length);
4800 for (k = 0; k < data->length; k++)
4801 BT_INFO("Data[%d] [0x%x]", k, data->data[k]);
4803 ret = gattc_write_descriptor(conn_info->connection_id,
4804 &srvc_id, &char_id, &desc_id,
4805 (oal_gatt_write_type_t)write_type, data->length,
4806 OAL_GATT_AUTH_REQ_NONE, (char *)(&data->data[0]));
4807 if (ret != OAL_STATUS_SUCCESS) {
4808 BT_ERR("ret: %d", ret);
4810 return BLUETOOTH_ERROR_INTERNAL;
4813 return BLUETOOTH_ERROR_NONE;
4816 int _bt_gatt_watch_characteristic(
4817 bluetooth_gatt_client_char_prop_info_t *chr,
4821 struct gatt_server_info_t *conn_info = NULL;
4822 oal_gatt_srvc_id_t srvc_id;
4823 oal_gatt_id_t char_id;
4824 int ret = OAL_STATUS_SUCCESS;
4827 BT_CHECK_PARAMETER(chr, return);
4829 BT_INFO("Client ID [%d] Is Notify [%d]", client_id, is_notify);
4831 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4832 _bt_convert_addr_type_to_string(addr, chr->device_address.addr);
4834 /* Check if remote GATT Server is connected or not */
4835 conn_info = _bt_find_remote_gatt_server_info(addr);
4837 BT_INFO("GATT Server [%s] is connected, conn Id [%d]",
4838 conn_info->addr, conn_info->connection_id);
4840 BT_ERR("GATT Server is not yet connected..");
4842 return BLUETOOTH_ERROR_NOT_CONNECTED;
4844 srvc_id.is_prmry = TRUE;
4845 srvc_id.id.inst_id = chr->svc.instance_id;
4846 memcpy(srvc_id.id.uuid.uuid, chr->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4848 char_id.inst_id = chr->characteristic.instance_id;
4849 memcpy(char_id.uuid.uuid, chr->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4851 /* Register or unregister Notification characteristic */
4853 ret = gattc_register_for_notification(conn_info->connection_id,
4854 (bt_address_t*)&(chr->device_address),
4855 &srvc_id, &char_id);
4857 ret = gattc_deregister_for_notification(conn_info->connection_id,
4858 (bt_address_t*)&(chr->device_address),
4859 &srvc_id, &char_id);
4861 BT_INFO("Result[%d]", ret);
4862 if (ret != OAL_STATUS_SUCCESS) {
4863 BT_ERR("ret: %d", ret);
4865 return BLUETOOTH_ERROR_INTERNAL;
4868 return BLUETOOTH_ERROR_NONE;
4872 int _bt_disconnect_le_device(bluetooth_device_address_t *address,
4875 struct gatt_server_info_t *conn_info = NULL;
4876 struct gatt_client_info_t *rem_client_conn_info = NULL;
4877 invocation_info_t *req_info = NULL;
4878 int ret = OAL_STATUS_SUCCESS;
4880 char *remote_address = NULL;
4882 BT_CHECK_PARAMETER(address, return);
4884 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4885 _bt_convert_addr_type_to_string(addr, address->addr);
4886 BT_INFO("GATT Client Disconnect request for address [%s]", addr);
4888 /* Check if Remote Device is already under connection progress */
4889 req_info = _bt_get_request_info_data_from_function_name(BT_DISCONNECT_LE);
4891 remote_address = (char*)req_info->user_data;
4892 if (remote_address && !strcasecmp(remote_address, addr)) {/* Address matched */
4893 BT_DBG("Already DisConnection ongoing for same remote GATT Server address [%s]", remote_address);
4894 /* Return success and wait for events to be sent to all apps */
4896 return BLUETOOTH_ERROR_IN_PROGRESS;
4899 /* Check if remote GATT Server is connected or not */
4900 conn_info = _bt_find_remote_gatt_server_info(addr);
4902 /* Check if app sent 0 client id for Disconnection, in such case, use default gatt client ID */
4903 if (client_id == 0) {
4904 BT_INFO("GATT CLient Disconnect request sent by an app without any client instance [%d]",
4906 BT_INFO("Assign default GATT client id [%d]", gatt_default_client);
4907 client_id = gatt_default_client;
4910 BT_INFO("Disconnect remote gatt server using CLient ID [%d] Connection ID [%d]", client_id, conn_info->connection_id);
4911 ret = gattc_disconnect(client_id, (bt_address_t*)(address),
4912 conn_info->connection_id);
4914 /* check if remote client is connected */
4915 rem_client_conn_info = _bt_find_remote_gatt_client_info(addr);
4917 if (!rem_client_conn_info || client_id != 0) {
4918 BT_ERR("GATT device is not connected..");
4920 return BLUETOOTH_ERROR_NOT_IN_OPERATION;
4923 BT_INFO("Disconnect remote gatt client ");
4925 ret = gatts_disconnect(rem_client_conn_info->instance_id,
4926 (bt_address_t*)(address), rem_client_conn_info->connection_id);
4929 if (ret != OAL_STATUS_SUCCESS) {
4930 BT_ERR("ret: %d", ret);
4932 return BLUETOOTH_ERROR_INTERNAL;
4935 return BLUETOOTH_ERROR_NONE;
4938 int _bt_gatt_watch_service_changed_indication(const char *sender,
4939 bluetooth_device_address_t *address,
4940 gboolean is_enabled)
4943 bt_service_app_info_t *info = NULL;
4945 BT_INFO("%s Servic changed Indication watcher for app [%s]",
4946 is_enabled ? "Enable":"Disable", sender);
4948 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
4951 if (g_strcmp0(sender, info->sender) == 0 &&
4952 memcmp(info->address.addr, address->addr,
4953 sizeof(bluetooth_device_address_t)) == 0) {
4954 BT_DBG("Found GATT client App.. [%s], sender [%s]", info->uuid, info->sender);
4955 info->is_watcher_enabled = is_enabled;
4959 return BLUETOOTH_ERROR_NONE;
4962 int _bt_unregister_gatt_client_instance(const char *sender, int client_id)
4964 bt_service_app_info_t *info = NULL;
4967 BT_INFO("Unregister Allocated GATT Client instance [%s] Client ID [%d]", sender, client_id);
4969 /* Unregister CLient instance associated with address X. It is possible that another app still
4970 has client_id valid for same remote address */
4971 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
4974 /* Exact matching of sender */
4975 if (!g_strcmp0(info->sender, sender) && info->client_id == client_id) { /* Check for only valid GATT client Instance */
4976 BT_INFO("Unregister GATT client instance [%d]", info->client_id);
4977 numapps[k].client_id = -1;
4978 numapps[k].is_initialized = FALSE;
4979 memset(numapps[k].sender, 0x00, sizeof(numapps[k].sender));
4980 memset(numapps[k].uuid, 0x00, sizeof(numapps[k].uuid));
4981 memset(&numapps[k].address.addr, 0x00, sizeof(bluetooth_device_address_t));
4983 /* Its a GATT Client Instance */
4984 ret = gattc_deregister(client_id);
4985 if (ret != OAL_STATUS_SUCCESS) {
4986 BT_ERR("DeAllocate GATT Client instance with stack Fail ret: %d", ret);
4987 return BLUETOOTH_ERROR_INTERNAL;
4989 return BLUETOOTH_ERROR_NONE;
4994 return BLUETOOTH_ERROR_NOT_FOUND;
4997 static void __bt_handle_client_mtu_exchange_completed(event_gattc_mtu_configured_t *event_data)
4999 int result = BLUETOOTH_ERROR_NONE;
5000 struct gatt_server_info_t *conn_info = NULL;
5001 GVariant *param = NULL;
5005 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(event_data->conn_id);
5006 if (conn_info == NULL) {
5007 BT_ERR("Cant find connection Information");
5011 BT_INFO("GATT Client: MTU Configured from addr [%s] status [%d] MTU size [%d]",
5012 conn_info->addr, event_data->status, event_data->mtu);
5014 if (event_data->status != OAL_STATUS_SUCCESS)
5015 result = BLUETOOTH_ERROR_INTERNAL;
5017 BT_INFO("reply BT_REQ_ATT_MTU ");
5019 /* DBUS Return fo BT_REQ_ATT_MTU for all the apps */
5020 __bt_gatt_handle_pending_request_info(result, BT_REQ_ATT_MTU, conn_info->addr,
5021 BT_ADDRESS_STRING_SIZE);
5023 if (result == BLUETOOTH_ERROR_NONE) {
5024 BT_INFO("sending mtu event");
5026 mtu = event_data->mtu;
5027 param = g_variant_new("(isqy)",
5033 /* Send event to BT-API */
5034 _bt_send_event(BT_DEVICE_EVENT,
5035 BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED,
5038 /* Update the MTU for current connection */
5039 BT_INFO("Updating the MTU for current connection");
5040 __bt_update_mtu_gatt_device(conn_info->addr, event_data->mtu);
5044 static struct gatt_mtu_info_t *__bt_find_mtu_gatt_device(char *address)
5047 struct gatt_mtu_info_t *info = NULL;
5051 for (l = gatt_mtu_info_list; l != NULL; l = g_slist_next(l)) {
5052 info = (struct gatt_mtu_info_t*)l->data;
5056 if (!g_strcmp0(info->addr, address)) {
5057 BT_INFO("Remote GATT device found addr[%s]", info->addr);
5062 BT_INFO("Not found Remote GATT device addr[%s]", address);
5066 static void __bt_remove_mtu_gatt_device(char *address)
5068 struct gatt_mtu_info_t *dev_info = NULL;
5072 dev_info = __bt_find_mtu_gatt_device(address);
5075 BT_INFO("removing the gatt device from mtu list");
5076 gatt_mtu_info_list = g_slist_remove(gatt_mtu_info_list, dev_info);
5077 g_free(dev_info->addr);
5082 static void __bt_add_mtu_gatt_device(char *address)
5084 struct gatt_mtu_info_t *dev_info = NULL;
5088 dev_info = __bt_find_mtu_gatt_device(address);
5091 BT_INFO("adding the gatt device in mtu list");
5092 dev_info = g_new0(struct gatt_mtu_info_t, 1);
5093 dev_info->addr = g_strdup(address);
5094 dev_info->att_mtu = BT_DEFAULT_ATT_MTU;
5095 gatt_mtu_info_list = g_slist_append(gatt_mtu_info_list, dev_info);
5099 static void __bt_update_mtu_gatt_device(char *address, int mtu)
5101 struct gatt_mtu_info_t *dev_info = NULL;
5105 dev_info = __bt_find_mtu_gatt_device(address);
5108 BT_INFO("Udating the mtu");
5109 dev_info->att_mtu = mtu;