2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
25 #include <net_connection.h>
26 #include <dbus/dbus.h>
32 #include <net_connection.h>
34 #include <eventsystem.h>
36 #include "bluetooth-api.h"
37 #include "bt-service-common.h"
38 #include "bt-service-agent.h"
40 static GDBusConnection *system_conn;
41 static GDBusConnection *session_conn;
42 static GDBusProxy *manager_proxy;
43 static GDBusProxy *adapter_proxy;
44 static void *net_conn;
46 static GDBusProxy *adapter_properties_proxy;
48 GDBusConnection *_bt_gdbus_init_system_gconn(void)
52 dbus_threads_init_default();
54 if (system_conn != NULL)
57 system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
60 BT_ERR("Unable to connect to dbus: %s", error->message);
61 g_clear_error(&error);
67 GDBusConnection *_bt_gdbus_get_system_gconn(void)
69 GDBusConnection *local_system_gconn = NULL;
72 if (system_conn == NULL) {
73 system_conn = _bt_gdbus_init_system_gconn();
74 } else if (g_dbus_connection_is_closed(system_conn)) {
75 local_system_gconn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
77 if (!local_system_gconn) {
78 BT_ERR("Unable to connect to dbus: %s", error->message);
79 g_clear_error(&error);
82 system_conn = local_system_gconn;
88 GDBusConnection *_bt_gdbus_init_session_gconn(void)
92 dbus_threads_init_default();
94 if (session_conn != NULL)
97 session_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
100 BT_ERR("Unable to connect to dbus: %s", error->message);
101 g_clear_error(&error);
107 GDBusConnection *_bt_gdbus_get_session_gconn(void)
109 GDBusConnection *local_session_gconn = NULL;
110 GError *error = NULL;
112 if (session_conn == NULL) {
113 session_conn = _bt_gdbus_init_session_gconn();
114 } else if (g_dbus_connection_is_closed(session_conn)) {
115 local_session_gconn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
117 if (!local_session_gconn) {
118 BT_ERR("Unable to connect to dbus: %s", error->message);
119 g_clear_error(&error);
122 session_conn = local_session_gconn;
128 static GDBusProxy *__bt_init_manager_proxy(void)
130 GDBusConnection *g_conn;
133 dbus_threads_init_default();
135 g_conn = _bt_gdbus_get_system_gconn();
136 retv_if(g_conn == NULL, NULL);
138 proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
140 BT_MANAGER_PATH, BT_MANAGER_INTERFACE, NULL, NULL);
143 BT_ERR("Unable to get proxy");
147 manager_proxy = proxy;
152 static GDBusProxy *__bt_init_adapter_proxy(void)
154 GDBusConnection *g_conn;
155 GDBusProxy *manager_proxy;
157 char *adapter_path = NULL;
159 dbus_threads_init_default();
161 g_conn = _bt_gdbus_get_system_gconn();
162 retv_if(g_conn == NULL, NULL);
164 manager_proxy = _bt_get_manager_proxy();
165 retv_if(manager_proxy == NULL, NULL);
167 adapter_path = _bt_get_adapter_path();
168 retv_if(adapter_path == NULL, NULL);
170 proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
172 adapter_path, BT_ADAPTER_INTERFACE, NULL, NULL);
174 g_free(adapter_path);
176 retv_if(proxy == NULL, NULL);
178 adapter_proxy = proxy;
183 static GDBusProxy *__bt_init_adapter_properties_proxy(void)
185 GDBusConnection *g_conn;
186 GDBusProxy *manager_proxy;
188 char *adapter_path = NULL;
190 dbus_threads_init_default();
192 g_conn = _bt_gdbus_get_system_gconn();
193 retv_if(g_conn == NULL, NULL);
195 manager_proxy = _bt_get_manager_proxy();
196 retv_if(manager_proxy == NULL, NULL);
198 adapter_path = _bt_get_adapter_path();
199 retv_if(adapter_path == NULL, NULL);
201 proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
203 adapter_path, BT_PROPERTIES_INTERFACE, NULL, NULL);
205 g_free(adapter_path);
207 retv_if(proxy == NULL, NULL);
209 adapter_properties_proxy = proxy;
214 GDBusProxy *_bt_get_manager_proxy(void)
217 const gchar *path = g_dbus_proxy_get_object_path(manager_proxy);
219 BT_ERR("Already proxy released hence creating new proxy");
220 return __bt_init_manager_proxy();
222 return manager_proxy;
224 return __bt_init_manager_proxy();
227 static void *__bt_init_net_conn(void)
230 connection_h connection = NULL;
232 if (net_conn == NULL) {
233 result = connection_create(&connection);
235 if (result != CONNECTION_ERROR_NONE ||
236 connection == NULL) {
237 BT_DBG("connection_create() failed: %d", result);
241 net_conn = connection;
246 void *_bt_get_net_conn(void)
248 return (net_conn) ? net_conn : __bt_init_net_conn();
251 GDBusProxy *_bt_get_adapter_proxy(void)
254 const char *path = g_dbus_proxy_get_object_path(adapter_proxy);
256 BT_ERR("Already proxy released hence creating new proxy");
257 return __bt_init_adapter_proxy();
260 return adapter_proxy;
262 return __bt_init_adapter_proxy();
266 GDBusProxy *_bt_get_adapter_properties_proxy(void)
268 return (adapter_properties_proxy) ? adapter_properties_proxy :
269 __bt_init_adapter_properties_proxy();
272 static char *__bt_extract_adapter_path(GVariantIter *iter)
274 char *object_path = NULL;
275 GVariantIter *interface_iter;
276 GVariantIter *svc_iter;
277 char *interface_str = NULL;
279 /* Parse the signature: oa{sa{sv}}} */
280 while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path,
283 if (object_path == NULL)
286 while (g_variant_iter_loop(interface_iter, "{&sa{sv}}",
287 &interface_str, &svc_iter)) {
288 if (g_strcmp0(interface_str, "org.bluez.Adapter1") != 0)
291 BT_DBG("Object Path: %s", object_path);
292 g_variant_iter_free(svc_iter);
293 g_variant_iter_free(interface_iter);
294 return g_strdup(object_path);
300 char *_bt_get_adapter_path(void)
302 GDBusConnection *conn;
303 GDBusProxy *manager_proxy;
304 GVariant *result = NULL;
305 GVariantIter *iter = NULL;
306 char *adapter_path = NULL;
308 conn = _bt_gdbus_get_system_gconn();
309 retv_if(conn == NULL, NULL);
311 manager_proxy = _bt_get_manager_proxy();
312 retv_if(manager_proxy == NULL, NULL);
314 result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
316 G_DBUS_CALL_FLAGS_NONE,
321 BT_ERR("Can't get managed objects");
325 /* signature of GetManagedObjects: a{oa{sa{sv}}} */
326 g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
328 adapter_path = __bt_extract_adapter_path(iter);
329 g_variant_iter_free(iter);
330 g_variant_unref(result);
334 void _bt_deinit_bluez_proxy(void)
337 g_object_unref(manager_proxy);
338 manager_proxy = NULL;
342 g_object_unref(adapter_proxy);
343 adapter_proxy = NULL;
345 if (adapter_properties_proxy) {
346 g_object_unref(adapter_properties_proxy);
347 adapter_properties_proxy = NULL;
351 void _bt_deinit_proxys(void)
354 _bt_deinit_bluez_proxy();
357 g_object_unref(system_conn);
362 g_object_unref(session_conn);
367 ret = connection_destroy(net_conn);
370 BT_ERR("connection_destroy failed : %d", ret);
374 void _bt_convert_device_path_to_address(const char *device_path,
375 char *device_address)
377 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
380 ret_if(device_path == NULL);
381 ret_if(device_address == NULL);
383 dev_addr = strstr(device_path, "dev_");
384 if (dev_addr != NULL) {
387 g_strlcpy(address, dev_addr, sizeof(address));
389 while ((pos = strchr(address, '_')) != NULL)
392 g_strlcpy(device_address, address, BT_ADDRESS_STRING_SIZE);
397 void _bt_convert_addr_string_to_type(unsigned char *addr,
403 ret_if(address == NULL);
404 ret_if(addr == NULL);
406 for (i = 0; i < BT_ADDRESS_LENGTH_MAX; i++) {
407 addr[i] = strtol(address, &ptr, 16);
408 if (ptr[0] != '\0') {
417 void _bt_convert_addr_string_to_secure_string(char *addr,
422 ret_if(address == NULL);
423 ret_if(addr == NULL);
425 len = strlen(address);
426 ret_if(len != BT_ADDRESS_STRING_SIZE - 1);
428 strncpy(addr, address, len);
436 void _bt_convert_addr_type_to_string(char *address,
439 ret_if(address == NULL);
440 ret_if(addr == NULL);
442 snprintf(address, BT_ADDRESS_STRING_SIZE,
443 "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
444 addr[0], addr[1], addr[2],
445 addr[3], addr[4], addr[5]);
448 void _bt_print_device_address_t(const bluetooth_device_address_t *addr)
450 BT_DBG("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n", addr->addr[0], addr->addr[1], addr->addr[2],
451 addr->addr[3], addr->addr[4], addr->addr[5]);
454 void _bt_divide_device_class(bluetooth_device_class_t *device_class,
457 ret_if(device_class == NULL);
459 device_class->major_class = (unsigned short)(cod & 0x00001F00) >> 8;
460 device_class->minor_class = (unsigned short)((cod & 0x000000FC));
461 device_class->service_class = (unsigned long)((cod & 0x00FF0000));
463 if (cod & 0x002000) {
464 device_class->service_class |=
465 BLUETOOTH_DEVICE_SERVICE_CLASS_LIMITED_DISCOVERABLE_MODE;
469 void _bt_free_device_info(bt_remote_dev_info_t *dev_info)
473 ret_if(dev_info == NULL);
475 g_free(dev_info->address);
476 g_free(dev_info->name);
477 g_free(dev_info->manufacturer_data);
479 if (dev_info->uuids) {
480 for (i = 0; i < dev_info->uuid_count && dev_info->uuids[i]; i++)
481 g_free(dev_info->uuids[i]);
483 g_free(dev_info->uuids);
489 void _bt_free_le_device_info(bt_remote_le_dev_info_t *le_dev_info)
491 ret_if(le_dev_info == NULL);
493 g_free(le_dev_info->adv_data);
497 int _bt_copy_utf8_string(char *dest, const char *src, unsigned int length)
504 if (dest == NULL || src == NULL)
505 return BLUETOOTH_ERROR_INVALID_PARAM;
507 BT_DBG("+src : %s", src);
508 BT_DBG("+dest : %s", dest);
511 while (*p != '\0' && i < length) {
512 next = g_utf8_next_char(p);
515 while (count > 0 && ((i + count) < length)) {
522 return BLUETOOTH_ERROR_NONE;
525 gboolean _bt_utf8_validate(char *name)
529 glong items_written = 0;
531 if (FALSE == g_utf8_validate(name, -1, NULL))
534 u16 = g_utf8_to_utf16(name, -1, NULL, &items_written, NULL);
540 if (items_written != g_utf8_strlen(name, -1))
547 int _bt_register_osp_server_in_agent(int type, char *uuid, char *path, int fd)
550 if (!_bt_agent_register_osp_server(type, uuid, path, fd))
551 return BLUETOOTH_ERROR_INTERNAL;
553 return BLUETOOTH_ERROR_NONE;
556 int _bt_unregister_osp_server_in_agent(int type, char *uuid)
559 if (!_bt_agent_unregister_osp_server(type, uuid))
560 return BLUETOOTH_ERROR_INTERNAL;
562 return BLUETOOTH_ERROR_NONE;
565 int _bt_set_socket_non_blocking(int socket_fd)
567 /* Set Nonblocking */
570 arg = fcntl(socket_fd, F_GETFL);
575 if (arg & O_NONBLOCK)
576 BT_ERR("Already Non-blocking \n");
580 if (fcntl(socket_fd, F_SETFL, arg) < 0)
583 return BLUETOOTH_ERROR_NONE;
586 int _bt_set_non_blocking_tty(int sk)
588 struct termios ti = {0,};
591 err = _bt_set_socket_non_blocking(sk);
594 BT_ERR("Error in set non blocking!\n");
598 tcflush(sk, TCIOFLUSH);
600 /* Switch tty to RAW mode */
602 tcsetattr(sk, TCSANOW, &ti);
604 return BLUETOOTH_ERROR_NONE;
607 static char *__bt_extract_device_path(GVariantIter *iter, char *address)
609 char *object_path = NULL;
610 char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
612 /* Parse the signature: oa{sa{sv}}} */
613 while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path,
616 BT_ERR("Unable to get object path");
619 _bt_convert_device_path_to_address(object_path, device_address);
620 if (g_strcmp0(address, device_address) == 0)
621 return g_strdup(object_path);
625 BT_ERR("Unable to get object path");
629 char *_bt_get_device_object_path(char *address)
631 char *object_path = NULL;
632 GDBusConnection *conn;
633 GDBusProxy *manager_proxy;
634 GVariant *result = NULL;
635 GVariantIter *iter = NULL;
637 conn = _bt_gdbus_get_system_gconn();
638 retv_if(conn == NULL, NULL);
640 manager_proxy = _bt_get_manager_proxy();
641 retv_if(manager_proxy == NULL, NULL);
643 result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
645 G_DBUS_CALL_FLAGS_NONE,
650 BT_ERR("Can't get managed objects");
654 /* signature of GetManagedObjects: a{oa{sa{sv}}} */
655 g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
656 object_path = __bt_extract_device_path(iter, address);
657 g_variant_iter_free(iter);
658 g_variant_unref(result);
662 char *_bt_get_profile_uuid128(bt_profile_type_t profile_type)
664 switch (profile_type) {
665 case BT_PROFILE_CONN_RFCOMM:
666 return strdup(RFCOMM_UUID_STR);
667 case BT_PROFILE_CONN_A2DP:
668 return strdup(A2DP_SINK_UUID);
669 case BT_PROFILE_CONN_A2DP_SINK:
670 return strdup(A2DP_SOURCE_UUID);
671 case BT_PROFILE_CONN_HSP:
672 return strdup(HFP_HS_UUID);
673 case BT_PROFILE_CONN_HID:
674 return strdup(HID_UUID);
675 case BT_PROFILE_CONN_NAP:
676 return strdup(NAP_UUID);
677 case BT_PROFILE_CONN_HFG:
678 return strdup(HFP_AG_UUID);
679 case BT_PROFILE_CONN_PBAP:
680 return strdup(PBAP_UUID);
681 case BT_PROFILE_CONN_GATT:
682 case BT_PROFILE_CONN_ALL: /* NULL UUID will connect to both the audio profiles*/
688 char *_bt_convert_error_to_string(int error)
691 case BLUETOOTH_ERROR_CANCEL:
693 case BLUETOOTH_ERROR_INVALID_PARAM:
694 return "INVALID_PARAMETER";
695 case BLUETOOTH_ERROR_INVALID_DATA:
696 return "INVALID DATA";
697 case BLUETOOTH_ERROR_MEMORY_ALLOCATION:
698 case BLUETOOTH_ERROR_OUT_OF_MEMORY:
699 return "OUT_OF_MEMORY";
700 case BLUETOOTH_ERROR_TIMEOUT:
702 case BLUETOOTH_ERROR_NO_RESOURCES:
703 return "NO_RESOURCES";
704 case BLUETOOTH_ERROR_INTERNAL:
706 case BLUETOOTH_ERROR_NOT_SUPPORT:
707 return "NOT_SUPPORT";
708 case BLUETOOTH_ERROR_DEVICE_NOT_ENABLED:
709 return "NOT_ENABLED";
710 case BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED:
711 return "ALREADY_ENABLED";
712 case BLUETOOTH_ERROR_DEVICE_BUSY:
713 return "DEVICE_BUSY";
714 case BLUETOOTH_ERROR_ACCESS_DENIED:
715 return "ACCESS_DENIED";
716 case BLUETOOTH_ERROR_MAX_CLIENT:
718 case BLUETOOTH_ERROR_NOT_FOUND:
720 case BLUETOOTH_ERROR_SERVICE_SEARCH_ERROR:
721 return "SERVICE_SEARCH_ERROR";
722 case BLUETOOTH_ERROR_PARING_FAILED:
723 return "PARING_FAILED";
724 case BLUETOOTH_ERROR_NOT_PAIRED:
726 case BLUETOOTH_ERROR_SERVICE_NOT_FOUND:
727 return "SERVICE_NOT_FOUND";
728 case BLUETOOTH_ERROR_NOT_CONNECTED:
729 return "NOT_CONNECTED";
730 case BLUETOOTH_ERROR_ALREADY_CONNECT:
731 return "ALREADY_CONNECT";
732 case BLUETOOTH_ERROR_CONNECTION_BUSY:
733 return "CONNECTION_BUSY";
734 case BLUETOOTH_ERROR_CONNECTION_ERROR:
735 return "CONNECTION_ERROR";
736 case BLUETOOTH_ERROR_MAX_CONNECTION:
737 return "MAX_CONNECTION";
738 case BLUETOOTH_ERROR_NOT_IN_OPERATION:
739 return "NOT_IN_OPERATION";
740 case BLUETOOTH_ERROR_CANCEL_BY_USER:
741 return "CANCEL_BY_USER";
742 case BLUETOOTH_ERROR_REGISTRATION_FAILED:
743 return "REGISTRATION_FAILED";
744 case BLUETOOTH_ERROR_IN_PROGRESS:
745 return "IN_PROGRESS";
746 case BLUETOOTH_ERROR_AUTHENTICATION_FAILED:
747 return "AUTHENTICATION_FAILED";
748 case BLUETOOTH_ERROR_HOST_DOWN:
750 case BLUETOOTH_ERROR_END_OF_DEVICE_LIST:
751 return "END_OF_DEVICE_LIST";
752 case BLUETOOTH_ERROR_AGENT_ALREADY_EXIST:
753 return "AGENT_ALREADY_EXIST";
754 case BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST:
755 return "AGENT_DOES_NOT_EXIST";
756 case BLUETOOTH_ERROR_ALREADY_INITIALIZED:
757 return "ALREADY_INITIALIZED";
758 case BLUETOOTH_ERROR_PERMISSION_DEINED:
759 return "PERMISSION_DEINED";
760 case BLUETOOTH_ERROR_ALREADY_DEACTIVATED:
761 return "ALREADY_DEACTIVATED";
762 case BLUETOOTH_ERROR_NOT_INITIALIZED:
763 return "NOT_INITIALIZED";
764 case BLUETOOTH_ERROR_AUTHENTICATION_REJECTED:
765 return "AUTHENTICATION REJECTED";
771 char * _bt_convert_disc_reason_to_string(int reason)
774 case (int)BLUETOOTH_ERROR_PAGE_TIMEOUT:
775 return "Page timeout";
776 case (int)BLUETOOTH_ERROR_CONNECTION_TIMEOUT:
778 case (int)BLUETOOTH_ERROR_PIN_OR_KEY_MISSING:
779 return "PIN or Key missing";
780 case (int)BLUETOOTH_ERROR_LOCAL_HOST_TERM:
781 return "Connection terminated by local host";
782 case (int)BLUETOOTH_ERROR_REMOTE_USER_TERM:
783 case (int)BLUETOOTH_ERROR_REMOTE_LOW_RESOURCES:
784 case (int)BLUETOOTH_ERROR_REMOTE_POWER_OFF:
785 return "Remote user terminated connection";
786 case (int)BLUETOOTH_ERROR_AUTH_FAILURE:
787 return "Authentication Failure";
788 case (int)BLUETOOTH_ERROR_REPEATED_ATTEMPTS:
789 return "Repeated attempts";
790 case (int)BLUETOOTH_ERROR_LMP_RESPONSE_TIMEOUT:
791 return "LMP response timeout";
792 case (int)BLUETOOTH_ERROR_CONNECTION_FAILED_TO_BE_ESTABLISHED:
793 return "Connection failed to be established";
799 void _bt_logging_connection(gboolean connect, int addr_type)
801 static int le_conn = 0;
802 static int le_disc = 0;
803 static int edr_conn = 0;
804 static int edr_disc = 0;
818 BT_INFO("[PM] Number of LE conn: %d disc: %d, Number of BR/EDR conn: %d disc: %d",
819 le_conn, le_disc, edr_conn, edr_disc);
822 void _bt_swap_byte_ordering(char *data, int data_len)
826 int half = data_len / 2;
828 ret_if(data == NULL);
829 /* Swap to opposite endian */
830 for (i = 0, j = data_len - 1; i < half; i++, j--) {
837 int _bt_byte_arr_cmp(const char *data1, const char *data2, int data_len)
841 retv_if(data1 == NULL, -1);
842 retv_if(data2 == NULL, -1);
843 for (i = 0; i < data_len; i++) {
844 if (data1[i] != data2[i])
845 return data1[i] - data2[i];
849 int _bt_byte_arr_cmp_with_mask(const char *data1, const char *data2,
850 const char *mask, int data_len)
855 retv_if(data1 == NULL, -1);
856 retv_if(data2 == NULL, -1);
857 retv_if(mask == NULL, -1);
858 for (i = 0; i < data_len; i++) {
859 a = data1[i] & mask[i];
860 b = data2[i] & mask[i];
867 int _bt_eventsystem_set_value(const char *event, const char *key, const char *value)
870 /* Send event system event in bt-core process because bt-service's permission is not system in now */
876 bundle_add_str(b, key, value);
878 ret = eventsystem_send_system_event(event, b);
880 BT_DBG("eventsystem_send_system_event result: %d", ret);
887 void __bt_get_auth_info(GVariant *reply, char *auth_info)
891 char *manufacturer_data = NULL;
892 int manufacturer_data_len;
893 gboolean is_alias_set;
894 GVariantIter *value_iter;
898 tmp_value = g_variant_lookup_value(reply, "IsAliasSet",
899 G_VARIANT_TYPE_BOOLEAN);
901 is_alias_set = g_variant_get_boolean(tmp_value);
902 g_variant_unref(tmp_value);
904 is_alias_set = FALSE;
906 if (is_alias_set == FALSE) {
907 tmp_value = g_variant_lookup_value(reply, "ManufacturerDataLen",
908 G_VARIANT_TYPE_UINT16);
910 manufacturer_data_len = g_variant_get_uint16(tmp_value);
911 if (manufacturer_data_len >
912 BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) {
913 BT_ERR("manufacturer_data_len is too long");
914 manufacturer_data_len = BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX;
916 g_variant_unref(tmp_value);
918 manufacturer_data_len = 0;
920 tmp_value = g_variant_lookup_value(reply, "ManufacturerData",
921 G_VARIANT_TYPE_ARRAY);
923 if ((manufacturer_data_len == 0) ||
924 manufacturer_data_len != g_variant_get_size(tmp_value)) {
925 BT_ERR("manufacturer data length doesn't match");
926 manufacturer_data_len = 0;
927 manufacturer_data = NULL;
929 manufacturer_data = g_malloc0(manufacturer_data_len);
930 g_variant_get(tmp_value, "ay", &value_iter);
931 while (g_variant_iter_loop(value_iter, "y", &m_value))
932 manufacturer_data[i++] = m_value;
934 g_variant_unref(tmp_value);
936 BT_INFO("manufacture data is not a G_VARIANT_TYPE_ARRAY ");
937 manufacturer_data_len = 0;
938 manufacturer_data = NULL;
940 /*minimum Size of the samsung specific manufacturer data is greater than 30 */
941 if (manufacturer_data_len < 30) {
942 g_free(manufacturer_data);
945 if (manufacturer_data[0] != 0x00 || manufacturer_data[1] != 0x75) {
946 BT_DBG("This is not a samsung specific manufaturer data");
947 g_free(manufacturer_data);
951 /* 2 samsung (0x00 0x75) + 1 (control and version) + 1 (service ID) +
952 1 (discovery version) + 1 (associated service ID)
953 2 (Proxamity and locality) + 2 (Device type and icon) */
957 memcpy(auth_info, &(manufacturer_data[cursor]), 5);
959 g_free(manufacturer_data);
962 int _bt_convert_gerror(GError *g_error)
964 int ret = BLUETOOTH_ERROR_INTERNAL;
967 if (!g_dbus_error_strip_remote_error(g_error))
970 str = g_error->message;
972 if (g_strcmp0(str, "Connection refused") == 0)
973 ret = BLUETOOTH_ERROR_AUTHENTICATION_REJECTED;
974 else if (g_strcmp0(str, "Connection timed out") == 0)
975 ret = BLUETOOTH_ERROR_TIMEOUT;
976 else if (g_strcmp0(str, "In Progress") == 0)
977 ret = BLUETOOTH_ERROR_IN_PROGRESS;