+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+
+ _bt_convert_device_path_to_address(path, address);
+
+ /* 0x00 BDADDR_BRDER
+ 0x01 BDADDR_LE_PUBLIC
+ 0x02 BDADDR_LE_RANDOM */
+ _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] [%s] [%d : %s]", !addr_type ? "BREDR" : "LE",
+ !addr_type ? dev_name : secure_address,
+ disc_reason, _bt_convert_disc_reason_to_string(disc_reason));
+ g_free(dev_name);
+
+ _bt_headset_set_local_connection(FALSE);
+ _bt_logging_connection(FALSE, 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;
+
+ 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,
+ param);
+ g_free(address);
+ } else if (strcasecmp(member, "ProfileStateChanged") == 0) {
+ 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);
+
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+
+ _bt_convert_device_path_to_address(path, address);
+ _bt_convert_addr_string_to_type(bd_addr.addr, address);
+
+ _bt_convert_addr_string_to_secure_string(secure_address, address);
+ BT_INFO_C("[%s] state: %s, addr: %s",
+ _bt_convert_uuid_to_string(profile_uuid),
+ _bt_convert_profile_state_to_string(state), secure_address);
+
+ if (strcmp(profile_uuid, A2DP_SINK_UUID) == 0) {
+ if (state == BT_PROFILE_STATE_CONNECTED) {
+
+ int event = BLUETOOTH_EVENT_AV_CONNECTED;
+ char connected_address[BT_ADDRESS_STRING_SIZE + 1];
+ 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);
+
+ _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);
+ }
+ param = g_variant_new("(is)", result, address);
+ _bt_send_event(BT_HEADSET_EVENT, event,
+ param);
+ connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
+ connected_address);
+ if (connected) {
+ if (g_strcmp0(connected_address, address) != 0) {
+ _bt_convert_addr_string_to_type(
+ device_address.addr,
+ connected_address);
+ _bt_audio_disconnect(0, BT_AUDIO_A2DP,
+ &device_address, NULL);
+ }
+ }
+
+ _bt_add_headset_to_list(BT_AUDIO_A2DP,
+ BT_STATE_CONNECTED, address);
+
+ wait_list = _bt_get_audio_wait_data();
+ if (wait_list != NULL &&
+ (g_strcmp0(wait_list->address, address) == 0))
+ _bt_rel_wait_data();
+
+ } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
+
+ int event = BLUETOOTH_EVENT_AV_DISCONNECTED;
+
+ if (!_bt_is_service_connected(address, BT_AUDIO_A2DP)) {
+ g_free(address);
+ g_free(profile_uuid);
+ return;
+ }
+
+ __bt_set_device_values(FALSE,
+ VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
+
+ __bt_connection_manager_set_state(address, event);
+ param = g_variant_new("(is)", result, address);
+ _bt_send_event(BT_HEADSET_EVENT, event,
+ param);
+ /* Remove data from the connected list */
+ _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
+ wait_list = _bt_get_audio_wait_data();
+
+ if (wait_list == NULL) {
+ g_free(address);
+ g_free(profile_uuid);
+ return;
+ }
+
+ if (((wait_list->type == BT_AUDIO_ALL) &&
+ (wait_list->ag_flag == TRUE)) ||
+ (wait_list->type == BT_AUDIO_A2DP) ||
+ (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
+ 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);
+ }
+ }
+ } else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) {
+
+ if (state == BT_PROFILE_STATE_CONNECTED) {
+ int event = BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED;
+ char connected_address[BT_ADDRESS_STRING_SIZE + 1];
+ bluetooth_device_address_t device_address;
+ gboolean connected;
+ param = g_variant_new("(is)", result, address);
+ _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
+ param);
+ connected = _bt_is_headset_type_connected(
+ BT_AVRCP,
+ connected_address);
+ if (connected) {
+ if (g_strcmp0(connected_address,
+ address) != 0) {
+ _bt_convert_addr_string_to_type(
+ device_address.addr,
+ connected_address);
+ _bt_audio_disconnect(0,
+ BT_AVRCP,
+ &device_address, NULL);
+ }
+ }
+ BT_DBG("device Path: %s", path);
+ _bt_add_headset_to_list(BT_AVRCP,
+ BT_STATE_CONNECTED, address);
+ } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
+ int event = BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED;
+ param = g_variant_new("(is)", result, address);
+ _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
+ param);
+ /* Remove data from the connected list */
+ _bt_remove_headset_from_list(BT_AVRCP, address);
+ }
+ } else if (strcasecmp(profile_uuid, A2DP_SOURCE_UUID) == 0) {
+ 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) ||
+ (state == BT_PROFILE_STATE_DISCONNECTED))) {
+ int event;
+ if (state == BT_PROFILE_STATE_CONNECTED)
+ event = BLUETOOTH_HID_CONNECTED;
+ else
+ event = BLUETOOTH_HID_DISCONNECTED;
+ param = g_variant_new("(is)", result, address);
+ _bt_send_event(BT_HID_EVENT, event,
+ param);
+ } 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);
+ } else if (strcasecmp(member, "AdvReport") == 0) {
+
+ bt_remote_le_dev_info_t *le_dev_info = NULL;
+ char *buffer = NULL;
+ int buffer_len = 0;
+ bt_le_adv_info_t *adv_info = NULL;
+ GVariant *value = NULL;
+ ret_if(_bt_is_le_scanning() == FALSE);
+
+ le_dev_info = g_malloc0(sizeof(bt_remote_le_dev_info_t));
+
+ g_variant_get(msg, "(&syyii@ay)", &le_dev_info->address,
+ &le_dev_info->addr_type,
+ &le_dev_info->adv_type,
+ &le_dev_info->rssi,
+ &le_dev_info->adv_data_len,
+ &value);
+ if (value == NULL) {
+ _bt_free_le_device_info(le_dev_info);
+ return;
+ }