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 GSList *list_gatt_info;
188 /* App Information structure */
191 char sender[BT_SENDER_MAX_LENGTH];
192 char uuid[BT_UUID_STRING_MAX];
195 bluetooth_advertising_data_t adv_data; /* Will store adv data for specific slot */
197 bluetooth_scan_resp_data_t scan_rsp; /* Will store scan rsp data for specific slot */
199 gboolean is_initialized;
200 GSList *service_handles;
201 #ifdef TIZEN_GATT_CLIENT
202 int client_id; /* GATT Client instance ID */
203 bluetooth_device_address_t address; /* Remote BLE Device Address */
204 gboolean is_watcher_enabled;
206 } bt_service_app_info_t;
208 /* GATT Server Request Info Structure */
209 struct gatt_server_req_info {
210 int connection_id; /* This value will uniquely identify a GATT client-server connection */
211 int request_id; /* This is an unique transaction ID assigned against each request by stack */
212 int attribute_handle; /* GATT server attribute handle */
213 int offset; /* GATT server attribute offset on which request is invoked by GATT client */
214 bluetooth_gatt_att_request_type_e request_type; /* Read or Write request */
215 char *addr; /* Remote GATT client address */
218 /* GATT Client Info List Structure */
219 struct gatt_client_info_t {
220 int connection_id; /* This value will uniquely identify a GATT client-server connection */
221 int instance_id; /* This value unique identifies a GATT server instance */
222 char *addr; /* Remote GATT client address */
225 /* GATT Indicate confirm result */
226 struct gatt_indicate_cfm_result_info_t {
227 int result; /* Result of event */
228 char *addr; /* Remote GATT client address */
229 int att_hdl; /* Characteristic Attribute handle */
230 int completed; /* 1 if last event, otheriwse 0 */
233 /* Request Search Utility method */
234 static struct gatt_server_req_info *__bt_gatt_server_find_request_info(int request_id,
235 bluetooth_gatt_att_request_type_e req_type);
237 static int __bt_gatt_send_indication_to_all_connected_clients(bluetooth_gatt_att_data_t *data,
238 bluetooth_gatt_server_indication_params_t *param);
240 static void __bt_remove_all_service_handles(bt_service_app_info_t *app_info);
242 static void __bt_free_service_info(bt_gatt_service_info_t *service_info);
244 static int __bt_unregister_gatt_client_instance(int client_if);
246 static void __bt_service_reset_gatt_data(void);
248 #ifdef TIZEN_GATT_CLIENT
249 static void __bt_handle_client_instance_registered(event_gattc_register_t *data);
250 static void __bt_handle_client_connected(event_gattc_conn_t *event_data);
251 static void __bt_handle_client_disconnected(event_gattc_conn_t *event_data);
252 static void __bt_handle_client_service_search_completed(event_gattc_conn_status_t *event_data);
253 static void __bt_handle_client_service_search_result(event_gattc_service_result_t *event_data);
254 static void __bt_handle_client_characteristic_search_result(
255 event_gattc_characteristic_result_t *event_data);
256 static void __bt_handle_client_descriptor_search_result(event_gattc_descriptor_result_t *event_data);
257 static void __bt_handle_client_characteristic_read_data(event_gattc_read_data *event_data);
258 static void __bt_handle_client_descriptor_read_data(event_gattc_read_data *event_data);
259 static void __bt_handle_client_characteristic_write_data(event_gattc_write_data *event_data);
260 static void __bt_handle_client_descriptor_write_data(event_gattc_write_data *event_data);
261 static void __bt_hanlde_le_device_disconnection(event_dev_conn_status_t *event_data);
262 static void __bt_handle_client_notification_registered(event_gattc_regdereg_notify_t *event_data,
263 gboolean is_registered);
264 static void __bt_handle_client_notification_data(event_gattc_notify_data *event_data);
265 static void __bt_handle_client_service_changed_ind(event_gattc_service_changed_data *event_data);
266 static void __bt_handle_client_mtu_exchange_completed(event_gattc_mtu_configured_t *event_data);
269 static int __bt_unregister_gatt_server_instance(int server_instance);
272 struct gatt_mtu_info_t {
273 char *addr; /* Remote GATT Server address */
277 static GSList *gatt_mtu_info_list = NULL;
279 static struct gatt_mtu_info_t *__bt_find_mtu_gatt_device(char *address);
280 static void __bt_remove_mtu_gatt_device(char *address);
281 static void __bt_add_mtu_gatt_device(char *address);
282 static void __bt_update_mtu_gatt_device(char *address, int mtu);
284 /* Linked List of GATT requests from Remote GATT Clients */
285 static GSList *gatt_server_requests = NULL;
287 /* Linked List of connected Remote GATT clients */
288 static GSList *gatt_client_info_list = NULL;
290 /* Number of clients to be notified to */
291 static int num_indicate_clients;
293 /* List of applications */
294 static bt_service_app_info_t numapps[MAX_APPS_SUPPORTED];
296 static void __bt_gatt_handle_pending_request_info(int result,
297 int service_function, void *data, unsigned int size);
299 static void __bt_handle_server_instance_registered(event_gatts_register_t *data);
301 static void __bt_gatt_event_handler(int event_type, gpointer event_data);
308 void _bt_check_adv_app_termination(const char *name)
310 bt_service_app_info_t *app = NULL;
312 int apps[MAX_APPS_SUPPORTED] = { 0, };
314 ret_if(NULL == name);
316 memset(&apps, -1, sizeof(apps));
318 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
321 /* Search for a app which has same sender and stop adv is running */
322 if (!strncasecmp(app->sender, name, strlen(name)) && app->is_initialized == TRUE) {
323 BT_DBG("Match found, name: %s", name);
325 /* TODO 2: Need to manage app info as list, not array.
326 This loop always run for MAX count if any apps are terminated.
329 /* Save instances of all apps that need to be unregistered */
330 if (app->instance_id != -1) {
332 /* Unregister all service handles with stack */
333 __bt_remove_all_service_handles(app);
335 /* If Advertising is enabled, stop it */
336 if (app->adv_handle > 0) {
337 BT_INFO("Stop advertising on instance ID [%d]", app->instance_id);
338 /* Disable adv if running */
339 BT_INFO("Disable Advertising Adv Handle [%d] sender [%s]",
340 app->adv_handle, name);
341 _bt_set_advertising(app->sender, app->adv_handle, FALSE, FALSE);
344 apps[app->instance_id] = BT_GATT_SERVER; /* App holds a GATT server Instance */
345 } else if (app->client_id != -1) {
347 apps[app->client_id] = BT_GATT_CLIENT; /* App holds a GATT client Instance */
352 /* Unregister all apps one by one */
353 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
354 if (apps[k] == BT_GATT_SERVER) {
355 BT_INFO("Unregister server app[%d]", k);
356 /* Unregister server instance */
357 __bt_unregister_gatt_server_instance(k);
358 } else if (apps[k] == BT_GATT_CLIENT) {
359 BT_INFO("Unregister client app[%d]", k);
360 /* Unregister client instance */
361 __bt_unregister_gatt_client_instance(k);
366 static int __bt_gatt_send_indication_to_all_connected_clients(bluetooth_gatt_att_data_t *data,
367 bluetooth_gatt_server_indication_params_t *param)
370 int ret = OAL_STATUS_SUCCESS;
371 int result = OAL_STATUS_INTERNAL_ERROR;
373 BT_INFO("Current total number of connected clients [%d]", g_slist_length(gatt_client_info_list));
374 for (l = gatt_client_info_list; l != NULL; l = l->next) {
375 struct gatt_client_info_t *info = l->data;
378 BT_INFO("GATT Remote client address [%s] connection Id [%d]", info->addr, info->connection_id);
380 ret = gatts_send_indication(param->instance_id, param->atrribute_handle,
381 info->connection_id, data->length,
382 param->need_confirmation, (char *)(&data->data[0]));
384 BT_INFO("Send Indication to GATT client [%s] result: [%d]", info->addr, ret);
385 if (ret == OAL_STATUS_SUCCESS) {
386 BT_INFO("Send Indication sent successfully to GATT client [%s]", info->addr);
388 num_indicate_clients++;
392 BT_INFO("Indication sending done for total number of clients [%d]", num_indicate_clients);
396 static struct gatt_server_req_info *__bt_gatt_server_find_request_info(int request_id,
397 bluetooth_gatt_att_request_type_e req_type)
401 for (l = gatt_server_requests; l != NULL; l = l->next) {
402 struct gatt_server_req_info *req_info = l->data;
404 if (req_info && req_info->request_id == request_id && req_info->request_type == req_type) {
405 BT_INFO("GATT Server request info found Req ID [%d] handle [%d] conn ID [%d]",
406 req_info->request_id, req_info->attribute_handle, req_info->connection_id);
410 BT_ERR("Gatt Request not found");
414 void _bt_get_adv_handle_from_instance(int server_inst, int *adv_handle)
418 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
419 if (numapps[k].is_initialized == 1 && numapps[k].instance_id == server_inst) {
420 *adv_handle = numapps[k].adv_handle;
426 #ifdef TIZEN_GATT_CLIENT
427 char * _bt_gatt_get_default_gatt_client_uuid(void)
429 return g_strdup(DEFAULT_GATT_CLIENT_UUID);
433 static void __bt_register_default_gatt_client()
438 uuid_str = _bt_gatt_get_default_gatt_client_uuid();
439 _bt_string_to_uuid(uuid_str, (service_uuid_t*)&uuid);
441 BT_INFO("Register Default GATT client uuid [%s]", uuid_str);
443 if (OAL_STATUS_SUCCESS != gattc_register(&uuid)) /* for only Smart Control */
444 BT_ERR("gattc register failed");
450 int _bt_gatt_init(void)
452 const char *stack_name = NULL;
456 if (OAL_STATUS_SUCCESS != gatt_enable()) {
457 BT_ERR("gatt Init failed");
458 return BLUETOOTH_ERROR_INTERNAL;
461 /* Register gatt event handler */
462 _bt_service_register_event_handler_callback(BT_GATT_MODULE, __bt_gatt_event_handler);
464 __bt_service_reset_gatt_data();
466 stack_name = oal_get_stack_name();
468 if (stack_name && g_strcmp0(stack_name, "bluez") == 0) {
469 /*In the platform, defacult gatt client should be registered */
470 __bt_register_default_gatt_client();
474 return BLUETOOTH_ERROR_NONE;
477 static void __bt_service_reset_gatt_data(void)
481 BT_INFO("Rest numapp");
484 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
485 numapps[k].is_initialized = 0;
486 numapps[k].instance_id = -1;
487 numapps[k].adv_handle = 0;
488 numapps[k].adv_instance = -1;
489 memset(numapps[k].sender, 0x00, sizeof(numapps[k].sender));
490 memset(numapps[k].uuid, 0x00, sizeof(numapps[k].uuid));
491 memset(numapps[k].adv_data.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX);
492 memset(numapps[k].scan_rsp.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX);
493 numapps[k].adv_data_len = 0;
494 numapps[k].scan_rsp_len = 0;
497 numapps[k].client_id = -1;
498 memset(numapps[k].address.addr, 0x00, BLUETOOTH_ADDRESS_LENGTH);
499 numapps[k].is_watcher_enabled = FALSE;
503 void _bt_gatt_deinit(void)
505 BT_INFO("GATT deinit");
507 if (OAL_STATUS_SUCCESS != gatt_disable())
508 BT_ERR("gatt deinit failed");
510 /* Un-register gatt event handler */
511 _bt_service_unregister_event_handler_callback(BT_GATT_MODULE);
513 __bt_service_reset_gatt_data();
516 void _bt_update_adv_handle(const char *sender, int adv_handle)
519 BT_DBG("Sender [%s] Adv handle [%d]", sender, adv_handle);
520 bt_service_app_info_t *info = NULL;
522 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
524 /* Do not update client instance */
525 if (info->instance_id == -1)
527 /* Search for a app which has same sender and adv handle as 0 */
528 if (!g_strcmp0(info->sender, sender) && info->adv_handle == 0)
529 info->adv_handle = adv_handle;
533 int _bt_is_sender_gatt_server_with_no_adv(const char *sender, int adv_handle)
536 BT_DBG("Sender [%s] Adv handle [%d]", sender, adv_handle);
537 bt_service_app_info_t *info = NULL;
539 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
541 /* Search for a app which has same sender and adv handle as 0
542 It is possible that same sender but different adv handle */
543 if (!g_strcmp0(info->sender, sender) && info->adv_handle == 0) {
544 //info->adv_handle = adv_handle;
545 return info->instance_id;
551 int _bt_get_allocated_server_instance(const char *sender, int adv_handle, gboolean use_reserved_slot)
554 BT_DBG("Sender [%s] Adv handle [%d]", sender, adv_handle);
555 bt_service_app_info_t *info = NULL;
557 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
560 /* Exact matching of Adv handle + sender combination */
561 if (!g_strcmp0(info->sender, sender) && info->adv_handle == adv_handle)
562 return info->instance_id;
564 if (!g_strcmp0(info->sender, sender) && info->adv_handle == -1)
565 return info->instance_id;
571 char * _bt_get_sender_and_handle(int server_instance, int *adv_handle)
574 bt_service_app_info_t *info = NULL;
576 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
579 if (info->instance_id == server_instance && info->adv_handle != -1) {
580 *adv_handle = info->adv_handle;
581 BT_DBG("Server instance [%d] Adv handle [%d] Sender [%s]", server_instance, *adv_handle, info->sender);
582 return g_strdup(info->sender);
588 void _bt_set_new_adv_data(bluetooth_advertising_data_t *adv, int len, int instance)
592 bt_service_app_info_t *info = NULL;
593 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
596 if (info->instance_id == instance) {
597 memcpy(info->adv_data.data, &adv->data, len);
603 void _bt_set_new_scan_rsp_data(bluetooth_scan_resp_data_t *scan, int len, int instance)
607 bt_service_app_info_t *info = NULL;
608 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
611 if (info->instance_id == instance) {
612 memcpy(info->scan_rsp.data, &scan->data, len);
618 void _bt_get_previous_adv_data(bluetooth_advertising_data_t *adv, int *len, int instance)
621 bt_service_app_info_t *info = NULL;
623 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
626 if (info->instance_id == instance) {
627 memcpy(&adv->data, info->adv_data.data, info->adv_data_len);
628 *len = info->adv_data_len;
634 void _bt_get_previous_scan_rsp_data(bluetooth_scan_resp_data_t *scan, int *len, int instance)
638 bt_service_app_info_t *info = NULL;
640 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
643 if (info->instance_id == instance) {
644 memcpy(&scan->data, info->scan_rsp.data, info->scan_rsp_len);
645 *len = info->scan_rsp_len;
651 static int __bt_unregister_gatt_client_instance(int client_if)
653 int ret = OAL_STATUS_SUCCESS;
656 BT_INFO("DeAllocate client instance ID [%d]", client_if);
658 /* Reset data: instance_id parameter could be either for GATT Server or for GATT client */
659 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
660 if (numapps[k].client_id == client_if) {
661 BT_INFO("This is a GATT client app, unregister: Slot [%d] vacant", k);
662 numapps[k].client_id = -1;
663 numapps[k].is_initialized = FALSE;
664 memset(numapps[k].sender, 0x00, sizeof(numapps[k].sender));
665 memset(numapps[k].uuid, 0x00, sizeof(numapps[k].uuid));
666 memset(&numapps[k].address.addr, 0x00, sizeof(bluetooth_device_address_t));
668 /* Its a GATT Client Instance */
669 ret = gattc_deregister(client_if);
670 if (ret != OAL_STATUS_SUCCESS) {
671 BT_ERR("DeAllocate GATT Client instance with stack Fail ret: %d", ret);
672 return BLUETOOTH_ERROR_INTERNAL;
677 return BLUETOOTH_ERROR_NONE;
680 static int __bt_unregister_gatt_server_instance(int server_instance)
682 int ret = OAL_STATUS_SUCCESS;
685 /* Unregister the server instance */
686 ret = gatts_unregister(server_instance);
687 if (ret != OAL_STATUS_SUCCESS) {
688 BT_ERR("DeAllocate server instance with stack Fail ret: %d", ret);
689 return BLUETOOTH_ERROR_INTERNAL;
691 BT_INFO("DeAllocated server instance with stack successful..");
694 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
695 if (numapps[k].instance_id == server_instance) {
696 numapps[k].is_initialized = 0;
697 numapps[k].instance_id = -1;
698 numapps[k].adv_handle = 0;
699 numapps[k].adv_instance = -1;
700 memset(numapps[k].sender, 0x00, sizeof(numapps[k].sender));
701 memset(numapps[k].uuid, 0x00, sizeof(numapps[k].uuid));
702 memset(numapps[k].adv_data.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX);
703 memset(numapps[k].scan_rsp.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX);
704 numapps[k].adv_data_len = 0;
705 numapps[k].scan_rsp_len = 0;
709 BT_DBG("Going8 to reset numapp block num [%d]", k);
710 return BLUETOOTH_ERROR_NONE;
713 static void __bt_remove_all_service_handles(bt_service_app_info_t *app_info)
717 int ret = OAL_STATUS_SUCCESS;
720 if (app_info == NULL)
723 count = g_slist_length(app_info->service_handles);
724 BT_INFO("Before handle removal: current count [%d]", count);
726 for (l = app_info->service_handles; l != NULL;) {
731 BT_INFO("Server Handle to be Removed [%d] Instance ID [%d]", *handle, app_info->instance_id);
732 if (_bt_gatt_server_stop_service(app_info->sender, *handle, app_info->instance_id) != BLUETOOTH_ERROR_NONE)
735 ret = gatts_delete_service(app_info->instance_id, *handle);
736 if (ret != OAL_STATUS_SUCCESS) {
737 BT_ERR("ret: %d", ret);
740 app_info->service_handles = g_slist_remove(app_info->service_handles, handle);
743 count = g_slist_length(app_info->service_handles);
744 BT_INFO("After deleting current count [%d]", count);
750 int _bt_unregister_server_instance(const char *sender, int adv_handle)
752 BT_INFO("Unregister Allocated server instance request Sender [%s] Adv handle [%d]", sender, adv_handle);
753 int result = BLUETOOTH_ERROR_NONE;
754 int apps[MAX_APPS_SUPPORTED];
758 memset(&apps, -1, sizeof(apps));
760 if (adv_handle == 0) {
761 BT_DBG("Its a direct GATT Server app request to unregister");
762 /* Unregister server instance for each app with same sender (case: GATT Server with multiple adv handle) */
763 bt_service_app_info_t *info = NULL;
765 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
768 /* Exact matching of sender */
769 if (!g_strcmp0(info->sender, sender)) {
770 BT_INFO("Unregister GATT server instance [%d]", info->instance_id);
771 /* Unregister all service handles with stack */
772 __bt_remove_all_service_handles(info);
774 /* Disable adv if running */
775 BT_INFO("Disable Advertising Adv Handle [%d] sender [%s]",
776 info->adv_handle, sender);
777 _bt_set_advertising(sender, info->adv_handle, FALSE, FALSE);
779 /* Save all instances which need to be unregistered */
780 apps[info->instance_id] = 1;
784 BT_DBG("Its an Internal unregister request by adv application");
785 server_instance = _bt_get_allocated_server_instance(sender, adv_handle, FALSE);
786 BT_DBG("Its an Internal unregister request by adv application: Adv disabled srv instance [%d]", server_instance);
787 if (server_instance == -1) {
788 BT_ERR("No allocated server instance to be removed");
789 return BLUETOOTH_ERROR_INVALID_PARAM;
791 if (!numapps[server_instance].service_handles) {
792 BT_INFO("There are no Service handles with this app, safe to unregister");
793 /* Unregister server instance only if this sender does not have any gatt services in it */
794 result = __bt_unregister_gatt_server_instance(server_instance);
796 numapps[server_instance].adv_handle = 0;
797 memset(numapps[server_instance].adv_data.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX);
798 numapps[server_instance].adv_data_len = 0;
799 memset(numapps[server_instance].scan_rsp.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX);
800 numapps[server_instance].scan_rsp_len = 0;
805 /* Unregister all apps one by one */
806 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
808 BT_INFO("Unregister app[%d]", k);
809 /* Unregister server instance */
810 __bt_unregister_gatt_server_instance(k);
817 int _bt_register_server_instance(const char *sender, int adv_handle)
819 int ret = OAL_STATUS_SUCCESS;
820 char *uuid_string = NULL;
825 BT_INFO("###Check on which instance Server instance can be initialized....");
826 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
827 if (numapps[k].is_initialized == 1) {
828 BT_INFO("Instance ID [%d] is already in use..Check next slot", numapps[k].instance_id);
831 BT_INFO("Time to register GATT Server..UUID to be used is [%s] slot [%d]", uuid_list[slot-1], slot);
837 BT_ERR("No Slot if free for GATT Server registration..");
838 return BLUETOOTH_ERROR_REGISTRATION_FAILED;
841 uuid_string = g_malloc0(BT_UUID_STRING_MAX);
842 _bt_string_to_uuid(uuid_list[slot-1], (service_uuid_t*)&uuid);
843 g_strlcpy(uuid_string, uuid_list[slot-1], BT_UUID_STRING_MAX);
844 BT_INFO("Copied UUID string [%s]", uuid_string);
846 /* Register GATT Server */
847 ret = gatts_register(&uuid);
848 if (ret != OAL_STATUS_SUCCESS) {
849 BT_ERR("ret: %d", ret);
851 return BLUETOOTH_ERROR_INTERNAL;
853 BT_INFO("GATT Server registration call successfully accepted by OAL..wait for Instance Initialized event from OAL..");
854 /* Return & wait for GATT Server Instance Initialization event */
855 memset(numapps[slot].sender, 0x00, sizeof(numapps[slot].sender));
856 memset(numapps[slot].uuid, 0x00, sizeof(numapps[slot].uuid));
858 g_strlcpy(numapps[slot].sender, sender, sizeof(numapps[slot].sender));
859 g_strlcpy(numapps[slot].uuid, uuid_string, sizeof(numapps[slot].uuid));
861 numapps[slot].is_initialized = 0; /* Set initialization from app registered callback */
862 numapps[slot].adv_handle = adv_handle;
865 return BLUETOOTH_ERROR_NONE;
869 static void __bt_gatt_handle_pending_request_info(int result,
870 int service_function, void *data, unsigned int size)
874 invocation_info_t *req_info = NULL;
875 ret_if(data == NULL);
877 for (l = _bt_get_invocation_list(); l != NULL; ) {
880 if (req_info == NULL || req_info->service_function != service_function)
883 switch (service_function) {
885 case BT_GATT_SERVER_REGISTER: {
886 bt_service_app_info_t *param = (bt_service_app_info_t*)data;
887 BT_DBG("Sender [%s] Request Sender [%s]", param->sender, req_info->sender);
888 if (!g_strcmp0(req_info->sender, param->sender)) {
889 BT_DBG("GATT Server app found [%s]", req_info->sender);
891 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
892 g_array_append_vals(out_param, ¶m->instance_id, sizeof(int));
893 _bt_service_method_return(req_info->context, out_param, result);
895 g_free(req_info->user_data);
896 _bt_free_info_from_invocation_list(req_info);
897 g_array_free(out_param, TRUE);
901 case BT_GATT_SERVER_START_SERVICE:
902 case BT_GATT_SERVER_DELETE_SERVICE: {
903 bt_service_app_info_t *param = (bt_service_app_info_t*)data;
904 BT_DBG("Sender [%s] Request Sender [%s]", param->sender, req_info->sender);
906 int *saved_instance_id = (int*)req_info->user_data;
907 if (!g_strcmp0(req_info->sender, param->sender) && param->instance_id == *saved_instance_id) {
908 BT_DBG("GATT Server app found [%s] Instance ID [%d] Reply DBUS",
909 req_info->sender, *saved_instance_id);
911 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
912 g_array_append_vals(out_param, &saved_instance_id, sizeof(int));
913 _bt_service_method_return(req_info->context, out_param, result);
915 g_free(req_info->user_data);
916 _bt_free_info_from_invocation_list(req_info);
917 g_array_free(out_param, TRUE);
921 case BT_GATT_SERVER_ADD_SERVICE:
922 case BT_GATT_SERVER_ADD_DESCRIPTOR:
923 case BT_GATT_SERVER_ADD_CHARACTERISTIC: {
924 int *handle = (int*)data;
925 BT_DBG("Characteristic added: Handle [%d]", *handle);
926 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
928 g_array_append_vals(out_param, handle, sizeof(int));
929 _bt_service_method_return(req_info->context, out_param, result);
931 g_free(req_info->user_data);
932 _bt_free_info_from_invocation_list(req_info);
933 g_array_free(out_param, TRUE);
938 case BT_DISCONNECT_LE: {
939 #ifdef TIZEN_GATT_CLIENT
940 char *addr = (char*)req_info->user_data;
941 bluetooth_device_address_t address;
943 if (!g_strcmp0(addr, (char*)data)) {
944 BT_INFO("GATT Client connect-disconnect call pending for app [%s] addr [%s]",
945 req_info->sender, addr);
946 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
947 _bt_convert_addr_string_to_type(address.addr, addr);
949 g_array_append_vals(out_param, (bluetooth_device_address_t*)&address,
950 sizeof(bluetooth_device_address_t));
951 _bt_service_method_return(req_info->context, out_param, result);
953 g_free(req_info->user_data);
954 _bt_free_info_from_invocation_list(req_info);
955 g_array_free(out_param, TRUE);
958 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
960 g_array_append_vals(out_param, (bluetooth_device_address_t*)data,
961 sizeof(bluetooth_device_address_t));
962 _bt_service_method_return(req_info->context, out_param, result);
964 g_free(req_info->user_data);
965 _bt_free_info_from_invocation_list(req_info);
967 g_array_free(out_param, TRUE);
971 #ifdef TIZEN_GATT_CLIENT
972 case BT_GATT_CLIENT_REGISTER: {
973 bt_service_app_info_t *param = (bt_service_app_info_t*)data;
974 BT_DBG("Sender [%s] Request Sender [%s]", param->sender, req_info->sender);
975 if (!g_strcmp0(req_info->sender, param->sender)) {
976 BT_DBG("GATT Client app found [%s] created client ID [%d]",
977 req_info->sender, param->client_id);
979 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
980 g_array_append_vals(out_param, ¶m->client_id, sizeof(int));
981 _bt_service_method_return(req_info->context, out_param, result);
983 g_free(req_info->user_data);
984 _bt_free_info_from_invocation_list(req_info);
985 g_array_free(out_param, TRUE);
989 case BT_GATT_GET_PRIMARY_SERVICES: {
990 bt_services_browse_info_t *param = (bt_services_browse_info_t*)data;
991 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
992 _bt_convert_addr_type_to_string(address,
993 (unsigned char *)(¶m->device_addr.addr));
995 BT_DBG("Request Sender [%s] address [%s]", req_info->sender, address);
997 /* Match address to determine same request */
998 if (!g_strcmp0((char*)req_info->user_data, address)) {
999 BT_DBG("GATT Client app found [%s] Remote address [%s]",
1000 req_info->sender, address);
1002 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
1003 g_array_append_vals(out_param, param,
1004 sizeof(bt_services_browse_info_t));
1006 //g_array_append_vals(out_param, ¶m->client_id, sizeof(int));
1007 _bt_service_method_return(req_info->context, out_param, result);
1009 g_free(req_info->user_data);
1010 _bt_free_info_from_invocation_list(req_info);
1011 g_array_free(out_param, TRUE);
1016 case BT_GATT_GET_SERVICE_PROPERTIES: {
1017 bt_char_browse_info_t param;
1018 memcpy((void*)¶m, data, sizeof(bt_char_browse_info_t));
1019 //bt_char_browse_info_t *param = (bt_char_browse_info_t*)data;
1020 BT_DBG("Request Sender [%s]", req_info->sender);
1021 bluetooth_gatt_client_svc_prop_info_t *prop = (bluetooth_gatt_client_svc_prop_info_t*)req_info->user_data;
1023 /* Match both address and service properties to determine same request */
1024 if (!memcmp(param.device_addr.addr,
1025 prop->device_address.addr,
1026 sizeof(bluetooth_device_address_t)) &&
1027 !memcmp(param.svc_uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) &&
1028 param.svc_inst_id == prop->svc.instance_id) {
1029 BT_DBG("Returning Service properties");
1031 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
1032 g_array_append_vals(out_param, ¶m, sizeof(bt_char_browse_info_t));
1033 _bt_service_method_return(req_info->context, out_param, result);
1035 g_free(req_info->user_data);
1036 _bt_free_info_from_invocation_list(req_info);
1037 g_array_free(out_param, TRUE);
1041 case BT_GATT_GET_CHARACTERISTIC_PROPERTIES: {
1042 bt_descriptor_browse_info_t *param = (bt_descriptor_browse_info_t*)data;
1044 BT_DBG("Request Sender [%s]", req_info->sender);
1045 bluetooth_gatt_client_char_prop_info_t *prop = (bluetooth_gatt_client_char_prop_info_t*)req_info->user_data;
1047 /* Match both address, service properties &char properties to determine same request */
1048 if (!memcmp(param->device_addr.addr,
1049 prop->device_address.addr,
1050 sizeof(bluetooth_device_address_t)) &&
1051 !memcmp(param->svc_uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) &&
1052 param->svc_inst_id == prop->svc.instance_id &&
1053 !memcmp(param->char_uuid, prop->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) &&
1054 param->char_inst_id == prop->characteristic.instance_id) {
1055 BT_DBG("Returning Characteristic properties");
1056 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
1057 g_array_append_vals(out_param, param, sizeof(bt_descriptor_browse_info_t));
1058 _bt_service_method_return(req_info->context, out_param, result);
1060 g_free(req_info->user_data);
1061 _bt_free_info_from_invocation_list(req_info);
1062 g_array_free(out_param, TRUE);
1066 case BT_GATT_WATCH_CHARACTERISTIC: {
1067 bt_gatt_notif_reg_info_t *param = (bt_gatt_notif_reg_info_t*)data;
1068 bluetooth_gatt_client_char_prop_info_t *prop = (bluetooth_gatt_client_char_prop_info_t*)req_info->user_data;
1069 BT_DBG("Request Sender [%s]", req_info->sender);
1070 /* Match both address, service properties &char properties to determine same request */
1071 if (!memcmp(param->addr.addr,
1072 prop->device_address.addr,
1073 sizeof(bluetooth_device_address_t)) &&
1074 !memcmp(param->svc_uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) &&
1075 param->svc_inst == prop->svc.instance_id &&
1076 !memcmp(param->char_uuid, prop->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) &&
1077 param->char_inst == prop->characteristic.instance_id) {
1078 BT_INFO("Characteristic Watch Successful: Is registered [%d]",
1079 param->is_registered);
1080 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
1081 g_array_append_vals(out_param, param, sizeof(bt_gatt_notif_reg_info_t));
1082 _bt_service_method_return(req_info->context, out_param, result);
1083 g_free(req_info->user_data);
1084 _bt_free_info_from_invocation_list(req_info);
1085 g_array_free(out_param, TRUE);
1089 case BT_GATT_READ_CHARACTERISTIC:
1090 case BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE: {
1091 bluetooth_gatt_client_char_prop_info_t *param = (bluetooth_gatt_client_char_prop_info_t*)data;
1092 BT_DBG("Request Sender [%s]", req_info->sender);
1094 char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
1095 bluetooth_gatt_client_char_prop_info_t *prop = (bluetooth_gatt_client_char_prop_info_t*)req_info->user_data;
1096 _bt_convert_addr_type_to_string(addr, prop->device_address.addr);
1098 if (!memcmp(param, prop, sizeof(bluetooth_gatt_client_char_prop_info_t))) {
1099 BT_DBG("Gatt Char read or write request matched for address [%s]", addr);
1100 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
1101 g_array_append_vals(out_param, param, sizeof(bluetooth_gatt_client_char_prop_info_t));
1102 _bt_service_method_return(req_info->context, out_param, result);
1104 g_free(req_info->user_data);
1105 _bt_free_info_from_invocation_list(req_info);
1106 g_array_free(out_param, TRUE);
1111 case BT_GATT_READ_DESCRIPTOR_VALUE:
1112 case BT_GATT_WRITE_DESCRIPTOR_VALUE: {
1113 bluetooth_gatt_client_desc_prop_info_t *param = (bluetooth_gatt_client_desc_prop_info_t*)data;
1114 BT_DBG("Request Sender [%s]", req_info->sender);
1116 char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
1117 bluetooth_gatt_client_desc_prop_info_t *prop = (bluetooth_gatt_client_desc_prop_info_t*)req_info->user_data;
1118 _bt_convert_addr_type_to_string(addr, prop->device_address.addr);
1120 if (!memcmp(param, prop, sizeof(bluetooth_gatt_client_desc_prop_info_t))) {
1121 BT_DBG("Descriptor read or write request matched for address [%s]", addr);
1122 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
1123 g_array_append_vals(out_param, param, sizeof(bluetooth_gatt_client_desc_prop_info_t));
1124 _bt_service_method_return(req_info->context, out_param, result);
1126 g_free(req_info->user_data);
1127 _bt_free_info_from_invocation_list(req_info);
1128 g_array_free(out_param, TRUE);
1133 case BT_REQ_ATT_MTU: {
1134 char *addr = (char*)req_info->user_data;
1135 bluetooth_device_address_t address;
1137 if (!g_strcmp0(addr, (char*)data)) {
1138 BT_DBG("GATT Client BT_REQ_ATT_MTU call pending for app [%s] addr [%s]",
1139 req_info->sender, addr);
1140 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
1141 _bt_convert_addr_string_to_type(address.addr, addr);
1143 g_array_append_vals(out_param, (bluetooth_device_address_t*)&address,
1144 sizeof(bluetooth_device_address_t));
1145 _bt_service_method_return(req_info->context, out_param, result);
1147 g_free(req_info->user_data);
1148 _bt_free_info_from_invocation_list(req_info);
1149 g_array_free(out_param, TRUE);
1159 static void __bt_handle_server_instance_registered(event_gatts_register_t *data)
1161 bt_service_app_info_t *info = NULL;
1163 char *uuid_string = g_malloc0(BT_UUID_STRING_MAX);
1165 _bt_uuid_to_string(&(data->server_uuid), uuid_string);
1166 BT_INFO("Instance ID is Intialized [%d] UUID initialized [%s]", data->server_inst, uuid_string);
1168 /* Check if the just registered Instance ID belongs to BLEAPP or GATT Server */
1169 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1172 if (g_strcmp0(info->uuid, uuid_string) == 0) {
1173 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1174 info->is_initialized = TRUE;
1175 info->instance_id = data->server_inst;
1176 info->adv_instance = data->server_inst;
1177 __bt_gatt_handle_pending_request_info(BLUETOOTH_ERROR_NONE, BT_GATT_SERVER_REGISTER,
1178 (void*)info, sizeof(bt_service_app_info_t));
1182 g_free(uuid_string);
1185 static void __bt_handle_gatt_server_service_added(event_gatts_srvc_prm_t *event)
1187 int result = BLUETOOTH_ERROR_NONE;
1191 bt_service_app_info_t *info = NULL;
1194 char *uuid_str = g_malloc0(BT_UUID_STRING_MAX);
1195 _bt_uuid_to_string(&(event->gatt_srvc_id.id.uuid), uuid_str);
1196 BT_INFO("GATT Added Service UUID: [%s] Server Ins [%d] Service hdl [%d] Is Primary [%d]\n",
1197 uuid_str, event->gatt_srvc_stat.server_inst, svc_handle, event->gatt_srvc_id.is_prmry);
1199 if (event->gatt_srvc_stat.status != OAL_STATUS_SUCCESS) {
1200 result = BLUETOOTH_ERROR_INTERNAL;
1201 svc_handle = 0; /* Service handle set to 0 indicates.
1202 0 is reserved by BT SIG, cant be used by app*/
1204 svc_handle = event->gatt_srvc_stat.servic_hndl;
1206 BT_INFO("GATT Added Service Status [%d] Server Ins [%d] Service hdl [%d] Is Primary [%d]\n",
1207 event->gatt_srvc_stat.status, event->gatt_srvc_stat.server_inst, svc_handle, event->gatt_srvc_id.is_prmry);
1209 /* Check if the just registered Instance ID belongs to BLEAPP or GATT Server */
1210 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1213 if (info->instance_id == event->gatt_srvc_stat.server_inst) {
1214 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1215 __bt_gatt_handle_pending_request_info(result, BT_GATT_SERVER_ADD_SERVICE,
1216 (int*)&svc_handle, sizeof(int));
1218 /* Add Service Handle */
1219 if (svc_handle > 0) {
1220 handle = g_malloc0(sizeof(int));
1221 *handle = svc_handle;
1222 numapps[event->gatt_srvc_stat.server_inst].service_handles = g_slist_append(numapps[event->gatt_srvc_stat.server_inst].service_handles, handle);
1223 count = g_slist_length(numapps[event->gatt_srvc_stat.server_inst].service_handles);
1224 BT_INFO("Added Service handle [%d] to list..current count [%d]", svc_handle, count);
1233 static void __bt_handle_gatt_server_characteristic_added(event_gatts_srvc_charctr_t *event)
1235 int result = BLUETOOTH_ERROR_NONE;
1237 bt_service_app_info_t *info = NULL;
1239 char *uuid_str = g_malloc0(BT_UUID_STRING_MAX);
1241 BT_INFO("GATT Server Char added status [%d]", event->gatt_srvc_stat.status);
1242 BT_INFO("GATT Server_inst: [%d]", event->gatt_srvc_stat.server_inst);
1243 BT_INFO("GATT Service Handle: [%d]", event->gatt_srvc_stat.servic_hndl);
1244 BT_INFO("GATT Add characteristic Status: [%d]", event->gatt_srvc_stat.status);
1245 BT_INFO("GATT Service characteristic Handle: [%d]", event->charctr_hndl);
1247 if (event->gatt_srvc_stat.status != OAL_STATUS_SUCCESS) {
1248 result = BLUETOOTH_ERROR_INTERNAL;
1249 char_handle = 0; /* characteristic handle set to 0 indicates.
1250 0 is reserved by BT SIG, cant be used by app*/
1252 char_handle = event->charctr_hndl;
1255 /* Check if the just registered Instance ID belongs to BLEAPP or GATT Server */
1256 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1259 if (info->instance_id == event->gatt_srvc_stat.server_inst) {
1260 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1261 __bt_gatt_handle_pending_request_info(result, BT_GATT_SERVER_ADD_CHARACTERISTIC,
1262 (int*)&char_handle, sizeof(int));
1268 _bt_uuid_to_string(&(event->charctr_uuid), uuid_str);
1269 BT_INFO("GATT Added Characteristic: UUID: [%s]", uuid_str);
1274 static void __bt_handle_gatt_server_descriptor_added(event_gatts_srvc_descr_t* event)
1276 int result = BLUETOOTH_ERROR_NONE;
1278 bt_service_app_info_t *info = NULL;
1280 char *uuid_str = g_malloc0(BT_UUID_STRING_MAX);
1282 BT_INFO("GATT Server Descriptor added status [%d]", event->gatt_srvc_stat.status);
1283 BT_INFO("GATT Server_inst: [%d]", event->gatt_srvc_stat.server_inst);
1284 BT_INFO("GATT Service Handle: [%d]", event->gatt_srvc_stat.servic_hndl);
1285 BT_INFO("GATT Add Descriptor Status: [%d]", event->gatt_srvc_stat.status);
1286 BT_INFO("GATT Service Descriptor Handle: [%d]", event->descrptr_hndl);
1288 if (event->gatt_srvc_stat.status != OAL_STATUS_SUCCESS) {
1289 result = BLUETOOTH_ERROR_INTERNAL;
1290 desc_handle = 0; /* Service handle set to 0 indicates.
1291 0 is reserved by BT SIG, cant be used by app*/
1293 desc_handle = event->descrptr_hndl;
1295 /* Check if the just registered Instance ID belongs to BLEAPP or GATT Server */
1296 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1299 if (info->instance_id == event->gatt_srvc_stat.server_inst) {
1300 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1301 __bt_gatt_handle_pending_request_info(result, BT_GATT_SERVER_ADD_DESCRIPTOR,
1302 (int*)&desc_handle, sizeof(int));
1307 _bt_uuid_to_string(&(event->descrptr_uuid), uuid_str);
1308 BT_INFO("GATT Added Descriptor: UUID: [%s]", uuid_str);
1313 static void __bt_handle_gatt_server_service_started(event_gatts_srvc_t *event)
1315 bt_service_app_info_t *info = NULL;
1316 int result = BLUETOOTH_ERROR_NONE;
1318 BT_INFO("GATT Server Service Started..");
1321 BT_INFO("GATT Server_inst: [%d]", event->server_inst);
1322 BT_INFO("GATT Service Handle: [%d]", event->servic_hndl);
1323 BT_INFO("GATT Service Started Status: [%d]", event->status);
1325 if (event->status != OAL_STATUS_SUCCESS) {
1326 BT_ERR("GATT Server Service Start Failed Err: [%d]", event->status);
1327 result = BLUETOOTH_ERROR_INTERNAL;
1330 /* Check if the just registered Instance ID belongs to requester */
1331 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1334 if (info->instance_id == event->server_inst) {
1335 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1336 __bt_gatt_handle_pending_request_info(result, BT_GATT_SERVER_START_SERVICE,
1337 (void*)info, sizeof(bt_service_app_info_t));
1343 static void __bt_handle_gatt_server_service_stopped(event_gatts_srvc_t *event)
1345 int result = BLUETOOTH_ERROR_NONE;
1346 bt_service_app_info_t *info = NULL;
1348 BT_INFO("GATT Server Service Stopped..");
1350 BT_INFO("GATT Server_inst: [%d]", event->server_inst);
1351 BT_INFO("GATT Service Handle: [%d]", event->servic_hndl);
1352 BT_INFO("GATT Service Stopped Status: [%d]", event->status);
1354 if (event->status != OAL_STATUS_SUCCESS) {
1355 BT_ERR("GATT Server Service Stop Failed Err: [%d]", event->status);
1356 result = BLUETOOTH_ERROR_INTERNAL;
1359 /* Check if the just registered Instance ID belongs to requester */
1360 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1363 if (info->instance_id == event->server_inst) {
1364 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1365 __bt_gatt_handle_pending_request_info(result, BT_GATT_SERVER_STOP_SERVICE,
1366 (void*)info, sizeof(bt_service_app_info_t));
1372 static void __bt_handle_gatt_server_service_deleted(event_gatts_srvc_t *event)
1374 int result = BLUETOOTH_ERROR_NONE;
1375 bt_service_app_info_t *info = NULL;
1377 BT_INFO("GATT Server Service Deleted..");
1379 BT_INFO("GATT Server_inst: [%d]", event->server_inst);
1380 BT_INFO("GATT Service Handle: [%d]", event->servic_hndl);
1381 BT_INFO("GATT Service Deleted Status: [%d]", event->status);
1383 if (event->status != OAL_STATUS_SUCCESS) {
1384 BT_ERR("GATT Server Service Delete Failed Err: [%d]", event->status);
1385 result = BLUETOOTH_ERROR_INTERNAL;
1388 /* Check if the just registered Instance ID belongs to requester */
1389 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1392 if (info->instance_id == event->server_inst) {
1393 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1394 __bt_gatt_handle_pending_request_info(result, BT_GATT_SERVER_DELETE_SERVICE,
1395 (void*)info, sizeof(bt_service_app_info_t));
1401 struct gatt_client_info_t *_bt_find_remote_gatt_client_info(char *address)
1404 struct gatt_client_info_t *info = NULL;
1405 for (l = gatt_client_info_list; l != NULL; l = g_slist_next(l)) {
1406 info = (struct gatt_client_info_t*)l->data;
1410 if (!g_strcmp0(info->addr, address)) {
1411 BT_DBG("Remote GATT client found addr[%s]", info->addr);
1418 static struct gatt_client_info_t *__bt_find_remote_gatt_client_info_from_conn_id(int conn_id)
1421 struct gatt_client_info_t *info = NULL;
1423 for (l = gatt_client_info_list; l != NULL; l = g_slist_next(l)) {
1424 info = (struct gatt_client_info_t*)l->data;
1428 if (info->connection_id == conn_id) {
1429 BT_INFO("Remote GATT client found addr[%s]", info->addr);
1436 #ifdef TIZEN_GATT_CLIENT
1437 struct gatt_server_info_t *_bt_find_remote_gatt_server_info(char *address)
1440 struct gatt_server_info_t *info = NULL;
1441 for (l = gatt_server_info_list; l != NULL; l = g_slist_next(l)) {
1442 info = (struct gatt_server_info_t*)l->data;
1446 if (!g_strcmp0(info->addr, address)) {
1447 BT_DBG("Remote GATT Server found addr[%s]", info->addr);
1454 static struct gatt_out_conn_info_t* __bt_find_gatt_outgoing_conn_info(char *address)
1457 struct gatt_out_conn_info_t *info = NULL;
1458 for (l = outgoing_gatt_conn_list; l != NULL; l = g_slist_next(l)) {
1459 info = (struct gatt_out_conn_info_t*)l->data;
1463 if (!g_strcmp0(info->addr, address)) {
1464 BT_INFO("Outgoing connection info found addr[%s]", info->addr);
1471 static struct gatt_server_info_t *__bt_find_remote_gatt_server_info_from_client_if(int client_if)
1474 struct gatt_server_info_t *info = NULL;
1476 for (l = gatt_server_info_list; l != NULL; l = g_slist_next(l)) {
1477 info = (struct gatt_server_info_t*)l->data;
1481 if (info->client_id == client_if) {
1482 BT_INFO("Remote GATT server found addr[%s]", info->addr);
1493 #ifdef TIZEN_GATT_CLIENT
1494 static void __bt_handle_gatt_server_connection_state(event_gatts_conn_t *event)
1496 int result = BLUETOOTH_ERROR_NONE;
1497 struct gatt_client_info_t *client_info = NULL;
1498 struct gatt_server_info_t *server_info = NULL;
1499 bluetooth_device_address_t dev_addr;
1500 GVariant *param = NULL;
1503 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1505 memcpy(dev_addr.addr, event->address.addr, 6);
1507 /* REPLY dbus Context to application which called BT_CONNECT_LE. There is status
1509 _bt_convert_addr_type_to_string(address,
1510 (unsigned char *)dev_addr.addr);
1512 if (event->status != OAL_STATUS_SUCCESS)
1513 result = BLUETOOTH_ERROR_INTERNAL;
1515 __bt_gatt_handle_pending_request_info(result, BT_CONNECT_LE,
1516 address, BT_ADDRESS_STRING_SIZE);
1518 BT_INFO("GATT Server Connedted: Remote Client addr[%s] Server Instance [%d] Connection ID [%d]",
1519 address, event->server_inst, event->conn_id);
1522 /* Check if device is already in connected list */
1523 client_info = _bt_find_remote_gatt_client_info(address);
1526 BT_INFO("Conn Info absent: But no need to Send Local GATT Server Connected event to apps");
1528 param = g_variant_new("(is)", result, address);
1530 /* Send event to application */
1531 _bt_send_event(BT_DEVICE_EVENT,
1532 BLUETOOTH_EVENT_GATT_SERVER_CONNECTED, /* Local device is GATT server */
1535 /* Save client connection info */
1536 client_info = g_new0(struct gatt_client_info_t, 1);
1537 client_info->addr = g_strdup(address);
1538 BT_INFO("Added GATT client addr[%s]", client_info->addr);
1539 client_info->connection_id = event->conn_id;
1540 client_info->instance_id = event->server_inst;
1541 gatt_client_info_list = g_slist_append(gatt_client_info_list, client_info);
1542 BT_INFO("Total num of connected Remote GATT Clients [%d]", g_slist_length(gatt_client_info_list));
1544 /* Save server connection info */
1545 server_info = g_new0(struct gatt_server_info_t, 1);
1546 server_info->addr = g_strdup(address);
1547 server_info->client_id = -1;
1548 BT_INFO("Added GATT server addr[%s]", server_info->addr);
1549 server_info->connection_id = event->conn_id;
1550 gatt_server_info_list = g_slist_append(gatt_server_info_list, server_info);
1551 BT_INFO("Total num of connected Remote GATT Servers [%d]", g_slist_length(gatt_server_info_list));
1553 ret = gattc_add_connection_info((bt_address_t *)&dev_addr, event->conn_id, event->server_inst);
1554 if (ret != OAL_STATUS_SUCCESS) {
1555 BT_ERR("gattc register server instance failed");
1559 __bt_add_mtu_gatt_device(address);
1564 /* GATT Server Dis connected */
1565 static void __bt_handle_gatt_server_disconnection_state(event_gatts_conn_t *event)
1567 int result = BLUETOOTH_ERROR_NONE;
1568 struct gatt_client_info_t *client_info = NULL;
1569 struct gatt_server_info_t *server_info = NULL;
1570 bluetooth_device_address_t dev_addr;
1571 GVariant *param = NULL;
1572 char address[BT_ADDRESS_STRING_SIZE];
1574 memcpy(dev_addr.addr, event->address.addr, 6);
1576 /* REPLY dbus Context to application which called BT_DISCONNECT_LE. There is status
1578 _bt_convert_addr_type_to_string(address,
1579 (unsigned char *)dev_addr.addr);
1581 if (event->status != OAL_STATUS_SUCCESS)
1582 result = BLUETOOTH_ERROR_INTERNAL;
1584 if (NULL == _bt_get_request_info_data(BT_DISCONNECT_LE, address)) {
1585 if (NULL != _bt_get_request_info_data(BT_CONNECT_LE, address)) {
1586 result = BLUETOOTH_ERROR_INTERNAL;
1588 __bt_gatt_handle_pending_request_info(result, BT_CONNECT_LE,
1589 address, BT_ADDRESS_STRING_SIZE);
1591 BT_ERR("Failed to connect Local GATT Server Remote Client addr[%s]", address);
1595 __bt_gatt_handle_pending_request_info(result, BT_DISCONNECT_LE,
1596 address, BT_ADDRESS_STRING_SIZE);
1599 BT_INFO("Local GATT Server DisConnected: Remote Client addr[%s] Server Instance [%d] Connection ID [%d]",
1600 address, event->server_inst, event->conn_id);
1601 /* Remove Connection info */
1602 client_info = _bt_find_remote_gatt_client_info(address);
1604 BT_INFO("No need to Send Local GATT Server Disconnected event to apps, just remove remote client info");
1606 param = g_variant_new("(is)", result, address);
1607 /* Send event to application */
1608 _bt_send_event(BT_DEVICE_EVENT,
1609 BLUETOOTH_EVENT_GATT_SERVER_DISCONNECTED, /* Local device is GATT server */
1612 /* Remove server info from list */
1613 server_info = _bt_find_remote_gatt_server_info(address);
1615 gatt_server_info_list = g_slist_remove(gatt_server_info_list, server_info);
1617 BT_INFO("Can not find conn info, already removed!");
1619 /* Remove client info from List */
1620 gatt_client_info_list = g_slist_remove(gatt_client_info_list, client_info);
1621 BT_INFO("Total num of connected GATT clients [%d]", g_slist_length(gatt_client_info_list));
1622 g_free(client_info->addr);
1623 g_free(client_info);
1626 __bt_remove_mtu_gatt_device(address);
1630 static void __bt_handle_gatt_server_connection_state(event_gatts_conn_t *event)
1632 int result = BLUETOOTH_ERROR_NONE;
1633 struct gatt_client_info_t *conn_info = NULL;
1634 bt_service_app_info_t *info = NULL;
1635 bluetooth_device_address_t dev_addr;
1636 GVariant *param = NULL;
1639 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1641 memcpy(dev_addr.addr, event->address.addr, 6);
1644 /* Check if the just registered Instance ID belongs to BLEAPP or GATT Server */
1645 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1648 if (info->instance_id == event->server_inst) {
1649 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1650 __bt_gatt_handle_pending_request_info(result, BT_CONNECT_LE,
1651 (bluetooth_device_address_t*)&dev_addr, sizeof(bluetooth_device_address_t));
1657 /* Send event to BT-API */
1658 _bt_convert_addr_type_to_string(address,
1659 (unsigned char *)dev_addr.addr);
1661 BT_INFO("GATT Server Connedted: Remote Client addr[%s] Server Instance [%d] Connection ID [%d]",
1662 address, event->server_inst, event->conn_id);
1665 /* Check if device is already in connected list */
1666 conn_info = _bt_find_remote_gatt_client_info(address);
1669 param = g_variant_new("(is)", result, address);
1670 /* Send event to application */
1671 _bt_send_event(BT_GATT_SERVER_EVENT,
1672 BLUETOOTH_EVENT_GATT_CONNECTED,
1675 /* Save Connection info */
1676 conn_info = g_new0(struct gatt_client_info_t, 1);
1677 conn_info->addr = g_strdup(address);
1678 BT_INFO("Added GATT client addr[%s]", conn_info->addr);
1679 conn_info->connection_id = event->conn_id;
1680 conn_info->instance_id = event->server_inst;
1681 gatt_client_info_list = g_slist_append(gatt_client_info_list, conn_info);
1682 BT_INFO("Total num of connected GATT clients [%d]", g_slist_length(gatt_client_info_list));
1688 /* GATT Server Dis connected */
1689 static void __bt_handle_gatt_server_disconnection_state(event_gatts_conn_t *event)
1691 int result = BLUETOOTH_ERROR_NONE;
1692 struct gatt_client_info_t *conn_info = NULL;
1693 bluetooth_device_address_t dev_addr;
1694 bt_service_app_info_t *info = NULL;
1695 GVariant *param = NULL;
1698 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1700 memcpy(dev_addr.addr, event->address.addr, 6);
1702 /* Check if the just registered Instance ID belongs to BLEAPP or GATT Server */
1703 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1706 if (info->instance_id == event->server_inst) {
1707 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1708 __bt_gatt_handle_pending_request_info(result, BT_DISCONNECT_LE,
1709 (bluetooth_device_address_t*)&dev_addr, sizeof(bluetooth_device_address_t));
1715 /* Send event to BT-API */
1716 _bt_convert_addr_type_to_string(address,
1717 (unsigned char *)dev_addr.addr);
1719 BT_INFO("GATT Server DisConnected: Remote Client addr[%s] Server Instance [%d] Connection ID [%d]",
1720 address, event->server_inst, event->conn_id);
1722 param = g_variant_new("(is)", result, address);
1723 /* Send event to application */
1724 _bt_send_event(BT_GATT_SERVER_EVENT,
1725 BLUETOOTH_EVENT_GATT_DISCONNECTED,
1728 /* Remove Connection info */
1729 conn_info = _bt_find_remote_gatt_client_info(address);
1731 BT_INFO("Remove GATT client info from List..");
1732 /* Remove info from List */
1733 gatt_client_info_list = g_slist_remove(gatt_client_info_list, conn_info);
1734 BT_INFO("Total num of connected GATT clients [%d]", g_slist_length(gatt_client_info_list));
1735 g_free(conn_info->addr);
1744 static void __bt_handle_gatt_server_acquire_write_requested(event_gatts_srvc_acquire_attr_t *event)
1746 GVariant *param = NULL;
1747 int result = BLUETOOTH_ERROR_NONE;
1748 struct gatt_server_req_info *req_info = NULL;
1749 bluetooth_device_address_t dev_addr;
1750 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
1752 BT_INFO("GATT Server ACQUIRE Write Req Connection ID: [%d]", event->attr_trans.conn_id);
1753 BT_INFO("GATT Server ACQUIRE Write Req Transaction ID:[%d]", event->attr_trans.trans_id);
1754 BT_INFO("GATT Server ACQUIRE Write Req Attribute Handle: [%d]", event->attr_trans.attr_handle);
1756 //address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1757 memcpy(dev_addr.addr, event->address.addr, 6);
1759 req_info = g_new0(struct gatt_server_req_info, 1);
1760 req_info->request_id = event->attr_trans.trans_id;
1761 req_info->attribute_handle = event->attr_trans.attr_handle;
1762 req_info->connection_id = event->attr_trans.conn_id;
1763 req_info->request_type = BLUETOOTH_GATT_REQUEST_TYPE_ACQUIRE_WRITE;
1764 gatt_server_requests = g_slist_append(gatt_server_requests, req_info);
1766 _bt_convert_addr_type_to_string(address,
1767 (unsigned char *)dev_addr.addr);
1769 param = g_variant_new("(iiiiiis)", result,
1770 event->attr_trans.conn_id,
1771 event->attr_trans.trans_id,
1772 event->attr_trans.attr_handle,
1773 event->mtu, event->attr_trans.offset, address);
1774 BT_INFO("GATT Server ACQUIRE Write Req Attribute remote address : [%s]", address);
1776 _bt_send_event(BT_GATT_SERVER_EVENT,
1777 BLUETOOTH_EVENT_GATT_SERVER_ACQUIRE_WRITE,
1782 static void __bt_handle_gatt_server_acquire_notify_requested(event_gatts_srvc_acquire_attr_t *event)
1784 GVariant *param = NULL;
1785 int result = BLUETOOTH_ERROR_NONE;
1786 struct gatt_server_req_info *req_info = NULL;
1787 bluetooth_device_address_t dev_addr;
1788 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
1790 BT_INFO("GATT Server ACQUIRE Notify Req Connection ID: [%d]", event->attr_trans.conn_id);
1791 BT_INFO("GATT Server ACQUIRE Notify Req Transaction ID:[%d]", event->attr_trans.trans_id);
1792 BT_INFO("GATT Server ACQUIRE Notify Req Attribute Handle: [%d]", event->attr_trans.attr_handle);
1793 BT_INFO("GATT Server ACQUIRE notify Req address : [%s]", address);
1795 memcpy(dev_addr.addr, event->address.addr, 6);
1796 _bt_convert_addr_type_to_string(address,
1797 (unsigned char *)dev_addr.addr);
1798 BT_INFO("GATT Server ACQUIRE notify Req remote address : [%s]", address);
1800 req_info = g_new0(struct gatt_server_req_info, 1);
1801 req_info->request_id = event->attr_trans.trans_id;
1802 req_info->attribute_handle = event->attr_trans.attr_handle;
1803 req_info->connection_id = event->attr_trans.conn_id;
1804 req_info->request_type = BLUETOOTH_GATT_REQUEST_TYPE_ACQUIRE_NOTIFY;
1805 gatt_server_requests = g_slist_append(gatt_server_requests, req_info);
1807 param = g_variant_new("(iiiiiis)", result,
1808 event->attr_trans.conn_id,
1809 event->attr_trans.trans_id,
1810 event->attr_trans.attr_handle,
1811 event->mtu, event->attr_trans.offset,
1814 BT_INFO("GATT Server ACQUIRE Notify Req Attribute : ");
1816 _bt_send_event(BT_GATT_SERVER_EVENT,
1817 BLUETOOTH_EVENT_GATT_SERVER_ACQUIRE_NOTIFY,
1821 static void __bt_handle_gatt_server_write_requested(event_gatts_srvc_write_attr_t *event)
1824 bluetooth_device_address_t dev_addr;
1825 GVariant *param = NULL;
1826 int result = BLUETOOTH_ERROR_NONE;
1828 gboolean is_prepare_write;
1830 GVariant *data = NULL;
1832 struct gatt_server_req_info *req_info = NULL;
1833 BT_INFO("GATT Server Write Requested");
1835 memcpy(dev_addr.addr, event->address.addr, 6);
1837 BT_INFO("GATT Server Write Req Connection ID: [%d]", event->attr_trans.conn_id);
1838 BT_INFO("GATT Server Write Req Transaction ID:[%d]", event->attr_trans.trans_id);
1839 BT_INFO("GATT Server Write Req Attribute Handle: [%d]", event->attr_trans.attr_handle);
1840 BT_INFO("GATT Server Write Req Attribute Offset: [%d]", event->attr_trans.offset);
1841 BT_INFO("GATT Server Write Req value length [%d]", event->length);
1842 BT_INFO("GATT Server Write Req needs response: [%d]", event->need_rsp);
1843 BT_INFO("GATT Server Write Req Is Prep: [%d]", event->is_prep);
1845 if (event->length <= 0) {
1846 BT_INFO("GATT Server write requested, but length of attr value is 0");
1850 need_resp = event->need_rsp;
1851 is_prepare_write = event->is_prep;
1853 write_val = g_memdup(&event->value[0], event->length);
1855 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1856 _bt_convert_addr_type_to_string(address,
1857 (unsigned char *)dev_addr.addr);
1859 BT_INFO("GATT Server Write Request from remote client [%s]", address);
1861 if (event->length > 0) {
1862 for (i = 0; i < event->length; i++)
1863 BT_DBG("Data[%d] = [0x%x]", i, event->value[i]);
1865 /* Save Write Request Info */
1866 req_info = g_new0(struct gatt_server_req_info, 1);
1867 req_info->request_id = event->attr_trans.trans_id;
1868 req_info->attribute_handle = event->attr_trans.attr_handle;
1869 req_info->connection_id = event->attr_trans.conn_id;
1870 req_info->addr = address;
1871 req_info->offset = event->attr_trans.offset;
1872 req_info->request_type = BLUETOOTH_GATT_REQUEST_TYPE_WRITE;
1873 gatt_server_requests = g_slist_append(gatt_server_requests, req_info);
1875 data = g_variant_new_from_data(
1876 G_VARIANT_TYPE_BYTESTRING,
1881 param = g_variant_new("(iiiiiibbsn@ay)", result,
1882 event->attr_trans.conn_id,
1883 event->attr_trans.trans_id,
1884 event->attr_trans.attr_handle,
1885 event->attr_trans.offset,
1893 _bt_send_event(BT_GATT_SERVER_EVENT,
1894 BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED,
1900 static void __bt_handle_gatt_server_read_requested(event_gatts_srvc_read_attr_t *event)
1902 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1903 bluetooth_device_address_t dev_addr;
1904 int result = BLUETOOTH_ERROR_NONE;
1905 struct gatt_server_req_info *req_info = NULL;
1906 GVariant *param = NULL;
1908 BT_INFO("GATT Server Read Requested");
1910 memcpy(dev_addr.addr, event->address.addr, 6);
1912 BT_INFO("GATT Server-Client Connection ID: [%d]", event->attr_trans.conn_id);
1913 BT_INFO("GATT Server-Client Transaction ID: [%d]", event->attr_trans.trans_id);
1914 BT_INFO("GATT Server Attribute Handle: [%d]", event->attr_trans.attr_handle);
1915 BT_INFO("GATT Server Attribute Offset for read: [%d]", event->attr_trans.offset);
1916 BT_INFO("GATT Server Attribute is long: [%d]", event->is_long);
1918 is_long = event->is_long;
1920 /* Save Read Request Info */
1921 req_info = g_new0(struct gatt_server_req_info, 1);
1922 req_info->request_id = event->attr_trans.trans_id;
1923 req_info->attribute_handle = event->attr_trans.attr_handle;
1924 req_info->connection_id = event->attr_trans.conn_id;
1925 req_info->addr = address;
1926 req_info->offset = event->attr_trans.offset;
1927 req_info->request_type = BLUETOOTH_GATT_REQUEST_TYPE_READ;
1928 gatt_server_requests = g_slist_append(gatt_server_requests, req_info);
1930 /* Send event to BT-API */
1931 _bt_convert_addr_type_to_string(address,
1932 (unsigned char *)dev_addr.addr);
1934 BT_INFO("GATT Server Read Request from remote client [%s]", address);
1936 param = g_variant_new("(iiiiibs)", result,
1937 event->attr_trans.conn_id,
1938 event->attr_trans.trans_id,
1939 event->attr_trans.attr_handle,
1940 event->attr_trans.offset,
1944 _bt_send_event(BT_GATT_SERVER_EVENT,
1945 BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED,
1949 static void __bt_handle_gatt_server_indicate_confirmed(event_gatts_ind_cnfrm_t *event)
1951 bluetooth_device_address_t dev_addr;
1952 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1953 int cur_connected_clients;
1954 static int recvd = 0;
1955 gboolean completed = 0;
1956 GVariant *param = NULL;
1958 /* OAL event does provide error, so MW assumes event will never contain wrong data,
1959 incase of any issues, check with OAL */
1960 int result = BLUETOOTH_ERROR_NONE;
1962 memcpy(dev_addr.addr, event->address.addr, 6);
1963 _bt_convert_addr_type_to_string(address,
1964 (unsigned char *)dev_addr.addr);
1966 BT_INFO("Indication sent to GATT client [%s] conn_ ID [%d] transaction ID [%d] Att handle [%d]",
1967 address, event->conn_id, event->trans_id, event->attr_handle);
1970 cur_connected_clients = g_slist_length(gatt_client_info_list);
1971 BT_INFO("Number of connected clients during sending Indication [%d] & current connected count [%d]",
1972 num_indicate_clients, cur_connected_clients);
1975 if (recvd == num_indicate_clients) {
1976 BT_INFO("Gatt indication confirm event for last GATT client.. [%s]", address);
1977 completed = 1; /* Last event */
1978 recvd = 0; /* Reset */
1979 num_indicate_clients = 0;
1982 param = g_variant_new("(isib)",
1988 /* Send event to BT-API */
1989 _bt_send_event(BT_GATT_SERVER_EVENT,
1990 BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_COMPLETED,
1993 BT_INFO("Received Indication confirm for client number [%d]", recvd);
1997 /* Tizen Platform Specific */
1998 static void __bt_handle_gatt_server_notification_changed(event_gatts_notif_t *event)
2000 bluetooth_device_address_t dev_addr;
2001 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2002 GVariant *param = NULL;
2005 /* OAL event does provide error, so MW assumes event will never contain wrong data,
2006 incase of any issues, check with OAL */
2007 int result = BLUETOOTH_ERROR_NONE;
2009 memcpy(dev_addr.addr, event->address.addr, 6);
2010 _bt_convert_addr_type_to_string(address,
2011 (unsigned char *)dev_addr.addr);
2013 BT_INFO("notification_changed [%s] conn_ ID [%d] transaction ID [%d] Att handle [%d] Notify[%d]",
2014 address, event->conn_id, event->trans_id, event->attr_handle, event->notify);
2016 /* Set Notifcation status */
2017 notify = event->notify;
2019 param = g_variant_new("(isib)",
2025 /* Send event to BT-API */
2026 _bt_send_event(BT_GATT_SERVER_EVENT,
2027 BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED,
2033 static void __bt_handle_gatt_mtu_changed_event(event_gatts_mtu_changed_t *event)
2035 int result = BLUETOOTH_ERROR_NONE;
2036 struct gatt_client_info_t *conn_info = NULL;
2037 GVariant *param = NULL;
2040 conn_info = __bt_find_remote_gatt_client_info_from_conn_id(event->conn_id);
2041 if (conn_info == NULL) {
2042 BT_ERR("Cant find connection Information");
2045 BT_INFO("Got connection Info GATT client [%s] MTU Size [%d]",
2046 conn_info->addr, event->mtu_size);
2048 __bt_update_mtu_gatt_device(conn_info->addr, event->mtu_size);
2050 param = g_variant_new("(isqy)",
2056 /* Send event to BT-API */
2057 _bt_send_event(BT_GATT_SERVER_EVENT,
2058 BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED,
2062 static void __bt_gatt_event_handler(int event_type, gpointer event_data)
2064 BT_INFO("OAL event = 0x%x, \n", event_type);
2065 switch (event_type) {
2066 case OAL_EVENT_BLE_SERVER_INSTANCE_INITIALISED: {
2067 BT_INFO("OAL Event: Server Instance Registered");
2068 /* GATT Server Registered event is handled in MAIN thread context */
2069 __bt_handle_server_instance_registered((event_gatts_register_t *)event_data);
2072 case OAL_EVENT_GATTS_SERVICE_ADDED: {
2073 BT_INFO("OAL Event: GATT Service added");
2074 __bt_handle_gatt_server_service_added((event_gatts_srvc_prm_t *)event_data);
2077 case OAL_EVENT_GATTS_CHARACTERISTIC_ADDED: {
2078 BT_INFO("OAL Event: GATT characteristic added");
2079 __bt_handle_gatt_server_characteristic_added((event_gatts_srvc_charctr_t *)event_data);
2082 case OAL_EVENT_GATTS_DESCRIPTOR_ADDED: {
2083 BT_INFO("OAL Event: GATT descriptor added");
2084 __bt_handle_gatt_server_descriptor_added((event_gatts_srvc_descr_t *)event_data);
2087 case OAL_EVENT_GATTS_SERVICE_STARTED: {
2088 BT_INFO("OAL Event: GATT Service started");
2089 __bt_handle_gatt_server_service_started((event_gatts_srvc_t *)event_data);
2092 case OAL_EVENT_GATTS_SERVICE_STOPED: {
2093 BT_INFO("OAL Event: GATT Service stopped");
2094 __bt_handle_gatt_server_service_stopped((event_gatts_srvc_t *)event_data);
2097 case OAL_EVENT_GATTS_SERVICE_DELETED: {
2098 BT_INFO("OAL Event: GATT Service deleted");
2099 __bt_handle_gatt_server_service_deleted((event_gatts_srvc_t *) event_data);
2102 case OAL_EVENT_GATTS_CONNECTION_COMPLETED: {
2103 BT_INFO("OAL Event: GATT Server Connected");
2104 __bt_handle_gatt_server_connection_state((event_gatts_conn_t *)event_data);
2107 case OAL_EVENT_GATTS_DISCONNECTION_COMPLETED: {
2108 BT_INFO("OAL Event: GATT Server Disconnected");
2109 __bt_handle_gatt_server_disconnection_state((event_gatts_conn_t *)event_data);
2112 case OAL_EVENT_GATTS_REQUEST_READ: {
2113 BT_INFO("OAL Event: GATT Server Read Request");
2114 __bt_handle_gatt_server_read_requested((event_gatts_srvc_read_attr_t *)event_data);
2117 case OAL_EVENT_GATTS_REQUEST_WRITE: {
2118 BT_INFO("OAL Event: GATT Server Write Request");
2119 __bt_handle_gatt_server_write_requested((event_gatts_srvc_write_attr_t *)event_data);
2122 case OAL_EVENT_GATTS_REQUEST_ACQUIRE_WRITE: {
2123 BT_INFO("OAL Event: GATT Server Acquire Write Request");
2124 __bt_handle_gatt_server_acquire_write_requested((event_gatts_srvc_acquire_attr_t*)event_data);
2127 case OAL_EVENT_GATTS_REQUEST_ACQUIRE_NOTIFY: {
2128 BT_INFO("OAL Event: GATT ServerAcquire Notify Request");
2129 __bt_handle_gatt_server_acquire_notify_requested((event_gatts_srvc_acquire_attr_t*)event_data);
2132 case OAL_EVENT_GATTS_IND_CONFIRM: {
2133 BT_INFO("OAL Event: GATT Server Indication confirmed");
2134 __bt_handle_gatt_server_indicate_confirmed((event_gatts_ind_cnfrm_t *)event_data);
2137 case OAL_EVENT_GATTS_NOTIFICATION: { /* Tizen Platform Specific */
2138 BT_INFO("OAL Event: GATT Server DisConnected");
2139 __bt_handle_gatt_server_notification_changed((event_gatts_notif_t *)event_data);
2142 case OAL_EVENT_GATTS_MTU_CHANGED: {
2143 BT_INFO("OAL Event: GATT Server MTU changed event callback");
2144 __bt_handle_gatt_mtu_changed_event((event_gatts_mtu_changed_t *)event_data);
2147 #ifdef TIZEN_GATT_CLIENT
2148 case OAL_EVENT_GATTC_REGISTRATION: {
2149 BT_INFO("OAL Event: GATT Client instance Registered");
2150 __bt_handle_client_instance_registered((event_gattc_register_t *) event_data);
2153 case OAL_EVENT_GATTC_CONNECTION_COMPLETED: {
2154 BT_INFO("OAL Event: GATT Client Connected");
2155 __bt_handle_client_connected((event_gattc_conn_t *) event_data);
2158 case OAL_EVENT_GATTC_DISCONNECTION_COMPLETED: {
2159 BT_INFO("OAL Event: GATT Client DisConnected");
2160 __bt_handle_client_disconnected((event_gattc_conn_t *) event_data);
2163 case OAL_EVENT_GATTC_SERVICE_SEARCH_RESULT: {
2164 BT_INFO("OAL Event: GATT Client Service Search Result");
2165 __bt_handle_client_service_search_result((event_gattc_service_result_t *) event_data);
2168 case OAL_EVENT_GATTC_SERVICE_SEARCH_DONE: {
2169 BT_INFO("OAL Event: GATT Client Service Completed");
2170 __bt_handle_client_service_search_completed((event_gattc_conn_status_t *) event_data);
2173 case OAL_EVENT_GATTC_CHARAC_SERACH_RESULT: {
2174 BT_INFO("OAL Event: GATT Client Characteristic Search Result");
2175 __bt_handle_client_characteristic_search_result((event_gattc_characteristic_result_t *) event_data);
2178 case OAL_EVENT_GATTC_DESC_SERACH_RESULT: {
2179 BT_INFO("OAL Event: GATT Client Descriptor Search Result");
2180 __bt_handle_client_descriptor_search_result((event_gattc_descriptor_result_t *) event_data);
2183 case OAL_EVENT_GATTC_READ_CHARAC: {
2184 BT_INFO("OAL Event: GATT Client Characteristic Read Data");
2185 __bt_handle_client_characteristic_read_data((event_gattc_read_data *) event_data);
2188 case OAL_EVENT_GATTC_READ_DESCR: {
2189 BT_INFO("OAL Event: GATT Client Descriptor Read Data");
2190 __bt_handle_client_descriptor_read_data((event_gattc_read_data *) event_data);
2193 case OAL_EVENT_GATTC_WRITE_CHARAC: {
2194 BT_INFO("OAL Event: GATT Client Characteristic Write Data");
2195 __bt_handle_client_characteristic_write_data((event_gattc_write_data *) event_data);
2198 case OAL_EVENT_GATTC_WRITE_DESCR: {
2199 BT_INFO("OAL Event: GATT Client Descriptor Write Data");
2200 __bt_handle_client_descriptor_write_data((event_gattc_write_data *) event_data);
2203 case OAL_EVENT_DEVICE_LE_DISCONNECTED: {
2204 BT_INFO("OAL Event: LE device disconnected");
2205 __bt_hanlde_le_device_disconnection((event_dev_conn_status_t *)event_data);
2208 case OAL_EVENT_GATTC_NOTIFICATION_REGISTERED: {
2209 BT_INFO("OAL Event: GATT Client Notification Registered");
2210 __bt_handle_client_notification_registered((event_gattc_regdereg_notify_t *) event_data, TRUE);
2213 case OAL_EVENT_GATTC_NOTIFICATION_DEREGISTERED: {
2214 BT_INFO("OAL Event: GATT Client Notification Registered");
2215 __bt_handle_client_notification_registered((event_gattc_regdereg_notify_t *) event_data, FALSE);
2218 case OAL_EVENT_GATTC_NOTIFY_DATA: {
2219 BT_INFO("OAL Event: GATT Client Notification Data");
2220 __bt_handle_client_notification_data((event_gattc_notify_data *) event_data);
2223 case OAL_EVENT_GATTC_SERVICE_CHANGED_IND: {
2224 BT_INFO("OAL Event: GATT Client service changed indication");
2225 __bt_handle_client_service_changed_ind((event_gattc_service_changed_data *)event_data);
2228 case OAL_EVENT_GATTC_MTU_EXCHANGE_COMPLETED: {
2229 BT_INFO("OAL Event: GATT Client MTU Exchange Complete");
2230 __bt_handle_client_mtu_exchange_completed((event_gattc_mtu_configured_t *) event_data);
2239 int _bt_gatt_server_add_service(char *sender, int service_type,
2240 int num_handles, char *svc_uuid, int instance_id)
2242 BT_CHECK_PARAMETER(svc_uuid, return);
2243 BT_CHECK_PARAMETER(sender, return);
2244 int ret = OAL_STATUS_SUCCESS;
2246 oal_gatt_srvc_id_t svc_data;
2248 svc_data.is_prmry = service_type;
2249 svc_data.id.inst_id = instance_id;
2251 BT_INFO("Service UUID [%s] Num handles [%d] Instance ID [%d]", svc_uuid, num_handles, instance_id);
2252 _bt_string_to_uuid(svc_uuid, (service_uuid_t*)&svc_data.id.uuid);
2254 ret = gatts_add_service(instance_id, &svc_data, num_handles);
2255 if (ret != OAL_STATUS_SUCCESS) {
2256 BT_ERR("ret: %d", ret);
2257 return BLUETOOTH_ERROR_INTERNAL;
2260 return BLUETOOTH_ERROR_NONE;
2264 int _bt_gatt_server_add_included_service(char *sender, int instance_id,
2265 int service_handle, int included_svc_handle)
2267 BT_CHECK_PARAMETER(sender, return);
2268 int ret = OAL_STATUS_SUCCESS;
2270 ret = gatts_add_included_services(instance_id, service_handle, included_svc_handle);
2271 if (ret != OAL_STATUS_SUCCESS) {
2272 BT_ERR("ret: %d", ret);
2273 return BLUETOOTH_ERROR_INTERNAL;
2275 return BLUETOOTH_ERROR_NONE;
2278 int _bt_gatt_server_add_characteristic(char *sender, char *char_uuid,
2279 bluetooth_gatt_server_attribute_params_t *param)
2281 BT_CHECK_PARAMETER(char_uuid, return);
2282 BT_CHECK_PARAMETER(sender, return);
2283 BT_CHECK_PARAMETER(param, return);
2284 int ret = OAL_STATUS_SUCCESS;
2286 oal_uuid_t uuid = {{0} };
2288 BT_INFO("Char UUID [%s] Instance ID [%d]", char_uuid, param->instance_id);
2289 _bt_string_to_uuid(char_uuid, (service_uuid_t*)&uuid);
2291 BT_INFO("Char permission From API [0x%x]", param->permissions);
2293 ret = gatts_add_characteristics(param->instance_id, param->service_handle, &uuid,
2294 param->properties, (int)param->permissions);
2295 if (ret != OAL_STATUS_SUCCESS) {
2296 BT_ERR("ret: %d", ret);
2297 return BLUETOOTH_ERROR_INTERNAL;
2299 return BLUETOOTH_ERROR_NONE;
2302 int _bt_gatt_server_add_descriptor(char *sender, char *desc_uuid,
2303 bt_gatt_permission_t *param, int service_handle, int instance_id)
2305 BT_CHECK_PARAMETER(desc_uuid, return);
2306 BT_CHECK_PARAMETER(sender, return);
2307 BT_CHECK_PARAMETER(param, return);
2308 int ret = OAL_STATUS_SUCCESS;
2310 oal_uuid_t uuid = {{0} };
2312 BT_INFO("Descriptor UUID [%s] Instance ID [%d] Service handle [%d]",
2313 desc_uuid, service_handle, instance_id);
2315 _bt_string_to_uuid(desc_uuid, (service_uuid_t*)&uuid);
2317 BT_INFO("Descriptor permission From API [0x%x]", *param);
2318 ret = gatts_add_descriptor(instance_id, service_handle, &uuid, (int)*param);
2320 if (ret != OAL_STATUS_SUCCESS) {
2321 BT_ERR("ret: %d", ret);
2322 return BLUETOOTH_ERROR_INTERNAL;
2324 return BLUETOOTH_ERROR_NONE;
2327 int _bt_gatt_server_start_service(char *sender, int service_handle, int instance_id)
2329 BT_CHECK_PARAMETER(sender, return);
2330 int ret = OAL_STATUS_SUCCESS;
2332 ret = gatts_start_service(instance_id, service_handle, BT_GATT_TRANSPORT_LE);
2333 if (ret != OAL_STATUS_SUCCESS) {
2334 BT_ERR("ret: %d", ret);
2335 return BLUETOOTH_ERROR_INTERNAL;
2337 return BLUETOOTH_ERROR_NONE;
2340 int _bt_gatt_server_stop_service(char *sender, int service_handle, int instance_id)
2342 BT_CHECK_PARAMETER(sender, return);
2343 int ret = OAL_STATUS_SUCCESS;
2345 ret = gatts_stop_service(instance_id, service_handle);
2346 if (ret != OAL_STATUS_SUCCESS) {
2347 BT_ERR("ret: %d", ret);
2348 return BLUETOOTH_ERROR_INTERNAL;
2350 return BLUETOOTH_ERROR_NONE;
2353 int _bt_gatt_server_delete_service(char *sender, int service_handle, int instance_id)
2355 BT_CHECK_PARAMETER(sender, return);
2356 int ret = OAL_STATUS_SUCCESS;
2360 ret = gatts_delete_service(instance_id, service_handle);
2361 if (ret != OAL_STATUS_SUCCESS) {
2362 BT_ERR("ret: %d", ret);
2363 return BLUETOOTH_ERROR_INTERNAL;
2366 /* Remove the Service Handle */
2367 for (l = numapps[instance_id].service_handles; l != NULL;) {
2369 l = g_slist_next(l);
2370 if (handle && *handle == service_handle) {
2371 BT_INFO("Remove Service handle [%d]", *handle);
2372 numapps[instance_id].service_handles = g_slist_remove(numapps[instance_id].service_handles, handle);
2378 return BLUETOOTH_ERROR_NONE;
2381 int _bt_gatt_server_send_response(char *sender, bluetooth_gatt_att_data_t *data,
2382 bluetooth_gatt_server_response_params_t *param)
2384 BT_CHECK_PARAMETER(sender, return);
2385 BT_CHECK_PARAMETER(data, return);
2386 BT_CHECK_PARAMETER(param, return);
2387 struct gatt_server_req_info *req_info = NULL;
2388 int ret = OAL_STATUS_SUCCESS;
2390 oal_gatt_response_t response;
2392 BT_INFO("GATT Server Response: Req Type [%d] req_id [%d] status [%d] auth_req [%d] offset[%d] data len[%d]",
2393 param->req_type, param->request_id,
2394 param->response_status, param->auth_req,
2395 data->offset, data->length);
2397 /* Search for matching Request in List */
2398 req_info = __bt_gatt_server_find_request_info(param->request_id, param->req_type);
2400 BT_ERR("GATT Server Req Info not found for current response..return Error");
2401 return BLUETOOTH_ERROR_NOT_IN_OPERATION;
2404 memset(&response, 0x00, sizeof(oal_gatt_response_t));
2406 response.handle = req_info->attribute_handle;
2407 response.attr_value.auth_req = param->auth_req;
2408 response.attr_value.handle = req_info->attribute_handle;
2409 response.attr_value.offset = data->offset;
2410 response.attr_value.len = data->length;
2411 memcpy(&response.attr_value.value, &data->data, data->length);
2414 ret = gatts_send_response(req_info->connection_id, param->request_id,
2415 param->response_status, &response);
2417 if (ret != OAL_STATUS_SUCCESS) {
2418 BT_ERR("ret: %d", ret);
2419 return BLUETOOTH_ERROR_INTERNAL;
2422 BT_INFO("GATT Server Response successfully sent");
2423 /* Remove GATT server request from list */
2424 gatt_server_requests = g_slist_remove(gatt_server_requests, req_info);
2425 g_free(req_info->addr);
2427 return BLUETOOTH_ERROR_NONE;
2430 int _bt_gatt_server_acquire_send_response(char *sender, bluetooth_gatt_server_acquire_response_params_t *param , void *fd_list)
2432 BT_CHECK_PARAMETER(sender, return);
2433 BT_CHECK_PARAMETER(param, return);
2434 struct gatt_server_req_info *req_info = NULL;
2435 int ret = OAL_STATUS_SUCCESS;
2438 BT_INFO("GATT acquire Server Response: Req Type [%d] req_id [%d] fd [%d] mtu[%d]",
2439 param->req_type, param->request_id,
2443 /* Search for matching Request in List */
2444 req_info = __bt_gatt_server_find_request_info(param->request_id, param->req_type);
2446 BT_ERR("GATT acquire Server Req Info not found for current response..return Error");
2447 return BLUETOOTH_ERROR_NOT_IN_OPERATION;
2450 ret = gatt_send_response_acquire(req_info->connection_id, param->request_id, 0, param->fd, param->mtu, fd_list);
2452 if (ret != OAL_STATUS_SUCCESS) {
2453 BT_ERR("ret: %d", ret);
2454 return BLUETOOTH_ERROR_INTERNAL;
2457 BT_INFO("GATT acquire Server Response successfully sent");
2458 /* Remove GATT server request from list */
2459 gatt_server_requests = g_slist_remove(gatt_server_requests, req_info);
2460 g_free(req_info->addr);
2462 return BLUETOOTH_ERROR_NONE;
2467 int _bt_gatt_server_send_indication(char *sender, bluetooth_device_address_t *dev_addr,
2468 bluetooth_gatt_att_data_t *data,
2469 bluetooth_gatt_server_indication_params_t *param)
2471 BT_CHECK_PARAMETER(sender, return);
2472 BT_CHECK_PARAMETER(data, return);
2473 BT_CHECK_PARAMETER(param, return);
2475 gboolean all_send = FALSE;
2476 int ret = OAL_STATUS_SUCCESS;
2477 struct gatt_client_info_t *conn;
2479 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2480 _bt_convert_addr_type_to_string(address, dev_addr->addr);
2482 if (memcmp(dev_addr->addr, BDADDR_ANY, 6) == 0) {
2483 BT_INFO("GATT Server: Send Indication to all connected GATT clients..");
2486 BT_INFO("GATT Server: Send Indication to connected GATT client addr [%s]", address);
2489 /* Attempt to send Notification/Indication to all Connected GATT clients */
2491 ret = __bt_gatt_send_indication_to_all_connected_clients(data, param);
2492 if (ret != OAL_STATUS_SUCCESS) {
2493 BT_ERR("ret: %d", ret);
2495 return BLUETOOTH_ERROR_INTERNAL;
2499 conn = _bt_find_remote_gatt_client_info(address);
2501 ret = gatts_send_indication(param->instance_id, param->atrribute_handle,
2502 conn->connection_id, data->length,
2503 param->need_confirmation, (char *)(&data->data[0]));
2505 if (ret != OAL_STATUS_SUCCESS) {
2506 BT_ERR("ret: %d", ret);
2507 BT_INFO("Indication failed to send to Remote GATT Client [%s]", address);
2509 return BLUETOOTH_ERROR_INTERNAL;
2511 BT_INFO("Indication sent to Remote GATT Client [%s] wait for Notification completed event from OAL", address);
2513 num_indicate_clients = 1;
2514 return BLUETOOTH_ERROR_NONE;
2516 BT_ERR("Remote GATT client [%s] is not connected..Cant send Indication!!", address);
2518 return BLUETOOTH_ERROR_NOT_CONNECTED;
2521 return BLUETOOTH_ERROR_NONE;
2524 int _bt_gatt_server_update_attribute_value(char *sender, int instance_id,
2525 bluetooth_gatt_server_update_value_t *param)
2527 BT_CHECK_PARAMETER(sender, return);
2528 BT_CHECK_PARAMETER(param, return);
2529 int ret = OAL_STATUS_SUCCESS;
2531 oal_gatt_value_t value;
2532 BT_INFO("GATT Server Update value: Instance ID [%d] attr handle [%d] Value len [%d]",
2533 instance_id, param->attribute_handle, param->length);
2536 memset(&value, 0x00, sizeof(oal_gatt_value_t));
2538 value.handle = param->attribute_handle;
2539 value.len = param->length;
2540 memcpy(&value.value, ¶m->data.data, param->length);
2542 ret = gatts_update_att_value(instance_id, &value);
2544 if (ret != OAL_STATUS_SUCCESS) {
2545 BT_ERR("ret: %d", ret);
2546 return BLUETOOTH_ERROR_INTERNAL;
2549 BT_INFO("GATT Server Update Attribute Value successfully");
2550 return BLUETOOTH_ERROR_NONE;
2553 int _bt_request_att_mtu(bluetooth_device_address_t *device_address,
2556 struct gatt_server_info_t *conn_info = NULL;
2558 int ret = OAL_STATUS_SUCCESS;
2560 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
2561 _bt_convert_addr_type_to_string(addr, device_address->addr);
2563 /* Check if remote GATT Server is connected or not */
2564 conn_info = _bt_find_remote_gatt_server_info(addr);
2566 BT_INFO("GATT Server [%s] is connected, conn Id [%d]",
2567 conn_info->addr, conn_info->connection_id);
2569 BT_ERR("GATT Server is not yet connected..");
2571 return BLUETOOTH_ERROR_NOT_CONNECTED;
2574 ret = gattc_configure_mtu(conn_info->connection_id, mtu);
2575 if (ret != OAL_STATUS_SUCCESS) {
2576 BT_ERR("ret: %d", ret);
2578 return BLUETOOTH_ERROR_INTERNAL;
2582 return BLUETOOTH_ERROR_NONE;
2585 int _bt_get_att_mtu(bluetooth_device_address_t *address,
2588 BT_CHECK_PARAMETER(address, return);
2589 BT_CHECK_PARAMETER(mtu, return);
2590 struct gatt_client_info_t *conn_info = NULL;
2591 char addr[BT_ADDRESS_STRING_SIZE] = { 0 };
2592 int ret = OAL_STATUS_SUCCESS;
2595 _bt_convert_addr_type_to_string(addr, address->addr);
2597 BT_INFO("Get current MTU size for the remote client:DevAddress:[%s]", addr);
2599 conn_info = _bt_find_remote_gatt_client_info(addr);
2601 BT_INFO("GATT Client [%s] is connected, conn Id [%d] Instance ID [%d]",
2602 conn_info->addr, conn_info->connection_id, conn_info->instance_id);
2604 BT_ERR("GATT Client [%s] is not yet connected..", addr);
2605 return BLUETOOTH_ERROR_NOT_CONNECTED;
2608 ret = gatts_get_att_mtu(conn_info->connection_id, &stack_mtu);
2609 if (ret != OAL_STATUS_SUCCESS) {
2610 BT_ERR("ret: %d", ret);
2611 return BLUETOOTH_ERROR_INTERNAL;
2614 BT_INFO("ATT MTU received from OAL [%d]", stack_mtu);
2615 *mtu = (unsigned int)stack_mtu;
2618 BT_ERR("MTU value is zero, GATT Client [%s] is not yet connected..", addr);
2619 return BLUETOOTH_ERROR_NOT_CONNECTED;
2622 return BLUETOOTH_ERROR_NONE;
2625 #ifdef TIZEN_GATT_CLIENT
2626 /* GATT Client utility static functions */
2627 static bt_gatt_service_info_list_t *__bt_get_service_info_list(int conn_id)
2630 bt_gatt_service_info_list_t *info = NULL;
2632 for (l = list_gatt_info; l != NULL; l = g_slist_next(l)) {
2633 info = (bt_gatt_service_info_list_t *)l->data;
2637 if (info->conn_id == conn_id)
2644 static bt_gatt_service_info_t *__bt_find_matching_service(
2645 bt_gatt_service_info_list_t *svc_list, oal_gatt_srvc_id_t *svc)
2648 bt_gatt_service_info_t *info = NULL;
2650 for (l = svc_list->services; l != NULL; l = g_slist_next(l)) {
2651 info = (bt_gatt_service_info_t *)l->data;
2655 /* Match UUID and instance ID */
2656 if (!memcmp(&svc->id.uuid.uuid, &info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN)
2657 && (svc->id.inst_id == info->inst_id)) {
2664 static bt_gatt_char_info_t *__bt_find_matching_charc(
2665 bt_gatt_service_info_t *svc_info, oal_gatt_id_t *charc)
2668 bt_gatt_char_info_t *info = NULL;
2670 for (l = svc_info->chars; l != NULL; l = g_slist_next(l)) {
2671 info = (bt_gatt_char_info_t *)l->data;
2675 /* Match UUID and instance ID */
2676 if (!memcmp(&charc->uuid.uuid, &info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN)
2677 && (charc->inst_id == info->inst_id)) {
2684 static bt_gatt_descriptor_info_t *__bt_find_matching_desc(
2685 bt_gatt_char_info_t *char_info, oal_gatt_id_t *desc)
2688 bt_gatt_descriptor_info_t *info = NULL;
2690 for (l = char_info->descs; l != NULL; l = g_slist_next(l)) {
2691 info = (bt_gatt_descriptor_info_t *)l->data;
2695 /* Match UUID and instance ID */
2696 if (!memcmp(&desc->uuid, &info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN)
2697 && (desc->inst_id == info->inst_id)) {
2705 static struct gatt_server_info_t *__bt_find_remote_gatt_server_info_from_conn_id(int conn_id)
2708 struct gatt_server_info_t *info = NULL;
2710 for (l = gatt_server_info_list; l != NULL; l = g_slist_next(l)) {
2711 info = (struct gatt_server_info_t*)l->data;
2715 if (info->connection_id == conn_id) {
2716 BT_INFO("Remote GATT server found addr[%s]", info->addr);
2723 static bt_gatt_service_info_t* __bt_find_removed_service(bt_gatt_service_info_list_t *svc_list)
2726 bt_gatt_service_info_t *info = NULL;
2728 for (l = svc_list->services; l != NULL; l = g_slist_next(l)) {
2729 info = (bt_gatt_service_info_t*)l->data;
2733 /* Service is marked a removed */
2734 if (info->is_removed == 1)
2740 static void __bt_remove_service_info_from_list(bt_gatt_service_info_t *svc_info)
2746 bt_gatt_char_info_t *charc = NULL;
2747 bt_gatt_included_service_info_t *incl = NULL;
2748 bt_gatt_descriptor_info_t *desc = NULL;
2750 /* Remove all Characteristic and Descriptors within characteristic */
2751 for (l = svc_info->chars; l != NULL;) {
2752 charc = (bt_gatt_char_info_t*)l->data;
2753 l = g_slist_next(l); /* Incase if l is removed, saving next to l */
2758 /* Inside Characteristic */
2759 for (l1 = charc->descs; l1 != NULL;) {
2761 desc = (bt_gatt_descriptor_info_t*)l1->data;
2762 l1 = g_slist_next(l1);
2767 /* Remove Descriptor */
2768 charc->descs = g_slist_remove(charc->descs, desc);
2771 /* Remove Characteristic */
2772 svc_info->chars = g_slist_remove(svc_info->chars, charc);
2776 /* Remove all Included Services */
2777 for (l2 = svc_info->included_svcs; l2 != NULL;) {
2778 incl = (bt_gatt_included_service_info_t*)l2->data;
2779 l2 = g_slist_next(l2); /* Incase if l is removed, saving next to l */
2784 /* Remove included service */
2785 svc_info->included_svcs = g_slist_remove(svc_info->included_svcs, incl);
2792 static void __bt_build_service_browse_info(int conn_id,
2793 bt_services_browse_info_t* info)
2796 bt_gatt_service_info_list_t *svc_info_list;
2797 bt_gatt_service_info_t *svc_info;
2799 service_uuid_t uuid;
2800 struct gatt_server_info_t *conn_info = NULL;
2802 char uuid_string[BLUETOOTH_UUID_STRING_MAX];
2804 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(conn_id);
2809 _bt_convert_addr_string_to_type(info->device_addr.addr, conn_info->addr);
2811 svc_info_list = __bt_get_service_info_list(conn_id);
2815 info->count = g_slist_length(svc_info_list->services);
2816 BT_DBG("Total services present in the svc info list for this conn id [%d] is [%d]",
2817 conn_id, info->count);
2819 for (l = svc_info_list->services; l != NULL; l = g_slist_next(l)) {
2820 svc_info = (bt_gatt_service_info_t*)l->data;
2821 if (svc_info == NULL)
2824 memcpy(&uuid.uuid, &svc_info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
2825 _bt_uuid_to_string(&uuid, uuid_string);
2827 BT_INFO("[%d] %s [%s]", count, uuid_string, _bt_convert_uuid_to_string(uuid_string));
2829 /* Fill UUID of service */
2830 g_strlcpy(info->uuids[count], uuid_string,
2831 BLUETOOTH_UUID_STRING_MAX);
2833 /* Fill instance ID of service */
2834 info->inst_id[count] = svc_info->inst_id;
2836 /* Fill primary service or not info */
2837 info->primary[count] = svc_info->is_primary;
2839 /* Increment count of services browsed */
2844 static void __bt_build_char_browse_info(int conn_id,
2845 bt_gatt_service_info_t *svc_info,
2846 bt_char_browse_info_t* info)
2849 bt_gatt_char_info_t *char_info;
2850 service_uuid_t uuid;
2852 struct gatt_server_info_t *conn_info = NULL;
2854 char uuid_string[BLUETOOTH_UUID_STRING_MAX];
2856 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(conn_id);
2860 /* Fill default data, this will be required even in case of failure */
2861 _bt_convert_addr_string_to_type(info->device_addr.addr, conn_info->addr);
2862 memcpy(&info->svc_uuid, svc_info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
2863 info->svc_inst_id = svc_info->inst_id;
2865 if (!svc_info->chars) {
2866 BT_ERR("No Chars browsed for address [%s]", conn_info->addr);
2870 info->count = g_slist_length(svc_info->chars);
2872 for (l = svc_info->chars; l != NULL; l = g_slist_next(l)) {
2873 char_info = (bt_gatt_char_info_t*)l->data;
2874 if (char_info == NULL)
2877 memcpy(&uuid.uuid, &char_info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
2878 _bt_uuid_to_string(&uuid, uuid_string);
2880 /* Fill UUID of characteristic */
2881 g_strlcpy(info->uuids[count], uuid_string,
2882 BLUETOOTH_UUID_STRING_MAX);
2884 /* Fill instance ID of characteristic */
2885 info->inst_id[count] = char_info->inst_id;
2887 /* Fill property of characteristic */
2888 info->props[count] = char_info->props;
2890 /* Increment count of services browsed */
2893 BT_DBG("Total characteristics browsed [%d]", count);
2896 static void __bt_build_descriptor_browse_info(int conn_id,
2897 bt_gatt_service_info_t *svc_info,
2898 bt_gatt_char_info_t *char_info,
2899 bt_descriptor_browse_info_t* info)
2902 bt_gatt_descriptor_info_t *desc_info;
2904 service_uuid_t uuid;
2905 struct gatt_server_info_t *conn_info = NULL;
2907 char uuid_string[BLUETOOTH_UUID_STRING_MAX];
2909 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(conn_id);
2911 /* Fill default data, this will be required even in case of failure */
2912 _bt_convert_addr_string_to_type(info->device_addr.addr, conn_info->addr);
2913 memcpy(&info->svc_uuid, svc_info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
2914 info->svc_inst_id = svc_info->inst_id;
2915 memcpy(&info->char_uuid, char_info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
2916 info->char_inst_id = char_info->inst_id;
2918 /* Fill property of the parent characteristic of this descriptor */
2919 info->char_props_map = char_info->props;
2921 info->count = g_slist_length(char_info->descs);
2923 if (!char_info->descs) {
2924 BT_ERR("No Descriptors browsed for address [%s]", conn_info->addr);
2928 for (l = char_info->descs; l != NULL; l = g_slist_next(l)) {
2929 desc_info = (bt_gatt_descriptor_info_t*)l->data;
2930 if (desc_info == NULL)
2933 memcpy(&uuid.uuid, &desc_info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
2934 _bt_uuid_to_string(&uuid, uuid_string);
2936 /* Fill UUID of Descriptor */
2937 g_strlcpy(info->uuids[count], uuid_string,
2938 BLUETOOTH_UUID_STRING_MAX);
2940 /* Fill instance ID of Descriptor */
2941 info->inst_id[count] = desc_info->inst_id;
2944 /* Increment count of Descriptor browsed */
2948 BT_INFO("Total descriptors browsed [%d]", count);
2951 static void __bt_free_service_info(bt_gatt_service_info_t *svc)
2953 GSList *ll, *lll, *llll;
2954 bt_gatt_char_info_t *chr = NULL;
2955 bt_gatt_descriptor_info_t *desc = NULL;
2956 bt_gatt_included_service_info_t *incl_svc = NULL;
2958 BT_DBG("Service info Is Prim[%d] Inst ID [%d]", svc->is_primary, svc->inst_id);
2959 /* Delete all chars and its descriptors */
2960 for (ll = svc->chars; ll != NULL; ) {
2961 chr = (bt_gatt_char_info_t *)ll->data;
2962 ll = g_slist_next(ll);
2966 for (lll = chr->descs; lll != NULL; ) {
2967 desc = (bt_gatt_descriptor_info_t *)lll->data;
2968 lll = g_slist_next(lll);
2971 chr->descs = g_slist_remove(chr->descs, desc);
2974 svc->chars = g_slist_remove(svc->chars, chr);
2978 /* Delete all included services */
2979 for (llll = svc->included_svcs; llll != NULL; ) {
2980 incl_svc = (bt_gatt_included_service_info_t *)llll->data;
2981 llll = g_slist_next(llll);
2982 if (incl_svc == NULL)
2984 svc->included_svcs = g_slist_remove(svc->included_svcs, incl_svc);
2989 static void __bt_cleanup_remote_services(struct gatt_server_info_t *conn_info)
2991 bt_gatt_service_info_list_t *svc_info_list = NULL;
2992 bt_gatt_service_info_t *svc = NULL;
2995 svc_info_list = __bt_get_service_info_list(conn_info->connection_id);
2996 if (!svc_info_list) {
2997 BT_INFO("Could not find Svc Info list for the connection ID [%d]",
2998 conn_info->connection_id);
3002 BT_INFO("Start Cleanup of all services. Num Services [%d]", g_slist_length(svc_info_list->services));
3003 for (l = svc_info_list->services; l != NULL; ) {
3004 svc = (bt_gatt_service_info_t *)l->data;
3005 l = g_slist_next(l);
3009 __bt_free_service_info(svc);
3010 svc_info_list->services = g_slist_remove(svc_info_list->services, svc);
3014 list_gatt_info = g_slist_remove(list_gatt_info, svc_info_list);
3015 g_free(svc_info_list);
3018 int _bt_register_gatt_client_instance(const char *sender,
3019 bluetooth_device_address_t *address)
3021 int ret = OAL_STATUS_SUCCESS;
3022 char *uuid_string = NULL;
3027 /* App should ensure that it should not send */
3028 BT_INFO("### Check on which instance GATT Client instance can be initialized....");
3029 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
3030 if (numapps[k].is_initialized == 1) {
3031 BT_INFO("Instance ID [%d] is already in use..Check next slot",
3032 numapps[k].instance_id);
3035 BT_INFO("Time to register GATT client instancer..UUID to be used is [%s] slot [%d]",
3036 uuid_list[slot-1], slot);
3042 BT_ERR("No Slot if free for GATT Client registration..");
3043 return BLUETOOTH_ERROR_REGISTRATION_FAILED;
3046 uuid_string = g_malloc0(BT_UUID_STRING_MAX);
3047 _bt_string_to_uuid(uuid_list[slot-1], (service_uuid_t*)&uuid);
3048 g_strlcpy(uuid_string, uuid_list[slot-1], BT_UUID_STRING_MAX);
3049 BT_INFO("Copied UUID string [%s]", uuid_string);
3051 /* Register GATT Client */
3052 ret = gattc_register(&uuid);
3053 if (ret != OAL_STATUS_SUCCESS) {
3054 BT_ERR("ret: %d", ret);
3055 g_free(uuid_string);
3056 return BLUETOOTH_ERROR_INTERNAL;
3059 BT_INFO("GATT Client registration call successfully accepted by OAL..wait for Instance Initialized event from OAL..");
3061 /* Return & wait for GATT Client Instance Initialization event */
3062 memset(numapps[slot].sender, 0x00, sizeof(numapps[slot].sender));
3063 memset(numapps[slot].uuid, 0x00, sizeof(numapps[slot].uuid));
3065 g_strlcpy(numapps[slot].sender, sender, sizeof(numapps[slot].sender));
3066 g_strlcpy(numapps[slot].uuid, uuid_string, sizeof(numapps[slot].uuid));
3068 /* Address is saved here. When event comes, sender + address are matched for replying pending
3069 request. It is impossible for same sender to have requests with two same addresses */
3070 memcpy(&numapps[slot].address.addr, address->addr, sizeof(bluetooth_device_address_t));
3072 BT_INFO("Slot [%d] occupied", slot);
3073 numapps[slot].is_initialized = TRUE; /* Set initialization to true here itself */
3075 g_free(uuid_string);
3076 return BLUETOOTH_ERROR_NONE;
3082 /* GATT client events */
3083 static void __bt_handle_client_instance_registered(event_gattc_register_t *data)
3085 bt_service_app_info_t *info = NULL;
3087 char *uuid_string = g_malloc0(BT_UUID_STRING_MAX);
3089 _bt_uuid_to_string(&(data->client_uuid), uuid_string);
3090 BT_INFO("CLient ID is Initialized [%d] UUID initialized [%s]", data->client_if, uuid_string);
3092 /* Platform GATT client framwork does not use Default GATT client instance
3093 This GATT client instance is never deregistred in the lifetime of bt-service */
3094 if (g_strcmp0(uuid_string, DEFAULT_GATT_CLIENT_UUID) == 0) {
3095 BT_INFO("Default client Instance Registered");
3096 gatt_default_client = data->client_if;
3097 g_free(uuid_string);
3101 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
3104 if (g_strcmp0(info->uuid, uuid_string) == 0) {
3105 BT_INFO("Found GATT client.. sender [%s] Slot [%d] occupied", info->sender, k);
3106 info->is_initialized = TRUE;
3107 info->client_id = data->client_if;
3108 __bt_gatt_handle_pending_request_info(BLUETOOTH_ERROR_NONE, BT_GATT_CLIENT_REGISTER,
3109 (void*)info, sizeof(bt_service_app_info_t));
3113 g_free(uuid_string);
3116 static void __bt_handle_client_connected(event_gattc_conn_t *event_data)
3118 int result = BLUETOOTH_ERROR_NONE;
3119 struct gatt_server_info_t *conn_info = NULL;
3120 struct gatt_out_conn_info_t *out_conn_info = NULL;
3122 GVariant *param = NULL;
3124 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
3125 _bt_convert_addr_type_to_string(address,
3126 (unsigned char *)event_data->address.addr);
3128 if (event_data->status != OAL_STATUS_SUCCESS)
3129 result = BLUETOOTH_ERROR_INTERNAL;
3131 /* DBUS Return fo BT_CONNECT_LE for all the apps */
3132 __bt_gatt_handle_pending_request_info(result, BT_CONNECT_LE, address,
3133 BT_ADDRESS_STRING_SIZE);
3135 BT_INFO("Local GATT Client Connected: Remote addr[%s] Client Interface [%d] Connection ID [%d] status[%d]",
3136 address, event_data->client_if, event_data->conn_id, event_data->status);
3138 if (result == BLUETOOTH_ERROR_NONE) {
3139 /* Check if device is already in connected list */
3140 conn_info = _bt_find_remote_gatt_server_info(address);
3143 /* Send event to BT-API */
3144 param = g_variant_new("(is)", result, address);
3145 _bt_send_event(BT_DEVICE_EVENT,
3146 BLUETOOTH_EVENT_GATT_CLIENT_CONNECTED, /* Local device is GATT client */
3149 /* Save Connection info */
3150 conn_info = g_new0(struct gatt_server_info_t, 1);
3151 conn_info->addr = g_strdup(address);
3152 conn_info->client_id = event_data->client_if;
3153 conn_info->connection_id = event_data->conn_id;
3154 gatt_server_info_list = g_slist_append(gatt_server_info_list, conn_info);
3155 BT_DBG("Total num of connected Remote GATT server devices [%d]",
3156 g_slist_length(gatt_server_info_list));
3159 BT_INFO("Do a Internal refresh");
3160 if (OAL_STATUS_SUCCESS != gattc_refresh(conn_info->client_id, &event_data->address))
3161 BT_ERR("GATT database refresh failed!!");
3163 BT_INFO("GATT database refresh Success!!");
3166 BT_ERR("Local GATT Client connected event for addr[%s], but device is in connected list already", address);
3168 __bt_add_mtu_gatt_device(address);
3170 BT_ERR("GATT Client Connection failed!!");
3172 /* If outgoing connection Info is present, then remove it */
3173 out_conn_info = __bt_find_gatt_outgoing_conn_info(address);
3174 if (out_conn_info) {
3175 BT_ERR("Outgoing Client connect request was sent");
3176 outgoing_gatt_conn_list = g_slist_remove(outgoing_gatt_conn_list, out_conn_info);
3177 g_free(out_conn_info->addr);
3178 g_free(out_conn_info);
3183 static void __bt_handle_client_disconnected(event_gattc_conn_t *event_data)
3185 int result = BLUETOOTH_ERROR_NONE;
3187 struct gatt_server_info_t *conn_info = NULL;
3188 struct gatt_out_conn_info_t *out_conn_info = NULL;
3190 GVariant *param = NULL;
3192 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
3193 _bt_convert_addr_type_to_string(address,
3194 (unsigned char *)event_data->address.addr);
3196 if (event_data->status != OAL_STATUS_SUCCESS)
3197 result = BLUETOOTH_ERROR_INTERNAL;
3199 if (NULL == _bt_get_request_info_data(BT_DISCONNECT_LE, address)) {
3200 if (NULL != _bt_get_request_info_data(BT_CONNECT_LE, address)) {
3201 result = BLUETOOTH_ERROR_INTERNAL;
3202 __bt_gatt_handle_pending_request_info(result, BT_CONNECT_LE,
3203 address, BT_ADDRESS_STRING_SIZE);
3204 BT_ERR("Failed to connect Local GATT Remote addr[%s]", address);
3209 /* DBUS Return for BT_DISCONNECT_LE for all the apps */
3210 __bt_gatt_handle_pending_request_info(result, BT_DISCONNECT_LE, address,
3211 BT_ADDRESS_STRING_SIZE);
3213 BT_INFO("Local GATT Client DisConnected: Remote addr[%s] Client Interface [%d] Connection ID [%d] status [%d]",
3214 address, event_data->client_if, event_data->conn_id, event_data->status);
3216 /* Remove Connection info */
3217 conn_info = _bt_find_remote_gatt_server_info(address);
3220 param = g_variant_new("(is)", result, address);
3221 /* Send event to application */
3222 _bt_send_event(BT_DEVICE_EVENT,
3223 BLUETOOTH_EVENT_GATT_CLIENT_DISCONNECTED,
3226 BT_INFO("Remove GATT server info from List..");
3227 /* Remove all services from info list_gatt_info */
3228 __bt_cleanup_remote_services(conn_info);
3230 /* Remove info from List */
3231 gatt_server_info_list = g_slist_remove(gatt_server_info_list, conn_info);
3232 BT_INFO("Total num of connected GATT servers [%d]", g_slist_length(gatt_server_info_list));
3233 g_free(conn_info->addr);
3236 BT_INFO("Can not find conn info, already removed!");
3238 __bt_remove_mtu_gatt_device(address);
3240 /* If outgoing connection Info is present, then remove it */
3241 out_conn_info = __bt_find_gatt_outgoing_conn_info(address);
3242 if (out_conn_info) {
3243 BT_ERR("Client Disconnected event, but outgoing connect request was sent");
3244 outgoing_gatt_conn_list = g_slist_remove(outgoing_gatt_conn_list, out_conn_info);
3245 g_free(out_conn_info->addr);
3246 g_free(out_conn_info);
3252 static void __bt_handle_client_service_search_result(
3253 event_gattc_service_result_t *event_data)
3255 /* Pre: status is never fail from OAL */
3257 /* Find service list from address */
3258 bt_gatt_service_info_list_t *svc_info_list;
3259 bt_gatt_service_info_t *svc_info;
3261 svc_info_list = __bt_get_service_info_list(event_data->conn_status.conn_id);
3262 if (!svc_info_list) {
3263 BT_DBG("Service info list not present for connection ID %d, means first time browse", event_data->conn_status.conn_id);
3264 /* Means for this conn_id, no services are ever browsed, first time,
3265 create service info list for this conn_id */
3266 svc_info_list = g_malloc0(sizeof(bt_gatt_service_info_list_t));
3267 svc_info_list->conn_id = event_data->conn_status.conn_id;
3268 list_gatt_info = g_slist_append(list_gatt_info, svc_info_list);
3271 /* send list and current service's uuid and instance id to find it */
3272 svc_info = __bt_find_matching_service(svc_info_list, &event_data->srvc_id);
3275 /* If not found, check if service changed, if yes, means this is a new service added
3276 in remote GATT device, update uuid info in svc info list structure, to be used when
3277 search is completed */
3279 if (svc_info_list->info.is_changed) {
3280 BT_DBG("Service Changed indication already found for connection ID %d", event_data->conn_status.conn_id);
3281 memcpy(svc_info_list->info.uuid, event_data->srvc_id.id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3283 /* Create and add new service in service list */
3284 svc_info = g_malloc0(sizeof(bt_gatt_service_info_t));
3285 memcpy(svc_info->uuid, event_data->srvc_id.id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3286 svc_info->inst_id = event_data->srvc_id.id.inst_id;
3287 svc_info->is_primary = event_data->srvc_id.is_prmry;
3288 svc_info_list->services = g_slist_append(svc_info_list->services, svc_info);
3289 BT_DBG("Service created and added in Svc info list or connection ID %d", event_data->conn_status.conn_id);
3291 /* If returned matching service info, then just update service_rmeoved value inside it to 0 */
3292 svc_info->is_removed = 0;
3296 static void __bt_handle_client_service_search_completed(
3297 event_gattc_conn_status_t *event_data)
3299 struct gatt_server_info_t *conn_info = NULL;
3300 bt_gatt_service_info_list_t *svc_info_list;
3301 bt_gatt_service_info_t *svc_info;
3302 bt_services_browse_info_t browse_info;
3303 unsigned char uuid_empty[BLUETOOTH_UUID_HEX_MAX_LEN];
3305 memset(&uuid_empty, 0x00, BLUETOOTH_UUID_HEX_MAX_LEN);
3306 memset(&browse_info, 0x00, sizeof(bt_services_browse_info_t));
3307 BT_INFO("Primary Services browsing completed status[%d] conn ID [%d]",
3308 event_data->status, event_data->conn_id);
3310 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(event_data->conn_id);
3312 svc_info_list = __bt_get_service_info_list(event_data->conn_id);
3313 if (!svc_info_list) {
3314 BT_ERR("No services browsed ever for addr [%s]", conn_info->addr);
3316 /* Just build response and return ERROR */
3317 __bt_build_service_browse_info(event_data->conn_id, &browse_info);
3319 __bt_gatt_handle_pending_request_info(BLUETOOTH_ERROR_INTERNAL,
3320 BT_GATT_GET_PRIMARY_SERVICES, &browse_info,
3321 sizeof(bt_services_browse_info_t));
3325 /* If fail, then send event with error */
3326 if (event_data->status != OAL_STATUS_SUCCESS) {
3327 /* Just build response and return ERROR */
3328 __bt_build_service_browse_info(event_data->conn_id, &browse_info);
3330 __bt_gatt_handle_pending_request_info(BLUETOOTH_ERROR_INTERNAL,
3331 BT_GATT_GET_PRIMARY_SERVICES, &browse_info,
3332 sizeof(bt_services_browse_info_t));
3336 /* If success, then find service info list from address */
3338 /* If svc_changed == 1 and uuid valid, means a new service is added*/
3339 if (svc_info_list->info.is_changed && !memcmp(uuid_empty, svc_info_list->info.uuid, BLUETOOTH_UUID_HEX_MAX_LEN)) {
3340 /* TODO: Send event -Service added with instance ID and UUID of newly added service */
3341 BT_INFO("new service added");
3343 BT_INFO("TODO new service added");
3346 /* If svc_changed == 1 and uuid invalid, then a service is removed */
3347 if (svc_info_list->info.is_changed && memcmp(uuid_empty, svc_info_list->info.uuid, BLUETOOTH_UUID_HEX_MAX_LEN)) {
3348 /* Scan through the service info list to find service with is_removed = 1*/
3349 svc_info = __bt_find_removed_service(svc_info_list);
3351 /* TODO Send event - Service removed with instance ID and UUID of just rmeoved service */
3353 /* Remove that service info from service info list */
3354 svc_info_list->services = g_slist_remove(svc_info_list->services, svc_info);
3356 /* Delete that service completely from svc_info list*/
3357 __bt_remove_service_info_from_list(svc_info);
3361 /* Reset svc_changed = 0, and reset UUID = all 0's */
3362 svc_info_list->info.is_changed = 0;
3363 memset(&svc_info_list->info.uuid, 0x00, BLUETOOTH_UUID_HEX_MAX_LEN);
3365 /* Build Reply and send to service browse primary services request of pending apps */
3366 __bt_build_service_browse_info(event_data->conn_id, &browse_info);
3368 __bt_gatt_handle_pending_request_info(BLUETOOTH_ERROR_NONE,
3369 BT_GATT_GET_PRIMARY_SERVICES, &browse_info,
3370 sizeof(bt_services_browse_info_t));
3374 static void __bt_handle_client_characteristic_search_result(
3375 event_gattc_characteristic_result_t *event_data)
3377 bt_gatt_service_info_list_t *svc_info_list;
3378 bt_gatt_service_info_t *svc_info;
3379 bt_gatt_char_info_t *char_info;
3380 bt_char_browse_info_t browse_info;
3382 memset(&browse_info, 0x00, sizeof(bt_char_browse_info_t));
3385 if (event_data->conn_status.status == OAL_STATUS_SUCCESS) {
3386 /* Find service info list from address */
3387 svc_info_list = __bt_get_service_info_list(event_data->conn_status.conn_id);
3388 if (svc_info_list == NULL) {
3389 BT_ERR("svc_info_list is NULL");
3394 /* Find matching service info from svc info list */
3395 svc_info = __bt_find_matching_service(svc_info_list, &event_data->srvc_id);
3396 if (svc_info == NULL) {
3397 BT_ERR("svc_info is NULL");
3401 /* Find Matching char from service info in event */
3402 char_info = __bt_find_matching_charc(svc_info, &event_data->char_id);
3404 /* If not found, then add new characteristic and return */
3406 BT_DBG("Add new characteristic");
3407 char_info = g_malloc0(sizeof(bt_gatt_char_info_t));
3408 memcpy(char_info->uuid, event_data->char_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3410 char_info->inst_id = event_data->char_id.inst_id;
3411 char_info->props = event_data->char_prop;
3412 svc_info->chars = g_slist_append(svc_info->chars, char_info);
3414 /* If found, then return */
3415 BT_DBG("update char property as Characteristic browsed is already present");
3416 char_info->props |= event_data->char_prop;
3419 /* If Not success: Means Charc browse is completed */
3420 /* Find char list from service in event */
3421 /* Find service list from address */
3422 svc_info_list = __bt_get_service_info_list(event_data->conn_status.conn_id);
3423 if (svc_info_list == NULL) {
3424 BT_ERR("svc_info_list is NULL");
3428 /* Find service info from service in event */
3429 svc_info = __bt_find_matching_service(svc_info_list, &event_data->srvc_id);
3430 if (svc_info == NULL) {
3431 BT_ERR("svc_info is NULL");
3435 /* Build char list from service in event */
3436 __bt_build_char_browse_info(event_data->conn_status.conn_id,
3437 svc_info, &browse_info);
3439 /* Create response and return by sending event*/
3440 /* Build Reply and send to service browse All Included services request of pending apps */
3441 __bt_gatt_handle_pending_request_info(BLUETOOTH_ERROR_NONE,
3442 BT_GATT_GET_SERVICE_PROPERTIES,
3444 sizeof(bt_char_browse_info_t));
3448 static void __bt_handle_client_descriptor_search_result(
3449 event_gattc_descriptor_result_t *event_data)
3451 bt_gatt_service_info_list_t *svc_info_list;
3452 bt_gatt_service_info_t *svc_info;
3453 bt_gatt_char_info_t *char_info;
3454 bt_gatt_descriptor_info_t *desc_info;
3455 bt_descriptor_browse_info_t browse_info;
3457 BT_INFO("descriptor search result status [%d]", event_data->conn_status.status);
3459 memset(&browse_info, 0x00, sizeof(bt_descriptor_browse_info_t));
3462 if (event_data->conn_status.status == OAL_STATUS_SUCCESS) {
3463 /* Find service list from address */
3464 svc_info_list = __bt_get_service_info_list(event_data->conn_status.conn_id);
3465 if (svc_info_list == NULL) {
3466 BT_ERR("svc_info_list is NULL");
3470 svc_info = __bt_find_matching_service(svc_info_list, &event_data->srvc_id);
3471 if (svc_info == NULL) {
3472 BT_ERR("svc_info is NULL");
3476 char_info = __bt_find_matching_charc(svc_info, &event_data->char_id);
3477 if (char_info == NULL) {
3478 BT_ERR("char_info is NULL");
3482 desc_info = __bt_find_matching_desc(char_info, &event_data->descr_id);
3483 /* If not found, add new descriptor and return */
3485 desc_info = g_malloc0(sizeof(bt_gatt_descriptor_info_t));
3486 memcpy(desc_info->uuid, event_data->descr_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3488 desc_info->inst_id = event_data->descr_id.inst_id;
3489 char_info->descs = g_slist_append(char_info->descs, desc_info);
3492 /* If found, then return */
3493 BT_INFO("Characteristic browsed is already presesnt");
3496 /* If Not success */
3497 /* Find service list from address */
3498 /* Find included service list from service in event */
3499 /* Create response and return by sending event*/
3500 svc_info_list = __bt_get_service_info_list(event_data->conn_status.conn_id);
3501 if (svc_info_list == NULL) {
3502 BT_ERR("svc_info_list is NULL");
3506 /* Find service info from service in event */
3507 svc_info = __bt_find_matching_service(svc_info_list, &event_data->srvc_id);
3508 if (svc_info == NULL) {
3509 BT_ERR("svc_info is NULL");
3513 /* Find char info from char in event */
3514 char_info = __bt_find_matching_charc(svc_info, &event_data->char_id);
3515 if (char_info == NULL) {
3516 BT_ERR("char_info is NULL");
3520 /* Build descriptor list from char in event */
3521 __bt_build_descriptor_browse_info(event_data->conn_status.conn_id,
3522 svc_info, char_info, &browse_info);
3525 __bt_gatt_handle_pending_request_info(BLUETOOTH_ERROR_NONE,
3526 BT_GATT_GET_CHARACTERISTIC_PROPERTIES,
3528 sizeof(bt_descriptor_browse_info_t));
3532 static void __bt_handle_client_characteristic_read_data(
3533 event_gattc_read_data *event_data)
3535 int result = BLUETOOTH_ERROR_NONE;
3536 struct gatt_server_info_t *conn_info = NULL;
3537 bluetooth_gatt_client_char_prop_info_t read_info;
3539 /* Read Information data structures */
3540 GVariant *param = NULL;
3541 GVariant *data = NULL;
3542 GVariant *data_svc_uuid = NULL;
3543 GVariant *data_char_uuid = NULL;
3544 char *read_val = NULL;
3545 char *svc_uuid = NULL;
3546 char *char_uuid = NULL;
3549 //memset(&read_info, 0x00, sizeof(bt_gatt_handle_property_t));
3550 memset(&read_info, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3552 /* Extract Address from conn_id of event data */
3553 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(
3554 event_data->uuid_status.conn_status.conn_id);
3556 BT_INFO("Characteristic Read result from addr [%s] status [%d]",
3557 conn_info->addr, event_data->uuid_status.conn_status.status);
3559 /* Fill char in buffer */
3560 memcpy(&read_info.characteristic.uuid,
3561 event_data->uuid_status.char_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3562 read_info.characteristic.instance_id = event_data->uuid_status.char_id.inst_id;
3564 /* Fill Service in buffer */
3565 memcpy(&read_info.svc.uuid,
3566 event_data->uuid_status.srvc_id.id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3567 read_info.svc.instance_id = event_data->uuid_status.srvc_id.id.inst_id;
3569 /* Fill remote device address */
3570 _bt_convert_addr_string_to_type(read_info.device_address.addr, conn_info->addr);
3572 /* Fill data and reply to all apps waiting for Read result on the same characteristic
3573 Note: Even in case of failure, address, handles and result code should be returned */
3574 if (event_data->uuid_status.conn_status.status != OAL_STATUS_SUCCESS)
3575 result = BLUETOOTH_ERROR_INTERNAL;
3577 if (event_data->data_len > 0) {
3579 // for (i = 0; i < event_data->data_len; i++)
3580 // BT_INFO("Data[%d] = [0x%x]", i, event_data->data[i]);
3583 read_val = g_memdup(&event_data->data[0], event_data->data_len);
3585 data = g_variant_new_from_data(
3586 G_VARIANT_TYPE_BYTESTRING,
3588 event_data->data_len,
3591 BT_ERR("Characteristic Read success, but no data!!!");
3593 data = g_variant_new_from_data(
3594 G_VARIANT_TYPE_BYTESTRING,
3601 svc_uuid = g_memdup(&event_data->uuid_status.srvc_id.id.uuid.uuid[0], uuid_len);
3603 data_svc_uuid = g_variant_new_from_data(
3604 G_VARIANT_TYPE_BYTESTRING,
3610 char_uuid = g_memdup(&event_data->uuid_status.char_id.uuid.uuid[0], uuid_len);
3612 data_char_uuid = g_variant_new_from_data(
3613 G_VARIANT_TYPE_BYTESTRING,
3618 param = g_variant_new("(isn@ayin@ayin@ay)", result,
3622 event_data->uuid_status.srvc_id.id.inst_id,
3625 event_data->uuid_status.char_id.inst_id,
3626 event_data->data_len,
3630 _bt_send_event(BT_GATT_CLIENT_EVENT,
3631 BLUETOOTH_EVENT_GATT_READ_CHAR,
3634 /* Send DBUS return */
3635 __bt_gatt_handle_pending_request_info(result,
3636 BT_GATT_READ_CHARACTERISTIC,
3638 sizeof(bluetooth_gatt_client_char_prop_info_t));
3649 static void __bt_handle_client_descriptor_read_data(
3650 event_gattc_read_data *event_data)
3652 int result = BLUETOOTH_ERROR_NONE;
3653 struct gatt_server_info_t *conn_info = NULL;
3654 bluetooth_gatt_client_desc_prop_info_t read_info;
3656 /* Read Information data structures */
3657 GVariant *param = NULL;
3658 GVariant *data = NULL;
3659 GVariant *data_svc_uuid = NULL;
3660 GVariant *data_char_uuid = NULL;
3661 GVariant *data_desc_uuid = NULL;
3662 char *read_val = NULL;
3663 char *svc_uuid = NULL;
3664 char *char_uuid = NULL;
3665 char *desc_uuid = NULL;
3670 memset(&read_info, 0x00, sizeof(bluetooth_gatt_client_desc_prop_info_t));
3672 /* Extract Address from conn_id of event data */
3673 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(
3674 event_data->uuid_status.conn_status.conn_id);
3676 BT_INFO("Descriptor Read result from addr [%s] status [%d]",
3677 conn_info->addr, event_data->uuid_status.conn_status.status);
3679 /* Fill descriptor informations in buffer */
3680 memcpy(&read_info.descriptor.uuid,
3681 event_data->uuid_status.descr_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3682 read_info.descriptor.instance_id = event_data->uuid_status.descr_id.inst_id;
3684 /* Fill Characteristic informations in buffer */
3685 memcpy(&read_info.characteristic.uuid,
3686 event_data->uuid_status.char_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3687 read_info.characteristic.instance_id = event_data->uuid_status.char_id.inst_id;
3689 /* Fill Service informations in buffer */
3690 memcpy(&read_info.svc.uuid,
3691 event_data->uuid_status.srvc_id.id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3692 read_info.svc.instance_id = event_data->uuid_status.srvc_id.id.inst_id;
3694 /* Fill remote device address */
3695 _bt_convert_addr_string_to_type(read_info.device_address.addr, conn_info->addr);
3697 /* Fill data and reply to all apps waiting for Read result on the same characteristic */
3698 if (event_data->uuid_status.conn_status.status != OAL_STATUS_SUCCESS)
3699 result = BLUETOOTH_ERROR_INTERNAL;
3701 BT_INFO("desc data len:%d", event_data->data_len);
3702 if (event_data->data_len > 0) {
3704 for (i = 0; i < event_data->data_len; i++)
3705 BT_DBG("Data[%d] = [0x%x]", i, event_data->data[i]);
3708 read_val = g_memdup(&event_data->data[0], event_data->data_len);
3710 data = g_variant_new_from_data(
3711 G_VARIANT_TYPE_BYTESTRING,
3713 event_data->data_len,
3716 BT_INFO("Descriptor Read success, but no data!!!");
3718 data = g_variant_new_from_data(
3719 G_VARIANT_TYPE_BYTESTRING,
3725 svc_uuid = g_memdup(&event_data->uuid_status.srvc_id.id.uuid.uuid[0], uuid_len);
3727 data_svc_uuid = g_variant_new_from_data(
3728 G_VARIANT_TYPE_BYTESTRING,
3734 char_uuid = g_memdup(&event_data->uuid_status.char_id.uuid.uuid[0], uuid_len);
3736 data_char_uuid = g_variant_new_from_data(
3737 G_VARIANT_TYPE_BYTESTRING,
3743 desc_uuid = g_memdup(&event_data->uuid_status.descr_id.uuid.uuid[0], uuid_len);
3745 data_desc_uuid = g_variant_new_from_data(
3746 G_VARIANT_TYPE_BYTESTRING,
3751 param = g_variant_new("(isn@ayin@ayin@ayin@ay)", result,
3755 event_data->uuid_status.srvc_id.id.inst_id,
3758 event_data->uuid_status.char_id.inst_id,
3761 event_data->uuid_status.descr_id.inst_id,
3762 event_data->data_len,
3766 _bt_send_event(BT_GATT_CLIENT_EVENT,
3767 BLUETOOTH_EVENT_GATT_READ_DESC,
3770 BT_INFO("Send DBUS rpely for GATT Read Descriptor");
3771 /* Send DBUS return */
3772 __bt_gatt_handle_pending_request_info(result,
3773 BT_GATT_READ_DESCRIPTOR_VALUE,
3775 sizeof(bluetooth_gatt_client_desc_prop_info_t));
3786 static void __bt_handle_client_characteristic_write_data(
3787 event_gattc_write_data *event_data)
3789 int result = BLUETOOTH_ERROR_NONE;
3790 struct gatt_server_info_t *conn_info = NULL;
3791 bluetooth_gatt_client_char_prop_info_t write_info;
3793 /* Read Information data structures */
3794 GVariant *param = NULL;
3795 GVariant *data_svc_uuid = NULL;
3796 GVariant *data_char_uuid = NULL;
3797 char *svc_uuid = NULL;
3798 char *char_uuid = NULL;
3802 memset(&write_info, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3804 /* Extract Address from conn_id of event data */
3805 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(
3806 event_data->conn_status.conn_id);
3808 BT_INFO("Characteristic Write callback from addr [%s] status [%d]",
3809 conn_info->addr, event_data->conn_status.status);
3811 /* Fill char in buffer */
3812 memcpy(&write_info.characteristic.uuid,
3813 event_data->char_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3814 write_info.characteristic.instance_id = event_data->char_id.inst_id;
3816 /* Fill Service in buffer */
3817 memcpy(&write_info.svc.uuid,
3818 event_data->srvc_id.id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3819 write_info.svc.instance_id = event_data->srvc_id.id.inst_id;
3821 /* Fill remote device address */
3822 _bt_convert_addr_string_to_type(write_info.device_address.addr, conn_info->addr);
3824 if (event_data->conn_status.status != OAL_STATUS_SUCCESS) {
3825 result = BLUETOOTH_ERROR_INTERNAL;
3831 svc_uuid = g_memdup(&event_data->srvc_id.id.uuid.uuid[0], uuid_len);
3833 data_svc_uuid = g_variant_new_from_data(
3834 G_VARIANT_TYPE_BYTESTRING,
3840 char_uuid = g_memdup(&event_data->char_id.uuid.uuid[0], uuid_len);
3842 data_char_uuid = g_variant_new_from_data(
3843 G_VARIANT_TYPE_BYTESTRING,
3848 param = g_variant_new("(isn@ayin@ayi)", result,
3852 event_data->srvc_id.id.inst_id,
3855 event_data->char_id.inst_id);
3858 _bt_send_event(BT_GATT_CLIENT_EVENT,
3859 BLUETOOTH_EVENT_GATT_WRITE_CHAR,
3868 /* Send DBUS return */
3869 __bt_gatt_handle_pending_request_info(result,
3870 BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE,
3872 sizeof(bluetooth_gatt_client_char_prop_info_t));
3876 static void __bt_handle_client_descriptor_write_data(
3877 event_gattc_write_data *event_data)
3879 int result = BLUETOOTH_ERROR_NONE;
3880 struct gatt_server_info_t *conn_info = NULL;
3881 bluetooth_gatt_client_desc_prop_info_t write_info;
3883 /* Write Information data structures */
3884 GVariant *param = NULL;
3885 GVariant *data_svc_uuid = NULL;
3886 GVariant *data_char_uuid = NULL;
3887 GVariant *data_desc_uuid = NULL;
3888 char *svc_uuid = NULL;
3889 char *char_uuid = NULL;
3890 char *desc_uuid = NULL;
3894 memset(&write_info, 0x00, sizeof(bluetooth_gatt_client_desc_prop_info_t));
3896 /* Extract Address from conn_id of event data */
3897 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(
3898 event_data->conn_status.conn_id);
3900 if (NULL == conn_info) {
3902 BT_INFO("Failed to get the conn info for conn_id [%d]", event_data->conn_status.conn_id);
3906 BT_INFO("Descriptor Write callback from addr [%s] status [%d]",
3907 conn_info->addr, event_data->conn_status.status);
3909 /* Fill descriptor informations in buffer */
3910 memcpy(&write_info.descriptor.uuid,
3911 event_data->descr_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3912 write_info.descriptor.instance_id = event_data->descr_id.inst_id;
3914 /* Fill Characteristic informations in buffer */
3915 memcpy(&write_info.characteristic.uuid,
3916 event_data->char_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3917 write_info.characteristic.instance_id = event_data->char_id.inst_id;
3919 /* Fill Service informations in buffer */
3920 memcpy(&write_info.svc.uuid,
3921 event_data->srvc_id.id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3922 write_info.svc.instance_id = event_data->srvc_id.id.inst_id;
3924 /* Fill remote device address */
3925 _bt_convert_addr_string_to_type(write_info.device_address.addr, conn_info->addr);
3927 if (event_data->conn_status.status != OAL_STATUS_SUCCESS) {
3928 result = BLUETOOTH_ERROR_INTERNAL;
3934 svc_uuid = g_memdup(&event_data->srvc_id.id.uuid.uuid[0], uuid_len);
3936 data_svc_uuid = g_variant_new_from_data(
3937 G_VARIANT_TYPE_BYTESTRING,
3943 char_uuid = g_memdup(&event_data->char_id.uuid.uuid[0], uuid_len);
3945 data_char_uuid = g_variant_new_from_data(
3946 G_VARIANT_TYPE_BYTESTRING,
3952 desc_uuid = g_memdup(&event_data->descr_id.uuid.uuid[0], uuid_len);
3954 data_desc_uuid = g_variant_new_from_data(
3955 G_VARIANT_TYPE_BYTESTRING,
3960 param = g_variant_new("(isn@ayin@ayin@ayi)", result,
3964 event_data->srvc_id.id.inst_id,
3967 event_data->char_id.inst_id,
3970 event_data->descr_id.inst_id);
3973 _bt_send_event(BT_GATT_CLIENT_EVENT,
3974 BLUETOOTH_EVENT_GATT_WRITE_DESC,
3985 /* Send DBUS return */
3986 __bt_gatt_handle_pending_request_info(result,
3987 BT_GATT_WRITE_DESCRIPTOR_VALUE,
3989 sizeof(bluetooth_gatt_client_desc_prop_info_t));
3992 static void __bt_hanlde_le_device_disconnection(event_dev_conn_status_t *event_data)
3994 int result = BLUETOOTH_ERROR_INTERNAL;
3995 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
3997 _bt_convert_addr_type_to_string(address, (unsigned char *)event_data->address.addr);
3999 /* DBUS Return with fail of pending BT_CONNECT_LE for all the apps */
4000 BT_INFO("Local GATT Client disconnected: Remote addr[%s] ", address);
4002 __bt_gatt_handle_pending_request_info(result, BT_CONNECT_LE, address,
4003 BT_ADDRESS_STRING_SIZE);
4007 static void __bt_handle_client_notification_registered(
4008 event_gattc_regdereg_notify_t *event_data,
4009 gboolean is_registered)
4011 int result = BLUETOOTH_ERROR_NONE;
4012 struct gatt_server_info_t *conn_info = NULL;
4013 bt_gatt_notif_reg_info_t notif_info;
4016 memset(¬if_info, 0x00, sizeof(bt_gatt_notif_reg_info_t));
4018 BT_INFO("Client Interface [%d] status [%d]",
4019 event_data->client_if,
4020 event_data->status);
4022 /* Extract Address from conn_id of event data */
4023 conn_info = __bt_find_remote_gatt_server_info_from_client_if(
4024 event_data->client_if);
4027 BT_INFO("Connection Info is not present, return");
4030 BT_INFO("Notification Registered for addr [%s]",
4034 /* Fill svc informations in buffer */
4035 memcpy(¬if_info.svc_uuid,
4036 event_data->srvc_id.id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4037 notif_info.svc_inst = event_data->srvc_id.id.inst_id;
4039 /* Fill char in buffer */
4040 memcpy(¬if_info.char_uuid,
4041 event_data->char_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4042 notif_info.char_inst = event_data->char_id.inst_id;
4044 /* Fill remote device address */
4045 _bt_convert_addr_string_to_type(notif_info.addr.addr, conn_info->addr);
4047 notif_info.is_registered = is_registered;
4049 if (event_data->status != OAL_STATUS_SUCCESS)
4050 result = BLUETOOTH_ERROR_INTERNAL;
4052 /* Send DBUS Return for BT_GATT_WATCH_CHARACTERISTIC */
4053 __bt_gatt_handle_pending_request_info(result,
4054 BT_GATT_WATCH_CHARACTERISTIC,
4056 sizeof(bt_gatt_notif_reg_info_t));
4059 static void __bt_handle_client_notification_data(event_gattc_notify_data *event_data)
4061 /* No status in this event from OAL */
4062 int result = BLUETOOTH_ERROR_NONE;
4064 /* Read Information data structures */
4065 GVariant *param = NULL;
4066 GVariant *data = NULL;
4067 GVariant *data_svc_uuid = NULL;
4068 GVariant *data_char_uuid = NULL;
4069 char *read_val = NULL;
4070 char *svc_uuid = NULL;
4071 char *char_uuid = NULL;
4077 BT_INFO("Notifcation of charc data changed");
4079 if (event_data->data_len > 0) {
4081 for (i = 0; i < event_data->data_len; i++)
4082 BT_INFO("Data[%d] = [0x%x]", i, event_data->data[i]);
4085 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
4086 _bt_convert_addr_type_to_string(addr,
4087 (unsigned char *)&(event_data->address.addr));
4090 read_val = g_memdup(&event_data->data[0], event_data->data_len);
4092 data = g_variant_new_from_data(
4093 G_VARIANT_TYPE_BYTESTRING,
4095 event_data->data_len,
4098 svc_uuid = g_memdup(&event_data->srvc_id.id.uuid.uuid[0], uuid_len);
4100 data_svc_uuid = g_variant_new_from_data(
4101 G_VARIANT_TYPE_BYTESTRING,
4107 char_uuid = g_memdup(&event_data->char_id.uuid.uuid[0], uuid_len);
4109 data_char_uuid = g_variant_new_from_data(
4110 G_VARIANT_TYPE_BYTESTRING,
4116 param = g_variant_new("(isn@ayin@ayin@ay)", result,
4120 event_data->srvc_id.id.inst_id,
4123 event_data->char_id.inst_id,
4124 event_data->data_len,
4128 _bt_send_event(BT_GATT_CLIENT_EVENT,
4129 BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED,
4132 BT_ERR("No Data!!");
4145 static void __bt_handle_client_service_changed_ind(event_gattc_service_changed_data *event_data)
4147 bt_gatt_service_info_list_t *svc_info_list;
4149 bt_gatt_service_info_t *svc_info;
4150 GVariant *param = NULL;
4151 char *address_str = NULL;
4152 char *uuid_str = NULL;
4154 svc_info_list = __bt_get_service_info_list(event_data->conn_id);
4155 if (svc_info_list == NULL) {
4156 BT_ERR("svc_info_list is NULL");
4160 if (event_data->change_type) {
4161 /* Add service UUID in list */
4162 svc_info = g_malloc0(sizeof(bt_gatt_service_info_t));
4163 memcpy(svc_info->uuid, event_data->uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4164 svc_info->inst_id = event_data->inst_id;
4165 svc_info->is_primary = 1; // TODO: Need to check is_primary is required or not
4166 svc_info_list->services = g_slist_append(svc_info_list->services, svc_info);
4167 BT_DBG("Service created and added in Svc info list or connection ID %d", event_data->conn_id);
4169 /* Remove service UUID in list */
4170 for (l = svc_info_list->services; l != NULL; l = g_slist_next(l)) {
4171 svc_info = (bt_gatt_service_info_t *)l->data;
4172 if (svc_info == NULL)
4175 if (!memcmp(svc_info->uuid, event_data->uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN)) {
4176 svc_info_list->services = g_slist_remove(svc_info_list->services, svc_info);
4177 __bt_free_service_info(svc_info);
4183 address_str = g_malloc0(BT_ADDRESS_STRING_SIZE);
4184 uuid_str = g_malloc0(BT_UUID_STRING_MAX);
4185 _bt_convert_addr_type_to_string(address_str, event_data->address.addr);
4186 _bt_uuid_to_string(&event_data->uuid, uuid_str);
4188 param = g_variant_new("(iiss)", event_data->inst_id, event_data->change_type, address_str, uuid_str);
4190 _bt_send_event(BT_GATT_CLIENT_EVENT,
4191 BLUETOOTH_EVENT_GATT_CLIENT_SERVICE_CHANGED,
4193 g_free(address_str);
4197 gboolean _bt_is_remote_gatt_device_connected(bluetooth_device_address_t *address)
4200 struct gatt_server_info_t *conn_info = NULL;
4201 gboolean connected = FALSE;
4203 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
4204 _bt_convert_addr_type_to_string(addr,
4205 (unsigned char *)&(address->addr));
4207 BT_DBG("Check GATT connection status of [%s]", addr);
4208 /* Check if device is already in connected list */
4209 conn_info = _bt_find_remote_gatt_server_info(addr);
4212 BT_DBG("Remote GATT Server device [%s] is Connected", conn_info->addr);
4215 struct gatt_client_info_t *client_info = NULL;
4217 BT_INFO("Remote GATT Server Device [%s] is not Connected", addr);
4219 /* Check if device is already in connected list */
4220 client_info = _bt_find_remote_gatt_client_info(addr);
4223 BT_DBG("Remote Client device [%s] is Connected", client_info->addr);
4226 BT_INFO("Remote GATT Client Device [%s] is not Connected", addr);
4235 int _bt_connect_le_device(bluetooth_device_address_t *address,
4236 int auto_connect, int client_id)
4238 struct gatt_server_info_t *conn_info = NULL;
4239 struct gatt_out_conn_info_t *out_conn_info = NULL;
4241 invocation_info_t *req_info = NULL;
4242 int ret = OAL_STATUS_SUCCESS;
4244 char *remote_address = NULL;
4246 BT_CHECK_PARAMETER(address, return);
4248 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4249 _bt_convert_addr_type_to_string(addr, address->addr);
4250 BT_DBG("GATT Client connect request for address [%s] client instance [%d]",
4254 /* Check if Remote Device is already under connection progress */
4255 req_info = _bt_get_request_info_data_from_function_name(BT_CONNECT_LE);
4257 remote_address = (char*)req_info->user_data;
4258 if (remote_address && !strcasecmp(remote_address, addr)) {/* Address matched */
4259 BT_DBG("Already Connection ongoing for same remote GATT Server address [%s]", remote_address);
4260 /* Return and wait for events to be sent to all apps */
4262 return BLUETOOTH_ERROR_IN_PROGRESS;
4266 /* Check if remote GATT Server is connected or not */
4267 conn_info = _bt_find_remote_gatt_server_info(addr);
4269 BT_ERR("GATT Server is already connected..");
4271 return BLUETOOTH_ERROR_ALREADY_CONNECT;
4274 /* TODO Check Requirement of holding Advertisement before initiating LE connect */
4276 /* Check if app sent 0 client id for connection, in such case, use default gatt client ID */
4277 if (client_id == 0) {
4278 /* GATT CLient connect request sent by an app without any client instance [0] */
4279 BT_DBG("Assign default GATT client id [%d]", gatt_default_client);
4280 client_id = gatt_default_client;
4283 BT_INFO("Connect using CLient ID [%d]", client_id);
4284 ret = gattc_connect(client_id, (bt_address_t*)(address), auto_connect);
4286 if (ret != OAL_STATUS_SUCCESS) {
4287 BT_ERR("gattc_connect is failed. ret: %d", ret);
4289 return BLUETOOTH_ERROR_INTERNAL;
4292 /* Mark this as outgoing connection */
4293 out_conn_info = g_new0(struct gatt_out_conn_info_t, 1);
4294 out_conn_info->addr = g_strdup(addr);
4295 out_conn_info->client_id = client_id;
4296 BT_INFO("Added outgoing connection info addr[%s]", out_conn_info->addr);
4297 outgoing_gatt_conn_list = g_slist_append(outgoing_gatt_conn_list, out_conn_info);
4300 return BLUETOOTH_ERROR_NONE;
4303 int _bt_gatt_get_primary_services(char *address)
4305 BT_CHECK_PARAMETER(address, return);
4306 struct gatt_server_info_t *conn_info = NULL;
4307 invocation_info_t *req_info = NULL;
4308 int ret = OAL_STATUS_SUCCESS;
4311 /* Check if any app is already browsing primary services on the same remote GATT Server */
4312 req_info = _bt_get_request_info_data(BT_GATT_GET_PRIMARY_SERVICES, address);
4314 BT_INFO("Already Primary Service Browsing ongoing for same rmeote GATT Server");
4315 /* Return and wait for events to be sent to all apps */
4316 return BLUETOOTH_ERROR_NONE;
4319 /* Check if remote GATT Server is connected or not */
4320 conn_info = _bt_find_remote_gatt_server_info(address);
4322 BT_INFO("GATT Server [%s] is connected, conn Id [%d]",
4323 conn_info->addr, conn_info->connection_id);
4325 BT_ERR("GATT Server is not yet connected..");
4326 return BLUETOOTH_ERROR_NOT_CONNECTED;
4329 BT_INFO("Remove GATT server info from List..");
4330 /* Remove all services from info list_gatt_info */
4331 __bt_cleanup_remote_services(conn_info);
4333 /* Send Primary Service Browsing request to stack */
4334 ret = gattc_search_service(conn_info->connection_id, NULL);
4335 if (ret != OAL_STATUS_SUCCESS) {
4336 BT_ERR("ret: %d", ret);
4337 return BLUETOOTH_ERROR_INTERNAL;
4339 return BLUETOOTH_ERROR_NONE;
4342 int _bt_gatt_get_all_characteristic(bluetooth_gatt_client_svc_prop_info_t *svc)
4344 BT_CHECK_PARAMETER(svc, return);
4345 struct gatt_server_info_t *conn_info = NULL;
4346 invocation_info_t *req_info = NULL;
4347 bluetooth_gatt_client_svc_prop_info_t *prop;
4348 oal_gatt_srvc_id_t srvc_id;
4349 int ret = OAL_STATUS_SUCCESS;
4352 /* Check if any app is already browsing characteristics of the same service on the same remote GATT Server */
4353 req_info = _bt_get_request_info_data_from_function_name(BT_GATT_GET_SERVICE_PROPERTIES);
4355 prop = (bluetooth_gatt_client_svc_prop_info_t*)req_info->user_data;
4356 if (prop && !memcmp(svc->device_address.addr, prop->device_address.addr, sizeof(bluetooth_device_address_t))
4357 && memcmp(prop->svc.uuid, svc->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN)
4358 && prop->svc.instance_id == svc->svc.instance_id) {
4359 BT_INFO("Already Properties browsing for Primary Service ongoing for same remote GATT Server");
4360 /* Return and wait for events to be sent to all apps */
4361 return BLUETOOTH_ERROR_NONE;
4365 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4366 _bt_convert_addr_type_to_string(addr, svc->device_address.addr);
4368 /* Check if remote GATT Server is connected or not */
4369 conn_info = _bt_find_remote_gatt_server_info(addr);
4371 BT_DBG("GATT Server [%s] is connected, conn Id [%d]",
4372 conn_info->addr, conn_info->connection_id);
4374 BT_ERR("GATT Server is not yet connected..");
4376 return BLUETOOTH_ERROR_NOT_CONNECTED;
4379 srvc_id.is_prmry = TRUE;
4380 srvc_id.id.inst_id = svc->svc.instance_id;
4381 memcpy(srvc_id.id.uuid.uuid, svc->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4383 /* Search All Characteristic */
4384 ret = gattc_get_characteristic(conn_info->connection_id, &srvc_id, NULL);
4385 if (ret != OAL_STATUS_SUCCESS) {
4386 BT_ERR("ret: %d", ret);
4388 return BLUETOOTH_ERROR_INTERNAL;
4391 return BLUETOOTH_ERROR_NONE;
4394 int _bt_gatt_get_all_characteristic_properties(
4395 bluetooth_gatt_client_char_prop_info_t *chr)
4397 struct gatt_server_info_t *conn_info = NULL;
4398 invocation_info_t *req_info = NULL;
4399 bluetooth_gatt_client_char_prop_info_t *prop;
4400 oal_gatt_srvc_id_t srvc_id;
4401 oal_gatt_id_t char_id;
4402 int ret = OAL_STATUS_SUCCESS;
4405 BT_CHECK_PARAMETER(chr, return);
4407 /* Check if any app is already browsing descriptors of the same char of
4408 particular service on the same remote GATT Server */
4409 req_info = _bt_get_request_info_data_from_function_name(BT_GATT_GET_CHARACTERISTIC_PROPERTIES);
4411 prop = (bluetooth_gatt_client_char_prop_info_t*)req_info->user_data;
4412 if (prop && !memcmp(chr->device_address.addr, prop->device_address.addr, sizeof(bluetooth_device_address_t)) /* Address matched */
4413 && memcmp(chr->svc.uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Service UUID matched */
4414 && chr->svc.instance_id == prop->svc.instance_id /* Service Instance ID matched */
4415 && memcmp(chr->characteristic.uuid, prop->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Characteristic UUID matched */
4416 && chr->characteristic.instance_id == prop->characteristic.instance_id) { /* Characteristic Instance ID matched */
4417 BT_INFO("Already Properties browsing for Characteristic ongoing for same remote GATT Server");
4418 /* Return and wait for events to be sent to all apps */
4419 return BLUETOOTH_ERROR_NONE;
4423 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4424 _bt_convert_addr_type_to_string(addr, chr->device_address.addr);
4426 /* Check if remote GATT Server is connected or not */
4427 conn_info = _bt_find_remote_gatt_server_info(addr);
4429 BT_DBG("GATT Server [%s] is connected, conn Id [%d]",
4430 conn_info->addr, conn_info->connection_id);
4432 BT_ERR("GATT Server is not yet connected..");
4434 return BLUETOOTH_ERROR_NOT_CONNECTED;
4437 srvc_id.is_prmry = TRUE;
4438 srvc_id.id.inst_id = chr->svc.instance_id;
4439 memcpy(srvc_id.id.uuid.uuid, chr->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4441 char_id.inst_id = chr->characteristic.instance_id;
4442 memcpy(char_id.uuid.uuid, chr->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4444 /* Search All Descriptors */
4445 ret = gattc_get_descriptor(conn_info->connection_id, &srvc_id, &char_id, NULL);
4446 if (ret != OAL_STATUS_SUCCESS) {
4447 BT_ERR("ret: %d", ret);
4449 return BLUETOOTH_ERROR_INTERNAL;
4452 return BLUETOOTH_ERROR_NONE;
4455 int _bt_gatt_read_characteristic_value(
4456 bluetooth_gatt_client_char_prop_info_t *chr)
4458 struct gatt_server_info_t *conn_info = NULL;
4459 invocation_info_t *req_info = NULL;
4460 bluetooth_gatt_client_char_prop_info_t *prop;
4461 oal_gatt_srvc_id_t srvc_id;
4462 oal_gatt_id_t char_id;
4463 int ret = OAL_STATUS_SUCCESS;
4466 BT_CHECK_PARAMETER(chr, return);
4468 /* Check if any app is already Reading characteristic of the same char of
4469 particular service on the same remote GATT Server */
4470 req_info = _bt_get_request_info_data_from_function_name(BT_GATT_READ_CHARACTERISTIC);
4472 prop = (bluetooth_gatt_client_char_prop_info_t*)req_info->user_data;
4473 if (prop && !memcmp(chr->device_address.addr, prop->device_address.addr, sizeof(bluetooth_device_address_t)) /* Address matched */
4474 && memcmp(chr->svc.uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Service UUID matched */
4475 && chr->svc.instance_id == prop->svc.instance_id /* Service Instance ID matched */
4476 && memcmp(chr->characteristic.uuid, prop->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Characteristic UUID matched */
4477 && chr->characteristic.instance_id == prop->characteristic.instance_id) { /* Characteristic Instance ID matched */
4478 BT_INFO("Already Characteristic value Read operation in progress for same remote GATT Server");
4479 /* Return and wait for events to be sent to all apps */
4480 return BLUETOOTH_ERROR_NONE;
4484 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4485 _bt_convert_addr_type_to_string(addr, chr->device_address.addr);
4487 /* Check if remote GATT Server is connected or not */
4488 conn_info = _bt_find_remote_gatt_server_info(addr);
4490 BT_DBG("GATT Server [%s] is connected, conn Id [%d]",
4491 conn_info->addr, conn_info->connection_id);
4493 BT_ERR("GATT Server is not yet connected..");
4495 return BLUETOOTH_ERROR_NOT_CONNECTED;
4498 srvc_id.is_prmry = TRUE;
4499 srvc_id.id.inst_id = chr->svc.instance_id;
4500 memcpy(srvc_id.id.uuid.uuid, chr->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4502 char_id.inst_id = chr->characteristic.instance_id;
4503 memcpy(char_id.uuid.uuid, chr->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4505 /* Search All Descriptors */
4506 ret = gattc_read_characteristic(conn_info->connection_id, &srvc_id, &char_id, OAL_GATT_AUTH_REQ_NONE);
4507 if (ret != OAL_STATUS_SUCCESS) {
4508 BT_ERR("ret: %d", ret);
4510 return BLUETOOTH_ERROR_INTERNAL;
4513 return BLUETOOTH_ERROR_NONE;
4516 int _bt_gatt_read_descriptor_value(
4517 bluetooth_gatt_client_desc_prop_info_t *desc)
4519 struct gatt_server_info_t *conn_info = NULL;
4520 invocation_info_t *req_info = NULL;
4521 bluetooth_gatt_client_desc_prop_info_t *prop;
4522 oal_gatt_srvc_id_t srvc_id;
4523 oal_gatt_id_t char_id;
4524 oal_gatt_id_t desc_id;
4525 int ret = OAL_STATUS_SUCCESS;
4528 BT_CHECK_PARAMETER(desc, return);
4530 /* Check if any app is already Reading descriptors of the same char of
4531 particular service on the same remote GATT Server */
4532 req_info = _bt_get_request_info_data_from_function_name(BT_GATT_READ_DESCRIPTOR_VALUE);
4534 prop = (bluetooth_gatt_client_desc_prop_info_t*)req_info->user_data;
4535 if (prop && !memcmp(desc->device_address.addr, prop->device_address.addr, sizeof(bluetooth_device_address_t)) /* Address matched */
4536 && memcmp(desc->svc.uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Service UUID matched */
4537 && desc->svc.instance_id == prop->svc.instance_id /* Service Instance ID matched */
4538 && memcmp(desc->characteristic.uuid, prop->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Characteristic UUID matched */
4539 && desc->characteristic.instance_id == prop->characteristic.instance_id /* Characteristic Instance ID matched */
4540 && memcmp(desc->descriptor.uuid, prop->descriptor.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Descriptor UUID matched */
4541 && desc->descriptor.instance_id == prop->descriptor.instance_id) { /* Descriptor Instance ID matched */
4542 BT_INFO("Already Descriptor value Read operation in progress for same remote GATT Server");
4543 /* Return and wait for events to be sent to all apps */
4544 return BLUETOOTH_ERROR_NONE;
4548 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4549 _bt_convert_addr_type_to_string(addr, desc->device_address.addr);
4551 /* Check if remote GATT Server is connected or not */
4552 conn_info = _bt_find_remote_gatt_server_info(addr);
4554 BT_DBG("GATT Server [%s] is connected, conn Id [%d]",
4555 conn_info->addr, conn_info->connection_id);
4557 BT_ERR("GATT Server is not yet connected..");
4559 return BLUETOOTH_ERROR_NOT_CONNECTED;
4562 srvc_id.is_prmry = TRUE;
4563 srvc_id.id.inst_id = desc->svc.instance_id;
4564 memcpy(srvc_id.id.uuid.uuid, desc->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4566 char_id.inst_id = desc->characteristic.instance_id;
4567 memcpy(char_id.uuid.uuid, desc->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4569 desc_id.inst_id = desc->descriptor.instance_id;
4570 memcpy(desc_id.uuid.uuid, desc->descriptor.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4572 /* Search All Descriptors */
4573 ret = gattc_read_descriptor(conn_info->connection_id, &srvc_id, &char_id,
4574 &desc_id, OAL_GATT_AUTH_REQ_NONE);
4575 if (ret != OAL_STATUS_SUCCESS) {
4576 BT_ERR("ret: %d", ret);
4578 return BLUETOOTH_ERROR_INTERNAL;
4581 return BLUETOOTH_ERROR_NONE;
4585 int _bt_gatt_acquire_notify(bluetooth_gatt_client_char_prop_info_t *chr, int *fd, int *mtu)
4587 struct gatt_server_info_t *conn_info = NULL;
4588 oal_gatt_srvc_id_t srvc_id;
4589 oal_gatt_id_t char_id;
4590 int ret = OAL_STATUS_SUCCESS;
4593 BT_CHECK_PARAMETER(chr, return);
4595 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4596 _bt_convert_addr_type_to_string(addr, chr->device_address.addr);
4598 /* Check if remote GATT Server is connected or not */
4599 conn_info = _bt_find_remote_gatt_server_info(addr);
4601 BT_DBG("GATT Server [%s] is connected, conn Id [%d]",
4602 conn_info->addr, conn_info->connection_id);
4604 BT_ERR("GATT Server is not yet connected..");
4606 return BLUETOOTH_ERROR_NOT_CONNECTED;
4609 srvc_id.is_prmry = TRUE;
4610 srvc_id.id.inst_id = chr->svc.instance_id;
4611 memcpy(srvc_id.id.uuid.uuid, chr->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4613 char_id.inst_id = chr->characteristic.instance_id;
4614 memcpy(char_id.uuid.uuid, chr->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4616 ret = gattc_acquire_notify(conn_info->connection_id, &srvc_id, &char_id, fd, mtu);
4618 if (ret != OAL_STATUS_SUCCESS) {
4619 BT_ERR("ret: %d", ret);
4621 return BLUETOOTH_ERROR_INTERNAL;
4623 BT_INFO("GATT characterstics FD [%d] mtu[%d]", *fd, *mtu);
4625 return BLUETOOTH_ERROR_NONE;
4629 int _bt_gatt_acquire_write(bluetooth_gatt_client_char_prop_info_t *chr, int *fd, int *mtu)
4632 struct gatt_server_info_t *conn_info = NULL;
4633 oal_gatt_srvc_id_t srvc_id;
4634 oal_gatt_id_t char_id;
4635 int ret = OAL_STATUS_SUCCESS;
4638 BT_CHECK_PARAMETER(chr, return);
4640 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4641 _bt_convert_addr_type_to_string(addr, chr->device_address.addr);
4643 /* Check if remote GATT Server is connected or not */
4644 conn_info = _bt_find_remote_gatt_server_info(addr);
4646 BT_DBG("GATT Server [%s] is connected, conn Id [%d]",
4647 conn_info->addr, conn_info->connection_id);
4649 BT_ERR("GATT Server is not yet connected..");
4651 return BLUETOOTH_ERROR_NOT_CONNECTED;
4654 srvc_id.is_prmry = TRUE;
4655 srvc_id.id.inst_id = chr->svc.instance_id;
4656 memcpy(srvc_id.id.uuid.uuid, chr->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4658 char_id.inst_id = chr->characteristic.instance_id;
4659 memcpy(char_id.uuid.uuid, chr->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4661 ret = gattc_acquire_write(conn_info->connection_id, &srvc_id, &char_id,
4662 OAL_GATT_AUTH_REQ_NONE, fd, mtu);
4663 if (ret != OAL_STATUS_SUCCESS) {
4664 BT_ERR("ret: %d", ret);
4666 return BLUETOOTH_ERROR_INTERNAL;
4668 BT_INFO("GATT characterstics FD [%d] mtu [%d]", *fd, *mtu);
4670 return BLUETOOTH_ERROR_NONE;
4675 /* Write Characteristic */
4676 int _bt_gatt_write_characteristic_value_by_type(
4677 bluetooth_gatt_client_char_prop_info_t *chr,
4678 bluetooth_gatt_att_data_t *data,
4679 bluetooth_gatt_write_type_e write_type)
4681 struct gatt_server_info_t *conn_info = NULL;
4682 invocation_info_t *req_info = NULL;
4683 bluetooth_gatt_client_char_prop_info_t *prop;
4684 oal_gatt_srvc_id_t srvc_id;
4685 oal_gatt_id_t char_id;
4686 int ret = OAL_STATUS_SUCCESS;
4690 BT_CHECK_PARAMETER(chr, return);
4691 BT_CHECK_PARAMETER(data, return);
4695 /* Check if any app is already writing same char of
4696 particular service on the same remote GATT Server */
4697 req_info = _bt_get_request_info_data_from_function_name(BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE);
4699 prop = (bluetooth_gatt_client_char_prop_info_t*)req_info->user_data;
4700 if (prop && !memcmp(chr->device_address.addr, prop->device_address.addr, sizeof(bluetooth_device_address_t)) /* Address matched */
4701 && memcmp(chr->svc.uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Service UUID matched */
4702 && chr->svc.instance_id == prop->svc.instance_id /* Service Instance ID matched */
4703 && memcmp(chr->characteristic.uuid, prop->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Characteristic UUID matched */
4704 && chr->characteristic.instance_id == prop->characteristic.instance_id) { /* Characteristic Instance ID matched */
4705 BT_INFO("Already Characteristic Write Value operation in progress for same remote GATT Server");
4706 /* Return and wait for events to be sent to all apps */
4707 return BLUETOOTH_ERROR_NONE;
4711 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4712 _bt_convert_addr_type_to_string(addr, chr->device_address.addr);
4714 /* Check if remote GATT Server is connected or not */
4715 conn_info = _bt_find_remote_gatt_server_info(addr);
4717 BT_INFO("GATT Server [%s] is connected, conn Id [%d]",
4718 conn_info->addr, conn_info->connection_id);
4720 BT_ERR("GATT Server is not yet connected..");
4722 return BLUETOOTH_ERROR_NOT_CONNECTED;
4725 srvc_id.is_prmry = TRUE;
4726 srvc_id.id.inst_id = chr->svc.instance_id;
4727 memcpy(srvc_id.id.uuid.uuid, chr->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4729 char_id.inst_id = chr->characteristic.instance_id;
4730 memcpy(char_id.uuid.uuid, chr->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4732 /* Write CHar value */
4734 BT_INFO("Connection ID [%d] write type [%d] data length [%d]", conn_info->connection_id, write_type, data->length);
4735 for (k = 0; k < data->length; k++)
4736 BT_INFO("Data[%d] [0x%x]", k, data->data[k]);
4738 ret = gattc_write_characteristic(conn_info->connection_id,
4740 (oal_gatt_write_type_t)write_type, data->length,
4741 OAL_GATT_AUTH_REQ_NONE, (char *)(&data->data[0]));
4742 if (ret != OAL_STATUS_SUCCESS) {
4743 BT_ERR("ret: %d", ret);
4745 return BLUETOOTH_ERROR_INTERNAL;
4748 return BLUETOOTH_ERROR_NONE;
4751 /* Write Descriptor */
4752 int _bt_gatt_write_descriptor_value_by_type(
4753 bluetooth_gatt_client_desc_prop_info_t *desc,
4754 bluetooth_gatt_att_data_t *data,
4755 bluetooth_gatt_write_type_e write_type)
4757 struct gatt_server_info_t *conn_info = NULL;
4758 invocation_info_t *req_info = NULL;
4759 bluetooth_gatt_client_desc_prop_info_t *prop;
4760 oal_gatt_srvc_id_t srvc_id;
4761 oal_gatt_id_t char_id;
4762 oal_gatt_id_t desc_id;
4763 int ret = OAL_STATUS_SUCCESS;
4767 BT_CHECK_PARAMETER(desc, return);
4768 BT_CHECK_PARAMETER(data, return);
4772 /* Check if any app is already writing on same Descriptor of the same char of
4773 particular service on the same remote GATT Server */
4774 req_info = _bt_get_request_info_data_from_function_name(BT_GATT_WRITE_DESCRIPTOR_VALUE);
4776 prop = (bluetooth_gatt_client_desc_prop_info_t*)req_info->user_data;
4777 if (prop && !memcmp(desc->device_address.addr, prop->device_address.addr, sizeof(bluetooth_device_address_t)) /* Address matched */
4778 && memcmp(desc->svc.uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Service UUID matched */
4779 && desc->svc.instance_id == prop->svc.instance_id /* Service Instance ID matched */
4780 && memcmp(desc->characteristic.uuid, prop->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Characteristic UUID matched */
4781 && desc->characteristic.instance_id == prop->characteristic.instance_id /* Characteristic Instance ID matched */
4782 && memcmp(desc->descriptor.uuid, prop->descriptor.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Descriptor UUID matched */
4783 && desc->descriptor.instance_id == prop->descriptor.instance_id) { /* Descriptor Instance ID matched */
4784 BT_INFO("Already Descriptor value Write operation in progress for same remote GATT Server");
4785 /* Return and wait for events to be sent to all apps */
4786 return BLUETOOTH_ERROR_NONE;
4790 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4791 _bt_convert_addr_type_to_string(addr, desc->device_address.addr);
4793 /* Check if remote GATT Server is connected or not */
4794 conn_info = _bt_find_remote_gatt_server_info(addr);
4796 BT_INFO("GATT Server [%s] is connected, conn Id [%d]",
4797 conn_info->addr, conn_info->connection_id);
4799 BT_ERR("GATT Server is not yet connected..");
4801 return BLUETOOTH_ERROR_NOT_CONNECTED;
4804 srvc_id.is_prmry = TRUE;
4805 srvc_id.id.inst_id = desc->svc.instance_id;
4806 memcpy(srvc_id.id.uuid.uuid, desc->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4808 char_id.inst_id = desc->characteristic.instance_id;
4809 memcpy(char_id.uuid.uuid, desc->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4811 desc_id.inst_id = desc->descriptor.instance_id;
4812 memcpy(desc_id.uuid.uuid, desc->descriptor.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4815 BT_INFO("Connection ID [%d] write type [%d] data length [%d]", conn_info->connection_id, write_type, data->length);
4816 for (k = 0; k < data->length; k++)
4817 BT_INFO("Data[%d] [0x%x]", k, data->data[k]);
4819 ret = gattc_write_descriptor(conn_info->connection_id,
4820 &srvc_id, &char_id, &desc_id,
4821 (oal_gatt_write_type_t)write_type, data->length,
4822 OAL_GATT_AUTH_REQ_NONE, (char *)(&data->data[0]));
4823 if (ret != OAL_STATUS_SUCCESS) {
4824 BT_ERR("ret: %d", ret);
4826 return BLUETOOTH_ERROR_INTERNAL;
4829 return BLUETOOTH_ERROR_NONE;
4832 int _bt_gatt_watch_characteristic(
4833 bluetooth_gatt_client_char_prop_info_t *chr,
4837 struct gatt_server_info_t *conn_info = NULL;
4838 oal_gatt_srvc_id_t srvc_id;
4839 oal_gatt_id_t char_id;
4840 int ret = OAL_STATUS_SUCCESS;
4843 BT_CHECK_PARAMETER(chr, return);
4845 BT_INFO("Client ID [%d] Is Notify [%d]", client_id, is_notify);
4847 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4848 _bt_convert_addr_type_to_string(addr, chr->device_address.addr);
4850 /* Check if remote GATT Server is connected or not */
4851 conn_info = _bt_find_remote_gatt_server_info(addr);
4853 BT_INFO("GATT Server [%s] is connected, conn Id [%d]",
4854 conn_info->addr, conn_info->connection_id);
4856 BT_ERR("GATT Server is not yet connected..");
4858 return BLUETOOTH_ERROR_NOT_CONNECTED;
4860 srvc_id.is_prmry = TRUE;
4861 srvc_id.id.inst_id = chr->svc.instance_id;
4862 memcpy(srvc_id.id.uuid.uuid, chr->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4864 char_id.inst_id = chr->characteristic.instance_id;
4865 memcpy(char_id.uuid.uuid, chr->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4867 /* Register or unregister Notification characteristic */
4869 ret = gattc_register_for_notification(conn_info->client_id,
4870 (bt_address_t*)&(chr->device_address),
4871 &srvc_id, &char_id);
4873 ret = gattc_deregister_for_notification(conn_info->client_id,
4874 (bt_address_t*)&(chr->device_address),
4875 &srvc_id, &char_id);
4877 BT_INFO("Result[%d]", ret);
4878 if (ret != OAL_STATUS_SUCCESS) {
4879 BT_ERR("ret: %d", ret);
4881 return BLUETOOTH_ERROR_INTERNAL;
4884 return BLUETOOTH_ERROR_NONE;
4888 int _bt_disconnect_le_device(bluetooth_device_address_t *address,
4891 struct gatt_server_info_t *conn_info = NULL;
4892 struct gatt_client_info_t *rem_client_conn_info = NULL;
4893 invocation_info_t *req_info = NULL;
4894 int ret = OAL_STATUS_SUCCESS;
4896 char *remote_address = NULL;
4898 BT_CHECK_PARAMETER(address, return);
4900 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4901 _bt_convert_addr_type_to_string(addr, address->addr);
4902 BT_INFO("GATT Client Disconnect request for address [%s]", addr);
4904 /* Check if Remote Device is already under connection progress */
4905 req_info = _bt_get_request_info_data_from_function_name(BT_DISCONNECT_LE);
4907 remote_address = (char*)req_info->user_data;
4908 if (remote_address && !strcasecmp(remote_address, addr)) {/* Address matched */
4909 BT_DBG("Already DisConnection ongoing for same remote GATT Server address [%s]", remote_address);
4910 /* Return success and wait for events to be sent to all apps */
4912 return BLUETOOTH_ERROR_IN_PROGRESS;
4915 /* Check if remote GATT Server is connected or not */
4916 conn_info = _bt_find_remote_gatt_server_info(addr);
4918 /* Check if app sent 0 client id for Disconnection, in such case, use default gatt client ID */
4919 if (client_id == 0) {
4920 BT_INFO("GATT CLient Disconnect request sent by an app without any client instance [%d]",
4922 BT_INFO("Assign default GATT client id [%d]", gatt_default_client);
4923 client_id = gatt_default_client;
4926 BT_INFO("Disconnect remote gatt server using CLient ID [%d] Connection ID [%d]", client_id, conn_info->connection_id);
4927 ret = gattc_disconnect(client_id, (bt_address_t*)(address),
4928 conn_info->connection_id);
4930 /* check if remote client is connected */
4931 rem_client_conn_info = _bt_find_remote_gatt_client_info(addr);
4933 if (!rem_client_conn_info || client_id != 0) {
4934 BT_ERR("GATT device is not connected..");
4936 return BLUETOOTH_ERROR_NOT_IN_OPERATION;
4939 BT_INFO("Disconnect remote gatt client ");
4941 ret = gatts_disconnect(rem_client_conn_info->instance_id,
4942 (bt_address_t*)(address), rem_client_conn_info->connection_id);
4945 if (ret != OAL_STATUS_SUCCESS) {
4946 BT_ERR("ret: %d", ret);
4948 return BLUETOOTH_ERROR_INTERNAL;
4951 return BLUETOOTH_ERROR_NONE;
4954 int _bt_gatt_watch_service_changed_indication(const char *sender,
4955 bluetooth_device_address_t *address,
4956 gboolean is_enabled)
4959 bt_service_app_info_t *info = NULL;
4961 BT_INFO("%s Servic changed Indication watcher for app [%s]",
4962 is_enabled ? "Enable":"Disable", sender);
4964 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
4967 if (g_strcmp0(sender, info->sender) == 0 &&
4968 memcmp(info->address.addr, address->addr,
4969 sizeof(bluetooth_device_address_t)) == 0) {
4970 BT_DBG("Found GATT client App.. [%s], sender [%s]", info->uuid, info->sender);
4971 info->is_watcher_enabled = is_enabled;
4975 return BLUETOOTH_ERROR_NONE;
4978 int _bt_unregister_gatt_client_instance(const char *sender, int client_id)
4980 bt_service_app_info_t *info = NULL;
4983 BT_INFO("Unregister Allocated GATT Client instance [%s] Client ID [%d]", sender, client_id);
4985 /* Unregister CLient instance associated with address X. It is possible that another app still
4986 has client_id valid for same remote address */
4987 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
4990 /* Exact matching of sender */
4991 if (!g_strcmp0(info->sender, sender) && info->client_id == client_id) { /* Check for only valid GATT client Instance */
4992 BT_INFO("Unregister GATT client instance [%d]", info->client_id);
4993 numapps[k].client_id = -1;
4994 numapps[k].is_initialized = FALSE;
4995 memset(numapps[k].sender, 0x00, sizeof(numapps[k].sender));
4996 memset(numapps[k].uuid, 0x00, sizeof(numapps[k].uuid));
4997 memset(&numapps[k].address.addr, 0x00, sizeof(bluetooth_device_address_t));
4999 /* Its a GATT Client Instance */
5000 ret = gattc_deregister(client_id);
5001 if (ret != OAL_STATUS_SUCCESS) {
5002 BT_ERR("DeAllocate GATT Client instance with stack Fail ret: %d", ret);
5003 return BLUETOOTH_ERROR_INTERNAL;
5005 return BLUETOOTH_ERROR_NONE;
5010 return BLUETOOTH_ERROR_NOT_FOUND;
5013 static void __bt_handle_client_mtu_exchange_completed(event_gattc_mtu_configured_t *event_data)
5015 int result = BLUETOOTH_ERROR_NONE;
5016 struct gatt_server_info_t *conn_info = NULL;
5017 GVariant *param = NULL;
5021 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(event_data->conn_id);
5022 if (conn_info == NULL) {
5023 BT_ERR("Cant find connection Information");
5027 BT_INFO("GATT Client: MTU Configured from addr [%s] status [%d] MTU size [%d]",
5028 conn_info->addr, event_data->status, event_data->mtu);
5030 if (event_data->status != OAL_STATUS_SUCCESS)
5031 result = BLUETOOTH_ERROR_INTERNAL;
5033 BT_INFO("reply BT_REQ_ATT_MTU ");
5035 /* DBUS Return fo BT_REQ_ATT_MTU for all the apps */
5036 __bt_gatt_handle_pending_request_info(result, BT_REQ_ATT_MTU, conn_info->addr,
5037 BT_ADDRESS_STRING_SIZE);
5039 if (result == BLUETOOTH_ERROR_NONE) {
5040 BT_INFO("sending mtu event");
5042 mtu = event_data->mtu;
5043 param = g_variant_new("(isqy)",
5049 /* Send event to BT-API */
5050 _bt_send_event(BT_DEVICE_EVENT,
5051 BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED,
5054 /* Update the MTU for current connection */
5055 BT_INFO("Updating the MTU for current connection");
5056 __bt_update_mtu_gatt_device(conn_info->addr, event_data->mtu);
5060 static struct gatt_mtu_info_t *__bt_find_mtu_gatt_device(char *address)
5063 struct gatt_mtu_info_t *info = NULL;
5067 for (l = gatt_mtu_info_list; l != NULL; l = g_slist_next(l)) {
5068 info = (struct gatt_mtu_info_t*)l->data;
5072 if (!g_strcmp0(info->addr, address)) {
5073 BT_INFO("Remote GATT device found addr[%s]", info->addr);
5078 BT_INFO("Not found Remote GATT device addr[%s]", address);
5082 static void __bt_remove_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("removing the gatt device from mtu list");
5092 gatt_mtu_info_list = g_slist_remove(gatt_mtu_info_list, dev_info);
5093 g_free(dev_info->addr);
5098 static void __bt_add_mtu_gatt_device(char *address)
5100 struct gatt_mtu_info_t *dev_info = NULL;
5104 dev_info = __bt_find_mtu_gatt_device(address);
5107 BT_INFO("adding the gatt device in mtu list");
5108 dev_info = g_new0(struct gatt_mtu_info_t, 1);
5109 dev_info->addr = g_strdup(address);
5110 dev_info->att_mtu = BT_DEFAULT_ATT_MTU;
5111 gatt_mtu_info_list = g_slist_append(gatt_mtu_info_list, dev_info);
5115 static void __bt_update_mtu_gatt_device(char *address, int mtu)
5117 struct gatt_mtu_info_t *dev_info = NULL;
5121 dev_info = __bt_find_mtu_gatt_device(address);
5124 BT_INFO("Udating the mtu");
5125 dev_info->att_mtu = mtu;