Index: uspace/drv/ohci/batch.c
===================================================================
--- uspace/drv/ohci/batch.c	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/ohci/batch.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -51,4 +51,5 @@
 static void batch_control(usb_transfer_batch_t *instance,
     usb_direction_t data_dir, usb_direction_t status_dir);
+static void batch_data(usb_transfer_batch_t *instance);
 static void batch_call_in_and_dispose(usb_transfer_batch_t *instance);
 static void batch_call_out_and_dispose(usb_transfer_batch_t *instance);
@@ -134,10 +135,17 @@
 	assert(data);
 	size_t tds = data->td_count - 1;
-	usb_log_debug2("Batch(%p) checking %d td(s) for completion.\n",
+	usb_log_debug("Batch(%p) checking %d td(s) for completion.\n",
 	    instance, tds);
+	usb_log_debug("ED: %x:%x:%x:%x.\n",
+	    data->ed->status, data->ed->td_head, data->ed->td_tail,
+	    data->ed->next);
 	size_t i = 0;
 	for (; i < tds; ++i) {
-		if (!td_is_finished(&data->tds[i]))
+		usb_log_debug("TD %d: %x:%x:%x:%x.\n", i,
+		    data->tds[i].status, data->tds[i].cbp, data->tds[i].next,
+		    data->tds[i].be);
+		if (!td_is_finished(&data->tds[i])) {
 			return false;
+		}
 		instance->error = td_error(&data->tds[i]);
 		/* FIXME: calculate real transfered size */
@@ -177,5 +185,5 @@
 	assert(instance->direction == USB_DIRECTION_IN);
 	instance->next_step = batch_call_in_and_dispose;
-	/* TODO: implement */
+	batch_data(instance);
 	usb_log_debug("Batch(%p) INTERRUPT IN initialized.\n", instance);
 }
@@ -189,5 +197,5 @@
 	    instance->buffer_size);
 	instance->next_step = batch_call_out_and_dispose;
-	/* TODO: implement */
+	batch_data(instance);
 	usb_log_debug("Batch(%p) INTERRUPT OUT initialized.\n", instance);
 }
@@ -198,5 +206,5 @@
 	instance->direction = USB_DIRECTION_IN;
 	instance->next_step = batch_call_in_and_dispose;
-	/* TODO: implement */
+	batch_data(instance);
 	usb_log_debug("Batch(%p) BULK IN initialized.\n", instance);
 }
@@ -207,5 +215,5 @@
 	instance->direction = USB_DIRECTION_IN;
 	instance->next_step = batch_call_in_and_dispose;
-	/* TODO: implement */
+	batch_data(instance);
 	usb_log_debug("Batch(%p) BULK IN initialized.\n", instance);
 }
@@ -227,6 +235,7 @@
 	ed_init(data->ed, instance->ep);
 	ed_add_tds(data->ed, &data->tds[0], &data->tds[data->td_count - 1]);
-	usb_log_debug("Created ED: %x:%x:%x:%x.\n", data->ed->status,
-	    data->ed->td_tail, data->ed->td_head, data->ed->next);
+	usb_log_debug("Created ED(%p): %x:%x:%x:%x.\n", data->ed,
+	    data->ed->status, data->ed->td_tail, data->ed->td_head,
+	    data->ed->next);
 	int toggle = 0;
 	/* setup stage */
@@ -267,4 +276,37 @@
 }
 /*----------------------------------------------------------------------------*/
+void batch_data(usb_transfer_batch_t *instance)
+{
+	assert(instance);
+	ohci_batch_t *data = instance->private_data;
+	assert(data);
+	ed_init(data->ed, instance->ep);
+	ed_add_tds(data->ed, &data->tds[0], &data->tds[data->td_count - 1]);
+	usb_log_debug("Created ED(%p): %x:%x:%x:%x.\n", data->ed,
+	    data->ed->status, data->ed->td_tail, data->ed->td_head,
+	    data->ed->next);
+
+	/* data stage */
+	size_t td_current = 0;
+	size_t remain_size = instance->buffer_size;
+	char *transfer_buffer = instance->transport_buffer;
+	while (remain_size > 0) {
+		size_t transfer_size = remain_size > OHCI_TD_MAX_TRANSFER ?
+		    OHCI_TD_MAX_TRANSFER : remain_size;
+
+		td_init(&data->tds[td_current], instance->ep->direction,
+		    transfer_buffer, transfer_size, -1);
+		td_set_next(&data->tds[td_current], &data->tds[td_current + 1]);
+		usb_log_debug("Created DATA TD: %x:%x:%x:%x.\n",
+		    data->tds[td_current].status, data->tds[td_current].cbp,
+		    data->tds[td_current].next, data->tds[td_current].be);
+
+		transfer_buffer += transfer_size;
+		remain_size -= transfer_size;
+		assert(td_current < data->td_count);
+		++td_current;
+	}
+}
+/*----------------------------------------------------------------------------*/
 /** Helper function calls callback and correctly disposes of batch structure.
  *
Index: uspace/drv/ohci/hc.c
===================================================================
--- uspace/drv/ohci/hc.c	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/ohci/hc.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -108,4 +108,13 @@
 	    ret, str_error(ret));
 
+	hc_gain_control(instance);
+	ret = hc_init_memory(instance);
+	CHECK_RET_RETURN(ret, "Failed to create OHCI memory structures:%s.\n",
+	    ret, str_error(ret));
+	hc_init_hw(instance);
+	fibril_mutex_initialize(&instance->guard);
+
+	rh_init(&instance->rh, dev, instance->registers);
+
 	if (!interrupts) {
 		instance->interrupt_emulator =
@@ -114,12 +123,4 @@
 	}
 
-	hc_gain_control(instance);
-
-	rh_init(&instance->rh, dev, instance->registers);
-
-	hc_init_memory(instance);
-	hc_init_hw(instance);
-
-	/* TODO: implement */
 	return EOK;
 }
@@ -135,17 +136,38 @@
 	}
 
-	transfer_list_add_batch(
-	    instance->transfers[batch->transfer_type], batch);
-
+	fibril_mutex_lock(&instance->guard);
 	switch (batch->transfer_type) {
 	case USB_TRANSFER_CONTROL:
+		instance->registers->control &= ~C_CLE;
+		transfer_list_add_batch(
+		    instance->transfers[batch->transfer_type], batch);
 		instance->registers->command_status |= CS_CLF;
+		usb_log_debug2("Set CS control transfer filled: %x.\n",
+			instance->registers->command_status);
+		instance->registers->control_current = 0;
+		instance->registers->control |= C_CLE;
 		break;
 	case USB_TRANSFER_BULK:
+		instance->registers->control &= ~C_BLE;
+		transfer_list_add_batch(
+		    instance->transfers[batch->transfer_type], batch);
 		instance->registers->command_status |= CS_BLF;
+		usb_log_debug2("Set bulk transfer filled: %x.\n",
+			instance->registers->command_status);
+		instance->registers->control |= C_BLE;
+		break;
+	case USB_TRANSFER_INTERRUPT:
+	case USB_TRANSFER_ISOCHRONOUS:
+		instance->registers->control &= (~C_PLE & ~C_IE);
+		transfer_list_add_batch(
+		    instance->transfers[batch->transfer_type], batch);
+		instance->registers->control |= C_PLE | C_IE;
+		usb_log_debug2("Added periodic transfer: %x.\n",
+		    instance->registers->periodic_current);
 		break;
 	default:
 		break;
 	}
+	fibril_mutex_unlock(&instance->guard);
 	return EOK;
 }
@@ -154,23 +176,35 @@
 {
 	assert(instance);
-	if (status == 0)
+	if ((status & ~IS_SF) == 0) /* ignore sof status */
 		return;
 	if (status & IS_RHSC)
 		rh_interrupt(&instance->rh);
 
-	usb_log_info("OHCI interrupt: %x.\n", status);
-
-	LIST_INITIALIZE(done);
-	transfer_list_remove_finished(&instance->transfers_interrupt, &done);
-	transfer_list_remove_finished(&instance->transfers_isochronous, &done);
-	transfer_list_remove_finished(&instance->transfers_control, &done);
-	transfer_list_remove_finished(&instance->transfers_bulk, &done);
-
-	while (!list_empty(&done)) {
-		link_t *item = done.next;
-		list_remove(item);
-		usb_transfer_batch_t *batch =
-		    list_get_instance(item, usb_transfer_batch_t, link);
-		usb_transfer_batch_finish(batch);
+	usb_log_debug("OHCI interrupt: %x.\n", status);
+
+	if (status & IS_WDH) {
+		fibril_mutex_lock(&instance->guard);
+		usb_log_debug2("HCCA: %p-%p(%p).\n", instance->hcca,
+		    instance->registers->hcca, addr_to_phys(instance->hcca));
+		usb_log_debug2("Periodic current: %p.\n",
+		    instance->registers->periodic_current);
+		LIST_INITIALIZE(done);
+		transfer_list_remove_finished(
+		    &instance->transfers_interrupt, &done);
+		transfer_list_remove_finished(
+		    &instance->transfers_isochronous, &done);
+		transfer_list_remove_finished(
+		    &instance->transfers_control, &done);
+		transfer_list_remove_finished(
+		    &instance->transfers_bulk, &done);
+
+		while (!list_empty(&done)) {
+			link_t *item = done.next;
+			list_remove(item);
+			usb_transfer_batch_t *batch =
+			    list_get_instance(item, usb_transfer_batch_t, link);
+			usb_transfer_batch_finish(batch);
+		}
+		fibril_mutex_unlock(&instance->guard);
 	}
 }
@@ -184,5 +218,5 @@
 		instance->registers->interrupt_status = status;
 		hc_interrupt(instance, status);
-		async_usleep(1000);
+		async_usleep(50000);
 	}
 	return EOK;
@@ -192,12 +226,19 @@
 {
 	assert(instance);
+	/* Turn off legacy emulation */
+	volatile uint32_t *ohci_emulation_reg =
+	    (uint32_t*)((char*)instance->registers + 0x100);
+	usb_log_debug("OHCI legacy register %p: %x.\n",
+		ohci_emulation_reg, *ohci_emulation_reg);
+	*ohci_emulation_reg = 0;
+
 	/* Interrupt routing enabled => smm driver is active */
 	if (instance->registers->control & C_IR) {
-		usb_log_info("Found SMM driver requesting ownership change.\n");
+		usb_log_debug("SMM driver: request ownership change.\n");
 		instance->registers->command_status |= CS_OCR;
 		while (instance->registers->control & C_IR) {
 			async_usleep(1000);
 		}
-		usb_log_info("Ownership taken from SMM driver.\n");
+		usb_log_info("SMM driver: Ownership taken.\n");
 		return;
 	}
@@ -207,7 +248,7 @@
 	/* Interrupt routing disabled && status != USB_RESET => BIOS active */
 	if (hc_status != C_HCFS_RESET) {
-		usb_log_info("Found BIOS driver.\n");
+		usb_log_debug("BIOS driver found.\n");
 		if (hc_status == C_HCFS_OPERATIONAL) {
-			usb_log_info("HC operational(BIOS).\n");
+			usb_log_info("BIOS driver: HC operational.\n");
 			return;
 		}
@@ -215,4 +256,5 @@
 		instance->registers->control &= (C_HCFS_RESUME << C_HCFS_SHIFT);
 		async_usleep(20000);
+		usb_log_info("BIOS driver: HC resumed.\n");
 		return;
 	}
@@ -220,38 +262,74 @@
 	/* HC is in reset (hw startup) => no other driver
 	 * maintain reset for at least the time specified in USB spec (50 ms)*/
+	usb_log_info("HC found in reset.\n");
 	async_usleep(50000);
-
-	/* turn off legacy emulation */
-	volatile uint32_t *ohci_emulation_reg =
-	    (uint32_t*)((char*)instance->registers + 0x100);
-	usb_log_info("OHCI legacy register status %p: %x.\n",
-		ohci_emulation_reg, *ohci_emulation_reg);
-	*ohci_emulation_reg = 0;
-
 }
 /*----------------------------------------------------------------------------*/
 void hc_init_hw(hc_t *instance)
 {
-	assert(instance);
+	/* OHCI guide page 42 */
+	assert(instance);
+	usb_log_debug2("Started hc initialization routine.\n");
+
+	/* Save contents of fm_interval register */
 	const uint32_t fm_interval = instance->registers->fm_interval;
-
-	/* reset hc */
+	usb_log_debug2("Old value of HcFmInterval: %x.\n", fm_interval);
+
+	/* Reset hc */
+	usb_log_debug2("HC reset.\n");
+	size_t time = 0;
 	instance->registers->command_status = CS_HCR;
-	async_usleep(10);
-
-	/* restore fm_interval */
+	while (instance->registers->command_status & CS_HCR) {
+		async_usleep(10);
+		time += 10;
+	}
+	usb_log_debug2("HC reset complete in %zu us.\n", time);
+
+	/* Restore fm_interval */
 	instance->registers->fm_interval = fm_interval;
 	assert((instance->registers->command_status & CS_HCR) == 0);
 
 	/* hc is now in suspend state */
-
-	/* enable queues */
+	usb_log_debug2("HC should be in suspend state(%x).\n",
+	    instance->registers->control);
+
+	/* Use HCCA */
+	instance->registers->hcca = addr_to_phys(instance->hcca);
+
+	/* Use queues */
+	instance->registers->bulk_head = instance->transfers_bulk.list_head_pa;
+	usb_log_debug2("Bulk HEAD set to: %p(%p).\n",
+	    instance->transfers_bulk.list_head,
+	    instance->transfers_bulk.list_head_pa);
+
+	instance->registers->control_head =
+	    instance->transfers_control.list_head_pa;
+	usb_log_debug2("Control HEAD set to: %p(%p).\n",
+	    instance->transfers_control.list_head,
+	    instance->transfers_control.list_head_pa);
+
+	/* Enable queues */
 	instance->registers->control |= (C_PLE | C_IE | C_CLE | C_BLE);
-	/* TODO: enable interrupts */
-	/* set periodic start to 90% */
-	instance->registers->periodic_start = (fm_interval / 10) * 9;
+	usb_log_debug2("All queues enabled(%x).\n",
+	    instance->registers->control);
+
+	/* Disable interrupts */
+	instance->registers->interrupt_disable = I_SF | I_OC;
+	usb_log_debug2("Disabling interrupts: %x.\n",
+	    instance->registers->interrupt_disable);
+	instance->registers->interrupt_disable = I_MI;
+	usb_log_debug2("Enabled interrupts: %x.\n",
+	    instance->registers->interrupt_enable);
+
+	/* Set periodic start to 90% */
+	uint32_t frame_length = ((fm_interval >> FMI_FI_SHIFT) & FMI_FI_MASK);
+	instance->registers->periodic_start = (frame_length / 10) * 9;
+	usb_log_debug2("All periodic start set to: %x(%u - 90%% of %d).\n",
+	    instance->registers->periodic_start,
+	    instance->registers->periodic_start, frame_length);
 
 	instance->registers->control &= (C_HCFS_OPERATIONAL << C_HCFS_SHIFT);
-	usb_log_info("OHCI HC up and running.\n");
+	usb_log_info("OHCI HC up and running(%x).\n",
+	    instance->registers->control);
 }
 /*----------------------------------------------------------------------------*/
@@ -277,5 +355,5 @@
 	SETUP_TRANSFER_LIST(transfers_control, "CONTROL");
 	SETUP_TRANSFER_LIST(transfers_bulk, "BULK");
-
+#undef SETUP_TRANSFER_LIST
 	transfer_list_set_next(&instance->transfers_interrupt,
 	    &instance->transfers_isochronous);
@@ -292,5 +370,4 @@
 
 	return EOK;
-#undef CHECK_RET_CLEAR_RETURN
 }
 /*----------------------------------------------------------------------------*/
@@ -298,18 +375,13 @@
 {
 	assert(instance);
-	/* init queues */
+	/* Init queues */
 	hc_init_transfer_lists(instance);
 
-	/* init HCCA */
+	/*Init HCCA */
 	instance->hcca = malloc32(sizeof(hcca_t));
 	if (instance->hcca == NULL)
 		return ENOMEM;
 	bzero(instance->hcca, sizeof(hcca_t));
-	instance->registers->hcca = addr_to_phys(instance->hcca);
-
-	/* use queues */
-	instance->registers->bulk_head = instance->transfers_bulk.list_head_pa;
-	instance->registers->control_head =
-	    instance->transfers_control.list_head_pa;
+	usb_log_debug2("OHCI HCCA initialized at %p.\n", instance->hcca);
 
 	unsigned i = 0;
@@ -318,4 +390,7 @@
 		    instance->transfers_interrupt.list_head_pa;
 	}
+	usb_log_debug2("Interrupt HEADs set to: %p(%p).\n",
+	    instance->transfers_interrupt.list_head,
+	    instance->transfers_interrupt.list_head_pa);
 
 	return EOK;
Index: uspace/drv/ohci/hc.h
===================================================================
--- uspace/drv/ohci/hc.h	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/ohci/hc.h	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -69,4 +69,5 @@
 	usb_endpoint_manager_t ep_manager;
 	fid_t interrupt_emulator;
+	fibril_mutex_t guard;
 } hc_t;
 
Index: uspace/drv/ohci/hw_struct/endpoint_descriptor.c
===================================================================
--- uspace/drv/ohci/hw_struct/endpoint_descriptor.c	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/ohci/hw_struct/endpoint_descriptor.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -42,5 +42,5 @@
 	bzero(instance, sizeof(ed_t));
 	if (ep == NULL) {
-		instance->status |= ED_STATUS_K_FLAG;
+		instance->status = ED_STATUS_K_FLAG;
 		return;
 	}
@@ -53,4 +53,5 @@
 	        << ED_STATUS_MPS_SHIFT);
 
+
 	if (ep->speed == USB_SPEED_LOW)
 		instance->status |= ED_STATUS_S_FLAG;
@@ -58,6 +59,7 @@
 		instance->status |= ED_STATUS_F_FLAG;
 
+	if (ep->toggle)
+		instance->td_head |= ED_TDHEAD_TOGGLE_CARRY;
 }
-
 /**
  * @}
Index: uspace/drv/ohci/hw_struct/endpoint_descriptor.h
===================================================================
--- uspace/drv/ohci/hw_struct/endpoint_descriptor.h	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/ohci/hw_struct/endpoint_descriptor.h	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -53,6 +53,6 @@
 #define ED_STATUS_D_MASK (0x3)     /* direction */
 #define ED_STATUS_D_SHIFT (11)
-#define ED_STATUS_D_IN (0x1)
-#define ED_STATUS_D_OUT (0x2)
+#define ED_STATUS_D_OUT (0x1)
+#define ED_STATUS_D_IN (0x2)
 #define ED_STATUS_D_TRANSFER (0x3)
 
@@ -84,5 +84,7 @@
 {
 	assert(instance);
-	instance->td_head = addr_to_phys(head) & ED_TDHEAD_PTR_MASK;
+	instance->td_head =
+	    ((addr_to_phys(head) & ED_TDHEAD_PTR_MASK)
+	    | (instance->td_head & ~ED_TDHEAD_PTR_MASK));
 	instance->td_tail = addr_to_phys(tail) & ED_TDTAIL_PTR_MASK;
 }
@@ -96,5 +98,4 @@
 	instance->next = pa;
 }
-
 #endif
 /**
Index: uspace/drv/ohci/hw_struct/hcca.h
===================================================================
--- uspace/drv/ohci/hw_struct/hcca.h	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/ohci/hw_struct/hcca.h	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -43,5 +43,5 @@
 	uint32_t done_head;
 	uint32_t reserved[29];
-} __attribute__((packed)) hcca_t;
+} __attribute__((packed, aligned)) hcca_t;
 
 #endif
Index: uspace/drv/ohci/hw_struct/transfer_descriptor.c
===================================================================
--- uspace/drv/ohci/hw_struct/transfer_descriptor.c	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/ohci/hw_struct/transfer_descriptor.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -53,4 +53,5 @@
 	}
 	if (buffer != NULL) {
+		assert(size != 0);
 		instance->cbp = addr_to_phys(buffer);
 		instance->be = addr_to_phys(buffer + size - 1);
Index: uspace/drv/ohci/hw_struct/transfer_descriptor.h
===================================================================
--- uspace/drv/ohci/hw_struct/transfer_descriptor.h	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/ohci/hw_struct/transfer_descriptor.h	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -50,6 +50,6 @@
 #define TD_STATUS_DP_SHIFT (19)
 #define TD_STATUS_DP_SETUP (0x0)
-#define TD_STATUS_DP_IN (0x1)
-#define TD_STATUS_DP_OUT (0x2)
+#define TD_STATUS_DP_OUT (0x1)
+#define TD_STATUS_DP_IN (0x2)
 #define TD_STATUS_DI_MASK (0x7) /* delay interrupt, wait DI frames before int */
 #define TD_STATUS_DI_SHIFT (21)
@@ -86,5 +86,5 @@
 	int cc = (instance->status >> TD_STATUS_CC_SHIFT) & TD_STATUS_CC_MASK;
 	/* something went wrong, error code is set */
-	if (cc != CC_NOACCESS1 && cc != CC_NOACCESS2 && cc != CC_NOERROR) {
+	if (cc != CC_NOACCESS1 && cc != CC_NOACCESS2) {
 		return true;
 	}
Index: uspace/drv/ohci/iface.c
===================================================================
--- uspace/drv/ohci/iface.c	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/ohci/iface.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -63,4 +63,7 @@
 	}
 
+	usb_log_debug("%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);
@@ -68,73 +71,12 @@
 		usb_log_error("Endpoint(%d:%d) %s needs %zu bw "
 		    "but only %zu is reserved.\n",
-		    name, target.address, target.endpoint, bw, res_bw);
+		    target.address, target.endpoint, name, bw, res_bw);
 		return ENOSPC;
 	}
-	usb_log_debug("%s %d:%d %zu(%zu).\n",
-	    name, target.address, target.endpoint, size, ep->max_packet_size);
-
-	assert(ep->speed ==
-	    usb_device_keeper_get_speed(&(*hc)->manager, target.address));
-//	assert(ep->max_packet_size == max_packet_size);
-//	assert(ep->transfer_type == USB_TRANSFER_CONTROL);
-
-	*batch =
-	    batch_get(fun, ep, data, size, setup_data, setup_size,
-		in, out, arg);
-	if (!batch)
+
+	*batch = batch_get(
+	    fun, ep, data, size, setup_data, setup_size, in, out, arg);
+	if (!*batch)
 		return ENOMEM;
-	return EOK;
-}
-
-
-/** Reserve default address interface function
- *
- * @param[in] fun DDF function that was called.
- * @param[in] speed Speed to associate with the new default address.
- * @return Error code.
- */
-static int reserve_default_address(ddf_fun_t *fun, usb_speed_t speed)
-{
-	assert(fun);
-	hc_t *hc = fun_to_hc(fun);
-	assert(hc);
-	usb_log_debug("Default address request with speed %d.\n", speed);
-	usb_device_keeper_reserve_default_address(&hc->manager, speed);
-	return EOK;
-#if 0
-	endpoint_t *ep = malloc(sizeof(endpoint_t));
-	if (ep == NULL)
-		return ENOMEM;
-	const size_t max_packet_size = speed == USB_SPEED_LOW ? 8 : 64;
-	endpoint_init(ep, USB_TRANSFER_CONTROL, speed, max_packet_size);
-	int ret;
-try_retgister:
-	ret = usb_endpoint_manager_register_ep(&hc->ep_manager,
-	    USB_ADDRESS_DEFAULT, 0, USB_DIRECTION_BOTH, ep, endpoint_destroy, 0);
-	if (ret == EEXISTS) {
-		async_usleep(1000);
-		goto try_retgister;
-	}
-	if (ret != EOK) {
-		endpoint_destroy(ep);
-	}
-	return ret;
-#endif
-}
-/*----------------------------------------------------------------------------*/
-/** Release default address interface function
- *
- * @param[in] fun DDF function that was called.
- * @return Error code.
- */
-static int release_default_address(ddf_fun_t *fun)
-{
-	assert(fun);
-	hc_t *hc = fun_to_hc(fun);
-	assert(hc);
-	usb_log_debug("Default address release.\n");
-//	return usb_endpoint_manager_unregister_ep(&hc->ep_manager,
-//	    USB_ADDRESS_DEFAULT, 0, USB_DIRECTION_BOTH);
-	usb_device_keeper_release_default_address(&hc->manager);
 	return EOK;
 }
@@ -216,15 +158,15 @@
 	hc_t *hc = fun_to_hc(fun);
 	assert(hc);
-	if (address == hc->rh.address)
-		return EOK;
+
 	usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, address);
 	if (speed >= USB_SPEED_MAX) {
 		speed = ep_speed;
 	}
-	const size_t size =
-	    (transfer_type == USB_TRANSFER_INTERRUPT
-	    || transfer_type == USB_TRANSFER_ISOCHRONOUS) ?
-	    max_packet_size : 0;
+	const size_t size = max_packet_size;
 	int ret;
+
+	usb_log_debug("Register endpoint %d:%d %s %s(%d) %zu(%zu) %u.\n",
+	    address, endpoint, usb_str_transfer_type(transfer_type),
+	    usb_str_speed(speed), direction, size, max_packet_size, interval);
 
 	endpoint_t *ep = malloc(sizeof(endpoint_t));
@@ -238,13 +180,7 @@
 	}
 
-	usb_log_debug("Register endpoint %d:%d %s %s(%d) %zu(%zu) %u.\n",
-	    address, endpoint, usb_str_transfer_type(transfer_type),
-	    usb_str_speed(speed), direction, size, max_packet_size, interval);
-
 	ret = usb_endpoint_manager_register_ep(&hc->ep_manager, ep, size);
 	if (ret != EOK) {
 		endpoint_destroy(ep);
-	} else {
-		usb_device_keeper_add_ep(&hc->manager, address, ep);
 	}
 	return ret;
@@ -259,9 +195,4 @@
 	usb_log_debug("Unregister endpoint %d:%d %d.\n",
 	    address, endpoint, direction);
-	endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
-	    address, endpoint, direction, NULL);
-	if (ep != NULL) {
-		usb_device_keeper_del_ep(&hc->manager, address, ep);
-	}
 	return usb_endpoint_manager_unregister_ep(&hc->ep_manager, address,
 	    endpoint, direction);
@@ -435,5 +366,5 @@
 	if (ret != EOK)
 		return ret;
-	usb_device_keeper_reset_if_need(&hc->manager, target, setup_data);
+	usb_endpoint_manager_reset_if_need(&hc->ep_manager, target, setup_data);
 	batch_control_write(batch);
 	ret = hc_schedule(hc, batch);
@@ -484,6 +415,4 @@
 /*----------------------------------------------------------------------------*/
 usbhc_iface_t hc_iface = {
-	.reserve_default_address = reserve_default_address,
-	.release_default_address = release_default_address,
 	.request_address = request_address,
 	.bind_address = bind_address,
Index: uspace/drv/ohci/ohci.ma
===================================================================
--- uspace/drv/ohci/ohci.ma	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/ohci/ohci.ma	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -1,1 +1,3 @@
 10 pci/ven=106b&dev=003f
+10 pci/ven=10de&dev=0aa5
+10 pci/ven=10de&dev=0aa5
Index: uspace/drv/ohci/ohci_regs.h
===================================================================
--- uspace/drv/ohci/ohci_regs.h	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/ohci/ohci_regs.h	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -84,5 +84,5 @@
 	/** Interupt enable/disable, reads give the same value, writing causes
 	 * enable/disable */
-	volatile uint32_t interupt_enable;
+	volatile uint32_t interrupt_enable;
 	volatile uint32_t interrupt_disable;
 #define I_SO   (1 << 0)   /* Scheduling overrun */
@@ -100,6 +100,6 @@
 #define HCCA_PTR_MASK 0xffffff00 /* HCCA is 256B aligned */
 
-	/** Currently executed period endpoint */
-	const volatile uint32_t period_current;
+	/** Currently executed periodic endpoint */
+	const volatile uint32_t periodic_current;
 
 	/** The first control endpoint */
@@ -120,5 +120,5 @@
 	/** Frame time and max packet size for all transfers */
 	volatile uint32_t fm_interval;
-#define FMI_FI_MASK (0x1fff) /* Frame interval in bit times (should be 11999)*/
+#define FMI_FI_MASK (0x3fff) /* Frame interval in bit times (should be 11999)*/
 #define FMI_FI_SHIFT (0)
 #define FMI_FSMPS_MASK (0x7fff) /* Full speed max packet size */
@@ -138,5 +138,5 @@
 	/** Remaining bit time in frame to start periodic transfers */
 	volatile uint32_t periodic_start;
-#define PS_PS_MASK (0x1fff) /* bit time when periodic get priority (0x3e67) */
+#define PS_PS_MASK (0x3fff) /* bit time when periodic get priority (0x3e67) */
 
 	/** Threshold for starting LS transaction */
Index: uspace/drv/ohci/root_hub.c
===================================================================
--- uspace/drv/ohci/root_hub.c	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/ohci/root_hub.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -210,5 +210,6 @@
 	instance->registers = regs;
 	instance->device = dev;
-	instance->port_count = instance->registers->rh_desc_a & 0xff;
+	instance->port_count =
+	    (instance->registers->rh_desc_a >> RHDA_NDS_SHIFT) & RHDA_NDS_MASK;
 	rh_init_descriptors(instance);
 	// set port power mode to no-power-switching
Index: uspace/drv/ohci/transfer_list.c
===================================================================
--- uspace/drv/ohci/transfer_list.c	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/ohci/transfer_list.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -79,5 +79,4 @@
 	assert(instance);
 	assert(next);
-	/* Set both queue_head.next to point to the follower */
 	ed_append_ed(instance->list_head, next->list_head);
 }
@@ -122,6 +121,12 @@
 	usb_transfer_batch_t *first = list_get_instance(
 	    instance->batch_list.next, usb_transfer_batch_t, link);
-	usb_log_debug("Batch(%p) added to queue %s, first is %p.\n",
-		batch, instance->name, first);
+	usb_log_debug("Batch(%p) added to list %s, first is %p(%p).\n",
+		batch, instance->name, first, batch_ed(first));
+	if (last_ed == instance->list_head) {
+		usb_log_debug2("%s head ED(%p-%p): %x:%x:%x:%x.\n",
+		    instance->name, last_ed, instance->list_head_pa,
+		    last_ed->status, last_ed->td_tail, last_ed->td_head,
+		    last_ed->next);
+	}
 	fibril_mutex_unlock(&instance->guard);
 }
@@ -138,4 +143,6 @@
 
 	fibril_mutex_lock(&instance->guard);
+	usb_log_debug2("Checking list %s for completed batches(%d).\n",
+	    instance->name, list_count(&instance->batch_list));
 	link_t *current = instance->batch_list.next;
 	while (current != &instance->batch_list) {
Index: uspace/drv/ohci/utils/malloc32.h
===================================================================
--- uspace/drv/ohci/utils/malloc32.h	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/ohci/utils/malloc32.h	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -41,5 +41,4 @@
 #include <as.h>
 
-#define UHCI_STRCUTURES_ALIGNMENT 16
 #define UHCI_REQUIRED_PAGE_SIZE 4096
 
@@ -65,5 +64,5 @@
  */
 static inline void * malloc32(size_t size)
-	{ return memalign(UHCI_STRCUTURES_ALIGNMENT, size); }
+	{ return memalign(size, size); }
 /*----------------------------------------------------------------------------*/
 /** Physical mallocator simulator
Index: uspace/drv/uhci-hcd/iface.c
===================================================================
--- uspace/drv/uhci-hcd/iface.c	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/uhci-hcd/iface.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -63,4 +63,7 @@
 	}
 
+	usb_log_debug("%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);
@@ -68,73 +71,12 @@
 		usb_log_error("Endpoint(%d:%d) %s needs %zu bw "
 		    "but only %zu is reserved.\n",
-		    name, target.address, target.endpoint, bw, res_bw);
+		    target.address, target.endpoint, name, bw, res_bw);
 		return ENOSPC;
 	}
-	usb_log_debug("%s %d:%d %zu(%zu).\n",
-	    name, target.address, target.endpoint, size, ep->max_packet_size);
-
-//	assert(ep->speed ==
-//	    usb_device_keeper_get_speed(&(*hc)->manager, target.address));
-//	assert(ep->max_packet_size == max_packet_size);
-//	assert(ep->transfer_type == USB_TRANSFER_CONTROL);
-
-	*batch =
-	    batch_get(fun, ep, data, size, setup_data, setup_size,
-		in, out, arg);
-	if (!batch)
+
+	*batch = batch_get(
+	        fun, ep, data, size, setup_data, setup_size, in, out, arg);
+	if (!*batch)
 		return ENOMEM;
-	return EOK;
-}
-
-
-/** Reserve default address interface function
- *
- * @param[in] fun DDF function that was called.
- * @param[in] speed Speed to associate with the new default address.
- * @return Error code.
- */
-static int reserve_default_address(ddf_fun_t *fun, usb_speed_t speed)
-{
-	assert(fun);
-	hc_t *hc = fun_to_hc(fun);
-	assert(hc);
-	usb_log_debug("Default address request with speed %d.\n", speed);
-	usb_device_keeper_reserve_default_address(&hc->manager, speed);
-	return EOK;
-#if 0
-	endpoint_t *ep = malloc(sizeof(endpoint_t));
-	if (ep == NULL)
-		return ENOMEM;
-	const size_t max_packet_size = speed == USB_SPEED_LOW ? 8 : 64;
-	endpoint_init(ep, USB_TRANSFER_CONTROL, speed, max_packet_size);
-	int ret;
-try_retgister:
-	ret = usb_endpoint_manager_register_ep(&hc->ep_manager,
-	    USB_ADDRESS_DEFAULT, 0, USB_DIRECTION_BOTH, ep, endpoint_destroy, 0);
-	if (ret == EEXISTS) {
-		async_usleep(1000);
-		goto try_retgister;
-	}
-	if (ret != EOK) {
-		endpoint_destroy(ep);
-	}
-	return ret;
-#endif
-}
-/*----------------------------------------------------------------------------*/
-/** Release default address interface function
- *
- * @param[in] fun DDF function that was called.
- * @return Error code.
- */
-static int release_default_address(ddf_fun_t *fun)
-{
-	assert(fun);
-	hc_t *hc = fun_to_hc(fun);
-	assert(hc);
-	usb_log_debug("Default address release.\n");
-//	return usb_endpoint_manager_unregister_ep(&hc->ep_manager,
-//	    USB_ADDRESS_DEFAULT, 0, USB_DIRECTION_BOTH);
-	usb_device_keeper_release_default_address(&hc->manager);
 	return EOK;
 }
@@ -205,13 +147,14 @@
 	hc_t *hc = fun_to_hc(fun);
 	assert(hc);
+	const size_t size = max_packet_size;
+	int ret;
 	usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, address);
 	if (speed >= USB_SPEED_MAX) {
 		speed = ep_speed;
 	}
-	const size_t size =
-	    (transfer_type == USB_TRANSFER_INTERRUPT
-	    || transfer_type == USB_TRANSFER_ISOCHRONOUS) ?
-	    max_packet_size : 0;
-	int ret;
+	usb_log_debug("Register endpoint %d:%d %s %s(%d) %zu(%zu) %u.\n",
+	    address, endpoint, usb_str_transfer_type(transfer_type),
+	    usb_str_speed(speed), direction, size, max_packet_size, interval);
+
 
 	endpoint_t *ep = malloc(sizeof(endpoint_t));
@@ -225,13 +168,7 @@
 	}
 
-	usb_log_debug("Register endpoint %d:%d %s %s(%d) %zu(%zu) %u.\n",
-	    address, endpoint, usb_str_transfer_type(transfer_type),
-	    usb_str_speed(speed), direction, size, max_packet_size, interval);
-
 	ret = usb_endpoint_manager_register_ep(&hc->ep_manager, ep, size);
 	if (ret != EOK) {
 		endpoint_destroy(ep);
-	} else {
-		usb_device_keeper_add_ep(&hc->manager, address, ep);
 	}
 	return ret;
@@ -246,9 +183,4 @@
 	usb_log_debug("Unregister endpoint %d:%d %d.\n",
 	    address, endpoint, direction);
-	endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
-	    address, endpoint, direction, NULL);
-	if (ep != NULL) {
-		usb_device_keeper_del_ep(&hc->manager, address, ep);
-	}
 	return usb_endpoint_manager_unregister_ep(&hc->ep_manager, address,
 	    endpoint, direction);
@@ -391,5 +323,5 @@
 	if (ret != EOK)
 		return ret;
-	usb_device_keeper_reset_if_need(&hc->manager, target, setup_data);
+	usb_endpoint_manager_reset_if_need(&hc->ep_manager, target, setup_data);
 	batch_control_write(batch);
 	ret = hc_schedule(hc, batch);
@@ -433,6 +365,4 @@
 /*----------------------------------------------------------------------------*/
 usbhc_iface_t hc_iface = {
-	.reserve_default_address = reserve_default_address,
-	.release_default_address = release_default_address,
 	.request_address = request_address,
 	.bind_address = bind_address,
Index: uspace/drv/usbhid/Makefile
===================================================================
--- uspace/drv/usbhid/Makefile	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/usbhid/Makefile	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -40,8 +40,10 @@
 	main.c \
 	usbhid.c \
+	subdrivers.c \
 	kbd/conv.c \
 	kbd/kbddev.c \
 	kbd/kbdrepeat.c \
 	generic/hiddev.c \
+	mouse/mousedev.c \
 	$(STOLEN_LAYOUT_SOURCES)
 
Index: uspace/drv/usbhid/generic/hiddev.c
===================================================================
--- uspace/drv/usbhid/generic/hiddev.c	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/usbhid/generic/hiddev.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -39,4 +39,5 @@
 
 #include "hiddev.h"
+#include "usbhid.h"
 
 /*----------------------------------------------------------------------------*/
@@ -54,8 +55,9 @@
 /*----------------------------------------------------------------------------*/
 
-bool usb_hid_polling_callback(usb_device_t *dev, uint8_t *buffer,
-     size_t buffer_size, void *arg)
+bool usb_generic_hid_polling_callback(usb_hid_dev_t *hid_dev, 
+    uint8_t *buffer, size_t buffer_size)
 {
-	usb_log_debug("usb_hid_polling_callback()\n");
+	usb_log_debug("usb_hid_polling_callback(%p, %p, %zu)\n",
+	    hid_dev, buffer, buffer_size);
 	usb_debug_str_buffer(buffer, buffer_size, 0);
 	return true;
Index: uspace/drv/usbhid/generic/hiddev.h
===================================================================
--- uspace/drv/usbhid/generic/hiddev.h	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/usbhid/generic/hiddev.h	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -34,8 +34,10 @@
  */
 
-#ifndef USB_HIDD_H_
-#define USB_HIDD_H_
+#ifndef USB_HID_HIDDDEV_H_
+#define USB_HID_HIDDDEV_H_
 
 #include <usb/devdrv.h>
+
+struct usb_hid_dev;
 
 usb_endpoint_description_t usb_hid_generic_poll_endpoint_description;
@@ -44,8 +46,8 @@
 const char *HID_GENERIC_CLASS_NAME;
 
-bool usb_hid_polling_callback(usb_device_t *dev, uint8_t *buffer,
-     size_t buffer_size, void *arg);
+bool usb_generic_hid_polling_callback(struct usb_hid_dev *hid_dev,
+    uint8_t *buffer, size_t buffer_size);
 
-#endif // USB_HIDD_H_
+#endif // USB_HID_HIDDDEV_H_
 
 /**
Index: uspace/drv/usbhid/kbd/conv.h
===================================================================
--- uspace/drv/usbhid/kbd/conv.h	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/usbhid/kbd/conv.h	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -34,10 +34,10 @@
  */
 
-#ifndef USB_KBD_CONV_H_
-#define USB_KBD_CONV_H_
+#ifndef USB_HID_CONV_H_
+#define USB_HID_CONV_H_
 
 unsigned int usbhid_parse_scancode(int scancode);
 
-#endif /* USB_KBD_CONV_H_ */
+#endif /* USB_HID_CONV_H_ */
 
 /**
Index: uspace/drv/usbhid/kbd/kbddev.c
===================================================================
--- uspace/drv/usbhid/kbd/kbddev.c	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/usbhid/kbd/kbddev.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -238,5 +238,5 @@
  * @param icall Call data.
  */
-void default_connection_handler(ddf_fun_t *fun,
+static void default_connection_handler(ddf_fun_t *fun,
     ipc_callid_t icallid, ipc_call_t *icall)
 {
@@ -856,13 +856,11 @@
 /*----------------------------------------------------------------------------*/
 
-bool usb_kbd_polling_callback(usb_device_t *dev, uint8_t *buffer,
-     size_t buffer_size, void *arg)
-{
-	if (dev == NULL || buffer == NULL || arg == NULL) {
+bool usb_kbd_polling_callback(usb_hid_dev_t *hid_dev, uint8_t *buffer,
+     size_t buffer_size)
+{
+	if (hid_dev == NULL || buffer == NULL) {
 		// do not continue polling (???)
 		return false;
 	}
-	
-	usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg;
 	
 	// TODO: add return value from this function
@@ -916,5 +914,5 @@
 /*----------------------------------------------------------------------------*/
 
-void usb_kbd_deinit(struct usb_hid_dev_t *hid_dev)
+void usb_kbd_deinit(usb_hid_dev_t *hid_dev)
 {
 	if (hid_dev == NULL) {
Index: uspace/drv/usbhid/kbd/kbddev.h
===================================================================
--- uspace/drv/usbhid/kbd/kbddev.h	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/usbhid/kbd/kbddev.h	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -34,6 +34,6 @@
  */
 
-#ifndef USB_KBDDEV_H_
-#define USB_KBDDEV_H_
+#ifndef USB_HID_KBDDEV_H_
+#define USB_HID_KBDDEV_H_
 
 #include <stdint.h>
@@ -49,5 +49,5 @@
 #include "kbdrepeat.h"
 
-struct usb_hid_dev_t;
+struct usb_hid_dev;
 
 /*----------------------------------------------------------------------------*/
@@ -65,8 +65,4 @@
  */
 typedef struct usb_kbd_t {
-	/** Structure holding generic USB device information. */
-	//usbhid_dev_t *hid_dev;
-	//usb_device_t *usb_dev;
-	
 	/** Currently pressed keys (not translated to key codes). */
 	uint8_t *keys;
@@ -91,10 +87,4 @@
 	fibril_mutex_t *repeat_mtx;
 	
-	/** Report descriptor. */
-	//uint8_t *report_desc;
-
-	/** Report descriptor size. */
-	//size_t report_desc_size;
-	
 	uint8_t *output_buffer;
 	
@@ -106,7 +96,4 @@
 	
 	int32_t *led_data;
-
-	/** HID Report parser. */
-	//usb_hid_report_parser_t *parser;
 	
 	/** State of the structure (for checking before use). 
@@ -121,14 +108,4 @@
 /*----------------------------------------------------------------------------*/
 
-//enum {
-//	USB_KBD_POLL_EP_NO = 0,
-//	USB_HID_POLL_EP_NO = 1,
-//	USB_KBD_POLL_EP_COUNT = 2
-//};
-
-//usb_endpoint_description_t *usb_kbd_endpoints[USB_KBD_POLL_EP_COUNT + 1];
-
-//ddf_dev_ops_t keyboard_ops;
-
 usb_endpoint_description_t usb_hid_kbd_poll_endpoint_description;
 
@@ -138,13 +115,8 @@
 /*----------------------------------------------------------------------------*/
 
-//usb_kbd_t *usb_kbd_new(void);
+int usb_kbd_init(struct usb_hid_dev *hid_dev);
 
-int usb_kbd_init(struct usb_hid_dev_t *hid_dev);
-
-bool usb_kbd_polling_callback(usb_device_t *dev, uint8_t *buffer,
-     size_t buffer_size, void *arg);
-
-//void usb_kbd_polling_ended_callback(usb_device_t *dev, bool reason, 
-//     void *arg);
+bool usb_kbd_polling_callback(struct usb_hid_dev *hid_dev, uint8_t *buffer,
+    size_t buffer_size);
 
 int usb_kbd_is_initialized(const usb_kbd_t *kbd_dev);
@@ -154,13 +126,12 @@
 void usb_kbd_free(usb_kbd_t **kbd_dev);
 
-void usb_kbd_push_ev(struct usb_hid_dev_t *hid_dev, usb_kbd_t *kbd_dev,
+void usb_kbd_push_ev(struct usb_hid_dev *hid_dev, usb_kbd_t *kbd_dev,
     int type, unsigned int key);
 
+void usb_kbd_deinit(struct usb_hid_dev *hid_dev);
 
-void usb_kbd_deinit(struct usb_hid_dev_t *hid_dev);
+int usb_kbd_set_boot_protocol(struct usb_hid_dev *hid_dev);
 
-int usb_kbd_set_boot_protocol(struct usb_hid_dev_t *hid_dev);
-
-#endif /* USB_KBDDEV_H_ */
+#endif /* USB_HID_KBDDEV_H_ */
 
 /**
Index: uspace/drv/usbhid/kbd/kbdrepeat.h
===================================================================
--- uspace/drv/usbhid/kbd/kbdrepeat.h	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/usbhid/kbd/kbdrepeat.h	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -34,6 +34,6 @@
  */
 
-#ifndef USB_KBDREPEAT_H_
-#define USB_KBDREPEAT_H_
+#ifndef USB_HID_KBDREPEAT_H_
+#define USB_HID_KBDREPEAT_H_
 
 struct usb_kbd_t;
@@ -62,5 +62,5 @@
 void usb_kbd_repeat_stop(struct usb_kbd_t *kbd, unsigned int key);
 
-#endif /* USB_KBDREPEAT_H_ */
+#endif /* USB_HID_KBDREPEAT_H_ */
 
 /**
Index: uspace/drv/usbhid/layout.h
===================================================================
--- uspace/drv/usbhid/layout.h	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/usbhid/layout.h	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -36,6 +36,6 @@
  */
 
-#ifndef USB_KBD_LAYOUT_H_
-#define USB_KBD_LAYOUT_H_
+#ifndef USB_HID_LAYOUT_H_
+#define USB_HID_LAYOUT_H_
 
 #include <sys/types.h>
Index: uspace/drv/usbhid/main.c
===================================================================
--- uspace/drv/usbhid/main.c	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/usbhid/main.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -98,5 +98,5 @@
 	/* Create the function exposed under /dev/devices. */
 	ddf_fun_t *hid_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, 
-	    usb_hid_get_function_name(hid_dev->device_type));
+	    usb_hid_get_function_name(hid_dev));
 	if (hid_fun == NULL) {
 		usb_log_error("Could not create DDF function node.\n");
@@ -122,6 +122,5 @@
 	}
 	
-	rc = ddf_fun_add_to_class(hid_fun, 
-	    usb_hid_get_class_name(hid_dev->device_type));
+	rc = ddf_fun_add_to_class(hid_fun, usb_hid_get_class_name(hid_dev));
 	if (rc != EOK) {
 		usb_log_error(
@@ -142,5 +141,5 @@
 	   hid_dev->poll_pipe_index,
 	   /* Callback when data arrives. */
-	   hid_dev->poll_callback,
+	   usb_hid_polling_callback,
 	   /* How much data to request. */
 	   dev->pipes[hid_dev->poll_pipe_index].pipe->max_packet_size,
Index: uspace/drv/usbhid/mouse/mousedev.c
===================================================================
--- uspace/drv/usbhid/mouse/mousedev.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
+++ uspace/drv/usbhid/mouse/mousedev.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -0,0 +1,322 @@
+/*
+ * Copyright (c) 2011 Lubos Slovak, 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 drvusbhid
+ * @{
+ */
+/**
+ * @file
+ * USB Mouse driver API.
+ */
+
+#include <usb/debug.h>
+#include <usb/classes/classes.h>
+#include <usb/classes/hid.h>
+#include <usb/classes/hidreq.h>
+#include <errno.h>
+#include <str_error.h>
+#include <ipc/mouse.h>
+
+#include "mousedev.h"
+#include "../usbhid.h"
+
+/*----------------------------------------------------------------------------*/
+
+usb_endpoint_description_t usb_hid_mouse_poll_endpoint_description = {
+	.transfer_type = USB_TRANSFER_INTERRUPT,
+	.direction = USB_DIRECTION_IN,
+	.interface_class = USB_CLASS_HID,
+	.interface_subclass = USB_HID_SUBCLASS_BOOT,
+	.interface_protocol = USB_HID_PROTOCOL_MOUSE,
+	.flags = 0
+};
+
+const char *HID_MOUSE_FUN_NAME = "mouse";
+const char *HID_MOUSE_CLASS_NAME = "mouse";
+
+/** Default idle rate for mouses. */
+static const uint8_t IDLE_RATE = 0;
+
+/*----------------------------------------------------------------------------*/
+
+enum {
+	USB_MOUSE_BOOT_REPORT_DESCRIPTOR_SIZE = 63
+};
+
+static const uint8_t USB_MOUSE_BOOT_REPORT_DESCRIPTOR[
+    USB_MOUSE_BOOT_REPORT_DESCRIPTOR_SIZE] = {
+	0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
+	0x09, 0x02,                    // USAGE (Mouse)
+	0xa1, 0x01,                    // COLLECTION (Application)
+	0x09, 0x01,                    //   USAGE (Pointer)
+	0xa1, 0x00,                    //   COLLECTION (Physical)
+	0x95, 0x03,                    //     REPORT_COUNT (3)
+	0x75, 0x01,                    //     REPORT_SIZE (1)
+	0x05, 0x09,                    //     USAGE_PAGE (Button)
+	0x19, 0x01,                    //     USAGE_MINIMUM (Button 1)
+	0x29, 0x03,                    //     USAGE_MAXIMUM (Button 3)
+	0x15, 0x00,                    //     LOGICAL_MINIMUM (0)
+	0x25, 0x01,                    //     LOGICAL_MAXIMUM (1)
+	0x81, 0x02,                    //     INPUT (Data,Var,Abs)
+	0x95, 0x01,                    //     REPORT_COUNT (1)
+	0x75, 0x05,                    //     REPORT_SIZE (5)
+	0x81, 0x01,                    //     INPUT (Cnst)
+	0x75, 0x08,                    //     REPORT_SIZE (8)
+	0x95, 0x02,                    //     REPORT_COUNT (2)
+	0x05, 0x01,                    //     USAGE_PAGE (Generic Desktop)
+	0x09, 0x30,                    //     USAGE (X)
+	0x09, 0x31,                    //     USAGE (Y)
+	0x15, 0x81,                    //     LOGICAL_MINIMUM (-127)
+	0x25, 0x7f,                    //     LOGICAL_MAXIMUM (127)
+	0x81, 0x06,                    //     INPUT (Data,Var,Rel)
+	0xc0,                          //   END_COLLECTION
+	0xc0                           // END_COLLECTION
+};
+
+/*----------------------------------------------------------------------------*/
+
+/** Default handler for IPC methods not handled by DDF.
+ *
+ * @param fun Device function handling the call.
+ * @param icallid Call id.
+ * @param icall Call data.
+ */
+static void default_connection_handler(ddf_fun_t *fun,
+    ipc_callid_t icallid, ipc_call_t *icall)
+{
+	sysarg_t method = IPC_GET_IMETHOD(*icall);
+	
+	usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
+	
+	if (hid_dev == NULL || hid_dev->data == NULL) {
+		async_answer_0(icallid, EINVAL);
+		return;
+	}
+	
+	assert(hid_dev != NULL);
+	assert(hid_dev->data != NULL);
+	usb_mouse_t *mouse_dev = (usb_mouse_t *)hid_dev->data;
+	
+	if (method == IPC_M_CONNECT_TO_ME) {
+		int callback = IPC_GET_ARG5(*icall);
+
+		if (mouse_dev->console_phone != -1) {
+			async_answer_0(icallid, ELIMIT);
+			return;
+		}
+
+		mouse_dev->console_phone = callback;
+		usb_log_debug("Console phone to mouse set ok (%d).\n", callback);
+		async_answer_0(icallid, EOK);
+		return;
+	}
+
+	async_answer_0(icallid, EINVAL);
+}
+
+/*----------------------------------------------------------------------------*/
+
+static usb_mouse_t *usb_mouse_new(void)
+{
+	usb_mouse_t *mouse = calloc(1, sizeof(usb_mouse_t));
+	if (mouse == NULL) {
+		return NULL;
+	}
+	mouse->console_phone = -1;
+	
+	return mouse;
+}
+
+/*----------------------------------------------------------------------------*/
+
+static void usb_mouse_free(usb_mouse_t **mouse_dev)
+{
+	if (mouse_dev == NULL || *mouse_dev == NULL) {
+		return;
+	}
+	
+	// hangup phone to the console
+	async_hangup((*mouse_dev)->console_phone);
+	
+	free(*mouse_dev);
+	*mouse_dev = NULL;
+}
+
+/*----------------------------------------------------------------------------*/
+
+static bool usb_mouse_process_boot_report(usb_mouse_t *mouse_dev,
+    uint8_t *buffer, size_t buffer_size)
+{
+	usb_log_debug2("got buffer: %s.\n",
+	    usb_debug_str_buffer(buffer, buffer_size, 0));
+
+	uint8_t butt = buffer[0];
+	char str_buttons[4] = {
+		butt & 1 ? '#' : '.',
+		butt & 2 ? '#' : '.',
+		butt & 4 ? '#' : '.',
+		0
+	};
+
+	int shift_x = ((int) buffer[1]) - 127;
+	int shift_y = ((int) buffer[2]) - 127;
+	int wheel = ((int) buffer[3]) - 127;
+
+	if (buffer[1] == 0) {
+		shift_x = 0;
+	}
+	if (buffer[2] == 0) {
+		shift_y = 0;
+	}
+	if (buffer[3] == 0) {
+		wheel = 0;
+	}
+	
+	if (mouse_dev->console_phone >= 0) {
+		usb_log_debug("Console phone: %d\n", mouse_dev->console_phone);
+		if ((shift_x != 0) || (shift_y != 0)) {
+			/* FIXME: guessed for QEMU */
+			async_req_2_0(mouse_dev->console_phone,
+			    MEVENT_MOVE,
+			    - shift_x / 10,  - shift_y / 10);
+		} else {
+			usb_log_error("No move reported\n");
+		}
+		if (butt) {
+			/* FIXME: proper button clicking. */
+			async_req_2_0(mouse_dev->console_phone,
+			    MEVENT_BUTTON, 1, 1);
+			async_req_2_0(mouse_dev->console_phone,
+			    MEVENT_BUTTON, 1, 0);
+		}
+	} else {
+		usb_log_error("No console phone in mouse!!\n");
+	}
+
+	usb_log_debug("buttons=%s  dX=%+3d  dY=%+3d  wheel=%+3d\n",
+	    str_buttons, shift_x, shift_y, wheel);
+
+	/* Guess. */
+	//async_usleep(1000);
+	// no sleep right now
+
+	return true;
+}
+
+/*----------------------------------------------------------------------------*/
+
+int usb_mouse_init(usb_hid_dev_t *hid_dev)
+{
+	usb_log_debug("Initializing HID/Mouse structure...\n");
+	
+	if (hid_dev == NULL) {
+		usb_log_error("Failed to init keyboard structure: no structure"
+		    " given.\n");
+		return EINVAL;
+	}
+	
+	usb_mouse_t *mouse_dev = usb_mouse_new();
+	if (mouse_dev == NULL) {
+		usb_log_error("Error while creating USB/HID Mouse device "
+		    "structure.\n");
+		return ENOMEM;
+	}
+	
+	// save the Mouse device structure into the HID device structure
+	hid_dev->data = mouse_dev;
+	
+	// set handler for incoming calls
+	hid_dev->ops.default_handler = default_connection_handler;
+	
+	// TODO: how to know if the device supports the request???
+	usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe, 
+	    hid_dev->usb_dev->interface_no, IDLE_RATE);
+	
+	return EOK;
+}
+
+/*----------------------------------------------------------------------------*/
+
+bool usb_mouse_polling_callback(usb_hid_dev_t *hid_dev, uint8_t *buffer,
+     size_t buffer_size)
+{
+	usb_log_debug("usb_mouse_polling_callback()\n");
+	usb_debug_str_buffer(buffer, buffer_size, 0);
+	
+	if (hid_dev == NULL) {
+		usb_log_error("Missing argument to the mouse polling callback."
+		    "\n");
+		return false;
+	}
+	
+	if (hid_dev->data == NULL) {
+		usb_log_error("Wrong argument to the mouse polling callback."
+		    "\n");
+		return false;
+	}
+	usb_mouse_t *mouse_dev = (usb_mouse_t *)hid_dev->data;
+	
+	return usb_mouse_process_boot_report(mouse_dev, buffer, buffer_size);
+}
+
+/*----------------------------------------------------------------------------*/
+
+void usb_mouse_deinit(usb_hid_dev_t *hid_dev)
+{
+	usb_mouse_free((usb_mouse_t **)&hid_dev->data);
+}
+
+/*----------------------------------------------------------------------------*/
+
+int usb_mouse_set_boot_protocol(usb_hid_dev_t *hid_dev)
+{
+	int rc = usb_hid_parse_report_descriptor(hid_dev->parser, 
+	    USB_MOUSE_BOOT_REPORT_DESCRIPTOR, 
+	    USB_MOUSE_BOOT_REPORT_DESCRIPTOR_SIZE);
+	
+	if (rc != EOK) {
+		usb_log_error("Failed to parse boot report descriptor: %s\n",
+		    str_error(rc));
+		return rc;
+	}
+	
+	rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe, 
+	    hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT);
+	
+	if (rc != EOK) {
+		usb_log_warning("Failed to set boot protocol to the device: "
+		    "%s\n", str_error(rc));
+		return rc;
+	}
+	
+	return EOK;
+}
+
+/**
+ * @}
+ */
Index: uspace/drv/usbhid/mouse/mousedev.h
===================================================================
--- uspace/drv/usbhid/mouse/mousedev.h	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
+++ uspace/drv/usbhid/mouse/mousedev.h	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2011 Lubos Slovak
+ * 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 drvusbhid
+ * @{
+ */
+/** @file
+ * USB Mouse driver API.
+ */
+
+#ifndef USB_HID_MOUSEDEV_H_
+#define USB_HID_MOUSEDEV_H_
+
+#include <usb/devdrv.h>
+
+struct usb_hid_dev;
+
+/*----------------------------------------------------------------------------*/
+
+/** Container for USB mouse device. */
+typedef struct {
+	///** Polling interval in microseconds. */
+	//suseconds_t poll_interval_us;
+	/** IPC phone to console (consumer). */
+	int console_phone;
+} usb_mouse_t;
+
+/*----------------------------------------------------------------------------*/
+
+usb_endpoint_description_t usb_hid_mouse_poll_endpoint_description;
+
+const char *HID_MOUSE_FUN_NAME;
+const char *HID_MOUSE_CLASS_NAME;
+
+/*----------------------------------------------------------------------------*/
+
+int usb_mouse_init(struct usb_hid_dev *hid_dev);
+
+bool usb_mouse_polling_callback(struct usb_hid_dev *hid_dev, uint8_t *buffer,
+    size_t buffer_size);
+
+void usb_mouse_deinit(struct usb_hid_dev *hid_dev);
+
+int usb_mouse_set_boot_protocol(struct usb_hid_dev *hid_dev);
+
+/*----------------------------------------------------------------------------*/
+
+#endif // USB_HID_MOUSEDEV_H_
+
+/**
+ * @}
+ */
Index: uspace/drv/usbhid/subdrivers.c
===================================================================
--- uspace/drv/usbhid/subdrivers.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
+++ uspace/drv/usbhid/subdrivers.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2011 Lubos Slovak
+ * 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 drvusbhid
+ * @{
+ */
+/** @file
+ * USB HID subdriver mappings.
+ */
+
+#include "subdrivers.h"
+#include "usb/classes/hidut.h"
+
+static usb_hid_subdriver_usage_t path_kbd[] = {{USB_HIDUT_PAGE_KEYBOARD, 0}};
+
+const usb_hid_subdriver_mapping_t usb_hid_subdrivers[] = {
+	{
+		path_kbd,
+		1,
+		USB_HID_PATH_COMPARE_END 
+		| USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
+		NULL,
+		NULL,
+		{
+			usb_kbd_init,
+			usb_kbd_deinit,
+			usb_kbd_polling_callback,
+			NULL
+		},
+		
+	},
+	{NULL, 0, 0, NULL, NULL, {NULL, NULL, NULL, NULL}}
+};
+
+/**
+ * @}
+ */
Index: uspace/drv/usbhid/subdrivers.h
===================================================================
--- uspace/drv/usbhid/subdrivers.h	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
+++ uspace/drv/usbhid/subdrivers.h	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2011 Lubos Slovak
+ * 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 drvusbhid
+ * @{
+ */
+/** @file
+ * USB HID subdriver mappings.
+ */
+
+#ifndef USB_HID_SUBDRIVERS_H_
+#define USB_HID_SUBDRIVERS_H_
+
+#include "usbhid.h"
+#include "kbd/kbddev.h"
+
+/*----------------------------------------------------------------------------*/
+
+typedef struct usb_hid_subdriver_usage {
+	int usage_page;
+	int usage;
+} usb_hid_subdriver_usage_t;
+
+/*----------------------------------------------------------------------------*/
+
+/* TODO: This mapping must contain some other information to get the proper
+ *       interface.
+ */
+typedef struct usb_hid_subdriver_mapping {
+	const usb_hid_subdriver_usage_t *usage_path;
+	int path_size;
+	int compare;
+	const char *vendor_id;
+	const char *product_id;
+	usb_hid_subdriver_t subdriver;
+} usb_hid_subdriver_mapping_t;
+
+/*----------------------------------------------------------------------------*/
+
+extern const usb_hid_subdriver_mapping_t usb_hid_subdrivers[];
+
+/*----------------------------------------------------------------------------*/
+
+#endif /* USB_HID_SUBDRIVERS_H_ */
+
+/**
+ * @}
+ */
Index: uspace/drv/usbhid/usbhid.c
===================================================================
--- uspace/drv/usbhid/usbhid.c	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/usbhid/usbhid.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -42,4 +42,5 @@
 #include <usb/classes/hidreq.h>
 #include <errno.h>
+#include <str_error.h>
 
 #include "usbhid.h"
@@ -47,16 +48,8 @@
 #include "kbd/kbddev.h"
 #include "generic/hiddev.h"
-
-/*----------------------------------------------------------------------------*/
-
-/** Mouse polling endpoint description for boot protocol class. */
-static usb_endpoint_description_t usb_hid_mouse_poll_endpoint_description = {
-	.transfer_type = USB_TRANSFER_INTERRUPT,
-	.direction = USB_DIRECTION_IN,
-	.interface_class = USB_CLASS_HID,
-	.interface_subclass = USB_HID_SUBCLASS_BOOT,
-	.interface_protocol = USB_HID_PROTOCOL_MOUSE,
-	.flags = 0
-};
+#include "mouse/mousedev.h"
+#include "subdrivers.h"
+
+/*----------------------------------------------------------------------------*/
 
 /* Array of endpoints expected on the device, NULL terminated. */
@@ -68,6 +61,252 @@
 };
 
-static const char *HID_MOUSE_FUN_NAME = "mouse";
-static const char *HID_MOUSE_CLASS_NAME = "mouse";
+static const int USB_HID_MAX_SUBDRIVERS = 10;
+
+/*----------------------------------------------------------------------------*/
+
+static int usb_hid_set_boot_kbd_subdriver(usb_hid_dev_t *hid_dev)
+{
+	assert(hid_dev->subdriver_count == 0);
+	
+	hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc(
+	    sizeof(usb_hid_subdriver_t));
+	if (hid_dev->subdrivers == NULL) {
+		return ENOMEM;
+	}
+	
+	// set the init callback
+	hid_dev->subdrivers[0].init = usb_kbd_init;
+	
+	// set the polling callback
+	hid_dev->subdrivers[0].poll = usb_kbd_polling_callback;
+	
+	// set the polling ended callback
+	hid_dev->subdrivers[0].poll_end = NULL;
+	
+	// set the deinit callback
+	hid_dev->subdrivers[0].deinit = usb_kbd_deinit;
+	
+	// set subdriver count
+	hid_dev->subdriver_count = 1;
+	
+	return EOK;
+}
+
+/*----------------------------------------------------------------------------*/
+
+static int usb_hid_set_boot_mouse_subdriver(usb_hid_dev_t *hid_dev)
+{
+	assert(hid_dev->subdriver_count == 0);
+	
+	hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc(
+	    sizeof(usb_hid_subdriver_t));
+	if (hid_dev->subdrivers == NULL) {
+		return ENOMEM;
+	}
+	
+	// set the init callback
+	hid_dev->subdrivers[0].init = usb_mouse_init;
+	
+	// set the polling callback
+	hid_dev->subdrivers[0].poll = usb_mouse_polling_callback;
+	
+	// set the polling ended callback
+	hid_dev->subdrivers[0].poll_end = NULL;
+	
+	// set the deinit callback
+	hid_dev->subdrivers[0].deinit = usb_mouse_deinit;
+	
+	// set subdriver count
+	hid_dev->subdriver_count = 1;
+	
+	return EOK;
+}
+
+/*----------------------------------------------------------------------------*/
+
+static int usb_hid_set_generic_hid_subdriver(usb_hid_dev_t *hid_dev)
+{
+	assert(hid_dev->subdriver_count == 0);
+	
+	hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc(
+	    sizeof(usb_hid_subdriver_t));
+	if (hid_dev->subdrivers == NULL) {
+		return ENOMEM;
+	}
+	
+	// set the init callback
+	hid_dev->subdrivers[0].init = NULL;
+	
+	// set the polling callback
+	hid_dev->subdrivers[0].poll = usb_generic_hid_polling_callback;
+	
+	// set the polling ended callback
+	hid_dev->subdrivers[0].poll_end = NULL;
+	
+	// set the deinit callback
+	hid_dev->subdrivers[0].deinit = NULL;
+	
+	// set subdriver count
+	hid_dev->subdriver_count = 1;
+	
+	return EOK;
+}
+
+/*----------------------------------------------------------------------------*/
+
+static bool usb_hid_ids_match(usb_hid_dev_t *hid_dev, 
+    const usb_hid_subdriver_mapping_t *mapping)
+{
+	return false;
+}
+
+/*----------------------------------------------------------------------------*/
+
+static bool usb_hid_path_matches(usb_hid_dev_t *hid_dev, 
+    const usb_hid_subdriver_usage_t *path, int path_size, int compare)
+{
+	assert(hid_dev != NULL);
+	assert(path != NULL);
+	
+	usb_hid_report_path_t *usage_path = usb_hid_report_path();
+	if (usage_path == NULL) {
+		usb_log_debug("Failed to create usage path.\n");
+		return false;
+	}
+	int i;
+	for (i = 0; i < path_size; ++i) {
+		if (usb_hid_report_path_append_item(usage_path, 
+		    path[i].usage_page, path[i].usage) != EOK) {
+			usb_log_debug("Failed to append to usage path.\n");
+			usb_hid_report_path_free(usage_path);
+			return false;
+		}
+	}
+	
+	assert(hid_dev->parser != NULL);
+	
+	usb_log_debug("Compare flags: %d\n", compare);
+	size_t size = usb_hid_report_input_length(hid_dev->parser, usage_path, 
+	    compare);
+	usb_log_debug("Size of the input report: %d\n", size);
+	
+	usb_hid_report_path_free(usage_path);
+	
+	return (size > 0);
+}
+
+/*----------------------------------------------------------------------------*/
+
+static int usb_hid_save_subdrivers(usb_hid_dev_t *hid_dev, 
+    const usb_hid_subdriver_t **subdrivers, int count)
+{
+	int i;
+	
+	if (count <= 0) {
+		hid_dev->subdriver_count = 0;
+		hid_dev->subdrivers = NULL;
+		return EOK;
+	}
+	
+	hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc(count * 
+	    sizeof(usb_hid_subdriver_t));
+	if (hid_dev->subdrivers == NULL) {
+		return ENOMEM;
+	}
+	
+	for (i = 0; i < count; ++i) {
+		hid_dev->subdrivers[i].init = subdrivers[i]->init;
+		hid_dev->subdrivers[i].deinit = subdrivers[i]->deinit;
+		hid_dev->subdrivers[i].poll = subdrivers[i]->poll;
+		hid_dev->subdrivers[i].poll_end = subdrivers[i]->poll_end;
+	}
+	
+	hid_dev->subdriver_count = count;
+	
+	return EOK;
+}
+
+/*----------------------------------------------------------------------------*/
+
+static int usb_hid_find_subdrivers(usb_hid_dev_t *hid_dev)
+{
+	const usb_hid_subdriver_t *subdrivers[USB_HID_MAX_SUBDRIVERS];
+	
+	int i = 0, count = 0;
+	const usb_hid_subdriver_mapping_t *mapping = &usb_hid_subdrivers[i];
+	
+	while (count < USB_HID_MAX_SUBDRIVERS &&
+	    (mapping->usage_path != NULL
+	    || mapping->vendor_id != NULL
+	    || mapping->product_id != NULL)) {
+		// check the vendor & product ID
+		if (mapping->vendor_id != NULL && mapping->product_id == NULL) {
+			usb_log_warning("Missing Product ID for Vendor ID %s\n",
+			    mapping->vendor_id);
+			return EINVAL;
+		}
+		if (mapping->product_id != NULL && mapping->vendor_id == NULL) {
+			usb_log_warning("Missing Vendor ID for Product ID %s\n",
+			    mapping->product_id);
+			return EINVAL;
+		}
+		
+		if (mapping->vendor_id != NULL) {
+			assert(mapping->product_id != NULL);
+			usb_log_debug("Comparing device against vendor ID %s"
+			    " and product ID %s.\n", mapping->vendor_id,
+			    mapping->product_id);
+			if (usb_hid_ids_match(hid_dev, mapping)) {
+				usb_log_debug("Matched.\n");
+				subdrivers[count++] = &mapping->subdriver;
+				// skip the checking of usage path
+				goto next;
+			}
+		}
+		
+		if (mapping->usage_path != NULL) {
+			usb_log_debug("Comparing device against usage path.\n");
+			if (usb_hid_path_matches(hid_dev, 
+			    mapping->usage_path, mapping->path_size,
+			    mapping->compare)) {
+				subdrivers[count++] = &mapping->subdriver;
+			} else {
+				usb_log_debug("Not matched.\n");
+			}
+		}
+	next:
+		mapping = &usb_hid_subdrivers[++i];
+	}
+	
+	// we have all subdrivers determined, save them into the hid device
+	return usb_hid_save_subdrivers(hid_dev, subdrivers, count);
+}
+
+/*----------------------------------------------------------------------------*/
+
+static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, usb_device_t *dev)
+{
+	int rc = EOK;
+	
+	if (dev->pipes[USB_HID_KBD_POLL_EP_NO].present) {
+		usb_log_debug("Found keyboard endpoint.\n");
+		// save the pipe index
+		hid_dev->poll_pipe_index = USB_HID_KBD_POLL_EP_NO;
+	} else if (dev->pipes[USB_HID_MOUSE_POLL_EP_NO].present) {
+		usb_log_debug("Found mouse endpoint.\n");
+		// save the pipe index
+		hid_dev->poll_pipe_index = USB_HID_MOUSE_POLL_EP_NO;
+	} else if (dev->pipes[USB_HID_GENERIC_POLL_EP_NO].present) {
+		usb_log_debug("Found generic HID endpoint.\n");
+		// save the pipe index
+		hid_dev->poll_pipe_index = USB_HID_GENERIC_POLL_EP_NO;
+	} else {
+		usb_log_error("None of supported endpoints found - probably"
+		    " not a supported device.\n");
+		rc = ENOTSUP;
+	}
+	
+	return rc;
+}
 
 /*----------------------------------------------------------------------------*/
@@ -91,4 +330,6 @@
 	}
 	
+	hid_dev->poll_pipe_index = -1;
+	
 	return hid_dev;
 }
@@ -96,91 +337,7 @@
 /*----------------------------------------------------------------------------*/
 
-static bool usb_dummy_polling_callback(usb_device_t *dev, uint8_t *buffer,
-     size_t buffer_size, void *arg)
-{
-	usb_log_debug("Dummy polling callback.\n");
-	return false;
-}
-
-/*----------------------------------------------------------------------------*/
-
-static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, usb_device_t *dev)
-{
-	if (dev->pipes[USB_HID_KBD_POLL_EP_NO].present) {
-		usb_log_debug("Found keyboard endpoint.\n");
-		
-		// save the pipe index and device type
-		hid_dev->poll_pipe_index = USB_HID_KBD_POLL_EP_NO;
-		hid_dev->device_type = USB_HID_PROTOCOL_KEYBOARD;
-		
-		// set the polling callback
-		hid_dev->poll_callback = usb_kbd_polling_callback;
-
-	} else if (dev->pipes[USB_HID_MOUSE_POLL_EP_NO].present) {
-		usb_log_debug("Found mouse endpoint.\n");
-		
-		// save the pipe index and device type
-		hid_dev->poll_pipe_index = USB_HID_MOUSE_POLL_EP_NO;
-		hid_dev->device_type = USB_HID_PROTOCOL_MOUSE;
-		
-		// set the polling callback
-		hid_dev->poll_callback = usb_dummy_polling_callback;
-		
-	} else if (dev->pipes[USB_HID_GENERIC_POLL_EP_NO].present) {
-		usb_log_debug("Found generic HID endpoint.\n");
-		
-		// save the pipe index and device type
-		hid_dev->poll_pipe_index = USB_HID_GENERIC_POLL_EP_NO;
-		hid_dev->device_type = USB_HID_PROTOCOL_NONE;
-		
-		// set the polling callback
-		hid_dev->poll_callback = usb_hid_polling_callback;
-		
-	} else {
-		usb_log_warning("None of supported endpoints found - probably"
-		    " not a supported device.\n");
-		return ENOTSUP;
-	}
-	
-	return EOK;
-}
-
-/*----------------------------------------------------------------------------*/
-
-static int usb_hid_init_parser(usb_hid_dev_t *hid_dev)
-{
-	/* Initialize the report parser. */
-	int rc = usb_hid_parser_init(hid_dev->parser);
-	if (rc != EOK) {
-		usb_log_error("Failed to initialize report parser.\n");
-		return rc;
-	}
-	
-	/* Get the report descriptor and parse it. */
-	rc = usb_hid_process_report_descriptor(hid_dev->usb_dev, 
-	    hid_dev->parser);
-	
-	if (rc != EOK) {
-		usb_log_warning("Could not process report descriptor.\n");
-		
-		if (hid_dev->device_type == USB_HID_PROTOCOL_KEYBOARD) {
-			usb_log_warning("Falling back to boot protocol.\n");
-			
-			rc = usb_kbd_set_boot_protocol(hid_dev);
-			
-		} else if (hid_dev->device_type == USB_HID_PROTOCOL_MOUSE) {
-			usb_log_warning("No boot protocol for mouse yet.\n");
-			rc = ENOTSUP;
-		}
-	}
-	
-	return rc;
-}
-
-/*----------------------------------------------------------------------------*/
-
 int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev)
 {
-	int rc;
+	int rc, i;
 	
 	usb_log_debug("Initializing HID structure...\n");
@@ -203,31 +360,125 @@
 	rc = usb_hid_check_pipes(hid_dev, dev);
 	if (rc != EOK) {
+		usb_hid_free(&hid_dev);
 		return rc;
 	}
 	
-	rc = usb_hid_init_parser(hid_dev);
+	/* Initialize the report parser. */
+	rc = usb_hid_parser_init(hid_dev->parser);
 	if (rc != EOK) {
-		usb_log_error("Failed to initialize HID parser.\n");
+		usb_log_error("Failed to initialize report parser.\n");
+		usb_hid_free(&hid_dev);
 		return rc;
 	}
 	
-	switch (hid_dev->device_type) {
-	case USB_HID_PROTOCOL_KEYBOARD:
-		// initialize the keyboard structure
-		rc = usb_kbd_init(hid_dev);
-		if (rc != EOK) {
-			usb_log_warning("Failed to initialize KBD structure."
-			    "\n");
-		}
-		break;
-	case USB_HID_PROTOCOL_MOUSE:
-		break;
-	default:
-//		usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe, 
-//		    hid_dev->usb_dev->interface_no, 0);
-		break;
+	/* Get the report descriptor and parse it. */
+	rc = usb_hid_process_report_descriptor(hid_dev->usb_dev, 
+	    hid_dev->parser);
+	
+	bool fallback = false;
+	
+	if (rc == EOK) {
+		// try to find subdrivers that may want to handle this device
+		rc = usb_hid_find_subdrivers(hid_dev);
+		if (rc != EOK || hid_dev->subdriver_count == 0) {
+			// try to fall back to the boot protocol if available
+			usb_log_info("No subdrivers found to handle this"
+			    " device.\n");
+			fallback = true;
+		}
+	} else {
+		usb_log_error("Failed to parse Report descriptor.\n");
+		// try to fall back to the boot protocol if available
+		fallback = true;
+	}
+	
+	// TODO: remove the mouse hack
+	if (hid_dev->poll_pipe_index == USB_HID_MOUSE_POLL_EP_NO ||
+	    fallback) {
+		// fall back to boot protocol
+		switch (hid_dev->poll_pipe_index) {
+		case USB_HID_KBD_POLL_EP_NO:
+			usb_log_info("Falling back to kbd boot protocol.\n");
+			rc = usb_kbd_set_boot_protocol(hid_dev);
+			if (rc == EOK) {
+				rc = usb_hid_set_boot_kbd_subdriver(hid_dev);
+			}
+			break;
+		case USB_HID_MOUSE_POLL_EP_NO:
+			usb_log_info("Falling back to mouse boot protocol.\n");
+			rc = usb_mouse_set_boot_protocol(hid_dev);
+			if (rc == EOK) {
+				rc = usb_hid_set_boot_mouse_subdriver(hid_dev);
+			}
+			break;
+		default:
+			assert(hid_dev->poll_pipe_index 
+			    == USB_HID_GENERIC_POLL_EP_NO);
+			
+			/* TODO: this has no meaning if the report descriptor
+			         is not parsed */
+			usb_log_info("Falling back to generic HID driver.\n");
+			rc = usb_hid_set_generic_hid_subdriver(hid_dev);
+		}
+	}
+	
+	if (rc != EOK) {
+		usb_log_error("No subdriver for handling this device could be"
+		    " initialized: %s.\n", str_error(rc));
+		usb_hid_free(&hid_dev);
+	} else {
+		bool ok = false;
+		
+		usb_log_debug("Subdriver count: %d\n", 
+		    hid_dev->subdriver_count);
+		
+		for (i = 0; i < hid_dev->subdriver_count; ++i) {
+			if (hid_dev->subdrivers[i].init != NULL) {
+				usb_log_debug("Initializing subdriver %d.\n",i);
+				rc = hid_dev->subdrivers[i].init(hid_dev);
+				if (rc != EOK) {
+					usb_log_warning("Failed to initialize"
+					    " HID subdriver structure.\n");
+				} else {
+					// at least one subdriver initialized
+					ok = true;
+				}
+			} else {
+				ok = true;
+			}
+		}
+		
+		rc = (ok) ? EOK : -1;	// what error to report
 	}
 	
 	return rc;
+}
+
+/*----------------------------------------------------------------------------*/
+
+bool usb_hid_polling_callback(usb_device_t *dev, uint8_t *buffer, 
+    size_t buffer_size, void *arg)
+{
+	int i;
+	
+	if (dev == NULL || arg == NULL || buffer == NULL) {
+		usb_log_error("Missing arguments to polling callback.\n");
+		return false;
+	}
+	
+	usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg;
+	
+	bool cont = false;
+	
+	// continue if at least one of the subdrivers want to continue
+	for (i = 0; i < hid_dev->subdriver_count; ++i) {
+		if (hid_dev->subdrivers[i].poll != NULL
+		    && hid_dev->subdrivers[i].poll(hid_dev, buffer, 
+		    buffer_size)) {
+			cont = true;
+		}
+	}
+	
+	return cont;
 }
 
@@ -237,4 +488,6 @@
      void *arg)
 {
+	int i; 
+	
 	if (dev == NULL || arg == NULL) {
 		return;
@@ -243,4 +496,10 @@
 	usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg;
 	
+	for (i = 0; i < hid_dev->subdriver_count; ++i) {
+		if (hid_dev->subdrivers[i].poll_end != NULL) {
+			hid_dev->subdrivers[i].poll_end(hid_dev, reason);
+		}
+	}
+	
 	usb_hid_free(&hid_dev);
 }
@@ -248,11 +507,11 @@
 /*----------------------------------------------------------------------------*/
 
-const char *usb_hid_get_function_name(usb_hid_iface_protocol_t device_type)
-{
-	switch (device_type) {
-	case USB_HID_PROTOCOL_KEYBOARD:
+const char *usb_hid_get_function_name(const usb_hid_dev_t *hid_dev)
+{
+	switch (hid_dev->poll_pipe_index) {
+	case USB_HID_KBD_POLL_EP_NO:
 		return HID_KBD_FUN_NAME;
 		break;
-	case USB_HID_PROTOCOL_MOUSE:
+	case USB_HID_MOUSE_POLL_EP_NO:
 		return HID_MOUSE_FUN_NAME;
 		break;
@@ -264,11 +523,14 @@
 /*----------------------------------------------------------------------------*/
 
-const char *usb_hid_get_class_name(usb_hid_iface_protocol_t device_type)
-{
-	switch (device_type) {
-	case USB_HID_PROTOCOL_KEYBOARD:
+const char *usb_hid_get_class_name(const usb_hid_dev_t *hid_dev)
+{
+	// this means that only boot protocol keyboards will be connected
+	// to the console; there is probably no better way to do this
+	
+	switch (hid_dev->poll_pipe_index) {
+	case USB_HID_KBD_POLL_EP_NO:
 		return HID_KBD_CLASS_NAME;
 		break;
-	case USB_HID_PROTOCOL_MOUSE:
+	case USB_HID_MOUSE_POLL_EP_NO:
 		return HID_MOUSE_CLASS_NAME;
 		break;
@@ -282,16 +544,22 @@
 void usb_hid_free(usb_hid_dev_t **hid_dev)
 {
+	int i;
+	
 	if (hid_dev == NULL || *hid_dev == NULL) {
 		return;
 	}
 	
-	switch ((*hid_dev)->device_type) {
-	case USB_HID_PROTOCOL_KEYBOARD:
-		usb_kbd_deinit(*hid_dev);
-		break;
-	case USB_HID_PROTOCOL_MOUSE:
-		break;
-	default:
-		break;
+	assert((*hid_dev)->subdrivers != NULL 
+	    || (*hid_dev)->subdriver_count == 0);
+	
+	for (i = 0; i < (*hid_dev)->subdriver_count; ++i) {
+		if ((*hid_dev)->subdrivers[i].deinit != NULL) {
+			(*hid_dev)->subdrivers[i].deinit(*hid_dev);
+		}
+	}
+	
+	// free the subdrivers info
+	if ((*hid_dev)->subdrivers != NULL) {
+		free((*hid_dev)->subdrivers);
 	}
 
Index: uspace/drv/usbhid/usbhid.h
===================================================================
--- uspace/drv/usbhid/usbhid.h	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/usbhid/usbhid.h	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -34,6 +34,6 @@
  */
 
-#ifndef USB_USBHID_H_
-#define USB_USBHID_H_
+#ifndef USB_HID_USBHID_H_
+#define USB_HID_USBHID_H_
 
 #include <stdint.h>
@@ -45,9 +45,28 @@
 #include <usb/classes/hid.h>
 
+struct usb_hid_dev;
+
+typedef int (*usb_hid_driver_init_t)(struct usb_hid_dev *);
+typedef void (*usb_hid_driver_deinit_t)(struct usb_hid_dev *);
+typedef bool (*usb_hid_driver_poll)(struct usb_hid_dev *, uint8_t *, size_t);
+typedef int (*usb_hid_driver_poll_ended)(struct usb_hid_dev *, bool reason);
+
+// TODO: add function and class name??
+typedef struct usb_hid_subdriver {	
+	/** Function to be called when initializing HID device. */
+	usb_hid_driver_init_t init;
+	/** Function to be called when destroying the HID device structure. */
+	usb_hid_driver_deinit_t deinit;
+	/** Function to be called when data arrives from the device. */
+	usb_hid_driver_poll poll;
+	/** Function to be called when polling ends. */
+	usb_hid_driver_poll_ended poll_end;
+} usb_hid_subdriver_t;
+
 /*----------------------------------------------------------------------------*/
 /**
  * Structure for holding general HID device data.
  */
-typedef struct usb_hid_dev_t {
+typedef struct usb_hid_dev {
 	/** Structure holding generic USB device information. */
 	usb_device_t *usb_dev;
@@ -59,6 +78,9 @@
 	int poll_pipe_index;
 	
-	/** Function to be called when data arrives from the device. */
-	usb_polling_callback_t poll_callback;
+	/** Subdrivers. */
+	usb_hid_subdriver_t *subdrivers;
+	
+	/** Number of subdrivers. */
+	int subdriver_count;
 	
 	/** Report descriptor. */
@@ -73,7 +95,4 @@
 	/** Arbitrary data (e.g. a special structure for handling keyboard). */
 	void *data;
-	
-	/** Type of the device (keyboard, mouse, generic HID device). */
-	usb_hid_iface_protocol_t device_type;
 } usb_hid_dev_t;
 
@@ -95,14 +114,17 @@
 int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev);
 
+bool usb_hid_polling_callback(usb_device_t *dev, uint8_t *buffer, 
+    size_t buffer_size, void *arg);
+
 void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason, 
      void *arg);
 
-const char *usb_hid_get_function_name(usb_hid_iface_protocol_t device_type);
+const char *usb_hid_get_function_name(const usb_hid_dev_t *hid_dev);
 
-const char *usb_hid_get_class_name(usb_hid_iface_protocol_t device_type);
+const char *usb_hid_get_class_name(const usb_hid_dev_t *hid_dev);
 
 void usb_hid_free(usb_hid_dev_t **hid_dev);
 
-#endif /* USB_USBHID_H_ */
+#endif /* USB_HID_USBHID_H_ */
 
 /**
Index: uspace/drv/usbhid/usbhid.ma
===================================================================
--- uspace/drv/usbhid/usbhid.ma	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/usbhid/usbhid.ma	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -1,3 +1,3 @@
 100 usb&interface&class=HID&subclass=0x01&protocol=0x01
-100 usb&interface&class=HID&subclass=0x01&protocol=0x02
+1000 usb&interface&class=HID&subclass=0x01&protocol=0x02
 100 usb&interface&class=HID
Index: uspace/drv/usbhub/ports.c
===================================================================
--- uspace/drv/usbhub/ports.c	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/usbhub/ports.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -181,9 +181,18 @@
 		 */
 	} else {
-		usb_log_warning("this is strange, disconnected device had "
-			"no address\n");
-		//device was disconnected before it`s port was reset -
-		//return default address
-		usb_hub_release_default_address(hub);
+		// TODO: is this really reason to print a warning?
+		usb_log_warning("Device removed before being registered.\n");
+
+		/*
+		 * Device was removed before port reset completed.
+		 * We will announce a failed port reset to unblock the
+		 * port reset callback from new device wrapper.
+		 */
+		usb_hub_port_t *the_port = hub->ports + port;
+		fibril_mutex_lock(&the_port->reset_mutex);
+		the_port->reset_completed = true;
+		the_port->reset_okay = false;
+		fibril_condvar_broadcast(&the_port->reset_cv);
+		fibril_mutex_unlock(&the_port->reset_mutex);
 	}
 }
@@ -207,4 +216,5 @@
 		fibril_mutex_lock(&the_port->reset_mutex);
 		the_port->reset_completed = true;
+		the_port->reset_okay = true;
 		fibril_condvar_broadcast(&the_port->reset_cv);
 		fibril_mutex_unlock(&the_port->reset_mutex);
@@ -319,5 +329,9 @@
 	}
 
-	return EOK;
+	if (my_port->reset_okay) {
+		return EOK;
+	} else {
+		return ESTALL;
+	}
 }
 
Index: uspace/drv/usbhub/ports.h
===================================================================
--- uspace/drv/usbhub/ports.h	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/usbhub/ports.h	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -51,4 +51,6 @@
 	 */
 	bool reset_completed;
+	/** Whether to announce the port reset as successful. */
+	bool reset_okay;
 
 	/** Information about attached device. */
Index: uspace/drv/usbhub/usbhub.c
===================================================================
--- uspace/drv/usbhub/usbhub.c	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/usbhub/usbhub.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -179,23 +179,4 @@
 }
 
-/**
- * release default address used by given hub
- *
- * Also unsets hub->is_default_address_used. Convenience wrapper function.
- * @note hub->connection MUST be open for communication
- * @param hub hub representation
- * @return error code
- */
-int usb_hub_release_default_address(usb_hub_info_t * hub) {
-	int opResult = usb_hc_release_default_address(&hub->connection);
-	if (opResult != EOK) {
-		usb_log_error("could not release default address, errno %d\n",
-		    opResult);
-		return opResult;
-	}
-	hub->is_default_address_used = false;
-	return EOK;
-}
-
 
 //*********************************************
@@ -266,9 +247,11 @@
 	for (port = 0; port < hub_info->port_count + 1; port++) {
 		usb_hub_port_init(&hub_info->ports[port]);
+	}
+	for (port = 0; port < hub_info->port_count; port++) {
 		opResult = usb_hub_set_port_feature(hub_info->control_pipe,
-		    port, USB_HUB_FEATURE_PORT_POWER);
+		    port+1, USB_HUB_FEATURE_PORT_POWER);
 		if (opResult != EOK) {
 			usb_log_error("cannot power on port %d;  %d\n",
-			    port, opResult);
+			    port+1, opResult);
 		}
 	}
Index: uspace/drv/usbhub/usbhub.h
===================================================================
--- uspace/drv/usbhub/usbhub.h	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/usbhub/usbhub.h	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -98,6 +98,4 @@
     uint8_t *change_bitmap, size_t change_bitmap_size, void *arg);
 
-int usb_hub_release_default_address(usb_hub_info_t * hub);
-
 #endif
 /**
Index: uspace/drv/vhc/connhost.c
===================================================================
--- uspace/drv/vhc/connhost.c	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/drv/vhc/connhost.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -324,16 +324,4 @@
 }
 
-static int reserve_default_address(ddf_fun_t *fun, usb_speed_t ignored)
-{
-	usb_address_keeping_reserve_default(&addresses);
-	return EOK;
-}
-
-static int release_default_address(ddf_fun_t *fun)
-{
-	usb_address_keeping_release_default(&addresses);
-	return EOK;
-}
-
 static int request_address(ddf_fun_t *fun, usb_speed_t ignored,
     usb_address_t *address)
@@ -388,6 +376,4 @@
 
 usbhc_iface_t vhc_iface = {
-	.reserve_default_address = reserve_default_address,
-	.release_default_address = release_default_address,
 	.request_address = request_address,
 	.bind_address = bind_address,
Index: uspace/lib/drv/generic/remote_usbhc.c
===================================================================
--- uspace/lib/drv/generic/remote_usbhc.c	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/lib/drv/generic/remote_usbhc.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -50,6 +50,4 @@
 static void remote_usbhc_control_write(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
 static void remote_usbhc_control_read(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
-static void remote_usbhc_reserve_default_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
-static void remote_usbhc_release_default_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
 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 *);
@@ -61,7 +59,4 @@
 /** Remote USB host controller interface operations. */
 static remote_iface_func_ptr_t remote_usbhc_iface_ops [] = {
-	remote_usbhc_reserve_default_address,
-	remote_usbhc_release_default_address,
-
 	remote_usbhc_request_address,
 	remote_usbhc_bind_address,
@@ -127,36 +122,4 @@
 
 	return trans;
-}
-
-void remote_usbhc_reserve_default_address(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->reserve_default_address) {
-		async_answer_0(callid, ENOTSUP);
-		return;
-	}
-	
-	usb_speed_t speed = DEV_IPC_GET_ARG1(*call);
-	
-	int rc = usb_iface->reserve_default_address(fun, speed);
-
-	async_answer_0(callid, rc);
-}
-
-void remote_usbhc_release_default_address(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->release_default_address) {
-		async_answer_0(callid, ENOTSUP);
-		return;
-	}
-
-	int rc = usb_iface->release_default_address(fun);
-
-	async_answer_0(callid, rc);
 }
 
Index: uspace/lib/drv/include/usbhc_iface.h
===================================================================
--- uspace/lib/drv/include/usbhc_iface.h	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/lib/drv/include/usbhc_iface.h	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -84,19 +84,4 @@
  */
 typedef enum {
-	/** Reserve usage of default address.
-	 * This call informs the host controller that the caller will be
-	 * using default USB address. It is duty of the HC driver to ensure
-	 * that only single entity will have it reserved.
-	 * The address is returned via IPC_M_USBHC_RELEASE_DEFAULT_ADDRESS.
-	 * The caller can start using the address after receiving EOK
-	 * answer.
-	 */
-	IPC_M_USBHC_RESERVE_DEFAULT_ADDRESS,
-
-	/** Release usage of default address.
-	 * @see IPC_M_USBHC_RESERVE_DEFAULT_ADDRESS
-	 */
-	IPC_M_USBHC_RELEASE_DEFAULT_ADDRESS,
-
 	/** Asks for address assignment by host controller.
 	 * Answer:
Index: uspace/lib/usb/Makefile
===================================================================
--- uspace/lib/usb/Makefile	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/lib/usb/Makefile	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -34,4 +34,5 @@
 SOURCES = \
 	src/addrkeep.c \
+	src/altiface.c \
 	src/class.c \
 	src/ddfiface.c \
Index: uspace/lib/usb/include/usb/devdrv.h
===================================================================
--- uspace/lib/usb/include/usb/devdrv.h	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/lib/usb/include/usb/devdrv.h	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -174,6 +174,9 @@
     usb_endpoint_mapping_t **, size_t *);
 int usb_device_destroy_pipes(ddf_dev_t *, usb_endpoint_mapping_t *, size_t);
+int usb_device_create(ddf_dev_t *, usb_endpoint_description_t **, usb_device_t **, const char **);
 
 size_t usb_interface_count_alternates(uint8_t *, size_t, uint8_t);
+int usb_alternate_interfaces_create(uint8_t *, size_t, int,
+    usb_alternate_interfaces_t **);
 
 #endif
Index: uspace/lib/usb/include/usb/host/device_keeper.h
===================================================================
--- uspace/lib/usb/include/usb/host/device_keeper.h	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/lib/usb/include/usb/host/device_keeper.h	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -71,9 +71,4 @@
 void usb_device_keeper_init(usb_device_keeper_t *instance);
 
-void usb_device_keeper_add_ep(
-    usb_device_keeper_t *instance, usb_address_t address, endpoint_t *ep);
-void usb_device_keeper_del_ep(
-    usb_device_keeper_t *instance, usb_address_t address, endpoint_t *ep);
-
 void usb_device_keeper_reserve_default_address(
     usb_device_keeper_t *instance, usb_speed_t speed);
Index: uspace/lib/usb/include/usb/host/endpoint.h
===================================================================
--- uspace/lib/usb/include/usb/host/endpoint.h	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/lib/usb/include/usb/host/endpoint.h	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -54,5 +54,4 @@
 	fibril_condvar_t avail;
 	volatile bool active;
-	link_t same_device_eps;
 } endpoint_t;
 
@@ -71,8 +70,5 @@
 void endpoint_toggle_set(endpoint_t *instance, int toggle);
 
-void endpoint_toggle_reset(link_t *ep);
-
-void endpoint_toggle_reset_filtered(link_t *ep, usb_endpoint_t epn);
-
+void endpoint_toggle_reset_filtered(endpoint_t *instance, usb_target_t target);
 #endif
 /**
Index: uspace/lib/usb/include/usb/host/usb_endpoint_manager.h
===================================================================
--- uspace/lib/usb/include/usb/host/usb_endpoint_manager.h	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/lib/usb/include/usb/host/usb_endpoint_manager.h	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -78,4 +78,6 @@
     size_t *bw);
 
+void usb_endpoint_manager_reset_if_need(
+    usb_endpoint_manager_t *instance, usb_target_t target, const uint8_t *data);
 #endif
 /**
Index: uspace/lib/usb/include/usb/hub.h
===================================================================
--- uspace/lib/usb/include/usb/hub.h	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/lib/usb/include/usb/hub.h	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -59,7 +59,4 @@
 } usb_hc_attached_device_t;
 
-int usb_hc_reserve_default_address(usb_hc_connection_t *, usb_speed_t);
-int usb_hc_release_default_address(usb_hc_connection_t *);
-
 usb_address_t usb_hc_request_address(usb_hc_connection_t *, usb_speed_t);
 int usb_hc_register_device(usb_hc_connection_t *,
Index: uspace/lib/usb/include/usb/request.h
===================================================================
--- uspace/lib/usb/include/usb/request.h	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/lib/usb/include/usb/request.h	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -50,4 +50,10 @@
 /** 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. */
@@ -135,4 +141,6 @@
     char **);
 
+int usb_request_clear_endpoint_halt(usb_pipe_t *, uint16_t);
+
 #endif
 /**
Index: uspace/lib/usb/src/altiface.c
===================================================================
--- uspace/lib/usb/src/altiface.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
+++ uspace/lib/usb/src/altiface.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -0,0 +1,181 @@
+/*
+ * 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
+ * Handling alternate interface settings.
+ */
+#include <usb/devdrv.h>
+#include <usb/request.h>
+#include <usb/debug.h>
+#include <usb/dp.h>
+#include <errno.h>
+#include <str_error.h>
+#include <assert.h>
+
+/** Count number of alternate settings of a interface.
+ *
+ * @param config_descr Full configuration descriptor.
+ * @param config_descr_size Size of @p config_descr in bytes.
+ * @param interface_no Interface number.
+ * @return Number of alternate interfaces for @p interface_no interface.
+ */
+size_t usb_interface_count_alternates(uint8_t *config_descr,
+    size_t config_descr_size, uint8_t interface_no)
+{
+	assert(config_descr != NULL);
+	assert(config_descr_size > 0);
+
+	usb_dp_parser_t dp_parser = {
+		.nesting = usb_dp_standard_descriptor_nesting
+	};
+	usb_dp_parser_data_t dp_data = {
+		.data = config_descr,
+		.size = config_descr_size,
+		.arg = NULL
+	};
+
+	size_t alternate_count = 0;
+
+	uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,
+	    &dp_data, config_descr);
+	while (iface_ptr != NULL) {
+		usb_standard_interface_descriptor_t *iface
+		    = (usb_standard_interface_descriptor_t *) iface_ptr;
+		if (iface->descriptor_type == USB_DESCTYPE_INTERFACE) {
+			if (iface->interface_number == interface_no) {
+				alternate_count++;
+			}
+		}
+		iface_ptr = usb_dp_get_sibling_descriptor(&dp_parser, &dp_data,
+		    config_descr, iface_ptr);
+	}
+
+	return alternate_count;
+}
+
+/** Create alternate interface representation structure.
+ *
+ * @param[in] config_descr Configuration descriptor.
+ * @param[in] config_descr_size Size of configuration descriptor.
+ * @param[in] interface_number Interface number.
+ * @param[out] alternates_ptr Where to store pointer to allocated structure.
+ * @return Error code.
+ */
+int usb_alternate_interfaces_create(uint8_t *config_descr,
+    size_t config_descr_size, int interface_number,
+    usb_alternate_interfaces_t **alternates_ptr)
+{
+	assert(alternates_ptr != NULL);
+	assert(config_descr != NULL);
+	assert(config_descr_size > 0);
+
+	if (interface_number < 0) {
+		alternates_ptr = NULL;
+		return EOK;
+	}
+
+	usb_alternate_interfaces_t *alternates
+	    = malloc(sizeof(usb_alternate_interfaces_t));
+
+	if (alternates == NULL) {
+		return ENOMEM;
+	}
+
+	alternates->alternative_count
+	    = usb_interface_count_alternates(config_descr, config_descr_size,
+	    interface_number);
+
+	if (alternates->alternative_count == 0) {
+		free(alternates);
+		return ENOENT;
+	}
+
+	alternates->alternatives = malloc(alternates->alternative_count
+	    * sizeof(usb_alternate_interface_descriptors_t));
+	if (alternates->alternatives == NULL) {
+		free(alternates);
+		return ENOMEM;
+	}
+
+	alternates->current = 0;
+
+	usb_dp_parser_t dp_parser = {
+		.nesting = usb_dp_standard_descriptor_nesting
+	};
+	usb_dp_parser_data_t dp_data = {
+		.data = config_descr,
+		.size = config_descr_size,
+		.arg = NULL
+	};
+
+	usb_alternate_interface_descriptors_t *cur_alt_iface
+	    = &alternates->alternatives[0];
+
+	uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,
+	    &dp_data, dp_data.data);
+	while (iface_ptr != NULL) {
+		usb_standard_interface_descriptor_t *iface
+		    = (usb_standard_interface_descriptor_t *) iface_ptr;
+		if ((iface->descriptor_type != USB_DESCTYPE_INTERFACE)
+		    || (iface->interface_number != interface_number)) {
+			iface_ptr = usb_dp_get_sibling_descriptor(&dp_parser,
+			    &dp_data,
+			    dp_data.data, iface_ptr);
+			continue;
+		}
+
+		cur_alt_iface->interface = iface;
+		cur_alt_iface->nested_descriptors = iface_ptr + sizeof(*iface);
+
+		/* Find next interface to count size of nested descriptors. */
+		iface_ptr = usb_dp_get_sibling_descriptor(&dp_parser, &dp_data,
+		    dp_data.data, iface_ptr);
+		if (iface_ptr == NULL) {
+			uint8_t *next = dp_data.data + dp_data.size;
+			cur_alt_iface->nested_descriptors_size
+			    = next - cur_alt_iface->nested_descriptors;
+		} else {
+			cur_alt_iface->nested_descriptors_size
+			    = iface_ptr - cur_alt_iface->nested_descriptors;
+		}
+
+		cur_alt_iface++;
+	}
+
+	*alternates_ptr = alternates;
+
+	return EOK;
+}
+
+
+/**
+ * @}
+ */
Index: uspace/lib/usb/src/devdrv.c
===================================================================
--- uspace/lib/usb/src/devdrv.c	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/lib/usb/src/devdrv.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -100,4 +100,10 @@
     usb_device_t *dev, int alternate_setting)
 {
+	if (endpoints == NULL) {
+		dev->pipes = NULL;
+		dev->pipes_count = 0;
+		return EOK;
+	}
+
 	usb_endpoint_mapping_t *pipes;
 	size_t pipes_count;
@@ -109,7 +115,4 @@
 
 	if (rc != EOK) {
-		usb_log_error(
-		    "Failed to create endpoint pipes for `%s': %s.\n",
-		    dev->ddf_dev->name, str_error(rc));
 		return rc;
 	}
@@ -117,207 +120,4 @@
 	dev->pipes = pipes;
 	dev->pipes_count = pipes_count;
-
-	return EOK;
-}
-
-/** Initialize all endpoint pipes.
- *
- * @param drv The driver.
- * @param dev The device to be initialized.
- * @return Error code.
- */
-static int initialize_pipes(usb_device_t *dev)
-{
-	int rc;
-
-	rc = usb_device_connection_initialize_from_device(&dev->wire,
-	    dev->ddf_dev);
-	if (rc != EOK) {
-		usb_log_error(
-		    "Failed initializing connection on device `%s'. %s.\n",
-		    dev->ddf_dev->name, str_error(rc));
-		return rc;
-	}
-
-	rc = usb_pipe_initialize_default_control(&dev->ctrl_pipe,
-	    &dev->wire);
-	if (rc != EOK) {
-		usb_log_error("Failed to initialize default control pipe " \
-		    "on device `%s': %s.\n",
-		    dev->ddf_dev->name, str_error(rc));
-		return rc;
-	}
-
-	rc = usb_pipe_probe_default_control(&dev->ctrl_pipe);
-	if (rc != EOK) {
-		usb_log_error(
-		    "Probing default control pipe on device `%s' failed: %s.\n",
-		    dev->ddf_dev->name, str_error(rc));
-		return rc;
-	}
-
-	/* Get our interface. */
-	dev->interface_no = usb_device_get_assigned_interface(dev->ddf_dev);
-
-	/*
-	 * We will do some querying of the device, it is worth to prepare
-	 * the long transfer.
-	 */
-	rc = usb_pipe_start_long_transfer(&dev->ctrl_pipe);
-	if (rc != EOK) {
-		usb_log_error("Failed to start transfer: %s.\n",
-		    str_error(rc));
-		return rc;
-	}
-
-	/* Retrieve the descriptors. */
-	rc = usb_device_retrieve_descriptors(&dev->ctrl_pipe,
-	    &dev->descriptors);
-	if (rc != EOK) {
-		usb_log_error("Failed to retrieve standard device " \
-		    "descriptors of %s: %s.\n",
-		    dev->ddf_dev->name, str_error(rc));
-		return rc;
-	}
-
-
-	if (driver->endpoints != NULL) {
-		rc = initialize_other_pipes(driver->endpoints, dev, 0);
-	}
-
-	usb_pipe_end_long_transfer(&dev->ctrl_pipe);
-
-	/* Rollback actions. */
-	if (rc != EOK) {
-		if (dev->descriptors.configuration != NULL) {
-			free(dev->descriptors.configuration);
-		}
-	}
-
-	return rc;
-}
-
-/** Count number of alternate settings of a interface.
- *
- * @param config_descr Full configuration descriptor.
- * @param config_descr_size Size of @p config_descr in bytes.
- * @param interface_no Interface number.
- * @return Number of alternate interfaces for @p interface_no interface.
- */
-size_t usb_interface_count_alternates(uint8_t *config_descr,
-    size_t config_descr_size, uint8_t interface_no)
-{
-	assert(config_descr != NULL);
-	assert(config_descr_size > 0);
-
-	usb_dp_parser_t dp_parser = {
-		.nesting = usb_dp_standard_descriptor_nesting
-	};
-	usb_dp_parser_data_t dp_data = {
-		.data = config_descr,
-		.size = config_descr_size,
-		.arg = NULL
-	};
-
-	size_t alternate_count = 0;
-
-	uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,
-	    &dp_data, config_descr);
-	while (iface_ptr != NULL) {
-		usb_standard_interface_descriptor_t *iface
-		    = (usb_standard_interface_descriptor_t *) iface_ptr;
-		if (iface->descriptor_type == USB_DESCTYPE_INTERFACE) {
-			if (iface->interface_number == interface_no) {
-				alternate_count++;
-			}
-		}
-		iface_ptr = usb_dp_get_sibling_descriptor(&dp_parser, &dp_data,
-		    config_descr, iface_ptr);
-	}
-
-	return alternate_count;
-}
-
-/** Initialize structures related to alternate interfaces.
- *
- * @param dev Device where alternate settings shall be initialized.
- * @return Error code.
- */
-static int initialize_alternate_interfaces(usb_device_t *dev)
-{
-	if (dev->interface_no < 0) {
-		dev->alternate_interfaces = NULL;
-		return EOK;
-	}
-
-	usb_alternate_interfaces_t *alternates
-	    = malloc(sizeof(usb_alternate_interfaces_t));
-
-	if (alternates == NULL) {
-		return ENOMEM;
-	}
-
-	alternates->alternative_count
-	    = usb_interface_count_alternates(dev->descriptors.configuration,
-	    dev->descriptors.configuration_size, dev->interface_no);
-
-	if (alternates->alternative_count == 0) {
-		free(alternates);
-		return ENOENT;
-	}
-
-	alternates->alternatives = malloc(alternates->alternative_count
-	    * sizeof(usb_alternate_interface_descriptors_t));
-	if (alternates->alternatives == NULL) {
-		free(alternates);
-		return ENOMEM;
-	}
-
-	alternates->current = 0;
-
-	usb_dp_parser_t dp_parser = {
-		.nesting = usb_dp_standard_descriptor_nesting
-	};
-	usb_dp_parser_data_t dp_data = {
-		.data = dev->descriptors.configuration,
-		.size = dev->descriptors.configuration_size,
-		.arg = NULL
-	};
-
-	usb_alternate_interface_descriptors_t *cur_alt_iface
-	    = &alternates->alternatives[0];
-
-	uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,
-	    &dp_data, dp_data.data);
-	while (iface_ptr != NULL) {
-		usb_standard_interface_descriptor_t *iface
-		    = (usb_standard_interface_descriptor_t *) iface_ptr;
-		if ((iface->descriptor_type != USB_DESCTYPE_INTERFACE)
-		    || (iface->interface_number != dev->interface_no)) {
-			iface_ptr = usb_dp_get_sibling_descriptor(&dp_parser,
-			    &dp_data,
-			    dp_data.data, iface_ptr);
-			continue;
-		}
-
-		cur_alt_iface->interface = iface;
-		cur_alt_iface->nested_descriptors = iface_ptr + sizeof(*iface);
-
-		/* Find next interface to count size of nested descriptors. */
-		iface_ptr = usb_dp_get_sibling_descriptor(&dp_parser, &dp_data,
-		    dp_data.data, iface_ptr);
-		if (iface_ptr == NULL) {
-			uint8_t *next = dp_data.data + dp_data.size;
-			cur_alt_iface->nested_descriptors_size
-			    = next - cur_alt_iface->nested_descriptors;
-		} else {
-			cur_alt_iface->nested_descriptors_size
-			    = iface_ptr - cur_alt_iface->nested_descriptors;
-		}
-
-		cur_alt_iface++;
-	}
-
-	dev->alternate_interfaces = alternates;
 
 	return EOK;
@@ -339,27 +139,12 @@
 	int rc;
 
-	usb_device_t *dev = malloc(sizeof(usb_device_t));
-	if (dev == NULL) {
-		usb_log_error("Out of memory when adding device `%s'.\n",
-		    gen_dev->name);
-		return ENOMEM;
-	}
-
-
-	dev->ddf_dev = gen_dev;
-	dev->ddf_dev->driver_data = dev;
-	dev->driver_data = NULL;
-	dev->descriptors.configuration = NULL;
-
-	dev->pipes_count = 0;
-	dev->pipes = NULL;
-
-	rc = initialize_pipes(dev);
-	if (rc != EOK) {
-		free(dev);
-		return rc;
-	}
-
-	(void) initialize_alternate_interfaces(dev);
+	usb_device_t *dev = NULL;
+	const char *err_msg = NULL;
+	rc = usb_device_create(gen_dev, driver->endpoints, &dev, &err_msg);
+	if (rc != EOK) {
+		usb_log_error("USB device `%s' creation failed (%s): %s.\n",
+		    gen_dev->name, err_msg, str_error(rc));
+		return rc;
+	}
 
 	return driver->ops->add_device(dev);
@@ -395,4 +180,11 @@
  * with usb_pipe_initialize_from_configuration().
  *
+ * @warning This is a wrapper function that does several operations that
+ * can fail and that cannot be rollbacked easily. That means that a failure
+ * during the SET_INTERFACE request would result in having a device with
+ * no pipes at all (except the default control one). That is because the old
+ * pipes needs to be unregistered at HC first and the new ones could not
+ * be created.
+ *
  * @param dev USB device.
  * @param alternate_setting Alternate setting to choose.
@@ -409,6 +201,4 @@
 	int rc;
 
-	/* TODO: more transactional behavior. */
-
 	/* Destroy existing pipes. */
 	rc = destroy_current_pipes(dev);
@@ -432,5 +222,5 @@
 /** Retrieve basic descriptors from the device.
  *
- * @param[in] ctrl_pipe Control pipe with opened session.
+ * @param[in] ctrl_pipe Control endpoint pipe.
  * @param[out] descriptors Where to store the descriptors.
  * @return Error code.
@@ -440,14 +230,19 @@
 {
 	assert(descriptors != NULL);
-	assert(usb_pipe_is_session_started(ctrl_pipe));
 
 	descriptors->configuration = NULL;
 
 	int rc;
+
+	/* It is worth to start a long transfer. */
+	rc = usb_pipe_start_long_transfer(ctrl_pipe);
+	if (rc != EOK) {
+		return rc;
+	}
 
 	/* Get the device descriptor. */
 	rc = usb_request_get_device_descriptor(ctrl_pipe, &descriptors->device);
 	if (rc != EOK) {
-		return rc;
+		goto leave;
 	}
 
@@ -456,9 +251,9 @@
 	    ctrl_pipe, 0, (void **) &descriptors->configuration,
 	    &descriptors->configuration_size);
-	if (rc != EOK) {
-		return rc;
-	}
-
-	return EOK;
+
+leave:
+	usb_pipe_end_long_transfer(ctrl_pipe);
+
+	return rc;
 }
 
@@ -641,4 +436,104 @@
 }
 
+/** Initialize control pipe in a device.
+ *
+ * @param dev USB device in question.
+ * @param errmsg Where to store error context.
+ * @return
+ */
+static int init_wire_and_ctrl_pipe(usb_device_t *dev, const char **errmsg)
+{
+	int rc;
+
+	rc = usb_device_connection_initialize_from_device(&dev->wire,
+	    dev->ddf_dev);
+	if (rc != EOK) {
+		*errmsg = "device connection initialization";
+		return rc;
+	}
+
+	rc = usb_pipe_initialize_default_control(&dev->ctrl_pipe,
+	    &dev->wire);
+	if (rc != EOK) {
+		*errmsg = "default control pipe initialization";
+		return rc;
+	}
+
+	return EOK;
+}
+
+
+/** Create new instance of USB device.
+ *
+ * @param[in] ddf_dev Generic DDF device backing the USB one.
+ * @param[in] endpoints NULL terminated array of endpoints (NULL for none).
+ * @param[out] dev_ptr Where to store pointer to the new device.
+ * @param[out] errstr_ptr Where to store description of context
+ *	(in case error occurs).
+ * @return Error code.
+ */
+int usb_device_create(ddf_dev_t *ddf_dev,
+    usb_endpoint_description_t **endpoints,
+    usb_device_t **dev_ptr, const char **errstr_ptr)
+{
+	assert(dev_ptr != NULL);
+	assert(ddf_dev != NULL);
+
+	int rc;
+
+	usb_device_t *dev = malloc(sizeof(usb_device_t));
+	if (dev == NULL) {
+		*errstr_ptr = "structure allocation";
+		return ENOMEM;
+	}
+
+	// FIXME: proper deallocation in case of errors
+
+	dev->ddf_dev = ddf_dev;
+	dev->driver_data = NULL;
+	dev->descriptors.configuration = NULL;
+	dev->alternate_interfaces = NULL;
+
+	dev->pipes_count = 0;
+	dev->pipes = NULL;
+
+	/* Initialize backing wire and control pipe. */
+	rc = init_wire_and_ctrl_pipe(dev, errstr_ptr);
+	if (rc != EOK) {
+		return rc;
+	}
+
+	/* Get our interface. */
+	dev->interface_no = usb_device_get_assigned_interface(dev->ddf_dev);
+
+	/* Retrieve standard descriptors. */
+	rc = usb_device_retrieve_descriptors(&dev->ctrl_pipe,
+	    &dev->descriptors);
+	if (rc != EOK) {
+		*errstr_ptr = "descriptor retrieval";
+		return rc;
+	}
+
+	/* Create alternate interfaces. */
+	rc = usb_alternate_interfaces_create(dev->descriptors.configuration,
+	    dev->descriptors.configuration_size, dev->interface_no,
+	    &dev->alternate_interfaces);
+	if (rc != EOK) {
+		/* We will try to silently ignore this. */
+		dev->alternate_interfaces = NULL;
+	}
+
+	rc = initialize_other_pipes(endpoints, dev, 0);
+	if (rc != EOK) {
+		*errstr_ptr = "pipes initialization";
+		return rc;
+	}
+
+	*errstr_ptr = NULL;
+	*dev_ptr = dev;
+
+	return EOK;
+}
+
 /**
  * @}
Index: uspace/lib/usb/src/hidparser.c
===================================================================
--- uspace/lib/usb/src/hidparser.c	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/lib/usb/src/hidparser.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -900,4 +900,6 @@
 	item->usage_page = usage_page;
 	
+	usb_log_debug("Appending usage %d, usage page %d\n", usage, usage_page);
+	
 	list_append (&usage_path->link, &item->link);
 	usage_path->depth++;
Index: uspace/lib/usb/src/host/device_keeper.c
===================================================================
--- uspace/lib/usb/src/host/device_keeper.c	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/lib/usb/src/host/device_keeper.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -54,33 +54,10 @@
 	for (; i < USB_ADDRESS_COUNT; ++i) {
 		instance->devices[i].occupied = false;
-		instance->devices[i].control_used = 0;
 		instance->devices[i].handle = 0;
 		instance->devices[i].speed = USB_SPEED_MAX;
-		list_initialize(&instance->devices[i].endpoints);
 	}
 	// TODO: is this hack enough?
 	// (it is needed to allow smooth registration at default address)
 	instance->devices[0].occupied = true;
-}
-/*----------------------------------------------------------------------------*/
-void usb_device_keeper_add_ep(
-    usb_device_keeper_t *instance, usb_address_t address, endpoint_t *ep)
-{
-	assert(instance);
-	fibril_mutex_lock(&instance->guard);
-	assert(instance->devices[address].occupied);
-	list_append(&ep->same_device_eps, &instance->devices[address].endpoints);
-	fibril_mutex_unlock(&instance->guard);
-}
-/*----------------------------------------------------------------------------*/
-void usb_device_keeper_del_ep(
-    usb_device_keeper_t *instance, usb_address_t address, endpoint_t *ep)
-{
-	assert(instance);
-	fibril_mutex_lock(&instance->guard);
-	assert(instance->devices[address].occupied);
-	list_remove(&ep->same_device_eps);
-	list_initialize(&ep->same_device_eps);
-	fibril_mutex_unlock(&instance->guard);
 }
 /*----------------------------------------------------------------------------*/
@@ -117,60 +94,4 @@
 }
 /*----------------------------------------------------------------------------*/
-/** Check setup packet data for signs of toggle reset.
- *
- * @param[in] instance Device keeper structure to use.
- * @param[in] target Device to receive setup packet.
- * @param[in] data Setup packet data.
- *
- * Really ugly one.
- */
-void usb_device_keeper_reset_if_need(
-    usb_device_keeper_t *instance, usb_target_t target, const uint8_t *data)
-{
-	assert(instance);
-	fibril_mutex_lock(&instance->guard);
-	if (target.endpoint > 15 || target.endpoint < 0
-	    || target.address >= USB_ADDRESS_COUNT || target.address < 0
-	    || !instance->devices[target.address].occupied) {
-		fibril_mutex_unlock(&instance->guard);
-		usb_log_error("Invalid data when checking for toggle reset.\n");
-		return;
-	}
-
-	switch (data[1])
-	{
-	case 0x01: /*clear feature*/
-		/* recipient is endpoint, value is zero (ENDPOINT_STALL) */
-		if (((data[0] & 0xf) == 1) && ((data[2] | data[3]) == 0)) {
-			link_t *current =
-			    instance->devices[target.address].endpoints.next;
-			while (current !=
-			   &instance->devices[target.address].endpoints)
-			{
-			/* endpoint number is < 16, thus first byte is enough */
-				endpoint_toggle_reset_filtered(
-				    current, data[4]);
-				current = current->next;
-			}
-		}
-	break;
-
-	case 0x9: /* set configuration */
-	case 0x11: /* set interface */
-		/* target must be device */
-		if ((data[0] & 0xf) == 0) {
-			link_t *current =
-			    instance->devices[target.address].endpoints.next;
-			while (current !=
-			   &instance->devices[target.address].endpoints)
-			{
-				endpoint_toggle_reset(current);
-				current = current->next;
-			}
-		}
-	break;
-	}
-	fibril_mutex_unlock(&instance->guard);
-}
 /*----------------------------------------------------------------------------*/
 /** Get a free USB address
Index: uspace/lib/usb/src/host/endpoint.c
===================================================================
--- uspace/lib/usb/src/host/endpoint.c	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/lib/usb/src/host/endpoint.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -53,5 +53,4 @@
 	fibril_mutex_initialize(&instance->guard);
 	fibril_condvar_initialize(&instance->avail);
-	link_initialize(&instance->same_device_eps);
 	return EOK;
 }
@@ -61,5 +60,4 @@
 	assert(instance);
 	assert(!instance->active);
-	list_remove(&instance->same_device_eps);
 	free(instance);
 }
@@ -97,18 +95,9 @@
 }
 /*----------------------------------------------------------------------------*/
-void endpoint_toggle_reset(link_t *ep)
+void endpoint_toggle_reset_filtered(endpoint_t *instance, usb_target_t target)
 {
-	endpoint_t *instance =
-	    list_get_instance(ep, endpoint_t, same_device_eps);
 	assert(instance);
-	instance->toggle = 0;
-}
-/*----------------------------------------------------------------------------*/
-void endpoint_toggle_reset_filtered(link_t *ep, usb_endpoint_t epn)
-{
-	endpoint_t *instance =
-	    list_get_instance(ep, endpoint_t, same_device_eps);
-	assert(instance);
-	if (instance->endpoint == epn)
+	if (instance->address == target.address &&
+	    (instance->endpoint == target.endpoint || target.endpoint == 0))
 		instance->toggle = 0;
 }
Index: uspace/lib/usb/src/host/usb_endpoint_manager.c
===================================================================
--- uspace/lib/usb/src/host/usb_endpoint_manager.c	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/lib/usb/src/host/usb_endpoint_manager.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -31,4 +31,5 @@
 #include <errno.h>
 
+#include <usb/debug.h>
 #include <usb/host/usb_endpoint_manager.h>
 
@@ -80,4 +81,12 @@
 	endpoint_destroy(node->ep);
 	free(node);
+}
+/*----------------------------------------------------------------------------*/
+static void node_toggle_reset_filtered(link_t *item, void *arg)
+{
+	assert(item);
+	node_t *node = hash_table_get_instance(item, node_t, link);
+	usb_target_t *target = arg;
+	endpoint_toggle_reset_filtered(node->ep, *target);
 }
 /*----------------------------------------------------------------------------*/
@@ -230,2 +239,50 @@
 	return node->ep;
 }
+/*----------------------------------------------------------------------------*/
+/** Check setup packet data for signs of toggle reset.
+ *
+ * @param[in] instance Device keeper structure to use.
+ * @param[in] target Device to receive setup packet.
+ * @param[in] data Setup packet data.
+ *
+ * Really ugly one.
+ */
+void usb_endpoint_manager_reset_if_need(
+    usb_endpoint_manager_t *instance, usb_target_t target, const uint8_t *data)
+{
+	assert(instance);
+	if (target.endpoint > 15 || target.endpoint < 0
+	    || target.address >= USB11_ADDRESS_MAX || target.address < 0) {
+		usb_log_error("Invalid data when checking for toggle reset.\n");
+		return;
+	}
+
+	switch (data[1])
+	{
+	case 0x01: /*clear feature*/
+		/* recipient is endpoint, value is zero (ENDPOINT_STALL) */
+		if (((data[0] & 0xf) == 1) && ((data[2] | data[3]) == 0)) {
+			/* endpoint number is < 16, thus first byte is enough */
+			usb_target_t reset_target =
+			    { .address = target.address, data[4] };
+			fibril_mutex_lock(&instance->guard);
+			hash_table_apply(&instance->ep_table,
+			    node_toggle_reset_filtered, &reset_target);
+			fibril_mutex_unlock(&instance->guard);
+		}
+	break;
+
+	case 0x9: /* set configuration */
+	case 0x11: /* set interface */
+		/* target must be device */
+		if ((data[0] & 0xf) == 0) {
+			usb_target_t reset_target =
+			    { .address = target.address, 0 };
+			fibril_mutex_lock(&instance->guard);
+			hash_table_apply(&instance->ep_table,
+			    node_toggle_reset_filtered, &reset_target);
+			fibril_mutex_unlock(&instance->guard);
+		}
+	break;
+	}
+}
Index: uspace/lib/usb/src/hub.c
===================================================================
--- uspace/lib/usb/src/hub.c	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/lib/usb/src/hub.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -42,4 +42,9 @@
 #include <usb/debug.h>
 
+/** How much time to wait between attempts to register endpoint 0:0.
+ * The value is based on typical value for port reset + some overhead.
+ */
+#define ENDPOINT_0_0_REGISTER_ATTEMPT_DELAY_USEC (1000 * (10 + 2))
+
 /** Check that HC connection is alright.
  *
@@ -53,41 +58,4 @@
 		} \
 	} while (false)
-
-
-/** Tell host controller to reserve default address.
- * @deprecated
- *
- * @param connection Opened connection to host controller.
- * @param speed Speed of the device that will respond on the default address.
- * @return Error code.
- */
-int usb_hc_reserve_default_address(usb_hc_connection_t *connection,
-    usb_speed_t speed)
-{
-	CHECK_CONNECTION(connection);
-
-	usb_log_warning("usb_hc_reserve_default_address() considered obsolete");
-
-	return async_req_2_0(connection->hc_phone,
-	    DEV_IFACE_ID(USBHC_DEV_IFACE),
-	    IPC_M_USBHC_RESERVE_DEFAULT_ADDRESS, speed);
-}
-
-/** Tell host controller to release default address.
- * @deprecated
- *
- * @param connection Opened connection to host controller.
- * @return Error code.
- */
-int usb_hc_release_default_address(usb_hc_connection_t *connection)
-{
-	CHECK_CONNECTION(connection);
-
-	usb_log_warning("usb_hc_release_default_address() considered obsolete");
-
-	return async_req_1_0(connection->hc_phone,
-	    DEV_IFACE_ID(USBHC_DEV_IFACE),
-	    IPC_M_USBHC_RELEASE_DEFAULT_ADDRESS);
-}
 
 /** Ask host controller for free address assignment.
@@ -269,5 +237,5 @@
 		if (rc != EOK) {
 			/* Do not overheat the CPU ;-). */
-			async_usleep(10);
+			async_usleep(ENDPOINT_0_0_REGISTER_ATTEMPT_DELAY_USEC);
 		}
 	} while (rc != EOK);
Index: uspace/lib/usb/src/request.c
===================================================================
--- uspace/lib/usb/src/request.c	(revision 58226b4b32e8d2aa70f23afb4fb8957c2ec93034)
+++ uspace/lib/usb/src/request.c	(revision 3f3afb9051ee57b968a9710732ba453ea747e6f3)
@@ -871,4 +871,18 @@
 }
 
+/** Clear halt bit of an endpoint pipe (after pipe stall).
+ *
+ * @param pipe Control pipe.
+ * @param ep_index Endpoint index (in native endianness).
+ * @return Error code.
+ */
+int usb_request_clear_endpoint_halt(usb_pipe_t *pipe, uint16_t ep_index)
+{
+	return usb_request_clear_feature(pipe,
+	    USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_ENDPOINT,
+	    uint16_host2usb(USB_FEATURE_SELECTOR_ENDPOINT_HALT),
+	    uint16_host2usb(ep_index));
+}
+
 /**
  * @}
