Index: uspace/drv/bus/usb/usbhub/port_status.h
===================================================================
--- uspace/drv/bus/usb/usbhub/port_status.h	(revision 34a0d17110432e87c53a15316b4d2faec79bb069)
+++ uspace/drv/bus/usb/usbhub/port_status.h	(revision 193da9d64b94bd4911014eee9463b03cbe34bbcb)
@@ -1,4 +1,5 @@
 /*
  * Copyright (c) 2010 Matus Dekanek
+ * Copyright (c) 2011 Jan Vesely
  * All rights reserved.
  *
@@ -36,5 +37,4 @@
 #include <sys/types.h>
 #include <usb/dev/request.h>
-#include "usbhub_private.h"
 
 /**
Index: uspace/drv/bus/usb/usbhub/ports.c
===================================================================
--- uspace/drv/bus/usb/usbhub/ports.c	(revision 34a0d17110432e87c53a15316b4d2faec79bb069)
+++ uspace/drv/bus/usb/usbhub/ports.c	(revision 193da9d64b94bd4911014eee9463b03cbe34bbcb)
@@ -44,5 +44,5 @@
 #include "ports.h"
 #include "usbhub.h"
-#include "usbhub_private.h"
+#include "utils.h"
 #include "port_status.h"
 
Index: uspace/drv/bus/usb/usbhub/ports.h
===================================================================
--- uspace/drv/bus/usb/usbhub/ports.h	(revision 34a0d17110432e87c53a15316b4d2faec79bb069)
+++ uspace/drv/bus/usb/usbhub/ports.h	(revision 193da9d64b94bd4911014eee9463b03cbe34bbcb)
@@ -62,5 +62,7 @@
  * @param port Port to be initialized.
  */
-static inline void usb_hub_port_init(usb_hub_port_t *port) {
+static inline void usb_hub_port_init(usb_hub_port_t *port)
+{
+	assert(port);
 	port->attached_device.address = -1;
 	port->attached_device.handle = 0;
Index: uspace/drv/bus/usb/usbhub/usbhub.c
===================================================================
--- uspace/drv/bus/usb/usbhub/usbhub.c	(revision 34a0d17110432e87c53a15316b4d2faec79bb069)
+++ uspace/drv/bus/usb/usbhub/usbhub.c	(revision 193da9d64b94bd4911014eee9463b03cbe34bbcb)
@@ -38,6 +38,9 @@
 #include <str_error.h>
 #include <inttypes.h>
-
-#include <usb_iface.h>
+#include <stdio.h>
+
+#include <usb/usb.h>
+#include <usb/dev/pipes.h>
+#include <usb/classes/classes.h>
 #include <usb/ddfiface.h>
 #include <usb/descriptor.h>
@@ -46,18 +49,15 @@
 #include <usb/classes/hub.h>
 #include <usb/dev/poll.h>
-#include <stdio.h>
+#include <usb_iface.h>
 
 #include "usbhub.h"
-#include "usbhub_private.h"
+#include "utils.h"
 #include "port_status.h"
-#include <usb/usb.h>
-#include <usb/dev/pipes.h>
-#include <usb/classes/classes.h>
 
 #define HUB_FNC_NAME "hub"
 
+static int usb_set_first_configuration(usb_device_t *usb_device);
 static usb_hub_info_t * usb_hub_info_create(usb_device_t *usb_dev);
 static int usb_hub_process_hub_specific_info(usb_hub_info_t *hub_info);
-static int usb_hub_set_configuration(usb_hub_info_t *hub_info);
 static int usb_process_hub_over_current(usb_hub_info_t *hub_info,
     usb_hub_status_t status);
@@ -85,8 +85,13 @@
 int usb_hub_add_device(usb_device_t *usb_dev)
 {
-	if (!usb_dev) return EINVAL;
+	assert(usb_dev);
+	/* Create driver soft-state structure */
 	usb_hub_info_t *hub_info = usb_hub_info_create(usb_dev);
-
-	//create hc connection
+	if (hub_info == NULL) {
+		usb_log_error("Failed to create hun driver structure.\n");
+		return ENOMEM;
+	}
+
+	/* Create hc connection */
 	usb_log_debug("Initializing USB wire abstraction.\n");
 	int opResult = usb_hc_connection_initialize_from_device(
@@ -99,6 +104,6 @@
 	}
 
-	//set hub configuration
-	opResult = usb_hub_set_configuration(hub_info);
+	/* Set hub's first configuration. (There should be only one) */
+	opResult = usb_set_first_configuration(usb_dev);
 	if (opResult != EOK) {
 		usb_log_error("Could not set hub configuration: %s\n",
@@ -233,5 +238,5 @@
  * information. If there are non-removable devices, start initializing them.
  * This function is hub-specific and should be run only after the hub is
- * configured using usb_hub_set_configuration function.
+ * configured using usb_set_first_configuration function.
  * @param hub_info hub representation
  * @return error code
@@ -239,4 +244,5 @@
 int usb_hub_process_hub_specific_info(usb_hub_info_t *hub_info)
 {
+	assert(hub_info);
 	// get hub descriptor
 	usb_log_debug("Retrieving descriptor\n");
@@ -267,4 +273,5 @@
 	hub_info->port_count = descriptor.ports_count;
 
+	// TODO Why +1 ?
 	hub_info->ports =
 	    malloc(sizeof(usb_hub_port_t) * (hub_info->port_count + 1));
@@ -304,5 +311,5 @@
 
 	} else {
-		usb_log_debug("Power not switched, not going to be powered\n");
+		usb_log_debug("Power not switched, ports always powered\n");
 	}
 	return EOK;
@@ -310,33 +317,33 @@
 
 /**
- * Set configuration of hub
+ * Set configuration of and USB device
  *
  * Check whether there is at least one configuration and sets the first one.
  * This function should be run prior to running any hub-specific action.
- * @param hub_info hub representation
+ * @param usb_device usb device representation
  * @return error code
  */
-static int usb_hub_set_configuration(usb_hub_info_t *hub_info)
+static int usb_set_first_configuration(usb_device_t *usb_device)
 {
-	//device descriptor
-	const usb_standard_device_descriptor_t *std_descriptor
-	    = &hub_info->usb_device->descriptors.device;
-	usb_log_debug("Hub has %d configurations\n",
-	    std_descriptor->configuration_count);
-
-	if (std_descriptor->configuration_count < 1) {
+	assert(usb_device);
+	/* Get number of possible configurations from device descriptor */
+	const size_t configuration_count =
+	    usb_device->descriptors.device.configuration_count;
+	usb_log_debug("Hub has %d configurations.\n", configuration_count);
+
+	if (configuration_count < 1) {
 		usb_log_error("There are no configurations available\n");
 		return EINVAL;
 	}
 
+	// TODO: Make sure that there is enough data and the cast is correct
 	usb_standard_configuration_descriptor_t *config_descriptor
 	    = (usb_standard_configuration_descriptor_t *)
-	    hub_info->usb_device->descriptors.configuration;
-
-	/* Set configuration. */
-	int opResult = usb_request_set_configuration(
-	    &hub_info->usb_device->ctrl_pipe,
-	    config_descriptor->configuration_number);
-
+	    usb_device->descriptors.configuration;
+
+	/* Set configuration. Use the configuration that was in
+	 * usb_device->descriptors.configuration */
+	const int opResult = usb_request_set_configuration(
+	    &usb_device->ctrl_pipe, config_descriptor->configuration_number);
 	if (opResult != EOK) {
 		usb_log_error("Failed to set hub configuration: %s.\n",
Index: uspace/drv/bus/usb/usbhub/usbhub.h
===================================================================
--- uspace/drv/bus/usb/usbhub/usbhub.h	(revision 34a0d17110432e87c53a15316b4d2faec79bb069)
+++ uspace/drv/bus/usb/usbhub/usbhub.h	(revision 193da9d64b94bd4911014eee9463b03cbe34bbcb)
@@ -56,10 +56,10 @@
 	size_t port_count;
 
-	/** attached device handles, for each port one */
+	/** Attached device handles, for each port one */
 	usb_hub_port_t *ports;
 
 	fibril_mutex_t port_mutex;
 
-	/** connection to hcd */
+	/** Connection to hcd */
 	usb_hc_connection_t connection;
 
Index: uspace/drv/bus/usb/usbhub/usbhub_private.h
===================================================================
--- uspace/drv/bus/usb/usbhub/usbhub_private.h	(revision 34a0d17110432e87c53a15316b4d2faec79bb069)
+++ 	(revision )
@@ -1,182 +1,0 @@
-/*
- * Copyright (c) 2010 Matus Dekanek
- * 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 drvusbhub
- * @{
- */
-/** @file
- * @brief Hub driver private definitions
- */
-
-#ifndef USBHUB_PRIVATE_H
-#define	USBHUB_PRIVATE_H
-
-#include "usbhub.h"
-
-#include <adt/list.h>
-#include <bool.h>
-#include <ddf/driver.h>
-#include <fibril_synch.h>
-
-#include <usb/classes/hub.h>
-#include <usb/usb.h>
-#include <usb/debug.h>
-#include <usb/dev/request.h>
-
-//************
-//
-// convenience define for malloc
-//
-//************
-
-
-usb_hub_info_t * usb_create_hub_info(ddf_dev_t * device);
-
-/**
- * Set the device request to be a get hub descriptor request.
- * @warning the size is allways set to USB_HUB_MAX_DESCRIPTOR_SIZE
- * @param request
- * @param addr
- */
-static inline void usb_hub_set_descriptor_request(
-    usb_device_request_setup_packet_t *request )
-{
-	request->index = 0;
-	request->request_type = USB_HUB_REQ_TYPE_GET_DESCRIPTOR;
-	request->request = USB_HUB_REQUEST_GET_DESCRIPTOR;
-	request->value_high = USB_DESCTYPE_HUB;
-	request->value_low = 0;
-	request->length = USB_HUB_MAX_DESCRIPTOR_SIZE;
-}
-
-/**
- * Clear feature on hub port.
- *
- * @param hc Host controller telephone
- * @param address Hub address
- * @param port_index Port
- * @param feature Feature selector
- * @return Operation result
- */
-static inline int usb_hub_clear_port_feature(usb_pipe_t *pipe,
-    int port_index, usb_hub_class_feature_t feature)
-{
-
-	usb_device_request_setup_packet_t clear_request = {
-		.request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE,
-		.request = USB_DEVREQ_CLEAR_FEATURE,
-		.length = 0,
-		.index = port_index
-	};
-	clear_request.value = feature;
-	return usb_pipe_control_write(pipe, &clear_request,
-	    sizeof (clear_request), NULL, 0);
-}
-
-/**
- * Clear feature on hub port.
- *
- * @param hc Host controller telephone
- * @param address Hub address
- * @param port_index Port
- * @param feature Feature selector
- * @return Operation result
- */
-static inline int usb_hub_set_port_feature(usb_pipe_t *pipe,
-    int port_index, usb_hub_class_feature_t feature)
-{
-
-	usb_device_request_setup_packet_t clear_request = {
-		.request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE,
-		.request = USB_DEVREQ_SET_FEATURE,
-		.length = 0,
-		.index = port_index
-	};
-	clear_request.value = feature;
-	return usb_pipe_control_write(pipe, &clear_request,
-	    sizeof (clear_request), NULL, 0);
-}
-
-/**
- * Clear feature on hub port.
- *
- * @param pipe pipe to hub control endpoint
- * @param feature Feature selector
- * @return Operation result
- */
-static inline int usb_hub_clear_feature(usb_pipe_t *pipe,
-    usb_hub_class_feature_t feature) {
-
-	usb_device_request_setup_packet_t clear_request = {
-		.request_type = USB_HUB_REQ_TYPE_CLEAR_HUB_FEATURE,
-		.request = USB_DEVREQ_CLEAR_FEATURE,
-		.length = 0,
-		.index = 0
-	};
-	clear_request.value = feature;
-	return usb_pipe_control_write(pipe, &clear_request,
-	    sizeof (clear_request), NULL, 0);
-}
-
-/**
- * Clear feature on hub port.
- *
- * @param pipe pipe to hub control endpoint
- * @param feature Feature selector
- * @return Operation result
- */
-static inline int usb_hub_set_feature(usb_pipe_t *pipe,
-    usb_hub_class_feature_t feature)
-{
-
-	usb_device_request_setup_packet_t clear_request = {
-		.request_type = USB_HUB_REQ_TYPE_CLEAR_HUB_FEATURE,
-		.request = USB_DEVREQ_SET_FEATURE,
-		.length = 0,
-		.index = 0
-	};
-	clear_request.value = feature;
-	return usb_pipe_control_write(pipe, &clear_request,
-	    sizeof (clear_request), NULL, 0);
-}
-
-
-void * usb_create_serialized_hub_descriptor(usb_hub_descriptor_t *descriptor);
-
-void usb_serialize_hub_descriptor(usb_hub_descriptor_t *descriptor,
-    void *serialized_descriptor);
-
-int usb_deserialize_hub_desriptor(
-    void *serialized_descriptor, size_t size, usb_hub_descriptor_t *descriptor);
-
-
-#endif	/* USBHUB_PRIVATE_H */
-
-/**
- * @}
- */
Index: uspace/drv/bus/usb/usbhub/utils.c
===================================================================
--- uspace/drv/bus/usb/usbhub/utils.c	(revision 34a0d17110432e87c53a15316b4d2faec79bb069)
+++ uspace/drv/bus/usb/usbhub/utils.c	(revision 193da9d64b94bd4911014eee9463b03cbe34bbcb)
@@ -42,6 +42,5 @@
 
 #include "usbhub.h"
-#include "usbhub_private.h"
-#include "port_status.h"
+#include "utils.h"
 
 
Index: uspace/drv/bus/usb/usbhub/utils.h
===================================================================
--- uspace/drv/bus/usb/usbhub/utils.h	(revision 193da9d64b94bd4911014eee9463b03cbe34bbcb)
+++ uspace/drv/bus/usb/usbhub/utils.h	(revision 193da9d64b94bd4911014eee9463b03cbe34bbcb)
@@ -0,0 +1,180 @@
+/*
+ * Copyright (c) 2010 Matus Dekanek
+ * 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 drvusbhub
+ * @{
+ */
+/** @file
+ * @brief Hub driver private definitions
+ */
+
+#ifndef USBHUB_UTILS_H
+#define USBHUB_UTILS_H
+
+#include <adt/list.h>
+#include <bool.h>
+#include <ddf/driver.h>
+#include <fibril_synch.h>
+
+#include <usb/classes/hub.h>
+#include <usb/usb.h>
+#include <usb/debug.h>
+#include <usb/dev/request.h>
+
+#include "usbhub.h"
+
+//************
+//
+// convenience define for malloc
+//
+//************
+
+
+usb_hub_info_t * usb_create_hub_info(ddf_dev_t * device);
+
+/**
+ * Set the device request to be a get hub descriptor request.
+ * @warning the size is allways set to USB_HUB_MAX_DESCRIPTOR_SIZE
+ * @param request
+ * @param addr
+ */
+static inline void usb_hub_set_descriptor_request(
+    usb_device_request_setup_packet_t *request )
+{
+	request->index = 0;
+	request->request_type = USB_HUB_REQ_TYPE_GET_DESCRIPTOR;
+	request->request = USB_HUB_REQUEST_GET_DESCRIPTOR;
+	request->value_high = USB_DESCTYPE_HUB;
+	request->value_low = 0;
+	request->length = USB_HUB_MAX_DESCRIPTOR_SIZE;
+}
+
+/**
+ * Clear feature on hub port.
+ *
+ * @param hc Host controller telephone
+ * @param address Hub address
+ * @param port_index Port
+ * @param feature Feature selector
+ * @return Operation result
+ */
+static inline int usb_hub_clear_port_feature(usb_pipe_t *pipe,
+    int port_index, usb_hub_class_feature_t feature)
+{
+
+	usb_device_request_setup_packet_t clear_request = {
+		.request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE,
+		.request = USB_DEVREQ_CLEAR_FEATURE,
+		.length = 0,
+		.index = port_index
+	};
+	clear_request.value = feature;
+	return usb_pipe_control_write(pipe, &clear_request,
+	    sizeof (clear_request), NULL, 0);
+}
+
+/**
+ * Clear feature on hub port.
+ *
+ * @param hc Host controller telephone
+ * @param address Hub address
+ * @param port_index Port
+ * @param feature Feature selector
+ * @return Operation result
+ */
+static inline int usb_hub_set_port_feature(usb_pipe_t *pipe,
+    int port_index, usb_hub_class_feature_t feature)
+{
+
+	usb_device_request_setup_packet_t clear_request = {
+		.request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE,
+		.request = USB_DEVREQ_SET_FEATURE,
+		.length = 0,
+		.index = port_index
+	};
+	clear_request.value = feature;
+	return usb_pipe_control_write(pipe, &clear_request,
+	    sizeof (clear_request), NULL, 0);
+}
+
+/**
+ * Clear feature on hub port.
+ *
+ * @param pipe pipe to hub control endpoint
+ * @param feature Feature selector
+ * @return Operation result
+ */
+static inline int usb_hub_clear_feature(usb_pipe_t *pipe,
+    usb_hub_class_feature_t feature) {
+
+	usb_device_request_setup_packet_t clear_request = {
+		.request_type = USB_HUB_REQ_TYPE_CLEAR_HUB_FEATURE,
+		.request = USB_DEVREQ_CLEAR_FEATURE,
+		.length = 0,
+		.index = 0
+	};
+	clear_request.value = feature;
+	return usb_pipe_control_write(pipe, &clear_request,
+	    sizeof (clear_request), NULL, 0);
+}
+
+/**
+ * Clear feature on hub port.
+ *
+ * @param pipe pipe to hub control endpoint
+ * @param feature Feature selector
+ * @return Operation result
+ */
+static inline int usb_hub_set_feature(usb_pipe_t *pipe,
+    usb_hub_class_feature_t feature)
+{
+
+	usb_device_request_setup_packet_t clear_request = {
+		.request_type = USB_HUB_REQ_TYPE_CLEAR_HUB_FEATURE,
+		.request = USB_DEVREQ_SET_FEATURE,
+		.length = 0,
+		.index = 0
+	};
+	clear_request.value = feature;
+	return usb_pipe_control_write(pipe, &clear_request,
+	    sizeof (clear_request), NULL, 0);
+}
+
+void * usb_create_serialized_hub_descriptor(usb_hub_descriptor_t *descriptor);
+
+void usb_serialize_hub_descriptor(usb_hub_descriptor_t *descriptor,
+    void *serialized_descriptor);
+
+int usb_deserialize_hub_desriptor(
+    void *serialized_descriptor, size_t size, usb_hub_descriptor_t *descriptor);
+
+#endif
+/**
+ * @}
+ */
