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>
31 #include <net_connection.h>
33 #include <eventsystem.h>
35 #include "bluetooth-api.h"
36 #include "bt-service-common.h"
37 #include "bt-service-agent.h"
39 static GDBusConnection *system_conn;
40 static GDBusConnection *session_conn;
41 static GDBusProxy *manager_proxy;
42 static GDBusProxy *adapter_proxy;
43 static void *net_conn;
45 static GDBusProxy *adapter_properties_proxy;
47 GDBusConnection *_bt_gdbus_init_system_gconn(void)
51 if (system_conn != NULL)
54 system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
57 BT_ERR("Unable to connect to dbus: %s", error->message);
58 g_clear_error(&error);
64 GDBusConnection *_bt_gdbus_get_system_gconn(void)
66 GDBusConnection *local_system_gconn = NULL;
69 if (system_conn == NULL) {
70 system_conn = _bt_gdbus_init_system_gconn();
71 } else if (g_dbus_connection_is_closed(system_conn)) {
72 local_system_gconn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
74 if (!local_system_gconn) {
75 BT_ERR("Unable to connect to dbus: %s", error->message);
76 g_clear_error(&error);
79 system_conn = local_system_gconn;
85 GDBusConnection *_bt_gdbus_init_session_gconn(void)
89 if (session_conn != NULL)
92 session_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
95 BT_ERR("Unable to connect to dbus: %s", error->message);
96 g_clear_error(&error);
102 GDBusConnection *_bt_gdbus_get_session_gconn(void)
104 GDBusConnection *local_session_gconn = NULL;
105 GError *error = NULL;
107 if (session_conn == NULL) {
108 session_conn = _bt_gdbus_init_session_gconn();
109 } else if (g_dbus_connection_is_closed(session_conn)) {
110 local_session_gconn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
112 if (!local_session_gconn) {
113 BT_ERR("Unable to connect to dbus: %s", error->message);
114 g_clear_error(&error);
117 session_conn = local_session_gconn;
123 static GDBusProxy *__bt_init_manager_proxy(void)
125 GDBusConnection *g_conn;
128 g_conn = _bt_gdbus_get_system_gconn();
129 retv_if(g_conn == NULL, NULL);
131 proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
133 BT_MANAGER_PATH, BT_MANAGER_INTERFACE, NULL, NULL);
136 BT_ERR("Unable to get proxy");
140 manager_proxy = proxy;
145 static GDBusProxy *__bt_init_adapter_proxy(void)
147 GDBusConnection *g_conn;
148 GDBusProxy *manager_proxy;
150 char *adapter_path = NULL;
152 g_conn = _bt_gdbus_get_system_gconn();
153 retv_if(g_conn == NULL, NULL);
155 manager_proxy = _bt_get_manager_proxy();
156 retv_if(manager_proxy == NULL, NULL);
158 adapter_path = _bt_get_adapter_path();
159 retv_if(adapter_path == NULL, NULL);
161 proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
163 adapter_path, BT_ADAPTER_INTERFACE, NULL, NULL);
165 g_free(adapter_path);
167 retv_if(proxy == NULL, NULL);
169 adapter_proxy = proxy;
174 static GDBusProxy *__bt_init_adapter_properties_proxy(void)
176 GDBusConnection *g_conn;
177 GDBusProxy *manager_proxy;
179 char *adapter_path = NULL;
181 g_conn = _bt_gdbus_get_system_gconn();
182 retv_if(g_conn == NULL, NULL);
184 manager_proxy = _bt_get_manager_proxy();
185 retv_if(manager_proxy == NULL, NULL);
187 adapter_path = _bt_get_adapter_path();
188 retv_if(adapter_path == NULL, NULL);
190 proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
192 adapter_path, BT_PROPERTIES_INTERFACE, NULL, NULL);
194 g_free(adapter_path);
196 retv_if(proxy == NULL, NULL);
198 adapter_properties_proxy = proxy;
203 GDBusProxy *_bt_get_manager_proxy(void)
206 const gchar *path = g_dbus_proxy_get_object_path(manager_proxy);
208 BT_ERR("Already proxy released hence creating new proxy");
209 return __bt_init_manager_proxy();
211 return manager_proxy;
213 return __bt_init_manager_proxy();
216 static void *__bt_init_net_conn(void)
219 connection_h connection = NULL;
221 if (net_conn == NULL) {
222 result = connection_create(&connection);
224 if (result != CONNECTION_ERROR_NONE ||
225 connection == NULL) {
226 BT_DBG("connection_create() failed: %d", result);
230 net_conn = connection;
235 void *_bt_get_net_conn(void)
237 return (net_conn) ? net_conn : __bt_init_net_conn();
240 GDBusProxy *_bt_get_adapter_proxy(void)
243 const char *path = g_dbus_proxy_get_object_path(adapter_proxy);
245 BT_ERR("Already proxy released hence creating new proxy");
246 return __bt_init_adapter_proxy();
249 return adapter_proxy;
251 return __bt_init_adapter_proxy();
255 GDBusProxy *_bt_get_adapter_properties_proxy(void)
257 return (adapter_properties_proxy) ? adapter_properties_proxy :
258 __bt_init_adapter_properties_proxy();
261 static char *__bt_extract_adapter_path(GVariantIter *iter)
263 char *object_path = NULL;
264 GVariantIter *interface_iter;
265 GVariantIter *svc_iter;
266 char *interface_str = NULL;
268 /* Parse the signature: oa{sa{sv}}} */
269 while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path,
272 if (object_path == NULL)
275 while (g_variant_iter_loop(interface_iter, "{&sa{sv}}",
276 &interface_str, &svc_iter)) {
277 if (g_strcmp0(interface_str, "org.bluez.Adapter1") != 0)
280 BT_DBG("Object Path: %s", object_path);
281 g_variant_iter_free(svc_iter);
282 g_variant_iter_free(interface_iter);
283 return g_strdup(object_path);
289 char *_bt_get_adapter_path(void)
291 GDBusConnection *conn;
292 GDBusProxy *manager_proxy;
293 GVariant *result = NULL;
294 GVariantIter *iter = NULL;
295 char *adapter_path = NULL;
297 conn = _bt_gdbus_get_system_gconn();
298 retv_if(conn == NULL, NULL);
300 manager_proxy = _bt_get_manager_proxy();
301 retv_if(manager_proxy == NULL, NULL);
303 result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
305 G_DBUS_CALL_FLAGS_NONE,
310 BT_ERR("Can't get managed objects");
314 /* signature of GetManagedObjects: a{oa{sa{sv}}} */
315 g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
317 adapter_path = __bt_extract_adapter_path(iter);
318 g_variant_iter_free(iter);
319 g_variant_unref(result);
323 void _bt_deinit_bluez_proxy(void)
326 g_object_unref(manager_proxy);
327 manager_proxy = NULL;
331 g_object_unref(adapter_proxy);
332 adapter_proxy = NULL;
334 if (adapter_properties_proxy) {
335 g_object_unref(adapter_properties_proxy);
336 adapter_properties_proxy = NULL;
340 void _bt_deinit_proxys(void)
343 _bt_deinit_bluez_proxy();
346 g_object_unref(system_conn);
351 g_object_unref(session_conn);
356 ret = connection_destroy(net_conn);
359 BT_ERR("connection_destroy failed : %d", ret);
363 void _bt_convert_device_path_to_address(const char *device_path,
364 char *device_address)
366 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
369 ret_if(device_path == NULL);
370 ret_if(device_address == NULL);
372 dev_addr = strstr(device_path, "dev_");
373 if (dev_addr != NULL) {
376 g_strlcpy(address, dev_addr, sizeof(address));
378 while ((pos = strchr(address, '_')) != NULL)
381 g_strlcpy(device_address, address, BT_ADDRESS_STRING_SIZE);
386 void _bt_convert_addr_string_to_type(unsigned char *addr,
392 ret_if(address == NULL);
393 ret_if(addr == NULL);
395 for (i = 0; i < BT_ADDRESS_LENGTH_MAX; i++) {
396 addr[i] = strtol(address, &ptr, 16);
397 if (ptr[0] != '\0') {
406 void _bt_convert_addr_string_to_secure_string(char *addr,
411 ret_if(address == NULL);
412 ret_if(addr == NULL);
414 len = strlen(address);
415 ret_if(len != BT_ADDRESS_STRING_SIZE - 1);
417 strncpy(addr, address, len);
425 void _bt_convert_addr_type_to_string(char *address,
428 ret_if(address == NULL);
429 ret_if(addr == NULL);
431 snprintf(address, BT_ADDRESS_STRING_SIZE,
432 "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
433 addr[0], addr[1], addr[2],
434 addr[3], addr[4], addr[5]);
437 void _bt_print_device_address_t(const bluetooth_device_address_t *addr)
439 BT_DBG("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n", addr->addr[0], addr->addr[1], addr->addr[2],
440 addr->addr[3], addr->addr[4], addr->addr[5]);
443 void _bt_divide_device_class(bluetooth_device_class_t *device_class,
446 ret_if(device_class == NULL);
448 device_class->major_class = (unsigned short)(cod & 0x00001F00) >> 8;
449 device_class->minor_class = (unsigned short)((cod & 0x000000FC));
450 device_class->service_class = (unsigned long)((cod & 0x00FF0000));
452 if (cod & 0x002000) {
453 device_class->service_class |=
454 BLUETOOTH_DEVICE_SERVICE_CLASS_LIMITED_DISCOVERABLE_MODE;
458 void _bt_free_device_info(bt_remote_dev_info_t *dev_info)
462 ret_if(dev_info == NULL);
464 g_free(dev_info->address);
465 g_free(dev_info->name);
466 g_free(dev_info->manufacturer_data);
468 if (dev_info->uuids) {
469 for (i = 0; i < dev_info->uuid_count && dev_info->uuids[i]; i++)
470 g_free(dev_info->uuids[i]);
472 g_free(dev_info->uuids);
478 void _bt_free_le_device_info(bt_remote_le_dev_info_t *le_dev_info)
480 ret_if(le_dev_info == NULL);
482 g_free(le_dev_info->adv_data);
486 int _bt_copy_utf8_string(char *dest, const char *src, unsigned int length)
493 if (dest == NULL || src == NULL)
494 return BLUETOOTH_ERROR_INVALID_PARAM;
496 BT_DBG("+src : %s", src);
497 BT_DBG("+dest : %s", dest);
500 while (*p != '\0' && i < length) {
501 next = g_utf8_next_char(p);
504 while (count > 0 && ((i + count) < length)) {
511 return BLUETOOTH_ERROR_NONE;
514 gboolean _bt_utf8_validate(char *name)
518 glong items_written = 0;
520 if (FALSE == g_utf8_validate(name, -1, NULL))
523 u16 = g_utf8_to_utf16(name, -1, NULL, &items_written, NULL);
529 if (items_written != g_utf8_strlen(name, -1))
536 int _bt_register_osp_server_in_agent(int type, char *uuid, char *path, int fd)
539 if (!_bt_agent_register_osp_server(type, uuid, path, fd))
540 return BLUETOOTH_ERROR_INTERNAL;
542 return BLUETOOTH_ERROR_NONE;
545 int _bt_unregister_osp_server_in_agent(int type, char *uuid)
548 if (!_bt_agent_unregister_osp_server(type, uuid))
549 return BLUETOOTH_ERROR_INTERNAL;
551 return BLUETOOTH_ERROR_NONE;
554 int _bt_set_socket_non_blocking(int socket_fd)
556 /* Set Nonblocking */
559 arg = fcntl(socket_fd, F_GETFL);
564 if (arg & O_NONBLOCK)
565 BT_ERR("Already Non-blocking \n");
569 if (fcntl(socket_fd, F_SETFL, arg) < 0)
572 return BLUETOOTH_ERROR_NONE;
575 int _bt_set_non_blocking_tty(int sk)
577 struct termios ti = {0,};
580 err = _bt_set_socket_non_blocking(sk);
583 BT_ERR("Error in set non blocking!\n");
587 tcflush(sk, TCIOFLUSH);
589 /* Switch tty to RAW mode */
591 tcsetattr(sk, TCSANOW, &ti);
593 return BLUETOOTH_ERROR_NONE;
596 static char *__bt_extract_device_path(GVariantIter *iter, char *address)
598 char *object_path = NULL;
599 char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
601 /* Parse the signature: oa{sa{sv}}} */
602 while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path,
605 BT_ERR("Unable to get object path");
608 _bt_convert_device_path_to_address(object_path, device_address);
609 if (g_strcmp0(address, device_address) == 0)
610 return g_strdup(object_path);
614 BT_ERR("Unable to get object path");
618 char *_bt_get_device_object_path(char *address)
620 char *object_path = NULL;
621 GDBusConnection *conn;
622 GDBusProxy *manager_proxy;
623 GVariant *result = NULL;
624 GVariantIter *iter = NULL;
626 conn = _bt_gdbus_get_system_gconn();
627 retv_if(conn == NULL, NULL);
629 manager_proxy = _bt_get_manager_proxy();
630 retv_if(manager_proxy == NULL, NULL);
632 result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
634 G_DBUS_CALL_FLAGS_NONE,
639 BT_ERR("Can't get managed objects");
643 /* signature of GetManagedObjects: a{oa{sa{sv}}} */
644 g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
645 object_path = __bt_extract_device_path(iter, address);
646 g_variant_iter_free(iter);
647 g_variant_unref(result);
651 char *_bt_get_profile_uuid128(bt_profile_type_t profile_type)
653 switch (profile_type) {
654 case BT_PROFILE_CONN_RFCOMM:
655 return strdup(RFCOMM_UUID_STR);
656 case BT_PROFILE_CONN_A2DP:
657 return strdup(A2DP_SINK_UUID);
658 case BT_PROFILE_CONN_A2DP_SINK:
659 return strdup(A2DP_SOURCE_UUID);
660 case BT_PROFILE_CONN_HSP:
661 return strdup(HFP_HS_UUID);
662 case BT_PROFILE_CONN_HID:
663 return strdup(HID_UUID);
664 case BT_PROFILE_CONN_NAP:
665 return strdup(NAP_UUID);
666 case BT_PROFILE_CONN_HFG:
667 return strdup(HFP_AG_UUID);
668 case BT_PROFILE_CONN_PBAP:
669 return strdup(PBAP_UUID);
670 case BT_PROFILE_CONN_GATT:
671 case BT_PROFILE_CONN_ALL: /* NULL UUID will connect to both the audio profiles*/
677 char *_bt_convert_error_to_string(int error)
680 case BLUETOOTH_ERROR_CANCEL:
682 case BLUETOOTH_ERROR_INVALID_PARAM:
683 return "INVALID_PARAMETER";
684 case BLUETOOTH_ERROR_INVALID_DATA:
685 return "INVALID DATA";
686 case BLUETOOTH_ERROR_MEMORY_ALLOCATION:
687 case BLUETOOTH_ERROR_OUT_OF_MEMORY:
688 return "OUT_OF_MEMORY";
689 case BLUETOOTH_ERROR_TIMEOUT:
691 case BLUETOOTH_ERROR_NO_RESOURCES:
692 return "NO_RESOURCES";
693 case BLUETOOTH_ERROR_INTERNAL:
695 case BLUETOOTH_ERROR_NOT_SUPPORT:
696 return "NOT_SUPPORT";
697 case BLUETOOTH_ERROR_DEVICE_NOT_ENABLED:
698 return "NOT_ENABLED";
699 case BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED:
700 return "ALREADY_ENABLED";
701 case BLUETOOTH_ERROR_DEVICE_BUSY:
702 return "DEVICE_BUSY";
703 case BLUETOOTH_ERROR_ACCESS_DENIED:
704 return "ACCESS_DENIED";
705 case BLUETOOTH_ERROR_MAX_CLIENT:
707 case BLUETOOTH_ERROR_NOT_FOUND:
709 case BLUETOOTH_ERROR_SERVICE_SEARCH_ERROR:
710 return "SERVICE_SEARCH_ERROR";
711 case BLUETOOTH_ERROR_PARING_FAILED:
712 return "PARING_FAILED";
713 case BLUETOOTH_ERROR_NOT_PAIRED:
715 case BLUETOOTH_ERROR_SERVICE_NOT_FOUND:
716 return "SERVICE_NOT_FOUND";
717 case BLUETOOTH_ERROR_NOT_CONNECTED:
718 return "NOT_CONNECTED";
719 case BLUETOOTH_ERROR_ALREADY_CONNECT:
720 return "ALREADY_CONNECT";
721 case BLUETOOTH_ERROR_CONNECTION_BUSY:
722 return "CONNECTION_BUSY";
723 case BLUETOOTH_ERROR_CONNECTION_ERROR:
724 return "CONNECTION_ERROR";
725 case BLUETOOTH_ERROR_MAX_CONNECTION:
726 return "MAX_CONNECTION";
727 case BLUETOOTH_ERROR_NOT_IN_OPERATION:
728 return "NOT_IN_OPERATION";
729 case BLUETOOTH_ERROR_CANCEL_BY_USER:
730 return "CANCEL_BY_USER";
731 case BLUETOOTH_ERROR_REGISTRATION_FAILED:
732 return "REGISTRATION_FAILED";
733 case BLUETOOTH_ERROR_IN_PROGRESS:
734 return "IN_PROGRESS";
735 case BLUETOOTH_ERROR_AUTHENTICATION_FAILED:
736 return "AUTHENTICATION_FAILED";
737 case BLUETOOTH_ERROR_HOST_DOWN:
739 case BLUETOOTH_ERROR_END_OF_DEVICE_LIST:
740 return "END_OF_DEVICE_LIST";
741 case BLUETOOTH_ERROR_AGENT_ALREADY_EXIST:
742 return "AGENT_ALREADY_EXIST";
743 case BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST:
744 return "AGENT_DOES_NOT_EXIST";
745 case BLUETOOTH_ERROR_ALREADY_INITIALIZED:
746 return "ALREADY_INITIALIZED";
747 case BLUETOOTH_ERROR_PERMISSION_DEINED:
748 return "PERMISSION_DEINED";
749 case BLUETOOTH_ERROR_ALREADY_DEACTIVATED:
750 return "ALREADY_DEACTIVATED";
751 case BLUETOOTH_ERROR_NOT_INITIALIZED:
752 return "NOT_INITIALIZED";
753 case BLUETOOTH_ERROR_AUTHENTICATION_REJECTED:
754 return "AUTHENTICATION REJECTED";
760 char * _bt_convert_disc_reason_to_string(int reason)
763 case (int)BLUETOOTH_ERROR_PAGE_TIMEOUT:
764 return "Page timeout";
765 case (int)BLUETOOTH_ERROR_CONNECTION_TIMEOUT:
767 case (int)BLUETOOTH_ERROR_PIN_OR_KEY_MISSING:
768 return "PIN or Key missing";
769 case (int)BLUETOOTH_ERROR_LOCAL_HOST_TERM:
770 return "Connection terminated by local host";
771 case (int)BLUETOOTH_ERROR_REMOTE_USER_TERM:
772 case (int)BLUETOOTH_ERROR_REMOTE_LOW_RESOURCES:
773 case (int)BLUETOOTH_ERROR_REMOTE_POWER_OFF:
774 return "Remote user terminated connection";
775 case (int)BLUETOOTH_ERROR_AUTH_FAILURE:
776 return "Authentication Failure";
777 case (int)BLUETOOTH_ERROR_REPEATED_ATTEMPTS:
778 return "Repeated attempts";
779 case (int)BLUETOOTH_ERROR_LMP_RESPONSE_TIMEOUT:
780 return "LMP response timeout";
781 case (int)BLUETOOTH_ERROR_CONNECTION_FAILED_TO_BE_ESTABLISHED:
782 return "Connection failed to be established";
788 void _bt_logging_connection(gboolean connect, int addr_type)
790 static int le_conn = 0;
791 static int le_disc = 0;
792 static int edr_conn = 0;
793 static int edr_disc = 0;
807 BT_INFO("[PM] Number of LE conn: %d disc: %d, Number of BR/EDR conn: %d disc: %d",
808 le_conn, le_disc, edr_conn, edr_disc);
811 void _bt_swap_byte_ordering(char *data, int data_len)
815 int half = data_len / 2;
817 ret_if(data == NULL);
818 /* Swap to opposite endian */
819 for (i = 0, j = data_len - 1; i < half; i++, j--) {
826 int _bt_byte_arr_cmp(const char *data1, const char *data2, int data_len)
830 retv_if(data1 == NULL, -1);
831 retv_if(data2 == NULL, -1);
832 for (i = 0; i < data_len; i++) {
833 if (data1[i] != data2[i])
834 return data1[i] - data2[i];
838 int _bt_byte_arr_cmp_with_mask(const char *data1, const char *data2,
839 const char *mask, int data_len)
844 retv_if(data1 == NULL, -1);
845 retv_if(data2 == NULL, -1);
846 retv_if(mask == NULL, -1);
847 for (i = 0; i < data_len; i++) {
848 a = data1[i] & mask[i];
849 b = data2[i] & mask[i];
856 int _bt_eventsystem_set_value(const char *event, const char *key, const char *value)
859 /* Send event system event in bt-core process because bt-service's permission is not system in now */
866 bundle_add_str(b, key, value);
868 ret = eventsystem_send_system_event(event, b);
870 BT_DBG("eventsystem_send_system_event result: %d", ret);
877 void __bt_get_auth_info(GVariant *reply, char *auth_info)
881 char *manufacturer_data = NULL;
882 int manufacturer_data_len;
883 gboolean is_alias_set;
884 GVariantIter *value_iter;
888 tmp_value = g_variant_lookup_value(reply, "IsAliasSet",
889 G_VARIANT_TYPE_BOOLEAN);
891 is_alias_set = g_variant_get_boolean(tmp_value);
892 g_variant_unref(tmp_value);
894 is_alias_set = FALSE;
896 if (is_alias_set == FALSE) {
897 tmp_value = g_variant_lookup_value(reply, "ManufacturerDataLen",
898 G_VARIANT_TYPE_UINT16);
900 manufacturer_data_len = g_variant_get_uint16(tmp_value);
901 if (manufacturer_data_len >
902 BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) {
903 BT_ERR("manufacturer_data_len is too long");
904 manufacturer_data_len = BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX;
906 g_variant_unref(tmp_value);
908 manufacturer_data_len = 0;
910 tmp_value = g_variant_lookup_value(reply, "ManufacturerData",
911 G_VARIANT_TYPE_ARRAY);
913 if ((manufacturer_data_len == 0) ||
914 manufacturer_data_len != g_variant_get_size(tmp_value)) {
915 BT_ERR("manufacturer data length doesn't match");
916 manufacturer_data_len = 0;
917 manufacturer_data = NULL;
919 manufacturer_data = g_malloc0(manufacturer_data_len);
920 g_variant_get(tmp_value, "ay", &value_iter);
921 while (g_variant_iter_loop(value_iter, "y", &m_value))
922 manufacturer_data[i++] = m_value;
924 g_variant_unref(tmp_value);
926 BT_INFO("manufacture data is not a G_VARIANT_TYPE_ARRAY ");
927 manufacturer_data_len = 0;
928 manufacturer_data = NULL;
930 /*minimum Size of the samsung specific manufacturer data is greater than 30 */
931 if (manufacturer_data_len < 30) {
932 g_free(manufacturer_data);
935 if (manufacturer_data[0] != 0x00 || manufacturer_data[1] != 0x75) {
936 BT_DBG("This is not a samsung specific manufaturer data");
937 g_free(manufacturer_data);
941 /* 2 samsung (0x00 0x75) + 1 (control and version) + 1 (service ID) +
942 1 (discovery version) + 1 (associated service ID)
943 2 (Proxamity and locality) + 2 (Device type and icon) */
947 memcpy(auth_info, &(manufacturer_data[cursor]), 5);
949 g_free(manufacturer_data);
952 int _bt_convert_gerror(GError *g_error)
954 int ret = BLUETOOTH_ERROR_INTERNAL;
957 if (!g_dbus_error_strip_remote_error(g_error))
960 str = g_error->message;
962 if (g_strcmp0(str, "Connection refused") == 0)
963 ret = BLUETOOTH_ERROR_AUTHENTICATION_REJECTED;
964 else if (g_strcmp0(str, "Connection timed out") == 0)
965 ret = BLUETOOTH_ERROR_TIMEOUT;
966 else if (g_strcmp0(str, "In Progress") == 0)
967 ret = BLUETOOTH_ERROR_IN_PROGRESS;