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.
26 #include <net_connection.h>
27 #include <dbus/dbus.h>
33 #include <net_connection.h>
35 #include <eventsystem.h>
36 #include <arpa/inet.h>
39 #include "bluetooth-api.h"
40 #include "bt-service-common.h"
42 #include <oal-manager.h>
43 #include <oal-device-mgr.h>
45 #ifdef TIZEN_FEATURE_BT_IPSP
46 static GDBusProxy *ipsp_proxy;
48 static GDBusConnection *system_conn;
49 static GDBusConnection *session_conn;
50 static GDBusProxy *manager_proxy_g;
51 static GDBusProxy *adapter_proxy_g;
52 static void *net_conn;
54 static GDBusProxy *adapter_properties_proxy;
56 static GDBusConnection *system_gconn = NULL;
58 GDBusConnection *_bt_gdbus_init_system_gconn(void)
62 dbus_threads_init_default();
64 if (system_gconn != NULL)
67 system_gconn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
70 BT_ERR("Unable to connect to dbus: %s", error->message);
71 g_clear_error(&error);
77 GDBusConnection *_bt_gdbus_get_system_gconn(void)
79 GDBusConnection *local_system_gconn = NULL;
82 if (system_gconn == NULL) {
83 system_gconn = _bt_gdbus_init_system_gconn();
84 } else if (g_dbus_connection_is_closed(system_gconn)) {
86 local_system_gconn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
88 if (!local_system_gconn) {
89 BT_ERR("Unable to connect to dbus: %s", error->message);
90 g_clear_error(&error);
93 system_gconn = local_system_gconn;
99 static GDBusProxy *__bt_init_manager_proxy(void)
103 if (system_conn == NULL) {
104 system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
105 retv_if(system_conn == NULL, NULL);
108 proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE,
110 BT_MANAGER_PATH, BT_MANAGER_INTERFACE, NULL, NULL);
112 retv_if(proxy == NULL, NULL);
114 manager_proxy_g = proxy;
119 static GDBusProxy *__bt_init_adapter_proxy(void)
121 GDBusProxy *manager_proxy;
123 char *adapter_path = NULL;
125 if (system_conn == NULL) {
126 system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
127 retv_if(system_conn == NULL, NULL);
130 manager_proxy = _bt_get_manager_proxy();
131 retv_if(manager_proxy == NULL, NULL);
133 adapter_path = _bt_get_adapter_path();
134 retv_if(adapter_path == NULL, NULL);
136 proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE,
138 adapter_path, BT_ADAPTER_INTERFACE, NULL, NULL);
140 g_free(adapter_path);
142 retv_if(proxy == NULL, NULL);
144 adapter_proxy_g = proxy;
148 #ifdef TIZEN_FEATURE_BT_IPSP
149 static GDBusProxy *__bt_init_ipsp_proxy(void)
153 GDBusConnection *g_conn;
155 g_conn = _bt_gdbus_get_system_gconn();
156 retv_if(g_conn == NULL, NULL);
157 proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
159 "/org/projectx/bt_ipsp", BT_IPSP_INTERFACE, NULL, NULL);
161 BT_ERR("Unable to get proxy");
169 static GDBusProxy *__bt_init_adapter_properties_proxy(void)
171 GDBusProxy *manager_proxy;
173 char *adapter_path = NULL;
175 if (system_conn == NULL) {
176 system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
177 retv_if(system_conn == NULL, NULL);
180 manager_proxy = _bt_get_manager_proxy();
181 retv_if(manager_proxy == NULL, NULL);
183 adapter_path = _bt_get_adapter_path();
184 retv_if(adapter_path == NULL, NULL);
186 proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE,
188 adapter_path, BT_PROPERTIES_INTERFACE, NULL, NULL);
190 g_free(adapter_path);
192 retv_if(proxy == NULL, NULL);
194 adapter_properties_proxy = proxy;
199 GDBusConnection *__bt_init_system_gconn(void)
201 if (system_conn == NULL)
202 system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
207 GDBusConnection *__bt_init_session_conn(void)
209 if (session_conn == NULL)
210 session_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
215 GDBusConnection *_bt_get_session_gconn(void)
217 return (session_conn) ? session_conn : __bt_init_session_conn();
220 GDBusConnection *_bt_get_system_gconn(void)
222 return (system_conn) ? system_conn : __bt_init_system_gconn();
225 GDBusConnection *_bt_get_system_conn(void)
227 GDBusConnection *g_conn;
229 if (system_conn == NULL)
230 g_conn = __bt_init_system_gconn();
232 g_conn = system_conn;
234 retv_if(g_conn == NULL, NULL);
239 GDBusProxy *_bt_get_manager_proxy(void)
241 if (manager_proxy_g) {
242 const gchar *path = g_dbus_proxy_get_object_path(manager_proxy_g);
244 BT_ERR("Already proxy released hence creating new proxy");
245 return __bt_init_manager_proxy();
247 return manager_proxy_g;
249 return __bt_init_manager_proxy();
251 #ifdef TIZEN_FEATURE_BT_IPSP
252 GDBusProxy *_bt_get_ipsp_proxy(void)
255 const char *path = g_dbus_proxy_get_object_path(ipsp_proxy);
257 BT_ERR("Already proxy released hence creating new proxy");
258 return __bt_init_ipsp_proxy();
262 return __bt_init_ipsp_proxy();
266 static void *__bt_init_net_conn(void)
269 connection_h connection = NULL;
271 if (net_conn == NULL) {
272 result = connection_create(&connection);
274 if (result != CONNECTION_ERROR_NONE ||
275 connection == NULL) {
276 BT_DBG("connection_create() failed: %d", result);
280 net_conn = connection;
285 void *_bt_get_net_conn(void)
287 return (net_conn) ? net_conn : __bt_init_net_conn();
290 GDBusProxy *_bt_get_adapter_proxy(void)
292 if (adapter_proxy_g) {
293 const char *path = g_dbus_proxy_get_object_path(adapter_proxy_g);
295 BT_ERR("Already proxy released hence creating new proxy");
296 return __bt_init_adapter_proxy();
299 return adapter_proxy_g;
301 return __bt_init_adapter_proxy();
305 GDBusProxy *_bt_get_adapter_properties_proxy(void)
307 return (adapter_properties_proxy) ? adapter_properties_proxy :
308 __bt_init_adapter_properties_proxy();
311 static char *__bt_extract_adapter_path(GVariantIter *iter)
313 char *object_path = NULL;
314 GVariantIter *interface_iter;
315 GVariantIter *svc_iter;
316 char *interface_str = NULL;
318 /* Parse the signature: oa{sa{sv}}} */
319 while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path,
322 if (object_path == NULL)
325 while (g_variant_iter_loop(interface_iter, "{&sa{sv}}",
326 &interface_str, &svc_iter)) {
327 if (g_strcmp0(interface_str, "org.bluez.Adapter1") != 0)
330 BT_DBG("Object Path: %s", object_path);
331 g_variant_iter_free(svc_iter);
332 g_variant_iter_free(interface_iter);
333 return g_strdup(object_path);
339 char *_bt_get_adapter_path(void)
341 GDBusConnection *conn;
342 GDBusProxy *manager_proxy;
343 GVariant *result = NULL;
344 GVariantIter *iter = NULL;
345 char *adapter_path = NULL;
347 conn = _bt_get_system_conn();
348 retv_if(conn == NULL, NULL);
350 manager_proxy = _bt_get_manager_proxy();
351 retv_if(manager_proxy == NULL, NULL);
353 result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
355 G_DBUS_CALL_FLAGS_NONE,
360 BT_ERR("Can't get managed objects");
364 /* signature of GetManagedObjects: a{oa{sa{sv}}} */
365 g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
367 adapter_path = __bt_extract_adapter_path(iter);
368 g_variant_iter_free(iter);
369 g_variant_unref(result);
373 void _bt_deinit_bluez_proxy(void)
375 if (manager_proxy_g) {
376 g_object_unref(manager_proxy_g);
377 manager_proxy_g = NULL;
380 if (adapter_proxy_g) {
381 g_object_unref(adapter_proxy_g);
382 adapter_proxy_g = NULL;
384 if (adapter_properties_proxy) {
385 g_object_unref(adapter_properties_proxy);
386 adapter_properties_proxy = NULL;
390 void _bt_deinit_proxys(void)
393 _bt_deinit_bluez_proxy();
396 g_object_unref(system_conn);
401 g_object_unref(session_conn);
406 ret = connection_destroy(net_conn);
409 BT_ERR("connection_destroy failed : %d", ret);
413 void _bt_convert_device_path_to_address(const char *device_path,
414 char *device_address)
416 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
419 ret_if(device_path == NULL);
420 ret_if(device_address == NULL);
422 dev_addr = strstr(device_path, "dev_");
423 if (dev_addr != NULL) {
426 g_strlcpy(address, dev_addr, sizeof(address));
428 while ((pos = strchr(address, '_')) != NULL)
431 g_strlcpy(device_address, address, BT_ADDRESS_STRING_SIZE);
436 void _bt_convert_addr_string_to_type(unsigned char *addr,
442 ret_if(address == NULL);
443 ret_if(addr == NULL);
445 for (i = 0; i < BT_ADDRESS_LENGTH_MAX; i++) {
446 addr[i] = strtol(address, &ptr, 16);
447 if (ptr[0] != '\0') {
456 void _bt_convert_addr_type_to_string(char *address,
459 ret_if(address == NULL);
460 ret_if(addr == NULL);
462 snprintf(address, BT_ADDRESS_STRING_SIZE,
463 "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
464 addr[0], addr[1], addr[2],
465 addr[3], addr[4], addr[5]);
468 gboolean _bt_compare_adddress(const bluetooth_device_address_t *addr1,
469 const bluetooth_device_address_t *addr2)
471 if (memcmp(&addr1->addr, &addr2->addr, 6) == 0)
477 void _bt_print_device_address_t(const bluetooth_device_address_t *addr)
479 BT_INFO("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
480 addr->addr[0], addr->addr[1], addr->addr[2],
481 addr->addr[3], addr->addr[4], addr->addr[5]);
484 void _bt_divide_device_class(bluetooth_device_class_t *device_class,
487 ret_if(device_class == NULL);
489 device_class->major_class = (unsigned short)(cod & 0x00001F00) >> 8;
490 device_class->minor_class = (unsigned short)((cod & 0x000000FC));
491 device_class->service_class = (unsigned long)((cod & 0x00FF0000));
493 if (cod & 0x002000) {
494 device_class->service_class |=
495 BLUETOOTH_DEVICE_SERVICE_CLASS_LIMITED_DISCOVERABLE_MODE;
499 void _bt_free_le_device_info(bt_remote_le_dev_info_t *le_dev_info)
501 ret_if(le_dev_info == NULL);
503 g_free(le_dev_info->adv_data);
507 int _bt_copy_utf8_string(char *dest, const char *src, unsigned int length)
514 if (dest == NULL || src == NULL)
515 return BLUETOOTH_ERROR_INVALID_PARAM;
517 BT_DBG("+src : %s", src);
518 BT_DBG("+dest : %s", dest);
521 while (*p != '\0' && i < length) {
522 next = g_utf8_next_char(p);
525 while (count > 0 && ((i + count) < length)) {
532 return BLUETOOTH_ERROR_NONE;
535 gboolean _bt_utf8_validate(char *name)
538 glong items_written = 0;
540 if (FALSE == g_utf8_validate(name, -1, NULL))
543 u16 = g_utf8_to_utf16(name, -1, NULL, &items_written, NULL);
549 if (items_written != g_utf8_strlen(name, -1))
555 int _bt_register_osp_server_in_agent(int type, char *uuid, char *path, int fd)
559 #if TODO_40 /* Need to add this function */
560 if (!_bt_agent_register_osp_server(type, uuid, path, fd))
561 return BLUETOOTH_ERROR_INTERNAL;
563 if (device_register_osp_server(type, uuid, path, fd) != 0)
564 return BLUETOOTH_ERROR_INTERNAL;
566 return BLUETOOTH_ERROR_NONE;
569 int _bt_unregister_osp_server_in_agent(int type, char *uuid)
573 #if TODO_40 /* Need to add this function */
574 if (!_bt_agent_unregister_osp_server(type, uuid))
575 return BLUETOOTH_ERROR_INTERNAL;
577 if (device_unregister_osp_server(type, uuid) != 0)
578 return BLUETOOTH_ERROR_INTERNAL;
580 return BLUETOOTH_ERROR_NONE;
583 int _bt_set_socket_non_blocking(int socket_fd)
585 /* Set Nonblocking */
588 arg = fcntl(socket_fd, F_GETFL);
593 if (arg & O_NONBLOCK)
594 BT_ERR("Already Non-blocking \n");
598 if (fcntl(socket_fd, F_SETFL, arg) < 0)
601 return BLUETOOTH_ERROR_NONE;
604 int _bt_set_non_blocking_tty(int sk)
606 struct termios ti = {0,};
609 err = _bt_set_socket_non_blocking(sk);
612 BT_ERR("Error in set non blocking!\n");
616 tcflush(sk, TCIOFLUSH);
618 /* Switch tty to RAW mode */
620 tcsetattr(sk, TCSANOW, &ti);
622 return BLUETOOTH_ERROR_NONE;
625 static char *__bt_extract_device_path(GVariantIter *iter, char *address)
627 char *object_path = NULL;
628 char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
630 /* Parse the signature: oa{sa{sv}}} */
631 while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path,
633 retv_if(object_path == NULL, NULL);
634 _bt_convert_device_path_to_address(object_path, device_address);
635 if (g_strcmp0(address, device_address) == 0)
636 return g_strdup(object_path);
641 char *_bt_get_device_object_path(char *address)
643 char *object_path = NULL;
644 GDBusConnection *conn;
645 GDBusProxy *manager_proxy;
646 GVariant *result = NULL;
647 GVariantIter *iter = NULL;
649 conn = _bt_get_system_conn();
650 retv_if(conn == NULL, NULL);
652 manager_proxy = _bt_get_manager_proxy();
653 retv_if(manager_proxy == NULL, NULL);
655 result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
657 G_DBUS_CALL_FLAGS_NONE,
662 BT_ERR("Can't get managed objects");
666 /* signature of GetManagedObjects: a{oa{sa{sv}}} */
667 g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
668 object_path = __bt_extract_device_path(iter, address);
669 g_variant_iter_free(iter);
670 g_variant_unref(result);
674 char *_bt_get_profile_uuid128(bt_profile_type_t profile_type)
676 switch (profile_type) {
677 case BT_PROFILE_CONN_RFCOMM:
678 return strdup(RFCOMM_UUID_STR);
679 case BT_PROFILE_CONN_A2DP:
680 return strdup(A2DP_SINK_UUID);
681 case BT_PROFILE_CONN_A2DP_SINK:
682 return strdup(A2DP_SOURCE_UUID);
683 case BT_PROFILE_CONN_HSP:
684 return strdup(HFP_HS_UUID);
685 case BT_PROFILE_CONN_HID:
686 return strdup(HID_UUID);
687 case BT_PROFILE_CONN_NAP:
688 return strdup(NAP_UUID);
689 case BT_PROFILE_CONN_HFG:
690 return strdup(HFP_AG_UUID);
691 case BT_PROFILE_CONN_GATT:
692 case BT_PROFILE_CONN_ALL: /* NULL UUID will connect to both the audio profiles*/
698 const char *_bt_convert_uuid_to_string(const char *uuid)
700 #define SHORT_UUID_COUNT 199
701 #define LONG_UUID_COUNT 17
710 const char *specification_name;
712 static uuid_name_s short_uuid_name[SHORT_UUID_COUNT] = {
713 // List should be sorted by UUID
714 /* BT Classic Services */
715 {"1101", "Serial Port Service"},
716 {"1102", "LAN Access Using PPP Service"},
717 {"1103", "Dialup Networking Service"},
718 {"1104", "IrMCSync Service"},
719 {"1105", "OBEX Object Push Service"},
720 {"1106", "OBEX File Transfer Service"},
721 {"1107", "IrMC Sync Command Service"},
722 {"1108", "Headset Service"},
723 {"1109", "Cordless Telephony Service"},
724 {"110A", "Audio Source Service"},
725 {"110B", "Audio Sink Service"},
726 {"110C", "AV Remote Control Target Service"},
727 {"110D", "Advanced Audio Distribution Profile"},
728 {"110E", "AV Remote Control Service"},
729 {"110F", "Video Conferencing Service"},
730 {"1110", "Intercom Service"},
731 {"1111", "Fax Service"},
732 {"1112", "Headset Audio Gateway Service"},
733 {"1113", "WAP Service"},
734 {"1114", "WAP Client Service"},
735 {"1115", "PANU Service"},
736 {"1116", "NAP Service"},
737 {"1117", "GN Service"},
738 {"1118", "Direct Printing Service"},
739 {"1119", "Reference Printing Service"},
740 {"111A", "Basic Imaging Profile"},
741 {"111B", "Imaging Responder Service"},
742 {"111C", "Imaging Automatic Archive Service"},
743 {"111D", "Imaging Reference Objects Service"},
744 {"111E", "Handsfree Service"},
745 {"111F", "Handsfree Audio Gateway Service"},
746 {"1120", "Direct Printing Reference Objects Service"},
747 {"1121", "Reflected UI Service"},
748 {"1122", "Basic Printing Profile"},
749 {"1123", "Printing Status Service"},
750 {"1124", "Human Interface Device Service"},
751 {"1125", "Hardcopy Cable Replacement Profile"},
752 {"1126", "HCR Print Service"},
753 {"1127", "HCR Scan Service"},
754 {"112D", "SIM Access Service"},
755 {"112E", "Phonebook Access PCE Service"},
756 {"112F", "Phonebook Access PSE Service"},
757 {"1130", "Phonebook Access Profile"},
758 {"1132", "Message Access Server Service"},
759 {"1133", "Message Notification Server Service"},
760 {"1134", "Message Access Profile"},
761 {"1200", "PnP Information Service"},
762 {"1201", "Generic Networking Service"},
763 {"1202", "Generic File Transfer Service"},
764 {"1203", "Generic Audio Service"},
765 {"1204", "Generic Telephony Service"},
766 {"1205", "UPnP Service"},
767 {"1206", "UPnP Ip Service"},
768 {"1303", "Video Source Service"},
769 {"1304", "Video Sink Service"},
770 {"1305", "Video Distribution Profile"},
771 {"1400", "Health Device Profile"},
772 {"1401", "HDP Source Service"},
773 {"1402", "HDP Sink Service"},
776 {"1800", "Generic Access"},
777 {"1801", "Generic Attribute"},
778 {"1802", "Immediate Alert"},
779 {"1803", "Link Loss"},
780 {"1804", "Tx Power"},
781 {"1805", "Current Time Service"},
782 {"1806", "Reference Time Update Service"},
783 {"1807", "Next DST Change Service"},
785 {"1809", "Health Thermometer"},
786 {"180A", "Device Information"},
787 {"180D", "Heart Rate"},
788 {"180F", "Battery Service"},
789 {"1810", "Blood Pressure"},
790 {"1811", "Alert Notification Service"},
791 {"1812", "Human Interface Device"},
792 {"1813", "Scan Parameters"},
793 {"1814", "Running Speed and Cadence"},
794 {"1815", "Automation IO"},
795 {"1816", "Cycling Speed and Cadence"},
796 {"1818", "Cycling Power"},
797 {"1819", "Location and Navigation"},
798 {"181A", "Environmental Sensing"},
799 {"181B", "Body Composition"},
800 {"181C", "User Data"},
801 {"181D", "Weight Scale"},
802 {"181E", "Bond Management"},
803 {"181F", "Continuous Glucose Monitoring"},
804 {"1820", "Internet Protocol Support Service"},
805 {"1821", "Indoor Positioning"},
806 {"1822", "Pulse Oximeter Service"},
807 {"1823", "HTTP Proxy"},
808 {"1824", "Transport Discovery"},
809 {"1825", "Object Transfer Service"},
810 {"1826", "Fitness Machine"},
811 {"1827", "Mesh Provisioning Service"},
812 {"1828", "Mesh Proxy Service"},
813 {"1829", "Reconnection Configuration"},
814 {"183A", "Insulin Delivery"},
816 /* GATT Declarations */
817 {"2800", "Primary Service Declaration"},
818 {"2801", "Secondary Service Declaration"},
819 {"2802", "Include Declaration"},
820 {"2803", "Characteristic Declaration"},
822 /* GATT Descriptors */
823 {"2900", "Characteristic Extended Properties"},
824 {"2901", "Characteristic User Description"},
825 {"2902", "Client Characteristic Configuration"},
826 {"2903", "Server Characteristic Configuration"},
827 {"2904", "Characteristic Format"},
828 {"2905", "Characteristic Aggregate Formate"},
829 {"2906", "Valid Range"},
830 {"2907", "External Report Reference"},
831 {"2908", "Report Reference"},
833 /* GATT Characteristics */
834 {"2A00", "Device Name"},
835 {"2A01", "Appearance"},
836 {"2A02", "Peripheral Privacy Flag"},
837 {"2A03", "Reconnection Address"},
838 {"2A04", "Peripheral Preferred Connection Parameters"},
839 {"2A05", "Service Changed"},
840 {"2A06", "Alert Level"},
841 {"2A07", "Tx Power Level"},
842 {"2A08", "Date Time"},
843 {"2A09", "Day of Week"},
844 {"2A0A", "Day Date Time"},
845 {"2A11", "Time with DST"},
846 {"2A12", "Time Accuracy"},
847 {"2A13", "Time Source"},
848 {"2A14", "Reference Time Information"},
849 {"2A16", "Time Update Control Point"},
850 {"2A17", "Time Update State"},
851 {"2A18", "Glucose Measurement"},
852 {"2A19", "Battery Level"},
853 {"2A1C", "Temperature Measurement"},
854 {"2A1D", "Temperature Type"},
855 {"2A1E", "Intermediate Temperature"},
856 {"2A21", "Measurement Interval"},
857 {"2A23", "System ID"},
858 {"2A24", "Model Number String"},
859 {"2A25", "Serial Number String"},
860 {"2A26", "Firmware Revision String"},
861 {"2A27", "Hardware Revision String"},
862 {"2A28", "Software Revision String"},
863 {"2A29", "Manufacturer Name String"},
864 {"2A2A", "IEEE 11073-20601 Regulatory Certification Data List"},
865 {"2A2B", "Current Time"},
866 {"2A34", "Glucose Measurement Context"},
867 {"2A35", "Blood Pressure Measurement"},
868 {"2A37", "Heart Rate Measurement"},
869 {"2A38", "Body Sensor Location"},
870 {"2A39", "Heart Rate Control Point"},
871 {"2A3F", "Alert Status"},
872 {"2A46", "New Alert"},
873 {"2A49", "Blood Pressure Feature"},
874 {"2A4A", "HID Information"},
875 {"2A4C", "HID Control Point"},
877 {"2A51", "Glucose Feature"},
878 {"2A52", "Record Access Control Point"},
879 {"2A53", "RSC Measurement"},
880 {"2A54", "RSC Feature"},
881 {"2A55", "SC Control Point"},
884 {"2A5A", "Aggregate"},
885 {"2A5B", "CSC Measurement"},
886 {"2A5C", "CSC Feature"},
887 {"2A5D", "Sensor Location"},
888 {"2A63", "Cycling Power Measurement"},
889 {"2A64", "Cycling Power Vector"},
890 {"2A65", "Cycling Power Feature"},
891 {"2A66", "Cycling Power Control Point"},
892 {"2A67", "Location and Speed"},
893 {"2A68", "Navigation"},
894 {"2A6D", "Pressure"},
895 {"2A6E", "Temperature"},
897 {"2A90", "Last Name"},
898 {"2A91", "Maximum Recommended Heart Rate"},
899 {"2A92", "Resting Heart Rate"},
901 {"2A9B", "Body Composition Feature"},
902 {"2A9C", "Body Composition Measurement"},
903 {"2A9D", "Weight Measurement"},
904 {"2AA2", "Language"},
905 {"2AA4", "Bond Management Control Point"},
906 {"2AA5", "Bond Management Features"},
907 {"2AA6", "Central Address Resolution"},
908 {"2AAD", "Indoor Positioning Configuration"},
909 {"2AB5", "Location Name"},
911 {"2ABC", "TDS Control Point"},
912 {"2AC9", "Resolvable Private Address Only"},
913 {"2ACC", "Fitness Machine Feature"},
914 {"2ACE", "Cross Trainer Data"},
915 {"2AD3", "Training Status"},
916 {"2AD7", "Supported Heart Rate Range"},
917 {"2AD9", "Fitness Machine Control Point"},
918 {"2ADA", "Fitness Machine Status"},
919 {"2B1D", "RC Feature"},
920 {"2B1E", "RC Settings"},
921 {"2B1F", "Reconnection Configuration Control Point"},
923 static uuid_name_s long_uuid_name[LONG_UUID_COUNT] = {
924 // List should be sorted by UUID
926 {"1AB7C24D-185A-45B9-90D4-F7AB1A71949A", "Samsung Health Service"},
927 {"22EAC6E9-24D6-4BB5-BE44-B36ACE7C7BFB", "Data Source"},
928 {"2F7CABCE-808D-411F-9A0C-BB92BA96C102", "Entity Update"},
929 {"32D1955A-E5AA-4A96-9A49-08538DA8B8F6", "Samsung Gear Fit Manager Service"},
930 {"69D1D8F3-45E1-49A8-9821-9BBDFDAAD9D9", "Control Point"},
931 {"7905F431-B5CE-4E99-A40F-4B1E122D00D0", "Apple Notification Center Service"},
932 {"89D3502B-0F36-433A-8EF4-C502AD55F8DC", "Apple Media Service"},
933 {"9A3F68E0-86CE-11E5-A309-0002A5D5C51B", "Samsung Gear Manager Service"},
934 {"9B3C81D8-57B1-4A8A-B8DF-0E56F7CA51C2", "Remote Command"},
935 {"9FBF120D-6301-42D9-8C58-25E699A21DBD", "Notifications Source"},
936 {"A49EB41E-CB06-495C-9F4F-BB80A90CDF00", "Samsung Gear Manager Service"},
937 {"ADE3D529-C784-4F63-A987-EB69F70EE816", "IoT OIC Service"},
938 {"C2051EE0-804D-4D50-A12C-15E243852100", "Notifications Source"},
939 {"C2F2CC0F-C085-4DD4-BE5A-ACA3074BBC72", "Control Point"},
940 {"C6B2F38C-23AB-46D8-A6AB-A3A870BBD5D7", "Entity Attribute"},
941 {"CECE518B-28D7-4171-92D5-76A1E249A3B9", "Notifications Source"},
942 {"FE53FF98-B259-4337-B56A-0EC9F82C6BAD", "Control Point"},
944 const uuid_name_s *uuid_name = short_uuid_name;
945 static const char *unknown_name = "Unknown";
947 int end = SHORT_UUID_COUNT - 1;
951 if (strlen(uuid) == 36) {
952 if (!g_ascii_strncasecmp(uuid + 9, "0000-1000-8000-00805F9B34FB", 27))
957 end = LONG_UUID_COUNT - 1;
958 uuid_name = long_uuid_name;
960 } else if (strlen(uuid) >= 8)
963 while (start <= end) {
964 p = start + (end - start) / 2;
965 ret = g_ascii_strncasecmp(uuid + offset, uuid_name[p].uuid, uuid_len);
967 return uuid_name[p].specification_name;
977 const char *_bt_convert_error_to_string(int error)
980 case BLUETOOTH_ERROR_CANCEL:
982 case BLUETOOTH_ERROR_INVALID_PARAM:
983 return "INVALID_PARAMETER";
984 case BLUETOOTH_ERROR_INVALID_DATA:
985 return "INVALID DATA";
986 case BLUETOOTH_ERROR_MEMORY_ALLOCATION:
987 case BLUETOOTH_ERROR_OUT_OF_MEMORY:
988 return "OUT_OF_MEMORY";
989 case BLUETOOTH_ERROR_TIMEOUT:
991 case BLUETOOTH_ERROR_NO_RESOURCES:
992 return "NO_RESOURCES";
993 case BLUETOOTH_ERROR_INTERNAL:
995 case BLUETOOTH_ERROR_NOT_SUPPORT:
996 return "NOT_SUPPORT";
997 case BLUETOOTH_ERROR_DEVICE_NOT_ENABLED:
998 return "NOT_ENABLED";
999 case BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED:
1000 return "ALREADY_ENABLED";
1001 case BLUETOOTH_ERROR_DEVICE_BUSY:
1002 return "DEVICE_BUSY";
1003 case BLUETOOTH_ERROR_ACCESS_DENIED:
1004 return "ACCESS_DENIED";
1005 case BLUETOOTH_ERROR_MAX_CLIENT:
1006 return "MAX_CLIENT";
1007 case BLUETOOTH_ERROR_NOT_FOUND:
1009 case BLUETOOTH_ERROR_SERVICE_SEARCH_ERROR:
1010 return "SERVICE_SEARCH_ERROR";
1011 case BLUETOOTH_ERROR_PARING_FAILED:
1012 return "PARING_FAILED";
1013 case BLUETOOTH_ERROR_NOT_PAIRED:
1014 return "NOT_PAIRED";
1015 case BLUETOOTH_ERROR_SERVICE_NOT_FOUND:
1016 return "SERVICE_NOT_FOUND";
1017 case BLUETOOTH_ERROR_NOT_CONNECTED:
1018 return "NOT_CONNECTED";
1019 case BLUETOOTH_ERROR_ALREADY_CONNECT:
1020 return "ALREADY_CONNECT";
1021 case BLUETOOTH_ERROR_CONNECTION_BUSY:
1022 return "CONNECTION_BUSY";
1023 case BLUETOOTH_ERROR_CONNECTION_ERROR:
1024 return "CONNECTION_ERROR";
1025 case BLUETOOTH_ERROR_MAX_CONNECTION:
1026 return "MAX_CONNECTION";
1027 case BLUETOOTH_ERROR_NOT_IN_OPERATION:
1028 return "NOT_IN_OPERATION";
1029 case BLUETOOTH_ERROR_CANCEL_BY_USER:
1030 return "CANCEL_BY_USER";
1031 case BLUETOOTH_ERROR_REGISTRATION_FAILED:
1032 return "REGISTRATION_FAILED";
1033 case BLUETOOTH_ERROR_IN_PROGRESS:
1034 return "IN_PROGRESS";
1035 case BLUETOOTH_ERROR_AUTHENTICATION_FAILED:
1036 return "AUTHENTICATION_FAILED";
1037 case BLUETOOTH_ERROR_HOST_DOWN:
1039 case BLUETOOTH_ERROR_END_OF_DEVICE_LIST:
1040 return "END_OF_DEVICE_LIST";
1041 case BLUETOOTH_ERROR_AGENT_ALREADY_EXIST:
1042 return "AGENT_ALREADY_EXIST";
1043 case BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST:
1044 return "AGENT_DOES_NOT_EXIST";
1045 case BLUETOOTH_ERROR_ALREADY_INITIALIZED:
1046 return "ALREADY_INITIALIZED";
1047 case BLUETOOTH_ERROR_PERMISSION_DEINED:
1048 return "PERMISSION_DEINED";
1049 case BLUETOOTH_ERROR_ALREADY_DEACTIVATED:
1050 return "ALREADY_DEACTIVATED";
1051 case BLUETOOTH_ERROR_NOT_INITIALIZED:
1052 return "NOT_INITIALIZED";
1058 const char * _bt_convert_disc_reason_to_string(int reason)
1064 return "Connection terminated by local host";
1066 return "Remote user terminated connection";
1074 void _bt_logging_connection(gboolean connect, int addr_type)
1076 static int le_conn = 0;
1077 static int le_disc = 0;
1078 static int edr_conn = 0;
1079 static int edr_disc = 0;
1093 BT_INFO("[PM] Number of LE conn: %d disc: %d, Number of BR/EDR conn: %d disc: %d",
1094 le_conn, le_disc, edr_conn, edr_disc);
1097 int _bt_eventsystem_set_value(const char *event, const char *key, const char *value)
1102 b = bundle_create();
1104 bundle_add_str(b, key, value);
1106 ret = eventsystem_send_system_event(event, b);
1108 BT_DBG("eventsystem_send_system_event result: %d", ret);
1115 void _bt_swap_byte_ordering(char *data, int data_len)
1120 ret_if(data == NULL);
1121 /* Swap to opposite endian */
1122 for (i = 0, j = data_len - 1; i < data_len; i++, j--) {
1129 int _bt_byte_arr_cmp(const char *data1, const char *data2, int data_len)
1133 retv_if(data1 == NULL, -1);
1134 retv_if(data2 == NULL, -1);
1135 for (i = 0; i < data_len; i++) {
1136 if (data1[i] != data2[i])
1137 return data1[i] - data2[i];
1141 int _bt_byte_arr_cmp_with_mask(const char *data1, const char *data2,
1142 const char *mask, int data_len)
1147 retv_if(data1 == NULL, -1);
1148 retv_if(data2 == NULL, -1);
1149 retv_if(mask == NULL, -1);
1150 for (i = 0; i < data_len; i++) {
1151 a = data1[i] & mask[i];
1152 b = data2[i] & mask[i];
1154 return (int)(a - b);
1159 void _bt_copy_remote_dev(bt_remote_dev_info_t *dev_info, remote_device_t *oal_device)
1163 dev_info->address = g_new0(char, BT_ADDRESS_STRING_SIZE);
1164 _bt_convert_addr_type_to_string(dev_info->address, oal_device->address.addr);
1165 BT_INFO("Address [%s]", dev_info->address);
1167 if (strlen(oal_device->name) == 0)
1168 dev_info->name = NULL;
1170 dev_info->name = g_strdup(oal_device->name);
1171 _bt_truncate_non_utf8_chars(dev_info->name);
1172 BT_INFO("Name [%s]", dev_info->name);
1175 if (strlen(oal_device->alias) == 0) {
1176 dev_info->alias = NULL;
1178 dev_info->alias = g_strdup(oal_device->alias);
1179 _bt_truncate_non_utf8_chars(dev_info->alias);
1180 BT_INFO("Alias [%s]", dev_info->alias);
1183 dev_info->class = oal_device->cod;
1184 dev_info->paired = oal_device->is_bonded;
1185 BT_INFO("Is Bonded [%d]", dev_info->paired);
1186 dev_info->connected = oal_device->is_connected;
1187 BT_INFO("iS Connected [%d]", dev_info->connected);
1188 dev_info->rssi = oal_device->rssi;
1189 dev_info->addr_type = oal_device->type;
1190 dev_info->uuid_count = oal_device->uuid_count;
1191 BT_INFO("UUID Count [%d]", dev_info->uuid_count);
1192 dev_info->trust = ((oal_device->is_trusted == 0) ? FALSE : TRUE);
1194 if (dev_info->uuid_count > 0)
1195 dev_info->uuids = g_new0(char *, dev_info->uuid_count);
1197 /* Fill Remote Device Service List list */
1198 for (i = 0; i < dev_info->uuid_count; i++) {
1199 dev_info->uuids[i] = g_malloc0(BLUETOOTH_UUID_STRING_MAX);
1200 _bt_uuid_to_string((service_uuid_t *)&oal_device->uuid[i].uuid, dev_info->uuids[i]);
1203 dev_info->vid = (unsigned short)oal_device->vid;
1204 dev_info->pid = (unsigned short)oal_device->pid;
1205 dev_info->device_type = (int)oal_device->type;
1206 dev_info->is_alias_set = ((oal_device->is_alias_set == 0) ? FALSE : TRUE);
1210 void _bt_free_remote_dev(bt_remote_dev_info_t *dev_info)
1214 ret_if(NULL == dev_info);
1216 g_free(dev_info->address);
1217 g_free(dev_info->name);
1218 g_free(dev_info->alias);
1219 g_free(dev_info->manufacturer_data);
1221 for (c = 0; c < dev_info->uuid_count; c++)
1222 g_free(dev_info->uuids[c]);
1223 g_free(dev_info->uuids);
1228 static void __bt_get_service_list(bt_remote_dev_info_t *info, bluetooth_device_info_t *dev)
1234 ret_if(info == NULL);
1235 ret_if(dev == NULL);
1237 uuids = info->uuids;
1238 if (uuids == NULL) {
1239 BT_ERR("No UUID's");
1243 dev->service_index = 0;
1244 BT_DBG("Total UUID count [%d]", info->uuid_count);
1245 for (i = 0; i < info->uuid_count; i++) {
1246 g_strlcpy(dev->uuids[i], uuids[i], BLUETOOTH_UUID_STRING_MAX);
1248 parts = g_strsplit(uuids[i], "-", -1);
1250 if (parts == NULL || parts[0] == NULL)
1253 dev->service_list_array[i] = g_ascii_strtoull(parts[0], NULL, 16);
1256 dev->service_index++;
1261 void _bt_copy_remote_device(bt_remote_dev_info_t *rem_dev, bluetooth_device_info_t *dev)
1263 memset(dev, 0x00, sizeof(bluetooth_device_info_t));
1264 __bt_get_service_list(rem_dev, dev);
1265 _bt_convert_addr_string_to_type(dev->device_address.addr, rem_dev->address);
1266 _bt_divide_device_class(&dev->device_class, rem_dev->class);
1268 if (rem_dev->alias) {
1269 g_strlcpy(dev->device_name.name, rem_dev->alias,
1270 BLUETOOTH_DEVICE_NAME_LENGTH_MAX + 1);
1271 BT_DBG("Name: %s", dev->device_name.name);
1273 g_strlcpy(dev->device_name.name, rem_dev->name,
1274 BLUETOOTH_DEVICE_NAME_LENGTH_MAX + 1);
1275 BT_DBG("Name: %s", dev->device_name.name);
1278 dev->rssi = rem_dev->rssi;
1279 dev->trust = rem_dev->trust;
1280 dev->paired = rem_dev->paired;
1281 dev->connected = rem_dev->connected;
1282 dev->is_alias_set = rem_dev->is_alias_set;
1284 /* Fill Manufacturer data */
1285 if (rem_dev->manufacturer_data_len > 0) {
1286 dev->manufacturer_data.data_len = rem_dev->manufacturer_data_len;
1287 memcpy(dev->manufacturer_data.data,
1288 rem_dev->manufacturer_data, rem_dev->manufacturer_data_len);
1290 dev->manufacturer_data.data_len = 0;
1295 void _bt_service_print_dev_info(bluetooth_device_info_t *dev_info)
1299 ret_if(dev_info == NULL);
1301 _bt_print_device_address_t(&(dev_info->device_address));
1302 BT_INFO("Device Name:[%s]", dev_info->device_name.name);
1303 BT_INFO("Device Major Class:[0x%X]", dev_info->device_class.major_class);
1304 BT_INFO("Device Minor Class:[0x%X]", dev_info->device_class.minor_class);
1305 BT_INFO("Device Service Class:[0x%X]", dev_info->device_class.minor_class);
1306 BT_INFO("Device Paired:[%s]", (dev_info->paired ? "TRUE" : "FALSE"));
1307 BT_INFO("Device Trusted:[%s]", (dev_info->trust ? "TRUE" : "FALSE"));
1308 BT_INFO("Device Connected:[%d]", dev_info->connected);
1309 BT_INFO("Device Service index:[%d]", dev_info->service_index);
1310 for (i = 0; i < dev_info->service_index; i++) {
1311 BT_INFO("Device Service List:[%d]", dev_info->service_list_array[i]);
1312 BT_INFO("Device UUID:[%s]", dev_info->uuids[i]);
1315 BT_INFO("Device manufacturer data len:[%d]", dev_info->manufacturer_data.data_len);
1316 for (i = 0; i < dev_info->manufacturer_data.data_len; i++)
1317 BT_INFO("%2.2X", dev_info->manufacturer_data.data[i]);
1320 void _bt_uuid_to_string(service_uuid_t *p_uuid, char *str)
1322 uint32_t uuid0, uuid4;
1323 uint16_t uuid1, uuid2, uuid3, uuid5;
1325 memcpy(&uuid0, &(p_uuid->uuid[0]), 4);
1326 memcpy(&uuid1, &(p_uuid->uuid[4]), 2);
1327 memcpy(&uuid2, &(p_uuid->uuid[6]), 2);
1328 memcpy(&uuid3, &(p_uuid->uuid[8]), 2);
1329 memcpy(&uuid4, &(p_uuid->uuid[10]), 4);
1330 memcpy(&uuid5, &(p_uuid->uuid[14]), 2);
1332 snprintf((char *)str, BLUETOOTH_UUID_STRING_MAX, "%.8x-%.4x-%.4x-%.4x-%.8x%.4x",
1333 ntohl(uuid0), ntohs(uuid1),
1334 ntohs(uuid2), ntohs(uuid3),
1335 ntohl(uuid4), ntohs(uuid5));
1339 void _bt_string_to_uuid(char *str, service_uuid_t *p_uuid)
1341 uint32_t uuid0, uuid4;
1342 uint16_t uuid1, uuid2, uuid3, uuid5;
1344 sscanf(str, "%08x-%04hx-%04hx-%04hx-%08x%04hx",
1345 &uuid0, &uuid1, &uuid2, &uuid3, &uuid4, &uuid5);
1347 uuid0 = htonl(uuid0);
1348 uuid1 = htons(uuid1);
1349 uuid2 = htons(uuid2);
1350 uuid3 = htons(uuid3);
1351 uuid4 = htonl(uuid4);
1352 uuid5 = htons(uuid5);
1354 memcpy(&(p_uuid->uuid[0]), &uuid0, 4);
1355 memcpy(&(p_uuid->uuid[4]), &uuid1, 2);
1356 memcpy(&(p_uuid->uuid[6]), &uuid2, 2);
1357 memcpy(&(p_uuid->uuid[8]), &uuid3, 2);
1358 memcpy(&(p_uuid->uuid[10]), &uuid4, 4);
1359 memcpy(&(p_uuid->uuid[14]), &uuid5, 2);
1364 void _bt_convert_byte_ordering(char *data, int data_len,
1365 char *converted_data)
1368 char temp[BT_UUID_LEN];
1370 memcpy(&temp, data, data_len);
1371 for (i = 0, j = data_len - 1; i < data_len; i++, j--)
1372 converted_data[i] = temp[j];
1376 /* Trim string at first non-utf8 char */
1377 void _bt_truncate_non_utf8_chars(char * str)
1380 const char *ptr = NULL;
1382 if (strlen(str) != 0) {
1383 if (!g_utf8_validate(str, -1, &ptr)) {
1384 while (*(str + i) != *ptr)
1391 invocation_info_t* _bt_get_request_info_data(int service_function, char *address)
1394 invocation_info_t *req_info = NULL;
1396 retv_if(NULL == address, NULL);
1398 /* Get method invocation context */
1399 for (l = _bt_get_invocation_list(); l != NULL; l = g_slist_next(l)) {
1401 if (req_info == NULL || req_info->service_function != service_function)
1404 if (!strncasecmp((char *)req_info->user_data, address, BT_ADDRESS_STRING_SIZE))
1411 #ifdef TIZEN_GATT_CLIENT
1412 invocation_info_t* _bt_get_request_info_data_from_function_name(int service_function)
1415 invocation_info_t *req_info = NULL;
1417 /* Get method invocation context */
1418 for (l = _bt_get_invocation_list(); l != NULL; l = g_slist_next(l)) {
1420 if (req_info == NULL || req_info->service_function != service_function)
1425 BT_DBG("Not existed");
1430 void _bt_set_device_values(gboolean connected, int state)
1432 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
1434 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
1435 BT_ERR("vconf_get_int failed");
1437 if (connected == TRUE)
1438 bt_device_state |= state;
1439 else if (bt_device_state & state)
1440 bt_device_state ^= state;
1442 if (vconf_set_int(VCONFKEY_BT_DEVICE, bt_device_state) != 0)
1443 BT_ERR("vconf_set_int failed");
1446 #ifdef TIZEN_FEATURE_READOUT_NOTIFICATION
1447 void _bt_set_readout_notification_of_tts(void)
1451 if (vconf_get_int(VCONFKEY_TTS_SETTING_NOTIFICATION_TTS, &tts_setting) != 0) {
1452 BT_ERR("vconf_get_int failed");
1456 BT_DBG("current value[%d]", tts_setting);
1458 if (tts_setting == -1)
1459 if (vconf_set_int(VCONFKEY_TTS_SETTING_NOTIFICATION_TTS, -1) != 0)
1460 BT_ERR("vconf_set_int failed");
1464 int _bt_get_ad_data_by_type(char *in_data, int in_len,
1465 char in_type, char **data, int *data_len)
1467 if (in_data == NULL || data == NULL || data_len == NULL)
1468 return BLUETOOTH_ERROR_INVALID_PARAM;
1471 return BLUETOOTH_ERROR_INVALID_PARAM;
1477 for (i = 0; i < in_len; i++) {
1479 if (len <= 0 || i + 1 >= in_len) {
1480 BT_ERR("Invalid advertising data");
1481 return BLUETOOTH_ERROR_INVALID_PARAM;
1484 type = in_data[i + 1];
1485 if (type == in_type) {
1495 if (i + len > in_len) {
1496 BT_ERR("Invalid advertising data");
1497 return BLUETOOTH_ERROR_INVALID_PARAM;
1498 } else if (len == 0) {
1499 BT_INFO("AD Type 0x%02x data is not set", in_type);
1502 return BLUETOOTH_ERROR_NONE;
1505 *data = g_memdup(&in_data[i], len);
1507 return BLUETOOTH_ERROR_OUT_OF_MEMORY;
1510 return BLUETOOTH_ERROR_NONE;
1513 void _bt_copy_remote_dev_info(bt_remote_dev_info_t *dest, bt_remote_dev_info_t *src)
1515 ret_if(NULL == src);
1517 if (!dest->address) {
1518 dest->address = g_strdup(src->address);
1523 dest->name = g_strdup(src->name);
1527 g_free(dest->alias);
1528 dest->alias = g_strdup(src->alias);
1531 if (src->uuid_count > 0 && src->uuids) {
1534 /* Release previously allocated UUIDs */
1535 if (dest->uuid_count > 0 && dest->uuids)
1536 for (i = 0; i < dest->uuid_count; i++)
1537 g_free(dest->uuids[i]);
1538 g_free(dest->uuids);
1540 /* Copy new UUID list */
1541 dest->uuids = g_malloc0(src->uuid_count * sizeof(char *));
1542 for (i = 0; i < src->uuid_count; i++)
1543 dest->uuids[i] = g_strdup(src->uuids[i]);
1545 dest->uuid_count = src->uuid_count;
1548 if (src->manufacturer_data_len > 0 && src->manufacturer_data) {
1549 if (dest->manufacturer_data)
1550 g_free(dest->manufacturer_data);
1552 dest->manufacturer_data_len = src->manufacturer_data_len;
1553 dest->manufacturer_data = g_memdup(
1554 src->manufacturer_data, src->manufacturer_data_len);
1557 dest->rssi = src->rssi;
1558 dest->class = src->class;
1559 dest->paired = src->paired;
1560 dest->connected = src->connected;
1561 dest->trust = src->trust;
1562 dest->addr_type = src->addr_type;
1563 dest->vid = src->vid;
1564 dest->pid = src->pid;
1565 dest->device_type = src->device_type;
1566 dest->is_alias_set = src->is_alias_set;
1570 #define BT_PERMANENT_LOG_FILE_PATH "/opt/usr/home/owner/media/Downloads/.bt_dump/permanent_log.txt"
1571 #define BT_PERMANENT_LOG_OLD_FILE_PATH "/opt/usr/home/owner/media/Downloads/.bt_dump/permanent_log_old.txt"
1572 #define PERMANENT_LOG_MAX (128 * 1024)
1573 void _bt_permanent_log(const char *fmt, ...)
1582 #ifndef TIZEN_FEATURE_BT_PERMANENT_LOG
1588 strftime(time_buf, sizeof(time_buf), "%m-%d %H:%M:%S", lt);
1590 fp = fopen(BT_PERMANENT_LOG_FILE_PATH, "r");
1592 fseek(fp, 0, SEEK_END);
1596 if (lsize > PERMANENT_LOG_MAX) {
1599 fp2 = fopen(BT_PERMANENT_LOG_OLD_FILE_PATH, "w");
1602 fseek(fp, 0, SEEK_SET);
1604 character = fgetc(fp);
1605 fputc(character, fp2);
1609 fp = fopen(BT_PERMANENT_LOG_FILE_PATH, "w");
1613 fp = fopen(BT_PERMANENT_LOG_FILE_PATH, "a");
1619 vsnprintf(buf, 100, fmt, ap);
1621 fprintf(fp, "%s %s\n", time_buf, buf);