Index: uspace/drv/usbhid/Makefile
===================================================================
--- uspace/drv/usbhid/Makefile	(revision c6fe4699d267b97fcb861bf87324fb21c4072051)
+++ uspace/drv/usbhid/Makefile	(revision 26d46d24d73a756523746db7987f7683c3dceffd)
@@ -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 c6fe4699d267b97fcb861bf87324fb21c4072051)
+++ uspace/drv/usbhid/generic/hiddev.c	(revision 26d46d24d73a756523746db7987f7683c3dceffd)
@@ -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 c6fe4699d267b97fcb861bf87324fb21c4072051)
+++ uspace/drv/usbhid/generic/hiddev.h	(revision 26d46d24d73a756523746db7987f7683c3dceffd)
@@ -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 c6fe4699d267b97fcb861bf87324fb21c4072051)
+++ uspace/drv/usbhid/kbd/conv.h	(revision 26d46d24d73a756523746db7987f7683c3dceffd)
@@ -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 c6fe4699d267b97fcb861bf87324fb21c4072051)
+++ uspace/drv/usbhid/kbd/kbddev.c	(revision 26d46d24d73a756523746db7987f7683c3dceffd)
@@ -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 c6fe4699d267b97fcb861bf87324fb21c4072051)
+++ uspace/drv/usbhid/kbd/kbddev.h	(revision 26d46d24d73a756523746db7987f7683c3dceffd)
@@ -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 c6fe4699d267b97fcb861bf87324fb21c4072051)
+++ uspace/drv/usbhid/kbd/kbdrepeat.h	(revision 26d46d24d73a756523746db7987f7683c3dceffd)
@@ -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 c6fe4699d267b97fcb861bf87324fb21c4072051)
+++ uspace/drv/usbhid/layout.h	(revision 26d46d24d73a756523746db7987f7683c3dceffd)
@@ -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 c6fe4699d267b97fcb861bf87324fb21c4072051)
+++ uspace/drv/usbhid/main.c	(revision 26d46d24d73a756523746db7987f7683c3dceffd)
@@ -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 26d46d24d73a756523746db7987f7683c3dceffd)
+++ uspace/drv/usbhid/mouse/mousedev.c	(revision 26d46d24d73a756523746db7987f7683c3dceffd)
@@ -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 26d46d24d73a756523746db7987f7683c3dceffd)
+++ uspace/drv/usbhid/mouse/mousedev.h	(revision 26d46d24d73a756523746db7987f7683c3dceffd)
@@ -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 26d46d24d73a756523746db7987f7683c3dceffd)
+++ uspace/drv/usbhid/subdrivers.c	(revision 26d46d24d73a756523746db7987f7683c3dceffd)
@@ -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 26d46d24d73a756523746db7987f7683c3dceffd)
+++ uspace/drv/usbhid/subdrivers.h	(revision 26d46d24d73a756523746db7987f7683c3dceffd)
@@ -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 c6fe4699d267b97fcb861bf87324fb21c4072051)
+++ uspace/drv/usbhid/usbhid.c	(revision 26d46d24d73a756523746db7987f7683c3dceffd)
@@ -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 c6fe4699d267b97fcb861bf87324fb21c4072051)
+++ uspace/drv/usbhid/usbhid.h	(revision 26d46d24d73a756523746db7987f7683c3dceffd)
@@ -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 c6fe4699d267b97fcb861bf87324fb21c4072051)
+++ uspace/drv/usbhid/usbhid.ma	(revision 26d46d24d73a756523746db7987f7683c3dceffd)
@@ -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
