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 /* Search for a app which has same sender and adv handle as 0 */
525 if (!g_strcmp0(info->sender, sender) && info->adv_handle == 0)
526 info->adv_handle = adv_handle;
530 int _bt_is_sender_gatt_server_with_no_adv(const char *sender, int adv_handle)
533 BT_DBG("Sender [%s] Adv handle [%d]", sender, adv_handle);
534 bt_service_app_info_t *info = NULL;
536 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
538 /* Search for a app which has same sender and adv handle as 0
539 It is possible that same sender but different adv handle */
540 if (!g_strcmp0(info->sender, sender) && info->adv_handle == 0) {
541 //info->adv_handle = adv_handle;
542 return info->instance_id;
548 int _bt_get_allocated_server_instance(const char *sender, int adv_handle, gboolean use_reserved_slot)
551 BT_DBG("Sender [%s] Adv handle [%d]", sender, adv_handle);
552 bt_service_app_info_t *info = NULL;
554 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
557 /* Exact matching of Adv handle + sender combination */
558 if (!g_strcmp0(info->sender, sender) && info->adv_handle == adv_handle)
559 return info->instance_id;
561 if (!g_strcmp0(info->sender, sender) && info->adv_handle == -1)
562 return info->instance_id;
568 char * _bt_get_sender_and_handle(int server_instance, int *adv_handle)
571 bt_service_app_info_t *info = NULL;
573 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
576 if (info->instance_id == server_instance && info->adv_handle != -1) {
577 *adv_handle = info->adv_handle;
578 BT_DBG("Server instance [%d] Adv handle [%d] Sender [%s]", server_instance, *adv_handle, info->sender);
579 return g_strdup(info->sender);
585 void _bt_set_new_adv_data(bluetooth_advertising_data_t *adv, int len, int instance)
589 bt_service_app_info_t *info = NULL;
590 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
593 if (info->instance_id == instance) {
594 memcpy(info->adv_data.data, &adv->data, len);
600 void _bt_set_new_scan_rsp_data(bluetooth_scan_resp_data_t *scan, int len, int instance)
604 bt_service_app_info_t *info = NULL;
605 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
608 if (info->instance_id == instance) {
609 memcpy(info->scan_rsp.data, &scan->data, len);
615 void _bt_get_previous_adv_data(bluetooth_advertising_data_t *adv, int *len, int instance)
618 bt_service_app_info_t *info = NULL;
620 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
623 if (info->instance_id == instance) {
624 memcpy(&adv->data, info->adv_data.data, info->adv_data_len);
625 *len = info->adv_data_len;
631 void _bt_get_previous_scan_rsp_data(bluetooth_scan_resp_data_t *scan, int *len, int instance)
635 bt_service_app_info_t *info = NULL;
637 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
640 if (info->instance_id == instance) {
641 memcpy(&scan->data, info->scan_rsp.data, info->scan_rsp_len);
642 *len = info->scan_rsp_len;
648 static int __bt_unregister_gatt_client_instance(int client_if)
650 int ret = OAL_STATUS_SUCCESS;
653 BT_INFO("DeAllocate client instance ID [%d]", client_if);
655 /* Reset data: instance_id parameter could be either for GATT Server or for GATT client */
656 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
657 if (numapps[k].client_id == client_if) {
658 BT_INFO("This is a GATT client app, unregister: Slot [%d] vacant", k);
659 numapps[k].client_id = -1;
660 numapps[k].is_initialized = FALSE;
661 memset(numapps[k].sender, 0x00, sizeof(numapps[k].sender));
662 memset(numapps[k].uuid, 0x00, sizeof(numapps[k].uuid));
663 memset(&numapps[k].address.addr, 0x00, sizeof(bluetooth_device_address_t));
665 /* Its a GATT Client Instance */
666 ret = gattc_deregister(client_if);
667 if (ret != OAL_STATUS_SUCCESS) {
668 BT_ERR("DeAllocate GATT Client instance with stack Fail ret: %d", ret);
669 return BLUETOOTH_ERROR_INTERNAL;
674 return BLUETOOTH_ERROR_NONE;
677 static int __bt_unregister_gatt_server_instance(int server_instance)
679 int ret = OAL_STATUS_SUCCESS;
682 /* Unregister the server instance */
683 ret = gatts_unregister(server_instance);
684 if (ret != OAL_STATUS_SUCCESS) {
685 BT_ERR("DeAllocate server instance with stack Fail ret: %d", ret);
686 return BLUETOOTH_ERROR_INTERNAL;
688 BT_INFO("DeAllocated server instance with stack successful..");
691 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
692 if (numapps[k].instance_id == server_instance) {
693 numapps[k].is_initialized = 0;
694 numapps[k].instance_id = -1;
695 numapps[k].adv_handle = 0;
696 numapps[k].adv_instance = -1;
697 memset(numapps[k].sender, 0x00, sizeof(numapps[k].sender));
698 memset(numapps[k].uuid, 0x00, sizeof(numapps[k].uuid));
699 memset(numapps[k].adv_data.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX);
700 memset(numapps[k].scan_rsp.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX);
701 numapps[k].adv_data_len = 0;
702 numapps[k].scan_rsp_len = 0;
706 BT_DBG("Going8 to reset numapp block num [%d]", k);
707 return BLUETOOTH_ERROR_NONE;
710 static void __bt_remove_all_service_handles(bt_service_app_info_t *app_info)
714 int ret = OAL_STATUS_SUCCESS;
717 if (app_info == NULL)
720 count = g_slist_length(app_info->service_handles);
721 BT_INFO("Before handle removal: current count [%d]", count);
723 for (l = app_info->service_handles; l != NULL;) {
728 BT_INFO("Server Handle to be Removed [%d] Instance ID [%d]", *handle, app_info->instance_id);
729 if (_bt_gatt_server_stop_service(app_info->sender, *handle, app_info->instance_id) != BLUETOOTH_ERROR_NONE)
732 ret = gatts_delete_service(app_info->instance_id, *handle);
733 if (ret != OAL_STATUS_SUCCESS) {
734 BT_ERR("ret: %d", ret);
737 app_info->service_handles = g_slist_remove(app_info->service_handles, handle);
740 count = g_slist_length(app_info->service_handles);
741 BT_INFO("After deleting current count [%d]", count);
747 int _bt_unregister_server_instance(const char *sender, int adv_handle)
749 BT_INFO("Unregister Allocated server instance request Sender [%s] Adv handle [%d]", sender, adv_handle);
750 int result = BLUETOOTH_ERROR_NONE;
751 int apps[MAX_APPS_SUPPORTED];
755 memset(&apps, -1, sizeof(apps));
757 if (adv_handle == 0) {
758 BT_DBG("Its a direct GATT Server app request to unregister");
759 /* Unregister server instance for each app with same sender (case: GATT Server with multiple adv handle) */
760 bt_service_app_info_t *info = NULL;
762 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
765 /* Exact matching of sender */
766 if (!g_strcmp0(info->sender, sender)) {
767 BT_INFO("Unregister GATT server instance [%d]", info->instance_id);
768 /* Unregister all service handles with stack */
769 __bt_remove_all_service_handles(info);
771 /* Disable adv if running */
772 BT_INFO("Disable Advertising Adv Handle [%d] sender [%s]",
773 info->adv_handle, sender);
774 _bt_set_advertising(sender, info->adv_handle, FALSE, FALSE);
776 /* Save all instances which need to be unregistered */
777 apps[info->instance_id] = 1;
781 BT_DBG("Its an Internal unregister request by adv application");
782 server_instance = _bt_get_allocated_server_instance(sender, adv_handle, FALSE);
783 BT_DBG("Its an Internal unregister request by adv application: Adv disabled srv instance [%d]", server_instance);
784 if (server_instance == -1) {
785 BT_ERR("No allocated server instance to be removed");
786 return BLUETOOTH_ERROR_INVALID_PARAM;
788 if (!numapps[server_instance].service_handles) {
789 BT_INFO("There are no Service handles with this app, safe to unregister");
790 /* Unregister server instance only if this sender does not have any gatt services in it */
791 result = __bt_unregister_gatt_server_instance(server_instance);
793 numapps[server_instance].adv_handle = 0;
794 memset(numapps[server_instance].adv_data.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX);
795 numapps[server_instance].adv_data_len = 0;
796 memset(numapps[server_instance].scan_rsp.data, 0x00, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX);
797 numapps[server_instance].scan_rsp_len = 0;
802 /* Unregister all apps one by one */
803 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
805 BT_INFO("Unregister app[%d]", k);
806 /* Unregister server instance */
807 __bt_unregister_gatt_server_instance(k);
814 int _bt_register_server_instance(const char *sender, int adv_handle)
816 int ret = OAL_STATUS_SUCCESS;
817 char *uuid_string = NULL;
822 BT_INFO("###Check on which instance Server instance can be initialized....");
823 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
824 if (numapps[k].is_initialized == 1) {
825 BT_INFO("Instance ID [%d] is already in use..Check next slot", numapps[k].instance_id);
828 BT_INFO("Time to register GATT Server..UUID to be used is [%s] slot [%d]", uuid_list[slot-1], slot);
834 BT_ERR("No Slot if free for GATT Server registration..");
835 return BLUETOOTH_ERROR_REGISTRATION_FAILED;
838 uuid_string = g_malloc0(BT_UUID_STRING_MAX);
839 _bt_string_to_uuid(uuid_list[slot-1], (service_uuid_t*)&uuid);
840 g_strlcpy(uuid_string, uuid_list[slot-1], BT_UUID_STRING_MAX);
841 BT_INFO("Copied UUID string [%s]", uuid_string);
843 /* Register GATT Server */
844 ret = gatts_register(&uuid);
845 if (ret != OAL_STATUS_SUCCESS) {
846 BT_ERR("ret: %d", ret);
848 return BLUETOOTH_ERROR_INTERNAL;
850 BT_INFO("GATT Server registration call successfully accepted by OAL..wait for Instance Initialized event from OAL..");
851 /* Return & wait for GATT Server Instance Initialization event */
852 memset(numapps[slot].sender, 0x00, sizeof(numapps[slot].sender));
853 memset(numapps[slot].uuid, 0x00, sizeof(numapps[slot].uuid));
855 g_strlcpy(numapps[slot].sender, sender, sizeof(numapps[slot].sender));
856 g_strlcpy(numapps[slot].uuid, uuid_string, sizeof(numapps[slot].uuid));
858 numapps[slot].is_initialized = 0; /* Set initialization from app registered callback */
859 numapps[slot].adv_handle = adv_handle;
862 return BLUETOOTH_ERROR_NONE;
866 static void __bt_gatt_handle_pending_request_info(int result,
867 int service_function, void *data, unsigned int size)
871 invocation_info_t *req_info = NULL;
872 ret_if(data == NULL);
874 for (l = _bt_get_invocation_list(); l != NULL; ) {
877 if (req_info == NULL || req_info->service_function != service_function)
880 switch (service_function) {
882 case BT_GATT_SERVER_REGISTER: {
883 bt_service_app_info_t *param = (bt_service_app_info_t*)data;
884 BT_DBG("Sender [%s] Request Sender [%s]", param->sender, req_info->sender);
885 if (!g_strcmp0(req_info->sender, param->sender)) {
886 BT_DBG("GATT Server app found [%s]", req_info->sender);
888 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
889 g_array_append_vals(out_param, ¶m->instance_id, sizeof(int));
890 _bt_service_method_return(req_info->context, out_param, result);
892 g_free(req_info->user_data);
893 _bt_free_info_from_invocation_list(req_info);
894 g_array_free(out_param, TRUE);
898 case BT_GATT_SERVER_START_SERVICE:
899 case BT_GATT_SERVER_DELETE_SERVICE: {
900 bt_service_app_info_t *param = (bt_service_app_info_t*)data;
901 BT_DBG("Sender [%s] Request Sender [%s]", param->sender, req_info->sender);
903 int *saved_instance_id = (int*)req_info->user_data;
904 if (!g_strcmp0(req_info->sender, param->sender) && param->instance_id == *saved_instance_id) {
905 BT_DBG("GATT Server app found [%s] Instance ID [%d] Reply DBUS",
906 req_info->sender, *saved_instance_id);
908 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
909 g_array_append_vals(out_param, &saved_instance_id, sizeof(int));
910 _bt_service_method_return(req_info->context, out_param, result);
912 g_free(req_info->user_data);
913 _bt_free_info_from_invocation_list(req_info);
914 g_array_free(out_param, TRUE);
918 case BT_GATT_SERVER_ADD_SERVICE:
919 case BT_GATT_SERVER_ADD_DESCRIPTOR:
920 case BT_GATT_SERVER_ADD_CHARACTERISTIC: {
921 int *handle = (int*)data;
922 BT_DBG("Characteristic added: Handle [%d]", *handle);
923 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
925 g_array_append_vals(out_param, handle, sizeof(int));
926 _bt_service_method_return(req_info->context, out_param, result);
928 g_free(req_info->user_data);
929 _bt_free_info_from_invocation_list(req_info);
930 g_array_free(out_param, TRUE);
935 case BT_DISCONNECT_LE: {
936 #ifdef TIZEN_GATT_CLIENT
937 char *addr = (char*)req_info->user_data;
938 bluetooth_device_address_t address;
940 if (!g_strcmp0(addr, (char*)data)) {
941 BT_INFO("GATT Client connect-disconnect call pending for app [%s] addr [%s]",
942 req_info->sender, addr);
943 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
944 _bt_convert_addr_string_to_type(address.addr, addr);
946 g_array_append_vals(out_param, (bluetooth_device_address_t*)&address,
947 sizeof(bluetooth_device_address_t));
948 _bt_service_method_return(req_info->context, out_param, result);
950 g_free(req_info->user_data);
951 _bt_free_info_from_invocation_list(req_info);
952 g_array_free(out_param, TRUE);
955 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
957 g_array_append_vals(out_param, (bluetooth_device_address_t*)data,
958 sizeof(bluetooth_device_address_t));
959 _bt_service_method_return(req_info->context, out_param, result);
961 g_free(req_info->user_data);
962 _bt_free_info_from_invocation_list(req_info);
964 g_array_free(out_param, TRUE);
968 #ifdef TIZEN_GATT_CLIENT
969 case BT_GATT_CLIENT_REGISTER: {
970 bt_service_app_info_t *param = (bt_service_app_info_t*)data;
971 BT_DBG("Sender [%s] Request Sender [%s]", param->sender, req_info->sender);
972 if (!g_strcmp0(req_info->sender, param->sender)) {
973 BT_DBG("GATT Client app found [%s] created client ID [%d]",
974 req_info->sender, param->client_id);
976 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
977 g_array_append_vals(out_param, ¶m->client_id, sizeof(int));
978 _bt_service_method_return(req_info->context, out_param, result);
980 g_free(req_info->user_data);
981 _bt_free_info_from_invocation_list(req_info);
982 g_array_free(out_param, TRUE);
986 case BT_GATT_GET_PRIMARY_SERVICES: {
987 bt_services_browse_info_t *param = (bt_services_browse_info_t*)data;
988 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
989 _bt_convert_addr_type_to_string(address,
990 (unsigned char *)(¶m->device_addr.addr));
992 BT_DBG("Request Sender [%s] address [%s]", req_info->sender, address);
994 /* Match address to determine same request */
995 if (!g_strcmp0((char*)req_info->user_data, address)) {
996 BT_DBG("GATT Client app found [%s] Remote address [%s]",
997 req_info->sender, address);
999 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
1000 g_array_append_vals(out_param, param,
1001 sizeof(bt_services_browse_info_t));
1003 //g_array_append_vals(out_param, ¶m->client_id, sizeof(int));
1004 _bt_service_method_return(req_info->context, out_param, result);
1006 g_free(req_info->user_data);
1007 _bt_free_info_from_invocation_list(req_info);
1008 g_array_free(out_param, TRUE);
1013 case BT_GATT_GET_SERVICE_PROPERTIES: {
1014 bt_char_browse_info_t param;
1015 memcpy((void*)¶m, data, sizeof(bt_char_browse_info_t));
1016 //bt_char_browse_info_t *param = (bt_char_browse_info_t*)data;
1017 BT_DBG("Request Sender [%s]", req_info->sender);
1018 bluetooth_gatt_client_svc_prop_info_t *prop = (bluetooth_gatt_client_svc_prop_info_t*)req_info->user_data;
1020 /* Match both address and service properties to determine same request */
1021 if (!memcmp(param.device_addr.addr,
1022 prop->device_address.addr,
1023 sizeof(bluetooth_device_address_t)) &&
1024 !memcmp(param.svc_uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) &&
1025 param.svc_inst_id == prop->svc.instance_id) {
1026 BT_DBG("Returning Service properties");
1028 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
1029 g_array_append_vals(out_param, ¶m, sizeof(bt_char_browse_info_t));
1030 _bt_service_method_return(req_info->context, out_param, result);
1032 g_free(req_info->user_data);
1033 _bt_free_info_from_invocation_list(req_info);
1034 g_array_free(out_param, TRUE);
1038 case BT_GATT_GET_CHARACTERISTIC_PROPERTIES: {
1039 bt_descriptor_browse_info_t *param = (bt_descriptor_browse_info_t*)data;
1041 BT_DBG("Request Sender [%s]", req_info->sender);
1042 bluetooth_gatt_client_char_prop_info_t *prop = (bluetooth_gatt_client_char_prop_info_t*)req_info->user_data;
1044 /* Match both address, service properties &char properties to determine same request */
1045 if (!memcmp(param->device_addr.addr,
1046 prop->device_address.addr,
1047 sizeof(bluetooth_device_address_t)) &&
1048 !memcmp(param->svc_uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) &&
1049 param->svc_inst_id == prop->svc.instance_id &&
1050 !memcmp(param->char_uuid, prop->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) &&
1051 param->char_inst_id == prop->characteristic.instance_id) {
1052 BT_DBG("Returning Characteristic properties");
1053 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
1054 g_array_append_vals(out_param, param, sizeof(bt_descriptor_browse_info_t));
1055 _bt_service_method_return(req_info->context, out_param, result);
1057 g_free(req_info->user_data);
1058 _bt_free_info_from_invocation_list(req_info);
1059 g_array_free(out_param, TRUE);
1063 case BT_GATT_WATCH_CHARACTERISTIC: {
1064 bt_gatt_notif_reg_info_t *param = (bt_gatt_notif_reg_info_t*)data;
1065 bluetooth_gatt_client_char_prop_info_t *prop = (bluetooth_gatt_client_char_prop_info_t*)req_info->user_data;
1066 BT_DBG("Request Sender [%s]", req_info->sender);
1067 /* Match both address, service properties &char properties to determine same request */
1068 if (!memcmp(param->addr.addr,
1069 prop->device_address.addr,
1070 sizeof(bluetooth_device_address_t)) &&
1071 !memcmp(param->svc_uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) &&
1072 param->svc_inst == prop->svc.instance_id &&
1073 !memcmp(param->char_uuid, prop->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) &&
1074 param->char_inst == prop->characteristic.instance_id) {
1075 BT_INFO("Characteristic Watch Successful: Is registered [%d]",
1076 param->is_registered);
1077 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
1078 g_array_append_vals(out_param, param, sizeof(bt_gatt_notif_reg_info_t));
1079 _bt_service_method_return(req_info->context, out_param, result);
1080 g_free(req_info->user_data);
1081 _bt_free_info_from_invocation_list(req_info);
1082 g_array_free(out_param, TRUE);
1086 case BT_GATT_READ_CHARACTERISTIC:
1087 case BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE: {
1088 bluetooth_gatt_client_char_prop_info_t *param = (bluetooth_gatt_client_char_prop_info_t*)data;
1089 BT_DBG("Request Sender [%s]", req_info->sender);
1091 char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
1092 bluetooth_gatt_client_char_prop_info_t *prop = (bluetooth_gatt_client_char_prop_info_t*)req_info->user_data;
1093 _bt_convert_addr_type_to_string(addr, prop->device_address.addr);
1095 if (!memcmp(param, prop, sizeof(bluetooth_gatt_client_char_prop_info_t))) {
1096 BT_DBG("Gatt Char read or write request matched for address [%s]", addr);
1097 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
1098 g_array_append_vals(out_param, param, sizeof(bluetooth_gatt_client_char_prop_info_t));
1099 _bt_service_method_return(req_info->context, out_param, result);
1101 g_free(req_info->user_data);
1102 _bt_free_info_from_invocation_list(req_info);
1103 g_array_free(out_param, TRUE);
1108 case BT_GATT_READ_DESCRIPTOR_VALUE:
1109 case BT_GATT_WRITE_DESCRIPTOR_VALUE: {
1110 bluetooth_gatt_client_desc_prop_info_t *param = (bluetooth_gatt_client_desc_prop_info_t*)data;
1111 BT_DBG("Request Sender [%s]", req_info->sender);
1113 char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
1114 bluetooth_gatt_client_desc_prop_info_t *prop = (bluetooth_gatt_client_desc_prop_info_t*)req_info->user_data;
1115 _bt_convert_addr_type_to_string(addr, prop->device_address.addr);
1117 if (!memcmp(param, prop, sizeof(bluetooth_gatt_client_desc_prop_info_t))) {
1118 BT_DBG("Descriptor read or write request matched for address [%s]", addr);
1119 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
1120 g_array_append_vals(out_param, param, sizeof(bluetooth_gatt_client_desc_prop_info_t));
1121 _bt_service_method_return(req_info->context, out_param, result);
1123 g_free(req_info->user_data);
1124 _bt_free_info_from_invocation_list(req_info);
1125 g_array_free(out_param, TRUE);
1130 case BT_REQ_ATT_MTU: {
1131 char *addr = (char*)req_info->user_data;
1132 bluetooth_device_address_t address;
1134 if (!g_strcmp0(addr, (char*)data)) {
1135 BT_DBG("GATT Client BT_REQ_ATT_MTU call pending for app [%s] addr [%s]",
1136 req_info->sender, addr);
1137 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
1138 _bt_convert_addr_string_to_type(address.addr, addr);
1140 g_array_append_vals(out_param, (bluetooth_device_address_t*)&address,
1141 sizeof(bluetooth_device_address_t));
1142 _bt_service_method_return(req_info->context, out_param, result);
1144 g_free(req_info->user_data);
1145 _bt_free_info_from_invocation_list(req_info);
1146 g_array_free(out_param, TRUE);
1156 static void __bt_handle_server_instance_registered(event_gatts_register_t *data)
1158 bt_service_app_info_t *info = NULL;
1160 char *uuid_string = g_malloc0(BT_UUID_STRING_MAX);
1162 _bt_uuid_to_string(&(data->server_uuid), uuid_string);
1163 BT_INFO("Instance ID is Intialized [%d] UUID initialized [%s]", data->server_inst, uuid_string);
1165 /* Check if the just registered Instance ID belongs to BLEAPP or GATT Server */
1166 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1169 if (g_strcmp0(info->uuid, uuid_string) == 0) {
1170 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1171 info->is_initialized = TRUE;
1172 info->instance_id = data->server_inst;
1173 info->adv_instance = data->server_inst;
1174 __bt_gatt_handle_pending_request_info(BLUETOOTH_ERROR_NONE, BT_GATT_SERVER_REGISTER,
1175 (void*)info, sizeof(bt_service_app_info_t));
1179 g_free(uuid_string);
1182 static void __bt_handle_gatt_server_service_added(event_gatts_srvc_prm_t *event)
1184 int result = BLUETOOTH_ERROR_NONE;
1188 bt_service_app_info_t *info = NULL;
1191 char *uuid_str = g_malloc0(BT_UUID_STRING_MAX);
1192 _bt_uuid_to_string(&(event->gatt_srvc_id.id.uuid), uuid_str);
1193 BT_INFO("GATT Added Service UUID: [%s] Server Ins [%d] Service hdl [%d] Is Primary [%d]\n",
1194 uuid_str, event->gatt_srvc_stat.server_inst, svc_handle, event->gatt_srvc_id.is_prmry);
1196 if (event->gatt_srvc_stat.status != OAL_STATUS_SUCCESS) {
1197 result = BLUETOOTH_ERROR_INTERNAL;
1198 svc_handle = 0; /* Service handle set to 0 indicates.
1199 0 is reserved by BT SIG, cant be used by app*/
1201 svc_handle = event->gatt_srvc_stat.servic_hndl;
1203 BT_INFO("GATT Added Service Status [%d] Server Ins [%d] Service hdl [%d] Is Primary [%d]\n",
1204 event->gatt_srvc_stat.status, event->gatt_srvc_stat.server_inst, svc_handle, event->gatt_srvc_id.is_prmry);
1206 /* Check if the just registered Instance ID belongs to BLEAPP or GATT Server */
1207 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1210 if (info->instance_id == event->gatt_srvc_stat.server_inst) {
1211 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1212 __bt_gatt_handle_pending_request_info(result, BT_GATT_SERVER_ADD_SERVICE,
1213 (int*)&svc_handle, sizeof(int));
1215 /* Add Service Handle */
1216 if (svc_handle > 0) {
1217 handle = g_malloc0(sizeof(int));
1218 *handle = svc_handle;
1219 numapps[event->gatt_srvc_stat.server_inst].service_handles = g_slist_append(numapps[event->gatt_srvc_stat.server_inst].service_handles, handle);
1220 count = g_slist_length(numapps[event->gatt_srvc_stat.server_inst].service_handles);
1221 BT_INFO("Added Service handle [%d] to list..current count [%d]", svc_handle, count);
1230 static void __bt_handle_gatt_server_characteristic_added(event_gatts_srvc_charctr_t *event)
1232 int result = BLUETOOTH_ERROR_NONE;
1234 bt_service_app_info_t *info = NULL;
1236 char *uuid_str = g_malloc0(BT_UUID_STRING_MAX);
1238 BT_INFO("GATT Server Char added status [%d]", event->gatt_srvc_stat.status);
1239 BT_INFO("GATT Server_inst: [%d]", event->gatt_srvc_stat.server_inst);
1240 BT_INFO("GATT Service Handle: [%d]", event->gatt_srvc_stat.servic_hndl);
1241 BT_INFO("GATT Add characteristic Status: [%d]", event->gatt_srvc_stat.status);
1242 BT_INFO("GATT Service characteristic Handle: [%d]", event->charctr_hndl);
1244 if (event->gatt_srvc_stat.status != OAL_STATUS_SUCCESS) {
1245 result = BLUETOOTH_ERROR_INTERNAL;
1246 char_handle = 0; /* characteristic handle set to 0 indicates.
1247 0 is reserved by BT SIG, cant be used by app*/
1249 char_handle = event->charctr_hndl;
1252 /* Check if the just registered Instance ID belongs to BLEAPP or GATT Server */
1253 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1256 if (info->instance_id == event->gatt_srvc_stat.server_inst) {
1257 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1258 __bt_gatt_handle_pending_request_info(result, BT_GATT_SERVER_ADD_CHARACTERISTIC,
1259 (int*)&char_handle, sizeof(int));
1265 _bt_uuid_to_string(&(event->charctr_uuid), uuid_str);
1266 BT_INFO("GATT Added Characteristic: UUID: [%s]", uuid_str);
1271 static void __bt_handle_gatt_server_descriptor_added(event_gatts_srvc_descr_t* event)
1273 int result = BLUETOOTH_ERROR_NONE;
1275 bt_service_app_info_t *info = NULL;
1277 char *uuid_str = g_malloc0(BT_UUID_STRING_MAX);
1279 BT_INFO("GATT Server Descriptor added status [%d]", event->gatt_srvc_stat.status);
1280 BT_INFO("GATT Server_inst: [%d]", event->gatt_srvc_stat.server_inst);
1281 BT_INFO("GATT Service Handle: [%d]", event->gatt_srvc_stat.servic_hndl);
1282 BT_INFO("GATT Add Descriptor Status: [%d]", event->gatt_srvc_stat.status);
1283 BT_INFO("GATT Service Descriptor Handle: [%d]", event->descrptr_hndl);
1285 if (event->gatt_srvc_stat.status != OAL_STATUS_SUCCESS) {
1286 result = BLUETOOTH_ERROR_INTERNAL;
1287 desc_handle = 0; /* Service handle set to 0 indicates.
1288 0 is reserved by BT SIG, cant be used by app*/
1290 desc_handle = event->descrptr_hndl;
1292 /* Check if the just registered Instance ID belongs to BLEAPP or GATT Server */
1293 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1296 if (info->instance_id == event->gatt_srvc_stat.server_inst) {
1297 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1298 __bt_gatt_handle_pending_request_info(result, BT_GATT_SERVER_ADD_DESCRIPTOR,
1299 (int*)&desc_handle, sizeof(int));
1304 _bt_uuid_to_string(&(event->descrptr_uuid), uuid_str);
1305 BT_INFO("GATT Added Descriptor: UUID: [%s]", uuid_str);
1310 static void __bt_handle_gatt_server_service_started(event_gatts_srvc_t *event)
1312 bt_service_app_info_t *info = NULL;
1313 int result = BLUETOOTH_ERROR_NONE;
1315 BT_INFO("GATT Server Service Started..");
1318 BT_INFO("GATT Server_inst: [%d]", event->server_inst);
1319 BT_INFO("GATT Service Handle: [%d]", event->servic_hndl);
1320 BT_INFO("GATT Service Started Status: [%d]", event->status);
1322 if (event->status != OAL_STATUS_SUCCESS) {
1323 BT_ERR("GATT Server Service Start Failed Err: [%d]", event->status);
1324 result = BLUETOOTH_ERROR_INTERNAL;
1327 /* Check if the just registered Instance ID belongs to requester */
1328 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1331 if (info->instance_id == event->server_inst) {
1332 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1333 __bt_gatt_handle_pending_request_info(result, BT_GATT_SERVER_START_SERVICE,
1334 (void*)info, sizeof(bt_service_app_info_t));
1340 static void __bt_handle_gatt_server_service_stopped(event_gatts_srvc_t *event)
1342 int result = BLUETOOTH_ERROR_NONE;
1343 bt_service_app_info_t *info = NULL;
1345 BT_INFO("GATT Server Service Stopped..");
1347 BT_INFO("GATT Server_inst: [%d]", event->server_inst);
1348 BT_INFO("GATT Service Handle: [%d]", event->servic_hndl);
1349 BT_INFO("GATT Service Stopped Status: [%d]", event->status);
1351 if (event->status != OAL_STATUS_SUCCESS) {
1352 BT_ERR("GATT Server Service Stop Failed Err: [%d]", event->status);
1353 result = BLUETOOTH_ERROR_INTERNAL;
1356 /* Check if the just registered Instance ID belongs to requester */
1357 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1360 if (info->instance_id == event->server_inst) {
1361 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1362 __bt_gatt_handle_pending_request_info(result, BT_GATT_SERVER_STOP_SERVICE,
1363 (void*)info, sizeof(bt_service_app_info_t));
1369 static void __bt_handle_gatt_server_service_deleted(event_gatts_srvc_t *event)
1371 int result = BLUETOOTH_ERROR_NONE;
1372 bt_service_app_info_t *info = NULL;
1374 BT_INFO("GATT Server Service Deleted..");
1376 BT_INFO("GATT Server_inst: [%d]", event->server_inst);
1377 BT_INFO("GATT Service Handle: [%d]", event->servic_hndl);
1378 BT_INFO("GATT Service Deleted Status: [%d]", event->status);
1380 if (event->status != OAL_STATUS_SUCCESS) {
1381 BT_ERR("GATT Server Service Delete Failed Err: [%d]", event->status);
1382 result = BLUETOOTH_ERROR_INTERNAL;
1385 /* Check if the just registered Instance ID belongs to requester */
1386 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1389 if (info->instance_id == event->server_inst) {
1390 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1391 __bt_gatt_handle_pending_request_info(result, BT_GATT_SERVER_DELETE_SERVICE,
1392 (void*)info, sizeof(bt_service_app_info_t));
1398 struct gatt_client_info_t *_bt_find_remote_gatt_client_info(char *address)
1401 struct gatt_client_info_t *info = NULL;
1402 for (l = gatt_client_info_list; l != NULL; l = g_slist_next(l)) {
1403 info = (struct gatt_client_info_t*)l->data;
1407 if (!g_strcmp0(info->addr, address)) {
1408 BT_DBG("Remote GATT client found addr[%s]", info->addr);
1415 static struct gatt_client_info_t *__bt_find_remote_gatt_client_info_from_conn_id(int conn_id)
1418 struct gatt_client_info_t *info = NULL;
1420 for (l = gatt_client_info_list; l != NULL; l = g_slist_next(l)) {
1421 info = (struct gatt_client_info_t*)l->data;
1425 if (info->connection_id == conn_id) {
1426 BT_INFO("Remote GATT client found addr[%s]", info->addr);
1433 #ifdef TIZEN_GATT_CLIENT
1434 struct gatt_server_info_t *_bt_find_remote_gatt_server_info(char *address)
1437 struct gatt_server_info_t *info = NULL;
1438 for (l = gatt_server_info_list; l != NULL; l = g_slist_next(l)) {
1439 info = (struct gatt_server_info_t*)l->data;
1443 if (!g_strcmp0(info->addr, address)) {
1444 BT_DBG("Remote GATT Server found addr[%s]", info->addr);
1451 static struct gatt_out_conn_info_t* __bt_find_gatt_outgoing_conn_info(char *address)
1454 struct gatt_out_conn_info_t *info = NULL;
1455 for (l = outgoing_gatt_conn_list; l != NULL; l = g_slist_next(l)) {
1456 info = (struct gatt_out_conn_info_t*)l->data;
1460 if (!g_strcmp0(info->addr, address)) {
1461 BT_INFO("Outgoing connection info found addr[%s]", info->addr);
1468 static struct gatt_server_info_t *__bt_find_remote_gatt_server_info_from_client_if(int client_if)
1471 struct gatt_server_info_t *info = NULL;
1473 for (l = gatt_server_info_list; l != NULL; l = g_slist_next(l)) {
1474 info = (struct gatt_server_info_t*)l->data;
1478 if (info->client_id == client_if) {
1479 BT_INFO("Remote GATT server found addr[%s]", info->addr);
1490 #ifdef TIZEN_GATT_CLIENT
1491 static void __bt_handle_gatt_server_connection_state(event_gatts_conn_t *event)
1493 int result = BLUETOOTH_ERROR_NONE;
1494 struct gatt_client_info_t *client_info = NULL;
1495 struct gatt_server_info_t *server_info = NULL;
1496 bluetooth_device_address_t dev_addr;
1497 GVariant *param = NULL;
1500 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1502 memcpy(dev_addr.addr, event->address.addr, 6);
1504 /* REPLY dbus Context to application which called BT_CONNECT_LE. There is status
1506 _bt_convert_addr_type_to_string(address,
1507 (unsigned char *)dev_addr.addr);
1509 if (event->status != OAL_STATUS_SUCCESS)
1510 result = BLUETOOTH_ERROR_INTERNAL;
1512 __bt_gatt_handle_pending_request_info(result, BT_CONNECT_LE,
1513 address, BT_ADDRESS_STRING_SIZE);
1515 BT_INFO("GATT Server Connedted: Remote Client addr[%s] Server Instance [%d] Connection ID [%d]",
1516 address, event->server_inst, event->conn_id);
1519 /* Check if device is already in connected list */
1520 client_info = _bt_find_remote_gatt_client_info(address);
1523 BT_INFO("Conn Info absent: But no need to Send Local GATT Server Connected event to apps");
1525 param = g_variant_new("(is)", result, address);
1527 /* Send event to application */
1528 _bt_send_event(BT_DEVICE_EVENT,
1529 BLUETOOTH_EVENT_GATT_SERVER_CONNECTED, /* Local device is GATT server */
1532 /* Save client connection info */
1533 client_info = g_new0(struct gatt_client_info_t, 1);
1534 client_info->addr = g_strdup(address);
1535 BT_INFO("Added GATT client addr[%s]", client_info->addr);
1536 client_info->connection_id = event->conn_id;
1537 client_info->instance_id = event->server_inst;
1538 gatt_client_info_list = g_slist_append(gatt_client_info_list, client_info);
1539 BT_INFO("Total num of connected Remote GATT Clients [%d]", g_slist_length(gatt_client_info_list));
1541 /* Save server connection info */
1542 server_info = g_new0(struct gatt_server_info_t, 1);
1543 server_info->addr = g_strdup(address);
1544 server_info->client_id = -1;
1545 BT_INFO("Added GATT server addr[%s]", server_info->addr);
1546 server_info->connection_id = event->conn_id;
1547 gatt_server_info_list = g_slist_append(gatt_server_info_list, server_info);
1548 BT_INFO("Total num of connected Remote GATT Servers [%d]", g_slist_length(gatt_server_info_list));
1550 ret = gattc_add_connection_info((bt_address_t *)&dev_addr, event->conn_id, event->server_inst);
1551 if (ret != OAL_STATUS_SUCCESS) {
1552 BT_ERR("gattc register server instance failed");
1556 __bt_add_mtu_gatt_device(address);
1561 /* GATT Server Dis connected */
1562 static void __bt_handle_gatt_server_disconnection_state(event_gatts_conn_t *event)
1564 int result = BLUETOOTH_ERROR_NONE;
1565 struct gatt_client_info_t *client_info = NULL;
1566 struct gatt_server_info_t *server_info = NULL;
1567 bluetooth_device_address_t dev_addr;
1568 GVariant *param = NULL;
1569 char address[BT_ADDRESS_STRING_SIZE];
1571 memcpy(dev_addr.addr, event->address.addr, 6);
1573 /* REPLY dbus Context to application which called BT_DISCONNECT_LE. There is status
1575 _bt_convert_addr_type_to_string(address,
1576 (unsigned char *)dev_addr.addr);
1578 if (event->status != OAL_STATUS_SUCCESS)
1579 result = BLUETOOTH_ERROR_INTERNAL;
1581 if (NULL == _bt_get_request_info_data(BT_DISCONNECT_LE, address)) {
1582 if (NULL != _bt_get_request_info_data(BT_CONNECT_LE, address)) {
1583 result = BLUETOOTH_ERROR_INTERNAL;
1585 __bt_gatt_handle_pending_request_info(result, BT_CONNECT_LE,
1586 address, BT_ADDRESS_STRING_SIZE);
1588 BT_ERR("Failed to connect Local GATT Server Remote Client addr[%s]", address);
1592 __bt_gatt_handle_pending_request_info(result, BT_DISCONNECT_LE,
1593 address, BT_ADDRESS_STRING_SIZE);
1596 BT_INFO("Local GATT Server DisConnected: Remote Client addr[%s] Server Instance [%d] Connection ID [%d]",
1597 address, event->server_inst, event->conn_id);
1598 /* Remove Connection info */
1599 client_info = _bt_find_remote_gatt_client_info(address);
1601 BT_INFO("No need to Send Local GATT Server Disconnected event to apps, just remove remote client info");
1603 param = g_variant_new("(is)", result, address);
1604 /* Send event to application */
1605 _bt_send_event(BT_DEVICE_EVENT,
1606 BLUETOOTH_EVENT_GATT_SERVER_DISCONNECTED, /* Local device is GATT server */
1609 /* Remove server info from list */
1610 server_info = _bt_find_remote_gatt_server_info(address);
1612 gatt_server_info_list = g_slist_remove(gatt_server_info_list, server_info);
1614 BT_INFO("Can not find conn info, already removed!");
1616 /* Remove client info from List */
1617 gatt_client_info_list = g_slist_remove(gatt_client_info_list, client_info);
1618 BT_INFO("Total num of connected GATT clients [%d]", g_slist_length(gatt_client_info_list));
1619 g_free(client_info->addr);
1620 g_free(client_info);
1623 __bt_remove_mtu_gatt_device(address);
1627 static void __bt_handle_gatt_server_connection_state(event_gatts_conn_t *event)
1629 int result = BLUETOOTH_ERROR_NONE;
1630 struct gatt_client_info_t *conn_info = NULL;
1631 bt_service_app_info_t *info = NULL;
1632 bluetooth_device_address_t dev_addr;
1633 GVariant *param = NULL;
1636 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1638 memcpy(dev_addr.addr, event->address.addr, 6);
1641 /* Check if the just registered Instance ID belongs to BLEAPP or GATT Server */
1642 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1645 if (info->instance_id == event->server_inst) {
1646 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1647 __bt_gatt_handle_pending_request_info(result, BT_CONNECT_LE,
1648 (bluetooth_device_address_t*)&dev_addr, sizeof(bluetooth_device_address_t));
1654 /* Send event to BT-API */
1655 _bt_convert_addr_type_to_string(address,
1656 (unsigned char *)dev_addr.addr);
1658 BT_INFO("GATT Server Connedted: Remote Client addr[%s] Server Instance [%d] Connection ID [%d]",
1659 address, event->server_inst, event->conn_id);
1662 /* Check if device is already in connected list */
1663 conn_info = _bt_find_remote_gatt_client_info(address);
1666 param = g_variant_new("(is)", result, address);
1667 /* Send event to application */
1668 _bt_send_event(BT_GATT_SERVER_EVENT,
1669 BLUETOOTH_EVENT_GATT_CONNECTED,
1672 /* Save Connection info */
1673 conn_info = g_new0(struct gatt_client_info_t, 1);
1674 conn_info->addr = g_strdup(address);
1675 BT_INFO("Added GATT client addr[%s]", conn_info->addr);
1676 conn_info->connection_id = event->conn_id;
1677 conn_info->instance_id = event->server_inst;
1678 gatt_client_info_list = g_slist_append(gatt_client_info_list, conn_info);
1679 BT_INFO("Total num of connected GATT clients [%d]", g_slist_length(gatt_client_info_list));
1685 /* GATT Server Dis connected */
1686 static void __bt_handle_gatt_server_disconnection_state(event_gatts_conn_t *event)
1688 int result = BLUETOOTH_ERROR_NONE;
1689 struct gatt_client_info_t *conn_info = NULL;
1690 bluetooth_device_address_t dev_addr;
1691 bt_service_app_info_t *info = NULL;
1692 GVariant *param = NULL;
1695 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1697 memcpy(dev_addr.addr, event->address.addr, 6);
1699 /* Check if the just registered Instance ID belongs to BLEAPP or GATT Server */
1700 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
1703 if (info->instance_id == event->server_inst) {
1704 BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
1705 __bt_gatt_handle_pending_request_info(result, BT_DISCONNECT_LE,
1706 (bluetooth_device_address_t*)&dev_addr, sizeof(bluetooth_device_address_t));
1712 /* Send event to BT-API */
1713 _bt_convert_addr_type_to_string(address,
1714 (unsigned char *)dev_addr.addr);
1716 BT_INFO("GATT Server DisConnected: Remote Client addr[%s] Server Instance [%d] Connection ID [%d]",
1717 address, event->server_inst, event->conn_id);
1719 param = g_variant_new("(is)", result, address);
1720 /* Send event to application */
1721 _bt_send_event(BT_GATT_SERVER_EVENT,
1722 BLUETOOTH_EVENT_GATT_DISCONNECTED,
1725 /* Remove Connection info */
1726 conn_info = _bt_find_remote_gatt_client_info(address);
1728 BT_INFO("Remove GATT client info from List..");
1729 /* Remove info from List */
1730 gatt_client_info_list = g_slist_remove(gatt_client_info_list, conn_info);
1731 BT_INFO("Total num of connected GATT clients [%d]", g_slist_length(gatt_client_info_list));
1732 g_free(conn_info->addr);
1741 static void __bt_handle_gatt_server_acquire_write_requested(event_gatts_srvc_acquire_attr_t *event)
1743 GVariant *param = NULL;
1744 int result = BLUETOOTH_ERROR_NONE;
1745 struct gatt_server_req_info *req_info = NULL;
1746 bluetooth_device_address_t dev_addr;
1747 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
1749 BT_INFO("GATT Server ACQUIRE Write Req Connection ID: [%d]", event->attr_trans.conn_id);
1750 BT_INFO("GATT Server ACQUIRE Write Req Transaction ID:[%d]", event->attr_trans.trans_id);
1751 BT_INFO("GATT Server ACQUIRE Write Req Attribute Handle: [%d]", event->attr_trans.attr_handle);
1753 //address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1754 memcpy(dev_addr.addr, event->address.addr, 6);
1756 req_info = g_new0(struct gatt_server_req_info, 1);
1757 req_info->request_id = event->attr_trans.trans_id;
1758 req_info->attribute_handle = event->attr_trans.attr_handle;
1759 req_info->connection_id = event->attr_trans.conn_id;
1760 req_info->request_type = BLUETOOTH_GATT_REQUEST_TYPE_ACQUIRE_WRITE;
1761 gatt_server_requests = g_slist_append(gatt_server_requests, req_info);
1763 _bt_convert_addr_type_to_string(address,
1764 (unsigned char *)dev_addr.addr);
1766 param = g_variant_new("(iiiiiis)", result,
1767 event->attr_trans.conn_id,
1768 event->attr_trans.trans_id,
1769 event->attr_trans.attr_handle,
1770 event->mtu, event->attr_trans.offset, address);
1771 BT_INFO("GATT Server ACQUIRE Write Req Attribute remote address : [%s]", address);
1773 _bt_send_event(BT_GATT_SERVER_EVENT,
1774 BLUETOOTH_EVENT_GATT_SERVER_ACQUIRE_WRITE,
1779 static void __bt_handle_gatt_server_acquire_notify_requested(event_gatts_srvc_acquire_attr_t *event)
1781 GVariant *param = NULL;
1782 int result = BLUETOOTH_ERROR_NONE;
1783 struct gatt_server_req_info *req_info = NULL;
1784 bluetooth_device_address_t dev_addr;
1785 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
1787 BT_INFO("GATT Server ACQUIRE Notify Req Connection ID: [%d]", event->attr_trans.conn_id);
1788 BT_INFO("GATT Server ACQUIRE Notify Req Transaction ID:[%d]", event->attr_trans.trans_id);
1789 BT_INFO("GATT Server ACQUIRE Notify Req Attribute Handle: [%d]", event->attr_trans.attr_handle);
1790 BT_INFO("GATT Server ACQUIRE notify Req address : [%s]", address);
1792 memcpy(dev_addr.addr, event->address.addr, 6);
1793 _bt_convert_addr_type_to_string(address,
1794 (unsigned char *)dev_addr.addr);
1795 BT_INFO("GATT Server ACQUIRE notify Req remote address : [%s]", address);
1797 req_info = g_new0(struct gatt_server_req_info, 1);
1798 req_info->request_id = event->attr_trans.trans_id;
1799 req_info->attribute_handle = event->attr_trans.attr_handle;
1800 req_info->connection_id = event->attr_trans.conn_id;
1801 req_info->request_type = BLUETOOTH_GATT_REQUEST_TYPE_ACQUIRE_NOTIFY;
1802 gatt_server_requests = g_slist_append(gatt_server_requests, req_info);
1804 param = g_variant_new("(iiiiiis)", result,
1805 event->attr_trans.conn_id,
1806 event->attr_trans.trans_id,
1807 event->attr_trans.attr_handle,
1808 event->mtu, event->attr_trans.offset,
1811 BT_INFO("GATT Server ACQUIRE Notify Req Attribute : ");
1813 _bt_send_event(BT_GATT_SERVER_EVENT,
1814 BLUETOOTH_EVENT_GATT_SERVER_ACQUIRE_NOTIFY,
1818 static void __bt_handle_gatt_server_write_requested(event_gatts_srvc_write_attr_t *event)
1821 bluetooth_device_address_t dev_addr;
1822 GVariant *param = NULL;
1823 int result = BLUETOOTH_ERROR_NONE;
1825 gboolean is_prepare_write;
1827 GVariant *data = NULL;
1829 struct gatt_server_req_info *req_info = NULL;
1830 BT_INFO("GATT Server Write Requested");
1832 memcpy(dev_addr.addr, event->address.addr, 6);
1834 BT_INFO("GATT Server Write Req Connection ID: [%d]", event->attr_trans.conn_id);
1835 BT_INFO("GATT Server Write Req Transaction ID:[%d]", event->attr_trans.trans_id);
1836 BT_INFO("GATT Server Write Req Attribute Handle: [%d]", event->attr_trans.attr_handle);
1837 BT_INFO("GATT Server Write Req Attribute Offset: [%d]", event->attr_trans.offset);
1838 BT_INFO("GATT Server Write Req value length [%d]", event->length);
1839 BT_INFO("GATT Server Write Req needs response: [%d]", event->need_rsp);
1840 BT_INFO("GATT Server Write Req Is Prep: [%d]", event->is_prep);
1842 if (event->length <= 0) {
1843 BT_INFO("GATT Server write requested, but length of attr value is 0");
1847 need_resp = event->need_rsp;
1848 is_prepare_write = event->is_prep;
1850 write_val = g_memdup(&event->value[0], event->length);
1852 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1853 _bt_convert_addr_type_to_string(address,
1854 (unsigned char *)dev_addr.addr);
1856 BT_INFO("GATT Server Write Request from remote client [%s]", address);
1858 if (event->length > 0) {
1859 for (i = 0; i < event->length; i++)
1860 BT_DBG("Data[%d] = [0x%x]", i, event->value[i]);
1862 /* Save Write Request Info */
1863 req_info = g_new0(struct gatt_server_req_info, 1);
1864 req_info->request_id = event->attr_trans.trans_id;
1865 req_info->attribute_handle = event->attr_trans.attr_handle;
1866 req_info->connection_id = event->attr_trans.conn_id;
1867 req_info->addr = address;
1868 req_info->offset = event->attr_trans.offset;
1869 req_info->request_type = BLUETOOTH_GATT_REQUEST_TYPE_WRITE;
1870 gatt_server_requests = g_slist_append(gatt_server_requests, req_info);
1872 data = g_variant_new_from_data(
1873 G_VARIANT_TYPE_BYTESTRING,
1878 param = g_variant_new("(iiiiiibbsn@ay)", result,
1879 event->attr_trans.conn_id,
1880 event->attr_trans.trans_id,
1881 event->attr_trans.attr_handle,
1882 event->attr_trans.offset,
1890 _bt_send_event(BT_GATT_SERVER_EVENT,
1891 BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED,
1897 static void __bt_handle_gatt_server_read_requested(event_gatts_srvc_read_attr_t *event)
1899 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1900 bluetooth_device_address_t dev_addr;
1901 int result = BLUETOOTH_ERROR_NONE;
1902 struct gatt_server_req_info *req_info = NULL;
1903 GVariant *param = NULL;
1905 BT_INFO("GATT Server Read Requested");
1907 memcpy(dev_addr.addr, event->address.addr, 6);
1909 BT_INFO("GATT Server-Client Connection ID: [%d]", event->attr_trans.conn_id);
1910 BT_INFO("GATT Server-Client Transaction ID: [%d]", event->attr_trans.trans_id);
1911 BT_INFO("GATT Server Attribute Handle: [%d]", event->attr_trans.attr_handle);
1912 BT_INFO("GATT Server Attribute Offset for read: [%d]", event->attr_trans.offset);
1913 BT_INFO("GATT Server Attribute is long: [%d]", event->is_long);
1915 is_long = event->is_long;
1917 /* Save Read Request Info */
1918 req_info = g_new0(struct gatt_server_req_info, 1);
1919 req_info->request_id = event->attr_trans.trans_id;
1920 req_info->attribute_handle = event->attr_trans.attr_handle;
1921 req_info->connection_id = event->attr_trans.conn_id;
1922 req_info->addr = address;
1923 req_info->offset = event->attr_trans.offset;
1924 req_info->request_type = BLUETOOTH_GATT_REQUEST_TYPE_READ;
1925 gatt_server_requests = g_slist_append(gatt_server_requests, req_info);
1927 /* Send event to BT-API */
1928 _bt_convert_addr_type_to_string(address,
1929 (unsigned char *)dev_addr.addr);
1931 BT_INFO("GATT Server Read Request from remote client [%s]", address);
1933 param = g_variant_new("(iiiiibs)", result,
1934 event->attr_trans.conn_id,
1935 event->attr_trans.trans_id,
1936 event->attr_trans.attr_handle,
1937 event->attr_trans.offset,
1941 _bt_send_event(BT_GATT_SERVER_EVENT,
1942 BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED,
1946 static void __bt_handle_gatt_server_indicate_confirmed(event_gatts_ind_cnfrm_t *event)
1948 bluetooth_device_address_t dev_addr;
1949 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1950 int cur_connected_clients;
1951 static int recvd = 0;
1952 gboolean completed = 0;
1953 GVariant *param = NULL;
1955 /* OAL event does provide error, so MW assumes event will never contain wrong data,
1956 incase of any issues, check with OAL */
1957 int result = BLUETOOTH_ERROR_NONE;
1959 memcpy(dev_addr.addr, event->address.addr, 6);
1960 _bt_convert_addr_type_to_string(address,
1961 (unsigned char *)dev_addr.addr);
1963 BT_INFO("Indication sent to GATT client [%s] conn_ ID [%d] transaction ID [%d] Att handle [%d]",
1964 address, event->conn_id, event->trans_id, event->attr_handle);
1967 cur_connected_clients = g_slist_length(gatt_client_info_list);
1968 BT_INFO("Number of connected clients during sending Indication [%d] & current connected count [%d]",
1969 num_indicate_clients, cur_connected_clients);
1972 if (recvd == num_indicate_clients) {
1973 BT_INFO("Gatt indication confirm event for last GATT client.. [%s]", address);
1974 completed = 1; /* Last event */
1975 recvd = 0; /* Reset */
1976 num_indicate_clients = 0;
1979 param = g_variant_new("(isib)",
1985 /* Send event to BT-API */
1986 _bt_send_event(BT_GATT_SERVER_EVENT,
1987 BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_COMPLETED,
1990 BT_INFO("Received Indication confirm for client number [%d]", recvd);
1994 /* Tizen Platform Specific */
1995 static void __bt_handle_gatt_server_notification_changed(event_gatts_notif_t *event)
1997 bluetooth_device_address_t dev_addr;
1998 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1999 GVariant *param = NULL;
2002 /* OAL event does provide error, so MW assumes event will never contain wrong data,
2003 incase of any issues, check with OAL */
2004 int result = BLUETOOTH_ERROR_NONE;
2006 memcpy(dev_addr.addr, event->address.addr, 6);
2007 _bt_convert_addr_type_to_string(address,
2008 (unsigned char *)dev_addr.addr);
2010 BT_INFO("notification_changed [%s] conn_ ID [%d] transaction ID [%d] Att handle [%d] Notify[%d]",
2011 address, event->conn_id, event->trans_id, event->attr_handle, event->notify);
2013 /* Set Notifcation status */
2014 notify = event->notify;
2016 param = g_variant_new("(isib)",
2022 /* Send event to BT-API */
2023 _bt_send_event(BT_GATT_SERVER_EVENT,
2024 BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED,
2030 static void __bt_handle_gatt_mtu_changed_event(event_gatts_mtu_changed_t *event)
2032 int result = BLUETOOTH_ERROR_NONE;
2033 struct gatt_client_info_t *conn_info = NULL;
2034 GVariant *param = NULL;
2037 conn_info = __bt_find_remote_gatt_client_info_from_conn_id(event->conn_id);
2038 if (conn_info == NULL) {
2039 BT_ERR("Cant find connection Information");
2042 BT_INFO("Got connection Info GATT client [%s] MTU Size [%d]",
2043 conn_info->addr, event->mtu_size);
2045 __bt_update_mtu_gatt_device(conn_info->addr, event->mtu_size);
2047 param = g_variant_new("(isqy)",
2053 /* Send event to BT-API */
2054 _bt_send_event(BT_GATT_SERVER_EVENT,
2055 BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED,
2059 static void __bt_gatt_event_handler(int event_type, gpointer event_data)
2061 BT_INFO("OAL event = 0x%x, \n", event_type);
2062 switch (event_type) {
2063 case OAL_EVENT_BLE_SERVER_INSTANCE_INITIALISED: {
2064 BT_INFO("OAL Event: Server Instance Registered");
2065 /* GATT Server Registered event is handled in MAIN thread context */
2066 __bt_handle_server_instance_registered((event_gatts_register_t *)event_data);
2069 case OAL_EVENT_GATTS_SERVICE_ADDED: {
2070 BT_INFO("OAL Event: GATT Service added");
2071 __bt_handle_gatt_server_service_added((event_gatts_srvc_prm_t *)event_data);
2074 case OAL_EVENT_GATTS_CHARACTERISTIC_ADDED: {
2075 BT_INFO("OAL Event: GATT characteristic added");
2076 __bt_handle_gatt_server_characteristic_added((event_gatts_srvc_charctr_t *)event_data);
2079 case OAL_EVENT_GATTS_DESCRIPTOR_ADDED: {
2080 BT_INFO("OAL Event: GATT descriptor added");
2081 __bt_handle_gatt_server_descriptor_added((event_gatts_srvc_descr_t *)event_data);
2084 case OAL_EVENT_GATTS_SERVICE_STARTED: {
2085 BT_INFO("OAL Event: GATT Service started");
2086 __bt_handle_gatt_server_service_started((event_gatts_srvc_t *)event_data);
2089 case OAL_EVENT_GATTS_SERVICE_STOPED: {
2090 BT_INFO("OAL Event: GATT Service stopped");
2091 __bt_handle_gatt_server_service_stopped((event_gatts_srvc_t *)event_data);
2094 case OAL_EVENT_GATTS_SERVICE_DELETED: {
2095 BT_INFO("OAL Event: GATT Service deleted");
2096 __bt_handle_gatt_server_service_deleted((event_gatts_srvc_t *) event_data);
2099 case OAL_EVENT_GATTS_CONNECTION_COMPLETED: {
2100 BT_INFO("OAL Event: GATT Server Connected");
2101 __bt_handle_gatt_server_connection_state((event_gatts_conn_t *)event_data);
2104 case OAL_EVENT_GATTS_DISCONNECTION_COMPLETED: {
2105 BT_INFO("OAL Event: GATT Server Disconnected");
2106 __bt_handle_gatt_server_disconnection_state((event_gatts_conn_t *)event_data);
2109 case OAL_EVENT_GATTS_REQUEST_READ: {
2110 BT_INFO("OAL Event: GATT Server Read Request");
2111 __bt_handle_gatt_server_read_requested((event_gatts_srvc_read_attr_t *)event_data);
2114 case OAL_EVENT_GATTS_REQUEST_WRITE: {
2115 BT_INFO("OAL Event: GATT Server Write Request");
2116 __bt_handle_gatt_server_write_requested((event_gatts_srvc_write_attr_t *)event_data);
2119 case OAL_EVENT_GATTS_REQUEST_ACQUIRE_WRITE: {
2120 BT_INFO("OAL Event: GATT Server Acquire Write Request");
2121 __bt_handle_gatt_server_acquire_write_requested((event_gatts_srvc_acquire_attr_t*)event_data);
2124 case OAL_EVENT_GATTS_REQUEST_ACQUIRE_NOTIFY: {
2125 BT_INFO("OAL Event: GATT ServerAcquire Notify Request");
2126 __bt_handle_gatt_server_acquire_notify_requested((event_gatts_srvc_acquire_attr_t*)event_data);
2129 case OAL_EVENT_GATTS_IND_CONFIRM: {
2130 BT_INFO("OAL Event: GATT Server Indication confirmed");
2131 __bt_handle_gatt_server_indicate_confirmed((event_gatts_ind_cnfrm_t *)event_data);
2134 case OAL_EVENT_GATTS_NOTIFICATION: { /* Tizen Platform Specific */
2135 BT_INFO("OAL Event: GATT Server DisConnected");
2136 __bt_handle_gatt_server_notification_changed((event_gatts_notif_t *)event_data);
2139 case OAL_EVENT_GATTS_MTU_CHANGED: {
2140 BT_INFO("OAL Event: GATT Server MTU changed event callback");
2141 __bt_handle_gatt_mtu_changed_event((event_gatts_mtu_changed_t *)event_data);
2144 #ifdef TIZEN_GATT_CLIENT
2145 case OAL_EVENT_GATTC_REGISTRATION: {
2146 BT_INFO("OAL Event: GATT Client instance Registered");
2147 __bt_handle_client_instance_registered((event_gattc_register_t *) event_data);
2150 case OAL_EVENT_GATTC_CONNECTION_COMPLETED: {
2151 BT_INFO("OAL Event: GATT Client Connected");
2152 __bt_handle_client_connected((event_gattc_conn_t *) event_data);
2155 case OAL_EVENT_GATTC_DISCONNECTION_COMPLETED: {
2156 BT_INFO("OAL Event: GATT Client DisConnected");
2157 __bt_handle_client_disconnected((event_gattc_conn_t *) event_data);
2160 case OAL_EVENT_GATTC_SERVICE_SEARCH_RESULT: {
2161 BT_INFO("OAL Event: GATT Client Service Search Result");
2162 __bt_handle_client_service_search_result((event_gattc_service_result_t *) event_data);
2165 case OAL_EVENT_GATTC_SERVICE_SEARCH_DONE: {
2166 BT_INFO("OAL Event: GATT Client Service Completed");
2167 __bt_handle_client_service_search_completed((event_gattc_conn_status_t *) event_data);
2170 case OAL_EVENT_GATTC_CHARAC_SERACH_RESULT: {
2171 BT_INFO("OAL Event: GATT Client Characteristic Search Result");
2172 __bt_handle_client_characteristic_search_result((event_gattc_characteristic_result_t *) event_data);
2175 case OAL_EVENT_GATTC_DESC_SERACH_RESULT: {
2176 BT_INFO("OAL Event: GATT Client Descriptor Search Result");
2177 __bt_handle_client_descriptor_search_result((event_gattc_descriptor_result_t *) event_data);
2180 case OAL_EVENT_GATTC_READ_CHARAC: {
2181 BT_INFO("OAL Event: GATT Client Characteristic Read Data");
2182 __bt_handle_client_characteristic_read_data((event_gattc_read_data *) event_data);
2185 case OAL_EVENT_GATTC_READ_DESCR: {
2186 BT_INFO("OAL Event: GATT Client Descriptor Read Data");
2187 __bt_handle_client_descriptor_read_data((event_gattc_read_data *) event_data);
2190 case OAL_EVENT_GATTC_WRITE_CHARAC: {
2191 BT_INFO("OAL Event: GATT Client Characteristic Write Data");
2192 __bt_handle_client_characteristic_write_data((event_gattc_write_data *) event_data);
2195 case OAL_EVENT_GATTC_WRITE_DESCR: {
2196 BT_INFO("OAL Event: GATT Client Descriptor Write Data");
2197 __bt_handle_client_descriptor_write_data((event_gattc_write_data *) event_data);
2200 case OAL_EVENT_DEVICE_LE_DISCONNECTED: {
2201 BT_INFO("OAL Event: LE device disconnected");
2202 __bt_hanlde_le_device_disconnection((event_dev_conn_status_t *)event_data);
2205 case OAL_EVENT_GATTC_NOTIFICATION_REGISTERED: {
2206 BT_INFO("OAL Event: GATT Client Notification Registered");
2207 __bt_handle_client_notification_registered((event_gattc_regdereg_notify_t *) event_data, TRUE);
2210 case OAL_EVENT_GATTC_NOTIFICATION_DEREGISTERED: {
2211 BT_INFO("OAL Event: GATT Client Notification Registered");
2212 __bt_handle_client_notification_registered((event_gattc_regdereg_notify_t *) event_data, FALSE);
2215 case OAL_EVENT_GATTC_NOTIFY_DATA: {
2216 BT_INFO("OAL Event: GATT Client Notification Data");
2217 __bt_handle_client_notification_data((event_gattc_notify_data *) event_data);
2220 case OAL_EVENT_GATTC_SERVICE_CHANGED_IND: {
2221 BT_INFO("OAL Event: GATT Client service changed indication");
2222 __bt_handle_client_service_changed_ind((event_gattc_service_changed_data *)event_data);
2225 case OAL_EVENT_GATTC_MTU_EXCHANGE_COMPLETED: {
2226 BT_INFO("OAL Event: GATT Client MTU Exchange Complete");
2227 __bt_handle_client_mtu_exchange_completed((event_gattc_mtu_configured_t *) event_data);
2236 int _bt_gatt_server_add_service(char *sender, int service_type,
2237 int num_handles, char *svc_uuid, int instance_id)
2239 BT_CHECK_PARAMETER(svc_uuid, return);
2240 BT_CHECK_PARAMETER(sender, return);
2241 int ret = OAL_STATUS_SUCCESS;
2243 oal_gatt_srvc_id_t svc_data;
2245 svc_data.is_prmry = service_type;
2246 svc_data.id.inst_id = instance_id;
2248 BT_INFO("Service UUID [%s] Num handles [%d] Instance ID [%d]", svc_uuid, num_handles, instance_id);
2249 _bt_string_to_uuid(svc_uuid, (service_uuid_t*)&svc_data.id.uuid);
2251 ret = gatts_add_service(instance_id, &svc_data, num_handles);
2252 if (ret != OAL_STATUS_SUCCESS) {
2253 BT_ERR("ret: %d", ret);
2254 return BLUETOOTH_ERROR_INTERNAL;
2257 return BLUETOOTH_ERROR_NONE;
2261 int _bt_gatt_server_add_included_service(char *sender, int instance_id,
2262 int service_handle, int included_svc_handle)
2264 BT_CHECK_PARAMETER(sender, return);
2265 int ret = OAL_STATUS_SUCCESS;
2267 ret = gatts_add_included_services(instance_id, service_handle, included_svc_handle);
2268 if (ret != OAL_STATUS_SUCCESS) {
2269 BT_ERR("ret: %d", ret);
2270 return BLUETOOTH_ERROR_INTERNAL;
2272 return BLUETOOTH_ERROR_NONE;
2275 int _bt_gatt_server_add_characteristic(char *sender, char *char_uuid,
2276 bluetooth_gatt_server_attribute_params_t *param)
2278 BT_CHECK_PARAMETER(char_uuid, return);
2279 BT_CHECK_PARAMETER(sender, return);
2280 BT_CHECK_PARAMETER(param, return);
2281 int ret = OAL_STATUS_SUCCESS;
2283 oal_uuid_t uuid = {{0} };
2285 BT_INFO("Char UUID [%s] Instance ID [%d]", char_uuid, param->instance_id);
2286 _bt_string_to_uuid(char_uuid, (service_uuid_t*)&uuid);
2288 BT_INFO("Char permission From API [0x%x]", param->permissions);
2290 ret = gatts_add_characteristics(param->instance_id, param->service_handle, &uuid,
2291 param->properties, (int)param->permissions);
2292 if (ret != OAL_STATUS_SUCCESS) {
2293 BT_ERR("ret: %d", ret);
2294 return BLUETOOTH_ERROR_INTERNAL;
2296 return BLUETOOTH_ERROR_NONE;
2299 int _bt_gatt_server_add_descriptor(char *sender, char *desc_uuid,
2300 bt_gatt_permission_t *param, int service_handle, int instance_id)
2302 BT_CHECK_PARAMETER(desc_uuid, return);
2303 BT_CHECK_PARAMETER(sender, return);
2304 BT_CHECK_PARAMETER(param, return);
2305 int ret = OAL_STATUS_SUCCESS;
2307 oal_uuid_t uuid = {{0} };
2309 BT_INFO("Descriptor UUID [%s] Instance ID [%d] Service handle [%d]",
2310 desc_uuid, service_handle, instance_id);
2312 _bt_string_to_uuid(desc_uuid, (service_uuid_t*)&uuid);
2314 BT_INFO("Descriptor permission From API [0x%x]", *param);
2315 ret = gatts_add_descriptor(instance_id, service_handle, &uuid, (int)*param);
2317 if (ret != OAL_STATUS_SUCCESS) {
2318 BT_ERR("ret: %d", ret);
2319 return BLUETOOTH_ERROR_INTERNAL;
2321 return BLUETOOTH_ERROR_NONE;
2324 int _bt_gatt_server_start_service(char *sender, int service_handle, int instance_id)
2326 BT_CHECK_PARAMETER(sender, return);
2327 int ret = OAL_STATUS_SUCCESS;
2329 ret = gatts_start_service(instance_id, service_handle, BT_GATT_TRANSPORT_LE);
2330 if (ret != OAL_STATUS_SUCCESS) {
2331 BT_ERR("ret: %d", ret);
2332 return BLUETOOTH_ERROR_INTERNAL;
2334 return BLUETOOTH_ERROR_NONE;
2337 int _bt_gatt_server_stop_service(char *sender, int service_handle, int instance_id)
2339 BT_CHECK_PARAMETER(sender, return);
2340 int ret = OAL_STATUS_SUCCESS;
2342 ret = gatts_stop_service(instance_id, service_handle);
2343 if (ret != OAL_STATUS_SUCCESS) {
2344 BT_ERR("ret: %d", ret);
2345 return BLUETOOTH_ERROR_INTERNAL;
2347 return BLUETOOTH_ERROR_NONE;
2350 int _bt_gatt_server_delete_service(char *sender, int service_handle, int instance_id)
2352 BT_CHECK_PARAMETER(sender, return);
2353 int ret = OAL_STATUS_SUCCESS;
2357 ret = gatts_delete_service(instance_id, service_handle);
2358 if (ret != OAL_STATUS_SUCCESS) {
2359 BT_ERR("ret: %d", ret);
2360 return BLUETOOTH_ERROR_INTERNAL;
2363 /* Remove the Service Handle */
2364 for (l = numapps[instance_id].service_handles; l != NULL;) {
2366 l = g_slist_next(l);
2367 if (handle && *handle == service_handle) {
2368 BT_INFO("Remove Service handle [%d]", *handle);
2369 numapps[instance_id].service_handles = g_slist_remove(numapps[instance_id].service_handles, handle);
2375 return BLUETOOTH_ERROR_NONE;
2378 int _bt_gatt_server_send_response(char *sender, bluetooth_gatt_att_data_t *data,
2379 bluetooth_gatt_server_response_params_t *param)
2381 BT_CHECK_PARAMETER(sender, return);
2382 BT_CHECK_PARAMETER(data, return);
2383 BT_CHECK_PARAMETER(param, return);
2384 struct gatt_server_req_info *req_info = NULL;
2385 int ret = OAL_STATUS_SUCCESS;
2387 oal_gatt_response_t response;
2389 BT_INFO("GATT Server Response: Req Type [%d] req_id [%d] status [%d] auth_req [%d] offset[%d] data len[%d]",
2390 param->req_type, param->request_id,
2391 param->response_status, param->auth_req,
2392 data->offset, data->length);
2394 /* Search for matching Request in List */
2395 req_info = __bt_gatt_server_find_request_info(param->request_id, param->req_type);
2397 BT_ERR("GATT Server Req Info not found for current response..return Error");
2398 return BLUETOOTH_ERROR_NOT_IN_OPERATION;
2401 memset(&response, 0x00, sizeof(oal_gatt_response_t));
2403 response.handle = req_info->attribute_handle;
2404 response.attr_value.auth_req = param->auth_req;
2405 response.attr_value.handle = req_info->attribute_handle;
2406 response.attr_value.offset = data->offset;
2407 response.attr_value.len = data->length;
2408 memcpy(&response.attr_value.value, &data->data, data->length);
2411 ret = gatts_send_response(req_info->connection_id, param->request_id,
2412 param->response_status, &response);
2414 if (ret != OAL_STATUS_SUCCESS) {
2415 BT_ERR("ret: %d", ret);
2416 return BLUETOOTH_ERROR_INTERNAL;
2419 BT_INFO("GATT Server Response successfully sent");
2420 /* Remove GATT server request from list */
2421 gatt_server_requests = g_slist_remove(gatt_server_requests, req_info);
2422 g_free(req_info->addr);
2424 return BLUETOOTH_ERROR_NONE;
2427 int _bt_gatt_server_acquire_send_response(char *sender, bluetooth_gatt_server_acquire_response_params_t *param , void *fd_list)
2429 BT_CHECK_PARAMETER(sender, return);
2430 BT_CHECK_PARAMETER(param, return);
2431 struct gatt_server_req_info *req_info = NULL;
2432 int ret = OAL_STATUS_SUCCESS;
2435 BT_INFO("GATT acquire Server Response: Req Type [%d] req_id [%d] fd [%d] mtu[%d]",
2436 param->req_type, param->request_id,
2440 /* Search for matching Request in List */
2441 req_info = __bt_gatt_server_find_request_info(param->request_id, param->req_type);
2443 BT_ERR("GATT acquire Server Req Info not found for current response..return Error");
2444 return BLUETOOTH_ERROR_NOT_IN_OPERATION;
2447 ret = gatt_send_response_acquire(req_info->connection_id, param->request_id, 0, param->fd, param->mtu, fd_list);
2449 if (ret != OAL_STATUS_SUCCESS) {
2450 BT_ERR("ret: %d", ret);
2451 return BLUETOOTH_ERROR_INTERNAL;
2454 BT_INFO("GATT acquire Server Response successfully sent");
2455 /* Remove GATT server request from list */
2456 gatt_server_requests = g_slist_remove(gatt_server_requests, req_info);
2457 g_free(req_info->addr);
2459 return BLUETOOTH_ERROR_NONE;
2464 int _bt_gatt_server_send_indication(char *sender, bluetooth_device_address_t *dev_addr,
2465 bluetooth_gatt_att_data_t *data,
2466 bluetooth_gatt_server_indication_params_t *param)
2468 BT_CHECK_PARAMETER(sender, return);
2469 BT_CHECK_PARAMETER(data, return);
2470 BT_CHECK_PARAMETER(param, return);
2472 gboolean all_send = FALSE;
2473 int ret = OAL_STATUS_SUCCESS;
2474 struct gatt_client_info_t *conn;
2476 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2477 _bt_convert_addr_type_to_string(address, dev_addr->addr);
2479 if (memcmp(dev_addr->addr, BDADDR_ANY, 6) == 0) {
2480 BT_INFO("GATT Server: Send Indication to all connected GATT clients..");
2483 BT_INFO("GATT Server: Send Indication to connected GATT client addr [%s]", address);
2486 /* Attempt to send Notification/Indication to all Connected GATT clients */
2488 ret = __bt_gatt_send_indication_to_all_connected_clients(data, param);
2489 if (ret != OAL_STATUS_SUCCESS) {
2490 BT_ERR("ret: %d", ret);
2492 return BLUETOOTH_ERROR_INTERNAL;
2496 conn = _bt_find_remote_gatt_client_info(address);
2498 ret = gatts_send_indication(param->instance_id, param->atrribute_handle,
2499 conn->connection_id, data->length,
2500 param->need_confirmation, (char *)(&data->data[0]));
2502 if (ret != OAL_STATUS_SUCCESS) {
2503 BT_ERR("ret: %d", ret);
2504 BT_INFO("Indication failed to send to Remote GATT Client [%s]", address);
2506 return BLUETOOTH_ERROR_INTERNAL;
2508 BT_INFO("Indication sent to Remote GATT Client [%s] wait for Notification completed event from OAL", address);
2510 num_indicate_clients = 1;
2511 return BLUETOOTH_ERROR_NONE;
2513 BT_ERR("Remote GATT client [%s] is not connected..Cant send Indication!!", address);
2515 return BLUETOOTH_ERROR_NOT_CONNECTED;
2518 return BLUETOOTH_ERROR_NONE;
2521 int _bt_gatt_server_update_attribute_value(char *sender, int instance_id,
2522 bluetooth_gatt_server_update_value_t *param)
2524 BT_CHECK_PARAMETER(sender, return);
2525 BT_CHECK_PARAMETER(param, return);
2526 int ret = OAL_STATUS_SUCCESS;
2528 oal_gatt_value_t value;
2529 BT_INFO("GATT Server Update value: Instance ID [%d] attr handle [%d] Value len [%d]",
2530 instance_id, param->attribute_handle, param->length);
2533 memset(&value, 0x00, sizeof(oal_gatt_value_t));
2535 value.handle = param->attribute_handle;
2536 value.len = param->length;
2537 memcpy(&value.value, ¶m->data.data, param->length);
2539 ret = gatts_update_att_value(instance_id, &value);
2541 if (ret != OAL_STATUS_SUCCESS) {
2542 BT_ERR("ret: %d", ret);
2543 return BLUETOOTH_ERROR_INTERNAL;
2546 BT_INFO("GATT Server Update Attribute Value successfully");
2547 return BLUETOOTH_ERROR_NONE;
2550 int _bt_request_att_mtu(bluetooth_device_address_t *device_address,
2553 struct gatt_server_info_t *conn_info = NULL;
2555 int ret = OAL_STATUS_SUCCESS;
2557 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
2558 _bt_convert_addr_type_to_string(addr, device_address->addr);
2560 /* Check if remote GATT Server is connected or not */
2561 conn_info = _bt_find_remote_gatt_server_info(addr);
2563 BT_INFO("GATT Server [%s] is connected, conn Id [%d]",
2564 conn_info->addr, conn_info->connection_id);
2566 BT_ERR("GATT Server is not yet connected..");
2568 return BLUETOOTH_ERROR_NOT_CONNECTED;
2571 ret = gattc_configure_mtu(conn_info->connection_id, mtu);
2572 if (ret != OAL_STATUS_SUCCESS) {
2573 BT_ERR("ret: %d", ret);
2575 return BLUETOOTH_ERROR_INTERNAL;
2579 return BLUETOOTH_ERROR_NONE;
2582 int _bt_get_att_mtu(bluetooth_device_address_t *address,
2585 BT_CHECK_PARAMETER(address, return);
2586 BT_CHECK_PARAMETER(mtu, return);
2587 struct gatt_client_info_t *conn_info = NULL;
2588 char addr[BT_ADDRESS_STRING_SIZE] = { 0 };
2589 int ret = OAL_STATUS_SUCCESS;
2592 _bt_convert_addr_type_to_string(addr, address->addr);
2594 BT_INFO("Get current MTU size for the remote client:DevAddress:[%s]", addr);
2596 conn_info = _bt_find_remote_gatt_client_info(addr);
2598 BT_INFO("GATT Client [%s] is connected, conn Id [%d] Instance ID [%d]",
2599 conn_info->addr, conn_info->connection_id, conn_info->instance_id);
2601 BT_ERR("GATT Client [%s] is not yet connected..", addr);
2602 return BLUETOOTH_ERROR_NOT_CONNECTED;
2605 ret = gatts_get_att_mtu(conn_info->connection_id, &stack_mtu);
2606 if (ret != OAL_STATUS_SUCCESS) {
2607 BT_ERR("ret: %d", ret);
2608 return BLUETOOTH_ERROR_INTERNAL;
2611 BT_INFO("ATT MTU received from OAL [%d]", stack_mtu);
2612 *mtu = (unsigned int)stack_mtu;
2615 BT_ERR("MTU value is zero, GATT Client [%s] is not yet connected..", addr);
2616 return BLUETOOTH_ERROR_NOT_CONNECTED;
2619 return BLUETOOTH_ERROR_NONE;
2622 #ifdef TIZEN_GATT_CLIENT
2623 /* GATT Client utility static functions */
2624 static bt_gatt_service_info_list_t *__bt_get_service_info_list(int conn_id)
2627 bt_gatt_service_info_list_t *info = NULL;
2629 for (l = list_gatt_info; l != NULL; l = g_slist_next(l)) {
2630 info = (bt_gatt_service_info_list_t *)l->data;
2634 if (info->conn_id == conn_id)
2641 static bt_gatt_service_info_t *__bt_find_matching_service(
2642 bt_gatt_service_info_list_t *svc_list, oal_gatt_srvc_id_t *svc)
2645 bt_gatt_service_info_t *info = NULL;
2647 for (l = svc_list->services; l != NULL; l = g_slist_next(l)) {
2648 info = (bt_gatt_service_info_t *)l->data;
2652 /* Match UUID and instance ID */
2653 if (!memcmp(&svc->id.uuid.uuid, &info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN)
2654 && (svc->id.inst_id == info->inst_id)) {
2661 static bt_gatt_char_info_t *__bt_find_matching_charc(
2662 bt_gatt_service_info_t *svc_info, oal_gatt_id_t *charc)
2665 bt_gatt_char_info_t *info = NULL;
2667 for (l = svc_info->chars; l != NULL; l = g_slist_next(l)) {
2668 info = (bt_gatt_char_info_t *)l->data;
2672 /* Match UUID and instance ID */
2673 if (!memcmp(&charc->uuid.uuid, &info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN)
2674 && (charc->inst_id == info->inst_id)) {
2681 static bt_gatt_descriptor_info_t *__bt_find_matching_desc(
2682 bt_gatt_char_info_t *char_info, oal_gatt_id_t *desc)
2685 bt_gatt_descriptor_info_t *info = NULL;
2687 for (l = char_info->descs; l != NULL; l = g_slist_next(l)) {
2688 info = (bt_gatt_descriptor_info_t *)l->data;
2692 /* Match UUID and instance ID */
2693 if (!memcmp(&desc->uuid, &info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN)
2694 && (desc->inst_id == info->inst_id)) {
2702 static struct gatt_server_info_t *__bt_find_remote_gatt_server_info_from_conn_id(int conn_id)
2705 struct gatt_server_info_t *info = NULL;
2707 for (l = gatt_server_info_list; l != NULL; l = g_slist_next(l)) {
2708 info = (struct gatt_server_info_t*)l->data;
2712 if (info->connection_id == conn_id) {
2713 BT_INFO("Remote GATT server found addr[%s]", info->addr);
2720 static bt_gatt_service_info_t* __bt_find_removed_service(bt_gatt_service_info_list_t *svc_list)
2723 bt_gatt_service_info_t *info = NULL;
2725 for (l = svc_list->services; l != NULL; l = g_slist_next(l)) {
2726 info = (bt_gatt_service_info_t*)l->data;
2730 /* Service is marked a removed */
2731 if (info->is_removed == 1)
2737 static void __bt_remove_service_info_from_list(bt_gatt_service_info_t *svc_info)
2743 bt_gatt_char_info_t *charc = NULL;
2744 bt_gatt_included_service_info_t *incl = NULL;
2745 bt_gatt_descriptor_info_t *desc = NULL;
2747 /* Remove all Characteristic and Descriptors within characteristic */
2748 for (l = svc_info->chars; l != NULL;) {
2749 charc = (bt_gatt_char_info_t*)l->data;
2750 l = g_slist_next(l); /* Incase if l is removed, saving next to l */
2755 /* Inside Characteristic */
2756 for (l1 = charc->descs; l1 != NULL;) {
2758 desc = (bt_gatt_descriptor_info_t*)l1->data;
2759 l1 = g_slist_next(l1);
2764 /* Remove Descriptor */
2765 charc->descs = g_slist_remove(charc->descs, desc);
2768 /* Remove Characteristic */
2769 svc_info->chars = g_slist_remove(svc_info->chars, charc);
2773 /* Remove all Included Services */
2774 for (l2 = svc_info->included_svcs; l2 != NULL;) {
2775 incl = (bt_gatt_included_service_info_t*)l2->data;
2776 l2 = g_slist_next(l2); /* Incase if l is removed, saving next to l */
2781 /* Remove included service */
2782 svc_info->included_svcs = g_slist_remove(svc_info->included_svcs, incl);
2789 static void __bt_build_service_browse_info(int conn_id,
2790 bt_services_browse_info_t* info)
2793 bt_gatt_service_info_list_t *svc_info_list;
2794 bt_gatt_service_info_t *svc_info;
2796 service_uuid_t uuid;
2797 struct gatt_server_info_t *conn_info = NULL;
2799 char uuid_string[BLUETOOTH_UUID_STRING_MAX];
2801 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(conn_id);
2806 _bt_convert_addr_string_to_type(info->device_addr.addr, conn_info->addr);
2808 svc_info_list = __bt_get_service_info_list(conn_id);
2812 info->count = g_slist_length(svc_info_list->services);
2813 BT_DBG("Total services present in the svc info list for this conn id [%d] is [%d]",
2814 conn_id, info->count);
2816 for (l = svc_info_list->services; l != NULL; l = g_slist_next(l)) {
2817 svc_info = (bt_gatt_service_info_t*)l->data;
2818 if (svc_info == NULL)
2821 memcpy(&uuid.uuid, &svc_info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
2822 _bt_uuid_to_string(&uuid, uuid_string);
2824 BT_INFO("[%d] %s [%s]", count, uuid_string, _bt_convert_uuid_to_string(uuid_string));
2826 /* Fill UUID of service */
2827 g_strlcpy(info->uuids[count], uuid_string,
2828 BLUETOOTH_UUID_STRING_MAX);
2830 /* Fill instance ID of service */
2831 info->inst_id[count] = svc_info->inst_id;
2833 /* Fill primary service or not info */
2834 info->primary[count] = svc_info->is_primary;
2836 /* Increment count of services browsed */
2841 static void __bt_build_char_browse_info(int conn_id,
2842 bt_gatt_service_info_t *svc_info,
2843 bt_char_browse_info_t* info)
2846 bt_gatt_char_info_t *char_info;
2847 service_uuid_t uuid;
2849 struct gatt_server_info_t *conn_info = NULL;
2851 char uuid_string[BLUETOOTH_UUID_STRING_MAX];
2853 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(conn_id);
2857 /* Fill default data, this will be required even in case of failure */
2858 _bt_convert_addr_string_to_type(info->device_addr.addr, conn_info->addr);
2859 memcpy(&info->svc_uuid, svc_info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
2860 info->svc_inst_id = svc_info->inst_id;
2862 if (!svc_info->chars) {
2863 BT_ERR("No Chars browsed for address [%s]", conn_info->addr);
2867 info->count = g_slist_length(svc_info->chars);
2869 for (l = svc_info->chars; l != NULL; l = g_slist_next(l)) {
2870 char_info = (bt_gatt_char_info_t*)l->data;
2871 if (char_info == NULL)
2874 memcpy(&uuid.uuid, &char_info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
2875 _bt_uuid_to_string(&uuid, uuid_string);
2877 /* Fill UUID of characteristic */
2878 g_strlcpy(info->uuids[count], uuid_string,
2879 BLUETOOTH_UUID_STRING_MAX);
2881 /* Fill instance ID of characteristic */
2882 info->inst_id[count] = char_info->inst_id;
2884 /* Fill property of characteristic */
2885 info->props[count] = char_info->props;
2887 /* Increment count of services browsed */
2890 BT_DBG("Total characteristics browsed [%d]", count);
2893 static void __bt_build_descriptor_browse_info(int conn_id,
2894 bt_gatt_service_info_t *svc_info,
2895 bt_gatt_char_info_t *char_info,
2896 bt_descriptor_browse_info_t* info)
2899 bt_gatt_descriptor_info_t *desc_info;
2901 service_uuid_t uuid;
2902 struct gatt_server_info_t *conn_info = NULL;
2904 char uuid_string[BLUETOOTH_UUID_STRING_MAX];
2906 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(conn_id);
2908 /* Fill default data, this will be required even in case of failure */
2909 _bt_convert_addr_string_to_type(info->device_addr.addr, conn_info->addr);
2910 memcpy(&info->svc_uuid, svc_info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
2911 info->svc_inst_id = svc_info->inst_id;
2912 memcpy(&info->char_uuid, char_info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
2913 info->char_inst_id = char_info->inst_id;
2915 /* Fill property of the parent characteristic of this descriptor */
2916 info->char_props_map = char_info->props;
2918 info->count = g_slist_length(char_info->descs);
2920 if (!char_info->descs) {
2921 BT_ERR("No Descriptors browsed for address [%s]", conn_info->addr);
2925 for (l = char_info->descs; l != NULL; l = g_slist_next(l)) {
2926 desc_info = (bt_gatt_descriptor_info_t*)l->data;
2927 if (desc_info == NULL)
2930 memcpy(&uuid.uuid, &desc_info->uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
2931 _bt_uuid_to_string(&uuid, uuid_string);
2933 /* Fill UUID of Descriptor */
2934 g_strlcpy(info->uuids[count], uuid_string,
2935 BLUETOOTH_UUID_STRING_MAX);
2937 /* Fill instance ID of Descriptor */
2938 info->inst_id[count] = desc_info->inst_id;
2941 /* Increment count of Descriptor browsed */
2945 BT_INFO("Total descriptors browsed [%d]", count);
2948 static void __bt_free_service_info(bt_gatt_service_info_t *svc)
2950 GSList *ll, *lll, *llll;
2951 bt_gatt_char_info_t *chr = NULL;
2952 bt_gatt_descriptor_info_t *desc = NULL;
2953 bt_gatt_included_service_info_t *incl_svc = NULL;
2955 BT_DBG("Service info Is Prim[%d] Inst ID [%d]", svc->is_primary, svc->inst_id);
2956 /* Delete all chars and its descriptors */
2957 for (ll = svc->chars; ll != NULL; ) {
2958 chr = (bt_gatt_char_info_t *)ll->data;
2959 ll = g_slist_next(ll);
2963 for (lll = chr->descs; lll != NULL; ) {
2964 desc = (bt_gatt_descriptor_info_t *)lll->data;
2965 lll = g_slist_next(lll);
2968 chr->descs = g_slist_remove(chr->descs, desc);
2971 svc->chars = g_slist_remove(svc->chars, chr);
2975 /* Delete all included services */
2976 for (llll = svc->included_svcs; llll != NULL; ) {
2977 incl_svc = (bt_gatt_included_service_info_t *)llll->data;
2978 llll = g_slist_next(llll);
2979 if (incl_svc == NULL)
2981 svc->included_svcs = g_slist_remove(svc->included_svcs, incl_svc);
2986 static void __bt_cleanup_remote_services(struct gatt_server_info_t *conn_info)
2988 bt_gatt_service_info_list_t *svc_info_list = NULL;
2989 bt_gatt_service_info_t *svc = NULL;
2992 svc_info_list = __bt_get_service_info_list(conn_info->connection_id);
2993 if (!svc_info_list) {
2994 BT_INFO("Could not find Svc Info list for the connection ID [%d]",
2995 conn_info->connection_id);
2999 BT_INFO("Start Cleanup of all services. Num Services [%d]", g_slist_length(svc_info_list->services));
3000 for (l = svc_info_list->services; l != NULL; ) {
3001 svc = (bt_gatt_service_info_t *)l->data;
3002 l = g_slist_next(l);
3006 __bt_free_service_info(svc);
3007 svc_info_list->services = g_slist_remove(svc_info_list->services, svc);
3011 list_gatt_info = g_slist_remove(list_gatt_info, svc_info_list);
3012 g_free(svc_info_list);
3015 int _bt_register_gatt_client_instance(const char *sender,
3016 bluetooth_device_address_t *address)
3018 int ret = OAL_STATUS_SUCCESS;
3019 char *uuid_string = NULL;
3024 /* App should ensure that it should not send */
3025 BT_INFO("### Check on which instance GATT Client instance can be initialized....");
3026 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
3027 if (numapps[k].is_initialized == 1) {
3028 BT_INFO("Instance ID [%d] is already in use..Check next slot",
3029 numapps[k].instance_id);
3032 BT_INFO("Time to register GATT client instancer..UUID to be used is [%s] slot [%d]",
3033 uuid_list[slot-1], slot);
3039 BT_ERR("No Slot if free for GATT Client registration..");
3040 return BLUETOOTH_ERROR_REGISTRATION_FAILED;
3043 uuid_string = g_malloc0(BT_UUID_STRING_MAX);
3044 _bt_string_to_uuid(uuid_list[slot-1], (service_uuid_t*)&uuid);
3045 g_strlcpy(uuid_string, uuid_list[slot-1], BT_UUID_STRING_MAX);
3046 BT_INFO("Copied UUID string [%s]", uuid_string);
3048 /* Register GATT Client */
3049 ret = gattc_register(&uuid);
3050 if (ret != OAL_STATUS_SUCCESS) {
3051 BT_ERR("ret: %d", ret);
3052 g_free(uuid_string);
3053 return BLUETOOTH_ERROR_INTERNAL;
3056 BT_INFO("GATT Client registration call successfully accepted by OAL..wait for Instance Initialized event from OAL..");
3058 /* Return & wait for GATT Client Instance Initialization event */
3059 memset(numapps[slot].sender, 0x00, sizeof(numapps[slot].sender));
3060 memset(numapps[slot].uuid, 0x00, sizeof(numapps[slot].uuid));
3062 g_strlcpy(numapps[slot].sender, sender, sizeof(numapps[slot].sender));
3063 g_strlcpy(numapps[slot].uuid, uuid_string, sizeof(numapps[slot].uuid));
3065 /* Address is saved here. When event comes, sender + address are matched for replying pending
3066 request. It is impossible for same sender to have requests with two same addresses */
3067 memcpy(&numapps[slot].address.addr, address->addr, sizeof(bluetooth_device_address_t));
3069 BT_INFO("Slot [%d] occupied", slot);
3070 numapps[slot].is_initialized = TRUE; /* Set initialization to true here itself */
3072 g_free(uuid_string);
3073 return BLUETOOTH_ERROR_NONE;
3079 /* GATT client events */
3080 static void __bt_handle_client_instance_registered(event_gattc_register_t *data)
3082 bt_service_app_info_t *info = NULL;
3084 char *uuid_string = g_malloc0(BT_UUID_STRING_MAX);
3086 _bt_uuid_to_string(&(data->client_uuid), uuid_string);
3087 BT_INFO("CLient ID is Initialized [%d] UUID initialized [%s]", data->client_if, uuid_string);
3089 /* Platform GATT client framwork does not use Default GATT client instance
3090 This GATT client instance is never deregistred in the lifetime of bt-service */
3091 if (g_strcmp0(uuid_string, DEFAULT_GATT_CLIENT_UUID) == 0) {
3092 BT_INFO("Default client Instance Registered");
3093 gatt_default_client = data->client_if;
3094 g_free(uuid_string);
3098 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
3101 if (g_strcmp0(info->uuid, uuid_string) == 0) {
3102 BT_INFO("Found GATT client.. sender [%s] Slot [%d] occupied", info->sender, k);
3103 info->is_initialized = TRUE;
3104 info->client_id = data->client_if;
3105 __bt_gatt_handle_pending_request_info(BLUETOOTH_ERROR_NONE, BT_GATT_CLIENT_REGISTER,
3106 (void*)info, sizeof(bt_service_app_info_t));
3110 g_free(uuid_string);
3113 static void __bt_handle_client_connected(event_gattc_conn_t *event_data)
3115 int result = BLUETOOTH_ERROR_NONE;
3116 struct gatt_server_info_t *conn_info = NULL;
3117 struct gatt_out_conn_info_t *out_conn_info = NULL;
3119 GVariant *param = NULL;
3121 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
3122 _bt_convert_addr_type_to_string(address,
3123 (unsigned char *)event_data->address.addr);
3125 if (event_data->status != OAL_STATUS_SUCCESS)
3126 result = BLUETOOTH_ERROR_INTERNAL;
3128 /* DBUS Return fo BT_CONNECT_LE for all the apps */
3129 __bt_gatt_handle_pending_request_info(result, BT_CONNECT_LE, address,
3130 BT_ADDRESS_STRING_SIZE);
3132 BT_INFO("Local GATT Client Connected: Remote addr[%s] Client Interface [%d] Connection ID [%d] status[%d]",
3133 address, event_data->client_if, event_data->conn_id, event_data->status);
3135 if (result == BLUETOOTH_ERROR_NONE) {
3136 /* Check if device is already in connected list */
3137 conn_info = _bt_find_remote_gatt_server_info(address);
3140 /* Send event to BT-API */
3141 param = g_variant_new("(is)", result, address);
3142 _bt_send_event(BT_DEVICE_EVENT,
3143 BLUETOOTH_EVENT_GATT_CLIENT_CONNECTED, /* Local device is GATT client */
3146 /* Save Connection info */
3147 conn_info = g_new0(struct gatt_server_info_t, 1);
3148 conn_info->addr = g_strdup(address);
3149 conn_info->client_id = event_data->client_if;
3150 conn_info->connection_id = event_data->conn_id;
3151 gatt_server_info_list = g_slist_append(gatt_server_info_list, conn_info);
3152 BT_DBG("Total num of connected Remote GATT server devices [%d]",
3153 g_slist_length(gatt_server_info_list));
3156 BT_INFO("Do a Internal refresh");
3157 if (OAL_STATUS_SUCCESS != gattc_refresh(conn_info->client_id, &event_data->address))
3158 BT_ERR("GATT database refresh failed!!");
3160 BT_INFO("GATT database refresh Success!!");
3163 BT_ERR("Local GATT Client connected event for addr[%s], but device is in connected list already", address);
3165 __bt_add_mtu_gatt_device(address);
3167 BT_ERR("GATT Client Connection failed!!");
3169 /* If outgoing connection Info is present, then remove it */
3170 out_conn_info = __bt_find_gatt_outgoing_conn_info(address);
3171 if (out_conn_info) {
3172 BT_ERR("Outgoing Client connect request was sent");
3173 outgoing_gatt_conn_list = g_slist_remove(outgoing_gatt_conn_list, out_conn_info);
3174 g_free(out_conn_info->addr);
3175 g_free(out_conn_info);
3180 static void __bt_handle_client_disconnected(event_gattc_conn_t *event_data)
3182 int result = BLUETOOTH_ERROR_NONE;
3184 struct gatt_server_info_t *conn_info = NULL;
3185 struct gatt_out_conn_info_t *out_conn_info = NULL;
3187 GVariant *param = NULL;
3189 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
3190 _bt_convert_addr_type_to_string(address,
3191 (unsigned char *)event_data->address.addr);
3193 if (event_data->status != OAL_STATUS_SUCCESS)
3194 result = BLUETOOTH_ERROR_INTERNAL;
3196 if (NULL == _bt_get_request_info_data(BT_DISCONNECT_LE, address)) {
3197 if (NULL != _bt_get_request_info_data(BT_CONNECT_LE, address)) {
3198 result = BLUETOOTH_ERROR_INTERNAL;
3199 __bt_gatt_handle_pending_request_info(result, BT_CONNECT_LE,
3200 address, BT_ADDRESS_STRING_SIZE);
3201 BT_ERR("Failed to connect Local GATT Remote addr[%s]", address);
3206 /* DBUS Return for BT_DISCONNECT_LE for all the apps */
3207 __bt_gatt_handle_pending_request_info(result, BT_DISCONNECT_LE, address,
3208 BT_ADDRESS_STRING_SIZE);
3210 BT_INFO("Local GATT Client DisConnected: Remote addr[%s] Client Interface [%d] Connection ID [%d] status [%d]",
3211 address, event_data->client_if, event_data->conn_id, event_data->status);
3213 /* Remove Connection info */
3214 conn_info = _bt_find_remote_gatt_server_info(address);
3217 param = g_variant_new("(is)", result, address);
3218 /* Send event to application */
3219 _bt_send_event(BT_DEVICE_EVENT,
3220 BLUETOOTH_EVENT_GATT_CLIENT_DISCONNECTED,
3223 BT_INFO("Remove GATT server info from List..");
3224 /* Remove all services from info list_gatt_info */
3225 __bt_cleanup_remote_services(conn_info);
3227 /* Remove info from List */
3228 gatt_server_info_list = g_slist_remove(gatt_server_info_list, conn_info);
3229 BT_INFO("Total num of connected GATT servers [%d]", g_slist_length(gatt_server_info_list));
3230 g_free(conn_info->addr);
3233 BT_INFO("Can not find conn info, already removed!");
3235 __bt_remove_mtu_gatt_device(address);
3237 /* If outgoing connection Info is present, then remove it */
3238 out_conn_info = __bt_find_gatt_outgoing_conn_info(address);
3239 if (out_conn_info) {
3240 BT_ERR("Client Disconnected event, but outgoing connect request was sent");
3241 outgoing_gatt_conn_list = g_slist_remove(outgoing_gatt_conn_list, out_conn_info);
3242 g_free(out_conn_info->addr);
3243 g_free(out_conn_info);
3249 static void __bt_handle_client_service_search_result(
3250 event_gattc_service_result_t *event_data)
3252 /* Pre: status is never fail from OAL */
3254 /* Find service list from address */
3255 bt_gatt_service_info_list_t *svc_info_list;
3256 bt_gatt_service_info_t *svc_info;
3258 svc_info_list = __bt_get_service_info_list(event_data->conn_status.conn_id);
3259 if (!svc_info_list) {
3260 BT_DBG("Service info list not present for connection ID %d, means first time browse", event_data->conn_status.conn_id);
3261 /* Means for this conn_id, no services are ever browsed, first time,
3262 create service info list for this conn_id */
3263 svc_info_list = g_malloc0(sizeof(bt_gatt_service_info_list_t));
3264 svc_info_list->conn_id = event_data->conn_status.conn_id;
3265 list_gatt_info = g_slist_append(list_gatt_info, svc_info_list);
3268 /* send list and current service's uuid and instance id to find it */
3269 svc_info = __bt_find_matching_service(svc_info_list, &event_data->srvc_id);
3272 /* If not found, check if service changed, if yes, means this is a new service added
3273 in remote GATT device, update uuid info in svc info list structure, to be used when
3274 search is completed */
3276 if (svc_info_list->info.is_changed) {
3277 BT_DBG("Service Changed indication already found for connection ID %d", event_data->conn_status.conn_id);
3278 memcpy(svc_info_list->info.uuid, event_data->srvc_id.id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3280 /* Create and add new service in service list */
3281 svc_info = g_malloc0(sizeof(bt_gatt_service_info_t));
3282 memcpy(svc_info->uuid, event_data->srvc_id.id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3283 svc_info->inst_id = event_data->srvc_id.id.inst_id;
3284 svc_info->is_primary = event_data->srvc_id.is_prmry;
3285 svc_info_list->services = g_slist_append(svc_info_list->services, svc_info);
3286 BT_DBG("Service created and added in Svc info list or connection ID %d", event_data->conn_status.conn_id);
3288 /* If returned matching service info, then just update service_rmeoved value inside it to 0 */
3289 svc_info->is_removed = 0;
3293 static void __bt_handle_client_service_search_completed(
3294 event_gattc_conn_status_t *event_data)
3296 struct gatt_server_info_t *conn_info = NULL;
3297 bt_gatt_service_info_list_t *svc_info_list;
3298 bt_gatt_service_info_t *svc_info;
3299 bt_services_browse_info_t browse_info;
3300 unsigned char uuid_empty[BLUETOOTH_UUID_HEX_MAX_LEN];
3302 memset(&uuid_empty, 0x00, BLUETOOTH_UUID_HEX_MAX_LEN);
3303 memset(&browse_info, 0x00, sizeof(bt_services_browse_info_t));
3304 BT_INFO("Primary Services browsing completed status[%d] conn ID [%d]",
3305 event_data->status, event_data->conn_id);
3307 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(event_data->conn_id);
3309 svc_info_list = __bt_get_service_info_list(event_data->conn_id);
3310 if (!svc_info_list) {
3311 BT_ERR("No services browsed ever for addr [%s]", conn_info->addr);
3313 /* Just build response and return ERROR */
3314 __bt_build_service_browse_info(event_data->conn_id, &browse_info);
3316 __bt_gatt_handle_pending_request_info(BLUETOOTH_ERROR_INTERNAL,
3317 BT_GATT_GET_PRIMARY_SERVICES, &browse_info,
3318 sizeof(bt_services_browse_info_t));
3322 /* If fail, then send event with error */
3323 if (event_data->status != OAL_STATUS_SUCCESS) {
3324 /* Just build response and return ERROR */
3325 __bt_build_service_browse_info(event_data->conn_id, &browse_info);
3327 __bt_gatt_handle_pending_request_info(BLUETOOTH_ERROR_INTERNAL,
3328 BT_GATT_GET_PRIMARY_SERVICES, &browse_info,
3329 sizeof(bt_services_browse_info_t));
3333 /* If success, then find service info list from address */
3335 /* If svc_changed == 1 and uuid valid, means a new service is added*/
3336 if (svc_info_list->info.is_changed && !memcmp(uuid_empty, svc_info_list->info.uuid, BLUETOOTH_UUID_HEX_MAX_LEN)) {
3337 /* TODO: Send event -Service added with instance ID and UUID of newly added service */
3338 BT_INFO("new service added");
3340 BT_INFO("TODO new service added");
3343 /* If svc_changed == 1 and uuid invalid, then a service is removed */
3344 if (svc_info_list->info.is_changed && memcmp(uuid_empty, svc_info_list->info.uuid, BLUETOOTH_UUID_HEX_MAX_LEN)) {
3345 /* Scan through the service info list to find service with is_removed = 1*/
3346 svc_info = __bt_find_removed_service(svc_info_list);
3348 /* TODO Send event - Service removed with instance ID and UUID of just rmeoved service */
3350 /* Remove that service info from service info list */
3351 svc_info_list->services = g_slist_remove(svc_info_list->services, svc_info);
3353 /* Delete that service completely from svc_info list*/
3354 __bt_remove_service_info_from_list(svc_info);
3358 /* Reset svc_changed = 0, and reset UUID = all 0's */
3359 svc_info_list->info.is_changed = 0;
3360 memset(&svc_info_list->info.uuid, 0x00, BLUETOOTH_UUID_HEX_MAX_LEN);
3362 /* Build Reply and send to service browse primary services request of pending apps */
3363 __bt_build_service_browse_info(event_data->conn_id, &browse_info);
3365 __bt_gatt_handle_pending_request_info(BLUETOOTH_ERROR_NONE,
3366 BT_GATT_GET_PRIMARY_SERVICES, &browse_info,
3367 sizeof(bt_services_browse_info_t));
3371 static void __bt_handle_client_characteristic_search_result(
3372 event_gattc_characteristic_result_t *event_data)
3374 bt_gatt_service_info_list_t *svc_info_list;
3375 bt_gatt_service_info_t *svc_info;
3376 bt_gatt_char_info_t *char_info;
3377 bt_char_browse_info_t browse_info;
3379 memset(&browse_info, 0x00, sizeof(bt_char_browse_info_t));
3382 if (event_data->conn_status.status == OAL_STATUS_SUCCESS) {
3383 /* Find service info list from address */
3384 svc_info_list = __bt_get_service_info_list(event_data->conn_status.conn_id);
3385 if (svc_info_list == NULL) {
3386 BT_ERR("svc_info_list is NULL");
3391 /* Find matching service info from svc info list */
3392 svc_info = __bt_find_matching_service(svc_info_list, &event_data->srvc_id);
3393 if (svc_info == NULL) {
3394 BT_ERR("svc_info is NULL");
3398 /* Find Matching char from service info in event */
3399 char_info = __bt_find_matching_charc(svc_info, &event_data->char_id);
3401 /* If not found, then add new characteristic and return */
3403 BT_DBG("Add new characteristic");
3404 char_info = g_malloc0(sizeof(bt_gatt_char_info_t));
3405 memcpy(char_info->uuid, event_data->char_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3407 char_info->inst_id = event_data->char_id.inst_id;
3408 char_info->props = event_data->char_prop;
3409 svc_info->chars = g_slist_append(svc_info->chars, char_info);
3411 /* If found, then return */
3412 BT_DBG("update char property as Characteristic browsed is already present");
3413 char_info->props |= event_data->char_prop;
3416 /* If Not success: Means Charc browse is completed */
3417 /* Find char list from service in event */
3418 /* Find service list from address */
3419 svc_info_list = __bt_get_service_info_list(event_data->conn_status.conn_id);
3420 if (svc_info_list == NULL) {
3421 BT_ERR("svc_info_list is NULL");
3425 /* Find service info from service in event */
3426 svc_info = __bt_find_matching_service(svc_info_list, &event_data->srvc_id);
3427 if (svc_info == NULL) {
3428 BT_ERR("svc_info is NULL");
3432 /* Build char list from service in event */
3433 __bt_build_char_browse_info(event_data->conn_status.conn_id,
3434 svc_info, &browse_info);
3436 /* Create response and return by sending event*/
3437 /* Build Reply and send to service browse All Included services request of pending apps */
3438 __bt_gatt_handle_pending_request_info(BLUETOOTH_ERROR_NONE,
3439 BT_GATT_GET_SERVICE_PROPERTIES,
3441 sizeof(bt_char_browse_info_t));
3445 static void __bt_handle_client_descriptor_search_result(
3446 event_gattc_descriptor_result_t *event_data)
3448 bt_gatt_service_info_list_t *svc_info_list;
3449 bt_gatt_service_info_t *svc_info;
3450 bt_gatt_char_info_t *char_info;
3451 bt_gatt_descriptor_info_t *desc_info;
3452 bt_descriptor_browse_info_t browse_info;
3454 BT_INFO("descriptor search result status [%d]", event_data->conn_status.status);
3456 memset(&browse_info, 0x00, sizeof(bt_descriptor_browse_info_t));
3459 if (event_data->conn_status.status == OAL_STATUS_SUCCESS) {
3460 /* Find service list from address */
3461 svc_info_list = __bt_get_service_info_list(event_data->conn_status.conn_id);
3462 if (svc_info_list == NULL) {
3463 BT_ERR("svc_info_list is NULL");
3467 svc_info = __bt_find_matching_service(svc_info_list, &event_data->srvc_id);
3468 if (svc_info == NULL) {
3469 BT_ERR("svc_info is NULL");
3473 char_info = __bt_find_matching_charc(svc_info, &event_data->char_id);
3474 if (char_info == NULL) {
3475 BT_ERR("char_info is NULL");
3479 desc_info = __bt_find_matching_desc(char_info, &event_data->descr_id);
3480 /* If not found, add new descriptor and return */
3482 desc_info = g_malloc0(sizeof(bt_gatt_descriptor_info_t));
3483 memcpy(desc_info->uuid, event_data->descr_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3485 desc_info->inst_id = event_data->descr_id.inst_id;
3486 char_info->descs = g_slist_append(char_info->descs, desc_info);
3489 /* If found, then return */
3490 BT_INFO("Characteristic browsed is already presesnt");
3493 /* If Not success */
3494 /* Find service list from address */
3495 /* Find included service list from service in event */
3496 /* Create response and return by sending event*/
3497 svc_info_list = __bt_get_service_info_list(event_data->conn_status.conn_id);
3498 if (svc_info_list == NULL) {
3499 BT_ERR("svc_info_list is NULL");
3503 /* Find service info from service in event */
3504 svc_info = __bt_find_matching_service(svc_info_list, &event_data->srvc_id);
3505 if (svc_info == NULL) {
3506 BT_ERR("svc_info is NULL");
3510 /* Find char info from char in event */
3511 char_info = __bt_find_matching_charc(svc_info, &event_data->char_id);
3512 if (char_info == NULL) {
3513 BT_ERR("char_info is NULL");
3517 /* Build descriptor list from char in event */
3518 __bt_build_descriptor_browse_info(event_data->conn_status.conn_id,
3519 svc_info, char_info, &browse_info);
3522 __bt_gatt_handle_pending_request_info(BLUETOOTH_ERROR_NONE,
3523 BT_GATT_GET_CHARACTERISTIC_PROPERTIES,
3525 sizeof(bt_descriptor_browse_info_t));
3529 static void __bt_handle_client_characteristic_read_data(
3530 event_gattc_read_data *event_data)
3532 int result = BLUETOOTH_ERROR_NONE;
3533 struct gatt_server_info_t *conn_info = NULL;
3534 bluetooth_gatt_client_char_prop_info_t read_info;
3536 /* Read Information data structures */
3537 GVariant *param = NULL;
3538 GVariant *data = NULL;
3539 GVariant *data_svc_uuid = NULL;
3540 GVariant *data_char_uuid = NULL;
3541 char *read_val = NULL;
3542 char *svc_uuid = NULL;
3543 char *char_uuid = NULL;
3546 //memset(&read_info, 0x00, sizeof(bt_gatt_handle_property_t));
3547 memset(&read_info, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3549 /* Extract Address from conn_id of event data */
3550 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(
3551 event_data->uuid_status.conn_status.conn_id);
3553 BT_INFO("Characteristic Read result from addr [%s] status [%d]",
3554 conn_info->addr, event_data->uuid_status.conn_status.status);
3556 /* Fill char in buffer */
3557 memcpy(&read_info.characteristic.uuid,
3558 event_data->uuid_status.char_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3559 read_info.characteristic.instance_id = event_data->uuid_status.char_id.inst_id;
3561 /* Fill Service in buffer */
3562 memcpy(&read_info.svc.uuid,
3563 event_data->uuid_status.srvc_id.id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3564 read_info.svc.instance_id = event_data->uuid_status.srvc_id.id.inst_id;
3566 /* Fill remote device address */
3567 _bt_convert_addr_string_to_type(read_info.device_address.addr, conn_info->addr);
3569 /* Fill data and reply to all apps waiting for Read result on the same characteristic
3570 Note: Even in case of failure, address, handles and result code should be returned */
3571 if (event_data->uuid_status.conn_status.status != OAL_STATUS_SUCCESS)
3572 result = BLUETOOTH_ERROR_INTERNAL;
3574 if (event_data->data_len > 0) {
3576 // for (i = 0; i < event_data->data_len; i++)
3577 // BT_INFO("Data[%d] = [0x%x]", i, event_data->data[i]);
3580 read_val = g_memdup(&event_data->data[0], event_data->data_len);
3582 data = g_variant_new_from_data(
3583 G_VARIANT_TYPE_BYTESTRING,
3585 event_data->data_len,
3588 BT_ERR("Characteristic Read success, but no data!!!");
3590 data = g_variant_new_from_data(
3591 G_VARIANT_TYPE_BYTESTRING,
3598 svc_uuid = g_memdup(&event_data->uuid_status.srvc_id.id.uuid.uuid[0], uuid_len);
3600 data_svc_uuid = g_variant_new_from_data(
3601 G_VARIANT_TYPE_BYTESTRING,
3607 char_uuid = g_memdup(&event_data->uuid_status.char_id.uuid.uuid[0], uuid_len);
3609 data_char_uuid = g_variant_new_from_data(
3610 G_VARIANT_TYPE_BYTESTRING,
3615 param = g_variant_new("(isn@ayin@ayin@ay)", result,
3619 event_data->uuid_status.srvc_id.id.inst_id,
3622 event_data->uuid_status.char_id.inst_id,
3623 event_data->data_len,
3627 _bt_send_event(BT_GATT_CLIENT_EVENT,
3628 BLUETOOTH_EVENT_GATT_READ_CHAR,
3631 /* Send DBUS return */
3632 __bt_gatt_handle_pending_request_info(result,
3633 BT_GATT_READ_CHARACTERISTIC,
3635 sizeof(bluetooth_gatt_client_char_prop_info_t));
3646 static void __bt_handle_client_descriptor_read_data(
3647 event_gattc_read_data *event_data)
3649 int result = BLUETOOTH_ERROR_NONE;
3650 struct gatt_server_info_t *conn_info = NULL;
3651 bluetooth_gatt_client_desc_prop_info_t read_info;
3653 /* Read Information data structures */
3654 GVariant *param = NULL;
3655 GVariant *data = NULL;
3656 GVariant *data_svc_uuid = NULL;
3657 GVariant *data_char_uuid = NULL;
3658 GVariant *data_desc_uuid = NULL;
3659 char *read_val = NULL;
3660 char *svc_uuid = NULL;
3661 char *char_uuid = NULL;
3662 char *desc_uuid = NULL;
3667 memset(&read_info, 0x00, sizeof(bluetooth_gatt_client_desc_prop_info_t));
3669 /* Extract Address from conn_id of event data */
3670 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(
3671 event_data->uuid_status.conn_status.conn_id);
3673 BT_INFO("Descriptor Read result from addr [%s] status [%d]",
3674 conn_info->addr, event_data->uuid_status.conn_status.status);
3676 /* Fill descriptor informations in buffer */
3677 memcpy(&read_info.descriptor.uuid,
3678 event_data->uuid_status.descr_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3679 read_info.descriptor.instance_id = event_data->uuid_status.descr_id.inst_id;
3681 /* Fill Characteristic informations in buffer */
3682 memcpy(&read_info.characteristic.uuid,
3683 event_data->uuid_status.char_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3684 read_info.characteristic.instance_id = event_data->uuid_status.char_id.inst_id;
3686 /* Fill Service informations in buffer */
3687 memcpy(&read_info.svc.uuid,
3688 event_data->uuid_status.srvc_id.id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3689 read_info.svc.instance_id = event_data->uuid_status.srvc_id.id.inst_id;
3691 /* Fill remote device address */
3692 _bt_convert_addr_string_to_type(read_info.device_address.addr, conn_info->addr);
3694 /* Fill data and reply to all apps waiting for Read result on the same characteristic */
3695 if (event_data->uuid_status.conn_status.status != OAL_STATUS_SUCCESS)
3696 result = BLUETOOTH_ERROR_INTERNAL;
3698 BT_INFO("desc data len:%d", event_data->data_len);
3699 if (event_data->data_len > 0) {
3701 for (i = 0; i < event_data->data_len; i++)
3702 BT_DBG("Data[%d] = [0x%x]", i, event_data->data[i]);
3705 read_val = g_memdup(&event_data->data[0], event_data->data_len);
3707 data = g_variant_new_from_data(
3708 G_VARIANT_TYPE_BYTESTRING,
3710 event_data->data_len,
3713 BT_INFO("Descriptor Read success, but no data!!!");
3715 data = g_variant_new_from_data(
3716 G_VARIANT_TYPE_BYTESTRING,
3722 svc_uuid = g_memdup(&event_data->uuid_status.srvc_id.id.uuid.uuid[0], uuid_len);
3724 data_svc_uuid = g_variant_new_from_data(
3725 G_VARIANT_TYPE_BYTESTRING,
3731 char_uuid = g_memdup(&event_data->uuid_status.char_id.uuid.uuid[0], uuid_len);
3733 data_char_uuid = g_variant_new_from_data(
3734 G_VARIANT_TYPE_BYTESTRING,
3740 desc_uuid = g_memdup(&event_data->uuid_status.descr_id.uuid.uuid[0], uuid_len);
3742 data_desc_uuid = g_variant_new_from_data(
3743 G_VARIANT_TYPE_BYTESTRING,
3748 param = g_variant_new("(isn@ayin@ayin@ayin@ay)", result,
3752 event_data->uuid_status.srvc_id.id.inst_id,
3755 event_data->uuid_status.char_id.inst_id,
3758 event_data->uuid_status.descr_id.inst_id,
3759 event_data->data_len,
3763 _bt_send_event(BT_GATT_CLIENT_EVENT,
3764 BLUETOOTH_EVENT_GATT_READ_DESC,
3767 BT_INFO("Send DBUS rpely for GATT Read Descriptor");
3768 /* Send DBUS return */
3769 __bt_gatt_handle_pending_request_info(result,
3770 BT_GATT_READ_DESCRIPTOR_VALUE,
3772 sizeof(bluetooth_gatt_client_desc_prop_info_t));
3783 static void __bt_handle_client_characteristic_write_data(
3784 event_gattc_write_data *event_data)
3786 int result = BLUETOOTH_ERROR_NONE;
3787 struct gatt_server_info_t *conn_info = NULL;
3788 bluetooth_gatt_client_char_prop_info_t write_info;
3790 /* Read Information data structures */
3791 GVariant *param = NULL;
3792 GVariant *data_svc_uuid = NULL;
3793 GVariant *data_char_uuid = NULL;
3794 char *svc_uuid = NULL;
3795 char *char_uuid = NULL;
3799 memset(&write_info, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3801 /* Extract Address from conn_id of event data */
3802 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(
3803 event_data->conn_status.conn_id);
3805 BT_INFO("Characteristic Write callback from addr [%s] status [%d]",
3806 conn_info->addr, event_data->conn_status.status);
3808 /* Fill char in buffer */
3809 memcpy(&write_info.characteristic.uuid,
3810 event_data->char_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3811 write_info.characteristic.instance_id = event_data->char_id.inst_id;
3813 /* Fill Service in buffer */
3814 memcpy(&write_info.svc.uuid,
3815 event_data->srvc_id.id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3816 write_info.svc.instance_id = event_data->srvc_id.id.inst_id;
3818 /* Fill remote device address */
3819 _bt_convert_addr_string_to_type(write_info.device_address.addr, conn_info->addr);
3821 if (event_data->conn_status.status != OAL_STATUS_SUCCESS) {
3822 result = BLUETOOTH_ERROR_INTERNAL;
3828 svc_uuid = g_memdup(&event_data->srvc_id.id.uuid.uuid[0], uuid_len);
3830 data_svc_uuid = g_variant_new_from_data(
3831 G_VARIANT_TYPE_BYTESTRING,
3837 char_uuid = g_memdup(&event_data->char_id.uuid.uuid[0], uuid_len);
3839 data_char_uuid = g_variant_new_from_data(
3840 G_VARIANT_TYPE_BYTESTRING,
3845 param = g_variant_new("(isn@ayin@ayi)", result,
3849 event_data->srvc_id.id.inst_id,
3852 event_data->char_id.inst_id);
3855 _bt_send_event(BT_GATT_CLIENT_EVENT,
3856 BLUETOOTH_EVENT_GATT_WRITE_CHAR,
3865 /* Send DBUS return */
3866 __bt_gatt_handle_pending_request_info(result,
3867 BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE,
3869 sizeof(bluetooth_gatt_client_char_prop_info_t));
3873 static void __bt_handle_client_descriptor_write_data(
3874 event_gattc_write_data *event_data)
3876 int result = BLUETOOTH_ERROR_NONE;
3877 struct gatt_server_info_t *conn_info = NULL;
3878 bluetooth_gatt_client_desc_prop_info_t write_info;
3880 /* Write Information data structures */
3881 GVariant *param = NULL;
3882 GVariant *data_svc_uuid = NULL;
3883 GVariant *data_char_uuid = NULL;
3884 GVariant *data_desc_uuid = NULL;
3885 char *svc_uuid = NULL;
3886 char *char_uuid = NULL;
3887 char *desc_uuid = NULL;
3891 memset(&write_info, 0x00, sizeof(bluetooth_gatt_client_desc_prop_info_t));
3893 /* Extract Address from conn_id of event data */
3894 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(
3895 event_data->conn_status.conn_id);
3897 if (NULL == conn_info) {
3899 BT_INFO("Failed to get the conn info for conn_id [%d]", event_data->conn_status.conn_id);
3903 BT_INFO("Descriptor Write callback from addr [%s] status [%d]",
3904 conn_info->addr, event_data->conn_status.status);
3906 /* Fill descriptor informations in buffer */
3907 memcpy(&write_info.descriptor.uuid,
3908 event_data->descr_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3909 write_info.descriptor.instance_id = event_data->descr_id.inst_id;
3911 /* Fill Characteristic informations in buffer */
3912 memcpy(&write_info.characteristic.uuid,
3913 event_data->char_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3914 write_info.characteristic.instance_id = event_data->char_id.inst_id;
3916 /* Fill Service informations in buffer */
3917 memcpy(&write_info.svc.uuid,
3918 event_data->srvc_id.id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
3919 write_info.svc.instance_id = event_data->srvc_id.id.inst_id;
3921 /* Fill remote device address */
3922 _bt_convert_addr_string_to_type(write_info.device_address.addr, conn_info->addr);
3924 if (event_data->conn_status.status != OAL_STATUS_SUCCESS) {
3925 result = BLUETOOTH_ERROR_INTERNAL;
3931 svc_uuid = g_memdup(&event_data->srvc_id.id.uuid.uuid[0], uuid_len);
3933 data_svc_uuid = g_variant_new_from_data(
3934 G_VARIANT_TYPE_BYTESTRING,
3940 char_uuid = g_memdup(&event_data->char_id.uuid.uuid[0], uuid_len);
3942 data_char_uuid = g_variant_new_from_data(
3943 G_VARIANT_TYPE_BYTESTRING,
3949 desc_uuid = g_memdup(&event_data->descr_id.uuid.uuid[0], uuid_len);
3951 data_desc_uuid = g_variant_new_from_data(
3952 G_VARIANT_TYPE_BYTESTRING,
3957 param = g_variant_new("(isn@ayin@ayin@ayi)", result,
3961 event_data->srvc_id.id.inst_id,
3964 event_data->char_id.inst_id,
3967 event_data->descr_id.inst_id);
3970 _bt_send_event(BT_GATT_CLIENT_EVENT,
3971 BLUETOOTH_EVENT_GATT_WRITE_DESC,
3982 /* Send DBUS return */
3983 __bt_gatt_handle_pending_request_info(result,
3984 BT_GATT_WRITE_DESCRIPTOR_VALUE,
3986 sizeof(bluetooth_gatt_client_desc_prop_info_t));
3989 static void __bt_hanlde_le_device_disconnection(event_dev_conn_status_t *event_data)
3991 int result = BLUETOOTH_ERROR_INTERNAL;
3992 char *address = g_malloc0(BT_ADDRESS_STRING_SIZE);
3994 _bt_convert_addr_type_to_string(address, (unsigned char *)event_data->address.addr);
3996 /* DBUS Return with fail of pending BT_CONNECT_LE for all the apps */
3997 BT_INFO("Local GATT Client disconnected: Remote addr[%s] ", address);
3999 __bt_gatt_handle_pending_request_info(result, BT_CONNECT_LE, address,
4000 BT_ADDRESS_STRING_SIZE);
4004 static void __bt_handle_client_notification_registered(
4005 event_gattc_regdereg_notify_t *event_data,
4006 gboolean is_registered)
4008 int result = BLUETOOTH_ERROR_NONE;
4009 struct gatt_server_info_t *conn_info = NULL;
4010 bt_gatt_notif_reg_info_t notif_info;
4013 memset(¬if_info, 0x00, sizeof(bt_gatt_notif_reg_info_t));
4015 BT_INFO("Client Interface [%d] status [%d]",
4016 event_data->client_if,
4017 event_data->status);
4019 /* Extract Address from conn_id of event data */
4020 conn_info = __bt_find_remote_gatt_server_info_from_client_if(
4021 event_data->client_if);
4024 BT_INFO("Connection Info is not present, return");
4027 BT_INFO("Notification Registered for addr [%s]",
4031 /* Fill svc informations in buffer */
4032 memcpy(¬if_info.svc_uuid,
4033 event_data->srvc_id.id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4034 notif_info.svc_inst = event_data->srvc_id.id.inst_id;
4036 /* Fill char in buffer */
4037 memcpy(¬if_info.char_uuid,
4038 event_data->char_id.uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4039 notif_info.char_inst = event_data->char_id.inst_id;
4041 /* Fill remote device address */
4042 _bt_convert_addr_string_to_type(notif_info.addr.addr, conn_info->addr);
4044 notif_info.is_registered = is_registered;
4046 if (event_data->status != OAL_STATUS_SUCCESS)
4047 result = BLUETOOTH_ERROR_INTERNAL;
4049 /* Send DBUS Return for BT_GATT_WATCH_CHARACTERISTIC */
4050 __bt_gatt_handle_pending_request_info(result,
4051 BT_GATT_WATCH_CHARACTERISTIC,
4053 sizeof(bt_gatt_notif_reg_info_t));
4056 static void __bt_handle_client_notification_data(event_gattc_notify_data *event_data)
4058 /* No status in this event from OAL */
4059 int result = BLUETOOTH_ERROR_NONE;
4061 /* Read Information data structures */
4062 GVariant *param = NULL;
4063 GVariant *data = NULL;
4064 GVariant *data_svc_uuid = NULL;
4065 GVariant *data_char_uuid = NULL;
4066 char *read_val = NULL;
4067 char *svc_uuid = NULL;
4068 char *char_uuid = NULL;
4074 BT_INFO("Notifcation of charc data changed");
4076 if (event_data->data_len > 0) {
4078 for (i = 0; i < event_data->data_len; i++)
4079 BT_INFO("Data[%d] = [0x%x]", i, event_data->data[i]);
4082 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
4083 _bt_convert_addr_type_to_string(addr,
4084 (unsigned char *)&(event_data->address.addr));
4087 read_val = g_memdup(&event_data->data[0], event_data->data_len);
4089 data = g_variant_new_from_data(
4090 G_VARIANT_TYPE_BYTESTRING,
4092 event_data->data_len,
4095 svc_uuid = g_memdup(&event_data->srvc_id.id.uuid.uuid[0], uuid_len);
4097 data_svc_uuid = g_variant_new_from_data(
4098 G_VARIANT_TYPE_BYTESTRING,
4104 char_uuid = g_memdup(&event_data->char_id.uuid.uuid[0], uuid_len);
4106 data_char_uuid = g_variant_new_from_data(
4107 G_VARIANT_TYPE_BYTESTRING,
4113 param = g_variant_new("(isn@ayin@ayin@ay)", result,
4117 event_data->srvc_id.id.inst_id,
4120 event_data->char_id.inst_id,
4121 event_data->data_len,
4125 _bt_send_event(BT_GATT_CLIENT_EVENT,
4126 BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED,
4129 BT_ERR("No Data!!");
4142 static void __bt_handle_client_service_changed_ind(event_gattc_service_changed_data *event_data)
4144 bt_gatt_service_info_list_t *svc_info_list;
4146 bt_gatt_service_info_t *svc_info;
4147 GVariant *param = NULL;
4148 char *address_str = NULL;
4149 char *uuid_str = NULL;
4151 svc_info_list = __bt_get_service_info_list(event_data->conn_id);
4152 if (svc_info_list == NULL) {
4153 BT_ERR("svc_info_list is NULL");
4157 if (event_data->change_type) {
4158 /* Add service UUID in list */
4159 svc_info = g_malloc0(sizeof(bt_gatt_service_info_t));
4160 memcpy(svc_info->uuid, event_data->uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4161 svc_info->inst_id = event_data->inst_id;
4162 svc_info->is_primary = 1; // TODO: Need to check is_primary is required or not
4163 svc_info_list->services = g_slist_append(svc_info_list->services, svc_info);
4164 BT_DBG("Service created and added in Svc info list or connection ID %d", event_data->conn_id);
4166 /* Remove service UUID in list */
4167 for (l = svc_info_list->services; l != NULL; l = g_slist_next(l)) {
4168 svc_info = (bt_gatt_service_info_t *)l->data;
4169 if (svc_info == NULL)
4172 if (!memcmp(svc_info->uuid, event_data->uuid.uuid, BLUETOOTH_UUID_HEX_MAX_LEN)) {
4173 svc_info_list->services = g_slist_remove(svc_info_list->services, svc_info);
4174 __bt_free_service_info(svc_info);
4180 address_str = g_malloc0(BT_ADDRESS_STRING_SIZE);
4181 uuid_str = g_malloc0(BT_UUID_STRING_MAX);
4182 _bt_convert_addr_type_to_string(address_str, event_data->address.addr);
4183 _bt_uuid_to_string(&event_data->uuid, uuid_str);
4185 param = g_variant_new("(iiss)", event_data->inst_id, event_data->change_type, address_str, uuid_str);
4187 _bt_send_event(BT_GATT_CLIENT_EVENT,
4188 BLUETOOTH_EVENT_GATT_CLIENT_SERVICE_CHANGED,
4190 g_free(address_str);
4194 gboolean _bt_is_remote_gatt_device_connected(bluetooth_device_address_t *address)
4197 struct gatt_server_info_t *conn_info = NULL;
4198 gboolean connected = FALSE;
4200 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
4201 _bt_convert_addr_type_to_string(addr,
4202 (unsigned char *)&(address->addr));
4204 BT_DBG("Check GATT connection status of [%s]", addr);
4205 /* Check if device is already in connected list */
4206 conn_info = _bt_find_remote_gatt_server_info(addr);
4209 BT_DBG("Remote GATT Server device [%s] is Connected", conn_info->addr);
4212 struct gatt_client_info_t *client_info = NULL;
4214 BT_INFO("Remote GATT Server Device [%s] is not Connected", addr);
4216 /* Check if device is already in connected list */
4217 client_info = _bt_find_remote_gatt_client_info(addr);
4220 BT_DBG("Remote Client device [%s] is Connected", client_info->addr);
4223 BT_INFO("Remote GATT Client Device [%s] is not Connected", addr);
4232 int _bt_connect_le_device(bluetooth_device_address_t *address,
4233 int auto_connect, int client_id)
4235 struct gatt_server_info_t *conn_info = NULL;
4236 struct gatt_out_conn_info_t *out_conn_info = NULL;
4238 invocation_info_t *req_info = NULL;
4239 int ret = OAL_STATUS_SUCCESS;
4241 char *remote_address = NULL;
4243 BT_CHECK_PARAMETER(address, return);
4245 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4246 _bt_convert_addr_type_to_string(addr, address->addr);
4247 BT_DBG("GATT Client connect request for address [%s] client instance [%d]",
4251 /* Check if Remote Device is already under connection progress */
4252 req_info = _bt_get_request_info_data_from_function_name(BT_CONNECT_LE);
4254 remote_address = (char*)req_info->user_data;
4255 if (remote_address && !strcasecmp(remote_address, addr)) {/* Address matched */
4256 BT_DBG("Already Connection ongoing for same remote GATT Server address [%s]", remote_address);
4257 /* Return and wait for events to be sent to all apps */
4259 return BLUETOOTH_ERROR_IN_PROGRESS;
4263 /* Check if remote GATT Server is connected or not */
4264 conn_info = _bt_find_remote_gatt_server_info(addr);
4266 BT_ERR("GATT Server is already connected..");
4268 return BLUETOOTH_ERROR_ALREADY_CONNECT;
4271 /* TODO Check Requirement of holding Advertisement before initiating LE connect */
4273 /* Check if app sent 0 client id for connection, in such case, use default gatt client ID */
4274 if (client_id == 0) {
4275 /* GATT CLient connect request sent by an app without any client instance [0] */
4276 BT_DBG("Assign default GATT client id [%d]", gatt_default_client);
4277 client_id = gatt_default_client;
4280 BT_INFO("Connect using CLient ID [%d]", client_id);
4281 ret = gattc_connect(client_id, (bt_address_t*)(address), auto_connect);
4283 if (ret != OAL_STATUS_SUCCESS) {
4284 BT_ERR("gattc_connect is failed. ret: %d", ret);
4286 return BLUETOOTH_ERROR_INTERNAL;
4289 /* Mark this as outgoing connection */
4290 out_conn_info = g_new0(struct gatt_out_conn_info_t, 1);
4291 out_conn_info->addr = g_strdup(addr);
4292 out_conn_info->client_id = client_id;
4293 BT_INFO("Added outgoing connection info addr[%s]", out_conn_info->addr);
4294 outgoing_gatt_conn_list = g_slist_append(outgoing_gatt_conn_list, out_conn_info);
4297 return BLUETOOTH_ERROR_NONE;
4300 int _bt_gatt_get_primary_services(char *address)
4302 BT_CHECK_PARAMETER(address, return);
4303 struct gatt_server_info_t *conn_info = NULL;
4304 invocation_info_t *req_info = NULL;
4305 int ret = OAL_STATUS_SUCCESS;
4308 /* Check if any app is already browsing primary services on the same remote GATT Server */
4309 req_info = _bt_get_request_info_data(BT_GATT_GET_PRIMARY_SERVICES, address);
4311 BT_INFO("Already Primary Service Browsing ongoing for same rmeote GATT Server");
4312 /* Return and wait for events to be sent to all apps */
4313 return BLUETOOTH_ERROR_NONE;
4316 /* Check if remote GATT Server is connected or not */
4317 conn_info = _bt_find_remote_gatt_server_info(address);
4319 BT_INFO("GATT Server [%s] is connected, conn Id [%d]",
4320 conn_info->addr, conn_info->connection_id);
4322 BT_ERR("GATT Server is not yet connected..");
4323 return BLUETOOTH_ERROR_NOT_CONNECTED;
4326 BT_INFO("Remove GATT server info from List..");
4327 /* Remove all services from info list_gatt_info */
4328 __bt_cleanup_remote_services(conn_info);
4330 /* Send Primary Service Browsing request to stack */
4331 ret = gattc_search_service(conn_info->connection_id, NULL);
4332 if (ret != OAL_STATUS_SUCCESS) {
4333 BT_ERR("ret: %d", ret);
4334 return BLUETOOTH_ERROR_INTERNAL;
4336 return BLUETOOTH_ERROR_NONE;
4339 int _bt_gatt_get_all_characteristic(bluetooth_gatt_client_svc_prop_info_t *svc)
4341 BT_CHECK_PARAMETER(svc, return);
4342 struct gatt_server_info_t *conn_info = NULL;
4343 invocation_info_t *req_info = NULL;
4344 bluetooth_gatt_client_svc_prop_info_t *prop;
4345 oal_gatt_srvc_id_t srvc_id;
4346 int ret = OAL_STATUS_SUCCESS;
4349 /* Check if any app is already browsing characteristics of the same service on the same remote GATT Server */
4350 req_info = _bt_get_request_info_data_from_function_name(BT_GATT_GET_SERVICE_PROPERTIES);
4352 prop = (bluetooth_gatt_client_svc_prop_info_t*)req_info->user_data;
4353 if (prop && !memcmp(svc->device_address.addr, prop->device_address.addr, sizeof(bluetooth_device_address_t))
4354 && memcmp(prop->svc.uuid, svc->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN)
4355 && prop->svc.instance_id == svc->svc.instance_id) {
4356 BT_INFO("Already Properties browsing for Primary Service ongoing for same remote GATT Server");
4357 /* Return and wait for events to be sent to all apps */
4358 return BLUETOOTH_ERROR_NONE;
4362 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4363 _bt_convert_addr_type_to_string(addr, svc->device_address.addr);
4365 /* Check if remote GATT Server is connected or not */
4366 conn_info = _bt_find_remote_gatt_server_info(addr);
4368 BT_DBG("GATT Server [%s] is connected, conn Id [%d]",
4369 conn_info->addr, conn_info->connection_id);
4371 BT_ERR("GATT Server is not yet connected..");
4373 return BLUETOOTH_ERROR_NOT_CONNECTED;
4376 srvc_id.is_prmry = TRUE;
4377 srvc_id.id.inst_id = svc->svc.instance_id;
4378 memcpy(srvc_id.id.uuid.uuid, svc->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4380 /* Search All Characteristic */
4381 ret = gattc_get_characteristic(conn_info->connection_id, &srvc_id, NULL);
4382 if (ret != OAL_STATUS_SUCCESS) {
4383 BT_ERR("ret: %d", ret);
4385 return BLUETOOTH_ERROR_INTERNAL;
4388 return BLUETOOTH_ERROR_NONE;
4391 int _bt_gatt_get_all_characteristic_properties(
4392 bluetooth_gatt_client_char_prop_info_t *chr)
4394 struct gatt_server_info_t *conn_info = NULL;
4395 invocation_info_t *req_info = NULL;
4396 bluetooth_gatt_client_char_prop_info_t *prop;
4397 oal_gatt_srvc_id_t srvc_id;
4398 oal_gatt_id_t char_id;
4399 int ret = OAL_STATUS_SUCCESS;
4402 BT_CHECK_PARAMETER(chr, return);
4404 /* Check if any app is already browsing descriptors of the same char of
4405 particular service on the same remote GATT Server */
4406 req_info = _bt_get_request_info_data_from_function_name(BT_GATT_GET_CHARACTERISTIC_PROPERTIES);
4408 prop = (bluetooth_gatt_client_char_prop_info_t*)req_info->user_data;
4409 if (prop && !memcmp(chr->device_address.addr, prop->device_address.addr, sizeof(bluetooth_device_address_t)) /* Address matched */
4410 && memcmp(chr->svc.uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Service UUID matched */
4411 && chr->svc.instance_id == prop->svc.instance_id /* Service Instance ID matched */
4412 && memcmp(chr->characteristic.uuid, prop->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Characteristic UUID matched */
4413 && chr->characteristic.instance_id == prop->characteristic.instance_id) { /* Characteristic Instance ID matched */
4414 BT_INFO("Already Properties browsing for Characteristic ongoing for same remote GATT Server");
4415 /* Return and wait for events to be sent to all apps */
4416 return BLUETOOTH_ERROR_NONE;
4420 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4421 _bt_convert_addr_type_to_string(addr, chr->device_address.addr);
4423 /* Check if remote GATT Server is connected or not */
4424 conn_info = _bt_find_remote_gatt_server_info(addr);
4426 BT_DBG("GATT Server [%s] is connected, conn Id [%d]",
4427 conn_info->addr, conn_info->connection_id);
4429 BT_ERR("GATT Server is not yet connected..");
4431 return BLUETOOTH_ERROR_NOT_CONNECTED;
4434 srvc_id.is_prmry = TRUE;
4435 srvc_id.id.inst_id = chr->svc.instance_id;
4436 memcpy(srvc_id.id.uuid.uuid, chr->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4438 char_id.inst_id = chr->characteristic.instance_id;
4439 memcpy(char_id.uuid.uuid, chr->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4441 /* Search All Descriptors */
4442 ret = gattc_get_descriptor(conn_info->connection_id, &srvc_id, &char_id, NULL);
4443 if (ret != OAL_STATUS_SUCCESS) {
4444 BT_ERR("ret: %d", ret);
4446 return BLUETOOTH_ERROR_INTERNAL;
4449 return BLUETOOTH_ERROR_NONE;
4452 int _bt_gatt_read_characteristic_value(
4453 bluetooth_gatt_client_char_prop_info_t *chr)
4455 struct gatt_server_info_t *conn_info = NULL;
4456 invocation_info_t *req_info = NULL;
4457 bluetooth_gatt_client_char_prop_info_t *prop;
4458 oal_gatt_srvc_id_t srvc_id;
4459 oal_gatt_id_t char_id;
4460 int ret = OAL_STATUS_SUCCESS;
4463 BT_CHECK_PARAMETER(chr, return);
4465 /* Check if any app is already Reading characteristic of the same char of
4466 particular service on the same remote GATT Server */
4467 req_info = _bt_get_request_info_data_from_function_name(BT_GATT_READ_CHARACTERISTIC);
4469 prop = (bluetooth_gatt_client_char_prop_info_t*)req_info->user_data;
4470 if (prop && !memcmp(chr->device_address.addr, prop->device_address.addr, sizeof(bluetooth_device_address_t)) /* Address matched */
4471 && memcmp(chr->svc.uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Service UUID matched */
4472 && chr->svc.instance_id == prop->svc.instance_id /* Service Instance ID matched */
4473 && memcmp(chr->characteristic.uuid, prop->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Characteristic UUID matched */
4474 && chr->characteristic.instance_id == prop->characteristic.instance_id) { /* Characteristic Instance ID matched */
4475 BT_INFO("Already Characteristic value Read operation in progress for same remote GATT Server");
4476 /* Return and wait for events to be sent to all apps */
4477 return BLUETOOTH_ERROR_NONE;
4481 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4482 _bt_convert_addr_type_to_string(addr, chr->device_address.addr);
4484 /* Check if remote GATT Server is connected or not */
4485 conn_info = _bt_find_remote_gatt_server_info(addr);
4487 BT_DBG("GATT Server [%s] is connected, conn Id [%d]",
4488 conn_info->addr, conn_info->connection_id);
4490 BT_ERR("GATT Server is not yet connected..");
4492 return BLUETOOTH_ERROR_NOT_CONNECTED;
4495 srvc_id.is_prmry = TRUE;
4496 srvc_id.id.inst_id = chr->svc.instance_id;
4497 memcpy(srvc_id.id.uuid.uuid, chr->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4499 char_id.inst_id = chr->characteristic.instance_id;
4500 memcpy(char_id.uuid.uuid, chr->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4502 /* Search All Descriptors */
4503 ret = gattc_read_characteristic(conn_info->connection_id, &srvc_id, &char_id, OAL_GATT_AUTH_REQ_NONE);
4504 if (ret != OAL_STATUS_SUCCESS) {
4505 BT_ERR("ret: %d", ret);
4507 return BLUETOOTH_ERROR_INTERNAL;
4510 return BLUETOOTH_ERROR_NONE;
4513 int _bt_gatt_read_descriptor_value(
4514 bluetooth_gatt_client_desc_prop_info_t *desc)
4516 struct gatt_server_info_t *conn_info = NULL;
4517 invocation_info_t *req_info = NULL;
4518 bluetooth_gatt_client_desc_prop_info_t *prop;
4519 oal_gatt_srvc_id_t srvc_id;
4520 oal_gatt_id_t char_id;
4521 oal_gatt_id_t desc_id;
4522 int ret = OAL_STATUS_SUCCESS;
4525 BT_CHECK_PARAMETER(desc, return);
4527 /* Check if any app is already Reading descriptors of the same char of
4528 particular service on the same remote GATT Server */
4529 req_info = _bt_get_request_info_data_from_function_name(BT_GATT_READ_DESCRIPTOR_VALUE);
4531 prop = (bluetooth_gatt_client_desc_prop_info_t*)req_info->user_data;
4532 if (prop && !memcmp(desc->device_address.addr, prop->device_address.addr, sizeof(bluetooth_device_address_t)) /* Address matched */
4533 && memcmp(desc->svc.uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Service UUID matched */
4534 && desc->svc.instance_id == prop->svc.instance_id /* Service Instance ID matched */
4535 && memcmp(desc->characteristic.uuid, prop->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Characteristic UUID matched */
4536 && desc->characteristic.instance_id == prop->characteristic.instance_id /* Characteristic Instance ID matched */
4537 && memcmp(desc->descriptor.uuid, prop->descriptor.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Descriptor UUID matched */
4538 && desc->descriptor.instance_id == prop->descriptor.instance_id) { /* Descriptor Instance ID matched */
4539 BT_INFO("Already Descriptor value Read operation in progress for same remote GATT Server");
4540 /* Return and wait for events to be sent to all apps */
4541 return BLUETOOTH_ERROR_NONE;
4545 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4546 _bt_convert_addr_type_to_string(addr, desc->device_address.addr);
4548 /* Check if remote GATT Server is connected or not */
4549 conn_info = _bt_find_remote_gatt_server_info(addr);
4551 BT_DBG("GATT Server [%s] is connected, conn Id [%d]",
4552 conn_info->addr, conn_info->connection_id);
4554 BT_ERR("GATT Server is not yet connected..");
4556 return BLUETOOTH_ERROR_NOT_CONNECTED;
4559 srvc_id.is_prmry = TRUE;
4560 srvc_id.id.inst_id = desc->svc.instance_id;
4561 memcpy(srvc_id.id.uuid.uuid, desc->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4563 char_id.inst_id = desc->characteristic.instance_id;
4564 memcpy(char_id.uuid.uuid, desc->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4566 desc_id.inst_id = desc->descriptor.instance_id;
4567 memcpy(desc_id.uuid.uuid, desc->descriptor.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4569 /* Search All Descriptors */
4570 ret = gattc_read_descriptor(conn_info->connection_id, &srvc_id, &char_id,
4571 &desc_id, OAL_GATT_AUTH_REQ_NONE);
4572 if (ret != OAL_STATUS_SUCCESS) {
4573 BT_ERR("ret: %d", ret);
4575 return BLUETOOTH_ERROR_INTERNAL;
4578 return BLUETOOTH_ERROR_NONE;
4582 int _bt_gatt_acquire_notify(bluetooth_gatt_client_char_prop_info_t *chr, int *fd, int *mtu)
4584 struct gatt_server_info_t *conn_info = NULL;
4585 oal_gatt_srvc_id_t srvc_id;
4586 oal_gatt_id_t char_id;
4587 int ret = OAL_STATUS_SUCCESS;
4590 BT_CHECK_PARAMETER(chr, return);
4592 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4593 _bt_convert_addr_type_to_string(addr, chr->device_address.addr);
4595 /* Check if remote GATT Server is connected or not */
4596 conn_info = _bt_find_remote_gatt_server_info(addr);
4598 BT_DBG("GATT Server [%s] is connected, conn Id [%d]",
4599 conn_info->addr, conn_info->connection_id);
4601 BT_ERR("GATT Server is not yet connected..");
4603 return BLUETOOTH_ERROR_NOT_CONNECTED;
4606 srvc_id.is_prmry = TRUE;
4607 srvc_id.id.inst_id = chr->svc.instance_id;
4608 memcpy(srvc_id.id.uuid.uuid, chr->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4610 char_id.inst_id = chr->characteristic.instance_id;
4611 memcpy(char_id.uuid.uuid, chr->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4613 ret = gattc_acquire_notify(conn_info->connection_id, &srvc_id, &char_id, fd, mtu);
4615 if (ret != OAL_STATUS_SUCCESS) {
4616 BT_ERR("ret: %d", ret);
4618 return BLUETOOTH_ERROR_INTERNAL;
4620 BT_INFO("GATT characterstics FD [%d] mtu[%d]", *fd, *mtu);
4622 return BLUETOOTH_ERROR_NONE;
4626 int _bt_gatt_acquire_write(bluetooth_gatt_client_char_prop_info_t *chr, int *fd, int *mtu)
4629 struct gatt_server_info_t *conn_info = NULL;
4630 oal_gatt_srvc_id_t srvc_id;
4631 oal_gatt_id_t char_id;
4632 int ret = OAL_STATUS_SUCCESS;
4635 BT_CHECK_PARAMETER(chr, return);
4637 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4638 _bt_convert_addr_type_to_string(addr, chr->device_address.addr);
4640 /* Check if remote GATT Server is connected or not */
4641 conn_info = _bt_find_remote_gatt_server_info(addr);
4643 BT_DBG("GATT Server [%s] is connected, conn Id [%d]",
4644 conn_info->addr, conn_info->connection_id);
4646 BT_ERR("GATT Server is not yet connected..");
4648 return BLUETOOTH_ERROR_NOT_CONNECTED;
4651 srvc_id.is_prmry = TRUE;
4652 srvc_id.id.inst_id = chr->svc.instance_id;
4653 memcpy(srvc_id.id.uuid.uuid, chr->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4655 char_id.inst_id = chr->characteristic.instance_id;
4656 memcpy(char_id.uuid.uuid, chr->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4658 ret = gattc_acquire_write(conn_info->connection_id, &srvc_id, &char_id,
4659 OAL_GATT_AUTH_REQ_NONE, fd, mtu);
4660 if (ret != OAL_STATUS_SUCCESS) {
4661 BT_ERR("ret: %d", ret);
4663 return BLUETOOTH_ERROR_INTERNAL;
4665 BT_INFO("GATT characterstics FD [%d] mtu [%d]", *fd, *mtu);
4667 return BLUETOOTH_ERROR_NONE;
4672 /* Write Characteristic */
4673 int _bt_gatt_write_characteristic_value_by_type(
4674 bluetooth_gatt_client_char_prop_info_t *chr,
4675 bluetooth_gatt_att_data_t *data,
4676 bluetooth_gatt_write_type_e write_type)
4678 struct gatt_server_info_t *conn_info = NULL;
4679 invocation_info_t *req_info = NULL;
4680 bluetooth_gatt_client_char_prop_info_t *prop;
4681 oal_gatt_srvc_id_t srvc_id;
4682 oal_gatt_id_t char_id;
4683 int ret = OAL_STATUS_SUCCESS;
4687 BT_CHECK_PARAMETER(chr, return);
4688 BT_CHECK_PARAMETER(data, return);
4692 /* Check if any app is already writing same char of
4693 particular service on the same remote GATT Server */
4694 req_info = _bt_get_request_info_data_from_function_name(BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE);
4696 prop = (bluetooth_gatt_client_char_prop_info_t*)req_info->user_data;
4697 if (prop && !memcmp(chr->device_address.addr, prop->device_address.addr, sizeof(bluetooth_device_address_t)) /* Address matched */
4698 && memcmp(chr->svc.uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Service UUID matched */
4699 && chr->svc.instance_id == prop->svc.instance_id /* Service Instance ID matched */
4700 && memcmp(chr->characteristic.uuid, prop->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Characteristic UUID matched */
4701 && chr->characteristic.instance_id == prop->characteristic.instance_id) { /* Characteristic Instance ID matched */
4702 BT_INFO("Already Characteristic Write Value operation in progress for same remote GATT Server");
4703 /* Return and wait for events to be sent to all apps */
4704 return BLUETOOTH_ERROR_NONE;
4708 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4709 _bt_convert_addr_type_to_string(addr, chr->device_address.addr);
4711 /* Check if remote GATT Server is connected or not */
4712 conn_info = _bt_find_remote_gatt_server_info(addr);
4714 BT_INFO("GATT Server [%s] is connected, conn Id [%d]",
4715 conn_info->addr, conn_info->connection_id);
4717 BT_ERR("GATT Server is not yet connected..");
4719 return BLUETOOTH_ERROR_NOT_CONNECTED;
4722 srvc_id.is_prmry = TRUE;
4723 srvc_id.id.inst_id = chr->svc.instance_id;
4724 memcpy(srvc_id.id.uuid.uuid, chr->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4726 char_id.inst_id = chr->characteristic.instance_id;
4727 memcpy(char_id.uuid.uuid, chr->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4729 /* Write CHar value */
4731 BT_INFO("Connection ID [%d] write type [%d] data length [%d]", conn_info->connection_id, write_type, data->length);
4732 for (k = 0; k < data->length; k++)
4733 BT_INFO("Data[%d] [0x%x]", k, data->data[k]);
4735 ret = gattc_write_characteristic(conn_info->connection_id,
4737 (oal_gatt_write_type_t)write_type, data->length,
4738 OAL_GATT_AUTH_REQ_NONE, (char *)(&data->data[0]));
4739 if (ret != OAL_STATUS_SUCCESS) {
4740 BT_ERR("ret: %d", ret);
4742 return BLUETOOTH_ERROR_INTERNAL;
4745 return BLUETOOTH_ERROR_NONE;
4748 /* Write Descriptor */
4749 int _bt_gatt_write_descriptor_value_by_type(
4750 bluetooth_gatt_client_desc_prop_info_t *desc,
4751 bluetooth_gatt_att_data_t *data,
4752 bluetooth_gatt_write_type_e write_type)
4754 struct gatt_server_info_t *conn_info = NULL;
4755 invocation_info_t *req_info = NULL;
4756 bluetooth_gatt_client_desc_prop_info_t *prop;
4757 oal_gatt_srvc_id_t srvc_id;
4758 oal_gatt_id_t char_id;
4759 oal_gatt_id_t desc_id;
4760 int ret = OAL_STATUS_SUCCESS;
4764 BT_CHECK_PARAMETER(desc, return);
4765 BT_CHECK_PARAMETER(data, return);
4769 /* Check if any app is already writing on same Descriptor of the same char of
4770 particular service on the same remote GATT Server */
4771 req_info = _bt_get_request_info_data_from_function_name(BT_GATT_WRITE_DESCRIPTOR_VALUE);
4773 prop = (bluetooth_gatt_client_desc_prop_info_t*)req_info->user_data;
4774 if (prop && !memcmp(desc->device_address.addr, prop->device_address.addr, sizeof(bluetooth_device_address_t)) /* Address matched */
4775 && memcmp(desc->svc.uuid, prop->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Service UUID matched */
4776 && desc->svc.instance_id == prop->svc.instance_id /* Service Instance ID matched */
4777 && memcmp(desc->characteristic.uuid, prop->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Characteristic UUID matched */
4778 && desc->characteristic.instance_id == prop->characteristic.instance_id /* Characteristic Instance ID matched */
4779 && memcmp(desc->descriptor.uuid, prop->descriptor.uuid, BLUETOOTH_UUID_HEX_MAX_LEN) /* Descriptor UUID matched */
4780 && desc->descriptor.instance_id == prop->descriptor.instance_id) { /* Descriptor Instance ID matched */
4781 BT_INFO("Already Descriptor value Write operation in progress for same remote GATT Server");
4782 /* Return and wait for events to be sent to all apps */
4783 return BLUETOOTH_ERROR_NONE;
4787 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4788 _bt_convert_addr_type_to_string(addr, desc->device_address.addr);
4790 /* Check if remote GATT Server is connected or not */
4791 conn_info = _bt_find_remote_gatt_server_info(addr);
4793 BT_INFO("GATT Server [%s] is connected, conn Id [%d]",
4794 conn_info->addr, conn_info->connection_id);
4796 BT_ERR("GATT Server is not yet connected..");
4798 return BLUETOOTH_ERROR_NOT_CONNECTED;
4801 srvc_id.is_prmry = TRUE;
4802 srvc_id.id.inst_id = desc->svc.instance_id;
4803 memcpy(srvc_id.id.uuid.uuid, desc->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4805 char_id.inst_id = desc->characteristic.instance_id;
4806 memcpy(char_id.uuid.uuid, desc->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4808 desc_id.inst_id = desc->descriptor.instance_id;
4809 memcpy(desc_id.uuid.uuid, desc->descriptor.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4812 BT_INFO("Connection ID [%d] write type [%d] data length [%d]", conn_info->connection_id, write_type, data->length);
4813 for (k = 0; k < data->length; k++)
4814 BT_INFO("Data[%d] [0x%x]", k, data->data[k]);
4816 ret = gattc_write_descriptor(conn_info->connection_id,
4817 &srvc_id, &char_id, &desc_id,
4818 (oal_gatt_write_type_t)write_type, data->length,
4819 OAL_GATT_AUTH_REQ_NONE, (char *)(&data->data[0]));
4820 if (ret != OAL_STATUS_SUCCESS) {
4821 BT_ERR("ret: %d", ret);
4823 return BLUETOOTH_ERROR_INTERNAL;
4826 return BLUETOOTH_ERROR_NONE;
4829 int _bt_gatt_watch_characteristic(
4830 bluetooth_gatt_client_char_prop_info_t *chr,
4834 struct gatt_server_info_t *conn_info = NULL;
4835 oal_gatt_srvc_id_t srvc_id;
4836 oal_gatt_id_t char_id;
4837 int ret = OAL_STATUS_SUCCESS;
4840 BT_CHECK_PARAMETER(chr, return);
4842 BT_INFO("Client ID [%d] Is Notify [%d]", client_id, is_notify);
4844 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4845 _bt_convert_addr_type_to_string(addr, chr->device_address.addr);
4847 /* Check if remote GATT Server is connected or not */
4848 conn_info = _bt_find_remote_gatt_server_info(addr);
4850 BT_INFO("GATT Server [%s] is connected, conn Id [%d]",
4851 conn_info->addr, conn_info->connection_id);
4853 BT_ERR("GATT Server is not yet connected..");
4855 return BLUETOOTH_ERROR_NOT_CONNECTED;
4857 srvc_id.is_prmry = TRUE;
4858 srvc_id.id.inst_id = chr->svc.instance_id;
4859 memcpy(srvc_id.id.uuid.uuid, chr->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4861 char_id.inst_id = chr->characteristic.instance_id;
4862 memcpy(char_id.uuid.uuid, chr->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
4864 /* Register or unregister Notification characteristic */
4866 ret = gattc_register_for_notification(conn_info->client_id,
4867 (bt_address_t*)&(chr->device_address),
4868 &srvc_id, &char_id);
4870 ret = gattc_deregister_for_notification(conn_info->client_id,
4871 (bt_address_t*)&(chr->device_address),
4872 &srvc_id, &char_id);
4874 BT_INFO("Result[%d]", ret);
4875 if (ret != OAL_STATUS_SUCCESS) {
4876 BT_ERR("ret: %d", ret);
4878 return BLUETOOTH_ERROR_INTERNAL;
4881 return BLUETOOTH_ERROR_NONE;
4885 int _bt_disconnect_le_device(bluetooth_device_address_t *address,
4888 struct gatt_server_info_t *conn_info = NULL;
4889 struct gatt_client_info_t *rem_client_conn_info = NULL;
4890 invocation_info_t *req_info = NULL;
4891 int ret = OAL_STATUS_SUCCESS;
4893 char *remote_address = NULL;
4895 BT_CHECK_PARAMETER(address, return);
4897 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
4898 _bt_convert_addr_type_to_string(addr, address->addr);
4899 BT_INFO("GATT Client Disconnect request for address [%s]", addr);
4901 /* Check if Remote Device is already under connection progress */
4902 req_info = _bt_get_request_info_data_from_function_name(BT_DISCONNECT_LE);
4904 remote_address = (char*)req_info->user_data;
4905 if (remote_address && !strcasecmp(remote_address, addr)) {/* Address matched */
4906 BT_DBG("Already DisConnection ongoing for same remote GATT Server address [%s]", remote_address);
4907 /* Return success and wait for events to be sent to all apps */
4909 return BLUETOOTH_ERROR_IN_PROGRESS;
4912 /* Check if remote GATT Server is connected or not */
4913 conn_info = _bt_find_remote_gatt_server_info(addr);
4915 /* Check if app sent 0 client id for Disconnection, in such case, use default gatt client ID */
4916 if (client_id == 0) {
4917 BT_INFO("GATT CLient Disconnect request sent by an app without any client instance [%d]",
4919 BT_INFO("Assign default GATT client id [%d]", gatt_default_client);
4920 client_id = gatt_default_client;
4923 BT_INFO("Disconnect remote gatt server using CLient ID [%d] Connection ID [%d]", client_id, conn_info->connection_id);
4924 ret = gattc_disconnect(client_id, (bt_address_t*)(address),
4925 conn_info->connection_id);
4927 /* check if remote client is connected */
4928 rem_client_conn_info = _bt_find_remote_gatt_client_info(addr);
4930 if (!rem_client_conn_info || client_id != 0) {
4931 BT_ERR("GATT device is not connected..");
4933 return BLUETOOTH_ERROR_NOT_IN_OPERATION;
4936 BT_INFO("Disconnect remote gatt client ");
4938 ret = gatts_disconnect(rem_client_conn_info->instance_id,
4939 (bt_address_t*)(address), rem_client_conn_info->connection_id);
4942 if (ret != OAL_STATUS_SUCCESS) {
4943 BT_ERR("ret: %d", ret);
4945 return BLUETOOTH_ERROR_INTERNAL;
4948 return BLUETOOTH_ERROR_NONE;
4951 int _bt_gatt_watch_service_changed_indication(const char *sender,
4952 bluetooth_device_address_t *address,
4953 gboolean is_enabled)
4956 bt_service_app_info_t *info = NULL;
4958 BT_INFO("%s Servic changed Indication watcher for app [%s]",
4959 is_enabled ? "Enable":"Disable", sender);
4961 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
4964 if (g_strcmp0(sender, info->sender) == 0 &&
4965 memcmp(info->address.addr, address->addr,
4966 sizeof(bluetooth_device_address_t)) == 0) {
4967 BT_DBG("Found GATT client App.. [%s], sender [%s]", info->uuid, info->sender);
4968 info->is_watcher_enabled = is_enabled;
4972 return BLUETOOTH_ERROR_NONE;
4975 int _bt_unregister_gatt_client_instance(const char *sender, int client_id)
4977 bt_service_app_info_t *info = NULL;
4980 BT_INFO("Unregister Allocated GATT Client instance [%s] Client ID [%d]", sender, client_id);
4982 /* Unregister CLient instance associated with address X. It is possible that another app still
4983 has client_id valid for same remote address */
4984 for (k = 1; k < MAX_APPS_SUPPORTED; k++) {
4987 /* Exact matching of sender */
4988 if (!g_strcmp0(info->sender, sender) && info->client_id == client_id) { /* Check for only valid GATT client Instance */
4989 BT_INFO("Unregister GATT client instance [%d]", info->client_id);
4990 numapps[k].client_id = -1;
4991 numapps[k].is_initialized = FALSE;
4992 memset(numapps[k].sender, 0x00, sizeof(numapps[k].sender));
4993 memset(numapps[k].uuid, 0x00, sizeof(numapps[k].uuid));
4994 memset(&numapps[k].address.addr, 0x00, sizeof(bluetooth_device_address_t));
4996 /* Its a GATT Client Instance */
4997 ret = gattc_deregister(client_id);
4998 if (ret != OAL_STATUS_SUCCESS) {
4999 BT_ERR("DeAllocate GATT Client instance with stack Fail ret: %d", ret);
5000 return BLUETOOTH_ERROR_INTERNAL;
5002 return BLUETOOTH_ERROR_NONE;
5007 return BLUETOOTH_ERROR_NOT_FOUND;
5010 static void __bt_handle_client_mtu_exchange_completed(event_gattc_mtu_configured_t *event_data)
5012 int result = BLUETOOTH_ERROR_NONE;
5013 struct gatt_server_info_t *conn_info = NULL;
5014 GVariant *param = NULL;
5018 conn_info = __bt_find_remote_gatt_server_info_from_conn_id(event_data->conn_id);
5019 if (conn_info == NULL) {
5020 BT_ERR("Cant find connection Information");
5024 BT_INFO("GATT Client: MTU Configured from addr [%s] status [%d] MTU size [%d]",
5025 conn_info->addr, event_data->status, event_data->mtu);
5027 if (event_data->status != OAL_STATUS_SUCCESS)
5028 result = BLUETOOTH_ERROR_INTERNAL;
5030 BT_INFO("reply BT_REQ_ATT_MTU ");
5032 /* DBUS Return fo BT_REQ_ATT_MTU for all the apps */
5033 __bt_gatt_handle_pending_request_info(result, BT_REQ_ATT_MTU, conn_info->addr,
5034 BT_ADDRESS_STRING_SIZE);
5036 if (result == BLUETOOTH_ERROR_NONE) {
5037 BT_INFO("sending mtu event");
5039 mtu = event_data->mtu;
5040 param = g_variant_new("(isqy)",
5046 /* Send event to BT-API */
5047 _bt_send_event(BT_DEVICE_EVENT,
5048 BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED,
5051 /* Update the MTU for current connection */
5052 BT_INFO("Updating the MTU for current connection");
5053 __bt_update_mtu_gatt_device(conn_info->addr, event_data->mtu);
5057 static struct gatt_mtu_info_t *__bt_find_mtu_gatt_device(char *address)
5060 struct gatt_mtu_info_t *info = NULL;
5064 for (l = gatt_mtu_info_list; l != NULL; l = g_slist_next(l)) {
5065 info = (struct gatt_mtu_info_t*)l->data;
5069 if (!g_strcmp0(info->addr, address)) {
5070 BT_INFO("Remote GATT device found addr[%s]", info->addr);
5075 BT_INFO("Not found Remote GATT device addr[%s]", address);
5079 static void __bt_remove_mtu_gatt_device(char *address)
5081 struct gatt_mtu_info_t *dev_info = NULL;
5085 dev_info = __bt_find_mtu_gatt_device(address);
5088 BT_INFO("removing the gatt device from mtu list");
5089 gatt_mtu_info_list = g_slist_remove(gatt_mtu_info_list, dev_info);
5090 g_free(dev_info->addr);
5095 static void __bt_add_mtu_gatt_device(char *address)
5097 struct gatt_mtu_info_t *dev_info = NULL;
5101 dev_info = __bt_find_mtu_gatt_device(address);
5104 BT_INFO("adding the gatt device in mtu list");
5105 dev_info = g_new0(struct gatt_mtu_info_t, 1);
5106 dev_info->addr = g_strdup(address);
5107 dev_info->att_mtu = BT_DEFAULT_ATT_MTU;
5108 gatt_mtu_info_list = g_slist_append(gatt_mtu_info_list, dev_info);
5112 static void __bt_update_mtu_gatt_device(char *address, int mtu)
5114 struct gatt_mtu_info_t *dev_info = NULL;
5118 dev_info = __bt_find_mtu_gatt_device(address);
5121 BT_INFO("Udating the mtu");
5122 dev_info->att_mtu = mtu;