Index: uspace/drv/usbhid/conv.c
===================================================================
--- uspace/drv/usbhid/conv.c	(revision b8622e2a2b028bfcaf885fa5ef67972b7e878d0a)
+++ uspace/drv/usbhid/conv.c	(revision 3a1aa20125303a64f338d843fa8ecf9271ee30a1)
@@ -36,4 +36,6 @@
 #include <io/keycode.h>
 #include <stdint.h>
+#include <stdio.h>
+#include <usb/debug.h>
 #include "conv.h"
 
@@ -141,4 +143,22 @@
 	//[0xe7] = KC_R	// TODO: right GUI
 	
+	[0x53] = KC_NUM_LOCK,
+	[0x54] = KC_NSLASH,
+	[0x55] = KC_NTIMES,
+	[0x56] = KC_NMINUS,
+	[0x57] = KC_NPLUS,
+	[0x58] = KC_NENTER,
+	[0x59] = KC_N1,
+	[0x5a] = KC_N2,
+	[0x5b] = KC_N3,
+	[0x5c] = KC_N4,
+	[0x5d] = KC_N5,
+	[0x5e] = KC_N6,
+	[0x5f] = KC_N7,
+	[0x60] = KC_N8,
+	[0x61] = KC_N9,
+	[0x62] = KC_N0,
+	[0x63] = KC_NPERIOD
+	
 };
 
@@ -189,4 +209,17 @@
 
 	key = map[scancode];
+	
+	if (scancode == 0x53) {
+		usb_log_debug("\n\nWe have a NUM LOCK!, sending key %u\n\n", key);
+	}
+	
+	if (scancode == 0x47) {
+		usb_log_debug("\n\nWe have a SCROLL LOCK!, sending key %u\n\n", key);
+	}
+	
+	if (scancode == 0x39) {
+		usb_log_debug("\n\nWe have a CAPS LOCK!, sending key %u\n\n", key);
+	}
+	
 //	if (key != 0)
 //		kbd_push_ev(type, key);
Index: uspace/drv/usbhid/hid.h
===================================================================
--- uspace/drv/usbhid/hid.h	(revision b8622e2a2b028bfcaf885fa5ef67972b7e878d0a)
+++ uspace/drv/usbhid/hid.h	(revision 3a1aa20125303a64f338d843fa8ecf9271ee30a1)
@@ -37,4 +37,6 @@
 #define USBHID_HID_H_
 
+#include <stdint.h>
+
 #include <usb/classes/hid.h>
 #include <ddf/driver.h>
@@ -74,4 +76,8 @@
 	usb_endpoint_pipe_t ctrl_pipe;
 	usb_endpoint_pipe_t poll_pipe;
+	
+	uint8_t *keycodes;
+	size_t keycode_count;
+	uint8_t modifiers;
 } usb_hid_dev_kbd_t;
 
Index: uspace/drv/usbhid/main.c
===================================================================
--- uspace/drv/usbhid/main.c	(revision b8622e2a2b028bfcaf885fa5ef67972b7e878d0a)
+++ uspace/drv/usbhid/main.c	(revision 3a1aa20125303a64f338d843fa8ecf9271ee30a1)
@@ -51,4 +51,5 @@
 #include <usb/descriptor.h>
 #include <io/console.h>
+#include <stdint.h>
 #include "hid.h"
 #include "descparser.h"
@@ -58,7 +59,9 @@
 
 #define BUFFER_SIZE 8
+#define BUFFER_OUT_SIZE 1
 #define NAME "usbhid"
 
 #define GUESSED_POLL_ENDPOINT 1
+#define BOOTP_REPORT_SIZE 6
 
 /** Keyboard polling endpoint description for boot protocol class. */
@@ -120,5 +123,5 @@
 
 static void dump_buffer(const char *msg, const uint8_t *buffer, size_t length)
-{
+{uint8_t buffer[BUFFER_SIZE];
 	printf("%s\n", msg);
 	
@@ -137,5 +140,5 @@
  */
 
-/** Currently active modifiers. 
+/** Currently active modifiers (locks is probably better word).
  *
  * TODO: put to device?
@@ -159,5 +162,105 @@
 static int active_layout = 0;
 
-static void kbd_push_ev(int type, unsigned int key)
+static void usbkbd_req_set_report(usb_hid_dev_kbd_t *kbd_dev, uint16_t iface,
+    usb_hid_report_type_t type, uint8_t *buffer, size_t buf_size)
+{
+	int rc, sess_rc;
+	
+	sess_rc = usb_endpoint_pipe_start_session(&kbd_dev->ctrl_pipe);
+	if (sess_rc != EOK) {
+		usb_log_warning("Failed to start a session: %s.\n",
+		    str_error(sess_rc));
+		return;
+	}
+
+	usb_log_debug("Sending Set_Report request to the device.\n");
+	
+	rc = usb_control_request_set(&kbd_dev->ctrl_pipe, 
+	    USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 
+	    USB_HIDREQ_SET_REPORT, type, iface, buffer, buf_size);
+
+	sess_rc = usb_endpoint_pipe_end_session(&kbd_dev->ctrl_pipe);
+
+	if (rc != EOK) {
+		usb_log_warning("Error sending output report to the keyboard: "
+		    "%s.\n", str_error(rc));
+		return;
+	}
+
+	if (sess_rc != EOK) {
+		usb_log_warning("Error closing session: %s.\n",
+		    str_error(sess_rc));
+		return;
+	}
+}
+
+static void usbkbd_req_set_protocol(usb_hid_dev_kbd_t *kbd_dev, uint16_t iface,
+    usb_hid_protocol_t protocol)
+{
+	int rc, sess_rc;
+	
+	sess_rc = usb_endpoint_pipe_start_session(&kbd_dev->ctrl_pipe);
+	if (sess_rc != EOK) {
+		usb_log_warning("Failed to start a session: %s.\n",
+		    str_error(sess_rc));
+		return;
+	}
+
+	usb_log_debug("Sending Set_Protocol request to the device.\n");
+	
+	rc = usb_control_request_set(&kbd_dev->ctrl_pipe, 
+	    USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 
+	    USB_HIDREQ_SET_PROTOCOL, protocol, iface, NULL, 0);
+
+	sess_rc = usb_endpoint_pipe_end_session(&kbd_dev->ctrl_pipe);
+
+	if (rc != EOK) {
+		usb_log_warning("Error sending output report to the keyboard: "
+		    "%s.\n", str_error(rc));
+		return;
+	}
+
+	if (sess_rc != EOK) {
+		usb_log_warning("Error closing session: %s.\n",
+		    str_error(sess_rc));
+		return;
+	}
+}
+
+static void usbkbd_set_led(unsigned mods, usb_hid_dev_kbd_t *kbd_dev) 
+{
+	uint8_t buffer[BUFFER_SIZE];
+	int rc= 0;
+	
+	uint8_t leds = 0;
+
+	if (mods & KM_NUM_LOCK) {
+		leds |= USB_HID_LED_NUM_LOCK;
+	}
+	
+	if (mods & KM_CAPS_LOCK) {
+		leds |= USB_HID_LED_CAPS_LOCK;
+	}
+	
+	if (mods & KM_SCROLL_LOCK) {
+		leds |= USB_HID_LED_SCROLL_LOCK;
+	}
+
+	// TODO: COMPOSE and KANA
+	
+	usb_log_debug("Creating output report.\n");
+	if ((rc = usb_hid_boot_keyboard_output_report(
+	    leds, buffer, BUFFER_SIZE)) != EOK) {
+		usb_log_warning("Error composing output report to the keyboard:"
+		    "%s.\n", str_error(rc));
+		return;
+	}
+	
+	// TODO: determine what interface to use!! (now set to 1)
+	usbkbd_req_set_report(kbd_dev, 1, USB_HID_REPORT_TYPE_OUTPUT, buffer, 
+	    BUFFER_SIZE);
+}
+
+static void kbd_push_ev(int type, unsigned int key, usb_hid_dev_kbd_t *kbd_dev)
 {
 	console_event_t ev;
@@ -183,12 +286,17 @@
 
 	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;
+	case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; usb_log_debug2("\n\nPushing CAPS LOCK! (mask: %u)\n\n", mod_mask); break;
+	case KC_NUM_LOCK: mod_mask = KM_NUM_LOCK; usb_log_debug2("\n\nPushing NUM LOCK! (mask: %u)\n\n", mod_mask); break;
+	case KC_SCROLL_LOCK: mod_mask = KM_SCROLL_LOCK; usb_log_debug2("\n\nPushing SCROLL LOCK! (mask: %u)\n\n", mod_mask); break;
 	default: mod_mask = 0; break;
 	}
 
 	if (mod_mask != 0) {
+		usb_log_debug2("\n\nChanging mods and lock keys\n");
+		usb_log_debug2("\nmods before: 0x%x\n", mods);
+		usb_log_debug2("\nLock keys before:0x%x\n\n", lock_keys);
+		
 		if (type == KEY_PRESS) {
+			usb_log_debug2("\nKey pressed.\n");
 			/*
 			 * Only change lock state on transition from released
@@ -200,15 +308,17 @@
 
 			/* Update keyboard lock indicator lights. */
-			// TODO
-			//kbd_ctl_set_ind(mods);
+ 			usbkbd_set_led(mods, kbd_dev);
 		} else {
+			usb_log_debug2("\nKey released.\n");
 			lock_keys = lock_keys & ~mod_mask;
 		}
 	}
 /*
-	printf("type: %d\n", type);
-	printf("mods: 0x%x\n", mods);
-	printf("keycode: %u\n", key);
+	usb_log_debug2("type: %d\n", type);
+	usb_log_debug2("mods: 0x%x\n", mods);
+	usb_log_debug2("keycode: %u\n", key);
 */
+	usb_log_debug2("\n\nmods after: 0x%x\n", mods);
+	usb_log_debug2("\nLock keys after: 0x%x\n\n", lock_keys);
 	
 	if (type == KEY_PRESS && (mods & KM_LCTRL) &&
@@ -236,10 +346,15 @@
 	ev.key = key;
 	ev.mods = mods;
+	
+	if (ev.mods & KM_NUM_LOCK) {
+		usb_log_debug("\n\nNum Lock turned on.\n\n");
+	}
 
 	ev.c = layout[active_layout]->parse_ev(&ev);
 
-	printf("Sending key %d to the console\n", ev.key);
+	usb_log_debug2("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);
+	async_msg_4(console_callback_phone, KBD_EVENT, ev.type, ev.key, 
+	    ev.mods, ev.c);
 }
 /*
@@ -249,9 +364,112 @@
 	/*
 	 * TODO:
-	 * 1) key press / key release - how does the keyboard notify about release?
+	 * 1) key press / key release - how does the keyboard notify about 
+	 *    release?
 	 * 2) layouts (use the already defined), not important now
 	 * 3) 
 	 */
 
+static const keycode_t usb_hid_modifiers_keycodes[USB_HID_MOD_COUNT] = {
+	KC_LCTRL,         /* USB_HID_MOD_LCTRL */
+	KC_LSHIFT,        /* USB_HID_MOD_LSHIFT */
+	KC_LALT,          /* USB_HID_MOD_LALT */
+	0,                /* USB_HID_MOD_LGUI */
+	KC_RCTRL,         /* USB_HID_MOD_RCTRL */
+	KC_RSHIFT,        /* USB_HID_MOD_RSHIFT */
+	KC_RALT,          /* USB_HID_MOD_RALT */
+	0,                /* USB_HID_MOD_RGUI */
+};
+
+static void usbkbd_check_modifier_changes(usb_hid_dev_kbd_t *kbd_dev,
+    uint8_t modifiers)
+{
+	/*
+	 * TODO: why the USB keyboard has NUM_, SCROLL_ and CAPS_LOCK
+	 *       both as modifiers and as keys with their own scancodes???
+	 *
+	 * modifiers should be sent as normal keys to usbkbd_parse_scancode()!!
+	 * so maybe it would be better if I received it from report parser in 
+	 * that way
+	 */
+	
+	int i;
+	for (i = 0; i < USB_HID_MOD_COUNT; ++i) {
+		if ((modifiers & usb_hid_modifiers_consts[i]) &&
+		    !(kbd_dev->modifiers & usb_hid_modifiers_consts[i])) {
+			// modifier pressed
+			if (usb_hid_modifiers_keycodes[i] != 0) {
+				kbd_push_ev(KEY_PRESS, 
+				    usb_hid_modifiers_keycodes[i], kbd_dev);
+			}
+		} else if (!(modifiers & usb_hid_modifiers_consts[i]) &&
+		    (kbd_dev->modifiers & usb_hid_modifiers_consts[i])) {
+			// modifier released
+			if (usb_hid_modifiers_keycodes[i] != 0) {
+				kbd_push_ev(KEY_RELEASE, 
+				    usb_hid_modifiers_keycodes[i], kbd_dev);
+			}
+		}	// no change
+	}
+	
+	kbd_dev->modifiers = modifiers;
+}
+
+static void usbkbd_check_key_changes(usb_hid_dev_kbd_t *kbd_dev, 
+    const uint8_t *key_codes)
+{
+	// TODO: phantom state!!
+	
+	unsigned int key;
+	unsigned int i, j;
+	
+	// TODO: quite dummy right now, think of better implementation
+	
+	// key releases
+	for (j = 0; j < kbd_dev->keycode_count; ++j) {
+		// try to find the old key in the new key list
+		i = 0;
+		while (i < kbd_dev->keycode_count
+		    && key_codes[i] != kbd_dev->keycodes[j]) {
+			++i;
+		}
+		
+		if (i == kbd_dev->keycode_count) {
+			// not found, i.e. the key was released
+			key = usbkbd_parse_scancode(kbd_dev->keycodes[j]);
+			kbd_push_ev(KEY_RELEASE, key, kbd_dev);
+			usb_log_debug2("\nKey released: %d\n", key);
+		} else {
+			// found, nothing happens
+		}
+	}
+	
+	// key presses
+	for (i = 0; i < kbd_dev->keycode_count; ++i) {
+		// try to find the new key in the old key list
+		j = 0;
+		while (j < kbd_dev->keycode_count 
+		    && kbd_dev->keycodes[j] != key_codes[i]) { 
+			++j;
+		}
+		
+		if (j == kbd_dev->keycode_count) {
+			// not found, i.e. new key pressed
+			key = usbkbd_parse_scancode(key_codes[i]);
+			usb_log_debug2("\nKey pressed: %d (keycode: %d)\n", key,
+			    key_codes[i]);
+			kbd_push_ev(KEY_PRESS, key, kbd_dev);
+		} else {
+			// found, nothing happens
+		}
+	}
+	
+	memcpy(kbd_dev->keycodes, key_codes, kbd_dev->keycode_count);
+	
+	usb_log_debug2("\nNew stored keycodes: ");
+	for (i = 0; i < kbd_dev->keycode_count; ++i) {
+		usb_log_debug2("%d ", kbd_dev->keycodes[i]);
+	}
+}
+
 /*
  * Callbacks for parser
@@ -260,23 +478,27 @@
     uint8_t modifiers, void *arg)
 {
-	printf("Got keys: ");
+	if (arg == NULL) {
+		usb_log_warning("Missing argument in callback "
+		    "usbkbd_process_keycodes().\n");
+		return;
+	}
+
+	usb_log_debug2("Got keys from parser: ");
 	unsigned i;
 	for (i = 0; i < count; ++i) {
-		printf("%d ", key_codes[i]);
-	}
-	printf("\n");
-
-	for (i = 0; i < count; ++i) {
-		// TODO: Key press / release
-
-		// TODO: NOT WORKING
-		unsigned int key = usbkbd_parse_scancode(key_codes[i]);
-
-		if (key == 0) {
-			continue;
-		}
-		kbd_push_ev(KEY_PRESS, key);
-	}
-	printf("\n");
+		usb_log_debug2("%d ", key_codes[i]);
+	}
+	usb_log_debug2("\n");
+	
+	usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)arg;
+	
+	if (count != kbd_dev->keycode_count) {
+		usb_log_warning("Number of received keycodes (%d) differs from"
+		    " expected number (%d).\n", count, kbd_dev->keycode_count);
+		return;
+	}
+	
+	usbkbd_check_modifier_changes(kbd_dev, modifiers);
+	usbkbd_check_key_changes(kbd_dev, key_codes);
 }
 
@@ -291,10 +513,11 @@
 	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;
+		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);
+		kbd_dev->conf->interfaces[i].report_desc = 
+		    (uint8_t *)malloc(length);
 		
 		// get the descriptor from the device
@@ -317,4 +540,5 @@
 	return EOK;
 }
+
 static int usbkbd_process_descriptors(usb_hid_dev_kbd_t *kbd_dev)
 {
@@ -375,7 +599,4 @@
 	}
 
-
-
-
 	kbd_dev->conf = (usb_hid_configuration_t *)calloc(1, 
 	    sizeof(usb_hid_configuration_t));
@@ -388,5 +609,5 @@
 	free(descriptors);
 	if (rc != EOK) {
-		printf("Problem with parsing standard descriptors.\n");
+		usb_log_warning("Problem with parsing standard descriptors.\n");
 		return rc;
 	}
@@ -395,5 +616,5 @@
 	rc = usbkbd_get_report_descriptor(kbd_dev);
 	if (rc != EOK) {
-		printf("Problem with parsing HID REPORT descriptor.\n");
+		usb_log_warning("Problem with parsing REPORT descriptor.\n");
 		return rc;
 	}
@@ -405,7 +626,8 @@
 	 * 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.")
+	 *    ("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
+	 *    as the endpoint for polling
 	 */
 
@@ -421,5 +643,5 @@
 
 	if (kbd_dev == NULL) {
-		fprintf(stderr, NAME ": No memory!\n");
+		usb_log_fatal("No memory!\n");
 		return NULL;
 	}
@@ -457,5 +679,4 @@
 	// TODO: get descriptors, parse descriptors and save endpoints
 	usb_endpoint_pipe_start_session(&kbd_dev->ctrl_pipe);
-	//usb_request_set_configuration(&kbd_dev->ctrl_pipe, 1);
 	rc = usbkbd_process_descriptors(kbd_dev);
 	usb_endpoint_pipe_end_session(&kbd_dev->ctrl_pipe);
@@ -463,5 +684,25 @@
 		goto error_leave;
 	}
-
+	
+	// save the size of the report
+	kbd_dev->keycode_count = BOOTP_REPORT_SIZE;
+	kbd_dev->keycodes = (uint8_t *)calloc(
+	    kbd_dev->keycode_count, sizeof(uint8_t));
+	
+	if (kbd_dev->keycodes == NULL) {
+		usb_log_fatal("No memory!\n");
+		goto error_leave;
+	}
+	
+	// set configuration to the first one
+	// TODO: handle case with no configurations
+	usb_endpoint_pipe_start_session(&kbd_dev->ctrl_pipe);
+	usb_request_set_configuration(&kbd_dev->ctrl_pipe, 
+	    kbd_dev->conf->config_descriptor.configuration_number);
+	usb_endpoint_pipe_end_session(&kbd_dev->ctrl_pipe);
+	
+	// set boot protocol
+	usbkbd_req_set_protocol(kbd_dev, 1, USB_HID_PROTOCOL_BOOT);
+	
 	return kbd_dev;
 
@@ -476,16 +717,18 @@
 	usb_hid_report_in_callbacks_t *callbacks =
 	    (usb_hid_report_in_callbacks_t *)malloc(
-		sizeof(usb_hid_report_in_callbacks_t));
+	        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);
+	/*usb_log_debug2("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);
+	int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size,
+	    callbacks, kbd_dev);
+	
+	if (rc != EOK) {
+		usb_log_warning("Error in usb_hid_boot_keyboard_input_report():"
+		    "%s\n", str_error(rc));
 	}
 }
@@ -497,12 +740,12 @@
 	size_t actual_size;
 
-	printf("Polling keyboard...\n");
+	usb_log_info("Polling keyboard...\n");
 
 	while (true) {
-		async_usleep(1000 * 10);
+		async_usleep(1000 * 1000);
 
 		sess_rc = usb_endpoint_pipe_start_session(&kbd_dev->poll_pipe);
 		if (sess_rc != EOK) {
-			printf("Failed to start a session: %s.\n",
+			usb_log_warning("Failed to start a session: %s.\n",
 			    str_error(sess_rc));
 			continue;
@@ -514,5 +757,5 @@
 
 		if (rc != EOK) {
-			printf("Error polling the keyboard: %s.\n",
+			usb_log_warning("Error polling the keyboard: %s.\n",
 			    str_error(rc));
 			continue;
@@ -520,5 +763,5 @@
 
 		if (sess_rc != EOK) {
-			printf("Error closing session: %s.\n",
+			usb_log_warning("Error closing session: %s.\n",
 			    str_error(sess_rc));
 			continue;
@@ -530,5 +773,5 @@
 		 */
 		if (actual_size == 0) {
-			printf("Keyboard returned NAK\n");
+			usb_log_debug("Keyboard returned NAK\n");
 			continue;
 		}
@@ -537,5 +780,5 @@
 		 * TODO: Process pressed keys.
 		 */
-		printf("Calling usbkbd_process_interrupt_in()\n");
+		usb_log_debug("Calling usbkbd_process_interrupt_in()\n");
 		usbkbd_process_interrupt_in(kbd_dev, buffer, actual_size);
 	}
@@ -547,19 +790,10 @@
 static int usbkbd_fibril_device(void *arg)
 {
-	printf("!!! USB device fibril\n");
-
 	if (arg == NULL) {
-		printf("No device!\n");
+		usb_log_error("No device!\n");
 		return -1;
 	}
-
-	ddf_dev_t *dev = (ddf_dev_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;
-	}
+	
+	usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)arg;
 
 	usbkbd_poll_keyboard(kbd_dev);
@@ -570,23 +804,4 @@
 static int usbkbd_add_device(ddf_dev_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 default function.
@@ -601,11 +816,20 @@
 	rc = ddf_fun_add_to_class(kbd_fun, "keyboard");
 	assert(rc == EOK);
+	
+	/* 
+	 * Initialize device (get and process descriptors, get address, etc.)
+	 */
+	usb_hid_dev_kbd_t *kbd_dev = usbkbd_init_device(dev);
+	if (kbd_dev == NULL) {
+		usb_log_error("Error while initializing device.\n");
+		return -1;
+	}
 
 	/*
 	 * Create new fibril for handling this keyboard
 	 */
-	fid_t fid = fibril_create(usbkbd_fibril_device, dev);
+	fid_t fid = fibril_create(usbkbd_fibril_device, kbd_dev);
 	if (fid == 0) {
-		printf("%s: failed to start fibril for HID device\n", NAME);
+		usb_log_error("Failed to start fibril for HID device\n");
 		return ENOMEM;
 	}
@@ -634,5 +858,5 @@
 int main(int argc, char *argv[])
 {
-	usb_log_enable(USB_LOG_LEVEL_INFO, "usbhid");
+	usb_log_enable(USB_LOG_LEVEL_MAX, NAME);
 	return ddf_driver_main(&kbd_driver);
 }
Index: uspace/lib/usb/include/usb/classes/hid.h
===================================================================
--- uspace/lib/usb/include/usb/classes/hid.h	(revision b8622e2a2b028bfcaf885fa5ef67972b7e878d0a)
+++ uspace/lib/usb/include/usb/classes/hid.h	(revision 3a1aa20125303a64f338d843fa8ecf9271ee30a1)
@@ -51,4 +51,15 @@
 } usb_hid_request_t;
 
+typedef enum {
+	USB_HID_REPORT_TYPE_INPUT = 1,
+	USB_HID_REPORT_TYPE_OUTPUT = 2,
+	USB_HID_REPORT_TYPE_FEATURE = 3
+} usb_hid_report_type_t;
+
+typedef enum {
+	USB_HID_PROTOCOL_BOOT = 0,
+	USB_HID_PROTOCOL_REPORT = 1
+} usb_hid_protocol_t;
+
 /** USB/HID subclass constants. */
 typedef enum {
@@ -62,5 +73,5 @@
 	USB_HID_PROTOCOL_KEYBOARD = 1,
 	USB_HID_PROTOCOL_MOUSE = 2
-} usb_hid_protocol_t;
+} usb_hid_iface_protocol_t;
 
 /** Part of standard USB HID descriptor specifying one class descriptor.
Index: uspace/lib/usb/include/usb/classes/hidparser.h
===================================================================
--- uspace/lib/usb/include/usb/classes/hidparser.h	(revision b8622e2a2b028bfcaf885fa5ef67972b7e878d0a)
+++ uspace/lib/usb/include/usb/classes/hidparser.h	(revision 3a1aa20125303a64f338d843fa8ecf9271ee30a1)
@@ -70,9 +70,51 @@
 } usb_hid_report_in_callbacks_t;
 
-#define USB_HID_BOOT_KEYBOARD_NUM_LOCK		0x01
-#define USB_HID_BOOT_KEYBOARD_CAPS_LOCK		0x02
-#define USB_HID_BOOT_KEYBOARD_SCROLL_LOCK	0x04
-#define USB_HID_BOOT_KEYBOARD_COMPOSE		0x08
-#define USB_HID_BOOT_KEYBOARD_KANA			0x10
+
+typedef enum {
+	USB_HID_MOD_LCTRL = 0x01,
+	USB_HID_MOD_LSHIFT = 0x02,
+	USB_HID_MOD_LALT = 0x04,
+	USB_HID_MOD_LGUI = 0x08,
+	USB_HID_MOD_RCTRL = 0x10,
+	USB_HID_MOD_RSHIFT = 0x20,
+	USB_HID_MOD_RALT = 0x40,
+	USB_HID_MOD_RGUI = 0x80,
+	USB_HID_MOD_COUNT = 8
+} usb_hid_modifiers_t;
+
+typedef enum {
+	USB_HID_LED_NUM_LOCK = 0x1,
+	USB_HID_LED_CAPS_LOCK = 0x2,
+	USB_HID_LED_SCROLL_LOCK = 0x4,
+	USB_HID_LED_COMPOSE = 0x8,
+	USB_HID_LED_KANA = 0x10,
+	USB_HID_LED_COUNT = 5
+} usb_hid_led_t;
+
+static const usb_hid_modifiers_t 
+    usb_hid_modifiers_consts[USB_HID_MOD_COUNT] = {
+	USB_HID_MOD_LCTRL,
+	USB_HID_MOD_LSHIFT,
+	USB_HID_MOD_LALT,
+	USB_HID_MOD_LGUI,
+	USB_HID_MOD_RCTRL,
+	USB_HID_MOD_RSHIFT,
+	USB_HID_MOD_RALT,
+	USB_HID_MOD_RGUI
+};
+
+//static const usb_hid_led_t usb_hid_led_consts[USB_HID_LED_COUNT] = {
+//	USB_HID_LED_NUM_LOCK,
+//	USB_HID_LED_CAPS_LOCK,
+//	USB_HID_LED_SCROLL_LOCK,
+//	USB_HID_LED_COMPOSE,
+//	USB_HID_LED_KANA
+//};
+
+//#define USB_HID_BOOT_KEYBOARD_NUM_LOCK		0x01
+//#define USB_HID_BOOT_KEYBOARD_CAPS_LOCK		0x02
+//#define USB_HID_BOOT_KEYBOARD_SCROLL_LOCK	0x04
+//#define USB_HID_BOOT_KEYBOARD_COMPOSE		0x08
+//#define USB_HID_BOOT_KEYBOARD_KANA			0x10
 
 /*
Index: uspace/lib/usb/src/hidparser.c
===================================================================
--- uspace/lib/usb/src/hidparser.c	(revision b8622e2a2b028bfcaf885fa5ef67972b7e878d0a)
+++ uspace/lib/usb/src/hidparser.c	(revision 3a1aa20125303a64f338d843fa8ecf9271ee30a1)
@@ -144,10 +144,9 @@
 int usb_hid_boot_keyboard_output_report(uint8_t leds, uint8_t *data, size_t size)
 {
-	if(size != 1){
+	if(size < 2){
 		return -1;
 	}
 
-	/* used only first five bits, others are only padding*/
-	*data = leds;
+	data[1] = leds;
 	return EOK;
 }
