Index: uspace/Makefile
===================================================================
--- uspace/Makefile	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/Makefile	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -140,5 +140,4 @@
 	drv/bus/usb/ohci \
 	drv/bus/usb/uhci \
-	drv/bus/usb/uhcirh \
 	drv/bus/usb/usbflbk \
 	drv/bus/usb/usbhid \
Index: uspace/app/mkbd/main.c
===================================================================
--- uspace/app/mkbd/main.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/app/mkbd/main.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -44,5 +44,4 @@
 #include <devman.h>
 #include <loc.h>
-#include <usb/dev/hub.h>
 #include <usb/hid/iface.h>
 #include <usb/dev/pipes.h>
@@ -224,5 +223,5 @@
 	devman_handle_t dev_handle = 0;
 	
-	int rc = usb_resolve_device_handle(devpath, NULL, NULL, &dev_handle);
+	int rc = usb_resolve_device_handle(devpath, &dev_handle);
 	if (rc != EOK) {
 		printf("Device not found or not of USB kind: %s.\n",
Index: uspace/app/usbinfo/Makefile
===================================================================
--- uspace/app/usbinfo/Makefile	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/app/usbinfo/Makefile	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -43,5 +43,4 @@
 SOURCES = \
 	desctree.c \
-	dev.c \
 	dump.c \
 	hid.c \
Index: uspace/app/usbinfo/dev.c
===================================================================
--- uspace/app/usbinfo/dev.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ 	(revision )
@@ -1,131 +1,0 @@
-/*
- * Copyright (c) 2011 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 usbinfo
- * @{
- */
-/**
- * @file
- * Representation of queried device.
- */
-#include <usb/dev.h>
-#include <usb/hc.h>
-#include <errno.h>
-#include <str_error.h>
-#include <usb/dev/request.h>
-#include "usbinfo.h"
-
-usbinfo_device_t *prepare_device(const char *name,
-    devman_handle_t hc_handle, usb_address_t dev_addr)
-{
-	usbinfo_device_t *dev = malloc(sizeof(usbinfo_device_t));
-	if (dev == NULL) {
-		fprintf(stderr, NAME ": memory allocation failed.\n");
-		return NULL;
-	}
-
-	int rc;
-	bool transfer_started = false;
-
-	usb_hc_connection_initialize(&dev->hc_conn, hc_handle);
-
-	rc = usb_device_connection_initialize(
-	    &dev->wire, &dev->hc_conn, dev_addr);
-	if (rc != EOK) {
-		fprintf(stderr,
-		    NAME ": failed to create connection to device %s: %s.\n",
-		    name, str_error(rc));
-		goto leave;
-	}
-
-	rc = usb_pipe_initialize_default_control(&dev->ctrl_pipe,
-	    &dev->wire);
-	if (rc != EOK) {
-		fprintf(stderr,
-		    NAME ": failed to create default control pipe to %s: %s.\n",
-		    name, str_error(rc));
-		goto leave;
-	}
-
-	rc = usb_pipe_probe_default_control(&dev->ctrl_pipe);
-	if (rc != EOK) {
-		if (rc == ENOENT) {
-			fprintf(stderr, NAME ": " \
-			    "device %s not present or malfunctioning.\n",
-			    name);
-		} else {
-			fprintf(stderr, NAME ": " \
-			    "probing default control pipe of %s failed: %s.\n",
-			    name, str_error(rc));
-		}
-		goto leave;
-	}
-
-	usb_pipe_start_long_transfer(&dev->ctrl_pipe);
-	transfer_started = true;
-
-	rc = usb_request_get_device_descriptor(&dev->ctrl_pipe,
-	    &dev->device_descriptor);
-	if (rc != EOK) {
-		fprintf(stderr,
-		    NAME ": failed to retrieve device descriptor of %s: %s.\n",
-		    name, str_error(rc));
-		goto leave;
-	}
-
-	rc = usb_request_get_full_configuration_descriptor_alloc(
-	    &dev->ctrl_pipe, 0, (void **)&dev->full_configuration_descriptor,
-	    &dev->full_configuration_descriptor_size);
-	if (rc != EOK) {
-		fprintf(stderr, NAME ": " \
-		    "failed to retrieve configuration descriptor of %s: %s.\n",
-		    name, str_error(rc));
-		goto leave;
-	}
-
-	return dev;
-
-
-leave:
-	if (transfer_started) {
-		usb_pipe_end_long_transfer(&dev->ctrl_pipe);
-	}
-
-	free(dev);
-
-	return NULL;
-}
-
-void destroy_device(usbinfo_device_t *dev)
-{
-	usb_pipe_end_long_transfer(&dev->ctrl_pipe);
-	free(dev);
-}
-
-/** @}
- */
Index: uspace/app/usbinfo/hid.c
===================================================================
--- uspace/app/usbinfo/hid.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/app/usbinfo/hid.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -36,4 +36,5 @@
 #include <stdio.h>
 #include <str_error.h>
+#include <usb/debug.h>
 #include <usb/classes/classes.h>
 #include <usb/dev/request.h>
@@ -50,5 +51,5 @@
 
 typedef struct {
-	usbinfo_device_t *dev;
+	usb_device_t *usb_dev;
 	hid_dump_type_t dump_type;
 	usb_standard_interface_descriptor_t *last_iface;
@@ -211,33 +212,35 @@
 
 	retrieve_and_dump_hid_report(context->dump_type,
-	    &context->dev->ctrl_pipe, context->last_iface->interface_number,
-	    report_size);
-}
-
-
-void dump_hidreport_raw(usbinfo_device_t *dev)
+	    usb_device_get_default_pipe(context->usb_dev),
+	    context->last_iface->interface_number, report_size);
+}
+
+
+void dump_hidreport_raw(usb_device_t *usb_dev)
 {
 	descriptor_walk_context_t context = {
-		.dev = dev,
+		.usb_dev = usb_dev,
 		.dump_type = HID_DUMP_RAW,
 		.last_iface = NULL
 	};
 
-	usb_dp_walk_simple(dev->full_configuration_descriptor,
-	    dev->full_configuration_descriptor_size,
+	usb_dp_walk_simple(
+	    usb_device_descriptors(usb_dev)->full_config,
+	    usb_device_descriptors(usb_dev)->full_config_size,
 	    usb_dp_standard_descriptor_nesting,
 	    descriptor_walk_callback, &context);
 }
 
-void dump_hidreport_usages(usbinfo_device_t *dev)
+void dump_hidreport_usages(usb_device_t *usb_dev)
 {
 	descriptor_walk_context_t context = {
-		.dev = dev,
+		.usb_dev = usb_dev,
 		.dump_type = HID_DUMP_USAGES,
 		.last_iface = NULL
 	};
 
-	usb_dp_walk_simple(dev->full_configuration_descriptor,
-	    dev->full_configuration_descriptor_size,
+	usb_dp_walk_simple(
+	    usb_device_descriptors(usb_dev)->full_config,
+	    usb_device_descriptors(usb_dev)->full_config_size,
 	    usb_dp_standard_descriptor_nesting,
 	    descriptor_walk_callback, &context);
Index: uspace/app/usbinfo/info.c
===================================================================
--- uspace/app/usbinfo/info.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/app/usbinfo/info.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -37,4 +37,5 @@
 #include <str_error.h>
 #include <errno.h>
+#include <usb/debug.h>
 #include <usb/dev/pipes.h>
 #include <usb/dev/recognise.h>
@@ -44,9 +45,9 @@
 #include "usbinfo.h"
 
-void dump_short_device_identification(usbinfo_device_t *dev)
+void dump_short_device_identification(usb_device_t *usb_dev)
 {
 	printf("%sDevice 0x%04x by vendor 0x%04x\n", get_indent(0),
-	    (int) dev->device_descriptor.product_id,
-	    (int) dev->device_descriptor.vendor_id);
+	    usb_device_descriptors(usb_dev)->device.product_id,
+	    usb_device_descriptors(usb_dev)->device.vendor_id);
 }
 
@@ -66,5 +67,6 @@
 	}
 
-	usbinfo_device_t *dev = (usbinfo_device_t *) arg;
+	usb_device_t *usb_dev = arg;
+	assert(usb_dev);
 
 	usb_standard_interface_descriptor_t *iface
@@ -80,28 +82,28 @@
 	match_id_list_t matches;
 	init_match_ids(&matches);
-	usb_device_create_match_ids_from_interface(&dev->device_descriptor,
-	    iface, &matches);
+	usb_device_create_match_ids_from_interface(
+	    &usb_device_descriptors(usb_dev)->device, iface, &matches);
 	dump_match_ids(&matches, get_indent(1));
 	clean_match_ids(&matches);
 }
 
-void dump_device_match_ids(usbinfo_device_t *dev)
+void dump_device_match_ids(usb_device_t *usb_dev)
 {
 	match_id_list_t matches;
 	init_match_ids(&matches);
 	usb_device_create_match_ids_from_device_descriptor(
-	    &dev->device_descriptor, &matches);
+		&usb_device_descriptors(usb_dev)->device, &matches);
 	printf("%sDevice match ids (0x%04x by 0x%04x, %s)\n", get_indent(0),
-	    (int) dev->device_descriptor.product_id,
-	    (int) dev->device_descriptor.vendor_id,
-	    usb_str_class(dev->device_descriptor.device_class));
+	    usb_device_descriptors(usb_dev)->device.product_id,
+	    usb_device_descriptors(usb_dev)->device.vendor_id,
+	    usb_str_class(usb_device_descriptors(usb_dev)->device.device_class));
 	dump_match_ids(&matches, get_indent(1));
 	clean_match_ids(&matches);
 
-	usb_dp_walk_simple(dev->full_configuration_descriptor,
-	    dev->full_configuration_descriptor_size,
+	usb_dp_walk_simple(
+	    usb_device_descriptors(usb_dev)->full_config,
+	    usb_device_descriptors(usb_dev)->full_config_size,
 	    usb_dp_standard_descriptor_nesting,
-	    dump_match_ids_from_interface,
-	    dev);
+	    dump_match_ids_from_interface, usb_dev);
 }
 
@@ -224,24 +226,28 @@
 }
 
-void dump_descriptor_tree_brief(usbinfo_device_t *dev)
-{
-	dump_descriptor_tree_callback((uint8_t *)&dev->device_descriptor,
+void dump_descriptor_tree_brief(usb_device_t *usb_dev)
+{
+	dump_descriptor_tree_callback(
+	    (const uint8_t *)&usb_device_descriptors(usb_dev)->device,
 	    (size_t) -1, NULL);
-	usb_dp_walk_simple(dev->full_configuration_descriptor,
-	    dev->full_configuration_descriptor_size,
+
+	usb_dp_walk_simple(
+	    usb_device_descriptors(usb_dev)->full_config,
+	    usb_device_descriptors(usb_dev)->full_config_size,
 	    usb_dp_standard_descriptor_nesting,
-	    dump_descriptor_tree_callback,
-	    NULL);
-}
-
-void dump_descriptor_tree_full(usbinfo_device_t *dev)
-{
-	dump_descriptor_tree_callback((uint8_t *)&dev->device_descriptor,
-	    (size_t) -1, dev);
-	usb_dp_walk_simple(dev->full_configuration_descriptor,
-	    dev->full_configuration_descriptor_size,
+	    dump_descriptor_tree_callback, NULL);
+}
+
+void dump_descriptor_tree_full(usb_device_t *usb_dev)
+{
+	dump_descriptor_tree_callback(
+	    (const uint8_t *)&usb_device_descriptors(usb_dev)->device,
+	    (size_t) -1, usb_dev);
+
+	usb_dp_walk_simple(
+	    usb_device_descriptors(usb_dev)->full_config,
+	    usb_device_descriptors(usb_dev)->full_config_size,
 	    usb_dp_standard_descriptor_nesting,
-	    dump_descriptor_tree_callback,
-	    dev);
+	    dump_descriptor_tree_callback, usb_dev);
 }
 
@@ -285,15 +291,17 @@
 
 
-void dump_strings(usbinfo_device_t *dev)
+void dump_strings(usb_device_t *usb_dev)
 {
 	/* Find used indexes. Devices with more than 64 strings are very rare.*/
 	uint64_t str_mask = 0;
-	find_string_indexes_callback((uint8_t *)&dev->device_descriptor, 0,
+	find_string_indexes_callback(
+	    (const uint8_t *)&usb_device_descriptors(usb_dev)->device, 0,
 	    &str_mask);
-	usb_dp_walk_simple(dev->full_configuration_descriptor,
-	    dev->full_configuration_descriptor_size,
+
+	usb_dp_walk_simple(
+	    usb_device_descriptors(usb_dev)->full_config,
+	    usb_device_descriptors(usb_dev)->full_config_size,
 	    usb_dp_standard_descriptor_nesting,
-	    find_string_indexes_callback,
-	    &str_mask);
+	    find_string_indexes_callback, &str_mask);
 
 	if (str_mask == 0) {
@@ -305,6 +313,6 @@
 	l18_win_locales_t *langs;
 	size_t langs_count;
-	int rc = usb_request_get_supported_languages(&dev->ctrl_pipe,
-	    &langs, &langs_count);
+	int rc = usb_request_get_supported_languages(
+	    usb_device_get_default_pipe(usb_dev), &langs, &langs_count);
 	if (rc != EOK) {
 		fprintf(stderr,
@@ -334,5 +342,6 @@
 			}
 			char *string = NULL;
-			rc = usb_request_get_string(&dev->ctrl_pipe, idx, lang,
+			rc = usb_request_get_string(
+			    usb_device_get_default_pipe(usb_dev), idx, lang,
 			    &string);
 			if ((rc != EOK) && (rc != EEMPTY)) {
@@ -351,46 +360,36 @@
 
 
-void dump_status(usbinfo_device_t *dev)
+void dump_status(usb_device_t *usb_dev)
 {
 	int rc;
-	uint16_t device_status = 0;
-	uint16_t ctrl_pipe_status = 0;
+	uint16_t status = 0;
 
 	/* Device status first. */
-	rc = usb_request_get_status(&dev->ctrl_pipe,
-	    USB_REQUEST_RECIPIENT_DEVICE, 0,
-	    &device_status);
+	rc = usb_request_get_status(usb_device_get_default_pipe(usb_dev),
+	    USB_REQUEST_RECIPIENT_DEVICE, 0, &status);
 	if (rc != EOK) {
 		printf("%sFailed to get device status: %s.\n",
 		    get_indent(0), str_error(rc));
-		goto try_ctrl_pipe_status;
-	}
-
-	printf("%sDevice status 0x%04x: power=%s, remote-wakeup=%s.\n",
-	    get_indent(0),
-	    device_status,
-	    device_status & USB_DEVICE_STATUS_SELF_POWERED ? "self" : "bus",
-	    device_status & USB_DEVICE_STATUS_REMOTE_WAKEUP ? "yes" : "no");
+	} else {
+		printf("%sDevice status 0x%04x: power=%s, remote-wakeup=%s.\n",
+		    get_indent(0), status,
+		    status & USB_DEVICE_STATUS_SELF_POWERED ? "self" : "bus",
+		    status & USB_DEVICE_STATUS_REMOTE_WAKEUP ? "yes" : "no");
+	}
 
 	/* Interface is not interesting, skipping ;-). */
 
 	/* Control endpoint zero. */
-try_ctrl_pipe_status:
-	rc = usb_request_get_status(&dev->ctrl_pipe,
-	    USB_REQUEST_RECIPIENT_ENDPOINT, 0,
-	    &ctrl_pipe_status);
+	status = 0;
+	rc = usb_request_get_status(usb_device_get_default_pipe(usb_dev),
+	    USB_REQUEST_RECIPIENT_ENDPOINT, 0, &status);
 	if (rc != EOK) {
 		printf("%sFailed to get control endpoint status: %s.\n",
 		    get_indent(0), str_error(rc));
-		goto leave;
-	}
-
-	printf("%sControl endpoint zero status %04X: halted=%s.\n",
-	    get_indent(0),
-	    ctrl_pipe_status,
-	    ctrl_pipe_status & USB_ENDPOINT_STATUS_HALTED ? "yes" : "no");
-
-leave:
-	return;
+	} else {
+		printf("%sControl endpoint zero status %04X: halted=%s.\n",
+		    get_indent(0), status,
+		    status & USB_ENDPOINT_STATUS_HALTED ? "yes" : "no");
+	}
 }
 
Index: uspace/app/usbinfo/list.c
===================================================================
--- uspace/app/usbinfo/list.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/app/usbinfo/list.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -44,48 +44,86 @@
 #include <devman.h>
 #include <loc.h>
-#include <usb/dev/hub.h>
-#include <usb/hc.h>
+#include <usb_iface.h>
 
 #include "usbinfo.h"
 
-#define MAX_USB_ADDRESS USB11_ADDRESS_MAX
 #define MAX_PATH_LENGTH 1024
 
-static void print_found_hc(service_id_t sid, const char *path)
+static void print_usb_device(devman_handle_t handle)
 {
-	printf("Bus %" PRIun ": %s\n", sid, path);
-}
-static void print_found_dev(usb_address_t addr, const char *path)
-{
-	printf("  Device %02d: %s\n", addr, path);
+	char path[MAX_PATH_LENGTH];
+	int rc = devman_fun_get_path(handle, path, MAX_PATH_LENGTH);
+	if (rc != EOK) {
+		printf(NAME "Failed to get path for device %"PRIun"\n", handle);
+		return;
+	}
+	printf("\tDevice %" PRIun ": %s\n", handle, path);
 }
 
-static void print_hc_devices(devman_handle_t hc_handle)
+static void print_usb_bus(service_id_t svc)
 {
-	int rc;
-	usb_hc_connection_t conn;
-
-	usb_hc_connection_initialize(&conn, hc_handle);
-	rc = usb_hc_connection_open(&conn);
+	devman_handle_t hc_handle = 0;
+	int rc = devman_fun_sid_to_handle(svc, &hc_handle);
 	if (rc != EOK) {
-		printf(NAME ": failed to connect to HC: %s.\n",
-		    str_error(rc));
+		printf(NAME ": Error resolving handle of HC with SID %"
+		    PRIun ", skipping.\n", svc);
 		return;
 	}
-	usb_address_t addr;
-	for (addr = 1; addr < MAX_USB_ADDRESS; addr++) {
-		devman_handle_t dev_handle;
-		rc = usb_hc_get_handle_by_address(&conn, addr, &dev_handle);
-		if (rc != EOK) {
-			continue;
-		}
-		char path[MAX_PATH_LENGTH];
-		rc = devman_fun_get_path(dev_handle, path, MAX_PATH_LENGTH);
-		if (rc != EOK) {
-			continue;
-		}
-		print_found_dev(addr, path);
+
+	char path[MAX_PATH_LENGTH];
+	rc = devman_fun_get_path(hc_handle, path, sizeof(path));
+	if (rc != EOK) {
+		printf(NAME ": Error resolving path of HC with SID %"
+		    PRIun ", skipping.\n", svc);
+		return;
 	}
-	usb_hc_connection_close(&conn);
+	printf("Bus %" PRIun ": %s\n", svc, path);
+
+	/* Construct device's path.
+	 * That's "hc function path" - ( '/' + "hc function name" ) */
+	// TODO replace this with something sane
+
+	/* Get function name */
+	char name[10];
+	rc = devman_fun_get_name(hc_handle, name, sizeof(name));
+	if (rc != EOK) {
+		printf(NAME ": Error resolving name of HC with SID %"
+		    PRIun ", skipping.\n", svc);
+		return;
+	}
+
+	/* Get handle of parent device */
+	devman_handle_t fh;
+	path[str_size(path) - str_size(name) - 1] = '\0';
+	rc = devman_fun_get_handle(path, &fh, IPC_FLAG_BLOCKING);
+	if (rc != EOK) {
+		printf(NAME ": Error resolving parent handle of HC with"
+		    " SID %" PRIun ", skipping.\n", svc);
+		return;
+	}
+
+	/* Get child handle */
+	devman_handle_t dh;
+	rc = devman_fun_get_child(fh, &dh);
+	if (rc != EOK) {
+		printf(NAME ": Error resolving parent handle of HC with"
+		    " SID %" PRIun ", skipping.\n", svc);
+		return;
+	}
+	
+	devman_handle_t *fhs = 0;
+	size_t count;
+	rc = devman_dev_get_functions(dh, &fhs, &count);
+	if (rc != EOK) {
+		printf(NAME ": Error siblings of HC with"
+		    " SID %" PRIun ", skipping.\n", svc);
+		return;
+	}
+
+	for (size_t i = 0; i < count; ++i) {
+		if (fhs[i] != hc_handle)
+			print_usb_device(fhs[i]);
+	}
+	free(fhs);
 }
 
@@ -95,5 +133,4 @@
 	service_id_t *svcs;
 	size_t count;
-	size_t i;
 	int rc;
 
@@ -111,21 +148,6 @@
 	}
 
-	for (i = 0; i < count; i++) {
-		devman_handle_t hc_handle = 0;
-		int rc = usb_ddf_get_hc_handle_by_sid(svcs[i], &hc_handle);
-		if (rc != EOK) {
-			printf(NAME ": Error resolving handle of HC with SID %"
-			    PRIun ", skipping.\n", svcs[i]);
-			continue;
-		}
-		char path[MAX_PATH_LENGTH];
-		rc = devman_fun_get_path(hc_handle, path, MAX_PATH_LENGTH);
-		if (rc != EOK) {
-			printf(NAME ": Error resolving path of HC with SID %"
-			    PRIun ", skipping.\n", svcs[i]);
-			continue;
-		}
-		print_found_hc(svcs[i], path);
-		print_hc_devices(hc_handle);
+	for (unsigned i = 0; i < count; ++i) {
+		print_usb_bus(svcs[i]);
 	}
 
Index: uspace/app/usbinfo/main.c
===================================================================
--- uspace/app/usbinfo/main.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/app/usbinfo/main.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -198,8 +198,6 @@
 
 		/* The initialization is here only to make compiler happy. */
-		devman_handle_t hc_handle = 0;
-		usb_address_t dev_addr = 0;
-		int rc = usb_resolve_device_handle(devpath,
-		    &hc_handle, &dev_addr, NULL);
+		devman_handle_t handle = 0;
+		int rc = usb_resolve_device_handle(devpath, &handle);
 		if (rc != EOK) {
 			fprintf(stderr, NAME ": device `%s' not found "
@@ -209,7 +207,7 @@
 		}
 
-		usbinfo_device_t *dev = prepare_device(devpath,
-		    hc_handle, dev_addr);
-		if (dev == NULL) {
+		usb_device_t *usb_dev = usb_device_create(handle);
+
+		if (usb_dev == NULL) {
 			continue;
 		}
@@ -221,11 +219,10 @@
 		while (actions[action].opt != 0) {
 			if (actions[action].active) {
-				actions[action].action(dev);
+				actions[action].action(usb_dev);
 			}
 			action++;
 		}
 
-		/* Destroy the control pipe (close the session etc.). */
-		destroy_device(dev);
+		usb_device_destroy(usb_dev);
 	}
 
Index: uspace/app/usbinfo/usbinfo.h
===================================================================
--- uspace/app/usbinfo/usbinfo.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/app/usbinfo/usbinfo.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -38,21 +38,11 @@
 #include <usb/usb.h>
 #include <usb/descriptor.h>
-#include <usb/dev/pipes.h>
-#include <usb/debug.h>
+#include <usb/dev/device.h>
 #include <usb/dev/dp.h>
 #include <ipc/devman.h>
 
 typedef struct {
-	usb_hc_connection_t hc_conn;
-	usb_device_connection_t wire;
-	usb_pipe_t ctrl_pipe;
-	usb_standard_device_descriptor_t device_descriptor;
-	uint8_t *full_configuration_descriptor;
-	size_t full_configuration_descriptor_size;
-} usbinfo_device_t;
-
-typedef struct {
 	int opt;
-	void (*action)(usbinfo_device_t *dev);
+	void (*action)(usb_device_t *usb_dev);
 	bool active;
 } usbinfo_action_t;
@@ -72,7 +62,4 @@
 }
 
-usbinfo_device_t *prepare_device(const char *, devman_handle_t, usb_address_t);
-void destroy_device(usbinfo_device_t *);
-
 typedef void (*dump_descriptor_in_tree_t)(const uint8_t *, size_t, void *);
 void browse_descriptor_tree(uint8_t *, size_t, usb_dp_descriptor_nesting_t *,
@@ -81,13 +68,12 @@
 void list(void);
 
-void dump_short_device_identification(usbinfo_device_t *);
-void dump_device_match_ids(usbinfo_device_t *);
-void dump_descriptor_tree_brief(usbinfo_device_t *);
-void dump_descriptor_tree_full(usbinfo_device_t *);
-void dump_strings(usbinfo_device_t *);
-void dump_status(usbinfo_device_t *);
-void dump_hidreport_raw(usbinfo_device_t *);
-void dump_hidreport_usages(usbinfo_device_t *);
-
+void dump_short_device_identification(usb_device_t *);
+void dump_device_match_ids(usb_device_t *);
+void dump_descriptor_tree_brief(usb_device_t *);
+void dump_descriptor_tree_full(usb_device_t *);
+void dump_strings(usb_device_t *);
+void dump_status(usb_device_t *);
+void dump_hidreport_raw(usb_device_t *);
+void dump_hidreport_usages(usb_device_t *);
 
 #endif
Index: uspace/app/vuhid/device.c
===================================================================
--- uspace/app/vuhid/device.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/app/vuhid/device.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -60,5 +60,5 @@
 static int on_data_to_device(usbvirt_device_t *dev,
     usb_endpoint_t ep, usb_transfer_type_t tr_type,
-    void *data, size_t data_size)
+    const void *data, size_t data_size)
 {
 	vuhid_data_t *vuhid = dev->device_data;
@@ -254,7 +254,6 @@
 
 	/* Extend existing extra descriptors with these ones. */
-	usbvirt_device_configuration_extras_t *extra_descriptors
-	    = dev->descriptors->configuration->extra;
-	extra_descriptors = realloc(extra_descriptors,
+	usbvirt_device_configuration_extras_t *extra_descriptors;
+	extra_descriptors = realloc(dev->descriptors->configuration->extra,
 	    sizeof(usbvirt_device_configuration_extras_t)
 	    * (dev->descriptors->configuration->extra_count + descr_count));
Index: uspace/app/vuhid/hids/bootkbd.c
===================================================================
--- uspace/app/vuhid/hids/bootkbd.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/app/vuhid/hids/bootkbd.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -102,5 +102,5 @@
 
 static int on_data_out(vuhid_interface_t *iface,
-    void *buffer, size_t buffer_size)
+    const void *buffer, size_t buffer_size)
 {
 	if (buffer_size == 0) {
Index: uspace/app/vuhid/main.c
===================================================================
--- uspace/app/vuhid/main.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/app/vuhid/main.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -40,4 +40,5 @@
 #include <errno.h>
 #include <str_error.h>
+#include <getopt.h>
 
 #include <usb/usb.h>
@@ -52,26 +53,19 @@
 #include "stdreq.h"
 
+#define DEFAULT_CONTROLLER   "/virt/usbhc/ctl"
+
 static usbvirt_control_request_handler_t endpoint_zero_handlers[] = {
 	{
-		.req_direction = USB_DIRECTION_IN,
-		.req_type = USB_REQUEST_TYPE_STANDARD,
-		.req_recipient = USB_REQUEST_RECIPIENT_INTERFACE,
-		.request = USB_DEVREQ_GET_DESCRIPTOR,
+		STD_REQ_IN(USB_REQUEST_RECIPIENT_INTERFACE, USB_DEVREQ_GET_DESCRIPTOR),
 		.name = "Get_Descriptor",
 		.callback = req_get_descriptor
 	},
 	{
-		.req_direction = USB_DIRECTION_OUT,
-		.req_recipient = USB_REQUEST_RECIPIENT_INTERFACE,
-		.req_type = USB_REQUEST_TYPE_CLASS,
-		.request = USB_HIDREQ_SET_PROTOCOL,
+		CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_INTERFACE, USB_HIDREQ_SET_PROTOCOL),
 		.name = "Set_Protocol",
 		.callback = req_set_protocol
 	},
 	{
-		.req_direction = USB_DIRECTION_OUT,
-		.req_recipient = USB_REQUEST_RECIPIENT_INTERFACE,
-		.req_type = USB_REQUEST_TYPE_CLASS,
-		.request = USB_HIDREQ_SET_REPORT,
+		CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_INTERFACE, USB_HIDREQ_SET_REPORT),
 		.name = "Set_Report",
 		.callback = req_set_report
@@ -151,7 +145,68 @@
 
 
+static struct option long_options[] = {
+	{"help", optional_argument, NULL, 'h'},
+	{"controller", required_argument, NULL, 'c' },
+	{"list", no_argument, NULL, 'l' },
+	{0, 0, NULL, 0}
+};
+static const char *short_options = "hc:l";
+
+static void print_help(const char* name, const char* module)
+{
+	if (module == NULL) {
+		/* Default help */
+		printf("Usage: %s [options] device.\n", name);
+		printf("\t-h, --help [device]\n");
+		printf("\t\to With no argument print this help and exit.\n");
+		printf("\t\to With argument print device specific help and exit.\n");
+		printf("\t-l, --list \n\t\tPrint list of available devices.\n");
+		printf("\t-c, --controller \n\t\t"
+		    "Use provided virtual hc instead of default (%s)\n",
+		    DEFAULT_CONTROLLER);
+		return;
+	}
+	printf("HELP for module %s\n", module);
+}
+
+static void print_list(void)
+{
+	printf("Available devices:\n");
+	for (vuhid_interface_t **i = available_hid_interfaces; *i != NULL; ++i)
+	{
+		printf("\t`%s'\t%s\n", (*i)->id, (*i)->name);
+	}
+
+}
+
+static const char *controller = DEFAULT_CONTROLLER;
+
 int main(int argc, char * argv[])
 {
-	int rc;
+
+	if (argc == 1) {
+		print_help(*argv, NULL);
+		return 0;
+	}
+
+	int opt = 0;
+	while ((opt = getopt_long(argc, argv, short_options, long_options, NULL)) > 0) {
+		switch (opt)
+		{
+		case 'h':
+			print_help(*argv, optarg);
+			return 0;
+		case 'c':
+			controller = optarg;
+			break;
+		case 'l':
+			print_list();
+			return 0;
+		case -1:
+		default:
+			break;
+		}
+	}
+
 
 	log_init("vuhid");
@@ -161,7 +216,6 @@
 
 	/* Determine which interfaces to initialize. */
-	int i;
-	for (i = 1; i < argc; i++) {
-		rc = add_interface_by_id(available_hid_interfaces, argv[i],
+	for (int i = optind; i < argc; i++) {
+		int rc = add_interface_by_id(available_hid_interfaces, argv[i],
 		    &hid_dev);
 		if (rc != EOK) {
@@ -173,5 +227,5 @@
 	}
 
-	for (i = 0; i < (int) hid_dev.descriptors->configuration->extra_count; i++) {
+	for (int i = 0; i < (int) hid_dev.descriptors->configuration->extra_count; i++) {
 		usb_log_debug("Found extra descriptor: %s.\n",
 		    usb_debug_str_buffer(
@@ -181,12 +235,12 @@
 	}
 
-	rc = usbvirt_device_plug(&hid_dev, "/virt/usbhc/hc");
+	const int rc = usbvirt_device_plug(&hid_dev, controller);
 	if (rc != EOK) {
-		printf("Unable to start communication with VHCD: %s.\n",
-		    str_error(rc));
+		printf("Unable to start communication with VHCD `%s': %s.\n",
+		    controller, str_error(rc));
 		return rc;
 	}
 	
-	printf("Connected to VHCD...\n");
+	printf("Connected to VHCD `%s'...\n", controller);
 
 	wait_for_interfaces_death(&hid_dev);
Index: uspace/app/vuhid/virthid.h
===================================================================
--- uspace/app/vuhid/virthid.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/app/vuhid/virthid.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -71,5 +71,5 @@
 
 	int (*on_data_in)(vuhid_interface_t *, void *, size_t, size_t *);
-	int (*on_data_out)(vuhid_interface_t *, void *, size_t);
+	int (*on_data_out)(vuhid_interface_t *, const void *, size_t);
 	void (*live)(vuhid_interface_t *);
 
Index: uspace/doc/doxygroups.h
===================================================================
--- uspace/doc/doxygroups.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/doc/doxygroups.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -285,16 +285,4 @@
 	 */
 
-		/**
-		 * @defgroup drvusbuhcirh UHCI root hub driver
-		 * @ingroup drvusbuhci
-		 * @brief Driver for UHCI complaint root hub.
-		 */
-
-		/**
-		 * @defgroup drvusbuhcihc UHCI host controller driver
-		 * @ingroup drvusbuhci
-		 * @brief Driver for UHCI complaint USB host controller.
-		 */
-
 	/**
 	 * @defgroup drvusbohci OHCI driver
Index: uspace/drv/bus/usb/ehci/main.c
===================================================================
--- uspace/drv/bus/usb/ehci/main.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/ehci/main.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -33,16 +33,13 @@
  * Main routines of EHCI driver.
  */
-
 #include <ddf/driver.h>
 #include <ddf/interrupt.h>
 #include <device/hw_res.h>
 #include <errno.h>
-#include <stdbool.h>
 #include <str_error.h>
 
 #include <usb_iface.h>
-#include <usb/ddfiface.h>
 #include <usb/debug.h>
-#include <usb/host/hcd.h>
+#include <usb/host/ddf_helpers.h>
 
 #include "res.h"
@@ -60,7 +57,4 @@
 	.driver_ops = &ehci_driver_ops
 };
-static ddf_dev_ops_t hc_ops = {
-	.interfaces[USBHC_DEV_IFACE] = &hcd_iface,
-};
 
 
@@ -72,7 +66,4 @@
 static int ehci_dev_add(ddf_dev_t *device)
 {
-	ddf_fun_t *hc_fun = NULL;
-	bool fun_bound = false;
-
 	assert(device);
 
@@ -80,9 +71,9 @@
 	int irq = 0;
 
-	int rc = get_my_registers(device, &reg_range, &irq);
-	if (rc != EOK) {
+	int ret = get_my_registers(device, &reg_range, &irq);
+	if (ret != EOK) {
 		usb_log_error("Failed to get memory addresses for %" PRIun
-		    ": %s.\n", ddf_dev_get_handle(device), str_error(rc));
-		goto error;
+		    ": %s.\n", ddf_dev_get_handle(device), str_error(ret));
+		return ret;
 	}
 
@@ -90,43 +81,17 @@
 	    RNGABSPTR(reg_range), RNGSZ(reg_range), irq);
 
-	rc = disable_legacy(device, &reg_range);
-	if (rc != EOK) {
+	ret = disable_legacy(device, &reg_range);
+	if (ret != EOK) {
 		usb_log_error("Failed to disable legacy USB: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	hc_fun = ddf_fun_create(device, fun_exposed, "ehci_hc");
-	if (hc_fun == NULL) {
-		usb_log_error("Failed to create EHCI function.\n");
-		rc = ENOMEM;
-		goto error;
-	}
-
-	hcd_t *ehci_hc = ddf_fun_data_alloc(hc_fun, sizeof(hcd_t));
-	if (ehci_hc == NULL) {
-		usb_log_error("Failed to alloc generic HC driver.\n");
-		rc = ENOMEM;
-		goto error;
+		    str_error(ret));
+		return ret;
 	}
 
 	/* High Speed, no bandwidth */
-	hcd_init(ehci_hc, USB_SPEED_HIGH, 0, NULL);
-	ddf_fun_set_ops(hc_fun,  &hc_ops);
-
-	rc = ddf_fun_bind(hc_fun);
-	if (rc != EOK) {
-		usb_log_error("Failed to bind EHCI function: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	fun_bound = true;
-
-	rc = ddf_fun_add_to_category(hc_fun, USB_HC_CATEGORY);
-	if (rc != EOK) {
-		usb_log_error("Failed to add EHCI to HC class: %s.\n",
-		    str_error(rc));
-		goto error;
+	ret = hcd_ddf_setup_hc(device, USB_SPEED_HIGH, 0, NULL);
+	if (ret != EOK) {
+		usb_log_error("Failed to init generci hcd driver: %s\n",
+		    str_error(ret));
+		return ret;
 	}
 
@@ -135,10 +100,4 @@
 
 	return EOK;
-error:
-	if (fun_bound)
-		ddf_fun_unbind(hc_fun);
-	if (hc_fun != NULL)
-		ddf_fun_destroy(hc_fun);
-	return rc;
 }
 
Index: uspace/drv/bus/usb/ehci/res.c
===================================================================
--- uspace/drv/bus/usb/ehci/res.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/ehci/res.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -142,14 +142,17 @@
 		return ENOMEM;
 
+#define CHECK_RET_HANGUP_RETURN(ret, message...) \
+	if (ret != EOK) { \
+		usb_log_error(message); \
+		async_hangup(parent_sess); \
+		return ret; \
+	} else (void)0
+
 	/* Read the first EEC. i.e. Legacy Support register */
 	uint32_t usblegsup;
-	int rc = pci_config_space_read_32(parent_sess,
+	int ret = pci_config_space_read_32(parent_sess,
 	    eecp + USBLEGSUP_OFFSET, &usblegsup);
-	if (rc != EOK) {
-		usb_log_error("Failed to read USBLEGSUP: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
+	CHECK_RET_HANGUP_RETURN(ret,
+	    "Failed to read USBLEGSUP: %s.\n", str_error(ret));
 	usb_log_debug("USBLEGSUP: %" PRIx32 ".\n", usblegsup);
 
@@ -157,31 +160,17 @@
 	 * byte. (OS Control semaphore)*/
 	usb_log_debug("Requesting OS control.\n");
-	rc = pci_config_space_write_8(parent_sess,
+	ret = pci_config_space_write_8(parent_sess,
 	    eecp + USBLEGSUP_OFFSET + 3, 1);
-	if (rc != EOK) {
-		usb_log_error("Failed to request OS EHCI control: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
+	CHECK_RET_HANGUP_RETURN(ret, "Failed to request OS EHCI control: %s.\n",
+	    str_error(ret));
 
 	size_t wait = 0;
 	/* Wait for BIOS to release control. */
-	rc = pci_config_space_read_32(
+	ret = pci_config_space_read_32(
 	    parent_sess, eecp + USBLEGSUP_OFFSET, &usblegsup);
-	if (rc != EOK) {
-		usb_log_error("Failed reading PCI config space: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
 	while ((wait < DEFAULT_WAIT) && (usblegsup & USBLEGSUP_BIOS_CONTROL)) {
 		async_usleep(WAIT_STEP);
-		rc = pci_config_space_read_32(parent_sess,
+		ret = pci_config_space_read_32(parent_sess,
 		    eecp + USBLEGSUP_OFFSET, &usblegsup);
-		if (rc != EOK) {
-			usb_log_error("Failed reading PCI config space: %s.\n",
-			    str_error(rc));
-			goto error;
-		}
 		wait += WAIT_STEP;
 	}
@@ -196,12 +185,8 @@
 	usb_log_warning( "BIOS failed to release control after "
 	    "%zu usecs, force it.\n", wait);
-	rc = pci_config_space_write_32(parent_sess,
+	ret = pci_config_space_write_32(parent_sess,
 	    eecp + USBLEGSUP_OFFSET, USBLEGSUP_OS_CONTROL);
-	if (rc != EOK) {
-		usb_log_error("Failed to force OS control: "
-		    "%s.\n", str_error(rc));
-		goto error;
-	}
-
+	CHECK_RET_HANGUP_RETURN(ret, "Failed to force OS control: "
+	    "%s.\n", str_error(ret));
 	/*
 	 * Check capability type here, value of 01h identifies the capability
@@ -213,12 +198,8 @@
 		/* Read the second EEC Legacy Support and Control register */
 		uint32_t usblegctlsts;
-		rc = pci_config_space_read_32(parent_sess,
+		ret = pci_config_space_read_32(parent_sess,
 		    eecp + USBLEGCTLSTS_OFFSET, &usblegctlsts);
-		if (rc != EOK) {
-			usb_log_error("Failed to get USBLEGCTLSTS: %s.\n",
-			    str_error(rc));
-			goto error;
-		}
-
+		CHECK_RET_HANGUP_RETURN(ret, "Failed to get USBLEGCTLSTS: %s.\n",
+		    str_error(ret));
 		usb_log_debug("USBLEGCTLSTS: %" PRIx32 ".\n", usblegctlsts);
 		/*
@@ -227,20 +208,12 @@
 		 * interfering. NOTE: Three upper bits are WC
 		 */
-		rc = pci_config_space_write_32(parent_sess,
+		ret = pci_config_space_write_32(parent_sess,
 		    eecp + USBLEGCTLSTS_OFFSET, 0xe0000000);
-		if (rc != EOK) {
-			usb_log_error("Failed(%d) zero USBLEGCTLSTS.\n", rc);
-			goto error;
-		}
-
+		CHECK_RET_HANGUP_RETURN(ret, "Failed(%d) zero USBLEGCTLSTS.\n", ret);
 		udelay(10);
-		rc = pci_config_space_read_32(parent_sess,
+		ret = pci_config_space_read_32(parent_sess,
 		    eecp + USBLEGCTLSTS_OFFSET, &usblegctlsts);
-		if (rc != EOK) {
-			usb_log_error("Failed to get USBLEGCTLSTS 2: %s.\n",
-			    str_error(rc));
-			goto error;
-		}
-
+		CHECK_RET_HANGUP_RETURN(ret, "Failed to get USBLEGCTLSTS 2: %s.\n",
+		    str_error(ret));
 		usb_log_debug("Zeroed USBLEGCTLSTS: %" PRIx32 ".\n",
 		    usblegctlsts);
@@ -248,18 +221,12 @@
 
 	/* Read again Legacy Support register */
-	rc = pci_config_space_read_32(parent_sess,
+	ret = pci_config_space_read_32(parent_sess,
 	    eecp + USBLEGSUP_OFFSET, &usblegsup);
-	if (rc != EOK) {
-		usb_log_error("Failed to read USBLEGSUP: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
+	CHECK_RET_HANGUP_RETURN(ret, "Failed to read USBLEGSUP: %s.\n",
+	    str_error(ret));
 	usb_log_debug("USBLEGSUP: %" PRIx32 ".\n", usblegsup);
 	async_hangup(parent_sess);
 	return EOK;
-error:
-	async_hangup(parent_sess);
-	return rc;
+#undef CHECK_RET_HANGUP_RETURN
 }
 
@@ -271,9 +238,9 @@
 	/* Map EHCI registers */
 	void *regs = NULL;
-	int rc = pio_enable_range(reg_range, &regs);
-	if (rc != EOK) {
+	int ret = pio_enable_range(reg_range, &regs);
+	if (ret != EOK) {
 		usb_log_error("Failed to map registers %p: %s.\n",
-		    RNGABSPTR(*reg_range), str_error(rc));
-		return rc;
+		    RNGABSPTR(*reg_range), str_error(ret));
+		return ret;
 	}
 
@@ -290,10 +257,11 @@
 	usb_log_debug("Value of EECP: %x.\n", eecp);
 
-	rc = disable_extended_caps(device, eecp);
-	if (rc != EOK) {
+	ret = disable_extended_caps(device, eecp);
+	if (ret != EOK) {
 		usb_log_error("Failed to disable extended capabilities: %s.\n",
-		    str_error(rc));
-		return rc;
-	}
+		    str_error(ret));
+		return ret;
+	}
+
 
 	/*
@@ -334,5 +302,5 @@
 	    usbcmd, *usbcmd, usbsts, *usbsts, usbint, *usbint, usbconf,*usbconf);
 
-	return rc;
+	return ret;
 }
 
Index: uspace/drv/bus/usb/ohci/Makefile
===================================================================
--- uspace/drv/bus/usb/ohci/Makefile	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/ohci/Makefile	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -31,5 +31,5 @@
 LIBS = \
 	$(LIBUSBHOST_PREFIX)/libusbhost.a \
-	$(LIBUSBDEV_PREFIX)/libusbdev.a \
+	$(LIBUSBVIRT_PREFIX)/libusbvirt.a \
 	$(LIBUSB_PREFIX)/libusb.a \
 	$(LIBDRV_PREFIX)/libdrv.a
@@ -39,4 +39,5 @@
 	-I$(LIBUSBDEV_PREFIX)/include \
 	-I$(LIBUSBHOST_PREFIX)/include \
+	-I$(LIBUSBVIRT_PREFIX)/include \
 	-I$(LIBDRV_PREFIX)/include
 
@@ -50,6 +51,6 @@
 	ohci_batch.c \
 	ohci_endpoint.c \
+	ohci_rh.c \
 	res.c \
-	root_hub.c \
 	hw_struct/endpoint_descriptor.c \
 	hw_struct/transfer_descriptor.c
Index: uspace/drv/bus/usb/ohci/hc.c
===================================================================
--- uspace/drv/bus/usb/ohci/hc.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/ohci/hc.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -35,5 +35,4 @@
 
 #include <errno.h>
-#include <stdbool.h>
 #include <str_error.h>
 #include <adt/list.h>
@@ -42,5 +41,4 @@
 #include <usb/debug.h>
 #include <usb/usb.h>
-#include <usb/ddfiface.h>
 
 #include "hc.h"
@@ -84,14 +82,4 @@
 };
 
-enum {
-	/** Number of PIO ranges used in IRQ code */
-	hc_irq_pio_range_count = 
-	    sizeof(ohci_pio_ranges) / sizeof(irq_pio_range_t),
-
-	/** Number of commands used in IRQ code */
-	hc_irq_cmd_count =
-	    sizeof(ohci_irq_commands) / sizeof(irq_cmd_t)
-};
-
 static void hc_gain_control(hc_t *instance);
 static void hc_start(hc_t *instance);
@@ -99,5 +87,20 @@
 static int hc_init_memory(hc_t *instance);
 static int interrupt_emulator(hc_t *instance);
-static int hc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch);
+
+/** Get number of PIO ranges used in IRQ code.
+ * @return Number of ranges.
+ */
+size_t hc_irq_pio_range_count(void)
+{
+	return sizeof(ohci_pio_ranges) / sizeof(irq_pio_range_t);
+}
+
+/** Get number of commands used in IRQ code.
+ * @return Number of commands.
+ */
+size_t hc_irq_cmd_count(void)
+{
+	return sizeof(ohci_irq_commands) / sizeof(irq_cmd_t);
+}
 
 /** Generate IRQ code.
@@ -145,11 +148,11 @@
 	int rc;
 
-	irq_pio_range_t irq_ranges[hc_irq_pio_range_count];
-	irq_cmd_t irq_cmds[hc_irq_cmd_count];
+	irq_pio_range_t irq_ranges[hc_irq_pio_range_count()];
+	irq_cmd_t irq_cmds[hc_irq_cmd_count()];
 
 	irq_code_t irq_code = {
-		.rangecount = hc_irq_pio_range_count,
+		.rangecount = hc_irq_pio_range_count(),
 		.ranges = irq_ranges,
-		.cmdcount = hc_irq_cmd_count,
+		.cmdcount = hc_irq_cmd_count(),
 		.cmds = irq_cmds
 	};
@@ -174,84 +177,4 @@
 }
 
-/** Announce OHCI root hub to the DDF
- *
- * @param[in] instance OHCI driver intance
- * @param[in] hub_fun DDF fuction representing OHCI root hub
- * @return Error code
- */
-int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun)
-{
-	bool addr_reqd = false;
-	bool ep_added = false;
-	bool fun_bound = false;
-	int rc;
-
-	assert(instance);
-	assert(hub_fun);
-
-	/* Try to get address 1 for root hub. */
-	instance->rh.address = 1;
-	rc = usb_device_manager_request_address(
-	    &instance->generic.dev_manager, &instance->rh.address, false,
-	    USB_SPEED_FULL);
-	if (rc != EOK) {
-		usb_log_error("Failed to get OHCI root hub address: %s\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	addr_reqd = true;
-
-	rc = usb_endpoint_manager_add_ep(
-	    &instance->generic.ep_manager, instance->rh.address, 0,
-	    USB_DIRECTION_BOTH, USB_TRANSFER_CONTROL, USB_SPEED_FULL, 64,
-	    0, NULL, NULL);
-	if (rc != EOK) {
-    	        usb_log_error("Failed to register root hub control endpoint: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	ep_added = true;
-
-	rc = ddf_fun_add_match_id(hub_fun, "usb&class=hub", 100);
-	if (rc != EOK) {
-		usb_log_error("Failed to add root hub match-id: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	rc = ddf_fun_bind(hub_fun);
-	if (rc != EOK) {
-		usb_log_error("Failed to bind root hub function: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	fun_bound = true;
-
-	rc = usb_device_manager_bind_address(&instance->generic.dev_manager,
-	    instance->rh.address, ddf_fun_get_handle(hub_fun));
-	if (rc != EOK) {
-		usb_log_warning("Failed to bind root hub address: %s.\n",
-		    str_error(rc));
-	}
-
-	return EOK;
-error:
-	if (fun_bound)
-		ddf_fun_unbind(hub_fun);
-	if (ep_added) {
-		usb_endpoint_manager_remove_ep(
-		    &instance->generic.ep_manager, instance->rh.address, 0,
-		    USB_DIRECTION_BOTH, NULL, NULL);
-	}
-	if (addr_reqd) {
-		usb_device_manager_release_address(
-		    &instance->generic.dev_manager, instance->rh.address);
-	}
-	return rc;
-}
-
 /** Initialize OHCI hc driver structure
  *
@@ -265,28 +188,20 @@
 	assert(instance);
 
-	int rc = pio_enable_range(regs, (void **) &instance->registers);
-	if (rc != EOK) {
+	int ret = pio_enable_range(regs, (void **) &instance->registers);
+	if (ret != EOK) {
 		usb_log_error("Failed to gain access to device registers: %s.\n",
-		    str_error(rc));
-		return rc;
+		    str_error(ret));
+		return ret;
 	}
 
 	list_initialize(&instance->pending_batches);
-
-	hcd_init(&instance->generic, USB_SPEED_FULL,
-	    BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11);
-	instance->generic.private_data = instance;
-	instance->generic.schedule = hc_schedule;
-	instance->generic.ep_add_hook = ohci_endpoint_init;
-	instance->generic.ep_remove_hook = ohci_endpoint_fini;
-
-	rc = hc_init_memory(instance);
-	if (rc != EOK) {
+	fibril_mutex_initialize(&instance->guard);
+
+	ret = hc_init_memory(instance);
+	if (ret != EOK) {
 		usb_log_error("Failed to create OHCI memory structures: %s.\n",
-		    str_error(rc));
-		return rc;
-	}
-
-	fibril_mutex_initialize(&instance->guard);
+		    str_error(ret));
+		return ret;
+	}
 
 	hc_gain_control(instance);
@@ -298,5 +213,5 @@
 	}
 
-	rh_init(&instance->rh, instance->registers);
+	ohci_rh_init(&instance->rh, instance->registers, "ohci rh");
 	hc_start(instance);
 
@@ -385,8 +300,7 @@
 
 	/* Check for root hub communication */
-	if (batch->ep->address == instance->rh.address) {
+	if (batch->ep->address == ohci_rh_get_address(&instance->rh)) {
 		usb_log_debug("OHCI root hub request.\n");
-		rh_request(&instance->rh, batch);
-		return EOK;
+		return ohci_rh_schedule(&instance->rh, batch);
 	}
 	ohci_transfer_batch_t *ohci_batch = ohci_transfer_batch_get(batch);
@@ -427,5 +341,5 @@
 	usb_log_debug2("OHCI(%p) interrupt: %x.\n", instance, status);
 	if (status & I_RHSC)
-		rh_interrupt(&instance->rh);
+		ohci_rh_interrupt(&instance->rh);
 
 	if (status & I_WDH) {
@@ -625,5 +539,5 @@
 do { \
 	const char *name = usb_str_transfer_type(type); \
-	int ret = endpoint_list_init(&instance->lists[type], name); \
+	const int ret = endpoint_list_init(&instance->lists[type], name); \
 	if (ret != EOK) { \
 		usb_log_error("Failed to setup %s endpoint list: %s.\n", \
Index: uspace/drv/bus/usb/ohci/hc.h
===================================================================
--- uspace/drv/bus/usb/ohci/hc.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/ohci/hc.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -35,9 +35,9 @@
 #define DRV_OHCI_HC_H
 
-#include <ddf/interrupt.h>
 #include <fibril.h>
 #include <fibril_synch.h>
 #include <adt/list.h>
 #include <ddi.h>
+#include <ddf/interrupt.h>
 
 #include <usb/usb.h>
@@ -46,5 +46,5 @@
 #include "ohci_batch.h"
 #include "ohci_regs.h"
-#include "root_hub.h"
+#include "ohci_rh.h"
 #include "endpoint_list.h"
 #include "hw_struct/hcca.h"
@@ -52,7 +52,4 @@
 /** Main OHCI driver structure */
 typedef struct hc {
-	/** Generic USB hc driver */
-	hcd_t generic;
-
 	/** Memory mapped I/O registers area */
 	ohci_regs_t *registers;
@@ -72,7 +69,9 @@
 
 	/** USB hub emulation structure */
-	rh_t rh;
+	ohci_rh_t rh;
 } hc_t;
 
+size_t hc_irq_pio_range_count(void);
+size_t hc_irq_cmd_count(void);
 int hc_get_irq_code(irq_pio_range_t [], size_t, irq_cmd_t [], size_t,
     addr_range_t *);
@@ -90,4 +89,5 @@
 void hc_enqueue_endpoint(hc_t *instance, const endpoint_t *ep);
 void hc_dequeue_endpoint(hc_t *instance, const endpoint_t *ep);
+int hc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch);
 
 void hc_interrupt(hc_t *instance, uint32_t status);
Index: uspace/drv/bus/usb/ohci/hw_struct/endpoint_descriptor.c
===================================================================
--- uspace/drv/bus/usb/ohci/hw_struct/endpoint_descriptor.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/ohci/hw_struct/endpoint_descriptor.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -33,4 +33,5 @@
  */
 #include "endpoint_descriptor.h"
+#include "macros.h"
 
 /** USB direction to OHCI values translation table. */
@@ -61,6 +62,8 @@
 		return;
 	}
-	/* Non-dummy ED must have TD assigned */
+	/* Non-dummy ED must have corresponding EP and TD assigned */
 	assert(td);
+	assert(ep);
+	assert(ep->direction < ARRAY_SIZE(dir));
 
 	/* Status: address, endpoint nr, direction mask and max packet size. */
@@ -77,4 +80,5 @@
 
 	/* Isochronous format flag */
+	// TODO: We need iTD instead of TD for iso transfers
 	if (ep->transfer_type == USB_TRANSFER_ISOCHRONOUS)
 		OHCI_MEM32_SET(instance->status, ED_STATUS_F_FLAG);
Index: uspace/drv/bus/usb/ohci/ohci.c
===================================================================
--- uspace/drv/bus/usb/ohci/ohci.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/ohci/ohci.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -34,14 +34,11 @@
  */
 
-/* XXX Fix this */
-#define _DDF_DATA_IMPLANT
-
 #include <errno.h>
 #include <str_error.h>
 #include <ddf/interrupt.h>
-#include <usb_iface.h>
 #include <usb/usb.h>
-#include <usb/ddfiface.h>
 #include <usb/debug.h>
+
+#include <usb/host/ddf_helpers.h>
 
 #include "ohci.h"
@@ -49,15 +46,6 @@
 #include "hc.h"
 
-typedef struct ohci {
-	ddf_fun_t *hc_fun;
-	ddf_fun_t *rh_fun;
 
-	hc_t hc;
-} ohci_t;
 
-static inline ohci_t *dev_to_ohci(ddf_dev_t *dev)
-{
-	return ddf_dev_data_get(dev);
-}
 /** IRQ handling callback, identifies device
  *
@@ -69,64 +57,13 @@
 {
 	assert(dev);
-
-	ohci_t *ohci = dev_to_ohci(dev);
-	if (!ohci) {
+	hcd_t *hcd = dev_to_hcd(dev);
+	if (!hcd || !hcd->private_data) {
 		usb_log_warning("Interrupt on device that is not ready.\n");
 		return;
 	}
+
 	const uint16_t status = IPC_GET_ARG1(*call);
-	hc_interrupt(&ohci->hc, status);
+	hc_interrupt(hcd->private_data, status);
 }
-
-/** Get USB address assigned to root hub.
- *
- * @param[in] fun Root hub function.
- * @param[out] address Store the address here.
- * @return Error code.
- */
-static int rh_get_my_address(ddf_fun_t *fun, usb_address_t *address)
-{
-	assert(fun);
-
-	if (address != NULL) {
-		*address = dev_to_ohci(ddf_fun_get_dev(fun))->hc.rh.address;
-	}
-
-	return EOK;
-}
-
-/** Gets handle of the respective hc (this device, hc function).
- *
- * @param[in] root_hub_fun Root hub function seeking hc handle.
- * @param[out] handle Place to write the handle.
- * @return Error code.
- */
-static int rh_get_hc_handle(
-    ddf_fun_t *fun, devman_handle_t *handle)
-{
-	assert(fun);
-	ddf_fun_t *hc_fun = dev_to_ohci(ddf_fun_get_dev(fun))->hc_fun;
-	assert(hc_fun);
-
-	if (handle != NULL)
-		*handle = ddf_fun_get_handle(hc_fun);
-	return EOK;
-}
-
-/** Root hub USB interface */
-static usb_iface_t usb_iface = {
-	.get_hc_handle = rh_get_hc_handle,
-	.get_my_address = rh_get_my_address,
-};
-
-/** Standard USB HC options (HC interface) */
-static ddf_dev_ops_t hc_ops = {
-	.interfaces[USBHC_DEV_IFACE] = &hcd_iface,
-};
-
-/** Standard USB RH options (RH interface) */
-static ddf_dev_ops_t rh_ops = {
-	.interfaces[USB_DEV_IFACE] = &usb_iface,
-};
 
 /** Initialize hc and rh ddf structures and their respective drivers.
@@ -143,47 +80,14 @@
 int device_setup_ohci(ddf_dev_t *device)
 {
-	bool ih_registered = false;
-	bool hc_inited = false;
-	int rc;
-
-	if (device == NULL)
-		return EBADMEM;
-
-	ohci_t *instance = ddf_dev_data_alloc(device,sizeof(ohci_t));
-	if (instance == NULL) {
-		usb_log_error("Failed to allocate OHCI driver.\n");
-		return ENOMEM;
-	}
-
-	instance->hc_fun = ddf_fun_create(device, fun_exposed, "ohci_hc");
-	if (instance->hc_fun == NULL) {
-		usb_log_error("Failed to create OHCI HC function: %s.\n",
-		    str_error(ENOMEM));
-		rc = ENOMEM;
-		goto error;
-	}
-
-	ddf_fun_set_ops(instance->hc_fun, &hc_ops);
-	ddf_fun_data_implant(instance->hc_fun, &instance->hc);
-
-	instance->rh_fun = ddf_fun_create(device, fun_inner, "ohci_rh");
-	if (instance->rh_fun == NULL) {
-		usb_log_error("Failed to create OHCI RH function: %s.\n",
-		    str_error(ENOMEM));
-		rc = ENOMEM;
-		goto error;
-	}
-
-	ddf_fun_set_ops(instance->rh_fun, &rh_ops);
 
 	addr_range_t regs;
 	int irq = 0;
 
-	rc = get_my_registers(device, &regs, &irq);
-	if (rc != EOK) {
+	int ret = get_my_registers(device, &regs, &irq);
+	if (ret != EOK) {
 		usb_log_error("Failed to get register memory addresses "
 		    "for %" PRIun ": %s.\n", ddf_dev_get_handle(device),
-		    str_error(rc));
-		goto error;
+		    str_error(ret));
+		return ret;
 	}
 
@@ -191,22 +95,29 @@
 	    RNGABSPTR(regs), RNGSZ(regs), irq);
 
-	rc = hc_register_irq_handler(device, &regs, irq, irq_handler);
-	if (rc != EOK) {
-		usb_log_error("Failed to register interrupt handler: %s.\n",
-		    str_error(rc));
-		goto error;
+	/* Initialize generic HCD driver */
+	ret = hcd_ddf_setup_hc(device, USB_SPEED_FULL,
+	    BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11);
+	if (ret != EOK) {
+		usb_log_error("Failedd to setup generic hcd: %s.",
+		    str_error(ret));
+		return ret;
 	}
 
-	ih_registered = true;
+	ret = hc_register_irq_handler(device, &regs, irq, irq_handler);
+	if (ret != EOK) {
+		usb_log_error("Failed to register interrupt handler: %s.\n",
+		    str_error(ret));
+		hcd_ddf_clean_hc(device);
+		return ret;
+	}
 
 	/* Try to enable interrupts */
 	bool interrupts = false;
-	rc = enable_interrupts(device);
-	if (rc != EOK) {
+	ret = enable_interrupts(device);
+	if (ret != EOK) {
 		usb_log_warning("Failed to enable interrupts: %s."
-		    " Falling back to polling\n", str_error(rc));
+		    " Falling back to polling\n", str_error(ret));
 		/* We don't need that handler */
 		unregister_interrupt_handler(device, irq);
-		ih_registered = false;
 	} else {
 		usb_log_debug("Hw interrupts enabled.\n");
@@ -214,45 +125,37 @@
 	}
 
-	rc = hc_init(&instance->hc, &regs, interrupts);
-	if (rc != EOK) {
-		usb_log_error("Failed to init ohci_hcd: %s.\n", str_error(rc));
-		goto error;
+
+	hc_t *hc_impl = malloc(sizeof(hc_t));
+	if (!hc_impl) {
+		usb_log_error("Failed to allocate driver structure.\n");
+		hcd_ddf_clean_hc(device);
+		unregister_interrupt_handler(device, irq);
+		return ret;
 	}
 
-	hc_inited = true;
-
-	rc = ddf_fun_bind(instance->hc_fun);
-	if (rc != EOK) {
-		usb_log_error("Failed to bind OHCI device function: %s.\n",
-		    str_error(rc));
-		goto error;
+	/* Initialize OHCI HC */
+	ret = hc_init(hc_impl, &regs, interrupts);
+	if (ret != EOK) {
+		usb_log_error("Failed to init hc: %s.\n", str_error(ret));
+		hcd_ddf_clean_hc(device);
+		unregister_interrupt_handler(device, irq);
+		return ret;
 	}
 
-	rc = ddf_fun_add_to_category(instance->hc_fun, USB_HC_CATEGORY);
-	if (rc != EOK) {
-		usb_log_error("Failed to add OHCI to HC category: %s.\n",
-		    str_error(rc));
-		goto error;
+	/* Connect OHCI to generic HCD */
+	hcd_set_implementation(dev_to_hcd(device), hc_impl,
+	    hc_schedule, ohci_endpoint_init, ohci_endpoint_fini);
+
+	/* HC should be running OK. We can add root hub */
+	ret = hcd_ddf_setup_root_hub(device);
+	if (ret != EOK) {
+		usb_log_error("Failed to registter OHCI root hub: %s.\n",
+		    str_error(ret));
+		hcd_ddf_clean_hc(device);
+		unregister_interrupt_handler(device, irq);
+		return ret;
 	}
 
-	rc = hc_register_hub(&instance->hc, instance->rh_fun);
-	if (rc != EOK) {
-		usb_log_error("Failed to register OHCI root hub: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	return EOK;
-
-error:
-	if (hc_inited)
-		hc_fini(&instance->hc);
-	if (ih_registered)
-		unregister_interrupt_handler(device, irq);
-	if (instance->hc_fun != NULL)
-		ddf_fun_destroy(instance->hc_fun);
-	if (instance->rh_fun != NULL)
-		ddf_fun_destroy(instance->rh_fun);
-	return rc;
+	return ret;
 }
 /**
Index: uspace/drv/bus/usb/ohci/ohci.h
===================================================================
--- uspace/drv/bus/usb/ohci/ohci.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/ohci/ohci.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -34,5 +34,4 @@
 #ifndef DRV_OHCI_OHCI_H
 #define DRV_OHCI_OHCI_H
-#include <ddi.h>
 #include <ddf/driver.h>
 
Index: uspace/drv/bus/usb/ohci/ohci_regs.h
===================================================================
--- uspace/drv/bus/usb/ohci/ohci_regs.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/ohci/ohci_regs.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -215,14 +215,14 @@
 	/** Root hub per port status */
 	ioport32_t rh_port_status[];
-#define RHPS_CCS_FLAG (1 << 0) /* r: current connect status,
+#define RHPS_CCS_FLAG (1 << 0)                /* r: current connect status,
                                                * w: 1-clear port enable, 0-N/S*/
 #define RHPS_CLEAR_PORT_ENABLE RHPS_CCS_FLAG
-#define RHPS_PES_FLAG (1 << 1) /* r: port enable status
+#define RHPS_PES_FLAG (1 << 1)               /* r: port enable status
                                               * w: 1-set port enable, 0-N/S */
 #define RHPS_SET_PORT_ENABLE RHPS_PES_FLAG
-#define RHPS_PSS_FLAG (1 << 2) /* r: port suspend status
+#define RHPS_PSS_FLAG (1 << 2)                /* r: port suspend status
                                                * w: 1-set port suspend, 0-N/S */
 #define RHPS_SET_PORT_SUSPEND RHPS_PSS_FLAG
-#define RHPS_POCI_FLAG (1 << 3) /* r: port over-current
+#define RHPS_POCI_FLAG (1 << 3)                /* r: port over-current
                                                 * (if reports are per-port
                                                 * w: 1-clear port suspend
@@ -230,11 +230,11 @@
                                                 *    0-nothing */
 #define RHPS_CLEAR_PORT_SUSPEND RHPS_POCI_FLAG
-#define RHPS_PRS_FLAG (1 << 4) /* r: port reset status
+#define RHPS_PRS_FLAG (1 << 4)                /* r: port reset status
                                                * w: 1-set port reset, 0-N/S */
 #define RHPS_SET_PORT_RESET RHPS_PRS_FLAG
-#define RHPS_PPS_FLAG (1 << 8) /* r: port power status
+#define RHPS_PPS_FLAG (1 << 8)               /* r: port power status
                                               * w: 1-set port power, 0-N/S */
 #define RHPS_SET_PORT_POWER RHPS_PPS_FLAG
-#define RHPS_LSDA_FLAG (1 << 9) /* r: low speed device attached
+#define RHPS_LSDA_FLAG (1 << 9)                /* r: low speed device attached
                                                 * w: 1-clear port power, 0-N/S*/
 #define RHPS_CLEAR_PORT_POWER RHPS_LSDA_FLAG
Index: uspace/drv/bus/usb/ohci/ohci_rh.c
===================================================================
--- uspace/drv/bus/usb/ohci/ohci_rh.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
+++ uspace/drv/bus/usb/ohci/ohci_rh.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -0,0 +1,518 @@
+/*
+ * Copyright (c) 2013 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/** @addtogroup drvusbohci
+ * @{
+ */
+/** @file
+ * @brief OHCI driver
+ */
+#include <assert.h>
+#include <usb/debug.h>
+
+#include "ohci_rh.h"
+
+enum {
+	HUB_STATUS_CHANGE_PIPE = 1,
+};
+
+static usbvirt_device_ops_t ops;
+
+/** Initialize internal USB HUB class descriptor.
+ * @param instance OHCI root hub.
+ * Use register based info to create accurate descriptor.
+ */
+static void ohci_rh_hub_desc_init(ohci_rh_t *instance)
+{
+	assert(instance);
+	const unsigned dsize = sizeof(usb_hub_descriptor_header_t) +
+	    STATUS_BYTES(instance->port_count);
+	assert(dsize <= sizeof(instance->hub_descriptor));
+	const uint32_t hub_desc = OHCI_RD(instance->registers->rh_desc_a);
+	const uint32_t port_desc = OHCI_RD(instance->registers->rh_desc_b);
+
+	instance->hub_descriptor.header.length = dsize;
+	instance->hub_descriptor.header.descriptor_type = USB_DESCTYPE_HUB;
+	instance->hub_descriptor.header.port_count = instance->port_count;
+	instance->hub_descriptor.header.characteristics = 0 |
+	    /* Bits 0,1 indicate power switching mode */
+	    ((hub_desc & RHDA_PSM_FLAG)  ? 0x01 : 0) |
+	    ((hub_desc & RHDA_NPS_FLAG)  ? 0x02 : 0) |
+	    /* Bit 2 indicates device type (compound device) */
+	    ((hub_desc & RHDA_DT_FLAG)   ? 0x04 : 0) |
+	    /* Bits 3,4 indicate over-current protection mode */
+	    ((hub_desc & RHDA_OCPM_FLAG) ? 0x08 : 0) |
+	    ((hub_desc & RHDA_NOCP_FLAG) ? 0x10 : 0);
+	instance->hub_descriptor.header.power_good_time =
+	    hub_desc >> RHDA_POTPGT_SHIFT;
+	/* bHubContrCurrent, root hubs don't need no power. */
+	instance->hub_descriptor.header.max_current = 0;
+
+	/* Device Removable and some legacy 1.0 stuff*/
+	instance->hub_descriptor.rempow[0] =
+	    (port_desc >> RHDB_DR_SHIFT) & 0xff;
+	if (STATUS_BYTES(instance->port_count) == 1) {
+		instance->hub_descriptor.rempow[1] = 0xff;
+	} else {
+		instance->hub_descriptor.rempow[1] =
+		     ((port_desc >> RHDB_DR_SHIFT) >> 8) & 0xff;
+	}
+
+	instance->hub_descriptor.rempow[2] = 0xff;
+	instance->hub_descriptor.rempow[3] = 0xff;
+
+}
+/** Initialize OHCI root hub.
+ * @param instance Place to initialize.
+ * @param regs OHCI device registers.
+ * @param name Device name.
+ * return Error code, EOK on success.
+ *
+ * Selects preconfigured port powering mode, sets up descriptor, and
+ * initializes internal virtual hub.
+ */
+int ohci_rh_init(ohci_rh_t *instance, ohci_regs_t *regs, const char *name)
+{
+	assert(instance);
+	instance->registers = regs;
+	instance->port_count = OHCI_RD(regs->rh_desc_a) & RHDA_NDS_MASK;
+	usb_log_debug2("rh_desc_a: %x.\n", OHCI_RD(regs->rh_desc_a));
+	if (instance->port_count > OHCI_MAX_PORTS) {
+		usb_log_warning("OHCI specification does not allow %d ports. "
+		    "Max %d ports will be used.\n", instance->port_count,
+		    OHCI_MAX_PORTS);
+		instance->port_count = OHCI_MAX_PORTS;
+	}
+	usb_log_info("%s: Found %u ports.\n", name, instance->port_count);
+
+#if defined OHCI_POWER_SWITCH_no
+	usb_log_info("%s: Set power mode to no power switching.\n", name);
+	/* Set port power mode to no power-switching. (always on) */
+	OHCI_SET(regs->rh_desc_a, RHDA_NPS_FLAG);
+
+	/* Set to no over-current reporting */
+	OHCI_SET(regs->rh_desc_a, RHDA_NOCP_FLAG);
+
+#elif defined OHCI_POWER_SWITCH_ganged
+	usb_log_info("%s: Set power mode to ganged power switching.\n", name);
+	/* Set port power mode to ganged power-switching. */
+	OHCI_CLR(regs->rh_desc_a, RHDA_NPS_FLAG);
+	OHCI_CLR(regs->rh_desc_a, RHDA_PSM_FLAG);
+
+	/* Turn off power (hub driver will turn this back on)*/
+	OHCI_WR(regs->rh_status, RHS_CLEAR_GLOBAL_POWER);
+
+	/* Set to global over-current */
+	OHCI_CLR(regs->rh_desc_a, RHDA_NOCP_FLAG);
+	OHCI_CLR(regs->rh_desc_a, RHDA_OCPM_FLAG);
+#else
+	usb_log_info("%s: Set power mode to per-port power switching.\n", name);
+	/* Set port power mode to per port power-switching. */
+	OHCI_CLR(regs->rh_desc_a, RHDA_NPS_FLAG);
+	OHCI_SET(regs->rh_desc_a, RHDA_PSM_FLAG);
+
+	/* Control all ports by global switch and turn them off */
+	OHCI_CLR(regs->rh_desc_b, RHDB_PCC_MASK << RHDB_PCC_SHIFT);
+	OHCI_WR(regs->rh_status, RHS_CLEAR_GLOBAL_POWER);
+
+	/* Return control to per port state */
+	OHCI_SET(regs->rh_desc_b, RHDB_PCC_MASK << RHDB_PCC_SHIFT);
+
+	/* Set per port over-current */
+	OHCI_CLR(regs->rh_desc_a, RHDA_NOCP_FLAG);
+	OHCI_SET(regs->rh_desc_a, RHDA_OCPM_FLAG);
+#endif
+
+	ohci_rh_hub_desc_init(instance);
+	instance->unfinished_interrupt_transfer = NULL;
+	return virthub_base_init(&instance->base, name, &ops, instance,
+	    NULL, &instance->hub_descriptor.header, HUB_STATUS_CHANGE_PIPE);
+}
+
+/** Schedule USB request.
+ * @param instance OCHI root hub instance.
+ * @param batch USB requst batch to schedule.
+ * @return Always EOK.
+ * Most requests complete even before this function returns,
+ * status change requests might be postponed until there is something to report.
+ */
+int ohci_rh_schedule(ohci_rh_t *instance, usb_transfer_batch_t *batch)
+{
+	assert(instance);
+	assert(batch);
+	const usb_target_t target = {{
+		.address = batch->ep->address,
+		.endpoint = batch->ep->endpoint,
+	}};
+	batch->error = virthub_base_request(&instance->base, target,
+	    usb_transfer_batch_direction(batch), (void*)batch->setup_buffer,
+	    batch->buffer, batch->buffer_size, &batch->transfered_size);
+	if (batch->error == ENAK) {
+		/* This is safe because only status change interrupt transfers
+		 * return NAK. The assertion holds tru because the batch
+		 * existence prevents communication with that ep */
+		assert(instance->unfinished_interrupt_transfer == NULL);
+		instance->unfinished_interrupt_transfer = batch;
+	} else {
+		usb_transfer_batch_finish(batch, NULL);
+		usb_transfer_batch_destroy(batch);
+	}
+	return EOK;
+}
+
+/** Handle OHCI RHSC interrupt.
+ * @param instance OHCI root hub isntance.
+ * @return Always EOK.
+ *
+ * Interrupt means there is a change of status to report. It may trigger
+ * processing of a postponed request.
+ */
+int ohci_rh_interrupt(ohci_rh_t *instance)
+{
+	//TODO atomic swap needed
+	usb_transfer_batch_t *batch = instance->unfinished_interrupt_transfer;
+	instance->unfinished_interrupt_transfer = NULL;
+	if (batch) {
+		const usb_target_t target = {{
+			.address = batch->ep->address,
+			.endpoint = batch->ep->endpoint,
+		}};
+		batch->error = virthub_base_request(&instance->base, target,
+		    usb_transfer_batch_direction(batch),
+		    (void*)batch->setup_buffer,
+		    batch->buffer, batch->buffer_size, &batch->transfered_size);
+		usb_transfer_batch_finish(batch, NULL);
+		usb_transfer_batch_destroy(batch);
+	}
+	return EOK;
+}
+
+/* HUB ROUTINES IMPLEMENTATION */
+#define TEST_SIZE_INIT(size, port, hub) \
+do { \
+	hub = virthub_get_data(device); \
+	assert(hub);\
+	if (uint16_usb2host(setup_packet->length) != size) \
+		return ESTALL; \
+	port = uint16_usb2host(setup_packet->index) - 1; \
+	if (port > hub->port_count) \
+		return EINVAL; \
+} while (0)
+
+/** Hub status request handler.
+ * @param device Virtual hub device
+ * @param setup_packet USB setup stage data.
+ * @param[out] data destination data buffer, size must be at least
+ *             setup_packet->length bytes
+ * @param[out] act_size Sized of the valid response part of the buffer.
+ * @return Error code.
+ */
+static int req_get_status(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet,
+    uint8_t *data, size_t *act_size)
+{
+	ohci_rh_t *hub = virthub_get_data(device);
+	assert(hub);
+	if (uint16_usb2host(setup_packet->length) != 4)
+		return ESTALL;
+	const uint32_t val = OHCI_RD(hub->registers->rh_status) &
+	    (RHS_LPS_FLAG | RHS_LPSC_FLAG | RHS_OCI_FLAG | RHS_OCIC_FLAG);
+	memcpy(data, &val, sizeof(val));
+	*act_size = sizeof(val);
+	return EOK;
+}
+
+/** Hub set feature request handler.
+ * @param device Virtual hub device
+ * @param setup_packet USB setup stage data.
+ * @param[out] data destination data buffer, size must be at least
+ *             setup_packet->length bytes
+ * @param[out] act_size Sized of the valid response part of the buffer.
+ * @return Error code.
+ */
+static int req_clear_hub_feature(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet,
+    uint8_t *data, size_t *act_size)
+{
+	ohci_rh_t *hub = virthub_get_data(device);
+	assert(hub);
+
+	/*
+	 * Chapter 11.16.2 specifies that only C_HUB_LOCAL_POWER and
+	 * C_HUB_OVER_CURRENT are supported.
+	 * C_HUB_LOCAL_POWER is not supported
+	 * because root hubs do not support local power status feature.
+	 * C_HUB_OVER_CURRENT is represented by OHCI RHS_OCIC_FLAG.
+	 * (OHCI pg. 127)
+	 */
+	const unsigned feature = uint16_usb2host(setup_packet->value);
+	if (feature == USB_HUB_FEATURE_C_HUB_OVER_CURRENT) {
+		OHCI_WR(hub->registers->rh_status, RHS_OCIC_FLAG);
+	}
+	return EOK;
+}
+
+/** Port status request handler.
+ * @param device Virtual hub device
+ * @param setup_packet USB setup stage data.
+ * @param[out] data destination data buffer, size must be at least
+ *             setup_packet->length bytes
+ * @param[out] act_size Sized of the valid response part of the buffer.
+ * @return Error code.
+ */
+static int req_get_port_status(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet,
+    uint8_t *data, size_t *act_size)
+{
+	ohci_rh_t *hub;
+	unsigned port;
+	TEST_SIZE_INIT(4, port, hub);
+	if (setup_packet->value != 0)
+		return EINVAL;
+
+	const uint32_t status = OHCI_RD(hub->registers->rh_port_status[port]);
+	memcpy(data, &status, sizeof(status));
+	*act_size = sizeof(status);
+	return EOK;
+}
+
+/** Port clear feature request handler.
+ * @param device Virtual hub device
+ * @param setup_packet USB setup stage data.
+ * @param[out] data destination data buffer, size must be at least
+ *             setup_packet->length bytes
+ * @param[out] act_size Sized of the valid response part of the buffer.
+ * @return Error code.
+ */
+static int req_clear_port_feature(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet,
+    uint8_t *data, size_t *act_size)
+{
+	ohci_rh_t *hub;
+	unsigned port;
+	TEST_SIZE_INIT(0, port, hub);
+	const unsigned feature = uint16_usb2host(setup_packet->value);
+	/* Enabled features to clear: see page 269 of USB specs */
+	switch (feature)
+	{
+	case USB_HUB_FEATURE_PORT_POWER:          /*8*/
+		{
+			const uint32_t rhda =
+			    OHCI_RD(hub->registers->rh_desc_a);
+			/* No power switching */
+			if (rhda & RHDA_NPS_FLAG)
+				return ENOTSUP;
+			/* Ganged power switching, one port powers all */
+			if (!(rhda & RHDA_PSM_FLAG)) {
+				OHCI_WR(hub->registers->rh_status,
+				    RHS_CLEAR_GLOBAL_POWER);
+				return EOK;
+			}
+			OHCI_WR(hub->registers->rh_port_status[port],
+			    RHPS_CLEAR_PORT_POWER);
+			return EOK;
+		}
+
+	case USB_HUB_FEATURE_PORT_ENABLE:         /*1*/
+		OHCI_WR(hub->registers->rh_port_status[port],
+		    RHPS_CLEAR_PORT_ENABLE);
+		return EOK;
+
+	case USB_HUB_FEATURE_PORT_SUSPEND:        /*2*/
+		OHCI_WR(hub->registers->rh_port_status[port],
+		    RHPS_CLEAR_PORT_SUSPEND);
+		return EOK;
+
+	case USB_HUB_FEATURE_C_PORT_CONNECTION:   /*16*/
+	case USB_HUB_FEATURE_C_PORT_ENABLE:       /*17*/
+	case USB_HUB_FEATURE_C_PORT_SUSPEND:      /*18*/
+	case USB_HUB_FEATURE_C_PORT_OVER_CURRENT: /*19*/
+	case USB_HUB_FEATURE_C_PORT_RESET:        /*20*/
+		usb_log_debug2("Clearing port C_CONNECTION, C_ENABLE, "
+		    "C_SUSPEND, C_OC or C_RESET on port %"PRIu16".\n", port);
+		/* Bit offsets correspond to the feature number */
+		OHCI_WR(hub->registers->rh_port_status[port],
+		    1 << feature);
+		return EOK;
+
+	default:
+		return ENOTSUP;
+	}
+}
+
+/** Port set feature request handler.
+ * @param device Virtual hub device
+ * @param setup_packet USB setup stage data.
+ * @param[out] data destination data buffer, size must be at least
+ *             setup_packet->length bytes
+ * @param[out] act_size Sized of the valid response part of the buffer.
+ * @return Error code.
+ */
+static int req_set_port_feature(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet,
+    uint8_t *data, size_t *act_size)
+{
+	ohci_rh_t *hub;
+	unsigned port;
+	TEST_SIZE_INIT(0, port, hub);
+	const unsigned feature = uint16_usb2host(setup_packet->value);
+	switch (feature) {
+	case USB_HUB_FEATURE_PORT_POWER:   /*8*/
+	{
+		const uint32_t rhda = OHCI_RD(hub->registers->rh_desc_a);
+		/* No power switching */
+		if (rhda & RHDA_NPS_FLAG)
+			return EOK;
+		/* Ganged power switching, one port powers all */
+		if (!(rhda & RHDA_PSM_FLAG)) {
+			OHCI_WR(hub->registers->rh_status,RHS_SET_GLOBAL_POWER);
+			return EOK;
+		}
+	}
+	/* Fall through, for per port power */
+	case USB_HUB_FEATURE_PORT_ENABLE:  /*1*/
+	case USB_HUB_FEATURE_PORT_SUSPEND: /*2*/
+	case USB_HUB_FEATURE_PORT_RESET:   /*4*/
+		usb_log_debug2("Setting port POWER, ENABLE, SUSPEND or RESET "
+		    "on port %"PRIu16".\n", port);
+		/* Bit offsets correspond to the feature number */
+		OHCI_WR(hub->registers->rh_port_status[port], 1 << feature);
+		return EOK;
+	default:
+		return ENOTSUP;
+	}
+}
+
+/** Status change handler.
+ * @param device Virtual hub device
+ * @param endpoint Endpoint number
+ * @param tr_type Transfer type
+ * @param buffer Response destination
+ * @param buffer_size Bytes available in buffer
+ * @param actual_size Size us the used part of the dest buffer.
+ *
+ * Produces status mask. Bit 0 indicates hub status change the other bits
+ * represent port status change. Endian does not matter as UHCI root hubs
+ * only need 1 byte.
+ */
+static int req_status_change_handler(usbvirt_device_t *device,
+    usb_endpoint_t endpoint, usb_transfer_type_t tr_type,
+    void *buffer, size_t buffer_size, size_t *actual_size)
+{
+	ohci_rh_t *hub = virthub_get_data(device);
+	assert(hub);
+
+	if (buffer_size < STATUS_BYTES(hub->port_count))
+		return ESTALL;
+
+	uint16_t mask = 0;
+
+	/* Only local power source change and over-current change can happen */
+	if (OHCI_RD(hub->registers->rh_status) & (RHS_LPSC_FLAG | RHS_OCIC_FLAG)) {
+		mask |= 1;
+	}
+
+	for (unsigned port = 1; port <= hub->port_count; ++port) {
+		/* Write-clean bits are those that indicate change */
+		if (OHCI_RD(hub->registers->rh_port_status[port - 1])
+		    & RHPS_CHANGE_WC_MASK) {
+			mask |= (1 << port);
+		}
+	}
+
+	usb_log_debug2("OHCI root hub interrupt mask: %hx.\n", mask);
+
+	if (mask == 0)
+		return ENAK;
+	mask = uint16_host2usb(mask);
+	memcpy(buffer, &mask, STATUS_BYTES(hub->port_count));
+	*actual_size = STATUS_BYTES(hub->port_count);
+	return EOK;
+}
+
+/** OHCI root hub request handlers */
+static const usbvirt_control_request_handler_t control_transfer_handlers[] = {
+	{
+		STD_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_DEVREQ_GET_DESCRIPTOR),
+		.name = "GetDescriptor",
+		.callback = virthub_base_get_hub_descriptor,
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_DEVREQ_GET_DESCRIPTOR),
+		.name = "GetDescriptor",
+		.callback = virthub_base_get_hub_descriptor,
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_GET_DESCRIPTOR),
+		.name = "GetHubDescriptor",
+		.callback = virthub_base_get_hub_descriptor,
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_GET_STATUS),
+		.name = "GetPortStatus",
+		.callback = req_get_port_status,
+	},
+	{
+		CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_CLEAR_FEATURE),
+		.name = "ClearHubFeature",
+		.callback = req_clear_hub_feature,
+	},
+	{
+		CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_CLEAR_FEATURE),
+		.name = "ClearPortFeature",
+		.callback = req_clear_port_feature,
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_GET_STATUS),
+		.name = "GetHubStatus",
+		.callback = req_get_status,
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_GET_STATUS),
+		.name = "GetPortStatus",
+		.callback = req_get_port_status,
+	},
+	{
+		CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_SET_FEATURE),
+		.name = "SetHubFeature",
+		.callback = req_nop,
+	},
+	{
+		CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_SET_FEATURE),
+		.name = "SetPortFeature",
+		.callback = req_set_port_feature,
+	},
+	{
+		.callback = NULL
+	}
+};
+
+/** Virtual OHCI root hub ops */
+static usbvirt_device_ops_t ops = {
+        .control = control_transfer_handlers,
+        .data_in[HUB_STATUS_CHANGE_PIPE] = req_status_change_handler,
+};
Index: uspace/drv/bus/usb/ohci/ohci_rh.h
===================================================================
--- uspace/drv/bus/usb/ohci/ohci_rh.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
+++ uspace/drv/bus/usb/ohci/ohci_rh.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2013 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/** @addtogroup drvusbohci
+ * @{
+ */
+/** @file
+ * @brief OHCI driver
+ */
+#ifndef DRV_OHCI_OHCI_RH_H
+#define DRV_OHCI_OHCI_RH_H
+
+#include <usb/usb.h>
+#include <usb/classes/hub.h>
+#include <usb/host/usb_transfer_batch.h>
+#include <usbvirt/virthub_base.h>
+
+#include "ohci_regs.h"
+
+enum {
+	OHCI_MAX_PORTS = 15,
+};
+
+typedef struct {
+	/** Virtual hub instance */
+	virthub_base_t base;
+	/** OHCI device registers */
+	ohci_regs_t *registers;
+	/** Number of downstream ports, OHCI limits this to 15 */
+	unsigned port_count;
+	/** USB hub descriptor describing the OHCI root hub */
+	struct {
+		usb_hub_descriptor_header_t header;
+		uint8_t rempow[STATUS_BYTES(OHCI_MAX_PORTS) * 2];
+	} __attribute__((packed)) hub_descriptor;
+	/** interrupt transfer waiting for an actual interrupt to occur */
+	usb_transfer_batch_t *unfinished_interrupt_transfer;
+} ohci_rh_t;
+
+int ohci_rh_init(ohci_rh_t *instance, ohci_regs_t *regs, const char *name);
+int ohci_rh_schedule(ohci_rh_t *instance, usb_transfer_batch_t *batch);
+int ohci_rh_interrupt(ohci_rh_t *instance);
+
+/** Get OHCI rh address.
+ *
+ * @param instance UHCI rh instance.
+ * @return USB address assigned to the hub.
+ * Wrapper for virtual hub address
+ */
+static inline usb_address_t ohci_rh_get_address(ohci_rh_t *instance)
+{
+	assert(instance);
+	return virthub_base_get_address(&instance->base);
+}
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/bus/usb/ohci/root_hub.c
===================================================================
--- uspace/drv/bus/usb/ohci/root_hub.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ 	(revision )
@@ -1,843 +1,0 @@
-/*
- * Copyright (c) 2011 Jan Vesely
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-/** @addtogroup drvusbohci
- * @{
- */
-/** @file
- * @brief OHCI driver
- */
-#include <assert.h>
-#include <byteorder.h>
-#include <errno.h>
-#include <str_error.h>
-#include <fibril_synch.h>
-
-#include <usb/usb.h>
-#include <usb/debug.h>
-#include <usb/dev/request.h>
-#include <usb/classes/hub.h>
-
-#include <usb/classes/classes.h>
-#include <usb/classes/hub.h>
-#include <usb/dev/driver.h>
-#include "ohci_regs.h"
-#include "root_hub.h"
-
-/**
- * standart device descriptor for ohci root hub
- */
-static const usb_standard_device_descriptor_t ohci_rh_device_descriptor = {
-	.configuration_count = 1,
-	.descriptor_type = USB_DESCTYPE_DEVICE,
-	.device_class = USB_CLASS_HUB,
-	.device_protocol = 0,
-	.device_subclass = 0,
-	.device_version = 0,
-	.length = sizeof(usb_standard_device_descriptor_t),
-	.max_packet_size = 64,
-	.vendor_id = 0x16db, /* HelenOS does not have USB vendor ID assigned.*/
-	.product_id = 0x0001,
-	.str_serial_number = 0,
-	.usb_spec_version = 0x110,
-};
-
-/**
- * standart configuration descriptor with filled common values
- * for ohci root hubs
- */
-static const usb_standard_configuration_descriptor_t ohci_rh_conf_descriptor = {
-	.attributes = 1 << 7,
-	.configuration_number = 1,
-	.descriptor_type = USB_DESCTYPE_CONFIGURATION,
-	.interface_count = 1,
-	.length = sizeof(usb_standard_configuration_descriptor_t),
-	.max_power = 0, /* root hubs don't need no power */
-	.str_configuration = 0,
-};
-
-/**
- * standart ohci root hub interface descriptor
- */
-static const usb_standard_interface_descriptor_t ohci_rh_iface_descriptor = {
-	.alternate_setting = 0,
-	.descriptor_type = USB_DESCTYPE_INTERFACE,
-	.endpoint_count = 1,
-	.interface_class = USB_CLASS_HUB,
-	.interface_number = 1,
-	.interface_protocol = 0,
-	.interface_subclass = 0,
-	.length = sizeof(usb_standard_interface_descriptor_t),
-	.str_interface = 0,
-};
-
-/**
- * standart ohci root hub endpoint descriptor
- */
-static const usb_standard_endpoint_descriptor_t ohci_rh_ep_descriptor = {
-	.attributes = USB_TRANSFER_INTERRUPT,
-	.descriptor_type = USB_DESCTYPE_ENDPOINT,
-	.endpoint_address = 1 | (1 << 7),
-	.length = sizeof(usb_standard_endpoint_descriptor_t),
-	.max_packet_size = 2,
-	.poll_interval = 255,
-};
-
-static void create_serialized_hub_descriptor(rh_t *instance);
-static void rh_init_descriptors(rh_t *instance);
-static uint16_t create_interrupt_mask(const rh_t *instance);
-static void get_status(const rh_t *instance, usb_transfer_batch_t *request);
-static void get_descriptor(const rh_t *instance, usb_transfer_batch_t *request);
-static void set_feature(const rh_t *instance, usb_transfer_batch_t *request);
-static void clear_feature(const rh_t *instance, usb_transfer_batch_t *request);
-static int set_feature_port(
-    const rh_t *instance, uint16_t feature, uint16_t port);
-static int clear_feature_port(
-    const rh_t *instance, uint16_t feature, uint16_t port);
-static void control_request(rh_t *instance, usb_transfer_batch_t *request);
-static inline void interrupt_request(
-    usb_transfer_batch_t *request, uint16_t mask, size_t size)
-{
-	assert(request);
-	usb_log_debug("Sending interrupt vector(%zu) %hhx:%hhx.\n",
-	    size, ((uint8_t*)&mask)[0], ((uint8_t*)&mask)[1]);
-	usb_transfer_batch_finish_error(request, &mask, size, EOK);
-	usb_transfer_batch_destroy(request);
-}
-
-#define TRANSFER_END_DATA(request, data, bytes) \
-do { \
-	usb_transfer_batch_finish_error(request, data, bytes, EOK); \
-	usb_transfer_batch_destroy(request); \
-	return; \
-} while (0)
-
-#define TRANSFER_END(request, error) \
-do { \
-	usb_transfer_batch_finish_error(request, NULL, 0, error); \
-	usb_transfer_batch_destroy(request); \
-	return; \
-} while (0)
-
-/** Root Hub driver structure initialization.
- *
- * Reads info registers and prepares descriptors. Sets power mode.
- */
-void rh_init(rh_t *instance, ohci_regs_t *regs)
-{
-	assert(instance);
-	assert(regs);
-
-	instance->registers = regs;
-	instance->port_count = OHCI_RD(regs->rh_desc_a) & RHDA_NDS_MASK;
-	usb_log_debug2("rh_desc_a: %x.\n", OHCI_RD(regs->rh_desc_a));
-	if (instance->port_count > 15) {
-		usb_log_warning("OHCI specification does not allow more than 15"
-		    " ports. Max 15 ports will be used");
-		instance->port_count = 15;
-	}
-
-	/* Don't forget the hub status bit and round up */
-	instance->interrupt_mask_size = 1 + (instance->port_count / 8);
-	instance->unfinished_interrupt_transfer = NULL;
-
-#if defined OHCI_POWER_SWITCH_no
-	usb_log_debug("OHCI rh: Set power mode to no power switching.\n");
-	/* Set port power mode to no power-switching. (always on) */
-	OHCI_SET(regs->rh_desc_a, RHDA_NPS_FLAG);
-
-	/* Set to no over-current reporting */
-	OHCI_SET(regs->rh_desc_a, RHDA_NOCP_FLAG);
-
-#elif defined OHCI_POWER_SWITCH_ganged
-	usb_log_debug("OHCI rh: Set power mode to ganged power switching.\n");
-	/* Set port power mode to ganged power-switching. */
-	OHCI_CLR(regs->rh_desc_a, RHDA_NPS_FLAG);
-	OHCI_CLR(regs->rh_desc_a, RHDA_PSM_FLAG);
-
-	/* Turn off power (hub driver will turn this back on)*/
-	OHCI_WR(regs->rh_status, RHS_CLEAR_GLOBAL_POWER);
-
-	/* Set to global over-current */
-	OHCI_CLR(regs->rh_desc_a, RHDA_NOCP_FLAG);
-	OHCI_CLR(regs->rh_desc_a, RHDA_OCPM_FLAG);
-#else
-	usb_log_debug("OHCI rh: Set power mode to per-port power switching.\n");
-	/* Set port power mode to per port power-switching. */
-	OHCI_CLR(regs->rh_desc_a, RHDA_NPS_FLAG);
-	OHCI_SET(regs->rh_desc_a, RHDA_PSM_FLAG);
-
-	/* Control all ports by global switch and turn them off */
-	OHCI_CLR(regs->rh_desc_b, RHDB_PCC_MASK << RHDB_PCC_SHIFT);
-	OHCI_WR(regs->rh_status, RHS_CLEAR_GLOBAL_POWER);
-
-	/* Return control to per port state */
-	OHCI_SET(regs->rh_desc_b, RHDB_PCC_MASK << RHDB_PCC_SHIFT);
-
-	/* Set per port over-current */
-	OHCI_CLR(regs->rh_desc_a, RHDA_NOCP_FLAG);
-	OHCI_SET(regs->rh_desc_a, RHDA_OCPM_FLAG);
-#endif
-
-	fibril_mutex_initialize(&instance->guard);
-	rh_init_descriptors(instance);
-
-	usb_log_info("Root hub (%zu ports) initialized.\n",
-	    instance->port_count);
-}
-
-/**
- * Process root hub request.
- *
- * @param instance Root hub instance
- * @param request Structure containing both request and response information
- * @return Error code
- */
-void rh_request(rh_t *instance, usb_transfer_batch_t *request)
-{
-	assert(instance);
-	assert(request);
-
-	switch (request->ep->transfer_type)
-	{
-	case USB_TRANSFER_CONTROL:
-		usb_log_debug("Root hub got CONTROL packet\n");
-		control_request(instance, request);
-		break;
-
-	case USB_TRANSFER_INTERRUPT:
-		usb_log_debug("Root hub got INTERRUPT packet\n");
-		fibril_mutex_lock(&instance->guard);
-		assert(instance->unfinished_interrupt_transfer == NULL);
-		const uint16_t mask = create_interrupt_mask(instance);
-		if (mask == 0) {
-			usb_log_debug("No changes(%hx)...\n", mask);
-			instance->unfinished_interrupt_transfer = request;
-		} else {
-			usb_log_debug("Processing changes...\n");
-			interrupt_request(
-			    request, mask, instance->interrupt_mask_size);
-		}
-		fibril_mutex_unlock(&instance->guard);
-		break;
-
-	default:
-		usb_log_error("Root hub got unsupported request.\n");
-		TRANSFER_END(request, ENOTSUP);
-	}
-}
-
-/**
- * Process interrupt on a hub device.
- *
- * If there is no pending interrupt transfer, nothing happens.
- * @param instance
- */
-void rh_interrupt(rh_t *instance)
-{
-	assert(instance);
-
-	fibril_mutex_lock(&instance->guard);
-	if (instance->unfinished_interrupt_transfer) {
-		usb_log_debug("Finalizing interrupt transfer\n");
-		const uint16_t mask = create_interrupt_mask(instance);
-		interrupt_request(instance->unfinished_interrupt_transfer,
-		    mask, instance->interrupt_mask_size);
-		instance->unfinished_interrupt_transfer = NULL;
-	}
-	fibril_mutex_unlock(&instance->guard);
-}
-
-/**
- * Create hub descriptor.
- *
- * For descriptor format see USB hub specification (chapter 11.15.2.1, pg. 263)
- *
- * @param instance Root hub instance
- * @return Error code
- */
-void create_serialized_hub_descriptor(rh_t *instance)
-{
-	assert(instance);
-
-	/* 7 bytes + 2 port bit fields (port count + global bit) */
-	size_t size = 7 + (instance->interrupt_mask_size * 2);
-	assert(size <= HUB_DESCRIPTOR_MAX_SIZE);
-	instance->hub_descriptor_size = size;
-
-	const uint32_t hub_desc = OHCI_RD(instance->registers->rh_desc_a);
-	const uint32_t port_desc = OHCI_RD(instance->registers->rh_desc_b);
-
-	/* bDescLength */
-	instance->descriptors.hub[0] = size;
-	/* bDescriptorType */
-	instance->descriptors.hub[1] = USB_DESCTYPE_HUB;
-	/* bNmbrPorts */
-	instance->descriptors.hub[2] = instance->port_count;
-	/* wHubCharacteristics */
-	instance->descriptors.hub[3] = 0 |
-	    /* The lowest 2 bits indicate power switching mode */
-	    (((hub_desc & RHDA_PSM_FLAG)  ? 1 : 0) << 0) |
-	    (((hub_desc & RHDA_NPS_FLAG)  ? 1 : 0) << 1) |
-	    /* Bit 3 indicates device type (compound device) */
-	    (((hub_desc & RHDA_DT_FLAG)   ? 1 : 0) << 2) |
-	    /* Bits 4,5 indicate over-current protection mode */
-	    (((hub_desc & RHDA_OCPM_FLAG) ? 1 : 0) << 3) |
-	    (((hub_desc & RHDA_NOCP_FLAG) ? 1 : 0) << 4);
-
-	/* Reserved */
-	instance->descriptors.hub[4] = 0;
-	/* bPwrOn2PwrGood */
-	instance->descriptors.hub[5] = hub_desc >> RHDA_POTPGT_SHIFT;
-	/* bHubContrCurrent, root hubs don't need no power. */
-	instance->descriptors.hub[6] = 0;
-
-	/* Device Removable and some legacy 1.0 stuff*/
-	instance->descriptors.hub[7] = (port_desc >> RHDB_DR_SHIFT) & 0xff;
-	instance->descriptors.hub[8] = 0xff;
-	if (instance->interrupt_mask_size == 2) {
-		instance->descriptors.hub[8] =
-		    (port_desc >> RHDB_DR_SHIFT) >> 8;
-		instance->descriptors.hub[9]  = 0xff;
-		instance->descriptors.hub[10] = 0xff;
-	}
-}
-
-/** Initialize hub descriptors.
- *
- * A full configuration descriptor is assembled. The configuration and endpoint
- * descriptors have local modifications.
- * @param instance Root hub instance
- * @return Error code
- */
-void rh_init_descriptors(rh_t *instance)
-{
-	assert(instance);
-
-	instance->descriptors.configuration = ohci_rh_conf_descriptor;
-	instance->descriptors.interface = ohci_rh_iface_descriptor;
-	instance->descriptors.endpoint = ohci_rh_ep_descriptor;
-	create_serialized_hub_descriptor(instance);
-
-	instance->descriptors.endpoint.max_packet_size =
-	    instance->interrupt_mask_size;
-
-	instance->descriptors.configuration.total_length = uint16_host2usb(
-	    sizeof(usb_standard_configuration_descriptor_t) +
-	    sizeof(usb_standard_endpoint_descriptor_t) +
-	    sizeof(usb_standard_interface_descriptor_t) +
-	    instance->hub_descriptor_size);
-}
-
-/**
- * Create bitmap of changes to answer status interrupt.
- *
- * Result contains bitmap where bit 0 indicates change on hub and
- * bit i indicates change on i`th port (i>0). For more info see
- * Hub and Port status bitmap specification in USB specification
- * (chapter 11.13.4).
- * @param instance root hub instance
- * @return Mask of changes.
- */
-uint16_t create_interrupt_mask(const rh_t *instance)
-{
-	assert(instance);
-	uint16_t mask = 0;
-
-	/* Only local power source change and over-current change can happen */
-	if (OHCI_RD(instance->registers->rh_status)
-	    & (RHS_LPSC_FLAG | RHS_OCIC_FLAG)) {
-		mask |= 1;
-	}
-	for (size_t port = 1; port <= instance->port_count; ++port) {
-		/* Write-clean bits are those that indicate change */
-		if (OHCI_RD(instance->registers->rh_port_status[port - 1])
-		    & RHPS_CHANGE_WC_MASK) {
-			mask |= (1 << port);
-		}
-	}
-	usb_log_debug2("OHCI root hub interrupt mask: %hx.\n", mask);
-	return uint16_host2usb(mask);
-}
-
-/**
- * Create answer to status request.
- *
- * This might be either hub status or port status request. If neither,
- * ENOTSUP is returned.
- * @param instance root hub instance
- * @param request structure containing both request and response information
- * @return error code
- */
-void get_status(const rh_t *instance, usb_transfer_batch_t *request)
-{
-	assert(instance);
-	assert(request);
-
-
-	usb_device_request_setup_packet_t *request_packet =
-	    (usb_device_request_setup_packet_t*)request->setup_buffer;
-
-	const uint16_t index = uint16_usb2host(request_packet->index);
-
-	switch (request_packet->request_type)
-	{
-	case USB_HUB_REQ_TYPE_GET_HUB_STATUS:
-	/* Hub status: just filter relevant info from rh_status reg */
-		if (request->buffer_size < 4) {
-			usb_log_error("Buffer(%zu) too small for hub get "
-			    "status request.\n", request->buffer_size);
-			TRANSFER_END(request, EOVERFLOW);
-		} else {
-			const uint32_t data =
-			    OHCI_RD(instance->registers->rh_status) &
-			        (RHS_LPS_FLAG | RHS_LPSC_FLAG
-			            | RHS_OCI_FLAG | RHS_OCIC_FLAG);
-			TRANSFER_END_DATA(request, &data, sizeof(data));
-		}
-
-	/* Copy appropriate rh_port_status register, OHCI designers were
-	 * kind enough to make those bit values match USB specification */
-	case USB_HUB_REQ_TYPE_GET_PORT_STATUS:
-		if (request->buffer_size < 4) {
-			usb_log_error("Buffer(%zu) too small for hub get "
-			    "status request.\n", request->buffer_size);
-			TRANSFER_END(request, EOVERFLOW);
-		} else {
-			const unsigned port = index;
-			if (port < 1 || port > instance->port_count)
-				TRANSFER_END(request, EINVAL);
-			/* Register format matches the format of port status
-			 * field */
-			const uint32_t data = uint32_host2usb(OHCI_RD(
-			    instance->registers->rh_port_status[port - 1]));
-			TRANSFER_END_DATA(request, &data, sizeof(data));
-		}
-	case SETUP_REQUEST_TO_HOST(USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE):
-		if (request->buffer_size < 2) {
-			usb_log_error("Buffer(%zu) too small for hub generic "
-			    "get status request.\n", request->buffer_size);
-			TRANSFER_END(request, EOVERFLOW);
-		} else {
-			const uint16_t data =
-			    uint16_host2usb(USB_DEVICE_STATUS_SELF_POWERED);
-			TRANSFER_END_DATA(request, &data, sizeof(data));
-		}
-
-	case SETUP_REQUEST_TO_HOST(USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_INTERFACE):
-		/* Hubs are allowed to have only one interface */
-		if (index != 0)
-			TRANSFER_END(request, EINVAL);
-		/* Fall through, as the answer will be the same: 0x0000 */
-	case SETUP_REQUEST_TO_HOST(USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_ENDPOINT):
-		/* Endpoint 0 (default control) and 1 (interrupt) */
-		if (index >= 2)
-			TRANSFER_END(request, EINVAL);
-
-		if (request->buffer_size < 2) {
-			usb_log_error("Buffer(%zu) too small for hub generic "
-			    "get status request.\n", request->buffer_size);
-			TRANSFER_END(request, EOVERFLOW);
-		} else {
-			/* Endpoints are OK. (We don't halt) */
-			const uint16_t data = 0;
-			TRANSFER_END_DATA(request, &data, sizeof(data));
-		}
-
-	default:
-		usb_log_error("Unsupported GET_STATUS request.\n");
-		TRANSFER_END(request, ENOTSUP);
-	}
-
-}
-
-/**
- * Create answer to a descriptor request.
- *
- * This might be a request for standard (configuration, device, endpoint or
- * interface) or device specific (hub) descriptor.
- * @param instance Root hub instance
- * @param request Structure containing both request and response information
- * @return Error code
- */
-void get_descriptor(const rh_t *instance, usb_transfer_batch_t *request)
-{
-	assert(instance);
-	assert(request);
-
-	usb_device_request_setup_packet_t *setup_request =
-	    (usb_device_request_setup_packet_t *) request->setup_buffer;
-	/* "The wValue field specifies the descriptor type in the high byte
-	 * and the descriptor index in the low byte (refer to Table 9-5)." */
-	const int desc_type = uint16_usb2host(setup_request->value) >> 8;
-	switch (desc_type)
-	{
-	case USB_DESCTYPE_HUB:
-		usb_log_debug2("USB_DESCTYPE_HUB\n");
-		/* Hub descriptor was generated locally.
-		 * Class specific request. */
-		TRANSFER_END_DATA(request, instance->descriptors.hub,
-		    instance->hub_descriptor_size);
-
-	case USB_DESCTYPE_DEVICE:
-		usb_log_debug2("USB_DESCTYPE_DEVICE\n");
-		/* Device descriptor is shared
-		 * (No one should ask for it, as the device is already setup)
-		 * Standard USB device request. */
-		TRANSFER_END_DATA(request, &ohci_rh_device_descriptor,
-		    sizeof(ohci_rh_device_descriptor));
-
-	case USB_DESCTYPE_CONFIGURATION:
-		usb_log_debug2("USB_DESCTYPE_CONFIGURATION\n");
-		/* Start with configuration and add others depending on
-		 * request size. Standard USB request. */
-		TRANSFER_END_DATA(request, &instance->descriptors,
-		    instance->descriptors.configuration.total_length);
-
-	case USB_DESCTYPE_INTERFACE:
-		usb_log_debug2("USB_DESCTYPE_INTERFACE\n");
-		/* Use local interface descriptor. There is one and it
-		 * might be modified. Hub driver should not ask or this
-		 * descriptor as it is not part of standard requests set. */
-		TRANSFER_END_DATA(request, &instance->descriptors.interface,
-		    sizeof(instance->descriptors.interface));
-
-	case USB_DESCTYPE_ENDPOINT:
-		/* Use local endpoint descriptor. There is one
-		 * it might have max_packet_size field modified. Hub driver
-		 * should not ask for this descriptor as it is not part
-		 * of standard requests set. */
-		usb_log_debug2("USB_DESCTYPE_ENDPOINT\n");
-		TRANSFER_END_DATA(request, &instance->descriptors.endpoint,
-		    sizeof(instance->descriptors.endpoint));
-
-	default:
-		usb_log_debug2("USB_DESCTYPE_EINVAL %d \n"
-		    "\ttype %d\n\trequest %d\n\tvalue "
-		    "%d\n\tindex %d\n\tlen %d\n ",
-		    setup_request->value,
-		    setup_request->request_type, setup_request->request,
-		    desc_type, setup_request->index,
-		    setup_request->length);
-		TRANSFER_END(request, EINVAL);
-	}
-
-	TRANSFER_END(request, ENOTSUP);
-}
-
-/**
- * process feature-enabling request on hub
- *
- * @param instance root hub instance
- * @param feature feature selector
- * @param port port number, counted from 1
- * @param enable enable or disable the specified feature
- * @return error code
- */
-int set_feature_port(const rh_t *instance, uint16_t feature, uint16_t port)
-{
-	assert(instance);
-
-	if (port < 1 || port > instance->port_count)
-		return EINVAL;
-
-	switch (feature) {
-	case USB_HUB_FEATURE_PORT_POWER:   /*8*/
-		{
-			const uint32_t rhda =
-			    OHCI_RD(instance->registers->rh_desc_a);
-			/* No power switching */
-			if (rhda & RHDA_NPS_FLAG)
-				return EOK;
-			/* Ganged power switching, one port powers all */
-			if (!(rhda & RHDA_PSM_FLAG)) {
-				OHCI_WR(instance->registers->rh_status,
-				    RHS_SET_GLOBAL_POWER);
-				return EOK;
-			}
-		}
-			/* Fall through */
-	case USB_HUB_FEATURE_PORT_ENABLE:  /*1*/
-	case USB_HUB_FEATURE_PORT_SUSPEND: /*2*/
-	case USB_HUB_FEATURE_PORT_RESET:   /*4*/
-		usb_log_debug2("Setting port POWER, ENABLE, SUSPEND or RESET "
-		    "on port %"PRIu16".\n", port);
-		OHCI_WR(instance->registers->rh_port_status[port - 1],
-		    1 << feature);
-		return EOK;
-	default:
-		return ENOTSUP;
-	}
-}
-
-/**
- * Process feature clear request.
- *
- * @param instance root hub instance
- * @param feature feature selector
- * @param port port number, counted from 1
- * @param enable enable or disable the specified feature
- * @return error code
- */
-int clear_feature_port(const rh_t *instance, uint16_t feature, uint16_t port)
-{
-	assert(instance);
-
-	if (port < 1 || port > instance->port_count)
-		return EINVAL;
-
-	/* Enabled features to clear: see page 269 of USB specs */
-	switch (feature)
-	{
-	case USB_HUB_FEATURE_PORT_POWER:          /*8*/
-		{
-			const uint32_t rhda =
-			    OHCI_RD(instance->registers->rh_desc_a);
-			/* No power switching */
-			if (rhda & RHDA_NPS_FLAG)
-				return ENOTSUP;
-			/* Ganged power switching, one port powers all */
-			if (!(rhda & RHDA_PSM_FLAG)) {
-				OHCI_WR(instance->registers->rh_status,
-				    RHS_CLEAR_GLOBAL_POWER);
-				return EOK;
-			}
-			OHCI_WR(instance->registers->rh_port_status[port - 1],
-			    RHPS_CLEAR_PORT_POWER);
-			return EOK;
-		}
-
-	case USB_HUB_FEATURE_PORT_ENABLE:         /*1*/
-		OHCI_WR(instance->registers->rh_port_status[port - 1],
-		    RHPS_CLEAR_PORT_ENABLE);
-		return EOK;
-
-	case USB_HUB_FEATURE_PORT_SUSPEND:        /*2*/
-		OHCI_WR(instance->registers->rh_port_status[port - 1],
-		    RHPS_CLEAR_PORT_SUSPEND);
-		return EOK;
-
-	case USB_HUB_FEATURE_C_PORT_CONNECTION:   /*16*/
-	case USB_HUB_FEATURE_C_PORT_ENABLE:       /*17*/
-	case USB_HUB_FEATURE_C_PORT_SUSPEND:      /*18*/
-	case USB_HUB_FEATURE_C_PORT_OVER_CURRENT: /*19*/
-	case USB_HUB_FEATURE_C_PORT_RESET:        /*20*/
-		usb_log_debug2("Clearing port C_CONNECTION, C_ENABLE, "
-		    "C_SUSPEND, C_OC or C_RESET on port %"PRIu16".\n", port);
-		/* Bit offsets correspond to the feature number */
-		OHCI_WR(instance->registers->rh_port_status[port - 1],
-		    1 << feature);
-		return EOK;
-
-	default:
-		return ENOTSUP;
-	}
-}
-
-/**
- * process one of requests that do not request nor carry additional data
- *
- * Request can be one of USB_DEVREQ_CLEAR_FEATURE, USB_DEVREQ_SET_FEATURE or
- * USB_DEVREQ_SET_ADDRESS.
- * @param instance root hub instance
- * @param request structure containing both request and response information
- * @return error code
- */
-void set_feature(const rh_t *instance, usb_transfer_batch_t *request)
-{
-	assert(instance);
-	assert(request);
-
-	usb_device_request_setup_packet_t *setup_request =
-	    (usb_device_request_setup_packet_t *) request->setup_buffer;
-	switch (setup_request->request_type)
-	{
-	case USB_HUB_REQ_TYPE_SET_PORT_FEATURE:
-		usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n");
-		const int ret = set_feature_port(instance,
-		    setup_request->value, setup_request->index);
-		TRANSFER_END(request, ret);
-
-	case USB_HUB_REQ_TYPE_SET_HUB_FEATURE:
-		/* Chapter 11.16.2 specifies that hub can be recipient
-		 * only for C_HUB_LOCAL_POWER and C_HUB_OVER_CURRENT
-		 * features. It makes no sense to SET either. */
-		usb_log_error("Invalid HUB set feature request.\n");
-		TRANSFER_END(request, ENOTSUP);
-	//TODO: Consider standard USB requests: REMOTE WAKEUP, ENDPOINT STALL
-	default:
-		usb_log_error("Invalid set feature request type: %d\n",
-		    setup_request->request_type);
-		TRANSFER_END(request, ENOTSUP);
-	}
-}
-
-/**
- * process one of requests that do not request nor carry additional data
- *
- * Request can be one of USB_DEVREQ_CLEAR_FEATURE, USB_DEVREQ_SET_FEATURE or
- * USB_DEVREQ_SET_ADDRESS.
- * @param instance root hub instance
- * @param request structure containing both request and response information
- * @return error code
- */
-void clear_feature(const rh_t *instance, usb_transfer_batch_t *request)
-{
-	assert(instance);
-	assert(request);
-
-	usb_device_request_setup_packet_t *setup_request =
-	    (usb_device_request_setup_packet_t *) request->setup_buffer;
-
-	switch (setup_request->request_type)
-	{
-	case USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE:
-		usb_log_debug("USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE\n");
-		const int ret = clear_feature_port(instance,
-		    setup_request->value, setup_request->index);
-		TRANSFER_END(request, ret);
-
-	case USB_HUB_REQ_TYPE_CLEAR_HUB_FEATURE:
-		usb_log_debug("USB_HUB_REQ_TYPE_CLEAR_HUB_FEATURE\n");
-		/*
-		 * Chapter 11.16.2 specifies that only C_HUB_LOCAL_POWER and
-		 * C_HUB_OVER_CURRENT are supported.
-		 * C_HUB_OVER_CURRENT is represented by OHCI RHS_OCIC_FLAG.
-		 * C_HUB_LOCAL_POWER is not supported
-		 * as root hubs do not support local power status feature.
-		 * (OHCI pg. 127) */
-		if (uint16_usb2host(setup_request->value)
-		    == USB_HUB_FEATURE_C_HUB_OVER_CURRENT) {
-			OHCI_WR(instance->registers->rh_status, RHS_OCIC_FLAG);
-			TRANSFER_END(request, EOK);
-		}
-	//TODO: Consider standard USB requests: REMOTE WAKEUP, ENDPOINT STALL
-	default:
-		usb_log_error("Invalid clear feature request type: %d\n",
-		    setup_request->request_type);
-		TRANSFER_END(request, ENOTSUP);
-	}
-}
-
-/**
- * Process hub control request.
- *
- * If needed, writes answer into the request structure.
- * Request can be one of
- * USB_DEVREQ_GET_STATUS,
- * USB_DEVREQ_GET_DESCRIPTOR,
- * USB_DEVREQ_GET_CONFIGURATION,
- * USB_DEVREQ_CLEAR_FEATURE,
- * USB_DEVREQ_SET_FEATURE,
- * USB_DEVREQ_SET_ADDRESS,
- * USB_DEVREQ_SET_DESCRIPTOR or
- * USB_DEVREQ_SET_CONFIGURATION.
- *
- * @param instance root hub instance
- * @param request structure containing both request and response information
- * @return error code
- */
-void control_request(rh_t *instance, usb_transfer_batch_t *request)
-{
-	assert(instance);
-	assert(request);
-
-	if (!request->setup_buffer) {
-		usb_log_error("Root hub received empty transaction!");
-		TRANSFER_END(request, EBADMEM);
-	}
-
-	if (sizeof(usb_device_request_setup_packet_t) > request->setup_size) {
-		usb_log_error("Setup packet too small\n");
-		TRANSFER_END(request, EOVERFLOW);
-	}
-
-	usb_log_debug2("CTRL packet: %s.\n",
-	    usb_debug_str_buffer((uint8_t *) request->setup_buffer, 8, 8));
-	usb_device_request_setup_packet_t *setup_request =
-	    (usb_device_request_setup_packet_t *) request->setup_buffer;
-	switch (setup_request->request)
-	{
-	case USB_DEVREQ_GET_STATUS:
-		usb_log_debug("USB_DEVREQ_GET_STATUS\n");
-		get_status(instance, request);
-		break;
-
-	case USB_DEVREQ_GET_DESCRIPTOR:
-		usb_log_debug("USB_DEVREQ_GET_DESCRIPTOR\n");
-		get_descriptor(instance, request);
-		break;
-
-	case USB_DEVREQ_GET_CONFIGURATION:
-		usb_log_debug("USB_DEVREQ_GET_CONFIGURATION\n");
-		if (request->buffer_size == 0)
-			TRANSFER_END(request, EOVERFLOW);
-		const uint8_t config = 1;
-		TRANSFER_END_DATA(request, &config, sizeof(config));
-
-	case USB_DEVREQ_CLEAR_FEATURE:
-		usb_log_debug2("USB_DEVREQ_CLEAR_FEATURE\n");
-		clear_feature(instance, request);
-		break;
-
-	case USB_DEVREQ_SET_FEATURE:
-		usb_log_debug2("USB_DEVREQ_SET_FEATURE\n");
-		set_feature(instance, request);
-		break;
-
-	case USB_DEVREQ_SET_ADDRESS:
-		usb_log_debug("USB_DEVREQ_SET_ADDRESS: %u\n",
-		    setup_request->value);
-		if (uint16_usb2host(setup_request->value) > 127)
-			TRANSFER_END(request, EINVAL);
-
-		instance->address = uint16_usb2host(setup_request->value);
-		TRANSFER_END(request, EOK);
-
-	case USB_DEVREQ_SET_CONFIGURATION:
-		usb_log_debug("USB_DEVREQ_SET_CONFIGURATION: %u\n",
-		    uint16_usb2host(setup_request->value));
-		/* We have only one configuration, it's number is 1 */
-		if (uint16_usb2host(setup_request->value) != 1)
-			TRANSFER_END(request, EINVAL);
-		TRANSFER_END(request, EOK);
-
-	/* Both class specific and std is optional for hubs */
-	case USB_DEVREQ_SET_DESCRIPTOR:
-	/* Hubs have only one interface GET/SET is not supported */
-	case USB_DEVREQ_GET_INTERFACE:
-	case USB_DEVREQ_SET_INTERFACE:
-	default:
-		/* Hub class GET_STATE(2) falls in here too. */
-		usb_log_error("Received unsupported request: %d.\n",
-		    setup_request->request);
-		TRANSFER_END(request, ENOTSUP);
-	}
-}
-/**
- * @}
- */
Index: uspace/drv/bus/usb/ohci/root_hub.h
===================================================================
--- uspace/drv/bus/usb/ohci/root_hub.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ 	(revision )
@@ -1,79 +1,0 @@
-/*
- * Copyright (c) 2011 Jan Vesely
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-/** @addtogroup drvusbohci
- * @{
- */
-/** @file
- * @brief OHCI driver
- */
-#ifndef DRV_OHCI_ROOT_HUB_H
-#define DRV_OHCI_ROOT_HUB_H
-
-#include <usb/usb.h>
-#include <usb/dev/driver.h>
-#include <usb/host/usb_transfer_batch.h>
-
-#include "ohci_regs.h"
-
-#define HUB_DESCRIPTOR_MAX_SIZE (7 + 2 + 2)
-
-/**
- * ohci root hub representation
- */
-typedef struct rh {
-	fibril_mutex_t guard;
-	/** pointer to ohci driver registers */
-	ohci_regs_t *registers;
-	/** usb address of the root hub */
-	usb_address_t address;
-	/** hub port count */
-	size_t port_count;
-	/** interrupt transfer waiting for an actual interrupt to occur */
-	usb_transfer_batch_t *unfinished_interrupt_transfer;
-	/** size of interrupt buffer */
-	size_t interrupt_mask_size;
-	/** Descriptors */
-	struct {
-		usb_standard_configuration_descriptor_t configuration;
-		usb_standard_interface_descriptor_t interface;
-		usb_standard_endpoint_descriptor_t endpoint;
-		uint8_t hub[HUB_DESCRIPTOR_MAX_SIZE];
-	} __attribute__ ((packed)) descriptors;
-	/** size of hub descriptor */
-	size_t hub_descriptor_size;
-} rh_t;
-
-void rh_init(rh_t *instance, ohci_regs_t *regs);
-
-void rh_request(rh_t *instance, usb_transfer_batch_t *request);
-
-void rh_interrupt(rh_t *instance);
-#endif
-/**
- * @}
- */
Index: uspace/drv/bus/usb/uhci/Makefile
===================================================================
--- uspace/drv/bus/usb/uhci/Makefile	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/uhci/Makefile	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -31,4 +31,5 @@
 LIBS = \
 	$(LIBUSBHOST_PREFIX)/libusbhost.a \
+	$(LIBUSBVIRT_PREFIX)/libusbvirt.a \
 	$(LIBUSB_PREFIX)/libusb.a \
 	$(LIBDRV_PREFIX)/libdrv.a
@@ -36,5 +37,7 @@
 EXTRA_CFLAGS += \
 	-I$(LIBUSB_PREFIX)/include \
+	-I$(LIBUSBDEV_PREFIX)/include \
 	-I$(LIBUSBHOST_PREFIX)/include \
+	-I$(LIBUSBVIRT_PREFIX)/include \
 	-I$(LIBDRV_PREFIX)/include
 
@@ -45,8 +48,8 @@
 	main.c \
 	res.c \
-	root_hub.c \
 	transfer_list.c \
 	uhci.c \
 	uhci_batch.c \
+	uhci_rh.c \
 	hw_struct/transfer_descriptor.c
 
Index: uspace/drv/bus/usb/uhci/hc.c
===================================================================
--- uspace/drv/bus/usb/uhci/hc.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/uhci/hc.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -85,18 +85,24 @@
 static int hc_init_mem_structures(hc_t *instance);
 static int hc_init_transfer_lists(hc_t *instance);
-static int hc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch);
 
 static int hc_interrupt_emulator(void *arg);
 static int hc_debug_checker(void *arg);
 
-enum {
-	/** Number of PIO ranges used in IRQ code */
-	hc_irq_pio_range_count =
-	    sizeof(uhci_irq_pio_ranges) / sizeof(irq_pio_range_t),
-
-	/* Number of commands used in IRQ code */
-	hc_irq_cmd_count =
-	    sizeof(uhci_irq_commands) / sizeof(irq_cmd_t)
-};
+
+/** Get number of PIO ranges used in IRQ code.
+ * @return Number of ranges.
+ */
+size_t hc_irq_pio_range_count(void)
+{
+	return sizeof(uhci_irq_pio_ranges) / sizeof(irq_pio_range_t);
+}
+
+/** Get number of commands used in IRQ code.
+ * @return Number of commands.
+ */
+size_t hc_irq_cmd_count(void)
+{
+	return sizeof(uhci_irq_commands) / sizeof(irq_cmd_t);
+}
 
 /** Generate IRQ code.
@@ -123,6 +129,6 @@
 	memcpy(cmds, uhci_irq_commands, sizeof(uhci_irq_commands));
 	uhci_regs_t *registers = (uhci_regs_t *) RNGABSPTR(*regs);
-	cmds[0].addr = &registers->usbsts;
-	cmds[3].addr = &registers->usbsts;
+	cmds[0].addr = (void*)&registers->usbsts;
+	cmds[3].addr = (void*)&registers->usbsts;
 
 	return EOK;
@@ -141,29 +147,30 @@
     interrupt_handler_t handler)
 {
-	int rc;
-	irq_pio_range_t irq_ranges[hc_irq_pio_range_count];
-	irq_cmd_t irq_cmds[hc_irq_cmd_count];
-	rc = hc_get_irq_code(irq_ranges, sizeof(irq_ranges), irq_cmds,
+	assert(device);
+	irq_pio_range_t irq_ranges[hc_irq_pio_range_count()];
+	irq_cmd_t irq_cmds[hc_irq_cmd_count()];
+
+	int ret = hc_get_irq_code(irq_ranges, sizeof(irq_ranges), irq_cmds,
 	    sizeof(irq_cmds), regs);
-	if (rc != EOK) {
+	if (ret != EOK) {
 		usb_log_error("Failed to generate IRQ commands: %s.\n",
-		    str_error(rc));
-		return rc;
+		    str_error(ret));
+		return ret;
 	}
 
 	irq_code_t irq_code = {
-		.rangecount = hc_irq_pio_range_count,
+		.rangecount = hc_irq_pio_range_count(),
 		.ranges = irq_ranges,
-		.cmdcount = hc_irq_cmd_count,
+		.cmdcount = hc_irq_cmd_count(),
 		.cmds = irq_cmds
 	};
 
         /* Register handler to avoid interrupt lockup */
-        rc = register_interrupt_handler(device, irq, handler, &irq_code);
-        if (rc != EOK) {
-    		usb_log_error("Failed to register interrupt handler: %s.\n",
-    		    str_error(rc));
-    		return rc;
-    	}
+        ret = register_interrupt_handler(device, irq, handler, &irq_code);
+        if (ret != EOK) {
+		usb_log_error("Failed to register interrupt handler: %s.\n",
+		    str_error(ret));
+		return ret;
+	}
 
 	return EOK;
@@ -240,6 +247,7 @@
 int hc_init(hc_t *instance, addr_range_t *regs, bool interrupts)
 {
+	assert(instance);
+	assert(regs);
 	assert(regs->size >= sizeof(uhci_regs_t));
-	int rc;
 
 	instance->hw_interrupts = interrupts;
@@ -248,28 +256,22 @@
 	/* allow access to hc control registers */
 	uhci_regs_t *io;
-	rc = pio_enable_range(regs, (void **) &io);
-	if (rc != EOK) {
+	int ret = pio_enable_range(regs, (void **) &io);
+	if (ret != EOK) {
 		usb_log_error("Failed to gain access to registers at %p: %s.\n",
-		    io, str_error(rc));
-		return rc;
-	}
-
+	            io, str_error(ret));
+		return ret;
+	}
 	instance->registers = io;
+
 	usb_log_debug(
 	    "Device registers at %p (%zuB) accessible.\n", io, regs->size);
 
-	rc = hc_init_mem_structures(instance);
-	if (rc != EOK) {
-		usb_log_error("Failed to initialize UHCI memory structures: %s.\n",
-		    str_error(rc));
-		return rc;
-	}
-
-	hcd_init(&instance->generic, USB_SPEED_FULL,
-	    BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11);
-
-	instance->generic.private_data = instance;
-	instance->generic.schedule = hc_schedule;
-	instance->generic.ep_add_hook = NULL;
+	ret = hc_init_mem_structures(instance);
+	if (ret != EOK) {
+		usb_log_error("Failed to init UHCI memory structures: %s.\n",
+		    str_error(ret));
+		// TODO: we should disable pio here
+		return ret;
+	}
 
 	hc_init_hw(instance);
@@ -280,4 +282,6 @@
 	}
 	(void)hc_debug_checker;
+
+	uhci_rh_init(&instance->rh, instance->registers->ports, "uhci");
 
 	return EOK;
@@ -443,4 +447,8 @@
 	assert(instance);
 	assert(batch);
+
+	if (batch->ep->address == uhci_rh_get_address(&instance->rh))
+		return uhci_rh_schedule(&instance->rh, batch);
+
 	uhci_transfer_batch_t *uhci_batch = uhci_transfer_batch_get(batch);
 	if (!uhci_batch) {
Index: uspace/drv/bus/usb/uhci/hc.h
===================================================================
--- uspace/drv/bus/usb/uhci/hc.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/uhci/hc.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -39,5 +39,7 @@
 #include <device/hw_res_parsed.h>
 #include <fibril.h>
+#include <macros.h>
 #include <usb/host/hcd.h>
+#include "uhci_rh.h"
 
 #include "transfer_list.h"
@@ -46,5 +48,5 @@
 typedef struct uhci_regs {
 	/** Command register, controls HC behaviour */
-	uint16_t usbcmd;
+	ioport16_t usbcmd;
 #define UHCI_CMD_MAX_PACKET (1 << 7)
 #define UHCI_CMD_CONFIGURE  (1 << 6)
@@ -57,5 +59,5 @@
 
 	/** Status register, 1 means interrupt is asserted (if enabled) */
-	uint16_t usbsts;
+	ioport16_t usbsts;
 #define UHCI_STATUS_HALTED (1 << 5)
 #define UHCI_STATUS_PROCESS_ERROR (1 << 4)
@@ -68,5 +70,5 @@
 
 	/** Interrupt enabled registers */
-	uint16_t usbintr;
+	ioport16_t usbintr;
 #define UHCI_INTR_SHORT_PACKET (1 << 3)
 #define UHCI_INTR_COMPLETE (1 << 2)
@@ -75,11 +77,14 @@
 
 	/** Register stores frame number used in SOF packet */
-	uint16_t frnum;
+	ioport16_t frnum;
 
 	/** Pointer(physical) to the Frame List */
-	uint32_t flbaseadd;
+	ioport32_t flbaseadd;
 
 	/** SOF modification to match external timers */
-	uint8_t sofmod;
+	ioport8_t sofmod;
+
+	PADD8[3];
+	ioport16_t ports[];
 } uhci_regs_t;
 
@@ -92,7 +97,5 @@
 /** Main UHCI driver structure */
 typedef struct hc {
-	/** Generic HCD driver structure */
-	hcd_t generic;
-
+	uhci_rh_t rh;
 	/** Addresses of I/O registers */
 	uhci_regs_t *registers;
@@ -121,4 +124,6 @@
 } hc_t;
 
+size_t hc_irq_pio_range_count(void);
+size_t hc_irq_cmd_count(void);
 int hc_register_irq_handler(ddf_dev_t *, addr_range_t *, int,
     interrupt_handler_t);
@@ -127,4 +132,5 @@
 void hc_interrupt(hc_t *instance, uint16_t status);
 int hc_init(hc_t *instance, addr_range_t *regs, bool interupts);
+int hc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch);
 
 /** Safely dispose host controller internal structures
Index: uspace/drv/bus/usb/uhci/main.c
===================================================================
--- uspace/drv/bus/usb/uhci/main.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/uhci/main.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -36,5 +36,4 @@
 #include <str_error.h>
 
-#include <usb/ddfiface.h>
 #include <usb/debug.h>
 
Index: uspace/drv/bus/usb/uhci/res.c
===================================================================
--- uspace/drv/bus/usb/uhci/res.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/uhci/res.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -62,5 +62,5 @@
 	hw_res_list_parsed_t hw_res;
 	hw_res_list_parsed_init(&hw_res);
-	const int ret =  hw_res_get_list_parsed(parent_sess, &hw_res, 0);
+	const int ret = hw_res_get_list_parsed(parent_sess, &hw_res, 0);
 	async_hangup(parent_sess);
 	if (ret != EOK) {
Index: uspace/drv/bus/usb/uhci/root_hub.c
===================================================================
--- uspace/drv/bus/usb/uhci/root_hub.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ 	(revision )
@@ -1,73 +1,0 @@
-/*
- * Copyright (c) 2011 Jan Vesely
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-/** @addtogroup drvusbuhci
- * @{
- */
-/** @file
- * @brief UHCI driver
- */
-#include <assert.h>
-#include <errno.h>
-#include <str_error.h>
-#include <stdio.h>
-
-#include <usb/debug.h>
-
-#include "root_hub.h"
-
-/** Root hub initialization
- * @param[in] instance RH structure to initialize
- * @param[in] fun DDF function representing UHCI root hub
- * @param[in] reg_addr Address of root hub status and control registers.
- * @param[in] reg_size Size of accessible address space.
- * @return Error code.
- */
-int rh_init(rh_t *instance, ddf_fun_t *fun, uintptr_t reg_addr, size_t reg_size)
-{
-	assert(instance);
-	assert(fun);
-
-	/* Initialize resource structure */
-	instance->resource_list.count = 1;
-	instance->resource_list.resources = &instance->io_regs;
-
-	instance->io_regs.type = IO_RANGE;
-	instance->io_regs.res.io_range.address = reg_addr;
-	instance->io_regs.res.io_range.size = reg_size;
-	instance->io_regs.res.io_range.endianness = LITTLE_ENDIAN;
-
-	const int ret = ddf_fun_add_match_id(fun, "usb&uhci&root-hub", 100);
-	if (ret != EOK) {
-		usb_log_error("Failed to add root hub match id: %s\n",
-		    str_error(ret));
-	}
-	return ret;
-}
-/**
- * @}
- */
Index: uspace/drv/bus/usb/uhci/root_hub.h
===================================================================
--- uspace/drv/bus/usb/uhci/root_hub.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ 	(revision )
@@ -1,55 +1,0 @@
-/*
- * Copyright (c) 2011 Jan Vesely
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup drvusbuhci
- * @{
- */
-/** @file
- * @brief UHCI driver
- */
-#ifndef DRV_UHCI_RH_H
-#define DRV_UHCI_RH_H
-
-#include <ddf/driver.h>
-#include <ops/hw_res.h>
-
-/** DDF support structure for uhci_rhd driver, provides I/O resources */
-typedef struct rh {
-	/** List of resources available to the root hub. */
-	hw_resource_list_t resource_list;
-	/** The only resource in the RH resource list */
-	hw_resource_t io_regs;
-} rh_t;
-
-int rh_init(
-    rh_t *instance, ddf_fun_t *fun, uintptr_t reg_addr, size_t reg_size);
-
-#endif
-/**
- * @}
- */
Index: uspace/drv/bus/usb/uhci/uhci.c
===================================================================
--- uspace/drv/bus/usb/uhci/uhci.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/uhci/uhci.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -34,14 +34,10 @@
  */
 
-/* XXX Fix this */
-#define _DDF_DATA_IMPLANT
-
 #include <errno.h>
-#include <stdbool.h>
 #include <str_error.h>
 #include <ddf/interrupt.h>
-#include <usb_iface.h>
-#include <usb/ddfiface.h>
 #include <usb/debug.h>
+#include <usb/host/hcd.h>
+#include <usb/host/ddf_helpers.h>
 
 #include "uhci.h"
@@ -49,24 +45,5 @@
 #include "res.h"
 #include "hc.h"
-#include "root_hub.h"
 
-/** Structure representing both functions of UHCI hc, USB host controller
- * and USB root hub */
-typedef struct uhci {
-	/** Pointer to DDF representation of UHCI host controller */
-	ddf_fun_t *hc_fun;
-	/** Pointer to DDF representation of UHCI root hub */
-	ddf_fun_t *rh_fun;
-
-	/** Internal driver's representation of UHCI host controller */
-	hc_t hc;
-	/** Internal driver's representation of UHCI root hub */
-	rh_t rh;
-} uhci_t;
-
-static inline uhci_t *dev_to_uhci(ddf_dev_t *dev)
-{
-	return ddf_dev_data_get(dev);
-}
 
 /** IRQ handling callback, forward status from call to diver structure.
@@ -79,62 +56,12 @@
 {
 	assert(dev);
-	uhci_t *uhci = dev_to_uhci(dev);
-	if (!uhci) {
+	hcd_t *hcd = dev_to_hcd(dev);
+	if (!hcd || !hcd->private_data) {
 		usb_log_error("Interrupt on not yet initialized device.\n");
 		return;
 	}
 	const uint16_t status = IPC_GET_ARG1(*call);
-	hc_interrupt(&uhci->hc, status);
+	hc_interrupt(hcd->private_data, status);
 }
-
-/** Operations supported by the HC driver */
-static ddf_dev_ops_t hc_ops = {
-	.interfaces[USBHC_DEV_IFACE] = &hcd_iface, /* see iface.h/c */
-};
-
-/** Gets handle of the respective hc.
- *
- * @param[in] fun DDF function of uhci device.
- * @param[out] handle Host cotnroller handle.
- * @return Error code.
- */
-static int usb_iface_get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle)
-{
-	ddf_fun_t *hc_fun = dev_to_uhci(ddf_fun_get_dev(fun))->hc_fun;
-	assert(hc_fun);
-
-	if (handle != NULL)
-		*handle = ddf_fun_get_handle(hc_fun);
-	return EOK;
-}
-
-/** USB interface implementation used by RH */
-static usb_iface_t usb_iface = {
-	.get_hc_handle = usb_iface_get_hc_handle,
-};
-
-/** Get root hub hw resources (I/O registers).
- *
- * @param[in] fun Root hub function.
- * @return Pointer to the resource list used by the root hub.
- */
-static hw_resource_list_t *get_resource_list(ddf_fun_t *fun)
-{
-	rh_t *rh = ddf_fun_data_get(fun);
-	assert(rh);
-	return &rh->resource_list;
-}
-
-/** Interface to provide the root hub driver with hw info */
-static hw_res_ops_t hw_res_iface = {
-	.get_resource_list = get_resource_list,
-	.enable_interrupt = NULL,
-};
-
-/** RH function support for uhci_rhd */
-static ddf_dev_ops_t rh_ops = {
-	.interfaces[USB_DEV_IFACE] = &usb_iface,
-	.interfaces[HW_RES_DEV_IFACE] = &hw_res_iface
-};
 
 /** Initialize hc and rh DDF structures and their respective drivers.
@@ -150,71 +77,46 @@
 int device_setup_uhci(ddf_dev_t *device)
 {
-	bool ih_registered = false;
-	bool hc_inited = false;
-	bool fun_bound = false;
-	int rc;
-
 	if (!device)
 		return EBADMEM;
-
-	uhci_t *instance = ddf_dev_data_alloc(device, sizeof(uhci_t));
-	if (instance == NULL) {
-		usb_log_error("Failed to allocate OHCI driver.\n");
-		return ENOMEM;
-	}
-
-	instance->hc_fun = ddf_fun_create(device, fun_exposed, "uhci_hc");
-	if (instance->hc_fun == NULL) {
-		usb_log_error("Failed to create UHCI HC function.\n");
-		rc = ENOMEM;
-		goto error;
-	}
-
-	ddf_fun_set_ops(instance->hc_fun, &hc_ops);
-	ddf_fun_data_implant(instance->hc_fun, &instance->hc.generic);
-
-	instance->rh_fun = ddf_fun_create(device, fun_inner, "uhci_rh");
-	if (instance->rh_fun == NULL) {
-		usb_log_error("Failed to create UHCI RH function.\n");
-		rc = ENOMEM;
-		goto error;
-	}
-
-	ddf_fun_set_ops(instance->rh_fun, &rh_ops);
-	ddf_fun_data_implant(instance->rh_fun, &instance->rh);
 
 	addr_range_t regs;
 	int irq = 0;
 
-	rc = get_my_registers(device, &regs, &irq);
-	if (rc != EOK) {
+	int ret = get_my_registers(device, &regs, &irq);
+	if (ret != EOK) {
 		usb_log_error("Failed to get I/O addresses for %" PRIun ": %s.\n",
-		    ddf_dev_get_handle(device), str_error(rc));
-		goto error;
+		    ddf_dev_get_handle(device), str_error(ret));
+		return ret;
 	}
 	usb_log_debug("I/O regs at %p (size %zu), IRQ %d.\n",
 	    RNGABSPTR(regs), RNGSZ(regs), irq);
 
-	rc = disable_legacy(device);
-	if (rc != EOK) {
-		usb_log_error("Failed to disable legacy USB: %s.\n",
-		    str_error(rc));
-		goto error;
+	ret = hcd_ddf_setup_hc(device, USB_SPEED_FULL,
+	    BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11);
+	if (ret != EOK) {
+		usb_log_error("Failed to setup generic HCD.\n");
+		return ret;
 	}
 
-	rc = hc_register_irq_handler(device, &regs, irq, irq_handler);
-	if (rc != EOK) {
-		usb_log_error("Failed to register interrupt handler: %s.\n",
-		    str_error(rc));
-		goto error;
+	hc_t *hc = malloc(sizeof(hc_t));
+	if (!hc) {
+		usb_log_error("Failed to allocate UHCI HC structure.\n");
+		hcd_ddf_clean_hc(device);
+		return ENOMEM;
 	}
 
-	ih_registered = true;
+	ret = hc_register_irq_handler(device, &regs, irq, irq_handler);
+	if (ret != EOK) {
+		usb_log_error("Failed to register interrupt handler: %s.\n",
+		    str_error(ret));
+		hcd_ddf_clean_hc(device);
+		return ret;
+	}
 
 	bool interrupts = false;
-	rc = enable_interrupts(device);
-	if (rc != EOK) {
+	ret = enable_interrupts(device);
+	if (ret != EOK) {
 		usb_log_warning("Failed to enable interrupts: %s."
-		    " Falling back to polling.\n", str_error(rc));
+		    " Falling back to polling.\n", str_error(ret));
 	} else {
 		usb_log_debug("Hw interrupts enabled.\n");
@@ -222,58 +124,37 @@
 	}
 
-	rc = hc_init(&instance->hc, &regs, interrupts);
-	if (rc != EOK) {
-		usb_log_error("Failed to init uhci_hcd: %s.\n", str_error(rc));
-		goto error;
+	ret = disable_legacy(device);
+	if (ret != EOK) {
+		usb_log_error("Failed to disable legacy USB: %s.\n",
+		    str_error(ret));
+		hcd_ddf_clean_hc(device);
+		return ret;
 	}
 
-	hc_inited = true;
-
-	rc = ddf_fun_bind(instance->hc_fun);
-	if (rc != EOK) {
-		usb_log_error("Failed to bind UHCI device function: %s.\n",
-		    str_error(rc));
-		goto error;
+	ret = hc_init(hc, &regs, interrupts);
+	if (ret != EOK) {
+		usb_log_error("Failed to init uhci_hcd: %s.\n", str_error(ret));
+		hcd_ddf_clean_hc(device);
+		// TODO unregister interrupt handler
+		return ret;
 	}
 
-	fun_bound = true;
+	hcd_set_implementation(dev_to_hcd(device), hc, hc_schedule, NULL, NULL);
 
-	rc = ddf_fun_add_to_category(instance->hc_fun, USB_HC_CATEGORY);
-	if (rc != EOK) {
-		usb_log_error("Failed to add UHCI to HC class: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	rc = rh_init(&instance->rh, instance->rh_fun,
-	    (uintptr_t)instance->hc.registers + 0x10, 4);
-	if (rc != EOK) {
+	/*
+	 * Creating root hub registers a new USB device so HC
+	 * needs to be ready at this time.
+	 */
+	ret = hcd_ddf_setup_root_hub(device);
+	if (ret != EOK) {
+		hc_fini(hc);
+		hcd_ddf_clean_hc(device);
+		// TODO unregister interrupt handler
 		usb_log_error("Failed to setup UHCI root hub: %s.\n",
-		    str_error(rc));
-		goto error;
-	}
-
-	rc = ddf_fun_bind(instance->rh_fun);
-	if (rc != EOK) {
-		usb_log_error("Failed to register UHCI root hub: %s.\n",
-		    str_error(rc));
-		goto error;
+		    str_error(ret));
+		return ret;
 	}
 
 	return EOK;
-
-error:
-	if (fun_bound)
-		ddf_fun_unbind(instance->hc_fun);
-	if (hc_inited)
-		hc_fini(&instance->hc);
-	if (ih_registered)
-		unregister_interrupt_handler(device, irq);
-	if (instance->hc_fun != NULL)
-		ddf_fun_destroy(instance->hc_fun);
-	if (instance->rh_fun != NULL) {
-		ddf_fun_destroy(instance->rh_fun);
-	}
-	return rc;
 }
 /**
Index: uspace/drv/bus/usb/uhci/uhci_rh.c
===================================================================
--- uspace/drv/bus/usb/uhci/uhci_rh.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
+++ uspace/drv/bus/usb/uhci/uhci_rh.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -0,0 +1,487 @@
+/*
+ * Copyright (c) 2013 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <assert.h>
+#include <macros.h>
+#include <usb/debug.h>
+#include <usb/classes/hub.h>
+#include <ddi.h>
+
+#include "uhci_rh.h"
+
+enum {
+	UHCI_RH_PORT_COUNT = 2,
+	UHCI_PORT_BYTES = STATUS_BYTES(UHCI_RH_PORT_COUNT),
+};
+
+/** Hub descriptor. */
+static const struct {
+	/** Common hub descriptor header */
+	usb_hub_descriptor_header_t header;
+	/** Port removable status bits */
+	uint8_t removable[UHCI_PORT_BYTES];
+	/** Port powered status bits */
+	uint8_t powered[UHCI_PORT_BYTES];
+} __attribute__((packed)) hub_descriptor = {
+	.header = {
+		.length = sizeof(hub_descriptor),
+		.descriptor_type = USB_DESCTYPE_HUB,
+		.port_count = UHCI_RH_PORT_COUNT,
+		.characteristics =
+		    HUB_CHAR_NO_POWER_SWITCH_FLAG | HUB_CHAR_NO_OC_FLAG,
+		.power_good_time = 50,
+		.max_current = 0,
+	},
+	.removable = { 0 },
+	.powered = { 0xFF },
+};
+
+static usbvirt_device_ops_t ops;
+
+/** Initialize uhci rh structure.
+ * @param instance Memory place to initialize.
+ * @param ports Pointer to TWO UHCI RH port registers.
+ * @param name device name, passed to virthub init
+ * @return Error code, EOK on success.
+ */
+int uhci_rh_init(uhci_rh_t *instance, ioport16_t *ports, const char *name)
+{
+	assert(instance);
+	instance->ports[0] = ports;
+	instance->ports[1] = ports + 1;
+	instance->reset_changed[0] = false;
+	instance->reset_changed[1] = false;
+	return virthub_base_init(&instance->base, name, &ops, instance,
+	    NULL, &hub_descriptor.header, HUB_STATUS_CHANGE_PIPE);
+}
+
+/** Schedule USB batch for the root hub.
+ *
+ * @param instance UHCI rh instance
+ * @param batch USB communication batch
+ * @return EOK.
+ *
+ * The result of scheduling is always EOK. The result of communication does
+ * not have to be.
+ */
+int uhci_rh_schedule(uhci_rh_t *instance, usb_transfer_batch_t *batch)
+{
+	assert(instance);
+	assert(batch);
+
+	const usb_target_t target = {{
+		.address = batch->ep->address,
+		.endpoint = batch->ep->endpoint
+	}};
+	batch->error = virthub_base_request(&instance->base, target,
+	    usb_transfer_batch_direction(batch), (void*)batch->setup_buffer,
+	    batch->buffer, batch->buffer_size, &batch->transfered_size);
+	usb_transfer_batch_finish(batch, NULL);
+	usb_transfer_batch_destroy(batch);
+	return EOK;
+}
+
+/** UHCI port register bits */
+enum {
+	STATUS_CONNECTED         = (1 << 0),
+	STATUS_CONNECTED_CHANGED = (1 << 1),
+	STATUS_ENABLED           = (1 << 2),
+	STATUS_ENABLED_CHANGED   = (1 << 3),
+	STATUS_LINE_D_PLUS       = (1 << 4),
+	STATUS_LINE_D_MINUS      = (1 << 5),
+	STATUS_RESUME            = (1 << 6),
+	STATUS_ALWAYS_ONE        = (1 << 7),
+
+	STATUS_LOW_SPEED = (1 <<  8),
+	STATUS_IN_RESET  = (1 <<  9),
+	STATUS_SUSPEND   = (1 << 12),
+
+	STATUS_CHANGE_BITS = STATUS_CONNECTED_CHANGED | STATUS_ENABLED_CHANGED,
+	STATUS_WC_BITS = STATUS_CHANGE_BITS,
+};
+
+/* HUB ROUTINES IMPLEMENTATION */
+
+static void uhci_port_reset_enable(ioport16_t *port)
+{
+	assert(port);
+	uint16_t port_status = pio_read_16(port);
+	/* We don't wan to remove changes, that's hub drivers work */
+	port_status &= ~STATUS_WC_BITS;
+	port_status |= STATUS_IN_RESET;
+	pio_write_16(port, port_status);
+	async_usleep(50000);
+	port_status = pio_read_16(port);
+	port_status &= ~STATUS_IN_RESET;
+	pio_write_16(port, port_status);
+	while ((port_status = pio_read_16(port)) & STATUS_IN_RESET);
+	/* PIO delay, should not be longer than 3ms as the device might
+	 * enter suspend state. */
+	udelay(10);
+	/* Drop ConnectionChange as some UHCI hw
+	 * sets this bit after reset, that is incorrect */
+	port_status &= ~STATUS_WC_BITS;
+	pio_write_16(port, port_status | STATUS_ENABLED | STATUS_CONNECTED_CHANGED);
+}
+#define TEST_SIZE_INIT(size, port, hub) \
+do { \
+	if (uint16_usb2host(setup_packet->length) != size) \
+		return ESTALL; \
+	port = uint16_usb2host(setup_packet->index) - 1; \
+	if (port != 0 && port != 1) \
+		return EINVAL; \
+	hub = virthub_get_data(device); \
+	assert(hub);\
+} while (0)
+
+#define RH_DEBUG(d, port, msg, ...) \
+	if ((int)port >= 0) \
+		usb_log_debug("%s: rh-%d: " msg, d->name, port, ##__VA_ARGS__); \
+	else \
+		usb_log_debug("%s: rh: " msg, d->name, ##__VA_ARGS__) \
+
+/** USB HUB port state request handler.
+ * @param device Virtual hub device
+ * @param setup_packet USB setup stage data.
+ * @param[out] data destination data buffer, size must be at least
+ *             setup_packet->length bytes
+ * @param[out] act_size Sized of the valid response part of the buffer.
+ * @return Error code.
+ *
+ * Do not confuse with port status. Port state reports data line states,
+ * it is usefull for debuging purposes only.
+ */
+static int req_get_port_state(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet,
+    uint8_t *data, size_t *act_size)
+{
+	uhci_rh_t *hub;
+	unsigned port;
+	TEST_SIZE_INIT(1, port, hub);
+	if (setup_packet->value != 0)
+		return EINVAL;
+
+	const uint16_t value = pio_read_16(hub->ports[port]);
+	data[0] = ((value & STATUS_LINE_D_MINUS) ? 1 : 0)
+	    | ((value & STATUS_LINE_D_PLUS) ? 2 : 0);
+	RH_DEBUG(device, port, "Bus state %" PRIx8 "(source %" PRIx16")\n",
+	    data[0], value);
+	*act_size = 1;
+	return EOK;
+}
+
+#define BIT_VAL(val, bit) \
+	((val & bit) ? 1 : 0)
+#define UHCI2USB(val, bit, feat) \
+	(BIT_VAL(val, bit) << feat)
+
+/** Port status request handler.
+ * @param device Virtual hub device
+ * @param setup_packet USB setup stage data.
+ * @param[out] data destination data buffer, size must be at least
+ *             setup_packet->length bytes
+ * @param[out] act_size Sized of the valid response part of the buffer.
+ * @return Error code.
+ *
+ * Converts status reported via ioport to USB format.
+ * @note: reset change status needs to be handled in sw.
+ */
+static int req_get_port_status(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet,
+    uint8_t *data, size_t *act_size)
+{
+	uhci_rh_t *hub;
+	unsigned port;
+	TEST_SIZE_INIT(4, port, hub);
+	if (setup_packet->value != 0)
+		return EINVAL;
+
+	const uint16_t val = pio_read_16(hub->ports[port]);
+	const uint32_t status = uint32_host2usb(
+	    UHCI2USB(val, STATUS_CONNECTED, USB_HUB_FEATURE_PORT_CONNECTION) |
+	    UHCI2USB(val, STATUS_ENABLED, USB_HUB_FEATURE_PORT_ENABLE) |
+	    UHCI2USB(val, STATUS_SUSPEND, USB_HUB_FEATURE_PORT_SUSPEND) |
+	    UHCI2USB(val, STATUS_IN_RESET, USB_HUB_FEATURE_PORT_RESET) |
+	    UHCI2USB(val, STATUS_ALWAYS_ONE, USB_HUB_FEATURE_PORT_POWER) |
+	    UHCI2USB(val, STATUS_LOW_SPEED, USB_HUB_FEATURE_PORT_LOW_SPEED) |
+	    UHCI2USB(val, STATUS_CONNECTED_CHANGED, USB_HUB_FEATURE_C_PORT_CONNECTION) |
+	    UHCI2USB(val, STATUS_ENABLED_CHANGED, USB_HUB_FEATURE_C_PORT_ENABLE) |
+//	    UHCI2USB(val, STATUS_SUSPEND, USB_HUB_FEATURE_C_PORT_SUSPEND) |
+	    ((hub->reset_changed[port] ? 1 : 0) << USB_HUB_FEATURE_C_PORT_RESET)
+	);
+	RH_DEBUG(device, port, "Port status %" PRIx32 " (source %" PRIx16
+	    "%s)\n", uint32_usb2host(status), val,
+	    hub->reset_changed[port] ? "-reset" : "");
+	memcpy(data, &status, sizeof(status));
+	*act_size = sizeof(status);;
+	return EOK;
+}
+
+/** Port clear feature request handler.
+ * @param device Virtual hub device
+ * @param setup_packet USB setup stage data.
+ * @param[out] data destination data buffer, size must be at least
+ *             setup_packet->length bytes
+ * @param[out] act_size Sized of the valid response part of the buffer.
+ * @return Error code.
+ */
+static int req_clear_port_feature(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet,
+    uint8_t *data, size_t *act_size)
+{
+	uhci_rh_t *hub;
+	unsigned port;
+	TEST_SIZE_INIT(0, port, hub);
+	const unsigned feature = uint16_usb2host(setup_packet->value);
+	const uint16_t status = pio_read_16(hub->ports[port]);
+	const uint16_t val = status & (~STATUS_WC_BITS);
+	switch (feature) {
+	case USB_HUB_FEATURE_PORT_ENABLE:
+		RH_DEBUG(device, port, "Clear port enable (status %"
+		    PRIx16 ")\n", status);
+		pio_write_16(hub->ports[port], val & ~STATUS_ENABLED);
+		break;
+	case USB_HUB_FEATURE_PORT_SUSPEND:
+		RH_DEBUG(device, port, "Clear port suspend (status %"
+		    PRIx16 ")\n", status);
+		pio_write_16(hub->ports[port], val & ~STATUS_SUSPEND);
+		// TODO we should do resume magic
+		usb_log_warning("Resume is not implemented on port %u\n", port);
+		break;
+	case USB_HUB_FEATURE_PORT_POWER:
+		RH_DEBUG(device, port, "Clear port power (status %" PRIx16 ")\n",
+		    status);
+		/* We are always powered */
+		usb_log_warning("Tried to power off port %u\n", port);
+		break;
+	case USB_HUB_FEATURE_C_PORT_CONNECTION:
+		RH_DEBUG(device, port, "Clear port conn change (status %"
+		    PRIx16 ")\n", status);
+		pio_write_16(hub->ports[port], val | STATUS_CONNECTED_CHANGED);
+		break;
+	case USB_HUB_FEATURE_C_PORT_RESET:
+		RH_DEBUG(device, port, "Clear port reset change (status %"
+		    PRIx16 ")\n", status);
+		hub->reset_changed[port] = false;
+		break;
+	case USB_HUB_FEATURE_C_PORT_ENABLE:
+		RH_DEBUG(device, port, "Clear port enable change (status %"
+		    PRIx16 ")\n", status);
+		pio_write_16(hub->ports[port], status | STATUS_ENABLED_CHANGED);
+		break;
+	case USB_HUB_FEATURE_C_PORT_SUSPEND:
+		RH_DEBUG(device, port, "Clear port suspend change (status %"
+		    PRIx16 ")\n", status);
+		//TODO
+		return ENOTSUP;
+	case USB_HUB_FEATURE_C_PORT_OVER_CURRENT:
+		RH_DEBUG(device, port, "Clear port OC change (status %"
+		    PRIx16 ")\n", status);
+		/* UHCI Does not report over current */
+		//TODO: newer chips do, but some have broken wiring 
+		break;
+	default:
+		RH_DEBUG(device, port, "Clear unknown feature %d (status %"
+		    PRIx16 ")\n", feature, status);
+		usb_log_warning("Clearing feature %d is unsupported\n",
+		    feature);
+		return ESTALL;
+	}
+	return EOK;
+}
+
+/** Port set feature request handler.
+ * @param device Virtual hub device
+ * @param setup_packet USB setup stage data.
+ * @param[out] data destination data buffer, size must be at least
+ *             setup_packet->length bytes
+ * @param[out] act_size Sized of the valid response part of the buffer.
+ * @return Error code.
+ */
+static int req_set_port_feature(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet,
+    uint8_t *data, size_t *act_size)
+{
+	uhci_rh_t *hub;
+	unsigned port;
+	TEST_SIZE_INIT(0, port, hub);
+	const unsigned feature = uint16_usb2host(setup_packet->value);
+	const uint16_t status = pio_read_16(hub->ports[port]);
+	switch (feature) {
+	case USB_HUB_FEATURE_PORT_RESET:
+		RH_DEBUG(device, port, "Set port reset before (status %" PRIx16
+		    ")\n", status);
+		uhci_port_reset_enable(hub->ports[port]);
+		hub->reset_changed[port] = true;
+		RH_DEBUG(device, port, "Set port reset after (status %" PRIx16
+		    ")\n", pio_read_16(hub->ports[port]));
+		break;
+	case USB_HUB_FEATURE_PORT_SUSPEND:
+		RH_DEBUG(device, port, "Set port suspend (status %" PRIx16
+		    ")\n", status);
+		pio_write_16(hub->ports[port],
+		    (status & ~STATUS_WC_BITS) | STATUS_SUSPEND);
+		usb_log_warning("Suspend is not implemented on port %u\n", port);
+		break;
+	case USB_HUB_FEATURE_PORT_POWER:
+		RH_DEBUG(device, port, "Set port power (status %" PRIx16
+		    ")\n", status);
+		/* We are always powered */
+		usb_log_warning("Tried to power port %u\n", port);
+		break;
+	case USB_HUB_FEATURE_C_PORT_CONNECTION:
+	case USB_HUB_FEATURE_C_PORT_ENABLE:
+	case USB_HUB_FEATURE_C_PORT_SUSPEND:
+	case USB_HUB_FEATURE_C_PORT_OVER_CURRENT:
+		RH_DEBUG(device, port, "Set port change flag (status %" PRIx16
+		    ")\n", status);
+		/* These are voluntary and don't have to be set
+		 * there is no way we could do it on UHCI anyway */
+		break;
+	default:
+		RH_DEBUG(device, port, "Set unknown feature %d (status %" PRIx16
+		    ")\n", feature, status);
+		usb_log_warning("Setting feature %d is unsupported\n",
+		    feature);
+		return ESTALL;
+	}
+	return EOK;
+}
+
+/** Status change handler.
+ * @param device Virtual hub device
+ * @param endpoint Endpoint number
+ * @param tr_type Transfer type
+ * @param buffer Response destination
+ * @param buffer_size Bytes available in buffer
+ * @param actual_size Size us the used part of the dest buffer.
+ *
+ * Produces status mask. Bit 0 indicates hub status change the other bits
+ * represent port status change. Endian does not matter as UHCI root hubs
+ * only need 1 byte.
+ */
+static int req_status_change_handler(usbvirt_device_t *device,
+    usb_endpoint_t endpoint, usb_transfer_type_t tr_type,
+    void *buffer, size_t buffer_size, size_t *actual_size)
+{
+	uhci_rh_t *hub = virthub_get_data(device);
+	assert(hub);
+
+	if (buffer_size < 1)
+		return ESTALL;
+
+	const uint16_t status_a = pio_read_16(hub->ports[0]);
+	const uint16_t status_b = pio_read_16(hub->ports[1]);
+	const uint8_t status =
+	    ((((status_a & STATUS_CHANGE_BITS) != 0) || hub->reset_changed[0]) ?
+	        0x2 : 0) |
+	    ((((status_b & STATUS_CHANGE_BITS) != 0) || hub->reset_changed[1]) ?
+	        0x4 : 0);
+
+	RH_DEBUG(device, -1, "Event mask %" PRIx8
+	    " (status_a %" PRIx16 "%s),"
+	    " (status_b %" PRIx16 "%s)\n", status,
+	    status_a, hub->reset_changed[0] ? "-reset" : "",
+	    status_b, hub->reset_changed[1] ? "-reset" : "" );
+	((uint8_t *)buffer)[0] = status;
+	*actual_size = 1;
+	return EOK;
+}
+
+/** UHCI root hub request handlers */
+static const usbvirt_control_request_handler_t control_transfer_handlers[] = {
+	{
+		STD_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_DEVREQ_GET_DESCRIPTOR),
+		.name = "GetDescriptor",
+		.callback = virthub_base_get_hub_descriptor,
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_DEVREQ_GET_DESCRIPTOR),
+		.name = "GetDescriptor",
+		.callback = virthub_base_get_hub_descriptor,
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_GET_DESCRIPTOR),
+		.name = "GetHubDescriptor",
+		.callback = virthub_base_get_hub_descriptor,
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_GET_STATE),
+		.name = "GetBusState",
+		.callback = req_get_port_state,
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_GET_STATUS),
+		.name = "GetPortStatus",
+		.callback = req_get_port_status
+	},
+	{
+		CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_CLEAR_FEATURE),
+		.name = "ClearHubFeature",
+		/* Hub features are overcurrent and supply good,
+		 * this request may only clear changes that we never report*/
+		.callback = req_nop,
+	},
+	{
+		CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_CLEAR_FEATURE),
+		.name = "ClearPortFeature",
+		.callback = req_clear_port_feature
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_GET_STATUS),
+		.name = "GetHubStatus",
+		/* UHCI can't report OC condition or,
+		 * lose power source */
+		.callback = virthub_base_get_null_status,
+	},
+	{
+		CLASS_REQ_IN(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_GET_STATUS),
+		.name = "GetPortStatus",
+		.callback = req_get_port_status
+	},
+	{
+		CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_SET_FEATURE),
+		.name = "SetHubFeature",
+		/* Hub features are overcurrent and supply good,
+		 * this request may only set changes that we never report*/
+		.callback = req_nop,
+	},
+	{
+		CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_SET_FEATURE),
+		.name = "SetPortFeature",
+		.callback = req_set_port_feature
+	},
+	{
+		.callback = NULL
+	}
+};
+
+static usbvirt_device_ops_t ops = {
+        .control = control_transfer_handlers,
+        .data_in[HUB_STATUS_CHANGE_PIPE] = req_status_change_handler,
+};
Index: uspace/drv/bus/usb/uhci/uhci_rh.h
===================================================================
--- uspace/drv/bus/usb/uhci/uhci_rh.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
+++ uspace/drv/bus/usb/uhci/uhci_rh.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2013 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup drvusbuhci
+ * @{
+ */
+/** @file
+ * @brief UHCI host controller driver structure
+ */
+#ifndef DRV_UHCI_UHCI_RH_H
+#define DRV_UHCI_UHCI_RH_H
+
+#include <usbvirt/virthub_base.h>
+#include <usb/host/usb_transfer_batch.h>
+
+/** Endpoint number for status change pipe. */
+#define HUB_STATUS_CHANGE_PIPE   1
+
+/** Virtual to UHCI hub connector */
+typedef struct {
+	/** Virtual hub software implementation */
+	virthub_base_t base;
+	/** UHCI root hub port io registers */
+	ioport16_t *ports[2];
+	/** Reset change indicator, it is not reported by regs */
+	bool reset_changed[2];
+} uhci_rh_t;
+
+int uhci_rh_init(uhci_rh_t *instance, ioport16_t *ports, const char *name);
+int uhci_rh_schedule(uhci_rh_t *instance, usb_transfer_batch_t *batch);
+
+/** Get UHCI rh address.
+ *
+ * @param instance UHCI rh instance.
+ * @return USB address assigned to the hub.
+ * Wrapper for virtual hub address
+ */
+static inline usb_address_t uhci_rh_get_address(uhci_rh_t *instance)
+{
+	assert(instance);
+	return virthub_base_get_address(&instance->base);
+}
+
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/bus/usb/uhcirh/Makefile
===================================================================
--- uspace/drv/bus/usb/uhcirh/Makefile	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ 	(revision )
@@ -1,48 +1,0 @@
-#
-# Copyright (c) 2010 Jan Vesely
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# - Redistributions of source code must retain the above copyright
-#   notice, this list of conditions and the following disclaimer.
-# - Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in the
-#   documentation and/or other materials provided with the distribution.
-# - The name of the author may not be used to endorse or promote products
-#   derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-USPACE_PREFIX = ../../../..
-
-LIBS = \
-	$(LIBUSBDEV_PREFIX)/libusbdev.a \
-	$(LIBUSB_PREFIX)/libusb.a \
-	$(LIBDRV_PREFIX)/libdrv.a
-
-EXTRA_CFLAGS += \
-	-I$(LIBUSB_PREFIX)/include \
-	-I$(LIBUSBDEV_PREFIX)/include \
-	-I$(LIBDRV_PREFIX)/include
-
-BINARY = uhcirh
-
-SOURCES = \
-	main.c \
-	port.c \
-	root_hub.c
-
-include $(USPACE_PREFIX)/Makefile.common
Index: uspace/drv/bus/usb/uhcirh/main.c
===================================================================
--- uspace/drv/bus/usb/uhcirh/main.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ 	(revision )
@@ -1,160 +1,0 @@
-/*
- * Copyright (c) 2011 Jan Vesely
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup drvusbuhcirh
- * @{
- */
-/** @file
- * @brief UHCI root hub initialization routines
- */
-
-#include <ddf/driver.h>
-#include <devman.h>
-#include <device/hw_res_parsed.h>
-#include <errno.h>
-#include <str_error.h>
-
-#include <usb_iface.h>
-#include <usb/ddfiface.h>
-#include <usb/debug.h>
-
-#include "root_hub.h"
-
-#define NAME "uhcirh"
-
-static int hc_get_my_registers(ddf_dev_t *dev, addr_range_t *io_regs);
-
-static int uhci_rh_dev_add(ddf_dev_t *device);
-
-static driver_ops_t uhci_rh_driver_ops = {
-	.dev_add = uhci_rh_dev_add,
-};
-
-static driver_t uhci_rh_driver = {
-	.name = NAME,
-	.driver_ops = &uhci_rh_driver_ops
-};
-
-/** Initialize global driver structures (NONE).
- *
- * @param[in] argc Nmber of arguments in argv vector (ignored).
- * @param[in] argv Cmdline argument vector (ignored).
- * @return Error code.
- *
- * Driver debug level is set here.
- */
-int main(int argc, char *argv[])
-{
-	printf(NAME ": HelenOS UHCI root hub driver.\n");
-	log_init(NAME);
-	return ddf_driver_main(&uhci_rh_driver);
-}
-
-/** Initialize a new ddf driver instance of UHCI root hub.
- *
- * @param[in] device DDF instance of the device to initialize.
- * @return Error code.
- */
-static int uhci_rh_dev_add(ddf_dev_t *device)
-{
-	if (!device)
-		return EINVAL;
-
-	usb_log_debug2("uhci_rh_dev_add(handle=%" PRIun ")\n",
-	    ddf_dev_get_handle(device));
-
-	addr_range_t regs;
-	uhci_root_hub_t *rh = NULL;
-	int rc;
-
-	rc = hc_get_my_registers(device, &regs);
-	if (rc != EOK) {
-		usb_log_error( "Failed to get registers from HC: %s.\n",
-		    str_error(rc));
-		return rc;
-	}
-
-	usb_log_debug("I/O regs at %p (size %zuB).\n",
-	    RNGABSPTR(regs), RNGSZ(regs));
-
-	rh = ddf_dev_data_alloc(device, sizeof(uhci_root_hub_t));
-	if (rh == NULL) {
-		usb_log_error("Failed to allocate rh driver instance.\n");
-		return ENOMEM;
-	}
-
-	rc = uhci_root_hub_init(rh, &regs, device);
-	if (rc != EOK) {
-		usb_log_error("Failed(%d) to initialize rh driver instance: "
-		    "%s.\n", rc, str_error(rc));
-		return rc;
-	}
-
-	usb_log_info("Controlling root hub '%s' (%" PRIun ").\n",
-	    ddf_dev_get_name(device), ddf_dev_get_handle(device));
-
-	return EOK;
-}
-
-/** Get address of I/O registers.
- *
- * @param[in] dev Device asking for the addresses.
- * @param[out] io_regs_p Pointer to the device's register range.
- * @return Error code.
- */
-int hc_get_my_registers(ddf_dev_t *dev, addr_range_t *io_regs_p)
-{
-	async_sess_t *parent_sess =
-	    devman_parent_device_connect(EXCHANGE_SERIALIZE,
-	    ddf_dev_get_handle(dev), IPC_FLAG_BLOCKING);
-	if (!parent_sess)
-		return ENOMEM;
-
-	hw_res_list_parsed_t hw_res;
-	hw_res_list_parsed_init(&hw_res);
-	const int ret =  hw_res_get_list_parsed(parent_sess, &hw_res, 0);
-	async_hangup(parent_sess);
-	if (ret != EOK) {
-		return ret;
-	}
-
-	if (hw_res.io_ranges.count != 1) {
-		hw_res_list_parsed_clean(&hw_res);
-		return EINVAL;
-	}
-
-	if (io_regs_p != NULL)
-		*io_regs_p = hw_res.io_ranges.ranges[0];
-
-	hw_res_list_parsed_clean(&hw_res);
-	return EOK;
-}
-
-/**
- * @}
- */
Index: uspace/drv/bus/usb/uhcirh/port.c
===================================================================
--- uspace/drv/bus/usb/uhcirh/port.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ 	(revision )
@@ -1,392 +1,0 @@
-/*
- * Copyright (c) 2011 Jan Vesely
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-/** @addtogroup drvusbuhcirh
- * @{
- */
-/** @file
- * @brief UHCI root hub port routines
- */
-#include <ddi.h>
-#include <fibril_synch.h> /* async_usleep */
-#include <errno.h>
-#include <str_error.h>
-#include <async.h>
-
-#include <usb/usb.h>    /* usb_address_t */
-#include <usb/debug.h>
-
-#include "port.h"
-
-#define MAX_ERROR_COUNT 5
-
-static int uhci_port_check(void *port);
-static int uhci_port_reset_enable(void *arg);
-static int uhci_port_new_device(uhci_port_t *port, usb_speed_t speed);
-static int uhci_port_remove_device(uhci_port_t *port);
-static int uhci_port_set_enabled(uhci_port_t *port, bool enabled);
-static void uhci_port_print_status(
-    uhci_port_t *port, const port_status_t value);
-
-/** Register reading helper function.
- *
- * @param[in] port Structure to use.
- * @return Error code. (Always EOK)
- */
-static inline port_status_t uhci_port_read_status(uhci_port_t *port)
-{
-	assert(port);
-	return pio_read_16(port->address);
-}
-
-/** Register writing helper function.
- *
- * @param[in] port Structure to use.
- * @param[in] val New register value.
- * @return Error code. (Always EOK)
- */
-static inline void uhci_port_write_status(uhci_port_t *port, port_status_t val)
-{
-	assert(port);
-	pio_write_16(port->address, val);
-}
-
-/** Initialize UHCI root hub port instance.
- *
- * @param[in] port Memory structure to use.
- * @param[in] address Address of I/O register.
- * @param[in] number Port number.
- * @param[in] usec Polling interval.
- * @param[in] rh Pointer to ddf instance of the root hub driver.
- * @return Error code.
- *
- * Creates and starts the polling fibril.
- */
-int uhci_port_init(uhci_port_t *port,
-    port_status_t *address, unsigned number, unsigned usec, ddf_dev_t *rh)
-{
-	assert(port);
-	char *id_string;
-	asprintf(&id_string, "Port (%p - %u)", port, number);
-	if (id_string == NULL) {
-		return ENOMEM;
-	}
-
-	port->id_string = id_string;
-	port->address = address;
-	port->number = number;
-	port->wait_period_usec = usec;
-	port->attached_device.fun = NULL;
-	port->attached_device.address = -1;
-	port->rh = rh;
-
-	int ret =
-	    usb_hc_connection_initialize_from_device(&port->hc_connection, rh);
-	if (ret != EOK) {
-		usb_log_error("%s: failed to initialize connection to HC.",
-		    port->id_string);
-		free(id_string);
-		return ret;
-	}
-
-	port->checker = fibril_create(uhci_port_check, port);
-	if (port->checker == 0) {
-		usb_log_error("%s: failed to create polling fibril.",
-		    port->id_string);
-		free(id_string);
-		return ENOMEM;
-	}
-
-	fibril_add_ready(port->checker);
-	usb_log_debug("%s: Started polling fibril (%" PRIun ").\n",
-	    port->id_string, port->checker);
-	return EOK;
-}
-
-/** Cleanup UHCI root hub port instance.
- *
- * @param[in] port Memory structure to use.
- *
- * Stops the polling fibril.
- */
-void uhci_port_fini(uhci_port_t *port)
-{
-	assert(port);
-	free(port->id_string);
-	// TODO: Kill fibril here
-	return;
-}
-
-/** Periodically checks port status and reports new devices.
- *
- * @param[in] port Port structure to use.
- * @return Error code.
- */
-int uhci_port_check(void *port)
-{
-	uhci_port_t *instance = port;
-	int rc;
-	assert(instance);
-
-	unsigned allowed_failures = MAX_ERROR_COUNT;
-
-	while (1) {
-		async_usleep(instance->wait_period_usec);
-
-		/* Read register value */
-		const port_status_t port_status =
-		    uhci_port_read_status(instance);
-
-		/* Print the value if it's interesting */
-		if (port_status & ~STATUS_ALWAYS_ONE)
-			uhci_port_print_status(instance, port_status);
-
-		if ((port_status & STATUS_CONNECTED_CHANGED) == 0)
-			continue;
-
-		usb_log_debug("%s: Connected change detected: %x.\n",
-		    instance->id_string, port_status);
-
-		rc = usb_hc_connection_open(&instance->hc_connection);
-		if (rc != EOK) {
-			usb_log_error("%s: Failed to connect to HC %s.\n",
-			    instance->id_string, str_error(rc));
-			if (!(allowed_failures-- > 0))
-				goto fatal_error;
-			continue;
-		}
-
-		/* Remove any old device */
-		if (instance->attached_device.fun) {
-			uhci_port_remove_device(instance);
-		}
-
-		if ((port_status & STATUS_CONNECTED) != 0) {
-			/* New device, this will take care of WC bits */
-			const usb_speed_t speed =
-			    ((port_status & STATUS_LOW_SPEED) != 0) ?
-			    USB_SPEED_LOW : USB_SPEED_FULL;
-			uhci_port_new_device(instance, speed);
-		} else {
-			/* Write one to WC bits, to ack changes */
-			uhci_port_write_status(instance, port_status);
-			usb_log_debug("%s: status change ACK.\n",
-			    instance->id_string);
-		}
-
-		rc = usb_hc_connection_close(&instance->hc_connection);
-		if (rc != EOK) {
-			usb_log_error("%s: Failed to disconnect from HC %s.\n",
-			    instance->id_string, str_error(rc));
-			if (!(allowed_failures-- > 0))
-				goto fatal_error;
-			continue;
-		}
-	}
-
-	return EOK;
-
-fatal_error:
-	usb_log_fatal("Maximum number of failures reached, bailing out.\n");
-	return rc;
-}
-
-/** Callback for enabling port during adding a new device.
- *
- * @param portno Port number (unused).
- * @param arg Pointer to uhci_port_t of port with the new device.
- * @return Error code.
- *
- * Resets and enables the ub port.
- */
-int uhci_port_reset_enable(void *arg)
-{
-	uhci_port_t *port = arg;
-	assert(port);
-
-	usb_log_debug2("%s: new_device_enable_port.\n", port->id_string);
-
-	/*
-	 * Resets from root ports should be nominally 50ms (USB spec 7.1.7.3)
-	 */
-	{
-		usb_log_debug("%s: Reset Signal start.\n", port->id_string);
-		port_status_t port_status = uhci_port_read_status(port);
-		port_status |= STATUS_IN_RESET;
-		uhci_port_write_status(port, port_status);
-		async_usleep(50000);
-		port_status = uhci_port_read_status(port);
-		port_status &= ~STATUS_IN_RESET;
-		uhci_port_write_status(port, port_status);
-		while (uhci_port_read_status(port) & STATUS_IN_RESET);
-	}
-	/* PIO delay, should not be longer than 3ms as the device might
-	 * enter suspend state. */
-	udelay(10);
-	/* Enable the port. */
-	uhci_port_set_enabled(port, true);
-	return EOK;
-}
-
-/** Initialize and report connected device.
- *
- * @param[in] port Port structure to use.
- * @param[in] speed Detected speed.
- * @return Error code.
- *
- * Uses libUSB function to do the actual work.
- */
-int uhci_port_new_device(uhci_port_t *port, usb_speed_t speed)
-{
-	assert(port);
-
-	usb_log_debug("%s: Detected new device.\n", port->id_string);
-
-	int ret, count = MAX_ERROR_COUNT;
-	do {
-		ret = usb_hc_new_device_wrapper(port->rh, &port->hc_connection,
-		    speed, uhci_port_reset_enable, port,
-		    &port->attached_device.address, NULL, NULL,
-		    &port->attached_device.fun);
-	} while (ret != EOK && count-- > 0);
-
-	if (ret != EOK) {
-		usb_log_error("%s: Failed(%d) to add device: %s.\n",
-		    port->id_string, ret, str_error(ret));
-		uhci_port_set_enabled(port, false);
-		return ret;
-	}
-
-	usb_log_info("%s: New device, address %d (handle %" PRIun ").\n",
-	    port->id_string, port->attached_device.address,
-	    ddf_fun_get_handle(port->attached_device.fun));
-	return EOK;
-}
-
-/** Remove device.
- *
- * @param[in] port Port instance to use.
- * @return Error code.
- */
-int uhci_port_remove_device(uhci_port_t *port)
-{
-	assert(port);
-	/* There is nothing to remove. */
-	if (port->attached_device.fun == NULL) {
-		usb_log_warning("%s: Removed a ghost device.\n",
-		    port->id_string);
-		assert(port->attached_device.address == -1);
-		return EOK;
-	}
-
-	usb_log_debug("%s: Removing device.\n", port->id_string);
-
-	/* Stop driver first */
-	int ret = ddf_fun_unbind(port->attached_device.fun);
-	if (ret != EOK) {
-		usb_log_error("%s: Failed to remove child function: %s.\n",
-		   port->id_string, str_error(ret));
-		return ret;
-	}
-	ddf_fun_destroy(port->attached_device.fun);
-	port->attached_device.fun = NULL;
-
-	/* Driver stopped, free used address */
-	ret = usb_hub_unregister_device(&port->hc_connection,
-	    &port->attached_device);
-	if (ret != EOK) {
-		usb_log_error("%s: Failed to unregister address of removed "
-		    "device: %s.\n", port->id_string, str_error(ret));
-		return ret;
-	}
-	port->attached_device.address = -1;
-
-	usb_log_info("%s: Removed attached device.\n", port->id_string);
-	return EOK;
-}
-
-/** Enable or disable root hub port.
- *
- * @param[in] port Port structure to use.
- * @param[in] enabled Port status to set.
- * @return Error code. (Always EOK)
- */
-int uhci_port_set_enabled(uhci_port_t *port, bool enabled)
-{
-	assert(port);
-
-	/* Read register value */
-	port_status_t port_status = uhci_port_read_status(port);
-
-	/* Set enabled bit */
-	if (enabled) {
-		port_status |= STATUS_ENABLED;
-	} else {
-		port_status &= ~STATUS_ENABLED;
-	}
-
-	/* Write new value. */
-	uhci_port_write_status(port, port_status);
-
-	/* Wait for port to become enabled */
-	do {
-		port_status = uhci_port_read_status(port);
-	} while ((port_status & STATUS_CONNECTED) &&
-	    !(port_status & STATUS_ENABLED));
-
-	usb_log_debug("%s: %sabled port.\n",
-		port->id_string, enabled ? "En" : "Dis");
-	return EOK;
-}
-
-/** Print the port status value in a human friendly way
- *
- * @param[in] port Port structure to use.
- * @param[in] value Port register value to print.
- * @return Error code. (Always EOK)
- */
-void uhci_port_print_status(uhci_port_t *port, const port_status_t value)
-{
-	assert(port);
-	usb_log_debug2("%s Port status(%#x):%s%s%s%s%s%s%s%s%s%s%s.\n",
-	    port->id_string, value,
-	    (value & STATUS_SUSPEND) ? " SUSPENDED," : "",
-	    (value & STATUS_RESUME) ? " IN RESUME," : "",
-	    (value & STATUS_IN_RESET) ? " IN RESET," : "",
-	    (value & STATUS_LINE_D_MINUS) ? " VD-," : "",
-	    (value & STATUS_LINE_D_PLUS) ? " VD+," : "",
-	    (value & STATUS_LOW_SPEED) ? " LOWSPEED," : "",
-	    (value & STATUS_ENABLED_CHANGED) ? " ENABLED-CHANGE," : "",
-	    (value & STATUS_ENABLED) ? " ENABLED," : "",
-	    (value & STATUS_CONNECTED_CHANGED) ? " CONNECTED-CHANGE," : "",
-	    (value & STATUS_CONNECTED) ? " CONNECTED," : "",
-	    (value & STATUS_ALWAYS_ONE) ? " ALWAYS ONE" : " ERR: NO ALWAYS ONE"
-	);
-}
-/**
- * @}
- */
Index: uspace/drv/bus/usb/uhcirh/port.h
===================================================================
--- uspace/drv/bus/usb/uhcirh/port.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ 	(revision )
@@ -1,78 +1,0 @@
-/*
- * Copyright (c) 2011 Jan Vesely
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-/** @addtogroup drvusbuhcirh
- * @{
- */
-/** @file
- * @brief UHCI root hub port routines
- */
-#ifndef DRV_UHCI_PORT_H
-#define DRV_UHCI_PORT_H
-
-#include <stdint.h>
-#include <fibril.h>
-#include <ddf/driver.h>
-#include <usb/hc.h> /* usb_hc_connection_t */
-#include <usb/dev/hub.h>
-
-typedef uint16_t port_status_t;
-#define STATUS_CONNECTED         (1 << 0)
-#define STATUS_CONNECTED_CHANGED (1 << 1)
-#define STATUS_ENABLED           (1 << 2)
-#define STATUS_ENABLED_CHANGED   (1 << 3)
-#define STATUS_LINE_D_PLUS       (1 << 4)
-#define STATUS_LINE_D_MINUS      (1 << 5)
-#define STATUS_RESUME            (1 << 6)
-#define STATUS_ALWAYS_ONE        (1 << 7)
-
-#define STATUS_LOW_SPEED (1 <<  8)
-#define STATUS_IN_RESET  (1 <<  9)
-#define STATUS_SUSPEND   (1 << 12)
-
-/** UHCI port structure */
-typedef struct uhci_port {
-	const char *id_string;
-	port_status_t *address;
-	unsigned number;
-	unsigned wait_period_usec;
-	usb_hc_connection_t hc_connection;
-	ddf_dev_t *rh;
-	usb_hub_attached_device_t attached_device;
-	fid_t checker;
-} uhci_port_t;
-
-int uhci_port_init(
-    uhci_port_t *port, port_status_t *address, unsigned number,
-    unsigned usec, ddf_dev_t *rh);
-
-void uhci_port_fini(uhci_port_t *port);
-
-#endif
-/**
- * @}
- */
Index: uspace/drv/bus/usb/uhcirh/root_hub.c
===================================================================
--- uspace/drv/bus/usb/uhcirh/root_hub.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ 	(revision )
@@ -1,99 +1,0 @@
-/*
- * Copyright (c) 2011 Jan Vesely
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-/** @addtogroup drvusbuhcirh
- * @{
- */
-/** @file
- * @brief UHCI root hub driver
- */
-#include <errno.h>
-#include <str_error.h>
-#include <ddi.h>
-#include <usb/debug.h>
-#include <device/hw_res_parsed.h>
-
-#include "root_hub.h"
-
-/** Initialize UHCI root hub instance.
- *
- * @param[in] instance Driver memory structure to use.
- * @param[in] io_regs Range of I/O registers.
- * @param[in] rh Pointer to DDF instance of the root hub driver.
- * @return Error code.
- */
-int uhci_root_hub_init(uhci_root_hub_t *instance, addr_range_t *io_regs,
-    ddf_dev_t *rh)
-{
-	port_status_t *regs;
-
-	assert(instance);
-	assert(rh);
-
-	/* Allow access to root hub port registers */
-	assert(sizeof(*regs) * UHCI_ROOT_HUB_PORT_COUNT <= io_regs->size);
-
-	int ret = pio_enable_range(io_regs, (void **) &regs);
-	if (ret < 0) {
-		usb_log_error(
-		    "Failed(%d) to gain access to port registers at %p: %s.\n",
-		    ret, RNGABSPTR(*io_regs), str_error(ret));
-		return ret;
-	}
-
-	/* Initialize root hub ports */
-	unsigned i = 0;
-	for (; i < UHCI_ROOT_HUB_PORT_COUNT; ++i) {
-		ret = uhci_port_init(
-		    &instance->ports[i], &regs[i], i, ROOT_HUB_WAIT_USEC, rh);
-		if (ret != EOK) {
-			unsigned j = 0;
-			for (;j < i; ++j)
-				uhci_port_fini(&instance->ports[j]);
-			return ret;
-		}
-	}
-
-	return EOK;
-}
-
-/** Cleanup UHCI root hub instance.
- *
- * @param[in] instance Root hub structure to use.
- */
-void uhci_root_hub_fini(uhci_root_hub_t* instance)
-{
-	assert(instance);
-	unsigned i = 0;
-	for (; i < UHCI_ROOT_HUB_PORT_COUNT; ++i) {
-		uhci_port_fini(&instance->ports[i]);
-	}
-}
-
-/**
- * @}
- */
Index: uspace/drv/bus/usb/uhcirh/root_hub.h
===================================================================
--- uspace/drv/bus/usb/uhcirh/root_hub.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ 	(revision )
@@ -1,58 +1,0 @@
-/*
- * Copyright (c) 2011 Jan Vesely
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-/** @addtogroup drvusbuhcirh
- * @{
- */
-/** @file
- * @brief UHCI driver
- */
-#ifndef DRV_UHCI_ROOT_HUB_H
-#define DRV_UHCI_ROOT_HUB_H
-
-#include <ddf/driver.h>
-#include <device/hw_res_parsed.h>
-
-#include "port.h"
-
-#define UHCI_ROOT_HUB_PORT_COUNT 2
-#define ROOT_HUB_WAIT_USEC 250000 /* 250 miliseconds */
-
-/** UHCI root hub drvier structure */
-typedef struct root_hub {
-	/** Ports provided by the hub */
-	uhci_port_t ports[UHCI_ROOT_HUB_PORT_COUNT];
-} uhci_root_hub_t;
-
-int uhci_root_hub_init(uhci_root_hub_t *instance, addr_range_t *regs,
-    ddf_dev_t *rh);
-
-void uhci_root_hub_fini(uhci_root_hub_t *instance);
-#endif
-/**
- * @}
- */
Index: uspace/drv/bus/usb/uhcirh/uhcirh.ma
===================================================================
--- uspace/drv/bus/usb/uhcirh/uhcirh.ma	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ 	(revision )
@@ -1,1 +1,0 @@
-10 usb&uhci&root-hub
Index: uspace/drv/bus/usb/usbflbk/main.c
===================================================================
--- uspace/drv/bus/usb/usbflbk/main.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/usbflbk/main.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -48,27 +48,7 @@
 static int usbfallback_device_add(usb_device_t *dev)
 {
-	int rc;
-	const char *fun_name = "ctl";
-
-	ddf_fun_t *ctl_fun = ddf_fun_create(dev->ddf_dev, fun_exposed,
-	    fun_name);
-	if (ctl_fun == NULL) {
-		usb_log_error("Failed to create control function.\n");
-		return ENOMEM;
-	}
-	rc = ddf_fun_bind(ctl_fun);
-	if (rc != EOK) {
-		usb_log_error("Failed to bind control function: %s.\n",
-		    str_error(rc));
-		return rc;
-	}
-
-	dev->driver_data = ctl_fun;
-
-	usb_log_info("Pretending to control %s `%s'" \
-	    " (node `%s', handle %" PRIun ").\n",
-	    dev->interface_no < 0 ? "device" : "interface",
-	    ddf_dev_get_name(dev->ddf_dev), fun_name, ddf_dev_get_handle(dev->ddf_dev));
-
+	usb_log_info("Pretending to control %s `%s'.\n",
+	    usb_device_get_iface_number(dev) < 0 ? "device" : "interface",
+	    usb_device_get_name(dev));
 	return EOK;
 }
@@ -82,13 +62,4 @@
 {
 	assert(dev);
-	ddf_fun_t *ctl_fun = dev->driver_data;
-	const int ret = ddf_fun_unbind(ctl_fun);
-	if (ret != EOK) {
-		usb_log_error("Failed to unbind %s.\n", ddf_fun_get_name(ctl_fun));
-		return ret;
-	}
-	ddf_fun_destroy(ctl_fun);
-	dev->driver_data = NULL;
-
 	return EOK;
 }
Index: uspace/drv/bus/usb/usbhid/generic/hiddev.c
===================================================================
--- uspace/drv/bus/usb/usbhid/generic/hiddev.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/usbhid/generic/hiddev.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -35,7 +35,4 @@
  */
 
-/* XXX Fix this */
-#define _DDF_DATA_IMPLANT
-
 #include <usb/debug.h>
 #include <usb/classes/classes.h>
@@ -195,6 +192,6 @@
 	/* Create the exposed function. */
 	usb_log_debug("Creating DDF function %s...\n", HID_GENERIC_FUN_NAME);
-	ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed, 
-	    HID_GENERIC_FUN_NAME);
+	ddf_fun_t *fun = usb_device_ddf_fun_create(hid_dev->usb_dev,
+	    fun_exposed, HID_GENERIC_FUN_NAME);
 	if (fun == NULL) {
 		usb_log_error("Could not create DDF function node.\n");
Index: uspace/drv/bus/usb/usbhid/kbd/kbddev.c
===================================================================
--- uspace/drv/bus/usb/usbhid/kbd/kbddev.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/usbhid/kbd/kbddev.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -34,7 +34,4 @@
  * USB HID keyboard device structure and API.
  */
-
-/* XXX Fix this */
-#define _DDF_DATA_IMPLANT
 
 #include <errno.h>
@@ -264,6 +261,6 @@
 
 	if (rc != EOK) {
-		usb_log_warning("Error translating LED output to output report"
-		    ".\n");
+		usb_log_warning("Could not translate LED output to output"
+		    "report.\n");
 		return;
 	}
@@ -273,6 +270,8 @@
 	        0));
 
-	rc = usbhid_req_set_report(&hid_dev->usb_dev->ctrl_pipe,
-	    hid_dev->usb_dev->interface_no, USB_HID_REPORT_TYPE_OUTPUT,
+	rc = usbhid_req_set_report(
+	    usb_device_get_default_pipe(hid_dev->usb_dev),
+	    usb_device_get_iface_number(hid_dev->usb_dev),
+	    USB_HID_REPORT_TYPE_OUTPUT,
 	    kbd_dev->output_buffer, kbd_dev->output_size);
 	if (rc != EOK) {
@@ -481,13 +480,153 @@
 /* HID/KBD structure manipulation                                             */
 
-static int usb_kbd_create_function(usb_kbd_t *kbd_dev)
-{
-	assert(kbd_dev != NULL);
-	assert(kbd_dev->hid_dev != NULL);
-	assert(kbd_dev->hid_dev->usb_dev != NULL);
+static int kbd_dev_init(usb_kbd_t *kbd_dev, usb_hid_dev_t *hid_dev)
+{
+	assert(kbd_dev);
+	assert(hid_dev);
+
+	/* Default values */
+	fibril_mutex_initialize(&kbd_dev->repeat_mtx);
+	kbd_dev->initialized = USB_KBD_STATUS_UNINITIALIZED;
+
+	/* Store link to HID device */
+	kbd_dev->hid_dev = hid_dev;
+
+	/* Modifiers and locks */
+	kbd_dev->mods = DEFAULT_ACTIVE_MODS;
+
+	/* Autorepeat */
+	kbd_dev->repeat.delay_before = DEFAULT_DELAY_BEFORE_FIRST_REPEAT;
+	kbd_dev->repeat.delay_between = DEFAULT_REPEAT_DELAY;
+
+	// TODO: make more general
+	usb_hid_report_path_t *path = usb_hid_report_path();
+	if (path == NULL) {
+		usb_log_error("Failed to create kbd report path.\n");
+		usb_kbd_destroy(kbd_dev);
+		return ENOMEM;
+	}
+
+	int ret =
+	    usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0);
+	if (ret != EOK) {
+		usb_log_error("Failed to append item to kbd report path.\n");
+		usb_hid_report_path_free(path);
+		usb_kbd_destroy(kbd_dev);
+		return ret;
+	}
+
+	usb_hid_report_path_set_report_id(path, 0);
+
+	kbd_dev->key_count =
+	    usb_hid_report_size(&hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT);
+
+	usb_hid_report_path_free(path);
+
+	usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count);
+
+	kbd_dev->keys = calloc(kbd_dev->key_count, sizeof(int32_t));
+	if (kbd_dev->keys == NULL) {
+		usb_log_error("Failed to allocate key buffer.\n");
+		usb_kbd_destroy(kbd_dev);
+		return ENOMEM;
+	}
+
+	kbd_dev->keys_old = calloc(kbd_dev->key_count, sizeof(int32_t));
+	if (kbd_dev->keys_old == NULL) {
+		usb_log_error("Failed to allocate old_key buffer.\n");
+		usb_kbd_destroy(kbd_dev);
+		return ENOMEM;
+	}
+
+	/* Output report */
+	kbd_dev->output_size = 0;
+	kbd_dev->output_buffer = usb_hid_report_output(&hid_dev->report,
+	    &kbd_dev->output_size, 0);
+	if (kbd_dev->output_buffer == NULL) {
+		usb_log_error("Error creating output report buffer.\n");
+		usb_kbd_destroy(kbd_dev);
+		return ENOMEM;
+	}
+
+	usb_log_debug("Output buffer size: %zu\n", kbd_dev->output_size);
+
+	kbd_dev->led_path = usb_hid_report_path();
+	if (kbd_dev->led_path == NULL) {
+		usb_log_error("Failed to create kbd led report path.\n");
+		usb_kbd_destroy(kbd_dev);
+		return ENOMEM;
+	}
+
+	ret = usb_hid_report_path_append_item(
+	    kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0);
+	if (ret != EOK) {
+		usb_log_error("Failed to append to kbd/led report path.\n");
+		usb_kbd_destroy(kbd_dev);
+		return ret;
+	}
+
+	kbd_dev->led_output_size = usb_hid_report_size(
+	    &hid_dev->report, 0, USB_HID_REPORT_TYPE_OUTPUT);
+
+	usb_log_debug("Output report size (in items): %zu\n",
+	    kbd_dev->led_output_size);
+
+	kbd_dev->led_data = calloc(kbd_dev->led_output_size, sizeof(int32_t));
+	if (kbd_dev->led_data == NULL) {
+		usb_log_error("Error creating buffer for LED output report.\n");
+		usb_kbd_destroy(kbd_dev);
+		return ENOMEM;
+	}
+
+	/* Set LEDs according to initial setup.
+	 * Set Idle rate */
+	usb_kbd_set_led(hid_dev, kbd_dev);
+
+	usbhid_req_set_idle(usb_device_get_default_pipe(hid_dev->usb_dev),
+	    usb_device_get_iface_number(hid_dev->usb_dev), IDLE_RATE);
+
+
+	kbd_dev->initialized = USB_KBD_STATUS_INITIALIZED;
+	usb_log_debug("HID/KBD device structure initialized.\n");
+
+	return EOK;
+}
+
+
+/* API functions                                                              */
+
+/**
+ * Initialization of the USB/HID keyboard structure.
+ *
+ * This functions initializes required structures from the device's descriptors.
+ *
+ * During initialization, the keyboard is switched into boot protocol, the idle
+ * rate is set to 0 (infinity), resulting in the keyboard only reporting event
+ * when a key is pressed or released. Finally, the LED lights are turned on
+ * according to the default setup of lock keys.
+ *
+ * @note By default, the keyboards is initialized with Num Lock turned on and
+ *       other locks turned off.
+ *
+ * @param kbd_dev Keyboard device structure to be initialized.
+ * @param dev DDF device structure of the keyboard.
+ *
+ * @retval EOK if successful.
+ * @retval EINVAL if some parameter is not given.
+ * @return Other value inherited from function usbhid_dev_init().
+ */
+int usb_kbd_init(usb_hid_dev_t *hid_dev, void **data)
+{
+	usb_log_debug("Initializing HID/KBD structure...\n");
+
+	if (hid_dev == NULL) {
+		usb_log_error(
+		    "Failed to init keyboard structure: no structure given.\n");
+		return EINVAL;
+	}
 
 	/* Create the exposed function. */
 	usb_log_debug("Creating DDF function %s...\n", HID_KBD_FUN_NAME);
-	ddf_fun_t *fun = ddf_fun_create(kbd_dev->hid_dev->usb_dev->ddf_dev,
+	ddf_fun_t *fun = usb_device_ddf_fun_create(hid_dev->usb_dev,
 	    fun_exposed, HID_KBD_FUN_NAME);
 	if (fun == NULL) {
@@ -496,15 +635,29 @@
 	}
 
+	usb_kbd_t *kbd_dev = ddf_fun_data_alloc(fun, sizeof(usb_kbd_t));
+	if (kbd_dev == NULL) {
+		usb_log_error("Failed to allocate KBD device structure.\n");
+		ddf_fun_destroy(fun);
+		return ENOMEM;
+	}
+
+	int ret = kbd_dev_init(kbd_dev, hid_dev);
+	if (ret != EOK) {
+		usb_log_error("Failed to initialize KBD device  structure.\n");
+		ddf_fun_destroy(fun);
+		return ret;
+	}
+
 	/* Store the initialized HID device and HID ops
 	 * to the DDF function. */
 	ddf_fun_set_ops(fun, &kbdops);
-	ddf_fun_data_implant(fun, kbd_dev);
-
-	int rc = ddf_fun_bind(fun);
-	if (rc != EOK) {
+
+	ret = ddf_fun_bind(fun);
+	if (ret != EOK) {
 		usb_log_error("Could not bind DDF function: %s.\n",
-		    str_error(rc));
+		    str_error(ret));
+		usb_kbd_destroy(kbd_dev);
 		ddf_fun_destroy(fun);
-		return rc;
+		return ret;
 	}
 
@@ -514,9 +667,10 @@
 	usb_log_debug("Adding DDF function to category %s...\n",
 	    HID_KBD_CLASS_NAME);
-	rc = ddf_fun_add_to_category(fun, HID_KBD_CATEGORY_NAME);
-	if (rc != EOK) {
+	ret = ddf_fun_add_to_category(fun, HID_KBD_CATEGORY_NAME);
+	if (ret != EOK) {
 		usb_log_error(
 		    "Could not add DDF function to category %s: %s.\n",
-		    HID_KBD_CLASS_NAME, str_error(rc));
+		    HID_KBD_CLASS_NAME, str_error(ret));
+		usb_kbd_destroy(kbd_dev);
 		if (ddf_fun_unbind(fun) == EOK) {
 			ddf_fun_destroy(fun);
@@ -526,160 +680,4 @@
 			    ddf_fun_get_name(fun));
 		}
-		return rc;
-	}
-	kbd_dev->fun = fun;
-
-	return EOK;
-}
-
-/* API functions                                                              */
-
-/**
- * Initialization of the USB/HID keyboard structure.
- *
- * This functions initializes required structures from the device's descriptors.
- *
- * During initialization, the keyboard is switched into boot protocol, the idle
- * rate is set to 0 (infinity), resulting in the keyboard only reporting event
- * when a key is pressed or released. Finally, the LED lights are turned on 
- * according to the default setup of lock keys.
- *
- * @note By default, the keyboards is initialized with Num Lock turned on and 
- *       other locks turned off.
- *
- * @param kbd_dev Keyboard device structure to be initialized.
- * @param dev DDF device structure of the keyboard.
- *
- * @retval EOK if successful.
- * @retval EINVAL if some parameter is not given.
- * @return Other value inherited from function usbhid_dev_init().
- */
-int usb_kbd_init(usb_hid_dev_t *hid_dev, void **data)
-{
-	usb_log_debug("Initializing HID/KBD structure...\n");
-
-	if (hid_dev == NULL) {
-		usb_log_error(
-		    "Failed to init keyboard structure: no structure given.\n");
-		return EINVAL;
-	}
-
-	usb_kbd_t *kbd_dev = calloc(1, sizeof(usb_kbd_t));
-	if (kbd_dev == NULL) {
-		usb_log_error("Failed to allocate KBD device structure.\n");
-		return ENOMEM;
-	}
-	/* Default values */
-	fibril_mutex_initialize(&kbd_dev->repeat_mtx);
-	kbd_dev->initialized = USB_KBD_STATUS_UNINITIALIZED;
-
-	/* Store link to HID device */
-	kbd_dev->hid_dev = hid_dev;
-
-	/* Modifiers and locks */
-	kbd_dev->mods = DEFAULT_ACTIVE_MODS;
-
-	/* Autorepeat */
-	kbd_dev->repeat.delay_before = DEFAULT_DELAY_BEFORE_FIRST_REPEAT;
-	kbd_dev->repeat.delay_between = DEFAULT_REPEAT_DELAY;
-
-
-	// TODO: make more general
-	usb_hid_report_path_t *path = usb_hid_report_path();
-	if (path == NULL) {
-		usb_log_error("Failed to create kbd report path.\n");
-		usb_kbd_destroy(kbd_dev);
-		return ENOMEM;
-	}
-
-	int ret =
-	    usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0);
-	if (ret != EOK) {
-		usb_log_error("Failed to append item to kbd report path.\n");
-		usb_hid_report_path_free(path);
-		usb_kbd_destroy(kbd_dev);
-		return ret;
-	}
-
-	usb_hid_report_path_set_report_id(path, 0);
-
-	kbd_dev->key_count =
-	    usb_hid_report_size(&hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT);
-
-	usb_hid_report_path_free(path);
-
-	usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count);
-
-	kbd_dev->keys = calloc(kbd_dev->key_count, sizeof(int32_t));
-	if (kbd_dev->keys == NULL) {
-		usb_log_error("Failed to allocate key buffer.\n");
-		usb_kbd_destroy(kbd_dev);
-		return ENOMEM;
-	}
-
-	kbd_dev->keys_old = calloc(kbd_dev->key_count, sizeof(int32_t));
-	if (kbd_dev->keys_old == NULL) {
-		usb_log_error("Failed to allocate old_key buffer.\n");
-		usb_kbd_destroy(kbd_dev);
-		return ENOMEM;
-	}
-
-	/* Output report */
-	kbd_dev->output_size = 0;
-	kbd_dev->output_buffer = usb_hid_report_output(&hid_dev->report,
-	    &kbd_dev->output_size, 0);
-	if (kbd_dev->output_buffer == NULL) {
-		usb_log_error("Error creating output report buffer.\n");
-		usb_kbd_destroy(kbd_dev);
-		return ENOMEM;
-	}
-
-	usb_log_debug("Output buffer size: %zu\n", kbd_dev->output_size);
-
-	kbd_dev->led_path = usb_hid_report_path();
-	if (kbd_dev->led_path == NULL) {
-		usb_log_error("Failed to create kbd led report path.\n");
-		usb_kbd_destroy(kbd_dev);
-		return ENOMEM;
-	}
-
-	ret = usb_hid_report_path_append_item(
-	    kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0);
-	if (ret != EOK) {
-		usb_log_error("Failed to append to kbd/led report path.\n");
-		usb_kbd_destroy(kbd_dev);
-		return ret;
-	}
-
-	kbd_dev->led_output_size = usb_hid_report_size(
-	    &hid_dev->report, 0, USB_HID_REPORT_TYPE_OUTPUT);
-
-	usb_log_debug("Output report size (in items): %zu\n",
-	    kbd_dev->led_output_size);
-
-	kbd_dev->led_data = calloc(kbd_dev->led_output_size, sizeof(int32_t));
-	if (kbd_dev->led_data == NULL) {
-		usb_log_error("Error creating buffer for LED output report.\n");
-		usb_kbd_destroy(kbd_dev);
-		return ENOMEM;
-	}
-
-	/* Set LEDs according to initial setup.
-	 * Set Idle rate */
-	usb_kbd_set_led(hid_dev, kbd_dev);
-
-	usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe,
-	    hid_dev->usb_dev->interface_no, IDLE_RATE);
-
-	/* Save the KBD device structure into the HID device structure. */
-	*data = kbd_dev;
-
-	kbd_dev->initialized = USB_KBD_STATUS_INITIALIZED;
-	usb_log_debug("HID/KBD device structure initialized.\n");
-
-	usb_log_debug("Creating KBD function...\n");
-	ret = usb_kbd_create_function(kbd_dev);
-	if (ret != EOK) {
-		usb_kbd_destroy(kbd_dev);
 		return ret;
 	}
@@ -693,4 +691,7 @@
 	}
 	fibril_add_ready(fid);
+	kbd_dev->fun = fun;
+	/* Save the KBD device structure into the HID device structure. */
+	*data = kbd_dev;
 
 	return EOK;
@@ -787,6 +788,8 @@
 	}
 
-	rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe,
-	    hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT);
+	rc = usbhid_req_set_protocol(
+	    usb_device_get_default_pipe(hid_dev->usb_dev),
+	    usb_device_get_iface_number(hid_dev->usb_dev),
+	    USB_HID_PROTOCOL_BOOT);
 
 	if (rc != EOK) {
Index: uspace/drv/bus/usb/usbhid/main.c
===================================================================
--- uspace/drv/bus/usb/usbhid/main.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/usbhid/main.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -65,5 +65,5 @@
 	}
 
-	if (dev->interface_no < 0) {
+	if (usb_device_get_iface_number(dev) < 0) {
 		usb_log_error("Failed to add HID device: endpoints not found."
 		    "\n");
@@ -89,11 +89,13 @@
 	 * This will create a separate fibril that will query the device
 	 * for the data continuously. */
-       rc = usb_device_auto_poll(dev,
+	rc = usb_device_auto_poll_desc(dev,
 	   /* Index of the polling pipe. */
-	   hid_dev->poll_pipe_index,
+	   hid_dev->poll_pipe_mapping->description,
 	   /* Callback when data arrives. */
 	   usb_hid_polling_callback,
 	   /* How much data to request. */
-	   dev->pipes[hid_dev->poll_pipe_index].pipe.max_packet_size,
+	   hid_dev->poll_pipe_mapping->pipe.max_packet_size,
+	   /* Delay */
+	   -1,
 	   /* Callback when the polling ends. */
 	   usb_hid_polling_ended_callback,
@@ -103,5 +105,5 @@
 	if (rc != EOK) {
 		usb_log_error("Failed to start polling fibril for `%s'.\n",
-		    ddf_dev_get_name(dev->ddf_dev));
+		    usb_device_get_name(dev));
 		usb_hid_deinit(hid_dev);
 		return rc;
@@ -109,6 +111,5 @@
 	hid_dev->running = true;
 
-	usb_log_info("HID device `%s' ready to use.\n",
-	    ddf_dev_get_name(dev->ddf_dev));
+	usb_log_info("HID device `%s' ready.\n", usb_device_get_name(dev));
 
 	return EOK;
@@ -137,6 +138,6 @@
 {
 	assert(dev);
-	assert(dev->driver_data);
-	usb_hid_dev_t *hid_dev = dev->driver_data;
+	usb_hid_dev_t *hid_dev = usb_device_data_get(dev);
+	assert(hid_dev);
 	unsigned tries = 100;
 	/* Wait for fail. */
@@ -150,5 +151,5 @@
 
 	usb_hid_deinit(hid_dev);
-	usb_log_debug2("%s destruction complete.\n", ddf_dev_get_name(dev->ddf_dev));
+	usb_log_debug2("%s destruction complete.\n", usb_device_get_name(dev));
 	return EOK;
 }
Index: uspace/drv/bus/usb/usbhid/mouse/mousedev.c
===================================================================
--- uspace/drv/bus/usb/usbhid/mouse/mousedev.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/usbhid/mouse/mousedev.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -34,7 +34,4 @@
  * USB Mouse driver API.
  */
-
-/* XXX Fix this */
-#define _DDF_DATA_IMPLANT
 
 #include <usb/debug.h>
@@ -259,44 +256,4 @@
 } else (void)0
 
-static int usb_mouse_create_function(usb_hid_dev_t *hid_dev, usb_mouse_t *mouse)
-{
-	assert(hid_dev != NULL);
-	assert(mouse != NULL);
-
-	/* Create the exposed function. */
-	usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME);
-	ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
-	    HID_MOUSE_FUN_NAME);
-	if (fun == NULL) {
-		usb_log_error("Could not create DDF function node `%s'.\n",
-		    HID_MOUSE_FUN_NAME);
-		return ENOMEM;
-	}
-
-	ddf_fun_set_ops(fun, &ops);
-	ddf_fun_data_implant(fun, mouse);
-
-	int rc = ddf_fun_bind(fun);
-	if (rc != EOK) {
-		usb_log_error("Could not bind DDF function `%s': %s.\n",
-		    ddf_fun_get_name(fun), str_error(rc));
-		ddf_fun_destroy(fun);
-		return rc;
-	}
-
-	usb_log_debug("Adding DDF function `%s' to category %s...\n",
-	    ddf_fun_get_name(fun), HID_MOUSE_CATEGORY);
-	rc = ddf_fun_add_to_category(fun, HID_MOUSE_CATEGORY);
-	if (rc != EOK) {
-		usb_log_error(
-		    "Could not add DDF function to category %s: %s.\n",
-		    HID_MOUSE_CATEGORY, str_error(rc));
-		FUN_UNBIND_DESTROY(fun);
-		return rc;
-	}
-	mouse->mouse_fun = fun;
-	return EOK;
-}
-
 /** Get highest index of a button mentioned in given report.
  *
@@ -339,21 +296,6 @@
 }
 
-int usb_mouse_init(usb_hid_dev_t *hid_dev, void **data)
-{
-	usb_log_debug("Initializing HID/Mouse structure...\n");
-
-	if (hid_dev == NULL) {
-		usb_log_error("Failed to init keyboard structure: no structure"
-		    " given.\n");
-		return EINVAL;
-	}
-
-	usb_mouse_t *mouse_dev = calloc(1, sizeof(usb_mouse_t));
-	if (mouse_dev == NULL) {
-		usb_log_error("Error while creating USB/HID Mouse device "
-		    "structure.\n");
-		return ENOMEM;
-	}
-
+static int mouse_dev_init(usb_mouse_t *mouse_dev, usb_hid_dev_t *hid_dev)
+{
 	// FIXME: This may not be optimal since stupid hardware vendor may
 	// use buttons 1, 2, 3 and 6000 and we would allocate array of
@@ -373,13 +315,63 @@
 
 	// TODO: how to know if the device supports the request???
-	usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe,
-	    hid_dev->usb_dev->interface_no, IDLE_RATE);
-
-	int rc = usb_mouse_create_function(hid_dev, mouse_dev);
-	if (rc != EOK) {
-		free(mouse_dev->buttons);
-		free(mouse_dev);
-		return rc;
-	}
+	usbhid_req_set_idle(usb_device_get_default_pipe(hid_dev->usb_dev),
+	    usb_device_get_iface_number(hid_dev->usb_dev), IDLE_RATE);
+	return EOK;
+}
+
+int usb_mouse_init(usb_hid_dev_t *hid_dev, void **data)
+{
+	usb_log_debug("Initializing HID/Mouse structure...\n");
+
+	if (hid_dev == NULL) {
+		usb_log_error("Failed to init keyboard structure: no structure"
+		    " given.\n");
+		return EINVAL;
+	}
+
+	/* Create the exposed function. */
+	usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME);
+	ddf_fun_t *fun = usb_device_ddf_fun_create(hid_dev->usb_dev,
+	    fun_exposed, HID_MOUSE_FUN_NAME);
+	if (fun == NULL) {
+		usb_log_error("Could not create DDF function node `%s'.\n",
+		    HID_MOUSE_FUN_NAME);
+		return ENOMEM;
+	}
+
+	usb_mouse_t *mouse_dev = ddf_fun_data_alloc(fun, sizeof(usb_mouse_t));
+	if (mouse_dev == NULL) {
+		usb_log_error("Failed to alloc HID mouse device structure.\n");
+		ddf_fun_destroy(fun);
+		return ENOMEM;
+	}
+
+	int ret = mouse_dev_init(mouse_dev, hid_dev);
+	if (ret != EOK) {
+		usb_log_error("Failed to init HID mouse device structure.\n");
+		return ret;
+	}
+
+	ddf_fun_set_ops(fun, &ops);
+
+	ret = ddf_fun_bind(fun);
+	if (ret != EOK) {
+		usb_log_error("Could not bind DDF function `%s': %s.\n",
+		    ddf_fun_get_name(fun), str_error(ret));
+		ddf_fun_destroy(fun);
+		return ret;
+	}
+
+	usb_log_debug("Adding DDF function `%s' to category %s...\n",
+	    ddf_fun_get_name(fun), HID_MOUSE_CATEGORY);
+	ret = ddf_fun_add_to_category(fun, HID_MOUSE_CATEGORY);
+	if (ret != EOK) {
+		usb_log_error(
+		    "Could not add DDF function to category %s: %s.\n",
+		    HID_MOUSE_CATEGORY, str_error(ret));
+		FUN_UNBIND_DESTROY(fun);
+		return ret;
+	}
+	mouse_dev->mouse_fun = fun;
 
 	/* Save the Mouse device structure into the HID device structure. */
@@ -417,7 +409,6 @@
 	}
 
+	free(mouse_dev->buttons);
 	FUN_UNBIND_DESTROY(mouse_dev->mouse_fun);
-
-	free(mouse_dev->buttons);
 }
 
@@ -434,6 +425,8 @@
 	}
 
-	rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe,
-	    hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT);
+	rc = usbhid_req_set_protocol(
+	    usb_device_get_default_pipe(hid_dev->usb_dev),
+	    usb_device_get_iface_number(hid_dev->usb_dev),
+	    USB_HID_PROTOCOL_BOOT);
 
 	if (rc != EOK) {
Index: uspace/drv/bus/usb/usbhid/multimedia/multimedia.c
===================================================================
--- uspace/drv/bus/usb/usbhid/multimedia/multimedia.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/usbhid/multimedia/multimedia.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -161,6 +161,6 @@
 
 	/* Create the exposed function. */
-	ddf_fun_t *fun = ddf_fun_create(
-	    hid_dev->usb_dev->ddf_dev, fun_exposed, NAME);
+	ddf_fun_t *fun = usb_device_ddf_fun_create(
+	    hid_dev->usb_dev, fun_exposed, NAME);
 	if (fun == NULL) {
 		usb_log_error("Could not create DDF function node.\n");
Index: uspace/drv/bus/usb/usbhid/usbhid.c
===================================================================
--- uspace/drv/bus/usb/usbhid/usbhid.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/usbhid/usbhid.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -41,5 +41,7 @@
 #include <usb/hid/hidreport.h>
 #include <usb/hid/request.h>
+
 #include <errno.h>
+#include <macros.h>
 #include <str_error.h>
 
@@ -114,11 +116,12 @@
     const usb_hid_subdriver_mapping_t *mapping)
 {
-	assert(hid_dev != NULL);
-	assert(hid_dev->usb_dev != NULL);
-
-	return (hid_dev->usb_dev->descriptors.device.vendor_id
-	    == mapping->vendor_id
-	    && hid_dev->usb_dev->descriptors.device.product_id
-	    == mapping->product_id);
+	assert(hid_dev);
+	assert(hid_dev->usb_dev);
+	assert(mapping);
+	const usb_standard_device_descriptor_t *d =
+	    &usb_device_descriptors(hid_dev->usb_dev)->device;
+
+	return (d->vendor_id == mapping->vendor_id)
+	    && (d->product_id == mapping->product_id);
 }
 
@@ -264,5 +267,5 @@
 }
 
-static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, const usb_device_t *dev)
+static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, usb_device_t *dev)
 {
 	assert(hid_dev);
@@ -270,19 +273,18 @@
 
 	static const struct {
-		unsigned ep_number;
+		const usb_endpoint_description_t *desc;
 		const char* description;
 	} endpoints[] = {
-		{USB_HID_KBD_POLL_EP_NO, "Keyboard endpoint"},
-		{USB_HID_MOUSE_POLL_EP_NO, "Mouse endpoint"},
-		{USB_HID_GENERIC_POLL_EP_NO, "Generic HID endpoint"},
+		{&usb_hid_kbd_poll_endpoint_description, "Keyboard endpoint"},
+		{&usb_hid_mouse_poll_endpoint_description, "Mouse endpoint"},
+		{&usb_hid_generic_poll_endpoint_description, "Generic HID endpoint"},
 	};
 
-	for (unsigned i = 0; i < sizeof(endpoints)/sizeof(endpoints[0]); ++i) {
-		if (endpoints[i].ep_number >= dev->pipes_count) {
-			return EINVAL;
-		}
-		if (dev->pipes[endpoints[i].ep_number].present) {
+	for (unsigned i = 0; i < ARRAY_SIZE(endpoints); ++i) {
+		usb_endpoint_mapping_t *epm =
+		    usb_device_get_mapped_ep_desc(dev, endpoints[i].desc);
+		if (epm && epm->present) {
 			usb_log_debug("Found: %s.\n", endpoints[i].description);
-			hid_dev->poll_pipe_index = endpoints[i].ep_number;
+			hid_dev->poll_pipe_mapping = epm;
 			return EOK;
 		}
@@ -351,5 +353,5 @@
 	/* The USB device should already be initialized, save it in structure */
 	hid_dev->usb_dev = dev;
-	hid_dev->poll_pipe_index = -1;
+	hid_dev->poll_pipe_mapping = NULL;
 
 	int rc = usb_hid_check_pipes(hid_dev, dev);
@@ -381,6 +383,6 @@
 		    "boot protocol.\n");
 
-		switch (hid_dev->poll_pipe_index) {
-		case USB_HID_KBD_POLL_EP_NO:
+		switch (hid_dev->poll_pipe_mapping->interface->interface_protocol) {
+		case USB_HID_PROTOCOL_KEYBOARD:
 			usb_log_info("Falling back to kbd boot protocol.\n");
 			rc = usb_kbd_set_boot_protocol(hid_dev);
@@ -389,5 +391,5 @@
 			}
 			break;
-		case USB_HID_MOUSE_POLL_EP_NO:
+		case USB_HID_PROTOCOL_MOUSE:
 			usb_log_info("Falling back to mouse boot protocol.\n");
 			rc = usb_mouse_set_boot_protocol(hid_dev);
@@ -397,6 +399,4 @@
 			break;
 		default:
-			assert(hid_dev->poll_pipe_index
-			    == USB_HID_GENERIC_POLL_EP_NO);
 			usb_log_info("Falling back to generic HID driver.\n");
 			usb_hid_set_generic_hid_subdriver(hid_dev);
@@ -485,5 +485,5 @@
 	    &hid_dev->report, buffer, buffer_size, &hid_dev->report_id);
 	if (rc != EOK) {
-		usb_log_warning("Error in usb_hid_parse_report():"
+		usb_log_warning("Failure in usb_hid_parse_report():"
 		    "%s\n", str_error(rc));
 	}
Index: uspace/drv/bus/usb/usbhid/usbhid.h
===================================================================
--- uspace/drv/bus/usb/usbhid/usbhid.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/usbhid/usbhid.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -103,6 +103,6 @@
 	usb_device_t *usb_dev;
 
-	/** Index of the polling pipe in usb_hid_endpoints array. */
-	unsigned poll_pipe_index;
+	/** Endpont mapping of the polling pipe. */
+	usb_endpoint_mapping_t *poll_pipe_mapping;
 
 	/** Subdrivers. */
@@ -132,16 +132,5 @@
 };
 
-
-
-enum {
-	USB_HID_KBD_POLL_EP_NO = 0,
-	USB_HID_MOUSE_POLL_EP_NO = 1,
-	USB_HID_GENERIC_POLL_EP_NO = 2,
-	USB_HID_POLL_EP_COUNT = 3
-};
-
 extern const usb_endpoint_description_t *usb_hid_endpoints[];
-
-
 
 int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev);
Index: uspace/drv/bus/usb/usbhub/main.c
===================================================================
--- uspace/drv/bus/usb/usbhub/main.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/usbhub/main.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -43,17 +43,4 @@
 #include "usbhub.h"
 
-/** Hub status-change endpoint description.
- *
- * For more information see section 11.15.1 of USB 1.1 specification.
- */
-static const usb_endpoint_description_t hub_status_change_endpoint_description =
-{
-	.transfer_type = USB_TRANSFER_INTERRUPT,
-	.direction = USB_DIRECTION_IN,
-	.interface_class = USB_CLASS_HUB,
-	.interface_subclass = 0,
-	.interface_protocol = 0,
-	.flags = 0
-};
 
 /** USB hub driver operations. */
Index: uspace/drv/bus/usb/usbhub/port.c
===================================================================
--- uspace/drv/bus/usb/usbhub/port.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/usbhub/port.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -41,5 +41,4 @@
 
 #include <usb/debug.h>
-#include <usb/dev/hub.h>
 
 #include "port.h"
@@ -58,5 +57,4 @@
     usb_port_status_t status);
 static int get_port_status(usb_hub_port_t *port, usb_port_status_t *status);
-static int enable_port_callback(void *arg);
 static int add_device_phase1_worker_fibril(void *arg);
 static int create_add_device_fibril(usb_hub_port_t *port, usb_hub_dev_t *hub,
@@ -66,5 +64,5 @@
 {
 	assert(port);
-	if (port->attached_device.fun)
+	if (port->device_attached)
 		return usb_hub_port_device_gone(port, hub);
 	return EOK;
@@ -141,10 +139,10 @@
 	assert(port);
 	assert(hub);
-	usb_log_debug("Interrupt at port %zu\n", port->port_number);
+	usb_log_debug("Interrupt at port %u\n", port->port_number);
 
 	usb_port_status_t status = 0;
 	const int opResult = get_port_status(port, &status);
 	if (opResult != EOK) {
-		usb_log_error("Failed to get port %zu status: %s.\n",
+		usb_log_error("Failed to get port %u status: %s.\n",
 		    port->port_number, str_error(opResult));
 		return;
@@ -155,5 +153,5 @@
 		const bool connected =
 		    (status & USB_HUB_PORT_STATUS_CONNECTION) != 0;
-		usb_log_debug("Connection change on port %zu: device %s.\n",
+		usb_log_debug("Connection change on port %u: device %s.\n",
 		    port->port_number, connected ? "attached" : "removed");
 
@@ -171,5 +169,5 @@
 			if (opResult != EOK) {
 				usb_log_error(
-				    "Cannot handle change on port %zu: %s.\n",
+				    "Cannot handle change on port %u: %s.\n",
 				    port->port_number, str_error(opResult));
 			}
@@ -185,5 +183,5 @@
 	/* Enable change, ports are automatically disabled on errors. */
 	if (status & USB_HUB_PORT_C_STATUS_ENABLED) {
-		usb_log_info("Port %zu, disabled because of errors.\n",
+		usb_log_info("Port %u, disabled because of errors.\n",
 		   port->port_number);
 		usb_hub_port_device_gone(port, hub);
@@ -192,5 +190,5 @@
 		if (rc != EOK) {
 			usb_log_error(
-			    "Failed to clear port %zu enable change feature: "
+			    "Failed to clear port %u enable change feature: "
 			    "%s.\n", port->port_number, str_error(rc));
 		}
@@ -200,5 +198,5 @@
 	/* Suspend change */
 	if (status & USB_HUB_PORT_C_STATUS_SUSPEND) {
-		usb_log_error("Port %zu went to suspend state, this should"
+		usb_log_error("Port %u went to suspend state, this should"
 		    "NOT happen as we do not support suspend state!",
 		    port->port_number);
@@ -207,5 +205,5 @@
 		if (rc != EOK) {
 			usb_log_error(
-			    "Failed to clear port %zu suspend change feature: "
+			    "Failed to clear port %u suspend change feature: "
 			    "%s.\n", port->port_number, str_error(rc));
 		}
@@ -223,5 +221,5 @@
 		if (rc != EOK) {
 			usb_log_error(
-			    "Failed to clear port %zu OC change feature: %s.\n",
+			    "Failed to clear port %u OC change feature: %s.\n",
 			    port->port_number, str_error(rc));
 		}
@@ -231,5 +229,5 @@
 			if (rc != EOK) {
 				usb_log_error(
-				    "Failed to set port %zu power after OC:"
+				    "Failed to set port %u power after OC:"
 				    " %s.\n", port->port_number, str_error(rc));
 			}
@@ -242,5 +240,5 @@
 	}
 
-	usb_log_debug("Port %zu status 0x%08" PRIx32 "\n",
+	usb_log_debug("Port %u status %#08" PRIx32 "\n",
 	    port->port_number, status);
 }
@@ -259,43 +257,13 @@
 	assert(port);
 	assert(hub);
-	if (port->attached_device.address < 0) {
-		usb_log_warning(
-		    "Device on port %zu removed before being registered.\n",
-		    port->port_number);
-
-		/*
-		 * Device was removed before port reset completed.
-		 * We will announce a failed port reset to unblock the
-		 * port reset callback from new device wrapper.
-		 */
-		usb_hub_port_reset_fail(port);
-		return EOK;
-	}
-
-	fibril_mutex_lock(&port->mutex);
-	assert(port->attached_device.fun);
-	usb_log_debug("Removing device on port %zu.\n", port->port_number);
-	int ret = ddf_fun_unbind(port->attached_device.fun);
-	if (ret != EOK) {
-		usb_log_error("Failed to unbind child function on port"
-		    " %zu: %s.\n", port->port_number, str_error(ret));
-		fibril_mutex_unlock(&port->mutex);
-		return ret;
-	}
-
-	ddf_fun_destroy(port->attached_device.fun);
-	port->attached_device.fun = NULL;
-
-	ret = usb_hub_unregister_device(&hub->usb_device->hc_conn,
-	    &port->attached_device);
-	if (ret != EOK) {
-		usb_log_warning("Failed to unregister address of the "
-		    "removed device: %s.\n", str_error(ret));
-	}
-
-	port->attached_device.address = -1;
-	fibril_mutex_unlock(&port->mutex);
-	usb_log_info("Removed device on port %zu.\n", port->port_number);
-	return EOK;
+	async_exch_t *exch = usb_device_bus_exchange_begin(hub->usb_device);
+	if (!exch)
+		return ENOMEM;
+	const int rc = usb_device_remove(exch, port->port_number);
+	usb_device_bus_exchange_end(exch);
+	if (rc == EOK)
+		port->device_attached = false;
+	return rc;
+
 }
 
@@ -318,8 +286,8 @@
 
 	if (port->reset_okay) {
-		usb_log_debug("Port %zu reset complete.\n", port->port_number);
+		usb_log_debug("Port %u reset complete.\n", port->port_number);
 	} else {
 		usb_log_warning(
-		    "Port %zu reset complete but port not enabled.\n",
+		    "Port %u reset complete but port not enabled.\n",
 		    port->port_number);
 	}
@@ -331,5 +299,5 @@
 	if (rc != EOK) {
 		usb_log_error(
-		    "Failed to clear port %zu reset change feature: %s.\n",
+		    "Failed to clear port %u reset change feature: %s.\n",
 		    port->port_number, str_error(rc));
 	}
@@ -376,34 +344,26 @@
 }
 
-/** Callback for enabling a specific port.
- *
- * We wait on a CV until port is reseted.
- * That is announced via change on interrupt pipe.
- *
- * @param port_no Port number (starting at 1).
- * @param arg Custom argument, points to @c usb_hub_dev_t.
- * @return Error code.
- */
-static int enable_port_callback(void *arg)
-{
-	usb_hub_port_t *port = arg;
-	assert(port);
-	const int rc =
-	    usb_hub_port_set_feature(port, USB_HUB_FEATURE_PORT_RESET);
-	if (rc != EOK) {
-		usb_log_warning("Port reset failed: %s.\n", str_error(rc));
-		return rc;
-	}
-
-	/*
-	 * Wait until reset completes.
-	 */
-	fibril_mutex_lock(&port->mutex);
-	while (!port->reset_completed) {
-		fibril_condvar_wait(&port->reset_cv, &port->mutex);
-	}
-	fibril_mutex_unlock(&port->mutex);
-
-	return port->reset_okay ? EOK : ESTALL;
+static int port_enable(usb_hub_port_t *port, bool enable)
+{
+	if (enable) {
+		const int rc =
+		    usb_hub_port_set_feature(port, USB_HUB_FEATURE_PORT_RESET);
+		if (rc != EOK) {
+			usb_log_error("Port reset failed: %s.\n",
+			    str_error(rc));
+		} else {
+			/* Wait until reset completes. */
+			fibril_mutex_lock(&port->mutex);
+			while (!port->reset_completed) {
+				fibril_condvar_wait(&port->reset_cv,
+				    &port->mutex);
+			}
+			fibril_mutex_unlock(&port->mutex);
+		}
+		return port->reset_okay ? EOK : ESTALL;
+	} else {
+		return usb_hub_port_clear_feature(port,
+				USB_HUB_FEATURE_PORT_ENABLE);
+	}
 }
 
@@ -418,40 +378,67 @@
 int add_device_phase1_worker_fibril(void *arg)
 {
-	struct add_device_phase1 *data = arg;
-	assert(data);
-
-	usb_address_t new_address;
-	ddf_fun_t *child_fun;
-
-	const int rc = usb_hc_new_device_wrapper(data->hub->usb_device->ddf_dev,
-	    &data->hub->usb_device->hc_conn, data->speed, enable_port_callback,
-	    data->port, &new_address, NULL, NULL, &child_fun);
-
-	if (rc == EOK) {
-		fibril_mutex_lock(&data->port->mutex);
-		data->port->attached_device.fun = child_fun;
-		data->port->attached_device.address = new_address;
-		fibril_mutex_unlock(&data->port->mutex);
-
-		usb_log_info("Detected new device on `%s' (port %zu), "
-		    "address %d (handle %" PRIun ").\n",
-		    ddf_dev_get_name(data->hub->usb_device->ddf_dev),
-		    data->port->port_number, new_address,
-		    ddf_fun_get_handle(child_fun));
+	struct add_device_phase1 *params = arg;
+	assert(params);
+
+	int ret = EOK;
+	usb_hub_dev_t *hub = params->hub;
+	usb_hub_port_t *port = params->port;
+	const usb_speed_t speed = params->speed;
+	free(arg);
+
+	async_exch_t *exch = usb_device_bus_exchange_begin(hub->usb_device);
+	if (!exch) {
+		usb_log_error("Failed to begin bus exchange\n");
+		ret = ENOMEM;
+		goto out;
+	}
+
+	/* Reserve default address */
+	while ((ret = usb_reserve_default_address(exch, speed)) == ENOENT) {
+		async_usleep(1000000);
+	}
+	if (ret != EOK) {
+		usb_log_error("Failed to reserve default address: %s\n",
+		    str_error(ret));
+		goto out;
+	}
+
+	/* Reset port */
+	port_enable(port, true);
+	if (!port->reset_completed || !port->reset_okay) {
+		usb_log_error("Failed to reset port %u\n", port->port_number);
+		if (usb_release_default_address(exch) != EOK)
+			usb_log_warning("Failed to release default address\n");
+		ret = EIO;
+		goto out;
+	}
+
+	ret = usb_device_enumerate(exch, port->port_number);
+	if (ret != EOK) {
+		usb_log_error("Failed to enumerate device on port %u\n",
+		    port->port_number);
+		if (port_enable(port, false) != EOK) {
+			usb_log_warning("Failed to disable port %u, NOT "
+			    "releasing default address.\n", port->port_number);
+		} else {
+			if (usb_release_default_address(exch) != EOK)
+				usb_log_warning(
+				    "Failed to release default address\n");
+		}
 	} else {
-		usb_log_error("Failed registering device on port %zu: %s.\n",
-		    data->port->port_number, str_error(rc));
-	}
-
-
-	fibril_mutex_lock(&data->hub->pending_ops_mutex);
-	assert(data->hub->pending_ops_count > 0);
-	--data->hub->pending_ops_count;
-	fibril_condvar_signal(&data->hub->pending_ops_cv);
-	fibril_mutex_unlock(&data->hub->pending_ops_mutex);
-
-	free(arg);
-
-	return rc;
+		port->device_attached = true;
+		if (usb_release_default_address(exch) != EOK)
+			usb_log_warning("Failed to release default address\n");
+	}
+out:
+	usb_device_bus_exchange_end(exch);
+
+	fibril_mutex_lock(&hub->pending_ops_mutex);
+	assert(hub->pending_ops_count > 0);
+	--hub->pending_ops_count;
+	fibril_condvar_signal(&hub->pending_ops_cv);
+	fibril_mutex_unlock(&hub->pending_ops_mutex);
+
+	return ret;
 }
 
Index: uspace/drv/bus/usb/usbhub/port.h
===================================================================
--- uspace/drv/bus/usb/usbhub/port.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/usbhub/port.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -37,6 +37,6 @@
 
 #include <usb/dev/driver.h>
-#include <usb/dev/hub.h>
 #include <usb/classes/hub.h>
+#include <usb_iface.h>
 
 typedef struct usb_hub_dev usb_hub_dev_t;
@@ -44,6 +44,6 @@
 /** Information about single port on a hub. */
 typedef struct {
-	/* Port number as reported in descriptors. */
-	size_t port_number;
+	/** Port number as reported in descriptors. */
+	unsigned port_number;
 	/** Device communication pipe. */
 	usb_pipe_t *control_pipe;
@@ -58,7 +58,6 @@
 	/** Whether to announce the port reset as successful. */
 	bool reset_okay;
-
-	/** Information about attached device. */
-	usb_hub_attached_device_t attached_device;
+	/** Device reported to USB bus driver */
+	bool device_attached;
 } usb_hub_port_t;
 
@@ -67,12 +66,13 @@
  * @param port Port to be initialized.
  */
-static inline void usb_hub_port_init(usb_hub_port_t *port, size_t port_number,
+static inline void usb_hub_port_init(usb_hub_port_t *port, unsigned port_number,
     usb_pipe_t *control_pipe)
 {
 	assert(port);
-	port->attached_device.address = -1;
-	port->attached_device.fun = NULL;
 	port->port_number = port_number;
 	port->control_pipe = control_pipe;
+	port->reset_completed = false;
+	port->reset_okay = false;
+	port->device_attached = false;
 	fibril_mutex_initialize(&port->mutex);
 	fibril_condvar_initialize(&port->reset_cv);
Index: uspace/drv/bus/usb/usbhub/usbhub.c
===================================================================
--- uspace/drv/bus/usb/usbhub/usbhub.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/usbhub/usbhub.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -45,5 +45,4 @@
 #include <usb/dev/pipes.h>
 #include <usb/classes/classes.h>
-#include <usb/ddfiface.h>
 #include <usb/descriptor.h>
 #include <usb/dev/recognise.h>
@@ -57,4 +56,17 @@
 
 #define HUB_FNC_NAME "hub"
+/** Hub status-change endpoint description.
+ *
+ * For more information see section 11.15.1 of USB 1.1 specification.
+ */
+const usb_endpoint_description_t hub_status_change_endpoint_description =
+{
+	.transfer_type = USB_TRANSFER_INTERRUPT,
+	.direction = USB_DIRECTION_IN,
+	.interface_class = USB_CLASS_HUB,
+	.interface_subclass = 0,
+	.interface_protocol = 0,
+	.flags = 0
+};
 
 /** Standard get hub global status request */
@@ -99,16 +111,7 @@
 	fibril_condvar_initialize(&hub_dev->pending_ops_cv);
 
-
-	int opResult = usb_pipe_start_long_transfer(&usb_dev->ctrl_pipe);
-	if (opResult != EOK) {
-		usb_log_error("Failed to start long ctrl pipe transfer: %s\n",
-		    str_error(opResult));
-		return opResult;
-	}
-
 	/* Set hub's first configuration. (There should be only one) */
-	opResult = usb_set_first_configuration(usb_dev);
-	if (opResult != EOK) {
-		usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
+	int opResult = usb_set_first_configuration(usb_dev);
+	if (opResult != EOK) {
 		usb_log_error("Could not set hub configuration: %s\n",
 		    str_error(opResult));
@@ -119,5 +122,4 @@
 	opResult = usb_hub_process_hub_specific_info(hub_dev);
 	if (opResult != EOK) {
-		usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
 		usb_log_error("Could process hub specific info, %s\n",
 		    str_error(opResult));
@@ -127,8 +129,7 @@
 	/* Create hub control function. */
 	usb_log_debug("Creating DDF function '" HUB_FNC_NAME "'.\n");
-	hub_dev->hub_fun = ddf_fun_create(hub_dev->usb_device->ddf_dev,
+	hub_dev->hub_fun = usb_device_ddf_fun_create(hub_dev->usb_device,
 	    fun_exposed, HUB_FNC_NAME);
 	if (hub_dev->hub_fun == NULL) {
-		usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
 		usb_log_error("Failed to create hub function.\n");
 		return ENOMEM;
@@ -138,5 +139,4 @@
 	opResult = ddf_fun_bind(hub_dev->hub_fun);
 	if (opResult != EOK) {
-		usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
 		usb_log_error("Failed to bind hub function: %s.\n",
 		   str_error(opResult));
@@ -146,9 +146,9 @@
 
 	/* Start hub operation. */
-	opResult = usb_device_auto_poll(hub_dev->usb_device, 0,
-	    hub_port_changes_callback, ((hub_dev->port_count + 1 + 8) / 8),
-	    usb_hub_polling_terminated_callback, hub_dev);
-	if (opResult != EOK) {
-		usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
+	opResult = usb_device_auto_poll_desc(hub_dev->usb_device,
+	    &hub_status_change_endpoint_description,
+	    hub_port_changes_callback, ((hub_dev->port_count + 1 + 7) / 8),
+	    -1, usb_hub_polling_terminated_callback, hub_dev);
+	if (opResult != EOK) {
 		/* Function is already bound */
 		ddf_fun_unbind(hub_dev->hub_fun);
@@ -160,7 +160,6 @@
 	hub_dev->running = true;
 	usb_log_info("Controlling hub '%s' (%zu ports).\n",
-	    ddf_dev_get_name(hub_dev->usb_device->ddf_dev), hub_dev->port_count);
-
-	usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
+	    usb_device_get_name(hub_dev->usb_device), hub_dev->port_count);
+
 	return EOK;
 }
@@ -185,5 +184,5 @@
 {
 	assert(usb_dev);
-	usb_hub_dev_t *hub = usb_dev->driver_data;
+	usb_hub_dev_t *hub = usb_device_data_get(usb_dev);
 	assert(hub);
 	unsigned tries = 10;
@@ -199,10 +198,7 @@
 
 	for (size_t port = 0; port < hub->port_count; ++port) {
-		if (hub->ports[port].attached_device.fun) {
-			const int ret =
-			    usb_hub_port_fini(&hub->ports[port], hub);
-			if (ret != EOK)
-				return ret;
-		}
+		const int ret = usb_hub_port_fini(&hub->ports[port], hub);
+		if (ret != EOK)
+			return ret;
 	}
 	free(hub->ports);
@@ -247,5 +243,5 @@
 
 	/* N + 1 bit indicates change on port N */
-	for (size_t port = 0; port < hub->port_count + 1; port++) {
+	for (size_t port = 0; port < hub->port_count; ++port) {
 		const size_t bit = port + 1;
 		const bool change = (change_bitmap[bit / 8] >> (bit % 8)) & 1;
@@ -273,5 +269,6 @@
 	/* Get hub descriptor. */
 	usb_log_debug("Retrieving descriptor\n");
-	usb_pipe_t *control_pipe = &hub_dev->usb_device->ctrl_pipe;
+	usb_pipe_t *control_pipe =
+	    usb_device_get_default_pipe(hub_dev->usb_device);
 
 	usb_hub_descriptor_header_t descriptor;
@@ -311,5 +308,6 @@
 	}
 
-	usb_log_info("Hub port power switching enabled.\n");
+	usb_log_info("Hub port power switching enabled (%s).\n",
+	    hub_dev->per_port_power ? "per port" : "ganged");
 
 	for (size_t port = 0; port < hub_dev->port_count; ++port) {
@@ -319,5 +317,5 @@
 
 		if (ret != EOK) {
-			usb_log_error("Cannot power on port %zu: %s.\n",
+			usb_log_error("Cannot power on port %u: %s.\n",
 			    hub_dev->ports[port].port_number, str_error(ret));
 		} else {
@@ -345,5 +343,5 @@
 	/* Get number of possible configurations from device descriptor */
 	const size_t configuration_count =
-	    usb_device->descriptors.device.configuration_count;
+	    usb_device_descriptors(usb_device)->device.configuration_count;
 	usb_log_debug("Hub has %zu configurations.\n", configuration_count);
 
@@ -353,6 +351,11 @@
 	}
 
-	if (usb_device->descriptors.configuration_size
-	    < sizeof(usb_standard_configuration_descriptor_t)) {
+	// TODO: Make sure that the cast is correct
+	const size_t config_size =
+	    usb_device_descriptors(usb_device)->full_config_size;
+	const usb_standard_configuration_descriptor_t *config_descriptor =
+	    usb_device_descriptors(usb_device)->full_config;
+
+	if (config_size < sizeof(usb_standard_configuration_descriptor_t)) {
 	    usb_log_error("Configuration descriptor is not big enough"
 	        " to fit standard configuration descriptor.\n");
@@ -360,13 +363,9 @@
 	}
 
-	// TODO: Make sure that the cast is correct
-	usb_standard_configuration_descriptor_t *config_descriptor
-	    = (usb_standard_configuration_descriptor_t *)
-	    usb_device->descriptors.configuration;
-
 	/* Set configuration. Use the configuration that was in
 	 * usb_device->descriptors.configuration i.e. The first one. */
 	const int opResult = usb_request_set_configuration(
-	    &usb_device->ctrl_pipe, config_descriptor->configuration_number);
+	    usb_device_get_default_pipe(usb_device),
+	    config_descriptor->configuration_number);
 	if (opResult != EOK) {
 		usb_log_error("Failed to set hub configuration: %s.\n",
@@ -407,5 +406,5 @@
 		if (ret != EOK) {
 			usb_log_warning("HUB OVER-CURRENT GONE: Cannot power on"
-			    " port %zu: %s\n", hub_dev->ports[port].port_number,
+			    " port %u: %s\n", hub_dev->ports[port].port_number,
 			    str_error(ret));
 		} else {
@@ -428,5 +427,6 @@
 	assert(hub_dev->usb_device);
 	usb_log_debug("Global interrupt on a hub\n");
-	usb_pipe_t *control_pipe = &hub_dev->usb_device->ctrl_pipe;
+	usb_pipe_t *control_pipe =
+	    usb_device_get_default_pipe(hub_dev->usb_device);
 
 	usb_hub_status_t status;
@@ -452,5 +452,5 @@
 		/* Ack change in hub OC flag */
 		const int ret = usb_request_clear_feature(
-		    &hub_dev->usb_device->ctrl_pipe, USB_REQUEST_TYPE_CLASS,
+		    control_pipe, USB_REQUEST_TYPE_CLASS,
 		    USB_REQUEST_RECIPIENT_DEVICE,
 		    USB_HUB_FEATURE_C_HUB_OVER_CURRENT, 0);
Index: uspace/drv/bus/usb/usbhub/usbhub.h
===================================================================
--- uspace/drv/bus/usb/usbhub/usbhub.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/usbhub/usbhub.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -39,5 +39,4 @@
 #include <ddf/driver.h>
 
-#include <usb/dev/hub.h>
 #include <usb/classes/hub.h>
 
@@ -81,4 +80,6 @@
 };
 
+extern const usb_endpoint_description_t hub_status_change_endpoint_description;
+
 int usb_hub_device_add(usb_device_t *usb_dev);
 int usb_hub_device_remove(usb_device_t *usb_dev);
Index: uspace/drv/bus/usb/usbmast/bo_trans.c
===================================================================
--- uspace/drv/bus/usb/usbmast/bo_trans.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/usbmast/bo_trans.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -67,6 +67,6 @@
 	int retval = EOK;
 	size_t act_size;
-	usb_pipe_t *bulk_in_pipe = &mfun->mdev->usb_dev->pipes[BULK_IN_EP].pipe;
-	usb_pipe_t *bulk_out_pipe = &mfun->mdev->usb_dev->pipes[BULK_OUT_EP].pipe;
+	usb_pipe_t *bulk_in_pipe = mfun->mdev->bulk_in_pipe;
+	usb_pipe_t *bulk_out_pipe = mfun->mdev->bulk_out_pipe;
 	usb_direction_t ddir;
 	void *dbuf;
@@ -117,9 +117,11 @@
 		/* Clear stall condition and continue below to read CSW. */
 		if (ddir == USB_DIRECTION_IN) {
-			usb_pipe_clear_halt(&mfun->mdev->usb_dev->ctrl_pipe,
-			    &mfun->mdev->usb_dev->pipes[BULK_IN_EP].pipe);
+			usb_pipe_clear_halt(
+			    usb_device_get_default_pipe(mfun->mdev->usb_dev),
+			    bulk_in_pipe);
 		} else {
-			usb_pipe_clear_halt(&mfun->mdev->usb_dev->ctrl_pipe,
-			    &mfun->mdev->usb_dev->pipes[BULK_OUT_EP].pipe);
+			usb_pipe_clear_halt(
+			    usb_device_get_default_pipe(mfun->mdev->usb_dev),
+			    bulk_out_pipe);
 		}
         } else if (rc != EOK) {
@@ -197,7 +199,8 @@
 int usb_massstor_reset(usbmast_dev_t *mdev)
 {
-	return usb_control_request_set(&mdev->usb_dev->ctrl_pipe,
+	return usb_control_request_set(
+	    usb_device_get_default_pipe(mdev->usb_dev),
 	    USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
-	    0xFF, 0, mdev->usb_dev->interface_no, NULL, 0);
+	    0xFF, 0, usb_device_get_iface_number(mdev->usb_dev), NULL, 0);
 }
 
@@ -215,8 +218,8 @@
 	 */
 	usb_massstor_reset(mdev);
-	usb_pipe_clear_halt(&mdev->usb_dev->ctrl_pipe,
-	    &mdev->usb_dev->pipes[BULK_IN_EP].pipe);
-	usb_pipe_clear_halt(&mdev->usb_dev->ctrl_pipe,
-	    &mdev->usb_dev->pipes[BULK_OUT_EP].pipe);
+	usb_pipe_clear_halt(usb_device_get_default_pipe(mdev->usb_dev),
+	    mdev->bulk_in_pipe);
+	usb_pipe_clear_halt(usb_device_get_default_pipe(mdev->usb_dev),
+	    mdev->bulk_out_pipe);
 }
 
@@ -236,7 +239,9 @@
 	uint8_t max_lun;
 	size_t data_recv_len;
-	int rc = usb_control_request_get(&mdev->usb_dev->ctrl_pipe,
+	int rc = usb_control_request_get(
+	    usb_device_get_default_pipe(mdev->usb_dev),
 	    USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
-	    0xFE, 0, mdev->usb_dev->interface_no, &max_lun, 1, &data_recv_len);
+	    0xFE, 0, usb_device_get_iface_number(mdev->usb_dev), &max_lun, 1,
+	    &data_recv_len);
 	if (rc != EOK) {
 		return rc;
Index: uspace/drv/bus/usb/usbmast/main.c
===================================================================
--- uspace/drv/bus/usb/usbmast/main.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/usbmast/main.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -52,7 +52,4 @@
 #define NAME "usbmast"
 
-#define GET_BULK_IN(dev) ((dev)->pipes[BULK_IN_EP].pipe)
-#define GET_BULK_OUT(dev) ((dev)->pipes[BULK_OUT_EP].pipe)
-
 static const usb_endpoint_description_t bulk_in_ep = {
 	.transfer_type = USB_TRANSFER_BULK,
@@ -110,5 +107,5 @@
 static int usbmast_device_gone(usb_device_t *dev)
 {
-	usbmast_dev_t *mdev = dev->driver_data;
+	usbmast_dev_t *mdev = usb_device_data_get(dev);
 	assert(mdev);
 
@@ -150,4 +147,13 @@
 	unsigned i;
 
+	usb_endpoint_mapping_t *epm_in =
+	    usb_device_get_mapped_ep_desc(dev, &bulk_in_ep);
+	usb_endpoint_mapping_t *epm_out =
+	    usb_device_get_mapped_ep_desc(dev, &bulk_out_ep);
+	if (!epm_in || !epm_out || !epm_in->present || !epm_out->present) {
+		usb_log_error("Required EPs were not mapped.\n");
+		return ENOENT;
+	}
+
 	/* Allocate softstate */
 	mdev = usb_device_data_alloc(dev, sizeof(usbmast_dev_t));
@@ -157,14 +163,12 @@
 	}
 
-	mdev->ddf_dev = dev->ddf_dev;
 	mdev->usb_dev = dev;
 
-	usb_log_info("Initializing mass storage `%s'.\n", ddf_dev_get_name(dev->ddf_dev));
+	usb_log_info("Initializing mass storage `%s'.\n",
+	    usb_device_get_name(dev));
 	usb_log_debug("Bulk in endpoint: %d [%zuB].\n",
-	    dev->pipes[BULK_IN_EP].pipe.endpoint_no,
-	    dev->pipes[BULK_IN_EP].pipe.max_packet_size);
+	    epm_in->pipe.endpoint_no, epm_in->pipe.max_packet_size);
 	usb_log_debug("Bulk out endpoint: %d [%zuB].\n",
-	    dev->pipes[BULK_OUT_EP].pipe.endpoint_no,
-	    dev->pipes[BULK_OUT_EP].pipe.max_packet_size);
+	    epm_out->pipe.endpoint_no, epm_out->pipe.max_packet_size);
 
 	usb_log_debug("Get LUN count...\n");
@@ -177,4 +181,6 @@
 	}
 
+	mdev->bulk_in_pipe = &epm_in->pipe;
+	mdev->bulk_out_pipe = &epm_out->pipe;
 	for (i = 0; i < mdev->lun_count; i++) {
 		rc = usbmast_fun_create(mdev, i);
@@ -221,5 +227,5 @@
 	}
 
-	fun = ddf_fun_create(mdev->ddf_dev, fun_exposed, fun_name);
+	fun = usb_device_ddf_fun_create(mdev->usb_dev, fun_exposed, fun_name);
 	if (fun == NULL) {
 		usb_log_error("Failed to create DDF function %s.\n", fun_name);
@@ -252,5 +258,5 @@
 	if (rc != EOK) {
 		usb_log_warning("Failed to inquire device `%s': %s.\n",
-		    ddf_dev_get_name(mdev->ddf_dev), str_error(rc));
+		    usb_device_get_name(mdev->usb_dev), str_error(rc));
 		rc = EIO;
 		goto error;
@@ -259,5 +265,5 @@
 	usb_log_info("Mass storage `%s' LUN %u: " \
 	    "%s by %s rev. %s is %s (%s).\n",
-	    ddf_dev_get_name(mdev->ddf_dev),
+	    usb_device_get_name(mdev->usb_dev),
 	    lun,
 	    inquiry.product,
@@ -272,5 +278,5 @@
 	if (rc != EOK) {
 		usb_log_warning("Failed to read capacity, device `%s': %s.\n",
-		    ddf_dev_get_name(mdev->ddf_dev), str_error(rc));
+		    usb_device_get_name(mdev->usb_dev), str_error(rc));
 		rc = EIO;
 		goto error;
Index: uspace/drv/bus/usb/usbmast/scsi_ms.c
===================================================================
--- uspace/drv/bus/usb/usbmast/scsi_ms.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/usbmast/scsi_ms.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -88,5 +88,5 @@
 		if (rc != EOK) {
 			usb_log_error("Inquiry transport failed, device %s: %s.\n",
-			   ddf_dev_get_name(mfun->mdev->ddf_dev), str_error(rc));
+			   usb_device_get_name(mfun->mdev->usb_dev), str_error(rc));
 			return rc;
 		}
@@ -96,5 +96,5 @@
 
 		usb_log_error("SCSI command failed, device %s.\n",
-		    ddf_dev_get_name(mfun->mdev->ddf_dev));
+		    usb_device_get_name(mfun->mdev->usb_dev));
 
 		rc = usbmast_request_sense(mfun, &sense_buf, sizeof(sense_buf));
@@ -147,5 +147,5 @@
 	if (rc != EOK) {
 		usb_log_error("Inquiry transport failed, device %s: %s.\n",
-		   ddf_dev_get_name(mfun->mdev->ddf_dev), str_error(rc));
+		   usb_device_get_name(mfun->mdev->usb_dev), str_error(rc));
 		return rc;
 	}
@@ -153,5 +153,5 @@
 	if (cmd.status != CMDS_GOOD) {
 		usb_log_error("Inquiry command failed, device %s.\n",
-		   ddf_dev_get_name(mfun->mdev->ddf_dev));
+		   usb_device_get_name(mfun->mdev->usb_dev));
 		return EIO;
 	}
@@ -215,5 +215,5 @@
         if (rc != EOK || cmd.status != CMDS_GOOD) {
 		usb_log_error("Request Sense failed, device %s: %s.\n",
-		   ddf_dev_get_name(mfun->mdev->ddf_dev), str_error(rc));
+		   usb_device_get_name(mfun->mdev->usb_dev), str_error(rc));
 		return rc;
 	}
@@ -257,5 +257,5 @@
         if (rc != EOK) {
 		usb_log_error("Read Capacity (10) transport failed, device %s: %s.\n",
-		   ddf_dev_get_name(mfun->mdev->ddf_dev), str_error(rc));
+		   usb_device_get_name(mfun->mdev->usb_dev), str_error(rc));
 		return rc;
 	}
@@ -263,5 +263,5 @@
 	if (cmd.status != CMDS_GOOD) {
 		usb_log_error("Read Capacity (10) command failed, device %s.\n",
-		   ddf_dev_get_name(mfun->mdev->ddf_dev));
+		   usb_device_get_name(mfun->mdev->usb_dev));
 		return EIO;
 	}
@@ -314,5 +314,5 @@
         if (rc != EOK) {
 		usb_log_error("Read (10) transport failed, device %s: %s.\n",
-		   ddf_dev_get_name(mfun->mdev->ddf_dev), str_error(rc));
+		   usb_device_get_name(mfun->mdev->usb_dev), str_error(rc));
 		return rc;
 	}
@@ -320,5 +320,5 @@
 	if (cmd.status != CMDS_GOOD) {
 		usb_log_error("Read (10) command failed, device %s.\n",
-		   ddf_dev_get_name(mfun->mdev->ddf_dev));
+		   usb_device_get_name(mfun->mdev->usb_dev));
 		return EIO;
 	}
@@ -370,5 +370,5 @@
         if (rc != EOK) {
 		usb_log_error("Write (10) transport failed, device %s: %s.\n",
-		   ddf_dev_get_name(mfun->mdev->ddf_dev), str_error(rc));
+		   usb_device_get_name(mfun->mdev->usb_dev), str_error(rc));
 		return rc;
 	}
@@ -376,5 +376,5 @@
 	if (cmd.status != CMDS_GOOD) {
 		usb_log_error("Write (10) command failed, device %s.\n",
-		   ddf_dev_get_name(mfun->mdev->ddf_dev));
+		   usb_device_get_name(mfun->mdev->usb_dev));
 		return EIO;
 	}
Index: uspace/drv/bus/usb/usbmast/usbmast.h
===================================================================
--- uspace/drv/bus/usb/usbmast/usbmast.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/usbmast/usbmast.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -43,6 +43,4 @@
 /** Mass storage device. */
 typedef struct usbmast_dev {
-	/** DDF device */
-	ddf_dev_t *ddf_dev;
 	/** USB device */
 	usb_device_t *usb_dev;
@@ -51,4 +49,8 @@
 	/** LUN functions */
 	ddf_fun_t **luns;
+	/** Data read pipe */
+	usb_pipe_t *bulk_in_pipe;
+	/** Data write pipe */
+	usb_pipe_t *bulk_out_pipe;
 } usbmast_dev_t;
 
Index: uspace/drv/bus/usb/usbmid/explore.c
===================================================================
--- uspace/drv/bus/usb/usbmid/explore.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/usbmid/explore.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -40,11 +40,5 @@
 #include <usb/dev/request.h>
 #include <usb/dev/dp.h>
-#include <usb/ddfiface.h>
 #include "usbmid.h"
-
-/** Operations of the device itself. */
-static ddf_dev_ops_t mid_device_ops = {
-	.interfaces[USB_DEV_IFACE] = &usb_iface_hub_impl
-};
 
 /** Tell whether given interface is already in the list.
@@ -56,5 +50,5 @@
 static bool interface_in_list(const list_t *list, int interface_no)
 {
-	list_foreach(*list, link, usbmid_interface_t, iface) {
+	list_foreach(*list, link, const usbmid_interface_t, iface) {
 		if (iface->interface_no == interface_no) {
 			return true;
@@ -71,7 +65,10 @@
  * @param list List where to add the interfaces.
  */
-static void create_interfaces(const uint8_t *config_descriptor,
-    size_t config_descriptor_size, list_t *list)
+static int create_interfaces(const uint8_t *config_descriptor,
+    size_t config_descriptor_size, list_t *list, usb_device_t *usb_dev)
 {
+	assert(config_descriptor);
+	assert(usb_dev);
+
 	const usb_dp_parser_data_t data = {
 		.data = config_descriptor,
@@ -89,5 +86,5 @@
 	/* Walk all descriptors nested in the current configuration decriptor;
 	 * i.e. all interface descriptors. */
-	for (;interface_ptr != NULL;
+	for (; interface_ptr != NULL;
 	    interface_ptr = usb_dp_get_sibling_descriptor(
 	        &parser, &data, config_descriptor, interface_ptr))
@@ -106,17 +103,24 @@
 			continue;
 		}
-		usbmid_interface_t *iface = malloc(sizeof(usbmid_interface_t));
-		if (iface == NULL) {
+
+
+		usb_log_info("Creating child for interface %d (%s).\n",
+		    interface->interface_number,
+		    usb_str_class(interface->interface_class));
+
+		usbmid_interface_t *iface = NULL;
+		const int rc = usbmid_spawn_interface_child(usb_dev, &iface,
+			&usb_device_descriptors(usb_dev)->device, interface);
+		if (rc != EOK) {
 			//TODO: Do something about that failure.
-			break;
+			usb_log_error("Failed to create interface child for "
+			    "%d (%s): %s.\n", interface->interface_number,
+			    usb_str_class(interface->interface_class),
+			    str_error(rc));
+		} else {
+			list_append(&iface->link, list);
 		}
-
-		link_initialize(&iface->link);
-		iface->fun = NULL;
-		iface->interface_no = interface->interface_number;
-		iface->interface = interface;
-
-		list_append(&iface->link, list);
 	}
+	return EOK;
 }
 
@@ -129,9 +133,9 @@
  * @return Whether to accept this device from devman.
  */
-bool usbmid_explore_device(usb_device_t *dev)
+int usbmid_explore_device(usb_device_t *dev)
 {
-	int rc;
-
-	unsigned dev_class = dev->descriptors.device.device_class;
+	assert(dev);
+	const unsigned dev_class =
+	    usb_device_descriptors(dev)->device.device_class;
 	if (dev_class != USB_CLASS_USE_INTERFACE) {
 		usb_log_warning(
@@ -139,37 +143,38 @@
 		    dev_class, usb_str_class(dev_class),
 		    USB_CLASS_USE_INTERFACE);
-		usb_log_error("Not multi interface device, refusing.\n");
-		return false;
+		usb_log_error("Not a multi-interface device, refusing.\n");
+		return ENOTSUP;
 	}
 
-	/* Shortcuts to save on typing ;-). */
-	const void *config_descriptor_raw = dev->descriptors.configuration;
-	size_t config_descriptor_size = dev->descriptors.configuration_size;
+	/* Get coonfiguration descriptor. */
+	const size_t config_descriptor_size =
+	    usb_device_descriptors(dev)->full_config_size;
+	const void *config_descriptor_raw =
+	    usb_device_descriptors(dev)->full_config;
 	const usb_standard_configuration_descriptor_t *config_descriptor =
 	    config_descriptor_raw;
 
 	/* Select the first configuration */
-	rc = usb_request_set_configuration(&dev->ctrl_pipe,
+	int rc = usb_request_set_configuration(usb_device_get_default_pipe(dev),
 	    config_descriptor->configuration_number);
 	if (rc != EOK) {
 		usb_log_error("Failed to set device configuration: %s.\n",
 		    str_error(rc));
-		return false;
+		return rc;
 	}
-
+	
 	/* Create driver soft-state. */
 	usb_mid_t *usb_mid = usb_device_data_alloc(dev, sizeof(usb_mid_t));
 	if (!usb_mid) {
 		usb_log_error("Failed to create USB MID structure.\n");
-		return false;
+		return ENOMEM;
 	}
 
 	/* Create control function. */
-	usb_mid->ctl_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, "ctl");
+	usb_mid->ctl_fun = usb_device_ddf_fun_create(dev, fun_exposed, "ctl");
 	if (usb_mid->ctl_fun == NULL) {
 		usb_log_error("Failed to create control function.\n");
-		return false;
+		return ENOMEM;
 	}
-	ddf_fun_set_ops(usb_mid->ctl_fun, &mid_device_ops);
 
 	/* Bind control function. */
@@ -179,28 +184,13 @@
 		    str_error(rc));
 		ddf_fun_destroy(usb_mid->ctl_fun);
-		return false;
+		return rc;
 	}
-
 
 	/* Create interface children. */
 	list_initialize(&usb_mid->interface_list);
 	create_interfaces(config_descriptor_raw, config_descriptor_size,
-	    &usb_mid->interface_list);
+	    &usb_mid->interface_list, dev);
 
-	/* Start child function for every interface. */
-	list_foreach(usb_mid->interface_list, link, usbmid_interface_t, iface) {
-		usb_log_info("Creating child for interface %d (%s).\n",
-		    iface->interface_no,
-		    usb_str_class(iface->interface->interface_class));
-
-		rc = usbmid_spawn_interface_child(dev, iface,
-		    &dev->descriptors.device, iface->interface);
-		if (rc != EOK) {
-			usb_log_error("Failed to create interface child: %s.\n",
-			    str_error(rc));
-		}
-	}
-
-	return true;
+	return EOK;
 }
 
Index: uspace/drv/bus/usb/usbmid/main.c
===================================================================
--- uspace/drv/bus/usb/usbmid/main.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/usbmid/main.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -51,13 +51,7 @@
 static int usbmid_device_add(usb_device_t *dev)
 {
-	usb_log_info("Taking care of new MID `%s'.\n", ddf_dev_get_name(dev->ddf_dev));
+	usb_log_info("Taking care of new MID `%s'.\n", usb_device_get_name(dev));
 
-	const bool accept = usbmid_explore_device(dev);
-
-	if (!accept) {
-		return ENOTSUP;
-	}
-
-	return EOK;
+	return usbmid_explore_device(dev);
 }
 
@@ -70,5 +64,5 @@
 {
 	assert(dev);
-	usb_mid_t *usb_mid = dev->driver_data;
+	usb_mid_t *usb_mid = usb_device_data_get(dev);
 	assert(usb_mid);
 
@@ -89,15 +83,12 @@
 		usbmid_interface_t *iface = usbmid_interface_from_link(item);
 
-		usb_log_info("Removing child for interface %d (%s).\n",
-		    iface->interface_no,
-		    usb_str_class(iface->interface->interface_class));
+		usb_log_info("Removing child `%s'.\n",
+		    ddf_fun_get_name(iface->fun));
 
 		/* Tell the child to go off-line. */
 		int pret = ddf_fun_offline(iface->fun);
 		if (pret != EOK) {
-			usb_log_warning("Failed to turn off child for interface"
-			    " %d (%s): %s\n", iface->interface_no,
-			    usb_str_class(iface->interface->interface_class),
-			    str_error(pret));
+			usb_log_warning("Failed to turn off child `%s': %s\n",
+			    ddf_fun_get_name(iface->fun), str_error(pret));
 			ret = pret;
 		}
@@ -106,8 +97,6 @@
 		pret = usbmid_interface_destroy(iface);
 		if (pret != EOK) {
-			usb_log_error("Failed to destroy child for interface "
-			    "%d (%s): %s\n", iface->interface_no,
-			    usb_str_class(iface->interface->interface_class),
-			    str_error(pret));
+			usb_log_error("Failed to destroy child `%s': %s\n",
+			    ddf_fun_get_name(iface->fun), str_error(pret));
 			ret = pret;
 		}
@@ -124,8 +113,8 @@
 {
 	assert(dev);
-	usb_mid_t *usb_mid = dev->driver_data;
+	usb_mid_t *usb_mid = usb_device_data_get(dev);
 	assert(usb_mid);
 
-	usb_log_info("USB MID gone: `%s'.\n", ddf_dev_get_name(dev->ddf_dev));
+	usb_log_info("USB MID gone: `%s'.\n", usb_device_get_name(dev));
 
 	/* Remove ctl function */
@@ -145,15 +134,11 @@
 		usbmid_interface_t *iface = usbmid_interface_from_link(item);
 
-		usb_log_info("Child for interface %d (%s) gone.\n",
-		    iface->interface_no,
-		    usb_str_class(iface->interface->interface_class));
+		usb_log_info("Child `%s' is gone.\n",
+		    ddf_fun_get_name(iface->fun));
 
 		const int pret = usbmid_interface_destroy(iface);
 		if (pret != EOK) {
-			usb_log_error("Failed to remove child for interface "
-			    "%d (%s): %s\n",
-			    iface->interface_no,
-			    usb_str_class(iface->interface->interface_class),
-			    str_error(pret));
+			usb_log_error("Failed to remove child `%s': %s\n",
+			    ddf_fun_get_name(iface->fun), str_error(pret));
 			ret = pret;
 		}
Index: uspace/drv/bus/usb/usbmid/usbmid.c
===================================================================
--- uspace/drv/bus/usb/usbmid/usbmid.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/usbmid/usbmid.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -31,7 +31,4 @@
  */
 
-/* XXX Fix this */
-#define _DDF_DATA_IMPLANT
-
 /**
  * @file
@@ -42,5 +39,4 @@
 #include <stdlib.h>
 #include <usb_iface.h>
-#include <usb/ddfiface.h>
 #include <usb/dev/pipes.h>
 #include <usb/classes/classes.h>
@@ -48,22 +44,35 @@
 #include "usbmid.h"
 
-/** Callback for DDF USB interface. */
-static int usb_iface_get_interface_impl(ddf_fun_t *fun, int *iface_no)
+/** Get USB device handle by calling the parent usb_device_t.
+ *
+ * @param[in] fun Device function the operation is running on.
+ * @param[out] handle Device handle.
+ * @return Error code.
+ */
+static int usb_iface_device_handle(ddf_fun_t *fun, devman_handle_t *handle)
+{
+	assert(fun);
+	assert(handle);
+	usb_device_t *usb_dev = usb_device_get(ddf_fun_get_dev(fun));
+	*handle = usb_device_get_devman_handle(usb_dev);
+	return EOK;
+}
+
+/** Callback for DDF USB get interface. */
+static int usb_iface_iface_no(ddf_fun_t *fun, int *iface_no)
 {
 	usbmid_interface_t *iface = ddf_fun_data_get(fun);
 	assert(iface);
 
-	if (iface_no != NULL) {
+	if (iface_no)
 		*iface_no = iface->interface_no;
-	}
 
 	return EOK;
 }
 
-/** DDF interface of the child - interface function. */
+/** DDF interface of the child - USB functions. */
 static usb_iface_t child_usb_iface = {
-	.get_hc_handle = usb_iface_get_hc_handle_device_impl,
-	.get_my_address = usb_iface_get_my_address_forward_impl,
-	.get_my_interface = usb_iface_get_interface_impl,
+	.get_my_device_handle = usb_iface_device_handle,
+	.get_my_interface = usb_iface_iface_no,
 };
 
@@ -81,9 +90,5 @@
 		return ret;
 	}
-	/* NOTE: usbmid->interface points somewhere, but we did not
-	 * allocate that space, so don't touch */
 	ddf_fun_destroy(mid_iface->fun);
-	/* NOTE: mid_iface is invalid at this point, it was assigned to
-	 * mid_iface->fun->driver_data and freed in ddf_fun_destroy */
 	return EOK;
 }
@@ -98,5 +103,5 @@
  */
 int usbmid_spawn_interface_child(usb_device_t *parent,
-    usbmid_interface_t *iface,
+    usbmid_interface_t **iface_ret,
     const usb_standard_device_descriptor_t *device_descriptor,
     const usb_standard_interface_descriptor_t *interface_descriptor)
@@ -119,5 +124,5 @@
 
 	/* Create the device. */
-	child = ddf_fun_create(parent->ddf_dev, fun_inner, child_name);
+	child = usb_device_ddf_fun_create(parent, fun_inner, child_name);
 	free(child_name);
 	if (child == NULL) {
@@ -144,4 +149,11 @@
 	}
 	clean_match_ids(&match_ids);
+	ddf_fun_set_ops(child, &child_device_ops);
+
+	usbmid_interface_t *iface = ddf_fun_data_alloc(child, sizeof(*iface));
+
+	iface->fun = child;
+	iface->interface_no = interface_descriptor->interface_number;
+	link_initialize(&iface->link);
 
 	rc = ddf_fun_bind(child);
@@ -151,8 +163,5 @@
 		return rc;
 	}
-
-	iface->fun = child;
-	ddf_fun_data_implant(child, iface);
-	ddf_fun_set_ops(child, &child_device_ops);
+	*iface_ret = iface;
 
 	return EOK;
Index: uspace/drv/bus/usb/usbmid/usbmid.h
===================================================================
--- uspace/drv/bus/usb/usbmid/usbmid.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/usbmid/usbmid.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -50,6 +50,4 @@
 	/** Function container. */
 	ddf_fun_t *fun;
-	/** Interface descriptor. */
-	const usb_standard_interface_descriptor_t *interface;
 	/** Interface number. */
 	int interface_no;
@@ -64,6 +62,6 @@
 } usb_mid_t;
 
-bool usbmid_explore_device(usb_device_t *);
-int usbmid_spawn_interface_child(usb_device_t *, usbmid_interface_t *,
+int usbmid_explore_device(usb_device_t *);
+int usbmid_spawn_interface_child(usb_device_t *, usbmid_interface_t **,
     const usb_standard_device_descriptor_t *,
     const usb_standard_interface_descriptor_t *);
Index: uspace/drv/bus/usb/usbmid/usbmid.ma
===================================================================
--- uspace/drv/bus/usb/usbmid/usbmid.ma	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/usbmid/usbmid.ma	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -1,1 +1,2 @@
+100 usb&class=use-interface
 100 usb&mid
Index: uspace/drv/bus/usb/vhc/Makefile
===================================================================
--- uspace/drv/bus/usb/vhc/Makefile	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/vhc/Makefile	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -49,7 +49,5 @@
 	hub/virthubops.c \
 	conndev.c \
-	connhost.c \
 	devconn.c \
-	hub.c \
 	main.c \
 	transfer.c
Index: uspace/drv/bus/usb/vhc/conn.h
===================================================================
--- uspace/drv/bus/usb/vhc/conn.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ 	(revision )
@@ -1,54 +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 drvusbvhc
- * @{
- */
-/** @file
- * @brief Connection handling of incoming calls.
- */
-#ifndef VHCD_CONN_H_
-#define VHCD_CONN_H_
-
-#include <usb/usb.h>
-#include <usbhc_iface.h>
-#include <usb_iface.h>
-#include "vhcd.h"
-
-extern usbhc_iface_t vhc_iface;
-extern usb_iface_t vhc_usb_iface;
-extern usb_iface_t rh_usb_iface;
-
-void default_connection_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *);
-void on_client_close(ddf_fun_t *);
-
-
-#endif
-/**
- * @}
- */
Index: uspace/drv/bus/usb/vhc/conndev.c
===================================================================
--- uspace/drv/bus/usb/vhc/conndev.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/vhc/conndev.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -38,6 +38,8 @@
 #include <ddf/driver.h>
 #include <usbvirt/ipc.h>
+#include <usb/debug.h>
 #include <async.h>
-#include "conn.h"
+
+#include "vhcd.h"
 
 static fibril_local uintptr_t plugged_device_handle = 0;
@@ -94,5 +96,5 @@
     ipc_call_t *icall)
 {
-	vhc_data_t *vhc = ddf_dev_data_get(ddf_fun_get_dev(fun));
+	vhc_data_t *vhc = ddf_fun_data_get(fun);
 	
 	async_sess_t *callback =
@@ -125,5 +127,5 @@
 void on_client_close(ddf_fun_t *fun)
 {
-	vhc_data_t *vhc = ddf_dev_data_get(ddf_fun_get_dev(fun));
+	vhc_data_t *vhc = ddf_fun_data_get(fun);
 
 	if (plugged_device_handle != 0) {
Index: uspace/drv/bus/usb/vhc/connhost.c
===================================================================
--- uspace/drv/bus/usb/vhc/connhost.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ 	(revision )
@@ -1,533 +1,0 @@
-/*
- * Copyright (c) 2011 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 drvusbvhc
- * @{
- */
-/** @file
- * Host controller interface implementation.
- */
-#include <assert.h>
-#include <errno.h>
-#include <usb/usb.h>
-#include <usb/ddfiface.h>
-#include <usb/debug.h>
-#include <usbhc_iface.h>
-#include "vhcd.h"
-
-#define GET_VHC_DATA(fun) \
-	((vhc_data_t *)ddf_dev_data_get(ddf_fun_get_dev(fun)))
-#define VHC_DATA(vhc, fun) \
-	vhc_data_t *vhc = GET_VHC_DATA(fun); assert(vhc->magic == 0xdeadbeef)
-
-#define UNSUPPORTED(methodname) \
-	usb_log_warning("Unsupported interface method `%s()' in %s:%d.\n", \
-	    methodname, __FILE__, __LINE__)
-
-/** Found free USB address.
- *
- * @param[in] fun Device function the action was invoked on.
- * @param[in] speed Speed of the device that will get this address.
- * @param[out] address Non-null pointer where to store the free address.
- * @return Error code.
- */
-static int request_address(ddf_fun_t *fun, usb_address_t *address, bool strict,
-    usb_speed_t speed)
-{
-	VHC_DATA(vhc, fun);
-
-	assert(address);
-	return usb_device_manager_request_address(
-	    &vhc->dev_manager, address, strict, speed);
-}
-
-/** Bind USB address with device devman handle.
- *
- * @param[in] fun Device function the action was invoked on.
- * @param[in] address USB address of the device.
- * @param[in] handle Devman handle of the device.
- * @return Error code.
- */
-static int bind_address(ddf_fun_t *fun,
-    usb_address_t address, devman_handle_t handle)
-{
-	VHC_DATA(vhc, fun);
-	usb_log_debug("Binding handle %" PRIun " to address %d.\n",
-	    handle, address);
-	usb_device_manager_bind_address(&vhc->dev_manager, address, handle);
-
-	return EOK;
-}
-
-/** Find device handle by address interface function.
- *
- * @param[in] fun DDF function that was called.
- * @param[in] address Address in question.
- * @param[out] handle Where to store device handle if found.
- * @return Error code.
- */
-static int find_by_address(ddf_fun_t *fun, usb_address_t address,
-    devman_handle_t *handle)
-{
-	VHC_DATA(vhc, fun);
-	return usb_device_manager_get_info_by_address(
-	    &vhc->dev_manager, address, handle, NULL);
-}
-
-/** Release previously requested address.
- *
- * @param[in] fun Device function the action was invoked on.
- * @param[in] address USB address to be released.
- * @return Error code.
- */
-static int release_address(ddf_fun_t *fun, usb_address_t address)
-{
-	VHC_DATA(vhc, fun);
-	usb_log_debug("Releasing address %d...\n", address);
-	usb_device_manager_release_address(&vhc->dev_manager, address);
-
-	return ENOTSUP;
-}
-
-/** Register endpoint for bandwidth reservation.
- *
- * @param[in] fun Device function the action was invoked on.
- * @param[in] address USB address of the device.
- * @param[in] speed Endpoint speed (invalid means to use device one).
- * @param[in] endpoint Endpoint number.
- * @param[in] transfer_type USB transfer type.
- * @param[in] direction Endpoint data direction.
- * @param[in] max_packet_size Max packet size of the endpoint.
- * @param[in] interval Polling interval.
- * @return Error code.
- */
-static int register_endpoint(ddf_fun_t *fun,
-    usb_address_t address, usb_endpoint_t endpoint,
-    usb_transfer_type_t transfer_type, usb_direction_t direction,
-    size_t max_packet_size, unsigned int interval)
-{
-	VHC_DATA(vhc, fun);
-
-	return usb_endpoint_manager_add_ep(&vhc->ep_manager,
-	    address, endpoint, direction, transfer_type, USB_SPEED_FULL, 1, 0,
-	    NULL, NULL);
-
-}
-
-/** Unregister endpoint (free some bandwidth reservation).
- *
- * @param[in] fun Device function the action was invoked on.
- * @param[in] address USB address of the device.
- * @param[in] endpoint Endpoint number.
- * @param[in] direction Endpoint data direction.
- * @return Error code.
- */
-static int unregister_endpoint(ddf_fun_t *fun, usb_address_t address,
-    usb_endpoint_t endpoint, usb_direction_t direction)
-{
-	VHC_DATA(vhc, fun);
-
-	int rc = usb_endpoint_manager_remove_ep(&vhc->ep_manager,
-	    address, endpoint, direction, NULL, NULL);
-
-	return rc;
-}
-#if 0
-/** Schedule interrupt out transfer.
- *
- * The callback is supposed to be called once the transfer (on the wire) is
- * complete regardless of the outcome.
- * However, the callback could be called only when this function returns
- * with success status (i.e. returns EOK).
- *
- * @param[in] fun Device function the action was invoked on.
- * @param[in] target Target pipe (address and endpoint number) specification.
- * @param[in] data Data to be sent (in USB endianess, allocated and deallocated
- *	by the caller).
- * @param[in] size Size of the @p data buffer in bytes.
- * @param[in] callback Callback to be issued once the transfer is complete.
- * @param[in] arg Pass-through argument to the callback.
- * @return Error code.
- */
-static int interrupt_out(ddf_fun_t *fun, usb_target_t target,
-    void *data, size_t size,
-    usbhc_iface_transfer_out_callback_t callback, void *arg)
-{
-	VHC_DATA(vhc, fun);
-
-	vhc_transfer_t *transfer = vhc_transfer_create(target.address,
-	    target.endpoint, USB_DIRECTION_OUT, USB_TRANSFER_INTERRUPT,
-	    fun, arg);
-	if (transfer == NULL) {
-		return ENOMEM;
-	}
-
-	transfer->data_buffer = data;
-	transfer->data_buffer_size = size;
-	transfer->callback_out = callback;
-
-	int rc = vhc_virtdev_add_transfer(vhc, transfer);
-	if (rc != EOK) {
-		free(transfer);
-		return rc;
-	}
-
-	return EOK;
-}
-
-/** Schedule interrupt in transfer.
- *
- * The callback is supposed to be called once the transfer (on the wire) is
- * complete regardless of the outcome.
- * However, the callback could be called only when this function returns
- * with success status (i.e. returns EOK).
- *
- * @param[in] fun Device function the action was invoked on.
- * @param[in] target Target pipe (address and endpoint number) specification.
- * @param[in] data Buffer where to store the data (in USB endianess,
- *	allocated and deallocated by the caller).
- * @param[in] size Size of the @p data buffer in bytes.
- * @param[in] callback Callback to be issued once the transfer is complete.
- * @param[in] arg Pass-through argument to the callback.
- * @return Error code.
- */
-static int interrupt_in(ddf_fun_t *fun, usb_target_t target,
-    void *data, size_t size,
-    usbhc_iface_transfer_in_callback_t callback, void *arg)
-{
-	VHC_DATA(vhc, fun);
-
-	vhc_transfer_t *transfer = vhc_transfer_create(target.address,
-	    target.endpoint, USB_DIRECTION_IN, USB_TRANSFER_INTERRUPT,
-	    fun, arg);
-	if (transfer == NULL) {
-		return ENOMEM;
-	}
-
-	transfer->data_buffer = data;
-	transfer->data_buffer_size = size;
-	transfer->callback_in = callback;
-
-	int rc = vhc_virtdev_add_transfer(vhc, transfer);
-	if (rc != EOK) {
-		free(transfer);
-		return rc;
-	}
-
-	return EOK;
-}
-
-/** Schedule bulk out transfer.
- *
- * The callback is supposed to be called once the transfer (on the wire) is
- * complete regardless of the outcome.
- * However, the callback could be called only when this function returns
- * with success status (i.e. returns EOK).
- *
- * @param[in] fun Device function the action was invoked on.
- * @param[in] target Target pipe (address and endpoint number) specification.
- * @param[in] data Data to be sent (in USB endianess, allocated and deallocated
- *	by the caller).
- * @param[in] size Size of the @p data buffer in bytes.
- * @param[in] callback Callback to be issued once the transfer is complete.
- * @param[in] arg Pass-through argument to the callback.
- * @return Error code.
- */
-static int bulk_out(ddf_fun_t *fun, usb_target_t target,
-    void *data, size_t size,
-    usbhc_iface_transfer_out_callback_t callback, void *arg)
-{
-	UNSUPPORTED("bulk_out");
-
-	return ENOTSUP;
-}
-
-/** Schedule bulk in transfer.
- *
- * The callback is supposed to be called once the transfer (on the wire) is
- * complete regardless of the outcome.
- * However, the callback could be called only when this function returns
- * with success status (i.e. returns EOK).
- *
- * @param[in] fun Device function the action was invoked on.
- * @param[in] target Target pipe (address and endpoint number) specification.
- * @param[in] data Buffer where to store the data (in USB endianess,
- *	allocated and deallocated by the caller).
- * @param[in] size Size of the @p data buffer in bytes.
- * @param[in] callback Callback to be issued once the transfer is complete.
- * @param[in] arg Pass-through argument to the callback.
- * @return Error code.
- */
-static int bulk_in(ddf_fun_t *fun, usb_target_t target,
-    void *data, size_t size,
-    usbhc_iface_transfer_in_callback_t callback, void *arg)
-{
-	UNSUPPORTED("bulk_in");
-
-	return ENOTSUP;
-}
-
-/** Schedule control write transfer.
- *
- * The callback is supposed to be called once the transfer (on the wire) is
- * complete regardless of the outcome.
- * However, the callback could be called only when this function returns
- * with success status (i.e. returns EOK).
- *
- * @param[in] fun Device function the action was invoked on.
- * @param[in] target Target pipe (address and endpoint number) specification.
- * @param[in] setup_packet Setup packet buffer (in USB endianess, allocated
- *	and deallocated by the caller).
- * @param[in] setup_packet_size Size of @p setup_packet buffer in bytes.
- * @param[in] data_buffer Data buffer (in USB endianess, allocated and
- *	deallocated by the caller).
- * @param[in] data_buffer_size Size of @p data_buffer buffer in bytes.
- * @param[in] callback Callback to be issued once the transfer is complete.
- * @param[in] arg Pass-through argument to the callback.
- * @return Error code.
- */
-static int control_write(ddf_fun_t *fun, usb_target_t target,
-    void *setup_packet, size_t setup_packet_size,
-    void *data_buffer, size_t data_buffer_size,
-    usbhc_iface_transfer_out_callback_t callback, void *arg)
-{
-	VHC_DATA(vhc, fun);
-
-	vhc_transfer_t *transfer = vhc_transfer_create(target.address,
-	    target.endpoint, USB_DIRECTION_OUT, USB_TRANSFER_CONTROL,
-	    fun, arg);
-	if (transfer == NULL) {
-		return ENOMEM;
-	}
-
-	transfer->setup_buffer = setup_packet;
-	transfer->setup_buffer_size = setup_packet_size;
-	transfer->data_buffer = data_buffer;
-	transfer->data_buffer_size = data_buffer_size;
-	transfer->callback_out = callback;
-
-	int rc = vhc_virtdev_add_transfer(vhc, transfer);
-	if (rc != EOK) {
-		free(transfer);
-		return rc;
-	}
-
-	return EOK;
-}
-
-/** Schedule control read transfer.
- *
- * The callback is supposed to be called once the transfer (on the wire) is
- * complete regardless of the outcome.
- * However, the callback could be called only when this function returns
- * with success status (i.e. returns EOK).
- *
- * @param[in] fun Device function the action was invoked on.
- * @param[in] target Target pipe (address and endpoint number) specification.
- * @param[in] setup_packet Setup packet buffer (in USB endianess, allocated
- *	and deallocated by the caller).
- * @param[in] setup_packet_size Size of @p setup_packet buffer in bytes.
- * @param[in] data_buffer Buffer where to store the data (in USB endianess,
- *	allocated and deallocated by the caller).
- * @param[in] data_buffer_size Size of @p data_buffer buffer in bytes.
- * @param[in] callback Callback to be issued once the transfer is complete.
- * @param[in] arg Pass-through argument to the callback.
- * @return Error code.
- */
-static int control_read(ddf_fun_t *fun, usb_target_t target,
-    void *setup_packet, size_t setup_packet_size,
-    void *data_buffer, size_t data_buffer_size,
-    usbhc_iface_transfer_in_callback_t callback, void *arg)
-{
-	VHC_DATA(vhc, fun);
-
-	vhc_transfer_t *transfer = vhc_transfer_create(target.address,
-	    target.endpoint, USB_DIRECTION_IN, USB_TRANSFER_CONTROL,
-	    fun, arg);
-	if (transfer == NULL) {
-		return ENOMEM;
-	}
-
-	transfer->setup_buffer = setup_packet;
-	transfer->setup_buffer_size = setup_packet_size;
-	transfer->data_buffer = data_buffer;
-	transfer->data_buffer_size = data_buffer_size;
-	transfer->callback_in = callback;
-
-	int rc = vhc_virtdev_add_transfer(vhc, transfer);
-	if (rc != EOK) {
-		free(transfer);
-		return rc;
-	}
-
-	return EOK;
-}
-#endif
-static int usb_read(ddf_fun_t *fun, usb_target_t target, uint64_t setup_buffer,
-    uint8_t *data_buffer, size_t data_buffer_size,
-    usbhc_iface_transfer_in_callback_t callback, void *arg)
-{
-	VHC_DATA(vhc, fun);
-
-	endpoint_t *ep = usb_endpoint_manager_find_ep(&vhc->ep_manager,
-	    target.address, target.endpoint, USB_DIRECTION_IN);
-	if (ep == NULL) {
-		return ENOENT;
-	}
-	const usb_transfer_type_t transfer_type = ep->transfer_type;
-
-
-	vhc_transfer_t *transfer = vhc_transfer_create(target.address,
-	    target.endpoint, USB_DIRECTION_IN, transfer_type,
-	    fun, arg);
-	if (transfer == NULL) {
-		return ENOMEM;
-	}
-	if (transfer_type == USB_TRANSFER_CONTROL) {
-		transfer->setup_buffer = malloc(sizeof(uint64_t));
-		assert(transfer->setup_buffer);
-		memcpy(transfer->setup_buffer, &setup_buffer, sizeof(uint64_t));
-		transfer->setup_buffer_size = sizeof(uint64_t);
-	}
-	transfer->data_buffer = data_buffer;
-	transfer->data_buffer_size = data_buffer_size;
-	transfer->callback_in = callback;
-
-	int rc = vhc_virtdev_add_transfer(vhc, transfer);
-	if (rc != EOK) {
-		if (transfer->setup_buffer != NULL) {
-			free(transfer->setup_buffer);
-		}
-		free(transfer);
-		return rc;
-	}
-
-	return EOK;
-}
-
-static int usb_write(ddf_fun_t *fun, usb_target_t target, uint64_t setup_buffer,
-    const uint8_t *data_buffer, size_t data_buffer_size,
-    usbhc_iface_transfer_out_callback_t callback, void *arg)
-{
-	VHC_DATA(vhc, fun);
-
-	endpoint_t *ep = usb_endpoint_manager_find_ep(&vhc->ep_manager,
-	    target.address, target.endpoint, USB_DIRECTION_OUT);
-	if (ep == NULL) {
-		return ENOENT;
-	}
-	const usb_transfer_type_t transfer_type = ep->transfer_type;
-
-
-	vhc_transfer_t *transfer = vhc_transfer_create(target.address,
-	    target.endpoint, USB_DIRECTION_OUT, transfer_type,
-	    fun, arg);
-	if (transfer == NULL) {
-		return ENOMEM;
-	}
-	if (transfer_type == USB_TRANSFER_CONTROL) {
-		transfer->setup_buffer = malloc(sizeof(uint64_t));
-		assert(transfer->setup_buffer);
-		memcpy(transfer->setup_buffer, &setup_buffer, sizeof(uint64_t));
-		transfer->setup_buffer_size = sizeof(uint64_t);
-	}
-	transfer->data_buffer = (void*)data_buffer;
-	transfer->data_buffer_size = data_buffer_size;
-	transfer->callback_out = callback;
-
-	int rc = vhc_virtdev_add_transfer(vhc, transfer);
-	if (rc != EOK) {
-		free(transfer->setup_buffer);
-		free(transfer);
-		return rc;
-	}
-
-	return EOK;
-}
-
-static int tell_address(ddf_fun_t *fun, usb_address_t *address)
-{
-	UNSUPPORTED("tell_address");
-
-	return ENOTSUP;
-}
-
-static int usb_iface_get_hc_handle_rh_impl(ddf_fun_t *root_hub_fun,
-    devman_handle_t *handle)
-{
-	VHC_DATA(vhc, root_hub_fun);
-
-	*handle = ddf_fun_get_handle(vhc->hc_fun);
-
-	return EOK;
-}
-
-static int tell_address_rh(ddf_fun_t *root_hub_fun, usb_address_t *address)
-{
-	VHC_DATA(vhc, root_hub_fun);
-
-	devman_handle_t handle = ddf_fun_get_handle(root_hub_fun);
-
-	usb_log_debug("tell_address_rh(handle=%" PRIun ")\n", handle);
-	const usb_address_t addr =
-	    usb_device_manager_find_address(&vhc->dev_manager, handle);
-	if (addr < 0) {
-		return addr;
-	} else {
-		*address = addr;
-		return EOK;
-	}
-}
-
-usbhc_iface_t vhc_iface = {
-	.request_address = request_address,
-	.bind_address = bind_address,
-	.get_handle = find_by_address,
-	.release_address = release_address,
-
-	.register_endpoint = register_endpoint,
-	.unregister_endpoint = unregister_endpoint,
-
-	.write = usb_write,
-	.read = usb_read,
-};
-
-usb_iface_t vhc_usb_iface = {
-	.get_hc_handle = usb_iface_get_hc_handle_hc_impl,
-	.get_my_address = tell_address
-};
-
-usb_iface_t rh_usb_iface = {
-	.get_hc_handle = usb_iface_get_hc_handle_rh_impl,
-	.get_my_address = tell_address_rh
-};
-
-
-/**
- * @}
- */
Index: uspace/drv/bus/usb/vhc/devconn.c
===================================================================
--- uspace/drv/bus/usb/vhc/devconn.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/vhc/devconn.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -51,5 +51,5 @@
 static int vhc_virtdev_plug_generic(vhc_data_t *vhc,
     async_sess_t *sess, usbvirt_device_t *virtdev,
-    uintptr_t *handle, bool connect)
+    uintptr_t *handle, bool connect, usb_address_t address)
 {
 	vhc_virtdev_t *dev = vhc_virtdev_create();
@@ -60,4 +60,5 @@
 	dev->dev_sess = sess;
 	dev->dev_local = virtdev;
+	dev->address = address;
 
 	fibril_mutex_lock(&vhc->guard);
@@ -78,5 +79,5 @@
 	if (connect) {
 		// FIXME: check status
-		(void) virthub_connect_device(vhc->hub, dev);
+		(void) virthub_connect_device(&vhc->hub, dev);
 	}
 
@@ -86,15 +87,15 @@
 int vhc_virtdev_plug(vhc_data_t *vhc, async_sess_t *sess, uintptr_t *handle)
 {
-	return vhc_virtdev_plug_generic(vhc, sess, NULL, handle, true);
+	return vhc_virtdev_plug_generic(vhc, sess, NULL, handle, true, 0);
 }
 
 int vhc_virtdev_plug_local(vhc_data_t *vhc, usbvirt_device_t *dev, uintptr_t *handle)
 {
-	return vhc_virtdev_plug_generic(vhc, NULL, dev, handle, true);
+	return vhc_virtdev_plug_generic(vhc, NULL, dev, handle, true, 0);
 }
 
-int vhc_virtdev_plug_hub(vhc_data_t *vhc, usbvirt_device_t *dev, uintptr_t *handle)
+int vhc_virtdev_plug_hub(vhc_data_t *vhc, usbvirt_device_t *dev, uintptr_t *handle, usb_address_t address)
 {
-	return vhc_virtdev_plug_generic(vhc, NULL, dev, handle, false);
+	return vhc_virtdev_plug_generic(vhc, NULL, dev, handle, false, address);
 }
 
@@ -104,5 +105,5 @@
 
 	// FIXME: check status
-	(void) virthub_disconnect_device(vhc->hub, dev);
+	(void) virthub_disconnect_device(&vhc->hub, dev);
 
 	fibril_mutex_lock(&vhc->guard);
Index: uspace/drv/bus/usb/vhc/hub.c
===================================================================
--- uspace/drv/bus/usb/vhc/hub.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ 	(revision )
@@ -1,133 +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 drvusbvhc
- * @{
- */
-/** @file
- * @brief Virtual USB hub.
- */
-
-#include <usb/classes/classes.h>
-#include <usbvirt/device.h>
-#include <errno.h>
-#include <async.h>
-#include <str_error.h>
-#include <stdlib.h>
-#include <ddf/driver.h>
-#include <devman.h>
-#include <usb/dev/hub.h>
-#include <usb/dev/recognise.h>
-
-#include "hub.h"
-#include "vhcd.h"
-#include "conn.h"
-
-usbvirt_device_t virtual_hub_device = {
-	.name = "root hub",
-	.ops = &hub_ops,
-	.address = 0
-};
-
-static ddf_dev_ops_t rh_ops = {
-	.interfaces[USB_DEV_IFACE] = &rh_usb_iface,
-};
-
-static int hub_register_in_devman_fibril(void *arg);
-
-void virtual_hub_device_init(ddf_fun_t *hc_dev)
-{
-	virthub_init(&virtual_hub_device);
-
-	/*
-	 * We need to register the root hub.
-	 * This must be done in separate fibril because the device
-	 * we are connecting to are ourselves and we cannot connect
-	 * before leaving the add_device() function.
-	 */
-	fid_t root_hub_registration
-	    = fibril_create(hub_register_in_devman_fibril, hc_dev);
-	if (root_hub_registration == 0) {
-		usb_log_fatal("Failed to create hub registration fibril.\n");
-		return;
-	}
-
-	fibril_add_ready(root_hub_registration);
-}
-
-static int pretend_port_rest(void *unused2)
-{
-	return EOK;
-}
-
-/** Register root hub in devman.
- *
- * @param arg Host controller device (type <code>device_t *</code>).
- * @return Error code.
- */
-int hub_register_in_devman_fibril(void *arg)
-{
-	ddf_fun_t *hc_dev = (ddf_fun_t *) arg;
-
-	/*
-	 * Wait until parent device is properly initialized.
-	 */
-	async_sess_t *sess;
-	do {
-		sess = devman_device_connect(EXCHANGE_SERIALIZE,
-		    ddf_fun_get_handle(hc_dev), 0);
-	} while (!sess);
-	async_hangup(sess);
-
-	int rc;
-
-	usb_hc_connection_t hc_conn;
-	usb_hc_connection_initialize(&hc_conn, ddf_fun_get_handle(hc_dev));
-
-	rc = usb_hc_connection_open(&hc_conn);
-	assert(rc == EOK);
-
-	ddf_fun_t *hub_dev;
-	rc = usb_hc_new_device_wrapper(ddf_fun_get_dev(hc_dev), &hc_conn, USB_SPEED_FULL,
-	    pretend_port_rest, NULL, NULL, &rh_ops, hc_dev, &hub_dev);
-	if (rc != EOK) {
-		usb_log_fatal("Failed to create root hub: %s.\n",
-		    str_error(rc));
-	}
-
-	usb_hc_connection_close(&hc_conn);
-
-	usb_log_info("Created root hub function (handle %zu).\n",
-	    (size_t) ddf_fun_get_handle(hub_dev));
-
-	return 0;
-}
-
-/**
- * @}
- */
Index: uspace/drv/bus/usb/vhc/hub.h
===================================================================
--- uspace/drv/bus/usb/vhc/hub.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ 	(revision )
@@ -1,52 +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 drvusbvhc
- * @{
- */
-/** @file
- * @brief Virtual USB hub.
- */
-
-#ifndef VHCD_HUB_H_
-#define VHCD_HUB_H_
-
-#include <usbvirt/device.h>
-#include <ddf/driver.h>
-
-#include "hub/hub.h"
-#include "hub/virthub.h"
-
-extern usbvirt_device_t virtual_hub_device;
-
-void virtual_hub_device_init(ddf_fun_t *);
-
-#endif
-/**
- * @}
- */
Index: uspace/drv/bus/usb/vhc/hub/virthub.c
===================================================================
--- uspace/drv/bus/usb/vhc/hub/virthub.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/vhc/hub/virthub.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -34,8 +34,10 @@
  */
 #include <usb/classes/classes.h>
+#include <usb/classes/hub.h>
 #include <usbvirt/device.h>
 #include <assert.h>
 #include <errno.h>
 #include <str_error.h>
+#include <stdio.h>
 #include <assert.h>
 #include <stdlib.h>
@@ -76,5 +78,5 @@
 	.type = USB_DESCTYPE_HUB,
 	.port_count = HUB_PORT_COUNT,
-	.characteristics = 0, 
+	.characteristics = HUB_CHAR_NO_POWER_SWITCH_FLAG | HUB_CHAR_NO_OC_FLAG,
 	.power_on_warm_up = 50, /* Huh? */
 	.max_current = 100, /* Huh again. */
@@ -97,5 +99,5 @@
 	.length = sizeof(usb_standard_configuration_descriptor_t),
 	.descriptor_type = USB_DESCTYPE_CONFIGURATION,
-	.total_length = 
+	.total_length =
 		sizeof(usb_standard_configuration_descriptor_t)
 		+ sizeof(std_interface_descriptor)
@@ -145,5 +147,5 @@
  * @return Error code.
  */
-int virthub_init(usbvirt_device_t *dev)
+int virthub_init(usbvirt_device_t *dev, const char* name)
 {
 	if (dev == NULL) {
@@ -152,7 +154,12 @@
 	dev->ops = &hub_ops;
 	dev->descriptors = &descriptors;
+	dev->address = 0;
+	dev->name = str_dup(name);
+	if (!dev->name)
+		return ENOMEM;
 
 	hub_t *hub = malloc(sizeof(hub_t));
 	if (hub == NULL) {
+		free(dev->name);
 		return ENOMEM;
 	}
Index: uspace/drv/bus/usb/vhc/hub/virthub.h
===================================================================
--- uspace/drv/bus/usb/vhc/hub/virthub.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/vhc/hub/virthub.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -79,5 +79,5 @@
 extern hub_descriptor_t hub_descriptor;
 
-int virthub_init(usbvirt_device_t *);
+int virthub_init(usbvirt_device_t *, const char *name);
 int virthub_connect_device(usbvirt_device_t *, vhc_virtdev_t *);
 int virthub_disconnect_device(usbvirt_device_t *, vhc_virtdev_t *);
Index: uspace/drv/bus/usb/vhc/hub/virthubops.c
===================================================================
--- uspace/drv/bus/usb/vhc/hub/virthubops.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/vhc/hub/virthubops.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -340,12 +340,4 @@
 
 
-/** IN class request. */
-#define CLASS_REQ_IN(recipient) \
-	USBVIRT_MAKE_CONTROL_REQUEST_TYPE(USB_DIRECTION_IN, \
-	USBVIRT_REQUEST_TYPE_CLASS, recipient)
-/** OUT class request. */
-#define CLASS_REQ_OUT(recipient) \
-	USBVIRT_MAKE_CONTROL_REQUEST_TYPE(USB_DIRECTION_OUT, \
-	USBVIRT_REQUEST_TYPE_CLASS, recipient)
 
 /** Recipient: other. */
@@ -353,88 +345,60 @@
 /** Recipient: device. */
 #define REC_DEVICE USB_REQUEST_RECIPIENT_DEVICE
-/** Direction: in. */
-#define DIR_IN USB_DIRECTION_IN
-/** Direction: out. */
-#define DIR_OUT USB_DIRECTION_OUT
-
-
-/** Create a class request.
- *
- * @param direction Request direction.
- * @param recipient Request recipient.
- * @param req Request code.
- */
-#define CLASS_REQ(direction, recipient, req) \
-	.req_direction = direction, \
-	.req_recipient = recipient, \
-	.req_type = USB_REQUEST_TYPE_CLASS, \
-	.request = req
-
-/** Create a standard request.
- *
- * @param direction Request direction.
- * @param recipient Request recipient.
- * @param req Request code.
- */
-#define STD_REQ(direction, recipient, req) \
-	.req_direction = direction, \
-	.req_recipient = recipient, \
-	.req_type = USB_REQUEST_TYPE_STANDARD, \
-	.request = req
+
 
 /** Hub operations on control endpoint zero. */
 static usbvirt_control_request_handler_t endpoint_zero_handlers[] = {
 	{
-		STD_REQ(DIR_IN, REC_DEVICE, USB_DEVREQ_GET_DESCRIPTOR),
+		STD_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_DEVREQ_GET_DESCRIPTOR),
 		.name = "GetDescriptor",
 		.callback = req_get_descriptor
 	},
 	{
-		CLASS_REQ(DIR_IN, REC_DEVICE, USB_DEVREQ_GET_DESCRIPTOR),
+		CLASS_REQ_IN(REC_DEVICE, USB_DEVREQ_GET_DESCRIPTOR),
 		.name = "GetDescriptor",
 		.callback = req_get_descriptor
 	},
 	{
-		CLASS_REQ(DIR_IN, REC_OTHER, USB_HUB_REQUEST_GET_STATUS),
+		CLASS_REQ_IN(REC_OTHER, USB_HUB_REQUEST_GET_STATUS),
 		.name = "GetPortStatus",
 		.callback = req_get_port_status
 	},
 	{
-		CLASS_REQ(DIR_OUT, REC_DEVICE, USB_HUB_REQUEST_CLEAR_FEATURE),
+		CLASS_REQ_OUT(REC_DEVICE, USB_HUB_REQUEST_CLEAR_FEATURE),
 		.name = "ClearHubFeature",
 		.callback = req_clear_hub_feature
 	},
 	{
-		CLASS_REQ(DIR_OUT, REC_OTHER, USB_HUB_REQUEST_CLEAR_FEATURE),
+		CLASS_REQ_OUT(REC_OTHER, USB_HUB_REQUEST_CLEAR_FEATURE),
 		.name = "ClearPortFeature",
 		.callback = req_clear_port_feature
 	},
 	{
-		CLASS_REQ(DIR_IN, REC_OTHER, USB_HUB_REQUEST_GET_STATE),
+		CLASS_REQ_IN(REC_OTHER, USB_HUB_REQUEST_GET_STATE),
 		.name = "GetBusState",
 		.callback = req_get_bus_state
 	},
 	{
-		CLASS_REQ(DIR_IN, REC_DEVICE, USB_HUB_REQUEST_GET_DESCRIPTOR),
+		CLASS_REQ_IN(REC_DEVICE, USB_HUB_REQUEST_GET_DESCRIPTOR),
 		.name = "GetHubDescriptor",
 		.callback = req_get_descriptor
 	},
 	{
-		CLASS_REQ(DIR_IN, REC_DEVICE, USB_HUB_REQUEST_GET_STATUS),
+		CLASS_REQ_IN(REC_DEVICE, USB_HUB_REQUEST_GET_STATUS),
 		.name = "GetHubStatus",
 		.callback = req_get_hub_status
 	},
 	{
-		CLASS_REQ(DIR_IN, REC_OTHER, USB_HUB_REQUEST_GET_STATUS),
+		CLASS_REQ_IN(REC_OTHER, USB_HUB_REQUEST_GET_STATUS),
 		.name = "GetPortStatus",
 		.callback = req_get_port_status
 	},
 	{
-		CLASS_REQ(DIR_OUT, REC_DEVICE, USB_HUB_REQUEST_SET_FEATURE),
+		CLASS_REQ_OUT(REC_DEVICE, USB_HUB_REQUEST_SET_FEATURE),
 		.name = "SetHubFeature",
 		.callback = req_set_hub_feature
 	},
 	{
-		CLASS_REQ(DIR_OUT, REC_OTHER, USB_HUB_REQUEST_SET_FEATURE),
+		CLASS_REQ_OUT(REC_OTHER, USB_HUB_REQUEST_SET_FEATURE),
 		.name = "SetPortFeature",
 		.callback = req_set_port_feature
Index: uspace/drv/bus/usb/vhc/main.c
===================================================================
--- uspace/drv/bus/usb/vhc/main.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/vhc/main.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -34,9 +34,4 @@
  */
 
-#include <loc.h>
-#include <async.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <sysinfo.h>
 #include <stdio.h>
 #include <errno.h>
@@ -44,84 +39,82 @@
 #include <ddf/driver.h>
 
-#include <usb/usb.h>
-#include <usb/ddfiface.h>
-#include <usb_iface.h>
+#include <usb/host/ddf_helpers.h>
+
+#include <usb/debug.h>
 #include "vhcd.h"
-#include "hub.h"
-#include "conn.h"
+
 
 static ddf_dev_ops_t vhc_ops = {
-	.interfaces[USBHC_DEV_IFACE] = &vhc_iface,
-	.interfaces[USB_DEV_IFACE] = &vhc_usb_iface,
 	.close = on_client_close,
 	.default_handler = default_connection_handler
 };
 
+static int vhc_control_node(ddf_dev_t *dev, ddf_fun_t **fun)
+{
+	assert(dev);
+	assert(fun);
+
+	*fun = ddf_fun_create(dev, fun_exposed, "ctl");
+	if (!*fun)
+		return ENOMEM;
+
+	vhc_data_t *vhc = ddf_fun_data_alloc(*fun, sizeof(vhc_data_t));
+	if (!vhc) {
+		ddf_fun_destroy(*fun);
+	}
+	ddf_fun_set_ops(*fun, &vhc_ops);
+	const int ret = ddf_fun_bind(*fun);
+	if (ret != EOK) {
+		ddf_fun_destroy(*fun);
+		*fun = NULL;
+		return ret;
+	}
+	vhc_init(vhc);
+	return EOK;
+}
+
 static int vhc_dev_add(ddf_dev_t *dev)
 {
-	static int vhc_count = 0;
-	int rc;
+	/* Initialize virtual structure */
+	ddf_fun_t *ctl_fun = NULL;
+	int ret = vhc_control_node(dev, &ctl_fun);
+	if (ret != EOK) {
+		usb_log_error("Failed to setup control node.\n");
+		return ret;
+	}
+	vhc_data_t *data = ddf_fun_data_get(ctl_fun);
 
-	if (vhc_count > 0) {
-		return ELIMIT;
+	/* Initialize generic structures */
+	ret = hcd_ddf_setup_hc(dev, USB_SPEED_FULL,
+	    BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11);
+	if (ret != EOK) {
+		usb_log_error("Failed to init HCD structures: %s.\n",
+		   str_error(ret));
+		ddf_fun_destroy(ctl_fun);
+		return ret;
 	}
 
-	vhc_data_t *data = ddf_dev_data_alloc(dev, sizeof(vhc_data_t));
-	if (data == NULL) {
-		usb_log_fatal("Failed to allocate memory.\n");
-		return ENOMEM;
-	}
-	data->magic = 0xDEADBEEF;
-	rc = usb_endpoint_manager_init(&data->ep_manager, (size_t) -1,
-	    bandwidth_count_usb11);
-	if (rc != EOK) {
-		usb_log_fatal("Failed to initialize endpoint manager.\n");
-		free(data);
-		return rc;
-	}
-	usb_device_manager_init(&data->dev_manager, USB_SPEED_MAX);
+	hcd_set_implementation(dev_to_hcd(dev), data, vhc_schedule, NULL, NULL);
 
-	ddf_fun_t *hc = ddf_fun_create(dev, fun_exposed, "hc");
-	if (hc == NULL) {
-		usb_log_fatal("Failed to create device function.\n");
-		free(data);
-		return ENOMEM;
+	/* Add virtual hub device */
+	ret = vhc_virtdev_plug_hub(data, &data->hub, NULL, 0);
+	if (ret != EOK) {
+		usb_log_error("Failed to plug root hub: %s.\n", str_error(ret));
+		ddf_fun_destroy(ctl_fun);
+		return ret;
 	}
 
-	ddf_fun_set_ops(hc, &vhc_ops);
-	list_initialize(&data->devices);
-	fibril_mutex_initialize(&data->guard);
-	data->hub = &virtual_hub_device;
-	data->hc_fun = hc;
-
-	rc = ddf_fun_bind(hc);
-	if (rc != EOK) {
-		usb_log_fatal("Failed to bind HC function: %s.\n",
-		    str_error(rc));
-		free(data);
-		return rc;
+	/*
+	 * Creating root hub registers a new USB device so HC
+	 * needs to be ready at this time.
+	 */
+	ret = hcd_ddf_setup_root_hub(dev);
+	if (ret != EOK) {
+		usb_log_error("Failed to init VHC root hub: %s\n",
+			str_error(ret));
+		// TODO do something here...
 	}
 
-	rc = ddf_fun_add_to_category(hc, USB_HC_CATEGORY);
-	if (rc != EOK) {
-		usb_log_fatal("Failed to add function to HC class: %s.\n",
-		    str_error(rc));
-		free(data);
-		return rc;
-	}
-
-	virtual_hub_device_init(hc);
-
-	usb_log_info("Virtual USB host controller ready (dev %zu, hc %zu).\n",
-	    (size_t) ddf_dev_get_handle(dev), (size_t) ddf_fun_get_handle(hc));
-
-	rc = vhc_virtdev_plug_hub(data, data->hub, NULL);
-	if (rc != EOK) {
-		usb_log_fatal("Failed to plug root hub: %s.\n", str_error(rc));
-		free(data);
-		return rc;
-	}
-
-	return EOK;
+	return ret;
 }
 
@@ -135,9 +128,7 @@
 };
 
-
 int main(int argc, char * argv[])
-{	
+{
 	log_init(NAME);
-
 	printf(NAME ": virtual USB host controller driver.\n");
 
@@ -145,5 +136,4 @@
 }
 
-
 /**
  * @}
Index: uspace/drv/bus/usb/vhc/transfer.c
===================================================================
--- uspace/drv/bus/usb/vhc/transfer.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/vhc/transfer.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -29,52 +29,23 @@
 #include <errno.h>
 #include <str_error.h>
+#include <usb/debug.h>
 #include <usbvirt/device.h>
 #include <usbvirt/ipc.h>
 #include "vhcd.h"
-
-vhc_transfer_t *vhc_transfer_create(usb_address_t address, usb_endpoint_t ep,
-    usb_direction_t dir, usb_transfer_type_t tr_type,
-    ddf_fun_t *fun, void *callback_arg)
-{
-	vhc_transfer_t *result = malloc(sizeof(vhc_transfer_t));
-	if (result == NULL) {
-		return NULL;
-	}
-	link_initialize(&result->link);
-	result->address = address;
-	result->endpoint = ep;
-	result->direction = dir;
-	result->transfer_type = tr_type;
-	result->setup_buffer = NULL;
-	result->setup_buffer_size = 0;
-	result->data_buffer = NULL;
-	result->data_buffer_size = 0;
-	result->ddf_fun = fun;
-	result->callback_arg = callback_arg;
-	result->callback_in = NULL;
-	result->callback_out = NULL;
-
-	usb_log_debug2("Created transfer %p (%d.%d %s %s)\n", result,
-	    address, ep, usb_str_transfer_type_short(tr_type),
-	    dir == USB_DIRECTION_IN ? "in" : "out");
-
-	return result;
-}
+#include "hub/virthub.h"
 
 static bool is_set_address_transfer(vhc_transfer_t *transfer)
 {
-	if (transfer->endpoint != 0) {
-		return false;
-	}
-	if (transfer->transfer_type != USB_TRANSFER_CONTROL) {
-		return false;
-	}
-	if (transfer->direction != USB_DIRECTION_OUT) {
-		return false;
-	}
-	if (transfer->setup_buffer_size != sizeof(usb_device_request_setup_packet_t)) {
-		return false;
-	}
-	usb_device_request_setup_packet_t *setup = transfer->setup_buffer;
+	if (transfer->batch->ep->endpoint != 0) {
+		return false;
+	}
+	if (transfer->batch->ep->transfer_type != USB_TRANSFER_CONTROL) {
+		return false;
+	}
+	if (usb_transfer_batch_direction(transfer->batch) != USB_DIRECTION_OUT) {
+		return false;
+	}
+	const usb_device_request_setup_packet_t *setup =
+	    (void*)transfer->batch->setup_buffer;
 	if (setup->request_type != 0) {
 		return false;
@@ -87,94 +58,70 @@
 }
 
-int vhc_virtdev_add_transfer(vhc_data_t *vhc, vhc_transfer_t *transfer)
-{
-	fibril_mutex_lock(&vhc->guard);
-
-	bool target_found = false;
-	list_foreach(vhc->devices, link, vhc_virtdev_t, dev) {
-		fibril_mutex_lock(&dev->guard);
-		if (dev->address == transfer->address) {
-			if (target_found) {
-				usb_log_warning("Transfer would be accepted by more devices!\n");
-				goto next;
-			}
-			target_found = true;
-			list_append(&transfer->link, &dev->transfer_queue);
-		}
-next:
-		fibril_mutex_unlock(&dev->guard);
-	}
-
-	fibril_mutex_unlock(&vhc->guard);
-
-	if (target_found) {
-		return EOK;
+static int process_transfer_local(usb_transfer_batch_t *batch,
+    usbvirt_device_t *dev, size_t *actual_data_size)
+{
+	int rc;
+	
+	const usb_direction_t dir = usb_transfer_batch_direction(batch);
+
+	if (batch->ep->transfer_type == USB_TRANSFER_CONTROL) {
+		if (dir == USB_DIRECTION_IN) {
+			rc = usbvirt_control_read(dev,
+			    batch->setup_buffer, batch->setup_size,
+			    batch->buffer, batch->buffer_size,
+			    actual_data_size);
+		} else {
+			assert(dir == USB_DIRECTION_OUT);
+			rc = usbvirt_control_write(dev,
+			    batch->setup_buffer, batch->setup_size,
+			    batch->buffer, batch->buffer_size);
+		}
 	} else {
-		return ENOENT;
-	}
-}
-
-static int process_transfer_local(vhc_transfer_t *transfer,
-    usbvirt_device_t *dev, size_t *actual_data_size)
+		if (dir == USB_DIRECTION_IN) {
+			rc = usbvirt_data_in(dev, batch->ep->transfer_type,
+			    batch->ep->endpoint,
+			    batch->buffer, batch->buffer_size,
+			    actual_data_size);
+		} else {
+			assert(dir == USB_DIRECTION_OUT);
+			rc = usbvirt_data_out(dev, batch->ep->transfer_type,
+			    batch->ep->endpoint,
+			    batch->buffer, batch->buffer_size);
+		}
+	}
+
+	return rc;
+}
+
+static int process_transfer_remote(usb_transfer_batch_t *batch,
+    async_sess_t *sess, size_t *actual_data_size)
 {
 	int rc;
 
-	if (transfer->transfer_type == USB_TRANSFER_CONTROL) {
-		if (transfer->direction == USB_DIRECTION_IN) {
-			rc = usbvirt_control_read(dev,
-			    transfer->setup_buffer, transfer->setup_buffer_size,
-			    transfer->data_buffer, transfer->data_buffer_size,
-			    actual_data_size);
-		} else {
-			assert(transfer->direction == USB_DIRECTION_OUT);
-			rc = usbvirt_control_write(dev,
-			    transfer->setup_buffer, transfer->setup_buffer_size,
-			    transfer->data_buffer, transfer->data_buffer_size);
+	const usb_direction_t dir = usb_transfer_batch_direction(batch);
+
+	if (batch->ep->transfer_type == USB_TRANSFER_CONTROL) {
+		if (dir == USB_DIRECTION_IN) {
+			rc = usbvirt_ipc_send_control_read(sess,
+			    batch->setup_buffer, batch->setup_size,
+			    batch->buffer, batch->buffer_size,
+			    actual_data_size);
+		} else {
+			assert(dir == USB_DIRECTION_OUT);
+			rc = usbvirt_ipc_send_control_write(sess,
+			    batch->setup_buffer, batch->setup_size,
+			    batch->buffer, batch->buffer_size);
 		}
 	} else {
-		if (transfer->direction == USB_DIRECTION_IN) {
-			rc = usbvirt_data_in(dev, transfer->transfer_type,
-			    transfer->endpoint,
-			    transfer->data_buffer, transfer->data_buffer_size,
-			    actual_data_size);
-		} else {
-			assert(transfer->direction == USB_DIRECTION_OUT);
-			rc = usbvirt_data_out(dev, transfer->transfer_type,
-			    transfer->endpoint,
-			    transfer->data_buffer, transfer->data_buffer_size);
-		}
-	}
-
-	return rc;
-}
-
-static int process_transfer_remote(vhc_transfer_t *transfer,
-    async_sess_t *sess, size_t *actual_data_size)
-{
-	int rc;
-
-	if (transfer->transfer_type == USB_TRANSFER_CONTROL) {
-		if (transfer->direction == USB_DIRECTION_IN) {
-			rc = usbvirt_ipc_send_control_read(sess,
-			    transfer->setup_buffer, transfer->setup_buffer_size,
-			    transfer->data_buffer, transfer->data_buffer_size,
-			    actual_data_size);
-		} else {
-			assert(transfer->direction == USB_DIRECTION_OUT);
-			rc = usbvirt_ipc_send_control_write(sess,
-			    transfer->setup_buffer, transfer->setup_buffer_size,
-			    transfer->data_buffer, transfer->data_buffer_size);
-		}
-	} else {
-		if (transfer->direction == USB_DIRECTION_IN) {
-			rc = usbvirt_ipc_send_data_in(sess, transfer->endpoint,
-			    transfer->transfer_type,
-			    transfer->data_buffer, transfer->data_buffer_size,
-			    actual_data_size);
-		} else {
-			assert(transfer->direction == USB_DIRECTION_OUT);
-			rc = usbvirt_ipc_send_data_out(sess, transfer->endpoint,
-			    transfer->transfer_type,
-			    transfer->data_buffer, transfer->data_buffer_size);
+		if (dir == USB_DIRECTION_IN) {
+			rc = usbvirt_ipc_send_data_in(sess, batch->ep->endpoint,
+			    batch->ep->transfer_type,
+			    batch->buffer, batch->buffer_size,
+			    actual_data_size);
+		} else {
+			assert(dir == USB_DIRECTION_OUT);
+			rc = usbvirt_ipc_send_data_out(sess, batch->ep->endpoint,
+			    batch->ep->transfer_type,
+			    batch->buffer, batch->buffer_size);
 		}
 	}
@@ -195,23 +142,59 @@
 }
 
-
 static void execute_transfer_callback_and_free(vhc_transfer_t *transfer,
     size_t data_transfer_size, int outcome)
 {
 	assert(outcome != ENAK);
-
-	usb_log_debug2("Transfer %p ended: %s.\n",
-	    transfer, str_error(outcome));
-
-	if (transfer->direction == USB_DIRECTION_IN) {
-		transfer->callback_in(transfer->ddf_fun, outcome,
-		    data_transfer_size, transfer->callback_arg);
-	} else {
-		assert(transfer->direction == USB_DIRECTION_OUT);
-		transfer->callback_out(transfer->ddf_fun, outcome,
-		    transfer->callback_arg);
-	}
-
+	assert(transfer);
+	assert(transfer->batch);
+	usb_transfer_batch_finish_error(transfer->batch, NULL,
+	    data_transfer_size, outcome);
+	usb_transfer_batch_destroy(transfer->batch);
 	free(transfer);
+}
+
+int vhc_init(vhc_data_t *instance)
+{
+	assert(instance);
+	list_initialize(&instance->devices);
+	fibril_mutex_initialize(&instance->guard);
+	instance->magic = 0xDEADBEEF;
+	return virthub_init(&instance->hub, "root hub");
+}
+
+int vhc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch)
+{
+	assert(hcd);
+	assert(batch);
+	vhc_data_t *vhc = hcd->private_data;
+	assert(vhc);
+
+	vhc_transfer_t *transfer = malloc(sizeof(vhc_transfer_t));
+	if (!transfer)
+		return ENOMEM;
+	link_initialize(&transfer->link);
+	transfer->batch = batch;
+
+	fibril_mutex_lock(&vhc->guard);
+
+	int targets = 0;
+
+	list_foreach(vhc->devices, link, vhc_virtdev_t, dev) {
+		fibril_mutex_lock(&dev->guard);
+		if (dev->address == transfer->batch->ep->address) {
+			if (!targets) {
+				list_append(&transfer->link, &dev->transfer_queue);
+			}
+			++targets;
+		}
+		fibril_mutex_unlock(&dev->guard);
+	}
+
+	fibril_mutex_unlock(&vhc->guard);
+	
+	if (targets > 1)
+		usb_log_warning("Transfer would be accepted by more devices!\n");
+
+	return targets ? EOK : ENOENT;
 }
 
@@ -234,9 +217,9 @@
 		size_t data_transfer_size = 0;
 		if (dev->dev_sess) {
-			rc = process_transfer_remote(transfer, dev->dev_sess,
-			    &data_transfer_size);
+			rc = process_transfer_remote(transfer->batch,
+			    dev->dev_sess, &data_transfer_size);
 		} else if (dev->dev_local != NULL) {
-			rc = process_transfer_local(transfer, dev->dev_local,
-			    &data_transfer_size);
+			rc = process_transfer_local(transfer->batch,
+			    dev->dev_local, &data_transfer_size);
 		} else {
 			usb_log_warning("Device has no remote phone nor local node.\n");
@@ -251,5 +234,5 @@
 			if (is_set_address_transfer(transfer)) {
 				usb_device_request_setup_packet_t *setup
-				    = transfer->setup_buffer;
+				    = (void*)transfer->batch->setup_buffer;
 				dev->address = setup->value;
 				usb_log_debug2("Address changed to %d\n",
@@ -284,3 +267,2 @@
 	return EOK;
 }
-
Index: uspace/drv/bus/usb/vhc/vhcd.h
===================================================================
--- uspace/drv/bus/usb/vhc/vhcd.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/drv/bus/usb/vhc/vhcd.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -36,10 +36,10 @@
 #define VHCD_VHCD_H_
 
-#include <usb/debug.h>
 #include <usbvirt/device.h>
-#include <usb/host/usb_endpoint_manager.h>
-#include <usb/host/usb_device_manager.h>
 #include <usbhc_iface.h>
 #include <async.h>
+
+#include <usb/host/hcd.h>
+
 
 #define NAME "vhc"
@@ -59,36 +59,25 @@
 	list_t devices;
 	fibril_mutex_t guard;
-	usb_endpoint_manager_t ep_manager;
-	usb_device_manager_t dev_manager;
-	usbvirt_device_t *hub;
-	ddf_fun_t *hc_fun;
+	usbvirt_device_t hub;
 } vhc_data_t;
 
 typedef struct {
 	link_t link;
-	usb_address_t address;
-	usb_endpoint_t endpoint;
-	usb_direction_t direction;
-	usb_transfer_type_t transfer_type;
-	void *setup_buffer;
-	size_t setup_buffer_size;
-	void *data_buffer;
-	size_t data_buffer_size;
-	ddf_fun_t *ddf_fun;
-	void *callback_arg;
-	usbhc_iface_transfer_in_callback_t callback_in;
-	usbhc_iface_transfer_out_callback_t callback_out;
+	usb_transfer_batch_t *batch;
 } vhc_transfer_t;
 
-vhc_transfer_t *vhc_transfer_create(usb_address_t, usb_endpoint_t,
-    usb_direction_t, usb_transfer_type_t, ddf_fun_t *, void *);
+
+void on_client_close(ddf_fun_t *fun);
+void default_connection_handler(ddf_fun_t *fun, ipc_callid_t icallid,
+    ipc_call_t *icall);
+
 int vhc_virtdev_plug(vhc_data_t *, async_sess_t *, uintptr_t *);
 int vhc_virtdev_plug_local(vhc_data_t *, usbvirt_device_t *, uintptr_t *);
-int vhc_virtdev_plug_hub(vhc_data_t *, usbvirt_device_t *, uintptr_t *);
+int vhc_virtdev_plug_hub(vhc_data_t *, usbvirt_device_t *, uintptr_t *, usb_address_t address);
 void vhc_virtdev_unplug(vhc_data_t *, uintptr_t);
-int vhc_virtdev_add_transfer(vhc_data_t *, vhc_transfer_t *);
 
+int vhc_init(vhc_data_t *instance);
+int vhc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch);
 int vhc_transfer_queue_processor(void *arg);
-
 
 #endif
Index: uspace/lib/c/generic/l18n/langs.c
===================================================================
--- uspace/lib/c/generic/l18n/langs.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/c/generic/l18n/langs.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -66,4 +66,6 @@
 		case L18N_WIN_LOCALE_ZULU:
 			return "Zulu";
+		default:
+			break;
 	}
 
Index: uspace/lib/c/include/l18n/langs.h
===================================================================
--- uspace/lib/c/include/l18n/langs.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/c/include/l18n/langs.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -54,5 +54,6 @@
 	L18N_WIN_LOCALE_SPANISH_TRADITIONAL = 0x040A,
 	/* ... */
-	L18N_WIN_LOCALE_ZULU = 0x0435
+	L18N_WIN_LOCALE_ZULU = 0x0435,
+	L18N_WIN_LOCALE_MAX = 0xFFFF
 } l18_win_locales_t;
 
Index: uspace/lib/drv/generic/driver.c
===================================================================
--- uspace/lib/drv/generic/driver.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/drv/generic/driver.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -815,4 +815,5 @@
 	assert(fun->bound == false);
 	assert(fun->name != NULL);
+	assert(fun->dev != NULL);
 	
 	add_to_functions_list(fun);
Index: uspace/lib/drv/generic/remote_usb.c
===================================================================
--- uspace/lib/drv/generic/remote_usb.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/drv/generic/remote_usb.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -35,34 +35,44 @@
 
 #include <async.h>
+#include <macros.h>
 #include <errno.h>
+#include <devman.h>
 
 #include "usb_iface.h"
 #include "ddf/driver.h"
 
+
+usb_dev_session_t *usb_dev_connect(devman_handle_t handle)
+{
+	return devman_device_connect(EXCHANGE_PARALLEL, handle, IPC_FLAG_BLOCKING);
+}
+
+usb_dev_session_t *usb_dev_connect_to_self(ddf_dev_t *dev)
+{
+	// TODO All usb requests are atomic so this is safe,
+	// it will need to change once USING EXCHANGE PARALLEL is safe with
+	// devman_parent_device_connect
+	return devman_parent_device_connect(EXCHANGE_ATOMIC,
+	    ddf_dev_get_handle(dev), IPC_FLAG_BLOCKING);
+}
+
+void usb_dev_disconnect(usb_dev_session_t *sess)
+{
+	if (sess)
+		async_hangup(sess);
+}
+
 typedef enum {
-	IPC_M_USB_GET_MY_ADDRESS,
 	IPC_M_USB_GET_MY_INTERFACE,
-	IPC_M_USB_GET_HOST_CONTROLLER_HANDLE,
+	IPC_M_USB_GET_MY_DEVICE_HANDLE,
+	IPC_M_USB_RESERVE_DEFAULT_ADDRESS,
+	IPC_M_USB_RELEASE_DEFAULT_ADDRESS,
+	IPC_M_USB_DEVICE_ENUMERATE,
+	IPC_M_USB_DEVICE_REMOVE,
+	IPC_M_USB_REGISTER_ENDPOINT,
+	IPC_M_USB_UNREGISTER_ENDPOINT,
+	IPC_M_USB_READ,
+	IPC_M_USB_WRITE,
 } usb_iface_funcs_t;
-
-/** Tell USB address assigned to device.
- * @param exch Vaid IPC exchange
- * @param address Pointer to address storage place.
- * @return Error code.
- *
- * Exch param is an open communication to device implementing usb_iface.
- */
-int usb_get_my_address(async_exch_t *exch, usb_address_t *address)
-{
-	if (!exch)
-		return EBADMEM;
-	sysarg_t addr;
-	const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
-	    IPC_M_USB_GET_MY_ADDRESS, &addr);
-
-	if (ret == EOK && address != NULL)
-		*address = (usb_address_t) addr;
-	return ret;
-}
 
 /** Tell interface number given device can use.
@@ -84,31 +94,202 @@
 }
 
-/** Tell devman handle of device host controller.
+/** Tell devman handle of the usb device function.
  * @param[in] exch IPC communication exchange
- * @param[out] hc_handle devman handle of the HC used by the target device.
+ * @param[out] handle devman handle of the HC used by the target device.
  * @return Error code.
  */
-int usb_get_hc_handle(async_exch_t *exch, devman_handle_t *hc_handle)
-{
-	if (!exch)
-		return EBADMEM;
-	devman_handle_t h;
+int usb_get_my_device_handle(async_exch_t *exch, devman_handle_t *handle)
+{
+	devman_handle_t h = 0;
 	const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
-	    IPC_M_USB_GET_HOST_CONTROLLER_HANDLE, &h);
-	if (ret == EOK && hc_handle)
-		*hc_handle = (devman_handle_t)h;
+	    IPC_M_USB_GET_MY_DEVICE_HANDLE, &h);
+	if (ret == EOK && handle)
+		*handle = (devman_handle_t)h;
 	return ret;
 }
 
-
-static void remote_usb_get_my_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
+/** Reserve default USB address.
+ * @param[in] exch IPC communication exchange
+ * @param[in] speed Communication speed of the newly attached device
+ * @return Error code.
+ */
+int usb_reserve_default_address(async_exch_t *exch, usb_speed_t speed)
+{
+	if (!exch)
+		return EBADMEM;
+	return async_req_2_0(exch, DEV_IFACE_ID(USB_DEV_IFACE),
+	    IPC_M_USB_RESERVE_DEFAULT_ADDRESS, speed);
+}
+
+/** Release default USB address.
+ * @param[in] exch IPC communication exchange
+ * @return Error code.
+ */
+int usb_release_default_address(async_exch_t *exch)
+{
+	if (!exch)
+		return EBADMEM;
+	return async_req_1_0(exch, DEV_IFACE_ID(USB_DEV_IFACE),
+	    IPC_M_USB_RELEASE_DEFAULT_ADDRESS);
+}
+
+/** Trigger USB device enumeration
+ * @param[in] exch IPC communication exchange
+ * @param[out] handle Identifier of the newly added device (if successful)
+ * @return Error code.
+ */
+int usb_device_enumerate(async_exch_t *exch, unsigned port)
+{
+	if (!exch)
+		return EBADMEM;
+	const int ret = async_req_2_0(exch, DEV_IFACE_ID(USB_DEV_IFACE),
+	    IPC_M_USB_DEVICE_ENUMERATE, port);
+	return ret;
+}
+
+/** Trigger USB device enumeration
+ * @param[in] exch IPC communication exchange
+ * @param[in] handle Identifier of the device
+ * @return Error code.
+ */
+int usb_device_remove(async_exch_t *exch, unsigned port)
+{
+	if (!exch)
+		return EBADMEM;
+	return async_req_2_0(exch, DEV_IFACE_ID(USB_DEV_IFACE),
+	    IPC_M_USB_DEVICE_REMOVE, port);
+}
+
+int usb_register_endpoint(async_exch_t *exch, usb_endpoint_t endpoint,
+    usb_transfer_type_t type, usb_direction_t direction,
+    size_t mps, unsigned interval)
+{
+	if (!exch)
+		return EBADMEM;
+#define _PACK2(high, low) (((high & 0xffff) << 16) | (low & 0xffff))
+
+	return async_req_4_0(exch, DEV_IFACE_ID(USB_DEV_IFACE),
+	    IPC_M_USB_REGISTER_ENDPOINT, endpoint,
+	    _PACK2(type, direction), _PACK2(mps, interval));
+
+#undef _PACK2
+}
+
+int usb_unregister_endpoint(async_exch_t *exch, usb_endpoint_t endpoint,
+    usb_direction_t direction)
+{
+	if (!exch)
+		return EBADMEM;
+	return async_req_3_0(exch, DEV_IFACE_ID(USB_DEV_IFACE),
+	    IPC_M_USB_UNREGISTER_ENDPOINT, endpoint, direction);
+}
+
+int usb_read(async_exch_t *exch, usb_endpoint_t endpoint, uint64_t setup,
+    void *data, size_t size, size_t *rec_size)
+{
+	if (!exch)
+		return EBADMEM;
+
+	if (size == 0 && setup == 0)
+		return EOK;
+
+	/* Make call identifying target USB device and type of transfer. */
+	aid_t opening_request = async_send_4(exch,
+	    DEV_IFACE_ID(USB_DEV_IFACE), IPC_M_USB_READ, endpoint,
+	    (setup & UINT32_MAX), (setup >> 32), NULL);
+
+	if (opening_request == 0) {
+		return ENOMEM;
+	}
+
+	/* Retrieve the data. */
+	ipc_call_t data_request_call;
+	aid_t data_request =
+	    async_data_read(exch, data, size, &data_request_call);
+
+	if (data_request == 0) {
+		// FIXME: How to let the other side know that we want to abort?
+		async_forget(opening_request);
+		return ENOMEM;
+	}
+
+	/* Wait for the answer. */
+	sysarg_t data_request_rc;
+	sysarg_t opening_request_rc;
+	async_wait_for(data_request, &data_request_rc);
+	async_wait_for(opening_request, &opening_request_rc);
+
+	if (data_request_rc != EOK) {
+		/* Prefer the return code of the opening request. */
+		if (opening_request_rc != EOK) {
+			return (int) opening_request_rc;
+		} else {
+			return (int) data_request_rc;
+		}
+	}
+	if (opening_request_rc != EOK) {
+		return (int) opening_request_rc;
+	}
+
+	*rec_size = IPC_GET_ARG2(data_request_call);
+	return EOK;
+}
+
+int usb_write(async_exch_t *exch, usb_endpoint_t endpoint, uint64_t setup,
+    const void *data, size_t size)
+{
+	if (!exch)
+		return EBADMEM;
+
+	if (size == 0 && setup == 0)
+		return EOK;
+
+	aid_t opening_request = async_send_5(exch,
+	    DEV_IFACE_ID(USB_DEV_IFACE), IPC_M_USB_WRITE, endpoint, size,
+	    (setup & UINT32_MAX), (setup >> 32), NULL);
+
+	if (opening_request == 0) {
+		return ENOMEM;
+	}
+
+	/* Send the data if any. */
+	if (size > 0) {
+		const int ret = async_data_write_start(exch, data, size);
+		if (ret != EOK) {
+			async_forget(opening_request);
+			return ret;
+		}
+	}
+
+	/* Wait for the answer. */
+	sysarg_t opening_request_rc;
+	async_wait_for(opening_request, &opening_request_rc);
+
+	return (int) opening_request_rc;
+}
+
 static void remote_usb_get_my_interface(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
-static void remote_usb_get_hc_handle(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
+static void remote_usb_get_my_device_handle(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
+static void remote_usb_reserve_default_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
+static void remote_usb_release_default_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
+static void remote_usb_device_enumerate(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
+static void remote_usb_device_remove(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
+static void remote_usb_register_endpoint(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
+static void remote_usb_unregister_endpoint(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
+static void remote_usb_read(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call);
+static void remote_usb_write(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call);
 
 /** Remote USB interface operations. */
 static remote_iface_func_ptr_t remote_usb_iface_ops [] = {
-	[IPC_M_USB_GET_MY_ADDRESS] = remote_usb_get_my_address,
 	[IPC_M_USB_GET_MY_INTERFACE] = remote_usb_get_my_interface,
-	[IPC_M_USB_GET_HOST_CONTROLLER_HANDLE] = remote_usb_get_hc_handle,
+	[IPC_M_USB_GET_MY_DEVICE_HANDLE] = remote_usb_get_my_device_handle,
+	[IPC_M_USB_RESERVE_DEFAULT_ADDRESS] = remote_usb_reserve_default_address,
+	[IPC_M_USB_RELEASE_DEFAULT_ADDRESS] = remote_usb_release_default_address,
+	[IPC_M_USB_DEVICE_ENUMERATE] = remote_usb_device_enumerate,
+	[IPC_M_USB_DEVICE_REMOVE] = remote_usb_device_remove,
+	[IPC_M_USB_REGISTER_ENDPOINT] = remote_usb_register_endpoint,
+	[IPC_M_USB_UNREGISTER_ENDPOINT] = remote_usb_unregister_endpoint,
+	[IPC_M_USB_READ] = remote_usb_read,
+	[IPC_M_USB_WRITE] = remote_usb_write,
 };
 
@@ -116,28 +297,7 @@
  */
 remote_iface_t remote_usb_iface = {
-	.method_count = sizeof(remote_usb_iface_ops) /
-	    sizeof(remote_usb_iface_ops[0]),
-	.methods = remote_usb_iface_ops
+	.method_count = ARRAY_SIZE(remote_usb_iface_ops),
+	.methods = remote_usb_iface_ops,
 };
-
-
-void remote_usb_get_my_address(ddf_fun_t *fun, void *iface,
-    ipc_callid_t callid, ipc_call_t *call)
-{
-	const usb_iface_t *usb_iface = (usb_iface_t *) iface;
-
-	if (usb_iface->get_my_address == NULL) {
-		async_answer_0(callid, ENOTSUP);
-		return;
-	}
-
-	usb_address_t address;
-	const int ret = usb_iface->get_my_address(fun, &address);
-	if (ret != EOK) {
-		async_answer_0(callid, ret);
-	} else {
-		async_answer_1(callid, EOK, address);
-	}
-}
 
 void remote_usb_get_my_interface(ddf_fun_t *fun, void *iface,
@@ -160,10 +320,10 @@
 }
 
-void remote_usb_get_hc_handle(ddf_fun_t *fun, void *iface,
+void remote_usb_get_my_device_handle(ddf_fun_t *fun, void *iface,
     ipc_callid_t callid, ipc_call_t *call)
 {
 	const usb_iface_t *usb_iface = (usb_iface_t *) iface;
 
-	if (usb_iface->get_hc_handle == NULL) {
+	if (usb_iface->get_my_device_handle == NULL) {
 		async_answer_0(callid, ENOTSUP);
 		return;
@@ -171,5 +331,5 @@
 
 	devman_handle_t handle;
-	const int ret = usb_iface->get_hc_handle(fun, &handle);
+	const int ret = usb_iface->get_my_device_handle(fun, &handle);
 	if (ret != EOK) {
 		async_answer_0(callid, ret);
@@ -178,4 +338,272 @@
 	async_answer_1(callid, EOK, (sysarg_t) handle);
 }
+
+void remote_usb_reserve_default_address(ddf_fun_t *fun, void *iface,
+    ipc_callid_t callid, ipc_call_t *call)
+{
+	const usb_iface_t *usb_iface = (usb_iface_t *) iface;
+
+	if (usb_iface->reserve_default_address == NULL) {
+		async_answer_0(callid, ENOTSUP);
+		return;
+	}
+
+	usb_speed_t speed = DEV_IPC_GET_ARG1(*call);
+	const int ret = usb_iface->reserve_default_address(fun, speed);
+	async_answer_0(callid, ret);
+}
+
+void remote_usb_release_default_address(ddf_fun_t *fun, void *iface,
+    ipc_callid_t callid, ipc_call_t *call)
+{
+	const usb_iface_t *usb_iface = (usb_iface_t *) iface;
+
+	if (usb_iface->release_default_address == NULL) {
+		async_answer_0(callid, ENOTSUP);
+		return;
+	}
+
+	const int ret = usb_iface->release_default_address(fun);
+	async_answer_0(callid, ret);
+}
+
+static void remote_usb_device_enumerate(ddf_fun_t *fun, void *iface,
+    ipc_callid_t callid, ipc_call_t *call)
+{
+	const usb_iface_t *usb_iface = (usb_iface_t *) iface;
+
+	if (usb_iface->device_enumerate == NULL) {
+		async_answer_0(callid, ENOTSUP);
+		return;
+	}
+
+	const unsigned port = DEV_IPC_GET_ARG1(*call);
+	const int ret = usb_iface->device_enumerate(fun, port);
+	async_answer_0(callid, ret);
+}
+
+static void remote_usb_device_remove(ddf_fun_t *fun, void *iface,
+    ipc_callid_t callid, ipc_call_t *call)
+{
+	const usb_iface_t *usb_iface = (usb_iface_t *) iface;
+
+	if (usb_iface->device_remove == NULL) {
+		async_answer_0(callid, ENOTSUP);
+		return;
+	}
+
+	const unsigned port = DEV_IPC_GET_ARG1(*call);
+	const int ret = usb_iface->device_remove(fun, port);
+	async_answer_0(callid, ret);
+}
+
+static void remote_usb_register_endpoint(ddf_fun_t *fun, void *iface,
+    ipc_callid_t callid, ipc_call_t *call)
+{
+	usb_iface_t *usb_iface = (usb_iface_t *) iface;
+
+	if (!usb_iface->register_endpoint) {
+		async_answer_0(callid, ENOTSUP);
+		return;
+	}
+
+#define _INIT_FROM_HIGH_DATA2(type, var, arg_no) \
+	type var = (type) (DEV_IPC_GET_ARG##arg_no(*call) >> 16)
+#define _INIT_FROM_LOW_DATA2(type, var, arg_no) \
+	type var = (type) (DEV_IPC_GET_ARG##arg_no(*call) & 0xffff)
+
+	const usb_endpoint_t endpoint = DEV_IPC_GET_ARG1(*call);
+
+	_INIT_FROM_HIGH_DATA2(usb_transfer_type_t, transfer_type, 2);
+	_INIT_FROM_LOW_DATA2(usb_direction_t, direction, 2);
+
+	_INIT_FROM_HIGH_DATA2(size_t, max_packet_size, 3);
+	_INIT_FROM_LOW_DATA2(unsigned int, interval, 3);
+
+#undef _INIT_FROM_HIGH_DATA2
+#undef _INIT_FROM_LOW_DATA2
+
+	const int ret = usb_iface->register_endpoint(fun, endpoint,
+	    transfer_type, direction, max_packet_size, interval);
+
+	async_answer_0(callid, ret);
+}
+
+static void remote_usb_unregister_endpoint(ddf_fun_t *fun, void *iface,
+    ipc_callid_t callid, ipc_call_t *call)
+{
+	usb_iface_t *usb_iface = (usb_iface_t *) iface;
+
+	if (!usb_iface->unregister_endpoint) {
+		async_answer_0(callid, ENOTSUP);
+		return;
+	}
+
+	usb_endpoint_t endpoint = (usb_endpoint_t) DEV_IPC_GET_ARG1(*call);
+	usb_direction_t direction = (usb_direction_t) DEV_IPC_GET_ARG2(*call);
+
+	int rc = usb_iface->unregister_endpoint(fun, endpoint, direction);
+
+	async_answer_0(callid, rc);
+}
+
+typedef struct {
+	ipc_callid_t caller;
+	ipc_callid_t data_caller;
+	void *buffer;
+} async_transaction_t;
+
+static void async_transaction_destroy(async_transaction_t *trans)
+{
+	if (trans == NULL) {
+		return;
+	}
+	if (trans->buffer != NULL) {
+		free(trans->buffer);
+	}
+
+	free(trans);
+}
+
+static async_transaction_t *async_transaction_create(ipc_callid_t caller)
+{
+	async_transaction_t *trans = malloc(sizeof(async_transaction_t));
+	if (trans == NULL) {
+		return NULL;
+	}
+
+	trans->caller = caller;
+	trans->data_caller = 0;
+	trans->buffer = NULL;
+
+	return trans;
+}
+
+static void callback_out(int outcome, void *arg)
+{
+	async_transaction_t *trans = arg;
+
+	async_answer_0(trans->caller, outcome);
+
+	async_transaction_destroy(trans);
+}
+
+static void callback_in(int outcome, size_t actual_size, void *arg)
+{
+	async_transaction_t *trans = (async_transaction_t *)arg;
+
+	if (outcome != EOK) {
+		async_answer_0(trans->caller, outcome);
+		if (trans->data_caller) {
+			async_answer_0(trans->data_caller, EINTR);
+		}
+		async_transaction_destroy(trans);
+		return;
+	}
+
+	if (trans->data_caller) {
+		async_data_read_finalize(trans->data_caller,
+		    trans->buffer, actual_size);
+	}
+
+	async_answer_0(trans->caller, EOK);
+
+	async_transaction_destroy(trans);
+}
+
+void remote_usb_read(
+    ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
+{
+	assert(fun);
+	assert(iface);
+	assert(call);
+
+	const usb_iface_t *usb_iface = iface;
+
+	if (!usb_iface->read) {
+		async_answer_0(callid, ENOTSUP);
+		return;
+	}
+
+	const usb_endpoint_t ep = DEV_IPC_GET_ARG1(*call);
+	const uint64_t setup =
+	    ((uint64_t)DEV_IPC_GET_ARG2(*call)) |
+	    (((uint64_t)DEV_IPC_GET_ARG3(*call)) << 32);
+
+	async_transaction_t *trans = async_transaction_create(callid);
+	if (trans == NULL) {
+		async_answer_0(callid, ENOMEM);
+		return;
+	}
+
+	size_t size = 0;
+	if (!async_data_read_receive(&trans->data_caller, &size)) {
+		async_answer_0(callid, EPARTY);
+		return;
+	}
+
+	trans->buffer = malloc(size);
+	if (trans->buffer == NULL) {
+		async_answer_0(trans->data_caller, ENOMEM);
+		async_answer_0(callid, ENOMEM);
+		async_transaction_destroy(trans);
+	}
+
+	const int rc = usb_iface->read(
+	    fun, ep, setup, trans->buffer, size, callback_in, trans);
+
+	if (rc != EOK) {
+		async_answer_0(trans->data_caller, rc);
+		async_answer_0(callid, rc);
+		async_transaction_destroy(trans);
+	}
+}
+
+void remote_usb_write(
+    ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
+{
+	assert(fun);
+	assert(iface);
+	assert(call);
+
+	const usb_iface_t *usb_iface = iface;
+
+	if (!usb_iface->write) {
+		async_answer_0(callid, ENOTSUP);
+		return;
+	}
+
+	const usb_endpoint_t ep = DEV_IPC_GET_ARG1(*call);
+	const size_t data_buffer_len = DEV_IPC_GET_ARG2(*call);
+	const uint64_t setup =
+	    ((uint64_t)DEV_IPC_GET_ARG3(*call)) |
+	    (((uint64_t)DEV_IPC_GET_ARG4(*call)) << 32);
+
+	async_transaction_t *trans = async_transaction_create(callid);
+	if (trans == NULL) {
+		async_answer_0(callid, ENOMEM);
+		return;
+	}
+
+	size_t size = 0;
+	if (data_buffer_len > 0) {
+		const int rc = async_data_write_accept(&trans->buffer, false,
+		    1, data_buffer_len, 0, &size);
+
+		if (rc != EOK) {
+			async_answer_0(callid, rc);
+			async_transaction_destroy(trans);
+			return;
+		}
+	}
+
+	const int rc = usb_iface->write(
+	    fun, ep, setup, trans->buffer, size, callback_out, trans);
+
+	if (rc != EOK) {
+		async_answer_0(callid, rc);
+		async_transaction_destroy(trans);
+	}
+}
 /**
  * @}
Index: uspace/lib/drv/generic/remote_usbhc.c
===================================================================
--- uspace/lib/drv/generic/remote_usbhc.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/drv/generic/remote_usbhc.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -84,70 +84,4 @@
  */
 typedef enum {
-	/** Asks for address assignment by host controller.
-	 * Answer:
-	 * - ELIMIT - host controller run out of address
-	 * - EOK - address assigned
-	 * Answer arguments:
-	 * - assigned address
-	 *
-	 * The address must be released by via IPC_M_USBHC_RELEASE_ADDRESS.
-	 */
-	IPC_M_USBHC_REQUEST_ADDRESS,
-
-	/** Bind USB address with devman handle.
-	 * Parameters:
-	 * - USB address
-	 * - devman handle
-	 * Answer:
-	 * - EOK - address binded
-	 * - ENOENT - address is not in use
-	 */
-	IPC_M_USBHC_BIND_ADDRESS,
-
-	/** Get handle binded with given USB address.
-	 * Parameters
-	 * - USB address
-	 * Answer:
-	 * - EOK - address binded, first parameter is the devman handle
-	 * - ENOENT - address is not in use at the moment
-	 */
-	IPC_M_USBHC_GET_HANDLE_BY_ADDRESS,
-
-	/** Release address in use.
-	 * Arguments:
-	 * - address to be released
-	 * Answer:
-	 * - ENOENT - address not in use
-	 * - EPERM - trying to release default USB address
-	 */
-	IPC_M_USBHC_RELEASE_ADDRESS,
-
-	/** Register endpoint attributes at host controller.
-	 * This is used to reserve portion of USB bandwidth.
-	 * When speed is invalid, speed of the device is used.
-	 * Parameters:
-	 * - USB address + endpoint number
-	 *   - packed as ADDR << 16 + EP
-	 * - speed + transfer type + direction
-	 *   - packed as ( SPEED << 8 + TYPE ) << 8 + DIR
-	 * - maximum packet size + interval (in milliseconds)
-	 *   - packed as MPS << 16 + INT
-	 * Answer:
-	 * - EOK - reservation successful
-	 * - ELIMIT - not enough bandwidth to satisfy the request
-	 */
-	IPC_M_USBHC_REGISTER_ENDPOINT,
-
-	/** Revert endpoint registration.
-	 * Parameters:
-	 * - USB address
-	 * - endpoint number
-	 * - data direction
-	 * Answer:
-	 * - EOK - endpoint unregistered
-	 * - ENOENT - unknown endpoint
-	 */
-	IPC_M_USBHC_UNREGISTER_ENDPOINT,
-
 	/** Get data from device.
 	 * See explanation at usb_iface_funcs_t (IN transaction).
@@ -160,73 +94,4 @@
 	IPC_M_USBHC_WRITE,
 } usbhc_iface_funcs_t;
-
-int usbhc_request_address(async_exch_t *exch, usb_address_t *address,
-    bool strict, usb_speed_t speed)
-{
-	if (!exch || !address)
-		return EBADMEM;
-	sysarg_t new_address;
-	const int ret = async_req_4_1(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
-	    IPC_M_USBHC_REQUEST_ADDRESS, *address, strict, speed, &new_address);
-	if (ret == EOK)
-		*address = (usb_address_t)new_address;
-	return ret;
-}
-
-int usbhc_bind_address(async_exch_t *exch, usb_address_t address,
-    devman_handle_t handle)
-{
-	if (!exch)
-		return EBADMEM;
-	return async_req_3_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
-	    IPC_M_USBHC_BIND_ADDRESS, address, handle);
-}
-
-int usbhc_get_handle(async_exch_t *exch, usb_address_t address,
-    devman_handle_t *handle)
-{
-	if (!exch)
-		return EBADMEM;
-	sysarg_t h;
-	const int ret = async_req_2_1(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
-	    IPC_M_USBHC_GET_HANDLE_BY_ADDRESS, address, &h);
-	if (ret == EOK && handle)
-		*handle = (devman_handle_t)h;
-	return ret;
-}
-
-int usbhc_release_address(async_exch_t *exch, usb_address_t address)
-{
-	if (!exch)
-		return EBADMEM;
-	return async_req_2_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
-	    IPC_M_USBHC_RELEASE_ADDRESS, address);
-}
-
-int usbhc_register_endpoint(async_exch_t *exch, usb_address_t address,
-    usb_endpoint_t endpoint, usb_transfer_type_t type,
-    usb_direction_t direction, size_t mps, unsigned interval)
-{
-	if (!exch)
-		return EBADMEM;
-	const usb_target_t target =
-	    {{ .address = address, .endpoint = endpoint }};
-#define _PACK2(high, low) (((high & 0xffff) << 16) | (low & 0xffff))
-
-	return async_req_4_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
-	    IPC_M_USBHC_REGISTER_ENDPOINT, target.packed,
-	    _PACK2(type, direction), _PACK2(mps, interval));
-
-#undef _PACK2
-}
-
-int usbhc_unregister_endpoint(async_exch_t *exch, usb_address_t address,
-    usb_endpoint_t endpoint, usb_direction_t direction)
-{
-	if (!exch)
-		return EBADMEM;
-	return async_req_4_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
-	    IPC_M_USBHC_UNREGISTER_ENDPOINT, address, endpoint, direction);
-}
 
 int usbhc_read(async_exch_t *exch, usb_address_t address,
@@ -322,25 +187,9 @@
 }
 
-
-static void remote_usbhc_request_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
-static void remote_usbhc_bind_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
-static void remote_usbhc_get_handle(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
-static void remote_usbhc_release_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
-static void remote_usbhc_register_endpoint(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
-static void remote_usbhc_unregister_endpoint(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
 static void remote_usbhc_read(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
 static void remote_usbhc_write(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
-//static void remote_usbhc(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
 
 /** Remote USB host controller interface operations. */
 static remote_iface_func_ptr_t remote_usbhc_iface_ops[] = {
-	[IPC_M_USBHC_REQUEST_ADDRESS] = remote_usbhc_request_address,
-	[IPC_M_USBHC_RELEASE_ADDRESS] = remote_usbhc_release_address,
-	[IPC_M_USBHC_BIND_ADDRESS] = remote_usbhc_bind_address,
-	[IPC_M_USBHC_GET_HANDLE_BY_ADDRESS] = remote_usbhc_get_handle,
-
-	[IPC_M_USBHC_REGISTER_ENDPOINT] = remote_usbhc_register_endpoint,
-	[IPC_M_USBHC_UNREGISTER_ENDPOINT] = remote_usbhc_unregister_endpoint,
-
 	[IPC_M_USBHC_READ] = remote_usbhc_read,
 	[IPC_M_USBHC_WRITE] = remote_usbhc_write,
@@ -387,82 +236,5 @@
 }
 
-void remote_usbhc_request_address(ddf_fun_t *fun, void *iface,
-    ipc_callid_t callid, ipc_call_t *call)
-{
-	const usbhc_iface_t *usb_iface = iface;
-
-	if (!usb_iface->request_address) {
-		async_answer_0(callid, ENOTSUP);
-		return;
-	}
-
-	usb_address_t address = DEV_IPC_GET_ARG1(*call);
-	const bool strict = DEV_IPC_GET_ARG2(*call);
-	const usb_speed_t speed = DEV_IPC_GET_ARG3(*call);
-
-	const int rc = usb_iface->request_address(fun, &address, strict, speed);
-	if (rc != EOK) {
-		async_answer_0(callid, rc);
-	} else {
-		async_answer_1(callid, EOK, (sysarg_t) address);
-	}
-}
-
-void remote_usbhc_bind_address(ddf_fun_t *fun, void *iface,
-    ipc_callid_t callid, ipc_call_t *call)
-{
-	const usbhc_iface_t *usb_iface = iface;
-
-	if (!usb_iface->bind_address) {
-		async_answer_0(callid, ENOTSUP);
-		return;
-	}
-
-	const usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call);
-	const devman_handle_t handle = (devman_handle_t) DEV_IPC_GET_ARG2(*call);
-
-	const int ret = usb_iface->bind_address(fun, address, handle);
-	async_answer_0(callid, ret);
-}
-
-void remote_usbhc_get_handle(ddf_fun_t *fun, void *iface,
-    ipc_callid_t callid, ipc_call_t *call)
-{
-	const usbhc_iface_t *usb_iface = iface;
-
-	if (!usb_iface->get_handle) {
-		async_answer_0(callid, ENOTSUP);
-		return;
-	}
-
-	const usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call);
-	devman_handle_t handle;
-	const int ret = usb_iface->get_handle(fun, address, &handle);
-
-	if (ret == EOK) {
-		async_answer_1(callid, ret, handle);
-	} else {
-		async_answer_0(callid, ret);
-	}
-}
-
-void remote_usbhc_release_address(ddf_fun_t *fun, void *iface,
-    ipc_callid_t callid, ipc_call_t *call)
-{
-	const usbhc_iface_t *usb_iface = iface;
-
-	if (!usb_iface->release_address) {
-		async_answer_0(callid, ENOTSUP);
-		return;
-	}
-
-	const usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call);
-
-	const int ret = usb_iface->release_address(fun, address);
-	async_answer_0(callid, ret);
-}
-
-static void callback_out(ddf_fun_t *fun,
-    int outcome, void *arg)
+static void callback_out(int outcome, void *arg)
 {
 	async_transaction_t *trans = arg;
@@ -473,6 +245,5 @@
 }
 
-static void callback_in(ddf_fun_t *fun,
-    int outcome, size_t actual_size, void *arg)
+static void callback_in(int outcome, size_t actual_size, void *arg)
 {
 	async_transaction_t *trans = (async_transaction_t *)arg;
@@ -497,56 +268,4 @@
 }
 
-void remote_usbhc_register_endpoint(ddf_fun_t *fun, void *iface,
-    ipc_callid_t callid, ipc_call_t *call)
-{
-	usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
-
-	if (!usb_iface->register_endpoint) {
-		async_answer_0(callid, ENOTSUP);
-		return;
-	}
-
-#define _INIT_FROM_HIGH_DATA2(type, var, arg_no) \
-	type var = (type) (DEV_IPC_GET_ARG##arg_no(*call) >> 16)
-#define _INIT_FROM_LOW_DATA2(type, var, arg_no) \
-	type var = (type) (DEV_IPC_GET_ARG##arg_no(*call) & 0xffff)
-
-	const usb_target_t target = { .packed = DEV_IPC_GET_ARG1(*call) };
-
-	_INIT_FROM_HIGH_DATA2(usb_transfer_type_t, transfer_type, 2);
-	_INIT_FROM_LOW_DATA2(usb_direction_t, direction, 2);
-
-	_INIT_FROM_HIGH_DATA2(size_t, max_packet_size, 3);
-	_INIT_FROM_LOW_DATA2(unsigned int, interval, 3);
-
-#undef _INIT_FROM_HIGH_DATA2
-#undef _INIT_FROM_LOW_DATA2
-
-	int rc = usb_iface->register_endpoint(fun, target.address,
-	    target.endpoint, transfer_type, direction, max_packet_size, interval);
-
-	async_answer_0(callid, rc);
-}
-
-void remote_usbhc_unregister_endpoint(ddf_fun_t *fun, void *iface,
-    ipc_callid_t callid, ipc_call_t *call)
-{
-	usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
-
-	if (!usb_iface->unregister_endpoint) {
-		async_answer_0(callid, ENOTSUP);
-		return;
-	}
-
-	usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call);
-	usb_endpoint_t endpoint = (usb_endpoint_t) DEV_IPC_GET_ARG2(*call);
-	usb_direction_t direction = (usb_direction_t) DEV_IPC_GET_ARG3(*call);
-
-	int rc = usb_iface->unregister_endpoint(fun,
-	    address, endpoint, direction);
-
-	async_answer_0(callid, rc);
-}
-
 void remote_usbhc_read(
     ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
Index: uspace/lib/drv/include/usb_iface.h
===================================================================
--- uspace/lib/drv/include/usb_iface.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/drv/include/usb_iface.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -42,13 +42,51 @@
 #include <usb/usb.h>
 
-int usb_get_my_address(async_exch_t *, usb_address_t *);
+typedef async_sess_t usb_dev_session_t;
+
+usb_dev_session_t *usb_dev_connect(devman_handle_t);
+usb_dev_session_t *usb_dev_connect_to_self(ddf_dev_t *);
+void usb_dev_disconnect(usb_dev_session_t *);
+
 int usb_get_my_interface(async_exch_t *, int *);
-int usb_get_hc_handle(async_exch_t *, devman_handle_t *);
+int usb_get_my_device_handle(async_exch_t *, devman_handle_t *);
+
+int usb_reserve_default_address(async_exch_t *, usb_speed_t);
+int usb_release_default_address(async_exch_t *);
+
+int usb_device_enumerate(async_exch_t *, unsigned port);
+int usb_device_remove(async_exch_t *, unsigned port);
+
+int usb_register_endpoint(async_exch_t *, usb_endpoint_t, usb_transfer_type_t,
+    usb_direction_t, size_t, unsigned);
+int usb_unregister_endpoint(async_exch_t *, usb_endpoint_t, usb_direction_t);
+int usb_read(async_exch_t *, usb_endpoint_t, uint64_t, void *, size_t, size_t *);
+int usb_write(async_exch_t *, usb_endpoint_t, uint64_t, const void *, size_t);
+
+/** Callback for outgoing transfer. */
+typedef void (*usbhc_iface_transfer_out_callback_t)(int, void *);
+
+/** Callback for incoming transfer. */
+typedef void (*usbhc_iface_transfer_in_callback_t)(int, size_t, void *);
 
 /** USB device communication interface. */
 typedef struct {
-	int (*get_my_address)(ddf_fun_t *, usb_address_t *);
 	int (*get_my_interface)(ddf_fun_t *, int *);
-	int (*get_hc_handle)(ddf_fun_t *, devman_handle_t *);
+	int (*get_my_device_handle)(ddf_fun_t *, devman_handle_t *);
+
+	int (*reserve_default_address)(ddf_fun_t *, usb_speed_t);
+	int (*release_default_address)(ddf_fun_t *);
+
+	int (*device_enumerate)(ddf_fun_t *, unsigned);
+	int (*device_remove)(ddf_fun_t *, unsigned);
+
+	int (*register_endpoint)(ddf_fun_t *, usb_endpoint_t,
+	    usb_transfer_type_t, usb_direction_t, size_t, unsigned);
+	int (*unregister_endpoint)(ddf_fun_t *, usb_endpoint_t,
+	    usb_direction_t);
+
+	int (*read)(ddf_fun_t *, usb_endpoint_t, uint64_t, uint8_t *, size_t,
+	    usbhc_iface_transfer_in_callback_t, void *);
+	int (*write)(ddf_fun_t *, usb_endpoint_t, uint64_t, const uint8_t *,
+	    size_t, usbhc_iface_transfer_out_callback_t, void *);
 } usb_iface_t;
 
Index: uspace/lib/drv/include/usbhc_iface.h
===================================================================
--- uspace/lib/drv/include/usbhc_iface.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/drv/include/usbhc_iface.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -44,12 +44,4 @@
 #include <stdbool.h>
 
-int usbhc_request_address(async_exch_t *, usb_address_t *, bool, usb_speed_t);
-int usbhc_bind_address(async_exch_t *, usb_address_t, devman_handle_t);
-int usbhc_get_handle(async_exch_t *, usb_address_t, devman_handle_t *);
-int usbhc_release_address(async_exch_t *, usb_address_t);
-int usbhc_register_endpoint(async_exch_t *, usb_address_t, usb_endpoint_t,
-    usb_transfer_type_t, usb_direction_t, size_t, unsigned int);
-int usbhc_unregister_endpoint(async_exch_t *, usb_address_t, usb_endpoint_t,
-    usb_direction_t);
 int usbhc_read(async_exch_t *, usb_address_t, usb_endpoint_t,
     uint64_t, void *, size_t, size_t *);
@@ -58,27 +50,13 @@
 
 /** Callback for outgoing transfer. */
-typedef void (*usbhc_iface_transfer_out_callback_t)(ddf_fun_t *, int, void *);
+typedef void (*usbhc_iface_transfer_out_callback_t)(int, void *);
 
 /** Callback for incoming transfer. */
-typedef void (*usbhc_iface_transfer_in_callback_t)(ddf_fun_t *,
-    int, size_t, void *);
+typedef void (*usbhc_iface_transfer_in_callback_t)(int, size_t, void *);
 
 /** USB host controller communication interface. */
 typedef struct {
-	int (*request_address)(ddf_fun_t *, usb_address_t *, bool, usb_speed_t);
-	int (*bind_address)(ddf_fun_t *, usb_address_t, devman_handle_t);
-	int (*get_handle)(ddf_fun_t *, usb_address_t,
-	    devman_handle_t *);
-	int (*release_address)(ddf_fun_t *, usb_address_t);
-
-	int (*register_endpoint)(ddf_fun_t *,
-	    usb_address_t, usb_endpoint_t,
-	    usb_transfer_type_t, usb_direction_t, size_t, unsigned int);
-	int (*unregister_endpoint)(ddf_fun_t *, usb_address_t, usb_endpoint_t,
-	    usb_direction_t);
-
 	int (*read)(ddf_fun_t *, usb_target_t, uint64_t, uint8_t *, size_t,
 	    usbhc_iface_transfer_in_callback_t, void *);
-
 	int (*write)(ddf_fun_t *, usb_target_t, uint64_t, const uint8_t *,
 	    size_t, usbhc_iface_transfer_out_callback_t, void *);
Index: uspace/lib/usb/Makefile
===================================================================
--- uspace/lib/usb/Makefile	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usb/Makefile	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -36,5 +36,4 @@
 SOURCES = \
 	src/class.c \
-	src/ddfiface.c \
 	src/dev.c \
 	src/debug.c \
Index: uspace/lib/usb/include/usb/classes/hub.h
===================================================================
--- uspace/lib/usb/include/usb/classes/hub.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usb/include/usb/classes/hub.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -67,108 +67,64 @@
 	/** Descriptor length. */
 	uint8_t length;
+
 	/** Descriptor type (0x29). */
 	uint8_t descriptor_type;
+
 	/** Number of downstream ports. */
 	uint8_t port_count;
-	/** Characteristics bitmask. */
+
+	/** Characteristics bitmask.
+	 *
+	 *  D1...D0: Logical Power Switching Mode
+	 *  00: Ganged power switching (all ports power at
+	 *  once)
+	 *  01: Individual port power switching
+	 *  1X: Reserved. Used only on 1.0 compliant hubs
+	 *  that implement no power switching.
+	 *  D2: Identifies a Compound Device
+	 *  0: Hub is not part of a compound device
+	 *  1: Hub is part of a compound device
+	 *  D4...D3: Over-current Protection Mode
+	 *  00: Global Over-current Protection. The hub
+	 *  reports over-current as a summation of all
+	 *  ports current draw, without a breakdown of
+	 *  individual port over-current status.
+	 *  01: Individual Port Over-current Protection. The
+	 *  hub reports over-current on a per-port basis.
+	 *  Each port has an over-current indicator.
+	 *  1X: No Over-current Protection. This option is
+	 *  allowed only for bus-powered hubs that do not
+	 *  implement over-current protection.
+	 *  D15...D5: Reserved
+	 */
 	uint8_t characteristics;
-#define HUB_CHAR_POWER_PER_PORT_FLAG  (1 << 0)
-#define HUB_CHAR_NO_POWER_SWITCH_FLAG (1 << 1)
-	/* Unused part of characteristics field */
+#define HUB_CHAR_POWER_PER_PORT_FLAG    (1 << 0)
+#define HUB_CHAR_NO_POWER_SWITCH_FLAG   (1 << 1)
+#define HUB_CHAR_COMPOUND_DEVICE        (1 << 2)
+#define HUB_CHAR_OC_PER_PORT_FLAG       (1 << 3)
+#define HUB_CHAR_NO_OC_FLAG             (1 << 4)
+
+	/** Unused part of characteristics field */
 	uint8_t characteristics_reserved;
-	/** Time from power-on to stabilization of current on the port. */
+
+	/** Time from power-on to stabilization of current on the port.
+	 *
+	 *  Time (in 2ms intervals) from the time the power-on
+	 *  sequence begins on a port until power is good on that
+	 *  port. The USB System Software uses this value to
+	 *  determine how long to wait before accessing a
+	 *  powered-on port.
+	 */
 	uint8_t power_good_time;
-	/** Maximum current requirements in mA. */
+	/** Maximum current requirements in mA.
+	 *
+	 *  Maximum current requirements of the Hub Controller
+	 *  electronics in mA.
+	 */
 	uint8_t max_current;
 } __attribute__ ((packed)) usb_hub_descriptor_header_t;
 
-/**
- * @brief usb hub descriptor
- *
- * For more information see Universal Serial Bus Specification Revision 1.1
- * chapter 11.16.2
- */
-typedef struct usb_hub_descriptor_type {
-    /** Number of bytes in this descriptor, including this byte */
-    //uint8_t bDescLength;
-
-    /** Descriptor Type, value: 29H for hub descriptor */
-    //uint8_t bDescriptorType;
-
-    /** Number of downstream ports that this hub supports */
-    uint8_t port_count;
-
-    /**
-            D1...D0: Logical Power Switching Mode
-            00: Ganged power switching (all ports power at
-            once)
-            01: Individual port power switching
-            1X: Reserved. Used only on 1.0 compliant hubs
-            that implement no power switching.
-            D2: Identifies a Compound Device
-            0: Hub is not part of a compound device
-            1: Hub is part of a compound device
-            D4...D3: Over-current Protection Mode
-            00: Global Over-current Protection. The hub
-            reports over-current as a summation of all
-            ports current draw, without a breakdown of
-            individual port over-current status.
-            01: Individual Port Over-current Protection. The
-            hub reports over-current on a per-port basis.
-            Each port has an over-current indicator.
-            1X: No Over-current Protection. This option is
-            allowed only for bus-powered hubs that do not
-            implement over-current protection.
-            D15...D5:
-            Reserved
-     */
-    uint16_t hub_characteristics;
-
-    /**
-            Time (in 2ms intervals) from the time the power-on
-            sequence begins on a port until power is good on that
-            port. The USB System Software uses this value to
-            determine how long to wait before accessing a
-            powered-on port.
-     */
-    uint8_t pwr_on_2_good_time;
-
-    /**
-            Maximum current requirements of the Hub Controller
-            electronics in mA.
-     */
-    uint8_t current_requirement;
-
-    /**
-            Indicates if a port has a removable device attached.
-            This field is reported on byte-granularity. Within a
-            byte, if no port exists for a given location, the field
-            representing the port characteristics returns 0.
-            Bit value definition:
-            0B - Device is removable
-            1B - Device is non-removable
-            This is a bitmap corresponding to the individual ports
-            on the hub:
-            Bit 0: Reserved for future use
-            Bit 1: Port 1
-            Bit 2: Port 2
-            ....
-            Bit n: Port n (implementation-dependent, up to a
-            maximum of 255 ports).
-     */
-    uint8_t devices_removable[32];
-
-    /**
-            This field exists for reasons of compatibility with
-            software written for 1.0 compliant devices. All bits in
-            this field should be set to 1B. This field has one bit for
-            each port on the hub with additional pad bits, if
-            necessary, to make the number of bits in the field an
-            integer multiple of 8.
-     */
-    //uint8_t * port_pwr_ctrl_mask;
-} usb_hub_descriptor_t;
-
-
+/** One bit for the device and one bit for every port */
+#define STATUS_BYTES(ports) ((1 + ports + 7) / 8)
 
 /**	@brief usb hub specific request types.
Index: uspace/lib/usb/include/usb/ddfiface.h
===================================================================
--- uspace/lib/usb/include/usb/ddfiface.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ 	(revision )
@@ -1,55 +1,0 @@
-/*
- * Copyright (c) 2011 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 libusb
- * @{
- */
-/** @file
- * Implementations of DDF interfaces functions.
- */
-
-#ifndef LIBUSB_DDFIFACE_H_
-#define LIBUSB_DDFIFACE_H_
-
-#include <sys/types.h>
-#include <usb_iface.h>
-
-extern int usb_iface_get_hc_handle_device_impl(ddf_fun_t *, devman_handle_t *);
-extern int usb_iface_get_my_address_forward_impl(ddf_fun_t *, usb_address_t *);
-extern usb_iface_t usb_iface_hub_impl;
-
-extern int usb_iface_get_my_address_from_device_data(ddf_fun_t *, usb_address_t *);
-extern usb_iface_t usb_iface_hub_child_impl;
-
-extern int usb_iface_get_hc_handle_hc_impl(ddf_fun_t *, devman_handle_t *);
-
-#endif
-
-/**
- * @}
- */
Index: uspace/lib/usb/include/usb/dev.h
===================================================================
--- uspace/lib/usb/include/usb/dev.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usb/include/usb/dev.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -38,25 +38,5 @@
 #include <usb/usb.h>
 
-int usb_get_info_by_handle(devman_handle_t,
-    devman_handle_t *, usb_address_t *, int *);
-
-static inline int usb_get_hc_by_handle(devman_handle_t dev, devman_handle_t *hc)
-{
-	return usb_get_info_by_handle(dev, hc, NULL, NULL);
-}
-
-static inline int usb_get_address_by_handle(
-    devman_handle_t dev, usb_address_t *address)
-{
-	return usb_get_info_by_handle(dev, NULL, address, NULL);
-}
-
-static inline int usb_get_iface_by_handle(devman_handle_t dev, int *iface)
-{
-	return usb_get_info_by_handle(dev, NULL, NULL, iface);
-}
-
-int usb_resolve_device_handle(const char *, devman_handle_t *, usb_address_t *,
-    devman_handle_t *);
+int usb_resolve_device_handle(const char *, devman_handle_t *);
 #endif
 /**
Index: uspace/lib/usb/include/usb/hc.h
===================================================================
--- uspace/lib/usb/include/usb/hc.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usb/include/usb/hc.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -84,16 +84,4 @@
 int usb_hc_connection_close(usb_hc_connection_t *);
 
-usb_address_t usb_hc_request_address(usb_hc_connection_t *, usb_address_t, bool,
-    usb_speed_t);
-int usb_hc_bind_address(usb_hc_connection_t *, usb_address_t, devman_handle_t);
-int usb_hc_get_handle_by_address(usb_hc_connection_t *, usb_address_t,
-    devman_handle_t *);
-int usb_hc_release_address(usb_hc_connection_t *, usb_address_t);
-
-int usb_hc_register_endpoint(usb_hc_connection_t *, usb_address_t,
-    usb_endpoint_t, usb_transfer_type_t, usb_direction_t, size_t, unsigned int);
-int usb_hc_unregister_endpoint(usb_hc_connection_t *, usb_address_t,
-    usb_endpoint_t, usb_direction_t);
-
 int usb_hc_read(usb_hc_connection_t *, usb_address_t, usb_endpoint_t,
     uint64_t, void *, size_t, size_t *);
Index: uspace/lib/usb/include/usb/request.h
===================================================================
--- uspace/lib/usb/include/usb/request.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
+++ uspace/lib/usb/include/usb/request.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2012 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libusb
+ * @{
+ */
+/** @file
+ * Standard USB request format.
+ */
+#ifndef LIBUSB_REQUEST_H_
+#define LIBUSB_REQUEST_H_
+
+#include <sys/types.h>
+
+/** Standard device request. */
+typedef enum {
+	USB_DEVREQ_GET_STATUS = 0,
+	USB_DEVREQ_CLEAR_FEATURE = 1,
+	USB_DEVREQ_SET_FEATURE = 3,
+	USB_DEVREQ_SET_ADDRESS = 5,
+	USB_DEVREQ_GET_DESCRIPTOR = 6,
+	USB_DEVREQ_SET_DESCRIPTOR = 7,
+	USB_DEVREQ_GET_CONFIGURATION = 8,
+	USB_DEVREQ_SET_CONFIGURATION = 9,
+	USB_DEVREQ_GET_INTERFACE = 10,
+	USB_DEVREQ_SET_INTERFACE = 11,
+	USB_DEVREQ_SYNCH_FRAME = 12,
+	USB_DEVREQ_LAST_STD
+} usb_stddevreq_t;
+
+/** USB device status - device is self powered (opposed to bus powered). */
+#define USB_DEVICE_STATUS_SELF_POWERED ((uint16_t)(1 << 0))
+
+/** USB device status - remote wake-up signaling is enabled. */
+#define USB_DEVICE_STATUS_REMOTE_WAKEUP ((uint16_t)(1 << 1))
+
+/** USB endpoint status - endpoint is halted (stalled). */
+#define USB_ENDPOINT_STATUS_HALTED ((uint16_t)(1 << 0))
+
+/** USB feature selector - endpoint halt (stall). */
+#define USB_FEATURE_SELECTOR_ENDPOINT_HALT (0)
+
+/** USB feature selector - device remote wake-up. */
+#define USB_FEATURE_SELECTOR_REMOTE_WAKEUP (1)
+
+/** Device request setup packet.
+ * The setup packet describes the request.
+ */
+typedef struct {
+	/** Request type.
+	 * The type combines transfer direction, request type and
+	 * intended recipient.
+	 */
+	uint8_t request_type;
+#define SETUP_REQUEST_TYPE_DEVICE_TO_HOST (1 << 7)
+#define SETUP_REQUEST_TYPE_HOST_TO_DEVICE (0 << 7)
+#define SETUP_REQUEST_TYPE_GET_TYPE(rt) ((rt >> 5) & 0x3)
+#define SETUP_REQUEST_TYPE_GET_RECIPIENT(rec) (rec & 0x1f)
+#define SETUP_REQUEST_TO_HOST(type, recipient) \
+    (uint8_t)((1 << 7) | ((type & 0x3) << 5) | (recipient & 0x1f))
+#define SETUP_REQUEST_TO_DEVICE(type, recipient) \
+    (uint8_t)(((type & 0x3) << 5) | (recipient & 0x1f))
+
+	/** Request identification. */
+	uint8_t request;
+	/** Main parameter to the request. */
+	union __attribute__ ((packed)) {
+		uint16_t value;
+		/* FIXME: add #ifdefs according to host endianness */
+		struct __attribute__ ((packed)) {
+			uint8_t value_low;
+			uint8_t value_high;
+		};
+	};
+	/** Auxiliary parameter to the request.
+	 * Typically, it is offset to something.
+	 */
+	uint16_t index;
+	/** Length of extra data. */
+	uint16_t length;
+} __attribute__ ((packed)) usb_device_request_setup_packet_t;
+
+int assert[(sizeof(usb_device_request_setup_packet_t) == 8) ? 1: -1];
+
+int usb_request_needs_toggle_reset(
+    const usb_device_request_setup_packet_t *request);
+
+#endif
+/**
+ * @}
+ */
Index: uspace/lib/usb/include/usb/usb.h
===================================================================
--- uspace/lib/usb/include/usb/usb.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usb/include/usb/usb.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -84,4 +84,9 @@
 } usb_speed_t;
 
+static inline bool usb_speed_is_11(const usb_speed_t s)
+{
+	return (s == USB_SPEED_FULL) || (s == USB_SPEED_LOW);
+}
+
 const char *usb_str_speed(usb_speed_t);
 
@@ -110,5 +115,16 @@
 #define USB_ADDRESS_DEFAULT 0
 /** Maximum address number in USB 1.1. */
-#define USB11_ADDRESS_MAX 128
+#define USB11_ADDRESS_MAX 127
+#define USB_ADDRESS_COUNT (USB11_ADDRESS_MAX + 1)
+
+/** Check USB address for allowed values.
+ *
+ * @param ep USB address.
+ * @return True, if value is wihtin limits, false otherwise.
+ */
+static inline bool usb_address_is_valid(usb_address_t a)
+{
+	return (a >= USB_ADDRESS_DEFAULT) && (a <= USB11_ADDRESS_MAX);
+}
 
 /** USB endpoint number type.
@@ -117,7 +133,19 @@
 typedef int16_t usb_endpoint_t;
 
-/** Maximum endpoint number in USB 1.1.
- */
+/** Default control endpoint */
+#define USB_ENDPOINT_DEFAULT_CONTROL 0
+/** Maximum endpoint number in USB 1.1. */
 #define USB11_ENDPOINT_MAX 16
+
+/** Check USB endpoint for allowed values.
+ *
+ * @param ep USB endpoint number.
+ * @return True, if value is wihtin limits, false otherwise.
+ */
+static inline bool usb_endpoint_is_valid(usb_endpoint_t ep)
+{
+	return (ep >= USB_ENDPOINT_DEFAULT_CONTROL) &&
+	    (ep < USB11_ENDPOINT_MAX);
+}
 
 
@@ -133,4 +161,5 @@
 } usb_target_t;
 
+
 /** Check USB target for allowed values (address and endpoint).
  *
@@ -140,6 +169,6 @@
 static inline bool usb_target_is_valid(usb_target_t target)
 {
-	return !(target.endpoint > 15 || target.endpoint < 0
-	    || target.address >= USB11_ADDRESS_MAX || target.address < 0);
+	return usb_address_is_valid(target.address) &&
+	    usb_endpoint_is_valid(target.endpoint);
 }
 
Index: uspace/lib/usb/src/ddfiface.c
===================================================================
--- uspace/lib/usb/src/ddfiface.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ 	(revision )
@@ -1,127 +1,0 @@
-/*
- * Copyright (c) 2011 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 libusb
- * @{
- */
-/** @file
- * Implementations of DDF interfaces functions (actual implementation).
- */
-
-#include <devman.h>
-#include <async.h>
-#include <usb_iface.h>
-#include <usb/ddfiface.h>
-#include <usb/hc.h>
-#include <usb/debug.h>
-#include <usb/dev/hub.h>
-#include <errno.h>
-#include <assert.h>
-
-#include <usb/dev.h>
-
-/** DDF interface for USB device, implementation for typical hub. */
-usb_iface_t usb_iface_hub_impl = {
-	.get_hc_handle = usb_iface_get_hc_handle_device_impl,
-	.get_my_address = usb_iface_get_my_address_forward_impl,
-};
-
-/** DDF interface for USB device, implementation for child of a typical hub. */
-usb_iface_t usb_iface_hub_child_impl = {
-	.get_hc_handle = usb_iface_get_hc_handle_device_impl,
-	.get_my_address = usb_iface_get_my_address_from_device_data,
-};
-
-
-/** Get host controller handle, interface implementation for hub driver.
- *
- * @param[in] fun Device function the operation is running on.
- * @param[out] handle Storage for the host controller handle.
- * @return Error code.
- */
-int usb_iface_get_hc_handle_device_impl(ddf_fun_t *fun, devman_handle_t *handle)
-{
-	assert(fun);
-	return usb_get_hc_by_handle(ddf_fun_get_handle(fun), handle);
-}
-
-/** Get host controller handle, interface implementation for HC driver.
- *
- * @param[in] fun Device function the operation is running on.
- * @param[out] handle Storage for the host controller handle.
- * @return Always EOK.
- */
-int usb_iface_get_hc_handle_hc_impl(ddf_fun_t *fun, devman_handle_t *handle)
-{
-	assert(fun);
-
-	if (handle != NULL) {
-		*handle = ddf_fun_get_handle(fun);
-	}
-
-	return EOK;
-}
-
-/** Get USB device address, interface implementation for hub driver.
- *
- * @param[in] fun Device function the operation is running on.
- * @param[in] handle Devman handle of USB device we want address of.
- * @param[out] address Storage for USB address of device with handle @p handle.
- * @return Error code.
- */
-int usb_iface_get_my_address_forward_impl(ddf_fun_t *fun,
-    usb_address_t *address)
-{
-	assert(fun);
-	return usb_get_address_by_handle(ddf_fun_get_handle(fun), address);
-}
-
-/** Get USB device address, interface implementation for child of
- * a hub driver.
- *
- * This implementation eccepts 0 as valid handle and replaces it with fun's
- * handle.
- *
- * @param[in] fun Device function the operation is running on.
- * @param[in] handle Devman handle of USB device we want address of.
- * @param[out] address Storage for USB address of device with handle @p handle.
- * @return Error code.
- */
-int usb_iface_get_my_address_from_device_data(ddf_fun_t *fun,
-    usb_address_t *address)
-{
-	const usb_hub_attached_device_t *device = ddf_fun_data_get(fun);
-	assert(device->fun == fun);
-	if (address)
-		*address = device->address;
-	return EOK;
-}
-
-/**
- * @}
- */
Index: uspace/lib/usb/src/dev.c
===================================================================
--- uspace/lib/usb/src/dev.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usb/src/dev.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -35,125 +35,4 @@
 #include <stdio.h>
 
-#define MAX_DEVICE_PATH 1024
-
-/** Find host controller handle, address and iface number for the device.
- *
- * @param[in] device_handle Device devman handle.
- * @param[out] hc_handle Where to store handle of host controller
- *	controlling device with @p device_handle handle.
- * @param[out] address Place to store the device's address
- * @param[out] iface Place to stoer the assigned USB interface number.
- * @return Error code.
- */
-int usb_get_info_by_handle(devman_handle_t device_handle,
-    devman_handle_t *hc_handle, usb_address_t *address, int *iface)
-{
-	async_sess_t *parent_sess =
-	    devman_parent_device_connect(EXCHANGE_ATOMIC, device_handle,
-	        IPC_FLAG_BLOCKING);
-	if (!parent_sess)
-		return ENOMEM;
-
-	async_exch_t *exch = async_exchange_begin(parent_sess);
-	if (!exch) {
-		async_hangup(parent_sess);
-		return ENOMEM;
-	}
-
-	usb_address_t tmp_address;
-	devman_handle_t tmp_handle;
-	int tmp_iface;
-
-	if (address) {
-		const int ret = usb_get_my_address(exch, &tmp_address);
-		if (ret != EOK) {
-			async_exchange_end(exch);
-			async_hangup(parent_sess);
-			return ret;
-		}
-	}
-
-	if (hc_handle) {
-		const int ret = usb_get_hc_handle(exch, &tmp_handle);
-		if (ret != EOK) {
-			async_exchange_end(exch);
-			async_hangup(parent_sess);
-			return ret;
-		}
-	}
-
-	if (iface) {
-		const int ret = usb_get_my_interface(exch, &tmp_iface);
-		switch (ret) {
-		case ENOTSUP:
-			/* Implementing GET_MY_INTERFACE is voluntary. */
-			tmp_iface = -1;
-		case EOK:
-			break;
-		default:
-			async_exchange_end(exch);
-			async_hangup(parent_sess);
-			return ret;
-		}
-	}
-
-	if (hc_handle)
-		*hc_handle = tmp_handle;
-
-	if (address)
-		*address = tmp_address;
-
-	if (iface)
-		*iface = tmp_iface;
-
-	async_exchange_end(exch);
-	async_hangup(parent_sess);
-
-	return EOK;
-}
-
-static bool try_parse_bus_and_address(const char *path,
-    const char **func_start,
-    devman_handle_t *out_hc_handle, usb_address_t *out_device_address)
-{
-	uint64_t sid;
-	size_t address;
-	int rc;
-	const char *ptr;
-
-	rc = str_uint64_t(path, &ptr, 10, false, &sid);
-	if (rc != EOK) {
-		return false;
-	}
-	if ((*ptr == ':') || (*ptr == '.')) {
-		ptr++;
-	} else {
-		return false;
-	}
-	rc = str_size_t(ptr, func_start, 10, false, &address);
-	if (rc != EOK) {
-		return false;
-	}
-	rc = usb_ddf_get_hc_handle_by_sid(sid, out_hc_handle);
-	if (rc != EOK) {
-		return false;
-	}
-	if (out_device_address != NULL) {
-		*out_device_address = (usb_address_t) address;
-	}
-	return true;
-}
-
-static int get_device_handle_by_address(devman_handle_t hc_handle, int addr,
-    devman_handle_t *dev_handle)
-{
-	usb_hc_connection_t conn;
-	usb_hc_connection_initialize(&conn, hc_handle);
-
-	const int rc = usb_hc_get_handle_by_address(&conn, addr, dev_handle);
-
-	return rc;
-}
-
 /** Resolve handle and address of USB device from its path.
  *
@@ -175,127 +54,19 @@
  * @return Error code.
  */
-int usb_resolve_device_handle(const char *dev_path, devman_handle_t *out_hc_handle,
-    usb_address_t *out_dev_addr, devman_handle_t *out_dev_handle)
+int usb_resolve_device_handle(const char *dev_path, devman_handle_t *dev_handle)
 {
-	if (dev_path == NULL) {
+	if (dev_path == NULL || dev_handle == NULL) {
 		return EBADMEM;
 	}
 
-	bool found_hc = false;
-	bool found_addr = false;
-	devman_handle_t hc_handle, dev_handle;
-	usb_address_t dev_addr = -1;
-	int rc;
-	bool is_bus_addr;
-	const char *func_start = NULL;
-	char *path = NULL;
+	/* First, try to get the device handle. */
+	int rc = devman_fun_get_handle(dev_path, dev_handle, 0);
 
-	/* First try the BUS.ADDR format. */
-	is_bus_addr = try_parse_bus_and_address(dev_path, &func_start,
-	    &hc_handle, &dev_addr);
-	if (is_bus_addr) {
-		found_hc = true;
-		found_addr = true;
-		/*
-		 * Now get the handle of the device. We will need that
-		 * in both cases. If there is only BUS.ADDR, it will
-		 * be the handle to be returned to the caller, otherwise
-		 * we will need it to resolve the path to which the
-		 * suffix would be appended.
-		 */
-		/* If there is nothing behind the BUS.ADDR, we will
-		 * get the device handle from the host controller.
-		 * Otherwise, we will
-		 */
-		rc = get_device_handle_by_address(hc_handle, dev_addr,
-		    &dev_handle);
-		if (rc != EOK) {
-			return rc;
-		}
-		if (str_length(func_start) > 0) {
-			char tmp_path[MAX_DEVICE_PATH];
-			rc = devman_fun_get_path(dev_handle,
-			    tmp_path, MAX_DEVICE_PATH);
-			if (rc != EOK) {
-				return rc;
-			}
-			rc = asprintf(&path, "%s%s", tmp_path, func_start);
-			if (rc < 0) {
-				return ENOMEM;
-			}
-		} else {
-			/* Everything is resolved. Get out of here. */
-			goto copy_out;
-		}
-	} else {
-		path = str_dup(dev_path);
-		if (path == NULL) {
-			return ENOMEM;
-		}
+	/* Next, try parsing dev_handle from the provided string */
+	if (rc != EOK) {
+		*dev_handle = strtoul(dev_path, NULL, 10);
+		//FIXME: check errno
+		rc = EOK;
 	}
-
-	/* First try to get the device handle. */
-	rc = devman_fun_get_handle(path, &dev_handle, 0);
-	if (rc != EOK) {
-		free(path);
-		/* Invalid path altogether. */
-		return rc;
-	}
-
-	/* Remove suffixes and hope that we will encounter device node. */
-	while (str_length(path) > 0) {
-		/* Get device handle first. */
-		devman_handle_t tmp_handle;
-		rc = devman_fun_get_handle(path, &tmp_handle, 0);
-		if (rc != EOK) {
-			free(path);
-			return rc;
-		}
-
-		/* Try to find its host controller. */
-		if (!found_hc) {
-			rc = usb_get_hc_by_handle(tmp_handle, &hc_handle);
-			if (rc == EOK) {
-				found_hc = true;
-			}
-		}
-
-		/* Try to get its address. */
-		if (!found_addr) {
-			rc = usb_get_address_by_handle(tmp_handle, &dev_addr);
-			if (rc == 0) {
-				found_addr = true;
-			}
-		}
-
-		/* Speed-up. */
-		if (found_hc && found_addr) {
-			break;
-		}
-
-		/* Remove the last suffix. */
-		char *slash_pos = str_rchr(path, '/');
-		if (slash_pos != NULL) {
-			*slash_pos = 0;
-		}
-	}
-
-	free(path);
-
-	if (!found_addr || !found_hc) {
-		return ENOENT;
-	}
-
-copy_out:
-	if (out_dev_addr != NULL) {
-		*out_dev_addr = dev_addr;
-	}
-	if (out_hc_handle != NULL) {
-		*out_hc_handle = hc_handle;
-	}
-	if (out_dev_handle != NULL) {
-		*out_dev_handle = dev_handle;
-	}
-
-	return EOK;
+	return rc;
 }
Index: uspace/lib/usb/src/dump.c
===================================================================
--- uspace/lib/usb/src/dump.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usb/src/dump.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -41,4 +41,5 @@
 #include <usb/descriptor.h>
 #include <usb/classes/classes.h>
+#include <usb/classes/hub.h>
 
 /** Mapping between descriptor id and dumping function. */
@@ -276,5 +277,53 @@
     const uint8_t *descriptor, size_t descriptor_length)
 {
-	/* TODO */
+	usb_hub_descriptor_header_t *d =
+	    (usb_hub_descriptor_header_t *) descriptor;
+	if (descriptor_length < sizeof(d))
+		return;
+
+	PRINTLINE("bDescLength: = %d", d->length);
+	PRINTLINE("bDescriptorType = 0x%02x", d->descriptor_type);
+	PRINTLINE("bNbrPorts = %d", d->port_count);
+	PRINTLINE("bHubCharacteristics = 0x%02x%02x (%s;%s%s)",
+	    d->characteristics_reserved, d->characteristics,
+	    (d->characteristics & HUB_CHAR_NO_POWER_SWITCH_FLAG) ?
+	        "No Power Switching" :
+		((d->characteristics & HUB_CHAR_POWER_PER_PORT_FLAG) ?
+		    "Per-Port Switching" : "Ganged Power Switching"),
+	    (d->characteristics & HUB_CHAR_COMPOUND_DEVICE) ?
+	        "Compound Device;" : "",
+	    (d->characteristics & HUB_CHAR_NO_OC_FLAG) ?
+	        "No OC Protection" :
+		    ((d->characteristics & HUB_CHAR_OC_PER_PORT_FLAG) ?
+		        "Individual Port OC Protection" :
+	                    "Global OC Protection")
+	);
+	PRINTLINE("bPwrOn2PwrGood = %d (%d ms)",
+	    d->power_good_time, d->power_good_time * 2);
+	PRINTLINE("bHubContrCurrent = %d (%d mA)",
+	    d->max_current, d->max_current);
+	const size_t port_bytes = (descriptor_length - sizeof(*d)) / 2;
+	const uint8_t *removable_mask = descriptor + sizeof(*d);
+	const uint8_t *powered_mask = descriptor + sizeof(*d) + port_bytes;
+
+	if (port_bytes == 0
+	    || port_bytes > (((d->port_count / (unsigned)8) + 1) * 2)) {
+		PRINTLINE("::CORRUPTED DESCRIPTOR:: (%zu bytes remain)",
+		    port_bytes * 2);
+	}
+
+	fprintf(output, "%sDeviceRemovable = 0x",
+	    line_prefix ? line_prefix : " - ");
+	for (unsigned i = port_bytes; i > 0; --i)
+		fprintf(output, "%02x", removable_mask[i - 1]);
+	fprintf(output, " (0b1 - Device non-removable)%s",
+	    line_suffix ? line_suffix : "\n");
+
+	fprintf(output, "%sPortPwrCtrlMask = 0x",
+	    line_prefix ? line_prefix : " - ");
+	for (unsigned i = port_bytes; i > 0; --i)
+		fprintf(output, "%02x", powered_mask[i - 1]);
+	fprintf(output, " (Legacy - All should be 0b1)%s",
+	    line_suffix ? line_suffix : "\n");
 }
 
Index: uspace/lib/usb/src/hc.c
===================================================================
--- uspace/lib/usb/src/hc.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usb/src/hc.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -108,24 +108,4 @@
 } else (void)0
 
-/** Initialize connection to USB host controller.
- *
- * @param connection Connection to be initialized.
- * @param device Device connecting to the host controller.
- * @return Error code.
- */
-int usb_hc_connection_initialize_from_device(usb_hc_connection_t *connection,
-    ddf_dev_t *device)
-{
-	if (device == NULL)
-		return EBADMEM;
-
-	devman_handle_t hc_handle;
-	const int rc = usb_get_hc_by_handle(ddf_dev_get_handle(device), &hc_handle);
-	if (rc == EOK) {
-		usb_hc_connection_initialize(connection, hc_handle);
-	}
-
-	return rc;
-}
 
 void usb_hc_connection_deinitialize(usb_hc_connection_t *connection)
@@ -164,96 +144,4 @@
 }
 
-/** Ask host controller for free address assignment.
- *
- * @param connection Opened connection to host controller.
- * @param preferred Preferred SUB address.
- * @param strict Fail if the preferred address is not avialable.
- * @param speed Speed of the new device (device that will be assigned
- *    the returned address).
- * @return Assigned USB address or negative error code.
- */
-usb_address_t usb_hc_request_address(usb_hc_connection_t *connection,
-    usb_address_t preferred, bool strict, usb_speed_t speed)
-{
-	async_exch_t *exch;
-	EXCH_INIT(connection, exch);
-
-	usb_address_t address = preferred;
-	const int ret = usbhc_request_address(exch, &address, strict, speed);
-
-	EXCH_FINI(connection, exch);
-	return ret == EOK ? address : ret;
-}
-
-int usb_hc_bind_address(usb_hc_connection_t * connection,
-    usb_address_t address, devman_handle_t handle)
-{
-	async_exch_t *exch;
-	EXCH_INIT(connection, exch);
-
-	const int ret = usbhc_bind_address(exch, address, handle);
-
-	EXCH_FINI(connection, exch);
-	return ret;
-}
-
-/** Get handle of USB device with given address.
- *
- * @param[in] connection Opened connection to host controller.
- * @param[in] address Address of device in question.
- * @param[out] handle Where to write the device handle.
- * @return Error code.
- */
-int usb_hc_get_handle_by_address(usb_hc_connection_t *connection,
-    usb_address_t address, devman_handle_t *handle)
-{
-	async_exch_t *exch;
-	EXCH_INIT(connection, exch);
-
-	const int ret = usbhc_get_handle(exch, address, handle);
-
-	EXCH_FINI(connection, exch);
-	return ret;
-}
-
-int usb_hc_release_address(usb_hc_connection_t *connection,
-    usb_address_t address)
-{
-	async_exch_t *exch;
-	EXCH_INIT(connection, exch);
-
-	const int ret = usbhc_release_address(exch, address);
-
-	EXCH_FINI(connection, exch);
-	return ret;
-}
-
-int usb_hc_register_endpoint(usb_hc_connection_t *connection,
-    usb_address_t address, usb_endpoint_t endpoint, usb_transfer_type_t type,
-    usb_direction_t direction, size_t packet_size, unsigned interval)
-{
-	async_exch_t *exch;
-	EXCH_INIT(connection, exch);
-
-	const int ret = usbhc_register_endpoint(exch, address, endpoint,
-	    type, direction, packet_size, interval);
-
-	EXCH_FINI(connection, exch);
-	return ret;
-}
-
-int usb_hc_unregister_endpoint(usb_hc_connection_t *connection,
-    usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction)
-{
-	async_exch_t *exch;
-	EXCH_INIT(connection, exch);
-
-	const int ret =
-	    usbhc_unregister_endpoint(exch, address, endpoint, direction);
-
-	EXCH_FINI(connection, exch);
-	return ret;
-}
-
 int usb_hc_read(usb_hc_connection_t *connection, usb_address_t address,
     usb_endpoint_t endpoint, uint64_t setup, void *data, size_t size,
Index: uspace/lib/usb/src/usb.c
===================================================================
--- uspace/lib/usb/src/usb.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usb/src/usb.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -34,7 +34,9 @@
  */
 #include <usb/usb.h>
+#include <usb/request.h>
+
 #include <errno.h>
-
-#define ARR_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
+#include <assert.h>
+#include <macros.h>
 
 static const char *str_speed[] = {
@@ -71,5 +73,5 @@
 const char *usb_str_transfer_type(usb_transfer_type_t t)
 {
-	if (t >= ARR_SIZE(str_transfer_type)) {
+	if (t >= ARRAY_SIZE(str_transfer_type)) {
 		return "invalid";
 	}
@@ -84,5 +86,5 @@
 const char *usb_str_transfer_type_short(usb_transfer_type_t t)
 {
-	if (t >= ARR_SIZE(str_transfer_type_short)) {
+	if (t >= ARRAY_SIZE(str_transfer_type_short)) {
 		return "invl";
 	}
@@ -97,5 +99,5 @@
 const char *usb_str_direction(usb_direction_t d)
 {
-	if (d >= ARR_SIZE(str_direction)) {
+	if (d >= ARRAY_SIZE(str_direction)) {
 		return "invalid";
 	}
@@ -110,5 +112,5 @@
 const char *usb_str_speed(usb_speed_t s)
 {
-	if (s >= ARR_SIZE(str_speed)) {
+	if (s >= ARRAY_SIZE(str_speed)) {
 		return "invalid";
 	}
@@ -116,4 +118,40 @@
 }
 
+/** Check setup packet data for signs of toggle reset.
+ *
+ * @param[in] requst Setup requst data.
+ * @retval -1 No endpoints need reset.
+ * @retval 0 All endpoints need reset.
+ * @retval >0 Specified endpoint needs reset.
+ */
+int usb_request_needs_toggle_reset(
+    const usb_device_request_setup_packet_t *request)
+{
+	assert(request);
+	switch (request->request)
+	{
+	/* Clear Feature ENPOINT_STALL */
+	case USB_DEVREQ_CLEAR_FEATURE: /*resets only cleared ep */
+		/* 0x2 ( HOST to device | STANDART | TO ENPOINT) */
+		if ((request->request_type == 0x2) &&
+		    (request->value == USB_FEATURE_SELECTOR_ENDPOINT_HALT))
+			return uint16_usb2host(request->index);
+		break;
+	case USB_DEVREQ_SET_CONFIGURATION:
+	case USB_DEVREQ_SET_INTERFACE:
+		/* Recipient must be device, this resets all endpoints,
+		 * In fact there should be no endpoints but EP 0 registered
+		 * as different interfaces use different endpoints,
+		 * unless you're changing configuration or alternative
+		 * interface of an already setup device. */
+		if (!(request->request_type & SETUP_REQUEST_TYPE_DEVICE_TO_HOST))
+			return 0;
+		break;
+	default:
+		break;
+	}
+	return -1;
+}
+
 /**
  * @}
Index: uspace/lib/usbdev/Makefile
===================================================================
--- uspace/lib/usbdev/Makefile	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbdev/Makefile	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -36,8 +36,8 @@
 SOURCES = \
 	src/altiface.c \
+	src/driver.c \
 	src/devdrv.c \
 	src/devpoll.c \
 	src/dp.c \
-	src/hub.c \
 	src/pipes.c \
 	src/pipesinit.c \
Index: uspace/lib/usbdev/include/usb/dev/alternate_ifaces.h
===================================================================
--- uspace/lib/usbdev/include/usb/dev/alternate_ifaces.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
+++ uspace/lib/usbdev/include/usb/dev/alternate_ifaces.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2011 Vojtech Horky
+ * Copyright (c) 2013 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libusbdev
+ * @{
+ */
+/** @file
+ * USB device driver framework.
+ */
+
+#ifndef LIBUSBDEV_ALTERNATE_IFACES_H_
+#define LIBUSBDEV_ALTERNATE_IFACES_H_
+
+#include <usb/descriptor.h>
+
+/** Wrapper for data related to alternate interface setting.
+ * The pointers will typically point inside configuration descriptor and
+ * thus you shall not deallocate them.
+ */
+typedef struct {
+	/** Interface descriptor. */
+	const usb_standard_interface_descriptor_t *interface;
+	/** Pointer to start of descriptor tree bound with this interface. */
+	const uint8_t *nested_descriptors;
+	/** Size of data pointed by nested_descriptors in bytes. */
+	size_t nested_descriptors_size;
+} usb_alternate_interface_descriptors_t;
+
+/** Alternate interface settings. */
+typedef struct {
+	/** Array of alternate interfaces descriptions. */
+	const usb_alternate_interface_descriptors_t *alternatives;
+	/** Size of @c alternatives array. */
+	size_t alternative_count;
+	/** Index of currently selected one. */
+	size_t current;
+} usb_alternate_interfaces_t;
+
+size_t usb_interface_count_alternates(const uint8_t *, size_t, uint8_t);
+int usb_alternate_interfaces_init(usb_alternate_interfaces_t *,
+    const uint8_t *, size_t, int);
+void usb_alternate_interfaces_deinit(usb_alternate_interfaces_t *);
+
+#endif
+/**
+ * @}
+ */
Index: uspace/lib/usbdev/include/usb/dev/device.h
===================================================================
--- uspace/lib/usbdev/include/usb/dev/device.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
+++ uspace/lib/usbdev/include/usb/dev/device.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2011 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 libusbdev
+ * @{
+ */
+/** @file
+ * USB device driver framework.
+ */
+
+#ifndef LIBUSBDEV_DEVICE_H_
+#define LIBUSBDEV_DEVICE_H_
+
+#include <ddf/driver.h>
+#include <usb/dev/alternate_ifaces.h>
+#include <usb/dev/pipes.h>
+
+/** Some useful descriptors for USB device. */
+typedef struct {
+	/** Standard device descriptor. */
+	usb_standard_device_descriptor_t device;
+	/** Full configuration descriptor of current configuration. */
+	const void *full_config;
+	size_t full_config_size;
+} usb_device_descriptors_t;
+
+typedef struct usb_device usb_device_t;
+
+/* DDF parts */
+int usb_device_create_ddf(ddf_dev_t *, const usb_endpoint_description_t **, const char **);
+void usb_device_destroy_ddf(ddf_dev_t *);
+
+static inline usb_device_t *usb_device_get(ddf_dev_t *dev)
+{
+	assert(dev);
+	return ddf_dev_data_get(dev);
+}
+
+usb_device_t * usb_device_create(devman_handle_t);
+void usb_device_destroy(usb_device_t *);
+
+const char * usb_device_get_name(usb_device_t *);
+ddf_fun_t *usb_device_ddf_fun_create(usb_device_t *, fun_type_t, const char *);
+
+async_exch_t * usb_device_bus_exchange_begin(usb_device_t *);
+void usb_device_bus_exchange_end(async_exch_t *);
+
+int usb_device_select_interface(usb_device_t *, uint8_t,
+    const usb_endpoint_description_t **);
+
+int usb_device_create_pipes(usb_device_t *usb_dev,
+    const usb_endpoint_description_t **endpoints);
+void usb_device_destroy_pipes(usb_device_t *);
+
+usb_pipe_t *usb_device_get_default_pipe(usb_device_t *);
+usb_endpoint_mapping_t * usb_device_get_mapped_ep_desc(usb_device_t *,
+    const usb_endpoint_description_t *);
+usb_endpoint_mapping_t * usb_device_get_mapped_ep(usb_device_t *,
+    usb_endpoint_t);
+
+int usb_device_get_iface_number(usb_device_t *);
+devman_handle_t usb_device_get_devman_handle(usb_device_t *);
+
+const usb_device_descriptors_t * usb_device_descriptors(usb_device_t *);
+
+const usb_alternate_interfaces_t * usb_device_get_alternative_ifaces(
+    usb_device_t *);
+
+void * usb_device_data_alloc(usb_device_t *, size_t);
+void * usb_device_data_get(usb_device_t *);
+
+#endif
+/**
+ * @}
+ */
Index: uspace/lib/usbdev/include/usb/dev/dp.h
===================================================================
--- uspace/lib/usbdev/include/usb/dev/dp.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbdev/include/usb/dev/dp.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -79,6 +79,6 @@
     const usb_dp_parser_data_t *, const uint8_t *, const uint8_t *);
 
-void usb_dp_walk_simple(uint8_t *, size_t, const usb_dp_descriptor_nesting_t *,
-    walk_callback_t, void *);
+void usb_dp_walk_simple(const uint8_t *, size_t,
+    const usb_dp_descriptor_nesting_t *, walk_callback_t, void *);
 
 #endif
Index: uspace/lib/usbdev/include/usb/dev/driver.h
===================================================================
--- uspace/lib/usbdev/include/usb/dev/driver.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbdev/include/usb/dev/driver.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -37,77 +37,6 @@
 #define LIBUSBDEV_DRIVER_H_
 
-#include <usb/hc.h>
-#include <usb/dev/usb_device_connection.h>
+#include <usb/dev/device.h>
 #include <usb/dev/pipes.h>
-
-/** Descriptors for USB device. */
-typedef struct {
-	/** Standard device descriptor. */
-	usb_standard_device_descriptor_t device;
-	/** Full configuration descriptor of current configuration. */
-	const uint8_t *configuration;
-	size_t configuration_size;
-} usb_device_descriptors_t;
-
-/** Wrapper for data related to alternate interface setting.
- * The pointers will typically point inside configuration descriptor and
- * thus you shall not deallocate them.
- */
-typedef struct {
-	/** Interface descriptor. */
-	const usb_standard_interface_descriptor_t *interface;
-	/** Pointer to start of descriptor tree bound with this interface. */
-	const uint8_t *nested_descriptors;
-	/** Size of data pointed by nested_descriptors in bytes. */
-	size_t nested_descriptors_size;
-} usb_alternate_interface_descriptors_t;
-
-/** Alternate interface settings. */
-typedef struct {
-	/** Array of alternate interfaces descriptions. */
-	usb_alternate_interface_descriptors_t *alternatives;
-	/** Size of @c alternatives array. */
-	size_t alternative_count;
-	/** Index of currently selected one. */
-	size_t current;
-} usb_alternate_interfaces_t;
-
-/** USB device structure. */
-typedef struct {
-	/** Connection to USB hc, used by wire and arbitrary requests. */
-	usb_hc_connection_t hc_conn;
-	/** Connection backing the pipes.
-	 * Typically, you will not need to use this attribute at all.
-	 */
-	usb_device_connection_t wire;
-	/** The default control pipe. */
-	usb_pipe_t ctrl_pipe;
-	/** Other endpoint pipes.
-	 * This is an array of other endpoint pipes in the same order as
-	 * in usb_driver_t.
-	 */
-	usb_endpoint_mapping_t *pipes;
-	/** Number of other endpoint pipes. */
-	size_t pipes_count;
-	/** Current interface.
-	 * Usually, drivers operate on single interface only.
-	 * This item contains the value of the interface or -1 for any.
-	 */
-	int interface_no;
-
-	/** Alternative interfaces. */
-	usb_alternate_interfaces_t alternate_interfaces;
-
-	/** Some useful descriptors. */
-	usb_device_descriptors_t descriptors;
-
-	/** Generic DDF device backing this one. DO NOT TOUCH! */
-	ddf_dev_t *ddf_dev;
-	/** Custom driver data.
-	 * Do not use the entry in generic device, that is already used
-	 * by the framework.
-	 */
-	void *driver_data;
-} usb_device_t;
 
 /** USB driver ops. */
@@ -164,25 +93,4 @@
 int usb_driver_main(const usb_driver_t *);
 
-int usb_device_init(usb_device_t *, ddf_dev_t *,
-    const usb_endpoint_description_t **, const char **);
-void usb_device_deinit(usb_device_t *);
-
-int usb_device_select_interface(usb_device_t *, uint8_t,
-    const usb_endpoint_description_t **);
-
-int usb_device_retrieve_descriptors(usb_pipe_t *, usb_device_descriptors_t *);
-void usb_device_release_descriptors(usb_device_descriptors_t *);
-
-int usb_device_create_pipes(usb_device_connection_t *,
-    const usb_endpoint_description_t **, const uint8_t *, size_t, int, int,
-    usb_endpoint_mapping_t **, size_t *);
-void usb_device_destroy_pipes(usb_endpoint_mapping_t *, size_t);
-
-void * usb_device_data_alloc(usb_device_t *, size_t);
-
-size_t usb_interface_count_alternates(const uint8_t *, size_t, uint8_t);
-int usb_alternate_interfaces_init(usb_alternate_interfaces_t *,
-    const uint8_t *, size_t, int);
-void usb_alternate_interfaces_deinit(usb_alternate_interfaces_t *);
 #endif
 /**
Index: uspace/lib/usbdev/include/usb/dev/hub.h
===================================================================
--- uspace/lib/usbdev/include/usb/dev/hub.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ 	(revision )
@@ -1,80 +1,0 @@
-/*
- * Copyright (c) 2011 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 libusbdev
- * @{
- */
-/** @file
- * Functions needed by hub drivers.
- *
- * For class specific requests, see usb/classes/hub.h.
- */
-
-#ifndef LIBUSBDEV_HUB_H_
-#define LIBUSBDEV_HUB_H_
-
-#include <ddf/driver.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <usb/hc.h>
-
-extern int usb_hc_new_device_wrapper(ddf_dev_t *, usb_hc_connection_t *, usb_speed_t,
-    int (*)(void *), void *, usb_address_t *, ddf_dev_ops_t *, void *,
-    ddf_fun_t **);
-
-/** Info about device attached to host controller.
- *
- * This structure exists only to keep the same signature of
- * usb_hc_register_device() when more properties of the device
- * would have to be passed to the host controller.
- */
-typedef struct {
-	/** Device address. */
-	usb_address_t address;
-	/** DDF function (external) of the device. */
-	ddf_fun_t *fun;
-} usb_hub_attached_device_t;
-
-extern int usb_hub_register_device(usb_hc_connection_t *,
-    const usb_hub_attached_device_t *);
-
-static inline int usb_hub_unregister_device(usb_hc_connection_t *conn,
-    const usb_hub_attached_device_t *attached_device)
-{
-	assert(conn);
-	if (attached_device == NULL)
-		return EBADMEM;
-	
-	return usb_hc_release_address(conn, attached_device->address);
-}
-
-#endif
-
-/**
- * @}
- */
Index: uspace/lib/usbdev/include/usb/dev/pipes.h
===================================================================
--- uspace/lib/usbdev/include/usb/dev/pipes.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbdev/include/usb/dev/pipes.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -41,5 +41,5 @@
 #include <usb/usb.h>
 #include <usb/descriptor.h>
-#include <usb/dev/usb_device_connection.h>
+#include <usb_iface.h>
 
 #define CTRL_PIPE_MIN_PACKET_SIZE 8
@@ -50,7 +50,4 @@
  */
 typedef struct {
-	/** The connection used for sending the data. */
-	usb_device_connection_t *wire;
-
 	/** Endpoint number. */
 	usb_endpoint_t endpoint_no;
@@ -69,4 +66,7 @@
 	 */
 	bool auto_reset_halt;
+
+	/** The connection used for sending the data. */
+	usb_dev_session_t *bus_session;
 } usb_pipe_t;
 
@@ -105,18 +105,14 @@
 } usb_endpoint_mapping_t;
 
-int usb_pipe_initialize(usb_pipe_t *, usb_device_connection_t *,
-    usb_endpoint_t, usb_transfer_type_t, size_t, usb_direction_t);
-int usb_pipe_initialize_default_control(usb_pipe_t *,
-    usb_device_connection_t *);
+int usb_pipe_initialize(usb_pipe_t *, usb_endpoint_t, usb_transfer_type_t,
+    size_t, usb_direction_t, usb_dev_session_t *);
+int usb_pipe_initialize_default_control(usb_pipe_t *, usb_dev_session_t *);
 
 int usb_pipe_probe_default_control(usb_pipe_t *);
 int usb_pipe_initialize_from_configuration(usb_endpoint_mapping_t *,
-    size_t, const uint8_t *, size_t, usb_device_connection_t *);
+    size_t, const uint8_t *, size_t, usb_dev_session_t *);
 
 int usb_pipe_register(usb_pipe_t *, unsigned);
 int usb_pipe_unregister(usb_pipe_t *);
-
-int usb_pipe_start_long_transfer(usb_pipe_t *);
-int usb_pipe_end_long_transfer(usb_pipe_t *);
 
 int usb_pipe_read(usb_pipe_t *, void *, size_t, size_t *);
Index: uspace/lib/usbdev/include/usb/dev/poll.h
===================================================================
--- uspace/lib/usbdev/include/usb/dev/poll.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbdev/include/usb/dev/poll.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -87,13 +87,20 @@
 } usb_device_auto_polling_t;
 
-int usb_device_auto_polling(usb_device_t *, size_t,
+typedef bool (*usb_polling_callback_t)(usb_device_t *, uint8_t *, size_t, void *);
+typedef void (*usb_polling_terminted_callback_t)(usb_device_t *, bool, void *);
+
+int usb_device_auto_polling(usb_device_t *, usb_endpoint_t,
     const usb_device_auto_polling_t *, size_t);
 
-typedef bool (*usb_polling_callback_t)(usb_device_t *,
-    uint8_t *, size_t, void *);
-typedef void (*usb_polling_terminted_callback_t)(usb_device_t *, bool, void *);
+int usb_device_auto_poll(usb_device_t *, usb_endpoint_t,
+    usb_polling_callback_t, size_t, int, usb_polling_terminted_callback_t, void *);
 
-int usb_device_auto_poll(usb_device_t *, size_t,
-    usb_polling_callback_t, size_t, usb_polling_terminted_callback_t, void *);
+int usb_device_auto_polling_desc(usb_device_t *,
+    const usb_endpoint_description_t *, const usb_device_auto_polling_t *,
+    size_t);
+
+int usb_device_auto_poll_desc(usb_device_t *,
+    const usb_endpoint_description_t *, usb_polling_callback_t, size_t, int,
+    usb_polling_terminted_callback_t, void *);
 
 #endif
Index: uspace/lib/usbdev/include/usb/dev/recognise.h
===================================================================
--- uspace/lib/usbdev/include/usb/dev/recognise.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbdev/include/usb/dev/recognise.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -37,8 +37,6 @@
 #define LIBUSBDEV_RECOGNISE_H_
 
-#include <sys/types.h>
 #include <usb/usb.h>
 #include <usb/dev/pipes.h>
-#include <ipc/devman.h>
 
 extern int usb_device_create_match_ids_from_device_descriptor(
@@ -50,8 +48,4 @@
 
 extern int usb_device_create_match_ids(usb_pipe_t *, match_id_list_t *);
-
-extern int usb_device_register_child_in_devman(usb_pipe_t *ctrl_pipe,
-    ddf_dev_t *, ddf_dev_ops_t *, void *, ddf_fun_t **);
-
 #endif
 
Index: uspace/lib/usbdev/include/usb/dev/request.h
===================================================================
--- uspace/lib/usbdev/include/usb/dev/request.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbdev/include/usb/dev/request.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -41,77 +41,9 @@
 #include <usb/dev/pipes.h>
 #include <usb/descriptor.h>
-
-/** USB device status - device is self powered (opposed to bus powered). */
-#define USB_DEVICE_STATUS_SELF_POWERED ((uint16_t)(1 << 0))
-
-/** USB device status - remote wake-up signaling is enabled. */
-#define USB_DEVICE_STATUS_REMOTE_WAKEUP ((uint16_t)(1 << 1))
-
-/** USB endpoint status - endpoint is halted (stalled). */
-#define USB_ENDPOINT_STATUS_HALTED ((uint16_t)(1 << 0))
-
-/** USB feature selector - endpoint halt (stall). */
-#define USB_FEATURE_SELECTOR_ENDPOINT_HALT (0)
-
-/** USB feature selector - device remote wake-up. */
-#define USB_FEATURE_SELECTOR_REMOTE_WAKEUP (1)
-
-/** Standard device request. */
-typedef enum {
-	USB_DEVREQ_GET_STATUS = 0,
-	USB_DEVREQ_CLEAR_FEATURE = 1,
-	USB_DEVREQ_SET_FEATURE = 3,
-	USB_DEVREQ_SET_ADDRESS = 5,
-	USB_DEVREQ_GET_DESCRIPTOR = 6,
-	USB_DEVREQ_SET_DESCRIPTOR = 7,
-	USB_DEVREQ_GET_CONFIGURATION = 8,
-	USB_DEVREQ_SET_CONFIGURATION = 9,
-	USB_DEVREQ_GET_INTERFACE = 10,
-	USB_DEVREQ_SET_INTERFACE = 11,
-	USB_DEVREQ_SYNCH_FRAME = 12,
-	USB_DEVREQ_LAST_STD
-} usb_stddevreq_t;
-
-/** Device request setup packet.
- * The setup packet describes the request.
- */
-typedef struct {
-	/** Request type.
-	 * The type combines transfer direction, request type and
-	 * intended recipient.
-	 */
-	uint8_t request_type;
-#define SETUP_REQUEST_TYPE_DEVICE_TO_HOST (1 << 7)
-#define SETUP_REQUEST_TYPE_GET_TYPE(rt) ((rt >> 5) & 0x3)
-#define SETUP_REQUEST_TYPE_GET_RECIPIENT(rec) (rec & 0x1f)
-#define SETUP_REQUEST_TO_HOST(type, recipient) \
-    (uint8_t)((1 << 7) | ((type & 0x3) << 5) | (recipient & 0x1f))
-#define SETUP_REQUEST_TO_DEVICE(type, recipient) \
-    (uint8_t)(((type & 0x3) << 5) | (recipient & 0x1f))
-
-	/** Request identification. */
-	uint8_t request;
-	/** Main parameter to the request. */
-	union __attribute__ ((packed)) {
-		uint16_t value;
-		/* FIXME: add #ifdefs according to host endianness */
-		struct __attribute__ ((packed)) {
-			uint8_t value_low;
-			uint8_t value_high;
-		};
-	};
-	/** Auxiliary parameter to the request.
-	 * Typically, it is offset to something.
-	 */
-	uint16_t index;
-	/** Length of extra data. */
-	uint16_t length;
-} __attribute__ ((packed)) usb_device_request_setup_packet_t;
-
-int assert[(sizeof(usb_device_request_setup_packet_t) == 8) ? 1: -1];
+#include <usb/request.h>
 
 int usb_control_request_set(usb_pipe_t *,
     usb_request_type_t, usb_request_recipient_t, uint8_t,
-    uint16_t, uint16_t, void *, size_t);
+    uint16_t, uint16_t, const void *, size_t);
 
 int usb_control_request_get(usb_pipe_t *,
@@ -137,10 +69,11 @@
     void *, size_t, size_t *);
 int usb_request_get_full_configuration_descriptor_alloc(usb_pipe_t *,
-    int, void **, size_t *);
+    int, const void **, size_t *);
 int usb_request_set_descriptor(usb_pipe_t *, usb_request_type_t,
-    usb_request_recipient_t, uint8_t, uint8_t, uint16_t, void *, size_t);
+    usb_request_recipient_t, uint8_t, uint8_t, uint16_t, const void *, size_t);
 
 int usb_request_get_configuration(usb_pipe_t *, uint8_t *);
 int usb_request_set_configuration(usb_pipe_t *, uint8_t);
+
 int usb_request_get_interface(usb_pipe_t *, uint8_t, uint8_t *);
 int usb_request_set_interface(usb_pipe_t *, uint8_t, uint8_t);
Index: uspace/lib/usbdev/include/usb/dev/usb_device_connection.h
===================================================================
--- uspace/lib/usbdev/include/usb/dev/usb_device_connection.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ 	(revision )
@@ -1,172 +1,0 @@
-/*
- * Copyright (c) 2011 Jan Vesely
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-/** @addtogroup libusbdev
- * @{
- */
-/** @file
- * Common USB types and functions.
- */
-#ifndef LIBUSBDEV_DEVICE_CONNECTION_H_
-#define LIBUSBDEV_DEVICE_CONNECTION_H_
-
-#include <errno.h>
-#include <devman.h>
-#include <usb/usb.h>
-#include <usb/hc.h>
-
-
-/** Abstraction of a physical connection to the device.
- * This type is an abstraction of the USB wire that connects the host and
- * the function (device).
- */
-typedef struct {
-	/** Connection to the host controller device is connected to. */
-	usb_hc_connection_t *hc_connection;
-	/** Address of the device. */
-	usb_address_t address;
-} usb_device_connection_t;
-
-/** Initialize device connection. Set address and hc connection.
- * @param instance Structure to initialize.
- * @param hc_connection. Host controller connection to use.
- * @param address USB address.
- * @return Error code.
- */
-static inline int usb_device_connection_initialize(
-    usb_device_connection_t *instance, usb_hc_connection_t *hc_connection,
-    usb_address_t address)
-{
-	assert(instance);
-	if (hc_connection == NULL)
-		return EBADMEM;
-	if ((address < 0) || (address >= USB11_ADDRESS_MAX))
-		return EINVAL;
-
-	instance->hc_connection = hc_connection;
-	instance->address = address;
-	return EOK;
-}
-
-/** Register endpoint on the device.
- * @param instance device connection structure to use.
- * @param ep USB endpoint number.
- * @param type Communication type of the endpoint.
- * @param direction Communication direction.
- * @param packet_size Maximum packet size for the endpoint.
- * @param interval Preferrred interval between communication.
- * @return Error code.
- */
-static inline int usb_device_register_endpoint(
-    usb_device_connection_t *instance, usb_endpoint_t ep,
-    usb_transfer_type_t type, usb_direction_t direction,
-    size_t packet_size, unsigned interval)
-{
-	assert(instance);
-	return usb_hc_register_endpoint(instance->hc_connection,
-	    instance->address, ep, type, direction, packet_size, interval);
-}
-
-/** Unregister endpoint on the device.
- * @param instance device connection structure
- * @param ep Endpoint number.
- * @param dir Communication direction.
- * @return Error code.
- */
-static inline int usb_device_unregister_endpoint(
-    usb_device_connection_t *instance, usb_endpoint_t ep, usb_direction_t dir)
-{
-	assert(instance);
-	return usb_hc_unregister_endpoint(instance->hc_connection,
-	    instance->address, ep, dir);
-}
-
-/** Get data from the device.
- * @param[in] instance device connection structure to use.
- * @param[in] ep target endpoint's number.
- * @param[in] setup Setup stage data (control transfers).
- * @param[in] data data buffer.
- * @param[in] size size of the data buffer.
- * @param[out] rsize bytes actually copied to the buffer.
- * @return Error code.
- */
-static inline int usb_device_control_read(usb_device_connection_t *instance,
-    usb_endpoint_t ep, uint64_t setup, void *data, size_t size, size_t *rsize)
-{
-	assert(instance);
-	return usb_hc_read(instance->hc_connection,
-	    instance->address, ep, setup, data, size, rsize);
-}
-
-/** Send data to the device.
- * @param instance device connection structure to use.
- * @param ep target endpoint's number.
- * @param setup Setup stage data (control transfers).
- * @param data data buffer.
- * @param size size of the data buffer.
- * @return Error code.
- */
-static inline int usb_device_control_write(usb_device_connection_t *instance,
-    usb_endpoint_t ep, uint64_t setup, const void *data, size_t size)
-{
-	assert(instance);
-	return usb_hc_write(instance->hc_connection,
-	    instance->address, ep, setup, data, size);
-}
-
-/** Wrapper for read calls with no setup stage.
- * @param[in] instance device connection structure.
- * @param[in] address USB device address.
- * @param[in] endpoint USB device endpoint.
- * @param[in] data Data buffer.
- * @param[in] size Size of the buffer.
- * @param[out] real_size Size of the transferred data.
- * @return Error code.
- */
-static inline int usb_device_read(usb_device_connection_t *instance,
-    usb_endpoint_t ep, void *data, size_t size, size_t *real_size)
-{
-	return usb_device_control_read(instance, ep, 0, data, size, real_size);
-}
-
-/** Wrapper for write calls with no setup stage.
- * @param instance device connection structure.
- * @param address USB device address.
- * @param endpoint USB device endpoint.
- * @param data Data buffer.
- * @param size Size of the buffer.
- * @return Error code.
- */
-static inline int usb_device_write(usb_device_connection_t *instance,
-    usb_endpoint_t ep, const void *data, size_t size)
-{
-	return usb_device_control_write(instance, ep, 0, data, size);
-}
-#endif
-/**
- * @}
- */
Index: uspace/lib/usbdev/src/altiface.c
===================================================================
--- uspace/lib/usbdev/src/altiface.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbdev/src/altiface.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -34,10 +34,8 @@
  */
 
-#include <usb/dev/driver.h>
-#include <usb/dev/request.h>
-#include <usb/debug.h>
+#include <usb/dev/alternate_ifaces.h>
 #include <usb/dev/dp.h>
+#include <malloc.h>
 #include <errno.h>
-#include <str_error.h>
 #include <assert.h>
 
@@ -105,15 +103,14 @@
 	}
 
-	alternates->alternative_count
-	    = usb_interface_count_alternates(config_descr, config_descr_size,
-	        interface_number);
+	const size_t alt_count =usb_interface_count_alternates(config_descr,
+	    config_descr_size, interface_number);
 
-	if (alternates->alternative_count == 0) {
+	if (alt_count == 0) {
 		return ENOENT;
 	}
 
-	alternates->alternatives = calloc(alternates->alternative_count,
+	usb_alternate_interface_descriptors_t *alts = calloc(alt_count,
 	    sizeof(usb_alternate_interface_descriptors_t));
-	if (alternates->alternatives == NULL) {
+	if (alts == NULL) {
 		return ENOMEM;
 	}
@@ -128,14 +125,10 @@
 	};
 
-	usb_alternate_interface_descriptors_t *iterator
-	    = &alternates->alternatives[0];
-
-	const usb_alternate_interface_descriptors_t *end
-	    = &alternates->alternatives[alternates->alternative_count];
 
 	const void *iface_ptr =
 	    usb_dp_get_nested_descriptor(&dp_parser, &dp_data, dp_data.data);
 
-	while (iface_ptr != NULL && iterator < end) {
+	usb_alternate_interface_descriptors_t *iterator = alts;
+	for (; iface_ptr != NULL && iterator < &alts[alt_count]; ++iterator) {
 		const usb_standard_interface_descriptor_t *iface = iface_ptr;
 
@@ -159,9 +152,10 @@
 		    dp_data.data + dp_data.size : iface_ptr;
 
-		iterator->nested_descriptors_size
-		    = next - iterator->nested_descriptors;
+		iterator->nested_descriptors_size =
+		    next - iterator->nested_descriptors;
+	}
 
-		++iterator;
-	}
+	alternates->alternatives = alts;
+	alternates->alternative_count = alt_count;
 
 	return EOK;
Index: uspace/lib/usbdev/src/devdrv.c
===================================================================
--- uspace/lib/usbdev/src/devdrv.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbdev/src/devdrv.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -33,5 +33,7 @@
  * USB device driver framework.
  */
-#include <usb/dev/driver.h>
+
+#include <usb_iface.h>
+#include <usb/dev/device.h>
 #include <usb/dev/request.h>
 #include <usb/debug.h>
@@ -41,37 +43,38 @@
 #include <assert.h>
 
-static int generic_device_add(ddf_dev_t *);
-static int generic_device_remove(ddf_dev_t *);
-static int generic_device_gone(ddf_dev_t *);
-
-static driver_ops_t generic_driver_ops = {
-	.dev_add = generic_device_add,
-	.dev_remove = generic_device_remove,
-	.dev_gone = generic_device_gone,
-};
-static driver_t generic_driver = {
-	.driver_ops = &generic_driver_ops
-};
-
-static const usb_driver_t *driver = NULL;
-
-/** Main routine of USB device driver.
- *
- * Under normal conditions, this function never returns.
- *
- * @param drv USB device driver structure.
- * @return Task exit status.
- */
-int usb_driver_main(const usb_driver_t *drv)
-{
-	assert(drv != NULL);
-
-	/* Prepare the generic driver. */
-	generic_driver.name = drv->name;
-
-	driver = drv;
-
-	return ddf_driver_main(&generic_driver);
-}
+/** USB device structure. */
+typedef struct usb_device {
+	/** Connection to device on USB bus */
+	usb_dev_session_t *bus_session;
+	/** devman handle */
+	devman_handle_t handle;
+	/** The default control pipe. */
+	usb_pipe_t ctrl_pipe;
+
+	/** Other endpoint pipes.
+	 * This is an array of other endpoint pipes in the same order as
+	 * in usb_driver_t.
+	 */
+	usb_endpoint_mapping_t *pipes;
+	/** Number of other endpoint pipes. */
+	size_t pipes_count;
+	/** Current interface.
+	 * Usually, drivers operate on single interface only.
+	 * This item contains the value of the interface or -1 for any.
+	 */
+	int interface_no;
+	/** Alternative interfaces. */
+	usb_alternate_interfaces_t alternate_interfaces;
+	/** Some useful descriptors for USB device. */
+	usb_device_descriptors_t descriptors;
+	/** Generic DDF device backing this one. DO NOT TOUCH! */
+	ddf_dev_t *ddf_dev;
+	/** Custom driver data.
+	 * Do not use the entry in generic device, that is already used
+	 * by the framework.
+	 */
+	void *driver_data;
+
+} usb_device_t;
 
 /** Count number of pipes the driver expects.
@@ -80,101 +83,9 @@
  * @return Number of pipes (excluding default control pipe).
  */
-static inline size_t count_other_pipes(
-    const usb_endpoint_description_t **endpoints)
+static inline size_t count_pipes(const usb_endpoint_description_t **endpoints)
 {
 	size_t count;
 	for (count = 0; endpoints != NULL && endpoints[count] != NULL; ++count);
 	return count;
-}
-
-/** Callback when a new device is supposed to be controlled by this driver.
- *
- * This callback is a wrapper for USB specific version of @c device_add.
- *
- * @param gen_dev Device structure as prepared by DDF.
- * @return Error code.
- */
-int generic_device_add(ddf_dev_t *gen_dev)
-{
-	assert(driver);
-	assert(driver->ops);
-	assert(driver->ops->device_add);
-
-	/* Get place for driver data. */
-	usb_device_t *dev = ddf_dev_data_alloc(gen_dev, sizeof(usb_device_t));
-	if (dev == NULL) {
-		usb_log_error("USB device `%s' structure allocation failed.\n",
-		    ddf_dev_get_name(gen_dev));
-		return ENOMEM;
-	}
-
-	/* Initialize generic USB driver data. */
-	const char *err_msg = NULL;
-	int rc = usb_device_init(dev, gen_dev, driver->endpoints, &err_msg);
-	if (rc != EOK) {
-		usb_log_error("USB device `%s' init failed (%s): %s.\n",
-		    ddf_dev_get_name(gen_dev), err_msg, str_error(rc));
-		return rc;
-	}
-
-	/* Start USB driver specific initialization. */
-	rc = driver->ops->device_add(dev);
-	if (rc != EOK)
-		usb_device_deinit(dev);
-	return rc;
-}
-
-/** Callback when a device is supposed to be removed from the system.
- *
- * This callback is a wrapper for USB specific version of @c device_remove.
- *
- * @param gen_dev Device structure as prepared by DDF.
- * @return Error code.
- */
-int generic_device_remove(ddf_dev_t *gen_dev)
-{
-	assert(driver);
-	assert(driver->ops);
-	if (driver->ops->device_rem == NULL)
-		return ENOTSUP;
-	/* Just tell the driver to stop whatever it is doing */
-	usb_device_t *usb_dev = ddf_dev_data_get(gen_dev);
-	const int ret = driver->ops->device_rem(usb_dev);
-	if (ret != EOK)
-		return ret;
-	usb_device_deinit(usb_dev);
-	return EOK;
-}
-
-/** Callback when a device was removed from the system.
- *
- * This callback is a wrapper for USB specific version of @c device_gone.
- *
- * @param gen_dev Device structure as prepared by DDF.
- * @return Error code.
- */
-int generic_device_gone(ddf_dev_t *gen_dev)
-{
-	assert(driver);
-	assert(driver->ops);
-	if (driver->ops->device_gone == NULL)
-		return ENOTSUP;
-	usb_device_t *usb_dev = ddf_dev_data_get(gen_dev);
-	const int ret = driver->ops->device_gone(usb_dev);
-	if (ret == EOK)
-		usb_device_deinit(usb_dev);
-
-	return ret;
-}
-
-/** Destroy existing pipes of a USB device.
- *
- * @param dev Device where to destroy the pipes.
- */
-static void destroy_current_pipes(usb_device_t *dev)
-{
-	usb_device_destroy_pipes(dev->pipes, dev->pipes_count);
-	dev->pipes = NULL;
-	dev->pipes_count = 0;
 }
 
@@ -201,26 +112,28 @@
  * @return Error code.
  */
-int usb_device_select_interface(usb_device_t *dev, uint8_t alternate_setting,
-    const usb_endpoint_description_t **endpoints)
-{
-	if (dev->interface_no < 0) {
+int usb_device_select_interface(usb_device_t *usb_dev,
+    uint8_t alternate_setting, const usb_endpoint_description_t **endpoints)
+{
+	assert(usb_dev);
+
+	if (usb_dev->interface_no < 0) {
 		return EINVAL;
 	}
 
-	/* Destroy existing pipes. */
-	destroy_current_pipes(dev);
-
 	/* Change the interface itself. */
-	int rc = usb_request_set_interface(&dev->ctrl_pipe, dev->interface_no,
-	    alternate_setting);
+	int rc = usb_request_set_interface(&usb_dev->ctrl_pipe,
+	    usb_dev->interface_no, alternate_setting);
 	if (rc != EOK) {
 		return rc;
 	}
 
+	/* Change current alternative */
+	usb_dev->alternate_interfaces.current = alternate_setting;
+
+	/* Destroy existing pipes. */
+	usb_device_destroy_pipes(usb_dev);
+
 	/* Create new pipes. */
-	rc = usb_device_create_pipes(&dev->wire, endpoints,
-	    dev->descriptors.configuration, dev->descriptors.configuration_size,
-	    dev->interface_no, (int)alternate_setting,
-	    &dev->pipes, &dev->pipes_count);
+	rc = usb_device_create_pipes(usb_dev, endpoints);
 
 	return rc;
@@ -233,29 +146,22 @@
  * @return Error code.
  */
-int usb_device_retrieve_descriptors(usb_pipe_t *ctrl_pipe,
-    usb_device_descriptors_t *descriptors)
-{
-	assert(descriptors != NULL);
-
-	descriptors->configuration = NULL;
-
-	int rc;
-
-	/* It is worth to start a long transfer. */
-	usb_pipe_start_long_transfer(ctrl_pipe);
+static int usb_device_retrieve_descriptors(usb_device_t *usb_dev)
+{
+	assert(usb_dev);
+	assert(usb_dev->descriptors.full_config == NULL);
 
 	/* Get the device descriptor. */
-	rc = usb_request_get_device_descriptor(ctrl_pipe, &descriptors->device);
+	int rc = usb_request_get_device_descriptor(&usb_dev->ctrl_pipe,
+	    &usb_dev->descriptors.device);
 	if (rc != EOK) {
-		goto leave;
+		return rc;
 	}
 
 	/* Get the full configuration descriptor. */
 	rc = usb_request_get_full_configuration_descriptor_alloc(
-	    ctrl_pipe, 0, (void **) &descriptors->configuration,
-	    &descriptors->configuration_size);
-
-leave:
-	usb_pipe_end_long_transfer(ctrl_pipe);
+	    &usb_dev->ctrl_pipe, 0,
+	    &usb_dev->descriptors.full_config,
+	    &usb_dev->descriptors.full_config_size);
+
 
 	return rc;
@@ -266,9 +172,10 @@
  * @param[in] descriptors Where to store the descriptors.
  */
-void usb_device_release_descriptors(usb_device_descriptors_t *descriptors)
-{
-	assert(descriptors);
-	free(descriptors->configuration);
-	descriptors->configuration = NULL;
+static void usb_device_release_descriptors(usb_device_t *usb_dev)
+{
+	assert(usb_dev);
+	free(usb_dev->descriptors.full_config);
+	usb_dev->descriptors.full_config = NULL;
+	usb_dev->descriptors.full_config_size = 0;
 }
 
@@ -280,5 +187,4 @@
  * - registers endpoints with the host controller
  *
- * @param[in] wire Initialized backing connection to the host controller.
  * @param[in] endpoints Endpoints description, NULL terminated.
  * @param[in] config_descr Configuration descriptor of active configuration.
@@ -292,28 +198,19 @@
  * @return Error code.
  */
-int usb_device_create_pipes(usb_device_connection_t *wire,
-    const usb_endpoint_description_t **endpoints,
-    const uint8_t *config_descr, size_t config_descr_size,
-    int interface_no, int interface_setting,
-    usb_endpoint_mapping_t **pipes_ptr, size_t *pipes_count_ptr)
-{
-	assert(wire != NULL);
-	assert(config_descr != NULL);
-	assert(config_descr_size > 0);
-	assert(pipes_ptr != NULL);
-
-	size_t i;
-	int rc;
-
-	const size_t pipe_count = count_other_pipes(endpoints);
+int usb_device_create_pipes(usb_device_t *usb_dev,
+    const usb_endpoint_description_t **endpoints)
+{
+	assert(usb_dev);
+	assert(usb_dev->descriptors.full_config);
+	assert(usb_dev->pipes == NULL);
+	assert(usb_dev->pipes_count == 0);
+
+	size_t pipe_count = count_pipes(endpoints);
 	if (pipe_count == 0) {
-		if (pipes_count_ptr)
-			*pipes_count_ptr = pipe_count;
-		*pipes_ptr = NULL;
 		return EOK;
 	}
 
-	usb_endpoint_mapping_t *pipes
-	    = calloc(pipe_count, sizeof(usb_endpoint_mapping_t));
+	usb_endpoint_mapping_t *pipes =
+	    calloc(pipe_count, sizeof(usb_endpoint_mapping_t));
 	if (pipes == NULL) {
 		return ENOMEM;
@@ -321,13 +218,16 @@
 
 	/* Now initialize. */
-	for (i = 0; i < pipe_count; i++) {
+	for (size_t i = 0; i < pipe_count; i++) {
 		pipes[i].description = endpoints[i];
-		pipes[i].interface_no = interface_no;
-		pipes[i].interface_setting = interface_setting;
+		pipes[i].interface_no = usb_dev->interface_no;
+		pipes[i].interface_setting =
+		    usb_dev->alternate_interfaces.current;
 	}
 
 	/* Find the mapping from configuration descriptor. */
-	rc = usb_pipe_initialize_from_configuration(pipes, pipe_count,
-	    config_descr, config_descr_size, wire);
+	int rc = usb_pipe_initialize_from_configuration(pipes, pipe_count,
+	    usb_dev->descriptors.full_config,
+	    usb_dev->descriptors.full_config_size,
+	    usb_dev->bus_session);
 	if (rc != EOK) {
 		free(pipes);
@@ -336,5 +236,5 @@
 
 	/* Register created pipes. */
-	for (i = 0; i < pipe_count; i++) {
+	for (size_t i = 0; i < pipe_count; i++) {
 		if (pipes[i].present) {
 			rc = usb_pipe_register(&pipes[i].pipe,
@@ -346,8 +246,6 @@
 	}
 
-	*pipes_ptr = pipes;
-	if (pipes_count_ptr != NULL) {
-		*pipes_count_ptr = pipe_count;
-	}
+	usb_dev->pipes = pipes;
+	usb_dev->pipes_count = pipe_count;
 
 	return EOK;
@@ -360,5 +258,5 @@
 	 */
 rollback_unregister_endpoints:
-	for (i = 0; i < pipe_count; i++) {
+	for (size_t i = 0; i < pipe_count; i++) {
 		if (pipes[i].present) {
 			usb_pipe_unregister(&pipes[i].pipe);
@@ -372,18 +270,94 @@
 /** Destroy pipes previously created by usb_device_create_pipes.
  *
- * @param[in] pipes Endpoint mapping to be destroyed.
- * @param[in] pipes_count Number of endpoints.
- */
-void usb_device_destroy_pipes(usb_endpoint_mapping_t *pipes, size_t pipes_count)
-{
+ * @param[in] usb_dev USB device.
+ */
+void usb_device_destroy_pipes(usb_device_t *usb_dev)
+{
+	assert(usb_dev);
+	assert(usb_dev->pipes || usb_dev->pipes_count == 0);
 	/* Destroy the pipes. */
-	for (size_t i = 0; i < pipes_count; ++i) {
-		assert(pipes);
+	for (size_t i = 0; i < usb_dev->pipes_count; ++i) {
 		usb_log_debug2("Unregistering pipe %zu: %spresent.\n",
-		    i, pipes[i].present ? "" : "not ");
-		if (pipes[i].present)
-			usb_pipe_unregister(&pipes[i].pipe);
-	}
-	free(pipes);
+		    i, usb_dev->pipes[i].present ? "" : "not ");
+		if (usb_dev->pipes[i].present)
+			usb_pipe_unregister(&usb_dev->pipes[i].pipe);
+	}
+	free(usb_dev->pipes);
+	usb_dev->pipes = NULL;
+	usb_dev->pipes_count = 0;
+}
+
+usb_pipe_t *usb_device_get_default_pipe(usb_device_t *usb_dev)
+{
+	assert(usb_dev);
+	return &usb_dev->ctrl_pipe;
+}
+
+usb_endpoint_mapping_t *usb_device_get_mapped_ep_desc(usb_device_t *usb_dev,
+    const usb_endpoint_description_t *desc)
+{
+	assert(usb_dev);
+	for (unsigned i = 0; i < usb_dev->pipes_count; ++i) {
+		if (usb_dev->pipes[i].description == desc)
+			return &usb_dev->pipes[i];
+	}
+	return NULL;
+}
+
+usb_endpoint_mapping_t * usb_device_get_mapped_ep(
+    usb_device_t *usb_dev, usb_endpoint_t ep)
+{
+	assert(usb_dev);
+	for (unsigned i = 0; i < usb_dev->pipes_count; ++i) {
+		if (usb_dev->pipes[i].pipe.endpoint_no == ep)
+			return &usb_dev->pipes[i];
+	}
+	return NULL;
+}
+
+int usb_device_get_iface_number(usb_device_t *usb_dev)
+{
+	assert(usb_dev);
+	return usb_dev->interface_no;
+}
+
+devman_handle_t usb_device_get_devman_handle(usb_device_t *usb_dev)
+{
+	assert(usb_dev);
+	return usb_dev->handle;
+}
+
+const usb_device_descriptors_t *usb_device_descriptors(usb_device_t *usb_dev)
+{
+	assert(usb_dev);
+	return &usb_dev->descriptors;
+}
+
+const usb_alternate_interfaces_t * usb_device_get_alternative_ifaces(
+    usb_device_t *usb_dev)
+{
+	assert(usb_dev);
+	return &usb_dev->alternate_interfaces;
+}
+
+/** Clean instance of a USB device.
+ *
+ * @param dev Device to be de-initialized.
+ *
+ * Does not free/destroy supplied pointer.
+ */
+static void usb_device_fini(usb_device_t *usb_dev)
+{
+	if (usb_dev) {
+		/* Destroy existing pipes. */
+		usb_device_destroy_pipes(usb_dev);
+		/* Ignore errors and hope for the best. */
+		usb_alternate_interfaces_deinit(&usb_dev->alternate_interfaces);
+		usb_device_release_descriptors(usb_dev);
+		free(usb_dev->driver_data);
+		usb_dev->driver_data = NULL;
+		usb_dev_disconnect(usb_dev->bus_session);
+		usb_dev->bus_session = NULL;
+	}
 }
 
@@ -397,62 +371,44 @@
  * @return Error code.
  */
-int usb_device_init(usb_device_t *usb_dev, ddf_dev_t *ddf_dev,
-    const usb_endpoint_description_t **endpoints, const char **errstr_ptr)
+static int usb_device_init(usb_device_t *usb_dev, ddf_dev_t *ddf_dev,
+    const usb_endpoint_description_t **endpoints, const char **errstr_ptr,
+    devman_handle_t handle, int interface_no)
 {
 	assert(usb_dev != NULL);
-	assert(ddf_dev != NULL);
+	assert(errstr_ptr);
 
 	*errstr_ptr = NULL;
 
 	usb_dev->ddf_dev = ddf_dev;
+	usb_dev->handle = handle;
+	usb_dev->interface_no = interface_no;
 	usb_dev->driver_data = NULL;
-	usb_dev->descriptors.configuration = NULL;
+	usb_dev->descriptors.full_config = NULL;
+	usb_dev->descriptors.full_config_size = 0;
 	usb_dev->pipes_count = 0;
 	usb_dev->pipes = NULL;
 
-	/* Get assigned params */
-	devman_handle_t hc_handle;
-	usb_address_t address;
-
-	int rc = usb_get_info_by_handle(ddf_dev_get_handle(ddf_dev),
-	    &hc_handle, &address, &usb_dev->interface_no);
-	if (rc != EOK) {
-		*errstr_ptr = "device parameters retrieval";
-		return rc;
-	}
-
-	/* Initialize hc connection. */
-	usb_hc_connection_initialize(&usb_dev->hc_conn, hc_handle);
-
-	/* Initialize backing wire and control pipe. */
-	rc = usb_device_connection_initialize(
-	    &usb_dev->wire, &usb_dev->hc_conn, address);
-	if (rc != EOK) {
-		*errstr_ptr = "device connection initialization";
-		return rc;
+	usb_dev->bus_session = usb_dev_connect(handle);
+
+	if (!usb_dev->bus_session) {
+		*errstr_ptr = "device bus session create";
+		return ENOMEM;
 	}
 
 	/* This pipe was registered by the hub driver,
 	 * during device initialization. */
-	rc = usb_pipe_initialize_default_control(
-	    &usb_dev->ctrl_pipe, &usb_dev->wire);
+	int rc = usb_pipe_initialize_default_control(
+	    &usb_dev->ctrl_pipe, usb_dev->bus_session);
 	if (rc != EOK) {
+		usb_dev_disconnect(usb_dev->bus_session);
 		*errstr_ptr = "default control pipe initialization";
 		return rc;
 	}
 
-	/* Open hc connection for pipe registration. */
-	rc = usb_hc_connection_open(&usb_dev->hc_conn);
-	if (rc != EOK) {
-		*errstr_ptr = "hc connection open";
-		return rc;
-	}
-
 	/* Retrieve standard descriptors. */
-	rc = usb_device_retrieve_descriptors(
-	    &usb_dev->ctrl_pipe, &usb_dev->descriptors);
+	rc = usb_device_retrieve_descriptors(usb_dev);
 	if (rc != EOK) {
 		*errstr_ptr = "descriptor retrieval";
-		usb_hc_connection_close(&usb_dev->hc_conn);
+		usb_dev_disconnect(usb_dev->bus_session);
 		return rc;
 	}
@@ -463,47 +419,134 @@
 	 * controlling a device. */
 	rc = usb_alternate_interfaces_init(&usb_dev->alternate_interfaces,
-	    usb_dev->descriptors.configuration,
-	    usb_dev->descriptors.configuration_size, usb_dev->interface_no);
-	const int alternate_iface =
-	    (rc == EOK) ? usb_dev->alternate_interfaces.current : 0;
-
-	/* Create and register other pipes than default control (EP 0) */
-	rc = usb_device_create_pipes(&usb_dev->wire, endpoints,
-	    usb_dev->descriptors.configuration,
-	    usb_dev->descriptors.configuration_size,
-	    usb_dev->interface_no, (int)alternate_iface,
-	    &usb_dev->pipes, &usb_dev->pipes_count);
-	if (rc != EOK) {
-		usb_hc_connection_close(&usb_dev->hc_conn);
-		/* Full configuration descriptor is allocated. */
-		usb_device_release_descriptors(&usb_dev->descriptors);
-		/* Alternate interfaces may be allocated */
-		usb_alternate_interfaces_deinit(&usb_dev->alternate_interfaces);
-		*errstr_ptr = "pipes initialization";
-		return rc;
-	}
-
-	usb_hc_connection_close(&usb_dev->hc_conn);
+	    usb_dev->descriptors.full_config,
+	    usb_dev->descriptors.full_config_size, usb_dev->interface_no);
+
+	if (endpoints) {
+		/* Create and register other pipes than default control (EP 0)*/
+		rc = usb_device_create_pipes(usb_dev, endpoints);
+		if (rc != EOK) {
+			usb_device_fini(usb_dev);
+			*errstr_ptr = "pipes initialization";
+			return rc;
+		}
+	}
+
 	return EOK;
 }
 
-/** Clean instance of a USB device.
- *
- * @param dev Device to be de-initialized.
- *
- * Does not free/destroy supplied pointer.
- */
-void usb_device_deinit(usb_device_t *dev)
-{
-	if (dev) {
-		/* Destroy existing pipes. */
-		destroy_current_pipes(dev);
-		/* Ignore errors and hope for the best. */
-		usb_hc_connection_deinitialize(&dev->hc_conn);
-		usb_alternate_interfaces_deinit(&dev->alternate_interfaces);
-		usb_device_release_descriptors(&dev->descriptors);
-		free(dev->driver_data);
-		dev->driver_data = NULL;
-	}
+static int usb_device_get_info(async_sess_t *sess, devman_handle_t *handle,
+	int *iface_no)
+{
+	assert(handle);
+	assert(iface_no);
+	async_exch_t *exch = async_exchange_begin(sess);
+	if (!exch)
+		return EPARTY;
+	int ret = usb_get_my_device_handle(exch, handle);
+	if (ret == EOK) {
+		ret = usb_get_my_interface(exch, iface_no);
+		if (ret == ENOTSUP) {
+			*iface_no = -1;
+			ret = EOK;
+		}
+	}
+	async_exchange_end(exch);
+	return ret;
+}
+
+int usb_device_create_ddf(ddf_dev_t *ddf_dev,
+    const usb_endpoint_description_t **desc, const char **err)
+{
+	assert(ddf_dev);
+	assert(err);
+
+	devman_handle_t h = 0;
+	int iface_no = -1;
+
+	async_sess_t *sess = devman_parent_device_connect(EXCHANGE_ATOMIC,
+	    ddf_dev_get_handle(ddf_dev), IPC_FLAG_BLOCKING);
+	const int ret = usb_device_get_info(sess, &h, &iface_no);
+	async_hangup(sess);
+	if (ret != EOK)
+		return ret;
+
+	usb_device_t *usb_dev =
+	    ddf_dev_data_alloc(ddf_dev, sizeof(usb_device_t));
+	if (usb_dev == NULL) {
+		*err = "DDF data alloc";
+		return ENOMEM;
+	}
+	
+	return usb_device_init(usb_dev, ddf_dev, desc, err, h, iface_no);
+}
+
+void usb_device_destroy_ddf(ddf_dev_t *ddf_dev)
+{
+	assert(ddf_dev);
+	usb_device_t *usb_dev = ddf_dev_data_get(ddf_dev);
+	assert(usb_dev);
+	usb_device_fini(usb_dev);
+	return;
+}
+
+usb_device_t * usb_device_create(devman_handle_t handle)
+{
+	devman_handle_t h = 0;
+	int iface_no = -1;
+
+	async_sess_t *sess = devman_device_connect(
+	    EXCHANGE_ATOMIC, handle, IPC_FLAG_BLOCKING);
+	int ret = usb_device_get_info(sess, &h, &iface_no);
+	async_hangup(sess);
+	if (ret != EOK)
+		return NULL;
+
+	usb_device_t *usb_dev = malloc(sizeof(usb_device_t));
+	if (!usb_dev)
+		return NULL;
+
+	const char* dummy = NULL;
+	ret = usb_device_init(usb_dev, NULL, NULL, &dummy, handle, iface_no);
+	if (ret != EOK) {
+		free(usb_dev);
+		usb_dev = NULL;
+	}
+	return usb_dev;
+}
+
+void usb_device_destroy(usb_device_t *usb_dev)
+{
+	if (usb_dev) {
+		usb_device_fini(usb_dev);
+		free(usb_dev);
+	}
+}
+
+const char *usb_device_get_name(usb_device_t *usb_dev)
+{
+	assert(usb_dev);
+	if (usb_dev->ddf_dev)
+		return ddf_dev_get_name(usb_dev->ddf_dev);
+	return NULL;
+}
+
+ddf_fun_t *usb_device_ddf_fun_create(usb_device_t *usb_dev, fun_type_t ftype,
+    const char* name)
+{
+	assert(usb_dev);
+	if (usb_dev->ddf_dev)
+		return ddf_fun_create(usb_dev->ddf_dev, ftype, name);
+	return NULL;
+}
+
+async_exch_t * usb_device_bus_exchange_begin(usb_device_t *usb_dev)
+{
+	assert(usb_dev);
+	return async_exchange_begin(usb_dev->bus_session);
+}
+
+void usb_device_bus_exchange_end(async_exch_t *exch)
+{
+	async_exchange_end(exch);
 }
 
@@ -521,4 +564,10 @@
 }
 
+void * usb_device_data_get(usb_device_t *usb_dev)
+{
+	assert(usb_dev);
+	return usb_dev->driver_data;
+}
+
 /**
  * @}
Index: uspace/lib/usbdev/src/devpoll.c
===================================================================
--- uspace/lib/usbdev/src/devpoll.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbdev/src/devpoll.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -51,6 +51,6 @@
 	/** USB device to poll. */
 	usb_device_t *dev;
-	/** Device pipe to use for polling. */
-	size_t pipe_index;
+	/** Device enpoint mapping to use for polling. */
+	usb_endpoint_mapping_t *polling_mapping;
 	/** Size of the recieved data. */
 	size_t request_size;
@@ -72,13 +72,12 @@
 	const usb_device_auto_polling_t *params = &data->auto_polling;
 
-	usb_pipe_t *pipe
-	    = &data->dev->pipes[data->pipe_index].pipe;
+	usb_pipe_t *pipe = &data->polling_mapping->pipe;
 
 	if (params->debug > 0) {
 		const usb_endpoint_mapping_t *mapping
-		    = &data->dev->pipes[data->pipe_index];
+		    = data->polling_mapping;
 		usb_log_debug("Poll%p: started polling of `%s' - " \
 		    "interface %d (%s,%d,%d), %zuB/%zu.\n",
-		    data, ddf_dev_get_name(data->dev->ddf_dev),
+		    data, usb_device_get_name(data->dev),
 		    (int) mapping->interface->interface_number,
 		    usb_str_class(mapping->interface->interface_class),
@@ -88,5 +87,4 @@
 	}
 
-	usb_pipe_start_long_transfer(pipe);
 	size_t failed_attempts = 0;
 	while (failed_attempts <= params->max_failures) {
@@ -117,5 +115,6 @@
 			 */
 			usb_request_clear_endpoint_halt(
-			    &data->dev->ctrl_pipe, pipe->endpoint_no);
+			    usb_device_get_default_pipe(data->dev),
+			    pipe->endpoint_no);
 		}
 
@@ -148,6 +147,4 @@
 	}
 
-	usb_pipe_end_long_transfer(pipe);
-
 	const bool failed = failed_attempts > 0;
 
@@ -159,10 +156,10 @@
 		if (failed) {
 			usb_log_error("Polling of device `%s' terminated: "
-			    "recurring failures.\n", ddf_dev_get_name(
-			    data->dev->ddf_dev));
+			    "recurring failures.\n",
+			    usb_device_get_name(data->dev));
 		} else {
 			usb_log_debug("Polling of device `%s' terminated: "
-			    "driver request.\n", ddf_dev_get_name(
-			    data->dev->ddf_dev));
+			    "driver request.\n",
+			    usb_device_get_name(data->dev));
 		}
 	}
@@ -175,8 +172,9 @@
 }
 
+
 /** Start automatic device polling over interrupt in pipe.
  *
- * @warning It is up to the callback to produce delays between individual
- * requests.
+ * The polling settings is copied thus it is okay to destroy the structure
+ * after this function returns.
  *
  * @warning There is no guarantee when the request to the device
@@ -185,7 +183,101 @@
  *
  * @param dev Device to be periodically polled.
+ * @param epm Endpoint mapping to use.
+ * @param polling Polling settings.
+ * @param request_size How many bytes to ask for in each request.
+ * @param arg Custom argument (passed as is to the callbacks).
+ * @return Error code.
+ * @retval EOK New fibril polling the device was already started.
+ */
+static int usb_device_auto_polling_internal(usb_device_t *dev,
+    usb_endpoint_mapping_t *epm, const usb_device_auto_polling_t *polling,
+    size_t request_size)
+{
+	if ((dev == NULL) || (polling == NULL) || (polling->on_data == NULL)) {
+		return EBADMEM;
+	}
+
+	if (request_size == 0)
+		return EINVAL;
+
+	if (!epm || (epm->pipe.transfer_type != USB_TRANSFER_INTERRUPT) ||
+	    (epm->pipe.direction != USB_DIRECTION_IN))
+		return EINVAL;
+
+
+	polling_data_t *polling_data = malloc(sizeof(polling_data_t));
+	if (polling_data == NULL) {
+		return ENOMEM;
+	}
+
+	/* Fill-in the data. */
+	polling_data->buffer = malloc(sizeof(request_size));
+	if (polling_data->buffer == NULL) {
+		free(polling_data);
+		return ENOMEM;
+	}
+	polling_data->request_size = request_size;
+	polling_data->dev = dev;
+	polling_data->polling_mapping = epm;
+
+	/* Copy provided settings. */
+	polling_data->auto_polling = *polling;
+
+	/* Negative value means use descriptor provided value. */
+	if (polling->delay < 0) {
+		polling_data->auto_polling.delay =
+		    epm->descriptor->poll_interval;
+	}
+
+	fid_t fibril = fibril_create(polling_fibril, polling_data);
+	if (fibril == 0) {
+		free(polling_data->buffer);
+		free(polling_data);
+		return ENOMEM;
+	}
+	fibril_add_ready(fibril);
+
+	/* Fibril launched. That fibril will free the allocated data. */
+
+	return EOK;
+}
+/** Start automatic device polling over interrupt in pipe.
+ *
+ * The polling settings is copied thus it is okay to destroy the structure
+ * after this function returns.
+ *
+ * @warning There is no guarantee when the request to the device
+ * will be sent for the first time (it is possible that this
+ * first request would be executed prior to return from this function).
+ *
+ * @param dev Device to be periodically polled.
  * @param pipe_index Index of the endpoint pipe used for polling.
+ * @param polling Polling settings.
+ * @param req_size How many bytes to ask for in each request.
+ * @param arg Custom argument (passed as is to the callbacks).
+ * @return Error code.
+ * @retval EOK New fibril polling the device was already started.
+ */
+int usb_device_auto_polling(usb_device_t *usb_dev, usb_endpoint_t ep,
+    const usb_device_auto_polling_t *polling, size_t req_size)
+{
+	usb_endpoint_mapping_t *epm = usb_device_get_mapped_ep(usb_dev, ep);
+	return usb_device_auto_polling_internal(usb_dev, epm, polling, req_size);
+}
+
+/** Start automatic device polling over interrupt in pipe.
+ *
+ * @warning It is up to the callback to produce delays between individual
+ * requests.
+ *
+ * @warning There is no guarantee when the request to the device
+ * will be sent for the first time (it is possible that this
+ * first request would be executed prior to return from this function).
+ *
+ * @param dev Device to be periodically polled.
+ * @param ep Endpoint  used for polling.
  * @param callback Callback when data are available.
  * @param request_size How many bytes to ask for in each request.
+ * @param delay NUmber of ms to wait between queries, -1 to use descriptor val.
  * @param terminated_callback Callback when polling is terminated.
  * @param arg Custom argument (passed as is to the callbacks).
@@ -193,6 +285,6 @@
  * @retval EOK New fibril polling the device was already started.
  */
-int usb_device_auto_poll(usb_device_t *dev, size_t pipe_index,
-    usb_polling_callback_t callback, size_t request_size,
+int usb_device_auto_poll(usb_device_t *dev, usb_endpoint_t ep,
+    usb_polling_callback_t callback, size_t request_size, int delay,
     usb_polling_terminted_callback_t terminated_callback, void *arg)
 {
@@ -200,5 +292,5 @@
 		.debug = 1,
 		.auto_clear_halt = true,
-		.delay = 0,
+		.delay = delay,
 		.max_failures = MAX_FAILED_ATTEMPTS,
 		.on_data = callback,
@@ -208,76 +300,38 @@
 	};
 
-	return usb_device_auto_polling(dev, pipe_index, &auto_polling,
-	   request_size);
-}
-
-/** Start automatic device polling over interrupt in pipe.
- *
- * The polling settings is copied thus it is okay to destroy the structure
- * after this function returns.
- *
- * @warning There is no guarantee when the request to the device
- * will be sent for the first time (it is possible that this
- * first request would be executed prior to return from this function).
- *
- * @param dev Device to be periodically polled.
- * @param pipe_index Index of the endpoint pipe used for polling.
- * @param polling Polling settings.
- * @param request_size How many bytes to ask for in each request.
- * @param arg Custom argument (passed as is to the callbacks).
- * @return Error code.
- * @retval EOK New fibril polling the device was already started.
- */
-int usb_device_auto_polling(usb_device_t *dev, size_t pipe_index,
-    const usb_device_auto_polling_t *polling,
-    size_t request_size)
-{
-	if ((dev == NULL) || (polling == NULL) || (polling->on_data == NULL)) {
-		return EBADMEM;
-	}
-
-	if (pipe_index >= dev->pipes_count || request_size == 0) {
-		return EINVAL;
-	}
-	if ((dev->pipes[pipe_index].pipe.transfer_type != USB_TRANSFER_INTERRUPT)
-	    || (dev->pipes[pipe_index].pipe.direction != USB_DIRECTION_IN)) {
-		return EINVAL;
-	}
-
-	polling_data_t *polling_data = malloc(sizeof(polling_data_t));
-	if (polling_data == NULL) {
-		return ENOMEM;
-	}
-
-	/* Fill-in the data. */
-	polling_data->buffer = malloc(sizeof(request_size));
-	if (polling_data->buffer == NULL) {
-		free(polling_data);
-		return ENOMEM;
-	}
-	polling_data->request_size = request_size;
-	polling_data->dev = dev;
-	polling_data->pipe_index = pipe_index;
-
-	/* Copy provided settings. */
-	polling_data->auto_polling = *polling;
-
-	/* Negative value means use descriptor provided value. */
-	if (polling->delay < 0) {
-		polling_data->auto_polling.delay =
-		    (int) dev->pipes[pipe_index].descriptor->poll_interval;
-	}
-
-	fid_t fibril = fibril_create(polling_fibril, polling_data);
-	if (fibril == 0) {
-		free(polling_data->buffer);
-		free(polling_data);
-		return ENOMEM;
-	}
-	fibril_add_ready(fibril);
-
-	/* Fibril launched. That fibril will free the allocated data. */
-
-	return EOK;
+	usb_endpoint_mapping_t *epm = usb_device_get_mapped_ep(dev, ep);
+	return usb_device_auto_polling_internal(
+	    dev, epm, &auto_polling, request_size);
+}
+
+int usb_device_auto_polling_desc(usb_device_t *usb_dev,
+    const usb_endpoint_description_t *desc,
+    const usb_device_auto_polling_t *polling, size_t req_size)
+{
+	usb_endpoint_mapping_t *epm =
+	    usb_device_get_mapped_ep_desc(usb_dev, desc);
+	return usb_device_auto_polling_internal(usb_dev, epm, polling, req_size);
+}
+
+int usb_device_auto_poll_desc(usb_device_t * usb_dev,
+    const usb_endpoint_description_t *desc, usb_polling_callback_t callback,
+    size_t req_size, int delay,
+    usb_polling_terminted_callback_t terminated_callback, void *arg)
+{
+	const usb_device_auto_polling_t auto_polling = {
+		.debug = 1,
+		.auto_clear_halt = true,
+		.delay = delay,
+		.max_failures = MAX_FAILED_ATTEMPTS,
+		.on_data = callback,
+		.on_polling_end = terminated_callback,
+		.on_error = NULL,
+		.arg = arg,
+	};
+
+	usb_endpoint_mapping_t *epm =
+	    usb_device_get_mapped_ep_desc(usb_dev, desc);
+	return usb_device_auto_polling_internal(
+	    usb_dev, epm, &auto_polling, req_size);
 }
 
Index: uspace/lib/usbdev/src/dp.c
===================================================================
--- uspace/lib/usbdev/src/dp.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbdev/src/dp.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -304,5 +304,5 @@
  * @param arg Custom (user) argument.
  */
-void usb_dp_walk_simple(uint8_t *descriptors, size_t descriptors_size,
+void usb_dp_walk_simple(const uint8_t *descriptors, size_t descriptors_size,
     const usb_dp_descriptor_nesting_t *descriptor_nesting,
     walk_callback_t callback, void *arg)
Index: uspace/lib/usbdev/src/driver.c
===================================================================
--- uspace/lib/usbdev/src/driver.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
+++ uspace/lib/usbdev/src/driver.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -0,0 +1,146 @@
+/*
+ * Copyright (c) 2011 Vojtech Horky
+ * Copyright (c) 2013 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/** @addtogroup libusbdev
+ * @{
+ */
+/** @file
+ * USB device driver framework.
+ */
+
+#include <usb/dev/driver.h>
+#include <errno.h>
+#include <str_error.h>
+#include <usb/debug.h>
+
+static const usb_driver_t *driver = NULL;
+
+/** Callback when a new device is supposed to be controlled by this driver.
+ *
+ * This callback is a wrapper for USB specific version of @c device_add.
+ *
+ * @param gen_dev Device structure as prepared by DDF.
+ * @return Error code.
+ */
+static int generic_device_add(ddf_dev_t *gen_dev)
+{
+	assert(driver);
+	assert(driver->ops);
+	assert(driver->ops->device_add);
+
+	/* Initialize generic USB driver data. */
+	const char *err_msg = NULL;
+	int rc = usb_device_create_ddf(gen_dev, driver->endpoints, &err_msg);
+	if (rc != EOK) {
+		usb_log_error("USB device `%s' init failed (%s): %s.\n",
+		    ddf_dev_get_name(gen_dev), err_msg, str_error(rc));
+		return rc;
+	}
+
+	/* Start USB driver specific initialization. */
+	rc = driver->ops->device_add(ddf_dev_data_get(gen_dev));
+	if (rc != EOK)
+		usb_device_destroy_ddf(gen_dev);
+	return rc;
+}
+
+/** Callback when a device is supposed to be removed from the system.
+ *
+ * This callback is a wrapper for USB specific version of @c device_remove.
+ *
+ * @param gen_dev Device structure as prepared by DDF.
+ * @return Error code.
+ */
+static int generic_device_remove(ddf_dev_t *gen_dev)
+{
+	assert(driver);
+	assert(driver->ops);
+	if (driver->ops->device_rem == NULL)
+		return ENOTSUP;
+	/* Just tell the driver to stop whatever it is doing */
+	usb_device_t *usb_dev = ddf_dev_data_get(gen_dev);
+	const int ret = driver->ops->device_rem(usb_dev);
+	if (ret != EOK)
+		return ret;
+	usb_device_destroy_ddf(gen_dev);
+	return EOK;
+}
+
+/** Callback when a device was removed from the system.
+ *
+ * This callback is a wrapper for USB specific version of @c device_gone.
+ *
+ * @param gen_dev Device structure as prepared by DDF.
+ * @return Error code.
+ */
+static int generic_device_gone(ddf_dev_t *gen_dev)
+{
+	assert(driver);
+	assert(driver->ops);
+	if (driver->ops->device_gone == NULL)
+		return ENOTSUP;
+	usb_device_t *usb_dev = ddf_dev_data_get(gen_dev);
+	const int ret = driver->ops->device_gone(usb_dev);
+	if (ret == EOK)
+		usb_device_destroy_ddf(gen_dev);
+
+	return ret;
+}
+
+static driver_ops_t generic_driver_ops = {
+	.dev_add = generic_device_add,
+	.dev_remove = generic_device_remove,
+	.dev_gone = generic_device_gone,
+};
+static driver_t generic_driver = {
+	.driver_ops = &generic_driver_ops
+};
+
+
+/** Main routine of USB device driver.
+ *
+ * Under normal conditions, this function never returns.
+ *
+ * @param drv USB device driver structure.
+ * @return Task exit status.
+ */
+int usb_driver_main(const usb_driver_t *drv)
+{
+	assert(drv != NULL);
+
+	/* Prepare the generic driver. */
+	generic_driver.name = drv->name;
+
+	driver = drv;
+
+	return ddf_driver_main(&generic_driver);
+}
+
+/**
+ * @}
+ */
Index: uspace/lib/usbdev/src/hub.c
===================================================================
--- uspace/lib/usbdev/src/hub.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ 	(revision )
@@ -1,333 +1,0 @@
-/*
- * Copyright (c) 2011 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 libusbdev
- * @{
- */
-/** @file
- * Functions needed by hub drivers.
- */
-
-#include <usb/dev/hub.h>
-#include <usb/dev/pipes.h>
-#include <usb/dev/request.h>
-#include <usb/dev/recognise.h>
-#include <usb/debug.h>
-#include <errno.h>
-#include <assert.h>
-#include <usb/debug.h>
-#include <time.h>
-#include <async.h>
-
-/** How much time to wait between attempts to get the default address.
- * The value is based on typical value for port reset + some overhead.
- */
-#define DEFAULT_ADDRESS_ATTEMPT_DELAY_USEC (1000 * (10 + 2))
-
-/** Inform host controller about new device.
- *
- * @param connection Opened connection to host controller.
- * @param attached_device Information about the new device.
- * @return Error code.
- */
-int usb_hub_register_device(usb_hc_connection_t *connection,
-    const usb_hub_attached_device_t *attached_device)
-{
-	assert(connection);
-	if (attached_device == NULL || attached_device->fun == NULL)
-		return EBADMEM;
-	return usb_hc_bind_address(connection,
-	    attached_device->address, ddf_fun_get_handle(attached_device->fun));
-}
-
-/** Change address of connected device.
- * This function automatically updates the backing connection to point to
- * the new address. It also unregisterrs the old endpoint and registers
- * a new one.
- * This creates whole bunch of problems:
- *  1. All pipes using this wire are broken because they are not
- *     registered for new address
- *  2. All other pipes for this device are using wrong address,
- *     possibly targeting completely different device
- *
- * @param pipe Control endpoint pipe (session must be already started).
- * @param new_address New USB address to be set (in native endianness).
- * @return Error code.
- */
-static int usb_request_set_address(usb_pipe_t *pipe, usb_address_t new_address)
-{
-	if ((new_address < 0) || (new_address >= USB11_ADDRESS_MAX)) {
-		return EINVAL;
-	}
-	assert(pipe);
-	assert(pipe->wire != NULL);
-
-	const uint16_t addr = uint16_host2usb((uint16_t)new_address);
-
-	int rc = usb_control_request_set(pipe,
-	    USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE,
-	    USB_DEVREQ_SET_ADDRESS, addr, 0, NULL, 0);
-
-	if (rc != EOK) {
-		return rc;
-	}
-
-	/* TODO: prevent others from accessing the wire now. */
-	if (usb_pipe_unregister(pipe) != EOK) {
-		usb_log_warning(
-		    "Failed to unregister the old pipe on address change.\n");
-	}
-	/* Address changed. We can release the old one, thus
-	 * allowing other to us it. */
-	usb_hc_release_address(pipe->wire->hc_connection, pipe->wire->address);
-
-	/* The address is already changed so set it in the wire */
-	pipe->wire->address = new_address;
-	rc = usb_pipe_register(pipe, 0);
-	if (rc != EOK)
-		return EADDRNOTAVAIL;
-
-	return EOK;
-}
-
-/** Wrapper for registering attached device to the hub.
- *
- * The @p enable_port function is expected to enable signaling on given
- * port.
- * The argument can have arbitrary meaning and it is not touched at all
- * by this function (it is passed as is to the @p enable_port function).
- *
- * If the @p enable_port fails (i.e. does not return EOK), the device
- * addition is canceled.
- * The return value is then returned (it is good idea to use different
- * error codes than those listed as return codes by this function itself).
- *
- * The @p connection representing connection with host controller does not
- * need to be started.
- * This function duplicates the connection to allow simultaneous calls of
- * this function (i.e. from different fibrils).
- *
- * @param[in] parent Parent device (i.e. the hub device).
- * @param[in] connection Connection to host controller. Must be non-null.
- * @param[in] dev_speed New device speed.
- * @param[in] enable_port Function for enabling signaling through the port the
- *	device is attached to.
- * @param[in] arg Any data argument to @p enable_port.
- * @param[out] assigned_address USB address of the device.
- * @param[in] dev_ops Child device ops. Will use default if not provided.
- * @param[in] new_dev_data Arbitrary pointer to be stored in the child
- *	as @c driver_data. Will allocate and assign usb_hub_attached_device_t
- *	structure if NULL.
- * @param[out] new_fun Storage where pointer to allocated child function
- *	will be written. Must be non-null.
- * @return Error code.
- * @retval EINVAL Either connection or new_fun is a NULL pointer.
- * @retval ENOENT Connection to HC not opened.
- * @retval EADDRNOTAVAIL Failed retrieving free address from host controller.
- * @retval EBUSY Failed reserving default USB address.
- * @retval ENOTCONN Problem connecting to the host controller via USB pipe.
- * @retval ESTALL Problem communication with device (either SET_ADDRESS
- *	request or requests for descriptors when creating match ids).
- */
-int usb_hc_new_device_wrapper(ddf_dev_t *parent,
-    usb_hc_connection_t *hc_conn, usb_speed_t dev_speed,
-    int (*enable_port)(void *arg), void *arg, usb_address_t *assigned_address,
-    ddf_dev_ops_t *dev_ops, void *new_dev_data, ddf_fun_t **new_fun)
-{
-	if ((new_fun == NULL) || (hc_conn == NULL))
-		return EINVAL;
-
-	int rc;
-	struct timeval start_time;
-
-	rc = gettimeofday(&start_time, NULL);
-	if (rc != EOK) {
-		return rc;
-	}
-
-	/* We are gona do a lot of communication better open it in advance. */
-	rc = usb_hc_connection_open(hc_conn);
-	if (rc != EOK) {
-		return rc;
-	}
-
-	/* Request a new address. */
-	usb_address_t dev_addr =
-	    usb_hc_request_address(hc_conn, 0, false, dev_speed);
-	if (dev_addr < 0) {
-		rc = EADDRNOTAVAIL;
-		goto close_connection;
-	}
-
-	/* Initialize connection to device. */
-	usb_device_connection_t dev_conn;
-	rc = usb_device_connection_initialize(
-	    &dev_conn, hc_conn, USB_ADDRESS_DEFAULT);
-	if (rc != EOK) {
-		rc = ENOTCONN;
-		goto leave_release_free_address;
-	}
-
-	/* Initialize control pipe on default address. Don't register yet. */
-	usb_pipe_t ctrl_pipe;
-	rc = usb_pipe_initialize_default_control(&ctrl_pipe, &dev_conn);
-	if (rc != EOK) {
-		rc = ENOTCONN;
-		goto leave_release_free_address;
-	}
-
-	/*
-	 * The default address request might fail.
-	 * That means that someone else is already using that address.
-	 * We will simply wait and try again.
-	 * (Someone else already wants to add a new device.)
-	 */
-	do {
-		rc = usb_hc_request_address(hc_conn, USB_ADDRESS_DEFAULT,
-		    true, dev_speed);
-		if (rc == ENOENT) {
-			/* Do not overheat the CPU ;-). */
-			async_usleep(DEFAULT_ADDRESS_ATTEMPT_DELAY_USEC);
-		}
-	} while (rc == ENOENT);
-	if (rc < 0) {
-		goto leave_release_free_address;
-	}
-
-	/* Register control pipe on default address. 0 means no interval. */
-	rc = usb_pipe_register(&ctrl_pipe, 0);
-	if (rc != EOK) {
-		rc = ENOTCONN;
-		goto leave_release_default_address;
-	}
-
-	struct timeval end_time;
-	rc = gettimeofday(&end_time, NULL);
-	if (rc != EOK) {
-		goto leave_release_default_address;
-	}
-
-	/* According to the USB spec part 9.1.2 host allows 100ms time for
-	 * the insertion process to complete. According to 7.1.7.1 this is the
-	 * time between attach detected and port reset. However, the setup done
-	 * above might use much of this time so we should only wait to fill
-	 * up the 100ms quota*/
-	const suseconds_t elapsed = tv_sub(&end_time, &start_time);
-	if (elapsed < 100000) {
-		async_usleep(100000 - elapsed);
-	}
-
-	/* Endpoint is registered. We can enable the port and change address. */
-	rc = enable_port(arg);
-	if (rc != EOK) {
-		goto leave_release_default_address;
-	}
-	/* USB spec 7.1.7.1: The USB System Software guarantees a minimum of
-	 * 10ms for reset recovery. Device response to any bus transactions
-	 * addressed to the default device address during the reset recovery
-	 * time is undefined.
-	 */
-	async_usleep(10000);
-
-	/* Get max_packet_size value. */
-	rc = usb_pipe_probe_default_control(&ctrl_pipe);
-	if (rc != EOK) {
-		rc = ESTALL;
-		goto leave_release_default_address;
-	}
-
-	rc = usb_request_set_address(&ctrl_pipe, dev_addr);
-	if (rc != EOK) {
-		rc = ESTALL;
-		goto leave_release_default_address;
-	}
-
-
-	/* Register the device with devman. */
-	/* FIXME: create device_register that will get opened ctrl pipe. */
-	ddf_fun_t *child_fun;
-	rc = usb_device_register_child_in_devman(&ctrl_pipe,
-	    parent, dev_ops, new_dev_data, &child_fun);
-	if (rc != EOK) {
-		goto leave_release_free_address;
-	}
-
-	const usb_hub_attached_device_t new_device = {
-		.address = dev_addr,
-		.fun = child_fun,
-	};
-
-
-	/* Inform the host controller about the handle. */
-	rc = usb_hub_register_device(hc_conn, &new_device);
-	if (rc != EOK) {
-		/* The child function is already created. */
-		ddf_fun_destroy(child_fun);
-		rc = EDESTADDRREQ;
-		goto leave_release_free_address;
-	}
-
-	if (assigned_address != NULL) {
-		*assigned_address = dev_addr;
-	}
-
-	*new_fun = child_fun;
-
-	rc = EOK;
-	goto close_connection;
-
-	/*
-	 * Error handling (like nested exceptions) starts here.
-	 * Completely ignoring errors here.
-	 */
-leave_release_default_address:
-	if (usb_hc_release_address(hc_conn, USB_ADDRESS_DEFAULT) != EOK)
-		usb_log_warning("%s: Failed to release defaut address.\n",
-		    __FUNCTION__);
-
-leave_release_free_address:
-	/* This might be either 0:0 or dev_addr:0 */
-	if (usb_pipe_unregister(&ctrl_pipe) != EOK)
-		usb_log_warning("%s: Failed to unregister default pipe.\n",
-		    __FUNCTION__);
-
-	if (usb_hc_release_address(hc_conn, dev_addr) != EOK)
-		usb_log_warning("%s: Failed to release address: %d.\n",
-		    __FUNCTION__, dev_addr);
-
-close_connection:
-	if (usb_hc_connection_close(hc_conn) != EOK)
-		usb_log_warning("%s: Failed to close hc connection.\n",
-		    __FUNCTION__);
-
-	return rc;
-}
-
-/**
- * @}
- */
Index: uspace/lib/usbdev/src/pipes.c
===================================================================
--- uspace/lib/usbdev/src/pipes.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbdev/src/pipes.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -38,34 +38,4 @@
 #include <assert.h>
 
-/** Prepare pipe for a long transfer.
- *
- * Long transfer is transfer consisting of several requests to the HC.
- * Calling this function is optional and it has positive effect of
- * improved performance because IPC session is initiated only once.
- *
- * @param pipe Pipe over which the transfer will happen.
- * @return Error code.
- */
-int usb_pipe_start_long_transfer(usb_pipe_t *pipe)
-{
-	assert(pipe);
-	assert(pipe->wire);
-	assert(pipe->wire->hc_connection);
-	return usb_hc_connection_open(pipe->wire->hc_connection);
-}
-
-/** Terminate a long transfer on a pipe.
- * @param pipe Pipe where to end the long transfer.
- * @return Error code.
- * @see usb_pipe_start_long_transfer
- */
-int usb_pipe_end_long_transfer(usb_pipe_t *pipe)
-{
-	assert(pipe);
-	assert(pipe->wire);
-	assert(pipe->wire->hc_connection);
-	return usb_hc_connection_close(pipe->wire->hc_connection);
-}
-
 /** Try to clear endpoint halt of default control pipe.
  *
@@ -121,7 +91,9 @@
 	memcpy(&setup_packet, setup_buffer, 8);
 
+	async_exch_t *exch = async_exchange_begin(pipe->bus_session);
 	size_t act_size = 0;
-	const int rc = usb_device_control_read(pipe->wire,
+	const int rc = usb_read(exch,
 	    pipe->endpoint_no, setup_packet, buffer, buffer_size, &act_size);
+	async_exchange_end(exch);
 
 	if (rc == ESTALL) {
@@ -173,6 +145,8 @@
 	memcpy(&setup_packet, setup_buffer, 8);
 
-	const int rc = usb_device_control_write(pipe->wire,
+	async_exch_t *exch = async_exchange_begin(pipe->bus_session);
+	const int rc = usb_write(exch,
 	    pipe->endpoint_no, setup_packet, buffer, buffer_size);
+	async_exchange_end(exch);
 
 	if (rc == ESTALL) {
@@ -217,7 +191,9 @@
 	    return ENOTSUP;
 
+	async_exch_t *exch = async_exchange_begin(pipe->bus_session);
 	size_t act_size = 0;
-	const int rc = usb_device_read(pipe->wire,
-	    pipe->endpoint_no, buffer, size, &act_size);
+	const int rc =
+	    usb_read(exch, pipe->endpoint_no, 0, buffer, size, &act_size);
+	async_exchange_end(exch);
 
 	if (rc == EOK && size_transfered != NULL) {
@@ -256,6 +232,8 @@
 	    return ENOTSUP;
 
-	return usb_device_write(pipe->wire,
-	    pipe->endpoint_no, buffer, size);
+	async_exch_t *exch = async_exchange_begin(pipe->bus_session);
+	const int rc = usb_write(exch, pipe->endpoint_no, 0, buffer, size);
+	async_exchange_end(exch);
+	return rc;
 }
 
@@ -263,5 +241,4 @@
  *
  * @param pipe Endpoint pipe to be initialized.
- * @param connection Connection to the USB device backing this pipe (the wire).
  * @param endpoint_no Endpoint number (in USB 1.1 in range 0 to 15).
  * @param transfer_type Transfer type (e.g. interrupt or bulk).
@@ -270,13 +247,10 @@
  * @return Error code.
  */
-int usb_pipe_initialize(usb_pipe_t *pipe,
-    usb_device_connection_t *connection, usb_endpoint_t endpoint_no,
+int usb_pipe_initialize(usb_pipe_t *pipe, usb_endpoint_t endpoint_no,
     usb_transfer_type_t transfer_type, size_t max_packet_size,
-    usb_direction_t direction)
-{
-	assert(pipe);
-	assert(connection);
-
-	pipe->wire = connection;
+    usb_direction_t direction, usb_dev_session_t *bus_session)
+{
+	assert(pipe);
+
 	pipe->endpoint_no = endpoint_no;
 	pipe->transfer_type = transfer_type;
@@ -284,4 +258,5 @@
 	pipe->direction = direction;
 	pipe->auto_reset_halt = false;
+	pipe->bus_session = bus_session;
 
 	return EOK;
@@ -291,15 +266,13 @@
  *
  * @param pipe Endpoint pipe to be initialized.
- * @param connection Connection to the USB device backing this pipe (the wire).
  * @return Error code.
  */
 int usb_pipe_initialize_default_control(usb_pipe_t *pipe,
-    usb_device_connection_t *connection)
-{
-	assert(pipe);
-	assert(connection);
-
-	int rc = usb_pipe_initialize(pipe, connection, 0, USB_TRANSFER_CONTROL,
-	    CTRL_PIPE_MIN_PACKET_SIZE, USB_DIRECTION_BOTH);
+    usb_dev_session_t *bus_session)
+{
+	assert(pipe);
+
+	const int rc = usb_pipe_initialize(pipe, 0, USB_TRANSFER_CONTROL,
+	    CTRL_PIPE_MIN_PACKET_SIZE, USB_DIRECTION_BOTH, bus_session);
 
 	pipe->auto_reset_halt = true;
@@ -317,9 +290,13 @@
 {
 	assert(pipe);
-	assert(pipe->wire);
-
-	return usb_device_register_endpoint(pipe->wire,
-	   pipe->endpoint_no, pipe->transfer_type,
-	   pipe->direction, pipe->max_packet_size, interval);
+	assert(pipe->bus_session);
+	async_exch_t *exch = async_exchange_begin(pipe->bus_session);
+	if (!exch)
+		return ENOMEM;
+	const int ret = usb_register_endpoint(exch, pipe->endpoint_no,
+	    pipe->transfer_type, pipe->direction, pipe->max_packet_size,
+	    interval);
+	async_exchange_end(exch);
+	return ret;
 }
 
@@ -332,8 +309,12 @@
 {
 	assert(pipe);
-	assert(pipe->wire);
-
-	return usb_device_unregister_endpoint(pipe->wire,
-	    pipe->endpoint_no, pipe->direction);
+	assert(pipe->bus_session);
+	async_exch_t *exch = async_exchange_begin(pipe->bus_session);
+	if (!exch)
+		return ENOMEM;
+	const int ret = usb_unregister_endpoint(exch, pipe->endpoint_no,
+	    pipe->direction);
+	async_exchange_end(exch);
+	return ret;
 }
 
Index: uspace/lib/usbdev/src/pipesinit.c
===================================================================
--- uspace/lib/usbdev/src/pipesinit.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbdev/src/pipesinit.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -148,5 +148,4 @@
  * @param interface Interface descriptor under which belongs the @p endpoint.
  * @param endpoint Endpoint descriptor.
- * @param wire Connection backing the endpoint pipes.
  * @return Error code.
  */
@@ -155,5 +154,5 @@
     usb_standard_interface_descriptor_t *interface,
     usb_standard_endpoint_descriptor_t *endpoint_desc,
-    usb_device_connection_t *wire)
+    usb_dev_session_t *bus_session)
 {
 
@@ -193,8 +192,8 @@
 	}
 
-	int rc = usb_pipe_initialize(&ep_mapping->pipe, wire,
+	int rc = usb_pipe_initialize(&ep_mapping->pipe,
 	    ep_no, description.transfer_type,
 	    uint16_usb2host(endpoint_desc->max_packet_size),
-	    description.direction);
+	    description.direction, bus_session);
 	if (rc != EOK) {
 		return rc;
@@ -220,5 +219,5 @@
     usb_endpoint_mapping_t *mapping, size_t mapping_count,
     const usb_dp_parser_t *parser, const usb_dp_parser_data_t *parser_data,
-    const uint8_t *interface_descriptor)
+    const uint8_t *interface_descriptor, usb_dev_session_t *bus_session)
 {
 	const uint8_t *descriptor = usb_dp_get_nested_descriptor(parser,
@@ -236,5 +235,5 @@
 			    (usb_standard_endpoint_descriptor_t *)
 			        descriptor,
-			    (usb_device_connection_t *) parser_data->arg);
+			    bus_session);
 		}
 
@@ -280,7 +279,6 @@
     usb_endpoint_mapping_t *mapping, size_t mapping_count,
     const uint8_t *config_descriptor, size_t config_descriptor_size,
-    usb_device_connection_t *connection)
-{
-	assert(connection);
+    usb_dev_session_t *bus_session)
+{
 
 	if (config_descriptor == NULL) {
@@ -306,5 +304,4 @@
 		.data = config_descriptor,
 		.size = config_descriptor_size,
-		.arg = connection
 	};
 
@@ -319,5 +316,5 @@
 	do {
 		(void) process_interface(mapping, mapping_count,
-		    &dp_parser, &dp_data, interface);
+		    &dp_parser, &dp_data, interface, bus_session);
 		interface = usb_dp_get_sibling_descriptor(&dp_parser, &dp_data,
 		    config_descriptor, interface);
@@ -347,7 +344,4 @@
 		return EINVAL;
 	}
-
-
-	usb_pipe_start_long_transfer(pipe);
 
 	uint8_t dev_descr_start[CTRL_PIPE_MIN_PACKET_SIZE];
@@ -367,5 +361,4 @@
 		}
 	}
-	usb_pipe_end_long_transfer(pipe);
 	if (rc != EOK) {
 		return rc;
Index: uspace/lib/usbdev/src/recognise.c
===================================================================
--- uspace/lib/usbdev/src/recognise.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbdev/src/recognise.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -34,14 +34,9 @@
  */
 
-/** XXX Fix this */
-#define _DDF_DATA_IMPLANT
-
 #include <sys/types.h>
 #include <fibril_synch.h>
 #include <usb/debug.h>
-#include <usb/dev/hub.h>
 #include <usb/dev/pipes.h>
 #include <usb/dev/recognise.h>
-#include <usb/ddfiface.h>
 #include <usb/dev/request.h>
 #include <usb/classes/classes.h>
@@ -49,9 +44,4 @@
 #include <errno.h>
 #include <assert.h>
-
-/** DDF operations of child devices. */
-static ddf_dev_ops_t child_ops = {
-	.interfaces[USB_DEV_IFACE] = &usb_iface_hub_child_impl
-};
 
 /** Get integer part from BCD coded number. */
@@ -253,14 +243,7 @@
 	}	
 
-	/*
-	 * If the device class points to interface we skip adding
-	 * class directly but we add a multi interface device.
-	 */
-	if (device_descriptor->device_class != USB_CLASS_USE_INTERFACE) {
-		ADD_MATCHID_OR_RETURN(matches, 50, "usb&class=%s",
-		    usb_str_class(device_descriptor->device_class));
-	} else {
-		ADD_MATCHID_OR_RETURN(matches, 50, "usb&mid");
-	}
+	/* Class match id */
+	ADD_MATCHID_OR_RETURN(matches, 50, "usb&class=%s",
+	    usb_str_class(device_descriptor->device_class));
 	
 	/* As a last resort, try fallback driver. */
@@ -305,108 +288,4 @@
 }
 
-/** Probe for device kind and register it in devman.
- *
- * @param[in] ctrl_pipe Control pipe to the device.
- * @param[in] parent Parent device.
- * @param[in] dev_ops Child device ops. Default child_ops will be used if NULL.
- * @param[in] dev_data Arbitrary pointer to be stored in the child
- *	as @c driver_data.
- * @param[out] child_fun Storage where pointer to allocated child function
- *	will be written.
- * @return Error code.
- *
- */
-int usb_device_register_child_in_devman(usb_pipe_t *ctrl_pipe,
-    ddf_dev_t *parent, ddf_dev_ops_t *dev_ops, void *dev_data,
-    ddf_fun_t **child_fun)
-{
-	if (child_fun == NULL || ctrl_pipe == NULL)
-		return EINVAL;
-	
-	if (!dev_ops && dev_data) {
-		usb_log_warning("Using standard fun ops with arbitrary "
-		    "driver data. This does not have to work.\n");
-	}
-	
-	/** Index to append after device name for uniqueness. */
-	static atomic_t device_name_index = {0};
-	const size_t this_device_name_index =
-	    (size_t) atomic_preinc(&device_name_index);
-	
-	ddf_fun_t *child = NULL;
-	int rc;
-	
-	/*
-	 * TODO: Once the device driver framework support persistent
-	 * naming etc., something more descriptive could be created.
-	 */
-	char child_name[12];  /* The format is: "usbAB_aXYZ", length 11 */
-	rc = snprintf(child_name, sizeof(child_name),
-	    "usb%02zu_a%d", this_device_name_index, ctrl_pipe->wire->address);
-	if (rc < 0) {
-		goto failure;
-	}
-	
-	child = ddf_fun_create(parent, fun_inner, child_name);
-	if (child == NULL) {
-		rc = ENOMEM;
-		goto failure;
-	}
-	
-	if (dev_ops != NULL)
-		ddf_fun_set_ops(child, dev_ops);
-	else
-		ddf_fun_set_ops(child, &child_ops);
-	
-	ddf_fun_data_implant(child, dev_data);
-	
-	/*
-	 * Store the attached device in fun
-	 * driver data if there is no other data
-	 */
-	if (!dev_data) {
-		usb_hub_attached_device_t *new_device = ddf_fun_data_alloc(
-		    child, sizeof(usb_hub_attached_device_t));
-		if (!new_device) {
-			rc = ENOMEM;
-			goto failure;
-		}
-		
-		new_device->address = ctrl_pipe->wire->address;
-		new_device->fun = child;
-	}
-	
-	match_id_list_t match_ids;
-	init_match_ids(&match_ids);
-	rc = usb_device_create_match_ids(ctrl_pipe, &match_ids);
-	if (rc != EOK)
-		goto failure;
-	
-	list_foreach(match_ids.ids, link, match_id_t, match_id) {
-		rc = ddf_fun_add_match_id(child, match_id->id, match_id->score);
-		if (rc != EOK) {
-			clean_match_ids(&match_ids);
-			goto failure;
-		}
-	}
-	
-	clean_match_ids(&match_ids);
-	
-	rc = ddf_fun_bind(child);
-	if (rc != EOK)
-		goto failure;
-	
-	*child_fun = child;
-	return EOK;
-	
-failure:
-	if (child != NULL) {
-		/* This takes care of match_id deallocation as well. */
-		ddf_fun_destroy(child);
-	}
-	
-	return rc;
-}
-
 /**
  * @}
Index: uspace/lib/usbdev/src/request.c
===================================================================
--- uspace/lib/usbdev/src/request.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbdev/src/request.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -49,9 +49,9 @@
  * @param request Actual request (e.g. GET_DESCRIPTOR).
  * @param value Value of @c wValue field of setup packet
- * 	(must be in USB endianness).
+ *	(must be in USB endianness).
  * @param index Value of @c wIndex field of setup packet
- * 	(must be in USB endianness).
+ *	(must be in USB endianness).
  * @param data Data to be sent during DATA stage
- * 	(expected to be in USB endianness).
+ *	(expected to be in USB endianness).
  * @param data_size Size of the @p data buffer (in native endianness).
  * @return Error code.
@@ -62,7 +62,6 @@
 int usb_control_request_set(usb_pipe_t *pipe,
     usb_request_type_t request_type, usb_request_recipient_t recipient,
-    uint8_t request,
-    uint16_t value, uint16_t index,
-    void *data, size_t data_size)
+    uint8_t request, uint16_t value, uint16_t index,
+    const void *data, size_t data_size)
 {
 	if (pipe == NULL) {
@@ -83,16 +82,14 @@
 	 */
 
-	usb_device_request_setup_packet_t setup_packet;
-	setup_packet.request_type = (request_type << 5) | recipient;
-	setup_packet.request = request;
-	setup_packet.value = value;
-	setup_packet.index = index;
-	setup_packet.length = (uint16_t) data_size;
-
-	int rc = usb_pipe_control_write(pipe,
-	    &setup_packet, sizeof(setup_packet),
-	    data, data_size);
-
-	return rc;
+	const usb_device_request_setup_packet_t setup_packet = {
+		.request_type = (request_type << 5) | recipient,
+		.request = request,
+		.value = value,
+		.index = index,
+		.length = (uint16_t) data_size,
+	};
+
+	return usb_pipe_control_write(pipe,
+	    &setup_packet, sizeof(setup_packet), data, data_size);
 }
 
@@ -106,5 +103,5 @@
   * @param request Actual request (e.g. GET_DESCRIPTOR).
   * @param value Value of @c wValue field of setup packet
-  * 	(must be in USB endianness).
+  *	(must be in USB endianness).
   * @param index Value of @c wIndex field of setup packet
   *	(must be in USB endianness).
@@ -112,7 +109,7 @@
   *	(they will come in USB endianness).
   * @param data_size Size of the @p data buffer
-  * 	(in native endianness).
+  *	(in native endianness).
   * @param actual_data_size Actual size of transfered data
-  *        (in native endianness).
+  *	(in native endianness).
   * @return Error code.
   * @retval EBADMEM @p pipe is NULL.
@@ -122,6 +119,5 @@
 int usb_control_request_get(usb_pipe_t *pipe,
     usb_request_type_t request_type, usb_request_recipient_t recipient,
-    uint8_t request,
-    uint16_t value, uint16_t index,
+    uint8_t request, uint16_t value, uint16_t index,
     void *data, size_t data_size, size_t *actual_data_size)
 {
@@ -207,16 +203,13 @@
 {
 	if (request_type == USB_REQUEST_TYPE_STANDARD) {
-		if ((recipient == USB_REQUEST_RECIPIENT_DEVICE)
-		    && (index != 0)) {
+		if ((recipient == USB_REQUEST_RECIPIENT_DEVICE) && (index != 0))
+		{
 			return EINVAL;
 		}
 	}
 
-	int rc = usb_control_request_set(pipe, request_type, recipient,
-	    USB_DEVREQ_CLEAR_FEATURE,
-	    uint16_host2usb(feature_selector), uint16_host2usb(index),
-	    NULL, 0);
-
-	return rc;
+	return usb_control_request_set(pipe,
+	    request_type, recipient, USB_DEVREQ_CLEAR_FEATURE,
+	    uint16_host2usb(feature_selector), uint16_host2usb(index), NULL, 0);
 }
 
@@ -235,16 +228,13 @@
 {
 	if (request_type == USB_REQUEST_TYPE_STANDARD) {
-		if ((recipient == USB_REQUEST_RECIPIENT_DEVICE)
-		    && (index != 0)) {
+		if ((recipient == USB_REQUEST_RECIPIENT_DEVICE) && (index != 0))
+		{
 			return EINVAL;
 		}
 	}
 
-	int rc = usb_control_request_set(pipe, request_type, recipient,
-	    USB_DEVREQ_SET_FEATURE,
-	    uint16_host2usb(feature_selector), uint16_host2usb(index),
-	    NULL, 0);
-
-	return rc;
+	return usb_control_request_set(pipe,
+	    request_type, recipient, USB_DEVREQ_SET_FEATURE,
+	    uint16_host2usb(feature_selector), uint16_host2usb(index), NULL, 0);
 }
 
@@ -275,4 +265,7 @@
 	}
 
+	/* The wValue field specifies the descriptor type in the high byte
+	 * and the descriptor index in the low byte. USB 1.1 spec p. 189
+	 */
 	const uint16_t wValue = descriptor_index | (descriptor_type << 8);
 
@@ -311,21 +304,19 @@
 	 * Get only first byte to retrieve descriptor length.
 	 */
-	uint8_t tmp_buffer[1];
+	uint8_t tmp_buffer;
 	size_t bytes_transfered;
 	rc = usb_request_get_descriptor(pipe, request_type, recipient,
 	    descriptor_type, descriptor_index, language,
-	    &tmp_buffer, 1, &bytes_transfered);
+	    &tmp_buffer, sizeof(tmp_buffer), &bytes_transfered);
 	if (rc != EOK) {
 		return rc;
 	}
 	if (bytes_transfered != 1) {
-		/* FIXME: some better error code? */
-		return ESTALL;
-	}
-
-	size_t size = tmp_buffer[0];
+		return ELIMIT;
+	}
+
+	const size_t size = tmp_buffer;
 	if (size == 0) {
-		/* FIXME: some better error code? */
-		return ESTALL;
+		return ELIMIT;
 	}
 
@@ -347,6 +338,5 @@
 	if (bytes_transfered != size) {
 		free(buffer);
-		/* FIXME: some better error code? */
-		return ESTALL;
+		return ELIMIT;
 	}
 
@@ -376,6 +366,5 @@
 	int rc = usb_request_get_descriptor(pipe,
 	    USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE,
-	    USB_DESCTYPE_DEVICE, 0, 0,
-	    &descriptor_tmp, sizeof(descriptor_tmp),
+	    USB_DESCTYPE_DEVICE, 0, 0, &descriptor_tmp, sizeof(descriptor_tmp),
 	    &actually_transferred);
 
@@ -419,5 +408,5 @@
 	size_t actually_transferred = 0;
 	usb_standard_configuration_descriptor_t descriptor_tmp;
-	int rc = usb_request_get_descriptor(pipe,
+	const int rc = usb_request_get_descriptor(pipe,
 	    USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE,
 	    USB_DESCTYPE_CONFIGURATION, index, 0,
@@ -477,5 +466,5 @@
 int usb_request_get_full_configuration_descriptor_alloc(
     usb_pipe_t *pipe, int index,
-    void **descriptor_ptr, size_t *descriptor_size)
+    const void **descriptor_ptr, size_t *descriptor_size)
 {
 	int rc;
@@ -544,6 +533,5 @@
     usb_request_type_t request_type, usb_request_recipient_t recipient,
     uint8_t descriptor_type, uint8_t descriptor_index,
-    uint16_t language,
-    void *buffer, size_t size)
+    uint16_t language, const void *buffer, size_t size)
 {
 	if (buffer == NULL) {
@@ -558,8 +546,6 @@
 
 	return usb_control_request_set(pipe,
-	    request_type, recipient,
-	    USB_DEVREQ_SET_DESCRIPTOR,
-	    wValue, language,
-	    buffer, size);
+	    request_type, recipient, USB_DEVREQ_SET_DESCRIPTOR,
+	    wValue, language, buffer, size);
 }
 
@@ -576,9 +562,7 @@
 	size_t actual_size;
 
-	int rc = usb_control_request_get(pipe,
+	const int rc = usb_control_request_get(pipe,
 	    USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE,
-	    USB_DEVREQ_GET_CONFIGURATION,
-	    0, 0,
-	    &value, 1, &actual_size);
+	    USB_DEVREQ_GET_CONFIGURATION, 0, 0, &value, 1, &actual_size);
 
 	if (rc != EOK) {
@@ -605,5 +589,5 @@
     uint8_t configuration_value)
 {
-	uint16_t config_value
+	const uint16_t config_value
 	    = uint16_host2usb((uint16_t) configuration_value);
 
@@ -627,9 +611,9 @@
 	size_t actual_size;
 
-	int rc = usb_control_request_get(pipe,
+	const int rc = usb_control_request_get(pipe,
 	    USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_INTERFACE,
 	    USB_DEVREQ_GET_INTERFACE,
 	    0, uint16_host2usb((uint16_t) interface_index),
-	    &value, 1, &actual_size);
+	    &value, sizeof(value), &actual_size);
 
 	if (rc != EOK) {
@@ -676,10 +660,5 @@
     l18_win_locales_t **languages_ptr, size_t *languages_count)
 {
-	int rc;
-
-	if (languages_ptr == NULL) {
-		return EBADMEM;
-	}
-	if (languages_count == NULL) {
+	if (languages_ptr == NULL || languages_count == NULL) {
 		return EBADMEM;
 	}
@@ -687,5 +666,5 @@
 	uint8_t *string_descriptor = NULL;
 	size_t string_descriptor_size = 0;
-	rc = usb_request_get_descriptor_alloc(pipe,
+	const int rc = usb_request_get_descriptor_alloc(pipe,
 	    USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE,
 	    USB_DESCTYPE_STRING, 0, 0,
@@ -708,7 +687,7 @@
 	}
 
-	size_t langs_count = string_descriptor_size / 2;
-	l18_win_locales_t *langs
-	    = malloc(sizeof(l18_win_locales_t) * langs_count);
+	const size_t langs_count = string_descriptor_size / 2;
+	l18_win_locales_t *langs =
+	    calloc(langs_count, sizeof(l18_win_locales_t));
 	if (langs == NULL) {
 		free(string_descriptor);
@@ -716,9 +695,9 @@
 	}
 
-	size_t i;
-	for (i = 0; i < langs_count; i++) {
+	for (size_t i = 0; i < langs_count; i++) {
 		/* Language code from the descriptor is in USB endianness. */
 		/* FIXME: is this really correct? */
-		uint16_t lang_code = (string_descriptor[2 + 2 * i + 1] << 8)
+		const uint16_t lang_code =
+		    (string_descriptor[2 + 2 * i + 1] << 8)
 		    + string_descriptor[2 + 2 * i];
 		langs[i] = uint16_usb2host(lang_code);
@@ -759,5 +738,5 @@
 	}
 	/* Language is actually two byte value. */
-	if (lang > 0xFFFF) {
+	if (lang > L18N_WIN_LOCALE_MAX) {
 		return ERANGE;
 	}
@@ -793,5 +772,5 @@
 	}
 
-	size_t string_char_count = string_size / 2;
+	const size_t string_char_count = string_size / 2;
 	string_chars = malloc(sizeof(wchar_t) * (string_char_count + 1));
 	if (string_chars == NULL) {
@@ -805,7 +784,6 @@
 	 * do not have them).
 	 */
-	size_t i;
-	for (i = 0; i < string_char_count; i++) {
-		uint16_t uni_char = (string[2 + 2 * i + 1] << 8)
+	for (size_t i = 0; i < string_char_count; i++) {
+		const uint16_t uni_char = (string[2 + 2 * i + 1] << 8)
 		    + string[2 + 2 * i];
 		string_chars[i] = uni_char;
@@ -825,10 +803,6 @@
 
 leave:
-	if (string != NULL) {
-		free(string);
-	}
-	if (string_chars != NULL) {
-		free(string_chars);
-	}
+	free(string);
+	free(string_chars);
 
 	return rc;
Index: uspace/lib/usbhid/src/hidreport.c
===================================================================
--- uspace/lib/usbhid/src/hidreport.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbhid/src/hidreport.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -61,6 +61,6 @@
 	
 	usb_dp_parser_data_t parser_data = {
-		.data = dev->descriptors.configuration,
-		.size = dev->descriptors.configuration_size,
+		.data = usb_device_descriptors(dev)->full_config,
+		.size = usb_device_descriptors(dev)->full_config_size,
 		.arg = NULL
 	};
@@ -71,5 +71,5 @@
 	const uint8_t *d =
 	    usb_dp_get_nested_descriptor(&parser, &parser_data,
-	    dev->descriptors.configuration);
+	        usb_device_descriptors(dev)->full_config);
 	
 	/*
@@ -77,7 +77,7 @@
 	 */
 	int i = 0;
-	while (d != NULL && i < dev->interface_no) {
+	while (d != NULL && i < usb_device_get_iface_number(dev)) {
 		d = usb_dp_get_sibling_descriptor(&parser, &parser_data,
-		    dev->descriptors.configuration, d);
+		    usb_device_descriptors(dev)->full_config, d);
 		++i;
 	}
@@ -85,5 +85,5 @@
 	if (d == NULL) {
 		usb_log_error("The %d. interface descriptor not found!\n",
-		    dev->interface_no);
+		    usb_device_get_iface_number(dev));
 		return ENOENT;
 	}
@@ -135,7 +135,7 @@
 	 * Get the descriptor from the device.
 	 */
-	int rc = usb_request_get_descriptor(&dev->ctrl_pipe,
+	int rc = usb_request_get_descriptor(usb_device_get_default_pipe(dev),
 	    USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_INTERFACE,
-	    USB_DESCTYPE_HID_REPORT, 0, dev->interface_no,
+	    USB_DESCTYPE_HID_REPORT, 0, usb_device_get_iface_number(dev),
 	    *report_desc, length, &actual_size);
 
Index: uspace/lib/usbhid/src/hidreq.c
===================================================================
--- uspace/lib/usbhid/src/hidreq.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbhid/src/hidreq.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -182,10 +182,10 @@
 	uint16_t value = duration << 8;
 	
-	rc = usb_control_request_set(ctrl_pipe, 
-	    USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 
+	rc = usb_control_request_set(ctrl_pipe,
+	    USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
 	    USB_HIDREQ_SET_IDLE, value, iface_no, NULL, 0);
 
 	if (rc != EOK) {
-		usb_log_warning("Error sending Set Idle request to the device: "
+		usb_log_warning("Device did not accept Set Idle request: "
 		    "%s.\n", str_error(rc));
 		return rc;
Index: uspace/lib/usbhost/Makefile
===================================================================
--- uspace/lib/usbhost/Makefile	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbhost/Makefile	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -32,10 +32,11 @@
 	-I$(LIBUSB_PREFIX)/include \
 	-I$(LIBDRV_PREFIX)/include \
+	-Iinclude/usb/host \
 	-Iinclude
 
 SOURCES = \
+	src/ddf_helpers.c \
 	src/endpoint.c \
-	src/iface.c \
-	src/usb_device_manager.c \
+	src/hcd.c \
 	src/usb_endpoint_manager.c \
 	src/usb_transfer_batch.c
Index: uspace/lib/usbhost/include/usb/host/ddf_helpers.h
===================================================================
--- uspace/lib/usbhost/include/usb/host/ddf_helpers.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
+++ uspace/lib/usbhost/include/usb/host/ddf_helpers.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2012 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libusbhost
+ * @{
+ */
+/** @file
+ *
+ */
+
+#ifndef LIBUSBHOST_HOST_DDF_HELPERS_H
+#define LIBUSBHOST_HOST_DDF_HELPERS_H
+
+#include <usb/host/hcd.h>
+#include <usbhc_iface.h>
+
+int hcd_ddf_setup_hc(ddf_dev_t *device, usb_speed_t max_speed,
+    size_t bw, bw_count_func_t bw_count);
+void hcd_ddf_clean_hc(ddf_dev_t *device);
+int hcd_ddf_setup_root_hub(ddf_dev_t *device);
+
+hcd_t *dev_to_hcd(ddf_dev_t *dev);
+
+#endif
+
+/**
+ * @}
+ */
Index: uspace/lib/usbhost/include/usb/host/endpoint.h
===================================================================
--- uspace/lib/usbhost/include/usb/host/endpoint.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbhost/include/usb/host/endpoint.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -67,4 +67,9 @@
 	/** Signals change of active status. */
 	fibril_condvar_t avail;
+	/** High speed TT data */
+	struct {
+		usb_address_t address;
+		unsigned port;
+	} tt;
 	/** Optional device specific data. */
 	struct {
@@ -80,5 +85,6 @@
 endpoint_t * endpoint_create(usb_address_t address, usb_endpoint_t endpoint,
     usb_direction_t direction, usb_transfer_type_t type, usb_speed_t speed,
-    size_t max_packet_size, size_t bw);
+    size_t max_packet_size, size_t bw, usb_address_t tt_address,
+    unsigned tt_port);
 void endpoint_destroy(endpoint_t *instance);
 
Index: uspace/lib/usbhost/include/usb/host/hcd.h
===================================================================
--- uspace/lib/usbhost/include/usb/host/hcd.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbhost/include/usb/host/hcd.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -38,7 +38,7 @@
 
 #include <assert.h>
+#include <adt/list.h>
 #include <usbhc_iface.h>
 
-#include <usb/host/usb_device_manager.h>
 #include <usb/host/usb_endpoint_manager.h>
 #include <usb/host/usb_transfer_batch.h>
@@ -46,8 +46,10 @@
 typedef struct hcd hcd_t;
 
+typedef int (*schedule_hook_t)(hcd_t *, usb_transfer_batch_t *);
+typedef int (*ep_add_hook_t)(hcd_t *, endpoint_t *);
+typedef void (*ep_remove_hook_t)(hcd_t *, endpoint_t *);
+
 /** Generic host controller driver structure. */
 struct hcd {
-	/** Device manager storing handles and addresses. */
-	usb_device_manager_t dev_manager;
 	/** Endpoint manager. */
 	usb_endpoint_manager_t ep_manager;
@@ -56,55 +58,51 @@
 	void *private_data;
 	/** Transfer scheduling, implement in device driver. */
-	int (*schedule)(hcd_t *, usb_transfer_batch_t *);
+	schedule_hook_t schedule;
 	/** Hook called upon registering new endpoint. */
-	int (*ep_add_hook)(hcd_t *, endpoint_t *);
+	ep_add_hook_t ep_add_hook;
 	/** Hook called upon removing of an endpoint. */
-	void (*ep_remove_hook)(hcd_t *, endpoint_t *);
+	ep_remove_hook_t ep_remove_hook;
 };
 
-/** Initialize hcd_t structure.
- * Initializes device and endpoint managers. Sets data and hook pointer to NULL.
- * @param hcd hcd_t structure to initialize, non-null.
- * @param bandwidth Available bandwidth, passed to endpoint manager.
- * @param bw_count Bandwidth compute function, passed to endpoint manager.
- */
-static inline void hcd_init(hcd_t *hcd, usb_speed_t max_speed, size_t bandwidth,
-    size_t (*bw_count)(usb_speed_t, usb_transfer_type_t, size_t, size_t))
+void hcd_init(hcd_t *hcd, usb_speed_t max_speed, size_t bandwidth,
+    bw_count_func_t bw_count);
+
+static inline void hcd_set_implementation(hcd_t *hcd, void *data,
+    schedule_hook_t schedule, ep_add_hook_t add_hook, ep_remove_hook_t rem_hook)
 {
 	assert(hcd);
-	usb_device_manager_init(&hcd->dev_manager, max_speed);
-	usb_endpoint_manager_init(&hcd->ep_manager, bandwidth, bw_count);
-	hcd->private_data = NULL;
-	hcd->schedule = NULL;
-	hcd->ep_add_hook = NULL;
-	hcd->ep_remove_hook = NULL;
+	hcd->private_data = data;
+	hcd->schedule = schedule;
+	hcd->ep_add_hook = add_hook;
+	hcd->ep_remove_hook = rem_hook;
 }
 
-/** Check registered endpoints and reset toggle bit if necessary.
- * @param hcd hcd_t structure, non-null.
- * @param target Control communication target.
- * @param setup_data Setup packet of the control communication.
- */
-static inline void reset_ep_if_need(hcd_t *hcd, usb_target_t target,
-    const char setup_data[8])
+usb_address_t hcd_request_address(hcd_t *hcd, usb_speed_t speed);
+
+int hcd_release_address(hcd_t *hcd, usb_address_t address);
+
+int hcd_reserve_default_address(hcd_t *hcd, usb_speed_t speed);
+
+static inline int hcd_release_default_address(hcd_t *hcd)
 {
-	assert(hcd);
-	usb_endpoint_manager_reset_eps_if_need(
-	    &hcd->ep_manager, target, (const uint8_t *)setup_data);
+	return hcd_release_address(hcd, USB_ADDRESS_DEFAULT);
 }
 
-/** Data retrieve wrapper.
- * @param fun ddf function, non-null.
- * @return pointer cast to hcd_t*.
- */
-static inline hcd_t *fun_to_hcd(ddf_fun_t *fun)
-{
-	return ddf_fun_data_get(fun);
-}
+int hcd_add_ep(hcd_t *hcd, usb_target_t target, usb_direction_t dir,
+    usb_transfer_type_t type, size_t max_packet_size, size_t size,
+    usb_address_t tt_address, unsigned tt_port);
 
-extern usbhc_iface_t hcd_iface;
+int hcd_remove_ep(hcd_t *hcd, usb_target_t target, usb_direction_t dir);
+
+int hcd_send_batch(hcd_t *hcd, usb_target_t target, usb_direction_t direction,
+    void *data, size_t size, uint64_t setup_data,
+    usbhc_iface_transfer_in_callback_t in,
+    usbhc_iface_transfer_out_callback_t out, void *arg, const char* name);
+
+ssize_t hcd_send_batch_sync(hcd_t *hcd, usb_target_t target,
+    usb_direction_t dir, void *data, size_t size, uint64_t setup_data,
+    const char* name);
 
 #endif
-
 /**
  * @}
Index: uspace/lib/usbhost/include/usb/host/usb_device_manager.h
===================================================================
--- uspace/lib/usbhost/include/usb/host/usb_device_manager.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ 	(revision )
@@ -1,89 +1,0 @@
-/*
- * Copyright (c) 2011 Jan Vesely
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-/** @addtogroup libusbhost
- * @{
- */
-/** @file
- * Device manager structure and functions.
- *
- * Typical USB host controller needs to keep track of various settings for
- * each device that is connected to it.
- * State of toggle bit, device speed etc. etc.
- * This structure shall simplify the management.
- */
-#ifndef LIBUSBHOST_HOST_USB_DEVICE_MANAGER_H
-#define LIBUSBHOST_HOST_USB_DEVICE_MANAGER_H
-
-#include <adt/list.h>
-#include <devman.h>
-#include <fibril_synch.h>
-#include <usb/usb.h>
-#include <usb/host/endpoint.h>
-
-/** Number of USB address for array dimensions. */
-#define USB_ADDRESS_COUNT (USB11_ADDRESS_MAX + 1)
-
-/** Host controller device manager.
- * You shall not access members directly.
- */
-typedef struct {
-	/** Information about attached USB devices. */
-	struct {
-		usb_speed_t speed;      /**< Device speed */
-		bool occupied;          /**< The address is in use. */
-		devman_handle_t handle; /**< Devman handle of the device. */
-	} devices[USB_ADDRESS_COUNT];
-	/** Maximum speed allowed. */
-	usb_speed_t max_speed;
-	/** Protect access to members. */
-	fibril_mutex_t guard;
-	/** The last reserved address */
-	usb_address_t last_address;
-} usb_device_manager_t;
-
-void usb_device_manager_init(
-    usb_device_manager_t *instance, usb_speed_t max_speed);
-
-int usb_device_manager_request_address(usb_device_manager_t *instance,
-    usb_address_t *address, bool strict, usb_speed_t speed);
-
-int usb_device_manager_bind_address(usb_device_manager_t *instance,
-    usb_address_t address, devman_handle_t handle);
-
-int usb_device_manager_release_address(usb_device_manager_t *instance,
-    usb_address_t address);
-
-usb_address_t usb_device_manager_find_address(usb_device_manager_t *instance,
-    devman_handle_t handle);
-
-int usb_device_manager_get_info_by_address(usb_device_manager_t *instance,
-    usb_address_t address, devman_handle_t *handle, usb_speed_t *speed);
-#endif
-/**
- * @}
- */
Index: uspace/lib/usbhost/include/usb/host/usb_endpoint_manager.h
===================================================================
--- uspace/lib/usbhost/include/usb/host/usb_endpoint_manager.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbhost/include/usb/host/usb_endpoint_manager.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -50,11 +50,16 @@
 /** 90% of total bandwidth is available for periodic transfers */
 #define BANDWIDTH_AVAILABLE_USB11 ((BANDWIDTH_TOTAL_USB11 / 10) * 9)
-/** 16 addresses per list */
-#define ENDPOINT_LIST_COUNT 8
+
+typedef size_t (*bw_count_func_t)(usb_speed_t, usb_transfer_type_t, size_t, size_t);
+typedef void (*ep_remove_callback_t)(endpoint_t *, void *);
+typedef int (*ep_add_callback_t)(endpoint_t *, void *);
 
 /** Endpoint management structure */
 typedef struct usb_endpoint_manager {
-	/** Store endpoint_t instances */
-	list_t endpoint_lists[ENDPOINT_LIST_COUNT];
+	struct {
+		usb_speed_t speed;      /**< Device speed */
+		bool occupied;          /**< The address is in use. */
+		list_t endpoint_list;   /**< Store endpoint_t instances */
+	} devices[USB_ADDRESS_COUNT];
 	/** Prevents races accessing lists */
 	fibril_mutex_t guard;
@@ -62,6 +67,11 @@
 	size_t free_bw;
 	/** Use this function to count bw required by EP */
-	size_t (*bw_count)(usb_speed_t, usb_transfer_type_t, size_t, size_t);
+	bw_count_func_t bw_count;
+	/** Maximum speed allowed. */
+	usb_speed_t max_speed;
+	/** The last reserved address */
+	usb_address_t last_address;
 } usb_endpoint_manager_t;
+
 
 size_t bandwidth_count_usb11(usb_speed_t speed, usb_transfer_type_t type,
@@ -69,14 +79,12 @@
 
 int usb_endpoint_manager_init(usb_endpoint_manager_t *instance,
-    size_t available_bandwidth,
-    size_t (*bw_count)(usb_speed_t, usb_transfer_type_t, size_t, size_t));
-
-void usb_endpoint_manager_reset_eps_if_need(usb_endpoint_manager_t *instance,
-    usb_target_t target, const uint8_t data[8]);
+    size_t available_bandwidth, bw_count_func_t bw_count, usb_speed_t max_speed);
 
 int usb_endpoint_manager_register_ep(
     usb_endpoint_manager_t *instance, endpoint_t *ep, size_t data_size);
+
 int usb_endpoint_manager_unregister_ep(
     usb_endpoint_manager_t *instance, endpoint_t *ep);
+
 endpoint_t * usb_endpoint_manager_find_ep(usb_endpoint_manager_t *instance,
     usb_address_t address, usb_endpoint_t ep, usb_direction_t direction);
@@ -84,13 +92,23 @@
 int usb_endpoint_manager_add_ep(usb_endpoint_manager_t *instance,
     usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction,
-    usb_transfer_type_t type, usb_speed_t speed, size_t max_packet_size,
-    size_t data_size, int (*callback)(endpoint_t *, void *), void *arg);
+    usb_transfer_type_t type, size_t max_packet_size, size_t data_size,
+    ep_add_callback_t callback, void *arg, usb_address_t tt_address,
+    unsigned tt_port);
 
 int usb_endpoint_manager_remove_ep(usb_endpoint_manager_t *instance,
     usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction,
-    void (*callback)(endpoint_t *, void *), void *arg);
+    ep_remove_callback_t callback, void *arg);
 
-void usb_endpoint_manager_remove_address(usb_endpoint_manager_t *instance,
-    usb_address_t address, void (*callback)(endpoint_t *, void *), void *arg);
+int usb_endpoint_manager_reset_toggle(usb_endpoint_manager_t *instance,
+    usb_target_t target, bool all);
+
+int usb_endpoint_manager_remove_address(usb_endpoint_manager_t *instance,
+    usb_address_t address, ep_remove_callback_t callback, void *arg);
+
+int usb_endpoint_manager_request_address(usb_endpoint_manager_t *instance,
+    usb_address_t *address, bool strict, usb_speed_t speed);
+
+int usb_endpoint_manager_get_speed(usb_endpoint_manager_t *instance,
+    usb_address_t address, usb_speed_t *speed);
 #endif
 /**
Index: uspace/lib/usbhost/include/usb/host/usb_transfer_batch.h
===================================================================
--- uspace/lib/usbhost/include/usb/host/usb_transfer_batch.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbhost/include/usb/host/usb_transfer_batch.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -67,6 +67,4 @@
 	 */
 	size_t setup_size;
-	/** Host controller function, passed to callback function */
-	ddf_fun_t *fun;
 
 	/** Actually used portion of the buffer
@@ -80,9 +78,4 @@
 	 */
 	int error;
-
-	/** Driver specific data */
-	void *private_data;
-	/** Callback to properly remove driver data during destruction */
-	void (*private_data_dtor)(void *p_data);
 } usb_transfer_batch_t;
 
@@ -108,8 +101,5 @@
     usbhc_iface_transfer_in_callback_t func_in,
     usbhc_iface_transfer_out_callback_t func_out,
-    void *arg,
-    ddf_fun_t *fun,
-    void *private_data,
-    void (*private_data_dtor)(void *p_data)
+    void *arg
 );
 void usb_transfer_batch_destroy(const usb_transfer_batch_t *instance);
Index: uspace/lib/usbhost/src/ddf_helpers.c
===================================================================
--- uspace/lib/usbhost/src/ddf_helpers.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
+++ uspace/lib/usbhost/src/ddf_helpers.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -0,0 +1,641 @@
+/*
+ * Copyright (c) 2013 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libusbhost
+ * @{
+ */
+/** @file
+ *
+ */
+
+#include <usb_iface.h>
+#include <usb/classes/classes.h>
+#include <usb/debug.h>
+#include <usb/descriptor.h>
+#include <usb/request.h>
+#include <errno.h>
+#include <str_error.h>
+
+#include "ddf_helpers.h"
+
+#define CTRL_PIPE_MIN_PACKET_SIZE 8
+
+typedef struct usb_dev {
+	link_t link;
+	list_t devices;
+	fibril_mutex_t guard;
+	ddf_fun_t *fun;
+	usb_address_t address;
+	usb_speed_t speed;
+	usb_address_t tt_address;
+	unsigned port;
+} usb_dev_t;
+
+typedef struct hc_dev {
+	ddf_fun_t *ctl_fun;
+	hcd_t hcd;
+	usb_dev_t *root_hub;
+} hc_dev_t;
+
+static hc_dev_t *dev_to_hc_dev(ddf_dev_t *dev)
+{
+	return ddf_dev_data_get(dev);
+}
+
+hcd_t *dev_to_hcd(ddf_dev_t *dev)
+{
+	hc_dev_t *hc_dev = dev_to_hc_dev(dev);
+	if (!hc_dev) {
+		usb_log_error("Invalid HCD device.\n");
+		return NULL;
+	}
+	return &hc_dev->hcd;
+}
+
+
+static int hcd_ddf_new_device(ddf_dev_t *device, usb_dev_t *hub, unsigned port);
+static int hcd_ddf_remove_device(ddf_dev_t *device, usb_dev_t *hub, unsigned port);
+
+
+/* DDF INTERFACE */
+
+/** Register endpoint interface function.
+ * @param fun DDF function.
+ * @param address USB address of the device.
+ * @param endpoint USB endpoint number to be registered.
+ * @param transfer_type Endpoint's transfer type.
+ * @param direction USB communication direction the endpoint is capable of.
+ * @param max_packet_size Maximu size of packets the endpoint accepts.
+ * @param interval Preferred timeout between communication.
+ * @return Error code.
+ */
+static int register_endpoint(
+    ddf_fun_t *fun, usb_endpoint_t endpoint,
+    usb_transfer_type_t transfer_type, usb_direction_t direction,
+    size_t max_packet_size, unsigned interval)
+{
+	assert(fun);
+	hcd_t *hcd = dev_to_hcd(ddf_fun_get_dev(fun));
+	usb_dev_t *dev = ddf_fun_data_get(fun);
+	assert(hcd);
+	assert(dev);
+	const size_t size = max_packet_size;
+	const usb_target_t target =
+	    {{.address = dev->address, .endpoint = endpoint}};
+
+	usb_log_debug("Register endpoint %d:%d %s-%s %zuB %ums.\n",
+	    dev->address, endpoint, usb_str_transfer_type(transfer_type),
+	    usb_str_direction(direction), max_packet_size, interval);
+
+	return hcd_add_ep(hcd, target, direction, transfer_type,
+	    max_packet_size, size, dev->tt_address, dev->port);
+}
+
+/** Unregister endpoint interface function.
+ * @param fun DDF function.
+ * @param address USB address of the endpoint.
+ * @param endpoint USB endpoint number.
+ * @param direction Communication direction of the enpdoint to unregister.
+ * @return Error code.
+ */
+static int unregister_endpoint(
+    ddf_fun_t *fun, usb_endpoint_t endpoint, usb_direction_t direction)
+{
+	assert(fun);
+	hcd_t *hcd = dev_to_hcd(ddf_fun_get_dev(fun));
+	usb_dev_t *dev = ddf_fun_data_get(fun);
+	assert(hcd);
+	assert(dev);
+	const usb_target_t target =
+	    {{.address = dev->address, .endpoint = endpoint}};
+	usb_log_debug("Unregister endpoint %d:%d %s.\n",
+	    dev->address, endpoint, usb_str_direction(direction));
+	return hcd_remove_ep(hcd, target, direction);
+}
+
+static int reserve_default_address(ddf_fun_t *fun, usb_speed_t speed)
+{
+	assert(fun);
+	hcd_t *hcd = dev_to_hcd(ddf_fun_get_dev(fun));
+	usb_dev_t *dev = ddf_fun_data_get(fun);
+	assert(hcd);
+	assert(dev);
+
+	usb_log_debug("Device %d requested default address at %s speed\n",
+	    dev->address, usb_str_speed(speed));
+	return hcd_reserve_default_address(hcd, speed);
+}
+
+static int release_default_address(ddf_fun_t *fun)
+{
+	assert(fun);
+	hcd_t *hcd = dev_to_hcd(ddf_fun_get_dev(fun));
+	usb_dev_t *dev = ddf_fun_data_get(fun);
+	assert(hcd);
+	assert(dev);
+
+	usb_log_debug("Device %d released default address\n", dev->address);
+	return hcd_release_default_address(hcd);
+}
+
+static int device_enumerate(ddf_fun_t *fun, unsigned port)
+{
+	assert(fun);
+	ddf_dev_t *ddf_dev = ddf_fun_get_dev(fun);
+	usb_dev_t *dev = ddf_fun_data_get(fun);
+	assert(ddf_dev);
+	assert(dev);
+	usb_log_debug("Hub %d reported a new USB device on port: %u\n",
+	    dev->address, port);
+	return hcd_ddf_new_device(ddf_dev, dev, port);
+}
+
+static int device_remove(ddf_fun_t *fun, unsigned port)
+{
+	assert(fun);
+	ddf_dev_t *ddf_dev = ddf_fun_get_dev(fun);
+	usb_dev_t *dev = ddf_fun_data_get(fun);
+	assert(ddf_dev);
+	assert(dev);
+	usb_log_debug("Hub `%s' reported removal of device on port %u\n",
+	    ddf_fun_get_name(fun), port);
+	return hcd_ddf_remove_device(ddf_dev, dev, port);
+}
+
+/** Gets handle of the respective device.
+ *
+ * @param[in] fun Device function.
+ * @param[out] handle Place to write the handle.
+ * @return Error code.
+ */
+static int get_my_device_handle(ddf_fun_t *fun, devman_handle_t *handle)
+{
+	assert(fun);
+	if (handle)
+		*handle = ddf_fun_get_handle(fun);
+	return EOK;
+}
+
+/** Inbound communication interface function.
+ * @param fun DDF function.
+ * @param target Communication target.
+ * @param setup_data Data to use in setup stage (control transfers).
+ * @param data Pointer to data buffer.
+ * @param size Size of the data buffer.
+ * @param callback Function to call on communication end.
+ * @param arg Argument passed to the callback function.
+ * @return Error code.
+ */
+static int dev_read(ddf_fun_t *fun, usb_endpoint_t endpoint,
+    uint64_t setup_data, uint8_t *data, size_t size,
+    usbhc_iface_transfer_in_callback_t callback, void *arg)
+{
+	assert(fun);
+	usb_dev_t *usb_dev = ddf_fun_data_get(fun);
+	assert(usb_dev);
+	const usb_target_t target = {{
+	    .address =  usb_dev->address,
+	    .endpoint = endpoint,
+	}};
+	return hcd_send_batch(dev_to_hcd(ddf_fun_get_dev(fun)), target,
+	    USB_DIRECTION_IN, data, size, setup_data, callback, NULL, arg,
+	    "READ");
+}
+
+/** Outbound communication interface function.
+ * @param fun DDF function.
+ * @param target Communication target.
+ * @param setup_data Data to use in setup stage (control transfers).
+ * @param data Pointer to data buffer.
+ * @param size Size of the data buffer.
+ * @param callback Function to call on communication end.
+ * @param arg Argument passed to the callback function.
+ * @return Error code.
+ */
+static int dev_write(ddf_fun_t *fun, usb_endpoint_t endpoint,
+    uint64_t setup_data, const uint8_t *data, size_t size,
+    usbhc_iface_transfer_out_callback_t callback, void *arg)
+{
+	assert(fun);
+	usb_dev_t *usb_dev = ddf_fun_data_get(fun);
+	assert(usb_dev);
+	const usb_target_t target = {{
+	    .address =  usb_dev->address,
+	    .endpoint = endpoint,
+	}};
+	return hcd_send_batch(dev_to_hcd(ddf_fun_get_dev(fun)),
+	    target, USB_DIRECTION_OUT, (uint8_t*)data, size, setup_data, NULL,
+	    callback, arg, "WRITE");
+}
+
+/** USB device interface */
+static usb_iface_t usb_iface = {
+	.get_my_device_handle = get_my_device_handle,
+
+	.reserve_default_address = reserve_default_address,
+	.release_default_address = release_default_address,
+
+	.device_enumerate = device_enumerate,
+	.device_remove = device_remove,
+
+	.register_endpoint = register_endpoint,
+	.unregister_endpoint = unregister_endpoint,
+
+	.read = dev_read,
+	.write = dev_write,
+};
+
+/** Standard USB device interface) */
+static ddf_dev_ops_t usb_ops = {
+	.interfaces[USB_DEV_IFACE] = &usb_iface,
+};
+
+
+/* DDF HELPERS */
+
+#define GET_DEVICE_DESC(size) \
+{ \
+	.request_type = SETUP_REQUEST_TYPE_DEVICE_TO_HOST \
+	    | (USB_REQUEST_TYPE_STANDARD << 5) \
+	    | USB_REQUEST_RECIPIENT_DEVICE, \
+	.request = USB_DEVREQ_GET_DESCRIPTOR, \
+	.value = uint16_host2usb(USB_DESCTYPE_DEVICE << 8), \
+	.index = uint16_host2usb(0), \
+	.length = uint16_host2usb(size), \
+};
+
+#define SET_ADDRESS(address) \
+{ \
+	.request_type = SETUP_REQUEST_TYPE_HOST_TO_DEVICE \
+	    | (USB_REQUEST_TYPE_STANDARD << 5) \
+	    | USB_REQUEST_RECIPIENT_DEVICE, \
+	.request = USB_DEVREQ_SET_ADDRESS, \
+	.value = uint16_host2usb(address), \
+	.index = uint16_host2usb(0), \
+	.length = uint16_host2usb(0), \
+};
+
+static int hcd_ddf_add_device(ddf_dev_t *parent, usb_dev_t *hub_dev,
+    unsigned port, usb_address_t address, usb_speed_t speed, const char *name,
+    const match_id_list_t *mids)
+{
+	assert(parent);
+
+	char default_name[10] = { 0 }; /* usbxyz-ss */
+	if (!name) {
+		snprintf(default_name, sizeof(default_name) - 1,
+		    "usb%u-%cs", address, usb_str_speed(speed)[0]);
+		name = default_name;
+	}
+
+	ddf_fun_t *fun = ddf_fun_create(parent, fun_inner, name);
+	if (!fun)
+		return ENOMEM;
+	usb_dev_t *info = ddf_fun_data_alloc(fun, sizeof(usb_dev_t));
+	if (!info) {
+		ddf_fun_destroy(fun);
+		return ENOMEM;
+	}
+	info->address = address;
+	info->speed = speed;
+	info->fun = fun;
+	info->port = port;
+	info->tt_address = hub_dev ? hub_dev->tt_address : -1;
+	link_initialize(&info->link);
+	list_initialize(&info->devices);
+	fibril_mutex_initialize(&info->guard);
+
+	if (hub_dev && hub_dev->speed == USB_SPEED_HIGH && usb_speed_is_11(speed))
+		info->tt_address = hub_dev->address;
+
+	ddf_fun_set_ops(fun, &usb_ops);
+	list_foreach(mids->ids, link, const match_id_t, mid) {
+		ddf_fun_add_match_id(fun, mid->id, mid->score);
+	}
+
+	int ret = ddf_fun_bind(fun);
+	if (ret != EOK) {
+		ddf_fun_destroy(fun);
+		return ret;
+	}
+
+	if (hub_dev) {
+		fibril_mutex_lock(&hub_dev->guard);
+		list_append(&info->link, &hub_dev->devices);
+		fibril_mutex_unlock(&hub_dev->guard);
+	} else {
+		hc_dev_t *hc_dev = dev_to_hc_dev(parent);
+		assert(hc_dev->root_hub == NULL);
+		hc_dev->root_hub = info;
+	}
+	return EOK;
+}
+
+#define ADD_MATCHID_OR_RETURN(list, sc, str, ...) \
+do { \
+	match_id_t *mid = malloc(sizeof(match_id_t)); \
+	if (!mid) { \
+		clean_match_ids(list); \
+		return ENOMEM; \
+	} \
+	char *id = NULL; \
+	int ret = asprintf(&id, str, ##__VA_ARGS__); \
+	if (ret < 0) { \
+		clean_match_ids(list); \
+		free(mid); \
+		return ENOMEM; \
+	} \
+	mid->score = sc; \
+	mid->id = id; \
+	add_match_id(list, mid); \
+} while (0)
+
+/* This is a copy of lib/usbdev/src/recognise.c */
+static int create_match_ids(match_id_list_t *l,
+    usb_standard_device_descriptor_t *d)
+{
+	assert(l);
+	assert(d);
+	
+	if (d->vendor_id != 0) {
+		/* First, with release number. */
+		ADD_MATCHID_OR_RETURN(l, 100,
+		    "usb&vendor=%#04x&product=%#04x&release=%x.%x",
+		    d->vendor_id, d->product_id, (d->device_version >> 8),
+		    (d->device_version & 0xff));
+	
+		/* Next, without release number. */
+		ADD_MATCHID_OR_RETURN(l, 90, "usb&vendor=%#04x&product=%#04x",
+		    d->vendor_id, d->product_id);
+	}
+
+	/* Class match id */
+	ADD_MATCHID_OR_RETURN(l, 50, "usb&class=%s",
+	    usb_str_class(d->device_class));
+
+	/* As a last resort, try fallback driver. */
+	ADD_MATCHID_OR_RETURN(l, 10, "usb&fallback");
+
+	return EOK;
+
+}
+
+static int hcd_ddf_remove_device(ddf_dev_t *device, usb_dev_t *hub,
+    unsigned port)
+{
+	assert(device);
+
+	hcd_t *hcd = dev_to_hcd(device);
+	assert(hcd);
+
+	hc_dev_t *hc_dev = dev_to_hc_dev(device);
+	assert(hc_dev);
+
+	fibril_mutex_lock(&hub->guard);
+
+	usb_dev_t *victim = NULL;
+
+	list_foreach(hub->devices, link, usb_dev_t, it) {
+		if (it->port == port) {
+			victim = it;
+			break;
+		}
+	}
+	if (victim && victim->port == port) {
+		list_remove(&victim->link);
+		fibril_mutex_unlock(&hub->guard);
+		const int ret = ddf_fun_unbind(victim->fun);
+		if (ret == EOK) {
+			ddf_fun_destroy(victim->fun);
+			hcd_release_address(hcd, victim->address);
+		} else {
+			usb_log_warning("Failed to unbind device `%s': %s\n",
+			    ddf_fun_get_name(victim->fun), str_error(ret));
+		}
+		return EOK;
+	}
+	return ENOENT;
+}
+
+static int hcd_ddf_new_device(ddf_dev_t *device, usb_dev_t *hub, unsigned port)
+{
+	assert(device);
+
+	hcd_t *hcd = dev_to_hcd(device);
+	assert(hcd);
+
+	usb_speed_t speed = USB_SPEED_MAX;
+
+	/* This checks whether the default address is reserved and gets speed */
+	int ret = usb_endpoint_manager_get_speed(&hcd->ep_manager,
+		USB_ADDRESS_DEFAULT, &speed);
+	if (ret != EOK) {
+		return ret;
+	}
+
+	static const usb_target_t default_target = {{
+		.address = USB_ADDRESS_DEFAULT,
+		.endpoint = 0,
+	}};
+
+	const usb_address_t address = hcd_request_address(hcd, speed);
+	if (address < 0)
+		return address;
+
+	const usb_target_t target = {{
+		.address = address,
+		.endpoint = 0,
+	}};
+
+	const usb_address_t tt_address = hub ? hub->tt_address : -1;
+
+	/* Add default pipe on default address */
+	ret = hcd_add_ep(hcd,
+	    default_target, USB_DIRECTION_BOTH, USB_TRANSFER_CONTROL,
+	    CTRL_PIPE_MIN_PACKET_SIZE, CTRL_PIPE_MIN_PACKET_SIZE,
+	    tt_address, port);
+
+	if (ret != EOK) {
+		hcd_release_address(hcd, address);
+		return ret;
+	}
+
+	/* Get max packet size for default pipe */
+	usb_standard_device_descriptor_t desc = { 0 };
+	static const usb_device_request_setup_packet_t get_device_desc_8 =
+	    GET_DEVICE_DESC(CTRL_PIPE_MIN_PACKET_SIZE);
+
+	// TODO CALLBACKS
+	ssize_t got = hcd_send_batch_sync(hcd, default_target, USB_DIRECTION_IN,
+	    &desc, CTRL_PIPE_MIN_PACKET_SIZE, *(uint64_t *)&get_device_desc_8,
+	    "read first 8 bytes of dev descriptor");
+
+	if (got != CTRL_PIPE_MIN_PACKET_SIZE) {
+		hcd_remove_ep(hcd, default_target, USB_DIRECTION_BOTH);
+		hcd_release_address(hcd, address);
+		return got < 0 ? got : EOVERFLOW;
+	}
+
+	/* Register EP on the new address */
+	ret = hcd_add_ep(hcd, target, USB_DIRECTION_BOTH, USB_TRANSFER_CONTROL,
+	    desc.max_packet_size, desc.max_packet_size, tt_address, port);
+	if (ret != EOK) {
+		hcd_remove_ep(hcd, default_target, USB_DIRECTION_BOTH);
+		hcd_remove_ep(hcd, target, USB_DIRECTION_BOTH);
+		hcd_release_address(hcd, address);
+		return ret;
+	}
+
+	/* Set new address */
+	const usb_device_request_setup_packet_t set_address =
+	    SET_ADDRESS(target.address);
+
+	got = hcd_send_batch_sync(hcd, default_target, USB_DIRECTION_OUT,
+	    NULL, 0, *(uint64_t *)&set_address, "set address");
+
+	hcd_remove_ep(hcd, default_target, USB_DIRECTION_BOTH);
+
+	if (got != 0) {
+		hcd_remove_ep(hcd, target, USB_DIRECTION_BOTH);
+		hcd_release_address(hcd, address);
+		return got;
+	}
+	
+	/* Get std device descriptor */
+	static const usb_device_request_setup_packet_t get_device_desc =
+	    GET_DEVICE_DESC(sizeof(desc));
+
+	got = hcd_send_batch_sync(hcd, target, USB_DIRECTION_IN,
+	    &desc, sizeof(desc), *(uint64_t *)&get_device_desc,
+	    "read device descriptor");
+	if (ret != EOK) {
+		hcd_remove_ep(hcd, target, USB_DIRECTION_BOTH);
+		hcd_release_address(hcd, target.address);
+		return got < 0 ? got : EOVERFLOW;
+	}
+
+	/* Create match ids from the device descriptor */
+	match_id_list_t mids;
+	init_match_ids(&mids);
+
+	ret = create_match_ids(&mids, &desc);
+	if (ret != EOK) {
+		hcd_remove_ep(hcd, target, USB_DIRECTION_BOTH);
+		hcd_release_address(hcd, target.address);
+		return ret;
+	}
+
+	/* Register device */
+	ret = hcd_ddf_add_device(device, hub, port, address, speed, NULL, &mids);
+	clean_match_ids(&mids);
+	if (ret != EOK) {
+		hcd_remove_ep(hcd, target, USB_DIRECTION_BOTH);
+		hcd_release_address(hcd, target.address);
+	}
+
+	return ret;
+}
+
+/** Announce root hub to the DDF
+ *
+ * @param[in] device Host controller ddf device
+ * @return Error code
+ */
+int hcd_ddf_setup_root_hub(ddf_dev_t *device)
+{
+	assert(device);
+	hcd_t *hcd = dev_to_hcd(device);
+	assert(hcd);
+
+	hcd_reserve_default_address(hcd, hcd->ep_manager.max_speed);
+	const int ret = hcd_ddf_new_device(device, NULL, 0);
+	hcd_release_default_address(hcd);
+	return ret;
+}
+
+/** Initialize hc structures.
+ *
+ * @param[in] device DDF instance of the device to use.
+ *
+ * This function does all the ddf work for hc driver.
+ */
+int hcd_ddf_setup_hc(ddf_dev_t *device, usb_speed_t max_speed,
+    size_t bw, bw_count_func_t bw_count)
+{
+	assert(device);
+
+	hc_dev_t *instance = ddf_dev_data_alloc(device, sizeof(hc_dev_t));
+	if (instance == NULL) {
+		usb_log_error("Failed to allocate HCD ddf structure.\n");
+		return ENOMEM;
+	}
+	instance->root_hub = NULL;
+	hcd_init(&instance->hcd, max_speed, bw, bw_count);
+
+	int ret = ENOMEM;
+	instance->ctl_fun = ddf_fun_create(device, fun_exposed, "ctl");
+	if (!instance->ctl_fun) {
+		usb_log_error("Failed to create HCD ddf fun.\n");
+		goto err_destroy_fun;
+	}
+
+	ret = ddf_fun_bind(instance->ctl_fun);
+	if (ret != EOK) {
+		usb_log_error("Failed to bind ctl_fun: %s.\n", str_error(ret));
+		goto err_destroy_fun;
+	}
+
+	ret = ddf_fun_add_to_category(instance->ctl_fun, USB_HC_CATEGORY);
+	if (ret != EOK) {
+		usb_log_error("Failed to add fun to category: %s.\n",
+		    str_error(ret));
+		ddf_fun_unbind(instance->ctl_fun);
+		goto err_destroy_fun;
+	}
+
+	/* HC should be ok at this point (except it can't do anything) */
+	return EOK;
+
+err_destroy_fun:
+	ddf_fun_destroy(instance->ctl_fun);
+	instance->ctl_fun = NULL;
+	return ret;
+}
+
+void hcd_ddf_clean_hc(ddf_dev_t *device)
+{
+	assert(device);
+	hc_dev_t *hc = dev_to_hc_dev(device);
+	assert(hc);
+	const int ret = ddf_fun_unbind(hc->ctl_fun);
+	if (ret == EOK)
+		ddf_fun_destroy(hc->ctl_fun);
+}
+/**
+ * @}
+ */
Index: uspace/lib/usbhost/src/endpoint.c
===================================================================
--- uspace/lib/usbhost/src/endpoint.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbhost/src/endpoint.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -50,5 +50,5 @@
 endpoint_t * endpoint_create(usb_address_t address, usb_endpoint_t endpoint,
     usb_direction_t direction, usb_transfer_type_t type, usb_speed_t speed,
-    size_t max_packet_size, size_t bw)
+    size_t max_packet_size, size_t bw, usb_address_t tt_address, unsigned tt_p)
 {
 	endpoint_t *instance = malloc(sizeof(endpoint_t));
@@ -63,4 +63,6 @@
 		instance->toggle = 0;
 		instance->active = false;
+		instance->tt.address = tt_address;
+		instance->tt.port = tt_p;
 		instance->hc_data.data = NULL;
 		instance->hc_data.toggle_get = NULL;
@@ -109,9 +111,5 @@
 {
 	assert(instance);
-	fibril_mutex_lock(&instance->guard);
-	instance->hc_data.data = NULL;
-	instance->hc_data.toggle_get = NULL;
-	instance->hc_data.toggle_set = NULL;
-	fibril_mutex_unlock(&instance->guard);
+	endpoint_set_hc_data(instance, NULL, NULL, NULL);
 }
 
Index: uspace/lib/usbhost/src/hcd.c
===================================================================
--- uspace/lib/usbhost/src/hcd.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
+++ uspace/lib/usbhost/src/hcd.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -0,0 +1,297 @@
+/*
+ * Copyright (c) 2011 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libusbhost
+ * @{
+ */
+/** @file
+ *
+ */
+
+#include <errno.h>
+#include <str_error.h>
+#include <usb_iface.h>
+#include <usb/debug.h>
+#include <usb/request.h>
+
+#include "hcd.h"
+
+/** Calls ep_add_hook upon endpoint registration.
+ * @param ep Endpoint to be registered.
+ * @param arg hcd_t in disguise.
+ * @return Error code.
+ */
+static int register_helper(endpoint_t *ep, void *arg)
+{
+	hcd_t *hcd = arg;
+	assert(ep);
+	assert(hcd);
+	if (hcd->ep_add_hook)
+		return hcd->ep_add_hook(hcd, ep);
+	return EOK;
+}
+
+/** Calls ep_remove_hook upon endpoint removal.
+ * @param ep Endpoint to be unregistered.
+ * @param arg hcd_t in disguise.
+ */
+static void unregister_helper(endpoint_t *ep, void *arg)
+{
+	hcd_t *hcd = arg;
+	assert(ep);
+	assert(hcd);
+	if (hcd->ep_remove_hook)
+		hcd->ep_remove_hook(hcd, ep);
+}
+
+/** Calls ep_remove_hook upon endpoint removal. Prints warning.
+ *  * @param ep Endpoint to be unregistered.
+ *   * @param arg hcd_t in disguise.
+ *    */
+static void unregister_helper_warn(endpoint_t *ep, void *arg)
+{
+        assert(ep);
+        usb_log_warning("Endpoint %d:%d %s was left behind, removing.\n",
+            ep->address, ep->endpoint, usb_str_direction(ep->direction));
+	unregister_helper(ep, arg);
+}
+
+
+/** Initialize hcd_t structure.
+ * Initializes device and endpoint managers. Sets data and hook pointer to NULL.
+ *
+ * @param hcd hcd_t structure to initialize, non-null.
+ * @param max_speed Maximum supported USB speed (full, high).
+ * @param bandwidth Available bandwidth, passed to endpoint manager.
+ * @param bw_count Bandwidth compute function, passed to endpoint manager.
+ */
+void hcd_init(hcd_t *hcd, usb_speed_t max_speed, size_t bandwidth,
+    bw_count_func_t bw_count)
+{
+	assert(hcd);
+	usb_endpoint_manager_init(&hcd->ep_manager, bandwidth, bw_count, max_speed);
+
+	hcd->private_data = NULL;
+	hcd->schedule = NULL;
+	hcd->ep_add_hook = NULL;
+	hcd->ep_remove_hook = NULL;
+}
+
+usb_address_t hcd_request_address(hcd_t *hcd, usb_speed_t speed)
+{
+	assert(hcd);
+	usb_address_t address = 0;
+	const int ret = usb_endpoint_manager_request_address(
+	    &hcd->ep_manager, &address, false, speed);
+	if (ret != EOK)
+		return ret;
+	return address;
+}
+
+int hcd_release_address(hcd_t *hcd, usb_address_t address)
+{
+	assert(hcd);
+	return usb_endpoint_manager_remove_address(&hcd->ep_manager, address,
+	    unregister_helper_warn, hcd);
+}
+
+int hcd_reserve_default_address(hcd_t *hcd, usb_speed_t speed)
+{
+	assert(hcd);
+	usb_address_t address = 0;
+	return usb_endpoint_manager_request_address(
+	    &hcd->ep_manager, &address, true, speed);
+}
+
+int hcd_add_ep(hcd_t *hcd, usb_target_t target, usb_direction_t dir,
+    usb_transfer_type_t type, size_t max_packet_size, size_t size,
+    usb_address_t tt_address, unsigned tt_port)
+{
+	assert(hcd);
+	return usb_endpoint_manager_add_ep(&hcd->ep_manager, target.address,
+	    target.endpoint, dir, type, max_packet_size, size, register_helper,
+	    hcd, tt_address, tt_port);
+}
+
+int hcd_remove_ep(hcd_t *hcd, usb_target_t target, usb_direction_t dir)
+{
+	assert(hcd);
+	return usb_endpoint_manager_remove_ep(&hcd->ep_manager, target.address,
+	    target.endpoint, dir, unregister_helper, hcd);
+}
+
+
+typedef struct {
+	void *original_data;
+	usbhc_iface_transfer_out_callback_t original_callback;
+	usb_target_t target;
+	hcd_t *hcd;
+} toggle_t;
+
+static void toggle_reset_callback(int retval, void *arg)
+{
+	assert(arg);
+	toggle_t *toggle = arg;
+	if (retval == EOK) {
+		usb_log_debug2("Reseting toggle on %d:%d.\n",
+		    toggle->target.address, toggle->target.endpoint);
+		usb_endpoint_manager_reset_toggle(&toggle->hcd->ep_manager,
+		    toggle->target, toggle->target.endpoint == 0);
+	}
+
+	toggle->original_callback(retval, toggle->original_data);
+}
+
+/** Prepare generic usb_transfer_batch and schedule it.
+ * @param hcd Host controller driver.
+ * @param fun DDF fun
+ * @param target address and endpoint number.
+ * @param setup_data Data to use in setup stage (Control communication type)
+ * @param in Callback for device to host communication.
+ * @param out Callback for host to device communication.
+ * @param arg Callback parameter.
+ * @param name Communication identifier (for nicer output).
+ * @return Error code.
+ */
+int hcd_send_batch(
+    hcd_t *hcd, usb_target_t target, usb_direction_t direction,
+    void *data, size_t size, uint64_t setup_data,
+    usbhc_iface_transfer_in_callback_t in,
+    usbhc_iface_transfer_out_callback_t out, void *arg, const char* name)
+{
+	assert(hcd);
+
+	endpoint_t *ep = usb_endpoint_manager_find_ep(&hcd->ep_manager,
+	    target.address, target.endpoint, direction);
+	if (ep == NULL) {
+		usb_log_error("Endpoint(%d:%d) not registered for %s.\n",
+		    target.address, target.endpoint, name);
+		return ENOENT;
+	}
+
+	usb_log_debug2("%s %d:%d %zu(%zu).\n",
+	    name, target.address, target.endpoint, size, ep->max_packet_size);
+
+	const size_t bw = bandwidth_count_usb11(
+	    ep->speed, ep->transfer_type, size, ep->max_packet_size);
+	/* Check if we have enough bandwidth reserved */
+	if (ep->bandwidth < bw) {
+		usb_log_error("Endpoint(%d:%d) %s needs %zu bw "
+		    "but only %zu is reserved.\n",
+		    ep->address, ep->endpoint, name, bw, ep->bandwidth);
+		return ENOSPC;
+	}
+	if (!hcd->schedule) {
+		usb_log_error("HCD does not implement scheduler.\n");
+		return ENOTSUP;
+	}
+
+	/* Check for commands that reset toggle bit */
+	if (ep->transfer_type == USB_TRANSFER_CONTROL) {
+		const int reset_toggle = usb_request_needs_toggle_reset(
+		    (usb_device_request_setup_packet_t *) &setup_data);
+		if (reset_toggle >= 0) {
+			assert(out);
+			toggle_t *toggle = malloc(sizeof(toggle_t));
+			if (!toggle)
+				return ENOMEM;
+			toggle->target.address = target.address;
+			toggle->target.endpoint = reset_toggle;
+			toggle->original_callback = out;
+			toggle->original_data = arg;
+			toggle->hcd = hcd;
+
+			arg = toggle;
+			out = toggle_reset_callback;
+		}
+	}
+
+	usb_transfer_batch_t *batch = usb_transfer_batch_create(
+	    ep, data, size, setup_data, in, out, arg);
+	if (!batch) {
+		usb_log_error("Failed to create transfer batch.\n");
+		return ENOMEM;
+	}
+
+	const int ret = hcd->schedule(hcd, batch);
+	if (ret != EOK)
+		usb_transfer_batch_destroy(batch);
+
+	return ret;
+}
+
+typedef struct {
+	volatile unsigned done;
+	int ret;
+	size_t size;
+} sync_data_t;
+
+static void transfer_in_cb(int ret, size_t size, void* data)
+{
+	sync_data_t *d = data;
+	assert(d);
+	d->ret = ret;
+	d->done = 1;
+	d->size = size;
+}
+
+static void transfer_out_cb(int ret, void* data)
+{
+	sync_data_t *d = data;
+	assert(data);
+	d->ret = ret;
+	d->done = 1;
+}
+
+/** this is really ugly version of sync usb communication */
+ssize_t hcd_send_batch_sync(
+    hcd_t *hcd, usb_target_t target, usb_direction_t dir,
+    void *data, size_t size, uint64_t setup_data, const char* name)
+{
+	assert(hcd);
+	sync_data_t sd = { .done = 0, .ret = EINPROGRESS, .size = size };
+
+	const int ret = hcd_send_batch(hcd, target, dir, data, size, setup_data,
+	    dir == USB_DIRECTION_IN ? transfer_in_cb : NULL,
+	    dir == USB_DIRECTION_OUT ? transfer_out_cb : NULL, &sd, name);
+	if (ret != EOK)
+		return ret;
+
+	while (!sd.done) {
+		async_usleep(1000);
+	}
+
+	if (sd.ret == EOK)
+		return sd.size;
+	return sd.ret;
+}
+
+
+/**
+ * @}
+ */
Index: uspace/lib/usbhost/src/iface.c
===================================================================
--- uspace/lib/usbhost/src/iface.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ 	(revision )
@@ -1,331 +1,0 @@
-/*
- * Copyright (c) 2011 Jan Vesely
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup libusbhost
- * @{
- */
-/** @file
- * @brief HCD DDF interface implementation
- */
-
-#include <ddf/driver.h>
-#include <errno.h>
-
-#include <usb/debug.h>
-#include <usb/host/endpoint.h>
-#include <usb/host/hcd.h>
-
-/** Prepare generic usb_transfer_batch and schedule it.
- * @param fun DDF fun
- * @param target address and endpoint number.
- * @param setup_data Data to use in setup stage (Control communication type)
- * @param in Callback for device to host communication.
- * @param out Callback for host to device communication.
- * @param arg Callback parameter.
- * @param name Communication identifier (for nicer output).
- * @return Error code.
- */
-static inline int send_batch(
-    ddf_fun_t *fun, usb_target_t target, usb_direction_t direction,
-    void *data, size_t size, uint64_t setup_data,
-    usbhc_iface_transfer_in_callback_t in,
-    usbhc_iface_transfer_out_callback_t out, void *arg, const char* name)
-{
-	assert(fun);
-	hcd_t *hcd = fun_to_hcd(fun);
-	assert(hcd);
-
-	endpoint_t *ep = usb_endpoint_manager_find_ep(&hcd->ep_manager,
-	    target.address, target.endpoint, direction);
-	if (ep == NULL) {
-		usb_log_error("Endpoint(%d:%d) not registered for %s.\n",
-		    target.address, target.endpoint, name);
-		return ENOENT;
-	}
-
-	usb_log_debug2("%s %d:%d %zu(%zu).\n",
-	    name, target.address, target.endpoint, size, ep->max_packet_size);
-
-	const size_t bw = bandwidth_count_usb11(
-	    ep->speed, ep->transfer_type, size, ep->max_packet_size);
-	/* Check if we have enough bandwidth reserved */
-	if (ep->bandwidth < bw) {
-		usb_log_error("Endpoint(%d:%d) %s needs %zu bw "
-		    "but only %zu is reserved.\n",
-		    ep->address, ep->endpoint, name, bw, ep->bandwidth);
-		return ENOSPC;
-	}
-	if (!hcd->schedule) {
-		usb_log_error("HCD does not implement scheduler.\n");
-		return ENOTSUP;
-	}
-
-	/* No private data and no private data dtor */
-	usb_transfer_batch_t *batch =
-	    usb_transfer_batch_create(ep, data, size, setup_data,
-	    in, out, arg, fun, NULL, NULL);
-	if (!batch) {
-		return ENOMEM;
-	}
-
-	const int ret = hcd->schedule(hcd, batch);
-	if (ret != EOK)
-		usb_transfer_batch_destroy(batch);
-
-	return ret;
-}
-
-/** Calls ep_add_hook upon endpoint registration.
- * @param ep Endpoint to be registered.
- * @param arg hcd_t in disguise.
- * @return Error code.
- */
-static int register_helper(endpoint_t *ep, void *arg)
-{
-	hcd_t *hcd = arg;
-	assert(ep);
-	assert(hcd);
-	if (hcd->ep_add_hook)
-		return hcd->ep_add_hook(hcd, ep);
-	return EOK;
-}
-
-/** Calls ep_remove_hook upon endpoint removal.
- * @param ep Endpoint to be unregistered.
- * @param arg hcd_t in disguise.
- */
-static void unregister_helper(endpoint_t *ep, void *arg)
-{
-	hcd_t *hcd = arg;
-	assert(ep);
-	assert(hcd);
-	if (hcd->ep_remove_hook)
-		hcd->ep_remove_hook(hcd, ep);
-}
-
-/** Calls ep_remove_hook upon endpoint removal. Prints warning.
- * @param ep Endpoint to be unregistered.
- * @param arg hcd_t in disguise.
- */
-static void unregister_helper_warn(endpoint_t *ep, void *arg)
-{
-	hcd_t *hcd = arg;
-	assert(ep);
-	assert(hcd);
-	usb_log_warning("Endpoint %d:%d %s was left behind, removing.\n",
-	    ep->address, ep->endpoint, usb_str_direction(ep->direction));
-	if (hcd->ep_remove_hook)
-		hcd->ep_remove_hook(hcd, ep);
-}
-
-/** Request address interface function.
- *
- * @param[in] fun DDF function that was called.
- * @param[in] address Pointer to preferred USB address.
- * @param[out] address Place to write a new address.
- * @param[in] strict Fail if the preferred address is not available.
- * @param[in] speed Speed to associate with the new default address.
- * @return Error code.
- */
-static int request_address(
-    ddf_fun_t *fun, usb_address_t *address, bool strict, usb_speed_t speed)
-{
-	assert(fun);
-	hcd_t *hcd = fun_to_hcd(fun);
-	assert(hcd);
-	assert(address);
-
-	usb_log_debug("Address request: speed: %s, address: %d, strict: %s.\n",
-	    usb_str_speed(speed), *address, strict ? "YES" : "NO");
-	return usb_device_manager_request_address(
-	    &hcd->dev_manager, address, strict, speed);
-}
-
-/** Bind address interface function.
- *
- * @param[in] fun DDF function that was called.
- * @param[in] address Address of the device
- * @param[in] handle Devman handle of the device driver.
- * @return Error code.
- */
-static int bind_address(
-    ddf_fun_t *fun, usb_address_t address, devman_handle_t handle)
-{
-	assert(fun);
-	hcd_t *hcd = fun_to_hcd(fun);
-	assert(hcd);
-
-	usb_log_debug("Address bind %d-%" PRIun ".\n", address, handle);
-	return usb_device_manager_bind_address(
-	    &hcd->dev_manager, address, handle);
-}
-
-/** Find device handle by address interface function.
- *
- * @param[in] fun DDF function that was called.
- * @param[in] address Address in question.
- * @param[out] handle Where to store device handle if found.
- * @return Error code.
- */
-static int find_by_address(ddf_fun_t *fun, usb_address_t address,
-    devman_handle_t *handle)
-{
-	assert(fun);
-	hcd_t *hcd = fun_to_hcd(fun);
-	assert(hcd);
-	return usb_device_manager_get_info_by_address(
-	    &hcd->dev_manager, address, handle, NULL);
-}
-
-/** Release address interface function.
- *
- * @param[in] fun DDF function that was called.
- * @param[in] address USB address to be released.
- * @return Error code.
- */
-static int release_address(ddf_fun_t *fun, usb_address_t address)
-{
-	assert(fun);
-	hcd_t *hcd = fun_to_hcd(fun);
-	assert(hcd);
-	usb_log_debug("Address release %d.\n", address);
-	usb_device_manager_release_address(&hcd->dev_manager, address);
-	usb_endpoint_manager_remove_address(&hcd->ep_manager, address,
-	    unregister_helper_warn, hcd);
-	return EOK;
-}
-
-/** Register endpoint interface function.
- * @param fun DDF function.
- * @param address USB address of the device.
- * @param endpoint USB endpoint number to be registered.
- * @param transfer_type Endpoint's transfer type.
- * @param direction USB communication direction the endpoint is capable of.
- * @param max_packet_size Maximu size of packets the endpoint accepts.
- * @param interval Preferred timeout between communication.
- * @return Error code.
- */
-static int register_endpoint(
-    ddf_fun_t *fun, usb_address_t address, usb_endpoint_t endpoint,
-    usb_transfer_type_t transfer_type, usb_direction_t direction,
-    size_t max_packet_size, unsigned interval)
-{
-	assert(fun);
-	hcd_t *hcd = fun_to_hcd(fun);
-	assert(hcd);
-	const size_t size = max_packet_size;
-	usb_speed_t speed = USB_SPEED_MAX;
-	const int ret = usb_device_manager_get_info_by_address(
-	    &hcd->dev_manager, address, NULL, &speed);
-	if (ret != EOK) {
-		return ret;
-	}
-
-	usb_log_debug("Register endpoint %d:%d %s-%s %s %zuB %ums.\n",
-	    address, endpoint, usb_str_transfer_type(transfer_type),
-	    usb_str_direction(direction), usb_str_speed(speed),
-	    max_packet_size, interval);
-
-	return usb_endpoint_manager_add_ep(&hcd->ep_manager, address, endpoint,
-	    direction, transfer_type, speed, max_packet_size, size,
-	    register_helper, hcd);
-}
-
-/** Unregister endpoint interface function.
- * @param fun DDF function.
- * @param address USB address of the endpoint.
- * @param endpoint USB endpoint number.
- * @param direction Communication direction of the enpdoint to unregister.
- * @return Error code.
- */
-static int unregister_endpoint(
-    ddf_fun_t *fun, usb_address_t address,
-    usb_endpoint_t endpoint, usb_direction_t direction)
-{
-	assert(fun);
-	hcd_t *hcd = fun_to_hcd(fun);
-	assert(hcd);
-	usb_log_debug("Unregister endpoint %d:%d %s.\n",
-	    address, endpoint, usb_str_direction(direction));
-	return usb_endpoint_manager_remove_ep(&hcd->ep_manager, address,
-	    endpoint, direction, unregister_helper, hcd);
-}
-
-/** Inbound communication interface function.
- * @param fun DDF function.
- * @param target Communication target.
- * @param setup_data Data to use in setup stage (control transfers).
- * @param data Pointer to data buffer.
- * @param size Size of the data buffer.
- * @param callback Function to call on communication end.
- * @param arg Argument passed to the callback function.
- * @return Error code.
- */
-static int usb_read(ddf_fun_t *fun, usb_target_t target, uint64_t setup_data,
-    uint8_t *data, size_t size, usbhc_iface_transfer_in_callback_t callback,
-    void *arg)
-{
-	return send_batch(fun, target, USB_DIRECTION_IN, data, size,
-	    setup_data, callback, NULL, arg, "READ");
-}
-
-/** Outbound communication interface function.
- * @param fun DDF function.
- * @param target Communication target.
- * @param setup_data Data to use in setup stage (control transfers).
- * @param data Pointer to data buffer.
- * @param size Size of the data buffer.
- * @param callback Function to call on communication end.
- * @param arg Argument passed to the callback function.
- * @return Error code.
- */
-static int usb_write(ddf_fun_t *fun, usb_target_t target, uint64_t setup_data,
-    const uint8_t *data, size_t size,
-    usbhc_iface_transfer_out_callback_t callback, void *arg)
-{
-	return send_batch(fun, target, USB_DIRECTION_OUT, (uint8_t*)data, size,
-	    setup_data, NULL, callback, arg, "WRITE");
-}
-
-/** usbhc Interface implementation using hcd_t from libusbhost library. */
-usbhc_iface_t hcd_iface = {
-	.request_address = request_address,
-	.bind_address = bind_address,
-	.get_handle = find_by_address,
-	.release_address = release_address,
-
-	.register_endpoint = register_endpoint,
-	.unregister_endpoint = unregister_endpoint,
-
-	.read = usb_read,
-	.write = usb_write,
-};
-
-/**
- * @}
- */
Index: uspace/lib/usbhost/src/usb_device_manager.c
===================================================================
--- uspace/lib/usbhost/src/usb_device_manager.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ 	(revision )
@@ -1,242 +1,0 @@
-/*
- * Copyright (c) 2011 Jan Vesely
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-/** @addtogroup libusbhost
- * @{
- */
-/** @file
- * Device manager structure and functions (implementation).
- */
-#include <assert.h>
-#include <errno.h>
-#include <usb/debug.h>
-#include <usb/host/usb_device_manager.h>
-
-/** Get a free USB address
- *
- * @param[in] instance Device manager structure to use.
- * @return Free address, or error code.
- */
-static usb_address_t usb_device_manager_get_free_address(
-    usb_device_manager_t *instance)
-{
-
-	usb_address_t new_address = instance->last_address;
-	do {
-		new_address = (new_address + 1) % USB_ADDRESS_COUNT;
-		if (new_address == USB_ADDRESS_DEFAULT)
-			new_address = 1;
-		if (new_address == instance->last_address) {
-			return ENOSPC;
-		}
-	} while (instance->devices[new_address].occupied);
-
-	assert(new_address != USB_ADDRESS_DEFAULT);
-	instance->last_address = new_address;
-
-	return new_address;
-}
-
-/** Initialize device manager structure.
- *
- * @param[in] instance Memory place to initialize.
- * @param[in] max_speed Maximum allowed USB speed of devices (inclusive).
- *
- * Set all values to false/0.
- */
-void usb_device_manager_init(
-    usb_device_manager_t *instance, usb_speed_t max_speed)
-{
-	assert(instance);
-	for (unsigned i = 0; i < USB_ADDRESS_COUNT; ++i) {
-		instance->devices[i].occupied = false;
-		instance->devices[i].handle = 0;
-		instance->devices[i].speed = USB_SPEED_MAX;
-	}
-	instance->last_address = 1;
-	instance->max_speed = max_speed;
-	fibril_mutex_initialize(&instance->guard);
-}
-
-/** Request USB address.
- * @param instance usb_device_manager
- * @param address Pointer to requested address value, place to store new address
- * @parma strict Fail if the requested address is not available.
- * @return Error code.
- * @note Default address is only available in strict mode.
- */
-int usb_device_manager_request_address(usb_device_manager_t *instance,
-    usb_address_t *address, bool strict, usb_speed_t speed)
-{
-	assert(instance);
-	assert(address);
-	if (speed > instance->max_speed)
-		return ENOTSUP;
-
-	if ((*address) < 0 || (*address) >= USB_ADDRESS_COUNT)
-		return EINVAL;
-
-	fibril_mutex_lock(&instance->guard);
-	/* Only grant default address to strict requests */
-	if (( (*address) == USB_ADDRESS_DEFAULT) && !strict) {
-		*address = instance->last_address;
-	}
-
-	if (instance->devices[*address].occupied) {
-		if (strict) {
-			fibril_mutex_unlock(&instance->guard);
-			return ENOENT;
-		}
-		*address = usb_device_manager_get_free_address(instance);
-	}
-	assert(instance->devices[*address].occupied == false);
-	assert(instance->devices[*address].handle == 0);
-	assert(*address != USB_ADDRESS_DEFAULT || strict);
-
-	instance->devices[*address].occupied = true;
-	instance->devices[*address].speed = speed;
-
-	fibril_mutex_unlock(&instance->guard);
-	return EOK;
-}
-
-/** Bind USB address to devman handle.
- *
- * @param[in] instance Device manager structure to use.
- * @param[in] address Device address
- * @param[in] handle Devman handle of the device.
- * @return Error code.
- * @note Won't accept binding for default address.
- */
-int usb_device_manager_bind_address(usb_device_manager_t *instance,
-    usb_address_t address, devman_handle_t handle)
-{
-	if ((address <= 0) || (address >= USB_ADDRESS_COUNT)) {
-		return EINVAL;
-	}
-	assert(instance);
-
-	fibril_mutex_lock(&instance->guard);
-	/* Not reserved */
-	if (!instance->devices[address].occupied) {
-		fibril_mutex_unlock(&instance->guard);
-		return ENOENT;
-	}
-	/* Already bound */
-	if (instance->devices[address].handle != 0) {
-		fibril_mutex_unlock(&instance->guard);
-		return EEXISTS;
-	}
-	instance->devices[address].handle = handle;
-	fibril_mutex_unlock(&instance->guard);
-	return EOK;
-}
-
-/** Release used USB address.
- *
- * @param[in] instance Device manager structure to use.
- * @param[in] address Device address
- * @return Error code.
- */
-int usb_device_manager_release_address(
-    usb_device_manager_t *instance, usb_address_t address)
-{
-	if ((address < 0) || (address >= USB_ADDRESS_COUNT)) {
-		return EINVAL;
-	}
-	assert(instance);
-
-	fibril_mutex_lock(&instance->guard);
-	if (!instance->devices[address].occupied) {
-		fibril_mutex_unlock(&instance->guard);
-		return ENOENT;
-	}
-
-	instance->devices[address].occupied = false;
-	instance->devices[address].handle = 0;
-	fibril_mutex_unlock(&instance->guard);
-	return EOK;
-}
-
-/** Find USB address associated with the device.
- *
- * @param[in] instance Device manager structure to use.
- * @param[in] handle Devman handle of the device seeking its address.
- * @return USB Address, or error code.
- */
-usb_address_t usb_device_manager_find_address(
-    usb_device_manager_t *instance, devman_handle_t handle)
-{
-	assert(instance);
-	fibril_mutex_lock(&instance->guard);
-	for (usb_address_t address = 1; address <= USB11_ADDRESS_MAX; ++address)
-	{
-		if (instance->devices[address].handle == handle) {
-			assert(instance->devices[address].occupied);
-			fibril_mutex_unlock(&instance->guard);
-			return address;
-		}
-	}
-	fibril_mutex_unlock(&instance->guard);
-	return ENOENT;
-}
-
-/** Find devman handle and speed assigned to USB address.
- *
- * @param[in] instance Device manager structure to use.
- * @param[in] address Address the caller wants to find.
- * @param[out] handle Where to store found handle.
- * @param[out] speed Assigned speed.
- * @return Error code.
- */
-int usb_device_manager_get_info_by_address(usb_device_manager_t *instance,
-    usb_address_t address, devman_handle_t *handle, usb_speed_t *speed)
-{
-	assert(instance);
-	if ((address < 0) || (address >= USB_ADDRESS_COUNT)) {
-		return EINVAL;
-	}
-
-	fibril_mutex_lock(&instance->guard);
-	if (!instance->devices[address].occupied) {
-		fibril_mutex_unlock(&instance->guard);
-		return ENOENT;
-	}
-
-	if (handle != NULL) {
-		*handle = instance->devices[address].handle;
-	}
-	if (speed != NULL) {
-		*speed = instance->devices[address].speed;
-	}
-
-	fibril_mutex_unlock(&instance->guard);
-	return EOK;
-}
-/**
- * @}
- */
Index: uspace/lib/usbhost/src/usb_endpoint_manager.c
===================================================================
--- uspace/lib/usbhost/src/usb_endpoint_manager.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbhost/src/usb_endpoint_manager.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -36,4 +36,5 @@
 #include <assert.h>
 #include <errno.h>
+#include <macros.h>
 
 #include <usb/debug.h>
@@ -71,5 +72,5 @@
 	assert(instance);
 	assert(addr >= 0);
-	return &instance->endpoint_lists[addr % ENDPOINT_LIST_COUNT];
+	return &instance->devices[addr % ARRAY_SIZE(instance->devices)].endpoint_list;
 }
 
@@ -95,4 +96,28 @@
 	}
 	return NULL;
+}
+
+/** Get a free USB address
+ *
+ * @param[in] instance Device manager structure to use.
+ * @return Free address, or error code.
+ */
+static usb_address_t usb_endpoint_manager_get_free_address(
+    usb_endpoint_manager_t *instance)
+{
+
+	usb_address_t new_address = instance->last_address;
+	do {
+		new_address = (new_address + 1) % USB_ADDRESS_COUNT;
+		if (new_address == USB_ADDRESS_DEFAULT)
+			new_address = 1;
+		if (new_address == instance->last_address)
+			return ENOSPC;
+	} while (instance->devices[new_address].occupied);
+
+	assert(new_address != USB_ADDRESS_DEFAULT);
+	instance->last_address = new_address;
+
+	return new_address;
 }
 
@@ -155,6 +180,5 @@
  */
 int usb_endpoint_manager_init(usb_endpoint_manager_t *instance,
-    size_t available_bandwidth,
-    size_t (*bw_count)(usb_speed_t, usb_transfer_type_t, size_t, size_t))
+    size_t available_bandwidth, bw_count_func_t bw_count, usb_speed_t max_speed)
 {
 	assert(instance);
@@ -162,67 +186,12 @@
 	instance->free_bw = available_bandwidth;
 	instance->bw_count = bw_count;
-	for (unsigned i = 0; i < ENDPOINT_LIST_COUNT; ++i) {
-		list_initialize(&instance->endpoint_lists[i]);
+	instance->last_address = 0;
+	instance->max_speed = max_speed;
+	for (unsigned i = 0; i < ARRAY_SIZE(instance->devices); ++i) {
+		list_initialize(&instance->devices[i].endpoint_list);
+		instance->devices[i].speed = USB_SPEED_MAX;
+		instance->devices[i].occupied = false;
 	}
 	return EOK;
-}
-
-/** Check setup packet data for signs of toggle reset.
- *
- * @param[in] instance usb_endpoint_manager structure, non-null.
- * @param[in] target Device to receive setup packet.
- * @param[in] data Setup packet data.
- *
- * Really ugly one. Resets toggle bit on all endpoints that need it.
- * @TODO Use tools from libusbdev requests.h
- */
-void usb_endpoint_manager_reset_eps_if_need(usb_endpoint_manager_t *instance,
-    usb_target_t target, const uint8_t data[8])
-{
-	assert(instance);
-	if (!usb_target_is_valid(target)) {
-		usb_log_error("Invalid data when checking for toggle reset.\n");
-		return;
-	}
-
-	assert(data);
-	switch (data[1])
-	{
-	case 0x01: /* Clear Feature -- resets only cleared ep */
-		/* Recipient is endpoint, value is zero (ENDPOINT_STALL) */
-		// TODO Use macros in libusbdev requests.h
-		if (((data[0] & 0xf) == 1) && ((data[2] | data[3]) == 0)) {
-			fibril_mutex_lock(&instance->guard);
-			/* endpoint number is < 16, thus first byte is enough */
-			list_foreach(*get_list(instance, target.address),
-			    link, endpoint_t, ep) {
-				if ((ep->address == target.address)
-				    && (ep->endpoint = data[4])) {
-					endpoint_toggle_set(ep,0);
-				}
-			}
-			fibril_mutex_unlock(&instance->guard);
-		}
-	break;
-
-	case 0x9: /* Set Configuration */
-	case 0x11: /* Set Interface */
-		/* Recipient must be device, this resets all endpoints,
-		 * In fact there should be no endpoints but EP 0 registered
-		 * as different interfaces use different endpoints,
-		 * unless you're changing configuration or alternative
-		 * interface of an already setup device. */
-		if ((data[0] & 0xf) == 0) {
-			fibril_mutex_lock(&instance->guard);
-			list_foreach(*get_list(instance, target.address),
-			    link, endpoint_t, ep) {
-				if (ep->address == target.address) {
-					endpoint_toggle_set(ep,0);
-				}
-			}
-			fibril_mutex_unlock(&instance->guard);
-		}
-	break;
-	}
 }
 
@@ -316,21 +285,20 @@
 int usb_endpoint_manager_add_ep(usb_endpoint_manager_t *instance,
     usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction,
-    usb_transfer_type_t type, usb_speed_t speed, size_t max_packet_size,
-    size_t data_size, int (*callback)(endpoint_t *, void *), void *arg)
+    usb_transfer_type_t type, size_t max_packet_size, size_t data_size,
+    ep_add_callback_t callback, void *arg, usb_address_t tt_address,
+    unsigned tt_port)
 {
 	assert(instance);
 	if (instance->bw_count == NULL)
 		return ENOTSUP;
-	if (address < 0)
-		return EINVAL;
-
-	const size_t bw =
-	    instance->bw_count(speed, type, data_size, max_packet_size);
-
-	fibril_mutex_lock(&instance->guard);
-	/* Check for available bandwidth */
-	if (bw > instance->free_bw) {
-		fibril_mutex_unlock(&instance->guard);
-		return ENOSPC;
+	if (!usb_address_is_valid(address))
+		return EINVAL;
+
+
+	fibril_mutex_lock(&instance->guard);
+	/* Check for speed and address */
+	if (!instance->devices[address].occupied) {
+		fibril_mutex_unlock(&instance->guard);
+		return ENOENT;
 	}
 
@@ -342,6 +310,16 @@
 	}
 
-	ep = endpoint_create(
-	    address, endpoint, direction, type, speed, max_packet_size, bw);
+	const usb_speed_t speed = instance->devices[address].speed;
+	const size_t bw =
+	    instance->bw_count(speed, type, data_size, max_packet_size);
+
+	/* Check for available bandwidth */
+	if (bw > instance->free_bw) {
+		fibril_mutex_unlock(&instance->guard);
+		return ENOSPC;
+	}
+
+	ep = endpoint_create(address, endpoint, direction, type, speed,
+	    max_packet_size, bw, tt_address, tt_port);
 	if (!ep) {
 		fibril_mutex_unlock(&instance->guard);
@@ -375,5 +353,5 @@
 int usb_endpoint_manager_remove_ep(usb_endpoint_manager_t *instance,
     usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction,
-    void (*callback)(endpoint_t *, void *), void *arg)
+    ep_remove_callback_t callback, void *arg)
 {
 	assert(instance);
@@ -393,4 +371,25 @@
 	endpoint_destroy(ep);
 	return EOK;
+}
+
+int usb_endpoint_manager_reset_toggle(usb_endpoint_manager_t *instance,
+    usb_target_t target, bool all)
+{
+	assert(instance);
+	if (!usb_target_is_valid(target))
+		return EINVAL;
+
+	int ret = ENOENT;
+
+	fibril_mutex_lock(&instance->guard);
+	list_foreach(*get_list(instance, target.address), link, endpoint_t, ep) {
+		if ((ep->address == target.address)
+		    && (all || ep->endpoint == target.endpoint)) {
+			endpoint_toggle_set(ep, 0);
+			ret = EOK;
+		}
+	}
+	fibril_mutex_unlock(&instance->guard);
+	return ret;
 }
 
@@ -404,21 +403,20 @@
  * @return Error code.
  */
-void usb_endpoint_manager_remove_address(usb_endpoint_manager_t *instance,
-    usb_address_t address, void (*callback)(endpoint_t *, void *), void *arg)
-{
-	list_t *list;
-	link_t *link;
-	link_t *next;
-
-	assert(address >= 0);
-	assert(instance);
-	fibril_mutex_lock(&instance->guard);
-
-	list = get_list(instance, address);
-	link = list_first(list);
-	while (link != NULL) {
+int usb_endpoint_manager_remove_address(usb_endpoint_manager_t *instance,
+    usb_address_t address, ep_remove_callback_t callback, void *arg)
+{
+	assert(instance);
+	if (!usb_address_is_valid(address))
+		return EINVAL;
+
+	fibril_mutex_lock(&instance->guard);
+
+	const int ret = instance->devices[address].occupied ? EOK : ENOENT;
+	instance->devices[address].occupied = false;
+
+	list_t *list = get_list(instance, address);
+	for (link_t *link = list_first(list); link != NULL; ) {
 		endpoint_t *ep = list_get_instance(link, endpoint_t, link);
-		next = list_next(link, list);
-
+		link = list_next(link, list);
 		if (ep->address == address) {
 			list_remove(&ep->link);
@@ -427,7 +425,80 @@
 			endpoint_destroy(ep);
 		}
-		link = next;
-	}
-	fibril_mutex_unlock(&instance->guard);
+	}
+	fibril_mutex_unlock(&instance->guard);
+	return ret;
+}
+
+/** Request USB address.
+ * @param instance usb_device_manager
+ * @param address Pointer to requested address value, place to store new address
+ * @parma strict Fail if the requested address is not available.
+ * @return Error code.
+ * @note Default address is only available in strict mode.
+ */
+int usb_endpoint_manager_request_address(usb_endpoint_manager_t *instance,
+    usb_address_t *address, bool strict, usb_speed_t speed)
+{
+	assert(instance);
+	assert(address);
+	if (speed > instance->max_speed)
+		return ENOTSUP;
+
+	if (!usb_address_is_valid(*address))
+		return EINVAL;
+
+	usb_address_t addr = *address;
+
+	fibril_mutex_lock(&instance->guard);
+	/* Only grant default address to strict requests */
+	if ((addr == USB_ADDRESS_DEFAULT) && !strict) {
+		addr = usb_endpoint_manager_get_free_address(instance);
+	}
+
+	if (instance->devices[addr].occupied) {
+		if (strict) {
+			fibril_mutex_unlock(&instance->guard);
+			return ENOENT;
+		}
+		addr = usb_endpoint_manager_get_free_address(instance);
+	}
+	if (usb_address_is_valid(addr)) {
+		assert(instance->devices[addr].occupied == false);
+		assert(addr != USB_ADDRESS_DEFAULT || strict);
+
+		instance->devices[addr].occupied = true;
+		instance->devices[addr].speed = speed;
+		*address = addr;
+		addr = 0;
+	}
+
+	fibril_mutex_unlock(&instance->guard);
+	return addr;
+}
+
+/** Get speed assigned to USB address.
+ *
+ * @param[in] instance Device manager structure to use.
+ * @param[in] address Address the caller wants to find.
+ * @param[out] speed Assigned speed.
+ * @return Error code.
+ */
+int usb_endpoint_manager_get_speed(usb_endpoint_manager_t *instance,
+    usb_address_t address, usb_speed_t *speed)
+{
+	assert(instance);
+	if (!usb_address_is_valid(address)) {
+		return EINVAL;
+	}
+
+	fibril_mutex_lock(&instance->guard);
+
+	const int ret = instance->devices[address].occupied ? EOK : ENOENT;
+	if (speed && instance->devices[address].occupied) {
+		*speed = instance->devices[address].speed;
+	}
+
+	fibril_mutex_unlock(&instance->guard);
+	return ret;
 }
 /**
Index: uspace/lib/usbhost/src/usb_transfer_batch.c
===================================================================
--- uspace/lib/usbhost/src/usb_transfer_batch.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbhost/src/usb_transfer_batch.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -61,8 +61,5 @@
     usbhc_iface_transfer_in_callback_t func_in,
     usbhc_iface_transfer_out_callback_t func_out,
-    void *arg,
-    ddf_fun_t *fun,
-    void *private_data,
-    void (*private_data_dtor)(void *)
+    void *arg
     )
 {
@@ -81,7 +78,4 @@
 		instance->buffer_size = buffer_size;
 		instance->setup_size = 0;
-		instance->fun = fun;
-		instance->private_data = private_data;
-		instance->private_data_dtor = private_data_dtor;
 		instance->transfered_size = 0;
 		instance->error = EOK;
@@ -110,8 +104,4 @@
 		endpoint_release(instance->ep);
 	}
-	if (instance->private_data) {
-		assert(instance->private_data_dtor);
-		instance->private_data_dtor(instance->private_data);
-	}
 	free(instance);
 }
@@ -133,13 +123,5 @@
 	/* NOTE: Only one of these pointers should be set. */
         if (instance->callback_out) {
-		/* Check for commands that reset toggle bit */
-		if (instance->ep->transfer_type == USB_TRANSFER_CONTROL
-		    && error == EOK) {
-			const usb_target_t target =
-			    {{ instance->ep->address, instance->ep->endpoint }};
-			reset_ep_if_need(fun_to_hcd(instance->fun), target,
-			    instance->setup_buffer);
-		}
-		instance->callback_out(instance->fun, error, instance->arg);
+		instance->callback_out(error, instance->arg);
 	}
 
@@ -150,6 +132,5 @@
 	                memcpy(instance->buffer, data, safe_size);
 		}
-		instance->callback_in(instance->fun, error,
-		    safe_size, instance->arg);
+		instance->callback_in(error, safe_size, instance->arg);
 	}
 }
Index: uspace/lib/usbvirt/Makefile
===================================================================
--- uspace/lib/usbvirt/Makefile	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbvirt/Makefile	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -34,5 +34,6 @@
 	-I$(LIBUSB_PREFIX)/include \
 	-I$(LIBUSBDEV_PREFIX)/include \
-	-Iinclude
+	-Iinclude \
+	-Iinclude/usbvirt
 
 SOURCES = \
@@ -42,5 +43,7 @@
 	src/ipc_hc.c \
 	src/stdreq.c \
-	src/transfer.c
+	src/transfer.c \
+	src/virthub_base.c \
+	src/virthub_descriptors.c
 
 include $(USPACE_PREFIX)/Makefile.common
Index: uspace/lib/usbvirt/include/usbvirt/device.h
===================================================================
--- uspace/lib/usbvirt/include/usbvirt/device.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbvirt/include/usbvirt/device.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -40,4 +40,6 @@
 #include <usb/dev/request.h>
 #include <async.h>
+#include <errno.h>
+
 
 /** Maximum number of endpoints supported by virtual USB. */
@@ -57,5 +59,5 @@
 typedef int (*usbvirt_on_data_to_device_t)(usbvirt_device_t *dev,
     usb_endpoint_t endpoint, usb_transfer_type_t transfer_type,
-    void *buffer, size_t buffer_size);
+    const void *buffer, size_t buffer_size);
 
 /** Callback for data from device (IN transaction).
@@ -88,4 +90,40 @@
     uint8_t *data, size_t *act_data_size);
 
+/** Create a class request to get data from device
+ *
+ * @param rec Request recipient.
+ * @param req Request code.
+ */
+#define CLASS_REQ_IN(rec, req) \
+	.request_type = SETUP_REQUEST_TO_HOST(USB_REQUEST_TYPE_CLASS, rec), \
+	.request = req
+
+/** Create a class request to send data to device
+ *
+ * @param rec Request recipient.
+ * @param req Request code.
+ */
+#define CLASS_REQ_OUT(rec, req) \
+	.request_type = SETUP_REQUEST_TO_DEVICE(USB_REQUEST_TYPE_CLASS, rec), \
+	.request = req
+
+/** Create a standard request to get data from device
+ *
+ * @param rec Request recipient.
+ * @param req Request code.
+ */
+#define STD_REQ_IN(rec, req) \
+	.request_type = SETUP_REQUEST_TO_HOST(USB_REQUEST_TYPE_STANDARD, rec), \
+	.request = req
+
+/** Create a standard request to send data to device
+ *
+ * @param rec Request recipient.
+ * @param req Request code.
+ */
+#define STD_REQ_OUT(rec, req) \
+	.request_type = SETUP_REQUEST_TO_DEVICE(USB_REQUEST_TYPE_STANDARD, rec), \
+	.request = req
+
 /** Callback for control request on a virtual USB device.
  *
@@ -94,10 +132,6 @@
  */
 typedef struct {
-	/** Request direction (in or out). */
-	usb_direction_t req_direction;
-	/** Request recipient (device, interface or endpoint). */
-	usb_request_recipient_t req_recipient;
-	/** Request type (standard, class or vendor). */
-	usb_request_type_t req_type;
+	/* Request type. See usb/request.h */
+	uint8_t request_type;
 	/** Actual request code. */
 	uint8_t request;
@@ -111,5 +145,5 @@
 typedef struct {
 	/** Actual data. */
-	uint8_t *data;
+	const uint8_t *data;
 	/** Data length. */
 	size_t length;
@@ -121,5 +155,5 @@
 	usb_standard_configuration_descriptor_t *descriptor;
 	/** Array of extra data. */
-	usbvirt_device_configuration_extras_t *extra;
+	const usbvirt_device_configuration_extras_t *extra;
 	/** Length of @c extra array. */
 	size_t extra_count;
@@ -131,5 +165,5 @@
 	 * There is always only one such descriptor for the device.
 	 */
-	usb_standard_device_descriptor_t *device;
+	const usb_standard_device_descriptor_t *device;
 
 	/** Configurations. */
@@ -164,5 +198,5 @@
 	 * Last handler is expected to have the @c callback field set to NULL
 	 */
-	usbvirt_control_request_handler_t *control;
+	const usbvirt_control_request_handler_t *control;
 	/** Callback when device changes state.
 	 *
@@ -180,4 +214,8 @@
 /** Virtual USB device. */
 struct usbvirt_device {
+	/** Device does not require USB bus power */
+	bool self_powered;
+	/** Device is allowed to signal remote wakeup */
+	bool remote_wakeup;
 	/** Name for debugging purposes. */
 	const char *name;
@@ -187,5 +225,5 @@
 	usbvirt_device_ops_t *ops;
 	/** Device descriptors. */
-	usbvirt_descriptors_t *descriptors;
+	const usbvirt_descriptors_t *descriptors;
 	/** Current device address.
 	 * You shall treat this field as read only in your code.
@@ -202,14 +240,19 @@
 };
 
+
+int req_nop(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet,
+    uint8_t *data, size_t *act_size);
+
 int usbvirt_device_plug(usbvirt_device_t *, const char *);
 void usbvirt_device_unplug(usbvirt_device_t *);
 
 void usbvirt_control_reply_helper(const usb_device_request_setup_packet_t *,
-    uint8_t *, size_t *, void *, size_t);
-
-int usbvirt_control_write(usbvirt_device_t *, void *, size_t, void *, size_t);
-int usbvirt_control_read(usbvirt_device_t *, void *, size_t, void *, size_t, size_t *);
+    uint8_t *, size_t *, const void *, size_t);
+
+int usbvirt_control_write(usbvirt_device_t *, const void *, size_t, void *, size_t);
+int usbvirt_control_read(usbvirt_device_t *, const void *, size_t, void *, size_t, size_t *);
 int usbvirt_data_out(usbvirt_device_t *, usb_transfer_type_t, usb_endpoint_t,
-    void *, size_t);
+    const void *, size_t);
 int usbvirt_data_in(usbvirt_device_t *, usb_transfer_type_t, usb_endpoint_t,
     void *, size_t, size_t *);
Index: uspace/lib/usbvirt/include/usbvirt/virthub_base.h
===================================================================
--- uspace/lib/usbvirt/include/usbvirt/virthub_base.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
+++ uspace/lib/usbvirt/include/usbvirt/virthub_base.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2013 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libusbvirt
+ * @{
+ */
+/** @file
+ * Virtual USB device.
+ */
+
+#ifndef LIBUSBVIRT_VIRTHUB_BASE_H_
+#define LIBUSBVIRT_VIRTHUB_BASE_H_
+
+#include <usbvirt/device.h>
+#include <usb/classes/hub.h>
+
+enum {
+	VIRTHUB_EXTR_DESC = 3,
+};
+
+typedef struct {
+	usb_standard_configuration_descriptor_t config_descriptor;
+	usb_standard_endpoint_descriptor_t endpoint_descriptor;
+	usbvirt_device_configuration_extras_t extra[VIRTHUB_EXTR_DESC];
+	usbvirt_device_configuration_t configuration;
+	usbvirt_descriptors_t descriptors;
+	usbvirt_device_t device;
+	void *data;
+} virthub_base_t;
+
+void *virthub_get_data(usbvirt_device_t *dev);
+
+int virthub_base_init(virthub_base_t *instance,
+    const char *name, usbvirt_device_ops_t *ops, void *data,
+    const usb_standard_device_descriptor_t *device_desc,
+    const usb_hub_descriptor_header_t *hub_desc, usb_endpoint_t ep);
+
+usb_address_t virthub_base_get_address(virthub_base_t *instance);
+
+int virthub_base_request(virthub_base_t *instance, usb_target_t target,
+    usb_direction_t dir, const usb_device_request_setup_packet_t *setup,
+    void *buffer, size_t buffer_size, size_t *real_size);
+
+int virthub_base_get_hub_descriptor(usbvirt_device_t *dev,
+    const usb_device_request_setup_packet_t *request, uint8_t *data,
+    size_t *act_size);
+int virthub_base_get_null_status(usbvirt_device_t *dev,
+    const usb_device_request_setup_packet_t *request, uint8_t *data,
+    size_t *act_size);
+
+
+#endif
+
+/**
+ * @}
+ */
Index: uspace/lib/usbvirt/src/ctrltransfer.c
===================================================================
--- uspace/lib/usbvirt/src/ctrltransfer.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbvirt/src/ctrltransfer.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -50,6 +50,6 @@
  */
 int process_control_transfer(usbvirt_device_t *dev,
-    usbvirt_control_request_handler_t *control_handlers,
-    usb_device_request_setup_packet_t *setup,
+    const usbvirt_control_request_handler_t *control_handlers,
+    const usb_device_request_setup_packet_t *setup,
     uint8_t *data, size_t *data_sent_size)
 {
@@ -60,23 +60,9 @@
 		return EFORWARD;
 	}
-
-	usb_direction_t direction = setup->request_type & 128 ?
-	    USB_DIRECTION_IN : USB_DIRECTION_OUT;
-	usb_request_recipient_t req_recipient = setup->request_type & 31;
-	usb_request_type_t req_type = (setup->request_type >> 5) & 3;
-
-	usbvirt_control_request_handler_t *handler = control_handlers;
-	while (handler->callback != NULL) {
-		if (handler->req_direction != direction) {
-			goto next;
-		}
-		if (handler->req_recipient != req_recipient) {
-			goto next;
-		}
-		if (handler->req_type != req_type) {
-			goto next;
-		}
-		if (handler->request != setup->request) {
-			goto next;
+	const usbvirt_control_request_handler_t *handler = control_handlers;
+	for (;handler->callback != NULL; ++handler) {
+		if (handler->request != setup->request ||
+		    handler->request_type != setup->request_type) {
+			continue;
 		}
 
@@ -84,12 +70,8 @@
 		    usb_debug_str_buffer((uint8_t*) setup, sizeof(*setup), 0));
 		int rc = handler->callback(dev, setup, data, data_sent_size);
-		if (rc == EFORWARD) {
-			goto next;
+		if (rc != EFORWARD) {
+			return rc;
 		}
 
-		return rc;
-
-next:
-		handler++;
 	}
 
Index: uspace/lib/usbvirt/src/private.h
===================================================================
--- uspace/lib/usbvirt/src/private.h	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbvirt/src/private.h	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -39,6 +39,6 @@
 
 int process_control_transfer(usbvirt_device_t *,
-    usbvirt_control_request_handler_t *,
-    usb_device_request_setup_packet_t *,
+    const usbvirt_control_request_handler_t *,
+    const usb_device_request_setup_packet_t *,
     uint8_t *, size_t *);
 
Index: uspace/lib/usbvirt/src/stdreq.c
===================================================================
--- uspace/lib/usbvirt/src/stdreq.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbvirt/src/stdreq.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -51,5 +51,5 @@
 void usbvirt_control_reply_helper(const usb_device_request_setup_packet_t *setup_packet,
     uint8_t *data, size_t *act_size,
-    void *actual_data, size_t actual_data_size)
+    const void *actual_data, size_t actual_data_size)
 {
 	size_t expected_size = setup_packet->length;
@@ -63,4 +63,12 @@
 		*act_size = actual_data_size;
 	}
+}
+
+/** NOP handler */
+int req_nop(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet,
+    uint8_t *data, size_t *act_size)
+{
+	return EOK;
 }
 
@@ -98,6 +106,6 @@
 		}
 		/* Copy the data. */
-		usbvirt_device_configuration_t *config = &device->descriptors
-		    ->configuration[index];
+		const usbvirt_device_configuration_t *config =
+		    &device->descriptors->configuration[index];
 		uint8_t *all_data = malloc(config->descriptor->total_length);
 		if (all_data == NULL) {
@@ -110,5 +118,5 @@
 		size_t i;
 		for (i = 0; i < config->extra_count; i++) {
-			usbvirt_device_configuration_extras_t *extra
+			const usbvirt_device_configuration_extras_t *extra
 			    = &config->extra[i];
 			memcpy(ptr, extra->data, extra->length);
@@ -189,31 +197,58 @@
 }
 
+static int req_get_dev_status(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet, uint8_t *data, size_t *act_size)
+{
+	if (setup_packet->length != 2)
+		return ESTALL;
+	data[0] = (device->self_powered ? 1 : 0) | (device->remote_wakeup ? 2 : 0);
+	data[1] = 0;
+	*act_size = 2;
+	return EOK;
+}
+static int req_get_iface_ep_status(usbvirt_device_t *device,
+    const usb_device_request_setup_packet_t *setup_packet, uint8_t *data, size_t *act_size)
+{
+	if (setup_packet->length != 2)
+		return ESTALL;
+	data[0] = 0;
+	data[1] = 0;
+	*act_size = 2;
+	return EOK;
+}
+
 /** Standard request handlers. */
 usbvirt_control_request_handler_t library_handlers[] = {
 	{
-		.req_direction = USB_DIRECTION_OUT,
-		.req_recipient = USB_REQUEST_RECIPIENT_DEVICE,
-		.req_type = USB_REQUEST_TYPE_STANDARD,
-		.request = USB_DEVREQ_SET_ADDRESS,
+		STD_REQ_OUT(USB_REQUEST_RECIPIENT_DEVICE, USB_DEVREQ_SET_ADDRESS),
 		.name = "SetAddress",
 		.callback = req_set_address
 	},
 	{
-		.req_direction = USB_DIRECTION_IN,
-		.req_recipient = USB_REQUEST_RECIPIENT_DEVICE,
-		.req_type = USB_REQUEST_TYPE_STANDARD,
-		.request = USB_DEVREQ_GET_DESCRIPTOR,
+		STD_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_DEVREQ_GET_DESCRIPTOR),
 		.name = "GetDescriptor",
 		.callback = req_get_descriptor
 	},
 	{
-		.req_direction = USB_DIRECTION_OUT,
-		.req_recipient = USB_REQUEST_RECIPIENT_DEVICE,
-		.req_type = USB_REQUEST_TYPE_STANDARD,
-		.request = USB_DEVREQ_SET_CONFIGURATION,
+		STD_REQ_OUT(USB_REQUEST_RECIPIENT_DEVICE, USB_DEVREQ_SET_CONFIGURATION),
 		.name = "SetConfiguration",
 		.callback = req_set_configuration
 	},
-
+	{
+		STD_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_DEVREQ_GET_STATUS),
+		.name = "GetDeviceStatus",
+		.callback = req_get_dev_status,
+	},
+	{
+		STD_REQ_IN(USB_REQUEST_RECIPIENT_INTERFACE, USB_DEVREQ_GET_STATUS),
+		.name = "GetInterfaceStatus",
+		.callback = req_get_iface_ep_status,
+	},
+	{
+		/* virtual EPs by default cannot be stalled */
+		STD_REQ_IN(USB_REQUEST_RECIPIENT_ENDPOINT, USB_DEVREQ_GET_STATUS),
+		.name = "GetEndpointStatus",
+		.callback = req_get_iface_ep_status,
+	},
 	{ .callback = NULL }
 };
Index: uspace/lib/usbvirt/src/transfer.c
===================================================================
--- uspace/lib/usbvirt/src/transfer.c	(revision 1c0cef08b9f78743c012e71181a38265e7dec433)
+++ uspace/lib/usbvirt/src/transfer.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -51,5 +51,5 @@
  */
 static int usbvirt_control_transfer(usbvirt_device_t *dev,
-    void *setup, size_t setup_size,
+    const void *setup, size_t setup_size,
     void *data, size_t data_size, size_t *data_size_sent)
 {
@@ -60,5 +60,5 @@
 		return ESTALL;
 	}
-	usb_device_request_setup_packet_t *setup_packet = setup;
+	const usb_device_request_setup_packet_t *setup_packet = setup;
 	if (data_size != setup_packet->length) {
 		return ESTALL;
@@ -100,6 +100,6 @@
  * @return Error code.
  */
-int usbvirt_control_write(usbvirt_device_t *dev, void *setup, size_t setup_size,
-    void *data, size_t data_size)
+int usbvirt_control_write(usbvirt_device_t *dev, const void *setup,
+    size_t setup_size, void *data, size_t data_size)
 {
 	return usbvirt_control_transfer(dev, setup, setup_size,
@@ -119,5 +119,5 @@
  * @return Error code.
  */
-int usbvirt_control_read(usbvirt_device_t *dev, void *setup, size_t setup_size,
+int usbvirt_control_read(usbvirt_device_t *dev, const void *setup, size_t setup_size,
     void *data, size_t data_size, size_t *data_size_sent)
 {
@@ -136,5 +136,5 @@
  */
 int usbvirt_data_out(usbvirt_device_t *dev, usb_transfer_type_t transf_type,
-    usb_endpoint_t endpoint, void *data, size_t data_size)
+    usb_endpoint_t endpoint, const void *data, size_t data_size)
 {
 	if ((endpoint <= 0) || (endpoint >= USBVIRT_ENDPOINT_MAX)) {
Index: uspace/lib/usbvirt/src/virthub_base.c
===================================================================
--- uspace/lib/usbvirt/src/virthub_base.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
+++ uspace/lib/usbvirt/src/virthub_base.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -0,0 +1,175 @@
+/*
+ * Copyright (c) 2013 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libusbvirt
+ * @{
+ */
+/** @file
+ * Virtual USB device main routines.
+ */
+
+#include <assert.h>
+#include <macros.h>
+#include <str.h>
+#include <usb/classes/hub.h>
+
+#include "virthub_base.h"
+
+extern const usb_standard_device_descriptor_t virthub_device_descriptor;
+extern const usb_standard_configuration_descriptor_t virthub_configuration_descriptor_without_hub_size;
+extern const usb_standard_endpoint_descriptor_t virthub_endpoint_descriptor;
+extern const usbvirt_device_configuration_extras_t virthub_interface_descriptor_ex;
+
+void *virthub_get_data(usbvirt_device_t *dev)
+{
+	assert(dev);
+	virthub_base_t *base = dev->device_data;
+	assert(base);
+	return base->data;
+}
+
+int virthub_base_init(virthub_base_t *instance, const char *name,
+    usbvirt_device_ops_t *ops, void *data,
+    const usb_standard_device_descriptor_t *device_desc,
+    const usb_hub_descriptor_header_t *hub_desc, usb_endpoint_t ep)
+{
+	assert(instance);
+	assert(hub_desc);
+	assert(name);
+
+	if (!usb_endpoint_is_valid(ep) || (ep == USB_ENDPOINT_DEFAULT_CONTROL))
+		return EINVAL;
+
+	instance->config_descriptor =
+	    virthub_configuration_descriptor_without_hub_size;
+	instance->config_descriptor.total_length += hub_desc->length;
+
+	instance->endpoint_descriptor = virthub_endpoint_descriptor;
+	instance->endpoint_descriptor.endpoint_address = 128 | ep;
+	instance->endpoint_descriptor.max_packet_size =
+	    STATUS_BYTES(hub_desc->port_count);
+
+	instance->descriptors.device =
+	    device_desc ? device_desc : &virthub_device_descriptor;
+	instance->descriptors.configuration = &instance->configuration;
+	instance->descriptors.configuration_count = 1;
+
+	instance->configuration.descriptor = &instance->config_descriptor;
+	instance->configuration.extra = instance->extra;
+	instance->configuration.extra_count = ARRAY_SIZE(instance->extra);
+
+	instance->extra[0] = virthub_interface_descriptor_ex;
+	instance->extra[1].data = (void *)hub_desc;
+	instance->extra[1].length = hub_desc->length;
+	instance->extra[2].data = (void*)&instance->endpoint_descriptor;
+	instance->extra[2].length = sizeof(instance->endpoint_descriptor);
+
+	instance->device.ops = ops;
+	instance->device.descriptors = &instance->descriptors;
+	instance->device.device_data = instance;
+	instance->device.address = 0;
+	instance->data = data;
+	instance->device.name = str_dup(name);
+
+	if (!instance->device.name)
+		return ENOMEM;
+
+	return EOK;
+}
+
+usb_address_t virthub_base_get_address(virthub_base_t *instance)
+{
+	assert(instance);
+	return instance->device.address;
+}
+
+int virthub_base_request(virthub_base_t *instance, usb_target_t target,
+    usb_direction_t dir, const usb_device_request_setup_packet_t *setup,
+    void *buffer, size_t buffer_size, size_t *real_size)
+{
+	assert(instance);
+	assert(real_size);
+	assert(setup);
+
+	if (target.address != virthub_base_get_address(instance))
+		return ENOENT;
+
+	switch (dir) {
+	case USB_DIRECTION_IN:
+		if (target.endpoint == 0) {
+			return usbvirt_control_read(&instance->device,
+			    setup, sizeof(*setup), buffer, buffer_size,
+			    real_size);
+		} else {
+			return usbvirt_data_in(&instance->device,
+			    USB_TRANSFER_INTERRUPT, target.endpoint,
+			    buffer, buffer_size, real_size);
+		}
+	case USB_DIRECTION_OUT:
+		if (target.endpoint == 0) {
+			return usbvirt_control_write(&instance->device,
+			    setup, sizeof(*setup), buffer, buffer_size);
+		}
+		/* fall through */
+	default:
+		return ENOTSUP;
+
+	}
+}
+
+int virthub_base_get_hub_descriptor(usbvirt_device_t *dev,
+    const usb_device_request_setup_packet_t *request, uint8_t *data,
+    size_t *act_size)
+{
+	assert(dev);
+	virthub_base_t *instance = dev->device_data;
+	assert(instance);
+	if (request->value_high == USB_DESCTYPE_HUB) {
+		usbvirt_control_reply_helper(request, data, act_size,
+		    instance->extra[1].data, instance->extra[1].length);
+		return EOK;
+	}
+	/* Let the framework handle all the rest. */
+	return EFORWARD;
+}
+
+int virthub_base_get_null_status(usbvirt_device_t *dev,
+    const usb_device_request_setup_packet_t *request, uint8_t *data,
+    size_t *act_size)
+{
+	uint32_t zero = 0;
+	if (request->length != sizeof(zero))
+		return ESTALL;
+	usbvirt_control_reply_helper(request, data, act_size,
+	    &zero, sizeof(zero));
+	return EOK;
+}
+
+/**
+ * @}
+ */
Index: uspace/lib/usbvirt/src/virthub_descriptors.c
===================================================================
--- uspace/lib/usbvirt/src/virthub_descriptors.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
+++ uspace/lib/usbvirt/src/virthub_descriptors.c	(revision 3f03199e0835b11c26a46cd190aeef79835d08f4)
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2013 Jan Vesely
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libusbvirt
+ * @{
+ */
+/** @file
+ * Virtual USB device main routines.
+ */
+
+#include <usb/classes/classes.h>
+#include <usb/classes/hub.h>
+#include <usb/descriptor.h>
+#include <usb/usb.h>
+#include <usbvirt/device.h>
+
+#include "virthub_base.h"
+
+#define HUB_CONFIGURATION_ID   1
+
+/** Standard device descriptor. */
+const usb_standard_device_descriptor_t virthub_device_descriptor = {
+	.length = sizeof(usb_standard_device_descriptor_t),
+	.descriptor_type = USB_DESCTYPE_DEVICE,
+	.usb_spec_version = 0x110,
+	.device_class = USB_CLASS_HUB,
+	.device_subclass = 0,
+	.device_protocol = 0,
+	.max_packet_size = 64,
+	.configuration_count = 1
+};
+
+
+/** Standard interface descriptor. */
+const usb_standard_interface_descriptor_t virthub_interface_descriptor = {
+	.length = sizeof(usb_standard_interface_descriptor_t),
+	.descriptor_type = USB_DESCTYPE_INTERFACE,
+	.interface_number = 0,
+	.alternate_setting = 0,
+	.endpoint_count = 1,
+	.interface_class = USB_CLASS_HUB,
+	.interface_subclass = 0,
+	.interface_protocol = 0,
+	.str_interface = 0
+};
+
+/** Endpoint descriptor. */
+const usb_standard_endpoint_descriptor_t virthub_endpoint_descriptor = {
+	.length = sizeof(usb_standard_endpoint_descriptor_t),
+	.descriptor_type = USB_DESCTYPE_ENDPOINT,
+	.endpoint_address = 1 | 128,
+	.attributes = USB_TRANSFER_INTERRUPT,
+	.max_packet_size = 8,
+	.poll_interval = 0xFF,
+};
+
+/** Standard configuration descriptor. */
+const usb_standard_configuration_descriptor_t virthub_configuration_descriptor_without_hub_size = {
+	.length = sizeof(virthub_configuration_descriptor_without_hub_size),
+	.descriptor_type = USB_DESCTYPE_CONFIGURATION,
+	.total_length =
+		sizeof(virthub_configuration_descriptor_without_hub_size)
+		+ sizeof(virthub_interface_descriptor)
+		+ sizeof(virthub_endpoint_descriptor)
+		,
+	.interface_count = 1,
+	.configuration_number = HUB_CONFIGURATION_ID,
+	.str_configuration = 0,
+	.attributes = 0, /* We are self-powered device */
+	.max_power = 0,
+};
+
+const usbvirt_device_configuration_extras_t virthub_interface_descriptor_ex = {
+	.data = (uint8_t *) &virthub_interface_descriptor,
+	.length = sizeof(virthub_interface_descriptor),
+};
+
+
+/**
+ * @}
+ */
