Index: uspace/drv/usbkbd/kbddev.c
===================================================================
--- uspace/drv/usbkbd/kbddev.c	(revision 0533b0336346626f6fcab2d2aab41dea7f751799)
+++ uspace/drv/usbkbd/kbddev.c	(revision 85fa1e1ef16b8643988a7fdecabb541e042fefb3)
@@ -56,4 +56,5 @@
 #include <usb/classes/hidreq.h>
 #include <usb/classes/hidreport.h>
+#include <usb/classes/hid/utled.h>
 
 #include <usb/devdrv.h>
@@ -263,20 +264,31 @@
 static void usb_kbd_set_led(usb_kbd_t *kbd_dev) 
 {
-	uint8_t buffer[BOOTP_BUFFER_OUT_SIZE];
-	int rc= 0;
-	
-	memset(buffer, 0, BOOTP_BUFFER_OUT_SIZE);
-	uint8_t leds = 0;
-
-	if (kbd_dev->mods & KM_NUM_LOCK) {
-		leds |= USB_HID_LED_NUM_LOCK;
-	}
-	
-	if (kbd_dev->mods & KM_CAPS_LOCK) {
-		leds |= USB_HID_LED_CAPS_LOCK;
-	}
-	
-	if (kbd_dev->mods & KM_SCROLL_LOCK) {
-		leds |= USB_HID_LED_SCROLL_LOCK;
+//	uint8_t buffer[BOOTP_BUFFER_OUT_SIZE];
+//	int rc= 0;
+	
+//	memset(buffer, 0, BOOTP_BUFFER_OUT_SIZE);
+//	uint8_t leds = 0;
+
+	unsigned i = 0;
+	
+	if ((kbd_dev->mods & KM_NUM_LOCK) && (i < kbd_dev->led_output_size)) {
+		kbd_dev->led_data[i++] = USB_HID_LED_NUM_LOCK;
+//		leds |= USB_HID_LED_NUM_LOCK;
+	}
+	
+	if ((kbd_dev->mods & KM_CAPS_LOCK) && (i < kbd_dev->led_output_size)) {
+		kbd_dev->led_data[i++] = USB_HID_LED_CAPS_LOCK;
+//		leds |= USB_HID_LED_CAPS_LOCK;
+	}
+	
+	if ((kbd_dev->mods & KM_SCROLL_LOCK) 
+	    && (i < kbd_dev->led_output_size)) {
+		kbd_dev->led_data[i++] = USB_HID_LED_SCROLL_LOCK;
+//		leds |= USB_HID_LED_SCROLL_LOCK;
+	}
+	
+	usb_log_debug("Output report data: ");
+	for (i = 0; i < kbd_dev->led_output_size; ++i) {
+		usb_log_debug("%u: %d", i, kbd_dev->led_data[i]);
 	}
 
@@ -284,20 +296,29 @@
 	
 	usb_log_debug("Creating output report.\n");
-	usb_log_debug("Leds: 0x%x\n", leds);
-	if ((rc = usb_hid_boot_keyboard_output_report(
-	    leds, buffer, BOOTP_BUFFER_OUT_SIZE)) != EOK) {
-		usb_log_warning("Error composing output report to the keyboard:"
-		    "%s.\n", str_error(rc));
-		return;
-	}
+	
+	int rc = usb_hid_report_output_translate(kbd_dev->parser, 
+	    kbd_dev->led_path, USB_HID_PATH_COMPARE_END, kbd_dev->output_buffer, 
+	    kbd_dev->output_size, kbd_dev->led_data, kbd_dev->led_output_size);
+	
+	if (rc != EOK) {
+		usb_log_warning("Error translating LED output to output report"
+		    ".\n");
+		return;
+	}
+	
+//	if ((rc = usb_hid_boot_keyboard_output_report(
+//	    leds, buffer, BOOTP_BUFFER_OUT_SIZE)) != EOK) {
+//		usb_log_warning("Error composing output report to the keyboard:"
+//		    "%s.\n", str_error(rc));
+//		return;
+//	}
 	
 	usb_log_debug("Output report buffer: %s\n", 
-	    usb_debug_str_buffer(buffer, BOOTP_BUFFER_OUT_SIZE, 0));
-	
-	assert(kbd_dev->usb_dev != NULL);
+	    usb_debug_str_buffer(kbd_dev->output_buffer, kbd_dev->output_size, 
+	        0));
 	
 	usbhid_req_set_report(&kbd_dev->usb_dev->ctrl_pipe, 
 	    kbd_dev->usb_dev->interface_no, USB_HID_REPORT_TYPE_OUTPUT, 
-	    buffer, BOOTP_BUFFER_OUT_SIZE);
+	    kbd_dev->output_buffer, kbd_dev->output_size);
 }
 
@@ -586,5 +607,5 @@
  */
 static void usb_kbd_process_data(usb_kbd_t *kbd_dev,
-                                    uint8_t *buffer, size_t actual_size)
+                                 uint8_t *buffer, size_t actual_size)
 {
 	assert(kbd_dev->initialized == USB_KBD_STATUS_INITIALIZED);
@@ -760,6 +781,5 @@
 	usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count);
 	
-	kbd_dev->keys = (uint8_t *)calloc(
-	    kbd_dev->key_count, sizeof(uint8_t));
+	kbd_dev->keys = (uint8_t *)calloc(kbd_dev->key_count, sizeof(uint8_t));
 	
 	if (kbd_dev->keys == NULL) {
@@ -768,8 +788,49 @@
 	}
 	
+	/*
+	 * Output report
+	 */
+	kbd_dev->output_size = 0;
+	kbd_dev->output_buffer = usb_hid_report_output(kbd_dev->parser, 
+	    &kbd_dev->output_size);
+	if (kbd_dev->output_buffer == NULL) {
+		usb_log_warning("Error creating output report buffer.\n");
+		free(kbd_dev->keys);
+		return ENOMEM;  /* TODO: other error code */
+	}
+	
+	usb_log_debug("Output buffer size: %zu\n", kbd_dev->output_size);
+	
+	kbd_dev->led_path = usb_hid_report_path();
+	usb_hid_report_path_append_item(
+	    kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0);
+	
+	kbd_dev->led_output_size = usb_hid_report_output_size(kbd_dev->parser, 
+	    kbd_dev->led_path, USB_HID_PATH_COMPARE_END);
+	
+	usb_log_debug("Output report size (in items): %zu\n", 
+	    kbd_dev->led_output_size);
+	
+	kbd_dev->led_data = (int32_t *)calloc(
+	    kbd_dev->led_output_size, sizeof(int32_t));
+	
+	if (kbd_dev->led_data == NULL) {
+		usb_log_warning("Error creating buffer for LED output report."
+		    "\n");
+		free(kbd_dev->keys);
+		usb_hid_report_output_free(kbd_dev->output_buffer);
+		return ENOMEM;
+	}
+	
+	/*
+	 * Modifiers and locks
+	 */	
 	kbd_dev->modifiers = 0;
 	kbd_dev->mods = DEFAULT_ACTIVE_MODS;
 	kbd_dev->lock_keys = 0;
 	
+	/*
+	 * Autorepeat
+	 */	
 	kbd_dev->repeat.key_new = 0;
 	kbd_dev->repeat.key_repeated = 0;
@@ -879,4 +940,7 @@
 	}
 	
+	// free the output buffer
+	usb_hid_report_output_free((*kbd_dev)->output_buffer);
+	
 	/* TODO: what about the USB device structure?? */
 
