Index: uspace/lib/drv/generic/remote_usbhc.c
===================================================================
--- uspace/lib/drv/generic/remote_usbhc.c	(revision 93f8da1abf394c603ef6b2571403715c0a8fb522)
+++ uspace/lib/drv/generic/remote_usbhc.c	(revision 584249332da929438e2776e3a1e91d867373dc35)
@@ -33,5 +33,4 @@
  */
 
-#include <ipc/ipc.h>
 #include <async.h>
 #include <errno.h>
@@ -43,5 +42,4 @@
 
 static void remote_usbhc_get_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
-static void remote_usbhc_get_buffer(device_t *, void *, ipc_callid_t, ipc_call_t *);
 static void remote_usbhc_interrupt_out(device_t *, void *, ipc_callid_t, ipc_call_t *);
 static void remote_usbhc_interrupt_in(device_t *, void *, ipc_callid_t, ipc_call_t *);
@@ -65,6 +63,4 @@
 	remote_usbhc_get_address,
 
-	remote_usbhc_get_buffer,
-
 	remote_usbhc_reserve_default_address,
 	remote_usbhc_release_default_address,
@@ -99,4 +95,5 @@
 typedef struct {
 	ipc_callid_t caller;
+	ipc_callid_t data_caller;
 	void *buffer;
 	void *setup_packet;
@@ -128,4 +125,5 @@
 
 	trans->caller = caller;
+	trans->data_caller = 0;
 	trans->buffer = NULL;
 	trans->setup_packet = NULL;
@@ -141,5 +139,5 @@
 
 	if (!usb_iface->tell_address) {
-		ipc_answer_0(callid, ENOTSUP);
+		async_answer_0(callid, ENOTSUP);
 		return;
 	}
@@ -150,41 +148,8 @@
 	int rc = usb_iface->tell_address(device, handle, &address);
 	if (rc != EOK) {
-		ipc_answer_0(callid, rc);
+		async_answer_0(callid, rc);
 	} else {
-		ipc_answer_1(callid, EOK, address);
-	}
-}
-
-void remote_usbhc_get_buffer(device_t *device, void *iface,
-    ipc_callid_t callid, ipc_call_t *call)
-{
-	sysarg_t buffer_hash = DEV_IPC_GET_ARG1(*call);
-	async_transaction_t * trans = (async_transaction_t *)buffer_hash;
-	if (trans == NULL) {
-		ipc_answer_0(callid, ENOENT);
-		return;
-	}
-	if (trans->buffer == NULL) {
-		ipc_answer_0(callid, EINVAL);
-		async_transaction_destroy(trans);
-		return;
-	}
-
-	ipc_callid_t cid;
-	size_t accepted_size;
-	if (!async_data_read_receive(&cid, &accepted_size)) {
-		ipc_answer_0(callid, EINVAL);
-		async_transaction_destroy(trans);
-		return;
-	}
-
-	if (accepted_size > trans->size) {
-		accepted_size = trans->size;
-	}
-	async_data_read_finalize(cid, trans->buffer, accepted_size);
-
-	ipc_answer_1(callid, EOK, accepted_size);
-
-	async_transaction_destroy(trans);
+		async_answer_1(callid, EOK, address);
+	}
 }
 
@@ -195,5 +160,5 @@
 
 	if (!usb_iface->reserve_default_address) {
-		ipc_answer_0(callid, ENOTSUP);
+		async_answer_0(callid, ENOTSUP);
 		return;
 	}
@@ -201,5 +166,5 @@
 	int rc = usb_iface->reserve_default_address(device);
 
-	ipc_answer_0(callid, rc);
+	async_answer_0(callid, rc);
 }
 
@@ -210,5 +175,5 @@
 
 	if (!usb_iface->release_default_address) {
-		ipc_answer_0(callid, ENOTSUP);
+		async_answer_0(callid, ENOTSUP);
 		return;
 	}
@@ -216,5 +181,5 @@
 	int rc = usb_iface->release_default_address(device);
 
-	ipc_answer_0(callid, rc);
+	async_answer_0(callid, rc);
 }
 
@@ -225,5 +190,5 @@
 
 	if (!usb_iface->request_address) {
-		ipc_answer_0(callid, ENOTSUP);
+		async_answer_0(callid, ENOTSUP);
 		return;
 	}
@@ -232,7 +197,7 @@
 	int rc = usb_iface->request_address(device, &address);
 	if (rc != EOK) {
-		ipc_answer_0(callid, rc);
+		async_answer_0(callid, rc);
 	} else {
-		ipc_answer_1(callid, EOK, (sysarg_t) address);
+		async_answer_1(callid, EOK, (sysarg_t) address);
 	}
 }
@@ -244,5 +209,5 @@
 
 	if (!usb_iface->bind_address) {
-		ipc_answer_0(callid, ENOTSUP);
+		async_answer_0(callid, ENOTSUP);
 		return;
 	}
@@ -253,5 +218,5 @@
 	int rc = usb_iface->bind_address(device, address, handle);
 
-	ipc_answer_0(callid, rc);
+	async_answer_0(callid, rc);
 }
 
@@ -262,5 +227,5 @@
 
 	if (!usb_iface->release_address) {
-		ipc_answer_0(callid, ENOTSUP);
+		async_answer_0(callid, ENOTSUP);
 		return;
 	}
@@ -270,5 +235,5 @@
 	int rc = usb_iface->release_address(device, address);
 
-	ipc_answer_0(callid, rc);
+	async_answer_0(callid, rc);
 }
 
@@ -279,5 +244,5 @@
 	async_transaction_t *trans = (async_transaction_t *)arg;
 
-	ipc_answer_0(trans->caller, outcome);
+	async_answer_0(trans->caller, outcome);
 
 	async_transaction_destroy(trans);
@@ -290,5 +255,8 @@
 
 	if (outcome != USB_OUTCOME_OK) {
-		ipc_answer_0(trans->caller, outcome);
+		async_answer_0(trans->caller, outcome);
+		if (trans->data_caller) {
+			async_answer_0(trans->data_caller, EINTR);
+		}
 		async_transaction_destroy(trans);
 		return;
@@ -296,5 +264,13 @@
 
 	trans->size = actual_size;
-	ipc_answer_1(trans->caller, USB_OUTCOME_OK, (sysarg_t)trans);
+
+	if (trans->data_caller) {
+		async_data_read_finalize(trans->data_caller,
+		    trans->buffer, actual_size);
+	}
+
+	async_answer_0(trans->caller, USB_OUTCOME_OK);
+
+	async_transaction_destroy(trans);
 }
 
@@ -311,5 +287,5 @@
 {
 	if (!transfer_func) {
-		ipc_answer_0(callid, ENOTSUP);
+		async_answer_0(callid, ENOTSUP);
 		return;
 	}
@@ -329,5 +305,5 @@
 
 		if (rc != EOK) {
-			ipc_answer_0(callid, rc);
+			async_answer_0(callid, rc);
 			return;
 		}
@@ -339,5 +315,5 @@
 			free(buffer);
 		}
-		ipc_answer_0(callid, ENOMEM);
+		async_answer_0(callid, ENOMEM);
 		return;
 	}
@@ -350,5 +326,5 @@
 
 	if (rc != EOK) {
-		ipc_answer_0(callid, rc);
+		async_answer_0(callid, rc);
 		async_transaction_destroy(trans);
 	}
@@ -367,5 +343,5 @@
 {
 	if (!transfer_func) {
-		ipc_answer_0(callid, ENOTSUP);
+		async_answer_0(callid, ENOTSUP);
 		return;
 	}
@@ -377,9 +353,16 @@
 	};
 
+	ipc_callid_t data_callid;
+	if (!async_data_read_receive(&data_callid, &len)) {
+		async_answer_0(callid, EPARTY);
+		return;
+	}
+
 	async_transaction_t *trans = async_transaction_create(callid);
 	if (trans == NULL) {
-		ipc_answer_0(callid, ENOMEM);
-		return;
-	}
+		async_answer_0(callid, ENOMEM);
+		return;
+	}
+	trans->data_caller = data_callid;
 	trans->buffer = malloc(len);
 	trans->size = len;
@@ -389,5 +372,5 @@
 
 	if (rc != EOK) {
-		ipc_answer_0(callid, rc);
+		async_answer_0(callid, rc);
 		async_transaction_destroy(trans);
 	}
@@ -414,5 +397,5 @@
 		case USB_DIRECTION_IN:
 			if (!transfer_in_func) {
-				ipc_answer_0(callid, ENOTSUP);
+				async_answer_0(callid, ENOTSUP);
 				return;
 			}
@@ -420,5 +403,5 @@
 		case USB_DIRECTION_OUT:
 			if (!transfer_out_func) {
-				ipc_answer_0(callid, ENOTSUP);
+				async_answer_0(callid, ENOTSUP);
 				return;
 			}
@@ -436,5 +419,5 @@
 	async_transaction_t *trans = async_transaction_create(callid);
 	if (trans == NULL) {
-		ipc_answer_0(callid, ENOMEM);
+		async_answer_0(callid, ENOMEM);
 		return;
 	}
@@ -456,5 +439,5 @@
 
 	if (rc != EOK) {
-		ipc_answer_0(callid, rc);
+		async_answer_0(callid, rc);
 		async_transaction_destroy(trans);
 	}
@@ -549,5 +532,5 @@
 
 	if (!usb_iface->control_write) {
-		ipc_answer_0(callid, ENOTSUP);
+		async_answer_0(callid, ENOTSUP);
 		return;
 	}
@@ -568,5 +551,5 @@
 	    1, USB_MAX_PAYLOAD_SIZE, 0, &setup_packet_len);
 	if (rc != EOK) {
-		ipc_answer_0(callid, rc);
+		async_answer_0(callid, rc);
 		return;
 	}
@@ -574,5 +557,5 @@
 	    1, USB_MAX_PAYLOAD_SIZE, 0, &data_buffer_len);
 	if (rc != EOK) {
-		ipc_answer_0(callid, rc);
+		async_answer_0(callid, rc);
 		free(setup_packet);
 		return;
@@ -581,5 +564,5 @@
 	async_transaction_t *trans = async_transaction_create(callid);
 	if (trans == NULL) {
-		ipc_answer_0(callid, ENOMEM);
+		async_answer_0(callid, ENOMEM);
 		free(setup_packet);
 		free(data_buffer);
@@ -596,5 +579,5 @@
 
 	if (rc != EOK) {
-		ipc_answer_0(callid, rc);
+		async_answer_0(callid, rc);
 		async_transaction_destroy(trans);
 	}
@@ -609,5 +592,5 @@
 
 	if (!usb_iface->control_read) {
-		ipc_answer_0(callid, ENOTSUP);
+		async_answer_0(callid, ENOTSUP);
 		return;
 	}
@@ -627,5 +610,12 @@
 	    1, USB_MAX_PAYLOAD_SIZE, 0, &setup_packet_len);
 	if (rc != EOK) {
-		ipc_answer_0(callid, rc);
+		async_answer_0(callid, rc);
+		return;
+	}
+
+	ipc_callid_t data_callid;
+	if (!async_data_read_receive(&data_callid, &data_len)) {
+		async_answer_0(callid, EPARTY);
+		free(setup_packet);
 		return;
 	}
@@ -633,13 +623,14 @@
 	async_transaction_t *trans = async_transaction_create(callid);
 	if (trans == NULL) {
-		ipc_answer_0(callid, ENOMEM);
+		async_answer_0(callid, ENOMEM);
 		free(setup_packet);
 		return;
 	}
+	trans->data_caller = data_callid;
 	trans->setup_packet = setup_packet;
 	trans->size = data_len;
 	trans->buffer = malloc(data_len);
 	if (trans->buffer == NULL) {
-		ipc_answer_0(callid, ENOMEM);
+		async_answer_0(callid, ENOMEM);
 		async_transaction_destroy(trans);
 		return;
@@ -652,5 +643,5 @@
 
 	if (rc != EOK) {
-		ipc_answer_0(callid, rc);
+		async_answer_0(callid, rc);
 		async_transaction_destroy(trans);
 	}
