From: DoHyun Pyun Date: Fri, 4 Aug 2017 06:38:13 +0000 (+0900) Subject: Apply tizen 3.0 based product patchsets X-Git-Tag: accepted/tizen/unified/20170808.171414^0 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git;a=commitdiff_plain;h=5a7a8022285f9381eb8c7c7fba3a9977651c0e1b Apply tizen 3.0 based product patchsets -------------------------------------------------- commit a049ded240d77ce4c14bda87796c4d3b06764270 Author: Sreeraj Mohan Kottapuzhackal Date: Mon Jul 24 13:16:05 2017 +0530 Fix for crash while pairing device -------------------------------------------------- Change-Id: I2206a657cddc27f8bca3d9ce7fffff4bf81be953 Signed-off-by: DoHyun Pyun --- diff --git a/bt-api/bt-adapter-le.c b/bt-api/bt-adapter-le.c index 018db76..989d2d4 100644 --- a/bt-api/bt-adapter-le.c +++ b/bt-api/bt-adapter-le.c @@ -268,7 +268,7 @@ gboolean __bluetooth_is_privileged_process(void) BT_EXPORT_API int bluetooth_set_advertising(int handle, gboolean enable) { int result; - gboolean use_reserved_slot = FALSE; + gboolean use_reserved_slot = TRUE; BT_CHECK_ENABLED_ANY(return); @@ -294,7 +294,7 @@ BT_EXPORT_API int bluetooth_set_custom_advertising(int handle, gboolean enable, bluetooth_advertising_params_t *params) { int result; - gboolean use_reserved_slot = FALSE; + gboolean use_reserved_slot = TRUE; BT_CHECK_ENABLED_ANY(return); @@ -348,7 +348,7 @@ BT_EXPORT_API int bluetooth_get_advertising_data(bluetooth_advertising_data_t *a BT_EXPORT_API int bluetooth_set_advertising_data(int handle, const bluetooth_advertising_data_t *value, int length) { int result; - gboolean use_reserved_slot = FALSE; + gboolean use_reserved_slot = TRUE; BT_CHECK_PARAMETER(value, return); BT_CHECK_ENABLED_ANY(return); @@ -407,7 +407,7 @@ BT_EXPORT_API int bluetooth_set_scan_response_data(int handle, const bluetooth_scan_resp_data_t *value, int length) { int result; - gboolean use_reserved_slot = FALSE; + gboolean use_reserved_slot = TRUE; BT_CHECK_PARAMETER(value, return); BT_CHECK_ENABLED_ANY(return); diff --git a/bt-api/bt-common.c b/bt-api/bt-common.c index 3e61585..a846c80 100644 --- a/bt-api/bt-common.c +++ b/bt-api/bt-common.c @@ -217,8 +217,7 @@ void _bt_divide_device_class(bluetooth_device_class_t *device_class, } } -void _bt_convert_addr_string_to_type(unsigned char *addr, - const char *address) +void _bt_convert_addr_string_to_type(unsigned char *addr, const char *address) { int i; char *ptr = NULL; @@ -237,8 +236,7 @@ void _bt_convert_addr_string_to_type(unsigned char *addr, } } -void _bt_convert_addr_string_to_secure_string(char *addr, - const char *address) +void _bt_convert_addr_string_to_secure_string(char *addr, const char *address) { int len; @@ -256,8 +254,7 @@ void _bt_convert_addr_string_to_secure_string(char *addr, return; } -void _bt_convert_addr_type_to_string(char *address, - unsigned char *addr) +void _bt_convert_addr_type_to_string(char *address, unsigned char *addr) { ret_if(address == NULL); ret_if(addr == NULL); @@ -268,6 +265,16 @@ void _bt_convert_addr_type_to_string(char *address, addr[3], addr[4], addr[5]); } +void _bt_convert_addr_type_to_secure_string(char *address, unsigned char *addr) +{ + ret_if(address == NULL); + ret_if(addr == NULL); + + g_snprintf(address, BT_ADDRESS_STRING_SIZE, + "%2.2X:%2.2X:%2.2X:%2.2X:XX:XX", + addr[0], addr[1], addr[2], addr[3]); +} + const char *_bt_convert_error_to_string(int error) { switch (error) { @@ -671,7 +678,6 @@ static GDBusConnection *gconn; static int latest_id = -1; #define BT_RFCOMM_ID_MAX 245 static gboolean id_used[BT_RFCOMM_ID_MAX]; -GDBusNodeInfo *new_conn_node; static const gchar rfcomm_agent_xml[] = "" @@ -882,6 +888,7 @@ void _bt_unregister_gdbus(int object_id) int _bt_register_new_conn(const char *path, bt_new_connection_cb cb) { GDBusConnection *gconn; + GDBusNodeInfo *node_info; int id; GError *error = NULL; @@ -889,16 +896,15 @@ int _bt_register_new_conn(const char *path, bt_new_connection_cb cb) if (gconn == NULL) return -1; - if (new_conn_node == NULL) - new_conn_node = _bt_get_gdbus_node(rfcomm_agent_xml); - - if (new_conn_node == NULL) + node_info = _bt_get_gdbus_node(rfcomm_agent_xml); + if (node_info == NULL) return -1; id = g_dbus_connection_register_object(gconn, path, - new_conn_node->interfaces[0], + node_info->interfaces[0], &method_table, cb, NULL, &error); + g_dbus_node_info_unref(node_info); if (id == 0) { BT_ERR("Failed to register: %s", error->message); g_error_free(error); @@ -982,6 +988,7 @@ fail: int _bt_register_new_conn_ex(const char *path, const char *bus_name, bt_new_connection_cb cb) { GDBusConnection *gconn; + GDBusNodeInfo *node_info; int id; GError *error = NULL; @@ -989,16 +996,16 @@ int _bt_register_new_conn_ex(const char *path, const char *bus_name, bt_new_conn if (gconn == NULL) return -1; - if (new_conn_node == NULL) - new_conn_node = _bt_get_gdbus_node_ex(rfcomm_agent_xml, bus_name); + node_info = _bt_get_gdbus_node_ex(rfcomm_agent_xml, bus_name); - if (new_conn_node == NULL) + if (node_info == NULL) return -1; id = g_dbus_connection_register_object(gconn, path, - new_conn_node->interfaces[0], + node_info->interfaces[0], &method_table, cb, NULL, &error); + g_dbus_node_info_unref(node_info); if (id == 0) { BT_ERR("Failed to register: %s", error->message); g_error_free(error); @@ -1453,6 +1460,9 @@ int _bt_discover_service_uuids(char *address, char *remote_uuid) proxy = g_dbus_proxy_new_sync(gconn, G_DBUS_PROXY_FLAGS_NONE, NULL, BT_BLUEZ_NAME, object_path, BT_PROPERTIES_INTERFACE, NULL, &err); + + g_free(object_path); + retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL); if (err) { BT_ERR("DBus Error: [%s]", err->message); @@ -1533,6 +1543,9 @@ int _bt_get_cod_by_address(char *address, bluetooth_device_class_t *dev_class) proxy = g_dbus_proxy_new_sync(gconn, G_DBUS_PROXY_FLAGS_NONE, NULL, BT_BLUEZ_NAME, object_path, BT_PROPERTIES_INTERFACE, NULL, &err); + + g_free(object_path); + retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL); if (err) { BT_ERR("DBus Error: [%s]", err->message); @@ -1621,6 +1634,30 @@ int _bt_disconnect_profile(char *address, char *uuid, void *cb, return BLUETOOTH_ERROR_NONE; } +int _bt_disconnect_ext_profile(char *address, char *path) +{ + GDBusProxy *proxy; + char *object_path; + + object_path = _bt_get_device_object_path(address); + if (object_path == NULL) + return BLUETOOTH_ERROR_INTERNAL; + + proxy = __bt_gdbus_get_device_proxy(object_path); + g_free(object_path); + if (proxy == NULL) { + BT_ERR("Error while getting proxy"); + return BLUETOOTH_ERROR_INTERNAL; + } + + g_dbus_proxy_call(proxy, "DisconnectExtProfile", + g_variant_new("(o)", path), + G_DBUS_CALL_FLAGS_NONE, + DBUS_TIMEOUT, NULL, NULL, NULL); + BT_DBG("-"); + return BLUETOOTH_ERROR_NONE; +} + int _bt_get_adapter_path(GDBusConnection *conn, char *path) { GError *err = NULL; @@ -1689,6 +1726,35 @@ fail: } +void _bt_convert_device_path_to_addr_type(const char *device_path, + unsigned char *addr) +{ + char *dev_addr; + char address[BT_ADDRESS_STRING_SIZE] = { 0 }; + int i; + char *addr_ptr = address; + char *ptr = NULL; + + ret_if(device_path == NULL); + ret_if(addr == NULL); + + dev_addr = strstr(device_path, "dev_"); + if (dev_addr != NULL) { + dev_addr += 4; + g_strlcpy(addr_ptr, dev_addr, BT_ADDRESS_STRING_SIZE); + + for (i = 0; i < BT_ADDRESS_LENGTH_MAX; i++) { + addr[i] = strtol(addr_ptr, &ptr, 16); + if (ptr[0] != '\0') { + if (ptr[0] != '_') + return; + + addr_ptr = ptr + 1; + } + } + } +} + void _bt_convert_device_path_to_address(const char *device_path, char *device_address) { diff --git a/bt-api/bt-event-handler.c b/bt-api/bt-event-handler.c index c0f8016..141c706 100644 --- a/bt-api/bt-event-handler.c +++ b/bt-api/bt-event-handler.c @@ -45,10 +45,10 @@ typedef struct { static int obex_server_id; static guint disable_timer_id; static gboolean is_initialized; -static GSList *sending_list = NULL; -static GSList *server_list = NULL; -static GSList *event_list = NULL; -static int owner_sig_id = -1; +static GSList *sending_list; +static GSList *server_list; +static GSList *event_list; +static guint owner_sig_id; void _bt_add_push_request_id(int request_id) { @@ -2908,6 +2908,7 @@ static void __bt_tds_event_filter(GDBusConnection *connection, } buffer = (char *) g_variant_get_data(byte_var); memcpy(act_req.tds_data.data, buffer, act_req.tds_data.length); + g_variant_unref(byte_var); _bt_convert_addr_string_to_type(act_req.rem_addr.addr, address); @@ -2988,6 +2989,7 @@ static void __bt_tds_event_filter(GDBusConnection *connection, buffer = (char *) g_variant_get_data(byte_var); memcpy(ind_res.tds_data.data, buffer, ind_res.tds_data.length); + g_free(buffer); _bt_convert_addr_string_to_type(ind_res.rem_addr.addr, address); @@ -3513,10 +3515,10 @@ void _bt_unregister_name_owner_changed(void) GDBusConnection *connection_type; connection_type = _bt_gdbus_get_system_gconn(); - if (connection_type != NULL && owner_sig_id != -1) { + if (connection_type != NULL && owner_sig_id > 0) { g_dbus_connection_signal_unsubscribe(connection_type, owner_sig_id); - owner_sig_id = -1; + owner_sig_id = 0; } } @@ -3532,77 +3534,68 @@ static void __bt_manager_event_filter(GDBusConnection *connection, GVariantIter *interface_iter = NULL; char *interface_str = NULL; bt_gatt_service_change_t change; - char address[BT_ADDRESS_STRING_SIZE] = { 0 }; char secure_address[BT_ADDRESS_STRING_SIZE] = { 0 }; bt_user_info_t *user_info = NULL; + user_info = _bt_get_user_data(BT_COMMON); + if (user_info == NULL) { + BT_ERR("There is no registered common event callback"); + return; + } + if (strcasecmp(signal_name, "GattServiceAdded") == 0) { g_variant_get(parameters, "(&s)", &path); - _bt_convert_device_path_to_address(path, address); - _bt_convert_addr_string_to_type(change.device_addr.addr, address); - _bt_convert_addr_string_to_secure_string(secure_address, address); + _bt_convert_device_path_to_addr_type(path, change.device_addr.addr); + _bt_convert_addr_type_to_secure_string(secure_address, + change.device_addr.addr); if (_bluetooth_gatt_check_service_change_watcher_address(&change.device_addr) == FALSE) { BT_INFO("GATT Service [%s] added, but no watcher for %s", - path, secure_address); + path, secure_address); return; } else BT_INFO(" ### GATT Service added [%s] [%s]", - path, secure_address); + path, secure_address); change.svc_path = g_strdup(path); change.change_type = BLUETOOTH_GATT_SERVICE_CHANGE_TYPE_ADD; - - user_info = _bt_get_user_data(BT_COMMON); - if (user_info != NULL) { - _bt_common_event_cb( - BLUETOOTH_EVENT_GATT_CLIENT_SERVICE_CHANGED, - BLUETOOTH_ERROR_NONE, &change, - user_info->cb, user_info->user_data); - } - + _bt_common_event_cb(BLUETOOTH_EVENT_GATT_CLIENT_SERVICE_CHANGED, + BLUETOOTH_ERROR_NONE, &change, + user_info->cb, user_info->user_data); g_free(change.svc_path); } else if (strcasecmp(signal_name, "InterfacesRemoved") == 0) { - g_variant_get(parameters, "(&oas)", - &path, &interface_iter); - + g_variant_get(parameters, "(&oas)", &path, &interface_iter); if (!path) { BT_ERR("Invalid adapter path"); + g_variant_iter_free(interface_iter); return; } - _bt_convert_device_path_to_address(path, address); - _bt_convert_addr_string_to_type(change.device_addr.addr, address); - _bt_convert_addr_string_to_secure_string(secure_address, address); - - if (_bluetooth_gatt_check_service_change_watcher_address(&change.device_addr) - == FALSE) { - BT_INFO("GATT Service [%s] removed, but no watcher for %s", - path, secure_address); + _bt_convert_device_path_to_addr_type(path, change.device_addr.addr); + if (!_bluetooth_gatt_check_service_change_watcher_address(&change.device_addr)) { + g_variant_iter_free(interface_iter); return; } - while (g_variant_iter_loop(interface_iter, "s", &interface_str)) { - if (g_strcmp0(interface_str, GATT_SERV_INTERFACE) == 0) { - change.svc_path = g_strdup(path); - change.change_type = BLUETOOTH_GATT_SERVICE_CHANGE_TYPE_REMOVE; - - BT_INFO(" ### GATT Service removed [%s] [%s]", - path, secure_address); + while (g_variant_iter_loop(interface_iter, "&s", &interface_str)) { + if (g_strcmp0(interface_str, GATT_SERV_INTERFACE) != 0) + continue; - user_info = _bt_get_user_data(BT_COMMON); - if (user_info != NULL) { - _bt_common_event_cb( - BLUETOOTH_EVENT_GATT_CLIENT_SERVICE_CHANGED, - BLUETOOTH_ERROR_NONE, &change, - user_info->cb, user_info->user_data); - } + _bt_convert_addr_type_to_secure_string(secure_address, + change.device_addr.addr); + BT_INFO(" ### GATT Service removed [%s] [%s]", + path, secure_address); - g_free(change.svc_path); - break; - } + change.svc_path = g_strdup(path); + change.change_type = BLUETOOTH_GATT_SERVICE_CHANGE_TYPE_REMOVE; + _bt_common_event_cb( + BLUETOOTH_EVENT_GATT_CLIENT_SERVICE_CHANGED, + BLUETOOTH_ERROR_NONE, &change, + user_info->cb, user_info->user_data); + g_free(change.svc_path); + break; } g_variant_iter_free(interface_iter); } @@ -3611,22 +3604,22 @@ static void __bt_manager_event_filter(GDBusConnection *connection, int _bt_register_manager_subscribe_signal(gboolean subscribe) { GDBusConnection *g_conn; - static int service_added_id = -1; - static int interface_removed_id = -1; + static guint service_added_id = 0; + static guint interface_removed_id = 0; g_conn = _bt_gdbus_get_system_gconn(); if (g_conn == NULL) return BLUETOOTH_ERROR_INTERNAL; if (subscribe == TRUE) { - if (service_added_id == -1) { + if (service_added_id == 0) { service_added_id = g_dbus_connection_signal_subscribe(g_conn, NULL, GATT_SERV_INTERFACE, "GattServiceAdded", NULL, NULL, 0, __bt_manager_event_filter, NULL, NULL); } - if (interface_removed_id == -1) { + if (interface_removed_id == 0) { interface_removed_id = g_dbus_connection_signal_subscribe(g_conn, NULL, BT_MANAGER_INTERFACE, "InterfacesRemoved", NULL, NULL, 0, @@ -3634,15 +3627,15 @@ int _bt_register_manager_subscribe_signal(gboolean subscribe) NULL, NULL); } } else { - if (service_added_id != -1) { + if (service_added_id > 0) { g_dbus_connection_signal_unsubscribe(g_conn, service_added_id); - service_added_id = -1; + service_added_id = 0; } - if (interface_removed_id != -1) { + if (interface_removed_id > 0) { g_dbus_connection_signal_unsubscribe(g_conn, interface_removed_id); - interface_removed_id = -1; + interface_removed_id = 0; } } diff --git a/bt-api/bt-gatt-service.c b/bt-api/bt-gatt-service.c index a99a5da..7cb8ee8 100644 --- a/bt-api/bt-gatt-service.c +++ b/bt-api/bt-gatt-service.c @@ -1624,6 +1624,7 @@ static GDBusConnection *__bt_gatt_get_gdbus_connection(void) NULL, /* GDBusAuthObserver */ NULL, &err); + g_free(address); if (!g_conn) { if (err) { BT_ERR("Unable to connect to dbus: %s", err->message); @@ -1647,7 +1648,7 @@ static GDBusConnection *__bt_gatt_get_gdbus_connection(void) NULL, /* GDBusAuthObserver */ NULL, &err); - + g_free(address); if (!local_system_gconn) { BT_ERR("Unable to connect to dbus: %s", err->message); g_clear_error(&err); @@ -1691,7 +1692,6 @@ BT_EXPORT_API int bluetooth_gatt_init(void) /* Register ObjectManager interface */ node_info = __bt_gatt_create_method_node_info( manager_introspection_xml); - if (node_info == NULL) { BT_ERR("failed to get node info"); goto failed; @@ -1705,7 +1705,7 @@ BT_EXPORT_API int bluetooth_gatt_init(void) &manager_interface_vtable, NULL, NULL, &error); } - + g_dbus_node_info_unref(node_info); if (manager_id == 0) { BT_ERR("failed to register: %s", error->message); g_error_free(error); @@ -1786,7 +1786,6 @@ BT_EXPORT_API int bluetooth_gatt_add_service(const char *svc_uuid, node_info = __bt_gatt_create_method_node_info( service_introspection_xml); - if (node_info == NULL) return BLUETOOTH_ERROR_INTERNAL; @@ -1797,6 +1796,7 @@ BT_EXPORT_API int bluetooth_gatt_add_service(const char *svc_uuid, node_info->interfaces[0], &serv_interface_vtable, NULL, NULL, &error); + g_dbus_node_info_unref(node_info); if (object_id == 0) { BT_ERR("failed to register: %s", error->message); @@ -1890,7 +1890,6 @@ BT_EXPORT_API int bluetooth_gatt_add_new_characteristic( node_info = __bt_gatt_create_method_node_info( characteristics_introspection_xml); - if (node_info == NULL) return BLUETOOTH_ERROR_INTERNAL; @@ -1901,6 +1900,7 @@ BT_EXPORT_API int bluetooth_gatt_add_new_characteristic( node_info->interfaces[0], &char_interface_vtable, NULL, NULL, &error); + g_dbus_node_info_unref(node_info); if (object_id == 0) { BT_ERR("failed to register: %s", error->message); @@ -2091,7 +2091,6 @@ BT_EXPORT_API int bluetooth_gatt_add_descriptor( node_info = __bt_gatt_create_method_node_info( descriptor_introspection_xml); - if (node_info == NULL) { g_strfreev(line_argv); g_free(serv_path); @@ -2105,6 +2104,7 @@ BT_EXPORT_API int bluetooth_gatt_add_descriptor( node_info->interfaces[0], &desc_interface_vtable, NULL, NULL, &error); + g_dbus_node_info_unref(node_info); if (object_id == 0) { BT_ERR("failed to register: %s", error->message); @@ -2166,6 +2166,7 @@ BT_EXPORT_API int bluetooth_gatt_add_descriptor( g_strfreev(line_argv); g_variant_builder_unref(inner_builder); g_variant_builder_unref(builder); + g_variant_builder_unref(builder2); return BLUETOOTH_ERROR_NONE; } diff --git a/bt-api/bt-hid-device.c b/bt-api/bt-hid-device.c index 52cc967..23942fa 100644 --- a/bt-api/bt-hid-device.c +++ b/bt-api/bt-hid-device.c @@ -454,6 +454,28 @@ static gboolean __received_cb(GIOChannel *chan, GIOCondition cond, break; } + case BT_HID_TRANS_GET_IDLE:{ + BT_INFO("Get_IDLE"); + data.type = HTYPE_TRANS_GET_IDLE; + data.param = PTYPE_DATA_RTYPE_INPUT; + data.buffer_size = len; + data.buffer = (char *) malloc(sizeof(char) * len); + if (data.buffer) + memcpy(data.buffer, buffer, len); + break; + } + + case BT_HID_TRANS_SET_IDLE:{ + BT_INFO("Set_IDLE"); + data.type = HTYPE_TRANS_SET_IDLE; + data.param = PTYPE_DATA_RTYPE_INPUT; + data.buffer_size = len; + data.buffer = (char *) malloc(sizeof(char) * len); + if (data.buffer) + memcpy(data.buffer, buffer, len); + break; + } + default: { BT_INFO("unsupported HIDP control message"); BT_ERR("Send Handshake Message"); @@ -610,6 +632,8 @@ BT_EXPORT_API int bluetooth_hid_device_activate(void) bt_register_profile_info_t profile_info; int result = BLUETOOTH_ERROR_NONE; + BT_CHECK_ENABLED(return); + if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_HID_DEVICE_ACTIVATE) == BLUETOOTH_ERROR_PERMISSION_DEINED) { BT_ERR("Don't have a privilege to use this API"); @@ -642,6 +666,8 @@ BT_EXPORT_API int bluetooth_hid_device_activate(void) BT_EXPORT_API int bluetooth_hid_device_deactivate(void) { + BT_CHECK_ENABLED(return); + if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_HID_DEVICE_DEACTIVATE) == BLUETOOTH_ERROR_PERMISSION_DEINED) { BT_ERR("Don't have a privilege to use this API"); @@ -666,6 +692,8 @@ BT_EXPORT_API int bluetooth_hid_device_connect(const char *remote_addr) BT_DBG("+"); BT_CHECK_PARAMETER(remote_addr, return); + BT_CHECK_ENABLED(return); + info = __find_hid_info_with_address(remote_addr); if (info) { BT_ERR("Connection Already Exists"); @@ -687,6 +715,8 @@ BT_EXPORT_API int bluetooth_hid_device_disconnect(const char *remote_addr) { BT_CHECK_PARAMETER(remote_addr, return); + BT_CHECK_ENABLED(return); + if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_HID_DEVICE_DISCONNECT) == BLUETOOTH_ERROR_PERMISSION_DEINED) { BT_ERR("Don't have a privilege to use this API"); @@ -874,7 +904,7 @@ BT_EXPORT_API int bluetooth_hid_device_reply_to_report(const char *remote_addr, { int result; struct reports output_report = { 0 }; - int bytes = 0; + int bytes = BLUETOOTH_ERROR_INTERNAL; hid_connected_device_info_t *info = NULL; info = __find_hid_info_with_address(remote_addr); if (info == NULL) { @@ -955,6 +985,26 @@ BT_EXPORT_API int bluetooth_hid_device_reply_to_report(const char *remote_addr, BT_DBG("Bytes Written %d", bytes); break; } + + case HTYPE_TRANS_GET_IDLE: { + BT_DBG("Replying to Get_IDLE"); + output_report.type = BT_HID_TRANS_DATA | BT_HID_DATA_RTYPE_OUTPUT; + output_report.rep_data[0] = data[0]; + bytes = write(info->intr_fd, &output_report, 2); + BT_DBG("Bytes Written %d", bytes); + break; + } + + case HTYPE_TRANS_SET_IDLE: { + BT_DBG("Reply to Set_IDLE"); + output_report.type = BT_HID_TRANS_DATA | BT_HID_DATA_RTYPE_INPUT; + memcpy(output_report.rep_data, data, data_len); + bytes = write(info->ctrl_fd, &output_report, + sizeof(output_report)); + BT_DBG("Bytes Written %d", bytes); + break; + } + default: break; } diff --git a/bt-api/bt-rfcomm-client.c b/bt-api/bt-rfcomm-client.c index ec57e1e..099816e 100644 --- a/bt-api/bt-rfcomm-client.c +++ b/bt-api/bt-rfcomm-client.c @@ -451,9 +451,8 @@ void _bt_rfcomm_client_disconnect_all(void) close(conn_info->fd); conn_info->disconnected = TRUE; - _bt_disconnect_profile(conn_info->bt_addr, info->uuid, - NULL, NULL); - + _bt_disconnect_ext_profile(conn_info->bt_addr, + info->obj_path); } client = client->next; @@ -692,6 +691,7 @@ BT_EXPORT_API int bluetooth_rfcomm_connect( object_id = _bt_register_new_conn(path, new_connection); if (object_id < 0) { __rfcomm_delete_id(id); + g_free(path); return BLUETOOTH_ERROR_INTERNAL; } @@ -873,7 +873,7 @@ BT_EXPORT_API int bluetooth_rfcomm_disconnect(int socket_fd) conn_info->disconnected = TRUE; BT_INFO("conn_info %s", conn_info->bt_addr); - _bt_disconnect_profile(conn_info->bt_addr, info->uuid, NULL, NULL); + _bt_disconnect_ext_profile(conn_info->bt_addr, info->obj_path); if (info->idle_id == 0) info->idle_id = g_idle_add(__rfcomm_client_disconnect, info); diff --git a/bt-api/bt-rfcomm-server.c b/bt-api/bt-rfcomm-server.c index aa59276..d29f93c 100644 --- a/bt-api/bt-rfcomm-server.c +++ b/bt-api/bt-rfcomm-server.c @@ -367,7 +367,7 @@ int new_server_connection(const char *path, int fd, bluetooth_device_address_t * close(fd); _bt_convert_addr_type_to_string(addr_str, addr->addr); - _bt_disconnect_profile(addr_str, info->uuid, NULL, NULL); + _bt_disconnect_ext_profile(addr_str, info->path); return -1; } @@ -505,7 +505,7 @@ void _bt_rfcomm_server_disconnect_all(void) _bt_convert_addr_type_to_string(addr, conn_info->addr.addr); - _bt_disconnect_profile(addr, info->uuid, NULL, NULL); + _bt_disconnect_ext_profile(addr, info->path); } server = server->next; @@ -729,7 +729,7 @@ BT_EXPORT_API int bluetooth_rfcomm_server_disconnect(int socket_fd) _bt_convert_addr_type_to_string(address, conn->addr.addr); BT_DBG("Address %s", address); - _bt_disconnect_profile(address, info->uuid, NULL, NULL); + _bt_disconnect_ext_profile(address, info->path); if (info->disconnect_idle_id == 0) info->disconnect_idle_id = g_idle_add( diff --git a/bt-api/bt-tds.c b/bt-api/bt-tds.c index c7b983b..f54696c 100644 --- a/bt-api/bt-tds.c +++ b/bt-api/bt-tds.c @@ -140,7 +140,9 @@ BT_EXPORT_API int bluetooth_set_tds_provider_transport_data(unsigned int tds_han BT_CHECK_ENABLED_LE(return); - retv_if(length > 0 && NULL == buf, BLUETOOTH_ERROR_INVALID_PARAM); + retv_if(NULL == buf, BLUETOOTH_ERROR_INVALID_PARAM); + retv_if(length == 0 || length > BLUETOOTH_TDS_DATA_LENGTH_MAX, + BLUETOOTH_ERROR_INVALID_PARAM); tds_data.length = length; memcpy(tds_data.data, buf, length); diff --git a/bt-api/bt-telephony.c b/bt-api/bt-telephony.c index 6dd2edd..f071e10 100644 --- a/bt-api/bt-telephony.c +++ b/bt-api/bt-telephony.c @@ -704,7 +704,6 @@ static int __bluetooth_telephony_proxy_init(void) node_info = __bt_telephony_create_method_node_info( bt_telephony_introspection_xml); - if (node_info == NULL) { BT_ERR("node_info NULL"); return BLUETOOTH_TELEPHONY_ERROR_INVALID_PARAM; @@ -712,10 +711,12 @@ static int __bluetooth_telephony_proxy_init(void) if (__bluetooth_telephony_register_object(TRUE, node_info) != BLUETOOTH_TELEPHONY_ERROR_NONE) { BT_ERR("Registation of Method Failed"); + g_dbus_node_info_unref(node_info); return BLUETOOTH_TELEPHONY_ERROR_INTERNAL; } FN_END; + g_dbus_node_info_unref(node_info); return BLUETOOTH_TELEPHONY_ERROR_NONE; } @@ -1184,9 +1185,10 @@ int __bt_telephony_subscribe_adapter_signal(GDBusConnection *conn, if (conn == NULL) return -1; - static int subscribe_adapter_id = -1; + static guint subscribe_adapter_id = 0; + if (subscribe == TRUE) { - if (subscribe_adapter_id == -1) { + if (subscribe_adapter_id == 0) { subscribe_adapter_id = g_dbus_connection_signal_subscribe(conn, NULL, "org.freedesktop.DBus.ObjectManager", "InterfacesAdded", NULL, NULL, 0, @@ -1195,10 +1197,10 @@ int __bt_telephony_subscribe_adapter_signal(GDBusConnection *conn, } return BLUETOOTH_TELEPHONY_ERROR_NONE; } else { - if (subscribe_adapter_id != -1) { + if (subscribe_adapter_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subscribe_adapter_id); - subscribe_adapter_id = -1; + subscribe_adapter_id = 0; } return BLUETOOTH_TELEPHONY_ERROR_NONE; } @@ -1210,21 +1212,22 @@ int __bt_telephony_event_subscribe_signal(GDBusConnection *conn, if (conn == NULL) return -1; - static int subscribe_event1_id = -1; - static int subscribe_event2_id = -1; - static int subscribe_event3_id = -1; - static int subscribe_event4_id = -1; - static int subscribe_event5_id = -1; - static int subscribe_event6_id = -1; + static guint subscribe_event1_id = 0; + static guint subscribe_event2_id = 0; + static guint subscribe_event3_id = 0; + static guint subscribe_event4_id = 0; + static guint subscribe_event5_id = 0; + static guint subscribe_event6_id = 0; + if (subscribe == TRUE) { - if (subscribe_event1_id == -1) { + if (subscribe_event1_id == 0) { subscribe_event1_id = g_dbus_connection_signal_subscribe(conn, NULL, BLUEZ_HEADSET_INTERFACE, "PropertyChanged", NULL, NULL, 0, __bluetooth_telephony_event_filter, NULL, NULL); } - if (subscribe_event2_id == -1) { + if (subscribe_event2_id == 0) { subscribe_event2_id = g_dbus_connection_signal_subscribe(conn, NULL, HFP_AGENT_SERVICE, HFP_NREC_STATUS_CHANGE, NULL, NULL, 0, @@ -1232,28 +1235,28 @@ int __bt_telephony_event_subscribe_signal(GDBusConnection *conn, NULL, NULL); } - if (subscribe_event3_id == -1) { + if (subscribe_event3_id == 0) { subscribe_event3_id = g_dbus_connection_signal_subscribe(conn, NULL, HFP_AGENT_SERVICE, HFP_ANSWER_CALL, NULL, NULL, 0, __bluetooth_telephony_event_filter, NULL, NULL); } - if (subscribe_event4_id == -1) { + if (subscribe_event4_id == 0) { subscribe_event4_id = g_dbus_connection_signal_subscribe(conn, NULL, HFP_AGENT_SERVICE, HFP_REJECT_CALL, NULL, NULL, 0, __bluetooth_telephony_event_filter, NULL, NULL); } - if (subscribe_event5_id == -1) { + if (subscribe_event5_id == 0) { subscribe_event5_id = g_dbus_connection_signal_subscribe(conn, NULL, HFP_AGENT_SERVICE, HFP_RELEASE_CALL, NULL, NULL, 0, __bluetooth_telephony_event_filter, NULL, NULL); } - if (subscribe_event6_id == -1) { + if (subscribe_event6_id == 0) { subscribe_event6_id = g_dbus_connection_signal_subscribe(conn, NULL, HFP_AGENT_SERVICE, HFP_THREEWAY_CALL, NULL, NULL, 0, @@ -1263,35 +1266,35 @@ int __bt_telephony_event_subscribe_signal(GDBusConnection *conn, return BLUETOOTH_TELEPHONY_ERROR_NONE; } else { - if (subscribe_event1_id != -1) { + if (subscribe_event1_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subscribe_event1_id); - subscribe_event1_id = -1; + subscribe_event1_id = 0; } - if (subscribe_event2_id != -1) { + if (subscribe_event2_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subscribe_event2_id); - subscribe_event2_id = -1; + subscribe_event2_id = 0; } - if (subscribe_event3_id != -1) { + if (subscribe_event3_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subscribe_event3_id); - subscribe_event3_id = -1; + subscribe_event3_id = 0; } - if (subscribe_event4_id != -1) { + if (subscribe_event4_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subscribe_event4_id); - subscribe_event4_id = -1; + subscribe_event4_id = 0; } - if (subscribe_event5_id != -1) { + if (subscribe_event5_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subscribe_event5_id); - subscribe_event5_id = -1; + subscribe_event5_id = 0; } - if (subscribe_event6_id != -1) { + if (subscribe_event6_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subscribe_event6_id); - subscribe_event6_id = -1; + subscribe_event6_id = 0; } return BLUETOOTH_TELEPHONY_ERROR_NONE; } @@ -1709,7 +1712,7 @@ static void __bluetooth_telephony_sco_start_cb(GDBusProxy *proxy, GAsyncResult *res, gpointer user_data) { GError *error = NULL; - GVariant *value; + GVariant *value = NULL; value = g_dbus_proxy_call_finish(proxy, res, &error); if (value == NULL) { @@ -1720,6 +1723,8 @@ static void __bluetooth_telephony_sco_start_cb(GDBusProxy *proxy, } else { BT_ERR("SCo Start Failed"); } + g_object_unref(proxy); + return; } BT_DBG("sco_start_cb : -"); @@ -1781,7 +1786,7 @@ static void __bluetooth_telephony_sco_close_cb(GDBusProxy *proxy, GAsyncResult *res, gpointer user_data) { GError *error = NULL; - GVariant *value; + GVariant *value = NULL; value = g_dbus_proxy_call_finish(proxy, res, &error); if (value == NULL) { @@ -1792,6 +1797,8 @@ static void __bluetooth_telephony_sco_close_cb(GDBusProxy *proxy, } else { BT_ERR("SCo close Failed"); } + g_object_unref(proxy); + return; } BT_DBG("sco_close_cb : -"); diff --git a/bt-api/include/bt-common.h b/bt-api/include/bt-common.h index e3a2af4..c4cc514 100644 --- a/bt-api/include/bt-common.h +++ b/bt-api/include/bt-common.h @@ -280,14 +280,13 @@ void _bt_map_client_event_cb(int event, int result, void *param, void _bt_divide_device_class(bluetooth_device_class_t *device_class, unsigned int cod); -void _bt_convert_addr_string_to_type(unsigned char *addr, - const char *address); +void _bt_convert_addr_string_to_type(unsigned char *addr, const char *address); -void _bt_convert_addr_string_to_secure_string(char *addr, - const char *address); +void _bt_convert_addr_string_to_secure_string(char *addr, const char *address); -void _bt_convert_addr_type_to_string(char *address, - unsigned char *addr); +void _bt_convert_addr_type_to_string(char *address, unsigned char *addr); + +void _bt_convert_addr_type_to_secure_string(char *address, unsigned char *addr); const char *_bt_convert_error_to_string(int error); @@ -314,6 +313,7 @@ int _bt_connect_profile(char *address, char *uuid, void *cb, gpointer func_data); int _bt_disconnect_profile(char *address, char *uuid, void *cb, gpointer func_data); +int _bt_disconnect_ext_profile(char *address, char *path); int _bt_cancel_discovers(char *address); int _bt_discover_services(char *address, char *uuid, void *cb, @@ -365,8 +365,11 @@ void _bt_set_adapter_internal_status(gboolean enabled); int _bt_get_uuid_specification_name(const char *uuid, char **name); +void _bt_convert_device_path_to_addr_type(const char *device_path, + unsigned char *addr); + void _bt_convert_device_path_to_address(const char *device_path, - char *device_address); + char *device_address); #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT void _bt_rfcomm_server_free_all(void); diff --git a/bt-core/bt-core-adapter.c b/bt-core/bt-core-adapter.c index 1ea2b8c..a98b5c9 100644 --- a/bt-core/bt-core-adapter.c +++ b/bt-core/bt-core-adapter.c @@ -541,6 +541,13 @@ gboolean _bt_core_enable_adapter(void) return TRUE; } +static gboolean __bt_core_terminate_cb(gpointer data) +{ + _bt_core_terminate(); + + return FALSE; +} + gboolean _bt_core_disable_adapter(void) { int ret; @@ -549,6 +556,8 @@ gboolean _bt_core_disable_adapter(void) if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0) BT_ERR("Set vconf failed"); + g_idle_add((GSourceFunc)__bt_core_terminate_cb, NULL); + ret = _bt_disable_adapter(); if (ret < 0) return FALSE; @@ -712,7 +721,6 @@ gboolean _bt_core_factory_test_mode(const char *type, const char *arg) arg_list[0] = "bt-enable-rf-channel.sh"; arg_list[1] = (char *)arg; } else { - _bt_core_terminate(); return FALSE; } @@ -720,7 +728,6 @@ gboolean _bt_core_factory_test_mode(const char *type, const char *arg) if (__execute_command(cmd, arg_list) < 0) BT_ERR("running script failed"); - _bt_core_terminate(); return TRUE; } diff --git a/bt-core/bt-core-dbus-handler.c b/bt-core/bt-core-dbus-handler.c index 34c34c7..5eb2894 100644 --- a/bt-core/bt-core-dbus-handler.c +++ b/bt-core/bt-core-dbus-handler.c @@ -387,6 +387,7 @@ static void __bt_core_dbus_method(GDBusConnection *connection, ret = _bt_core_factory_test_mode(type, arg); g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", ret)); + _bt_core_terminate(); return; } else { ret = FALSE; diff --git a/bt-httpproxy/bt-httpproxy.c b/bt-httpproxy/bt-httpproxy.c index dbea6cc..4d23471 100644 --- a/bt-httpproxy/bt-httpproxy.c +++ b/bt-httpproxy/bt-httpproxy.c @@ -44,8 +44,8 @@ char *http_status_desc_obj_path = NULL; char *http_security_obj_path = NULL; static GMainLoop *main_loop; -static int property_sub_id = -1; -static int adapter_sub_id = -1; +static guint property_sub_id; +static guint adapter_sub_id; static http_request_state req_state; #ifdef HPS_GATT_DB @@ -69,7 +69,6 @@ static GSList *hps_char_list = NULL; static GDBusConnection *conn; static GDBusConnection *g_conn; static guint g_owner_id = 0; -GDBusNodeInfo *hps_node_info = NULL; char *g_uri = NULL; char *g_header = NULL; @@ -202,6 +201,7 @@ static const GDBusInterfaceVTable hps_method_table = { static void _bt_hps_on_bus_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) { + GDBusNodeInfo *node_info = NULL; guint object_id; GError *error = NULL; @@ -209,14 +209,21 @@ static void _bt_hps_on_bus_acquired(GDBusConnection *connection, const gchar *na g_conn = connection; + node_info = g_dbus_node_info_new_for_xml(hps_introspection_xml, &error); + if (!node_info) { + BT_ERR("Failed to install: %s", error->message); + g_clear_error(&error); + return; + } + object_id = g_dbus_connection_register_object(connection, BT_HPS_OBJECT_PATH, - hps_node_info->interfaces[0], + node_info->interfaces[0], &hps_method_table, NULL, NULL, &error); + g_dbus_node_info_unref(node_info); if (object_id == 0) { BT_ERR("Failed to register method table: %s", error->message); g_error_free(error); - g_dbus_node_info_unref(hps_node_info); } return; @@ -237,7 +244,6 @@ static void _bt_hps_on_name_lost(GDBusConnection *connection, BT_DBG(""); g_object_unref(g_conn); g_conn = NULL; - g_dbus_node_info_unref(hps_node_info); g_bus_unown_name(g_owner_id); return; @@ -245,17 +251,10 @@ static void _bt_hps_on_name_lost(GDBusConnection *connection, int _bt_hps_register_interface(void) { - GError *error = NULL; guint owner_id; BT_DBG(""); - hps_node_info = g_dbus_node_info_new_for_xml(hps_introspection_xml, &error); - if (!hps_node_info) { - BT_ERR("Failed to install: %s", error->message); - return BLUETOOTH_ERROR_INTERNAL; - } - owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, BT_HPS_SERVICE_NAME, G_BUS_NAME_OWNER_FLAGS_NONE, @@ -273,7 +272,6 @@ void _bt_hps_unregister_interface(void) g_object_unref(g_conn); g_conn = NULL; - g_dbus_node_info_unref(hps_node_info); g_bus_unown_name(g_owner_id); return; @@ -320,28 +318,24 @@ static void _bt_hps_set_char_value(const char *obj_path, const char* value, int if (tmp->data) { struct hps_char_info *char_info = tmp->data; if (!g_strcmp0(char_info->char_path, obj_path)) { - gchar *str = NULL; - if (offset > 0) { - str = g_strdup(char_info->char_value); - char_info->char_value = g_try_realloc(char_info->char_value, offset + value_length); + gchar *data = NULL; + if (char_info->char_value == NULL) { + char_info->char_value = g_malloc0(offset + value_length); + char_info->value_length = offset + value_length; + } else if (char_info->value_length >= offset + value_length) { + /* Just change from offset */ + memcpy(&char_info->char_value[offset], value, value_length); } else { - char_info->char_value = g_try_realloc(char_info->char_value, value_length); + /* Values crossing pervious allocated limit realloc */ + data = g_memdup(char_info->char_value, char_info->value_length); + char_info->char_value = g_try_realloc(char_info->char_value, offset + value_length); + memcpy(char_info->char_value, data, char_info->value_length); + memcpy(&char_info->char_value[offset], value, value_length); + char_info->value_length = offset + value_length; + g_free(data); } - if (char_info->char_value) { - if (str) { - memcpy(char_info->char_value, str, strlen(str)); - } - if (offset > 0) { - memcpy(&char_info->char_value[offset], value, value_length); - char_info->value_length = offset + value_length; - } else { - memcpy(char_info->char_value, value, value_length); - char_info->value_length = value_length; - } - hps_char_list = g_slist_insert_sorted(hps_char_list, + hps_char_list = g_slist_insert_sorted(hps_char_list, char_info, char_info_cmp); - } - g_free(str); return; } } @@ -363,7 +357,7 @@ static void _bt_hps_set_notify_read_status(const char *obj_path, notify_read_info->offset_status = offset_status; notify_read_info->https_status = https_status; hps_notify_read_list = g_slist_insert_sorted(hps_notify_read_list, - notify_read_info, notify_info_cmp); + notify_read_info, notify_info_cmp); return; } } @@ -380,16 +374,17 @@ static void _bt_hps_set_notify_read_status(const char *obj_path, hps_notify_read_list = g_slist_append(hps_notify_read_list, notify_read_info); } return; - } - - /* Store Notification information */ - notify_read_info = g_new0(struct hps_notify_read_info, 1); - if (notify_read_info) { - notify_read_info->char_path = g_strdup(obj_path); - notify_read_info->read_status = read_status; - notify_read_info->offset_status = offset_status; - notify_read_info->https_status = https_status; - hps_notify_read_list = g_slist_append(hps_notify_read_list, notify_read_info); + } else { + /* Store Notification information */ + notify_read_info = g_new0(struct hps_notify_read_info, 1); + if (notify_read_info) { + notify_read_info->char_path = g_strdup(obj_path); + notify_read_info->read_status = read_status; + notify_read_info->offset_status = offset_status; + notify_read_info->https_status = https_status; + hps_notify_read_list = g_slist_append(hps_notify_read_list, notify_read_info); + } + return; } } @@ -1425,9 +1420,22 @@ int _bt_hps_init_event_receiver() void _bt_hps_deinit_event_receiver(void) { BT_DBG(""); - g_dbus_connection_signal_unsubscribe(conn, property_sub_id); - g_dbus_connection_signal_unsubscribe(conn, adapter_sub_id); + + if (conn == NULL) + return; + + if (property_sub_id > 0) { + g_dbus_connection_signal_unsubscribe(conn, property_sub_id); + property_sub_id = 0; + } + + if (adapter_sub_id) { + g_dbus_connection_signal_unsubscribe(conn, adapter_sub_id); + adapter_sub_id = 0; + } + conn = NULL; + return; } diff --git a/bt-service/bt-request-handler.c b/bt-service/bt-request-handler.c index ba994ba..38ec417 100644 --- a/bt-service/bt-request-handler.c +++ b/bt-service/bt-request-handler.c @@ -73,7 +73,7 @@ static const gchar bt_service_introspection_xml[] = " " ""; -GDBusNodeInfo *node_info = NULL; +static gboolean name_acquired = FALSE; static char *current_sender_playing = NULL; @@ -715,15 +715,19 @@ int __bt_bluez_request(int function_name, break; } case BT_LE_CONN_UPDATE: { + char *sender = NULL; bluetooth_device_address_t local_address = { {0} }; bluetooth_le_connection_param_t parameters = {0}; + sender = (char *)g_dbus_method_invocation_get_sender(context); + __bt_service_get_parameters(in_param1, &local_address, sizeof(bluetooth_device_address_t)); __bt_service_get_parameters(in_param2, ¶meters, sizeof(bluetooth_le_connection_param_t)); - result = _bt_le_conn_update(local_address.addr, + result = _bt_le_conn_update(sender, + local_address.addr, parameters.interval_min, parameters.interval_max, parameters.latency, @@ -968,6 +972,7 @@ int __bt_bluez_request(int function_name, break; } case BT_UPDATE_LE_CONNECTION_MODE: { + char *sender = NULL; bluetooth_device_address_t remote_address = { { 0 } }; bluetooth_le_connection_param_t param = { 0 }; bluetooth_le_connection_mode_t mode = BLUETOOTH_LE_CONNECTION_MODE_BALANCED; @@ -981,7 +986,10 @@ int __bt_bluez_request(int function_name, if (result != BLUETOOTH_ERROR_NONE) break; - result = _bt_le_conn_update(remote_address.addr, + sender = (char *)g_dbus_method_invocation_get_sender(context); + + result = _bt_le_conn_update(sender, + remote_address.addr, param.interval_min, param.interval_max, param.latency, @@ -3446,39 +3454,64 @@ int __bt_service_register_object(GDBusConnection *conn, return 0; } +static void __bt_service_bus_acquired_handler(GDBusConnection *connection, + const gchar *name, gpointer user_data) +{ + GDBusNodeInfo *node_info = NULL; + + BT_INFO("bus acquired"); + + ret_if(connection == NULL); + + node_info = __bt_service_create_method_node_info( + bt_service_introspection_xml); + ret_if(node_info == NULL); + + __bt_service_register_object(connection, node_info, TRUE); + g_dbus_node_info_unref(node_info); + + bt_service_conn = connection; +} + +static void __bt_service_name_acquired_handler(GDBusConnection *connection, + const gchar *name, gpointer user_data) +{ + BT_INFO("name acquired"); + name_acquired = TRUE; +} + +static void __bt_service_name_lost_handler(GDBusConnection *connection, + const gchar *name, gpointer user_data) +{ + BT_INFO("name lost"); + name_acquired = FALSE; +} + +gboolean _is_name_acquired(void) +{ + return name_acquired; +} + int _bt_service_register(void) { GDBusConnection *conn; GError *err = NULL; - int result; conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL); + bt_service_conn = conn; owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, BT_SERVICE_NAME, G_BUS_NAME_OWNER_FLAGS_NONE, - NULL, NULL, NULL, + __bt_service_bus_acquired_handler, + __bt_service_name_acquired_handler, + __bt_service_name_lost_handler, NULL, NULL); BT_DBG("owner_id is [%d]", owner_id); if (owner_id == 0) goto fail; - node_info = __bt_service_create_method_node_info( - bt_service_introspection_xml); - - if (node_info == NULL) - goto fail; - - result = __bt_service_register_object(conn, node_info, TRUE); - g_dbus_node_info_unref(node_info); - node_info = NULL; - - if (result != BLUETOOTH_ERROR_NONE) - goto fail; - - bt_service_conn = conn; - return BLUETOOTH_ERROR_NONE; fail: @@ -3498,10 +3531,6 @@ void _bt_service_unregister(void) g_object_unref(bt_service_conn); bt_service_conn = NULL; } - if (node_info) { - g_dbus_node_info_unref(node_info); - node_info = NULL; - } if (owner_id > 0) { g_bus_unown_name(owner_id); owner_id = 0; diff --git a/bt-service/bt-service-adapter-le.c b/bt-service/bt-service-adapter-le.c index efd72e3..d6567b1 100644 --- a/bt-service/bt-service-adapter-le.c +++ b/bt-service/bt-service-adapter-le.c @@ -94,23 +94,14 @@ static void __bt_free_le_adv_slot(void) le_adv_slot = NULL; } -int _bt_service_adapter_le_init(void) -{ - le_adv_slot = g_malloc0(sizeof(bt_adapter_le_adv_slot_t) * le_feature_info.adv_inst_max); - - return BLUETOOTH_ERROR_NONE; -} - -void _bt_service_adapter_le_deinit(void) -{ - __bt_free_le_adv_slot(); -} - gboolean _bt_update_le_feature_support(const char *item, const char *value) { if (item == NULL || value == NULL) return FALSE; + if (!le_adv_slot) + _bt_service_adapter_le_init(); + if (g_strcmp0(item, "adv_inst_max") == 0) { int slot_num; @@ -204,6 +195,11 @@ void _bt_unregister_adv_slot_owner(int slot_id) if (le_adv_slot == NULL) return; + if (le_adv_slot[slot_id].hold_timer_id > 0) { + BT_INFO("Hold state adv is not unregistered"); + return; + } + g_free(le_adv_slot[slot_id].sender); le_adv_slot[slot_id].sender = NULL; le_adv_slot[slot_id].adv_handle = 0; @@ -304,14 +300,15 @@ int _bt_set_advertising(const char *sender, int adv_handle, gboolean enable, gbo if (le_adv_slot[slot_id].is_advertising == TRUE && enable == TRUE) return BLUETOOTH_ERROR_IN_PROGRESS; - if (le_adv_slot[slot_id].sender != NULL && le_adv_slot[slot_id].is_advertising == FALSE && enable == FALSE) - return BLUETOOTH_ERROR_NOT_IN_OPERATION; - if (le_adv_slot[slot_id].hold_timer_id > 0) { g_source_remove(le_adv_slot[slot_id].hold_timer_id); le_adv_slot[slot_id].hold_timer_id = 0; + _bt_unregister_adv_slot_owner(slot_id); } + if (le_adv_slot[slot_id].is_advertising == FALSE && enable == FALSE) + return BLUETOOTH_ERROR_NOT_IN_OPERATION; + proxy = _bt_get_adapter_proxy(); retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL); @@ -371,14 +368,15 @@ int _bt_set_custom_advertising(const char *sender, int adv_handle, if (le_adv_slot[slot_id].is_advertising == TRUE && enable == TRUE) return BLUETOOTH_ERROR_IN_PROGRESS; - if (le_adv_slot[slot_id].sender != NULL && le_adv_slot[slot_id].is_advertising == FALSE && enable == FALSE) - return BLUETOOTH_ERROR_NOT_IN_OPERATION; - if (le_adv_slot[slot_id].hold_timer_id > 0) { g_source_remove(le_adv_slot[slot_id].hold_timer_id); le_adv_slot[slot_id].hold_timer_id = 0; + _bt_unregister_adv_slot_owner(slot_id); } + if (le_adv_slot[slot_id].is_advertising == FALSE && enable == FALSE) + return BLUETOOTH_ERROR_NOT_IN_OPERATION; + proxy = _bt_get_adapter_proxy(); retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL); @@ -433,8 +431,6 @@ int _bt_set_custom_advertising(const char *sender, int adv_handle, if (enable == TRUE) __bt_register_adv_slot_owner(sender, adv_handle, slot_id); - else - _bt_unregister_adv_slot_owner(slot_id); le_adv_slot[slot_id].is_advertising = enable; BT_INFO_C("### Set advertising [%d]", enable); @@ -507,7 +503,7 @@ int _bt_hold_current_advertising(void) le_adv_slot[0].hold_timer_id = g_timeout_add(2000, __bt_hold_current_advertising_timeout_cb, NULL); } else { - BT_ERR("It's NOT advertising"); + BT_INFO("It's NOT advertising"); return BLUETOOTH_ERROR_NOT_IN_OPERATION; } @@ -1177,16 +1173,18 @@ int _bt_register_scan_filter(const char *sender, bluetooth_le_scan_filter_t *fil scanner = __bt_find_scanner_from_list(sender); if (scanner == NULL) { scanner = g_malloc0(sizeof(bt_adapter_le_scanner_t)); - scanner->sender = strdup(sender); + scanner->sender = g_strdup(sender); scanner_list = g_slist_append(scanner_list, scanner); } - filter_data = g_malloc0(sizeof(bluetooth_le_scan_filter_t)); - memcpy(filter_data, filter, sizeof(bluetooth_le_scan_filter_t)); - filter_data->slot_id = *slot_id; - if (scanner) + if (scanner) { + filter_data = g_malloc0(sizeof(bluetooth_le_scan_filter_t)); + memcpy(filter_data, filter, sizeof(bluetooth_le_scan_filter_t)); + filter_data->slot_id = *slot_id; + scanner->filter_list = g_slist_append(scanner->filter_list, filter_data); + } if (ret) g_variant_unref(ret); @@ -1290,7 +1288,7 @@ int _bt_start_le_scan(const char *sender) if (scanner == NULL) { scanner = g_malloc0(sizeof(bt_adapter_le_scanner_t)); - scanner->sender = strdup(sender); + scanner->sender = g_strdup(sender); scanner_list = g_slist_append(scanner_list, scanner); } @@ -1462,6 +1460,26 @@ void _bt_disable_all_scanner_status(void) } } +static void __bt_free_le_scanner(void) +{ + GSList *l; + bt_adapter_le_scanner_t *scanner; + + for (l = scanner_list; l != NULL; l = g_slist_next(l)) { + scanner = l->data; + g_free(scanner->sender); + g_slist_free_full(scanner->filter_list, g_free); + g_free(scanner); + } + + g_slist_free(scanner_list); + scanner_list = NULL; + + scan_filter_enabled = FALSE; + is_le_scanning = FALSE; + is_le_set_scan_parameter = FALSE; +} + void _bt_set_le_scan_status(gboolean mode) { is_le_scanning = mode; @@ -2194,3 +2212,16 @@ int _bt_le_set_data_length(bluetooth_device_address_t *device_address, return BLUETOOTH_ERROR_NONE; } + +int _bt_service_adapter_le_init(void) +{ + le_adv_slot = g_malloc0(sizeof(bt_adapter_le_adv_slot_t) * le_feature_info.adv_inst_max); + + return BLUETOOTH_ERROR_NONE; +} + +void _bt_service_adapter_le_deinit(void) +{ + __bt_free_le_adv_slot(); + __bt_free_le_scanner(); +} diff --git a/bt-service/bt-service-adapter.c b/bt-service/bt-service-adapter.c index 569afe2..fb44cea 100644 --- a/bt-service/bt-service-adapter.c +++ b/bt-service/bt-service-adapter.c @@ -65,6 +65,8 @@ typedef struct { GList *g_alarm_list; } bt_service_alarm_mgr_t; +#define BT_RECOVERY_MAX_COUNT 3 + static bt_service_alarm_mgr_t alarm_mgr = {0, }; static gboolean is_discovering; @@ -77,7 +79,8 @@ static void *adapter_agent = NULL; static GDBusProxy *core_proxy = NULL; static guint timer_id = 0; static guint le_timer_id = 0; -static gboolean is_recovery_mode; +static int recovery_cnt = BT_RECOVERY_MAX_COUNT; +static guint recovery_timer = 0; static uint status_reg_id; @@ -87,6 +90,9 @@ static uint status_reg_id; #define BT_DISABLE_TIME 500 /* 500 ms */ +#define BT_RECOVERY_TIME_W 2000 /*2 sec*/ +#define BT_RECOVERY_TIME 5000 /*5 sec*/ + static int alarm_cb(alarm_id_t alarm_id, void* user_param); static void alarm_data_free(void *data); @@ -457,8 +463,7 @@ static void __bt_phone_name_changed_cb(keynode_t *node, void *data) char *phone_name = NULL; char *ptr = NULL; - if (node == NULL) - return; + ret_if(node == NULL); if (vconf_keynode_get_type(node) == VCONF_TYPE_STRING) { phone_name = vconf_keynode_get_str(node); @@ -468,8 +473,13 @@ static void __bt_phone_name_changed_cb(keynode_t *node, void *data) (const char **)&ptr)) *ptr = '\0'; + BT_INFO("device_name is changed to %s", phone_name); _bt_set_local_name(phone_name); + } else { + BT_ERR("phone_name is NOT valid"); } + } else { + BT_ERR("vconf type is NOT string"); } } @@ -589,13 +599,6 @@ void _bt_set_disabled(int result) _bt_adapter_set_status(BT_DEACTIVATED); _bt_set_discovery_status(FALSE); - if (TIZEN_FEATURE_BT_USB_DONGLE || - _bt_adapter_get_le_status() != BT_LE_DEACTIVATED) { - /* Send disabled event */ - _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_DISABLED, - g_variant_new("(i)", result)); - } - BT_INFO("Adapter disabled"); } @@ -659,7 +662,7 @@ void _bt_set_le_disabled(int result) /* Send disabled event */ _bt_send_event(BT_LE_ADAPTER_EVENT, BLUETOOTH_EVENT_LE_DISABLED, - g_variant_new("(i)", result)); + g_variant_new("(i)", result)); } void *_bt_get_adapter_agent(void) @@ -773,6 +776,34 @@ static void __bt_state_event_handler(const char *event_name, bundle *data, void BT_DBG("bt_state: (%s)", bt_le_status); } +static gboolean __bt_adapter_recovery_cb(gpointer data) +{ + int ret = 0; + + BT_DBG("+"); + + recovery_timer = 0; + + _bt_service_initialize(); + + ret = _bt_enable_adapter_check_status(); + if (ret == BLUETOOTH_ERROR_NONE) { + ret = _bt_enable_adapter(); + if (ret < 0) + BT_ERR("_bt_enable_adapter() failed"); + + ret = _bt_enable_adapter_le(); + if (ret < 0) + BT_ERR("_bt_enable_adapter_le() failed"); + } + + recovery_cnt--; + + BT_DBG("-"); + + return FALSE; +} + void _bt_handle_adapter_added(void) { BT_DBG("+"); @@ -787,11 +818,12 @@ void _bt_handle_adapter_added(void) } */ + recovery_cnt = -1; + status = _bt_adapter_get_status(); le_status = _bt_adapter_get_le_status(); - BT_DBG("status : %d", status); - BT_DBG("le_status : %d", le_status); - + BT_INFO("status : %d", status); + BT_INFO("le_status : %d", le_status); if (!TIZEN_FEATURE_BT_USB_DONGLE) { adapter_agent = _bt_create_agent(BT_ADAPTER_AGENT_PATH, TRUE); if (!adapter_agent) { @@ -867,33 +899,49 @@ void _bt_handle_adapter_removed(void) if (0 != ret) ERR("vconf_ignore_key_changed failed\n"); -/* unregister all the services/servers/profiles registered on bluez-adapter - once adapter is removed, reinitializing of the state-varaibles becomes - a problem */ + /* unregister all the services/servers/profiles registered on bluez-adapter + once adapter is removed, reinitializing of the state-varaibles becomes + a problem */ if (_bt_unregister_obex_server() != BLUETOOTH_ERROR_NONE) BT_ERR("Fail to unregister obex server"); if (_bt_unregister_media_player() != BLUETOOTH_ERROR_NONE) BT_ERR("Fail to unregister media player"); -/* Other unregister APIs should be placed here */ + /* Other unregister APIs should be placed here */ if (!TIZEN_FEATURE_BT_USB_DONGLE) { _bt_destroy_agent(adapter_agent); adapter_agent = NULL; - if (is_recovery_mode == TRUE) { + if (recovery_cnt > 0) { /* Send disabled event */ _bt_set_disabled(BLUETOOTH_ERROR_NONE); + _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_DISABLED, + g_variant_new("(i)", BLUETOOTH_ERROR_NONE)); - /* Will recover BT by bt-core, so set the mode as activating */ - _bt_adapter_set_status(BT_ACTIVATING); - is_recovery_mode = FALSE; - } else { - _bt_reliable_terminate_service(NULL); + if (recovery_timer > 0) + g_source_remove(recovery_timer); + + if (TIZEN_PROFILE_WEARABLE) { + recovery_timer = g_timeout_add(BT_RECOVERY_TIME_W, + (GSourceFunc)__bt_adapter_recovery_cb, NULL); + } else { + recovery_timer = g_timeout_add(BT_RECOVERY_TIME, + (GSourceFunc)__bt_adapter_recovery_cb, NULL); + } + + if (eventsystem_unregister_event(status_reg_id) != ES_R_OK) + BT_ERR("Fail to unregister system event"); + return; } + + if (recovery_timer == 0) + _bt_reliable_terminate_service(NULL); } else { _bt_set_disabled(BLUETOOTH_ERROR_NONE); + _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_DISABLED, + g_variant_new("(i)", BLUETOOTH_ERROR_NONE)); } if (eventsystem_unregister_event(status_reg_id) != ES_R_OK) @@ -938,6 +986,22 @@ static gboolean __bt_enable_timeout_cb(gpointer user_data) g_variant_unref(result); _bt_set_disabled(BLUETOOTH_ERROR_TIMEOUT); + if (recovery_cnt > 0) { + BT_ERR("Try recovery again(remain:%d)", recovery_cnt); + if (recovery_timer > 0) + g_source_remove(recovery_timer); + + if (TIZEN_PROFILE_WEARABLE) { + recovery_timer = g_timeout_add(BT_RECOVERY_TIME_W, + (GSourceFunc)__bt_adapter_recovery_cb, NULL); + } else { + recovery_timer = g_timeout_add(BT_RECOVERY_TIME, + (GSourceFunc)__bt_adapter_recovery_cb, NULL); + } + + return FALSE; + } + if (!TIZEN_FEATURE_BT_USB_DONGLE) _bt_terminate_service(NULL); @@ -979,9 +1043,9 @@ static gboolean __bt_enable_le_timeout_cb(gpointer user_data) } g_variant_unref(result); - _bt_adapter_set_le_status(BT_LE_DEACTIVATED); - _bt_set_le_disabled(BLUETOOTH_ERROR_TIMEOUT); + if (_bt_adapter_get_le_status() != BT_LE_DEACTIVATED) + _bt_set_le_disabled(BLUETOOTH_ERROR_TIMEOUT); if (_bt_adapter_get_status() == BT_DEACTIVATED) _bt_terminate_service(NULL); @@ -1141,6 +1205,37 @@ if (TIZEN_PROFILE_TV) { return BLUETOOTH_ERROR_NONE; } +static gboolean __bt_set_powered(gboolean powered) +{ + GDBusProxy *proxy; + GError *error = NULL; + GVariant *result; + + BT_DBG(""); + + proxy = _bt_get_adapter_properties_proxy(); + retv_if(proxy == NULL, FALSE); + + result = g_dbus_proxy_call_sync(proxy, "Set", + g_variant_new("(ssv)", BT_ADAPTER_INTERFACE, "Powered", + g_variant_new("b", powered)), + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (!result) { + if (error != NULL) { + BT_ERR("Failed to set powered property (Error: %s)", + error->message); + g_clear_error(&error); + } else { + BT_ERR("Failed to set powered property"); + } + return FALSE; + } + + BT_INFO("Set powered [%d]", powered); + g_variant_unref(result); + return TRUE; +} + static gboolean __bt_disconnect_all(void) { int i; @@ -1227,6 +1322,8 @@ static gboolean __bt_set_disabled_timeout_cb(gpointer user_data) { BT_DBG(""); _bt_set_disabled(BLUETOOTH_ERROR_NONE); + _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_DISABLED, + g_variant_new("(i)", BLUETOOTH_ERROR_NONE)); return FALSE; } @@ -1313,6 +1410,7 @@ int _bt_disable_adapter(void) { BT_DBG("+"); int ret; + bt_le_status_t le_status; if (_bt_adapter_get_status() == BT_DEACTIVATING) { BT_DBG("Disabling in progress"); @@ -1328,17 +1426,27 @@ int _bt_disable_adapter(void) g_source_remove(timer_id); timer_id = 0; } -/* unregister all the services/servers/profiles registered on bluez-adapter - once adapter is removed, reinitializing of the state-varaibles becomes - a problem */ + + /* unregister all the services/servers/profiles registered on bluez-adapter + once adapter is removed, reinitializing of the state-varaibles becomes + a problem */ if (_bt_unregister_obex_server() != BLUETOOTH_ERROR_NONE) BT_ERR("Fail to unregister obex server"); if (_bt_unregister_media_player() != BLUETOOTH_ERROR_NONE) BT_ERR("Fail to unregister media player"); + /* Other unregister APIs should be placed here */ + + le_status = _bt_adapter_get_le_status(); + if (le_status == BT_LE_ACTIVATED && is_le_intended == TRUE) { + __bt_disconnect_all(); + } else { + if (le_status == BT_LE_ACTIVATED) + _bt_set_le_disabled(BLUETOOTH_ERROR_NONE); + + __bt_set_powered(FALSE); + } -/* Other unregister APIs should be placed here */ - __bt_disconnect_all(); ret = _bt_disable_cb(); BT_DBG("-"); @@ -1348,9 +1456,6 @@ int _bt_disable_adapter(void) int _bt_recover_adapter(void) { BT_DBG("+"); - GDBusProxy *proxy; - GVariant *result; - GError *error = NULL; if (_bt_adapter_get_status() == BT_DEACTIVATING) { BT_DBG("Disabling in progress"); @@ -1362,32 +1467,10 @@ int _bt_recover_adapter(void) return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED; } - _bt_adapter_set_status(BT_DEACTIVATING); - - proxy = __bt_get_core_proxy(); - retv_if(!proxy, BLUETOOTH_ERROR_INTERNAL); - - result = g_dbus_proxy_call_sync(proxy, - "RecoverAdapter", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - &error); - - if (!result) { - if (error != NULL) { - BT_ERR("Failed to RecoverAdapter (Error: %s)", error->message); - g_clear_error(&error); - } else - BT_ERR("Failed to RecoverAdapter"); - return BLUETOOTH_ERROR_INTERNAL; - } - - is_recovery_mode = TRUE; + recovery_cnt = BT_RECOVERY_MAX_COUNT; - g_variant_unref(result); - __bt_disconnect_all(); + _bt_disable_adapter(); + _bt_disable_adapter_le(); BT_DBG("-"); return BLUETOOTH_ERROR_NONE; @@ -1513,6 +1596,7 @@ int _bt_enable_adapter_le(void) if (status == BT_DEACTIVATING || le_status == BT_LE_DEACTIVATING) { BT_ERR("Disabling in progress"); + _bt_set_le_intended_status(FALSE); return BLUETOOTH_ERROR_DEVICE_BUSY; } diff --git a/bt-service/bt-service-audio.c b/bt-service/bt-service-audio.c index 719a834..1cadaab 100644 --- a/bt-service/bt-service-audio.c +++ b/bt-service/bt-service-audio.c @@ -206,12 +206,6 @@ static void __bt_audio_request_cb(GDBusProxy *proxy, GAsyncResult *res, } check_req_info: - req_info = _bt_get_request_info(func_data->req_id); - if (req_info == NULL) { - BT_ERR("req_info == NULL"); - goto done; - } - if (g_error == NULL) goto dbus_return; @@ -241,8 +235,12 @@ check_req_info: /* Event will be sent by the event reciever */ dbus_return: - if (req_info->context == NULL) { - BT_DBG("req_info->context is NULL"); + req_info = _bt_get_request_info(func_data->req_id); + if (req_info == NULL) { + BT_ERR("req_info == NULL"); + goto done; + } else if (req_info->context == NULL) { + BT_ERR("req_info->context is NULL"); goto done; } @@ -445,8 +443,10 @@ static int __bt_is_headset_connected(int type, int req_id, node = g_list_next(node); } - if (!connected) + if (!connected) { + __bt_free_wait_data(); return BLUETOOTH_ERROR_NOT_CONNECTED; + } BT_DBG("connected headset %s", connected_address); @@ -815,6 +815,12 @@ int _bt_audio_connect(int request_id, int type, goto fail; } BT_INFO("Connecting to service %s", uuid); + /* First Check if device is in connecting state if it than return error */ + value = __bt_is_headset_connecting(type); + if (value != BLUETOOTH_ERROR_NONE) { + result = BLUETOOTH_ERROR_IN_PROGRESS; + goto fail; + } value = __bt_is_headset_connected(type, request_id, address); @@ -822,11 +828,6 @@ int _bt_audio_connect(int request_id, int type, result = BLUETOOTH_ERROR_ALREADY_CONNECT; goto fail; } else if (value == BLUETOOTH_ERROR_NOT_CONNECTED) { - value = __bt_is_headset_connecting(type); - if (value != BLUETOOTH_ERROR_NONE) { - result = BLUETOOTH_ERROR_IN_PROGRESS; - goto fail; - } _bt_headset_set_local_connection(TRUE); ret = _bt_connect_profile(address, uuid, __bt_audio_request_cb, func_data); diff --git a/bt-service/bt-service-device.c b/bt-service/bt-service-device.c index 896a228..e9ce2f1 100644 --- a/bt-service/bt-service-device.c +++ b/bt-service/bt-service-device.c @@ -90,11 +90,28 @@ typedef struct { gboolean auto_connect; } bt_pending_le_conn_info_s; +typedef struct { + char *address; + float interval_min; + float interval_max; + GSList *senders; +} bt_connected_le_dev_t; + +typedef struct { + char *sender; + float interval_min; + float interval_max; + guint16 latency; + guint16 time_out; + float key; +} bt_le_conn_param_t; + gboolean is_device_creating; bt_funcion_data_t *bonding_info; bt_funcion_data_t *searching_info; bt_funcion_data_t *att_mtu_req_info; +static GSList *le_connected_dev_list = NULL; static GSList *pin_info_list = NULL; static bt_pending_le_conn_info_s *pending_le_conn_info = NULL; static guint pending_le_conn_timer_id = 0; @@ -577,6 +594,8 @@ static int __bt_retry_bond(void) BT_CHECK_PARAMETER(bonding_info, return); BT_CHECK_PARAMETER(bonding_info->addr, return); + is_device_creating = TRUE; + g_dbus_proxy_call(bonding_info->device_proxy, "Pair", g_variant_new("(y)", bonding_info->conn_type), G_DBUS_CALL_FLAGS_NONE, @@ -856,8 +875,6 @@ dbus_return: g_dbus_method_invocation_return_value(req_info->context, g_variant_new("(iv)", result, out_param1)); - g_variant_unref(out_param1); - _bt_delete_request_list(req_info->req_id); done: if (err) @@ -1902,14 +1919,41 @@ fail: static gboolean __bt_connect_le_timer_cb(gpointer user_data) { + int ret; + BT_INFO("Try to initiate pending LE connection"); pending_le_conn_timer_id = 0; - __bt_connect_le_device_internal(pending_le_conn_info->req_id, - &pending_le_conn_info->bd_addr, - pending_le_conn_info->auto_connect); + ret = __bt_connect_le_device_internal(pending_le_conn_info->req_id, + &pending_le_conn_info->bd_addr, + pending_le_conn_info->auto_connect); + if (ret != BLUETOOTH_ERROR_NONE) { + request_info_t *req_info = NULL; + GVariant *out_param1; + + req_info = _bt_get_request_info(pending_le_conn_info->req_id); + if (req_info == NULL) { + BT_ERR("req_info is NULL"); + goto done; + } + + if (req_info->context == NULL) { + BT_ERR("req_info->context is NULL"); + _bt_delete_request_list(req_info->req_id); + goto done; + } + + out_param1 = g_variant_new_from_data((const GVariantType *)"ay", + &pending_le_conn_info->bd_addr, + sizeof(bluetooth_device_address_t), TRUE, + NULL, NULL); + + g_dbus_method_invocation_return_value(req_info->context, + g_variant_new("(iv)", ret, out_param1)); + } +done: g_free(pending_le_conn_info); pending_le_conn_info = NULL; @@ -1944,10 +1988,10 @@ int _bt_connect_le_device(int req_id, const bluetooth_device_address_t *bd_addr, g_timeout_add(1000, __bt_connect_le_timer_cb, NULL); return BLUETOOTH_ERROR_NONE; + } else if (ret != BLUETOOTH_ERROR_NOT_IN_OPERATION) { + BT_ERR("Unable to hold advertising"); } - BT_ERR("Unable to hold advertising"); - return __bt_connect_le_device_internal(req_id, bd_addr, auto_connect); } @@ -2339,59 +2383,24 @@ int _bt_get_rssi_strength(bluetooth_device_address_t *bd_addr, return ret; } -int _bt_le_conn_update(unsigned char *device_address, +static int __bt_le_set_conn_parameter(const char *address, float interval_min, float interval_max, guint16 latency, guint16 time_out) { - char address[BT_ADDRESS_STRING_SIZE] = { 0 }; gchar *device_path = NULL; GError *error = NULL; GDBusProxy *device_proxy = NULL; GDBusConnection *conn; GVariant *reply; guint32 min, max, to; - guint32 min_supervision_to; int ret = BLUETOOTH_ERROR_NONE; - BT_CHECK_PARAMETER(device_address, return); + BT_CHECK_PARAMETER(address, return); BT_INFO("Min interval: %f, Max interval: %f, Latency: %u, Supervision timeout: %u", interval_min, interval_max, latency, time_out); - if (interval_min > interval_max || - interval_min < BT_LE_CONN_INTERVAL_MIN || - interval_max > BT_LE_CONN_INTERVAL_MAX) { - ret = BLUETOOTH_ERROR_INVALID_PARAM; - goto fail; - } - - if (time_out < BT_LE_CONN_SUPER_TO_MIN || - time_out > BT_LE_CONN_SUPER_TO_MAX) { - ret = BLUETOOTH_ERROR_INVALID_PARAM; - goto fail; - } - - if (latency > BT_LE_CONN_SLAVE_LATENCY_MAX) { - ret = BLUETOOTH_ERROR_INVALID_PARAM; - goto fail; - } - - /* - * The Supervision_Timeout in milliseconds shall be larger than - * (1 + Conn_Latency) * Conn_Interval_Max * 2, - * where Conn_Interval_Max is given in milliseconds. - */ - min_supervision_to = (1 + latency) * interval_max * 2; - if (time_out <= min_supervision_to) { - ret = BLUETOOTH_ERROR_INVALID_PARAM; - goto fail; - } - - _bt_convert_addr_type_to_string(address, device_address); - - BT_DBG("Remote device address: %s", address); - - device_path = _bt_get_device_object_path(address); + device_path = _bt_get_device_object_path((char *)address); if (device_path == NULL) { BT_ERR("device_path NULL"); @@ -2442,6 +2451,306 @@ fail: return ret; } +static void __bt_le_conn_param_free(void *data) +{ + bt_le_conn_param_t *param = (bt_le_conn_param_t *)data; + + BT_DBG("%s", param->sender); + g_free(param->sender); + g_free(param); +} + +static gint __bt_compare_le_conn_param_key(gpointer *a, gpointer *b) +{ + bt_le_conn_param_t *parama = (bt_le_conn_param_t *)a; + bt_le_conn_param_t *paramb = (bt_le_conn_param_t *)b; + + return parama->key > paramb->key; +} + +static bt_connected_le_dev_t *__bt_get_le_connected_dev_info(const char *address) +{ + GSList *l = NULL; + bt_connected_le_dev_t *dev; + + if (!address) + return NULL; + + for (l = le_connected_dev_list; l; l = g_slist_next(l)) { + dev = l->data; + + if (g_strcmp0(dev->address, address) == 0) + return dev; + } + return NULL; +} + +static bt_le_conn_param_t *__bt_get_le_conn_param_info(bt_connected_le_dev_t *dev, const char *sender) +{ + GSList *l = NULL; + bt_le_conn_param_t *param = NULL; + + if (!dev || !sender) + return NULL; + + for (l = dev->senders; l; l = g_slist_next(l)) { + param = l->data; + if (g_strcmp0(param->sender, sender) == 0) + return param; + } + + return NULL; +} + +int _bt_add_le_conn_param_info(const char *address, const char *sender, + float interval_min, float interval_max, guint16 latency, guint16 time_out) +{ + bt_connected_le_dev_t *dev = NULL; + bt_le_conn_param_t *param = NULL; + bt_le_conn_param_t *data = NULL; + + if (!address || !sender) + return BLUETOOTH_ERROR_INVALID_PARAM; + + dev = __bt_get_le_connected_dev_info(address); + if (!dev) + return BLUETOOTH_ERROR_INTERNAL; + + param = __bt_get_le_conn_param_info(dev, sender); + + data = g_malloc0(sizeof(bt_le_conn_param_t)); + data->sender = g_strdup(sender); + data->interval_min = interval_min; + data->interval_max = interval_max; + data->latency = latency; + data->time_out = time_out; + data->key = interval_min + (interval_max - interval_min)/2; + + if (param == NULL) { + BT_DBG("Add param %s %s %f %f", address, sender, interval_min, interval_max); + dev->senders = g_slist_append(dev->senders, data); + } else { + BT_DBG("Update param %s %s %f %f", address, sender, interval_min, interval_max); + dev->senders = g_slist_remove(dev->senders, param); + g_free(param->sender); + g_free(param); + dev->senders = g_slist_append(dev->senders, data); + } + + /* Sorting. First element have the minimum interval */ + dev->senders = g_slist_sort(dev->senders, + (GCompareFunc)__bt_compare_le_conn_param_key); + + return BLUETOOTH_ERROR_NONE; +} + +int _bt_remove_le_conn_param_info(const char *address, const char *sender, gboolean *is_removed) +{ + bt_connected_le_dev_t *dev = NULL; + bt_le_conn_param_t *param = NULL; + + if (!address || !sender) + return BLUETOOTH_ERROR_INVALID_PARAM; + + dev = __bt_get_le_connected_dev_info(address); + if (!dev) + return BLUETOOTH_ERROR_INTERNAL; + + param = __bt_get_le_conn_param_info(dev, sender); + if (param) { + BT_DBG("Remove param %s %s ", address, sender); + dev->senders = g_slist_remove(dev->senders, param); + g_free(param->sender); + g_free(param); + *is_removed = TRUE; + } else + *is_removed = FALSE; + + return BLUETOOTH_ERROR_NONE; +} + +int _bt_remove_all_le_conn_param_info(const char *sender) +{ + GSList *l = NULL; + bt_connected_le_dev_t *dev = NULL; + bt_le_conn_param_t *param = NULL; + gboolean is_removed = FALSE; + char *sender_new = NULL; + unsigned char addr[BLUETOOTH_ADDRESS_LENGTH]; + int ret = BLUETOOTH_ERROR_NONE; + + if (!sender) + return BLUETOOTH_ERROR_INVALID_PARAM; + + for (l = le_connected_dev_list; l; l = g_slist_next(l)) { + dev = l->data; + _bt_remove_le_conn_param_info(dev->address, sender, &is_removed); + + if (is_removed) { + BT_INFO("Sender terminated. Update le conn interval [senders %d]", + g_slist_length(dev->senders)); + if (g_slist_length(dev->senders) > 0) { + param = dev->senders->data; + BT_DBG("dev %f %f, param %f %f", dev->interval_min, dev->interval_max, + param->interval_min, param->interval_max); + + if (dev->interval_min != param->interval_min || + dev->interval_max != param->interval_max) { + sender_new = g_strdup(param->sender); + + _bt_convert_addr_string_to_type(addr, dev->address); + ret = _bt_le_conn_update(sender_new, addr, + param->interval_min, param->interval_max, + param->latency, param->time_out); + g_free(sender_new); + + if (ret != BLUETOOTH_ERROR_NONE) + BT_ERR("Unable to set le connection parameter"); + } + } else { + BT_INFO("Set the default interval"); + + bluetooth_le_connection_param_t param = { 0 }; + _bt_get_le_connection_parameter( + BLUETOOTH_LE_CONNECTION_MODE_LOW_POWER, + ¶m); + + ret = __bt_le_set_conn_parameter(dev->address, + param.interval_min, param.interval_max, + param.latency, param.timeout); + if (ret == BLUETOOTH_ERROR_NONE) { + dev->interval_min = param.interval_min; + dev->interval_max = param.interval_max; + } + } + } + } + + return ret; +} + +void _bt_add_le_connected_dev_info(const char *address) +{ + bt_connected_le_dev_t *dev = NULL; + + if (!address) + return; + + dev = g_malloc0(sizeof(bt_connected_le_dev_t)); + dev->address = g_strdup(address); + + le_connected_dev_list = g_slist_append(le_connected_dev_list, dev); + + return; +} + +void _bt_remove_le_connected_dev_info(const char *address) +{ + bt_connected_le_dev_t *dev = NULL; + + if (!address) + return; + + dev = __bt_get_le_connected_dev_info(address); + if (!dev) + return; + + g_slist_free_full(dev->senders, __bt_le_conn_param_free); + le_connected_dev_list = g_slist_remove(le_connected_dev_list, dev); + g_free(dev->address); + g_free(dev); + + return; +} + +int _bt_le_conn_update(const char *sender, + unsigned char *device_address, + float interval_min, float interval_max, + guint16 latency, guint16 time_out) +{ + char address[BT_ADDRESS_STRING_SIZE] = { 0 }; + guint32 min_supervision_to; + bt_connected_le_dev_t *dev = NULL; + bt_le_conn_param_t *param = NULL; + gboolean is_removed = FALSE; + int ret = BLUETOOTH_ERROR_NONE; + + BT_CHECK_PARAMETER(device_address, return); + + BT_INFO("Sender %s, Min interval: %f, Max interval: %f, Latency: %u, Supervision timeout: %u", + sender, interval_min, interval_max, latency, time_out); + + if (interval_min > interval_max || + interval_min < BT_LE_CONN_INTERVAL_MIN || + interval_max > BT_LE_CONN_INTERVAL_MAX) { + ret = BLUETOOTH_ERROR_INVALID_PARAM; + goto fail; + } + + if (time_out < BT_LE_CONN_SUPER_TO_MIN || + time_out > BT_LE_CONN_SUPER_TO_MAX) { + ret = BLUETOOTH_ERROR_INVALID_PARAM; + goto fail; + } + + if (latency > BT_LE_CONN_SLAVE_LATENCY_MAX) { + ret = BLUETOOTH_ERROR_INVALID_PARAM; + goto fail; + } + + /* + * The Supervision_Timeout in milliseconds shall be larger than + * (1 + Conn_Latency) * Conn_Interval_Max * 2, + * where Conn_Interval_Max is given in milliseconds. + */ + min_supervision_to = (1 + latency) * interval_max * 2; + if (time_out <= min_supervision_to) { + ret = BLUETOOTH_ERROR_INVALID_PARAM; + goto fail; + } + + _bt_convert_addr_type_to_string(address, device_address); + BT_DBG("Remote device address: %s", address); + + _bt_add_le_conn_param_info(address, sender, interval_min, interval_max, 0, 2000); + + dev = __bt_get_le_connected_dev_info(address); + if (dev == NULL) { + ret = BLUETOOTH_ERROR_NOT_CONNECTED; + goto fail; + } + + if (g_slist_length(dev->senders) == 1) + goto update; + else { + param = dev->senders->data; + + BT_DBG("dev %f, param %f, input %f", dev->interval_min, param->interval_min, interval_min); + + if (dev->interval_min == param->interval_min && dev->interval_max == param->interval_max) { + BT_DBG("Skip due to same interval"); + return ret; + } + + interval_min = param->interval_min; + interval_max = param->interval_max; + } + +update: + ret = __bt_le_set_conn_parameter(address, interval_min, interval_max, latency, time_out); + + if (ret != BLUETOOTH_ERROR_NONE) { + _bt_remove_le_conn_param_info(address, sender, &is_removed); + return ret; + } + + dev->interval_min = interval_min; + dev->interval_max = interval_max; + +fail: + return ret; +} + int _bt_set_pin_code(bluetooth_device_address_t *device_address, bluetooth_device_pin_code_t *pin_code) { diff --git a/bt-service/bt-service-event-receiver.c b/bt-service/bt-service-event-receiver.c index a7944a5..835cbe6 100644 --- a/bt-service/bt-service-event-receiver.c +++ b/bt-service/bt-service-event-receiver.c @@ -409,36 +409,6 @@ void __bt_update_remote_cache_devinfo(const char *address, gboolean paired_statu BT_DBG("-"); } -static void __bt_device_remote_connected_properties( - bt_remote_dev_info_t *remote_dev_info, - char *address, gboolean connected) -{ - int result = BLUETOOTH_ERROR_NONE; - int i; - GVariant *param = NULL; - BT_DBG("+"); - - if (remote_dev_info->uuid_count > 0) { - for (i = 0; i < remote_dev_info->uuid_count; i++) { - char *uuid = remote_dev_info->uuids[i]; - if (strcasecmp(uuid, HID_UUID) == 0) { - int event = BLUETOOTH_EVENT_NONE; - - event = (connected == TRUE) ? - BLUETOOTH_HID_CONNECTED : - BLUETOOTH_HID_DISCONNECTED; - param = g_variant_new("(is)", result, - address); - _bt_send_event(BT_HID_EVENT, event, - param); - break; - } - } - } - - BT_DBG("-"); -} - gboolean __bt_handle_is_flight_mode_enabled(void) { int is_flight_mode = 0; @@ -638,6 +608,9 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path) g_variant_get(val, "b", &discovering); /* Send event to application */ BT_DBG("Discovering %d", discovering); + if (_bt_adapter_get_status() != BT_ACTIVATED) + return; + if (discovering == TRUE) { _bt_set_discovery_status(TRUE); param = g_variant_new("(i)", result); @@ -670,6 +643,11 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path) gboolean le_discovering = FALSE; g_variant_get(val, "b", &le_discovering); + BT_DBG("LEDiscovering %d", le_discovering); + if (_bt_adapter_get_status() != BT_ACTIVATED || + _bt_adapter_get_le_status() != BT_LE_ACTIVATED) + return; + /* Send event to application */ if (le_discovering == TRUE) { _bt_set_le_scan_status(TRUE); @@ -922,7 +900,6 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path) char *property = NULL; char *address; GVariant *param = NULL; - bt_remote_dev_info_t *remote_dev_info; g_variant_iter_init(&value_iter, msg); #ifdef TIZEN_FEATURE_BT_DPM int desktop_state = DPM_BT_ERROR; @@ -945,15 +922,6 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path) BT_DBG("connected: %d", connected); BT_DBG("address: %s", address); - remote_dev_info = _bt_get_remote_device_info_by_object_path(path); - - if (remote_dev_info != NULL) { - __bt_device_remote_connected_properties( - remote_dev_info, address, - connected != BLUETOOTH_CONNECTED_LINK_NONE ? - TRUE : FALSE); - _bt_free_device_info(remote_dev_info); - } param = g_variant_new("(is)", result, address); /* Send event to application */ _bt_send_event(BT_DEVICE_EVENT, @@ -1274,7 +1242,6 @@ static void __bt_media_control_changed_event(GVariant *msg, const char *path) char *address; GVariant *val = NULL; GVariant *child = NULL; - bt_remote_dev_info_t *remote_dev_info; GVariant *param = NULL; g_variant_iter_init(&value_iter, msg); while ((child = g_variant_iter_next_value(&value_iter))) { @@ -1295,13 +1262,6 @@ static void __bt_media_control_changed_event(GVariant *msg, const char *path) BT_DBG("connected: %d", connected); BT_DBG("address: %s", address); - remote_dev_info = _bt_get_remote_device_info(address); - - if (remote_dev_info != NULL) { - __bt_device_remote_connected_properties( - remote_dev_info, address, connected); - _bt_free_device_info(remote_dev_info); - } param = g_variant_new("(is)", result, address); /* Send event to application */ _bt_send_event(BT_AVRCP_EVENT, @@ -1880,6 +1840,9 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path !addr_type ? dev_name : secure_address); g_free(dev_name); + if (addr_type) + _bt_add_le_connected_dev_info(address); + _bt_logging_connection(TRUE, addr_type); param = g_variant_new("(isy)", result, address, addr_type); /*Send event to application*/ @@ -1914,7 +1877,9 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path _bt_headset_set_local_connection(FALSE); _bt_logging_connection(FALSE, addr_type); - if (!addr_type) { + if (addr_type) + _bt_remove_le_connected_dev_info(address); + else { #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT { int bt_device_state = VCONFKEY_BT_DEVICE_NONE; @@ -2475,7 +2440,6 @@ void _bt_handle_headset_event(GVariant *msg, const char *path) wait_list->address); _bt_audio_connect(wait_list->req_id, wait_list->type, &device_address, NULL); - _bt_rel_wait_data(); } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) { /* Add data to the connected list */ _bt_add_headset_to_list(BT_AUDIO_HSP, @@ -2943,11 +2907,13 @@ static void __bt_manager_event_filter(GDBusConnection *connection, BT_INFO_C("### Bluetoothd is terminated"); if (_bt_adapter_get_status() != BT_DEACTIVATING && _bt_adapter_get_status() != BT_DEACTIVATED) { - BT_INFO_C("### Recover it"); - _bt_recover_adapter(); + BT_INFO_C("Turn Off Bluetooth"); + _bt_set_le_disabled(BLUETOOTH_ERROR_NONE); + _bt_disable_cb(); } _bt_handle_adapter_removed(); __bt_devices_list_free(); + _bt_service_adapter_le_deinit(); } _bt_obex_server_check_allocation(&value); @@ -2964,6 +2930,9 @@ static void __bt_manager_event_filter(GDBusConnection *connection, _bt_rfcomm_server_check_termination(name); } + /* Reset connection interval */ + _bt_remove_all_le_conn_param_info(name); + /* Stop advertising started by terminated process */ _bt_stop_advertising_by_terminated_process(name); /* Stop LE Scan */ @@ -3280,50 +3249,50 @@ int _bt_register_manager_subscribe_signal(GDBusConnection *conn, if (conn == NULL) return -1; - static int subs_interface_added_id = -1; - static int subs_interface_removed_id = -1; - static int subs_name_owner_id = -1; - static int subs_property_id = -1; - static int subs_adapter_id = -1; - static int subs_gatt_id = -1; + static guint subs_interface_added_id; + static guint subs_interface_removed_id; + static guint subs_name_owner_id; + static guint subs_property_id; + static guint subs_adapter_id; + static guint subs_gatt_id; if (subscribe) { - if (subs_interface_added_id == -1) { + if (subs_interface_added_id == 0) { subs_interface_added_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_MANAGER_INTERFACE, BT_INTERFACES_ADDED, NULL, NULL, 0, __bt_manager_event_filter, NULL, NULL); } - if (subs_interface_removed_id == -1) { + if (subs_interface_removed_id == 0) { subs_interface_removed_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_MANAGER_INTERFACE, BT_INTERFACES_REMOVED, NULL, NULL, 0, __bt_manager_event_filter, NULL, NULL); } - if (subs_name_owner_id == -1) { + if (subs_name_owner_id == 0) { subs_name_owner_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_FREEDESKTOP_INTERFACE, BT_NAME_OWNER_CHANGED, NULL, NULL, 0, __bt_manager_event_filter, NULL, NULL); } - if (subs_property_id == -1) { + if (subs_property_id == 0) { subs_property_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_PROPERTIES_INTERFACE, BT_PROPERTIES_CHANGED, NULL, NULL, 0, __bt_manager_event_filter, NULL, NULL); } - if (subs_adapter_id == -1) { + if (subs_adapter_id == 0) { subs_adapter_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_ADAPTER_INTERFACE, NULL, NULL, NULL, 0, __bt_manager_event_filter, NULL, NULL); } - if (subs_gatt_id == -1) { + if (subs_gatt_id == 0) { subs_gatt_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_GATT_CHAR_INTERFACE, NULL, NULL, NULL, 0, @@ -3331,33 +3300,33 @@ int _bt_register_manager_subscribe_signal(GDBusConnection *conn, NULL, NULL); } } else { - if (subs_interface_added_id != -1) { + if (subs_interface_added_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subs_interface_added_id); - subs_interface_added_id = -1; + subs_interface_added_id = 0; } - if (subs_interface_removed_id != -1) { + if (subs_interface_removed_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subs_interface_removed_id); - subs_interface_removed_id = -1; + subs_interface_removed_id = 0; } - if (subs_name_owner_id != -1) { + if (subs_name_owner_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subs_name_owner_id); - subs_name_owner_id = -1; + subs_name_owner_id = 0; } - if (subs_property_id != -1) { + if (subs_property_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subs_property_id); - subs_property_id = -1; + subs_property_id = 0; } - if (subs_adapter_id != -1) { + if (subs_adapter_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subs_adapter_id); - subs_adapter_id = -1; + subs_adapter_id = 0; } - if (subs_gatt_id != -1) { + if (subs_gatt_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subs_gatt_id); - subs_gatt_id = -1; + subs_gatt_id = 0; } } return 0; @@ -3369,10 +3338,10 @@ int _bt_register_device_subscribe_signal(GDBusConnection *conn, if (conn == NULL) return -1; - static int subs_device_id = -1; + static guint subs_device_id = 0; if (subscribe) { - if (subs_device_id == -1) { + if (subs_device_id == 0) { subs_device_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_DEVICE_INTERFACE, NULL, NULL, NULL, 0, @@ -3380,10 +3349,10 @@ int _bt_register_device_subscribe_signal(GDBusConnection *conn, NULL, NULL); } } else { - if (subs_device_id != -1) { + if (subs_device_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subs_device_id); - subs_device_id = -1; + subs_device_id = 0; } } return 0; @@ -3395,10 +3364,10 @@ int _bt_register_input_subscribe_signal(GDBusConnection *conn, if (conn == NULL) return -1; - static int subs_input_id = -1; + static int subs_input_id = 0; if (subscribe) { - if (subs_input_id == -1) { + if (subs_input_id == 0) { subs_input_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_INPUT_INTERFACE, NULL, NULL, NULL, 0, @@ -3406,10 +3375,10 @@ int _bt_register_input_subscribe_signal(GDBusConnection *conn, NULL, NULL); } } else { - if (subs_input_id != -1) { + if (subs_input_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subs_input_id); - subs_input_id = -1; + subs_input_id = 0; } } return 0; @@ -3421,18 +3390,18 @@ int _bt_register_network_subscribe_signal(GDBusConnection *conn, if (conn == NULL) return -1; - static int subs_serv_id = -1; - static int subs_client_id = -1; + static guint subs_serv_id = 0; + static guint subs_client_id = 0; if (subscribe) { - if (subs_serv_id == -1) { + if (subs_serv_id == 0) { subs_serv_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_NETWORK_SERVER_INTERFACE, NULL, NULL, NULL, 0, __bt_manager_event_filter, NULL, NULL); } - if (subs_client_id == -1) { + if (subs_client_id == 0) { subs_client_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_NETWORK_CLIENT_INTERFACE, NULL, NULL, NULL, 0, @@ -3440,15 +3409,15 @@ int _bt_register_network_subscribe_signal(GDBusConnection *conn, NULL, NULL); } } else { - if (subs_serv_id != -1) { + if (subs_serv_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subs_serv_id); - subs_serv_id = -1; + subs_serv_id = 0; } - if (subs_client_id != -1) { + if (subs_client_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subs_client_id); - subs_client_id = -1; + subs_client_id = 0; } } return 0; @@ -3460,18 +3429,18 @@ int _bt_register_audio_subscribe_signal(GDBusConnection *conn, if (conn == NULL) return -1; - static int subs_headset_id = -1; - static int subs_sink_id = -1; + static guint subs_headset_id = 0; + static guint subs_sink_id = 0; if (subscribe) { - if (subs_headset_id == -1) { + if (subs_headset_id == 0) { subs_headset_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_HEADSET_INTERFACE, NULL, NULL, NULL, 0, __bt_manager_event_filter, NULL, NULL); } - if (subs_sink_id == -1) { + if (subs_sink_id == 0) { subs_sink_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_SINK_INTERFACE, NULL, NULL, NULL, 0, @@ -3479,15 +3448,15 @@ int _bt_register_audio_subscribe_signal(GDBusConnection *conn, NULL, NULL); } } else { - if (subs_headset_id != -1) { + if (subs_headset_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subs_headset_id); - subs_headset_id = -1; + subs_headset_id = 0; } - if (subs_sink_id != -1) { + if (subs_sink_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subs_sink_id); - subs_sink_id = -1; + subs_sink_id = 0; } } return 0; @@ -3499,27 +3468,27 @@ int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn, if (conn == NULL) return -1; - static int subs_opp_server_interface_added_id = -1; - static int subs_opp_server_interface_removed_id = -1; - static int subs_opp_server_property_id = -1; + static guint subs_opp_server_interface_added_id = 0; + static guint subs_opp_server_interface_removed_id = 0; + static guint subs_opp_server_property_id = 0; if (subscribe) { - if (subs_opp_server_interface_added_id == -1) { + if (subs_opp_server_interface_added_id == 0) { subs_opp_server_interface_added_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_MANAGER_INTERFACE, BT_INTERFACES_ADDED, NULL, NULL, 0, __bt_obexd_event_filter, NULL, NULL); } - if (subs_opp_server_interface_removed_id == -1) { + if (subs_opp_server_interface_removed_id == 0) { subs_opp_server_interface_removed_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_MANAGER_INTERFACE, BT_INTERFACES_REMOVED, NULL, NULL, 0, __bt_obexd_event_filter, NULL, NULL); } - if (subs_opp_server_property_id == -1) { + if (subs_opp_server_property_id == 0) { subs_opp_server_property_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_PROPERTIES_INTERFACE, BT_PROPERTIES_CHANGED, NULL, NULL, 0, @@ -3527,20 +3496,20 @@ int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn, NULL, NULL); } } else { - if (subs_opp_server_interface_added_id != -1) { + if (subs_opp_server_interface_added_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subs_opp_server_interface_added_id); - subs_opp_server_interface_added_id = -1; + subs_opp_server_interface_added_id = 0; } - if (subs_opp_server_interface_removed_id != -1) { + if (subs_opp_server_interface_removed_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subs_opp_server_interface_removed_id); - subs_opp_server_interface_removed_id = -1; + subs_opp_server_interface_removed_id = 0; } - if (subs_opp_server_property_id != -1) { + if (subs_opp_server_property_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subs_opp_server_property_id); - subs_opp_server_property_id = -1; + subs_opp_server_property_id = 0; } } return 0; @@ -3552,27 +3521,27 @@ int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn, if (conn == NULL) return -1; - static int subs_opp_client_interface_added_id = -1; - static int subs_opp_client_interface_removed_id = -1; - static int subs_opp_client_property_id = -1; + static guint subs_opp_client_interface_added_id = 0; + static guint subs_opp_client_interface_removed_id = 0; + static guint subs_opp_client_property_id = 0; if (subscribe) { - if (subs_opp_client_interface_added_id == -1) { + if (subs_opp_client_interface_added_id == 0) { subs_opp_client_interface_added_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_MANAGER_INTERFACE, BT_INTERFACES_ADDED, NULL, NULL, 0, __bt_opc_event_filter, NULL, NULL); } - if (subs_opp_client_interface_removed_id == -1) { + if (subs_opp_client_interface_removed_id == 0) { subs_opp_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_MANAGER_INTERFACE, BT_INTERFACES_REMOVED, NULL, NULL, 0, __bt_opc_event_filter, NULL, NULL); } - if (subs_opp_client_property_id == -1) { + if (subs_opp_client_property_id == 0) { subs_opp_client_property_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_PROPERTIES_INTERFACE, BT_PROPERTIES_CHANGED, NULL, NULL, 0, @@ -3580,20 +3549,20 @@ int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn, NULL, NULL); } } else { - if (subs_opp_client_interface_added_id != -1) { + if (subs_opp_client_interface_added_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subs_opp_client_interface_added_id); - subs_opp_client_interface_added_id = -1; + subs_opp_client_interface_added_id = 0; } - if (subs_opp_client_interface_removed_id != -1) { + if (subs_opp_client_interface_removed_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subs_opp_client_interface_removed_id); - subs_opp_client_interface_removed_id = -1; + subs_opp_client_interface_removed_id = 0; } - if (subs_opp_client_property_id != -1) { + if (subs_opp_client_property_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subs_opp_client_property_id); - subs_opp_client_property_id = -1; + subs_opp_client_property_id = 0; } } return 0; @@ -3605,27 +3574,27 @@ int _bt_register_map_client_subscribe_signal(GDBusConnection *conn, if (conn == NULL) return -1; - static int subs_map_client_interface_added_id = -1; - static int subs_map_client_interface_removed_id = -1; - static int subs_map_client_property_id = -1; + static guint subs_map_client_interface_added_id = 0; + static guint subs_map_client_interface_removed_id = 0; + static guint subs_map_client_property_id = 0; if (subscribe) { - if (subs_map_client_interface_added_id == -1) { + if (subs_map_client_interface_added_id == 0) { subs_map_client_interface_added_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_MANAGER_INTERFACE, BT_INTERFACES_ADDED, NULL, NULL, 0, __bt_map_event_filter, NULL, NULL); } - if (subs_map_client_interface_removed_id == -1) { + if (subs_map_client_interface_removed_id == 0) { subs_map_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_MANAGER_INTERFACE, BT_INTERFACES_REMOVED, NULL, NULL, 0, __bt_map_event_filter, NULL, NULL); } - if (subs_map_client_property_id == -1) { + if (subs_map_client_property_id == 0) { subs_map_client_property_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_PROPERTIES_INTERFACE, BT_PROPERTIES_CHANGED, NULL, NULL, 0, @@ -3633,20 +3602,20 @@ int _bt_register_map_client_subscribe_signal(GDBusConnection *conn, NULL, NULL); } } else { - if (subs_map_client_interface_added_id != -1) { + if (subs_map_client_interface_added_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subs_map_client_interface_added_id); - subs_map_client_interface_added_id = -1; + subs_map_client_interface_added_id = 0; } - if (subs_map_client_interface_removed_id != -1) { + if (subs_map_client_interface_removed_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subs_map_client_interface_removed_id); - subs_map_client_interface_removed_id = -1; + subs_map_client_interface_removed_id = 0; } - if (subs_map_client_property_id != -1) { + if (subs_map_client_property_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subs_map_client_property_id); - subs_map_client_property_id = -1; + subs_map_client_property_id = 0; } } return 0; @@ -3658,18 +3627,18 @@ int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn, if (conn == NULL) return -1; - static int subs_a2dp_source_id = -1; - static int subs_a2dp_sink_id = -1; + static guint subs_a2dp_source_id = 0; + static guint subs_a2dp_sink_id = 0; if (subscribe) { - if (subs_a2dp_source_id == -1) { + if (subs_a2dp_source_id == 0) { subs_a2dp_source_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_A2DP_SOURCE_INTERFACE, NULL, NULL, NULL, 0, __bt_opc_event_filter, NULL, NULL); } - if (subs_a2dp_sink_id == -1) { + if (subs_a2dp_sink_id == 0) { subs_a2dp_sink_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_SINK_INTERFACE, NULL, NULL, NULL, 0, @@ -3677,15 +3646,15 @@ int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn, NULL, NULL); } } else { - if (subs_a2dp_source_id != -1) { + if (subs_a2dp_source_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subs_a2dp_source_id); - subs_a2dp_source_id = -1; + subs_a2dp_source_id = 0; } - if (subs_a2dp_sink_id != -1) { + if (subs_a2dp_sink_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subs_a2dp_sink_id); - subs_a2dp_sink_id = -1; + subs_a2dp_sink_id = 0; } } return 0; @@ -3696,10 +3665,10 @@ int _bt_register_tds_provider_subscribe_signal(GDBusConnection *conn, int subscr if (conn == NULL) return -1; - static int subs_custom_id = -1; + static guint subs_custom_id = 0; if (subscribe) { - if (subs_custom_id == -1) { + if (subs_custom_id == 0) { subs_custom_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_TDS_PROVIDER_INTERFACE, NULL, NULL, NULL, 0, @@ -3707,10 +3676,10 @@ int _bt_register_tds_provider_subscribe_signal(GDBusConnection *conn, int subscr NULL, NULL); } } else { - if (subs_custom_id != -1) { + if (subs_custom_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subs_custom_id); - subs_custom_id = -1; + subs_custom_id = 0; } } @@ -3734,10 +3703,10 @@ int __bt_register_dump_subscribe_signal(GDBusConnection *conn, if (conn == NULL) return -1; - static int subs_source_id = -1; + static guint subs_source_id = 0; if (subscribe) { - if (subs_source_id == -1) { + if (subs_source_id == 0) { subs_source_id = g_dbus_connection_signal_subscribe(conn, NULL, BT_DUMP_SERVICE_INTERFACE, BT_DUMP_SERVICE_SIGNAL, BT_DUMP_SERVICE_PATH, NULL, 0, @@ -3745,10 +3714,10 @@ int __bt_register_dump_subscribe_signal(GDBusConnection *conn, NULL, NULL); } } else { - if (subs_source_id != -1) { + if (subs_source_id > 0) { g_dbus_connection_signal_unsubscribe(conn, subs_source_id); - subs_source_id = -1; + subs_source_id = 0; } } return 0; diff --git a/bt-service/bt-service-main.c b/bt-service/bt-service-main.c index 9b10d6d..b9d9fb5 100644 --- a/bt-service/bt-service-main.c +++ b/bt-service/bt-service-main.c @@ -130,6 +130,11 @@ static gboolean __bt_check_bt_service(void *data) int ps_mode_deactivation = 0; #endif + if (_is_name_acquired() == FALSE) { + BT_ERR("dbus name is NOT acquired yet"); + return TRUE; + } + status = _bt_adapter_get_status(); le_status = _bt_adapter_get_le_status(); BT_DBG("State: %d, LE State: %d", status, le_status); @@ -156,6 +161,15 @@ static gboolean __bt_check_bt_service(void *data) if (vconf_get_int(BT_OFF_DUE_TO_TIMEOUT, &bt_off_due_to_timeout) != 0) BT_ERR("Fail to get BT_OFF_DUE_TO_TIMEOUT"); + if (bt_off_due_to_timeout) { + /* Set the vconf flag to 0 here, if BT need to be enabled + bt_off_due_to_timeout variable already hold the old value */ + + if (vconf_set_int(BT_OFF_DUE_TO_TIMEOUT, 0) != 0) + BT_ERR("Set vconf failed"); + } + + if ((bt_status != VCONFKEY_BT_STATUS_OFF || bt_off_due_to_timeout) && (status == BT_DEACTIVATED)) { BT_DBG("Previous session was enabled."); diff --git a/bt-service/bt-service-network.c b/bt-service/bt-service-network.c index 18875c7..439218d 100644 --- a/bt-service/bt-service-network.c +++ b/bt-service/bt-service-network.c @@ -148,8 +148,9 @@ static void __bt_network_connect_cb(GDBusProxy *proxy, GAsyncResult *res, g_clear_error(&g_error); } result = BLUETOOTH_ERROR_INTERNAL; + } else { + g_variant_unref(reply); } - g_variant_unref(reply); func_data = user_data; if (func_data == NULL) { @@ -207,8 +208,9 @@ static void __bt_network_disconnect_cb(GDBusProxy *proxy, GAsyncResult *res, g_clear_error(&g_error); } result = BLUETOOTH_ERROR_INTERNAL; + } else { + g_variant_unref(reply); } - g_variant_unref(reply); func_data = user_data; if (func_data == NULL) { diff --git a/bt-service/include/bt-request-handler.h b/bt-service/include/bt-request-handler.h old mode 100755 new mode 100644 index 2d769f4..a984c14 --- a/bt-service/include/bt-request-handler.h +++ b/bt-service/include/bt-request-handler.h @@ -32,6 +32,8 @@ extern "C" { #define BT_SERVICE_NAME "org.projectx.bt" #define BT_SERVICE_PATH "/org/projectx/bt_service" +gboolean _is_name_acquired(void); + int _bt_service_register(void); void _bt_service_unregister(void); diff --git a/bt-service/include/bt-service-device.h b/bt-service/include/bt-service-device.h index ab78174..477d055 100644 --- a/bt-service/include/bt-service-device.h +++ b/bt-service/include/bt-service-device.h @@ -88,7 +88,12 @@ int _bt_connect_le_device(int req_id, const bluetooth_device_address_t *bd_addr, int _bt_disconnect_le_device(int req_id, const bluetooth_device_address_t *bd_addr); -int _bt_le_conn_update(unsigned char *device_address, +void _bt_add_le_connected_dev_info(const char *address); +void _bt_remove_le_connected_dev_info(const char *address); +int _bt_remove_all_le_conn_param_info(const char *sender); + +int _bt_le_conn_update(const char *sender, + unsigned char *device_address, float interval_min, float interval_max, guint16 latency, guint16 time_out); diff --git a/include/bluetooth-api.h b/include/bluetooth-api.h index 8cbbd7b..59d7e3a 100644 --- a/include/bluetooth-api.h +++ b/include/bluetooth-api.h @@ -1321,7 +1321,9 @@ typedef enum { HTYPE_TRANS_GET_PROTOCOL, HTYPE_TRANS_SET_PROTOCOL, HTYPE_TRANS_DATA, - HTYPE_TRANS_UNKNOWN + HTYPE_TRANS_UNKNOWN, + HTYPE_TRANS_GET_IDLE = 0xF0, + HTYPE_TRANS_SET_IDLE = 0xF1, } bt_hid_header_type_t; /** @@ -1643,6 +1645,15 @@ typedef struct { } bt_gatt_indicate_confirm_t; /** + * Structure for GATT response data + */ +typedef struct { + guint8 *value; + guint32 len; + gpointer user_data; +} bt_gatt_resp_data_t; + +/** * Structure to RSSI Signal Strength Alert */ diff --git a/test/bluetooth-frwk-test.c b/test/bluetooth-frwk-test.c index eeeda98..ea4dba1 100644 --- a/test/bluetooth-frwk-test.c +++ b/test/bluetooth-frwk-test.c @@ -562,7 +562,7 @@ int test_input_callback(void *data) ret = bluetooth_authorize_device(&device_address, FALSE); if (ret < 0) TC_PRT("%s failed with [0x%04x]", tc_table[23].tc_name, ret); - break; + break; } case 25: { @@ -1168,6 +1168,8 @@ int test_input_callback(void *data) TC_PRT("service obj_path is %s", svc_obj_path); + g_free(service_uuid); + break; }