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)
539 glong items_written = 0;
541 if (FALSE == g_utf8_validate(name, -1, NULL))
544 u16 = g_utf8_to_utf16(name, -1, NULL, &items_written, NULL);
550 if (items_written != g_utf8_strlen(name, -1))
557 int _bt_register_osp_server_in_agent(int type, char *uuid, char *path, int fd)
561 #if TODO_40 /* Need to add this function */
562 if (!_bt_agent_register_osp_server(type, uuid, path, fd))
563 return BLUETOOTH_ERROR_INTERNAL;
565 if (device_register_osp_server(type, uuid, path, fd) != 0)
566 return BLUETOOTH_ERROR_INTERNAL;
568 return BLUETOOTH_ERROR_NONE;
571 int _bt_unregister_osp_server_in_agent(int type, char *uuid)
575 #if TODO_40 /* Need to add this function */
576 if (!_bt_agent_unregister_osp_server(type, uuid))
577 return BLUETOOTH_ERROR_INTERNAL;
579 if (device_unregister_osp_server(type, uuid) != 0)
580 return BLUETOOTH_ERROR_INTERNAL;
582 return BLUETOOTH_ERROR_NONE;
585 int _bt_set_socket_non_blocking(int socket_fd)
587 /* Set Nonblocking */
590 arg = fcntl(socket_fd, F_GETFL);
595 if (arg & O_NONBLOCK)
596 BT_ERR("Already Non-blocking \n");
600 if (fcntl(socket_fd, F_SETFL, arg) < 0)
603 return BLUETOOTH_ERROR_NONE;
606 int _bt_set_non_blocking_tty(int sk)
608 struct termios ti = {0,};
611 err = _bt_set_socket_non_blocking(sk);
614 BT_ERR("Error in set non blocking!\n");
618 tcflush(sk, TCIOFLUSH);
620 /* Switch tty to RAW mode */
622 tcsetattr(sk, TCSANOW, &ti);
624 return BLUETOOTH_ERROR_NONE;
627 static char *__bt_extract_device_path(GVariantIter *iter, char *address)
629 char *object_path = NULL;
630 char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
632 /* Parse the signature: oa{sa{sv}}} */
633 while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path,
635 retv_if(object_path == NULL, NULL);
636 _bt_convert_device_path_to_address(object_path, device_address);
637 if (g_strcmp0(address, device_address) == 0)
638 return g_strdup(object_path);
643 char *_bt_get_device_object_path(char *address)
645 char *object_path = NULL;
646 GDBusConnection *conn;
647 GDBusProxy *manager_proxy;
648 GVariant *result = NULL;
649 GVariantIter *iter = NULL;
651 conn = _bt_get_system_conn();
652 retv_if(conn == NULL, NULL);
654 manager_proxy = _bt_get_manager_proxy();
655 retv_if(manager_proxy == NULL, NULL);
657 result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
659 G_DBUS_CALL_FLAGS_NONE,
664 BT_ERR("Can't get managed objects");
668 /* signature of GetManagedObjects: a{oa{sa{sv}}} */
669 g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
670 object_path = __bt_extract_device_path(iter, address);
671 g_variant_iter_free(iter);
672 g_variant_unref(result);
676 char *_bt_get_profile_uuid128(bt_profile_type_t profile_type)
678 switch (profile_type) {
679 case BT_PROFILE_CONN_RFCOMM:
680 return strdup(RFCOMM_UUID_STR);
681 case BT_PROFILE_CONN_A2DP:
682 return strdup(A2DP_SINK_UUID);
683 case BT_PROFILE_CONN_A2DP_SINK:
684 return strdup(A2DP_SOURCE_UUID);
685 case BT_PROFILE_CONN_HSP:
686 return strdup(HFP_HS_UUID);
687 case BT_PROFILE_CONN_HID:
688 return strdup(HID_UUID);
689 case BT_PROFILE_CONN_NAP:
690 return strdup(NAP_UUID);
691 case BT_PROFILE_CONN_HFG:
692 return strdup(HFP_AG_UUID);
693 case BT_PROFILE_CONN_GATT:
694 case BT_PROFILE_CONN_ALL: /* NULL UUID will connect to both the audio profiles*/
700 const char *_bt_convert_uuid_to_string(const char *uuid)
702 #define SHORT_UUID_COUNT 199
703 #define LONG_UUID_COUNT 17
712 const char *specification_name;
714 static uuid_name_s short_uuid_name[SHORT_UUID_COUNT] = {
715 // List should be sorted by UUID
716 /* BT Classic Services */
717 {"1101", "Serial Port Service"},
718 {"1102", "LAN Access Using PPP Service"},
719 {"1103", "Dialup Networking Service"},
720 {"1104", "IrMCSync Service"},
721 {"1105", "OBEX Object Push Service"},
722 {"1106", "OBEX File Transfer Service"},
723 {"1107", "IrMC Sync Command Service"},
724 {"1108", "Headset Service"},
725 {"1109", "Cordless Telephony Service"},
726 {"110A", "Audio Source Service"},
727 {"110B", "Audio Sink Service"},
728 {"110C", "AV Remote Control Target Service"},
729 {"110D", "Advanced Audio Distribution Profile"},
730 {"110E", "AV Remote Control Service"},
731 {"110F", "Video Conferencing Service"},
732 {"1110", "Intercom Service"},
733 {"1111", "Fax Service"},
734 {"1112", "Headset Audio Gateway Service"},
735 {"1113", "WAP Service"},
736 {"1114", "WAP Client Service"},
737 {"1115", "PANU Service"},
738 {"1116", "NAP Service"},
739 {"1117", "GN Service"},
740 {"1118", "Direct Printing Service"},
741 {"1119", "Reference Printing Service"},
742 {"111A", "Basic Imaging Profile"},
743 {"111B", "Imaging Responder Service"},
744 {"111C", "Imaging Automatic Archive Service"},
745 {"111D", "Imaging Reference Objects Service"},
746 {"111E", "Handsfree Service"},
747 {"111F", "Handsfree Audio Gateway Service"},
748 {"1120", "Direct Printing Reference Objects Service"},
749 {"1121", "Reflected UI Service"},
750 {"1122", "Basic Printing Profile"},
751 {"1123", "Printing Status Service"},
752 {"1124", "Human Interface Device Service"},
753 {"1125", "Hardcopy Cable Replacement Profile"},
754 {"1126", "HCR Print Service"},
755 {"1127", "HCR Scan Service"},
756 {"112D", "SIM Access Service"},
757 {"112E", "Phonebook Access PCE Service"},
758 {"112F", "Phonebook Access PSE Service"},
759 {"1130", "Phonebook Access Profile"},
760 {"1132", "Message Access Server Service"},
761 {"1133", "Message Notification Server Service"},
762 {"1134", "Message Access Profile"},
763 {"1200", "PnP Information Service"},
764 {"1201", "Generic Networking Service"},
765 {"1202", "Generic File Transfer Service"},
766 {"1203", "Generic Audio Service"},
767 {"1204", "Generic Telephony Service"},
768 {"1205", "UPnP Service"},
769 {"1206", "UPnP Ip Service"},
770 {"1303", "Video Source Service"},
771 {"1304", "Video Sink Service"},
772 {"1305", "Video Distribution Profile"},
773 {"1400", "Health Device Profile"},
774 {"1401", "HDP Source Service"},
775 {"1402", "HDP Sink Service"},
778 {"1800", "Generic Access"},
779 {"1801", "Generic Attribute"},
780 {"1802", "Immediate Alert"},
781 {"1803", "Link Loss"},
782 {"1804", "Tx Power"},
783 {"1805", "Current Time Service"},
784 {"1806", "Reference Time Update Service"},
785 {"1807", "Next DST Change Service"},
787 {"1809", "Health Thermometer"},
788 {"180A", "Device Information"},
789 {"180D", "Heart Rate"},
790 {"180F", "Battery Service"},
791 {"1810", "Blood Pressure"},
792 {"1811", "Alert Notification Service"},
793 {"1812", "Human Interface Device"},
794 {"1813", "Scan Parameters"},
795 {"1814", "Running Speed and Cadence"},
796 {"1815", "Automation IO"},
797 {"1816", "Cycling Speed and Cadence"},
798 {"1818", "Cycling Power"},
799 {"1819", "Location and Navigation"},
800 {"181A", "Environmental Sensing"},
801 {"181B", "Body Composition"},
802 {"181C", "User Data"},
803 {"181D", "Weight Scale"},
804 {"181E", "Bond Management"},
805 {"181F", "Continuous Glucose Monitoring"},
806 {"1820", "Internet Protocol Support Service"},
807 {"1821", "Indoor Positioning"},
808 {"1822", "Pulse Oximeter Service"},
809 {"1823", "HTTP Proxy"},
810 {"1824", "Transport Discovery"},
811 {"1825", "Object Transfer Service"},
812 {"1826", "Fitness Machine"},
813 {"1827", "Mesh Provisioning Service"},
814 {"1828", "Mesh Proxy Service"},
815 {"1829", "Reconnection Configuration"},
816 {"183A", "Insulin Delivery"},
818 /* GATT Declarations */
819 {"2800", "Primary Service Declaration"},
820 {"2801", "Secondary Service Declaration"},
821 {"2802", "Include Declaration"},
822 {"2803", "Characteristic Declaration"},
824 /* GATT Descriptors */
825 {"2900", "Characteristic Extended Properties"},
826 {"2901", "Characteristic User Description"},
827 {"2902", "Client Characteristic Configuration"},
828 {"2903", "Server Characteristic Configuration"},
829 {"2904", "Characteristic Format"},
830 {"2905", "Characteristic Aggregate Formate"},
831 {"2906", "Valid Range"},
832 {"2907", "External Report Reference"},
833 {"2908", "Report Reference"},
835 /* GATT Characteristics */
836 {"2A00", "Device Name"},
837 {"2A01", "Appearance"},
838 {"2A02", "Peripheral Privacy Flag"},
839 {"2A03", "Reconnection Address"},
840 {"2A04", "Peripheral Preferred Connection Parameters"},
841 {"2A05", "Service Changed"},
842 {"2A06", "Alert Level"},
843 {"2A07", "Tx Power Level"},
844 {"2A08", "Date Time"},
845 {"2A09", "Day of Week"},
846 {"2A0A", "Day Date Time"},
847 {"2A11", "Time with DST"},
848 {"2A12", "Time Accuracy"},
849 {"2A13", "Time Source"},
850 {"2A14", "Reference Time Information"},
851 {"2A16", "Time Update Control Point"},
852 {"2A17", "Time Update State"},
853 {"2A18", "Glucose Measurement"},
854 {"2A19", "Battery Level"},
855 {"2A1C", "Temperature Measurement"},
856 {"2A1D", "Temperature Type"},
857 {"2A1E", "Intermediate Temperature"},
858 {"2A21", "Measurement Interval"},
859 {"2A23", "System ID"},
860 {"2A24", "Model Number String"},
861 {"2A25", "Serial Number String"},
862 {"2A26", "Firmware Revision String"},
863 {"2A27", "Hardware Revision String"},
864 {"2A28", "Software Revision String"},
865 {"2A29", "Manufacturer Name String"},
866 {"2A2A", "IEEE 11073-20601 Regulatory Certification Data List"},
867 {"2A2B", "Current Time"},
868 {"2A34", "Glucose Measurement Context"},
869 {"2A35", "Blood Pressure Measurement"},
870 {"2A37", "Heart Rate Measurement"},
871 {"2A38", "Body Sensor Location"},
872 {"2A39", "Heart Rate Control Point"},
873 {"2A3F", "Alert Status"},
874 {"2A46", "New Alert"},
875 {"2A49", "Blood Pressure Feature"},
876 {"2A4A", "HID Information"},
877 {"2A4C", "HID Control Point"},
879 {"2A51", "Glucose Feature"},
880 {"2A52", "Record Access Control Point"},
881 {"2A53", "RSC Measurement"},
882 {"2A54", "RSC Feature"},
883 {"2A55", "SC Control Point"},
886 {"2A5A", "Aggregate"},
887 {"2A5B", "CSC Measurement"},
888 {"2A5C", "CSC Feature"},
889 {"2A5D", "Sensor Location"},
890 {"2A63", "Cycling Power Measurement"},
891 {"2A64", "Cycling Power Vector"},
892 {"2A65", "Cycling Power Feature"},
893 {"2A66", "Cycling Power Control Point"},
894 {"2A67", "Location and Speed"},
895 {"2A68", "Navigation"},
896 {"2A6D", "Pressure"},
897 {"2A6E", "Temperature"},
899 {"2A90", "Last Name"},
900 {"2A91", "Maximum Recommended Heart Rate"},
901 {"2A92", "Resting Heart Rate"},
903 {"2A9B", "Body Composition Feature"},
904 {"2A9C", "Body Composition Measurement"},
905 {"2A9D", "Weight Measurement"},
906 {"2AA2", "Language"},
907 {"2AA4", "Bond Management Control Point"},
908 {"2AA5", "Bond Management Features"},
909 {"2AA6", "Central Address Resolution"},
910 {"2AAD", "Indoor Positioning Configuration"},
911 {"2AB5", "Location Name"},
913 {"2ABC", "TDS Control Point"},
914 {"2AC9", "Resolvable Private Address Only"},
915 {"2ACC", "Fitness Machine Feature"},
916 {"2ACE", "Cross Trainer Data"},
917 {"2AD3", "Training Status"},
918 {"2AD7", "Supported Heart Rate Range"},
919 {"2AD9", "Fitness Machine Control Point"},
920 {"2ADA", "Fitness Machine Status"},
921 {"2B1D", "RC Feature"},
922 {"2B1E", "RC Settings"},
923 {"2B1F", "Reconnection Configuration Control Point"},
925 static uuid_name_s long_uuid_name[LONG_UUID_COUNT] = {
926 // List should be sorted by UUID
928 {"1AB7C24D-185A-45B9-90D4-F7AB1A71949A", "Samsung Health Service"},
929 {"22EAC6E9-24D6-4BB5-BE44-B36ACE7C7BFB", "Data Source"},
930 {"2F7CABCE-808D-411F-9A0C-BB92BA96C102", "Entity Update"},
931 {"32D1955A-E5AA-4A96-9A49-08538DA8B8F6", "Samsung Gear Fit Manager Service"},
932 {"69D1D8F3-45E1-49A8-9821-9BBDFDAAD9D9", "Control Point"},
933 {"7905F431-B5CE-4E99-A40F-4B1E122D00D0", "Apple Notification Center Service"},
934 {"89D3502B-0F36-433A-8EF4-C502AD55F8DC", "Apple Media Service"},
935 {"9A3F68E0-86CE-11E5-A309-0002A5D5C51B", "Samsung Gear Manager Service"},
936 {"9B3C81D8-57B1-4A8A-B8DF-0E56F7CA51C2", "Remote Command"},
937 {"9FBF120D-6301-42D9-8C58-25E699A21DBD", "Notifications Source"},
938 {"A49EB41E-CB06-495C-9F4F-BB80A90CDF00", "Samsung Gear Manager Service"},
939 {"ADE3D529-C784-4F63-A987-EB69F70EE816", "IoT OIC Service"},
940 {"C2051EE0-804D-4D50-A12C-15E243852100", "Notifications Source"},
941 {"C2F2CC0F-C085-4DD4-BE5A-ACA3074BBC72", "Control Point"},
942 {"C6B2F38C-23AB-46D8-A6AB-A3A870BBD5D7", "Entity Attribute"},
943 {"CECE518B-28D7-4171-92D5-76A1E249A3B9", "Notifications Source"},
944 {"FE53FF98-B259-4337-B56A-0EC9F82C6BAD", "Control Point"},
946 const uuid_name_s *uuid_name = short_uuid_name;
947 static const char *unknown_name = "Unknown";
949 int end = SHORT_UUID_COUNT - 1;
953 if (strlen(uuid) == 36) {
954 if (!g_ascii_strncasecmp(uuid + 9, "0000-1000-8000-00805F9B34FB", 27))
959 end = LONG_UUID_COUNT - 1;
960 uuid_name = long_uuid_name;
962 } else if (strlen(uuid) >= 8)
965 while (start <= end) {
966 p = start + (end - start) / 2;
967 ret = g_ascii_strncasecmp(uuid + offset, uuid_name[p].uuid, uuid_len);
969 return uuid_name[p].specification_name;
979 const char *_bt_convert_error_to_string(int error)
982 case BLUETOOTH_ERROR_CANCEL:
984 case BLUETOOTH_ERROR_INVALID_PARAM:
985 return "INVALID_PARAMETER";
986 case BLUETOOTH_ERROR_INVALID_DATA:
987 return "INVALID DATA";
988 case BLUETOOTH_ERROR_MEMORY_ALLOCATION:
989 case BLUETOOTH_ERROR_OUT_OF_MEMORY:
990 return "OUT_OF_MEMORY";
991 case BLUETOOTH_ERROR_TIMEOUT:
993 case BLUETOOTH_ERROR_NO_RESOURCES:
994 return "NO_RESOURCES";
995 case BLUETOOTH_ERROR_INTERNAL:
997 case BLUETOOTH_ERROR_NOT_SUPPORT:
998 return "NOT_SUPPORT";
999 case BLUETOOTH_ERROR_DEVICE_NOT_ENABLED:
1000 return "NOT_ENABLED";
1001 case BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED:
1002 return "ALREADY_ENABLED";
1003 case BLUETOOTH_ERROR_DEVICE_BUSY:
1004 return "DEVICE_BUSY";
1005 case BLUETOOTH_ERROR_ACCESS_DENIED:
1006 return "ACCESS_DENIED";
1007 case BLUETOOTH_ERROR_MAX_CLIENT:
1008 return "MAX_CLIENT";
1009 case BLUETOOTH_ERROR_NOT_FOUND:
1011 case BLUETOOTH_ERROR_SERVICE_SEARCH_ERROR:
1012 return "SERVICE_SEARCH_ERROR";
1013 case BLUETOOTH_ERROR_PARING_FAILED:
1014 return "PARING_FAILED";
1015 case BLUETOOTH_ERROR_NOT_PAIRED:
1016 return "NOT_PAIRED";
1017 case BLUETOOTH_ERROR_SERVICE_NOT_FOUND:
1018 return "SERVICE_NOT_FOUND";
1019 case BLUETOOTH_ERROR_NOT_CONNECTED:
1020 return "NOT_CONNECTED";
1021 case BLUETOOTH_ERROR_ALREADY_CONNECT:
1022 return "ALREADY_CONNECT";
1023 case BLUETOOTH_ERROR_CONNECTION_BUSY:
1024 return "CONNECTION_BUSY";
1025 case BLUETOOTH_ERROR_CONNECTION_ERROR:
1026 return "CONNECTION_ERROR";
1027 case BLUETOOTH_ERROR_MAX_CONNECTION:
1028 return "MAX_CONNECTION";
1029 case BLUETOOTH_ERROR_NOT_IN_OPERATION:
1030 return "NOT_IN_OPERATION";
1031 case BLUETOOTH_ERROR_CANCEL_BY_USER:
1032 return "CANCEL_BY_USER";
1033 case BLUETOOTH_ERROR_REGISTRATION_FAILED:
1034 return "REGISTRATION_FAILED";
1035 case BLUETOOTH_ERROR_IN_PROGRESS:
1036 return "IN_PROGRESS";
1037 case BLUETOOTH_ERROR_AUTHENTICATION_FAILED:
1038 return "AUTHENTICATION_FAILED";
1039 case BLUETOOTH_ERROR_HOST_DOWN:
1041 case BLUETOOTH_ERROR_END_OF_DEVICE_LIST:
1042 return "END_OF_DEVICE_LIST";
1043 case BLUETOOTH_ERROR_AGENT_ALREADY_EXIST:
1044 return "AGENT_ALREADY_EXIST";
1045 case BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST:
1046 return "AGENT_DOES_NOT_EXIST";
1047 case BLUETOOTH_ERROR_ALREADY_INITIALIZED:
1048 return "ALREADY_INITIALIZED";
1049 case BLUETOOTH_ERROR_PERMISSION_DEINED:
1050 return "PERMISSION_DEINED";
1051 case BLUETOOTH_ERROR_ALREADY_DEACTIVATED:
1052 return "ALREADY_DEACTIVATED";
1053 case BLUETOOTH_ERROR_NOT_INITIALIZED:
1054 return "NOT_INITIALIZED";
1060 const char * _bt_convert_disc_reason_to_string(int reason)
1066 return "Connection terminated by local host";
1068 return "Remote user terminated connection";
1076 void _bt_logging_connection(gboolean connect, int addr_type)
1078 static int le_conn = 0;
1079 static int le_disc = 0;
1080 static int edr_conn = 0;
1081 static int edr_disc = 0;
1095 BT_INFO("[PM] Number of LE conn: %d disc: %d, Number of BR/EDR conn: %d disc: %d",
1096 le_conn, le_disc, edr_conn, edr_disc);
1099 int _bt_eventsystem_set_value(const char *event, const char *key, const char *value)
1104 b = bundle_create();
1106 bundle_add_str(b, key, value);
1108 ret = eventsystem_send_system_event(event, b);
1110 BT_DBG("eventsystem_send_system_event result: %d", ret);
1117 void _bt_swap_byte_ordering(char *data, int data_len)
1122 ret_if(data == NULL);
1123 /* Swap to opposite endian */
1124 for (i = 0, j = data_len - 1; i < data_len; i++, j--) {
1131 int _bt_byte_arr_cmp(const char *data1, const char *data2, int data_len)
1135 retv_if(data1 == NULL, -1);
1136 retv_if(data2 == NULL, -1);
1137 for (i = 0; i < data_len; i++) {
1138 if (data1[i] != data2[i])
1139 return data1[i] - data2[i];
1143 int _bt_byte_arr_cmp_with_mask(const char *data1, const char *data2,
1144 const char *mask, int data_len)
1149 retv_if(data1 == NULL, -1);
1150 retv_if(data2 == NULL, -1);
1151 retv_if(mask == NULL, -1);
1152 for (i = 0; i < data_len; i++) {
1153 a = data1[i] & mask[i];
1154 b = data2[i] & mask[i];
1156 return (int)(a - b);
1161 void _bt_copy_remote_dev(bt_remote_dev_info_t *dev_info, remote_device_t *oal_device)
1165 dev_info->address = g_new0(char, BT_ADDRESS_STRING_SIZE);
1166 _bt_convert_addr_type_to_string(dev_info->address, oal_device->address.addr);
1167 BT_INFO("Address [%s]", dev_info->address);
1169 if (strlen(oal_device->name) == 0)
1170 dev_info->name = NULL;
1172 dev_info->name = g_strdup(oal_device->name);
1173 _bt_truncate_non_utf8_chars(dev_info->name);
1174 BT_INFO("Name [%s]", dev_info->name);
1177 if (strlen(oal_device->alias) == 0) {
1178 dev_info->alias = NULL;
1180 dev_info->alias = g_strdup(oal_device->alias);
1181 _bt_truncate_non_utf8_chars(dev_info->alias);
1182 BT_INFO("Alias [%s]", dev_info->alias);
1185 dev_info->class = oal_device->cod;
1186 dev_info->paired = oal_device->is_bonded;
1187 BT_INFO("Is Bonded [%d]", dev_info->paired);
1188 dev_info->connected = oal_device->is_connected;
1189 BT_INFO("iS Connected [%d]", dev_info->connected);
1190 dev_info->rssi = oal_device->rssi;
1191 dev_info->addr_type = oal_device->type;
1192 dev_info->uuid_count = oal_device->uuid_count;
1193 BT_INFO("UUID Count [%d]", dev_info->uuid_count);
1194 dev_info->trust = ((oal_device->is_trusted == 0) ? FALSE : TRUE);
1196 if (dev_info->uuid_count > 0)
1197 dev_info->uuids = g_new0(char *, dev_info->uuid_count);
1199 /* Fill Remote Device Service List list */
1200 for (i = 0; i < dev_info->uuid_count; i++) {
1201 dev_info->uuids[i] = g_malloc0(BLUETOOTH_UUID_STRING_MAX);
1202 _bt_uuid_to_string((service_uuid_t *)&oal_device->uuid[i].uuid, dev_info->uuids[i]);
1205 dev_info->vid = (unsigned short)oal_device->vid;
1206 dev_info->pid = (unsigned short)oal_device->pid;
1207 dev_info->device_type = (int)oal_device->type;
1208 dev_info->is_alias_set = ((oal_device->is_alias_set == 0) ? FALSE : TRUE);
1212 void _bt_free_remote_dev(bt_remote_dev_info_t *dev_info)
1216 ret_if(NULL == dev_info);
1218 g_free(dev_info->address);
1219 g_free(dev_info->name);
1220 g_free(dev_info->alias);
1221 g_free(dev_info->manufacturer_data);
1223 for (c = 0; c < dev_info->uuid_count; c++)
1224 g_free(dev_info->uuids[c]);
1225 g_free(dev_info->uuids);
1230 static void __bt_get_service_list(bt_remote_dev_info_t *info, bluetooth_device_info_t *dev)
1236 ret_if(info == NULL);
1237 ret_if(dev == NULL);
1239 uuids = info->uuids;
1240 if (uuids == NULL) {
1241 BT_ERR("No UUID's");
1245 dev->service_index = 0;
1246 BT_DBG("Total UUID count [%d]", info->uuid_count);
1247 for (i = 0; i < info->uuid_count; i++) {
1248 g_strlcpy(dev->uuids[i], uuids[i], BLUETOOTH_UUID_STRING_MAX);
1250 parts = g_strsplit(uuids[i], "-", -1);
1252 if (parts == NULL || parts[0] == NULL)
1255 dev->service_list_array[i] = g_ascii_strtoull(parts[0], NULL, 16);
1258 dev->service_index++;
1263 void _bt_copy_remote_device(bt_remote_dev_info_t *rem_dev, bluetooth_device_info_t *dev)
1265 memset(dev, 0x00, sizeof(bluetooth_device_info_t));
1266 __bt_get_service_list(rem_dev, dev);
1267 _bt_convert_addr_string_to_type(dev->device_address.addr, rem_dev->address);
1268 _bt_divide_device_class(&dev->device_class, rem_dev->class);
1270 if (rem_dev->alias) {
1271 g_strlcpy(dev->device_name.name, rem_dev->alias,
1272 BLUETOOTH_DEVICE_NAME_LENGTH_MAX + 1);
1273 BT_DBG("Name: %s", dev->device_name.name);
1275 g_strlcpy(dev->device_name.name, rem_dev->name,
1276 BLUETOOTH_DEVICE_NAME_LENGTH_MAX + 1);
1277 BT_DBG("Name: %s", dev->device_name.name);
1280 dev->rssi = rem_dev->rssi;
1281 dev->trust = rem_dev->trust;
1282 dev->paired = rem_dev->paired;
1283 dev->connected = rem_dev->connected;
1284 dev->is_alias_set = rem_dev->is_alias_set;
1286 /* Fill Manufacturer data */
1287 if (rem_dev->manufacturer_data_len > 0) {
1288 dev->manufacturer_data.data_len = rem_dev->manufacturer_data_len;
1289 memcpy(dev->manufacturer_data.data,
1290 rem_dev->manufacturer_data, rem_dev->manufacturer_data_len);
1292 dev->manufacturer_data.data_len = 0;
1297 void _bt_service_print_dev_info(bluetooth_device_info_t *dev_info)
1301 ret_if(dev_info == NULL);
1303 _bt_print_device_address_t(&(dev_info->device_address));
1304 BT_INFO("Device Name:[%s]", dev_info->device_name.name);
1305 BT_INFO("Device Major Class:[0x%X]", dev_info->device_class.major_class);
1306 BT_INFO("Device Minor Class:[0x%X]", dev_info->device_class.minor_class);
1307 BT_INFO("Device Service Class:[0x%X]", dev_info->device_class.minor_class);
1308 BT_INFO("Device Paired:[%s]", (dev_info->paired ? "TRUE" : "FALSE"));
1309 BT_INFO("Device Trusted:[%s]", (dev_info->trust ? "TRUE" : "FALSE"));
1310 BT_INFO("Device Connected:[%d]", dev_info->connected);
1311 BT_INFO("Device Service index:[%d]", dev_info->service_index);
1312 for (i = 0; i < dev_info->service_index; i++) {
1313 BT_INFO("Device Service List:[%d]", dev_info->service_list_array[i]);
1314 BT_INFO("Device UUID:[%s]", dev_info->uuids[i]);
1317 BT_INFO("Device manufacturer data len:[%d]", dev_info->manufacturer_data.data_len);
1318 for (i = 0; i < dev_info->manufacturer_data.data_len; i++)
1319 BT_INFO("%2.2X", dev_info->manufacturer_data.data[i]);
1322 void _bt_uuid_to_string(service_uuid_t *p_uuid, char *str)
1324 uint32_t uuid0, uuid4;
1325 uint16_t uuid1, uuid2, uuid3, uuid5;
1327 memcpy(&uuid0, &(p_uuid->uuid[0]), 4);
1328 memcpy(&uuid1, &(p_uuid->uuid[4]), 2);
1329 memcpy(&uuid2, &(p_uuid->uuid[6]), 2);
1330 memcpy(&uuid3, &(p_uuid->uuid[8]), 2);
1331 memcpy(&uuid4, &(p_uuid->uuid[10]), 4);
1332 memcpy(&uuid5, &(p_uuid->uuid[14]), 2);
1334 snprintf((char *)str, BLUETOOTH_UUID_STRING_MAX, "%.8x-%.4x-%.4x-%.4x-%.8x%.4x",
1335 ntohl(uuid0), ntohs(uuid1),
1336 ntohs(uuid2), ntohs(uuid3),
1337 ntohl(uuid4), ntohs(uuid5));
1341 void _bt_string_to_uuid(char *str, service_uuid_t *p_uuid)
1343 uint32_t uuid0, uuid4;
1344 uint16_t uuid1, uuid2, uuid3, uuid5;
1346 sscanf(str, "%08x-%04hx-%04hx-%04hx-%08x%04hx",
1347 &uuid0, &uuid1, &uuid2, &uuid3, &uuid4, &uuid5);
1349 uuid0 = htonl(uuid0);
1350 uuid1 = htons(uuid1);
1351 uuid2 = htons(uuid2);
1352 uuid3 = htons(uuid3);
1353 uuid4 = htonl(uuid4);
1354 uuid5 = htons(uuid5);
1356 memcpy(&(p_uuid->uuid[0]), &uuid0, 4);
1357 memcpy(&(p_uuid->uuid[4]), &uuid1, 2);
1358 memcpy(&(p_uuid->uuid[6]), &uuid2, 2);
1359 memcpy(&(p_uuid->uuid[8]), &uuid3, 2);
1360 memcpy(&(p_uuid->uuid[10]), &uuid4, 4);
1361 memcpy(&(p_uuid->uuid[14]), &uuid5, 2);
1366 void _bt_convert_byte_ordering(char *data, int data_len,
1367 char *converted_data)
1370 char temp[BT_UUID_LEN];
1372 memcpy(&temp, data, data_len);
1373 for (i = 0, j = data_len - 1; i < data_len; i++, j--)
1374 converted_data[i] = temp[j];
1378 /* Trim string at first non-utf8 char */
1379 void _bt_truncate_non_utf8_chars(char * str)
1382 const char *ptr = NULL;
1384 if (strlen(str) != 0) {
1385 if (!g_utf8_validate(str, -1, &ptr)) {
1386 while (*(str + i) != *ptr)
1393 invocation_info_t* _bt_get_request_info_data(int service_function, char *address)
1396 invocation_info_t *req_info = NULL;
1400 retv_if(NULL == address, NULL);
1402 /* Get method invocation context */
1403 for (l = _bt_get_invocation_list(); l != NULL; l = g_slist_next(l)) {
1405 if (req_info == NULL || req_info->service_function != service_function)
1408 if (!strncasecmp((char *)req_info->user_data, address, BT_ADDRESS_STRING_SIZE))
1416 #ifdef TIZEN_GATT_CLIENT
1417 invocation_info_t* _bt_get_request_info_data_from_function_name(int service_function)
1420 invocation_info_t *req_info = NULL;
1422 /* Get method invocation context */
1423 for (l = _bt_get_invocation_list(); l != NULL; l = g_slist_next(l)) {
1425 if (req_info == NULL || req_info->service_function != service_function)
1430 BT_DBG("Not existed");
1435 void _bt_set_device_values(gboolean connected, int state)
1437 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
1439 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
1440 BT_ERR("vconf_get_int failed");
1442 if (connected == TRUE)
1443 bt_device_state |= state;
1444 else if (bt_device_state & state)
1445 bt_device_state ^= state;
1447 if (vconf_set_int(VCONFKEY_BT_DEVICE, bt_device_state) != 0)
1448 BT_ERR("vconf_set_int failed");
1451 int _bt_get_ad_data_by_type(char *in_data, int in_len,
1452 char in_type, char **data, int *data_len)
1454 if (in_data == NULL || data == NULL || data_len == NULL)
1455 return BLUETOOTH_ERROR_INVALID_PARAM;
1458 return BLUETOOTH_ERROR_INVALID_PARAM;
1464 for (i = 0; i < in_len; i++) {
1466 if (len <= 0 || i + 1 >= in_len) {
1467 BT_ERR("Invalid advertising data");
1468 return BLUETOOTH_ERROR_INVALID_PARAM;
1471 type = in_data[i + 1];
1472 if (type == in_type) {
1482 if (i + len > in_len) {
1483 BT_ERR("Invalid advertising data");
1484 return BLUETOOTH_ERROR_INVALID_PARAM;
1485 } else if (len == 0) {
1486 BT_INFO("AD Type 0x%02x data is not set", in_type);
1489 return BLUETOOTH_ERROR_NONE;
1492 *data = g_memdup(&in_data[i], len);
1494 return BLUETOOTH_ERROR_OUT_OF_MEMORY;
1497 return BLUETOOTH_ERROR_NONE;
1500 void _bt_copy_remote_dev_info(bt_remote_dev_info_t *dest, bt_remote_dev_info_t *src)
1502 ret_if(NULL == src);
1504 if (!dest->address) {
1505 dest->address = g_strdup(src->address);
1510 dest->name = g_strdup(src->name);
1514 g_free(dest->alias);
1515 dest->alias = g_strdup(src->alias);
1518 if (src->uuid_count > 0 && src->uuids) {
1521 /* Release previously allocated UUIDs */
1522 if (dest->uuid_count > 0 && dest->uuids)
1523 for (i = 0; i < dest->uuid_count; i++)
1524 g_free(dest->uuids[i]);
1525 g_free(dest->uuids);
1527 /* Copy new UUID list */
1528 dest->uuids = g_malloc0(src->uuid_count * sizeof(char *));
1529 for (i = 0; i < src->uuid_count; i++)
1530 dest->uuids[i] = g_strdup(src->uuids[i]);
1532 dest->uuid_count = src->uuid_count;
1535 if (src->manufacturer_data_len > 0 && src->manufacturer_data) {
1536 if (dest->manufacturer_data)
1537 g_free(dest->manufacturer_data);
1539 dest->manufacturer_data_len = src->manufacturer_data_len;
1540 dest->manufacturer_data = g_memdup(
1541 src->manufacturer_data, src->manufacturer_data_len);
1544 dest->rssi = src->rssi;
1545 dest->class = src->class;
1546 dest->paired = src->paired;
1547 dest->connected = src->connected;
1548 dest->trust = src->trust;
1549 dest->addr_type = src->addr_type;
1550 dest->vid = src->vid;
1551 dest->pid = src->pid;
1552 dest->device_type = src->device_type;
1553 dest->is_alias_set = src->is_alias_set;
1557 #define BT_PERMANENT_LOG_FILE_PATH "/opt/usr/home/owner/media/Downloads/.bt_dump/permanent_log.txt"
1558 #define BT_PERMANENT_LOG_OLD_FILE_PATH "/opt/usr/home/owner/media/Downloads/.bt_dump/permanent_log_old.txt"
1559 #define PERMANENT_LOG_MAX (128 * 1024)
1560 void _bt_permanent_log(const char *fmt, ...)
1569 #ifndef TIZEN_FEATURE_BT_PERMANENT_LOG
1575 strftime(time_buf, sizeof(time_buf), "%m-%d %H:%M:%S", lt);
1577 fp = fopen(BT_PERMANENT_LOG_FILE_PATH, "r");
1579 fseek(fp, 0, SEEK_END);
1583 if (lsize > PERMANENT_LOG_MAX) {
1586 fp2 = fopen(BT_PERMANENT_LOG_OLD_FILE_PATH, "w");
1589 fseek(fp, 0, SEEK_SET);
1591 character = fgetc(fp);
1592 fputc(character, fp2);
1596 fp = fopen(BT_PERMANENT_LOG_FILE_PATH, "w");
1600 fp = fopen(BT_PERMANENT_LOG_FILE_PATH, "a");
1606 vsnprintf(buf, 100, fmt, ap);
1608 fprintf(fp, "%s %s\n", time_buf, buf);