+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+
+ _bt_convert_device_path_to_address(path, address);
+
+ remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
+ if (remote_dev_info == NULL) {
+ g_free(address);
+ return;
+ }
+ 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++) {
+ g_variant_builder_add(builder, "s",
+ remote_dev_info->uuids[i]);
+ }
+ uuids = g_variant_new("as", builder);
+ g_variant_builder_unref(builder);
+ GVariant *manufacturer_data = NULL;
+ manufacturer_data = g_variant_new_from_data(
+ G_VARIANT_TYPE_BYTESTRING,
+ remote_dev_info->manufacturer_data,
+ remote_dev_info->manufacturer_data_len,
+ TRUE, NULL, NULL);
+ param = g_variant_new("(isunsbub@asn@ay)", result,
+ address,
+ remote_dev_info->class,
+ remote_dev_info->rssi,
+ remote_dev_info->name,
+ remote_dev_info->paired,
+ remote_dev_info->connected,
+ remote_dev_info->trust,
+ uuids,
+ remote_dev_info->manufacturer_data_len,
+ manufacturer_data);
+ _bt_send_event(BT_ADAPTER_EVENT,
+ BLUETOOTH_EVENT_BONDING_FINISHED,
+ param);
+ _bt_free_device_info(remote_dev_info);
+ g_free(address);
+
+ } else if (strcasecmp(property, "UUIDs") == 0) {
+ /* Once we get the updated uuid information after
+ * reverse service search, update it to application */
+
+ bt_remote_dev_info_t *remote_dev_info;
+
+ ret_if(_bt_is_device_creating() == TRUE);
+
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+
+ _bt_convert_device_path_to_address(path, address);
+
+ remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
+ if (remote_dev_info == NULL) {
+ g_free(address);
+ return;
+ }
+
+ BT_DBG("UUID's count = %d", remote_dev_info->uuid_count);
+ if (remote_dev_info->paired && remote_dev_info->uuid_count) {
+ 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++) {
+ g_variant_builder_add(builder, "s",
+ remote_dev_info->uuids[i]);
+ }
+ uuids = g_variant_new("as", builder);
+ g_variant_builder_unref(builder);
+ GVariant *manufacture_data = g_variant_new_from_data((const GVariantType *)"ay",
+ remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
+ TRUE, NULL, NULL);
+
+ param = g_variant_new("(isunsbub@asn@ay)", result,
+ address, remote_dev_info->class,
+ remote_dev_info->rssi,
+ remote_dev_info->name,
+ remote_dev_info->paired,
+ remote_dev_info->connected,
+ remote_dev_info->trust,
+ uuids,
+ remote_dev_info->manufacturer_data_len,
+ manufacture_data);
+ _bt_send_event(BT_ADAPTER_EVENT,
+ BLUETOOTH_EVENT_SERVICE_SEARCHED,
+ param);
+ }
+
+ _bt_free_device_info(remote_dev_info);
+ g_free(address);
+ }
+ } else if (strcasecmp(member, "DeviceConnected") == 0) {
+ unsigned char addr_type = 0;
+
+ g_variant_get(msg, "(y)", &addr_type);
+
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+
+ _bt_convert_device_path_to_address(path, address);
+ dev_name = _bt_get_device_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);
+
+ 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*/
+ _bt_send_event(BT_DEVICE_EVENT,
+ BLUETOOTH_EVENT_DEVICE_CONNECTED,
+ param);
+ g_free(address);
+ } 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, "(yys)", &addr_type, &disc_reason, &dev_name);
+
+ result = disc_reason;
+
+ 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);
+ /* TODO: MAP? see above */
+ }
+ 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_DBG("Address: %s", secure_address);
+ BT_DBG("Profile UUID: %s", profile_uuid);
+ BT_DBG("State: %d", state);
+
+ if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
+ (state == BT_PROFILE_STATE_CONNECTED)) {
+
+ int event = BLUETOOTH_EVENT_AV_CONNECTED;
+#ifndef TIZEN_BT_DUAL_HEADSET_CONNECT
+ bluetooth_device_address_t device_address;
+ char connected_address[BT_ADDRESS_STRING_SIZE + 1];
+ gboolean connected;
+#endif
+ bt_headset_wait_t *wait_list;
+ guint trusted = TRUE;
+
+ __bt_set_device_values(TRUE,
+ VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
+
+ __bt_connection_manager_set_state(address, event);
+
+ _bt_get_trust_profile(&bd_addr, TRUSTED_PROFILE_HFP_HF, &trusted);
+
+ if (_bt_headset_get_local_connection() == FALSE) {
+ if (trusted == TRUE) /* 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);
+#ifdef TIZEN_BT_DUAL_HEADSET_CONNECT
+ _bt_check_already_connected_headset(BT_AUDIO_A2DP,
+ address);
+#else
+ 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);
+ }
+ }
+#endif
+ _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 ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
+ (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);
+
+ /* Set the vconf value for device */
+ if (state == BT_PROFILE_STATE_CONNECTED) {
+ hid_connected_device_count++;
+ __bt_set_device_values(TRUE,
+ VCONFKEY_BT_DEVICE_HID_CONNECTED);
+ } else {
+ hid_connected_device_count--;
+ if (hid_connected_device_count == 0)
+ __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);
+ } 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;
+ }
+
+ _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);
+
+ le_dev_info->adv_data = g_memdup(buffer, buffer_len);
+ if (le_dev_info->adv_data == NULL &&
+ le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) {
+ _bt_free_le_device_info(le_dev_info);
+ g_variant_unref(value);
+ return;
+ }
+
+ if (_bt_get_le_scan_type() == BT_LE_PASSIVE_SCAN) {
+ _bt_send_scan_result_event(le_dev_info, NULL);
+ _bt_free_le_device_info(le_dev_info);
+ g_variant_unref(value);
+ return;
+ }
+
+ if (le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) { /* ADV_IND */
+ adv_info = g_malloc0(sizeof(bt_le_adv_info_t));
+ 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);
+ memcpy(adv_info->data, le_dev_info->adv_data,
+ le_dev_info->adv_data_len);
+
+ 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) {
+ _bt_send_scan_result_event(le_dev_info, adv_info);
+ __bt_del_adv_ind_info(le_dev_info->address);
+ }
+ }
+ _bt_free_le_device_info(le_dev_info);
+ g_variant_unref(value);
+ } else if (strcasecmp(member, "LEDataLengthChanged") == 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);
+
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+ _bt_convert_device_path_to_address(path, address);
+
+ 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,
+ BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED, param);
+ g_free(address);
+ } else if (strcasecmp(member, "IpspStateChanged") == 0) {
+ gboolean connected = FALSE;
+ char *ifname = NULL;
+ GVariant *ipsp_param = 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, address: %s", ifname, address);
+
+ param = g_variant_new("(iss)", result, address, ifname);
+ ipsp_param = g_variant_new("(ss)", ifname, address);
+
+ g_free(ifname);
+
+ /* Set Ipv6 Addr */
+ GDBusProxy *ipsp_proxy;
+ if (connected) {
+ BT_DBG("IPSP connected, Set Ipv6 Addr");
+ ipsp_proxy = _bt_get_ipsp_proxy();
+ if (ipsp_proxy == NULL) {
+ BT_ERR("can not get ipsp proxy");
+ g_free(address);
+ g_variant_unref(param);
+ g_variant_unref(ipsp_param);
+ return;
+ }
+
+ g_dbus_proxy_call(ipsp_proxy, "SetIpv6Addr",
+ ipsp_param, G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, NULL, NULL);
+ } else {
+ g_variant_unref(ipsp_param);
+ BT_DBG("IPSP disconnected");
+ ipsp_proxy = _bt_get_ipsp_proxy();
+ if (ipsp_proxy == NULL) {
+ BT_ERR("can not get ipsp proxy");
+ g_free(address);
+ g_variant_unref(param);
+ return;
+ }
+
+ g_dbus_proxy_call(ipsp_proxy, "DisableIpsp",
+ NULL, G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, NULL, NULL);
+ }
+
+ /* Send event to application */
+ _bt_send_event(BT_DEVICE_EVENT, event, param);
+ g_free(address);
+ } else if (strcasecmp(member, "AttMtuChanged") == 0) {
+ int result = BLUETOOTH_ERROR_NONE;
+ guint16 mtu = 0;
+ guint8 status = 0;
+
+ g_variant_get(msg, "(q)", &mtu);
+
+ address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+
+ _bt_convert_device_path_to_address(path, address);
+ _bt_convert_addr_string_to_secure_string(secure_address, address);
+ BT_DBG("Address : %s MTU changed : %d", secure_address, mtu);
+
+ param = g_variant_new("(isqy)",
+ result,
+ address,
+ mtu,
+ status);
+
+ /* Send the event to application */
+ _bt_send_event(BT_DEVICE_EVENT,
+ BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED,
+ param);