X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=bt-service%2Fbt-service-event-receiver.c;h=0581b01af20d007187be50cd9b4be26f9c01cccb;hb=0571628caff05a8a62926837db59e8ca95329e96;hp=de50bc748a5659bddb5a332b8fb20bbcda6e0677;hpb=b382c11b0b3e2f45e1e5889ca04d7fa43cd4dd60;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git diff --git a/bt-service/bt-service-event-receiver.c b/bt-service/bt-service-event-receiver.c old mode 100755 new mode 100644 index de50bc7..0581b01 --- a/bt-service/bt-service-event-receiver.c +++ b/bt-service/bt-service-event-receiver.c @@ -38,9 +38,14 @@ #include "bt-service-pbap.h" #include "bt-service-headset-connection.h" #include "bt-service-avrcp-controller.h" +#include "bt-service-hid.h" #include "bt-service-opp-client.h" +#ifdef TIZEN_DPM_ENABLE +#include "bt-service-dpm.h" +#endif + #define DBUS_TIMEOUT 20 * 1000 /* 20 Sec */ static GDBusConnection *manager_conn; static GDBusConnection *obexd_conn; @@ -49,9 +54,10 @@ static GDBusConnection *opc_obexd_conn; static GList *p_cache_list = NULL; static guint event_id; +static guint session_reinit_timer; guint nap_connected_device_count = 0; static guint hid_connected_device_count = 0; -static GList *p_adv_ind_list; +static GList *p_adv_ind_list = NULL; typedef struct { bt_remote_dev_info_t *dev_info; @@ -81,8 +87,14 @@ void _bt_handle_network_client_event(GVariant *msg_iter, void __bt_gatt_char_property_changed_event(GVariant *msg_iter, const char *path); -static void __bt_free_bt_le_adv_info_t(bt_le_adv_info_t *adv_info) +static void __bt_free_bt_le_adv_info_t(gpointer data) { + bt_le_adv_info_t *adv_info = data; + + if (adv_info->timer_id) + g_source_remove(adv_info->timer_id); + adv_info->timer_id = 0; + g_free(adv_info->addr); g_free(adv_info->data); g_free(adv_info); @@ -93,23 +105,25 @@ static bt_le_adv_info_t *__bt_get_adv_ind_info(char *addr) retv_if(!addr, NULL); bt_le_adv_info_t *adv_info = NULL; GList *current = g_list_first((GList *)p_adv_ind_list); - while(current && current->data) { + while (current && current->data) { adv_info = (bt_le_adv_info_t *)current->data; - retv_if(adv_info && !g_strcmp0(adv_info->addr, addr), adv_info); + if (adv_info && !g_strcmp0(adv_info->addr, addr)) + return adv_info; current = g_list_next(current); } return NULL; } -static void __bt_add_adv_ind_info(bt_le_adv_info_t *adv_info) +static int __bt_add_adv_ind_info(bt_le_adv_info_t *adv_info) { - ret_if(!adv_info); + retv_if(!adv_info, -1); if (__bt_get_adv_ind_info(adv_info->addr) != NULL) { - BT_ERR("adv_info is already added"); __bt_free_bt_le_adv_info_t(adv_info); - return; + return -1; } p_adv_ind_list = g_list_append(p_adv_ind_list, adv_info); + + return 0; } static void __bt_del_adv_ind_info(char *addr) @@ -118,7 +132,7 @@ static void __bt_del_adv_ind_info(char *addr) ret_if(!p_adv_ind_list); bt_le_adv_info_t *adv_info = NULL; GList *current = g_list_first((GList *)p_adv_ind_list); - while(current && current->data) { + while (current && current->data) { adv_info = (bt_le_adv_info_t *)current->data; if (adv_info && !g_strcmp0(adv_info->addr, addr)) { p_adv_ind_list = g_list_remove(p_adv_ind_list, adv_info); @@ -129,6 +143,26 @@ static void __bt_del_adv_ind_info(char *addr) } } +static gboolean __bt_adv_scan_req_timeout_cb(gpointer user_data) +{ + bt_remote_le_dev_info_t le_dev_info; + bt_le_adv_info_t *adv_info = (bt_le_adv_info_t*)user_data; + + memset(&le_dev_info, 0x00, sizeof(bt_remote_le_dev_info_t)); + + le_dev_info.address = adv_info->addr; + le_dev_info.addr_type = adv_info->addr_type; + le_dev_info.rssi = adv_info->rssi; + le_dev_info.adv_data = adv_info->data; + le_dev_info.adv_data_len = 0; + adv_info->timer_id = 0; + + _bt_send_scan_result_event(&le_dev_info, adv_info); + __bt_del_adv_ind_info(adv_info->addr); + + return FALSE; +} + static void __bt_free_cache_info(bt_cache_info_t *cache_info) { ret_if(cache_info == NULL); @@ -156,7 +190,7 @@ static gboolean __bt_parse_device_properties(GVariant *item, if (dev_info->name == NULL) dev_info->name = g_variant_dup_string(val, &len); } else if (strcasecmp(key, "Connected") == 0) { - dev_info->connected = g_variant_get_uint32(val); + dev_info->connected = g_variant_get_byte(val); } else if (strcasecmp(key, "paired") == 0) { dev_info->paired = g_variant_get_boolean(val); } else if (strcasecmp(key, "Trusted") == 0) { @@ -168,7 +202,7 @@ static gboolean __bt_parse_device_properties(GVariant *item, } else if (strcasecmp(key, "UUIDs") == 0) { char **uuid_value; gsize size = 0; - int i =0; + int i = 0; size = g_variant_get_size(val); if (size > 0) { @@ -183,7 +217,7 @@ static gboolean __bt_parse_device_properties(GVariant *item, g_free(uuid_value); } } else if (strcasecmp(key, "ManufacturerDataLen") == 0) { - g_variant_get(val, "(i)", &dev_info->manufacturer_data_len); + g_variant_get(val, "q", &dev_info->manufacturer_data_len); if (dev_info->manufacturer_data_len > BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) { BT_ERR("manufacturer_data_len is too long(len = %d)", dev_info->manufacturer_data_len); dev_info->manufacturer_data_len = BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX; @@ -192,18 +226,21 @@ static gboolean __bt_parse_device_properties(GVariant *item, if (dev_info->manufacturer_data_len == 0) dev_info->manufacturer_data = g_strdup(""); } else if (strcasecmp(key, "ManufacturerData") == 0) { + int i = 0; int len = 0; - GVariant *manufacturer_var; - g_variant_get(val, "@ay", &manufacturer_var); - len = g_variant_get_size(manufacturer_var); - if (len > 0) { - char *manufacturer_data = (char *)g_variant_get_data(manufacturer_var); - dev_info->manufacturer_data = g_malloc0(len); - if (dev_info->manufacturer_data) - memcpy(dev_info->manufacturer_data, manufacturer_data, - len); - } - g_variant_unref(manufacturer_var); + GVariantIter *value_iter; + guint8 m_value; + + len = g_variant_get_size(val); + if (len <= 0) + continue; + + dev_info->manufacturer_data = g_malloc0(len); + + g_variant_get(val, "ay", &value_iter); + while (g_variant_iter_loop(value_iter, "y", &m_value)) + dev_info->manufacturer_data[i++] = m_value; + g_variant_iter_free(value_iter); } } @@ -215,17 +252,19 @@ static gboolean __bt_parse_interface(GVariant *msg, bt_remote_dev_info_t *dev_info) { char *path = NULL; - GVariant *optional_param; + GVariant *optional_param = NULL; GVariantIter iter; GVariant *child; - char *interface_name= NULL; + char *interface_name = NULL; GVariant *inner_iter = NULL; g_variant_get(msg, "(&o@a{sa{sv}})", &path, &optional_param); g_variant_iter_init(&iter, optional_param); + retv_if(optional_param == NULL, FALSE); + while ((child = g_variant_iter_next_value(&iter))) { - g_variant_get(child,"{&s@a{sv}}", &interface_name, &inner_iter); + g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter); if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) { BT_DBG("Found a device: %s", path); if (__bt_parse_device_properties(inner_iter, @@ -243,7 +282,7 @@ static gboolean __bt_parse_interface(GVariant *msg, } } g_variant_unref(inner_iter); - g_variant_unref(child); + g_variant_unref(child); } g_variant_unref(optional_param); @@ -314,6 +353,9 @@ static gboolean __bt_le_discovery_finished_cb(gpointer user_data) result = BLUETOOTH_ERROR_CANCEL_BY_USER; } + g_list_free_full(p_adv_ind_list, __bt_free_bt_le_adv_info_t); + p_adv_ind_list = NULL; + _bt_set_cancel_by_user(FALSE); _bt_disable_all_scanner_status(); _bt_set_le_scan_status(FALSE); @@ -338,7 +380,7 @@ void __bt_update_remote_cache_devinfo(const char *address, gboolean paired_statu node = g_list_first(p_cache_list); - while (node != NULL){ + while (node != NULL) { cache_info = (bt_cache_info_t *)node->data; if (cache_info == NULL) { @@ -370,10 +412,10 @@ static void __bt_device_remote_connected_properties( GVariant *param = NULL; BT_DBG("+"); - if (remote_dev_info->uuid_count > 0 ) { - for (i = 0; iuuid_count; i++) { + 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){ + if (strcasecmp(uuid, HID_UUID) == 0) { int event = BLUETOOTH_EVENT_NONE; event = (connected == TRUE) ? @@ -412,7 +454,7 @@ void _bt_handle_adapter_event(GVariant *msg, const char *member) g_variant_get(msg, "(&o)", &object_path); _bt_convert_device_path_to_address((const char*)object_path, address); - remote_dev_info = _bt_get_remote_device_info(address); + remote_dev_info = _bt_get_remote_device_info_by_object_path(object_path); if (remote_dev_info == NULL) { g_free(address); return; @@ -429,17 +471,16 @@ void _bt_handle_adapter_event(GVariant *msg, const char *member) /* Bonding from remote device */ address = g_malloc0(BT_ADDRESS_STRING_SIZE); - g_variant_get(msg, "(&o)", &object_path); - - /* Fix : NULL_RETURNS */ if (address == NULL) return; + g_variant_get(msg, "(&o)", &object_path); + _bt_convert_device_path_to_address((const char *)object_path, address); node = g_list_first(p_cache_list); - while (node != NULL){ + while (node != NULL) { cache_info = (bt_cache_info_t *)node->data; if (cache_info == NULL) { @@ -461,7 +502,6 @@ void _bt_handle_adapter_event(GVariant *msg, const char *member) } else if (strcasecmp(member, "AdvertisingEnabled") == 0) { BT_DBG("Advertising Enabled"); int slot_id; - const char *sender; int event; int adv_handle; gboolean status = FALSE; @@ -473,7 +513,6 @@ void _bt_handle_adapter_event(GVariant *msg, const char *member) /* Send event to application */ _bt_set_advertising_status(slot_id, status); - sender = _bt_get_adv_slot_owner(slot_id); adv_handle = _bt_get_adv_slot_adv_handle(slot_id); if (status) @@ -482,9 +521,16 @@ void _bt_handle_adapter_event(GVariant *msg, const char *member) event = BLUETOOTH_EVENT_ADVERTISING_STOPPED; param = g_variant_new("(ii)", result, adv_handle); + +#if 0 + const char *sender; + sender = _bt_get_adv_slot_owner(slot_id); _bt_send_event_to_dest(sender, BT_ADAPTER_EVENT, event, param); +#else + _bt_send_event(BT_ADAPTER_EVENT, event, param); +#endif if (event == BLUETOOTH_EVENT_ADVERTISING_STOPPED) _bt_unregister_adv_slot_owner(slot_id); @@ -493,7 +539,7 @@ void _bt_handle_adapter_event(GVariant *msg, const char *member) gboolean status = FALSE; char *address = NULL; int link_type; - g_variant_get(msg,"(sib)", &address, &link_type, &status); + g_variant_get(msg, "(sib)", &address, &link_type, &status); BT_DBG("RSSI Enabled [%s %d]", address, status); param = g_variant_new("(isib)", result, @@ -508,7 +554,7 @@ void _bt_handle_adapter_event(GVariant *msg, const char *member) int rssi_dbm; int link_type; char *address = NULL; - g_variant_get(msg,"(siii)", &address, &link_type, &alert_type, &rssi_dbm); + g_variant_get(msg, "(siii)", &address, &link_type, &alert_type, &rssi_dbm); BT_DBG("RSSI Alert: [Address %s LinkType %d] [Type %d DBM %d]", address, alert_type, rssi_dbm); @@ -523,7 +569,7 @@ void _bt_handle_adapter_event(GVariant *msg, const char *member) int rssi_dbm; int link_type; char *address = NULL; - g_variant_get(msg,"(sii)", &address, &link_type, &rssi_dbm); + g_variant_get(msg, "(sii)", &address, &link_type, &rssi_dbm); BT_DBG("Raw RSSI: [Address %s] [Link Type %d][RSSI DBM %d]", address, link_type, rssi_dbm); @@ -535,10 +581,16 @@ void _bt_handle_adapter_event(GVariant *msg, const char *member) g_free(address); } else if (strcasecmp(member, BT_HARDWARE_ERROR) == 0) { BT_ERR_C("Hardware error received from BLUEZ"); +/* Don't add the recovery logic into platform */ +#if 0 _bt_recover_adapter(); +#endif } else if (strcasecmp(member, BT_TX_TIMEOUT_ERROR) == 0) { BT_ERR_C("Tx timeout error received from BLUEZ"); +/* Don't add the recovery logic into platform */ +#if 0 _bt_recover_adapter(); +#endif } BT_DBG("-"); } @@ -550,11 +602,12 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path) int result = BLUETOOTH_ERROR_NONE; GVariantIter value_iter; GVariant *val = NULL; + GVariant *ret = NULL; GError *err = NULL; char *property = NULL; GVariant *param = NULL; - g_variant_iter_init (&value_iter, msg); - while ((g_variant_iter_loop (&value_iter,"{sv}", &property, &val))) { + g_variant_iter_init(&value_iter, msg); + while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) { BT_INFO("Property %s", property); if (strcasecmp(property, "Discovering") == 0) { @@ -575,7 +628,7 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path) ret_if(adapter_proxy == NULL); /* Need to stop searching */ - g_dbus_proxy_call_sync(adapter_proxy, "StopDiscovery", + ret = g_dbus_proxy_call_sync(adapter_proxy, "StopDiscovery", NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_TIMEOUT, NULL, @@ -584,6 +637,8 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path) BT_ERR("Dbus Error : %s", err->message); g_clear_error(&err); } + if (ret) + g_variant_unref(ret); event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY, (GSourceFunc)_bt_discovery_finished_cb, NULL); @@ -606,7 +661,7 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path) ret_if(adapter_proxy == NULL); /* Need to stop searching */ - g_dbus_proxy_call_sync(adapter_proxy, "StopLEDiscovery", + ret = g_dbus_proxy_call_sync(adapter_proxy, "StopLEDiscovery", NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_TIMEOUT, NULL, @@ -615,6 +670,8 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path) BT_ERR("Dbus Error %s", err->message); g_clear_error(&err); } + if (ret) + g_variant_unref(ret); event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY, (GSourceFunc)__bt_le_discovery_finished_cb, NULL); @@ -648,18 +705,20 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path) int time = 0; adapter_proxy = _bt_get_adapter_properties_proxy(); ret_if(adapter_proxy == NULL); - g_dbus_proxy_call_sync(adapter_proxy, "Set", - g_variant_new("(ssv)", BT_ADAPTER_INTERFACE, + ret = g_dbus_proxy_call_sync(adapter_proxy, "Set", + g_variant_new("(ssv)", BT_ADAPTER_INTERFACE, "DiscoverableTimeout", g_variant_new("i", time)), - G_DBUS_CALL_FLAGS_NONE, - DBUS_TIMEOUT, NULL, - &err); + G_DBUS_CALL_FLAGS_NONE, + DBUS_TIMEOUT, NULL, + &err); if (err != NULL) { BT_ERR("StopLEDiscovery Failed: %s", err->message); g_error_free(err); } + if (ret) + g_variant_unref(ret); } mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE; @@ -710,7 +769,7 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path) gboolean powered = FALSE; int bt_state; - g_variant_get(val, "b" ,&powered); + g_variant_get(val, "b", &powered); BT_DBG("Powered = %d", powered); if (powered == FALSE) { #ifdef USB_BLUETOOTH @@ -725,8 +784,7 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path) bt_state != VCONFKEY_BT_LE_STATUS_OFF) { _bt_set_le_disabled(BLUETOOTH_ERROR_NONE); } - } - else { + } else { #ifdef USB_BLUETOOTH _bt_handle_adapter_added(); #endif @@ -741,25 +799,26 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path) _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_CONNECTABLE_CHANGED, param); +#if 0 if (_bt_adapter_get_status() == BT_DEACTIVATING && _bt_adapter_get_le_status() == BT_LE_ACTIVATED && connectable == 0) _bt_set_disabled(BLUETOOTH_ERROR_NONE); +#endif } else if (strcasecmp(property, "SupportedLEFeatures") == 0) { char *name = NULL; char *value = NULL; GVariantIter *iter = NULL; g_variant_get(val, "as", &iter); - if (iter) { - while (g_variant_iter_loop(iter, "s", &name)) { - BT_DBG("name = %s", name); - g_variant_iter_loop(iter, "s", &value); - BT_DBG("Value = %s", value); - if (FALSE == _bt_update_le_feature_support(name, value)) - BT_INFO("Fail to update LE feature info"); - } - g_variant_iter_free(iter); + while (g_variant_iter_loop(iter, "s", &name)) { + BT_DBG("name = %s", name); + g_variant_iter_loop(iter, "s", &value); + BT_DBG("Value = %s", value); + if (FALSE == _bt_update_le_feature_support(name, value)) + BT_INFO("Fail to update LE feature info"); } + if (iter) + g_variant_iter_free(iter); } else if (strcasecmp(property, "IpspInitStateChanged") == 0) { gboolean ipsp_initialized = FALSE; @@ -771,6 +830,8 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path) _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_IPSP_INIT_STATE_CHANGED, param); + } else { + BT_DBG("property : [%s]", property); } } } @@ -782,8 +843,8 @@ static void __bt_obex_property_changed_event(GVariant *msg, const char *path) GVariantIter value_iter; GVariant *child = NULL, *val = NULL; char *property = NULL; - g_variant_iter_init (&value_iter, msg); - while ((child = g_variant_iter_next_value (&value_iter))) { + g_variant_iter_init(&value_iter, msg); + while ((child = g_variant_iter_next_value(&value_iter))) { g_variant_get(child, "{sv}", &property, &val); ret_if(property == NULL); @@ -794,21 +855,25 @@ static void __bt_obex_property_changed_event(GVariant *msg, const char *path) char *status; g_variant_get(val, "s", &status); - if (strcasecmp(status, "active") == 0){ + if (strcasecmp(status, "active") == 0) { _bt_obex_transfer_started(path); } else if (strcasecmp(status, "complete") == 0) { _bt_obex_transfer_completed(path, TRUE); _bt_pbap_obex_transfer_completed(path, TRUE); - } else if (strcasecmp(status, "error") == 0){ + } else if (strcasecmp(status, "error") == 0) { _bt_obex_transfer_completed(path, FALSE); _bt_pbap_obex_transfer_completed(path, FALSE); } g_free(status); } else if (strcasecmp(property, "Transferred") == 0) { - static int transferred = 0; + guint64 transferred = 0; + /* As Transferred is expected guint64 so change int to guint64 and + * eariler transferred is static because of it can overwrite data + * on present on opc_obex_conn or obexd_conn as these are + * static memory are in sequential */ g_variant_get(val, "t", &transferred); - _bt_obex_transfer_progress(path,transferred); + _bt_obex_transfer_progress(path, transferred); } g_free(property); g_variant_unref(val); @@ -829,7 +894,7 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path) char *address; GVariant *param = NULL; bt_remote_dev_info_t *remote_dev_info; - g_variant_iter_init (&value_iter, msg); + g_variant_iter_init(&value_iter, msg); while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) { BT_DBG("Property %s", property); if (strcasecmp(property, "Connected") == 0) { @@ -848,7 +913,7 @@ 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(address); + remote_dev_info = _bt_get_remote_device_info_by_object_path(path); if (remote_dev_info != NULL) { __bt_device_remote_connected_properties( @@ -871,7 +936,7 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path) _bt_convert_device_path_to_address(path, address); BT_DBG("address: %s", address); - remote_dev_info = _bt_get_remote_device_info(address); + remote_dev_info = _bt_get_remote_device_info_by_object_path(path); if (remote_dev_info == NULL) { g_free(property); g_variant_unref(val); @@ -883,11 +948,28 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path) if (remote_dev_info->addr_type == 0) { BT_DBG("Name %s", remote_dev_info->name); +#ifdef TIZEN_DPM_ENABLE + if (_bt_dpm_get_bluetooth_desktop_connectivity_state() == + DPM_RESTRICTED) { + bluetooth_device_class_t device_class; + _bt_divide_device_class(&device_class, remote_dev_info->class); + + if (device_class.major_class == + BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) { + _bt_free_device_info(remote_dev_info); + g_free(property); + g_variant_unref(val); + g_free(address); + return; + } + } +#endif + GVariant *uuids = NULL; GVariantBuilder *builder = NULL; int i = 0; builder = g_variant_builder_new(G_VARIANT_TYPE("as")); - for (i=0; i < remote_dev_info->uuid_count; i++) { + for (i = 0; i < remote_dev_info->uuid_count; i++) { g_variant_builder_add(builder, "s", remote_dev_info->uuids[i]); } @@ -956,7 +1038,7 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path) _bt_convert_device_path_to_address(path, address); - remote_dev_info = _bt_get_remote_device_info(address); + remote_dev_info = _bt_get_remote_device_info_by_object_path(path); if (remote_dev_info == NULL) { g_free(property); g_variant_unref(val); @@ -964,15 +1046,28 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path) return; } - if(paired == FALSE) { + if (paired == FALSE) { BT_INFO("Unpaired: %s", address); __bt_update_remote_cache_devinfo(address, FALSE); param = g_variant_new("(is)", result, address); _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED, param); +#ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT + { + char *last_connected = NULL; + last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE); + if (!g_strcmp0(address, last_connected)) + _bt_audio_set_auto_connect_device_addr(""); + if (last_connected) + free(last_connected); + } +#endif } else { - BT_INFO("Paired: %s", address); + char secure_addr[BT_ADDRESS_STRING_SIZE] = { 0 }; + + _bt_convert_addr_string_to_secure_string(secure_addr, address); + BT_INFO("### Paired: %s", secure_addr); __bt_update_remote_cache_devinfo(address, TRUE); if (_bt_is_device_creating() == TRUE) { @@ -987,7 +1082,7 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path) GVariantBuilder *builder = NULL; int i = 0; builder = g_variant_builder_new(G_VARIANT_TYPE("as")); - for (i=0; i < remote_dev_info->uuid_count; i++) { + for (i = 0; i < remote_dev_info->uuid_count; i++) { g_variant_builder_add(builder, "s", remote_dev_info->uuids[i]); } @@ -1019,6 +1114,7 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path) } else if (strcasecmp(property, "LegacyPaired") == 0) { gboolean paired = FALSE; bt_remote_dev_info_t *remote_dev_info; + unsigned char auth_info[5] = {0, }; if (_bt_adapter_get_status() != BT_ACTIVATED) { BT_DBG("BT is not activated, so ignore this"); @@ -1032,18 +1128,30 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path) BT_DBG("LegacyPaired: %d", paired); _bt_convert_device_path_to_address(path, address); - remote_dev_info = _bt_get_remote_device_info(address); + remote_dev_info = _bt_get_remote_device_info_by_object_path(path); if (remote_dev_info == NULL) { g_free(address); g_free(property); g_variant_unref(val); return; } + if (remote_dev_info->is_alias_set == FALSE) { + /*minimum Size of the samsung specific manufacturer data is greater than 30 */ + if ((remote_dev_info->manufacturer_data_len > 30) && + (remote_dev_info->manufacturer_data[0] == 0x00) && + (remote_dev_info->manufacturer_data[1] == 0x75)) { - BT_DBG("LegacyPairing Failed with %s. Show Error Popup", - remote_dev_info->name); + /* 2 samsung (0x00 0x75) + 1 (control and version) + 1 (service ID) + + 1 (discovery version) + 1 (associated service ID) + 2 (Proxamity and locality) + 2 (Device type and icon) = 10 */ + + memcpy(auth_info, &(remote_dev_info->manufacturer_data[10]), 5); + } + } + + BT_DBG("LegacyPairing Failed with %s. Show Error Popup", remote_dev_info->name); _bt_launch_system_popup(BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE, - remote_dev_info->name, NULL, NULL, NULL); + remote_dev_info->name, auth_info, NULL, NULL, NULL); _bt_free_device_info(remote_dev_info); g_free(address); @@ -1067,6 +1175,19 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path) event, param); g_free(address); + } else if (strcasecmp(property, "TrustedProfiles") == 0) { + int trusted = 0; + + g_variant_get(val, "u", &trusted); + + address = g_malloc0(BT_ADDRESS_STRING_SIZE); + _bt_convert_device_path_to_address(path, address); + + BT_DBG("Address: %s, TrustedProfiles: %d", address, trusted); + _bt_send_event(BT_DEVICE_EVENT, + BLUETOOTH_EVENT_SUPPORTED_PROFILE_TRUSTED, + g_variant_new("(isi)", result, address, trusted)); + g_free(address); } else if (strcasecmp(property, "IpspConnected") == 0) { gboolean connected = FALSE; @@ -1074,7 +1195,7 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path) event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED : - BLUETOOTH_EVENT_IPSP_DISCONNECTED; + BLUETOOTH_EVENT_IPSP_DISCONNECTED; address = g_malloc0(BT_ADDRESS_STRING_SIZE); @@ -1089,6 +1210,24 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path) event, param); g_free(address); + } else if (strcasecmp(property, "IpspBtInterfaceInfo") == 0) { + char *ifname = NULL; + + g_variant_get(val, "s", &ifname); + + address = g_malloc0(BT_ADDRESS_STRING_SIZE); + + _bt_convert_device_path_to_address(path, address); + + BT_DBG("Ipsp BT Interface Name: %s", ifname); + BT_DBG("address: %s", address); + param = g_variant_new("(iss)", result, address, ifname); + + /* Send event to application */ + _bt_send_event(BT_DEVICE_EVENT, + BLUETOOTH_EVENT_IPSP_INTERFACE_INFO, + param); + g_free(address); } } BT_DBG("-"); @@ -1105,8 +1244,8 @@ static void __bt_media_control_changed_event(GVariant *msg, const char *path) 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))) { + g_variant_iter_init(&value_iter, msg); + while ((child = g_variant_iter_next_value(&value_iter))) { g_variant_get(child, "{sv}", &property, &val); BT_INFO("Property %s", property); if (strcasecmp(property, "Connected") == 0) { @@ -1150,13 +1289,13 @@ void _bt_handle_property_changed_event(GVariant *msg, const char *object_path) char *interface_name = NULL; GVariant *val = NULL; - g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &val,NULL); + g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &val, NULL); if (strcasecmp(interface_name, BT_ADAPTER_INTERFACE) == 0) { __bt_adapter_property_changed_event(val, object_path); } else if (strcasecmp(interface_name, BT_DEVICE_INTERFACE) == 0) { - __bt_device_property_changed_event(val,object_path); + __bt_device_property_changed_event(val, object_path); } else if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) { BT_DBG("BT_OBEX_TRANSFER_INTERFACE"); __bt_obex_property_changed_event(val, @@ -1186,8 +1325,8 @@ void __bt_opc_property_changed_event(GVariant *msg, GVariant *val = NULL; GVariant *child = NULL; - g_variant_iter_init (&value_iter, msg); - while ((child = g_variant_iter_next_value (&value_iter))) { + g_variant_iter_init(&value_iter, msg); + while ((child = g_variant_iter_next_value(&value_iter))) { g_variant_get(child, "{sv}", &property, &val); ret_if(property == NULL); @@ -1196,16 +1335,16 @@ void __bt_opc_property_changed_event(GVariant *msg, g_variant_get(val, "s", &status); BT_DBG("Status is %s", status); - if(strcasecmp(status, "active") == 0){ + if (strcasecmp(status, "active") == 0) { _bt_obex_client_started(path); - }else if (strcasecmp(status, "complete") == 0) { + } else if (strcasecmp(status, "complete") == 0) { _bt_obex_client_completed(path, TRUE); - }else if (strcasecmp(status, "error") == 0){ + } else if (strcasecmp(status, "error") == 0) { _bt_obex_client_completed(path, FALSE); } g_free(status); } else if (strcasecmp(property, "Transferred") == 0) { - static int transferred = 0; + guint64 transferred = 0; g_variant_get(val, "t", &transferred); _bt_obex_client_progress(path, transferred); @@ -1243,8 +1382,8 @@ void _bt_handle_input_event(GVariant *msg, const char *path) GVariant *child = NULL, *val = 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))) { + g_variant_iter_init(&value_iter, msg); + while ((child = g_variant_iter_next_value(&value_iter))) { g_variant_get(child, "{sv}", &property, &val); ret_if(property == NULL); @@ -1265,7 +1404,7 @@ void _bt_handle_input_event(GVariant *msg, const char *path) _bt_send_event(BT_HID_EVENT, event, param); /* Check HID connection type (Keyboard or Mouse) and update the status */ - remote_dev_info = _bt_get_remote_device_info(address); + remote_dev_info = _bt_get_remote_device_info_by_object_path(path); if (property_flag == TRUE) { hid_connected_device_count++; @@ -1282,19 +1421,15 @@ void _bt_handle_input_event(GVariant *msg, const char *path) BT_DBG("HID device class [%x]", remote_dev_info->class); if (remote_dev_info->class & BLUETOOTH_DEVICE_MINOR_CLASS_KEY_BOARD) { -#ifdef ENABLE_TIZEN_2_4 __bt_set_device_values(property_flag, VCONFKEY_BT_DEVICE_HID_KEYBOARD_CONNECTED); -#endif } if (remote_dev_info->class & BLUETOOTH_DEVICE_MINOR_CLASS_POINTING_DEVICE) { -#ifdef ENABLE_TIZEN_2_4 __bt_set_device_values(property_flag, VCONFKEY_BT_DEVICE_HID_MOUSE_CONNECTED); -#endif } _bt_free_device_info(remote_dev_info); } @@ -1349,7 +1484,7 @@ void _bt_handle_network_client_event(GVariant *msg, GVariant *val = NULL; GVariantIter value_iter; GVariant *param = NULL; - g_variant_iter_init (&value_iter, msg); + g_variant_iter_init(&value_iter, msg); while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) { if (strcasecmp(property, "Connected") == 0) { int event = BLUETOOTH_EVENT_NONE; @@ -1392,7 +1527,7 @@ void __bt_gatt_char_property_changed_event(GVariant *msg, GVariant *val = NULL; int result = BLUETOOTH_ERROR_NONE; GVariant *param = NULL; - g_variant_iter_init (&value_iter, msg); + g_variant_iter_init(&value_iter, msg); char_handle = g_strdup(path); while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) { BT_INFO("Property %s", property); @@ -1409,13 +1544,13 @@ void __bt_gatt_char_property_changed_event(GVariant *msg, } else if (strcasecmp(property, "ChangedValue") == 0) { int len = 0; GByteArray *gp_byte_array = NULL; - BT_INFO("Type '%s'\n", g_variant_get_type_string (val)); + BT_INFO("Type '%s'\n", g_variant_get_type_string(val)); if (val) { gp_byte_array = g_byte_array_new(); len = g_variant_get_size(val); BT_DBG("Len = %d", len); - g_byte_array_append (gp_byte_array, + g_byte_array_append(gp_byte_array, (const guint8 *) g_variant_get_data(val), len); if (gp_byte_array->len != 0) { GVariant *byte_array = NULL; @@ -1478,9 +1613,10 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path int event = 0; int result = BLUETOOTH_ERROR_NONE; char *address; - char *dev_name; + char *dev_name = NULL; const char *property = NULL; GVariant *param = NULL; + char secure_address[BT_ADDRESS_STRING_SIZE] = { 0 }; ret_if(path == NULL); if (strcasecmp(member, "PropertyChanged") == 0) { @@ -1530,7 +1666,7 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path _bt_convert_device_path_to_address(path, address); - remote_dev_info = _bt_get_remote_device_info(address); + remote_dev_info = _bt_get_remote_device_info_by_object_path(path); if (remote_dev_info == NULL) { g_free(address); return; @@ -1539,7 +1675,7 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path GVariantBuilder *builder = NULL; int i = 0; builder = g_variant_builder_new(G_VARIANT_TYPE("as")); - for (i=0; i < remote_dev_info->uuid_count; i++) { + for (i = 0; i < remote_dev_info->uuid_count; i++) { g_variant_builder_add(builder, "s", remote_dev_info->uuids[i]); } @@ -1581,7 +1717,7 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path _bt_convert_device_path_to_address(path, address); - remote_dev_info = _bt_get_remote_device_info(address); + remote_dev_info = _bt_get_remote_device_info_by_object_path(path); if (remote_dev_info == NULL) { g_free(address); return; @@ -1593,7 +1729,7 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path GVariantBuilder *builder = NULL; int i = 0; builder = g_variant_builder_new(G_VARIANT_TYPE("as")); - for (i=0; i < remote_dev_info->uuid_count; i++) { + for (i = 0; i < remote_dev_info->uuid_count; i++) { g_variant_builder_add(builder, "s", remote_dev_info->uuids[i]); } @@ -1632,15 +1768,13 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path _bt_convert_device_path_to_address(path, address); dev_name = _bt_get_bonded_device_name(address); - BT_INFO("Address : %s Type : %d", address, addr_type); - BT_ERR_C("Connected [%s] [%s]", !addr_type ? "BREDR" : "LE", - !addr_type ? dev_name : address); + _bt_convert_addr_string_to_secure_string(secure_address, address); + BT_INFO("Address : %s Type : %d", secure_address, addr_type); + BT_ERR_C("### Connected [%s] [%s]", !addr_type ? "BREDR" : "LE", + !addr_type ? dev_name : secure_address); g_free(dev_name); _bt_logging_connection(TRUE, addr_type); -#ifdef ENABLE_TIZEN_2_4 - journal_bt_connected(); -#endif param = g_variant_new("(isy)", result, address, addr_type); /*Send event to application*/ _bt_send_event(BT_DEVICE_EVENT, @@ -1650,9 +1784,10 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path } else if (strcasecmp(member, "Disconnected") == 0) { unsigned char disc_reason = 0; unsigned char addr_type = 0; + char *dev_name = NULL; gboolean sending = FALSE; - g_variant_get(msg, "(yy)", &addr_type, &disc_reason); + g_variant_get(msg, "(yys)", &addr_type, &disc_reason, &dev_name); result = disc_reason; @@ -1660,30 +1795,55 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path ret_if(address == NULL); _bt_convert_device_path_to_address(path, address); - dev_name = _bt_get_bonded_device_name(address); -#ifdef ENABLE_TIZEN_2_4 - journal_bt_disconnected(); -#endif /* 0x00 BDADDR_BRDER 0x01 BDADDR_LE_PUBLIC 0x02 BDADDR_LE_RANDOM */ - BT_INFO("Address : %s Type : %d", address, addr_type); - BT_ERR_C("Disconnected [%s] [%d : %s] [%s]", !addr_type ? "BREDR" : "LE", + _bt_convert_addr_string_to_secure_string(secure_address, address); + BT_INFO("Address : %s Type : %d", secure_address, addr_type); + BT_ERR_C("### Disconnected [%s] [%d : %s] [%s]", !addr_type ? "BREDR" : "LE", disc_reason, _bt_convert_disc_reason_to_string(disc_reason), - !addr_type ? dev_name : address); + !addr_type ? dev_name : secure_address); g_free(dev_name); _bt_headset_set_local_connection(FALSE); _bt_logging_connection(FALSE, addr_type); - /*Check for any OPP transfer on the device and cancel - * the transfer - */ - _bt_obex_check_pending_transfer(address); - _bt_opp_client_is_sending(&sending); - if(sending == TRUE) - _bt_opp_client_check_pending_transfer(address); + if (!addr_type) { +#ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT + { + int bt_device_state = VCONFKEY_BT_DEVICE_NONE; + + if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0) + BT_ERR("vconf_get_int failed"); + + BT_INFO("conn_state[0x%x], adapter_state [%d]", + bt_device_state, _bt_adapter_get_status()); + + if (disc_reason == BLUETOOTH_ERROR_CONNECTION_TIMEOUT) { + _bt_audio_start_auto_connect(TRUE); + } else if (bt_device_state & + VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED) { + BT_INFO("Disconnected due to turning BT off. Skip a address"); + } else { + char *last_connected = NULL; + last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE); + if (!g_strcmp0(address, last_connected)) + _bt_audio_set_auto_connect_device_addr(""); + if (last_connected) + free(last_connected); + } + } + +#endif + /*Check for any OPP transfer on the device and cancel + * the transfer + */ + _bt_obex_check_pending_transfer(address); + _bt_opp_client_is_sending(&sending); + if (sending == TRUE) + _bt_opp_client_check_pending_transfer(address); + } param = g_variant_new("(isy)", result, address, addr_type); _bt_send_event(BT_DEVICE_EVENT, BLUETOOTH_EVENT_DEVICE_DISCONNECTED, @@ -1693,6 +1853,7 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path int state = 0; char *profile_uuid = NULL; bt_headset_wait_t *wait_list; + bluetooth_device_address_t bd_addr; g_variant_get(msg, "(si)", &profile_uuid, &state); @@ -1700,8 +1861,10 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path ret_if(address == NULL); _bt_convert_device_path_to_address(path, address); + _bt_convert_addr_string_to_type(bd_addr.addr, address); - BT_DBG("Address: %s", address); + _bt_convert_addr_string_to_secure_string(secure_address, address); + BT_DBG("Address: %s", secure_address); BT_DBG("Profile UUID: %s", profile_uuid); BT_DBG("State: %d", state); @@ -1713,15 +1876,19 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path bluetooth_device_address_t device_address; gboolean connected; bt_headset_wait_t *wait_list; + guint restricted = 0x0; __bt_set_device_values(TRUE, VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED); __bt_connection_manager_set_state(address, event); - if (_bt_headset_get_local_connection() == FALSE) - _bt_start_timer_for_connection(address, BT_AUDIO_HSP); - else { + _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_HFP_HS, &restricted); + + if (_bt_headset_get_local_connection() == FALSE) { + if (restricted == 0x0) /* not restricted*/ + _bt_start_timer_for_connection(address, BT_AUDIO_HSP); + } else { /* Connection Started from local device therefore no need to * intiate connection for pending profile */ _bt_headset_set_local_connection(FALSE); @@ -1789,7 +1956,7 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path _bt_audio_connect(wait_list->req_id, wait_list->type, &device_address, - wait_list->out_param1); + NULL); } } else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) { @@ -1830,13 +1997,44 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path if (state == BT_PROFILE_STATE_CONNECTED) { int event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED; BT_INFO("A2DP Source is connected"); +#ifdef TIZEN_BT_A2DP_SINK_ENABLE + __bt_set_device_values(TRUE, + VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED); +#endif + +#ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT + _bt_audio_set_auto_connect_device_addr(address); + _bt_audio_stop_auto_connect(); +#endif + _bt_add_headset_to_list(BT_AUDIO_A2DP_SOURCE, + BT_STATE_CONNECTED, address); _bt_send_event(BT_A2DP_SOURCE_EVENT, event, g_variant_new("(is)", result, address)); } else if (state == BT_PROFILE_STATE_DISCONNECTED) { int event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED; BT_INFO("A2DP Source Disconnected"); +#ifdef TIZEN_BT_A2DP_SINK_ENABLE + __bt_set_device_values(FALSE, + VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED); +#endif + _bt_remove_headset_from_list(BT_AUDIO_A2DP_SOURCE, address); _bt_send_event(BT_A2DP_SOURCE_EVENT, event, g_variant_new("(is)", result, address)); + + wait_list = _bt_get_audio_wait_data(); + if (wait_list && wait_list->type == BT_AUDIO_A2DP_SOURCE) { + bluetooth_device_address_t device_address; + _bt_convert_addr_string_to_type( + device_address.addr, + wait_list->address); + + _bt_audio_connect(wait_list->req_id, + wait_list->type, + &device_address, + NULL); + /* Now free the wait list */ + _bt_rel_wait_data(); + } } } else if ((strcmp(profile_uuid, HID_UUID) == 0) && ((state == BT_PROFILE_STATE_CONNECTED) || @@ -1849,13 +2047,19 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path param = g_variant_new("(is)", result, address); _bt_send_event(BT_HID_EVENT, event, param); - - if (state == BT_PROFILE_STATE_CONNECTED) - __bt_set_device_values(TRUE, - VCONFKEY_BT_DEVICE_HID_CONNECTED); - else - __bt_set_device_values(FALSE, - VCONFKEY_BT_DEVICE_HID_CONNECTED); + } else if (strcmp(profile_uuid, HID_DEVICE_UUID) == 0) { + if (state == BT_PROFILE_STATE_CONNECTED) { + int event; + event = BLUETOOTH_HID_DEVICE_CONNECTED; + param = g_variant_new("(is)", result, address); + _bt_send_event(BT_HID_DEVICE_EVENT, event, + param); + } else if (state == BT_PROFILE_STATE_DISCONNECTED) { + event = BLUETOOTH_HID_DEVICE_DISCONNECTED; + param = g_variant_new("(is)", result, address); + _bt_send_event(BT_HID_DEVICE_EVENT, event, + param); + } } g_free(address); g_free(profile_uuid); @@ -1878,6 +2082,8 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path &le_dev_info->rssi, &le_dev_info->adv_data_len, &value); + _bt_convert_device_path_to_address(path, le_dev_info->address); + buffer_len = g_variant_get_size(value); if (buffer_len > 0) buffer = (char *)g_variant_get_data(value); @@ -1906,15 +2112,19 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path } adv_info->addr = g_strdup(le_dev_info->address); + adv_info->addr_type = le_dev_info->addr_type; + adv_info->rssi = le_dev_info->rssi; adv_info->data_len = le_dev_info->adv_data_len; adv_info->data = g_malloc0(le_dev_info->adv_data_len); if (adv_info->data) { memcpy(adv_info->data, le_dev_info->adv_data, le_dev_info->adv_data_len); - - __bt_add_adv_ind_info(adv_info); } + if (__bt_add_adv_ind_info(adv_info) == 0) { + adv_info->timer_id = g_timeout_add(1000, + (GSourceFunc)__bt_adv_scan_req_timeout_cb, (void*)adv_info); + } } else { /* SCAN_RSP */ adv_info = __bt_get_adv_ind_info(le_dev_info->address); if (adv_info) { @@ -1925,13 +2135,13 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path _bt_free_le_device_info(le_dev_info); g_variant_unref(value); } else if (strcasecmp(member, "LEDataLengthChanged") == 0) { - int tx_octets = 0; - int tx_time = 0; - int rx_octets = 0; - int rx_time = 0; + guint16 tx_octets = 0; + guint16 tx_time = 0; + guint16 rx_octets = 0; + guint16 rx_time = 0; g_variant_get(msg, "(qqqq)", - tx_octets, tx_time, rx_octets, rx_time); + &tx_octets, &tx_time, &rx_octets, &rx_time); address = g_malloc0(BT_ADDRESS_STRING_SIZE); _bt_convert_device_path_to_address(path, address); @@ -1939,10 +2149,50 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path param = g_variant_new("(isqqqq)", result, address, tx_octets, tx_time, rx_octets, rx_time); /* Send event to application */ - _bt_send_event(BT_DEVICE_EVENT, event, param); + _bt_send_event(BT_DEVICE_EVENT, + BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED, param); g_free(address); - } + } else if (strcasecmp(member, "IpspStateChanged") == 0) { + gboolean connected = FALSE; + char *ifname = NULL; + + g_variant_get(msg, "(bs)", &connected, &ifname); + + event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED : + BLUETOOTH_EVENT_IPSP_DISCONNECTED; + + address = g_malloc0(BT_ADDRESS_STRING_SIZE); + _bt_convert_device_path_to_address(path, address); + + BT_DBG("Ipsp BT Interface Name: %s", ifname); + BT_DBG("address: %s", address); + param = g_variant_new("(iss)", result, address, ifname); + + /* Send event to application */ + _bt_send_event(BT_DEVICE_EVENT, + event, + param); + g_free(address); + } else if (strcasecmp(member, "iBeaconReport") == 0) { + bt_remote_ibeacon_dev_info_t *ibeacon_dev_info = NULL; + + ret_if(_bt_is_le_scanning() == FALSE); + ibeacon_dev_info = g_malloc0(sizeof(bt_remote_ibeacon_dev_info_t)); + if (ibeacon_dev_info == NULL) + return; + + g_variant_get(msg, "(syuusuuy)", &ibeacon_dev_info->address, + &ibeacon_dev_info->addr_type, + &ibeacon_dev_info->company_id, + &ibeacon_dev_info->ibeacon_type, + &ibeacon_dev_info->uuid, + &ibeacon_dev_info->major_id, + &ibeacon_dev_info->minor_id, + &ibeacon_dev_info->measured_power); + _bt_send_ibeacon_scan_result_event(ibeacon_dev_info); + g_free(ibeacon_dev_info); + } } void __bt_set_audio_values(gboolean connected, char *address) @@ -1967,7 +2217,7 @@ void __bt_set_audio_values(gboolean connected, char *address) /* Set the headset state */ if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0) { - BT_ERR("vconf_get_str failed"); + BT_ERR("vconf_get_int failed"); } #ifdef TIZEN_SUPPORT_DUAL_HF @@ -2000,6 +2250,7 @@ void _bt_handle_headset_event(GVariant *msg, const char *path) GVariant *value = NULL; GVariant *param = NULL; g_variant_get(msg, "(sv)", &property, &value); + bluetooth_device_address_t bd_addr; ret_if(property == NULL); @@ -2009,21 +2260,24 @@ void _bt_handle_headset_event(GVariant *msg, const char *path) int event = BLUETOOTH_EVENT_NONE; bt_headset_wait_t *wait_list; char *address; + guint restricted = 0x0; g_variant_get(value, "b", &property_flag); address = g_malloc0(BT_ADDRESS_STRING_SIZE); - - /* Fix : NULL_RETURNS */ if (address == NULL) return; _bt_convert_device_path_to_address(path, address); + _bt_convert_addr_string_to_type(bd_addr.addr, address); if (property_flag == TRUE) { event = BLUETOOTH_EVENT_AG_CONNECTED; - if (_bt_headset_get_local_connection() == FALSE) - _bt_start_timer_for_connection(address, BT_AUDIO_A2DP); - else + _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_A2DP, &restricted); + + if (_bt_headset_get_local_connection() == FALSE) { + if (restricted == 0x0) /* not restricted*/ + _bt_start_timer_for_connection(address, BT_AUDIO_A2DP); + } else _bt_headset_set_local_connection(FALSE); } else { int previous_state; @@ -2058,7 +2312,7 @@ void _bt_handle_headset_event(GVariant *msg, const char *path) _bt_convert_addr_string_to_type(device_address.addr, wait_list->address); _bt_audio_connect(wait_list->req_id, wait_list->type, - &device_address, wait_list->out_param1); + &device_address, NULL); _bt_rel_wait_data(); } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) { /* Add data to the connected list */ @@ -2100,8 +2354,11 @@ void _bt_handle_headset_event(GVariant *msg, const char *path) _bt_convert_device_path_to_address(path, address); - g_variant_get(value, "i", &spkr_gain); - param = g_variant_new("(isq)", result, address, spkr_gain); + spkr_gain = g_variant_get_uint16(value); + + BT_DBG("spkr_gain: %d", spkr_gain); + + param = g_variant_new("(i&sq)", result, address, spkr_gain); _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_SPEAKER_GAIN, param); @@ -2114,8 +2371,9 @@ void _bt_handle_headset_event(GVariant *msg, const char *path) _bt_convert_device_path_to_address(path, address); - g_variant_get(value, "i", &mic_gain); - param = g_variant_new("(isq)", result, address, mic_gain); + mic_gain = g_variant_get_uint16(value); + + param = g_variant_new("(i&sq)", result, address, mic_gain); _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_MIC_GAIN, param); g_free(address); @@ -2136,8 +2394,8 @@ void _bt_handle_sink_event(GVariant *msg, const char *path) GVariant *child = NULL; GVariant *val = NULL; GVariant *param = NULL; - g_variant_iter_init (&value_iter, msg); - while ((child = g_variant_iter_next_value (&value_iter))) { + g_variant_iter_init(&value_iter, msg); + while ((child = g_variant_iter_next_value(&value_iter))) { g_variant_get(child, "{sv}", &property, &val); @@ -2191,10 +2449,10 @@ void _bt_handle_sink_event(GVariant *msg, const char *path) _bt_audio_connect(wait_list->req_id, wait_list->type, &device_address, - wait_list->out_param1); + NULL); } g_free(address); - }else if (strcasecmp(value, "Connected") == 0) { + } else if (strcasecmp(value, "Connected") == 0) { char *address; char connected_address[BT_ADDRESS_STRING_SIZE + 1]; bluetooth_device_address_t device_address; @@ -2291,7 +2549,7 @@ static void __bt_devices_list_free(void) node = g_list_first(p_cache_list); - while (node != NULL){ + while (node != NULL) { cache_info = (bt_cache_info_t *)node->data; p_cache_list = g_list_remove(p_cache_list, cache_info); __bt_free_cache_info(cache_info); @@ -2304,13 +2562,13 @@ static int __bt_parse_event(GVariant *msg) { GVariantIter iter; GVariant *child; - char *interface_name= NULL; + char *interface_name = NULL; GVariant *inner_iter = NULL; g_variant_iter_init(&iter, msg); while ((child = g_variant_iter_next_value(&iter))) { - g_variant_get(child,"{&s@a{sv}}", &interface_name, &inner_iter); + g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter); if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) { g_variant_unref(inner_iter); @@ -2359,8 +2617,7 @@ static void __bt_manager_event_filter(GDBusConnection *connection, #else _bt_handle_adapter_added(); #endif - } - else { + } else { bt_event = __bt_parse_event(value); if (bt_event == BT_DEVICE_EVENT) { bt_cache_info_t *cache_info; @@ -2402,11 +2659,27 @@ static void __bt_manager_event_filter(GDBusConnection *connection, */ dev_info->name = g_strdup(dev_info->address); +#ifdef TIZEN_DPM_ENABLE + if (_bt_dpm_get_bluetooth_desktop_connectivity_state() == + DPM_RESTRICTED) { + bluetooth_device_class_t device_class; + _bt_divide_device_class(&device_class, dev_info->class); + BT_DBG("[%s]device_class.major_class : %d", dev_info->name, device_class.major_class); + + if (device_class.major_class == + BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) { + __bt_free_cache_info(cache_info); + g_variant_unref(value); + return; + } + } +#endif + GVariant *uuids = NULL; GVariantBuilder *builder = NULL; int i = 0; builder = g_variant_builder_new(G_VARIANT_TYPE("as")); - for (i=0; i < dev_info->uuid_count; i++) { + for (i = 0; i < dev_info->uuid_count; i++) { g_variant_builder_add(builder, "s", dev_info->uuids[i]); } @@ -2481,7 +2754,7 @@ static void __bt_manager_event_filter(GDBusConnection *connection, if (strcasecmp(name, BT_BLUEZ_NAME) == 0) { BT_DBG("Bluetoothd is terminated"); if (_bt_adapter_get_status() == BT_ACTIVATED) - __bt_disable_cb(); + _bt_disable_cb(); _bt_handle_adapter_removed(); __bt_devices_list_free(); @@ -2543,7 +2816,7 @@ static gboolean __bt_is_obexd_event(GVariant *msg, const char *interface) if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) { char *interface_name = NULL; - g_variant_get(msg,"(&s@a{sv}@as)", &interface_name, NULL, NULL); + g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL); retv_if(interface_name == NULL, FALSE); if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) { @@ -2572,7 +2845,7 @@ static void __bt_obexd_event_filter(GDBusConnection *connection, BT_ERR("Fail to get the path"); return; } - BT_INFO("object_path = [%s]", object_path); + BT_INFO("object_path = [%s]", obj_path); /*Handle OPP_SERVER_CONNECTED_EVENT here */ if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER, @@ -2583,7 +2856,7 @@ static void __bt_obexd_event_filter(GDBusConnection *connection, if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) { BT_DBG("Obex_Server_Session_Transfer connected"); - _bt_obex_transfer_connected(); + _bt_obex_transfer_connected(obj_path); } g_free(obj_path); } else if (strcasecmp(member, "InterfacesRemoved") == 0) { @@ -2592,7 +2865,7 @@ static void __bt_obexd_event_filter(GDBusConnection *connection, BT_ERR("Fail to get the path"); return; } - BT_INFO("object_path = [%s]", object_path); + BT_INFO("object_path = [%s]", obj_path); if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT, strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) { @@ -2607,8 +2880,10 @@ static void __bt_obexd_event_filter(GDBusConnection *connection, } if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) { - BT_DBG("Obex_Server_Session_Transfer disconnected"); - _bt_obex_transfer_disconnected(); + BT_DBG("Obex_Server_Session_Transfer disconnected %s", + obj_path); + + _bt_obex_transfer_disconnected(obj_path); } g_free(obj_path); } else if (__bt_is_obexd_event(parameters, interface_name) == TRUE) { @@ -2635,7 +2910,7 @@ static gboolean __bt_is_obexd_client_event(GVariant *msg, const char *interface) if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) { char *interface_name = NULL; - g_variant_get(msg,"(&s@a{sv}@as)", &interface_name, NULL, NULL); + g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL); retv_if(interface_name == NULL, FALSE); @@ -2663,22 +2938,21 @@ static void __bt_opc_event_filter(GDBusConnection *connection, char *obj_path = NULL; if (strcasecmp(member, "InterfacesAdded") == 0) { BT_DBG("InterfacesAdded"); - }else if (strcasecmp(member, "InterfacesRemoved") == 0) { + } else if (strcasecmp(member, "InterfacesRemoved") == 0) { if (__bt_get_object_path(parameters, &obj_path)) { BT_ERR("Fail to get the path"); return; } - BT_DBG("object_path =%s",obj_path); + BT_DBG("object_path = %s", obj_path); if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT, strlen(BT_SESSION_BASEPATH_CLIENT)) != 0 || strstr(obj_path, "transfer") == NULL) { g_free(obj_path); return; - } - else if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT, + } else if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT, strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) { BT_DBG("Going to call opc disconnected"); _bt_opc_disconnected(obj_path); @@ -2686,7 +2960,7 @@ static void __bt_opc_event_filter(GDBusConnection *connection, _bt_sending_files(); g_free(obj_path); - }else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE){ + } else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE) { char *path = (char *)object_path; BT_INFO("object_path %s", path); if (strncmp(path, BT_SESSION_BASEPATH_CLIENT, @@ -3101,6 +3375,43 @@ int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn, return 0; } +static void __bt_dump_event_filter(GDBusConnection *connection, + const gchar *sender_name, + const gchar *object_path, + const gchar *interface_name, + const gchar *signal_name, + GVariant *parameters, + gpointer user_data) +{ + return; +} + +int __bt_register_dump_subscribe_signal(GDBusConnection *conn, + gboolean subscribe) +{ + if (conn == NULL) + return -1; + + static int subs_source_id = -1; + + if (subscribe) { + if (subs_source_id == -1) { + subs_source_id = g_dbus_connection_signal_subscribe(conn, + NULL, BT_DUMP_SERVICE_INTERFACE, + BT_DUMP_SERVICE_SIGNAL, BT_DUMP_SERVICE_PATH, NULL, 0, + __bt_dump_event_filter, + NULL, NULL); + } + } else { + if (subs_source_id != -1) { + g_dbus_connection_signal_unsubscribe(conn, + subs_source_id); + subs_source_id = -1; + } + } + return 0; +} + int _bt_register_service_event(GDBusConnection *g_conn, int event_type) { BT_DBG("+"); @@ -3205,6 +3516,8 @@ static int __bt_init_manager_receiver(void) if (_bt_register_service_event(manager_conn, BT_NETWORK_EVENT) != BLUETOOTH_ERROR_NONE) goto fail; + + __bt_register_dump_subscribe_signal(manager_conn, TRUE); return BLUETOOTH_ERROR_NONE; fail: if (manager_conn) { @@ -3245,6 +3558,36 @@ static int __bt_init_obexd_receiver(void) return BLUETOOTH_ERROR_NONE; } +gboolean __bt_reinit_obexd_receiver(gpointer user_data) +{ + static int retry_cnt = 0; + int result = BLUETOOTH_ERROR_NONE; + + BT_DBG("+"); + + result = __bt_init_obexd_receiver(); + if (result != BLUETOOTH_ERROR_NONE) { + /* 20 ms * 50 = 10 seconds. During 10 seconds fail to initialize, + then it is not the timing issue. Just can't use the session bus connection */ + if (retry_cnt > 100) { + BT_ERR("Fail to init obexd receiver by 50 times."); + retry_cnt = 0; + session_reinit_timer = 0; + return FALSE; + } + retry_cnt++; + BT_DBG("Retry to initialize the obexd receiver"); + return TRUE; + } + + retry_cnt = 0; + session_reinit_timer = 0; + + BT_DBG("-"); + + return FALSE; +} + /* To receive the event from bluez */ int _bt_init_service_event_receiver(void) { @@ -3256,9 +3599,17 @@ int _bt_init_service_event_receiver(void) retv_if(result != BLUETOOTH_ERROR_NONE, result); result = __bt_init_obexd_receiver(); - if (result != BLUETOOTH_ERROR_NONE) + if (result != BLUETOOTH_ERROR_NONE) { BT_ERR("Fail to init obexd receiver"); + /* Try to re-initialize obexd receiver in the timer */ + if (session_reinit_timer > 0) + g_source_remove(session_reinit_timer); + + session_reinit_timer = g_timeout_add(BT_SESSION_BUS_GET_TIMEOUT, + (GSourceFunc)__bt_reinit_obexd_receiver, NULL); + } + BT_DBG("-"); return BLUETOOTH_ERROR_NONE; @@ -3272,6 +3623,8 @@ void _bt_deinit_service_event_receiver(void) _bt_unregister_service_event(obexd_conn, BT_OPP_SERVER_EVENT); + __bt_register_dump_subscribe_signal(manager_conn, FALSE); + if (manager_conn) { g_object_unref(manager_conn); manager_conn = NULL; @@ -3284,6 +3637,8 @@ void _bt_deinit_service_event_receiver(void) if (event_id > 0) g_source_remove(event_id); + event_id = 0; BT_DBG("-"); } +