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 if (!g_thread_supported()) {
96 dbus_threads_init_default();
98 if (session_conn != NULL)
101 session_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
104 BT_ERR("Unable to connect to dbus: %s", error->message);
105 g_clear_error(&error);
111 GDBusConnection *_bt_gdbus_get_session_gconn(void)
113 GDBusConnection *local_session_gconn = NULL;
114 GError *error = NULL;
116 if (session_conn == NULL) {
117 session_conn = _bt_gdbus_init_session_gconn();
118 } else if (g_dbus_connection_is_closed(session_conn)) {
119 local_session_gconn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
121 if (!local_session_gconn) {
122 BT_ERR("Unable to connect to dbus: %s", error->message);
123 g_clear_error(&error);
126 session_conn = local_session_gconn;
132 static GDBusProxy *__bt_init_manager_proxy(void)
134 GDBusConnection *g_conn;
137 dbus_threads_init_default();
139 g_conn = _bt_gdbus_get_system_gconn();
140 retv_if(g_conn == NULL, NULL);
142 proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
144 BT_MANAGER_PATH, BT_MANAGER_INTERFACE, NULL, NULL);
147 BT_ERR("Unable to get proxy");
151 manager_proxy = proxy;
156 static GDBusProxy *__bt_init_adapter_proxy(void)
158 GDBusConnection *g_conn;
159 GDBusProxy *manager_proxy;
161 char *adapter_path = NULL;
163 dbus_threads_init_default();
165 g_conn = _bt_gdbus_get_system_gconn();
166 retv_if(g_conn == NULL, NULL);
168 manager_proxy = _bt_get_manager_proxy();
169 retv_if(manager_proxy == NULL, NULL);
171 adapter_path = _bt_get_adapter_path();
172 retv_if(adapter_path == NULL, NULL);
174 proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
176 adapter_path, BT_ADAPTER_INTERFACE, NULL, NULL);
178 g_free(adapter_path);
180 retv_if(proxy == NULL, NULL);
182 adapter_proxy = proxy;
187 static GDBusProxy *__bt_init_adapter_properties_proxy(void)
189 GDBusConnection *g_conn;
190 GDBusProxy *manager_proxy;
192 char *adapter_path = NULL;
194 dbus_threads_init_default();
196 g_conn = _bt_gdbus_get_system_gconn();
197 retv_if(g_conn == NULL, NULL);
199 manager_proxy = _bt_get_manager_proxy();
200 retv_if(manager_proxy == NULL, NULL);
202 adapter_path = _bt_get_adapter_path();
203 retv_if(adapter_path == NULL, NULL);
205 proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
207 adapter_path, BT_PROPERTIES_INTERFACE, NULL, NULL);
209 g_free(adapter_path);
211 retv_if(proxy == NULL, NULL);
213 adapter_properties_proxy = proxy;
218 GDBusProxy *_bt_get_manager_proxy(void)
221 const gchar *path = g_dbus_proxy_get_object_path(manager_proxy);
223 BT_ERR("Already proxy released hence creating new proxy");
224 return __bt_init_manager_proxy();
226 return manager_proxy;
228 return __bt_init_manager_proxy();
231 static void *__bt_init_net_conn(void)
234 connection_h connection = NULL;
236 if (net_conn == NULL) {
237 result = connection_create(&connection);
239 if (result != CONNECTION_ERROR_NONE ||
240 connection == NULL) {
241 BT_DBG("connection_create() failed: %d", result);
245 net_conn = connection;
250 void *_bt_get_net_conn(void)
252 return (net_conn) ? net_conn : __bt_init_net_conn();
255 GDBusProxy *_bt_get_adapter_proxy(void)
258 const char *path = g_dbus_proxy_get_object_path(adapter_proxy);
260 BT_ERR("Already proxy released hence creating new proxy");
261 return __bt_init_adapter_proxy();
264 return adapter_proxy;
266 return __bt_init_adapter_proxy();
270 GDBusProxy *_bt_get_adapter_properties_proxy(void)
272 return (adapter_properties_proxy) ? adapter_properties_proxy :
273 __bt_init_adapter_properties_proxy();
276 static char *__bt_extract_adapter_path(GVariantIter *iter)
278 char *object_path = NULL;
279 GVariantIter *interface_iter;
280 GVariantIter *svc_iter;
281 char *interface_str = NULL;
283 /* Parse the signature: oa{sa{sv}}} */
284 while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path,
287 if (object_path == NULL)
290 while (g_variant_iter_loop(interface_iter, "{&sa{sv}}",
291 &interface_str, &svc_iter)) {
292 if (g_strcmp0(interface_str, "org.bluez.Adapter1") != 0)
295 BT_DBG("Object Path: %s", object_path);
296 g_variant_iter_free(svc_iter);
297 g_variant_iter_free(interface_iter);
298 return g_strdup(object_path);
304 char *_bt_get_adapter_path(void)
306 GDBusConnection *conn;
307 GDBusProxy *manager_proxy;
308 GVariant *result = NULL;
309 GVariantIter *iter = NULL;
310 char *adapter_path = NULL;
312 conn = _bt_gdbus_get_system_gconn();
313 retv_if(conn == NULL, NULL);
315 manager_proxy = _bt_get_manager_proxy();
316 retv_if(manager_proxy == NULL, NULL);
318 result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
320 G_DBUS_CALL_FLAGS_NONE,
325 BT_ERR("Can't get managed objects");
329 /* signature of GetManagedObjects: a{oa{sa{sv}}} */
330 g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
332 adapter_path = __bt_extract_adapter_path(iter);
333 g_variant_iter_free(iter);
334 g_variant_unref(result);
338 void _bt_deinit_bluez_proxy(void)
341 g_object_unref(manager_proxy);
342 manager_proxy = NULL;
346 g_object_unref(adapter_proxy);
347 adapter_proxy = NULL;
349 if (adapter_properties_proxy) {
350 g_object_unref(adapter_properties_proxy);
351 adapter_properties_proxy = NULL;
355 void _bt_deinit_proxys(void)
358 _bt_deinit_bluez_proxy();
361 g_object_unref(system_conn);
366 g_object_unref(session_conn);
371 ret = connection_destroy(net_conn);
374 BT_ERR("connection_destroy failed : %d", ret);
378 void _bt_convert_device_path_to_address(const char *device_path,
379 char *device_address)
381 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
384 ret_if(device_path == NULL);
385 ret_if(device_address == NULL);
387 dev_addr = strstr(device_path, "dev_");
388 if (dev_addr != NULL) {
391 g_strlcpy(address, dev_addr, sizeof(address));
393 while ((pos = strchr(address, '_')) != NULL) {
397 g_strlcpy(device_address, address, BT_ADDRESS_STRING_SIZE);
402 void _bt_convert_addr_string_to_type(unsigned char *addr,
408 ret_if(address == NULL);
409 ret_if(addr == NULL);
411 for (i = 0; i < BT_ADDRESS_LENGTH_MAX; i++) {
412 addr[i] = strtol(address, &ptr, 16);
413 if (ptr[0] != '\0') {
422 void _bt_convert_addr_string_to_secure_string(char *addr,
427 ret_if(address == NULL);
428 ret_if(addr == NULL);
430 len = strlen(address);
431 ret_if(len != BT_ADDRESS_STRING_SIZE - 1);
433 strncpy(addr, address, len);
441 void _bt_convert_addr_type_to_string(char *address,
444 ret_if(address == NULL);
445 ret_if(addr == NULL);
447 snprintf(address, BT_ADDRESS_STRING_SIZE,
448 "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
449 addr[0], addr[1], addr[2],
450 addr[3], addr[4], addr[5]);
453 void _bt_print_device_address_t(const bluetooth_device_address_t *addr)
455 BT_DBG("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n", addr->addr[0], addr->addr[1], addr->addr[2],
456 addr->addr[3], addr->addr[4], addr->addr[5]);
459 void _bt_divide_device_class(bluetooth_device_class_t *device_class,
462 ret_if(device_class == NULL);
464 device_class->major_class = (unsigned short)(cod & 0x00001F00) >> 8;
465 device_class->minor_class = (unsigned short)((cod & 0x000000FC));
466 device_class->service_class = (unsigned long)((cod & 0x00FF0000));
468 if (cod & 0x002000) {
469 device_class->service_class |=
470 BLUETOOTH_DEVICE_SERVICE_CLASS_LIMITED_DISCOVERABLE_MODE;
474 void _bt_free_device_info(bt_remote_dev_info_t *dev_info)
478 ret_if(dev_info == NULL);
480 g_free(dev_info->address);
481 g_free(dev_info->name);
482 g_free(dev_info->manufacturer_data);
484 if (dev_info->uuids) {
485 for (i = 0; i < dev_info->uuid_count && dev_info->uuids[i]; i++)
486 g_free(dev_info->uuids[i]);
488 g_free(dev_info->uuids);
494 void _bt_free_le_device_info(bt_remote_le_dev_info_t *le_dev_info)
496 ret_if(le_dev_info == NULL);
498 g_free(le_dev_info->adv_data);
502 int _bt_copy_utf8_string(char *dest, const char *src, unsigned int length)
509 if (dest == NULL || src == NULL)
510 return BLUETOOTH_ERROR_INVALID_PARAM;
512 BT_DBG("+src : %s", src);
513 BT_DBG("+dest : %s", dest);
516 while (*p != '\0' && i < length) {
517 next = g_utf8_next_char(p);
520 while (count > 0 && ((i + count) < length)) {
527 return BLUETOOTH_ERROR_NONE;
530 gboolean _bt_utf8_validate(char *name)
534 glong items_written = 0;
536 if (FALSE == g_utf8_validate(name, -1, NULL))
539 u16 = g_utf8_to_utf16(name, -1, NULL, &items_written, NULL);
545 if (items_written != g_utf8_strlen(name, -1))
552 int _bt_register_osp_server_in_agent(int type, char *uuid, char *path, int fd)
555 if (!_bt_agent_register_osp_server(type, uuid, path, fd))
556 return BLUETOOTH_ERROR_INTERNAL;
558 return BLUETOOTH_ERROR_NONE;
561 int _bt_unregister_osp_server_in_agent(int type, char *uuid)
564 if (!_bt_agent_unregister_osp_server(type, uuid))
565 return BLUETOOTH_ERROR_INTERNAL;
567 return BLUETOOTH_ERROR_NONE;
570 int _bt_set_socket_non_blocking(int socket_fd)
572 /* Set Nonblocking */
575 arg = fcntl(socket_fd, F_GETFL);
580 if (arg & O_NONBLOCK) {
581 BT_ERR("Already Non-blocking \n");
586 if (fcntl(socket_fd, F_SETFL, arg) < 0)
589 return BLUETOOTH_ERROR_NONE;
592 int _bt_set_non_blocking_tty(int sk)
594 struct termios ti = {0,};
597 err = _bt_set_socket_non_blocking(sk);
600 BT_ERR("Error in set non blocking!\n");
604 tcflush(sk, TCIOFLUSH);
606 /* Switch tty to RAW mode */
608 tcsetattr(sk, TCSANOW, &ti);
610 return BLUETOOTH_ERROR_NONE;
613 static char *__bt_extract_device_path(GVariantIter *iter, char *address)
615 char *object_path = NULL;
616 char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
618 /* Parse the signature: oa{sa{sv}}} */
619 while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path,
622 BT_ERR("Unable to get object path");
625 _bt_convert_device_path_to_address(object_path, device_address);
626 if (g_strcmp0(address, device_address) == 0) {
627 return g_strdup(object_path);
631 BT_ERR("Unable to get object path");
635 char *_bt_get_device_object_path(char *address)
637 char *object_path = NULL;
638 GDBusConnection *conn;
639 GDBusProxy *manager_proxy;
640 GVariant *result = NULL;
641 GVariantIter *iter = NULL;
643 conn = _bt_gdbus_get_system_gconn();
644 retv_if(conn == NULL, NULL);
646 manager_proxy = _bt_get_manager_proxy();
647 retv_if(manager_proxy == NULL, NULL);
649 result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
651 G_DBUS_CALL_FLAGS_NONE,
656 BT_ERR("Can't get managed objects");
660 /* signature of GetManagedObjects: a{oa{sa{sv}}} */
661 g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
662 object_path = __bt_extract_device_path(iter, address);
663 g_variant_iter_free(iter);
664 g_variant_unref(result);
668 char *_bt_get_profile_uuid128(bt_profile_type_t profile_type)
670 switch (profile_type) {
671 case BT_PROFILE_CONN_RFCOMM:
672 return strdup(RFCOMM_UUID_STR);
673 case BT_PROFILE_CONN_A2DP:
674 return strdup(A2DP_SINK_UUID);
675 case BT_PROFILE_CONN_A2DP_SINK:
676 return strdup(A2DP_SOURCE_UUID);
677 case BT_PROFILE_CONN_HSP:
678 return strdup(HFP_HS_UUID);
679 case BT_PROFILE_CONN_HID:
680 return strdup(HID_UUID);
681 case BT_PROFILE_CONN_NAP:
682 return strdup(NAP_UUID);
683 case BT_PROFILE_CONN_HFG:
684 return strdup(HFP_AG_UUID);
685 case BT_PROFILE_CONN_PBAP:
686 return strdup(PBAP_UUID);
687 case BT_PROFILE_CONN_GATT:
688 case BT_PROFILE_CONN_ALL: /* NULL UUID will connect to both the audio profiles*/
694 char *_bt_convert_error_to_string(int error)
697 case BLUETOOTH_ERROR_CANCEL:
699 case BLUETOOTH_ERROR_INVALID_PARAM:
700 return "INVALID_PARAMETER";
701 case BLUETOOTH_ERROR_INVALID_DATA:
702 return "INVALID DATA";
703 case BLUETOOTH_ERROR_MEMORY_ALLOCATION:
704 case BLUETOOTH_ERROR_OUT_OF_MEMORY:
705 return "OUT_OF_MEMORY";
706 case BLUETOOTH_ERROR_TIMEOUT:
708 case BLUETOOTH_ERROR_NO_RESOURCES:
709 return "NO_RESOURCES";
710 case BLUETOOTH_ERROR_INTERNAL:
712 case BLUETOOTH_ERROR_NOT_SUPPORT:
713 return "NOT_SUPPORT";
714 case BLUETOOTH_ERROR_DEVICE_NOT_ENABLED:
715 return "NOT_ENABLED";
716 case BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED:
717 return "ALREADY_ENABLED";
718 case BLUETOOTH_ERROR_DEVICE_BUSY:
719 return "DEVICE_BUSY";
720 case BLUETOOTH_ERROR_ACCESS_DENIED:
721 return "ACCESS_DENIED";
722 case BLUETOOTH_ERROR_MAX_CLIENT:
724 case BLUETOOTH_ERROR_NOT_FOUND:
726 case BLUETOOTH_ERROR_SERVICE_SEARCH_ERROR:
727 return "SERVICE_SEARCH_ERROR";
728 case BLUETOOTH_ERROR_PARING_FAILED:
729 return "PARING_FAILED";
730 case BLUETOOTH_ERROR_NOT_PAIRED:
732 case BLUETOOTH_ERROR_SERVICE_NOT_FOUND:
733 return "SERVICE_NOT_FOUND";
734 case BLUETOOTH_ERROR_NOT_CONNECTED:
735 return "NOT_CONNECTED";
736 case BLUETOOTH_ERROR_ALREADY_CONNECT:
737 return "ALREADY_CONNECT";
738 case BLUETOOTH_ERROR_CONNECTION_BUSY:
739 return "CONNECTION_BUSY";
740 case BLUETOOTH_ERROR_CONNECTION_ERROR:
741 return "CONNECTION_ERROR";
742 case BLUETOOTH_ERROR_MAX_CONNECTION:
743 return "MAX_CONNECTION";
744 case BLUETOOTH_ERROR_NOT_IN_OPERATION:
745 return "NOT_IN_OPERATION";
746 case BLUETOOTH_ERROR_CANCEL_BY_USER:
747 return "CANCEL_BY_USER";
748 case BLUETOOTH_ERROR_REGISTRATION_FAILED:
749 return "REGISTRATION_FAILED";
750 case BLUETOOTH_ERROR_IN_PROGRESS:
751 return "IN_PROGRESS";
752 case BLUETOOTH_ERROR_AUTHENTICATION_FAILED:
753 return "AUTHENTICATION_FAILED";
754 case BLUETOOTH_ERROR_HOST_DOWN:
756 case BLUETOOTH_ERROR_END_OF_DEVICE_LIST:
757 return "END_OF_DEVICE_LIST";
758 case BLUETOOTH_ERROR_AGENT_ALREADY_EXIST:
759 return "AGENT_ALREADY_EXIST";
760 case BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST:
761 return "AGENT_DOES_NOT_EXIST";
762 case BLUETOOTH_ERROR_ALREADY_INITIALIZED:
763 return "ALREADY_INITIALIZED";
764 case BLUETOOTH_ERROR_PERMISSION_DEINED:
765 return "PERMISSION_DEINED";
766 case BLUETOOTH_ERROR_ALREADY_DEACTIVATED:
767 return "ALREADY_DEACTIVATED";
768 case BLUETOOTH_ERROR_NOT_INITIALIZED:
769 return "NOT_INITIALIZED";
770 case BLUETOOTH_ERROR_AUTHENTICATION_REJECTED:
771 return "AUTHENTICATION REJECTED";
777 char * _bt_convert_disc_reason_to_string(int reason)
780 case (int)BLUETOOTH_ERROR_PAGE_TIMEOUT:
781 return "Page timeout";
782 case (int)BLUETOOTH_ERROR_CONNECTION_TIMEOUT:
784 case (int)BLUETOOTH_ERROR_PIN_OR_KEY_MISSING:
785 return "PIN or Key missing";
786 case (int)BLUETOOTH_ERROR_LOCAL_HOST_TERM:
787 return "Connection terminated by local host";
788 case (int)BLUETOOTH_ERROR_REMOTE_USER_TERM:
789 case (int)BLUETOOTH_ERROR_REMOTE_LOW_RESOURCES:
790 case (int)BLUETOOTH_ERROR_REMOTE_POWER_OFF:
791 return "Remote user terminated connection";
792 case (int)BLUETOOTH_ERROR_AUTH_FAILURE:
793 return "Authentication Failure";
794 case (int)BLUETOOTH_ERROR_REPEATED_ATTEMPTS:
795 return "Repeated attempts";
796 case (int)BLUETOOTH_ERROR_LMP_RESPONSE_TIMEOUT:
797 return "LMP response timeout";
798 case (int)BLUETOOTH_ERROR_CONNECTION_FAILED_TO_BE_ESTABLISHED:
799 return "Connection failed to be established";
805 void _bt_logging_connection(gboolean connect, int addr_type)
807 static int le_conn = 0;
808 static int le_disc = 0;
809 static int edr_conn = 0;
810 static int edr_disc = 0;
824 BT_INFO("[PM] Number of LE conn: %d disc: %d, Number of BR/EDR conn: %d disc: %d",
825 le_conn, le_disc, edr_conn, edr_disc);
828 void _bt_swap_byte_ordering(char *data, int data_len)
832 int half = data_len / 2;
834 ret_if(data == NULL);
835 /* Swap to opposite endian */
836 for (i = 0, j = data_len - 1; i < half; i++, j--) {
843 int _bt_byte_arr_cmp(const char *data1, const char *data2, int data_len)
847 retv_if(data1 == NULL, -1);
848 retv_if(data2 == NULL, -1);
849 for (i = 0; i < data_len; i++) {
850 if (data1[i] != data2[i])
851 return data1[i] - data2[i];
855 int _bt_byte_arr_cmp_with_mask(const char *data1, const char *data2,
856 const char *mask, int data_len)
861 retv_if(data1 == NULL, -1);
862 retv_if(data2 == NULL, -1);
863 retv_if(mask == NULL, -1);
864 for (i = 0; i < data_len; i++) {
865 a = data1[i] & mask[i];
866 b = data2[i] & mask[i];
873 int _bt_eventsystem_set_value(const char *event, const char *key, const char *value)
876 /* Send event system event in bt-core process because bt-service's permission is not system in now */
882 bundle_add_str(b, key, value);
884 ret = eventsystem_send_system_event(event, b);
886 BT_DBG("eventsystem_send_system_event result: %d", ret);
893 void __bt_get_auth_info(GVariant *reply, char *auth_info)
897 char *manufacturer_data = NULL;
898 int manufacturer_data_len;
899 gboolean is_alias_set;
900 GVariantIter *value_iter;
904 tmp_value = g_variant_lookup_value(reply, "IsAliasSet",
905 G_VARIANT_TYPE_BOOLEAN);
907 is_alias_set = g_variant_get_boolean(tmp_value);
908 g_variant_unref(tmp_value);
910 is_alias_set = FALSE;
912 if (is_alias_set == FALSE) {
913 tmp_value = g_variant_lookup_value(reply, "ManufacturerDataLen",
914 G_VARIANT_TYPE_UINT16);
916 manufacturer_data_len = g_variant_get_uint16(tmp_value);
917 if (manufacturer_data_len >
918 BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) {
919 BT_ERR("manufacturer_data_len is too long");
920 manufacturer_data_len = BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX;
922 g_variant_unref(tmp_value);
924 manufacturer_data_len = 0;
926 tmp_value = g_variant_lookup_value(reply, "ManufacturerData",
927 G_VARIANT_TYPE_ARRAY);
929 if ((manufacturer_data_len == 0) ||
930 manufacturer_data_len != g_variant_get_size(tmp_value)) {
931 BT_ERR("manufacturer data length doesn't match");
932 manufacturer_data_len = 0;
933 manufacturer_data = NULL;
935 manufacturer_data = g_malloc0(manufacturer_data_len);
936 g_variant_get(tmp_value, "ay", &value_iter);
937 while (g_variant_iter_loop(value_iter, "y", &m_value))
938 manufacturer_data[i++] = m_value;
940 g_variant_unref(tmp_value);
942 BT_INFO("manufacture data is not a G_VARIANT_TYPE_ARRAY ");
943 manufacturer_data_len = 0;
944 manufacturer_data = NULL;
946 /*minimum Size of the samsung specific manufacturer data is greater than 30 */
947 if (manufacturer_data_len < 30) {
948 g_free(manufacturer_data);
951 if (manufacturer_data[0] != 0x00 || manufacturer_data[1] != 0x75) {
952 BT_DBG("This is not a samsung specific manufaturer data");
953 g_free(manufacturer_data);
957 /* 2 samsung (0x00 0x75) + 1 (control and version) + 1 (service ID) +
958 1 (discovery version) + 1 (associated service ID)
959 2 (Proxamity and locality) + 2 (Device type and icon) */
963 memcpy(auth_info, &(manufacturer_data[cursor]), 5);
965 g_free(manufacturer_data);
968 int _bt_convert_gerror(GError *g_error)
970 int ret = BLUETOOTH_ERROR_INTERNAL;
973 if (!g_dbus_error_strip_remote_error(g_error))
976 str = g_error->message;
978 if (g_strcmp0(str, "Connection refused") == 0)
979 ret = BLUETOOTH_ERROR_AUTHENTICATION_REJECTED;
980 else if (g_strcmp0(str, "Connection timed out") == 0)
981 ret = BLUETOOTH_ERROR_TIMEOUT;
982 else if (g_strcmp0(str, "In Progress") == 0)
983 ret = BLUETOOTH_ERROR_IN_PROGRESS;