Apply tizen 3.0 based product patchsets
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-audio.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *              http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <gio/gio.h>
19 #include <glib.h>
20 #include <dlog.h>
21 #include <string.h>
22 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
23 #include <vconf.h>
24 #endif
25 #include <syspopup_caller.h>
26
27 #include "bluetooth-api.h"
28 #include "bt-internal-types.h"
29
30 #include "bt-service-audio.h"
31 #include "bt-service-adapter.h"
32 #include "bt-service-common.h"
33 #include "bt-service-device.h"
34 #include "bt-service-event.h"
35 #include "bt-service-util.h"
36
37 #include "bt-service-headset-connection.h"
38
39 #ifdef TIZEN_SUPPORT_DUAL_HF
40 #define VCONF_KEY_BT_HOST_BT_MAC_ADDR "db/wms/host_bt_mac"
41 #endif
42
43 typedef struct {
44         unsigned int type;
45         int device_state;
46         char device_address[BT_ADDRESS_STRING_SIZE + 1];
47 } bt_connected_headset_data_t;
48
49 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
50 typedef struct {
51         int alarm_id;
52         int retry_count;
53 } bt_auto_connect_timer_t;
54
55 bt_auto_connect_timer_t auto_connect_timer = {0, };
56 #endif
57
58 static GList *g_connected_list;
59
60 static bt_headset_wait_t *g_wait_data;
61
62 static bt_audio_function_data_t *pdata;
63
64 static void __bt_remove_device_from_wait_list();
65
66 static void __bt_free_wait_data();
67
68 static gboolean __bt_device_support_uuid(char *remote_address,
69                                 bt_audio_type_t type);
70
71 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
72 static int __bt_auto_connect_alarm_cb(alarm_id_t alarm_id, void* user_param);
73 #endif
74
75 static void __bt_hf_request_cb(GDBusProxy *proxy, GAsyncResult *res,
76                                     gpointer user_data)
77 {
78         GError *g_error = NULL;
79         GVariant *out_param1 = NULL;
80         GVariant *reply = NULL;
81         int result = BLUETOOTH_ERROR_NONE;
82         bt_function_data_t *func_data;
83         request_info_t *req_info;
84
85         reply = g_dbus_proxy_call_finish(proxy, res, &g_error);
86         g_object_unref(proxy);
87
88         func_data = user_data;
89
90         if (func_data == NULL) {
91                 /* Send reply */
92                 BT_ERR("func_data == NULL");
93                 goto done;
94         }
95
96         req_info = _bt_get_request_info(func_data->req_id);
97         if (req_info == NULL) {
98                 BT_ERR("req_info == NULL");
99                 goto done;
100         }
101
102         if (reply == NULL) {
103                 BT_ERR("HF Connect Dbus Call Error");
104                 result = _bt_convert_gerror(g_error);
105                 if (g_error) {
106                         BT_ERR("Error: %s\n", g_error->message);
107                         g_clear_error(&g_error);
108                 }
109         } else {
110                 g_variant_unref(reply);
111         }
112
113         if (req_info->context == NULL)
114                 goto done;
115
116         out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
117                 func_data->address, BT_ADDRESS_STR_LEN, TRUE, NULL, NULL);
118
119         g_dbus_method_invocation_return_value(req_info->context,
120                         g_variant_new("(iv)", result, out_param1));
121
122         _bt_delete_request_list(req_info->req_id);
123
124 done:
125         if (func_data) {
126                 g_free(func_data->address);
127                 g_free(func_data);
128         }
129 }
130
131 void _bt_audio_check_pending_connect()
132 {
133         BT_DBG("+");
134         bluetooth_device_address_t device_address;
135
136         if (pdata == NULL)
137                 return;
138
139         if (pdata->pending == BT_PENDING_CONNECT) {
140
141                 _bt_convert_addr_string_to_type(device_address.addr,
142                                 pdata->address);
143                 _bt_audio_connect(pdata->req_id,
144                                 BT_AUDIO_A2DP,
145                                 &device_address,
146                                 NULL);
147
148                 g_free(pdata->address);
149                 g_free(pdata);
150                 pdata = NULL;
151         }
152
153         BT_DBG("-");
154         return;
155 }
156
157 static void __bt_audio_request_cb(GDBusProxy *proxy, GAsyncResult *res,
158                                     gpointer user_data)
159 {
160         GError *g_error = NULL;
161         GVariant *out_param1 = NULL;
162         GVariant *reply = NULL;
163         int result = BLUETOOTH_ERROR_NONE;
164         bt_audio_function_data_t *func_data;
165         request_info_t *req_info;
166
167         reply = g_dbus_proxy_call_finish(proxy, res, &g_error);
168         g_object_unref(proxy);
169         g_variant_unref(reply);
170
171         func_data = user_data;
172
173         if (func_data == NULL) {
174                 /* Send reply */
175                 BT_ERR("func_data == NULL");
176                 goto done;
177         }
178
179         if (func_data->pending != BT_PENDING_NONE && g_error == NULL) {
180                 bluetooth_device_address_t device_address;
181                 _bt_convert_addr_string_to_type(device_address.addr,
182                                         func_data->address);
183
184                 if (func_data->pending == BT_PENDING_CONNECT) {
185
186                         if (__bt_device_support_uuid(func_data->address,
187                                                         BT_AUDIO_A2DP)) {
188
189                                 pdata = g_new0(bt_audio_function_data_t, 1);
190                                 pdata->req_id = func_data->req_id;
191                                 pdata->address = strdup(func_data->address);
192                                 pdata->pending = func_data->pending;
193                         } else
194                                 goto check_req_info;
195
196                 } else {
197                         if (_bt_is_service_connected(func_data->address
198                                                         , BT_AUDIO_HSP)) {
199                                 _bt_audio_disconnect(func_data->req_id,
200                                         BT_AUDIO_HSP, &device_address, NULL);
201                         } else
202                                 goto check_req_info;
203                 }
204
205                 goto done;
206         }
207
208 check_req_info:
209         if (g_error == NULL)
210                 goto dbus_return;
211
212         BT_ERR("Audio Connect/Disconnect Dbus Call Error: %s\n", g_error->message);
213
214         result = BLUETOOTH_ERROR_INTERNAL;
215         /* If there is error then we need to set local initiated connection as false
216           * If don't do this then when headset initiate connection for HFP then we don't
217           * initiate connection for A2dp to headset as this flag was set to true in first
218           * connection failure attempt and not set in error case.*/
219         _bt_headset_set_local_connection(FALSE);
220
221         /* Remove the device from the list */
222         _bt_remove_headset_from_list(func_data->type, func_data->address);
223
224         /* Error, check if any waiting device is there */
225         if (g_wait_data == NULL)
226                 goto dbus_return;
227
228         if (g_strcmp0(g_wait_data->address, func_data->address) != 0) {
229                 bluetooth_device_address_t device_address;
230                 _bt_convert_addr_string_to_type(device_address.addr,
231                                 g_wait_data->address);
232                 _bt_audio_connect(g_wait_data->req_id, g_wait_data->type,
233                                 &device_address, NULL);
234         }
235
236         /* Event will be sent by the event reciever */
237 dbus_return:
238         req_info = _bt_get_request_info(func_data->req_id);
239         if (req_info == NULL) {
240                 BT_ERR("req_info == NULL");
241                 goto done;
242         } else if (req_info->context == NULL) {
243                 BT_ERR("req_info->context is NULL");
244                 goto done;
245         }
246
247         out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
248                 func_data->address, BT_ADDRESS_STR_LEN, TRUE, NULL, NULL);
249
250         g_dbus_method_invocation_return_value(req_info->context,
251                         g_variant_new("(iv)", result, out_param1));
252
253         _bt_delete_request_list(req_info->req_id);
254 done:
255         g_clear_error(&g_error);
256
257         if (func_data) {
258                 g_free(func_data->address);
259                 g_free(func_data);
260         }
261 }
262
263 static void __bt_free_wait_data()
264 {
265         if (g_wait_data != NULL) {
266                 g_free(g_wait_data->address);
267                 g_free(g_wait_data);
268                 g_wait_data = NULL;
269         }
270 }
271
272 static void __bt_remove_device_from_wait_list()
273 {
274         /* Before deleting the request update the UI */
275         GVariant *out_param_1 = NULL;
276         int result = BLUETOOTH_ERROR_INTERNAL;
277         request_info_t *req_info;
278
279         req_info = _bt_get_request_info(g_wait_data->req_id);
280         if (req_info == NULL) {
281                 BT_ERR("req_info == NULL");
282                 return;
283         }
284
285         out_param_1 = g_variant_new_from_data((const GVariantType *)"ay",
286                 g_wait_data->address, BT_ADDRESS_STR_LEN, TRUE, NULL, NULL);
287
288         g_dbus_method_invocation_return_value(req_info->context,
289                         g_variant_new("(iv)", result, out_param_1));
290
291         _bt_delete_request_list(g_wait_data->req_id);
292 }
293
294 static void __bt_set_headset_disconnection_type(const char *address)
295 {
296         bt_connected_headset_data_t *connected_device;
297         GList *node;
298
299         node = g_list_first(g_connected_list);
300         while (node != NULL) {
301                 connected_device = node->data;
302                 if (g_strcmp0(connected_device->device_address, address) == 0) {
303                         g_wait_data->disconnection_type = connected_device->type;
304                         return;
305                 }
306                 node = g_list_next(node);
307         }
308 }
309
310 #ifdef TIZEN_BT_DUAL_HEADSET_CONNECT
311 void _bt_check_already_connected_headset(int type, char *address)
312 {
313         GList *node;
314         char connected_address[BT_ADDRESS_STRING_SIZE + 1];
315         bluetooth_device_address_t device_address;
316         int device_count = 0;
317
318         if (address != NULL) {
319                 node = g_list_first(g_connected_list);
320                 while (node != NULL) {
321                         bt_connected_headset_data_t *connected_device = node->data;
322                         if ((connected_device->type & type) &&
323                                 (g_strcmp0(connected_device->device_address, address) != 0)) {
324                                 device_count++;
325                                 /* Disconnect the earliest(1st) connected headset */
326                                 if (device_count == 1) {
327                                         g_strlcpy(connected_address,
328                                                 connected_device->device_address,
329                                                 BT_ADDRESS_STRING_SIZE + 1);
330                                         BT_DBG("Earliest/First Connected headset %s",
331                                                 connected_address);
332                                 } else if (device_count == MAX_CONNECTED_HEADSET) {
333                                         _bt_convert_addr_string_to_type(device_address.addr,
334                                                 connected_address);
335                                         _bt_audio_disconnect(0, type, &device_address, NULL);
336                                         return;
337                                 }
338                         }
339                         node = g_list_next(node);
340                 }
341         }
342 }
343 #endif
344
345 gboolean _bt_is_headset_type_connected(int type, char *address)
346 {
347         GList *node;
348
349         node = g_list_first(g_connected_list);
350         while (node != NULL) {
351                 bt_connected_headset_data_t *connected_device = node->data;
352
353                 if (connected_device->type & type) {
354                         if (address != NULL)
355                                 g_strlcpy(address, connected_device->device_address,
356                                                 BT_ADDRESS_STRING_SIZE + 1);
357                         return TRUE;
358                 }
359
360                 node = g_list_next(node);
361         }
362         return FALSE;
363 }
364
365 #ifdef TIZEN_SUPPORT_DUAL_HF
366 gboolean __bt_is_companion_device(const char *addr)
367 {
368         if (TIZEN_PROFILE_WEARABLE) {
369                 char *host_device_address = NULL;
370                 host_device_address = vconf_get_str(VCONF_KEY_BT_HOST_BT_MAC_ADDR);
371
372                 if (!host_device_address) {
373                         BT_INFO("Failed to get a companion device address");
374                         return FALSE;
375                 }
376
377                 if (g_strcmp0(host_device_address, addr) == 0) {
378                         BT_INFO("Found companion device");
379                         free(host_device_address);
380                         return TRUE;
381                 }
382
383                 free(host_device_address);
384                 return FALSE;
385         } else {
386                 /* TODO : Need to add companion device check condition for Phone models */
387                 return FALSE;
388         }
389 }
390 #endif
391
392 static int __bt_is_headset_connected(int type, int req_id,
393                                 const char *address)
394 {
395         gboolean connected = FALSE;
396         char connected_address[BT_ADDRESS_STRING_SIZE + 1];
397         bluetooth_device_address_t device_address;
398         bt_connected_headset_data_t *connected_device = NULL;
399 #ifdef TIZEN_SUPPORT_DUAL_HF
400         gboolean is_companion_device = FALSE;
401 #endif
402
403         /* Check if any other headset is connected */
404         GList *node = NULL;;
405
406         node = g_list_first(g_connected_list);
407         while (node != NULL) {
408                 connected_device = node->data;
409                 if ((connected_device->type & type)) {
410 #ifdef TIZEN_BT_DUAL_HEADSET_CONNECT
411                         device_count++;
412                         /* Disconnect the earliest(1st) connected headset */
413                         if (device_count == 1)
414                                 g_strlcpy(connected_address, connected_device->device_address,
415                                         BT_ADDRESS_STRING_SIZE + 1);
416
417                         if (g_strcmp0(connected_device->device_address, address) == 0)
418                                 return BLUETOOTH_ERROR_ALREADY_CONNECT;
419 #else
420                         g_strlcpy(connected_address, connected_device->device_address,
421                                         BT_ADDRESS_STRING_SIZE + 1);
422 #endif
423 #ifdef TIZEN_SUPPORT_DUAL_HF
424                         is_companion_device = __bt_is_companion_device(connected_address);
425                         BT_INFO(" is_companion_device[%d]", is_companion_device);
426
427                         if (!is_companion_device) {
428                                 connected = TRUE;
429                                 break;
430                         }
431 #else
432 #ifdef TIZEN_BT_DUAL_HEADSET_CONNECT
433                         if (device_count == MAX_CONNECTED_HEADSET) {
434                                 connected = TRUE;
435                                 break;
436                         }
437 #else
438                         connected = TRUE;
439                         break;
440 #endif
441 #endif
442                 }
443                 node = g_list_next(node);
444         }
445
446         if (!connected) {
447                 __bt_free_wait_data();
448                 return BLUETOOTH_ERROR_NOT_CONNECTED;
449         }
450
451         BT_DBG("connected headset %s", connected_address);
452
453         if (g_strcmp0(connected_address, address) == 0)
454                 return BLUETOOTH_ERROR_ALREADY_CONNECT;
455 #ifdef TIZEN_SUPPORT_DUAL_HF
456         else if (TRUE == __bt_is_companion_device(address))
457                 return BLUETOOTH_ERROR_NOT_CONNECTED;
458 #endif
459
460         /* Convert BD adress from string type */
461         _bt_convert_addr_string_to_type(device_address.addr, connected_address);
462         int value = BLUETOOTH_ERROR_NONE;
463         value = _bt_audio_disconnect(0, connected_device->type & type, &device_address, NULL);
464
465         /* If already one device is waiting, remove current waiting device and add new */
466         if (value == BLUETOOTH_ERROR_NONE) {
467                 if (g_wait_data != NULL) {
468                         if (g_strcmp0(g_wait_data->address, address) != 0) {
469                                 __bt_remove_device_from_wait_list();
470                                 __bt_free_wait_data();
471                         }
472                 }
473
474                 if (g_wait_data == NULL) {
475                         g_wait_data = g_malloc0(sizeof(bt_headset_wait_t));
476                         g_wait_data->address = g_strdup(address);
477                         g_wait_data->req_id = req_id;
478                         g_wait_data->type = type;
479                         g_wait_data->ag_flag = FALSE;
480
481                         /* Set disconnection type */
482                         __bt_set_headset_disconnection_type(connected_address);
483                 }
484         }
485
486         return value;
487 }
488
489 static int __bt_is_headset_connecting(int type)
490 {
491         bt_connected_headset_data_t *connected_device = NULL;
492
493         /* Check if any other headset is connected */
494         GList *node = NULL;
495
496         node = g_list_first(g_connected_list);
497         while (node != NULL) {
498                 connected_device = node->data;
499                 if (connected_device->device_state == BT_STATE_CONNECTING)
500                         return BLUETOOTH_ERROR_CONNECTION_BUSY;
501                 node = g_list_next(node);
502         }
503
504         return BLUETOOTH_ERROR_NONE;
505 }
506
507 int __bt_is_headset_disconnecting(int type)
508 {
509         bt_connected_headset_data_t *connected_device = NULL;
510
511         /* Check if any other headset is connected */
512         GList *node = NULL;
513
514         node = g_list_first(g_connected_list);
515         while (node != NULL) {
516                 connected_device = node->data;
517                 if (connected_device->device_state == BT_STATE_DISCONNECTING)
518                         return BLUETOOTH_ERROR_CONNECTION_BUSY;
519
520                 node = g_list_next(node);
521         }
522
523         return BLUETOOTH_ERROR_NONE;
524 }
525
526 void _bt_set_audio_wait_data_flag(gboolean flag)
527 {
528         BT_DBG("_bt_set_audio_wait_data_flag \n");
529         g_wait_data->ag_flag = flag;
530 }
531
532 bt_headset_wait_t *_bt_get_audio_wait_data(void)
533 {
534         BT_DBG("_bt_get_audio_wait_data \n");
535         return g_wait_data;
536 }
537
538 void _bt_rel_wait_data(void)
539 {
540         BT_DBG("_bt_rel_wait_data \n");
541         __bt_free_wait_data();
542 }
543
544 void _bt_add_headset_to_list(int type, int status, const char *address)
545 {
546         bt_connected_headset_data_t *connected_device;
547         bt_connected_headset_data_t *device;
548         GList *node;
549
550         BT_DBG("_bt_add_headset_to_list \n");
551
552         node = g_list_first(g_connected_list);
553         while (node != NULL) {
554                 device = (bt_connected_headset_data_t *)node->data;
555
556                 if (g_strcmp0(device->device_address, address) == 0) {
557                         BT_DBG("Address match, update connection type \n");
558                         if (status == BT_STATE_CONNECTED)
559                                 device->type |= type;
560                         device->device_state = status;
561                         return;
562                 }
563                 node = g_list_next(node);
564         }
565
566         connected_device = g_malloc0(sizeof(bt_connected_headset_data_t));
567         connected_device->device_state = status;
568         if ((status == BT_STATE_CONNECTED) || (status == BT_STATE_CONNECTING))
569                 connected_device->type |= type;
570         g_strlcpy(connected_device->device_address, address,
571                         sizeof(connected_device->device_address));
572         g_connected_list = g_list_append(g_connected_list, connected_device);
573 }
574
575 int _bt_get_device_state_from_list(int type, const char *address)
576 {
577         GList *node;
578         bt_connected_headset_data_t *device;
579
580         BT_DBG("+");
581         node = g_list_first(g_connected_list);
582         while (node != NULL) {
583                 device = (bt_connected_headset_data_t *)node->data;
584                 if (g_strcmp0(device->device_address, address) == 0) {
585                         BT_DBG("Device found");
586                         return device->device_state;
587                 }
588                 node = g_list_next(node);
589         }
590
591         BT_DBG("Device not found");
592         return BLUETOOTH_ERROR_INTERNAL;
593 }
594
595 void _bt_remove_headset_from_list(int type, const char *address)
596 {
597         GList *node;
598
599         BT_DBG("_bt_remove_headset_from_list \n");
600
601         node = g_list_first(g_connected_list);
602         while (node != NULL) {
603                 bt_connected_headset_data_t *connected_device = node->data;
604
605                 if (g_strcmp0(connected_device->device_address, address) != 0) {
606                         node = g_list_next(node);
607                         continue;
608                 }
609
610                 BT_DBG("Address match \n");
611
612                 BT_DBG("Connection type = %x\n", connected_device->type);
613
614                 switch (type) {
615                 case BT_AUDIO_A2DP:
616                         if (connected_device->type & BT_AUDIO_A2DP)
617                                 connected_device->type &= ~(BT_AUDIO_A2DP);
618                         break;
619                 case BT_AUDIO_HSP:
620                         if (connected_device->type & BT_AUDIO_HSP)
621                                 connected_device->type &= ~(BT_AUDIO_HSP);
622                         break;
623                 case BT_AUDIO_ALL:
624                         if (connected_device->type & BT_AUDIO_ALL)
625                                 connected_device->type &= ~(BT_AUDIO_ALL);
626                         break;
627                 case BT_AVRCP:
628                         if (connected_device->type & BT_AVRCP)
629                                 connected_device->type &= ~(BT_AVRCP);
630                         break;
631                 case BT_AUDIO_A2DP_SOURCE:
632                         if (connected_device->type & BT_AUDIO_A2DP_SOURCE)
633                                 connected_device->type &= ~(BT_AUDIO_A2DP_SOURCE);
634                 }
635
636                 BT_DBG("Connection type = %x\n", connected_device->type);
637
638                 if (connected_device->type == 0x00) {
639                         g_connected_list = g_list_remove(g_connected_list, connected_device);
640                         g_free(connected_device);
641                 } else {
642                         connected_device->device_state = BT_STATE_CONNECTED;
643                 }
644
645                 node = g_list_next(node);
646         }
647 }
648
649 static gboolean __bt_device_support_uuid(char *remote_address,
650                                 bt_audio_type_t type)
651 {
652         GArray *dev_list = NULL;
653         int size;
654         int i;
655         int j;
656         bluetooth_device_info_t info;
657         char bond_address[BT_ADDRESS_STRING_SIZE] = { 0 };
658         gboolean ret = FALSE;
659
660         BT_DBG("+");
661
662         dev_list = g_array_new(FALSE, FALSE, sizeof(gchar));
663
664         _bt_get_bonded_devices(&dev_list);
665         size = (dev_list->len) / sizeof(bluetooth_device_info_t);
666
667         for (i = 0; i < size; i++) {
668                 info = g_array_index(dev_list, bluetooth_device_info_t, i);
669                 _bt_convert_addr_type_to_string(bond_address,
670                                 info.device_address.addr);
671                 if (strcmp(bond_address, remote_address) != 0)
672                         continue;
673
674                 BT_INFO("Device address Matched");
675                 j = 0;
676                 while (j != info.service_index) {
677                         if (type == BT_AUDIO_HSP) {
678                                 if (strcmp(info.uuids[j], HFP_HS_UUID) == 0) {
679                                         BT_INFO("HFP HS UUID exists");
680                                         ret = TRUE;
681                                         goto end;
682                                 }
683                         } else if (type == BT_AUDIO_A2DP) {
684                                 if (strcmp(info.uuids[j], A2DP_SINK_UUID) == 0) {
685                                         BT_INFO("A2DP SINK UUID exists");
686                                         ret = TRUE;
687                                         goto end;
688                                 }
689                         }
690                         j++;
691                 }
692         }
693 end:
694         g_array_free(dev_list, TRUE);
695         BT_DBG("-");
696         return ret;
697 }
698
699 gboolean _bt_is_service_connected(char* address, int type)
700 {
701         GList *node;
702
703         node = g_list_first(g_connected_list);
704         while (node != NULL) {
705                 bt_connected_headset_data_t *conn_device = node->data;
706
707                 if ((g_strcmp0(conn_device->device_address, address) == 0) &&
708                         (conn_device->type & type)) {
709                                 BT_INFO("Service connected");
710                                 return TRUE;
711                 }
712
713                 node = g_list_next(node);
714         }
715         BT_INFO("Service not connected");
716         return FALSE;
717 }
718
719 int _bt_audio_connect(int request_id, int type,
720                 bluetooth_device_address_t *device_address,
721                 GArray *out_param1)
722 {
723         int result = BLUETOOTH_ERROR_NONE;
724         char address[BT_ADDRESS_STRING_SIZE] = { 0 };
725         GDBusProxy *adapter_proxy;
726         GDBusConnection *g_conn;
727         int ret;
728         char *uuid = NULL;
729         int value = BLUETOOTH_ERROR_NONE;
730         bt_audio_function_data_t *func_data;
731         guint hfp_hs_restricted = 0x0; /* set default "allowed" */
732         guint a2dp_restricted = 0x0;
733
734         BT_CHECK_PARAMETER(device_address, return);
735
736         adapter_proxy = _bt_get_adapter_proxy();
737         retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
738
739         g_conn = _bt_gdbus_get_system_gconn();
740         retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
741
742         _bt_convert_addr_type_to_string(address, device_address->addr);
743
744         func_data = g_malloc0(sizeof(bt_audio_function_data_t));
745         func_data->address = g_strdup(address);
746         func_data->req_id = request_id;
747         func_data->type = type;
748         func_data->pending = BT_PENDING_NONE;
749
750         result = _bt_get_restrict_profile(device_address, RESTRICTED_PROFILE_HFP_HS, &hfp_hs_restricted);
751         if (result != BLUETOOTH_ERROR_NONE)
752                 BT_ERR("Can't get hfp_hs restriction info");
753
754         result = _bt_get_restrict_profile(device_address, RESTRICTED_PROFILE_A2DP, &a2dp_restricted);
755         if (result != BLUETOOTH_ERROR_NONE)
756                 BT_ERR("Can't get a2dp restriction info");
757
758         switch (type) {
759         case BT_AUDIO_HSP:
760                 uuid = HFP_HS_UUID;
761                 break;
762         case BT_AUDIO_A2DP:
763                 uuid = A2DP_SINK_UUID;
764                 break;
765         case BT_AVRCP:
766                 uuid = AVRCP_TARGET_UUID;
767                 break;
768         case BT_AUDIO_A2DP_SOURCE:
769                 uuid = A2DP_SOURCE_UUID;
770                 break;
771         case BT_AUDIO_ALL:
772                 if ((hfp_hs_restricted == 0x0) && (a2dp_restricted == 0x0)) { /* in case of both profiles are not restricted */
773                         if (__bt_device_support_uuid(address, BT_AUDIO_HSP)) {
774                                 uuid = HFP_HS_UUID;
775                                 func_data->pending = BT_PENDING_CONNECT;
776                                 type = BT_AUDIO_HSP;
777                         } else if (__bt_device_support_uuid(address, BT_AUDIO_A2DP)) {
778                                 uuid = A2DP_SINK_UUID;
779                                 type = BT_AUDIO_A2DP;
780                         } else {
781                                 BT_ERR("No audio role supported");
782                                 result = BLUETOOTH_ERROR_SERVICE_NOT_FOUND;
783                                 goto fail;
784                         }
785                 } else if ((hfp_hs_restricted == 0x1) && (a2dp_restricted == 0x1)) { /* in case of both profiles are restricted */
786                         BT_ERR("All profiles are restricted");
787                         result = BLUETOOTH_ERROR_INTERNAL;
788                         goto fail;
789                 } else if (a2dp_restricted == 0x01) { /* in case of a2dp is restricted, only connection for hfp_hs */
790                         if (__bt_device_support_uuid(address, BT_AUDIO_HSP)) {
791                                 uuid = HFP_HS_UUID;
792                                 type = BT_AUDIO_HSP;
793                         } else {
794                                 BT_ERR("HFP_HS role is not supported");
795                                 result = BLUETOOTH_ERROR_SERVICE_NOT_FOUND;
796                                 goto fail;
797                         }
798                 } else if (hfp_hs_restricted == 0x01) { /* in case of hfp_hs is restricted, only connection for a2dp */
799                         if (__bt_device_support_uuid(address, BT_AUDIO_A2DP)) {
800                                 uuid = A2DP_SINK_UUID;
801                                 type = BT_AUDIO_A2DP;
802                         } else {
803                                 BT_ERR("A2DP role is not supported");
804                                 result = BLUETOOTH_ERROR_SERVICE_NOT_FOUND;
805                                 goto fail;
806                         }
807                 }
808                 break;
809         case BT_AVRCP_TARGET:
810                 uuid = AVRCP_REMOTE_UUID;
811                 break;
812         default:
813                 BT_ERR("Unknown role");
814                 result = BLUETOOTH_ERROR_INTERNAL;
815                 goto fail;
816         }
817         BT_INFO("Connecting to service %s", uuid);
818         /* First Check if device is in connecting state if it than return error */
819         value = __bt_is_headset_connecting(type);
820         if (value != BLUETOOTH_ERROR_NONE) {
821                 result = BLUETOOTH_ERROR_IN_PROGRESS;
822                 goto fail;
823         }
824
825         value = __bt_is_headset_connected(type, request_id, address);
826
827         if (value == BLUETOOTH_ERROR_ALREADY_CONNECT) {
828                 result = BLUETOOTH_ERROR_ALREADY_CONNECT;
829                 goto fail;
830         } else if (value == BLUETOOTH_ERROR_NOT_CONNECTED) {
831                 _bt_headset_set_local_connection(TRUE);
832                 ret = _bt_connect_profile(address, uuid,
833                                 __bt_audio_request_cb, func_data);
834
835                 if (ret != BLUETOOTH_ERROR_NONE) {
836                         BT_ERR("_bt_connect_profile Error");
837                         _bt_headset_set_local_connection(FALSE);
838                         g_free(func_data->address);
839                         g_free(func_data);
840                         return ret;
841                 }
842
843                 /* Add data to the connected list */
844                 _bt_add_headset_to_list(type, BT_STATE_CONNECTING, address);
845         } else if (value == BLUETOOTH_ERROR_IN_PROGRESS) {
846                 result = BLUETOOTH_ERROR_IN_PROGRESS;
847                 goto fail;
848         }
849
850         if (out_param1)
851                 g_array_free(out_param1, TRUE);
852
853         return BLUETOOTH_ERROR_NONE;
854 fail:
855         if (out_param1 != NULL)
856                 g_array_append_vals(out_param1, address,
857                                 BT_ADDRESS_STR_LEN);
858
859         g_free(func_data->address);
860         g_free(func_data);
861
862         return result;
863 }
864
865 int _bt_audio_disconnect(int request_id, int type,
866                 bluetooth_device_address_t *device_address,
867                 GArray *out_param1)
868 {
869         int result = BLUETOOTH_ERROR_NONE;
870         char address[BT_ADDRESS_STRING_SIZE] = { 0 };
871         bt_audio_function_data_t *func_data;
872         GDBusProxy *adapter_proxy;
873         GDBusConnection *g_conn;
874         GList *node;
875         int ret;
876         char *uuid;
877         int value = BLUETOOTH_ERROR_NONE;
878
879         BT_CHECK_PARAMETER(device_address, return);
880
881         adapter_proxy = _bt_get_adapter_proxy();
882         retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
883
884         g_conn = _bt_gdbus_get_system_gconn();
885         retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
886
887         _bt_convert_addr_type_to_string(address, device_address->addr);
888
889         func_data = g_malloc0(sizeof(bt_audio_function_data_t));
890         func_data->address = g_strdup(address);
891         func_data->req_id = request_id;
892         func_data->pending = BT_PENDING_NONE;
893         func_data->type = type;
894
895         switch (type) {
896         case BT_AUDIO_HSP:
897                 uuid = HFP_HS_UUID;
898                 break;
899         case BT_AUDIO_A2DP:
900                 uuid = A2DP_SINK_UUID;
901                 break;
902         case BT_AVRCP:
903                 uuid = AVRCP_TARGET_UUID;
904                 break;
905         case BT_AUDIO_A2DP_SOURCE:
906                 uuid = A2DP_SOURCE_UUID;
907                 break;
908         case BT_AUDIO_ALL:
909                 if (_bt_is_service_connected(address, BT_AUDIO_A2DP)) {
910                         uuid = A2DP_SINK_UUID;
911                         func_data->pending = BT_PENDING_DISCONNECT;
912                 } else if (_bt_is_service_connected(address, BT_AUDIO_HSP)) {
913                         uuid = HFP_HS_UUID;
914                 } else {
915                         BT_ERR("No audio service connected");
916                         result = BLUETOOTH_ERROR_NOT_CONNECTED;
917                         goto fail;
918                 }
919                 break;
920         case BT_AVRCP_TARGET:
921                 uuid = AVRCP_REMOTE_UUID;
922                 break;
923         default:
924                 BT_ERR("Unknown role");
925                 result = BLUETOOTH_ERROR_INTERNAL;
926                 goto fail;
927         }
928         value = __bt_is_headset_disconnecting(type);
929         if (value != BLUETOOTH_ERROR_NONE) {
930                 BT_INFO("Disconnect in progress");
931                 result = BLUETOOTH_ERROR_IN_PROGRESS;
932                 goto fail;
933         }
934         BT_INFO("Disconnecting service %s", uuid);
935         ret = _bt_disconnect_profile(address, uuid,
936                         __bt_audio_request_cb, func_data);
937
938         if (ret != BLUETOOTH_ERROR_NONE) {
939                 BT_ERR("_bt_disconnect_profile Error");
940                 g_free(func_data->address);
941                 g_free(func_data);
942                 return ret;
943         }
944
945         /*
946          *      This logic is added for dual HF mode issue.
947          */
948         node = g_list_first(g_connected_list);
949         while (node != NULL) {
950                 bt_connected_headset_data_t *connected_device = node->data;
951
952                 if (g_strcmp0(connected_device->device_address, address) == 0) {
953                         BT_DBG("Connection type update");
954                         type = connected_device->type;
955                         break;
956                 }
957                 node = g_list_next(node);
958         }
959         _bt_add_headset_to_list(type, BT_STATE_DISCONNECTING, address);
960
961         if (out_param1)
962                 g_array_free(out_param1, TRUE);
963
964         return BLUETOOTH_ERROR_NONE;
965 fail:
966         if (out_param1 != NULL)
967                 g_array_append_vals(out_param1, address,
968                                 BT_ADDRESS_STR_LEN);
969
970         g_free(func_data->address);
971         g_free(func_data);
972
973         return result;
974 }
975
976 void _bt_remove_from_connected_list(const char *address)
977 {
978         bt_connected_headset_data_t *connected_device;
979         GList *node;
980
981         node = g_list_first(g_connected_list);
982         while (node != NULL) {
983                 connected_device = node->data;
984                 if (connected_device != NULL &&
985                 g_strcmp0(connected_device->device_address, address) == 0) {
986                         BT_ERR("Device is removed from the list");
987                         g_connected_list = g_list_remove(g_connected_list, connected_device);
988                         g_free(connected_device);
989                         return;
990                 }
991                 node = g_list_next(node);
992         }
993 }
994
995 int _bt_hf_connect(int request_id,
996                 bluetooth_device_address_t *device_address,
997                 GArray *out_param1)
998 {
999         int result = BLUETOOTH_ERROR_NONE;
1000         char address[BT_ADDRESS_STRING_SIZE] = { 0 };
1001         bt_function_data_t *func_data;
1002         GDBusProxy *adapter_proxy;
1003         GDBusConnection *g_conn;
1004         gboolean connected = FALSE;
1005         int ret;
1006         char *uuid;
1007
1008         BT_CHECK_PARAMETER(device_address, return);
1009
1010         _bt_convert_addr_type_to_string(address, device_address->addr);
1011
1012         adapter_proxy = _bt_get_adapter_proxy();
1013         if (adapter_proxy == NULL) {
1014                 result = BLUETOOTH_ERROR_INTERNAL;
1015                 goto fail;
1016         }
1017
1018         g_conn = _bt_gdbus_get_system_gconn();
1019         if (g_conn == NULL) {
1020                 result = BLUETOOTH_ERROR_INTERNAL;
1021                 goto fail;
1022         }
1023
1024         /* Check if HF is connected or not */
1025         result = _bt_is_device_connected(device_address, BT_PROFILE_CONN_HFG, &connected);
1026         if (connected == TRUE) {
1027                 BT_ERR("HF is already connected");
1028                 result = BLUETOOTH_ERROR_ALREADY_CONNECT;
1029                 goto fail;
1030         }
1031
1032         func_data = g_malloc0(sizeof(bt_function_data_t));
1033         func_data->address = g_strdup(address);
1034         func_data->req_id = request_id;
1035         uuid = g_strdup(HFP_AG_UUID);
1036
1037         BT_DBG("Connecting to service %s", uuid);
1038
1039         ret = _bt_connect_profile(address, uuid,
1040                         __bt_hf_request_cb, func_data);
1041
1042         if (ret != BLUETOOTH_ERROR_NONE) {
1043                 BT_ERR("_bt_connect_profile Error");
1044                 g_free(func_data->address);
1045                 g_free(func_data);
1046                 g_free(uuid);
1047                 return ret;
1048         }
1049         g_free(uuid);
1050         if (out_param1)
1051                 g_array_free(out_param1, TRUE);
1052
1053         return BLUETOOTH_ERROR_NONE;
1054 fail:
1055         if (out_param1 != NULL)
1056                 g_array_append_vals(out_param1, address,
1057                                 BT_ADDRESS_STR_LEN);
1058
1059         return result;
1060 }
1061
1062 int _bt_hf_disconnect(int request_id,
1063                 bluetooth_device_address_t *device_address,
1064                 GArray *out_param1)
1065 {
1066         int result = BLUETOOTH_ERROR_NONE;
1067         char address[BT_ADDRESS_STRING_SIZE] = { 0 };
1068         bt_function_data_t *func_data;
1069         GDBusProxy *adapter_proxy;
1070         GDBusConnection *g_conn;
1071
1072         int ret;
1073         char *uuid;
1074
1075         BT_CHECK_PARAMETER(device_address, return);
1076
1077         _bt_convert_addr_type_to_string(address, device_address->addr);
1078
1079         adapter_proxy = _bt_get_adapter_proxy();
1080         if (adapter_proxy == NULL) {
1081                 result = BLUETOOTH_ERROR_INTERNAL;
1082                 goto fail;
1083         }
1084
1085         g_conn = _bt_gdbus_get_system_gconn();
1086         if (g_conn == NULL) {
1087                 result = BLUETOOTH_ERROR_INTERNAL;
1088                 goto fail;
1089         }
1090
1091         func_data = g_malloc0(sizeof(bt_function_data_t));
1092         func_data->address = g_strdup(address);
1093         func_data->req_id = request_id;
1094         uuid = g_strdup(HFP_AG_UUID);
1095
1096         BT_DBG("Disconnecting service %s", uuid);
1097         ret = _bt_disconnect_profile(address, uuid,
1098                         __bt_hf_request_cb, func_data);
1099
1100         if (ret != BLUETOOTH_ERROR_NONE) {
1101                 BT_ERR("_bt_disconnect_profile Error");
1102                 g_free(func_data->address);
1103                 g_free(func_data);
1104                 g_free(uuid);
1105                 return ret;
1106         }
1107         g_free(uuid);
1108         if (out_param1)
1109                 g_array_free(out_param1, TRUE);
1110
1111         return BLUETOOTH_ERROR_NONE;
1112 fail:
1113         if (out_param1 != NULL)
1114                 g_array_append_vals(out_param1, address,
1115                                 BT_ADDRESS_STR_LEN);
1116
1117         return result;
1118 }
1119
1120 int _bt_audio_set_content_protect(gboolean status)
1121 {
1122         GDBusConnection *conn;
1123         GError *error = NULL;
1124
1125         BT_DBG("+\n");
1126
1127         conn = _bt_gdbus_get_system_gconn();
1128         retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
1129
1130         BT_DBG("Content Protection status = [%d]", status);
1131
1132         g_dbus_connection_emit_signal(conn,
1133                         NULL, BT_CONTENT_PROTECTION_PATH,
1134                         BT_CONTENT_PROTECTION_INTERFACE,
1135                         "ProtectionRequired",
1136                         g_variant_new("(b)", status),
1137                         &error);
1138
1139         if (error) {
1140                 /* dBUS gives error cause */
1141                 ERR("Could not Emit Signal: errCode[%x], message[%s]",
1142                         error->code, error->message);
1143                 g_clear_error(&error);
1144                 return BLUETOOTH_ERROR_INTERNAL;
1145         }
1146
1147         BT_DBG("Emit Signal done = [ProtectionRequired]");
1148         return BLUETOOTH_ERROR_NONE;
1149 }
1150
1151 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
1152 static void __bt_auto_connect_request_cb(GDBusProxy *proxy, GAsyncResult *res,
1153                                     gpointer user_data)
1154 {
1155         GError *err = NULL;
1156         GVariant *reply = NULL;
1157
1158         reply = g_dbus_proxy_call_finish(proxy, res, &err);
1159         g_object_unref(proxy);
1160         g_variant_unref(reply);
1161
1162         BT_DBG("+");
1163         if (err != NULL) {
1164                 g_dbus_error_strip_remote_error(err);
1165                 BT_INFO("Auto_connect_request Dbus Call Error: %s", err->message);
1166
1167                 if (strcmp("Host is down", err->message)) {
1168                         BT_INFO("Fail reason is not 'Host Down'. Terminate auto connect");
1169                         _bt_audio_stop_auto_connect();
1170                         vconf_set_str(BT_LAST_CONNECTED_DEVICE, "");
1171                 }
1172         }
1173         g_clear_error(&err);
1174 }
1175
1176
1177 // It is the function that retry to create alarm.
1178 // Sometimes alarm mgr service is created later than bluetooth-frwk service in booting time.
1179 // So, in this case, we have to retry alarmmgr_add_alarm.
1180 static gboolean __bt_audio_alarm_retry_cb(gpointer data)
1181 {
1182         int result;
1183         alarm_id_t alarm_id;
1184
1185         BT_DBG("__bt_audio_alarm_retry_cb called.");
1186         result = _bt_service_set_alarm(BT_AUTO_CONNECT_TIMEOUT_AFTER_LINKLOSS,
1187                                                 __bt_auto_connect_alarm_cb, NULL, &alarm_id);
1188
1189         if (result != BLUETOOTH_ERROR_NONE)
1190                 return TRUE;
1191         else
1192                 auto_connect_timer.alarm_id = alarm_id;
1193
1194         return FALSE;
1195 }
1196
1197 static int __bt_auto_connect_alarm_cb(alarm_id_t alarm_id, void* user_param)
1198 {
1199         int result = BLUETOOTH_ERROR_NONE;
1200         char *address = NULL;
1201         alarm_id_t new_alarm_id;
1202
1203         BT_INFO("alram id = [%d] , retry_count [%d] ",
1204                                                 alarm_id, auto_connect_timer.retry_count);
1205
1206         if (alarm_id != auto_connect_timer.alarm_id)
1207                 return 0;
1208
1209         address = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
1210
1211         if (address == NULL) {
1212                 BT_ERR("Address vconf is null");
1213                 auto_connect_timer.alarm_id = 0;
1214                 return 0;
1215         }
1216
1217         BT_DBG("ADDRESS [%s]", address);
1218
1219         result = _bt_connect_profile(address, A2DP_SOURCE_UUID,
1220                         __bt_auto_connect_request_cb, NULL);
1221
1222         auto_connect_timer.retry_count--;
1223
1224         BT_DBG("result [%d]", result);
1225
1226         if (auto_connect_timer.retry_count <= 0) {
1227                 BT_INFO("Stopping Auto connect retry");
1228                 auto_connect_timer.alarm_id = 0;
1229         } else {
1230                 result = _bt_service_set_alarm(BT_AUTO_CONNECT_TIMEOUT_AFTER_LINKLOSS,
1231                                                 __bt_auto_connect_alarm_cb, NULL, &new_alarm_id);
1232                 if (result == BLUETOOTH_ERROR_NONE)
1233                         auto_connect_timer.alarm_id = new_alarm_id;
1234         }
1235
1236         free(address);
1237         return 0;
1238 }
1239
1240 static void __bt_auto_connect_alarm_remove()
1241 {
1242         BT_DBG("");
1243         if (auto_connect_timer.alarm_id > 0) {
1244                 _bt_service_remove_alarm(auto_connect_timer.alarm_id);
1245                 auto_connect_timer.alarm_id = 0;
1246         }
1247         auto_connect_timer.retry_count = 0;
1248 }
1249
1250 int _bt_audio_start_auto_connect(gboolean linkloss_flag)
1251 {
1252         int result = BLUETOOTH_ERROR_NONE;
1253         char *address = NULL;
1254         alarm_id_t alarm_id = 0;
1255
1256         BT_DBG("");
1257
1258         address = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
1259
1260         if (address == NULL) {
1261                 BT_ERR("No target device");
1262                 return 0;
1263         }
1264
1265         __bt_auto_connect_alarm_remove();
1266
1267         auto_connect_timer.retry_count =  BT_AUTO_CONNECT_TIMEOUT_RETRY_TIME /
1268                                                 BT_AUTO_CONNECT_TIMEOUT_AFTER_LINKLOSS;
1269
1270         if (linkloss_flag) {
1271                 BT_INFO("Start auto connection after linkloss");
1272                 result = _bt_service_set_alarm(BT_AUTO_CONNECT_TIMEOUT_AFTER_LINKLOSS,
1273                                                 __bt_auto_connect_alarm_cb, NULL, &alarm_id);
1274                 if (result != BLUETOOTH_ERROR_NONE)
1275                         g_timeout_add(500, (GSourceFunc)__bt_audio_alarm_retry_cb, NULL);
1276                 else
1277                         auto_connect_timer.alarm_id = alarm_id;
1278
1279         } else {
1280                 BT_INFO("Start auto connection after BT activated");
1281                 result = _bt_service_set_alarm(BT_AUTO_CONNECT_TIMEOUT_AFTER_BT_ACTIVATED,
1282                                                 __bt_auto_connect_alarm_cb, NULL, &alarm_id);
1283                 if (result == BLUETOOTH_ERROR_NONE)
1284                         auto_connect_timer.alarm_id = alarm_id;
1285         }
1286
1287         free(address);
1288         return BLUETOOTH_ERROR_NONE;
1289 }
1290
1291 int _bt_audio_stop_auto_connect(void)
1292 {
1293         BT_DBG("");
1294         __bt_auto_connect_alarm_remove();
1295
1296         return BLUETOOTH_ERROR_NONE;
1297 }
1298
1299 void _bt_audio_set_auto_connect_device_addr(const char *address)
1300 {
1301         if (address == NULL) {
1302                 BT_ERR("address is null");
1303                 return;
1304         }
1305
1306         BT_INFO("Last connected device is [%s]", address);
1307         vconf_set_str(BT_LAST_CONNECTED_DEVICE, address);
1308 }
1309 #endif /*TIZEN_BT_A2DP_SINK_AUTO_CONNECT */
1310
1311 int _bt_audio_select_role(bluetooth_audio_role_t role)
1312 {
1313
1314         GDBusProxy *proxy;
1315         GVariant *ret;
1316         GError *error = NULL;
1317         GDBusConnection *g_conn = _bt_gdbus_get_system_gconn();
1318         gchar *adapter_path = _bt_get_adapter_path();
1319
1320         BT_INFO("_bt_audio_select_role called [%d]", role);
1321
1322         retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
1323         BT_INFO("Adapter Path = %s", adapter_path);
1324
1325         proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
1326                 BT_BLUEZ_NAME, adapter_path, BT_MEDIA_INTERFACE, NULL, &error);
1327
1328         g_free(adapter_path);
1329
1330         if (proxy == NULL) {
1331                 BT_ERR("Unable to create proxy");
1332
1333                 if (error) {
1334                         BT_ERR("Error: %s", error->message);
1335                         g_clear_error(&error);
1336                 }
1337
1338                 return BLUETOOTH_ERROR_INTERNAL;
1339         }
1340
1341         if (role == BLUETOOTH_A2DP_SOURCE)
1342                 ret = g_dbus_proxy_call_sync(proxy, "SelectRole", g_variant_new("(s)", "source"),
1343                         G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1344         else
1345                 ret = g_dbus_proxy_call_sync(proxy, "SelectRole", g_variant_new("(s)", "sink"),
1346                         G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1347
1348         g_object_unref(proxy);
1349
1350         if (ret == NULL) {
1351                 BT_ERR("Call SelectRole Failed");
1352                 if (error) {
1353                         BT_ERR("errCode[%x], message[%s]", error->code, error->message);
1354                         g_clear_error(&error);
1355                 }
1356
1357                 return BLUETOOTH_ERROR_INTERNAL;
1358         }
1359
1360         g_variant_unref(ret);
1361         return BLUETOOTH_ERROR_NONE;
1362 }