Merge "Fix channel connected signal emission." into ics-mr1
diff --git a/health/hdp.c b/health/hdp.c
index df388bc..943e713 100644
--- a/health/hdp.c
+++ b/health/hdp.c
@@ -479,8 +479,22 @@
 
 static void abort_mdl_cb(GError *err, gpointer data)
 {
+	struct hdp_device *dev;
+	struct hdp_channel *hdp_chan = data;
 	if (err)
 		error("Aborting error: %s", err->message);
+
+	if (hdp_chan) {
+		dev = hdp_chan->dev;
+		if (dev && hdp_chan->mdep != HDP_MDEP_ECHO)
+			g_dbus_emit_signal(dev->conn,
+						device_get_path(dev->dev),
+						HEALTH_DEVICE,
+						"ChannelConnected",
+						DBUS_TYPE_OBJECT_PATH,
+						&hdp_chan->path,
+						DBUS_TYPE_INVALID);
+	}
 }
 
 static void hdp_mdl_reconn_cb(struct mcap_mdl *mdl, GError *err, gpointer data)
@@ -1646,7 +1660,7 @@
 
 		/* Send abort request because remote side */
 		/* is now in PENDING state */
-		if (!mcap_mdl_abort(hdp_chann->mdl, abort_mdl_cb, NULL,
+		if (!mcap_mdl_abort(hdp_chann->mdl, abort_mdl_cb, hdp_chann,
 								NULL, &gerr)) {
 			error("%s", gerr->message);
 			g_error_free(gerr);
@@ -1669,6 +1683,15 @@
 
 	dev->fr = hdp_channel_ref(hdp_chann);
 
+	if (dev->fr->mdep != HDP_MDEP_ECHO)
+		g_dbus_emit_signal(dev->conn,
+					device_get_path(dev->dev),
+					HEALTH_DEVICE,
+					"ChannelConnected",
+					DBUS_TYPE_OBJECT_PATH, &dev->fr->path,
+					DBUS_TYPE_INVALID);
+
+
 	emit_property_changed(dev->conn, device_get_path(dev->dev),
 					HEALTH_DEVICE, "MainChannel",
 					DBUS_TYPE_OBJECT_PATH, &dev->fr->path);
@@ -1713,14 +1736,6 @@
 	if (!hdp_chan)
 		goto fail;
 
-	if (user_data->mdep != HDP_MDEP_ECHO)
-		g_dbus_emit_signal(user_data->conn,
-					device_get_path(hdp_chan->dev->dev),
-					HEALTH_DEVICE,
-					"ChannelConnected",
-					DBUS_TYPE_OBJECT_PATH, &hdp_chan->path,
-					DBUS_TYPE_INVALID);
-
 	hdp_conn = g_new0(struct hdp_tmp_dc_data, 1);
 	hdp_conn->msg = dbus_message_ref(user_data->msg);
 	hdp_conn->conn = dbus_connection_ref(user_data->conn);
@@ -1743,7 +1758,7 @@
 	hdp_tmp_dc_data_unref(hdp_conn);
 
 	/* Send abort request because remote side is now in PENDING state */
-	if (!mcap_mdl_abort(mdl, abort_mdl_cb, NULL, NULL, &gerr)) {
+	if (!mcap_mdl_abort(mdl, abort_mdl_cb, hdp_chan, NULL, &gerr)) {
 		error("%s", gerr->message);
 		g_error_free(gerr);
 	}