Index: uspace/drv/usbhub/utils.c
===================================================================
--- uspace/drv/usbhub/utils.c	(revision ee0d8a80ff3a427a6b7985ba4f8758440c006795)
+++ uspace/drv/usbhub/utils.c	(revision 4c74ac39e6e9e5218bfae7015043736e4d9a17b7)
@@ -34,18 +34,17 @@
  */
 #include <driver.h>
-#include <usb/devreq.h>
+#include <bool.h>
+#include <errno.h>
+
 #include <usbhc_iface.h>
 #include <usb/usbdrv.h>
 #include <usb/descriptor.h>
-#include <driver.h>
-#include <bool.h>
-#include <errno.h>
+#include <usb/devreq.h>
 #include <usb/classes/hub.h>
+
 #include "usbhub.h"
 #include "usbhub_private.h"
 #include "port_status.h"
-#include <usb/devreq.h>
-
-static void check_hub_changes(void);
+
 
 size_t USB_HUB_MAX_DESCRIPTOR_SIZE = 71;
@@ -302,4 +301,6 @@
 	//result->device = device;
 	result->port_count = -1;
+	/// \TODO is this correct? is the device stored?
+	result->device = device;
 
 
@@ -316,6 +317,6 @@
 	}*/
 
-	result->device = usb_new(usb_hcd_attached_device_info_t);
-	result->device->address = addr;
+	result->usb_device = usb_new(usb_hcd_attached_device_info_t);
+	result->usb_device->address = addr;
 
 	// get hub descriptor
@@ -362,9 +363,4 @@
 }
 
-/** Callback when new hub device is detected.
- *
- * @param dev New device.
- * @return Error code.
- */
 int usb_add_hub_device(device_t *dev) {
 	printf(NAME ": add_hub_device(handle=%d)\n", (int) dev->handle);
@@ -387,5 +383,5 @@
 	usb_device_request_setup_packet_t request;
 	usb_target_t target;
-	target.address = hub_info->device->address;
+	target.address = hub_info->usb_device->address;
 	target.endpoint = 0;
 	for (port = 0; port < hub_info->port_count; ++port) {
@@ -404,5 +400,5 @@
 	printf("[usb_hub] hub info added to list\n");
 	//(void)hub_info;
-	check_hub_changes();
+	usb_hub_check_hub_changes();
 
 	/// \TODO start the check loop, if not already started...
@@ -412,4 +408,7 @@
 
 	printf("[usb_hub] hub dev added\n");
+	printf("\taddress %d, has %d ports \n",
+			hub_info->usb_device->address,
+			hub_info->port_count);
 
 	return EOK;
@@ -429,5 +428,4 @@
  * @param target
  */
-
 static void usb_hub_init_add_device(int hc, uint16_t port, usb_target_t target) {
 	usb_device_request_setup_packet_t request;
@@ -459,5 +457,5 @@
  * @param target
  */
-static void usb_hub_finalize_add_device(
+static void usb_hub_finalize_add_device( usb_hub_info_t * hub,
 		int hc, uint16_t port, usb_target_t target) {
 
@@ -479,9 +477,17 @@
 		return;
 	}
+
+
 	usb_drv_release_default_address(hc);
 
-
-	/// \TODO driver work
-	//add_child_device.....
+	devman_handle_t child_handle;
+	opResult = usb_drv_register_child_in_devman(hc, hub->device,
+        new_device_address, &child_handle);
+	if (opResult != EOK) {
+		printf("[usb_hub] could not start driver for new device \n");
+		return;
+	}
+	usb_drv_bind_address(hc, new_device_address, child_handle);
+	
 }
 
@@ -519,5 +525,5 @@
  * @param target
  */
-static void usb_hub_process_interrupt(int hc, uint16_t port, usb_target_t target) {
+static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc, uint16_t port, usb_target_t target) {
 	printf("[usb_hub] interrupt at port %d\n", port);
 	//determine type of change
@@ -554,5 +560,5 @@
 		printf("[usb_hub] finalizing add device\n");
 		if (usb_port_enabled(&status)) {
-			usb_hub_finalize_add_device(hc, port, target);
+			usb_hub_finalize_add_device(hub, hc, port, target);
 		} else {
 			printf("[usb_hub] ERROR: port reset, but port still not enabled\n");
@@ -585,5 +591,5 @@
 /** Check changes on all known hubs.
  */
-static void check_hub_changes(void) {
+void usb_hub_check_hub_changes(void) {
 	/*
 	 * Iterate through all hubs.
@@ -594,24 +600,19 @@
 			lst_item = lst_item->next) {
 		printf("[usb_hub] checking hub changes\n");
+		usb_hub_info_t * hub_info = ((usb_hub_info_t*)lst_item->data);
 		/*
 		 * Check status change pipe of this hub.
 		 */
 
-		usb_target_t target = {
-			.address = 5,
-			.endpoint = 1
-		};
-		/// \TODO uncomment once it works correctly
-		//target.address = usb_create_hub_info(lst_item)->device->address;
-
-		size_t port_count = 7;
+		usb_target_t target;
+		target.address = hub_info->usb_device->address;
+		target.endpoint = 1;
+
+		size_t port_count = hub_info->port_count;
 
 		/*
 		 * Connect to respective HC.
 		 */
-		/// \FIXME this is incorrect code: here
-		/// must be used particular device instead of NULL
-		//which one?
-		int hc = usb_drv_hc_connect(NULL, 0);
+		int hc = usb_drv_hc_connect(hub_info->device, 0);
 		if (hc < 0) {
 			continue;
@@ -642,5 +643,5 @@
 			bool interrupt = (((uint8_t*) change_bitmap)[port / 8] >> (port % 8)) % 2;
 			if (interrupt) {
-				usb_hub_process_interrupt(hc, port, target);
+				usb_hub_process_interrupt(hub_info, hc, port, target);
 			}
 		}
