Index: uspace/drv/uhci/root_hub/root_hub.c
===================================================================
--- uspace/drv/uhci/root_hub/root_hub.c	(revision f088c00baff82dafff909fe1a103cbfe3ce2acdb)
+++ uspace/drv/uhci/root_hub/root_hub.c	(revision bf5a3be3f91be8c93abd675e1ef6d32a4852ba39)
@@ -1,3 +1,5 @@
+#include <bool.h>
 #include <ddi.h>
+#include <devman.h>
 #include <async.h>
 #include <errno.h>
@@ -5,12 +7,16 @@
 #include <stdio.h>
 
-#include <usb/debug.h>
-
 #include "../name.h"
 #include "../uhci.h"
+#include "../debug.h"
 #include "port_status.h"
 #include "root_hub.h"
 
 #define ROOT_HUB_WAIT_USEC 10000000 /* 10 second */
+
+struct usb_match {
+	int id_score;
+	const char *id_string;
+};
 
 static int uhci_root_hub_check_ports( void *hc );
@@ -19,4 +25,6 @@
 static int uhci_root_hub_report_new_device(
   device_t *hc, usb_address_t address, int port, devman_handle_t *handle );
+static int uhci_root_hub_port_set_enabled(
+  uhci_root_hub_t *instance, unsigned port, bool enabled );
 
 /*----------------------------------------------------------------------------*/
@@ -29,5 +37,6 @@
 	const int ret = pio_enable( addr, sizeof(port_regs_t), (void**)&regs);
 	if (ret < 0) {
-		printf( NAME": Failed to gain access to port registers at %p\n", regs );
+		uhci_print_error(
+		  ": Failed to gain access to port registers at %p\n", regs );
 		return ret;
 	}
@@ -37,5 +46,5 @@
 	hub->checker = fibril_create( uhci_root_hub_check_ports, hc );
 	if (hub->checker == 0) {
-		printf( NAME": failed to launch root hub fibril." );
+		uhci_print_error( ": failed to launch root hub fibril." );
 		return ENOMEM;
 	}
@@ -51,4 +60,27 @@
 	//destroy fibril here
 	//disable access to registers
+	return EOK;
+}
+/*----------------------------------------------------------------------------*/
+static int uhci_root_hub_port_set_enabled( uhci_root_hub_t *instance,
+  unsigned port, bool enabled )
+{
+	assert( instance );
+	assert( instance->registers );
+	assert( port < UHCI_ROOT_HUB_PORT_COUNT );
+
+	volatile uint16_t * address =
+		&(instance->registers->portsc[port]);
+
+	/* read register value */
+	port_status_t port_status;
+	port_status.raw_value = pio_read_16( address );
+
+	/* enable port: register write */
+	port_status.status.enabled_change = 0;
+	port_status.status.enabled = (bool)enabled;
+	pio_write_16( address, port_status.raw_value );
+
+	uhci_print_info( "Enabled port %d.\n", port );
 	return EOK;
 }
@@ -65,5 +97,5 @@
 				&(uhci_instance->root_hub.registers->portsc[i]);
 
-			usb_dprintf( NAME, 1, "Port(%d) status address %p:\n", i, address );
+			uhci_print_info( "Port(%d) status address %p:\n", i, address );
 
 			/* read register value */
@@ -72,5 +104,5 @@
 
 			/* debug print */
-			usb_dprintf( NAME, 1, "Port(%d) status 0x%x:\n", i, port_status.raw_value );
+			uhci_print_info( "Port(%d) status %#x:\n", i, port_status.raw_value );
 			print_port_status( &port_status );
 
@@ -96,5 +128,5 @@
 	assert( port < UHCI_ROOT_HUB_PORT_COUNT );
 
-	usb_dprintf( NAME, 2, "Adding new device on port %d.\n", port );
+	uhci_print_info( "Adding new device on port %d.\n", port );
 
 	uhci_t *uhci_instance = (uhci_t*)hc->driver_data;
@@ -104,28 +136,17 @@
 
 	/* enable port */
-	{
-		volatile uint16_t * address =
-			&(uhci_instance->root_hub.registers->portsc[port]);
-
-		/* read register value */
-		port_status_t port_status;
-		port_status.raw_value = pio_read_16( address );
-
-		/* enable port: register write */
-		port_status.status.enabled = 1;
-		pio_write_16( address, port_status.raw_value );
-
-		usb_dprintf( NAME, 2, "Enabled port %d.\n", port );
-	}
+	uhci_root_hub_port_set_enabled( &uhci_instance->root_hub, port, true );
 
 	/* assign address to device */
-	usb_address_t address =
-	 uhci_root_hub_assign_address( hc );
-	if (address <= 0) {
-		printf( NAME": Failed to assign address to the device" );
-		return ENOMEM;
-	}
+	usb_address_t address = uhci_root_hub_assign_address( hc );
+
 	/* release default address */
 	usb_address_keeping_release_default( &uhci_instance->address_manager );
+
+	if (address <= 0) { /* address assigning went wrong */
+		uhci_root_hub_port_set_enabled( &uhci_instance->root_hub, port, false );
+		uhci_print_error( "Failed to assign address to the device" );
+		return ENOMEM;
+	}
 
 	/* report to devman */
@@ -148,10 +169,10 @@
 	uhci_t *uhci_instance = (uhci_t*)hc->driver_data;
 	/* get new address */
-	const usb_address_t usb_address = usb_address_keeping_request(
-	  &uhci_instance->address_manager );
+	const usb_address_t usb_address =
+	  usb_address_keeping_request( &uhci_instance->address_manager );
 
 	/* assign new address */
-	/* TODO send new address*/
-	usb_dprintf( NAME, 3, "Assigned address 0x%x.\n", usb_address );
+	/* TODO send new address to the device*/
+	uhci_print_error( "Assigned address %#x.\n", usb_address );
 
 	return usb_address;
@@ -165,13 +186,14 @@
 	assert( address <= USB11_ADDRESS_MAX );
 
-	int ret;
 	device_t *child = create_device();
 	if (child == NULL)
 		{ return ENOMEM; }
+
 	char *name;
-
-	ret = asprintf( &name, "usbdevice on hc%p/%d/0x%x", hc, hub_port, address );
+	int ret;
+
+	ret = asprintf( &name, "usbdevice on hc%p/%d/%#x", hc, hub_port, address );
 	if (ret < 0) {
-		usb_dprintf( NAME, 4, "Failed to create device name.\n" );
+		uhci_print_error( "Failed to create device name.\n" );
 		delete_device( child );
 		return ret;
@@ -179,9 +201,48 @@
 	child->name = name;
 
-	/* TODO create match ids */
+	/* TODO get and parse device descriptor */
+	const int vendor = 1;
+	const int product = 1;
+	const char* release = "unknown";
+	const char* class = "unknown";
+
+	/* create match ids TODO fix class printf*/
+	static const struct usb_match usb_matches[] = {
+	  { 100, "usb&vendor=%d&product=%d&release=%s" },
+	  {  90, "usb&vendor=%d&product=%d" },
+	  {  50, "usb&class=%d" },
+	  {   1, "usb&fallback" }
+	};
+
+	unsigned i = 0;
+	for (;i < sizeof( usb_matches )/ sizeof( struct usb_match ); ++i ) {
+		char *match_str;
+		const int ret = asprintf(
+		  &match_str, usb_matches[i].id_string, vendor, product, release, class );
+		if (ret < 0 ) {
+			uhci_print_error( "Failed to create matchid string.\n" );
+			delete_device( child );
+			return ret;
+		}
+		uhci_print_info( "Adding match id rule:%s\n", match_str );
+
+		match_id_t *id = create_match_id();
+		if (id == NULL) {
+			uhci_print_error( "Failed to create matchid.\n" );
+			delete_device( child );
+			free( match_str );
+			return ENOMEM;
+		}
+		id->id = match_str;
+		id->score = usb_matches[i].id_score;
+		add_match_id( &child->match_ids, id );
+
+		uhci_print_info( "Added match id, score: %d, string %s\n",
+		  id->score, id->id );
+	}
 
 	ret = child_device_register( child, hc );
 	if (ret < 0) {
-		usb_dprintf( NAME, 4, "Failed to create device name.\n" );
+		uhci_print_error( "Failed to create device name.\n" );
 		delete_device( child );
 		return ret;
