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),
+};
+
+
+/**
+ * @}
+ */
