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>
49 static GSList *osp_server_list;
51 #ifdef TIZEN_FEATURE_BT_IPSP
52 static GDBusProxy *ipsp_proxy;
54 static GDBusConnection *system_conn;
55 static GDBusConnection *session_conn;
56 static GDBusProxy *manager_proxy_g;
57 static GDBusProxy *adapter_proxy_g;
58 static void *net_conn;
60 static GDBusProxy *adapter_properties_proxy;
62 static GDBusConnection *system_gconn = NULL;
64 GDBusConnection *_bt_gdbus_init_system_gconn(void)
68 dbus_threads_init_default();
70 if (system_gconn != NULL)
73 system_gconn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
76 BT_ERR("Unable to connect to dbus: %s", error->message);
77 g_clear_error(&error);
83 GDBusConnection *_bt_gdbus_get_system_gconn(void)
85 GDBusConnection *local_system_gconn = NULL;
88 if (system_gconn == NULL) {
89 system_gconn = _bt_gdbus_init_system_gconn();
90 } else if (g_dbus_connection_is_closed(system_gconn)) {
92 local_system_gconn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
94 if (!local_system_gconn) {
95 BT_ERR("Unable to connect to dbus: %s", error->message);
96 g_clear_error(&error);
99 system_gconn = local_system_gconn;
105 static GDBusProxy *__bt_init_manager_proxy(void)
109 if (system_conn == NULL) {
110 system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
111 retv_if(system_conn == NULL, NULL);
114 proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE,
116 BT_MANAGER_PATH, BT_MANAGER_INTERFACE, NULL, NULL);
118 retv_if(proxy == NULL, NULL);
120 manager_proxy_g = proxy;
125 static GDBusProxy *__bt_init_adapter_proxy(void)
127 GDBusProxy *manager_proxy;
129 char *adapter_path = NULL;
131 if (system_conn == NULL) {
132 system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
133 retv_if(system_conn == NULL, NULL);
136 manager_proxy = _bt_get_manager_proxy();
137 retv_if(manager_proxy == NULL, NULL);
139 adapter_path = _bt_get_adapter_path();
140 retv_if(adapter_path == NULL, NULL);
142 proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE,
144 adapter_path, BT_ADAPTER_INTERFACE, NULL, NULL);
146 g_free(adapter_path);
148 retv_if(proxy == NULL, NULL);
150 adapter_proxy_g = proxy;
154 #ifdef TIZEN_FEATURE_BT_IPSP
155 static GDBusProxy *__bt_init_ipsp_proxy(void)
159 GDBusConnection *g_conn;
161 g_conn = _bt_gdbus_get_system_gconn();
162 retv_if(g_conn == NULL, NULL);
163 proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
165 "/org/projectx/bt_ipsp", BT_IPSP_INTERFACE, NULL, NULL);
167 BT_ERR("Unable to get proxy");
175 static GDBusProxy *__bt_init_adapter_properties_proxy(void)
177 GDBusProxy *manager_proxy;
179 char *adapter_path = NULL;
181 if (system_conn == NULL) {
182 system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
183 retv_if(system_conn == NULL, NULL);
186 manager_proxy = _bt_get_manager_proxy();
187 retv_if(manager_proxy == NULL, NULL);
189 adapter_path = _bt_get_adapter_path();
190 retv_if(adapter_path == NULL, NULL);
192 proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE,
194 adapter_path, BT_PROPERTIES_INTERFACE, NULL, NULL);
196 g_free(adapter_path);
198 retv_if(proxy == NULL, NULL);
200 adapter_properties_proxy = proxy;
205 GDBusConnection *__bt_init_system_gconn(void)
207 if (system_conn == NULL)
208 system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
213 GDBusConnection *__bt_init_session_conn(void)
215 if (session_conn == NULL)
216 session_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
221 GDBusConnection *_bt_get_session_gconn(void)
223 return (session_conn) ? session_conn : __bt_init_session_conn();
226 GDBusConnection *_bt_get_system_gconn(void)
228 return (system_conn) ? system_conn : __bt_init_system_gconn();
231 GDBusConnection *_bt_get_system_conn(void)
233 GDBusConnection *g_conn;
235 if (system_conn == NULL)
236 g_conn = __bt_init_system_gconn();
238 g_conn = system_conn;
240 retv_if(g_conn == NULL, NULL);
245 GDBusProxy *_bt_get_manager_proxy(void)
247 if (manager_proxy_g) {
248 const gchar *path = g_dbus_proxy_get_object_path(manager_proxy_g);
250 BT_ERR("Already proxy released hence creating new proxy");
251 return __bt_init_manager_proxy();
253 return manager_proxy_g;
255 return __bt_init_manager_proxy();
257 #ifdef TIZEN_FEATURE_BT_IPSP
258 GDBusProxy *_bt_get_ipsp_proxy(void)
261 const char *path = g_dbus_proxy_get_object_path(ipsp_proxy);
263 BT_ERR("Already proxy released hence creating new proxy");
264 return __bt_init_ipsp_proxy();
268 return __bt_init_ipsp_proxy();
272 static void *__bt_init_net_conn(void)
275 connection_h connection = NULL;
277 if (net_conn == NULL) {
278 result = connection_create(&connection);
280 if (result != CONNECTION_ERROR_NONE ||
281 connection == NULL) {
282 BT_DBG("connection_create() failed: %d", result);
286 net_conn = connection;
291 void *_bt_get_net_conn(void)
293 return (net_conn) ? net_conn : __bt_init_net_conn();
296 GDBusProxy *_bt_get_adapter_proxy(void)
298 if (adapter_proxy_g) {
299 const char *path = g_dbus_proxy_get_object_path(adapter_proxy_g);
301 BT_ERR("Already proxy released hence creating new proxy");
302 return __bt_init_adapter_proxy();
305 return adapter_proxy_g;
307 return __bt_init_adapter_proxy();
311 GDBusProxy *_bt_get_adapter_properties_proxy(void)
313 return (adapter_properties_proxy) ? adapter_properties_proxy :
314 __bt_init_adapter_properties_proxy();
317 static char *__bt_extract_adapter_path(GVariantIter *iter)
319 char *object_path = NULL;
320 GVariantIter *interface_iter;
321 GVariantIter *svc_iter;
322 char *interface_str = NULL;
324 /* Parse the signature: oa{sa{sv}}} */
325 while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path,
328 if (object_path == NULL)
331 while (g_variant_iter_loop(interface_iter, "{&sa{sv}}",
332 &interface_str, &svc_iter)) {
333 if (g_strcmp0(interface_str, "org.bluez.Adapter1") != 0)
336 BT_DBG("Object Path: %s", object_path);
337 g_variant_iter_free(svc_iter);
338 g_variant_iter_free(interface_iter);
339 return g_strdup(object_path);
345 char *_bt_get_adapter_path(void)
347 GDBusConnection *conn;
348 GDBusProxy *manager_proxy;
349 GVariant *result = NULL;
350 GVariantIter *iter = NULL;
351 char *adapter_path = NULL;
353 conn = _bt_get_system_conn();
354 retv_if(conn == NULL, NULL);
356 manager_proxy = _bt_get_manager_proxy();
357 retv_if(manager_proxy == NULL, NULL);
359 result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
361 G_DBUS_CALL_FLAGS_NONE,
366 BT_ERR("Can't get managed objects");
370 /* signature of GetManagedObjects: a{oa{sa{sv}}} */
371 g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
373 adapter_path = __bt_extract_adapter_path(iter);
374 g_variant_iter_free(iter);
375 g_variant_unref(result);
379 void _bt_deinit_bluez_proxy(void)
381 if (manager_proxy_g) {
382 g_object_unref(manager_proxy_g);
383 manager_proxy_g = NULL;
386 if (adapter_proxy_g) {
387 g_object_unref(adapter_proxy_g);
388 adapter_proxy_g = NULL;
390 if (adapter_properties_proxy) {
391 g_object_unref(adapter_properties_proxy);
392 adapter_properties_proxy = NULL;
396 void _bt_deinit_proxys(void)
399 _bt_deinit_bluez_proxy();
402 g_object_unref(system_conn);
407 g_object_unref(session_conn);
412 ret = connection_destroy(net_conn);
415 BT_ERR("connection_destroy failed : %d", ret);
419 void _bt_convert_device_path_to_address(const char *device_path,
420 char *device_address)
422 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
425 ret_if(device_path == NULL);
426 ret_if(device_address == NULL);
428 dev_addr = strstr(device_path, "dev_");
429 if (dev_addr != NULL) {
432 g_strlcpy(address, dev_addr, sizeof(address));
434 while ((pos = strchr(address, '_')) != NULL)
437 g_strlcpy(device_address, address, BT_ADDRESS_STRING_SIZE);
442 void _bt_convert_addr_string_to_type(unsigned char *addr,
448 ret_if(address == NULL);
449 ret_if(addr == NULL);
451 for (i = 0; i < BT_ADDRESS_LENGTH_MAX; i++) {
452 addr[i] = strtol(address, &ptr, 16);
453 if (ptr[0] != '\0') {
462 void _bt_convert_addr_type_to_string(char *address,
465 ret_if(address == NULL);
466 ret_if(addr == NULL);
468 snprintf(address, BT_ADDRESS_STRING_SIZE,
469 "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
470 addr[0], addr[1], addr[2],
471 addr[3], addr[4], addr[5]);
474 int _bt_convert_oal_status_to_bt_error(oal_status_t oal_status)
476 switch (oal_status) {
477 case OAL_STATUS_SUCCESS:
478 return BLUETOOTH_ERROR_NONE;
479 case OAL_STATUS_INVALID_PARAM:
480 return BLUETOOTH_ERROR_INVALID_PARAM;
481 case OAL_STATUS_NOT_SUPPORT:
482 return BLUETOOTH_ERROR_NOT_SUPPORT;
483 case OAL_STATUS_NOT_READY:
484 return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
485 case OAL_STATUS_BUSY:
486 return BLUETOOTH_ERROR_DEVICE_BUSY;
487 case OAL_STATUS_NOT_PAIRED:
488 return BLUETOOTH_ERROR_NOT_PAIRED;
489 case OAL_STATUS_ALREADY_DONE:
490 return BLUETOOTH_ERROR_ALREADY_CONNECT;
491 case OAL_STATUS_PENDING:
492 return BLUETOOTH_ERROR_IN_PROGRESS;
493 case OAL_STATUS_INTERNAL_ERROR:
494 case OAL_STATUS_RMT_DEVICE_DOWN:
495 case OAL_STATUS_AUTH_FAILED:
496 case OAL_STATUS_CONN_TIMEOUT:
497 case OAL_STATUS_HID_FAILED_MOUSE:
499 case OAL_STATUS_LINK_LOSS:
501 case OAL_STATUS_LINK_LOSS:
502 case OAL_STATUS_CONN_TERM_LOCAL_HOST:
503 case OAL_STATUS_CONN_TERM_RMT_HOST:
504 case OAL_STATUS_ALREADY_CONNECT:
507 return BLUETOOTH_ERROR_INTERNAL;
511 gboolean _bt_compare_adddress(const bluetooth_device_address_t *addr1,
512 const bluetooth_device_address_t *addr2)
514 if (memcmp(&addr1->addr, &addr2->addr, 6) == 0)
520 void _bt_print_device_address_t(const bluetooth_device_address_t *addr)
522 BT_INFO("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
523 addr->addr[0], addr->addr[1], addr->addr[2],
524 addr->addr[3], addr->addr[4], addr->addr[5]);
527 void _bt_divide_device_class(bluetooth_device_class_t *device_class,
530 ret_if(device_class == NULL);
532 device_class->major_class = (unsigned short)(cod & 0x00001F00) >> 8;
533 device_class->minor_class = (unsigned short)((cod & 0x000000FC));
534 device_class->service_class = (unsigned long)((cod & 0x00FF0000));
536 if (cod & 0x002000) {
537 device_class->service_class |=
538 BLUETOOTH_DEVICE_SERVICE_CLASS_LIMITED_DISCOVERABLE_MODE;
542 void _bt_free_le_device_info(bt_remote_le_dev_info_t *le_dev_info)
544 ret_if(le_dev_info == NULL);
546 g_free(le_dev_info->adv_data);
550 int _bt_copy_utf8_string(char *dest, const char *src, unsigned int length)
557 if (dest == NULL || src == NULL)
558 return BLUETOOTH_ERROR_INVALID_PARAM;
560 BT_DBG("+src : %s", src);
561 BT_DBG("+dest : %s", dest);
564 while (*p != '\0' && i < length) {
565 next = g_utf8_next_char(p);
568 while (count > 0 && ((i + count) < length)) {
575 return BLUETOOTH_ERROR_NONE;
578 gboolean _bt_utf8_validate(char *name)
581 glong items_written = 0;
583 if (FALSE == g_utf8_validate(name, -1, NULL))
586 u16 = g_utf8_to_utf16(name, -1, NULL, &items_written, NULL);
592 if (items_written != g_utf8_strlen(name, -1))
598 int _bt_register_osp_server_in_agent(const char *sender, int type, char *uuid, char *path, int fd)
600 retv_if(sender == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
601 retv_if(uuid == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
602 retv_if(path == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
606 if (type == OAL_OSP_SERVER_RFCOMM) {
607 struct osp_server_t *osp_server;
608 osp_server = g_malloc0(sizeof(struct osp_server_t));
609 osp_server->sender = g_strdup(sender);
610 osp_server->uuid = g_strdup(uuid);
611 osp_server_list = g_slist_append(osp_server_list, osp_server);
614 if (device_register_osp_server(type, uuid, path, fd) != 0)
615 return BLUETOOTH_ERROR_INTERNAL;
616 return BLUETOOTH_ERROR_NONE;
619 static void __bt_free_osp_server(struct osp_server_t *osp_server)
621 g_free(osp_server->sender);
622 g_free(osp_server->uuid);
626 int _bt_unregister_osp_server_in_agent(int type, char *uuid)
629 struct osp_server_t *osp_server;
630 retv_if(uuid == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
634 if (device_unregister_osp_server(type, uuid) != 0)
635 return BLUETOOTH_ERROR_INTERNAL;
637 for (l = osp_server_list; l; l = g_slist_next(l)) {
638 osp_server = l->data;
641 if (g_strcmp0(osp_server->uuid, uuid) == 0) {
642 osp_server_list = g_slist_remove(osp_server_list, osp_server);
643 __bt_free_osp_server(osp_server);
648 return BLUETOOTH_ERROR_NONE;
651 int _bt_unregister_osp_server_in_agent_by_sender(const char *sender)
654 struct osp_server_t *osp_server;
655 retv_if(sender == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
657 BT_DBG("Unregister osp server by sender: %s", sender);
659 /* App termination case, unregister all osp_server of sender */
660 for (l = osp_server_list; l; ) {
661 osp_server = l->data;
665 if (g_strcmp0(osp_server->sender, sender) == 0) {
666 if (device_unregister_osp_server(OAL_OSP_SERVER_RFCOMM, osp_server->uuid) != 0)
667 return BLUETOOTH_ERROR_INTERNAL;
668 osp_server_list = g_slist_remove(osp_server_list, osp_server);
669 __bt_free_osp_server(osp_server);
673 return BLUETOOTH_ERROR_NONE;
676 void _bt_deinit_osp_server()
678 g_slist_free_full(osp_server_list, (GDestroyNotify)__bt_free_osp_server);
679 osp_server_list = NULL;
682 int _bt_set_socket_non_blocking(int socket_fd)
684 /* Set Nonblocking */
687 arg = fcntl(socket_fd, F_GETFL);
692 if (arg & O_NONBLOCK)
693 BT_ERR("Already Non-blocking \n");
697 if (fcntl(socket_fd, F_SETFL, arg) < 0)
700 return BLUETOOTH_ERROR_NONE;
703 int _bt_set_non_blocking_tty(int sk)
705 struct termios ti = {0,};
708 err = _bt_set_socket_non_blocking(sk);
711 BT_ERR("Error in set non blocking!\n");
715 tcflush(sk, TCIOFLUSH);
717 /* Switch tty to RAW mode */
719 tcsetattr(sk, TCSANOW, &ti);
721 return BLUETOOTH_ERROR_NONE;
724 static char *__bt_extract_device_path(GVariantIter *iter, char *address)
726 char *object_path = NULL;
727 char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
729 /* Parse the signature: oa{sa{sv}}} */
730 while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path,
732 retv_if(object_path == NULL, NULL);
733 _bt_convert_device_path_to_address(object_path, device_address);
734 if (g_strcmp0(address, device_address) == 0)
735 return g_strdup(object_path);
740 char *_bt_get_device_object_path(char *address)
742 char *object_path = NULL;
743 GDBusConnection *conn;
744 GDBusProxy *manager_proxy;
745 GVariant *result = NULL;
746 GVariantIter *iter = NULL;
748 conn = _bt_get_system_conn();
749 retv_if(conn == NULL, NULL);
751 manager_proxy = _bt_get_manager_proxy();
752 retv_if(manager_proxy == NULL, NULL);
754 result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
756 G_DBUS_CALL_FLAGS_NONE,
761 BT_ERR("Can't get managed objects");
765 /* signature of GetManagedObjects: a{oa{sa{sv}}} */
766 g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
767 object_path = __bt_extract_device_path(iter, address);
768 g_variant_iter_free(iter);
769 g_variant_unref(result);
773 char *_bt_get_profile_uuid128(bt_profile_type_t profile_type)
775 switch (profile_type) {
776 case BT_PROFILE_CONN_RFCOMM:
777 return strdup(RFCOMM_UUID_STR);
778 case BT_PROFILE_CONN_A2DP:
779 return strdup(A2DP_SINK_UUID);
780 case BT_PROFILE_CONN_A2DP_SINK:
781 return strdup(A2DP_SOURCE_UUID);
782 case BT_PROFILE_CONN_HSP:
783 return strdup(HFP_HS_UUID);
784 case BT_PROFILE_CONN_HID:
785 return strdup(HID_UUID);
786 case BT_PROFILE_CONN_NAP:
787 return strdup(NAP_UUID);
788 case BT_PROFILE_CONN_HFG:
789 return strdup(HFP_AG_UUID);
790 case BT_PROFILE_CONN_GATT:
791 case BT_PROFILE_CONN_ALL: /* NULL UUID will connect to both the audio profiles*/
797 const char *_bt_convert_uuid_to_string(const char *uuid)
799 #define SHORT_UUID_COUNT 199
800 #define LONG_UUID_COUNT 17
809 const char *specification_name;
811 static uuid_name_s short_uuid_name[SHORT_UUID_COUNT] = {
812 // List should be sorted by UUID
813 /* BT Classic Services */
814 {"1101", "Serial Port Service"},
815 {"1102", "LAN Access Using PPP Service"},
816 {"1103", "Dialup Networking Service"},
817 {"1104", "IrMCSync Service"},
818 {"1105", "OBEX Object Push Service"},
819 {"1106", "OBEX File Transfer Service"},
820 {"1107", "IrMC Sync Command Service"},
821 {"1108", "Headset Service"},
822 {"1109", "Cordless Telephony Service"},
823 {"110A", "Audio Source Service"},
824 {"110B", "Audio Sink Service"},
825 {"110C", "AV Remote Control Target Service"},
826 {"110D", "Advanced Audio Distribution Profile"},
827 {"110E", "AV Remote Control Service"},
828 {"110F", "Video Conferencing Service"},
829 {"1110", "Intercom Service"},
830 {"1111", "Fax Service"},
831 {"1112", "Headset Audio Gateway Service"},
832 {"1113", "WAP Service"},
833 {"1114", "WAP Client Service"},
834 {"1115", "PANU Service"},
835 {"1116", "NAP Service"},
836 {"1117", "GN Service"},
837 {"1118", "Direct Printing Service"},
838 {"1119", "Reference Printing Service"},
839 {"111A", "Basic Imaging Profile"},
840 {"111B", "Imaging Responder Service"},
841 {"111C", "Imaging Automatic Archive Service"},
842 {"111D", "Imaging Reference Objects Service"},
843 {"111E", "Handsfree Service"},
844 {"111F", "Handsfree Audio Gateway Service"},
845 {"1120", "Direct Printing Reference Objects Service"},
846 {"1121", "Reflected UI Service"},
847 {"1122", "Basic Printing Profile"},
848 {"1123", "Printing Status Service"},
849 {"1124", "Human Interface Device Service"},
850 {"1125", "Hardcopy Cable Replacement Profile"},
851 {"1126", "HCR Print Service"},
852 {"1127", "HCR Scan Service"},
853 {"112D", "SIM Access Service"},
854 {"112E", "Phonebook Access PCE Service"},
855 {"112F", "Phonebook Access PSE Service"},
856 {"1130", "Phonebook Access Profile"},
857 {"1132", "Message Access Server Service"},
858 {"1133", "Message Notification Server Service"},
859 {"1134", "Message Access Profile"},
860 {"1200", "PnP Information Service"},
861 {"1201", "Generic Networking Service"},
862 {"1202", "Generic File Transfer Service"},
863 {"1203", "Generic Audio Service"},
864 {"1204", "Generic Telephony Service"},
865 {"1205", "UPnP Service"},
866 {"1206", "UPnP Ip Service"},
867 {"1303", "Video Source Service"},
868 {"1304", "Video Sink Service"},
869 {"1305", "Video Distribution Profile"},
870 {"1400", "Health Device Profile"},
871 {"1401", "HDP Source Service"},
872 {"1402", "HDP Sink Service"},
875 {"1800", "Generic Access"},
876 {"1801", "Generic Attribute"},
877 {"1802", "Immediate Alert"},
878 {"1803", "Link Loss"},
879 {"1804", "Tx Power"},
880 {"1805", "Current Time Service"},
881 {"1806", "Reference Time Update Service"},
882 {"1807", "Next DST Change Service"},
884 {"1809", "Health Thermometer"},
885 {"180A", "Device Information"},
886 {"180D", "Heart Rate"},
887 {"180F", "Battery Service"},
888 {"1810", "Blood Pressure"},
889 {"1811", "Alert Notification Service"},
890 {"1812", "Human Interface Device"},
891 {"1813", "Scan Parameters"},
892 {"1814", "Running Speed and Cadence"},
893 {"1815", "Automation IO"},
894 {"1816", "Cycling Speed and Cadence"},
895 {"1818", "Cycling Power"},
896 {"1819", "Location and Navigation"},
897 {"181A", "Environmental Sensing"},
898 {"181B", "Body Composition"},
899 {"181C", "User Data"},
900 {"181D", "Weight Scale"},
901 {"181E", "Bond Management"},
902 {"181F", "Continuous Glucose Monitoring"},
903 {"1820", "Internet Protocol Support Service"},
904 {"1821", "Indoor Positioning"},
905 {"1822", "Pulse Oximeter Service"},
906 {"1823", "HTTP Proxy"},
907 {"1824", "Transport Discovery"},
908 {"1825", "Object Transfer Service"},
909 {"1826", "Fitness Machine"},
910 {"1827", "Mesh Provisioning Service"},
911 {"1828", "Mesh Proxy Service"},
912 {"1829", "Reconnection Configuration"},
913 {"183A", "Insulin Delivery"},
915 /* GATT Declarations */
916 {"2800", "Primary Service Declaration"},
917 {"2801", "Secondary Service Declaration"},
918 {"2802", "Include Declaration"},
919 {"2803", "Characteristic Declaration"},
921 /* GATT Descriptors */
922 {"2900", "Characteristic Extended Properties"},
923 {"2901", "Characteristic User Description"},
924 {"2902", "Client Characteristic Configuration"},
925 {"2903", "Server Characteristic Configuration"},
926 {"2904", "Characteristic Format"},
927 {"2905", "Characteristic Aggregate Formate"},
928 {"2906", "Valid Range"},
929 {"2907", "External Report Reference"},
930 {"2908", "Report Reference"},
932 /* GATT Characteristics */
933 {"2A00", "Device Name"},
934 {"2A01", "Appearance"},
935 {"2A02", "Peripheral Privacy Flag"},
936 {"2A03", "Reconnection Address"},
937 {"2A04", "Peripheral Preferred Connection Parameters"},
938 {"2A05", "Service Changed"},
939 {"2A06", "Alert Level"},
940 {"2A07", "Tx Power Level"},
941 {"2A08", "Date Time"},
942 {"2A09", "Day of Week"},
943 {"2A0A", "Day Date Time"},
944 {"2A11", "Time with DST"},
945 {"2A12", "Time Accuracy"},
946 {"2A13", "Time Source"},
947 {"2A14", "Reference Time Information"},
948 {"2A16", "Time Update Control Point"},
949 {"2A17", "Time Update State"},
950 {"2A18", "Glucose Measurement"},
951 {"2A19", "Battery Level"},
952 {"2A1C", "Temperature Measurement"},
953 {"2A1D", "Temperature Type"},
954 {"2A1E", "Intermediate Temperature"},
955 {"2A21", "Measurement Interval"},
956 {"2A23", "System ID"},
957 {"2A24", "Model Number String"},
958 {"2A25", "Serial Number String"},
959 {"2A26", "Firmware Revision String"},
960 {"2A27", "Hardware Revision String"},
961 {"2A28", "Software Revision String"},
962 {"2A29", "Manufacturer Name String"},
963 {"2A2A", "IEEE 11073-20601 Regulatory Certification Data List"},
964 {"2A2B", "Current Time"},
965 {"2A34", "Glucose Measurement Context"},
966 {"2A35", "Blood Pressure Measurement"},
967 {"2A37", "Heart Rate Measurement"},
968 {"2A38", "Body Sensor Location"},
969 {"2A39", "Heart Rate Control Point"},
970 {"2A3F", "Alert Status"},
971 {"2A46", "New Alert"},
972 {"2A49", "Blood Pressure Feature"},
973 {"2A4A", "HID Information"},
974 {"2A4C", "HID Control Point"},
976 {"2A51", "Glucose Feature"},
977 {"2A52", "Record Access Control Point"},
978 {"2A53", "RSC Measurement"},
979 {"2A54", "RSC Feature"},
980 {"2A55", "SC Control Point"},
983 {"2A5A", "Aggregate"},
984 {"2A5B", "CSC Measurement"},
985 {"2A5C", "CSC Feature"},
986 {"2A5D", "Sensor Location"},
987 {"2A63", "Cycling Power Measurement"},
988 {"2A64", "Cycling Power Vector"},
989 {"2A65", "Cycling Power Feature"},
990 {"2A66", "Cycling Power Control Point"},
991 {"2A67", "Location and Speed"},
992 {"2A68", "Navigation"},
993 {"2A6D", "Pressure"},
994 {"2A6E", "Temperature"},
996 {"2A90", "Last Name"},
997 {"2A91", "Maximum Recommended Heart Rate"},
998 {"2A92", "Resting Heart Rate"},
1000 {"2A9B", "Body Composition Feature"},
1001 {"2A9C", "Body Composition Measurement"},
1002 {"2A9D", "Weight Measurement"},
1003 {"2AA2", "Language"},
1004 {"2AA4", "Bond Management Control Point"},
1005 {"2AA5", "Bond Management Features"},
1006 {"2AA6", "Central Address Resolution"},
1007 {"2AAD", "Indoor Positioning Configuration"},
1008 {"2AB5", "Location Name"},
1010 {"2ABC", "TDS Control Point"},
1011 {"2AC9", "Resolvable Private Address Only"},
1012 {"2ACC", "Fitness Machine Feature"},
1013 {"2ACE", "Cross Trainer Data"},
1014 {"2AD3", "Training Status"},
1015 {"2AD7", "Supported Heart Rate Range"},
1016 {"2AD9", "Fitness Machine Control Point"},
1017 {"2ADA", "Fitness Machine Status"},
1018 {"2B1D", "RC Feature"},
1019 {"2B1E", "RC Settings"},
1020 {"2B1F", "Reconnection Configuration Control Point"},
1022 static uuid_name_s long_uuid_name[LONG_UUID_COUNT] = {
1023 // List should be sorted by UUID
1025 {"1AB7C24D-185A-45B9-90D4-F7AB1A71949A", "Samsung Health Service"},
1026 {"22EAC6E9-24D6-4BB5-BE44-B36ACE7C7BFB", "Data Source"},
1027 {"2F7CABCE-808D-411F-9A0C-BB92BA96C102", "Entity Update"},
1028 {"32D1955A-E5AA-4A96-9A49-08538DA8B8F6", "Samsung Gear Fit Manager Service"},
1029 {"69D1D8F3-45E1-49A8-9821-9BBDFDAAD9D9", "Control Point"},
1030 {"7905F431-B5CE-4E99-A40F-4B1E122D00D0", "Apple Notification Center Service"},
1031 {"89D3502B-0F36-433A-8EF4-C502AD55F8DC", "Apple Media Service"},
1032 {"9A3F68E0-86CE-11E5-A309-0002A5D5C51B", "Samsung Gear Manager Service"},
1033 {"9B3C81D8-57B1-4A8A-B8DF-0E56F7CA51C2", "Remote Command"},
1034 {"9FBF120D-6301-42D9-8C58-25E699A21DBD", "Notifications Source"},
1035 {"A49EB41E-CB06-495C-9F4F-BB80A90CDF00", "Samsung Gear Manager Service"},
1036 {"ADE3D529-C784-4F63-A987-EB69F70EE816", "IoT OIC Service"},
1037 {"C2051EE0-804D-4D50-A12C-15E243852100", "Notifications Source"},
1038 {"C2F2CC0F-C085-4DD4-BE5A-ACA3074BBC72", "Control Point"},
1039 {"C6B2F38C-23AB-46D8-A6AB-A3A870BBD5D7", "Entity Attribute"},
1040 {"CECE518B-28D7-4171-92D5-76A1E249A3B9", "Notifications Source"},
1041 {"FE53FF98-B259-4337-B56A-0EC9F82C6BAD", "Control Point"},
1043 const uuid_name_s *uuid_name = short_uuid_name;
1044 static const char *unknown_name = "Unknown";
1046 int end = SHORT_UUID_COUNT - 1;
1050 if (strlen(uuid) == 36) {
1051 if (!g_ascii_strncasecmp(uuid + 9, "0000-1000-8000-00805F9B34FB", 27))
1056 end = LONG_UUID_COUNT - 1;
1057 uuid_name = long_uuid_name;
1059 } else if (strlen(uuid) >= 8)
1062 while (start <= end) {
1063 p = start + (end - start) / 2;
1064 ret = g_ascii_strncasecmp(uuid + offset, uuid_name[p].uuid, uuid_len);
1066 return uuid_name[p].specification_name;
1073 return unknown_name;
1076 const char *_bt_convert_error_to_string(int error)
1079 case BLUETOOTH_ERROR_CANCEL:
1081 case BLUETOOTH_ERROR_INVALID_PARAM:
1082 return "INVALID_PARAMETER";
1083 case BLUETOOTH_ERROR_INVALID_DATA:
1084 return "INVALID DATA";
1085 case BLUETOOTH_ERROR_MEMORY_ALLOCATION:
1086 case BLUETOOTH_ERROR_OUT_OF_MEMORY:
1087 return "OUT_OF_MEMORY";
1088 case BLUETOOTH_ERROR_TIMEOUT:
1090 case BLUETOOTH_ERROR_NO_RESOURCES:
1091 return "NO_RESOURCES";
1092 case BLUETOOTH_ERROR_INTERNAL:
1094 case BLUETOOTH_ERROR_NOT_SUPPORT:
1095 return "NOT_SUPPORT";
1096 case BLUETOOTH_ERROR_DEVICE_NOT_ENABLED:
1097 return "NOT_ENABLED";
1098 case BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED:
1099 return "ALREADY_ENABLED";
1100 case BLUETOOTH_ERROR_DEVICE_BUSY:
1101 return "DEVICE_BUSY";
1102 case BLUETOOTH_ERROR_ACCESS_DENIED:
1103 return "ACCESS_DENIED";
1104 case BLUETOOTH_ERROR_MAX_CLIENT:
1105 return "MAX_CLIENT";
1106 case BLUETOOTH_ERROR_NOT_FOUND:
1108 case BLUETOOTH_ERROR_SERVICE_SEARCH_ERROR:
1109 return "SERVICE_SEARCH_ERROR";
1110 case BLUETOOTH_ERROR_PARING_FAILED:
1111 return "PARING_FAILED";
1112 case BLUETOOTH_ERROR_NOT_PAIRED:
1113 return "NOT_PAIRED";
1114 case BLUETOOTH_ERROR_SERVICE_NOT_FOUND:
1115 return "SERVICE_NOT_FOUND";
1116 case BLUETOOTH_ERROR_NOT_CONNECTED:
1117 return "NOT_CONNECTED";
1118 case BLUETOOTH_ERROR_ALREADY_CONNECT:
1119 return "ALREADY_CONNECT";
1120 case BLUETOOTH_ERROR_CONNECTION_BUSY:
1121 return "CONNECTION_BUSY";
1122 case BLUETOOTH_ERROR_CONNECTION_ERROR:
1123 return "CONNECTION_ERROR";
1124 case BLUETOOTH_ERROR_MAX_CONNECTION:
1125 return "MAX_CONNECTION";
1126 case BLUETOOTH_ERROR_NOT_IN_OPERATION:
1127 return "NOT_IN_OPERATION";
1128 case BLUETOOTH_ERROR_CANCEL_BY_USER:
1129 return "CANCEL_BY_USER";
1130 case BLUETOOTH_ERROR_REGISTRATION_FAILED:
1131 return "REGISTRATION_FAILED";
1132 case BLUETOOTH_ERROR_IN_PROGRESS:
1133 return "IN_PROGRESS";
1134 case BLUETOOTH_ERROR_AUTHENTICATION_FAILED:
1135 return "AUTHENTICATION_FAILED";
1136 case BLUETOOTH_ERROR_HOST_DOWN:
1138 case BLUETOOTH_ERROR_END_OF_DEVICE_LIST:
1139 return "END_OF_DEVICE_LIST";
1140 case BLUETOOTH_ERROR_AGENT_ALREADY_EXIST:
1141 return "AGENT_ALREADY_EXIST";
1142 case BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST:
1143 return "AGENT_DOES_NOT_EXIST";
1144 case BLUETOOTH_ERROR_ALREADY_INITIALIZED:
1145 return "ALREADY_INITIALIZED";
1146 case BLUETOOTH_ERROR_PERMISSION_DEINED:
1147 return "PERMISSION_DEINED";
1148 case BLUETOOTH_ERROR_ALREADY_DEACTIVATED:
1149 return "ALREADY_DEACTIVATED";
1150 case BLUETOOTH_ERROR_NOT_INITIALIZED:
1151 return "NOT_INITIALIZED";
1157 const char * _bt_convert_disc_reason_to_string(int reason)
1163 return "Connection terminated by local host";
1165 return "Remote user terminated connection";
1173 void _bt_logging_connection(gboolean connect, int addr_type)
1175 static int le_conn = 0;
1176 static int le_disc = 0;
1177 static int edr_conn = 0;
1178 static int edr_disc = 0;
1192 BT_INFO("[PM] Number of LE conn: %d disc: %d, Number of BR/EDR conn: %d disc: %d",
1193 le_conn, le_disc, edr_conn, edr_disc);
1196 int _bt_eventsystem_set_value(const char *event, const char *key, const char *value)
1201 b = bundle_create();
1203 bundle_add_str(b, key, value);
1205 ret = eventsystem_send_system_event(event, b);
1207 BT_DBG("eventsystem_send_system_event result: %d", ret);
1214 void _bt_swap_byte_ordering(char *data, int data_len)
1219 ret_if(data == NULL);
1220 /* Swap to opposite endian */
1221 for (i = 0, j = data_len - 1; i < data_len; i++, j--) {
1228 int _bt_byte_arr_cmp(const char *data1, const char *data2, int data_len)
1232 retv_if(data1 == NULL, -1);
1233 retv_if(data2 == NULL, -1);
1234 for (i = 0; i < data_len; i++) {
1235 if (data1[i] != data2[i])
1236 return data1[i] - data2[i];
1240 int _bt_byte_arr_cmp_with_mask(const char *data1, const char *data2,
1241 const char *mask, int data_len)
1246 retv_if(data1 == NULL, -1);
1247 retv_if(data2 == NULL, -1);
1248 retv_if(mask == NULL, -1);
1249 for (i = 0; i < data_len; i++) {
1250 a = data1[i] & mask[i];
1251 b = data2[i] & mask[i];
1253 return (int)(a - b);
1258 void _bt_copy_remote_dev(bt_remote_dev_info_t *dev_info, remote_device_t *oal_device)
1262 dev_info->address = g_new0(char, BT_ADDRESS_STRING_SIZE);
1263 _bt_convert_addr_type_to_string(dev_info->address, oal_device->address.addr);
1265 if (strlen(oal_device->name) == 0)
1266 dev_info->name = NULL;
1268 dev_info->name = g_strdup(oal_device->name);
1269 _bt_truncate_non_utf8_chars(dev_info->name);
1272 if (strlen(oal_device->alias) == 0) {
1273 dev_info->alias = NULL;
1275 dev_info->alias = g_strdup(oal_device->alias);
1276 _bt_truncate_non_utf8_chars(dev_info->alias);
1277 BT_INFO("Alias [%s]", dev_info->alias);
1280 dev_info->class = oal_device->cod;
1281 dev_info->paired = oal_device->is_bonded;
1282 dev_info->connected = oal_device->is_connected;
1283 dev_info->rssi = oal_device->rssi;
1284 dev_info->addr_type = oal_device->type;
1285 dev_info->uuid_count = oal_device->uuid_count;
1286 BT_INFO("UUID Count [%d]", dev_info->uuid_count);
1287 dev_info->trust = ((oal_device->is_trusted == 0) ? FALSE : TRUE);
1289 BT_DBG("[%s] link type [0x%x] name [%s] bonded [%d]", dev_info->address,
1290 dev_info->connected, dev_info->name, dev_info->paired);
1292 if (dev_info->uuid_count > 0)
1293 dev_info->uuids = g_new0(char *, dev_info->uuid_count);
1295 /* Fill Remote Device Service List list */
1296 for (i = 0; i < dev_info->uuid_count; i++) {
1297 dev_info->uuids[i] = g_malloc0(BLUETOOTH_UUID_STRING_MAX);
1298 _bt_uuid_to_string((service_uuid_t *)&oal_device->uuid[i].uuid, dev_info->uuids[i]);
1301 dev_info->vid = (unsigned short)oal_device->vid;
1302 dev_info->pid = (unsigned short)oal_device->pid;
1303 dev_info->device_type = (int)oal_device->type;
1304 dev_info->is_alias_set = ((oal_device->is_alias_set == 0) ? FALSE : TRUE);
1308 void _bt_free_remote_dev(bt_remote_dev_info_t *dev_info)
1312 ret_if(NULL == dev_info);
1314 g_free(dev_info->address);
1315 g_free(dev_info->name);
1316 g_free(dev_info->alias);
1317 g_free(dev_info->manufacturer_data);
1319 for (c = 0; c < dev_info->uuid_count; c++)
1320 g_free(dev_info->uuids[c]);
1321 g_free(dev_info->uuids);
1326 void _bt_free_paired_dev(void *paired_info)
1328 bt_remote_dev_info_t* dev_info = (bt_remote_dev_info_t*) paired_info;
1331 ret_if(NULL == dev_info);
1333 g_free(dev_info->address);
1334 g_free(dev_info->name);
1335 g_free(dev_info->alias);
1336 g_free(dev_info->manufacturer_data);
1338 for (c = 0; c < dev_info->uuid_count; c++)
1339 g_free(dev_info->uuids[c]);
1340 g_free(dev_info->uuids);
1344 static void __bt_get_service_list(bt_remote_dev_info_t *info, bluetooth_device_info_t *dev)
1350 ret_if(info == NULL);
1351 ret_if(dev == NULL);
1353 uuids = info->uuids;
1354 if (uuids == NULL) {
1355 BT_ERR("No UUID's");
1359 dev->service_index = 0;
1360 BT_DBG("Total UUID count [%d]", info->uuid_count);
1361 for (i = 0; i < info->uuid_count; i++) {
1362 g_strlcpy(dev->uuids[i], uuids[i], BLUETOOTH_UUID_STRING_MAX);
1364 parts = g_strsplit(uuids[i], "-", -1);
1366 if (parts == NULL || parts[0] == NULL)
1369 dev->service_list_array[i] = g_ascii_strtoull(parts[0], NULL, 16);
1372 dev->service_index++;
1377 void _bt_copy_remote_device(bt_remote_dev_info_t *rem_dev, bluetooth_device_info_t *dev)
1379 memset(dev, 0x00, sizeof(bluetooth_device_info_t));
1380 __bt_get_service_list(rem_dev, dev);
1381 _bt_convert_addr_string_to_type(dev->device_address.addr, rem_dev->address);
1382 _bt_divide_device_class(&dev->device_class, rem_dev->class);
1384 if (rem_dev->alias) {
1385 g_strlcpy(dev->device_name.name, rem_dev->alias,
1386 BLUETOOTH_DEVICE_NAME_LENGTH_MAX + 1);
1387 BT_DBG("Name: %s", dev->device_name.name);
1389 g_strlcpy(dev->device_name.name, rem_dev->name,
1390 BLUETOOTH_DEVICE_NAME_LENGTH_MAX + 1);
1391 BT_DBG("Name: %s", dev->device_name.name);
1394 dev->rssi = rem_dev->rssi;
1395 dev->trust = rem_dev->trust;
1396 dev->paired = rem_dev->paired;
1397 dev->connected = rem_dev->connected;
1398 dev->is_alias_set = rem_dev->is_alias_set;
1400 /* Fill Manufacturer data */
1401 if (rem_dev->manufacturer_data_len > 0) {
1402 dev->manufacturer_data.data_len = rem_dev->manufacturer_data_len;
1403 memcpy(dev->manufacturer_data.data,
1404 rem_dev->manufacturer_data, rem_dev->manufacturer_data_len);
1406 dev->manufacturer_data.data_len = 0;
1411 void _bt_service_print_dev_info(bluetooth_device_info_t *dev_info)
1415 ret_if(dev_info == NULL);
1417 _bt_print_device_address_t(&(dev_info->device_address));
1418 BT_INFO("Device Name:[%s]", dev_info->device_name.name);
1419 BT_INFO("Device Major Class:[0x%X]", dev_info->device_class.major_class);
1420 BT_INFO("Device Minor Class:[0x%X]", dev_info->device_class.minor_class);
1421 BT_INFO("Device Service Class:[0x%X]", dev_info->device_class.minor_class);
1422 BT_INFO("Device Paired:[%s]", (dev_info->paired ? "TRUE" : "FALSE"));
1423 BT_INFO("Device Trusted:[%s]", (dev_info->trust ? "TRUE" : "FALSE"));
1424 BT_INFO("Device Connected:[%d]", dev_info->connected);
1425 BT_INFO("Device Service index:[%d]", dev_info->service_index);
1426 for (i = 0; i < dev_info->service_index; i++) {
1427 BT_INFO("Device Service List:[%d]", dev_info->service_list_array[i]);
1428 BT_INFO("Device UUID:[%s]", dev_info->uuids[i]);
1431 BT_INFO("Device manufacturer data len:[%d]", dev_info->manufacturer_data.data_len);
1432 for (i = 0; i < dev_info->manufacturer_data.data_len; i++)
1433 BT_INFO("%2.2X", dev_info->manufacturer_data.data[i]);
1436 void _bt_uuid_to_string(service_uuid_t *p_uuid, char *str)
1438 uint32_t uuid0, uuid4;
1439 uint16_t uuid1, uuid2, uuid3, uuid5;
1441 memcpy(&uuid0, &(p_uuid->uuid[0]), 4);
1442 memcpy(&uuid1, &(p_uuid->uuid[4]), 2);
1443 memcpy(&uuid2, &(p_uuid->uuid[6]), 2);
1444 memcpy(&uuid3, &(p_uuid->uuid[8]), 2);
1445 memcpy(&uuid4, &(p_uuid->uuid[10]), 4);
1446 memcpy(&uuid5, &(p_uuid->uuid[14]), 2);
1448 snprintf((char *)str, BLUETOOTH_UUID_STRING_MAX, "%.8x-%.4x-%.4x-%.4x-%.8x%.4x",
1449 ntohl(uuid0), ntohs(uuid1),
1450 ntohs(uuid2), ntohs(uuid3),
1451 ntohl(uuid4), ntohs(uuid5));
1455 void _bt_string_to_uuid(char *str, service_uuid_t *p_uuid)
1457 uint32_t uuid0, uuid4;
1458 uint16_t uuid1, uuid2, uuid3, uuid5;
1460 sscanf(str, "%08x-%04hx-%04hx-%04hx-%08x%04hx",
1461 &uuid0, &uuid1, &uuid2, &uuid3, &uuid4, &uuid5);
1463 uuid0 = htonl(uuid0);
1464 uuid1 = htons(uuid1);
1465 uuid2 = htons(uuid2);
1466 uuid3 = htons(uuid3);
1467 uuid4 = htonl(uuid4);
1468 uuid5 = htons(uuid5);
1470 memcpy(&(p_uuid->uuid[0]), &uuid0, 4);
1471 memcpy(&(p_uuid->uuid[4]), &uuid1, 2);
1472 memcpy(&(p_uuid->uuid[6]), &uuid2, 2);
1473 memcpy(&(p_uuid->uuid[8]), &uuid3, 2);
1474 memcpy(&(p_uuid->uuid[10]), &uuid4, 4);
1475 memcpy(&(p_uuid->uuid[14]), &uuid5, 2);
1480 void _bt_convert_byte_ordering(char *data, int data_len,
1481 char *converted_data)
1484 char temp[BT_UUID_LEN];
1486 memcpy(&temp, data, data_len);
1487 for (i = 0, j = data_len - 1; i < data_len; i++, j--)
1488 converted_data[i] = temp[j];
1492 /* Trim string at first non-utf8 char */
1493 void _bt_truncate_non_utf8_chars(char * str)
1496 const char *ptr = NULL;
1498 if (strlen(str) != 0) {
1499 if (!g_utf8_validate(str, -1, &ptr)) {
1500 while (*(str + i) != *ptr)
1507 invocation_info_t* _bt_get_request_info_data(int service_function, char *address)
1510 invocation_info_t *req_info = NULL;
1512 retv_if(NULL == address, NULL);
1514 /* Get method invocation context */
1515 for (l = _bt_get_invocation_list(); l != NULL; l = g_slist_next(l)) {
1517 if (req_info == NULL || req_info->service_function != service_function)
1520 if (!strncasecmp((char *)req_info->user_data, address, BT_ADDRESS_STRING_SIZE))
1527 #ifdef TIZEN_GATT_CLIENT
1528 invocation_info_t* _bt_get_request_info_data_from_function_name(int service_function)
1531 invocation_info_t *req_info = NULL;
1533 /* Get method invocation context */
1534 for (l = _bt_get_invocation_list(); l != NULL; l = g_slist_next(l)) {
1536 if (req_info == NULL || req_info->service_function != service_function)
1541 BT_DBG("Not existed");
1546 void _bt_set_device_values(gboolean connected, int state)
1548 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
1550 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
1551 BT_ERR("vconf_get_int failed");
1553 if (connected == TRUE)
1554 bt_device_state |= state;
1555 else if (bt_device_state & state)
1556 bt_device_state ^= state;
1558 if (vconf_set_int(VCONFKEY_BT_DEVICE, bt_device_state) != 0)
1559 BT_ERR("vconf_set_int failed");
1562 #ifdef TIZEN_FEATURE_READOUT_NOTIFICATION
1563 void _bt_set_readout_notification_of_tts(void)
1567 if (vconf_get_int(VCONFKEY_TTS_SETTING_NOTIFICATION_TTS, &tts_setting) != 0) {
1568 BT_ERR("vconf_get_int failed");
1572 BT_DBG("current value[%d]", tts_setting);
1574 if (tts_setting == -1)
1575 if (vconf_set_int(VCONFKEY_TTS_SETTING_NOTIFICATION_TTS, -1) != 0)
1576 BT_ERR("vconf_set_int failed");
1580 int _bt_get_ad_data_by_type(char *in_data, int in_len,
1581 char in_type, char **data, int *data_len)
1583 if (in_data == NULL || data == NULL || data_len == NULL)
1584 return BLUETOOTH_ERROR_INVALID_PARAM;
1587 return BLUETOOTH_ERROR_INVALID_PARAM;
1593 for (i = 0; i < in_len; i++) {
1595 if (len <= 0 || i + 1 >= in_len) {
1596 BT_ERR("Invalid advertising data");
1597 return BLUETOOTH_ERROR_INVALID_PARAM;
1600 type = in_data[i + 1];
1601 if (type == in_type) {
1611 if (i + len > in_len) {
1612 BT_ERR("Invalid advertising data");
1613 return BLUETOOTH_ERROR_INVALID_PARAM;
1614 } else if (len == 0) {
1615 BT_INFO("AD Type 0x%02x data is not set", in_type);
1618 return BLUETOOTH_ERROR_NONE;
1621 *data = g_memdup(&in_data[i], len);
1623 return BLUETOOTH_ERROR_OUT_OF_MEMORY;
1626 return BLUETOOTH_ERROR_NONE;
1629 void _bt_copy_remote_dev_info(bt_remote_dev_info_t *dest, bt_remote_dev_info_t *src)
1631 ret_if(NULL == src);
1633 if (!dest->address) {
1634 dest->address = g_strdup(src->address);
1639 dest->name = g_strdup(src->name);
1643 g_free(dest->alias);
1644 dest->alias = g_strdup(src->alias);
1647 if (src->uuid_count > 0 && src->uuids) {
1650 /* Release previously allocated UUIDs */
1651 if (dest->uuid_count > 0 && dest->uuids)
1652 for (i = 0; i < dest->uuid_count; i++)
1653 g_free(dest->uuids[i]);
1654 g_free(dest->uuids);
1656 /* Copy new UUID list */
1657 dest->uuids = g_malloc0(src->uuid_count * sizeof(char *));
1658 for (i = 0; i < src->uuid_count; i++)
1659 dest->uuids[i] = g_strdup(src->uuids[i]);
1661 dest->uuid_count = src->uuid_count;
1664 if (src->manufacturer_data_len > 0 && src->manufacturer_data) {
1665 if (dest->manufacturer_data)
1666 g_free(dest->manufacturer_data);
1668 dest->manufacturer_data_len = src->manufacturer_data_len;
1669 dest->manufacturer_data = g_memdup(
1670 src->manufacturer_data, src->manufacturer_data_len);
1673 dest->rssi = src->rssi;
1674 dest->class = src->class;
1675 dest->paired = src->paired;
1676 dest->connected = src->connected;
1677 dest->trust = src->trust;
1678 dest->addr_type = src->addr_type;
1679 dest->vid = src->vid;
1680 dest->pid = src->pid;
1681 dest->device_type = src->device_type;
1682 dest->is_alias_set = src->is_alias_set;
1686 #define BT_PERMANENT_LOG_FILE_PATH "/opt/usr/home/owner/media/Downloads/.bt_dump/permanent_log.txt"
1687 #define BT_PERMANENT_LOG_OLD_FILE_PATH "/opt/usr/home/owner/media/Downloads/.bt_dump/permanent_log_old.txt"
1688 #define BT_PERMANENT_LOG_FIRMWARE_DIR_PATH "/usr/lib/firmware"
1689 #define PERMANENT_LOG_MAX (128 * 1024)
1691 static void __bt_write_firmware_name(FILE *fp)
1694 struct dirent *pEntry;
1696 pDir = opendir(BT_PERMANENT_LOG_FIRMWARE_DIR_PATH);
1698 BT_ERR("Read directory failed");
1702 pEntry = readdir(pDir);
1704 if (!strncmp(pEntry->d_name, "BCM", 3))
1705 fprintf(fp, "BTFW: %s\n", pEntry->d_name);
1706 pEntry = readdir(pDir);
1711 void _bt_permanent_log(const char *fmt, ...)
1719 gboolean is_first = FALSE;
1721 #ifndef TIZEN_FEATURE_BT_PERMANENT_LOG
1727 strftime(time_buf, sizeof(time_buf), "%m-%d %H:%M:%S", lt);
1729 fp = fopen(BT_PERMANENT_LOG_FILE_PATH, "r");
1731 fseek(fp, 0, SEEK_END);
1735 if (lsize > PERMANENT_LOG_MAX) {
1738 fp2 = fopen(BT_PERMANENT_LOG_OLD_FILE_PATH, "w");
1741 fseek(fp, 0, SEEK_SET);
1743 character = fgetc(fp);
1744 fputc(character, fp2);
1748 fp = fopen(BT_PERMANENT_LOG_FILE_PATH, "w");
1755 fp = fopen(BT_PERMANENT_LOG_FILE_PATH, "a");
1760 if (is_first == TRUE)
1761 __bt_write_firmware_name(fp);
1764 vsnprintf(buf, 100, fmt, ap);
1766 fprintf(fp, "%s %s\n", time_buf, buf);