Index: .bzrignore
===================================================================
--- .bzrignore	(revision 54b5625688dd8f9522ddb56ea51a0dc1b9759df6)
+++ .bzrignore	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
@@ -86,5 +86,5 @@
 ./uspace/drv/uhci/uhci
 ./uspace/drv/usbhub/usbhub
-./uspace/drv/usbkbd/usbkbd
+./uspace/drv/usbhid/usbhid
 ./uspace/drv/vhc/vhc
 ./uspace/srv/bd/ata_bd/ata_bd
Index: boot/arch/amd64/Makefile.inc
===================================================================
--- boot/arch/amd64/Makefile.inc	(revision 54b5625688dd8f9522ddb56ea51a0dc1b9759df6)
+++ boot/arch/amd64/Makefile.inc	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
@@ -45,5 +45,5 @@
 	uhci \
 	usbhub \
-	usbkbd \
+	usbhid \
 	vhc
 
Index: uspace/Makefile
===================================================================
--- uspace/Makefile	(revision 54b5625688dd8f9522ddb56ea51a0dc1b9759df6)
+++ uspace/Makefile	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
@@ -118,6 +118,6 @@
 		srv/hw/irc/i8259 \
 		drv/uhci \
+		drv/usbhid \
 		drv/usbhub \
-		drv/usbkbd \
 		drv/vhc
 endif
@@ -132,6 +132,6 @@
 		srv/hw/irc/i8259 \
 		drv/uhci \
+		drv/usbhid \
 		drv/usbhub \
-		drv/usbkbd \
 		drv/vhc
 endif
Index: uspace/app/usbinfo/dump.c
===================================================================
--- uspace/app/usbinfo/dump.c	(revision 54b5625688dd8f9522ddb56ea51a0dc1b9759df6)
+++ uspace/app/usbinfo/dump.c	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
@@ -27,10 +27,10 @@
  */
 
-/** @addtogroup usb
+/** @addtogroup usbinfo
  * @{
  */
 /**
  * @file
- * @brief USB querying.
+ * USB querying.
  */
 
Index: uspace/app/usbinfo/info.c
===================================================================
--- uspace/app/usbinfo/info.c	(revision 54b5625688dd8f9522ddb56ea51a0dc1b9759df6)
+++ uspace/app/usbinfo/info.c	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
@@ -27,10 +27,10 @@
  */
 
-/** @addtogroup usb
+/** @addtogroup usbinfo
  * @{
  */
 /**
  * @file
- * @brief
+ * Dumping of generic device properties.
  */
 #include <stdio.h>
Index: uspace/app/usbinfo/main.c
===================================================================
--- uspace/app/usbinfo/main.c	(revision 54b5625688dd8f9522ddb56ea51a0dc1b9759df6)
+++ uspace/app/usbinfo/main.c	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
@@ -27,10 +27,10 @@
  */
 
-/** @addtogroup usb
+/** @addtogroup usbinfo
  * @{
  */
 /**
  * @file
- * @brief USB querying.
+ * USB querying.
  */
 
Index: uspace/app/usbinfo/usbinfo.h
===================================================================
--- uspace/app/usbinfo/usbinfo.h	(revision 54b5625688dd8f9522ddb56ea51a0dc1b9759df6)
+++ uspace/app/usbinfo/usbinfo.h	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
@@ -27,9 +27,9 @@
  */
 
-/** @addtogroup usb
+/** @addtogroup usbinfo
  * @{
  */
 /** @file
- * @brief Common header for usbinfo application.
+ * Common header for usbinfo application.
  */
 #ifndef USBINFO_USBINFO_H_
Index: uspace/doc/doxygroups.h
===================================================================
--- uspace/doc/doxygroups.h	(revision 54b5625688dd8f9522ddb56ea51a0dc1b9759df6)
+++ uspace/doc/doxygroups.h	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
@@ -210,20 +210,29 @@
 		 */
 
-	 /**
-	  * @defgroup drvusbhub USB hub driver
-	  * @ingroup usb
-	  * @brief USB hub driver.
-	  */
-
-	 /**
-	  * @defgroup drvusbhid USB HID driver
-	  * @ingroup usb
-	  * @brief USB driver for HID devices.
-	  */
-
-	 /**
-	  * @defgroup drvusbuhci UHCI driver
-	  * @ingroup usb
-	  * @brief Driver for USB host controller UHCI.
-	  */
-
+	/**
+	 * @defgroup usbinfo USB info application
+	 * @ingroup usb
+	 * @brief Application for querying USB devices.
+	 * @details
+	 * The intended usage of this application is to query new USB devices
+	 * for their descriptors etc. to simplify driver writing.
+	 */
+
+	/**
+	 * @defgroup drvusbhub USB hub driver
+	 * @ingroup usb
+	 * @brief USB hub driver.
+	 */
+
+	/**
+	 * @defgroup drvusbhid USB HID driver
+	 * @ingroup usb
+	 * @brief USB driver for HID devices.
+	 */
+
+	/**
+	 * @defgroup drvusbuhci UHCI driver
+	 * @ingroup usb
+	 * @brief Driver for USB host controller UHCI.
+	 */
+
Index: uspace/drv/uhci/Makefile
===================================================================
--- uspace/drv/uhci/Makefile	(revision 54b5625688dd8f9522ddb56ea51a0dc1b9759df6)
+++ uspace/drv/uhci/Makefile	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
@@ -34,4 +34,5 @@
 SOURCES = \
 	main.c \
+	pci.c \
 	transfers.c
 
Index: uspace/drv/uhci/main.c
===================================================================
--- uspace/drv/uhci/main.c	(revision 54b5625688dd8f9522ddb56ea51a0dc1b9759df6)
+++ uspace/drv/uhci/main.c	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
@@ -30,4 +30,5 @@
 #include <usb/debug.h>
 #include <errno.h>
+#include <str_error.h>
 #include <driver.h>
 #include "uhci.h"
@@ -55,4 +56,21 @@
 	usb_dprintf(NAME, 1, "uhci_add_device() called\n");
 	device->ops = &uhci_ops;
+
+	uintptr_t io_reg_base;
+	size_t io_reg_size;
+	int irq;
+
+	int rc = pci_get_my_registers(device,
+	    &io_reg_base, &io_reg_size, &irq);
+
+	if (rc != EOK) {
+		fprintf(stderr,
+		    NAME ": failed to get I/O registers addresses: %s.\n",
+		    str_error(rc));
+		return rc;
+	}
+
+	usb_dprintf(NAME, 2, "I/O regs at 0x%X (size %zu), IRQ %d.\n",
+	    io_reg_base, io_reg_size, irq);
 
 	/*
Index: uspace/drv/uhci/pci.c
===================================================================
--- uspace/drv/uhci/pci.c	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
+++ uspace/drv/uhci/pci.c	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
@@ -0,0 +1,126 @@
+/*
+ * 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 drvusbuhci
+ * @{
+ */
+/**
+ * @file
+ * PCI related functions needed by the UHCI driver.
+ */
+#include "uhci.h"
+#include <errno.h>
+#include <assert.h>
+#include <devman.h>
+#include <device/hw_res.h>
+
+/** Get address of registers and IRQ for given device.
+ *
+ * @param[in] dev Device asking for the addresses.
+ * @param[out] io_reg_address Base address of the I/O range.
+ * @param[out] io_reg_size Size of the I/O range.
+ * @param[out] irq_no IRQ assigned to the device.
+ * @return Error code.
+ */
+int pci_get_my_registers(device_t *dev,
+    uintptr_t *io_reg_address, size_t *io_reg_size,
+    int *irq_no)
+{
+	assert(dev != NULL);
+
+	int parent_phone = devman_parent_device_connect(dev->handle,
+	    IPC_FLAG_BLOCKING);
+	if (parent_phone < 0) {
+		return parent_phone;
+	}
+
+	int rc;
+
+	hw_resource_list_t hw_resources;
+	rc = hw_res_get_resource_list(parent_phone, &hw_resources);
+	if (rc != EOK) {
+		goto leave;
+	}
+
+	uintptr_t io_address = 0;
+	size_t io_size = 0;
+	bool io_found = false;
+
+	int irq = 0;
+	bool irq_found = false;
+
+	size_t i;
+	for (i = 0; i < hw_resources.count; i++) {
+		hw_resource_t *res = &hw_resources.resources[i];
+		switch (res->type) {
+			case INTERRUPT:
+				irq = res->res.interrupt.irq;
+				irq_found = true;
+				break;
+			case IO_RANGE:
+				io_address = (uintptr_t)
+				    res->res.io_range.address;
+				io_size = res->res.io_range.size;
+				io_found = true;
+				break;
+			default:
+				break;
+		}
+	}
+
+	if (!io_found) {
+		rc = ENOENT;
+		goto leave;
+	}
+
+	if (!irq_found) {
+		rc = ENOENT;
+		goto leave;
+	}
+
+	if (io_reg_address != NULL) {
+		*io_reg_address = io_address;
+	}
+	if (io_reg_size != NULL) {
+		*io_reg_size = io_size;
+	}
+	if (irq_no != NULL) {
+		*irq_no = irq;
+	}
+
+	rc = EOK;
+leave:
+	ipc_hangup(parent_phone);
+
+	return rc;
+}
+
+/**
+ * @}
+ */
+
Index: uspace/drv/uhci/uhci.h
===================================================================
--- uspace/drv/uhci/uhci.h	(revision 54b5625688dd8f9522ddb56ea51a0dc1b9759df6)
+++ uspace/drv/uhci/uhci.h	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
@@ -27,5 +27,5 @@
  */
 
-/** @addtogroup usb
+/** @addtogroup drvusbuhci
  * @{
  */
@@ -42,4 +42,6 @@
 usbhc_iface_t uhci_iface;
 
+int pci_get_my_registers(device_t *, uintptr_t *, size_t *, int *);
+
 #endif
 /**
Index: uspace/drv/usbhid/Makefile
===================================================================
--- uspace/drv/usbhid/Makefile	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
+++ uspace/drv/usbhid/Makefile	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
@@ -0,0 +1,53 @@
+#
+# Copyright (c) 2010-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.
+#
+
+USPACE_PREFIX = ../..
+LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBUSB_PREFIX)/libusb.a
+EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBUSB_PREFIX)/include -I.
+BINARY = usbhid
+
+STOLEN_LAYOUT_SOURCES = \
+	layout/us_qwerty.c \
+	layout/us_dvorak.c \
+	layout/cz.c
+
+SOURCES = \
+	main.c \
+	descparser.c \
+	descdump.c \
+	conv.c \
+	$(STOLEN_LAYOUT_SOURCES)
+
+EXTRA_CLEAN = $(STOLEN_LAYOUT_SOURCES)
+
+SRV_KBD = $(USPACE_PREFIX)/srv/hid/kbd
+
+include $(USPACE_PREFIX)/Makefile.common
+
+layout/%.c: $(SRV_KBD)/layout/%.c
+	ln -sfn ../$< $@
Index: uspace/drv/usbhid/conv.c
===================================================================
--- uspace/drv/usbhid/conv.c	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
+++ uspace/drv/usbhid/conv.c	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
@@ -0,0 +1,198 @@
+/*
+ * 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 scancode parser.
+ */
+
+#include <io/keycode.h>
+#include <stdint.h>
+#include "conv.h"
+
+static int scanmap_simple[255] = {
+
+//	[0x29] = KC_BACKTICK,
+
+//	[0x02] = KC_1,
+//	[0x03] = KC_2,
+	[0x04] = KC_A,
+	[0x05] = KC_B,
+	[0x06] = KC_C,
+	[0x07] = KC_D,
+	[0x08] = KC_E,
+	[0x09] = KC_F,
+	[0x0a] = KC_G,
+	[0x0b] = KC_H,
+	[0x0c] = KC_I,
+	[0x0d] = KC_J,
+	[0x0e] = KC_K,
+	[0x0f] = KC_L,
+	[0x10] = KC_M,
+	[0x11] = KC_N,
+	[0x12] = KC_O,
+	[0x13] = KC_P,
+	[0x14] = KC_Q,
+	[0x15] = KC_R,
+	[0x16] = KC_S,
+	[0x17] = KC_T,
+	[0x18] = KC_U,
+	[0x19] = KC_V,
+	[0x1a] = KC_W,
+	[0x1b] = KC_X,
+	[0x1c] = KC_Y,
+	[0x1d] = KC_Z,
+
+	[0x1e] = KC_1,
+	[0x1f] = KC_2,
+	[0x20] = KC_3,
+	[0x21] = KC_4,
+	[0x22] = KC_5,
+	[0x23] = KC_6,
+	[0x24] = KC_7,
+	[0x25] = KC_8,
+	[0x26] = KC_9,
+	[0x27] = KC_0,
+	
+	[0x28] = KC_ENTER,
+	[0x29] = KC_ESCAPE,
+	[0x2a] = KC_BACKSPACE,
+	[0x2b] = KC_TAB,
+	[0x2c] = KC_SPACE,
+
+	[0x2d] = KC_MINUS,  // same as DASH? (- or _)
+	[0x2e] = KC_EQUALS,
+	[0x2f] = KC_LBRACKET,
+	[0x30] = KC_RBRACKET,
+	[0x31] = KC_BACKSLASH,
+	//[0x32] = KC_,	// TODO: HASH??? maybe some as 0x31 - backslash
+	[0x33] = KC_SEMICOLON,
+	[0x34] = KC_QUOTE,  // same as APOSTROPHE? (')
+	[0x35] = KC_BACKTICK,  // same as GRAVE ACCENT?? (`)
+	[0x36] = KC_COMMA,
+	[0x37] = KC_PERIOD,
+	[0x38] = KC_SLASH,
+
+	[0x39] = KC_CAPS_LOCK,
+	
+	[0x3a] = KC_F1,
+	[0x3b] = KC_F2,
+	[0x3c] = KC_F3,
+	[0x3d] = KC_F4,
+	[0x3e] = KC_F5,
+	[0x3f] = KC_F6,
+	[0x40] = KC_F7,
+	[0x41] = KC_F8,
+	[0x42] = KC_F9,
+	[0x43] = KC_F10,
+	[0x44] = KC_F11,
+	[0x45] = KC_F12,
+	
+	[0x46] = KC_PRTSCR,
+	[0x47] = KC_SCROLL_LOCK,
+	[0x48] = KC_PAUSE,
+	[0x49] = KC_INSERT,
+	[0x4a] = KC_HOME,
+	[0x4b] = KC_PAGE_UP,
+	[0x4c] = KC_DELETE,
+	[0x4d] = KC_END,
+	[0x4e] = KC_PAGE_DOWN,
+	[0x4f] = KC_RIGHT,
+	[0x50] = KC_LEFT,
+	[0x51] = KC_DOWN,
+	[0x52] = KC_UP,
+	
+	//[0x64] = // some funny key
+	
+	[0xe0] = KC_LCTRL,
+	[0xe1] = KC_LSHIFT,
+	[0xe2] = KC_LALT,
+	//[0xe3] = KC_L	// TODO: left GUI
+	[0xe4] = KC_RCTRL,
+	[0xe5] = KC_RSHIFT,
+	[0xe6] = KC_RALT,
+	//[0xe7] = KC_R	// TODO: right GUI
+	
+};
+
+unsigned int usbkbd_parse_scancode(int scancode)
+{
+//	console_ev_type_t type;
+	unsigned int key;
+	int *map = scanmap_simple;
+	size_t map_length = sizeof(scanmap_simple) / sizeof(int);
+
+	/*
+	 * ACK/NAK are returned as response to us sending a command.
+	 * We are not interested in them.
+	 */
+//	if (scancode == SC_ACK || scancode == SC_NAK)
+//		return;
+
+//	if (scancode == 0xe0) {
+//		ds = ds_e;
+//		return;
+//	}
+
+//	switch (ds) {
+//	case ds_s:
+//		map = scanmap_simple;
+//		map_length = sizeof(scanmap_simple) / sizeof(int);
+//		break;
+//	case ds_e:
+//		map = scanmap_e0;
+//		map_length = sizeof(scanmap_e0) / sizeof(int);
+//		break;
+//	default:
+//		map = NULL;
+//		map_length = 0;
+//	}
+
+//	ds = ds_s;
+
+//	if (scancode & 0x80) {
+//		scancode &= ~0x80;
+//		type = KEY_RELEASE;
+//	} else {
+//		type = KEY_PRESS;
+//	}
+
+	if ((scancode < 0) || ((size_t) scancode >= map_length))
+		return -1;
+
+	key = map[scancode];
+//	if (key != 0)
+//		kbd_push_ev(type, key);
+	return key;
+}
+
+/**
+ * @}
+ */
Index: uspace/drv/usbhid/conv.h
===================================================================
--- uspace/drv/usbhid/conv.h	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
+++ uspace/drv/usbhid/conv.h	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
@@ -0,0 +1,45 @@
+/*
+ * 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 scancode parser.
+ */
+
+#ifndef USBHID_CONV_H_
+#define USBHID_CONV_H_
+
+unsigned int usbkbd_parse_scancode(int scancode);
+
+#endif
+
+/**
+ * @}
+ */
Index: uspace/drv/usbhid/descdump.c
===================================================================
--- uspace/drv/usbhid/descdump.c	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
+++ uspace/drv/usbhid/descdump.c	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
@@ -0,0 +1,157 @@
+/*
+ * Copyright (c) 2010 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
+ * Descriptor dumping.
+ */
+
+#include <usb/classes/hid.h>
+
+#include "descdump.h"
+
+/*----------------------------------------------------------------------------*/
+
+#define BYTES_PER_LINE 12
+
+static void dump_buffer(const char *msg, const uint8_t *buffer, size_t length)
+{
+	printf("%s\n", msg);
+
+	size_t i;
+	for (i = 0; i < length; i++) {
+		printf("  0x%02X", buffer[i]);
+		if (((i > 0) && (((i+1) % BYTES_PER_LINE) == 0))
+		    || (i + 1 == length)) {
+			printf("\n");
+		}
+	}
+}
+
+/*----------------------------------------------------------------------------*/
+
+#define INDENT "  "
+
+void dump_standard_configuration_descriptor(
+    int index, const usb_standard_configuration_descriptor_t *d)
+{
+	bool self_powered = d->attributes & 64;
+	bool remote_wakeup = d->attributes & 32;
+	
+	printf("Standard configuration descriptor #%d\n", index);
+	printf(INDENT "bLength = %d\n", d->length);
+	printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type);
+	printf(INDENT "wTotalLength = %d\n", d->total_length);
+	printf(INDENT "bNumInterfaces = %d\n", d->interface_count);
+	printf(INDENT "bConfigurationValue = %d\n", d->configuration_number);
+	printf(INDENT "iConfiguration = %d\n", d->str_configuration);
+	printf(INDENT "bmAttributes = %d [%s%s%s]\n", d->attributes,
+	    self_powered ? "self-powered" : "",
+	    (self_powered & remote_wakeup) ? ", " : "",
+	    remote_wakeup ? "remote-wakeup" : "");
+	printf(INDENT "MaxPower = %d (%dmA)\n", d->max_power,
+	    2 * d->max_power);
+	// printf(INDENT " = %d\n", d->);
+}
+
+void dump_standard_interface_descriptor(
+    const usb_standard_interface_descriptor_t *d)
+{
+	printf("Standard interface descriptor\n");
+	printf(INDENT "bLength = %d\n", d->length);
+	printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type);
+	printf(INDENT "bInterfaceNumber = %d\n", d->interface_number);
+	printf(INDENT "bAlternateSetting = %d\n", d->alternate_setting);
+	printf(INDENT "bNumEndpoints = %d\n", d->endpoint_count);
+	printf(INDENT "bInterfaceClass = %d\n", d->interface_class);
+	printf(INDENT "bInterfaceSubClass = %d\n", d->interface_subclass);
+	printf(INDENT "bInterfaceProtocol = %d\n", d->interface_protocol);
+	printf(INDENT "iInterface = %d\n", d->str_interface);
+}
+
+void dump_standard_endpoint_descriptor(
+    const usb_standard_endpoint_descriptor_t *d)
+{
+	const char *transfer_type;
+	switch (d->attributes & 3) {
+	case USB_TRANSFER_CONTROL:
+		transfer_type = "control";
+		break;
+	case USB_TRANSFER_ISOCHRONOUS:
+		transfer_type = "isochronous";
+		break;
+	case USB_TRANSFER_BULK:
+		transfer_type = "bulk";
+		break;
+	case USB_TRANSFER_INTERRUPT:
+		transfer_type = "interrupt";
+		break;
+	}
+
+	printf("Standard endpoint descriptor\n");
+	printf(INDENT "bLength = %d\n", d->length);
+	printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type);
+	printf(INDENT "bmAttributes = %d [%s]\n", d->attributes, transfer_type);
+	printf(INDENT "wMaxPacketSize = %d\n", d->max_packet_size);
+	printf(INDENT "bInterval = %d\n", d->poll_interval);
+}
+
+void dump_standard_hid_descriptor_header(
+    const usb_standard_hid_descriptor_t *d)
+{
+	printf("Standard HID descriptor\n");
+	printf(INDENT "bLength = %d\n", d->length);
+	printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type);
+	printf(INDENT "bcdHID = %d\n", d->spec_release);
+	printf(INDENT "bCountryCode = %d\n", d->country_code);
+	printf(INDENT "bNumDescriptors = %d\n", d->class_desc_count);
+	printf(INDENT "bDescriptorType = %d\n", d->report_desc_info.type);
+	printf(INDENT "wDescriptorLength = %d\n", d->report_desc_info.length);
+}
+
+void dump_standard_hid_class_descriptor_info(
+    const usb_standard_hid_class_descriptor_info_t *d)
+{
+	printf(INDENT "bDescriptorType = %d\n", d->type);
+	printf(INDENT "wDescriptorLength = %d\n", d->length);
+}
+
+void dump_hid_class_descriptor(int index, uint8_t type, 
+    const uint8_t *d, size_t size )
+{
+	printf("Class-specific descriptor #%d (type: %u)\n", index, type);
+	assert(d != NULL);
+	dump_buffer("", d, size);
+}
+
+/**
+ * @}
+ */
+
Index: uspace/drv/usbhid/descdump.h
===================================================================
--- uspace/drv/usbhid/descdump.h	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
+++ uspace/drv/usbhid/descdump.h	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2010 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
+ * Descriptor dumping.
+ */
+
+#ifndef USBHID_DESCDUMP_H_
+#define USBHID_DESCDUMP_H_
+
+#include "hid.h"
+
+void dump_standard_configuration_descriptor(
+    int index, const usb_standard_configuration_descriptor_t *d);
+
+void dump_standard_interface_descriptor(
+    const usb_standard_interface_descriptor_t *d);
+
+void dump_standard_endpoint_descriptor(
+    const usb_standard_endpoint_descriptor_t *d);
+
+void dump_standard_hid_descriptor_header(
+    const usb_standard_hid_descriptor_t *d);
+
+void dump_standard_hid_class_descriptor_info(
+    const usb_standard_hid_class_descriptor_info_t *d);
+
+void dump_hid_class_descriptor(int index, uint8_t type, 
+    const uint8_t *d, size_t size);
+
+#endif /* USBHID_DESCDUMP_H_ */
+
+/**
+ * @}
+ */
Index: uspace/drv/usbhid/descparser.c
===================================================================
--- uspace/drv/usbhid/descparser.c	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
+++ uspace/drv/usbhid/descparser.c	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
@@ -0,0 +1,351 @@
+/*
+ * Copyright (c) 2010 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
+ * Descriptor parser.
+ */
+
+#include <errno.h>
+#include <stdint.h>
+#include <usb/usb.h>
+#include <usb/classes/hid.h>
+#include <usb/descriptor.h>
+#include "descparser.h"
+#include "descdump.h"
+
+static void usbkbd_config_free(usb_hid_configuration_t *config)
+{
+	if (config == NULL) {
+		return;
+	}
+	
+	if (config->interfaces == NULL) {
+		return;
+	}
+	
+	int i;
+	for (i = 0; i < config->config_descriptor.interface_count; ++i) {
+		
+		usb_hid_iface_t *iface = &config->interfaces[i];
+		
+		if (iface->endpoints != NULL) {
+			free(config->interfaces[i].endpoints);
+		}
+		/*if (iface->class_desc_info != NULL) {
+			free(iface->class_desc_info);
+		}
+		if (iface->class_descs != NULL) {
+			int j;
+			for (j = 0; 
+			     j < iface->hid_desc.class_desc_count;
+			     ++j) {
+				if (iface->class_descs[j] != NULL) {
+					free(iface->class_descs[j]);
+				}
+			}
+		}*/
+	}
+	
+	free(config->interfaces);	
+}
+
+/*----------------------------------------------------------------------------*/
+
+
+
+/*----------------------------------------------------------------------------*/
+
+int usbkbd_parse_descriptors(const uint8_t *data, size_t size,
+                             usb_hid_configuration_t *config)
+{
+	if (config == NULL) {
+		return EINVAL;
+	}
+	
+	const uint8_t *pos = data;
+	
+	// get the configuration descriptor (should be first) || *config == NULL
+	if (*pos != sizeof(usb_standard_configuration_descriptor_t)
+	    || *(pos + 1) != USB_DESCTYPE_CONFIGURATION) {
+		fprintf(stderr, "Wrong format of configuration descriptor.\n");
+		return EINVAL;
+	}
+	
+	memcpy(&config->config_descriptor, pos, 
+	    sizeof(usb_standard_configuration_descriptor_t));
+	pos += sizeof(usb_standard_configuration_descriptor_t);
+
+	//printf("Parsed configuration descriptor: \n");
+	//dump_standard_configuration_descriptor(0, &config->config_descriptor);
+	
+	int ret = EOK;
+
+	// first descriptor after configuration should be interface
+	if (*(pos + 1) != USB_DESCTYPE_INTERFACE) {
+		fprintf(stderr, "Expected interface descriptor, but got %u.\n", 
+		    *(pos + 1));
+		return EINVAL;
+	}
+	
+	// prepare place for interface descriptors
+	config->interfaces = (usb_hid_iface_t *)calloc(
+	    config->config_descriptor.interface_count, sizeof(usb_hid_iface_t));
+	
+	int iface_i = 0;
+	// as long as these are < 0, there is no space allocated for
+	// the respective structures
+	int ep_i = -1;
+	//int hid_i = -1;
+	
+	usb_hid_iface_t *actual_iface = NULL;
+	//usb_standard_endpoint_descriptor_t *actual_ep = NULL;
+	
+	// parse other descriptors
+	while ((size_t)(pos - data) < size) {
+		uint8_t desc_size = *pos;
+		uint8_t desc_type = *(pos + 1);  // 2nd byte is descriptor size
+		
+		switch (desc_type) {
+		case USB_DESCTYPE_INTERFACE:
+			if (desc_size != 
+			    sizeof(usb_standard_interface_descriptor_t)) {
+				ret = EINVAL;
+				goto end;
+			}
+			
+			actual_iface = &config->interfaces[iface_i++];
+			
+			memcpy(&actual_iface->iface_desc, pos, desc_size);
+			pos += desc_size;
+
+			//printf("Parsed interface descriptor: \n");
+			//dump_standard_interface_descriptor(&actual_iface->iface_desc);
+			
+			// allocate space for endpoint descriptors
+			uint8_t eps = actual_iface->iface_desc.endpoint_count;
+			actual_iface->endpoints = 
+			    (usb_standard_endpoint_descriptor_t *)malloc(
+			     eps * sizeof(usb_standard_endpoint_descriptor_t));
+			if (actual_iface->endpoints == NULL) {
+				ret = ENOMEM;
+				goto end;
+			}
+			ep_i = 0;
+
+			//printf("Remaining size: %d\n", size - (size_t)(pos - data));
+			
+			break;
+		case USB_DESCTYPE_ENDPOINT:
+			if (desc_size != 
+			    sizeof(usb_standard_endpoint_descriptor_t)) {
+				ret = EINVAL;
+				goto end;
+			}
+			
+			if (ep_i < 0) {
+				fprintf(stderr, "Missing interface descriptor "
+				    "before endpoint descriptor.\n");
+				ret = EINVAL;
+				goto end;
+			}
+			if (ep_i > actual_iface->iface_desc.endpoint_count) {
+				fprintf(stderr, "More endpoint descriptors than"
+					" expected.\n");
+				ret = EINVAL;
+				goto end;
+			}
+			
+			// save the endpoint descriptor
+			memcpy(&actual_iface->endpoints[ep_i], pos, desc_size);
+			pos += desc_size;
+
+			//printf("Parsed endpoint descriptor: \n");
+			//dump_standard_endpoint_descriptor(&actual_iface->endpoints[ep_i]);
+			++ep_i;
+			
+			break;
+		case USB_DESCTYPE_HID:
+			if (desc_size < sizeof(usb_standard_hid_descriptor_t)) {
+				printf("Wrong size of descriptor: %d (should be %zu)\n",
+				    desc_size, sizeof(usb_standard_hid_descriptor_t));
+				ret = EINVAL;
+				goto end;
+			}
+			
+			// copy the header of the hid descriptor
+			memcpy(&actual_iface->hid_desc, pos, 
+			       sizeof(usb_standard_hid_descriptor_t));
+			pos += sizeof(usb_standard_hid_descriptor_t);
+			
+			/*if (actual_iface->hid_desc.class_desc_count
+			    * sizeof(usb_standard_hid_class_descriptor_info_t)
+			    != desc_size 
+			        - sizeof(usb_standard_hid_descriptor_t)) {
+				fprintf(stderr, "Wrong size of HID descriptor."
+					"\n");
+				ret = EINVAL;
+				goto end;
+			}*/
+
+			//printf("Parsed HID descriptor header: \n");
+			//dump_standard_hid_descriptor_header(&actual_iface->hid_desc);
+			
+			// allocate space for all class-specific descriptor info
+			/*actual_iface->class_desc_info = 
+			    (usb_standard_hid_class_descriptor_info_t *)malloc(
+			    actual_iface->hid_desc.class_desc_count
+			    * sizeof(usb_standard_hid_class_descriptor_info_t));
+			if (actual_iface->class_desc_info == NULL) {
+				ret = ENOMEM;
+				goto end;
+			}*/
+			
+			// allocate space for all class-specific descriptors
+			/*actual_iface->class_descs = (uint8_t **)calloc(
+			    actual_iface->hid_desc.class_desc_count,
+			    sizeof(uint8_t *));
+			if (actual_iface->class_descs == NULL) {
+				ret = ENOMEM;
+				goto end;
+			}*/
+
+			// copy all class-specific descriptor info
+			// TODO: endianness
+			/*
+			memcpy(actual_iface->class_desc_info, pos, 
+			    actual_iface->hid_desc.class_desc_count
+			    * sizeof(usb_standard_hid_class_descriptor_info_t));
+			pos += actual_iface->hid_desc.class_desc_count
+			    * sizeof(usb_standard_hid_class_descriptor_info_t);
+
+			printf("Parsed HID descriptor info:\n");
+			dump_standard_hid_class_descriptor_info(
+			    actual_iface->class_desc_info);
+			*/
+			
+			/*size_t tmp = (size_t)(pos - data);
+			printf("Parser position: %d, remaining: %d\n",
+			       pos - data, size - tmp);*/
+
+			//hid_i = 0;
+			
+			break;
+/*		case USB_DESCTYPE_HID_REPORT:
+		case USB_DESCTYPE_HID_PHYSICAL: {
+			// check if the type matches
+			uint8_t exp_type = 
+			    actual_iface->class_desc_info[hid_i].type;
+			if (exp_type != desc_type) {
+				fprintf(stderr, "Expected descriptor type %u, "
+				    "but got %u.\n", exp_type, desc_type);
+				ret = EINVAL;
+				goto end;
+			}
+			
+			// the size of this descriptor is stored in the
+			// class-specific descriptor info
+			uint16_t length = 
+			    actual_iface->class_desc_info[hid_i].length;
+			
+			printf("Saving class-specific descriptor #%d\n", hid_i);
+			
+			actual_iface->class_descs[hid_i] = 
+			    (uint8_t *)malloc(length);
+			if (actual_iface->class_descs[hid_i] == NULL) {
+				ret = ENOMEM;
+				goto end;
+			}
+			
+			memcpy(actual_iface->class_descs[hid_i], pos, length);
+			pos += length;
+
+			printf("Parsed class-specific descriptor:\n");
+			dump_hid_class_descriptor(hid_i, desc_type, 
+			                          actual_iface->class_descs[hid_i], length);
+			                          
+			++hid_i;
+			
+			break; }*/
+		default:
+			fprintf(stderr, "Got descriptor of unknown type: %u.\n",
+				desc_type);
+			ret = EINVAL;
+			goto end;
+			break;
+		}
+	}
+
+end:
+	if (ret != EOK) {
+		usbkbd_config_free(config);
+	}
+	
+	return ret;
+}
+
+void usbkbd_print_config(const usb_hid_configuration_t *config)
+{
+	dump_standard_configuration_descriptor(0, &config->config_descriptor);
+	int i = 0;
+	for (; i < config->config_descriptor.interface_count; ++i) {
+		usb_hid_iface_t *iface_d = &config->interfaces[i];
+		dump_standard_interface_descriptor(&iface_d->iface_desc);
+		printf("\n");
+		int j = 0;
+		for (; j < iface_d->iface_desc.endpoint_count; ++j) {
+			dump_standard_endpoint_descriptor(
+			    &iface_d->endpoints[j]);
+			printf("\n");
+		}
+		dump_standard_hid_descriptor_header(&iface_d->hid_desc);
+		printf("\n");
+		dump_hid_class_descriptor(0, USB_DESCTYPE_HID_REPORT, 
+		    iface_d->report_desc, iface_d->hid_desc.report_desc_info.length);
+		printf("\n");
+//		printf("%d class-specific descriptors\n", 
+//		    iface_d->hid_desc.class_desc_count);
+		/*for (j = 0; j < iface_d->hid_desc.class_desc_count; ++j) {
+			dump_standard_hid_class_descriptor_info(
+			    &iface_d->class_desc_info[j]);
+		}
+		
+		for (j = 0; j < iface_d->hid_desc.class_desc_count; ++j) {
+			dump_hid_class_descriptor(j, 
+			    iface_d->class_desc_info[j].type,
+			    iface_d->class_descs[j],
+			    iface_d->class_desc_info[j].length);
+		}*/
+	}
+}
+
+/**
+ * @}
+ */
Index: uspace/drv/usbhid/descparser.h
===================================================================
--- uspace/drv/usbhid/descparser.h	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
+++ uspace/drv/usbhid/descparser.h	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2010 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
+ * Descriptor parser.
+ */
+
+#ifndef USBHID_DESCPARSER_H_
+#define USBHID_DESCPARSER_H_
+
+#include "hid.h"
+
+int usbkbd_parse_descriptors(const uint8_t *data, size_t size,
+                             usb_hid_configuration_t *config);
+
+void usbkbd_print_config(const usb_hid_configuration_t *config);
+
+#endif
+
+/**
+ * @}
+ */
Index: uspace/drv/usbhid/hid.h
===================================================================
--- uspace/drv/usbhid/hid.h	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
+++ uspace/drv/usbhid/hid.h	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
@@ -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
+ * Common definitions.
+ */
+
+#ifndef USBHID_HID_H_
+#define USBHID_HID_H_
+
+#include <usb/classes/hid.h>
+#include <driver.h>
+
+/**
+ *
+ */
+typedef struct {
+	usb_standard_interface_descriptor_t iface_desc;
+	usb_standard_endpoint_descriptor_t *endpoints;
+	usb_standard_hid_descriptor_t hid_desc;
+	uint8_t *report_desc;
+	//usb_standard_hid_class_descriptor_info_t *class_desc_info;
+	//uint8_t **class_descs;
+} usb_hid_iface_t;
+
+/**
+ *
+ */
+typedef struct {
+	usb_standard_configuration_descriptor_t config_descriptor;
+	usb_hid_iface_t *interfaces;
+} usb_hid_configuration_t;
+
+/**
+ * @brief USB/HID keyboard device type.
+ *
+ * Quite dummy right now.
+ */
+typedef struct {
+	device_t *device;
+	usb_hid_configuration_t *conf;
+	usb_address_t address;
+	usb_endpoint_t poll_endpoint;
+	usb_hid_report_parser_t *parser;
+} usb_hid_dev_kbd_t;
+
+// TODO: more configurations!
+
+#endif
Index: uspace/drv/usbhid/kbd.h
===================================================================
--- uspace/drv/usbhid/kbd.h	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
+++ uspace/drv/usbhid/kbd.h	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
@@ -0,0 +1,5 @@
+/*
+ * Dummy file because of shared layout sources.
+ *
+ * Do not delete.
+ */
Index: uspace/drv/usbhid/layout.h
===================================================================
--- uspace/drv/usbhid/layout.h	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
+++ uspace/drv/usbhid/layout.h	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2009 Jiri Svoboda
+ * Copyright (c) 2011 Lubos Slovak 
+ * (copied from /uspace/srv/hid/kbd/include/layout.h)
+ * 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
+ * Keyboard layout.
+ */
+
+#ifndef USBHID_LAYOUT_H_
+#define USBHID_LAYOUT_H_
+
+#include <sys/types.h>
+#include <io/console.h>
+
+typedef struct {
+	void (*reset)(void);
+	wchar_t (*parse_ev)(console_event_t *);
+} layout_op_t;
+
+extern layout_op_t us_qwerty_op;
+extern layout_op_t us_dvorak_op;
+extern layout_op_t cz_op;
+
+#endif
+
+/**
+ * @}
+ */
Index: uspace/drv/usbhid/main.c
===================================================================
--- uspace/drv/usbhid/main.c	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
+++ uspace/drv/usbhid/main.c	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
@@ -0,0 +1,573 @@
+/*
+ * Copyright (c) 2010 Vojtech Horky
+ * 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
+ * Main routines of USB HID driver.
+ */
+
+#include <usb/usbdrv.h>
+#include <driver.h>
+#include <ipc/driver.h>
+#include <ipc/kbd.h>
+#include <io/keycode.h>
+#include <io/console.h>
+#include <errno.h>
+#include <fibril.h>
+#include <usb/classes/hid.h>
+#include <usb/classes/hidparser.h>
+#include <usb/devreq.h>
+#include <usb/descriptor.h>
+#include <io/console.h>
+#include "hid.h"
+#include "descparser.h"
+#include "descdump.h"
+#include "conv.h"
+#include "layout.h"
+
+#define BUFFER_SIZE 32
+#define NAME "usbhid"
+
+#define GUESSED_POLL_ENDPOINT 1
+
+static void default_connection_handler(device_t *, ipc_callid_t, ipc_call_t *);
+static device_ops_t keyboard_ops = {
+	.default_handler = default_connection_handler
+};
+
+static int console_callback_phone = -1;
+
+/** Default handler for IPC methods not handled by DDF.
+ *
+ * @param dev Device handling the call.
+ * @param icallid Call id.
+ * @param icall Call data.
+ */
+void default_connection_handler(device_t *dev,
+    ipc_callid_t icallid, ipc_call_t *icall)
+{
+	sysarg_t method = IPC_GET_IMETHOD(*icall);
+
+	if (method == IPC_M_CONNECT_TO_ME) {
+		int callback = IPC_GET_ARG5(*icall);
+
+		if (console_callback_phone != -1) {
+			ipc_answer_0(icallid, ELIMIT);
+			return;
+		}
+
+		console_callback_phone = callback;
+		ipc_answer_0(icallid, EOK);
+		return;
+	}
+
+	ipc_answer_0(icallid, EINVAL);
+}
+
+#if 0
+static void send_key(int key, int type, wchar_t c) {
+	async_msg_4(console_callback_phone, KBD_EVENT, type, key,
+	    KM_NUM_LOCK, c);
+}
+#endif
+
+/*
+ * TODO: Move somewhere else
+ */
+/*
+#define BYTES_PER_LINE 12
+
+static void dump_buffer(const char *msg, const uint8_t *buffer, size_t length)
+{
+	printf("%s\n", msg);
+	
+	size_t i;
+	for (i = 0; i < length; i++) {
+		printf("  0x%02X", buffer[i]);
+		if (((i > 0) && (((i+1) % BYTES_PER_LINE) == 0))
+		    || (i + 1 == length)) {
+			printf("\n");
+		}
+	}
+}
+*/
+/*
+ * Copy-paste from srv/hid/kbd/generic/kbd.c
+ */
+
+/** Currently active modifiers. 
+ *
+ * TODO: put to device?
+ */
+static unsigned mods = KM_NUM_LOCK;
+
+/** Currently pressed lock keys. We track these to tackle autorepeat.  
+ *
+ * TODO: put to device? 
+ */
+static unsigned lock_keys;
+
+#define NUM_LAYOUTS 3
+
+static layout_op_t *layout[NUM_LAYOUTS] = {
+	&us_qwerty_op,
+	&us_dvorak_op,
+	&cz_op
+};
+
+static int active_layout = 0;
+
+static void kbd_push_ev(int type, unsigned int key)
+{
+	console_event_t ev;
+	unsigned mod_mask;
+
+	// TODO: replace by our own parsing?? or are the key codes identical??
+	switch (key) {
+	case KC_LCTRL: mod_mask = KM_LCTRL; break;
+	case KC_RCTRL: mod_mask = KM_RCTRL; break;
+	case KC_LSHIFT: mod_mask = KM_LSHIFT; break;
+	case KC_RSHIFT: mod_mask = KM_RSHIFT; break;
+	case KC_LALT: mod_mask = KM_LALT; break;
+	case KC_RALT: mod_mask = KM_RALT; break;
+	default: mod_mask = 0; break;
+	}
+
+	if (mod_mask != 0) {
+		if (type == KEY_PRESS)
+			mods = mods | mod_mask;
+		else
+			mods = mods & ~mod_mask;
+	}
+
+	switch (key) {
+	case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; break;
+	case KC_NUM_LOCK: mod_mask = KM_NUM_LOCK; break;
+	case KC_SCROLL_LOCK: mod_mask = KM_SCROLL_LOCK; break;
+	default: mod_mask = 0; break;
+	}
+
+	if (mod_mask != 0) {
+		if (type == KEY_PRESS) {
+			/*
+			 * Only change lock state on transition from released
+			 * to pressed. This prevents autorepeat from messing
+			 * up the lock state.
+			 */
+			mods = mods ^ (mod_mask & ~lock_keys);
+			lock_keys = lock_keys | mod_mask;
+
+			/* Update keyboard lock indicator lights. */
+			// TODO
+			//kbd_ctl_set_ind(mods);
+		} else {
+			lock_keys = lock_keys & ~mod_mask;
+		}
+	}
+/*
+	printf("type: %d\n", type);
+	printf("mods: 0x%x\n", mods);
+	printf("keycode: %u\n", key);
+*/
+	
+	if (type == KEY_PRESS && (mods & KM_LCTRL) &&
+		key == KC_F1) {
+		active_layout = 0;
+		layout[active_layout]->reset();
+		return;
+	}
+
+	if (type == KEY_PRESS && (mods & KM_LCTRL) &&
+		key == KC_F2) {
+		active_layout = 1;
+		layout[active_layout]->reset();
+		return;
+	}
+
+	if (type == KEY_PRESS && (mods & KM_LCTRL) &&
+		key == KC_F3) {
+		active_layout = 2;
+		layout[active_layout]->reset();
+		return;
+	}
+	
+	ev.type = type;
+	ev.key = key;
+	ev.mods = mods;
+
+	ev.c = layout[active_layout]->parse_ev(&ev);
+
+	printf("Sending key %d to the console\n", ev.key);
+	assert(console_callback_phone != -1);
+	async_msg_4(console_callback_phone, KBD_EVENT, ev.type, ev.key, ev.mods, ev.c);
+}
+/*
+ * End of copy-paste
+ */
+
+	/*
+	 * TODO:
+	 * 1) key press / key release - how does the keyboard notify about release?
+	 * 2) layouts (use the already defined), not important now
+	 * 3) 
+	 */
+
+/*
+ * Callbacks for parser
+ */
+static void usbkbd_process_keycodes(const uint8_t *key_codes, size_t count,
+    uint8_t modifiers, void *arg)
+{
+	printf("Got keys: ");
+	unsigned i;
+	for (i = 0; i < count; ++i) {
+		printf("%d ", key_codes[i]);
+		// TODO: Key press / release
+
+		// TODO: NOT WORKING
+		unsigned int key = usbkbd_parse_scancode(key_codes[i]);
+		kbd_push_ev(KEY_PRESS, key);
+	}
+	printf("\n");
+}
+
+/*
+ * Kbd functions
+ */
+static int usbkbd_get_report_descriptor(usb_hid_dev_kbd_t *kbd_dev)
+{
+	// iterate over all configurations and interfaces
+	// TODO: more configurations!!
+	unsigned i;
+	for (i = 0; i < kbd_dev->conf->config_descriptor.interface_count; ++i) {
+		// TODO: endianness
+		uint16_t length = 
+		    kbd_dev->conf->interfaces[i].hid_desc.report_desc_info.length;
+		size_t actual_size = 0;
+
+		// allocate space for the report descriptor
+		kbd_dev->conf->interfaces[i].report_desc = (uint8_t *)malloc(length);
+		
+		// get the descriptor from the device
+		int rc = usb_drv_req_get_descriptor(kbd_dev->device->parent_phone,
+		    kbd_dev->address, USB_REQUEST_TYPE_CLASS, USB_DESCTYPE_HID_REPORT, 
+		    0, i, kbd_dev->conf->interfaces[i].report_desc, length, 
+		    &actual_size);
+
+		if (rc != EOK) {
+			return rc;
+		}
+
+		assert(actual_size == length);
+
+		//dump_hid_class_descriptor(0, USB_DESCTYPE_HID_REPORT, 
+		//    kbd_dev->conf->interfaces[i].report_desc, length);
+	}
+
+	return EOK;
+}
+
+static int usbkbd_process_descriptors(usb_hid_dev_kbd_t *kbd_dev)
+{
+	// get the first configuration descriptor (TODO: parse also other!)
+	usb_standard_configuration_descriptor_t config_desc;
+	
+	int rc = usb_drv_req_get_bare_configuration_descriptor(
+	    kbd_dev->device->parent_phone, kbd_dev->address, 0, &config_desc);
+	
+	if (rc != EOK) {
+		return rc;
+	}
+	
+	// prepare space for all underlying descriptors
+	uint8_t *descriptors = (uint8_t *)malloc(config_desc.total_length);
+	if (descriptors == NULL) {
+		return ENOMEM;
+	}
+	
+	size_t transferred = 0;
+	// get full configuration descriptor
+	rc = usb_drv_req_get_full_configuration_descriptor(
+	    kbd_dev->device->parent_phone, kbd_dev->address, 0, descriptors,
+	    config_desc.total_length, &transferred);
+	
+	if (rc != EOK) {
+		return rc;
+	}
+	if (transferred != config_desc.total_length) {
+		return ELIMIT;
+	}
+	
+	kbd_dev->conf = (usb_hid_configuration_t *)calloc(1, 
+	    sizeof(usb_hid_configuration_t));
+	if (kbd_dev->conf == NULL) {
+		free(descriptors);
+		return ENOMEM;
+	}
+	
+	rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf);
+	free(descriptors);
+	if (rc != EOK) {
+		printf("Problem with parsing standard descriptors.\n");
+		return rc;
+	}
+
+	// get and report descriptors
+	rc = usbkbd_get_report_descriptor(kbd_dev);
+	if (rc != EOK) {
+		printf("Problem with parsing HID REPORT descriptor.\n");
+		return rc;
+	}
+	
+	//usbkbd_print_config(kbd_dev->conf);
+
+	/*
+	 * TODO: 
+	 * 1) select one configuration (lets say the first)
+	 * 2) how many interfaces?? how to select one??
+     *    ("The default setting for an interface is always alternate setting zero.")
+	 * 3) find endpoint which is IN and INTERRUPT (parse), save its number
+     *    as the endpoint for polling
+	 */
+	
+	return EOK;
+}
+
+static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev)
+{
+	usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)calloc(1, 
+	    sizeof(usb_hid_dev_kbd_t));
+
+	if (kbd_dev == NULL) {
+		fprintf(stderr, NAME ": No memory!\n");
+		return NULL;
+	}
+
+	kbd_dev->device = dev;
+
+	// get phone to my HC and save it as my parent's phone
+	// TODO: maybe not a good idea if DDF will use parent_phone
+	int rc = kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0);
+	if (rc < 0) {
+		printf("Problem setting phone to HC.\n");
+		free(kbd_dev);
+		return NULL;
+	}
+
+	rc = kbd_dev->address = usb_drv_get_my_address(dev->parent_phone, dev);
+	if (rc < 0) {
+		printf("Problem getting address of the device.\n");
+		free(kbd_dev);
+		return NULL;
+	}
+
+	// doesn't matter now that we have no address
+//	if (kbd_dev->address < 0) {
+//		fprintf(stderr, NAME ": No device address!\n");
+//		free(kbd_dev);
+//		return NULL;
+//	}
+
+	// default endpoint
+	kbd_dev->poll_endpoint = GUESSED_POLL_ENDPOINT;
+	
+	/*
+	 * will need all descriptors:
+	 * 1) choose one configuration from configuration descriptors 
+	 *    (set it to the device)
+	 * 2) set endpoints from endpoint descriptors
+	 */
+
+	// TODO: get descriptors, parse descriptors and save endpoints
+	usbkbd_process_descriptors(kbd_dev);
+
+	return kbd_dev;
+}
+
+static void usbkbd_process_interrupt_in(usb_hid_dev_kbd_t *kbd_dev,
+                                        uint8_t *buffer, size_t actual_size)
+{
+	usb_hid_report_in_callbacks_t *callbacks =
+	    (usb_hid_report_in_callbacks_t *)malloc(
+		sizeof(usb_hid_report_in_callbacks_t));
+	callbacks->keyboard = usbkbd_process_keycodes;
+
+	//usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 
+	//    NULL);
+	printf("Calling usb_hid_boot_keyboard_input_report() with size %zu\n",
+	    actual_size);
+	//dump_buffer("bufffer: ", buffer, actual_size);
+	int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, 
+	    NULL);
+	if (rc != EOK) {
+		printf("Error in usb_hid_boot_keyboard_input_report(): %d\n", rc);
+	}
+}
+
+static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev)
+{
+	int rc;
+	usb_handle_t handle;
+	uint8_t buffer[BUFFER_SIZE];
+	size_t actual_size;
+	//usb_endpoint_t poll_endpoint = 1;
+
+//	usb_address_t my_address = usb_drv_get_my_address(dev->parent_phone,
+//	    dev);
+//	if (my_address < 0) {
+//		return;
+//	}
+
+	usb_target_t poll_target = {
+		.address = kbd_dev->address,
+		.endpoint = kbd_dev->poll_endpoint
+	};
+
+	printf("Polling keyboard...\n");
+
+	while (true) {
+		async_usleep(1000 * 1000 * 2);
+		rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone,
+		    poll_target, buffer, BUFFER_SIZE, &actual_size, &handle);
+
+		if (rc != EOK) {
+			printf("Error in usb_drv_async_interrupt_in(): %d\n", rc);
+			continue;
+		}
+
+		rc = usb_drv_async_wait_for(handle);
+		if (rc != EOK) {
+			printf("Error in usb_drv_async_wait_for(): %d\n", rc);
+			continue;
+		}
+
+		/*
+		 * If the keyboard answered with NAK, it returned no data.
+		 * This implies that no change happened since last query.
+		 */
+		if (actual_size == 0) {
+			printf("Keyboard returned NAK\n");
+			continue;
+		}
+
+		/*
+		 * TODO: Process pressed keys.
+		 */
+		printf("Calling usbkbd_process_interrupt_in()\n");
+		usbkbd_process_interrupt_in(kbd_dev, buffer, actual_size);
+	}
+
+	// not reached
+	assert(0);
+}
+
+static int usbkbd_fibril_device(void *arg)
+{
+	printf("!!! USB device fibril\n");
+
+	if (arg == NULL) {
+		printf("No device!\n");
+		return -1;
+	}
+
+	device_t *dev = (device_t *)arg;
+
+	// initialize device (get and process descriptors, get address, etc.)
+	usb_hid_dev_kbd_t *kbd_dev = usbkbd_init_device(dev);
+	if (kbd_dev == NULL) {
+		printf("Error while initializing device.\n");
+		return -1;
+	}
+
+	usbkbd_poll_keyboard(kbd_dev);
+
+	return EOK;
+}
+
+static int usbkbd_add_device(device_t *dev)
+{
+	/* For now, fail immediately. */
+	//return ENOTSUP;
+
+	/*
+	 * When everything is okay, connect to "our" HC.
+	 *
+	 * Not supported yet, skip..
+	 */
+//	int phone = usb_drv_hc_connect_auto(dev, 0);
+//	if (phone < 0) {
+//		/*
+//		 * Connecting to HC failed, roll-back and announce
+//		 * failure.
+//		 */
+//		return phone;
+//	}
+
+//	dev->parent_phone = phone;
+
+	/*
+	 * Create new fibril for handling this keyboard
+	 */
+	fid_t fid = fibril_create(usbkbd_fibril_device, dev);
+	if (fid == 0) {
+		printf("%s: failed to start fibril for HID device\n", NAME);
+		return ENOMEM;
+	}
+	fibril_add_ready(fid);
+
+	dev->ops = &keyboard_ops;
+
+	add_device_to_class(dev, "keyboard");
+
+	/*
+	 * Hurrah, device is initialized.
+	 */
+	return EOK;
+}
+
+static driver_ops_t kbd_driver_ops = {
+	.add_device = usbkbd_add_device,
+};
+
+static driver_t kbd_driver = {
+	.name = NAME,
+	.driver_ops = &kbd_driver_ops
+};
+
+int main(int argc, char *argv[])
+{
+	return driver_main(&kbd_driver);
+}
+
+/**
+ * @}
+ */
Index: uspace/drv/usbhid/usbhid.ma
===================================================================
--- uspace/drv/usbhid/usbhid.ma	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
+++ uspace/drv/usbhid/usbhid.ma	(revision c2772b8f24f0b1dbeac73f461826687e10411f0c)
@@ -0,0 +1,4 @@
+10 usb&class=hid
+10 usb&class=HID
+10 usb&interface&class=HID
+10 usb&hid
Index: pace/drv/usbkbd/Makefile
===================================================================
--- uspace/drv/usbkbd/Makefile	(revision 54b5625688dd8f9522ddb56ea51a0dc1b9759df6)
+++ 	(revision )
@@ -1,55 +1,0 @@
-#
-# Copyright (c) 2010 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.
-#
-
-USPACE_PREFIX = ../..
-LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBUSB_PREFIX)/libusb.a
-EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBUSB_PREFIX)/include -I.
-BINARY = usbkbd
-SRV_KBD = $(USPACE_PREFIX)/srv/hid/kbd
-
-SOURCES = \
-	main.c \
-	descparser.c \
-	descdump.c \
-	conv.c \
-	us_qwerty.c \
-	us_dvorak.c \
-	cz.c
-
-include $(USPACE_PREFIX)/Makefile.common
-
-us_qwerty.c:
-	ln -snf $(SRV_KBD)/layout/$@ $@
-
-us_dvorak.c:
-	ln -snf $(SRV_KBD)/layout/$@ $@
-
-cz.c:
-	ln -snf $(SRV_KBD)/layout/$@ $@
-
-
Index: pace/drv/usbkbd/conv.c
===================================================================
--- uspace/drv/usbkbd/conv.c	(revision 54b5625688dd8f9522ddb56ea51a0dc1b9759df6)
+++ 	(revision )
@@ -1,186 +1,0 @@
-/*
- * 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.
- */
-#include <io/keycode.h>
-#include <stdint.h>
-#include "conv.h"
-
-static int scanmap_simple[255] = {
-
-//	[0x29] = KC_BACKTICK,
-
-//	[0x02] = KC_1,
-//	[0x03] = KC_2,
-	[0x04] = KC_A,
-	[0x05] = KC_B,
-	[0x06] = KC_C,
-	[0x07] = KC_D,
-	[0x08] = KC_E,
-	[0x09] = KC_F,
-	[0x0a] = KC_G,
-	[0x0b] = KC_H,
-	[0x0c] = KC_I,
-	[0x0d] = KC_J,
-	[0x0e] = KC_K,
-	[0x0f] = KC_L,
-	[0x10] = KC_M,
-	[0x11] = KC_N,
-	[0x12] = KC_O,
-	[0x13] = KC_P,
-	[0x14] = KC_Q,
-	[0x15] = KC_R,
-	[0x16] = KC_S,
-	[0x17] = KC_T,
-	[0x18] = KC_U,
-	[0x19] = KC_V,
-	[0x1a] = KC_W,
-	[0x1b] = KC_X,
-	[0x1c] = KC_Y,
-	[0x1d] = KC_Z,
-
-	[0x1e] = KC_1,
-	[0x1f] = KC_2,
-	[0x20] = KC_3,
-	[0x21] = KC_4,
-	[0x22] = KC_5,
-	[0x23] = KC_6,
-	[0x24] = KC_7,
-	[0x25] = KC_8,
-	[0x26] = KC_9,
-	[0x27] = KC_0,
-	
-	[0x28] = KC_ENTER,
-	[0x29] = KC_ESCAPE,
-	[0x2a] = KC_BACKSPACE,
-	[0x2b] = KC_TAB,
-	[0x2c] = KC_SPACE,
-
-	[0x2d] = KC_MINUS,  // same as DASH? (- or _)
-	[0x2e] = KC_EQUALS,
-	[0x2f] = KC_LBRACKET,
-	[0x30] = KC_RBRACKET,
-	[0x31] = KC_BACKSLASH,
-	//[0x32] = KC_,	// TODO: HASH??? maybe some as 0x31 - backslash
-	[0x33] = KC_SEMICOLON,
-	[0x34] = KC_QUOTE,  // same as APOSTROPHE? (')
-	[0x35] = KC_BACKTICK,  // same as GRAVE ACCENT?? (`)
-	[0x36] = KC_COMMA,
-	[0x37] = KC_PERIOD,
-	[0x38] = KC_SLASH,
-
-	[0x39] = KC_CAPS_LOCK,
-	
-	[0x3a] = KC_F1,
-	[0x3b] = KC_F2,
-	[0x3c] = KC_F3,
-	[0x3d] = KC_F4,
-	[0x3e] = KC_F5,
-	[0x3f] = KC_F6,
-	[0x40] = KC_F7,
-	[0x41] = KC_F8,
-	[0x42] = KC_F9,
-	[0x43] = KC_F10,
-	[0x44] = KC_F11,
-	[0x45] = KC_F12,
-	
-	[0x46] = KC_PRTSCR,
-	[0x47] = KC_SCROLL_LOCK,
-	[0x48] = KC_PAUSE,
-	[0x49] = KC_INSERT,
-	[0x4a] = KC_HOME,
-	[0x4b] = KC_PAGE_UP,
-	[0x4c] = KC_DELETE,
-	[0x4d] = KC_END,
-	[0x4e] = KC_PAGE_DOWN,
-	[0x4f] = KC_RIGHT,
-	[0x50] = KC_LEFT,
-	[0x51] = KC_DOWN,
-	[0x52] = KC_UP,
-	
-	//[0x64] = // some funny key
-	
-	[0xe0] = KC_LCTRL,
-	[0xe1] = KC_LSHIFT,
-	[0xe2] = KC_LALT,
-	//[0xe3] = KC_L	// TODO: left GUI
-	[0xe4] = KC_RCTRL,
-	[0xe5] = KC_RSHIFT,
-	[0xe6] = KC_RALT,
-	//[0xe7] = KC_R	// TODO: right GUI
-	
-};
-
-unsigned int usbkbd_parse_scancode(int scancode)
-{
-//	console_ev_type_t type;
-	unsigned int key;
-	int *map = scanmap_simple;
-	size_t map_length = sizeof(scanmap_simple) / sizeof(int);
-
-	/*
-	 * ACK/NAK are returned as response to us sending a command.
-	 * We are not interested in them.
-	 */
-//	if (scancode == SC_ACK || scancode == SC_NAK)
-//		return;
-
-//	if (scancode == 0xe0) {
-//		ds = ds_e;
-//		return;
-//	}
-
-//	switch (ds) {
-//	case ds_s:
-//		map = scanmap_simple;
-//		map_length = sizeof(scanmap_simple) / sizeof(int);
-//		break;
-//	case ds_e:
-//		map = scanmap_e0;
-//		map_length = sizeof(scanmap_e0) / sizeof(int);
-//		break;
-//	default:
-//		map = NULL;
-//		map_length = 0;
-//	}
-
-//	ds = ds_s;
-
-//	if (scancode & 0x80) {
-//		scancode &= ~0x80;
-//		type = KEY_RELEASE;
-//	} else {
-//		type = KEY_PRESS;
-//	}
-
-	if ((scancode < 0) || ((size_t) scancode >= map_length))
-		return -1;
-
-	key = map[scancode];
-//	if (key != 0)
-//		kbd_push_ev(type, key);
-	return key;
-}
Index: pace/drv/usbkbd/conv.h
===================================================================
--- uspace/drv/usbkbd/conv.h	(revision 54b5625688dd8f9522ddb56ea51a0dc1b9759df6)
+++ 	(revision )
@@ -1,41 +1,0 @@
-/*
- * 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 usb
- * @{
- */
-/** @file
- * @brief USB Scancode parser.
- */
-
-#ifndef USBHID_CONV_H_
-#define USBHID_CONV_H_
-
-unsigned int usbkbd_parse_scancode(int scancode);
-
-#endif
Index: pace/drv/usbkbd/descdump.c
===================================================================
--- uspace/drv/usbkbd/descdump.c	(revision 54b5625688dd8f9522ddb56ea51a0dc1b9759df6)
+++ 	(revision )
@@ -1,153 +1,0 @@
-/*
- * Copyright (c) 2010 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
- * @{
- */
-
-#include <usb/classes/hid.h>
-
-#include "descdump.h"
-
-/*----------------------------------------------------------------------------*/
-
-#define BYTES_PER_LINE 12
-
-static void dump_buffer(const char *msg, const uint8_t *buffer, size_t length)
-{
-	printf("%s\n", msg);
-
-	size_t i;
-	for (i = 0; i < length; i++) {
-		printf("  0x%02X", buffer[i]);
-		if (((i > 0) && (((i+1) % BYTES_PER_LINE) == 0))
-		    || (i + 1 == length)) {
-			printf("\n");
-		}
-	}
-}
-
-/*----------------------------------------------------------------------------*/
-
-#define INDENT "  "
-
-void dump_standard_configuration_descriptor(
-    int index, const usb_standard_configuration_descriptor_t *d)
-{
-	bool self_powered = d->attributes & 64;
-	bool remote_wakeup = d->attributes & 32;
-	
-	printf("Standard configuration descriptor #%d\n", index);
-	printf(INDENT "bLength = %d\n", d->length);
-	printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type);
-	printf(INDENT "wTotalLength = %d\n", d->total_length);
-	printf(INDENT "bNumInterfaces = %d\n", d->interface_count);
-	printf(INDENT "bConfigurationValue = %d\n", d->configuration_number);
-	printf(INDENT "iConfiguration = %d\n", d->str_configuration);
-	printf(INDENT "bmAttributes = %d [%s%s%s]\n", d->attributes,
-	    self_powered ? "self-powered" : "",
-	    (self_powered & remote_wakeup) ? ", " : "",
-	    remote_wakeup ? "remote-wakeup" : "");
-	printf(INDENT "MaxPower = %d (%dmA)\n", d->max_power,
-	    2 * d->max_power);
-	// printf(INDENT " = %d\n", d->);
-}
-
-void dump_standard_interface_descriptor(
-    const usb_standard_interface_descriptor_t *d)
-{
-	printf("Standard interface descriptor\n");
-	printf(INDENT "bLength = %d\n", d->length);
-	printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type);
-	printf(INDENT "bInterfaceNumber = %d\n", d->interface_number);
-	printf(INDENT "bAlternateSetting = %d\n", d->alternate_setting);
-	printf(INDENT "bNumEndpoints = %d\n", d->endpoint_count);
-	printf(INDENT "bInterfaceClass = %d\n", d->interface_class);
-	printf(INDENT "bInterfaceSubClass = %d\n", d->interface_subclass);
-	printf(INDENT "bInterfaceProtocol = %d\n", d->interface_protocol);
-	printf(INDENT "iInterface = %d\n", d->str_interface);
-}
-
-void dump_standard_endpoint_descriptor(
-    const usb_standard_endpoint_descriptor_t *d)
-{
-	const char *transfer_type;
-	switch (d->attributes & 3) {
-	case USB_TRANSFER_CONTROL:
-		transfer_type = "control";
-		break;
-	case USB_TRANSFER_ISOCHRONOUS:
-		transfer_type = "isochronous";
-		break;
-	case USB_TRANSFER_BULK:
-		transfer_type = "bulk";
-		break;
-	case USB_TRANSFER_INTERRUPT:
-		transfer_type = "interrupt";
-		break;
-	}
-
-	printf("Standard endpoint descriptor\n");
-	printf(INDENT "bLength = %d\n", d->length);
-	printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type);
-	printf(INDENT "bmAttributes = %d [%s]\n", d->attributes, transfer_type);
-	printf(INDENT "wMaxPacketSize = %d\n", d->max_packet_size);
-	printf(INDENT "bInterval = %d\n", d->poll_interval);
-}
-
-void dump_standard_hid_descriptor_header(
-    const usb_standard_hid_descriptor_t *d)
-{
-	printf("Standard HID descriptor\n");
-	printf(INDENT "bLength = %d\n", d->length);
-	printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type);
-	printf(INDENT "bcdHID = %d\n", d->spec_release);
-	printf(INDENT "bCountryCode = %d\n", d->country_code);
-	printf(INDENT "bNumDescriptors = %d\n", d->class_desc_count);
-	printf(INDENT "bDescriptorType = %d\n", d->report_desc_info.type);
-	printf(INDENT "wDescriptorLength = %d\n", d->report_desc_info.length);
-}
-
-void dump_standard_hid_class_descriptor_info(
-    const usb_standard_hid_class_descriptor_info_t *d)
-{
-	printf(INDENT "bDescriptorType = %d\n", d->type);
-	printf(INDENT "wDescriptorLength = %d\n", d->length);
-}
-
-void dump_hid_class_descriptor(int index, uint8_t type, 
-    const uint8_t *d, size_t size )
-{
-	printf("Class-specific descriptor #%d (type: %u)\n", index, type);
-	assert(d != NULL);
-	dump_buffer("", d, size);
-}
-
-/**
- * @}
- */
-
Index: pace/drv/usbkbd/descdump.h
===================================================================
--- uspace/drv/usbkbd/descdump.h	(revision 54b5625688dd8f9522ddb56ea51a0dc1b9759df6)
+++ 	(revision )
@@ -1,58 +1,0 @@
-/*
- * Copyright (c) 2010 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
- * @{
- */
-#ifndef USBHID_DESCDUMP_H_
-#define USBHID_DESCDUMP_H_
-
-#include "hid.h"
-
-void dump_standard_configuration_descriptor(
-    int index, const usb_standard_configuration_descriptor_t *d);
-
-void dump_standard_interface_descriptor(
-    const usb_standard_interface_descriptor_t *d);
-
-void dump_standard_endpoint_descriptor(
-    const usb_standard_endpoint_descriptor_t *d);
-
-void dump_standard_hid_descriptor_header(
-    const usb_standard_hid_descriptor_t *d);
-
-void dump_standard_hid_class_descriptor_info(
-    const usb_standard_hid_class_descriptor_info_t *d);
-
-void dump_hid_class_descriptor(int index, uint8_t type, 
-    const uint8_t *d, size_t size);
-
-#endif /* USBHID_DESCDUMP_H_ */
-
-/**
- * @}
- */
Index: pace/drv/usbkbd/descparser.c
===================================================================
--- uspace/drv/usbkbd/descparser.c	(revision 54b5625688dd8f9522ddb56ea51a0dc1b9759df6)
+++ 	(revision )
@@ -1,347 +1,0 @@
-/*
- * Copyright (c) 2010 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
- * @{
- */
-
-#include <errno.h>
-#include <stdint.h>
-#include <usb/usb.h>
-#include <usb/classes/hid.h>
-#include <usb/descriptor.h>
-#include "descparser.h"
-#include "descdump.h"
-
-static void usbkbd_config_free(usb_hid_configuration_t *config)
-{
-	if (config == NULL) {
-		return;
-	}
-	
-	if (config->interfaces == NULL) {
-		return;
-	}
-	
-	int i;
-	for (i = 0; i < config->config_descriptor.interface_count; ++i) {
-		
-		usb_hid_iface_t *iface = &config->interfaces[i];
-		
-		if (iface->endpoints != NULL) {
-			free(config->interfaces[i].endpoints);
-		}
-		/*if (iface->class_desc_info != NULL) {
-			free(iface->class_desc_info);
-		}
-		if (iface->class_descs != NULL) {
-			int j;
-			for (j = 0; 
-			     j < iface->hid_desc.class_desc_count;
-			     ++j) {
-				if (iface->class_descs[j] != NULL) {
-					free(iface->class_descs[j]);
-				}
-			}
-		}*/
-	}
-	
-	free(config->interfaces);	
-}
-
-/*----------------------------------------------------------------------------*/
-
-
-
-/*----------------------------------------------------------------------------*/
-
-int usbkbd_parse_descriptors(const uint8_t *data, size_t size,
-                             usb_hid_configuration_t *config)
-{
-	if (config == NULL) {
-		return EINVAL;
-	}
-	
-	const uint8_t *pos = data;
-	
-	// get the configuration descriptor (should be first) || *config == NULL
-	if (*pos != sizeof(usb_standard_configuration_descriptor_t)
-	    || *(pos + 1) != USB_DESCTYPE_CONFIGURATION) {
-		fprintf(stderr, "Wrong format of configuration descriptor.\n");
-		return EINVAL;
-	}
-	
-	memcpy(&config->config_descriptor, pos, 
-	    sizeof(usb_standard_configuration_descriptor_t));
-	pos += sizeof(usb_standard_configuration_descriptor_t);
-
-	//printf("Parsed configuration descriptor: \n");
-	//dump_standard_configuration_descriptor(0, &config->config_descriptor);
-	
-	int ret = EOK;
-
-	// first descriptor after configuration should be interface
-	if (*(pos + 1) != USB_DESCTYPE_INTERFACE) {
-		fprintf(stderr, "Expected interface descriptor, but got %u.\n", 
-		    *(pos + 1));
-		return EINVAL;
-	}
-	
-	// prepare place for interface descriptors
-	config->interfaces = (usb_hid_iface_t *)calloc(
-	    config->config_descriptor.interface_count, sizeof(usb_hid_iface_t));
-	
-	int iface_i = 0;
-	// as long as these are < 0, there is no space allocated for
-	// the respective structures
-	int ep_i = -1;
-	//int hid_i = -1;
-	
-	usb_hid_iface_t *actual_iface = NULL;
-	//usb_standard_endpoint_descriptor_t *actual_ep = NULL;
-	
-	// parse other descriptors
-	while ((size_t)(pos - data) < size) {
-		uint8_t desc_size = *pos;
-		uint8_t desc_type = *(pos + 1);  // 2nd byte is descriptor size
-		
-		switch (desc_type) {
-		case USB_DESCTYPE_INTERFACE:
-			if (desc_size != 
-			    sizeof(usb_standard_interface_descriptor_t)) {
-				ret = EINVAL;
-				goto end;
-			}
-			
-			actual_iface = &config->interfaces[iface_i++];
-			
-			memcpy(&actual_iface->iface_desc, pos, desc_size);
-			pos += desc_size;
-
-			//printf("Parsed interface descriptor: \n");
-			//dump_standard_interface_descriptor(&actual_iface->iface_desc);
-			
-			// allocate space for endpoint descriptors
-			uint8_t eps = actual_iface->iface_desc.endpoint_count;
-			actual_iface->endpoints = 
-			    (usb_standard_endpoint_descriptor_t *)malloc(
-			     eps * sizeof(usb_standard_endpoint_descriptor_t));
-			if (actual_iface->endpoints == NULL) {
-				ret = ENOMEM;
-				goto end;
-			}
-			ep_i = 0;
-
-			//printf("Remaining size: %d\n", size - (size_t)(pos - data));
-			
-			break;
-		case USB_DESCTYPE_ENDPOINT:
-			if (desc_size != 
-			    sizeof(usb_standard_endpoint_descriptor_t)) {
-				ret = EINVAL;
-				goto end;
-			}
-			
-			if (ep_i < 0) {
-				fprintf(stderr, "Missing interface descriptor "
-				    "before endpoint descriptor.\n");
-				ret = EINVAL;
-				goto end;
-			}
-			if (ep_i > actual_iface->iface_desc.endpoint_count) {
-				fprintf(stderr, "More endpoint descriptors than"
-					" expected.\n");
-				ret = EINVAL;
-				goto end;
-			}
-			
-			// save the endpoint descriptor
-			memcpy(&actual_iface->endpoints[ep_i], pos, desc_size);
-			pos += desc_size;
-
-			//printf("Parsed endpoint descriptor: \n");
-			//dump_standard_endpoint_descriptor(&actual_iface->endpoints[ep_i]);
-			++ep_i;
-			
-			break;
-		case USB_DESCTYPE_HID:
-			if (desc_size < sizeof(usb_standard_hid_descriptor_t)) {
-				printf("Wrong size of descriptor: %d (should be %zu)\n",
-				    desc_size, sizeof(usb_standard_hid_descriptor_t));
-				ret = EINVAL;
-				goto end;
-			}
-			
-			// copy the header of the hid descriptor
-			memcpy(&actual_iface->hid_desc, pos, 
-			       sizeof(usb_standard_hid_descriptor_t));
-			pos += sizeof(usb_standard_hid_descriptor_t);
-			
-			/*if (actual_iface->hid_desc.class_desc_count
-			    * sizeof(usb_standard_hid_class_descriptor_info_t)
-			    != desc_size 
-			        - sizeof(usb_standard_hid_descriptor_t)) {
-				fprintf(stderr, "Wrong size of HID descriptor."
-					"\n");
-				ret = EINVAL;
-				goto end;
-			}*/
-
-			//printf("Parsed HID descriptor header: \n");
-			//dump_standard_hid_descriptor_header(&actual_iface->hid_desc);
-			
-			// allocate space for all class-specific descriptor info
-			/*actual_iface->class_desc_info = 
-			    (usb_standard_hid_class_descriptor_info_t *)malloc(
-			    actual_iface->hid_desc.class_desc_count
-			    * sizeof(usb_standard_hid_class_descriptor_info_t));
-			if (actual_iface->class_desc_info == NULL) {
-				ret = ENOMEM;
-				goto end;
-			}*/
-			
-			// allocate space for all class-specific descriptors
-			/*actual_iface->class_descs = (uint8_t **)calloc(
-			    actual_iface->hid_desc.class_desc_count,
-			    sizeof(uint8_t *));
-			if (actual_iface->class_descs == NULL) {
-				ret = ENOMEM;
-				goto end;
-			}*/
-
-			// copy all class-specific descriptor info
-			// TODO: endianness
-			/*
-			memcpy(actual_iface->class_desc_info, pos, 
-			    actual_iface->hid_desc.class_desc_count
-			    * sizeof(usb_standard_hid_class_descriptor_info_t));
-			pos += actual_iface->hid_desc.class_desc_count
-			    * sizeof(usb_standard_hid_class_descriptor_info_t);
-
-			printf("Parsed HID descriptor info:\n");
-			dump_standard_hid_class_descriptor_info(
-			    actual_iface->class_desc_info);
-			*/
-			
-			/*size_t tmp = (size_t)(pos - data);
-			printf("Parser position: %d, remaining: %d\n",
-			       pos - data, size - tmp);*/
-
-			//hid_i = 0;
-			
-			break;
-/*		case USB_DESCTYPE_HID_REPORT:
-		case USB_DESCTYPE_HID_PHYSICAL: {
-			// check if the type matches
-			uint8_t exp_type = 
-			    actual_iface->class_desc_info[hid_i].type;
-			if (exp_type != desc_type) {
-				fprintf(stderr, "Expected descriptor type %u, "
-				    "but got %u.\n", exp_type, desc_type);
-				ret = EINVAL;
-				goto end;
-			}
-			
-			// the size of this descriptor is stored in the
-			// class-specific descriptor info
-			uint16_t length = 
-			    actual_iface->class_desc_info[hid_i].length;
-			
-			printf("Saving class-specific descriptor #%d\n", hid_i);
-			
-			actual_iface->class_descs[hid_i] = 
-			    (uint8_t *)malloc(length);
-			if (actual_iface->class_descs[hid_i] == NULL) {
-				ret = ENOMEM;
-				goto end;
-			}
-			
-			memcpy(actual_iface->class_descs[hid_i], pos, length);
-			pos += length;
-
-			printf("Parsed class-specific descriptor:\n");
-			dump_hid_class_descriptor(hid_i, desc_type, 
-			                          actual_iface->class_descs[hid_i], length);
-			                          
-			++hid_i;
-			
-			break; }*/
-		default:
-			fprintf(stderr, "Got descriptor of unknown type: %u.\n",
-				desc_type);
-			ret = EINVAL;
-			goto end;
-			break;
-		}
-	}
-
-end:
-	if (ret != EOK) {
-		usbkbd_config_free(config);
-	}
-	
-	return ret;
-}
-
-void usbkbd_print_config(const usb_hid_configuration_t *config)
-{
-	dump_standard_configuration_descriptor(0, &config->config_descriptor);
-	int i = 0;
-	for (; i < config->config_descriptor.interface_count; ++i) {
-		usb_hid_iface_t *iface_d = &config->interfaces[i];
-		dump_standard_interface_descriptor(&iface_d->iface_desc);
-		printf("\n");
-		int j = 0;
-		for (; j < iface_d->iface_desc.endpoint_count; ++j) {
-			dump_standard_endpoint_descriptor(
-			    &iface_d->endpoints[j]);
-			printf("\n");
-		}
-		dump_standard_hid_descriptor_header(&iface_d->hid_desc);
-		printf("\n");
-		dump_hid_class_descriptor(0, USB_DESCTYPE_HID_REPORT, 
-		    iface_d->report_desc, iface_d->hid_desc.report_desc_info.length);
-		printf("\n");
-//		printf("%d class-specific descriptors\n", 
-//		    iface_d->hid_desc.class_desc_count);
-		/*for (j = 0; j < iface_d->hid_desc.class_desc_count; ++j) {
-			dump_standard_hid_class_descriptor_info(
-			    &iface_d->class_desc_info[j]);
-		}
-		
-		for (j = 0; j < iface_d->hid_desc.class_desc_count; ++j) {
-			dump_hid_class_descriptor(j, 
-			    iface_d->class_desc_info[j].type,
-			    iface_d->class_descs[j],
-			    iface_d->class_desc_info[j].length);
-		}*/
-	}
-}
-
-/**
- * @}
- */
Index: pace/drv/usbkbd/descparser.h
===================================================================
--- uspace/drv/usbkbd/descparser.h	(revision 54b5625688dd8f9522ddb56ea51a0dc1b9759df6)
+++ 	(revision )
@@ -1,46 +1,0 @@
-/*
- * Copyright (c) 2010 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
- * @{
- */
-
-#ifndef USBHID_DESCPARSER_H_
-#define USBHID_DESCPARSER_H_
-
-#include "hid.h"
-
-int usbkbd_parse_descriptors(const uint8_t *data, size_t size,
-                             usb_hid_configuration_t *config);
-
-void usbkbd_print_config(const usb_hid_configuration_t *config);
-
-#endif
-
-/**
- * @}
- */
Index: pace/drv/usbkbd/hid.h
===================================================================
--- uspace/drv/usbkbd/hid.h	(revision 54b5625688dd8f9522ddb56ea51a0dc1b9759df6)
+++ 	(revision )
@@ -1,77 +1,0 @@
-/*
- * 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
- * Common definitions.
- */
-
-#ifndef USBHID_HID_H_
-#define USBHID_HID_H_
-
-#include <usb/classes/hid.h>
-#include <driver.h>
-
-/**
- *
- */
-typedef struct {
-	usb_standard_interface_descriptor_t iface_desc;
-	usb_standard_endpoint_descriptor_t *endpoints;
-	usb_standard_hid_descriptor_t hid_desc;
-	uint8_t *report_desc;
-	//usb_standard_hid_class_descriptor_info_t *class_desc_info;
-	//uint8_t **class_descs;
-} usb_hid_iface_t;
-
-/**
- *
- */
-typedef struct {
-	usb_standard_configuration_descriptor_t config_descriptor;
-	usb_hid_iface_t *interfaces;
-} usb_hid_configuration_t;
-
-/**
- * @brief USB/HID keyboard device type.
- *
- * Quite dummy right now.
- */
-typedef struct {
-	device_t *device;
-	usb_hid_configuration_t *conf;
-	usb_address_t address;
-	usb_endpoint_t poll_endpoint;
-	usb_hid_report_parser_t *parser;
-} usb_hid_dev_kbd_t;
-
-// TODO: more configurations!
-
-#endif
Index: pace/drv/usbkbd/layout.h
===================================================================
--- uspace/drv/usbkbd/layout.h	(revision 54b5625688dd8f9522ddb56ea51a0dc1b9759df6)
+++ 	(revision )
@@ -1,57 +1,0 @@
-/*
- * Copyright (c) 2011 Lubos Slovak 
- * (copied from /uspace/srv/hid/kbd/include/layout.h)
- * 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 usb
- * @brief 
- * @ingroup
- * @{
- */
-/** @file
- */
-
-#ifndef USBHID_LAYOUT_H_
-#define USBHID_LAYOUT_H_
-
-#include <sys/types.h>
-#include <io/console.h>
-
-typedef struct {
-	void (*reset)(void);
-	wchar_t (*parse_ev)(console_event_t *);
-} layout_op_t;
-
-extern layout_op_t us_qwerty_op;
-extern layout_op_t us_dvorak_op;
-extern layout_op_t cz_op;
-
-#endif
-
-/**
- * @}
- */
Index: pace/drv/usbkbd/main.c
===================================================================
--- uspace/drv/usbkbd/main.c	(revision 54b5625688dd8f9522ddb56ea51a0dc1b9759df6)
+++ 	(revision )
@@ -1,566 +1,0 @@
-/*
- * Copyright (c) 2010 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
- * @{
- */
-#include <usb/usbdrv.h>
-#include <driver.h>
-#include <ipc/driver.h>
-#include <ipc/kbd.h>
-#include <io/keycode.h>
-#include <io/console.h>
-#include <errno.h>
-#include <fibril.h>
-#include <usb/classes/hid.h>
-#include <usb/classes/hidparser.h>
-#include <usb/devreq.h>
-#include <usb/descriptor.h>
-#include <io/console.h>
-#include "hid.h"
-#include "descparser.h"
-#include "descdump.h"
-#include "conv.h"
-#include "layout.h"
-
-#define BUFFER_SIZE 32
-#define NAME "usbkbd"
-
-#define GUESSED_POLL_ENDPOINT 1
-
-static void default_connection_handler(device_t *, ipc_callid_t, ipc_call_t *);
-static device_ops_t keyboard_ops = {
-	.default_handler = default_connection_handler
-};
-
-static int console_callback_phone = -1;
-
-/** Default handler for IPC methods not handled by DDF.
- *
- * @param dev Device handling the call.
- * @param icallid Call id.
- * @param icall Call data.
- */
-void default_connection_handler(device_t *dev,
-    ipc_callid_t icallid, ipc_call_t *icall)
-{
-	sysarg_t method = IPC_GET_IMETHOD(*icall);
-
-	if (method == IPC_M_CONNECT_TO_ME) {
-		int callback = IPC_GET_ARG5(*icall);
-
-		if (console_callback_phone != -1) {
-			ipc_answer_0(icallid, ELIMIT);
-			return;
-		}
-
-		console_callback_phone = callback;
-		ipc_answer_0(icallid, EOK);
-		return;
-	}
-
-	ipc_answer_0(icallid, EINVAL);
-}
-
-#if 0
-static void send_key(int key, int type, wchar_t c) {
-	async_msg_4(console_callback_phone, KBD_EVENT, type, key,
-	    KM_NUM_LOCK, c);
-}
-#endif
-
-/*
- * TODO: Move somewhere else
- */
-/*
-#define BYTES_PER_LINE 12
-
-static void dump_buffer(const char *msg, const uint8_t *buffer, size_t length)
-{
-	printf("%s\n", msg);
-	
-	size_t i;
-	for (i = 0; i < length; i++) {
-		printf("  0x%02X", buffer[i]);
-		if (((i > 0) && (((i+1) % BYTES_PER_LINE) == 0))
-		    || (i + 1 == length)) {
-			printf("\n");
-		}
-	}
-}
-*/
-/*
- * Copy-paste from srv/hid/kbd/generic/kbd.c
- */
-
-/** Currently active modifiers. 
- *
- * TODO: put to device?
- */
-static unsigned mods = KM_NUM_LOCK;
-
-/** Currently pressed lock keys. We track these to tackle autorepeat.  
- *
- * TODO: put to device? 
- */
-static unsigned lock_keys;
-
-#define NUM_LAYOUTS 3
-
-static layout_op_t *layout[NUM_LAYOUTS] = {
-	&us_qwerty_op,
-	&us_dvorak_op,
-	&cz_op
-};
-
-static int active_layout = 0;
-
-static void kbd_push_ev(int type, unsigned int key)
-{
-	console_event_t ev;
-	unsigned mod_mask;
-
-	// TODO: replace by our own parsing?? or are the key codes identical??
-	switch (key) {
-	case KC_LCTRL: mod_mask = KM_LCTRL; break;
-	case KC_RCTRL: mod_mask = KM_RCTRL; break;
-	case KC_LSHIFT: mod_mask = KM_LSHIFT; break;
-	case KC_RSHIFT: mod_mask = KM_RSHIFT; break;
-	case KC_LALT: mod_mask = KM_LALT; break;
-	case KC_RALT: mod_mask = KM_RALT; break;
-	default: mod_mask = 0; break;
-	}
-
-	if (mod_mask != 0) {
-		if (type == KEY_PRESS)
-			mods = mods | mod_mask;
-		else
-			mods = mods & ~mod_mask;
-	}
-
-	switch (key) {
-	case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; break;
-	case KC_NUM_LOCK: mod_mask = KM_NUM_LOCK; break;
-	case KC_SCROLL_LOCK: mod_mask = KM_SCROLL_LOCK; break;
-	default: mod_mask = 0; break;
-	}
-
-	if (mod_mask != 0) {
-		if (type == KEY_PRESS) {
-			/*
-			 * Only change lock state on transition from released
-			 * to pressed. This prevents autorepeat from messing
-			 * up the lock state.
-			 */
-			mods = mods ^ (mod_mask & ~lock_keys);
-			lock_keys = lock_keys | mod_mask;
-
-			/* Update keyboard lock indicator lights. */
-			// TODO
-			//kbd_ctl_set_ind(mods);
-		} else {
-			lock_keys = lock_keys & ~mod_mask;
-		}
-	}
-/*
-	printf("type: %d\n", type);
-	printf("mods: 0x%x\n", mods);
-	printf("keycode: %u\n", key);
-*/
-	
-	if (type == KEY_PRESS && (mods & KM_LCTRL) &&
-		key == KC_F1) {
-		active_layout = 0;
-		layout[active_layout]->reset();
-		return;
-	}
-
-	if (type == KEY_PRESS && (mods & KM_LCTRL) &&
-		key == KC_F2) {
-		active_layout = 1;
-		layout[active_layout]->reset();
-		return;
-	}
-
-	if (type == KEY_PRESS && (mods & KM_LCTRL) &&
-		key == KC_F3) {
-		active_layout = 2;
-		layout[active_layout]->reset();
-		return;
-	}
-	
-	ev.type = type;
-	ev.key = key;
-	ev.mods = mods;
-
-	ev.c = layout[active_layout]->parse_ev(&ev);
-
-	printf("Sending key %d to the console\n", ev.key);
-	assert(console_callback_phone != -1);
-	async_msg_4(console_callback_phone, KBD_EVENT, ev.type, ev.key, ev.mods, ev.c);
-}
-/*
- * End of copy-paste
- */
-
-	/*
-	 * TODO:
-	 * 1) key press / key release - how does the keyboard notify about release?
-	 * 2) layouts (use the already defined), not important now
-	 * 3) 
-	 */
-
-/*
- * Callbacks for parser
- */
-static void usbkbd_process_keycodes(const uint8_t *key_codes, size_t count,
-    uint8_t modifiers, void *arg)
-{
-	printf("Got keys: ");
-	unsigned i;
-	for (i = 0; i < count; ++i) {
-		printf("%d ", key_codes[i]);
-		// TODO: Key press / release
-
-		// TODO: NOT WORKING
-		unsigned int key = usbkbd_parse_scancode(key_codes[i]);
-		kbd_push_ev(KEY_PRESS, key);
-	}
-	printf("\n");
-}
-
-/*
- * Kbd functions
- */
-static int usbkbd_get_report_descriptor(usb_hid_dev_kbd_t *kbd_dev)
-{
-	// iterate over all configurations and interfaces
-	// TODO: more configurations!!
-	unsigned i;
-	for (i = 0; i < kbd_dev->conf->config_descriptor.interface_count; ++i) {
-		// TODO: endianness
-		uint16_t length = 
-		    kbd_dev->conf->interfaces[i].hid_desc.report_desc_info.length;
-		size_t actual_size = 0;
-
-		// allocate space for the report descriptor
-		kbd_dev->conf->interfaces[i].report_desc = (uint8_t *)malloc(length);
-		
-		// get the descriptor from the device
-		int rc = usb_drv_req_get_descriptor(kbd_dev->device->parent_phone,
-		    kbd_dev->address, USB_REQUEST_TYPE_CLASS, USB_DESCTYPE_HID_REPORT, 
-		    0, i, kbd_dev->conf->interfaces[i].report_desc, length, 
-		    &actual_size);
-
-		if (rc != EOK) {
-			return rc;
-		}
-
-		assert(actual_size == length);
-
-		//dump_hid_class_descriptor(0, USB_DESCTYPE_HID_REPORT, 
-		//    kbd_dev->conf->interfaces[i].report_desc, length);
-	}
-
-	return EOK;
-}
-
-static int usbkbd_process_descriptors(usb_hid_dev_kbd_t *kbd_dev)
-{
-	// get the first configuration descriptor (TODO: parse also other!)
-	usb_standard_configuration_descriptor_t config_desc;
-	
-	int rc = usb_drv_req_get_bare_configuration_descriptor(
-	    kbd_dev->device->parent_phone, kbd_dev->address, 0, &config_desc);
-	
-	if (rc != EOK) {
-		return rc;
-	}
-	
-	// prepare space for all underlying descriptors
-	uint8_t *descriptors = (uint8_t *)malloc(config_desc.total_length);
-	if (descriptors == NULL) {
-		return ENOMEM;
-	}
-	
-	size_t transferred = 0;
-	// get full configuration descriptor
-	rc = usb_drv_req_get_full_configuration_descriptor(
-	    kbd_dev->device->parent_phone, kbd_dev->address, 0, descriptors,
-	    config_desc.total_length, &transferred);
-	
-	if (rc != EOK) {
-		return rc;
-	}
-	if (transferred != config_desc.total_length) {
-		return ELIMIT;
-	}
-	
-	kbd_dev->conf = (usb_hid_configuration_t *)calloc(1, 
-	    sizeof(usb_hid_configuration_t));
-	if (kbd_dev->conf == NULL) {
-		free(descriptors);
-		return ENOMEM;
-	}
-	
-	rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf);
-	free(descriptors);
-	if (rc != EOK) {
-		printf("Problem with parsing standard descriptors.\n");
-		return rc;
-	}
-
-	// get and report descriptors
-	rc = usbkbd_get_report_descriptor(kbd_dev);
-	if (rc != EOK) {
-		printf("Problem with parsing HID REPORT descriptor.\n");
-		return rc;
-	}
-	
-	//usbkbd_print_config(kbd_dev->conf);
-
-	/*
-	 * TODO: 
-	 * 1) select one configuration (lets say the first)
-	 * 2) how many interfaces?? how to select one??
-     *    ("The default setting for an interface is always alternate setting zero.")
-	 * 3) find endpoint which is IN and INTERRUPT (parse), save its number
-     *    as the endpoint for polling
-	 */
-	
-	return EOK;
-}
-
-static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev)
-{
-	usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)calloc(1, 
-	    sizeof(usb_hid_dev_kbd_t));
-
-	if (kbd_dev == NULL) {
-		fprintf(stderr, NAME ": No memory!\n");
-		return NULL;
-	}
-
-	kbd_dev->device = dev;
-
-	// get phone to my HC and save it as my parent's phone
-	// TODO: maybe not a good idea if DDF will use parent_phone
-	int rc = kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0);
-	if (rc < 0) {
-		printf("Problem setting phone to HC.\n");
-		free(kbd_dev);
-		return NULL;
-	}
-
-	rc = kbd_dev->address = usb_drv_get_my_address(dev->parent_phone, dev);
-	if (rc < 0) {
-		printf("Problem getting address of the device.\n");
-		free(kbd_dev);
-		return NULL;
-	}
-
-	// doesn't matter now that we have no address
-//	if (kbd_dev->address < 0) {
-//		fprintf(stderr, NAME ": No device address!\n");
-//		free(kbd_dev);
-//		return NULL;
-//	}
-
-	// default endpoint
-	kbd_dev->poll_endpoint = GUESSED_POLL_ENDPOINT;
-	
-	/*
-	 * will need all descriptors:
-	 * 1) choose one configuration from configuration descriptors 
-	 *    (set it to the device)
-	 * 2) set endpoints from endpoint descriptors
-	 */
-
-	// TODO: get descriptors, parse descriptors and save endpoints
-	usbkbd_process_descriptors(kbd_dev);
-
-	return kbd_dev;
-}
-
-static void usbkbd_process_interrupt_in(usb_hid_dev_kbd_t *kbd_dev,
-                                        uint8_t *buffer, size_t actual_size)
-{
-	usb_hid_report_in_callbacks_t *callbacks =
-	    (usb_hid_report_in_callbacks_t *)malloc(
-		sizeof(usb_hid_report_in_callbacks_t));
-	callbacks->keyboard = usbkbd_process_keycodes;
-
-	//usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 
-	//    NULL);
-	printf("Calling usb_hid_boot_keyboard_input_report() with size %zu\n",
-	    actual_size);
-	//dump_buffer("bufffer: ", buffer, actual_size);
-	int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, 
-	    NULL);
-	if (rc != EOK) {
-		printf("Error in usb_hid_boot_keyboard_input_report(): %d\n", rc);
-	}
-}
-
-static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev)
-{
-	int rc;
-	usb_handle_t handle;
-	uint8_t buffer[BUFFER_SIZE];
-	size_t actual_size;
-	//usb_endpoint_t poll_endpoint = 1;
-
-//	usb_address_t my_address = usb_drv_get_my_address(dev->parent_phone,
-//	    dev);
-//	if (my_address < 0) {
-//		return;
-//	}
-
-	usb_target_t poll_target = {
-		.address = kbd_dev->address,
-		.endpoint = kbd_dev->poll_endpoint
-	};
-
-	printf("Polling keyboard...\n");
-
-	while (true) {
-		async_usleep(1000 * 1000 * 2);
-		rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone,
-		    poll_target, buffer, BUFFER_SIZE, &actual_size, &handle);
-
-		if (rc != EOK) {
-			printf("Error in usb_drv_async_interrupt_in(): %d\n", rc);
-			continue;
-		}
-
-		rc = usb_drv_async_wait_for(handle);
-		if (rc != EOK) {
-			printf("Error in usb_drv_async_wait_for(): %d\n", rc);
-			continue;
-		}
-
-		/*
-		 * If the keyboard answered with NAK, it returned no data.
-		 * This implies that no change happened since last query.
-		 */
-		if (actual_size == 0) {
-			printf("Keyboard returned NAK\n");
-			continue;
-		}
-
-		/*
-		 * TODO: Process pressed keys.
-		 */
-		printf("Calling usbkbd_process_interrupt_in()\n");
-		usbkbd_process_interrupt_in(kbd_dev, buffer, actual_size);
-	}
-
-	// not reached
-	assert(0);
-}
-
-static int usbkbd_fibril_device(void *arg)
-{
-	printf("!!! USB device fibril\n");
-
-	if (arg == NULL) {
-		printf("No device!\n");
-		return -1;
-	}
-
-	device_t *dev = (device_t *)arg;
-
-	// initialize device (get and process descriptors, get address, etc.)
-	usb_hid_dev_kbd_t *kbd_dev = usbkbd_init_device(dev);
-	if (kbd_dev == NULL) {
-		printf("Error while initializing device.\n");
-		return -1;
-	}
-
-	usbkbd_poll_keyboard(kbd_dev);
-
-	return EOK;
-}
-
-static int usbkbd_add_device(device_t *dev)
-{
-	/* For now, fail immediately. */
-	//return ENOTSUP;
-
-	/*
-	 * When everything is okay, connect to "our" HC.
-	 *
-	 * Not supported yet, skip..
-	 */
-//	int phone = usb_drv_hc_connect_auto(dev, 0);
-//	if (phone < 0) {
-//		/*
-//		 * Connecting to HC failed, roll-back and announce
-//		 * failure.
-//		 */
-//		return phone;
-//	}
-
-//	dev->parent_phone = phone;
-
-	/*
-	 * Create new fibril for handling this keyboard
-	 */
-	fid_t fid = fibril_create(usbkbd_fibril_device, dev);
-	if (fid == 0) {
-		printf("%s: failed to start fibril for HID device\n", NAME);
-		return ENOMEM;
-	}
-	fibril_add_ready(fid);
-
-	dev->ops = &keyboard_ops;
-
-	add_device_to_class(dev, "keyboard");
-
-	/*
-	 * Hurrah, device is initialized.
-	 */
-	return EOK;
-}
-
-static driver_ops_t kbd_driver_ops = {
-	.add_device = usbkbd_add_device,
-};
-
-static driver_t kbd_driver = {
-	.name = NAME,
-	.driver_ops = &kbd_driver_ops
-};
-
-int main(int argc, char *argv[])
-{
-	return driver_main(&kbd_driver);
-}
-
-/**
- * @}
- */
Index: pace/drv/usbkbd/usbkbd.ma
===================================================================
--- uspace/drv/usbkbd/usbkbd.ma	(revision 54b5625688dd8f9522ddb56ea51a0dc1b9759df6)
+++ 	(revision )
@@ -1,4 +1,0 @@
-10 usb&class=hid
-10 usb&class=HID
-10 usb&interface&class=HID
-10 usb&hid
