Index: uspace/app/netstart/self_test.c
===================================================================
--- uspace/app/netstart/self_test.c	(revision 37f7cfe6ab80448fed991af05947b5c57080be0f)
+++ 	(revision )
@@ -1,334 +1,0 @@
-/*
- * Copyright (c) 2009 Lukas Mejdrech
- * 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 net
- * @{
- */
-
-/** @file
- * Networking self-tests implementation.
- *
- */
-
-#include <errno.h>
-#include <malloc.h>
-#include <stdio.h>
-
-#include <net_checksum.h>
-#include <adt/int_map.h>
-#include <adt/char_map.h>
-#include <adt/generic_char_map.h>
-#include <adt/measured_strings.h>
-#include <adt/dynamic_fifo.h>
-
-#include "self_test.h"
-
-/** Test the statement, compare the result and evaluate.
- *
- * @param[in] statement The statement to test.
- * @param[in] result    The expected result.
- *
- */
-#define TEST(statement, result) \
-	do { \
-		printf("\n\t%s == %s", #statement, #result); \
-		if ((statement) != (result)) { \
-			printf("\tfailed\n"); \
-			fprintf(stderr, "\nNetwork self-test failed\n"); \
-			return EINVAL; \
-		} else \
-			printf("\tOK"); \
-	} while (0)
-
-#define XMALLOC(var, type) \
-	do { \
-		(var) = (type *) malloc(sizeof(type)); \
-		if ((var) == NULL) { \
-			fprintf(stderr, "\nMemory allocation error\n"); \
-			return ENOMEM; \
-		} \
-	} while (0)
-
-GENERIC_CHAR_MAP_DECLARE(int_char_map, int);
-GENERIC_CHAR_MAP_IMPLEMENT(int_char_map, int);
-
-GENERIC_FIELD_DECLARE(int_field, int);
-GENERIC_FIELD_IMPLEMENT(int_field, int);
-
-INT_MAP_DECLARE(int_map, int);
-INT_MAP_IMPLEMENT(int_map, int);
-
-/** Self-test start function.
- *
- * Run all self-tests.
- *
- * @returns EOK on success.
- * @returns The first error occurred.
- *
- */
-int self_test(void)
-{
-	printf("Running networking self-tests\n");
-	
-	printf("\nChar map test");
-	char_map_t cm;
-	
-	TEST(char_map_update(&cm, "ucho", 0, 3), EINVAL);
-	TEST(char_map_initialize(&cm), EOK);
-	TEST(char_map_exclude(&cm, "bla", 0), CHAR_MAP_NULL);
-	TEST(char_map_find(&cm, "bla", 0), CHAR_MAP_NULL);
-	TEST(char_map_add(&cm, "bla", 0, 1), EOK);
-	TEST(char_map_find(&cm, "bla", 0), 1);
-	TEST(char_map_add(&cm, "bla", 0, 10), EEXISTS);
-	TEST(char_map_update(&cm, "bla", 0, 2), EOK);
-	TEST(char_map_find(&cm, "bla", 0), 2);
-	TEST(char_map_update(&cm, "ucho", 0, 2), EOK);
-	TEST(char_map_exclude(&cm, "bla", 0), 2);
-	TEST(char_map_exclude(&cm, "bla", 0), CHAR_MAP_NULL);
-	TEST(char_map_find(&cm, "ucho", 0), 2);
-	TEST(char_map_update(&cm, "ucho", 0, 3), EOK);
-	TEST(char_map_find(&cm, "ucho", 0), 3);
-	TEST(char_map_add(&cm, "blabla", 0, 5), EOK);
-	TEST(char_map_find(&cm, "blabla", 0), 5);
-	TEST(char_map_add(&cm, "bla", 0, 6), EOK);
-	TEST(char_map_find(&cm, "bla", 0), 6);
-	TEST(char_map_exclude(&cm, "bla", 0), 6);
-	TEST(char_map_find(&cm, "bla", 0), CHAR_MAP_NULL);
-	TEST(char_map_find(&cm, "blabla", 0), 5);
-	TEST(char_map_add(&cm, "auto", 0, 7), EOK);
-	TEST(char_map_find(&cm, "auto", 0), 7);
-	TEST(char_map_add(&cm, "kara", 0, 8), EOK);
-	TEST(char_map_find(&cm, "kara", 0), 8);
-	TEST(char_map_add(&cm, "nic", 0, 9), EOK);
-	TEST(char_map_find(&cm, "nic", 0), 9);
-	TEST(char_map_find(&cm, "blabla", 0), 5);
-	TEST(char_map_add(&cm, "micnicnic", 5, 9), EOK);
-	TEST(char_map_find(&cm, "micni", 0), 9);
-	TEST(char_map_find(&cm, "micnicn", 5), 9);
-	TEST(char_map_add(&cm, "\x10\x0\x2\x2", 4, 15), EOK);
-	TEST(char_map_find(&cm, "\x10\x0\x2\x2", 4), 15);
-	
-	TEST((char_map_destroy(&cm), EOK), EOK);
-	TEST(char_map_update(&cm, "ucho", 0, 3), EINVAL);
-	
-	printf("\nCRC computation test");
-	uint32_t value;
-	
-	TEST(value = ~compute_crc32(~0, "123456789", 8 * 9), 0xcbf43926);
-	TEST(value = ~compute_crc32(~0, "1", 8), 0x83dcefb7);
-	TEST(value = ~compute_crc32(~0, "12", 8 * 2), 0x4f5344cd);
-	TEST(value = ~compute_crc32(~0, "123", 8 * 3), 0x884863d2);
-	TEST(value = ~compute_crc32(~0, "1234", 8 * 4), 0x9be3e0a3);
-	TEST(value = ~compute_crc32(~0, "12345678", 8 * 8), 0x9ae0daaf);
-	TEST(value = ~compute_crc32(~0, "ahoj pane", 8 * 9), 0x5fc3d706);
-	
-	printf("\nDynamic fifo test");
-	dyn_fifo_t fifo;
-	
-	TEST(dyn_fifo_push(&fifo, 1, 0), EINVAL);
-	TEST(dyn_fifo_initialize(&fifo, 1), EOK);
-	TEST(dyn_fifo_push(&fifo, 1, 0), EOK);
-	TEST(dyn_fifo_pop(&fifo), 1);
-	TEST(dyn_fifo_pop(&fifo), ENOENT);
-	TEST(dyn_fifo_push(&fifo, 2, 1), EOK);
-	TEST(dyn_fifo_push(&fifo, 3, 1), ENOMEM);
-	TEST(dyn_fifo_push(&fifo, 3, 0), EOK);
-	TEST(dyn_fifo_pop(&fifo), 2);
-	TEST(dyn_fifo_pop(&fifo), 3);
-	TEST(dyn_fifo_push(&fifo, 4, 2), EOK);
-	TEST(dyn_fifo_push(&fifo, 5, 2), EOK);
-	TEST(dyn_fifo_push(&fifo, 6, 2), ENOMEM);
-	TEST(dyn_fifo_push(&fifo, 6, 5), EOK);
-	TEST(dyn_fifo_push(&fifo, 7, 5), EOK);
-	TEST(dyn_fifo_pop(&fifo), 4);
-	TEST(dyn_fifo_pop(&fifo), 5);
-	TEST(dyn_fifo_push(&fifo, 8, 5), EOK);
-	TEST(dyn_fifo_push(&fifo, 9, 5), EOK);
-	TEST(dyn_fifo_push(&fifo, 10, 6), EOK);
-	TEST(dyn_fifo_push(&fifo, 11, 6), EOK);
-	TEST(dyn_fifo_pop(&fifo), 6);
-	TEST(dyn_fifo_pop(&fifo), 7);
-	TEST(dyn_fifo_push(&fifo, 12, 6), EOK);
-	TEST(dyn_fifo_push(&fifo, 13, 6), EOK);
-	TEST(dyn_fifo_push(&fifo, 14, 6), ENOMEM);
-	TEST(dyn_fifo_push(&fifo, 14, 8), EOK);
-	TEST(dyn_fifo_pop(&fifo), 8);
-	TEST(dyn_fifo_pop(&fifo), 9);
-	TEST(dyn_fifo_pop(&fifo), 10);
-	TEST(dyn_fifo_pop(&fifo), 11);
-	TEST(dyn_fifo_pop(&fifo), 12);
-	TEST(dyn_fifo_pop(&fifo), 13);
-	TEST(dyn_fifo_pop(&fifo), 14);
-	TEST(dyn_fifo_destroy(&fifo), EOK);
-	TEST(dyn_fifo_push(&fifo, 1, 0), EINVAL);
-	
-	printf("\nGeneric char map test");
-	
-	int *x;
-	int *y;
-	int *z;
-	int *u;
-	int *v;
-	int *w;
-	
-	XMALLOC(x, int);
-	XMALLOC(y, int);
-	XMALLOC(z, int);
-	XMALLOC(u, int);
-	XMALLOC(v, int);
-	XMALLOC(w, int);
-	
-	int_char_map_t icm;
-	icm.magic = 0;
-	
-	TEST(int_char_map_add(&icm, "ucho", 0, z), EINVAL);
-	TEST(int_char_map_initialize(&icm), EOK);
-	TEST((int_char_map_exclude(&icm, "bla", 0), EOK), EOK);
-	TEST(int_char_map_find(&icm, "bla", 0), NULL);
-	TEST(int_char_map_add(&icm, "bla", 0, x), EOK);
-	TEST(int_char_map_find(&icm, "bla", 0), x);
-	TEST(int_char_map_add(&icm, "bla", 0, y), EEXISTS);
-	TEST((int_char_map_exclude(&icm, "bla", 0), EOK), EOK);
-	TEST((int_char_map_exclude(&icm, "bla", 0), EOK), EOK);
-	TEST(int_char_map_add(&icm, "blabla", 0, v), EOK);
-	TEST(int_char_map_find(&icm, "blabla", 0), v);
-	TEST(int_char_map_add(&icm, "bla", 0, w), EOK);
-	TEST(int_char_map_find(&icm, "bla", 0), w);
-	TEST((int_char_map_exclude(&icm, "bla", 0), EOK), EOK);
-	TEST(int_char_map_find(&icm, "bla", 0), NULL);
-	TEST(int_char_map_find(&icm, "blabla", 0), v);
-	TEST(int_char_map_add(&icm, "auto", 0, u), EOK);
-	TEST(int_char_map_find(&icm, "auto", 0), u);
-	TEST((int_char_map_destroy(&icm), EOK), EOK);
-	TEST(int_char_map_add(&icm, "ucho", 0, z), EINVAL);
-	
-	printf("\nGeneric field test");
-	
-	XMALLOC(x, int);
-	XMALLOC(y, int);
-	XMALLOC(z, int);
-	XMALLOC(u, int);
-	XMALLOC(v, int);
-	XMALLOC(w, int);
-	
-	int_field_t gf;
-	gf.magic = 0;
-	
-	TEST(int_field_add(&gf, x), EINVAL);
-	TEST(int_field_count(&gf), -1);
-	TEST(int_field_initialize(&gf), EOK);
-	TEST(int_field_count(&gf), 0);
-	TEST(int_field_get_index(&gf, 1), NULL);
-	TEST(int_field_add(&gf, x), 0);
-	TEST(int_field_get_index(&gf, 0), x);
-	TEST((int_field_exclude_index(&gf, 0), EOK), EOK);
-	TEST(int_field_get_index(&gf, 0), NULL);
-	TEST(int_field_add(&gf, y), 1);
-	TEST(int_field_get_index(&gf, 1), y);
-	TEST(int_field_add(&gf, z), 2);
-	TEST(int_field_get_index(&gf, 2), z);
-	TEST(int_field_get_index(&gf, 1), y);
-	TEST(int_field_count(&gf), 3);
-	TEST(int_field_add(&gf, u), 3);
-	TEST(int_field_get_index(&gf, 3), u);
-	TEST(int_field_add(&gf, v), 4);
-	TEST(int_field_get_index(&gf, 4), v);
-	TEST(int_field_add(&gf, w), 5);
-	TEST(int_field_get_index(&gf, 5), w);
-	TEST(int_field_count(&gf), 6);
-	TEST((int_field_exclude_index(&gf, 1), EOK), EOK);
-	TEST(int_field_get_index(&gf, 1), NULL);
-	TEST(int_field_get_index(&gf, 3), u);
-	TEST((int_field_exclude_index(&gf, 7), EOK), EOK);
-	TEST(int_field_get_index(&gf, 3), u);
-	TEST(int_field_get_index(&gf, 5), w);
-	TEST((int_field_exclude_index(&gf, 4), EOK), EOK);
-	TEST(int_field_get_index(&gf, 4), NULL);
-	TEST((int_field_destroy(&gf), EOK), EOK);
-	TEST(int_field_count(&gf), -1);
-	
-	printf("\nInt map test");
-	
-	XMALLOC(x, int);
-	XMALLOC(y, int);
-	XMALLOC(z, int);
-	XMALLOC(u, int);
-	XMALLOC(v, int);
-	XMALLOC(w, int);
-	
-	int_map_t im;
-	im.magic = 0;
-	
-	TEST(int_map_add(&im, 1, x), EINVAL);
-	TEST(int_map_count(&im), -1);
-	TEST(int_map_initialize(&im), EOK);
-	TEST(int_map_count(&im), 0);
-	TEST(int_map_find(&im, 1), NULL);
-	TEST(int_map_add(&im, 1, x), 0);
-	TEST(int_map_find(&im, 1), x);
-	TEST((int_map_exclude(&im, 1), EOK), EOK);
-	TEST(int_map_find(&im, 1), NULL);
-	TEST(int_map_add(&im, 1, y), 1);
-	TEST(int_map_find(&im, 1), y);
-	TEST(int_map_add(&im, 4, z), 2);
-	TEST(int_map_get_index(&im, 2), z);
-	TEST(int_map_find(&im, 4), z);
-	TEST(int_map_find(&im, 1), y);
-	TEST(int_map_count(&im), 3);
-	TEST(int_map_add(&im, 2, u), 3);
-	TEST(int_map_find(&im, 2), u);
-	TEST(int_map_add(&im, 3, v), 4);
-	TEST(int_map_find(&im, 3), v);
-	TEST(int_map_get_index(&im, 4), v);
-	TEST(int_map_add(&im, 6, w), 5);
-	TEST(int_map_find(&im, 6), w);
-	TEST(int_map_count(&im), 6);
-	TEST((int_map_exclude(&im, 1), EOK), EOK);
-	TEST(int_map_find(&im, 1), NULL);
-	TEST(int_map_find(&im, 2), u);
-	TEST((int_map_exclude(&im, 7), EOK), EOK);
-	TEST(int_map_find(&im, 2), u);
-	TEST(int_map_find(&im, 6), w);
-	TEST((int_map_exclude_index(&im, 4), EOK), EOK);
-	TEST(int_map_get_index(&im, 4), NULL);
-	TEST(int_map_find(&im, 3), NULL);
-	TEST((int_map_destroy(&im), EOK), EOK);
-	TEST(int_map_count(&im), -1);
-	
-	printf("\nMeasured strings test");
-	
-	measured_string_ref string =
-	    measured_string_create_bulk("I am a measured string!", 0);
-	printf("\n%x, %s at %x of %d\n", string, string->value, string->value,
-	    string->length);
-	
-	return EOK;
-}
-
-/** @}
- */
Index: uspace/app/netstart/self_test.h
===================================================================
--- uspace/app/netstart/self_test.h	(revision 37f7cfe6ab80448fed991af05947b5c57080be0f)
+++ 	(revision )
@@ -1,41 +1,0 @@
-/*
- * Copyright (c) 2009 Lukas Mejdrech
- * 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 net
- * @{
- */
-
-#ifndef __SELF_TEST_H__
-#define __SELF_TEST_H__
-
-extern int self_test(void);
-
-#endif
-
-/** @}
- */
Index: uspace/app/virtusbkbd/Makefile
===================================================================
--- uspace/app/virtusbkbd/Makefile	(revision 37f7cfe6ab80448fed991af05947b5c57080be0f)
+++ uspace/app/virtusbkbd/Makefile	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
@@ -33,5 +33,5 @@
 
 LIBS = $(LIBUSB_PREFIX)/libusb.a $(LIBUSBVIRT_PREFIX)/libusbvirt.a
-EXTRA_CFLAGS = -I$(LIBUSB_PREFIX)/include -I$(LIB_PREFIX) -I$(LIBDRV_PREFIX)/include
+EXTRA_CFLAGS = -I$(LIBUSB_PREFIX)/include -I$(LIBUSBVIRT_PREFIX)/include -I$(LIBDRV_PREFIX)/include
 
 SOURCES = \
Index: uspace/app/virtusbkbd/stdreq.c
===================================================================
--- uspace/app/virtusbkbd/stdreq.c	(revision 37f7cfe6ab80448fed991af05947b5c57080be0f)
+++ uspace/app/virtusbkbd/stdreq.c	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
@@ -39,23 +39,5 @@
 #include "kbdconfig.h"
 
-static int on_get_descriptor(struct usbvirt_device *dev,
-    usb_device_request_setup_packet_t *request, uint8_t *data);
-
-usbvirt_standard_device_request_ops_t standard_request_ops = {
-	.on_get_status = NULL,
-	.on_clear_feature = NULL,
-	.on_set_feature = NULL,
-	.on_set_address = NULL,
-	.on_get_descriptor = on_get_descriptor,
-	.on_set_descriptor = NULL,
-	.on_get_configuration = NULL,
-	.on_set_configuration = NULL,
-	.on_get_interface = NULL,
-	.on_set_interface = NULL,
-	.on_synch_frame = NULL
-};
-
-
-static int on_get_descriptor(struct usbvirt_device *dev,
+int stdreq_on_get_descriptor(struct usbvirt_device *dev,
     usb_device_request_setup_packet_t *request, uint8_t *data)
 {
Index: uspace/app/virtusbkbd/stdreq.h
===================================================================
--- uspace/app/virtusbkbd/stdreq.h	(revision 37f7cfe6ab80448fed991af05947b5c57080be0f)
+++ uspace/app/virtusbkbd/stdreq.h	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
@@ -38,5 +38,6 @@
 #include <usbvirt/device.h>
 
-extern usbvirt_standard_device_request_ops_t standard_request_ops;
+int stdreq_on_get_descriptor(usbvirt_device_t *,
+    usb_device_request_setup_packet_t *, uint8_t *);
 
 #endif
Index: uspace/app/virtusbkbd/virtusbkbd.c
===================================================================
--- uspace/app/virtusbkbd/virtusbkbd.c	(revision 37f7cfe6ab80448fed991af05947b5c57080be0f)
+++ uspace/app/virtusbkbd/virtusbkbd.c	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
@@ -143,5 +143,6 @@
  */
 static usbvirt_device_ops_t keyboard_ops = {
-	.standard_request_ops = &standard_request_ops,
+	.on_standard_request[USB_DEVREQ_GET_DESCRIPTOR]
+	    = stdreq_on_get_descriptor,
 	.on_class_device_request = on_class_request,
 	.on_data = on_incoming_data,
Index: uspace/drv/vhc/Makefile
===================================================================
--- uspace/drv/vhc/Makefile	(revision 37f7cfe6ab80448fed991af05947b5c57080be0f)
+++ uspace/drv/vhc/Makefile	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
@@ -33,5 +33,5 @@
 	$(LIBDRV_PREFIX)/libdrv.a
 EXTRA_CFLAGS += \
-	-I$(LIB_PREFIX) \
+	-I$(LIBUSBVIRT_PREFIX)/include \
 	-I$(LIBUSB_PREFIX)/include \
 	-I$(LIBDRV_PREFIX)/include
Index: uspace/drv/vhc/hubops.c
===================================================================
--- uspace/drv/vhc/hubops.c	(revision 37f7cfe6ab80448fed991af05947b5c57080be0f)
+++ uspace/drv/vhc/hubops.c	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
@@ -70,22 +70,8 @@
 static void set_port_state_nl(hub_port_t *, hub_port_state_t);
 
-/** Standard USB requests. */
-static usbvirt_standard_device_request_ops_t standard_request_ops = {
-	.on_get_status = NULL,
-	.on_clear_feature = NULL,
-	.on_set_feature = NULL,
-	.on_set_address = NULL,
-	.on_get_descriptor = on_get_descriptor,
-	.on_set_descriptor = NULL,
-	.on_get_configuration = NULL,
-	.on_set_configuration = on_set_configuration,
-	.on_get_interface = NULL,
-	.on_set_interface = NULL,
-	.on_synch_frame = NULL
-};
-
 /** Hub operations. */
 usbvirt_device_ops_t hub_ops = {
-	.standard_request_ops = &standard_request_ops,
+	.on_standard_request[USB_DEVREQ_GET_DESCRIPTOR] = on_get_descriptor,
+	.on_standard_request[USB_DEVREQ_SET_CONFIGURATION] = on_set_configuration,
 	.on_class_device_request = on_class_request,
 	.on_data = NULL,
Index: uspace/lib/packet/include/net_byteorder.h
===================================================================
--- uspace/lib/packet/include/net_byteorder.h	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
+++ uspace/lib/packet/include/net_byteorder.h	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2009 Lukas Mejdrech
+ * 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 net
+ *  @{
+ */
+
+/** @file
+ *  Host - network byte order manipulation functions.
+ */
+
+#ifndef __NET_BYTEORDER_H__
+#define __NET_BYTEORDER_H__
+
+#include <byteorder.h>
+#include <sys/types.h>
+
+
+/** Converts the given short number (16 bit) from the host byte order to the network byte order (big endian).
+ *  @param[in] number The number in the host byte order to be converted.
+ *  @returns The number in the network byte order.
+ */
+#define htons(number)		host2uint16_t_be(number)
+
+/** Converts the given long number (32 bit) from the host byte order to the network byte order (big endian).
+ *  @param[in] number The number in the host byte order to be converted.
+ *  @returns The number in the network byte order.
+ */
+#define htonl(number)		host2uint32_t_be(number)
+
+/** Converts the given short number (16 bit) from the network byte order (big endian) to the host byte order.
+ *  @param[in] number The number in the network byte order to be converted.
+ *  @returns The number in the host byte order.
+ */
+#define ntohs(number) 	uint16_t_be2host(number)
+
+/** Converts the given long number (32 bit) from the network byte order (big endian) to the host byte order.
+ *  @param[in] number The number in the network byte order to be converted.
+ *  @returns The number in the host byte order.
+ */
+#define ntohl(number)		uint32_t_be2host(number)
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/packet/include/net_err.h
===================================================================
--- uspace/lib/packet/include/net_err.h	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
+++ uspace/lib/packet/include/net_err.h	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2009 Lukas Mejdrech
+ * 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 net
+ * @{
+ */
+
+/** @file
+ * Common error processing codes and routines.
+ */
+
+#ifndef __NET_ERR_H__
+#define __NET_ERR_H__
+
+#include <errno.h>
+
+#ifdef CONFIG_DEBUG
+	#include <stdio.h>
+	#include <str_error.h>
+#endif
+
+/** An actual stored error code.
+ *
+ */
+#define ERROR_CODE  error_check_return_value
+
+/** An error processing routines declaration.
+ *
+ * This has to be declared in the block where the error processing
+ * is desired.
+ *
+ */
+#define ERROR_DECLARE  int ERROR_CODE
+
+/** Store the value as an error code and checks if an error occurred.
+ *
+ * @param[in] value The value to be checked. May be a function call.
+ * @return False if the value indicates success (EOK).
+ * @return True otherwise.
+ *
+ */
+#ifdef CONFIG_DEBUG
+
+#define ERROR_OCCURRED(value) \
+	(((ERROR_CODE = (value)) != EOK) \
+	&& ({ \
+		fprintf(stderr, "libsocket error at %s:%d (%s)\n", \
+		__FILE__, __LINE__, str_error(ERROR_CODE)); \
+		1; \
+	}))
+
+#else
+
+#define ERROR_OCCURRED(value)  ((ERROR_CODE = (value)) != EOK)
+
+#endif
+
+/** Error propagation
+ *
+ * Check if an error occurred and immediately exit the actual
+ * function returning the error code.
+ *
+ * @param[in] value The value to be checked. May be a function call.
+ *
+ */
+
+#define ERROR_PROPAGATE(value) \
+	if (ERROR_OCCURRED(value)) \
+		return ERROR_CODE
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/packet/include/socket_errno.h
===================================================================
--- uspace/lib/packet/include/socket_errno.h	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
+++ uspace/lib/packet/include/socket_errno.h	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2009 Lukas Mejdrech
+ * 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 net
+ *  @{
+ */
+
+/** @file
+ *  Socket error codes.
+ *  Based on BSD.
+ */
+
+#ifndef __NET_SOCKET_ERR_H__
+#define __NET_SOCKET_ERR_H__
+
+#include <errno.h>
+
+/** @name Socket error codes definitions
+ */
+/*@{*/
+
+////#define EINTR			(-10004)
+////#define EBADF			(-10009)
+//#define EACCES			(-10013)
+//#define EFAULT			(-10014)
+////#define EINVAL			(-10022)
+////#define EMFILE			(-10024)
+//#define EWOULDBLOCK		(-10035)
+
+/** An API function is called while another blocking function is in progress.
+ */
+#define EINPROGRESS		(-10036)
+
+//#define EALREADY		(-10037)
+
+/** The socket identifier is not valid.
+ */
+#define ENOTSOCK		(-10038)
+
+/** The destination address required.
+ */
+#define EDESTADDRREQ	(-10039)
+
+//#define EMSGSIZE		(-10040)
+//#define EPROTOTYPE		(-10041)
+//#define ENOPROTOOPT		(-10042)
+
+/** Protocol is not supported.
+ */
+#define EPROTONOSUPPORT	(-10043)
+
+/** Socket type is not supported.
+ */
+#define ESOCKTNOSUPPORT	(-10044)
+
+//#define EOPNOTSUPP		(-10045)
+
+/** Protocol family is not supported.
+ */
+#define EPFNOSUPPORT	(-10046)
+
+/** Address family is not supported.
+ */
+#define EAFNOSUPPORT	(-10047)
+
+/** Address is already in use.
+ */
+#define EADDRINUSE		(-10048)
+
+//#define EADDRNOTAVAIL	(-10049)
+/* May be reported at any time if the implementation detects an underlying failure.
+ */
+//#define ENETDOWN		(-10050)
+//#define ENETUNREACH		(-10051)
+//#define ENETRESET		(-10052)
+//#define ECONNABORTED	(-10053)
+//#define ECONNRESET		(-10054)
+//#define ENOBUFS			(-10055)
+//#define EISCONN			(-10056)
+
+/** The socket is not connected or bound.
+ */
+#define ENOTCONN		(-10057)
+
+//#define ESHUTDOWN		(-10058)
+//#define ETOOMANYREFS	(-10059)
+//#define ETIMEDOUT		(-10060)
+//#define ECONNREFUSED	(-10061)
+//#define ELOOP			(-10062)
+////#define ENAMETOOLONG	(-10063)
+//#define EHOSTDOWN		(-10064)
+//#define EHOSTUNREACH	(-10065)
+//#define HOST_NOT_FOUND	(-11001)
+
+/** The requested operation was not performed.
+ *  Try again later.
+ */
+#define TRY_AGAIN		(-11002)
+
+//#define NO_RECOVERY		(-11003)
+
+/** No data.
+ */
+#define NO_DATA			(-11004)
+
+/*@}*/
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/usbvirt/Makefile
===================================================================
--- uspace/lib/usbvirt/Makefile	(revision 37f7cfe6ab80448fed991af05947b5c57080be0f)
+++ uspace/lib/usbvirt/Makefile	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
@@ -31,13 +31,13 @@
 
 LIBS = $(LIBUSB_PREFIX)/libusb.a
-EXTRA_CFLAGS = -I$(LIBUSB_PREFIX)/include
+EXTRA_CFLAGS = -I$(LIBUSB_PREFIX)/include -Iinclude
 
 SOURCES = \
-	callback.c \
-	ctrlpipe.c \
-	debug.c \
-	main.c \
-	stdreq.c \
-	transaction.c
+	src/callback.c \
+	src/ctrlpipe.c \
+	src/debug.c \
+	src/main.c \
+	src/stdreq.c \
+	src/transaction.c
 
 include $(USPACE_PREFIX)/Makefile.common
Index: uspace/lib/usbvirt/callback.c
===================================================================
--- uspace/lib/usbvirt/callback.c	(revision 37f7cfe6ab80448fed991af05947b5c57080be0f)
+++ 	(revision )
@@ -1,236 +1,0 @@
-/*
- * Copyright (c) 2010 Vojtech Horky
- * 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 libusbvirt usb
- * @{
- */
-/** @file
- * @brief Callback connection handling.
- */
-#include <devmap.h>
-#include <fcntl.h>
-#include <vfs/vfs.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <mem.h>
-
-#include "hub.h"
-#include "device.h"
-#include "private.h"
-
-#define NAMESPACE "usb"
-#define USB_MAX_PAYLOAD_SIZE 1020
-
-/** Wrapper for SETUP transaction over telephone. */
-static void handle_setup_transaction(usbvirt_device_t *device,
-    ipc_callid_t iid, ipc_call_t icall)
-{
-	usb_address_t address = IPC_GET_ARG1(icall);
-	usb_endpoint_t endpoint = IPC_GET_ARG2(icall);
-	size_t expected_len = IPC_GET_ARG3(icall);
-	
-	if (address != device->address) {
-		ipc_answer_0(iid, EADDRNOTAVAIL);
-		return;
-	}
-	
-	if ((endpoint < 0) || (endpoint >= USB11_ENDPOINT_MAX)) {
-		ipc_answer_0(iid, EINVAL);
-		return;
-	}
-	
-	if (expected_len == 0) {
-		ipc_answer_0(iid, EINVAL);
-		return;
-	}
-	
-	size_t len = 0;
-	void * buffer = NULL;
-	int rc = async_data_write_accept(&buffer, false,
-	    1, USB_MAX_PAYLOAD_SIZE, 0, &len);
-		
-	if (rc != EOK) {
-		ipc_answer_0(iid, rc);
-		return;
-	}
-	
-	rc = device->transaction_setup(device, endpoint, buffer, len);
-	
-	ipc_answer_0(iid, rc);
-}
-
-/** Wrapper for OUT transaction over telephone. */
-static void handle_out_transaction(usbvirt_device_t *device,
-    ipc_callid_t iid, ipc_call_t icall)
-{
-	usb_address_t address = IPC_GET_ARG1(icall);
-	usb_endpoint_t endpoint = IPC_GET_ARG2(icall);
-	size_t expected_len = IPC_GET_ARG3(icall);
-	
-	if (address != device->address) {
-		ipc_answer_0(iid, EADDRNOTAVAIL);
-		return;
-	}
-	
-	if ((endpoint < 0) || (endpoint >= USB11_ENDPOINT_MAX)) {
-		ipc_answer_0(iid, EINVAL);
-		return;
-	}
-	
-	int rc = EOK;
-	
-	size_t len = 0;
-	void *buffer = NULL;
-	
-	if (expected_len > 0) {
-		rc = async_data_write_accept(&buffer, false,
-		    1, USB_MAX_PAYLOAD_SIZE, 0, &len);
-			
-		if (rc != EOK) {
-			ipc_answer_0(iid, rc);
-			return;
-		}
-	}
-	
-	rc = device->transaction_out(device, endpoint, buffer, len);
-	
-	if (buffer != NULL) {
-		free(buffer);
-	}
-	
-	ipc_answer_0(iid, rc);
-}
-
-
-/** Wrapper for IN transaction over telephone. */
-static void handle_in_transaction(usbvirt_device_t *device,
-    ipc_callid_t iid, ipc_call_t icall)
-{
-	usb_address_t address = IPC_GET_ARG1(icall);
-	usb_endpoint_t endpoint = IPC_GET_ARG2(icall);
-	size_t expected_len = IPC_GET_ARG3(icall);
-	
-	if (address != device->address) {
-		ipc_answer_0(iid, EADDRNOTAVAIL);
-		return;
-	}
-	
-	if ((endpoint < 0) || (endpoint >= USB11_ENDPOINT_MAX)) {
-		ipc_answer_0(iid, EINVAL);
-		return;
-	}
-	
-	int rc = EOK;
-	
-	void *buffer = expected_len > 0 ? malloc(expected_len) : NULL;
-	size_t len;
-	
-	rc = device->transaction_in(device, endpoint, buffer, expected_len, &len);
-	/*
-	 * If the request was processed, we will send data back.
-	 */
-	if ((rc == EOK) && (expected_len > 0)) {
-		size_t receive_len;
-		ipc_callid_t callid;
-		if (!async_data_read_receive(&callid, &receive_len)) {
-			ipc_answer_0(iid, EINVAL);
-			return;
-		}
-		async_data_read_finalize(callid, buffer, receive_len);
-	}
-	
-	ipc_answer_0(iid, rc);
-}
-
-/** Wrapper for getting device name. */
-static void handle_get_name(usbvirt_device_t *device,
-    ipc_callid_t iid, ipc_call_t icall)
-{
-	if (device->name == NULL) {
-		ipc_answer_0(iid, ENOENT);
-	}
-	
-	size_t size = str_size(device->name);
-	
-	ipc_callid_t callid;
-	size_t accepted_size;
-	if (!async_data_read_receive(&callid, &accepted_size)) {
-		ipc_answer_0(iid, EINVAL);
-		return;
-	}
-	
-	if (accepted_size > size) {
-		accepted_size = size;
-	}
-	async_data_read_finalize(callid, device->name, accepted_size);
-	
-	ipc_answer_1(iid, EOK, accepted_size);
-}
-
-/** Callback connection for a given device. */
-void device_callback_connection(usbvirt_device_t *device, ipc_callid_t iid, ipc_call_t *icall)
-{
-	ipc_answer_0(iid, EOK);
-	
-	while (true) {
-		ipc_callid_t callid; 
-		ipc_call_t call; 
-		
-		callid = async_get_call(&call);
-		switch (IPC_GET_METHOD(call)) {
-			case IPC_M_PHONE_HUNGUP:
-				ipc_answer_0(callid, EOK);
-				return;
-			
-			case IPC_M_USBVIRT_GET_NAME:
-				handle_get_name(device, callid, call);
-				break;
-			
-			case IPC_M_USBVIRT_TRANSACTION_SETUP:
-				handle_setup_transaction(device, callid, call);
-				break;
-			
-			case IPC_M_USBVIRT_TRANSACTION_OUT:
-				handle_out_transaction(device, callid, call);
-				break;
-				
-			case IPC_M_USBVIRT_TRANSACTION_IN:
-				handle_in_transaction(device, callid, call);
-				break;
-			
-			default:
-				ipc_answer_0(callid, EINVAL);
-				break;
-		}
-	}
-}
-
-
-/**
- * @}
- */
Index: uspace/lib/usbvirt/ctrlpipe.c
===================================================================
--- uspace/lib/usbvirt/ctrlpipe.c	(revision 37f7cfe6ab80448fed991af05947b5c57080be0f)
+++ 	(revision )
@@ -1,127 +1,0 @@
-/*
- * Copyright (c) 2010 Vojtech Horky
- * 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 libusbvirt usb
- * @{
- */
-/** @file
- * @brief Device control pipe.
- */
-#include <errno.h>
-
-#include "private.h"
-
-#define REQUEST_TYPE_STANDARD 0 
-#define REQUEST_TYPE_CLASS 1
-
-#define GET_MIDBITS_MASK(size, shift) \
-	(((1 << size) - 1) << shift)
-#define GET_MIDBITS(value, size, shift) \
-	((value & GET_MIDBITS_MASK(size, shift)) >> shift)
-
-
-static const char *str_request_type(int type)
-{
-	switch (type) {
-		case REQUEST_TYPE_STANDARD:
-			return "standard";
-		case REQUEST_TYPE_CLASS:
-			return "class";
-		default:
-			return "unknown";
-	}
-}
-
-/** Tell request type.
- * By type is meant either standard, class, vendor or other.
- */
-static int request_get_type(uint8_t request_type)
-{
-	return GET_MIDBITS(request_type, 2, 5);
-}
-
-/** Handle communication over control pipe zero.
- */
-int control_pipe(usbvirt_device_t *device, usbvirt_control_transfer_t *transfer)
-{
-	device->lib_debug(device, 1, USBVIRT_DEBUGTAG_CONTROL_PIPE_ZERO,
-	    "op on control pipe zero (request_size=%u)", transfer->request_size);
-	
-	if (transfer->request_size < sizeof(usb_device_request_setup_packet_t)) {
-		return ENOMEM;
-	}
-	
-	usb_device_request_setup_packet_t *request = (usb_device_request_setup_packet_t *) transfer->request;
-	uint8_t *remaining_data = transfer->data;
-	
-	int type = request_get_type(request->request_type);
-	
-	int rc = EOK;
-	
-	device->lib_debug(device, 2, USBVIRT_DEBUGTAG_CONTROL_PIPE_ZERO,
-	    "request type: %s", str_request_type(type));
-	
-	switch (type) {
-		case REQUEST_TYPE_STANDARD:
-			rc = handle_std_request(device, request, remaining_data);
-			break;
-		case REQUEST_TYPE_CLASS:
-			if (DEVICE_HAS_OP(device, on_class_device_request)) {
-				rc = device->ops->on_class_device_request(device,
-				    request, remaining_data);
-			}
-			break;
-		default:
-			break;
-	}
-	
-	if (device->new_address != -1) {
-		/*
-		 * TODO: handle when this request is invalid (e.g.
-		 * setting address when in configured state).
-		 */
-		if (device->new_address == 0) {
-			device->state = USBVIRT_STATE_DEFAULT;
-		} else {
-			device->state = USBVIRT_STATE_ADDRESS;
-		}
-		device->address = device->new_address;
-		
-		device->new_address = -1;
-		
-		device->lib_debug(device, 2, USBVIRT_DEBUGTAG_CONTROL_PIPE_ZERO,
-		    "device address changed to %d (state %s)",
-		    device->address, str_device_state(device->state));
-	}
-	
-	return rc;
-}
-
-/**
- * @}
- */
Index: uspace/lib/usbvirt/debug.c
===================================================================
--- uspace/lib/usbvirt/debug.c	(revision 37f7cfe6ab80448fed991af05947b5c57080be0f)
+++ 	(revision )
@@ -1,104 +1,0 @@
-/*
- * Copyright (c) 2010 Vojtech Horky
- * 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 libusbvirt usb
- * @{
- */
-/** @file
- * @brief Debugging support.
- */
-#include <stdio.h>
-#include <bool.h>
-
-#include "device.h"
-#include "private.h"
-
-
-static void debug_print(int level, uint8_t tag,
-    int current_level, uint8_t enabled_tags,
-    const char *format, va_list args)
-{
-	if (level > current_level) {
-		return;
-	}
-	
-	if ((tag & enabled_tags) == 0) {
-		return;
-	}
-	
-	bool print_prefix = true;
-	
-	if ((format[0] == '%') && (format[1] == 'M')) {
-		format += 2;
-		print_prefix = false;
-	}
-	
-	if (print_prefix) {
-		printf("[vusb]: ");
-		while (--level > 0) {
-			printf(" ");
-		}
-	}
-	
-	vprintf(format, args);
-	
-	if (print_prefix) {
-		printf("\n");
-	}
-}
-
-
-void user_debug(usbvirt_device_t *device, int level, uint8_t tag,
-    const char *format, ...)
-{
-	va_list args;
-	va_start(args, format);
-	
-	debug_print(level, tag,
-	    device->debug_level, device->debug_enabled_tags,
-	    format, args);
-	
-	va_end(args);
-}
-
-void lib_debug(usbvirt_device_t *device, int level, uint8_t tag,
-    const char *format, ...)
-{
-	va_list args;
-	va_start(args, format);
-	
-	debug_print(level, tag,
-	    device->lib_debug_level, device->lib_debug_enabled_tags,
-	    format, args);
-	
-	va_end(args);
-}
-
-/**
- * @}
- */
Index: uspace/lib/usbvirt/device.h
===================================================================
--- uspace/lib/usbvirt/device.h	(revision 37f7cfe6ab80448fed991af05947b5c57080be0f)
+++ 	(revision )
@@ -1,224 +1,0 @@
-/*
- * Copyright (c) 2010 Vojtech Horky
- * 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 libusbvirt usb
- * @{
- */
-/** @file
- * @brief Virtual USB device.
- */
-#ifndef LIBUSBVIRT_DEVICE_H_
-#define LIBUSBVIRT_DEVICE_H_
-
-#include <usb/usb.h>
-#include <usb/descriptor.h>
-#include <usb/devreq.h>
-
-typedef struct usbvirt_device usbvirt_device_t;
-struct usbvirt_control_transfer;
-
-typedef int (*usbvirt_on_device_request_t)(usbvirt_device_t *dev,
-	usb_device_request_setup_packet_t *request,
-	uint8_t *data);
-
-/** Callbacks for standard device requests.
- * When these functions are NULL or return EFORWARD, this
- * framework will try to satisfy the request by itself.
- */
-typedef struct {
-	usbvirt_on_device_request_t on_get_status;
-	usbvirt_on_device_request_t on_clear_feature;
-	usbvirt_on_device_request_t on_set_feature;
-	usbvirt_on_device_request_t on_set_address;
-	usbvirt_on_device_request_t on_get_descriptor;
-	usbvirt_on_device_request_t on_set_descriptor;
-	usbvirt_on_device_request_t on_get_configuration;
-	usbvirt_on_device_request_t on_set_configuration;
-	usbvirt_on_device_request_t on_get_interface;
-	usbvirt_on_device_request_t on_set_interface;
-	usbvirt_on_device_request_t on_synch_frame;
-} usbvirt_standard_device_request_ops_t;
-
-/** Device operations. */
-typedef struct {
-	/** Callbacks for standard deivce requests. */
-	usbvirt_standard_device_request_ops_t *standard_request_ops;
-	/** Callback for class-specific USB request. */
-	usbvirt_on_device_request_t on_class_device_request;
-	
-	int (*on_control_transfer)(usbvirt_device_t *dev,
-	    usb_endpoint_t endpoint, struct usbvirt_control_transfer *transfer);
-	
-	/** Callback for all other incoming data. */
-	int (*on_data)(usbvirt_device_t *dev,
-	    usb_endpoint_t endpoint, void *buffer, size_t size);
-	
-	/** Callback for host request for data. */
-	int (*on_data_request)(usbvirt_device_t *dev,
-	    usb_endpoint_t endpoint, void *buffer, size_t size, size_t *actual_size);
-	
-	/** Decides direction of control transfer. */
-	usb_direction_t (*decide_control_transfer_direction)(
-	    usb_endpoint_t endpoint, void *buffer, size_t size);
-} usbvirt_device_ops_t;
-
-/** Extra configuration data for GET_CONFIGURATION request. */
-typedef struct {
-	/** Actual data. */
-	uint8_t *data;
-	/** Data length. */
-	size_t length;
-} usbvirt_device_configuration_extras_t;
-
-/** Single device configuration. */
-typedef struct {
-	/** Standard configuration descriptor. */
-	usb_standard_configuration_descriptor_t *descriptor;
-	/** Array of extra data. */
-	usbvirt_device_configuration_extras_t *extra;
-	/** Length of @c extra array. */
-	size_t extra_count;
-} usbvirt_device_configuration_t;
-
-/** Standard USB descriptors. */
-typedef struct {
-	/** Standard device descriptor.
-	 * There is always only one such descriptor for the device.
-	 */
-	usb_standard_device_descriptor_t *device;
-	
-	/** Configurations. */
-	usbvirt_device_configuration_t *configuration;
-	/** Number of configurations. */
-	size_t configuration_count;
-	/** Index of currently selected configuration. */
-	uint8_t current_configuration;
-} usbvirt_descriptors_t;
-
-/** Possible states of virtual USB device.
- * Notice that these are not 1:1 mappings to those in USB specification.
- */
-typedef enum {
-	USBVIRT_STATE_DEFAULT,
-	USBVIRT_STATE_ADDRESS,
-	USBVIRT_STATE_CONFIGURED
-} usbvirt_device_state_t;
-
-/** Information about on-going control transfer.
- */
-typedef struct usbvirt_control_transfer {
-	/** Transfer direction (read/write control transfer). */
-	usb_direction_t direction;
-	/** Request data. */
-	void *request;
-	/** Size of request data. */
-	size_t request_size;
-	/** Payload. */
-	void *data;
-	/** Size of payload. */
-	size_t data_size;
-} usbvirt_control_transfer_t;
-
-typedef enum {
-	USBVIRT_DEBUGTAG_BASE = 1,
-	USBVIRT_DEBUGTAG_TRANSACTION = 2,
-	USBVIRT_DEBUGTAG_CONTROL_PIPE_ZERO = 4,
-	USBVIRT_DEBUGTAG_ALL = 255
-} usbvirt_debug_tags_t;
-
-/** Virtual USB device. */
-struct usbvirt_device {
-	/** Callback device operations. */
-	usbvirt_device_ops_t *ops;
-	
-	/** Reply onto control transfer.
-	 */
-	int (*control_transfer_reply)(usbvirt_device_t *dev,
-	    usb_endpoint_t endpoint, void *buffer, size_t size);
-	
-	/** Device name.
-	 * Used in debug prints and sent to virtual host controller.
-	 */
-	const char *name;
-	
-	/** Standard descriptors. */
-	usbvirt_descriptors_t *descriptors;
-	
-	/** Current device state. */
-	usbvirt_device_state_t state;
-	
-	/** Device address. */
-	usb_address_t address;
-	/** New device address.
-	 * This field is used during SET_ADDRESS request.
-	 * On all other occasions, it holds invalid address (e.g. -1).
-	 */
-	usb_address_t new_address;
-	
-	/** Process OUT transaction. */
-	int (*transaction_out)(usbvirt_device_t *dev,
-	    usb_endpoint_t endpoint, void *buffer, size_t size);
-	/** Process SETUP transaction. */
-	int (*transaction_setup)(usbvirt_device_t *dev,
-	    usb_endpoint_t endpoint, void *buffer, size_t size);
-	/** Process IN transaction. */
-	int (*transaction_in)(usbvirt_device_t *dev,
-	    usb_endpoint_t endpoint, void *buffer, size_t size, size_t *data_size);
-	
-	/** State information on control-transfer endpoints. */
-	usbvirt_control_transfer_t current_control_transfers[USB11_ENDPOINT_MAX];
-	
-	/* User debugging. */
-	
-	/** Debug print. */
-	void (*debug)(usbvirt_device_t *dev, int level, uint8_t tag,
-	    const char *format, ...);
-	
-	/** Current debug level. */
-	int debug_level;
-	
-	/** Bitmap of currently enabled tags. */
-	uint8_t debug_enabled_tags;
-	
-	/* Library debugging. */
-	
-	/** Debug print. */
-	void (*lib_debug)(usbvirt_device_t *dev, int level, uint8_t tag,
-	    const char *format, ...);
-	
-	/** Current debug level. */
-	int lib_debug_level;
-	
-	/** Bitmap of currently enabled tags. */
-	uint8_t lib_debug_enabled_tags;
-};
-
-#endif
-/**
- * @}
- */
Index: uspace/lib/usbvirt/hub.h
===================================================================
--- uspace/lib/usbvirt/hub.h	(revision 37f7cfe6ab80448fed991af05947b5c57080be0f)
+++ 	(revision )
@@ -1,68 +1,0 @@
-/*
- * Copyright (c) 2010 Vojtech Horky
- * 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 libusbvirt usb
- * @{
- */
-/** @file
- * @brief Virtual USB device.
- */
-#ifndef LIBUSBVIRT_HUB_H_
-#define LIBUSBVIRT_HUB_H_
-
-#include "device.h"
-
-/** USB transaction type.
- * This types does not correspond directly to types in USB specification,
- * as actually DATA transactions are marked with these types to identify
- * their direction (and tag).
- */
-typedef enum {
-	USBVIRT_TRANSACTION_SETUP,
-	USBVIRT_TRANSACTION_IN,
-	USBVIRT_TRANSACTION_OUT
-} usbvirt_transaction_type_t;
-
-const char *usbvirt_str_transaction_type(usbvirt_transaction_type_t type);
-
-/** Telephony methods of virtual devices. */
-typedef enum {
-	IPC_M_USBVIRT_GET_NAME = IPC_FIRST_USER_METHOD,
-	IPC_M_USBVIRT_TRANSACTION_SETUP,
-	IPC_M_USBVIRT_TRANSACTION_OUT,
-	IPC_M_USBVIRT_TRANSACTION_IN,
-} usbvirt_device_method_t;
-
-int usbvirt_connect(usbvirt_device_t *);
-int usbvirt_connect_local(usbvirt_device_t *);
-int usbvirt_disconnect(usbvirt_device_t *dev);
-
-#endif
-/**
- * @}
- */
Index: uspace/lib/usbvirt/include/usbvirt/device.h
===================================================================
--- uspace/lib/usbvirt/include/usbvirt/device.h	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
+++ uspace/lib/usbvirt/include/usbvirt/device.h	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
@@ -0,0 +1,208 @@
+/*
+ * Copyright (c) 2010 Vojtech Horky
+ * 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 libusbvirt usb
+ * @{
+ */
+/** @file
+ * @brief Virtual USB device.
+ */
+#ifndef LIBUSBVIRT_DEVICE_H_
+#define LIBUSBVIRT_DEVICE_H_
+
+#include <usb/usb.h>
+#include <usb/descriptor.h>
+#include <usb/devreq.h>
+
+typedef struct usbvirt_device usbvirt_device_t;
+struct usbvirt_control_transfer;
+
+typedef int (*usbvirt_on_device_request_t)(usbvirt_device_t *dev,
+	usb_device_request_setup_packet_t *request,
+	uint8_t *data);
+
+/** Device operations. */
+typedef struct {
+	/** Callbacks for standard device requests.
+	 * The callbacks are indexed by usb_stddevreq_t enum.
+	 */
+	usbvirt_on_device_request_t on_standard_request[USB_DEVREQ_LAST_STD];
+	/** Callback for class-specific USB request. */
+	usbvirt_on_device_request_t on_class_device_request;
+	
+	int (*on_control_transfer)(usbvirt_device_t *dev,
+	    usb_endpoint_t endpoint, struct usbvirt_control_transfer *transfer);
+	
+	/** Callback for all other incoming data. */
+	int (*on_data)(usbvirt_device_t *dev,
+	    usb_endpoint_t endpoint, void *buffer, size_t size);
+	
+	/** Callback for host request for data. */
+	int (*on_data_request)(usbvirt_device_t *dev,
+	    usb_endpoint_t endpoint, void *buffer, size_t size, size_t *actual_size);
+	
+	/** Decides direction of control transfer. */
+	usb_direction_t (*decide_control_transfer_direction)(
+	    usb_endpoint_t endpoint, void *buffer, size_t size);
+} usbvirt_device_ops_t;
+
+/** Extra configuration data for GET_CONFIGURATION request. */
+typedef struct {
+	/** Actual data. */
+	uint8_t *data;
+	/** Data length. */
+	size_t length;
+} usbvirt_device_configuration_extras_t;
+
+/** Single device configuration. */
+typedef struct {
+	/** Standard configuration descriptor. */
+	usb_standard_configuration_descriptor_t *descriptor;
+	/** Array of extra data. */
+	usbvirt_device_configuration_extras_t *extra;
+	/** Length of @c extra array. */
+	size_t extra_count;
+} usbvirt_device_configuration_t;
+
+/** Standard USB descriptors. */
+typedef struct {
+	/** Standard device descriptor.
+	 * There is always only one such descriptor for the device.
+	 */
+	usb_standard_device_descriptor_t *device;
+	
+	/** Configurations. */
+	usbvirt_device_configuration_t *configuration;
+	/** Number of configurations. */
+	size_t configuration_count;
+	/** Index of currently selected configuration. */
+	uint8_t current_configuration;
+} usbvirt_descriptors_t;
+
+/** Possible states of virtual USB device.
+ * Notice that these are not 1:1 mappings to those in USB specification.
+ */
+typedef enum {
+	USBVIRT_STATE_DEFAULT,
+	USBVIRT_STATE_ADDRESS,
+	USBVIRT_STATE_CONFIGURED
+} usbvirt_device_state_t;
+
+/** Information about on-going control transfer.
+ */
+typedef struct usbvirt_control_transfer {
+	/** Transfer direction (read/write control transfer). */
+	usb_direction_t direction;
+	/** Request data. */
+	void *request;
+	/** Size of request data. */
+	size_t request_size;
+	/** Payload. */
+	void *data;
+	/** Size of payload. */
+	size_t data_size;
+} usbvirt_control_transfer_t;
+
+typedef enum {
+	USBVIRT_DEBUGTAG_BASE = 1,
+	USBVIRT_DEBUGTAG_TRANSACTION = 2,
+	USBVIRT_DEBUGTAG_CONTROL_PIPE_ZERO = 4,
+	USBVIRT_DEBUGTAG_ALL = 255
+} usbvirt_debug_tags_t;
+
+/** Virtual USB device. */
+struct usbvirt_device {
+	/** Callback device operations. */
+	usbvirt_device_ops_t *ops;
+	
+	/** Reply onto control transfer.
+	 */
+	int (*control_transfer_reply)(usbvirt_device_t *dev,
+	    usb_endpoint_t endpoint, void *buffer, size_t size);
+	
+	/** Device name.
+	 * Used in debug prints and sent to virtual host controller.
+	 */
+	const char *name;
+	
+	/** Standard descriptors. */
+	usbvirt_descriptors_t *descriptors;
+	
+	/** Current device state. */
+	usbvirt_device_state_t state;
+	
+	/** Device address. */
+	usb_address_t address;
+	/** New device address.
+	 * This field is used during SET_ADDRESS request.
+	 * On all other occasions, it holds invalid address (e.g. -1).
+	 */
+	usb_address_t new_address;
+	
+	/** Process OUT transaction. */
+	int (*transaction_out)(usbvirt_device_t *dev,
+	    usb_endpoint_t endpoint, void *buffer, size_t size);
+	/** Process SETUP transaction. */
+	int (*transaction_setup)(usbvirt_device_t *dev,
+	    usb_endpoint_t endpoint, void *buffer, size_t size);
+	/** Process IN transaction. */
+	int (*transaction_in)(usbvirt_device_t *dev,
+	    usb_endpoint_t endpoint, void *buffer, size_t size, size_t *data_size);
+	
+	/** State information on control-transfer endpoints. */
+	usbvirt_control_transfer_t current_control_transfers[USB11_ENDPOINT_MAX];
+	
+	/* User debugging. */
+	
+	/** Debug print. */
+	void (*debug)(usbvirt_device_t *dev, int level, uint8_t tag,
+	    const char *format, ...);
+	
+	/** Current debug level. */
+	int debug_level;
+	
+	/** Bitmap of currently enabled tags. */
+	uint8_t debug_enabled_tags;
+	
+	/* Library debugging. */
+	
+	/** Debug print. */
+	void (*lib_debug)(usbvirt_device_t *dev, int level, uint8_t tag,
+	    const char *format, ...);
+	
+	/** Current debug level. */
+	int lib_debug_level;
+	
+	/** Bitmap of currently enabled tags. */
+	uint8_t lib_debug_enabled_tags;
+};
+
+#endif
+/**
+ * @}
+ */
Index: uspace/lib/usbvirt/include/usbvirt/hub.h
===================================================================
--- uspace/lib/usbvirt/include/usbvirt/hub.h	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
+++ uspace/lib/usbvirt/include/usbvirt/hub.h	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2010 Vojtech Horky
+ * 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 libusbvirt usb
+ * @{
+ */
+/** @file
+ * @brief Virtual USB device.
+ */
+#ifndef LIBUSBVIRT_HUB_H_
+#define LIBUSBVIRT_HUB_H_
+
+#include "device.h"
+
+/** USB transaction type.
+ * This types does not correspond directly to types in USB specification,
+ * as actually DATA transactions are marked with these types to identify
+ * their direction (and tag).
+ */
+typedef enum {
+	USBVIRT_TRANSACTION_SETUP,
+	USBVIRT_TRANSACTION_IN,
+	USBVIRT_TRANSACTION_OUT
+} usbvirt_transaction_type_t;
+
+const char *usbvirt_str_transaction_type(usbvirt_transaction_type_t type);
+
+/** Telephony methods of virtual devices. */
+typedef enum {
+	IPC_M_USBVIRT_GET_NAME = IPC_FIRST_USER_METHOD,
+	IPC_M_USBVIRT_TRANSACTION_SETUP,
+	IPC_M_USBVIRT_TRANSACTION_OUT,
+	IPC_M_USBVIRT_TRANSACTION_IN,
+} usbvirt_device_method_t;
+
+int usbvirt_connect(usbvirt_device_t *);
+int usbvirt_connect_local(usbvirt_device_t *);
+int usbvirt_disconnect(usbvirt_device_t *dev);
+
+#endif
+/**
+ * @}
+ */
Index: uspace/lib/usbvirt/main.c
===================================================================
--- uspace/lib/usbvirt/main.c	(revision 37f7cfe6ab80448fed991af05947b5c57080be0f)
+++ 	(revision )
@@ -1,289 +1,0 @@
-/*
- * Copyright (c) 2010 Vojtech Horky
- * 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 libusbvirt usb
- * @{
- */
-/** @file
- * @brief Device registration with virtual USB framework.
- */
-#include <devman.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <mem.h>
-#include <assert.h>
-
-#include "hub.h"
-#include "device.h"
-#include "private.h"
-
-#define NAMESPACE "usb"
-
-/** Virtual device wrapper. */
-typedef struct {
-	/** Actual device. */
-	usbvirt_device_t *device;
-	/** Phone to host controller. */
-	int vhcd_phone;
-	/** Device id. */
-	ipcarg_t id;
-	/** Linked-list member. */
-	link_t link;
-} virtual_device_t;
-
-/*** List of known device. */
-static LIST_INITIALIZE(device_list);
-
-/** Find virtual device wrapper based on the contents. */
-static virtual_device_t *find_device(usbvirt_device_t *device)
-{
-	if (list_empty(&device_list)) {
-		return NULL;
-	}
-	
-	link_t *pos;
-	for (pos = device_list.next; pos != &device_list; pos = pos->next) {
-		virtual_device_t *dev
-		    = list_get_instance(pos, virtual_device_t, link);
-		if (dev->device == device) {
-			return dev;
-		}
-	}
-	
-	return NULL;
-}
-
-/** Find virtual device wrapper by its id. */
-static virtual_device_t *find_device_by_id(ipcarg_t id)
-{
-	if (list_empty(&device_list)) {
-		return NULL;
-	}
-	
-	link_t *pos;
-	for (pos = device_list.next; pos != &device_list; pos = pos->next) {
-		virtual_device_t *dev
-		    = list_get_instance(pos, virtual_device_t, link);
-		if (dev->id == id) {
-			return dev;
-		}
-	}
-	
-	return NULL;
-}
-
-/** Reply to a control transfer. */
-static int control_transfer_reply(usbvirt_device_t *device,
-	    usb_endpoint_t endpoint, void *buffer, size_t size)
-{
-	usbvirt_control_transfer_t *transfer = &device->current_control_transfers[endpoint];
-	if (transfer->data != NULL) {
-		free(transfer->data);
-	}
-	transfer->data = malloc(size);
-	memcpy(transfer->data, buffer, size);
-	transfer->data_size = size;
-	
-	return EOK;
-}
-
-/** Initialize virtual device. */
-static void device_init(usbvirt_device_t *dev)
-{
-	dev->transaction_out = transaction_out;
-	dev->transaction_setup = transaction_setup;
-	dev->transaction_in = transaction_in;
-	
-	dev->control_transfer_reply = control_transfer_reply;
-	
-	dev->debug = user_debug;
-	dev->lib_debug = lib_debug;
-	
-	dev->state = USBVIRT_STATE_DEFAULT;
-	dev->address = 0;
-	dev->new_address = -1;
-	
-	size_t i;
-	for (i = 0; i < USB11_ENDPOINT_MAX; i++) {
-		usbvirt_control_transfer_t *transfer = &dev->current_control_transfers[i];
-		transfer->direction = 0;
-		transfer->request = NULL;
-		transfer->request_size = 0;
-		transfer->data = NULL;
-		transfer->data_size = 0;
-	}
-}
-
-/** Add a virtual device.
- * The returned device (if not NULL) shall be destroy via destroy_device().
- */
-static virtual_device_t *add_device(usbvirt_device_t *dev)
-{
-	assert(find_device(dev) == NULL);
-	virtual_device_t *new_device
-	    = (virtual_device_t *) malloc(sizeof(virtual_device_t));
-	
-	new_device->device = dev;
-	link_initialize(&new_device->link);
-	
-	list_append(&new_device->link, &device_list);
-	
-	return new_device;
-}
-
-/** Destroy virtual device. */
-static void destroy_device(virtual_device_t *dev)
-{
-	if (dev->vhcd_phone > 0) {
-		ipc_hangup(dev->vhcd_phone);
-	}
-	
-	list_remove(&dev->link);
-	
-	free(dev);
-}
-
-/** Callback connection handler. */
-static void callback_connection(ipc_callid_t iid, ipc_call_t *icall)
-{
-	// FIXME - determine which device just called back
-	virtual_device_t *dev = find_device_by_id(0);
-	if (dev == NULL) {
-		ipc_answer_0(iid, EINVAL);
-		printf("Ooops\n");
-		return;
-	}
-
-	device_callback_connection(dev->device, iid, icall);
-}
-
-/** Create necessary phones for communication with virtual HCD.
- * This function wraps following calls:
- * -# open <code>/dev/devices/\\virt\\usbhc for reading
- * -# access phone of file opened in previous step
- * -# create callback through just opened phone
- * -# create handler for calling on data from host to function
- * -# return the (outgoing) phone
- *
- * @warning This function is wrapper for several actions and therefore
- * it is not possible - in case of error - to determine at which point
- * error occurred.
- *
- * @param dev Device to connect.
- * @return EOK on success or error code from errno.h.
- */
-int usbvirt_connect(usbvirt_device_t *dev)
-{
-	virtual_device_t *virtual_device = find_device(dev);
-	if (virtual_device != NULL) {
-		return EEXISTS;
-	}
-	
-	const char *vhc_path = "/virt/usbhc";
-	int rc;
-	devman_handle_t handle;
-
-	rc = devman_device_get_handle(vhc_path, &handle, 0);
-	if (rc != EOK) {
-		printf("devman_device_get_handle() failed\n");
-		return rc;
-	}
-	
-	int hcd_phone = devman_device_connect(handle, 0);
-	
-	if (hcd_phone < 0) {
-		printf("devman_device_connect() failed\n");
-		return hcd_phone;
-	}
-	
-	ipcarg_t phonehash;
-	rc = ipc_connect_to_me(hcd_phone, 0, 0, 0, &phonehash);
-	if (rc != EOK) {
-		printf("ipc_connect_to_me() failed\n");
-		return rc;
-	}
-	
-	device_init(dev);
-	
-	virtual_device = add_device(dev);
-	virtual_device->vhcd_phone = hcd_phone;
-	virtual_device->id = 0;
-	
-	async_new_connection(phonehash, 0, NULL, callback_connection);
-	
-	return EOK;
-}
-
-/** Prepares device as local.
- * This is useful if you want to have a virtual device in the same task
- * as HCD.
- *
- * @param dev Device to connect.
- * @return Error code.
- * @retval EOK Device connected.
- * @retval EEXISTS This device is already connected.
- */
-int usbvirt_connect_local(usbvirt_device_t *dev)
-{
-	virtual_device_t *virtual_device = find_device(dev);
-	if (virtual_device != NULL) {
-		return EEXISTS;
-	}
-	
-	device_init(dev);
-	
-	virtual_device = add_device(dev);
-	virtual_device->vhcd_phone = -1;
-	virtual_device->id = 0;
-	
-	return EOK;
-}
-
-/** Disconnects device from HCD.
- *
- * @param dev Device to be disconnected.
- * @return Error code.
- * @retval EOK Device connected.
- * @retval ENOENT This device is not connected.
- */
-int usbvirt_disconnect(usbvirt_device_t *dev)
-{
-	virtual_device_t *virtual_device = find_device(dev);
-	if (virtual_device == NULL) {
-		return ENOENT;
-	}
-	
-	destroy_device(virtual_device);
-	
-	return EOK;
-}
-
-
-/**
- * @}
- */
Index: uspace/lib/usbvirt/private.h
===================================================================
--- uspace/lib/usbvirt/private.h	(revision 37f7cfe6ab80448fed991af05947b5c57080be0f)
+++ 	(revision )
@@ -1,91 +1,0 @@
-/*
- * Copyright (c) 2010 Vojtech Horky
- * 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 libusbvirt usb
- * @{
- */
-/** @file
- * @brief Virtual USB private header.
- */
-#ifndef LIBUSBVIRT_PRIVATE_H_
-#define LIBUSBVIRT_PRIVATE_H_
-
-#include "device.h"
-#include "hub.h"
-
-
-#define DEVICE_HAS_OP(dev, op) \
-	( \
-		(  ((dev)->ops) != NULL  ) \
-		&& \
-		(  ((dev)->ops->op) != NULL  ) \
-	)
-
-int usbvirt_data_to_host(struct usbvirt_device *dev,
-    usb_endpoint_t endpoint, void *buffer, size_t size);
-
-int handle_incoming_data(struct usbvirt_device *dev,
-    usb_endpoint_t endpoint, void *buffer, size_t size);
-
-int control_pipe(usbvirt_device_t *device, usbvirt_control_transfer_t *transfer);
-
-int handle_std_request(usbvirt_device_t *device, usb_device_request_setup_packet_t *request, uint8_t *data);
-
-void device_callback_connection(usbvirt_device_t *device, ipc_callid_t iid, ipc_call_t *icall);
-
-int transaction_setup(usbvirt_device_t *device, usb_endpoint_t endpoint,
-    void *buffer, size_t size);
-int transaction_out(usbvirt_device_t *device, usb_endpoint_t endpoint,
-    void *buffer, size_t size);
-int transaction_in(usbvirt_device_t *device, usb_endpoint_t endpoint,
-    void *buffer, size_t size, size_t *data_size);
-
-
-void user_debug(usbvirt_device_t *device, int level, uint8_t tag,
-    const char *format, ...);
-void lib_debug(usbvirt_device_t *device, int level, uint8_t tag,
-    const char *format, ...);
-    
-static inline const char *str_device_state(usbvirt_device_state_t state)
-{
-	switch (state) {
-		case USBVIRT_STATE_DEFAULT:
-			return "default";
-		case USBVIRT_STATE_ADDRESS:
-			return "address";
-		case USBVIRT_STATE_CONFIGURED:
-			return "configured";
-		default:
-			return "unknown";
-	}
-}
-
-#endif
-/**
- * @}
- */
Index: uspace/lib/usbvirt/src/callback.c
===================================================================
--- uspace/lib/usbvirt/src/callback.c	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
+++ uspace/lib/usbvirt/src/callback.c	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
@@ -0,0 +1,234 @@
+/*
+ * Copyright (c) 2010 Vojtech Horky
+ * 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 libusbvirt usb
+ * @{
+ */
+/** @file
+ * @brief Callback connection handling.
+ */
+#include <devmap.h>
+#include <fcntl.h>
+#include <vfs/vfs.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <mem.h>
+
+#include "private.h"
+
+#define NAMESPACE "usb"
+#define USB_MAX_PAYLOAD_SIZE 1020
+
+/** Wrapper for SETUP transaction over telephone. */
+static void handle_setup_transaction(usbvirt_device_t *device,
+    ipc_callid_t iid, ipc_call_t icall)
+{
+	usb_address_t address = IPC_GET_ARG1(icall);
+	usb_endpoint_t endpoint = IPC_GET_ARG2(icall);
+	size_t expected_len = IPC_GET_ARG3(icall);
+	
+	if (address != device->address) {
+		ipc_answer_0(iid, EADDRNOTAVAIL);
+		return;
+	}
+	
+	if ((endpoint < 0) || (endpoint >= USB11_ENDPOINT_MAX)) {
+		ipc_answer_0(iid, EINVAL);
+		return;
+	}
+	
+	if (expected_len == 0) {
+		ipc_answer_0(iid, EINVAL);
+		return;
+	}
+	
+	size_t len = 0;
+	void * buffer = NULL;
+	int rc = async_data_write_accept(&buffer, false,
+	    1, USB_MAX_PAYLOAD_SIZE, 0, &len);
+		
+	if (rc != EOK) {
+		ipc_answer_0(iid, rc);
+		return;
+	}
+	
+	rc = device->transaction_setup(device, endpoint, buffer, len);
+	
+	ipc_answer_0(iid, rc);
+}
+
+/** Wrapper for OUT transaction over telephone. */
+static void handle_out_transaction(usbvirt_device_t *device,
+    ipc_callid_t iid, ipc_call_t icall)
+{
+	usb_address_t address = IPC_GET_ARG1(icall);
+	usb_endpoint_t endpoint = IPC_GET_ARG2(icall);
+	size_t expected_len = IPC_GET_ARG3(icall);
+	
+	if (address != device->address) {
+		ipc_answer_0(iid, EADDRNOTAVAIL);
+		return;
+	}
+	
+	if ((endpoint < 0) || (endpoint >= USB11_ENDPOINT_MAX)) {
+		ipc_answer_0(iid, EINVAL);
+		return;
+	}
+	
+	int rc = EOK;
+	
+	size_t len = 0;
+	void *buffer = NULL;
+	
+	if (expected_len > 0) {
+		rc = async_data_write_accept(&buffer, false,
+		    1, USB_MAX_PAYLOAD_SIZE, 0, &len);
+			
+		if (rc != EOK) {
+			ipc_answer_0(iid, rc);
+			return;
+		}
+	}
+	
+	rc = device->transaction_out(device, endpoint, buffer, len);
+	
+	if (buffer != NULL) {
+		free(buffer);
+	}
+	
+	ipc_answer_0(iid, rc);
+}
+
+
+/** Wrapper for IN transaction over telephone. */
+static void handle_in_transaction(usbvirt_device_t *device,
+    ipc_callid_t iid, ipc_call_t icall)
+{
+	usb_address_t address = IPC_GET_ARG1(icall);
+	usb_endpoint_t endpoint = IPC_GET_ARG2(icall);
+	size_t expected_len = IPC_GET_ARG3(icall);
+	
+	if (address != device->address) {
+		ipc_answer_0(iid, EADDRNOTAVAIL);
+		return;
+	}
+	
+	if ((endpoint < 0) || (endpoint >= USB11_ENDPOINT_MAX)) {
+		ipc_answer_0(iid, EINVAL);
+		return;
+	}
+	
+	int rc = EOK;
+	
+	void *buffer = expected_len > 0 ? malloc(expected_len) : NULL;
+	size_t len;
+	
+	rc = device->transaction_in(device, endpoint, buffer, expected_len, &len);
+	/*
+	 * If the request was processed, we will send data back.
+	 */
+	if ((rc == EOK) && (expected_len > 0)) {
+		size_t receive_len;
+		ipc_callid_t callid;
+		if (!async_data_read_receive(&callid, &receive_len)) {
+			ipc_answer_0(iid, EINVAL);
+			return;
+		}
+		async_data_read_finalize(callid, buffer, receive_len);
+	}
+	
+	ipc_answer_0(iid, rc);
+}
+
+/** Wrapper for getting device name. */
+static void handle_get_name(usbvirt_device_t *device,
+    ipc_callid_t iid, ipc_call_t icall)
+{
+	if (device->name == NULL) {
+		ipc_answer_0(iid, ENOENT);
+	}
+	
+	size_t size = str_size(device->name);
+	
+	ipc_callid_t callid;
+	size_t accepted_size;
+	if (!async_data_read_receive(&callid, &accepted_size)) {
+		ipc_answer_0(iid, EINVAL);
+		return;
+	}
+	
+	if (accepted_size > size) {
+		accepted_size = size;
+	}
+	async_data_read_finalize(callid, device->name, accepted_size);
+	
+	ipc_answer_1(iid, EOK, accepted_size);
+}
+
+/** Callback connection for a given device. */
+void device_callback_connection(usbvirt_device_t *device, ipc_callid_t iid, ipc_call_t *icall)
+{
+	ipc_answer_0(iid, EOK);
+	
+	while (true) {
+		ipc_callid_t callid; 
+		ipc_call_t call; 
+		
+		callid = async_get_call(&call);
+		switch (IPC_GET_METHOD(call)) {
+			case IPC_M_PHONE_HUNGUP:
+				ipc_answer_0(callid, EOK);
+				return;
+			
+			case IPC_M_USBVIRT_GET_NAME:
+				handle_get_name(device, callid, call);
+				break;
+			
+			case IPC_M_USBVIRT_TRANSACTION_SETUP:
+				handle_setup_transaction(device, callid, call);
+				break;
+			
+			case IPC_M_USBVIRT_TRANSACTION_OUT:
+				handle_out_transaction(device, callid, call);
+				break;
+				
+			case IPC_M_USBVIRT_TRANSACTION_IN:
+				handle_in_transaction(device, callid, call);
+				break;
+			
+			default:
+				ipc_answer_0(callid, EINVAL);
+				break;
+		}
+	}
+}
+
+
+/**
+ * @}
+ */
Index: uspace/lib/usbvirt/src/ctrlpipe.c
===================================================================
--- uspace/lib/usbvirt/src/ctrlpipe.c	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
+++ uspace/lib/usbvirt/src/ctrlpipe.c	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2010 Vojtech Horky
+ * 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 libusbvirt usb
+ * @{
+ */
+/** @file
+ * @brief Device control pipe.
+ */
+#include <errno.h>
+
+#include "private.h"
+
+#define REQUEST_TYPE_STANDARD 0 
+#define REQUEST_TYPE_CLASS 1
+
+#define GET_MIDBITS_MASK(size, shift) \
+	(((1 << size) - 1) << shift)
+#define GET_MIDBITS(value, size, shift) \
+	((value & GET_MIDBITS_MASK(size, shift)) >> shift)
+
+
+static const char *str_request_type(int type)
+{
+	switch (type) {
+		case REQUEST_TYPE_STANDARD:
+			return "standard";
+		case REQUEST_TYPE_CLASS:
+			return "class";
+		default:
+			return "unknown";
+	}
+}
+
+/** Tell request type.
+ * By type is meant either standard, class, vendor or other.
+ */
+static int request_get_type(uint8_t request_type)
+{
+	return GET_MIDBITS(request_type, 2, 5);
+}
+
+/** Handle communication over control pipe zero.
+ */
+int control_pipe(usbvirt_device_t *device, usbvirt_control_transfer_t *transfer)
+{
+	device->lib_debug(device, 1, USBVIRT_DEBUGTAG_CONTROL_PIPE_ZERO,
+	    "op on control pipe zero (request_size=%u)", transfer->request_size);
+	
+	if (transfer->request_size < sizeof(usb_device_request_setup_packet_t)) {
+		return ENOMEM;
+	}
+	
+	usb_device_request_setup_packet_t *request = (usb_device_request_setup_packet_t *) transfer->request;
+	uint8_t *remaining_data = transfer->data;
+	
+	int type = request_get_type(request->request_type);
+	
+	int rc = EOK;
+	
+	device->lib_debug(device, 2, USBVIRT_DEBUGTAG_CONTROL_PIPE_ZERO,
+	    "request type: %s", str_request_type(type));
+	
+	switch (type) {
+		case REQUEST_TYPE_STANDARD:
+			rc = handle_std_request(device, request, remaining_data);
+			break;
+		case REQUEST_TYPE_CLASS:
+			if (DEVICE_HAS_OP(device, on_class_device_request)) {
+				rc = device->ops->on_class_device_request(device,
+				    request, remaining_data);
+			}
+			break;
+		default:
+			break;
+	}
+	
+	if (device->new_address != -1) {
+		/*
+		 * TODO: handle when this request is invalid (e.g.
+		 * setting address when in configured state).
+		 */
+		if (device->new_address == 0) {
+			device->state = USBVIRT_STATE_DEFAULT;
+		} else {
+			device->state = USBVIRT_STATE_ADDRESS;
+		}
+		device->address = device->new_address;
+		
+		device->new_address = -1;
+		
+		device->lib_debug(device, 2, USBVIRT_DEBUGTAG_CONTROL_PIPE_ZERO,
+		    "device address changed to %d (state %s)",
+		    device->address, str_device_state(device->state));
+	}
+	
+	return rc;
+}
+
+/**
+ * @}
+ */
Index: uspace/lib/usbvirt/src/debug.c
===================================================================
--- uspace/lib/usbvirt/src/debug.c	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
+++ uspace/lib/usbvirt/src/debug.c	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2010 Vojtech Horky
+ * 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 libusbvirt usb
+ * @{
+ */
+/** @file
+ * @brief Debugging support.
+ */
+#include <stdio.h>
+#include <bool.h>
+
+#include "private.h"
+
+
+static void debug_print(int level, uint8_t tag,
+    int current_level, uint8_t enabled_tags,
+    const char *format, va_list args)
+{
+	if (level > current_level) {
+		return;
+	}
+	
+	if ((tag & enabled_tags) == 0) {
+		return;
+	}
+	
+	bool print_prefix = true;
+	
+	if ((format[0] == '%') && (format[1] == 'M')) {
+		format += 2;
+		print_prefix = false;
+	}
+	
+	if (print_prefix) {
+		printf("[vusb]: ");
+		while (--level > 0) {
+			printf(" ");
+		}
+	}
+	
+	vprintf(format, args);
+	
+	if (print_prefix) {
+		printf("\n");
+	}
+}
+
+
+void user_debug(usbvirt_device_t *device, int level, uint8_t tag,
+    const char *format, ...)
+{
+	va_list args;
+	va_start(args, format);
+	
+	debug_print(level, tag,
+	    device->debug_level, device->debug_enabled_tags,
+	    format, args);
+	
+	va_end(args);
+}
+
+void lib_debug(usbvirt_device_t *device, int level, uint8_t tag,
+    const char *format, ...)
+{
+	va_list args;
+	va_start(args, format);
+	
+	debug_print(level, tag,
+	    device->lib_debug_level, device->lib_debug_enabled_tags,
+	    format, args);
+	
+	va_end(args);
+}
+
+/**
+ * @}
+ */
Index: uspace/lib/usbvirt/src/main.c
===================================================================
--- uspace/lib/usbvirt/src/main.c	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
+++ uspace/lib/usbvirt/src/main.c	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
@@ -0,0 +1,287 @@
+/*
+ * Copyright (c) 2010 Vojtech Horky
+ * 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 libusbvirt usb
+ * @{
+ */
+/** @file
+ * @brief Device registration with virtual USB framework.
+ */
+#include <devman.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <mem.h>
+#include <assert.h>
+
+#include "private.h"
+
+#define NAMESPACE "usb"
+
+/** Virtual device wrapper. */
+typedef struct {
+	/** Actual device. */
+	usbvirt_device_t *device;
+	/** Phone to host controller. */
+	int vhcd_phone;
+	/** Device id. */
+	ipcarg_t id;
+	/** Linked-list member. */
+	link_t link;
+} virtual_device_t;
+
+/*** List of known device. */
+static LIST_INITIALIZE(device_list);
+
+/** Find virtual device wrapper based on the contents. */
+static virtual_device_t *find_device(usbvirt_device_t *device)
+{
+	if (list_empty(&device_list)) {
+		return NULL;
+	}
+	
+	link_t *pos;
+	for (pos = device_list.next; pos != &device_list; pos = pos->next) {
+		virtual_device_t *dev
+		    = list_get_instance(pos, virtual_device_t, link);
+		if (dev->device == device) {
+			return dev;
+		}
+	}
+	
+	return NULL;
+}
+
+/** Find virtual device wrapper by its id. */
+static virtual_device_t *find_device_by_id(ipcarg_t id)
+{
+	if (list_empty(&device_list)) {
+		return NULL;
+	}
+	
+	link_t *pos;
+	for (pos = device_list.next; pos != &device_list; pos = pos->next) {
+		virtual_device_t *dev
+		    = list_get_instance(pos, virtual_device_t, link);
+		if (dev->id == id) {
+			return dev;
+		}
+	}
+	
+	return NULL;
+}
+
+/** Reply to a control transfer. */
+static int control_transfer_reply(usbvirt_device_t *device,
+	    usb_endpoint_t endpoint, void *buffer, size_t size)
+{
+	usbvirt_control_transfer_t *transfer = &device->current_control_transfers[endpoint];
+	if (transfer->data != NULL) {
+		free(transfer->data);
+	}
+	transfer->data = malloc(size);
+	memcpy(transfer->data, buffer, size);
+	transfer->data_size = size;
+	
+	return EOK;
+}
+
+/** Initialize virtual device. */
+static void device_init(usbvirt_device_t *dev)
+{
+	dev->transaction_out = transaction_out;
+	dev->transaction_setup = transaction_setup;
+	dev->transaction_in = transaction_in;
+	
+	dev->control_transfer_reply = control_transfer_reply;
+	
+	dev->debug = user_debug;
+	dev->lib_debug = lib_debug;
+	
+	dev->state = USBVIRT_STATE_DEFAULT;
+	dev->address = 0;
+	dev->new_address = -1;
+	
+	size_t i;
+	for (i = 0; i < USB11_ENDPOINT_MAX; i++) {
+		usbvirt_control_transfer_t *transfer = &dev->current_control_transfers[i];
+		transfer->direction = 0;
+		transfer->request = NULL;
+		transfer->request_size = 0;
+		transfer->data = NULL;
+		transfer->data_size = 0;
+	}
+}
+
+/** Add a virtual device.
+ * The returned device (if not NULL) shall be destroy via destroy_device().
+ */
+static virtual_device_t *add_device(usbvirt_device_t *dev)
+{
+	assert(find_device(dev) == NULL);
+	virtual_device_t *new_device
+	    = (virtual_device_t *) malloc(sizeof(virtual_device_t));
+	
+	new_device->device = dev;
+	link_initialize(&new_device->link);
+	
+	list_append(&new_device->link, &device_list);
+	
+	return new_device;
+}
+
+/** Destroy virtual device. */
+static void destroy_device(virtual_device_t *dev)
+{
+	if (dev->vhcd_phone > 0) {
+		ipc_hangup(dev->vhcd_phone);
+	}
+	
+	list_remove(&dev->link);
+	
+	free(dev);
+}
+
+/** Callback connection handler. */
+static void callback_connection(ipc_callid_t iid, ipc_call_t *icall)
+{
+	// FIXME - determine which device just called back
+	virtual_device_t *dev = find_device_by_id(0);
+	if (dev == NULL) {
+		ipc_answer_0(iid, EINVAL);
+		printf("Ooops\n");
+		return;
+	}
+
+	device_callback_connection(dev->device, iid, icall);
+}
+
+/** Create necessary phones for communication with virtual HCD.
+ * This function wraps following calls:
+ * -# open <code>/dev/devices/\\virt\\usbhc for reading
+ * -# access phone of file opened in previous step
+ * -# create callback through just opened phone
+ * -# create handler for calling on data from host to function
+ * -# return the (outgoing) phone
+ *
+ * @warning This function is wrapper for several actions and therefore
+ * it is not possible - in case of error - to determine at which point
+ * error occurred.
+ *
+ * @param dev Device to connect.
+ * @return EOK on success or error code from errno.h.
+ */
+int usbvirt_connect(usbvirt_device_t *dev)
+{
+	virtual_device_t *virtual_device = find_device(dev);
+	if (virtual_device != NULL) {
+		return EEXISTS;
+	}
+	
+	const char *vhc_path = "/virt/usbhc";
+	int rc;
+	devman_handle_t handle;
+
+	rc = devman_device_get_handle(vhc_path, &handle, 0);
+	if (rc != EOK) {
+		printf("devman_device_get_handle() failed\n");
+		return rc;
+	}
+	
+	int hcd_phone = devman_device_connect(handle, 0);
+	
+	if (hcd_phone < 0) {
+		printf("devman_device_connect() failed\n");
+		return hcd_phone;
+	}
+	
+	ipcarg_t phonehash;
+	rc = ipc_connect_to_me(hcd_phone, 0, 0, 0, &phonehash);
+	if (rc != EOK) {
+		printf("ipc_connect_to_me() failed\n");
+		return rc;
+	}
+	
+	device_init(dev);
+	
+	virtual_device = add_device(dev);
+	virtual_device->vhcd_phone = hcd_phone;
+	virtual_device->id = 0;
+	
+	async_new_connection(phonehash, 0, NULL, callback_connection);
+	
+	return EOK;
+}
+
+/** Prepares device as local.
+ * This is useful if you want to have a virtual device in the same task
+ * as HCD.
+ *
+ * @param dev Device to connect.
+ * @return Error code.
+ * @retval EOK Device connected.
+ * @retval EEXISTS This device is already connected.
+ */
+int usbvirt_connect_local(usbvirt_device_t *dev)
+{
+	virtual_device_t *virtual_device = find_device(dev);
+	if (virtual_device != NULL) {
+		return EEXISTS;
+	}
+	
+	device_init(dev);
+	
+	virtual_device = add_device(dev);
+	virtual_device->vhcd_phone = -1;
+	virtual_device->id = 0;
+	
+	return EOK;
+}
+
+/** Disconnects device from HCD.
+ *
+ * @param dev Device to be disconnected.
+ * @return Error code.
+ * @retval EOK Device connected.
+ * @retval ENOENT This device is not connected.
+ */
+int usbvirt_disconnect(usbvirt_device_t *dev)
+{
+	virtual_device_t *virtual_device = find_device(dev);
+	if (virtual_device == NULL) {
+		return ENOENT;
+	}
+	
+	destroy_device(virtual_device);
+	
+	return EOK;
+}
+
+
+/**
+ * @}
+ */
Index: uspace/lib/usbvirt/src/private.h
===================================================================
--- uspace/lib/usbvirt/src/private.h	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
+++ uspace/lib/usbvirt/src/private.h	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2010 Vojtech Horky
+ * 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 libusbvirt usb
+ * @{
+ */
+/** @file
+ * @brief Virtual USB private header.
+ */
+#ifndef LIBUSBVIRT_PRIVATE_H_
+#define LIBUSBVIRT_PRIVATE_H_
+
+#include <usbvirt/device.h>
+#include <usbvirt/hub.h>
+#include <assert.h>
+
+
+#define DEVICE_HAS_OP(dev, op) \
+	( \
+		(  ((dev)->ops) != NULL  ) \
+		&& \
+		(  ((dev)->ops->op) != NULL  ) \
+	)
+
+int usbvirt_data_to_host(struct usbvirt_device *dev,
+    usb_endpoint_t endpoint, void *buffer, size_t size);
+
+int handle_incoming_data(struct usbvirt_device *dev,
+    usb_endpoint_t endpoint, void *buffer, size_t size);
+
+int control_pipe(usbvirt_device_t *device, usbvirt_control_transfer_t *transfer);
+
+int handle_std_request(usbvirt_device_t *device, usb_device_request_setup_packet_t *request, uint8_t *data);
+
+void device_callback_connection(usbvirt_device_t *device, ipc_callid_t iid, ipc_call_t *icall);
+
+int transaction_setup(usbvirt_device_t *device, usb_endpoint_t endpoint,
+    void *buffer, size_t size);
+int transaction_out(usbvirt_device_t *device, usb_endpoint_t endpoint,
+    void *buffer, size_t size);
+int transaction_in(usbvirt_device_t *device, usb_endpoint_t endpoint,
+    void *buffer, size_t size, size_t *data_size);
+
+
+void user_debug(usbvirt_device_t *device, int level, uint8_t tag,
+    const char *format, ...);
+void lib_debug(usbvirt_device_t *device, int level, uint8_t tag,
+    const char *format, ...);
+    
+static inline const char *str_device_state(usbvirt_device_state_t state)
+{
+	switch (state) {
+		case USBVIRT_STATE_DEFAULT:
+			return "default";
+		case USBVIRT_STATE_ADDRESS:
+			return "address";
+		case USBVIRT_STATE_CONFIGURED:
+			return "configured";
+		default:
+			return "unknown";
+	}
+}
+
+#endif
+/**
+ * @}
+ */
Index: uspace/lib/usbvirt/src/stdreq.c
===================================================================
--- uspace/lib/usbvirt/src/stdreq.c	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
+++ uspace/lib/usbvirt/src/stdreq.c	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
@@ -0,0 +1,220 @@
+/*
+ * Copyright (c) 2010 Vojtech Horky
+ * 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 libusbvirt usb
+ * @{
+ */
+/** @file
+ * @brief Preprocessing of standard device requests.
+ */
+#include <errno.h>
+#include <stdlib.h>
+#include <mem.h>
+#include <usb/devreq.h>
+
+#include "private.h"
+
+
+typedef int (*usbvirt_stdreq_handler_t)(usbvirt_device_t *,
+usb_device_request_setup_packet_t *, uint8_t *);
+
+/*
+ * All sub handlers must return EFORWARD to inform the caller that
+ * they were not able to process the request (yes, it is abuse of
+ * this error code but such error code shall not collide with anything
+ * else in this context).
+ */
+ 
+/** GET_DESCRIPTOR handler. */
+static int handle_get_descriptor(usbvirt_device_t *device,
+    usb_device_request_setup_packet_t *setup_packet, uint8_t *extra_data)
+{
+	uint8_t type = setup_packet->value_high;
+	uint8_t index = setup_packet->value_low;
+
+	/* 
+	 * Standard device descriptor.
+	 */
+	if ((type == USB_DESCTYPE_DEVICE) && (index == 0)) {
+		if (device->descriptors && device->descriptors->device) {
+			return device->control_transfer_reply(device, 0,
+			    device->descriptors->device,
+			    device->descriptors->device->length);
+		} else {
+			return EFORWARD;
+		}
+	}
+	
+	/*
+	 * Configuration descriptor together with interface, endpoint and
+	 * class-specific descriptors.
+	 */
+	if (type == USB_DESCTYPE_CONFIGURATION) {
+		if (!device->descriptors) {
+			return EFORWARD;
+		}
+		if (index >= device->descriptors->configuration_count) {
+			return EFORWARD;
+		}
+		/* Copy the data. */
+		usbvirt_device_configuration_t *config = &device->descriptors
+		    ->configuration[index];
+		uint8_t *all_data = malloc(config->descriptor->total_length);
+		if (all_data == NULL) {
+			return ENOMEM;
+		}
+		
+		uint8_t *ptr = all_data;
+		memcpy(ptr, config->descriptor, config->descriptor->length);
+		ptr += config->descriptor->length;
+		size_t i;
+		for (i = 0; i < config->extra_count; i++) {
+			usbvirt_device_configuration_extras_t *extra
+			    = &config->extra[i];
+			memcpy(ptr, extra->data, extra->length);
+			ptr += extra->length;
+		}
+		
+		int rc = device->control_transfer_reply(device, 0,
+		    all_data, config->descriptor->total_length);
+		
+		free(all_data);
+		
+		return rc;
+	}
+	
+	return EFORWARD;
+}
+
+/** SET_ADDRESS handler. */
+static int handle_set_address(usbvirt_device_t *device,
+    usb_device_request_setup_packet_t *setup_packet, uint8_t *extra_data)
+{
+	uint16_t new_address = setup_packet->value;
+	uint16_t zero1 = setup_packet->index;
+	uint16_t zero2 = setup_packet->length;
+
+	if ((zero1 != 0) || (zero2 != 0)) {
+		return EINVAL;
+	}
+	
+	if (new_address > 127) {
+		return EINVAL;
+	}
+	
+	device->new_address = new_address;
+	
+	return EOK;
+}
+
+/** SET_CONFIGURATION handler. */
+static int handle_set_configuration(usbvirt_device_t *device,
+    usb_device_request_setup_packet_t *setup_packet, uint8_t *extra_data)
+{
+	uint16_t configuration_value = setup_packet->value;
+	uint16_t zero1 = setup_packet->index;
+	uint16_t zero2 = setup_packet->length;
+
+	if ((zero1 != 0) || (zero2 != 0)) {
+		return EINVAL;
+	}
+	
+	/*
+	 * Configuration value is 1 byte information.
+	 */
+	if (configuration_value > 255) {
+		return EINVAL;
+	}
+	
+	/*
+	 * Do nothing when in default state. According to specification,
+	 * this is not specified.
+	 */
+	if (device->state == USBVIRT_STATE_DEFAULT) {
+		return EOK;
+	}
+	
+	if (configuration_value == 0) {
+		device->state = USBVIRT_STATE_ADDRESS;
+	} else {
+		/*
+		* TODO: browse provided configurations and verify that
+		* user selected existing configuration.
+		*/
+		device->state = USBVIRT_STATE_CONFIGURED;
+		if (device->descriptors) {
+			device->descriptors->current_configuration
+			    = configuration_value;
+		}
+	}
+		
+	return EOK;
+}
+
+static usbvirt_stdreq_handler_t local_handlers[USB_DEVREQ_LAST_STD] = {
+	[USB_DEVREQ_GET_DESCRIPTOR] = handle_get_descriptor,
+	[USB_DEVREQ_SET_ADDRESS] = handle_set_address,
+	[USB_DEVREQ_SET_CONFIGURATION] = handle_set_configuration
+};
+
+/** Handle standard device request. */
+int handle_std_request(usbvirt_device_t *device,
+    usb_device_request_setup_packet_t *request_packet, uint8_t *data)
+{
+	int request = request_packet->request;
+
+	device->lib_debug(device, 3, USBVIRT_DEBUGTAG_CONTROL_PIPE_ZERO,
+	    "handling standard request %d", request);
+
+	if (request >= USB_DEVREQ_LAST_STD) {
+		return ENOTSUP;
+	}
+	
+	int rc = EFORWARD;
+	if ((device->ops)
+	    && (device->ops->on_standard_request[request])) {
+		rc = device->ops->on_standard_request[request](device,
+		    request_packet, data);
+	}
+
+	if (rc == EFORWARD) {
+		if (local_handlers[request]) {
+			rc = local_handlers[request](device,
+			    request_packet, data);
+		} else {
+			rc = ENOTSUP;
+		}
+	}
+
+	assert(rc != EFORWARD);
+	return rc;
+}
+
+/**
+ * @}
+ */
Index: uspace/lib/usbvirt/src/transaction.c
===================================================================
--- uspace/lib/usbvirt/src/transaction.c	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
+++ uspace/lib/usbvirt/src/transaction.c	(revision 75732daeac84e2935c03d316ed5cb327455ac6a3)
@@ -0,0 +1,268 @@
+/*
+ * Copyright (c) 2010 Vojtech Horky
+ * 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 libusbvirt usb
+ * @{
+ */
+/** @file
+ * @brief Transaction processing.
+ */
+#include <errno.h>
+#include <stdlib.h>
+#include <mem.h>
+
+#include "private.h"
+
+static usb_direction_t setup_transaction_direction(usbvirt_device_t *,
+    usb_endpoint_t, void *, size_t);
+static void process_control_transfer(usbvirt_device_t *,
+    usb_endpoint_t, usbvirt_control_transfer_t *);
+
+/** Convert virtual USB transaction type to string.
+ */
+const char *usbvirt_str_transaction_type(usbvirt_transaction_type_t type)
+{
+	switch (type) {
+		case USBVIRT_TRANSACTION_SETUP:
+			return "setup";
+		case USBVIRT_TRANSACTION_IN:
+			return "in";
+		case USBVIRT_TRANSACTION_OUT:
+			return "out";
+		default:
+			return "unknown";
+	}
+}
+
+/** SETUP transaction handling.
+ * The setup transaction only prepares control transfer on given endpoint.
+ */
+int transaction_setup(usbvirt_device_t *device, usb_endpoint_t endpoint,
+    void *buffer, size_t size)
+{
+	device->lib_debug(device, 1, USBVIRT_DEBUGTAG_TRANSACTION,
+	    "setup transaction: endpoint=%d, size=%u", endpoint, size);
+	
+	usbvirt_control_transfer_t *transfer = &device->current_control_transfers[endpoint];
+	
+	if (transfer->request != NULL) {
+		free(transfer->request);
+	}
+	if (transfer->data != NULL) {
+		free(transfer->data);
+	}
+	
+	transfer->direction = setup_transaction_direction(device, endpoint,
+	    buffer, size);
+	transfer->request = malloc(size);
+	memcpy(transfer->request, buffer, size);
+	transfer->request_size = size;
+	transfer->data = NULL;
+	transfer->data_size = 0;
+	
+	if (transfer->direction == USB_DIRECTION_IN) {
+		process_control_transfer(device, endpoint, transfer);
+	}
+	
+	return EOK;
+}
+
+/** OUT transaction handling.
+ * The OUT transaction can trigger processing of a control transfer.
+ */
+int transaction_out(usbvirt_device_t *device, usb_endpoint_t endpoint,
+    void *buffer, size_t size)
+{
+	device->lib_debug(device, 1, USBVIRT_DEBUGTAG_TRANSACTION,
+	    "out transaction: endpoint=%d, size=%u", endpoint, size);
+	
+	/*
+	 * First check whether it is a transaction over control pipe.
+	 */
+	usbvirt_control_transfer_t *transfer = &device->current_control_transfers[endpoint];
+	if (transfer->request != NULL) {
+		if (transfer->direction == USB_DIRECTION_OUT) {
+			/*
+			 * For out transactions, append the data to the buffer.
+			 */
+			uint8_t *new_buffer = (uint8_t *) malloc(transfer->data_size + size);
+			if (transfer->data) {
+				memcpy(new_buffer, transfer->data, transfer->data_size);
+			}
+			memcpy(new_buffer + transfer->data_size, buffer, size);
+			
+			if (transfer->data) {
+				free(transfer->data);
+			}
+			transfer->data = new_buffer;
+			transfer->data_size += size;
+		} else {
+			/*
+			 * For in transactions, this means end of the
+			 * transaction.
+			 */
+			free(transfer->request);
+			if (transfer->data) {
+				free(transfer->data);
+			}
+			transfer->request = NULL;
+			transfer->request_size = 0;
+			transfer->data = NULL;
+			transfer->data_size = 0;
+		}
+		
+		return EOK;
+	}
+	
+	/*
+	 * Otherwise, announce that some data has come.
+	 */
+	if (device->ops && device->ops->on_data) {
+		return device->ops->on_data(device, endpoint, buffer, size);
+	} else {
+		return ENOTSUP;
+	}
+}
+
+/** IN transaction handling.
+ * The IN transaction can trigger processing of a control transfer.
+ */
+int transaction_in(usbvirt_device_t *device, usb_endpoint_t endpoint,
+    void *buffer, size_t size, size_t *data_size)
+{
+	device->lib_debug(device, 1, USBVIRT_DEBUGTAG_TRANSACTION,
+	    "in transaction: endpoint=%d, size=%u", endpoint, size);
+	
+	/*
+	 * First check whether it is a transaction over control pipe.
+	 */
+	usbvirt_control_transfer_t *transfer = &device->current_control_transfers[endpoint];
+	if (transfer->request != NULL) {
+		if (transfer->direction == USB_DIRECTION_OUT) {
+			/*
+			 * This means end of input data.
+			 */
+			process_control_transfer(device, endpoint, transfer);
+		} else {
+			/*
+			 * For in transactions, this means sending next part
+			 * of the buffer.
+			 */
+			// FIXME: handle when the HC wants the data back
+			// in more chunks
+			size_t actual_size = 0;
+			if (transfer->data) {
+				actual_size = transfer->data_size;
+			}
+			if (actual_size > size) {
+				actual_size = size;
+			}
+			device->lib_debug(device, 1, USBVIRT_DEBUGTAG_TRANSACTION,
+			    "in transaction: will copy %zu bytes", actual_size);
+			if (actual_size > 0) {
+				memcpy(buffer, transfer->data, actual_size);
+				if (data_size) {
+					*data_size = actual_size;
+				}
+			}
+		}
+		
+		return EOK;
+	}
+	
+	if (size == 0) {
+		return EINVAL;
+	}
+	
+	int rc = 1;
+	
+	if (device->ops && device->ops->on_data_request) {
+		rc = device->ops->on_data_request(device, endpoint, buffer, size, data_size);
+	}
+	
+	return rc;
+}
+
+/** Determine direction of control transfer.
+ * First, try the user provided callback, otherwise guess, believing that
+ * it uses the same format as control pipe 0.
+ */
+static usb_direction_t setup_transaction_direction(usbvirt_device_t *device,
+    usb_endpoint_t endpoint,
+    void *data, size_t size)
+{
+	int direction = -1;
+	if (device->ops && device->ops->decide_control_transfer_direction) {
+		direction = device->ops->decide_control_transfer_direction(endpoint,
+		    data, size);
+	}
+	
+	/*
+	 * If the user-supplied routine have not handled the direction
+	 * (or simply was not provided) we will guess, hoping that it 
+	 * uses same format as standard request on control pipe zero.
+	 */
+	if (direction < 0) {
+		if (size > 0) {
+			uint8_t *ptr = (uint8_t *) data;
+			if ((ptr[0] & 128) == 128) {
+				direction = USB_DIRECTION_IN;
+			} else {
+				direction = USB_DIRECTION_OUT;
+			}
+		} else {
+			/* This shall not happen anyway. */
+			direction = USB_DIRECTION_OUT;
+		}
+	}
+	
+	return (usb_direction_t) direction;
+}
+
+/** Process control transfer.
+ */
+static void process_control_transfer(usbvirt_device_t *device,
+    usb_endpoint_t endpoint,
+    usbvirt_control_transfer_t *transfer)
+{
+	int rc = EFORWARD;
+	
+	if (device->ops && device->ops->on_control_transfer) {
+		rc = device->ops->on_control_transfer(device, endpoint, transfer);
+	}
+	
+	if (rc == EFORWARD) {
+		if (endpoint == 0) {
+			rc = control_pipe(device, transfer);
+		}
+	}
+}
+
+/**
+ * @}
+ */
Index: uspace/lib/usbvirt/stdreq.c
===================================================================
--- uspace/lib/usbvirt/stdreq.c	(revision 37f7cfe6ab80448fed991af05947b5c57080be0f)
+++ 	(revision )
@@ -1,212 +1,0 @@
-/*
- * Copyright (c) 2010 Vojtech Horky
- * 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 libusbvirt usb
- * @{
- */
-/** @file
- * @brief Preprocessing of standard device requests.
- */
-#include <errno.h>
-#include <stdlib.h>
-#include <mem.h>
-#include <usb/devreq.h>
-
-#include "private.h"
-
-
-
-/*
- * All sub handlers must return EFORWARD to inform the caller that
- * they were not able to process the request (yes, it is abuse of
- * this error code but such error code shall not collide with anything
- * else in this context).
- */
- 
-/** GET_DESCRIPTOR handler. */
-static int handle_get_descriptor(usbvirt_device_t *device,
-    uint8_t type, uint8_t index, uint16_t language,
-    uint16_t length)
-{
-	/* 
-	 * Standard device descriptor.
-	 */
-	if ((type == USB_DESCTYPE_DEVICE) && (index == 0)) {
-		if (device->descriptors && device->descriptors->device) {
-			return device->control_transfer_reply(device, 0,
-			    device->descriptors->device,
-			    device->descriptors->device->length);
-		} else {
-			return EFORWARD;
-		}
-	}
-	
-	/*
-	 * Configuration descriptor together with interface, endpoint and
-	 * class-specific descriptors.
-	 */
-	if (type == USB_DESCTYPE_CONFIGURATION) {
-		if (!device->descriptors) {
-			return EFORWARD;
-		}
-		if (index >= device->descriptors->configuration_count) {
-			return EFORWARD;
-		}
-		/* Copy the data. */
-		usbvirt_device_configuration_t *config = &device->descriptors
-		    ->configuration[index];
-		uint8_t *all_data = malloc(config->descriptor->total_length);
-		if (all_data == NULL) {
-			return ENOMEM;
-		}
-		
-		uint8_t *ptr = all_data;
-		memcpy(ptr, config->descriptor, config->descriptor->length);
-		ptr += config->descriptor->length;
-		size_t i;
-		for (i = 0; i < config->extra_count; i++) {
-			usbvirt_device_configuration_extras_t *extra
-			    = &config->extra[i];
-			memcpy(ptr, extra->data, extra->length);
-			ptr += extra->length;
-		}
-		
-		int rc = device->control_transfer_reply(device, 0,
-		    all_data, config->descriptor->total_length);
-		
-		free(all_data);
-		
-		return rc;
-	}
-	
-	return EFORWARD;
-}
-
-/** SET_ADDRESS handler. */
-static int handle_set_address(usbvirt_device_t *device,
-    uint16_t new_address,
-    uint16_t zero1, uint16_t zero2)
-{
-	if ((zero1 != 0) || (zero2 != 0)) {
-		return EINVAL;
-	}
-	
-	if (new_address > 127) {
-		return EINVAL;
-	}
-	
-	device->new_address = new_address;
-	
-	return EOK;
-}
-
-/** SET_CONFIGURATION handler. */
-static int handle_set_configuration(usbvirt_device_t *device,
-    uint16_t configuration_value,
-    uint16_t zero1, uint16_t zero2)
-{
-	if ((zero1 != 0) || (zero2 != 0)) {
-		return EINVAL;
-	}
-	
-	/*
-	 * Configuration value is 1 byte information.
-	 */
-	if (configuration_value > 255) {
-		return EINVAL;
-	}
-	
-	/*
-	 * Do nothing when in default state. According to specification,
-	 * this is not specified.
-	 */
-	if (device->state == USBVIRT_STATE_DEFAULT) {
-		return EOK;
-	}
-	
-	if (configuration_value == 0) {
-		device->state = USBVIRT_STATE_ADDRESS;
-	} else {
-		/*
-		* TODO: browse provided configurations and verify that
-		* user selected existing configuration.
-		*/
-		device->state = USBVIRT_STATE_CONFIGURED;
-		if (device->descriptors) {
-			device->descriptors->current_configuration
-			    = configuration_value;
-		}
-	}
-		
-	return EOK;
-}
-
-#define HANDLE_REQUEST(request, data, type, dev, user_callback, default_handler) \
-	do { \
-		if ((request)->request == (type)) { \
-			int _rc = EFORWARD; \
-			if (((dev)->ops) && ((dev)->ops->standard_request_ops) \
-			    && ((dev)->ops->standard_request_ops->user_callback)) { \
-				_rc = (dev)->ops->standard_request_ops->\
-				    user_callback(dev, request, data); \
-			} \
-			if (_rc == EFORWARD) { \
-				default_handler; \
-			} \
-			return _rc; \
-		} \
-	} while (false)
-
-/** Handle standard device request. */
-int handle_std_request(usbvirt_device_t *device,
-    usb_device_request_setup_packet_t *request, uint8_t *data)
-{
-	device->lib_debug(device, 3, USBVIRT_DEBUGTAG_CONTROL_PIPE_ZERO,
-	    "handling standard request %d", request->request);
-	
-	HANDLE_REQUEST(request, data, USB_DEVREQ_GET_DESCRIPTOR,
-	    device, on_get_descriptor,
-	    handle_get_descriptor(device, request->value_high, request->value_low,
-	        request->index, request->length));
-	
-	HANDLE_REQUEST(request, data, USB_DEVREQ_SET_ADDRESS,
-	    device, on_set_address,
-	    handle_set_address(device, request->value,
-	        request->index, request->length));
-	
-	HANDLE_REQUEST(request, data, USB_DEVREQ_SET_CONFIGURATION,
-	    device, on_set_configuration,
-	    handle_set_configuration(device, request->value,
-	        request->index, request->length));
-	
-	return ENOTSUP;
-}
-
-/**
- * @}
- */
Index: uspace/lib/usbvirt/transaction.c
===================================================================
--- uspace/lib/usbvirt/transaction.c	(revision 37f7cfe6ab80448fed991af05947b5c57080be0f)
+++ 	(revision )
@@ -1,269 +1,0 @@
-/*
- * Copyright (c) 2010 Vojtech Horky
- * 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 libusbvirt usb
- * @{
- */
-/** @file
- * @brief Transaction processing.
- */
-#include <errno.h>
-#include <stdlib.h>
-#include <mem.h>
-
-#include "hub.h"
-#include "private.h"
-
-static usb_direction_t setup_transaction_direction(usbvirt_device_t *,
-    usb_endpoint_t, void *, size_t);
-static void process_control_transfer(usbvirt_device_t *,
-    usb_endpoint_t, usbvirt_control_transfer_t *);
-
-/** Convert virtual USB transaction type to string.
- */
-const char *usbvirt_str_transaction_type(usbvirt_transaction_type_t type)
-{
-	switch (type) {
-		case USBVIRT_TRANSACTION_SETUP:
-			return "setup";
-		case USBVIRT_TRANSACTION_IN:
-			return "in";
-		case USBVIRT_TRANSACTION_OUT:
-			return "out";
-		default:
-			return "unknown";
-	}
-}
-
-/** SETUP transaction handling.
- * The setup transaction only prepares control transfer on given endpoint.
- */
-int transaction_setup(usbvirt_device_t *device, usb_endpoint_t endpoint,
-    void *buffer, size_t size)
-{
-	device->lib_debug(device, 1, USBVIRT_DEBUGTAG_TRANSACTION,
-	    "setup transaction: endpoint=%d, size=%u", endpoint, size);
-	
-	usbvirt_control_transfer_t *transfer = &device->current_control_transfers[endpoint];
-	
-	if (transfer->request != NULL) {
-		free(transfer->request);
-	}
-	if (transfer->data != NULL) {
-		free(transfer->data);
-	}
-	
-	transfer->direction = setup_transaction_direction(device, endpoint,
-	    buffer, size);
-	transfer->request = malloc(size);
-	memcpy(transfer->request, buffer, size);
-	transfer->request_size = size;
-	transfer->data = NULL;
-	transfer->data_size = 0;
-	
-	if (transfer->direction == USB_DIRECTION_IN) {
-		process_control_transfer(device, endpoint, transfer);
-	}
-	
-	return EOK;
-}
-
-/** OUT transaction handling.
- * The OUT transaction can trigger processing of a control transfer.
- */
-int transaction_out(usbvirt_device_t *device, usb_endpoint_t endpoint,
-    void *buffer, size_t size)
-{
-	device->lib_debug(device, 1, USBVIRT_DEBUGTAG_TRANSACTION,
-	    "out transaction: endpoint=%d, size=%u", endpoint, size);
-	
-	/*
-	 * First check whether it is a transaction over control pipe.
-	 */
-	usbvirt_control_transfer_t *transfer = &device->current_control_transfers[endpoint];
-	if (transfer->request != NULL) {
-		if (transfer->direction == USB_DIRECTION_OUT) {
-			/*
-			 * For out transactions, append the data to the buffer.
-			 */
-			uint8_t *new_buffer = (uint8_t *) malloc(transfer->data_size + size);
-			if (transfer->data) {
-				memcpy(new_buffer, transfer->data, transfer->data_size);
-			}
-			memcpy(new_buffer + transfer->data_size, buffer, size);
-			
-			if (transfer->data) {
-				free(transfer->data);
-			}
-			transfer->data = new_buffer;
-			transfer->data_size += size;
-		} else {
-			/*
-			 * For in transactions, this means end of the
-			 * transaction.
-			 */
-			free(transfer->request);
-			if (transfer->data) {
-				free(transfer->data);
-			}
-			transfer->request = NULL;
-			transfer->request_size = 0;
-			transfer->data = NULL;
-			transfer->data_size = 0;
-		}
-		
-		return EOK;
-	}
-	
-	/*
-	 * Otherwise, announce that some data has come.
-	 */
-	if (device->ops && device->ops->on_data) {
-		return device->ops->on_data(device, endpoint, buffer, size);
-	} else {
-		return ENOTSUP;
-	}
-}
-
-/** IN transaction handling.
- * The IN transaction can trigger processing of a control transfer.
- */
-int transaction_in(usbvirt_device_t *device, usb_endpoint_t endpoint,
-    void *buffer, size_t size, size_t *data_size)
-{
-	device->lib_debug(device, 1, USBVIRT_DEBUGTAG_TRANSACTION,
-	    "in transaction: endpoint=%d, size=%u", endpoint, size);
-	
-	/*
-	 * First check whether it is a transaction over control pipe.
-	 */
-	usbvirt_control_transfer_t *transfer = &device->current_control_transfers[endpoint];
-	if (transfer->request != NULL) {
-		if (transfer->direction == USB_DIRECTION_OUT) {
-			/*
-			 * This means end of input data.
-			 */
-			process_control_transfer(device, endpoint, transfer);
-		} else {
-			/*
-			 * For in transactions, this means sending next part
-			 * of the buffer.
-			 */
-			// FIXME: handle when the HC wants the data back
-			// in more chunks
-			size_t actual_size = 0;
-			if (transfer->data) {
-				actual_size = transfer->data_size;
-			}
-			if (actual_size > size) {
-				actual_size = size;
-			}
-			device->lib_debug(device, 1, USBVIRT_DEBUGTAG_TRANSACTION,
-			    "in transaction: will copy %zu bytes", actual_size);
-			if (actual_size > 0) {
-				memcpy(buffer, transfer->data, actual_size);
-				if (data_size) {
-					*data_size = actual_size;
-				}
-			}
-		}
-		
-		return EOK;
-	}
-	
-	if (size == 0) {
-		return EINVAL;
-	}
-	
-	int rc = 1;
-	
-	if (device->ops && device->ops->on_data_request) {
-		rc = device->ops->on_data_request(device, endpoint, buffer, size, data_size);
-	}
-	
-	return rc;
-}
-
-/** Determine direction of control transfer.
- * First, try the user provided callback, otherwise guess, believing that
- * it uses the same format as control pipe 0.
- */
-static usb_direction_t setup_transaction_direction(usbvirt_device_t *device,
-    usb_endpoint_t endpoint,
-    void *data, size_t size)
-{
-	int direction = -1;
-	if (device->ops && device->ops->decide_control_transfer_direction) {
-		direction = device->ops->decide_control_transfer_direction(endpoint,
-		    data, size);
-	}
-	
-	/*
-	 * If the user-supplied routine have not handled the direction
-	 * (or simply was not provided) we will guess, hoping that it 
-	 * uses same format as standard request on control pipe zero.
-	 */
-	if (direction < 0) {
-		if (size > 0) {
-			uint8_t *ptr = (uint8_t *) data;
-			if ((ptr[0] & 128) == 128) {
-				direction = USB_DIRECTION_IN;
-			} else {
-				direction = USB_DIRECTION_OUT;
-			}
-		} else {
-			/* This shall not happen anyway. */
-			direction = USB_DIRECTION_OUT;
-		}
-	}
-	
-	return (usb_direction_t) direction;
-}
-
-/** Process control transfer.
- */
-static void process_control_transfer(usbvirt_device_t *device,
-    usb_endpoint_t endpoint,
-    usbvirt_control_transfer_t *transfer)
-{
-	int rc = EFORWARD;
-	
-	if (device->ops && device->ops->on_control_transfer) {
-		rc = device->ops->on_control_transfer(device, endpoint, transfer);
-	}
-	
-	if (rc == EFORWARD) {
-		if (endpoint == 0) {
-			rc = control_pipe(device, transfer);
-		}
-	}
-}
-
-/**
- * @}
- */
