Index: uspace/lib/usb/src/ddfiface.c
===================================================================
--- uspace/lib/usb/src/ddfiface.c	(revision b49d8725cc1c4a58c2affddebe1cffcc4caa6c90)
+++ 	(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 b49d8725cc1c4a58c2affddebe1cffcc4caa6c90)
+++ uspace/lib/usb/src/dev.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -36,80 +36,4 @@
 
 #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,
@@ -175,26 +99,18 @@
  * @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;
+	devman_handle_t hc;
+	usb_address_t addr = -1;
 	int rc;
-	bool is_bus_addr;
 	const char *func_start = NULL;
 	char *path = NULL;
 
 	/* 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;
+	if (try_parse_bus_and_address(dev_path, &func_start, &hc, &addr)) {
 		/*
 		 * Now get the handle of the device. We will need that
@@ -208,6 +124,6 @@
 		 * Otherwise, we will
 		 */
-		rc = get_device_handle_by_address(hc_handle, dev_addr,
-		    &dev_handle);
+
+		rc = get_device_handle_by_address(hc, addr, dev_handle);
 		if (rc != EOK) {
 			return rc;
@@ -215,5 +131,5 @@
 		if (str_length(func_start) > 0) {
 			char tmp_path[MAX_DEVICE_PATH];
-			rc = devman_fun_get_path(dev_handle,
+			rc = devman_fun_get_path(*dev_handle,
 			    tmp_path, MAX_DEVICE_PATH);
 			if (rc != EOK) {
@@ -226,5 +142,5 @@
 		} else {
 			/* Everything is resolved. Get out of here. */
-			goto copy_out;
+			return EOK;
 		}
 	} else {
@@ -236,5 +152,5 @@
 
 	/* First try to get the device handle. */
-	rc = devman_fun_get_handle(path, &dev_handle, 0);
+	rc = devman_fun_get_handle(path, dev_handle, 0);
 	if (rc != EOK) {
 		free(path);
@@ -253,25 +169,4 @@
 		}
 
-		/* 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, '/');
@@ -283,18 +178,4 @@
 	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;
Index: uspace/lib/usb/src/dump.c
===================================================================
--- uspace/lib/usb/src/dump.c	(revision b49d8725cc1c4a58c2affddebe1cffcc4caa6c90)
+++ uspace/lib/usb/src/dump.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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 b49d8725cc1c4a58c2affddebe1cffcc4caa6c90)
+++ uspace/lib/usb/src/hc.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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,37 +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.
@@ -212,43 +159,4 @@
 
 	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);
Index: uspace/lib/usb/src/usb.c
===================================================================
--- uspace/lib/usb/src/usb.c	(revision b49d8725cc1c4a58c2affddebe1cffcc4caa6c90)
+++ uspace/lib/usb/src/usb.c	(revision db71e2af5cdfe169de296e6f39b3e5eda7a966f6)
@@ -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;
+}
+
 /**
  * @}
