Index: uspace/lib/usbvirt/src/ipc_hc.c
===================================================================
--- uspace/lib/usbvirt/src/ipc_hc.c	(revision beee81a7687467f9672b71143423415145ae7160)
+++ uspace/lib/usbvirt/src/ipc_hc.c	(revision 4a4c8bcf0ce34cbf901b7d7d1d02ef84f5b04d48)
@@ -45,5 +45,5 @@
 /** Send control read transfer to virtual USB device.
  *
- * @param phone IPC phone to the virtual device.
+ * @param sess Session to the virtual device.
  * @param ep Target endpoint number.
  * @param setup_buffer Setup buffer.
@@ -52,64 +52,67 @@
  * @param data_buffer_size Size of data buffer in bytes.
  * @param data_transfered_size Number of actually transferred bytes.
+ *
  * @return Error code.
- */
-int usbvirt_ipc_send_control_read(int phone,
-    void *setup_buffer, size_t setup_buffer_size,
-    void *data_buffer, size_t data_buffer_size, size_t *data_transfered_size)
+ *
+ */
+int usbvirt_ipc_send_control_read(async_sess_t *sess, void *setup_buffer,
+    size_t setup_buffer_size, void *data_buffer, size_t data_buffer_size,
+    size_t *data_transfered_size)
 {
-	if (phone < 0) {
-		return EINVAL;
-	}
-	if ((setup_buffer == NULL) || (setup_buffer_size == 0)) {
-		return EINVAL;
-	}
-	if ((data_buffer == NULL) || (data_buffer_size == 0)) {
-		return EINVAL;
-	}
-
-	aid_t opening_request = async_send_0(phone,
-	    IPC_M_USBVIRT_CONTROL_READ, NULL);
+	if (!sess)
+		return EINVAL;
+	
+	if ((setup_buffer == NULL) || (setup_buffer_size == 0))
+		return EINVAL;
+	
+	if ((data_buffer == NULL) || (data_buffer_size == 0))
+		return EINVAL;
+	
+	async_exch_t *exch = async_exchange_begin(sess);
+	
+	aid_t opening_request = async_send_0(exch, IPC_M_USBVIRT_CONTROL_READ,
+	    NULL);
 	if (opening_request == 0) {
-		return ENOMEM;
-	}
-
-	int rc = async_data_write_start(phone,
-	    setup_buffer, setup_buffer_size);
+		async_exchange_end(exch);
+		return ENOMEM;
+	}
+	
+	int rc = async_data_write_start(exch, setup_buffer, setup_buffer_size);
 	if (rc != EOK) {
+		async_exchange_end(exch);
 		async_wait_for(opening_request, NULL);
 		return rc;
 	}
-
+	
 	ipc_call_t data_request_call;
-	aid_t data_request = async_data_read(phone,
-	    data_buffer, data_buffer_size,
+	aid_t data_request = async_data_read(exch, data_buffer, data_buffer_size,
 	    &data_request_call);
-
+	
+	async_exchange_end(exch);
+	
 	if (data_request == 0) {
 		async_wait_for(opening_request, NULL);
 		return ENOMEM;
 	}
-
+	
 	sysarg_t data_request_rc;
 	sysarg_t opening_request_rc;
 	async_wait_for(data_request, &data_request_rc);
 	async_wait_for(opening_request, &opening_request_rc);
-
+	
 	if (data_request_rc != EOK) {
 		/* Prefer the return code of the opening request. */
-		if (opening_request_rc != EOK) {
+		if (opening_request_rc != EOK)
 			return (int) opening_request_rc;
-		} else {
+		else
 			return (int) data_request_rc;
-		}
-	}
-	if (opening_request_rc != EOK) {
+	}
+	
+	if (opening_request_rc != EOK)
 		return (int) opening_request_rc;
-	}
-
-	if (data_transfered_size != NULL) {
+	
+	if (data_transfered_size != NULL)
 		*data_transfered_size = IPC_GET_ARG2(data_request_call);
-	}
-
+	
 	return EOK;
 }
@@ -117,5 +120,5 @@
 /** Send control write transfer to virtual USB device.
  *
- * @param phone IPC phone to the virtual device.
+ * @param sess Session to the virtual device.
  * @param ep Target endpoint number.
  * @param setup_buffer Setup buffer.
@@ -123,46 +126,50 @@
  * @param data_buffer Data buffer (DATA stage of control transfer).
  * @param data_buffer_size Size of data buffer in bytes.
+ *
  * @return Error code.
- */
-int usbvirt_ipc_send_control_write(int phone,
-    void *setup_buffer, size_t setup_buffer_size,
-    void *data_buffer, size_t data_buffer_size)
+ *
+ */
+int usbvirt_ipc_send_control_write(async_sess_t *sess, void *setup_buffer,
+    size_t setup_buffer_size, void *data_buffer, size_t data_buffer_size)
 {
-	if (phone < 0) {
-		return EINVAL;
-	}
-	if ((setup_buffer == NULL) || (setup_buffer_size == 0)) {
-		return EINVAL;
-	}
-	if ((data_buffer_size > 0) && (data_buffer == NULL)) {
-		return EINVAL;
-	}
-
-	aid_t opening_request = async_send_1(phone,
-	    IPC_M_USBVIRT_CONTROL_WRITE, data_buffer_size,  NULL);
+	if (!sess)
+		return EINVAL;
+	
+	if ((setup_buffer == NULL) || (setup_buffer_size == 0))
+		return EINVAL;
+	
+	if ((data_buffer_size > 0) && (data_buffer == NULL))
+		return EINVAL;
+	
+	async_exch_t *exch = async_exchange_begin(sess);
+	
+	aid_t opening_request = async_send_1(exch, IPC_M_USBVIRT_CONTROL_WRITE,
+	    data_buffer_size, NULL);
 	if (opening_request == 0) {
-		return ENOMEM;
-	}
-
-	int rc = async_data_write_start(phone,
-	    setup_buffer, setup_buffer_size);
+		async_exchange_end(exch);
+		return ENOMEM;
+	}
+	
+	int rc = async_data_write_start(exch, setup_buffer, setup_buffer_size);
 	if (rc != EOK) {
+		async_exchange_end(exch);
 		async_wait_for(opening_request, NULL);
 		return rc;
 	}
-
+	
 	if (data_buffer_size > 0) {
-		rc = async_data_write_start(phone,
-		    data_buffer, data_buffer_size);
-
+		rc = async_data_write_start(exch, data_buffer, data_buffer_size);
 		if (rc != EOK) {
+			async_exchange_end(exch);
 			async_wait_for(opening_request, NULL);
 			return rc;
 		}
 	}
-
+	
+	async_exchange_end(exch);
+	
 	sysarg_t opening_request_rc;
 	async_wait_for(opening_request, &opening_request_rc);
-
+	
 	return (int) opening_request_rc;
 }
@@ -170,5 +177,5 @@
 /** Request data transfer from virtual USB device.
  *
- * @param phone IPC phone to the virtual device.
+ * @param sess Session to the virtual device.
  * @param ep Target endpoint number.
  * @param tr_type Transfer type (interrupt or bulk).
@@ -176,13 +183,16 @@
  * @param data_size Size of the data buffer in bytes.
  * @param act_size Number of actually returned bytes.
+ *
  * @return Error code.
- */
-int usbvirt_ipc_send_data_in(int phone, usb_endpoint_t ep,
+ *
+ */
+int usbvirt_ipc_send_data_in(async_sess_t *sess, usb_endpoint_t ep,
     usb_transfer_type_t tr_type, void *data, size_t data_size, size_t *act_size)
 {
-	if (phone < 0) {
-		return EINVAL;
-	}
+	if (!sess)
+		return EINVAL;
+	
 	usbvirt_hc_to_device_method_t method;
+	
 	switch (tr_type) {
 	case USB_TRANSFER_INTERRUPT:
@@ -195,48 +205,49 @@
 		return EINVAL;
 	}
-	if ((ep <= 0) || (ep >= USBVIRT_ENDPOINT_MAX)) {
-		return EINVAL;
-	}
-	if ((data == NULL) || (data_size == 0)) {
-		return EINVAL;
-	}
-
-
-	aid_t opening_request = async_send_2(phone, method, ep, tr_type, NULL);
+	
+	if ((ep <= 0) || (ep >= USBVIRT_ENDPOINT_MAX))
+		return EINVAL;
+	
+	if ((data == NULL) || (data_size == 0))
+		return EINVAL;
+	
+	async_exch_t *exch = async_exchange_begin(sess);
+	
+	aid_t opening_request = async_send_2(exch, method, ep, tr_type, NULL);
 	if (opening_request == 0) {
-		return ENOMEM;
-	}
-
-
+		async_exchange_end(exch);
+		return ENOMEM;
+	}
+	
 	ipc_call_t data_request_call;
-	aid_t data_request = async_data_read(phone,
-	    data, data_size,  &data_request_call);
-
+	aid_t data_request = async_data_read(exch, data, data_size,
+	    &data_request_call);
+	
+	async_exchange_end(exch);
+	
 	if (data_request == 0) {
 		async_wait_for(opening_request, NULL);
 		return ENOMEM;
 	}
-
+	
 	sysarg_t data_request_rc;
 	sysarg_t opening_request_rc;
 	async_wait_for(data_request, &data_request_rc);
 	async_wait_for(opening_request, &opening_request_rc);
-
+	
 	if (data_request_rc != EOK) {
 		/* Prefer the return code of the opening request. */
-		if (opening_request_rc != EOK) {
+		if (opening_request_rc != EOK)
 			return (int) opening_request_rc;
-		} else {
+		else
 			return (int) data_request_rc;
-		}
-	}
-	if (opening_request_rc != EOK) {
+	}
+	
+	if (opening_request_rc != EOK)
 		return (int) opening_request_rc;
-	}
-
-	if (act_size != NULL) {
+	
+	if (act_size != NULL)
 		*act_size = IPC_GET_ARG2(data_request_call);
-	}
-
+	
 	return EOK;
 }
@@ -244,18 +255,21 @@
 /** Send data to virtual USB device.
  *
- * @param phone IPC phone to the virtual device.
+ * @param sess Session to the virtual device.
  * @param ep Target endpoint number.
  * @param tr_type Transfer type (interrupt or bulk).
  * @param data Data buffer.
  * @param data_size Size of the data buffer in bytes.
+ *
  * @return Error code.
- */
-int usbvirt_ipc_send_data_out(int phone, usb_endpoint_t ep,
+ *
+ */
+int usbvirt_ipc_send_data_out(async_sess_t *sess, usb_endpoint_t ep,
     usb_transfer_type_t tr_type, void *data, size_t data_size)
 {
-	if (phone < 0) {
-		return EINVAL;
-	}
+	if (!sess)
+		return EINVAL;
+	
 	usbvirt_hc_to_device_method_t method;
+	
 	switch (tr_type) {
 	case USB_TRANSFER_INTERRUPT:
@@ -268,30 +282,34 @@
 		return EINVAL;
 	}
-	if ((ep <= 0) || (ep >= USBVIRT_ENDPOINT_MAX)) {
-		return EINVAL;
-	}
-	if ((data == NULL) || (data_size == 0)) {
-		return EINVAL;
-	}
-
-	aid_t opening_request = async_send_1(phone, method, ep, NULL);
+	
+	if ((ep <= 0) || (ep >= USBVIRT_ENDPOINT_MAX))
+		return EINVAL;
+	
+	if ((data == NULL) || (data_size == 0))
+		return EINVAL;
+	
+	async_exch_t *exch = async_exchange_begin(sess);
+	
+	aid_t opening_request = async_send_1(exch, method, ep, NULL);
 	if (opening_request == 0) {
-		return ENOMEM;
-	}
-
-	int rc = async_data_write_start(phone,
-	    data, data_size);
+		async_exchange_end(exch);
+		return ENOMEM;
+	}
+	
+	int rc = async_data_write_start(exch, data, data_size);
+	
+	async_exchange_end(exch);
+	
 	if (rc != EOK) {
 		async_wait_for(opening_request, NULL);
 		return rc;
 	}
-
+	
 	sysarg_t opening_request_rc;
 	async_wait_for(opening_request, &opening_request_rc);
-
+	
 	return (int) opening_request_rc;
 }
 
-
 /**
  * @}
