Index: uspace/drv/bus/usb/ohci/ohci_batch.h
===================================================================
--- uspace/drv/bus/usb/ohci/ohci_batch.h	(revision bbce2c219ee90a62d234a3ddd1cce80b1758a294)
+++ uspace/drv/bus/usb/ohci/ohci_batch.h	(revision f58ef61d1eb8228798d5216b18e8d5bab331b6f3)
@@ -38,5 +38,5 @@
 #include <usbhc_iface.h>
 #include <usb/usb.h>
-#include <usb/host/batch.h>
+#include <usb/host/usb_transfer_batch.h>
 
 #include "hw_struct/transfer_descriptor.h"
Index: uspace/drv/bus/usb/ohci/root_hub.h
===================================================================
--- uspace/drv/bus/usb/ohci/root_hub.h	(revision bbce2c219ee90a62d234a3ddd1cce80b1758a294)
+++ uspace/drv/bus/usb/ohci/root_hub.h	(revision f58ef61d1eb8228798d5216b18e8d5bab331b6f3)
@@ -37,5 +37,5 @@
 #include <usb/usb.h>
 #include <usb/dev/driver.h>
-#include <usb/host/batch.h>
+#include <usb/host/usb_transfer_batch.h>
 
 #include "ohci_regs.h"
@@ -66,5 +66,4 @@
 	/** size of hub descriptor */
 	size_t hub_descriptor_size;
-
 } rh_t;
 
Index: uspace/drv/bus/usb/uhci/hc.h
===================================================================
--- uspace/drv/bus/usb/uhci/hc.h	(revision bbce2c219ee90a62d234a3ddd1cce80b1758a294)
+++ uspace/drv/bus/usb/uhci/hc.h	(revision f58ef61d1eb8228798d5216b18e8d5bab331b6f3)
@@ -39,5 +39,4 @@
 #include <ddi.h>
 
-#include <usb/host/batch.h>
 #include <usb/host/hcd.h>
 
Index: uspace/drv/bus/usb/uhci/uhci_batch.h
===================================================================
--- uspace/drv/bus/usb/uhci/uhci_batch.h	(revision bbce2c219ee90a62d234a3ddd1cce80b1758a294)
+++ uspace/drv/bus/usb/uhci/uhci_batch.h	(revision f58ef61d1eb8228798d5216b18e8d5bab331b6f3)
@@ -35,5 +35,5 @@
 #define DRV_UHCI_BATCH_H
 
-#include <usb/host/batch.h>
+#include <usb/host/usb_transfer_batch.h>
 #include <adt/list.h>
 
Index: uspace/lib/usbhost/Makefile
===================================================================
--- uspace/lib/usbhost/Makefile	(revision bbce2c219ee90a62d234a3ddd1cce80b1758a294)
+++ uspace/lib/usbhost/Makefile	(revision f58ef61d1eb8228798d5216b18e8d5bab331b6f3)
@@ -35,9 +35,9 @@
 
 SOURCES = \
-	src/batch.c \
 	src/device_keeper.c \
 	src/endpoint.c \
 	src/iface.c \
-	src/usb_endpoint_manager.c
+	src/usb_endpoint_manager.c \
+	src/usb_transfer_batch.c
 
 include $(USPACE_PREFIX)/Makefile.common
Index: pace/lib/usbhost/include/usb/host/batch.h
===================================================================
--- uspace/lib/usbhost/include/usb/host/batch.h	(revision bbce2c219ee90a62d234a3ddd1cce80b1758a294)
+++ 	(revision )
@@ -1,129 +1,0 @@
-/*
- * Copyright (c) 2011 Jan Vesely
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-/** @addtogroup libusbhost
- * @{
- */
-/** @file
- * USB transfer transaction structures.
- */
-#ifndef LIBUSBHOST_HOST_BATCH_H
-#define LIBUSBHOST_HOST_BATCH_H
-
-#include <adt/list.h>
-
-#include <usbhc_iface.h>
-#include <usb/usb.h>
-#include <usb/host/endpoint.h>
-
-#define USB_SETUP_PACKET_SIZE 8
-
-typedef struct usb_transfer_batch usb_transfer_batch_t;
-struct usb_transfer_batch {
-	endpoint_t *ep;
-	usbhc_iface_transfer_in_callback_t callback_in;
-	usbhc_iface_transfer_out_callback_t callback_out;
-	void *arg;
-	char *buffer;
-	size_t buffer_size;
-	char setup_buffer[USB_SETUP_PACKET_SIZE];
-	size_t setup_size;
-	size_t transfered_size;
-	int error;
-	ddf_fun_t *fun;
-	void *private_data;
-	void (*private_data_dtor)(void *p_data);
-};
-
-/** Printf formatting string for dumping usb_transfer_batch_t. */
-#define USB_TRANSFER_BATCH_FMT "[%d:%d %s %s-%s %zuB/%zu]"
-
-/** Printf arguments for dumping usb_transfer_batch_t.
- * @param batch USB transfer batch to be dumped.
- */
-#define USB_TRANSFER_BATCH_ARGS(batch) \
-	(batch).ep->address, (batch).ep->endpoint, \
-	usb_str_speed((batch).ep->speed), \
-	usb_str_transfer_type_short((batch).ep->transfer_type), \
-	usb_str_direction((batch).ep->direction), \
-	(batch).buffer_size, (batch).ep->max_packet_size
-
-
-usb_transfer_batch_t * usb_transfer_batch_get(
-    endpoint_t *ep,
-    char *buffer,
-    size_t buffer_size,
-    uint64_t setup_buffer,
-    usbhc_iface_transfer_in_callback_t func_in,
-    usbhc_iface_transfer_out_callback_t func_out,
-    void *arg,
-    ddf_fun_t *fun,
-    void *private_data,
-    void (*private_data_dtor)(void *p_data)
-);
-
-void usb_transfer_batch_finish(usb_transfer_batch_t *instance,
-    const void* data, size_t size);
-void usb_transfer_batch_call_in(usb_transfer_batch_t *instance);
-void usb_transfer_batch_call_out(usb_transfer_batch_t *instance);
-void usb_transfer_batch_dispose(usb_transfer_batch_t *instance);
-
-/** Helper function, calls callback and correctly destroys batch structure.
- *
- * @param[in] instance Batch structure to use.
- */
-static inline void usb_transfer_batch_call_in_and_dispose(
-    usb_transfer_batch_t *instance)
-{
-	assert(instance);
-	usb_transfer_batch_call_in(instance);
-	usb_transfer_batch_dispose(instance);
-}
-/*----------------------------------------------------------------------------*/
-/** Helper function calls callback and correctly destroys batch structure.
- *
- * @param[in] instance Batch structure to use.
- */
-static inline void usb_transfer_batch_call_out_and_dispose(
-    usb_transfer_batch_t *instance)
-{
-	assert(instance);
-	usb_transfer_batch_call_out(instance);
-	usb_transfer_batch_dispose(instance);
-}
-/*----------------------------------------------------------------------------*/
-static inline void usb_transfer_batch_finish_error(
-    usb_transfer_batch_t *instance, const void* data, size_t size, int error)
-{
-	assert(instance);
-	instance->error = error;
-	usb_transfer_batch_finish(instance, data, size);
-}
-#endif
-/**
- * @}
- */
Index: uspace/lib/usbhost/include/usb/host/hcd.h
===================================================================
--- uspace/lib/usbhost/include/usb/host/hcd.h	(revision bbce2c219ee90a62d234a3ddd1cce80b1758a294)
+++ uspace/lib/usbhost/include/usb/host/hcd.h	(revision f58ef61d1eb8228798d5216b18e8d5bab331b6f3)
@@ -39,5 +39,5 @@
 #include <usb/host/device_keeper.h>
 #include <usb/host/usb_endpoint_manager.h>
-#include <usb/host/batch.h>
+#include <usb/host/usb_transfer_batch.h>
 #include <usbhc_iface.h>
 
Index: uspace/lib/usbhost/include/usb/host/usb_transfer_batch.h
===================================================================
--- uspace/lib/usbhost/include/usb/host/usb_transfer_batch.h	(revision f58ef61d1eb8228798d5216b18e8d5bab331b6f3)
+++ uspace/lib/usbhost/include/usb/host/usb_transfer_batch.h	(revision f58ef61d1eb8228798d5216b18e8d5bab331b6f3)
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2011 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/** @addtogroup libusbhost
+ * @{
+ */
+/** @file
+ * USB transfer transaction structures.
+ */
+#ifndef LIBUSBHOST_HOST_USB_TRANSFER_BATCH_H
+#define LIBUSBHOST_HOST_USB_TRANSFER_BATCH_H
+
+#include <adt/list.h>
+
+#include <usbhc_iface.h>
+#include <usb/usb.h>
+#include <usb/host/endpoint.h>
+
+#define USB_SETUP_PACKET_SIZE 8
+
+typedef struct usb_transfer_batch usb_transfer_batch_t;
+struct usb_transfer_batch {
+	endpoint_t *ep;
+	usbhc_iface_transfer_in_callback_t callback_in;
+	usbhc_iface_transfer_out_callback_t callback_out;
+	void *arg;
+	char *buffer;
+	size_t buffer_size;
+	char setup_buffer[USB_SETUP_PACKET_SIZE];
+	size_t setup_size;
+	size_t transfered_size;
+	int error;
+	ddf_fun_t *fun;
+	void *private_data;
+	void (*private_data_dtor)(void *p_data);
+};
+
+/** Printf formatting string for dumping usb_transfer_batch_t. */
+#define USB_TRANSFER_BATCH_FMT "[%d:%d %s %s-%s %zuB/%zu]"
+
+/** Printf arguments for dumping usb_transfer_batch_t.
+ * @param batch USB transfer batch to be dumped.
+ */
+#define USB_TRANSFER_BATCH_ARGS(batch) \
+	(batch).ep->address, (batch).ep->endpoint, \
+	usb_str_speed((batch).ep->speed), \
+	usb_str_transfer_type_short((batch).ep->transfer_type), \
+	usb_str_direction((batch).ep->direction), \
+	(batch).buffer_size, (batch).ep->max_packet_size
+
+
+usb_transfer_batch_t * usb_transfer_batch_get(
+    endpoint_t *ep,
+    char *buffer,
+    size_t buffer_size,
+    uint64_t setup_buffer,
+    usbhc_iface_transfer_in_callback_t func_in,
+    usbhc_iface_transfer_out_callback_t func_out,
+    void *arg,
+    ddf_fun_t *fun,
+    void *private_data,
+    void (*private_data_dtor)(void *p_data)
+);
+
+void usb_transfer_batch_finish(usb_transfer_batch_t *instance,
+    const void* data, size_t size);
+void usb_transfer_batch_call_in(usb_transfer_batch_t *instance);
+void usb_transfer_batch_call_out(usb_transfer_batch_t *instance);
+void usb_transfer_batch_dispose(usb_transfer_batch_t *instance);
+
+/** Helper function, calls callback and correctly destroys batch structure.
+ *
+ * @param[in] instance Batch structure to use.
+ */
+static inline void usb_transfer_batch_call_in_and_dispose(
+    usb_transfer_batch_t *instance)
+{
+	assert(instance);
+	usb_transfer_batch_call_in(instance);
+	usb_transfer_batch_dispose(instance);
+}
+/*----------------------------------------------------------------------------*/
+/** Helper function calls callback and correctly destroys batch structure.
+ *
+ * @param[in] instance Batch structure to use.
+ */
+static inline void usb_transfer_batch_call_out_and_dispose(
+    usb_transfer_batch_t *instance)
+{
+	assert(instance);
+	usb_transfer_batch_call_out(instance);
+	usb_transfer_batch_dispose(instance);
+}
+/*----------------------------------------------------------------------------*/
+static inline void usb_transfer_batch_finish_error(
+    usb_transfer_batch_t *instance, const void* data, size_t size, int error)
+{
+	assert(instance);
+	instance->error = error;
+	usb_transfer_batch_finish(instance, data, size);
+}
+#endif
+/**
+ * @}
+ */
Index: pace/lib/usbhost/src/batch.c
===================================================================
--- uspace/lib/usbhost/src/batch.c	(revision bbce2c219ee90a62d234a3ddd1cce80b1758a294)
+++ 	(revision )
@@ -1,169 +1,0 @@
-/*
- * Copyright (c) 2011 Jan Vesely
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-/** @addtogroup libusbhost
- * @{
- */
-/** @file
- * USB transfer transaction structures (implementation).
- */
-#include <errno.h>
-#include <str_error.h>
-
-#include <usb/usb.h>
-#include <usb/debug.h>
-#include <usb/host/batch.h>
-#include <usb/host/hcd.h>
-
-usb_transfer_batch_t * usb_transfer_batch_get(
-    endpoint_t *ep,
-    char *buffer,
-    size_t buffer_size,
-    uint64_t setup_buffer,
-    usbhc_iface_transfer_in_callback_t func_in,
-    usbhc_iface_transfer_out_callback_t func_out,
-    void *arg,
-    ddf_fun_t *fun,
-    void *private_data,
-    void (*private_data_dtor)(void *)
-    )
-{
-	usb_transfer_batch_t *instance = malloc(sizeof(usb_transfer_batch_t));
-	if (instance) {
-		instance->ep = ep;
-		instance->callback_in = func_in;
-		instance->callback_out = func_out;
-		instance->arg = arg;
-		instance->buffer = buffer;
-		instance->buffer_size = buffer_size;
-		instance->setup_size = 0;
-		instance->fun = fun;
-		instance->private_data = private_data;
-		instance->private_data_dtor = private_data_dtor;
-		instance->transfered_size = 0;
-		instance->error = EOK;
-		if (ep && ep->transfer_type == USB_TRANSFER_CONTROL) {
-			memcpy(instance->setup_buffer, &setup_buffer,
-			    USB_SETUP_PACKET_SIZE);
-			instance->setup_size = USB_SETUP_PACKET_SIZE;
-		}
-		if (instance->ep)
-			endpoint_use(instance->ep);
-	}
-	return instance;
-}
-/*----------------------------------------------------------------------------*/
-/** Mark batch as finished and continue with next step.
- *
- * @param[in] instance Batch structure to use.
- *
- */
-void usb_transfer_batch_finish(
-    usb_transfer_batch_t *instance, const void *data, size_t size)
-{
-	assert(instance);
-	assert(instance->ep);
-	/* we care about the data and there are some to copy */
-        if (instance->ep->direction != USB_DIRECTION_OUT
-	    && data) {
-		const size_t min_size =
-		    size < instance->buffer_size ? size : instance->buffer_size;
-                memcpy(instance->buffer, data, min_size);
-        }
-        if (instance->callback_out)
-                usb_transfer_batch_call_out(instance);
-        if (instance->callback_in)
-                usb_transfer_batch_call_in(instance);
-
-}
-/*----------------------------------------------------------------------------*/
-/** Prepare data, get error status and call callback in.
- *
- * @param[in] instance Batch structure to use.
- * Copies data from transport buffer, and calls callback with appropriate
- * parameters.
- */
-void usb_transfer_batch_call_in(usb_transfer_batch_t *instance)
-{
-	assert(instance);
-	assert(instance->callback_in);
-
-	usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " completed (%zuB): %s.\n",
-	    instance, USB_TRANSFER_BATCH_ARGS(*instance),
-	    instance->transfered_size, str_error(instance->error));
-
-	instance->callback_in(instance->fun, instance->error,
-	    instance->transfered_size, instance->arg);
-}
-/*----------------------------------------------------------------------------*/
-/** Get error status and call callback out.
- *
- * @param[in] instance Batch structure to use.
- */
-void usb_transfer_batch_call_out(usb_transfer_batch_t *instance)
-{
-	assert(instance);
-	assert(instance->callback_out);
-
-	usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " completed: %s.\n",
-	    instance, USB_TRANSFER_BATCH_ARGS(*instance),
-	    str_error(instance->error));
-
-	if (instance->ep->transfer_type == USB_TRANSFER_CONTROL
-	    && instance->error == EOK) {
-		const usb_target_t target =
-		    {{ instance->ep->address, instance->ep->endpoint }};
-		reset_ep_if_need(
-		    fun_to_hcd(instance->fun), target, instance->setup_buffer);
-	}
-
-	instance->callback_out(instance->fun,
-	    instance->error, instance->arg);
-}
-/*----------------------------------------------------------------------------*/
-/** Correctly dispose all used data structures.
- *
- * @param[in] instance Batch structure to use.
- */
-void usb_transfer_batch_dispose(usb_transfer_batch_t *instance)
-{
-	if (!instance)
-		return;
-	usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " disposing.\n",
-	    instance, USB_TRANSFER_BATCH_ARGS(*instance));
-	if (instance->ep) {
-		endpoint_release(instance->ep);
-	}
-	if (instance->private_data) {
-		assert(instance->private_data_dtor);
-		instance->private_data_dtor(instance->private_data);
-	}
-	free(instance);
-}
-/**
- * @}
- */
Index: uspace/lib/usbhost/src/usb_transfer_batch.c
===================================================================
--- uspace/lib/usbhost/src/usb_transfer_batch.c	(revision f58ef61d1eb8228798d5216b18e8d5bab331b6f3)
+++ uspace/lib/usbhost/src/usb_transfer_batch.c	(revision f58ef61d1eb8228798d5216b18e8d5bab331b6f3)
@@ -0,0 +1,169 @@
+/*
+ * Copyright (c) 2011 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/** @addtogroup libusbhost
+ * @{
+ */
+/** @file
+ * USB transfer transaction structures (implementation).
+ */
+#include <errno.h>
+#include <str_error.h>
+
+#include <usb/usb.h>
+#include <usb/debug.h>
+#include <usb/host/usb_transfer_batch.h>
+#include <usb/host/hcd.h>
+
+usb_transfer_batch_t * usb_transfer_batch_get(
+    endpoint_t *ep,
+    char *buffer,
+    size_t buffer_size,
+    uint64_t setup_buffer,
+    usbhc_iface_transfer_in_callback_t func_in,
+    usbhc_iface_transfer_out_callback_t func_out,
+    void *arg,
+    ddf_fun_t *fun,
+    void *private_data,
+    void (*private_data_dtor)(void *)
+    )
+{
+	usb_transfer_batch_t *instance = malloc(sizeof(usb_transfer_batch_t));
+	if (instance) {
+		instance->ep = ep;
+		instance->callback_in = func_in;
+		instance->callback_out = func_out;
+		instance->arg = arg;
+		instance->buffer = buffer;
+		instance->buffer_size = buffer_size;
+		instance->setup_size = 0;
+		instance->fun = fun;
+		instance->private_data = private_data;
+		instance->private_data_dtor = private_data_dtor;
+		instance->transfered_size = 0;
+		instance->error = EOK;
+		if (ep && ep->transfer_type == USB_TRANSFER_CONTROL) {
+			memcpy(instance->setup_buffer, &setup_buffer,
+			    USB_SETUP_PACKET_SIZE);
+			instance->setup_size = USB_SETUP_PACKET_SIZE;
+		}
+		if (instance->ep)
+			endpoint_use(instance->ep);
+	}
+	return instance;
+}
+/*----------------------------------------------------------------------------*/
+/** Mark batch as finished and continue with next step.
+ *
+ * @param[in] instance Batch structure to use.
+ *
+ */
+void usb_transfer_batch_finish(
+    usb_transfer_batch_t *instance, const void *data, size_t size)
+{
+	assert(instance);
+	assert(instance->ep);
+	/* we care about the data and there are some to copy */
+        if (instance->ep->direction != USB_DIRECTION_OUT
+	    && data) {
+		const size_t min_size =
+		    size < instance->buffer_size ? size : instance->buffer_size;
+                memcpy(instance->buffer, data, min_size);
+        }
+        if (instance->callback_out)
+                usb_transfer_batch_call_out(instance);
+        if (instance->callback_in)
+                usb_transfer_batch_call_in(instance);
+
+}
+/*----------------------------------------------------------------------------*/
+/** Prepare data, get error status and call callback in.
+ *
+ * @param[in] instance Batch structure to use.
+ * Copies data from transport buffer, and calls callback with appropriate
+ * parameters.
+ */
+void usb_transfer_batch_call_in(usb_transfer_batch_t *instance)
+{
+	assert(instance);
+	assert(instance->callback_in);
+
+	usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " completed (%zuB): %s.\n",
+	    instance, USB_TRANSFER_BATCH_ARGS(*instance),
+	    instance->transfered_size, str_error(instance->error));
+
+	instance->callback_in(instance->fun, instance->error,
+	    instance->transfered_size, instance->arg);
+}
+/*----------------------------------------------------------------------------*/
+/** Get error status and call callback out.
+ *
+ * @param[in] instance Batch structure to use.
+ */
+void usb_transfer_batch_call_out(usb_transfer_batch_t *instance)
+{
+	assert(instance);
+	assert(instance->callback_out);
+
+	usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " completed: %s.\n",
+	    instance, USB_TRANSFER_BATCH_ARGS(*instance),
+	    str_error(instance->error));
+
+	if (instance->ep->transfer_type == USB_TRANSFER_CONTROL
+	    && instance->error == EOK) {
+		const usb_target_t target =
+		    {{ instance->ep->address, instance->ep->endpoint }};
+		reset_ep_if_need(
+		    fun_to_hcd(instance->fun), target, instance->setup_buffer);
+	}
+
+	instance->callback_out(instance->fun,
+	    instance->error, instance->arg);
+}
+/*----------------------------------------------------------------------------*/
+/** Correctly dispose all used data structures.
+ *
+ * @param[in] instance Batch structure to use.
+ */
+void usb_transfer_batch_dispose(usb_transfer_batch_t *instance)
+{
+	if (!instance)
+		return;
+	usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT " disposing.\n",
+	    instance, USB_TRANSFER_BATCH_ARGS(*instance));
+	if (instance->ep) {
+		endpoint_release(instance->ep);
+	}
+	if (instance->private_data) {
+		assert(instance->private_data_dtor);
+		instance->private_data_dtor(instance->private_data);
+	}
+	free(instance);
+}
+/**
+ * @}
+ */
