Index: uspace/drv/usbhid/kbd/conv.c
===================================================================
--- uspace/drv/usbhid/kbd/conv.c	(revision 564a2b33fa6a9365cde0a9228b5722048647e566)
+++ uspace/drv/usbhid/kbd/conv.c	(revision 308a5d52410eedc0ee1ce72952d26a931def9c82)
@@ -99,5 +99,6 @@
 	[0x30] = KC_RBRACKET,
 	[0x31] = KC_BACKSLASH,
-	//[0x32] = KC_,	// TODO: HASH??? maybe some as 0x31 - backslash
+	//[0x32] = KC_,	// TODO: HASH??? maybe same as 0x31 - backslash
+	[0x32] = KC_BACKSLASH,
 	[0x33] = KC_SEMICOLON,
 	[0x34] = KC_QUOTE,  // same as APOSTROPHE? (')
Index: uspace/drv/usbhid/kbd/kbddev.c
===================================================================
--- uspace/drv/usbhid/kbd/kbddev.c	(revision 564a2b33fa6a9365cde0a9228b5722048647e566)
+++ uspace/drv/usbhid/kbd/kbddev.c	(revision 308a5d52410eedc0ee1ce72952d26a931def9c82)
@@ -177,10 +177,10 @@
 /*----------------------------------------------------------------------------*/
 
-static void usb_kbd_process_keycodes(const uint8_t *key_codes, size_t count,
-    uint8_t report_id, void *arg);
-
-static const usb_hid_report_in_callbacks_t usb_kbd_parser_callbacks = {
-	.keyboard = usb_kbd_process_keycodes
-};
+//static void usb_kbd_process_keycodes(const uint8_t *key_codes, size_t count,
+//    uint8_t report_id, void *arg);
+
+//static const usb_hid_report_in_callbacks_t usb_kbd_parser_callbacks = {
+//	.keyboard = usb_kbd_process_keycodes
+//};
 
 /*----------------------------------------------------------------------------*/
@@ -299,32 +299,39 @@
 		return;
 	}
-	
-	unsigned i = 0;
-	
+		
 	/* Reset the LED data. */
 	memset(kbd_dev->led_data, 0, kbd_dev->led_output_size * sizeof(int32_t));
-	
-	if ((kbd_dev->mods & KM_NUM_LOCK) && (i < kbd_dev->led_output_size)) {
-		kbd_dev->led_data[i++] = 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;
-	}
-	
-	if ((kbd_dev->mods & KM_SCROLL_LOCK) 
-	    && (i < kbd_dev->led_output_size)) {
-		kbd_dev->led_data[i++] = USB_HID_LED_SCROLL_LOCK;
-	}
-
-	// TODO: COMPOSE and KANA
-	
-	usb_log_debug("Creating output report.\n");
-	
-	int rc = usb_hid_report_output_translate(hid_dev->parser, 
-	    kbd_dev->led_path, 
-	    USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 
-	    kbd_dev->output_buffer, 
-	    kbd_dev->output_size, kbd_dev->led_data, kbd_dev->led_output_size);
+	usb_log_debug("Creating output report:\n");
+
+	usb_hid_report_field_t *field = usb_hid_report_get_sibling(
+	    hid_dev->report, NULL, kbd_dev->led_path, 
+	    USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY | USB_HID_PATH_COMPARE_END,
+	    USB_HID_REPORT_TYPE_OUTPUT);
+	
+	while (field != NULL) {
+
+		if ((field->usage == USB_HID_LED_NUM_LOCK) 
+		    && (kbd_dev->mods & KM_NUM_LOCK)){
+			field->value = 1;
+		}
+
+		if ((field->usage == USB_HID_LED_CAPS_LOCK) 
+		    && (kbd_dev->mods & KM_CAPS_LOCK)){
+			field->value = 1;
+		}
+
+		if ((field->usage == USB_HID_LED_SCROLL_LOCK) 
+		    && (kbd_dev->mods & KM_SCROLL_LOCK)){
+			field->value = 1;
+		}
+		
+		field = usb_hid_report_get_sibling(hid_dev->report, field,
+		    kbd_dev->led_path, USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY 
+		    | USB_HID_PATH_COMPARE_END, USB_HID_REPORT_TYPE_OUTPUT);
+	}
+	
+	// TODO: what about the Report ID?
+	int rc = usb_hid_report_output_translate(hid_dev->report, 0,
+	    kbd_dev->output_buffer, kbd_dev->output_size);
 	
 	if (rc != EOK) {
@@ -485,5 +492,5 @@
  */
 static void usb_kbd_check_key_changes(usb_hid_dev_t *hid_dev, 
-    usb_kbd_t *kbd_dev, const uint8_t *key_codes, size_t count)
+    usb_kbd_t *kbd_dev/*, const uint8_t *key_codes, size_t count*/)
 {
 	unsigned int key;
@@ -499,30 +506,27 @@
 	 */
 	i = 0;
-	while (i < count && key_codes[i] != ERROR_ROLLOVER) {
+	while (i < kbd_dev->key_count && kbd_dev->keys[i] != ERROR_ROLLOVER) {
 		++i;
 	}
-	if (i != count) {
+	if (i != kbd_dev->key_count) {
 		usb_log_debug("Phantom state occured.\n");
 		// phantom state, do nothing
 		return;
 	}
-	
-	/* TODO: quite dummy right now, think of better implementation */
-	assert(count == kbd_dev->key_count);
 	
 	/*
 	 * 1) Key releases
 	 */
-	for (j = 0; j < count; ++j) {
+	for (j = 0; j < kbd_dev->key_count; ++j) {
 		// try to find the old key in the new key list
 		i = 0;
 		while (i < kbd_dev->key_count
-		    && key_codes[i] != kbd_dev->keys[j]) {
+		    && kbd_dev->keys[i] != kbd_dev->keys_old[j]) {
 			++i;
 		}
 		
-		if (i == count) {
+		if (i == kbd_dev->key_count) {
 			// not found, i.e. the key was released
-			key = usbhid_parse_scancode(kbd_dev->keys[j]);
+			key = usbhid_parse_scancode(kbd_dev->keys_old[j]);
 			if (!usb_kbd_is_lock(key)) {
 				usb_kbd_repeat_stop(kbd_dev, key);
@@ -541,15 +545,15 @@
 		// try to find the new key in the old key list
 		j = 0;
-		while (j < count && kbd_dev->keys[j] != key_codes[i]) { 
+		while (j < kbd_dev->key_count 
+		    && kbd_dev->keys_old[j] != kbd_dev->keys[i]) { 
 			++j;
 		}
 		
-		if (j == count) {
+		if (j == kbd_dev->key_count) {
 			// not found, i.e. new key pressed
-			key = usbhid_parse_scancode(key_codes[i]);
+			key = usbhid_parse_scancode(kbd_dev->keys[i]);
 			usb_log_debug2("Key pressed: %d (keycode: %d)\n", key,
-			    key_codes[i]);
-			usb_kbd_push_ev(hid_dev, kbd_dev, KEY_PRESS, 
-			    key);
+			    kbd_dev->keys[i]);
+			usb_kbd_push_ev(hid_dev, kbd_dev, KEY_PRESS, key);
 			if (!usb_kbd_is_lock(key)) {
 				usb_kbd_repeat_start(kbd_dev, key);
@@ -560,8 +564,24 @@
 	}
 	
-	memcpy(kbd_dev->keys, key_codes, count);
-
-	usb_log_debug("New stored keycodes: %s\n", 
-	    usb_debug_str_buffer(kbd_dev->keys, kbd_dev->key_count, 0));
+//	usb_log_debug("Old keys: ");
+//	for (i = 0; i < kbd_dev->key_count; ++i) {
+//		usb_log_debug("%d ", kbd_dev->keys_old[i]);
+//	}
+//	usb_log_debug("\n");
+	
+	
+//	usb_log_debug("New keys: ");
+//	for (i = 0; i < kbd_dev->key_count; ++i) {
+//		usb_log_debug("%d ", kbd_dev->keys[i]);
+//	}
+//	usb_log_debug("\n");
+	
+	memcpy(kbd_dev->keys_old, kbd_dev->keys, kbd_dev->key_count * 4);
+	
+	usb_log_debug2("New stored keys: ");
+	for (i = 0; i < kbd_dev->key_count; ++i) {
+		usb_log_debug2("%d ", kbd_dev->keys_old[i]);
+	}
+	usb_log_debug2("\n");
 }
 
@@ -585,34 +605,34 @@
  * @sa usb_kbd_check_key_changes(), usb_kbd_check_modifier_changes()
  */
-static void usb_kbd_process_keycodes(const uint8_t *key_codes, size_t count,
-    uint8_t report_id, void *arg)
-{
-	if (arg == NULL) {
-		usb_log_warning("Missing argument in callback "
-		    "usbhid_process_keycodes().\n");
-		return;
-	}
-	
-	usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg;
-	
-	if (hid_dev->data == NULL) {
-		usb_log_warning("Missing KBD device structure in callback.\n");
-		return;
-	}
-	
-	usb_kbd_t *kbd_dev = (usb_kbd_t *)hid_dev->data;
-
-	usb_log_debug("Got keys from parser (report id: %u): %s\n", 
-	    report_id, usb_debug_str_buffer(key_codes, count, 0));
-	
-	if (count != kbd_dev->key_count) {
-		usb_log_warning("Number of received keycodes (%zu) differs from"
-		    " expected (%zu).\n", count, kbd_dev->key_count);
-		return;
-	}
-	
-	///usb_kbd_check_modifier_changes(kbd_dev, key_codes, count);
-	usb_kbd_check_key_changes(hid_dev, kbd_dev, key_codes, count);
-}
+//static void usb_kbd_process_keycodes(const uint8_t *key_codes, size_t count,
+//    uint8_t report_id, void *arg)
+//{
+//	if (arg == NULL) {
+//		usb_log_warning("Missing argument in callback "
+//		    "usbhid_process_keycodes().\n");
+//		return;
+//	}
+	
+//	usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg;
+	
+//	if (hid_dev->data == NULL) {
+//		usb_log_warning("Missing KBD device structure in callback.\n");
+//		return;
+//	}
+	
+//	usb_kbd_t *kbd_dev = (usb_kbd_t *)hid_dev->data;
+
+//	usb_log_debug("Got keys from parser (report id: %u): %s\n", 
+//	    report_id, usb_debug_str_buffer(key_codes, count, 0));
+	
+//	if (count != kbd_dev->key_count) {
+//		usb_log_warning("Number of received keycodes (%zu) differs from"
+//		    " expected (%zu).\n", count, kbd_dev->key_count);
+//		return;
+//	}
+	
+//	///usb_kbd_check_modifier_changes(kbd_dev, key_codes, count);
+//	usb_kbd_check_key_changes(hid_dev, kbd_dev, key_codes, count);
+//}
 
 /*----------------------------------------------------------------------------*/
@@ -638,5 +658,9 @@
                                  uint8_t *buffer, size_t actual_size)
 {
-	assert(hid_dev->parser != NULL);
+	assert(hid_dev->report != NULL);
+	assert(hid_dev != NULL);
+	assert(hid_dev->data != NULL);
+	
+	usb_kbd_t *kbd_dev = (usb_kbd_t *)hid_dev->data;
 
 	usb_log_debug("Calling usb_hid_parse_report() with "
@@ -648,16 +672,59 @@
 	usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0);
 	//usb_hid_report_path_set_report_id(path, 0);
-	
-	int rc = usb_hid_parse_report(hid_dev->parser, buffer,
-	    actual_size, path, 
+
+	uint8_t report_id;
+	int rc = usb_hid_parse_report(hid_dev->report, buffer, actual_size, 
+	    &report_id);
+	
+	if (rc != EOK) {
+		usb_log_warning("Error in usb_hid_parse_report():"
+		    "%s\n", str_error(rc));
+	}
+	
+	usb_hid_report_path_set_report_id (path, report_id);
+	
+	// fill in the currently pressed keys
+	
+	usb_hid_report_field_t *field = usb_hid_report_get_sibling(
+	    hid_dev->report, NULL, path, 
 	    USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 
-	    &usb_kbd_parser_callbacks, hid_dev);
-
+	    USB_HID_REPORT_TYPE_INPUT);
+	unsigned i = 0;
+	
+	while (field != NULL) {
+		usb_log_debug2("FIELD (%p) - VALUE(%d) USAGE(%u)\n", 
+		    field, field->value, field->usage);
+		
+		assert(i < kbd_dev->key_count);
+//		if (i == kbd_dev->key_count) {
+//			break;
+//		}
+		
+		// save the key usage
+		/* TODO: maybe it's not good to save value, nor usage
+		 *       as the value may be e.g. 1 for LEDs and usage may be
+		 *       value of the LED. On the other hand, in case of normal
+		 *       keys, the usage is more important and we must check
+		 *       that. One possible solution: distinguish between those
+		 *       two parts of the Report somehow.
+		 */
+		if( field->value != 0 ) {
+			kbd_dev->keys[i] = field->usage;
+		}
+		else {
+			kbd_dev->keys[i] = 0;
+		}
+		usb_log_debug2("Saved %u. key usage %d\n", i, kbd_dev->keys[i]);
+		
+		++i;
+		field = usb_hid_report_get_sibling(hid_dev->report, field, path, 
+		    USB_HID_PATH_COMPARE_END 
+		    | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 
+		    USB_HID_REPORT_TYPE_INPUT);
+	}
+	
 	usb_hid_report_path_free(path);
 	
-	if (rc != EOK) {
-		usb_log_warning("Error in usb_hid_boot_keyboard_input_report():"
-		    "%s\n", str_error(rc));
-	}
+	usb_kbd_check_key_changes(hid_dev, kbd_dev);
 }
 
@@ -747,5 +814,5 @@
 	
 	kbd_dev->key_count = usb_hid_report_input_length(
-	    hid_dev->parser, path, 
+	    hid_dev->report, path, 
 	    USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY);
 	usb_hid_report_path_free(path);
@@ -753,5 +820,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 = (int32_t *)calloc(kbd_dev->key_count, sizeof(int32_t));
 	
 	if (kbd_dev->keys == NULL) {
@@ -761,15 +828,24 @@
 	}
 	
+	kbd_dev->keys_old = 
+		(int32_t *)calloc(kbd_dev->key_count, sizeof(int32_t));
+	
+	if (kbd_dev->keys_old == NULL) {
+		usb_log_fatal("No memory!\n");
+		free(kbd_dev->keys);
+		free(kbd_dev);
+		return ENOMEM;
+	}
+	
 	/*
 	 * Output report
 	 */
 	kbd_dev->output_size = 0;
-	kbd_dev->output_buffer = usb_hid_report_output(hid_dev->parser, 
-	    &kbd_dev->output_size);
-	if (kbd_dev->output_buffer == NULL && kbd_dev->output_size != 0) {
+	kbd_dev->output_buffer = usb_hid_report_output(hid_dev->report, 
+	    &kbd_dev->output_size, 0);
+	if (kbd_dev->output_buffer == NULL) {
 		usb_log_warning("Error creating output report buffer.\n");
 		free(kbd_dev->keys);
-		free(kbd_dev);
-		return ENOMEM;
+		return ENOMEM;  /* TODO: other error code */
 	}
 	
@@ -780,5 +856,5 @@
 	    kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0);
 	
-	kbd_dev->led_output_size = usb_hid_report_output_size(hid_dev->parser, 
+	kbd_dev->led_output_size = usb_hid_report_output_size(hid_dev->report, 
 	    kbd_dev->led_path, 
 	    USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY);
@@ -937,5 +1013,5 @@
 int usb_kbd_set_boot_protocol(usb_hid_dev_t *hid_dev)
 {
-	int rc = usb_hid_parse_report_descriptor(hid_dev->parser, 
+	int rc = usb_hid_parse_report_descriptor(hid_dev->report, 
 	    USB_KBD_BOOT_REPORT_DESCRIPTOR, 
 	    USB_KBD_BOOT_REPORT_DESCRIPTOR_SIZE);
Index: uspace/drv/usbhid/kbd/kbddev.h
===================================================================
--- uspace/drv/usbhid/kbd/kbddev.h	(revision 564a2b33fa6a9365cde0a9228b5722048647e566)
+++ uspace/drv/usbhid/kbd/kbddev.h	(revision 308a5d52410eedc0ee1ce72952d26a931def9c82)
@@ -65,6 +65,8 @@
  */
 typedef struct usb_kbd_t {
+	/** Previously pressed keys (not translated to key codes). */
+	int32_t *keys_old;
 	/** Currently pressed keys (not translated to key codes). */
-	uint8_t *keys;
+	int32_t *keys;
 	/** Count of stored keys (i.e. number of keys in the report). */
 	size_t key_count;
Index: uspace/drv/usbhid/lgtch-ultrax/lgtch-ultrax.c
===================================================================
--- uspace/drv/usbhid/lgtch-ultrax/lgtch-ultrax.c	(revision 564a2b33fa6a9365cde0a9228b5722048647e566)
+++ uspace/drv/usbhid/lgtch-ultrax/lgtch-ultrax.c	(revision 308a5d52410eedc0ee1ce72952d26a931def9c82)
@@ -81,15 +81,25 @@
 	usb_hid_report_path_t *path = usb_hid_report_path();
 	usb_hid_report_path_append_item(path, 0xc, 0);
-	usb_hid_report_path_set_report_id(path, 1);
+
+	uint8_t report_id;
 	
-	int rc = usb_hid_parse_report(hid_dev->parser, buffer,
-	    buffer_size, path, 
-	    USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 
-	    &usb_lgtch_parser_callbacks, hid_dev);
+	int rc = usb_hid_parse_report(hid_dev->report, buffer, buffer_size, 
+	    &report_id);
+	usb_hid_report_path_set_report_id(path, report_id);
+
+	usb_hid_report_field_t *field = usb_hid_report_get_sibling(
+	    hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END , 
+	    USB_HID_REPORT_TYPE_INPUT);
+	
+	while (field != NULL) {
+		usb_log_debug(NAME " KEY VALUE(%X) USAGE(%X)\n", field->value, 
+		    field->usage);
+	}
+	
 
 	usb_hid_report_path_free(path);
 	
 	if (rc != EOK) {
-		usb_log_warning("Error in usb_hid_boot_keyboard_input_report():"
+		usb_log_warning(NAME "Error in usb_hid_boot_keyboard_input_report():"
 		    "%s\n", str_error(rc));
 	}
Index: uspace/drv/usbhid/mouse/mousedev.c
===================================================================
--- uspace/drv/usbhid/mouse/mousedev.c	(revision 564a2b33fa6a9365cde0a9228b5722048647e566)
+++ uspace/drv/usbhid/mouse/mousedev.c	(revision 308a5d52410eedc0ee1ce72952d26a931def9c82)
@@ -296,5 +296,5 @@
 int usb_mouse_set_boot_protocol(usb_hid_dev_t *hid_dev)
 {
-	int rc = usb_hid_parse_report_descriptor(hid_dev->parser, 
+	int rc = usb_hid_parse_report_descriptor(hid_dev->report, 
 	    USB_MOUSE_BOOT_REPORT_DESCRIPTOR, 
 	    USB_MOUSE_BOOT_REPORT_DESCRIPTOR_SIZE);
Index: uspace/drv/usbhid/subdrivers.c
===================================================================
--- uspace/drv/usbhid/subdrivers.c	(revision 564a2b33fa6a9365cde0a9228b5722048647e566)
+++ uspace/drv/usbhid/subdrivers.c	(revision 308a5d52410eedc0ee1ce72952d26a931def9c82)
@@ -55,6 +55,6 @@
 		USB_HID_PATH_COMPARE_END 
 		| USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
-		0,
-		0,
+		-1,
+		-1,
 		{
 			.init = usb_kbd_init,
@@ -79,5 +79,5 @@
 		}
 	},
-	{NULL, -1, 0, 0, 0, {NULL, NULL, NULL, NULL}}
+	{NULL, -1, 0, -1, -1, {NULL, NULL, NULL, NULL}}
 };
 
Index: uspace/drv/usbhid/subdrivers.h
===================================================================
--- uspace/drv/usbhid/subdrivers.h	(revision 564a2b33fa6a9365cde0a9228b5722048647e566)
+++ uspace/drv/usbhid/subdrivers.h	(revision 308a5d52410eedc0ee1ce72952d26a931def9c82)
@@ -56,6 +56,6 @@
 	int report_id;
 	int compare;
-	uint16_t vendor_id;
-	uint16_t product_id;
+	int vendor_id;
+	int product_id;
 	usb_hid_subdriver_t subdriver;
 } usb_hid_subdriver_mapping_t;
Index: uspace/drv/usbhid/usbhid.c
===================================================================
--- uspace/drv/usbhid/usbhid.c	(revision 564a2b33fa6a9365cde0a9228b5722048647e566)
+++ uspace/drv/usbhid/usbhid.c	(revision 308a5d52410eedc0ee1ce72952d26a931def9c82)
@@ -158,5 +158,11 @@
     const usb_hid_subdriver_mapping_t *mapping)
 {
-	return false;
+	assert(hid_dev != NULL);
+	assert(hid_dev->usb_dev != NULL);
+	
+	return (hid_dev->usb_dev->descriptors.device.vendor_id 
+	    == mapping->vendor_id
+	    && hid_dev->usb_dev->descriptors.device.product_id 
+	    == mapping->product_id);
 }
 
@@ -192,8 +198,8 @@
 	}
 	
-	assert(hid_dev->parser != NULL);
+	assert(hid_dev->report != NULL);
 	
 	usb_log_debug("Compare flags: %d\n", mapping->compare);
-	size_t size = usb_hid_report_input_length(hid_dev->parser, usage_path, 
+	size_t size = usb_hid_report_input_length(hid_dev->report, usage_path, 
 	    mapping->compare);
 	usb_log_debug("Size of the input report: %zuB\n", size);
@@ -251,13 +257,13 @@
 	while (count < USB_HID_MAX_SUBDRIVERS &&
 	    (mapping->usage_path != NULL
-	    || mapping->vendor_id != 0 || mapping->product_id != 0)) {
+	    || mapping->vendor_id >= 0 || mapping->product_id >= 0)) {
 		// check the vendor & product ID
-		if (mapping->vendor_id != 0 && mapping->product_id == 0) {
-			usb_log_warning("Missing Product ID for Vendor ID %u\n",
+		if (mapping->vendor_id >= 0 && mapping->product_id < 0) {
+			usb_log_warning("Missing Product ID for Vendor ID %d\n",
 			    mapping->vendor_id);
 			return EINVAL;
 		}
-		if (mapping->product_id != 0 && mapping->vendor_id == 0) {
-			usb_log_warning("Missing Vendor ID for Product ID %u\n",
+		if (mapping->product_id >= 0 && mapping->vendor_id < 0) {
+			usb_log_warning("Missing Vendor ID for Product ID %d\n",
 			    mapping->product_id);
 			return EINVAL;
@@ -267,6 +273,6 @@
 		matched = false;
 		
-		if (mapping->vendor_id != 0) {
-			assert(mapping->product_id != 0);
+		if (mapping->vendor_id >= 0) {
+			assert(mapping->product_id >= 0);
 			usb_log_debug("Comparing device against vendor ID %u"
 			    " and product ID %u.\n", mapping->vendor_id,
@@ -341,7 +347,7 @@
 	}
 	
-	hid_dev->parser = (usb_hid_report_parser_t *)(malloc(sizeof(
-	    usb_hid_report_parser_t)));
-	if (hid_dev->parser == NULL) {
+	hid_dev->report = (usb_hid_report_t *)(malloc(sizeof(
+	    usb_hid_report_t)));
+	if (hid_dev->report == NULL) {
 		usb_log_fatal("No memory!\n");
 		free(hid_dev);
@@ -382,16 +388,8 @@
 		return rc;
 	}
-	
-	/* Initialize the report parser. */
-	rc = usb_hid_parser_init(hid_dev->parser);
-	if (rc != EOK) {
-		usb_log_error("Failed to initialize report parser.\n");
-		//usb_hid_free(&hid_dev);
-		return rc;
-	}
-	
+		
 	/* Get the report descriptor and parse it. */
 	rc = usb_hid_process_report_descriptor(hid_dev->usb_dev, 
-	    hid_dev->parser);
+	    hid_dev->report);
 	
 	bool fallback = false;
@@ -591,6 +589,6 @@
 
 	// destroy the parser
-	if ((*hid_dev)->parser != NULL) {
-		usb_hid_free_report_parser((*hid_dev)->parser);
+	if ((*hid_dev)->report != NULL) {
+		usb_hid_free_report((*hid_dev)->report);
 	}
 
Index: uspace/drv/usbhid/usbhid.h
===================================================================
--- uspace/drv/usbhid/usbhid.h	(revision 564a2b33fa6a9365cde0a9228b5722048647e566)
+++ uspace/drv/usbhid/usbhid.h	(revision 308a5d52410eedc0ee1ce72952d26a931def9c82)
@@ -91,5 +91,5 @@
 	
 	/** HID Report parser. */
-	usb_hid_report_parser_t *parser;
+	usb_hid_report_t *report;
 	
 	/** Arbitrary data (e.g. a special structure for handling keyboard). */
Index: uspace/drv/usbkbd/kbddev.c
===================================================================
--- uspace/drv/usbkbd/kbddev.c	(revision 564a2b33fa6a9365cde0a9228b5722048647e566)
+++ uspace/drv/usbkbd/kbddev.c	(revision 308a5d52410eedc0ee1ce72952d26a931def9c82)
@@ -128,7 +128,10 @@
         0x15, 0x00,  //   Logical Minimum (0),
         0x25, 0x01,  //   Logical Maximum (1),
+	//0x85, 0x00,  //   Report ID,
+	//0xA4,	     //   Push
         0x81, 0x02,  //   Input (Data, Variable, Absolute),   ; Modifier byte
-	0x95, 0x01,  //   Report Count (1),
-        0x75, 0x08,  //   Report Size (8),
+	//0xB4,	     //   Pop
+        0x75, 0x08,  //   Report Size (1),
+        0x95, 0x01,  //   Report Count (8),       
         0x81, 0x01,  //   Input (Constant),                   ; Reserved byte
         0x95, 0x05,  //   Report Count (5),
@@ -268,5 +271,5 @@
 		return;
 	}
-	
+
 	unsigned i = 0;
 	
@@ -290,10 +293,10 @@
 	
 	usb_log_debug("Creating output report.\n");
-	
-	int rc = usb_hid_report_output_translate(kbd_dev->parser, 
-	    kbd_dev->led_path, 
-	    USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 
-	    kbd_dev->output_buffer, 
-	    kbd_dev->output_size, kbd_dev->led_data, kbd_dev->led_output_size);
+
+	usb_hid_report_output_set_data(kbd_dev->parser, kbd_dev->led_path, 
+	                               USB_HID_PATH_COMPARE_END , kbd_dev->led_data, 
+	                               kbd_dev->led_output_size);
+	int rc = usb_hid_report_output_translate(kbd_dev->parser, 0,
+	    kbd_dev->output_buffer, kbd_dev->output_size);
 	
 	if (rc != EOK) {
@@ -563,6 +566,6 @@
 	assert(kbd_dev != NULL);
 
-	usb_log_debug("Got keys from parser (report id: %u): %s\n", 
-	    report_id, usb_debug_str_buffer(key_codes, count, 0));
+	usb_log_debug("Got keys from parser (report id: %d): %s\n", report_id, 
+	    usb_debug_str_buffer(key_codes, count, 0));
 	
 	if (count != kbd_dev->key_count) {
@@ -614,10 +617,8 @@
 	usb_hid_report_path_t *path = usb_hid_report_path();
 	usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0);
-	usb_hid_report_path_set_report_id(path, 0);
-	
-	int rc = usb_hid_parse_report(kbd_dev->parser, buffer,
-	    actual_size, path, 
-	    USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 
-	    callbacks, kbd_dev);
+
+	uint8_t report_id;
+	int rc = usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, &report_id);
+	usb_hid_descriptor_print (kbd_dev->parser);
 
 	usb_hid_report_path_free (path);
@@ -663,6 +664,6 @@
 	memset(kbd_dev, 0, sizeof(usb_kbd_t));
 	
-	kbd_dev->parser = (usb_hid_report_parser_t *)(malloc(sizeof(
-	    usb_hid_report_parser_t)));
+	kbd_dev->parser = (usb_hid_report_t *)(malloc(sizeof(
+	    usb_hid_report_t)));
 	if (kbd_dev->parser == NULL) {
 		usb_log_fatal("No memory!\n");
@@ -732,9 +733,9 @@
 	
 	/* Initialize the report parser. */
-	rc = usb_hid_parser_init(kbd_dev->parser);
-	if (rc != EOK) {
-		usb_log_error("Failed to initialize report parser.\n");
-		return rc;
-	}
+	//rc = usb_hid_parser_init(kbd_dev->parser);
+	//if (rc != EOK) {
+	//	usb_log_error("Failed to initialize report parser.\n");
+	//	return rc;
+	//}
 	
 	/* Get the report descriptor and parse it. */
@@ -771,6 +772,5 @@
 	
 	kbd_dev->key_count = usb_hid_report_input_length(
-	    kbd_dev->parser, path, 
-	    USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY);
+	    kbd_dev->parser, path, USB_HID_PATH_COMPARE_END);
 	usb_hid_report_path_free (path);
 	
@@ -789,6 +789,6 @@
 	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 && kbd_dev->output_size != 0) {
+	    &kbd_dev->output_size, 0x00);
+	if (kbd_dev->output_buffer == NULL) {
 		usb_log_warning("Error creating output report buffer.\n");
 		free(kbd_dev->keys);
@@ -801,4 +801,5 @@
 	usb_hid_report_path_append_item(
 	    kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0);
+	usb_hid_report_path_set_report_id(kbd_dev->led_path, 0x00);
 	
 	kbd_dev->led_output_size = usb_hid_report_output_size(kbd_dev->parser, 
@@ -849,5 +850,5 @@
 	 * Set Idle rate
 	 */
-	usb_kbd_set_led(kbd_dev);
+	usb_kbd_set_led(kbd_dev);	
 	
 	usbhid_req_set_idle(&kbd_dev->usb_dev->ctrl_pipe, 
@@ -934,5 +935,5 @@
 	// destroy the parser
 	if ((*kbd_dev)->parser != NULL) {
-		usb_hid_free_report_parser((*kbd_dev)->parser);
+		usb_hid_free_report((*kbd_dev)->parser);
 	}
 	
Index: uspace/drv/usbkbd/kbddev.h
===================================================================
--- uspace/drv/usbkbd/kbddev.h	(revision 564a2b33fa6a9365cde0a9228b5722048647e566)
+++ uspace/drv/usbkbd/kbddev.h	(revision 308a5d52410eedc0ee1ce72952d26a931def9c82)
@@ -106,5 +106,5 @@
 
 	/** HID Report parser. */
-	usb_hid_report_parser_t *parser;
+	usb_hid_report_t *parser;
 	
 	/** State of the structure (for checking before use). 
Index: uspace/lib/usb/include/usb/classes/hid.h
===================================================================
--- uspace/lib/usb/include/usb/classes/hid.h	(revision 564a2b33fa6a9365cde0a9228b5722048647e566)
+++ uspace/lib/usb/include/usb/classes/hid.h	(revision 308a5d52410eedc0ee1ce72952d26a931def9c82)
@@ -50,10 +50,4 @@
 	USB_HIDREQ_SET_PROTOCOL = 11
 } 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 {
Index: uspace/lib/usb/include/usb/classes/hidparser.h
===================================================================
--- uspace/lib/usb/include/usb/classes/hidparser.h	(revision 564a2b33fa6a9365cde0a9228b5722048647e566)
+++ uspace/lib/usb/include/usb/classes/hidparser.h	(revision 308a5d52410eedc0ee1ce72952d26a931def9c82)
@@ -73,11 +73,23 @@
 #define USB_HID_PATH_COMPARE_END				1
 #define USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY	4
-
-/** */
-typedef struct {
-	/** */
-	int32_t usage_page;
-	/** */	
-	int32_t usage;
+#define USB_HID_PATH_COMPARE_COLLECTION_ONLY	2 /* porovnava jenom cestu z Kolekci */
+
+
+#define USB_HID_MAX_USAGES	20
+
+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;
+
+/** Collection usage path structure */
+typedef struct {
+	/** */
+	uint32_t usage_page;
+	/** */	
+	uint32_t usage;
+
+	uint8_t flags;
 	/** */
 	link_t link;
@@ -91,18 +103,83 @@
 	
 	/** */	
+	link_t link; /* list */
+
+	link_t head; /* head of list of usage paths */
+
+} usb_hid_report_path_t;
+
+
+typedef struct {
+	/** */
+	int report_count;
+	link_t reports;		/** list of usb_hid_report_description_t */
+
+	link_t collection_paths;
+	int collection_paths_count;
+
+	int use_report_ids;
+	uint8_t last_report_id;
+	
+} usb_hid_report_t;
+
+typedef struct {
+	uint8_t report_id;
+	usb_hid_report_type_t type;
+
+	size_t bit_length;
+	size_t item_length;
+	
+	link_t report_items;	/** list of report items (fields) */
+
 	link_t link;
-
-} usb_hid_report_path_t;
-
-/**
- * Description of report items
- */
-typedef struct {
-	/** */	
+} usb_hid_report_description_t;
+
+typedef struct {
+
+	int offset;
+	size_t size;
+
+	uint16_t usage_page;
+	uint16_t usage;
+
+	uint8_t item_flags;
+	usb_hid_report_path_t *collection_path;
+
+	int32_t logical_minimum;
+	int32_t logical_maximum;
+	int32_t physical_minimum;
+	int32_t physical_maximum;
+	uint32_t usage_minimum;
+	uint32_t usage_maximum;
+	uint32_t unit;
+	uint32_t unit_exponent;
+	
+
+	int32_t value;
+
+	link_t link;
+} usb_hid_report_field_t;
+
+
+
+/**
+ * state table
+ */
+typedef struct {
+	/** report id */	
 	int32_t id;
-	/** */	
-	int32_t usage_minimum;
-	/** */	
-	int32_t usage_maximum;
+	
+	/** */
+	uint16_t extended_usage_page;
+	uint32_t usages[USB_HID_MAX_USAGES];
+	int usages_count;
+
+	/** */
+	uint32_t usage_page;
+
+	/** */	
+	uint32_t usage_minimum;
+	/** */	
+	uint32_t usage_maximum;
 	/** */	
 	int32_t logical_minimum;
@@ -116,6 +193,4 @@
 	size_t offset;
 	/** */	
-	int32_t delimiter;
-	/** */	
 	int32_t unit_exponent;
 	/** */	
@@ -123,15 +198,15 @@
 
 	/** */
-	int32_t string_index;
-	/** */	
-	int32_t string_minimum;
-	/** */	
-	int32_t string_maximum;
-	/** */	
-	int32_t designator_index;
-	/** */	
-	int32_t designator_minimum;
-	/** */	
-	int32_t designator_maximum;
+	uint32_t string_index;
+	/** */	
+	uint32_t string_minimum;
+	/** */	
+	uint32_t string_maximum;
+	/** */	
+	uint32_t designator_index;
+	/** */	
+	uint32_t designator_minimum;
+	/** */	
+	uint32_t designator_maximum;
 	/** */	
 	int32_t physical_minimum;
@@ -142,26 +217,11 @@
 	uint8_t item_flags;
 
-	/** */	
+	usb_hid_report_type_t type;
+
+	/** current collection path*/	
 	usb_hid_report_path_t *usage_path;
 	/** */	
 	link_t link;
 } usb_hid_report_item_t;
-
-
-/** HID report parser structure. */
-typedef struct {	
-	/** */	
-	link_t input;
-	/** */	
-	link_t output;
-	/** */	
-	link_t feature;
-	
-	int use_report_id;
-
-	/** */
- 	link_t stack;
-} usb_hid_report_parser_t;	
-
 
 /** HID parser callbacks for IN items. */
@@ -189,13 +249,4 @@
 } 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] = {
@@ -210,43 +261,17 @@
 };
 
-//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
-
 /*
  * Descriptor parser functions
  */
-/** */
-int usb_hid_parser_init(usb_hid_report_parser_t *parser);
-
-/** */
-int usb_hid_parse_report_descriptor(usb_hid_report_parser_t *parser, 
+
+/** */
+int usb_hid_parse_report_descriptor(usb_hid_report_t *report, 
     const uint8_t *data, size_t size);
 
 /** */
-void usb_hid_free_report_parser(usb_hid_report_parser_t *parser);
-
-/** */
-void usb_hid_descriptor_print(usb_hid_report_parser_t *parser);
-
-/*
- * Boot protocol functions
- */
-/** */
-int usb_hid_boot_keyboard_input_report(const uint8_t *data, size_t size,
-	const usb_hid_report_in_callbacks_t *callbacks, void *arg);
-
-/** */
-int usb_hid_boot_keyboard_output_report(uint8_t leds, uint8_t *data, size_t size);
+void usb_hid_free_report(usb_hid_report_t *report);
+
+/** */
+void usb_hid_descriptor_print(usb_hid_report_t *report);
 
 
@@ -255,11 +280,8 @@
  */
 /** */
-int usb_hid_parse_report(const usb_hid_report_parser_t *parser,  
-    const uint8_t *data, size_t size,
-    usb_hid_report_path_t *path, int flags,
-    const usb_hid_report_in_callbacks_t *callbacks, void *arg);
-
-/** */
-size_t usb_hid_report_input_length(const usb_hid_report_parser_t *parser,
+int usb_hid_parse_report(const usb_hid_report_t *report, const uint8_t *data, size_t size, uint8_t *report_id);
+
+/** */
+size_t usb_hid_report_input_length(const usb_hid_report_t *report,
 	usb_hid_report_path_t *path, int flags);
 
@@ -296,4 +318,8 @@
 usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path);
 
+usb_hid_report_field_t *usb_hid_report_get_sibling(usb_hid_report_t *report, usb_hid_report_field_t *field, usb_hid_report_path_t *path, int flags, usb_hid_report_type_t type);
+
+uint8_t usb_hid_report_get_report_id(usb_hid_report_t *report, uint8_t report_id, usb_hid_report_type_t type);
+
 
 /*
@@ -301,5 +327,5 @@
  */
 /** Allocates output report buffer*/
-uint8_t *usb_hid_report_output(usb_hid_report_parser_t *parser, size_t *size);
+uint8_t *usb_hid_report_output(usb_hid_report_t *report, size_t *size, uint8_t report_id);
 
 /** Frees output report buffer*/
@@ -307,12 +333,14 @@
 
 /** Returns size of output for given usage path */
-size_t usb_hid_report_output_size(usb_hid_report_parser_t *parser,
+size_t usb_hid_report_output_size(usb_hid_report_t *report,
                                   usb_hid_report_path_t *path, int flags);
 
-/** Updates the output report buffer by translated given data */
-int usb_hid_report_output_translate(usb_hid_report_parser_t *parser,
-                                    usb_hid_report_path_t *path, int flags,
-                                    uint8_t *buffer, size_t size,
-                                    int32_t *data, size_t data_size);
+/** Sets data in report structure */
+int usb_hid_report_output_set_data(usb_hid_report_t *report, 
+                                   usb_hid_report_path_t *path, int flags, 
+                                  int *data, size_t data_size);
+
+/** Makes the output report buffer by translated given data */
+int usb_hid_report_output_translate(usb_hid_report_t *report, uint8_t report_id, uint8_t *buffer, size_t size);
 #endif
 /**
Index: uspace/lib/usb/include/usb/classes/hidreport.h
===================================================================
--- uspace/lib/usb/include/usb/classes/hidreport.h	(revision 564a2b33fa6a9365cde0a9228b5722048647e566)
+++ uspace/lib/usb/include/usb/classes/hidreport.h	(revision 308a5d52410eedc0ee1ce72952d26a931def9c82)
@@ -57,5 +57,5 @@
  */
 int usb_hid_process_report_descriptor(usb_device_t *dev, 
-    usb_hid_report_parser_t *parser);
+    usb_hid_report_t *report);
 
 #endif /* LIBUSB_HIDREPORT_H_ */
Index: uspace/lib/usb/src/hidparser.c
===================================================================
--- uspace/lib/usb/src/hidparser.c	(revision 564a2b33fa6a9365cde0a9228b5722048647e566)
+++ uspace/lib/usb/src/hidparser.c	(revision 308a5d52410eedc0ee1ce72952d26a931def9c82)
@@ -39,12 +39,19 @@
 #include <mem.h>
 #include <usb/debug.h>
-
-/** */
+#include <assert.h>
+
+/** The new report item flag. Used to determine when the item is completly
+ * configured and should be added to the report structure
+ */
 #define USB_HID_NEW_REPORT_ITEM 1
 
-/** */
-#define USB_HID_NO_ACTION		2
-
-/** */
+/** No special action after the report descriptor tag is processed should be
+ * done
+ */
+#define USB_HID_NO_ACTION	2
+
+#define USB_HID_RESET_OFFSET	3
+
+/** Unknown tag was founded in report descriptor data*/
 #define USB_HID_UNKNOWN_TAG		-99
 
@@ -52,4 +59,7 @@
  * Private descriptor parser functions
  */
+int usb_hid_report_init(usb_hid_report_t *report);
+int usb_hid_report_append_fields(usb_hid_report_t *report, usb_hid_report_item_t *report_item);
+usb_hid_report_description_t * usb_hid_report_find_description(const usb_hid_report_t *report, uint8_t report_id, usb_hid_report_type_t type);
 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, size_t item_size,
                              usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path);
@@ -61,6 +71,7 @@
                              usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path);
 
+void usb_hid_print_usage_path(usb_hid_report_path_t *path);
 void usb_hid_descriptor_print_list(link_t *head);
-int usb_hid_report_reset_local_items();
+void usb_hid_report_reset_local_items(usb_hid_report_item_t *report_item);
 void usb_hid_free_report_list(link_t *head);
 usb_hid_report_item_t *usb_hid_report_item_clone(const usb_hid_report_item_t *item);
@@ -68,10 +79,12 @@
  * Data translation private functions
  */
-int32_t usb_hid_report_tag_data_int32(const uint8_t *data, size_t size);
+uint32_t usb_hid_report_tag_data_uint32(const uint8_t *data, size_t size);
 inline size_t usb_hid_count_item_offset(usb_hid_report_item_t * report_item, size_t offset);
-int usb_hid_translate_data(usb_hid_report_item_t *item, const uint8_t *data, size_t j);
-int32_t usb_hid_translate_data_reverse(usb_hid_report_item_t *item, int32_t value);
+int usb_hid_translate_data(usb_hid_report_field_t *item, const uint8_t *data);
+uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item, int32_t value);
 int usb_pow(int a, int b);
 
+#define USB_HID_UINT32_TO_INT32(x, size)	((((x) & (1 << ((size) - 1))) != 0) ? -(~(x - 1) & ((1 << size) - 1)) : (x)) //(-(~((x) - 1)))
+#define USB_HID_INT32_TO_UINT32(x, size)	(((x) < 0 ) ? ((1 << (size)) + (x)) : (x))
 // TODO: tohle ma bejt asi jinde
 int usb_pow(int a, int b)
@@ -96,20 +109,163 @@
  * @return Error code
  */
-int usb_hid_parser_init(usb_hid_report_parser_t *parser)
-{
-	if(parser == NULL) {
+int usb_hid_report_init(usb_hid_report_t *report)
+{
+	if(report == NULL) {
 		return EINVAL;
 	}
 
-	list_initialize(&(parser->input));
-    list_initialize(&(parser->output));
-    list_initialize(&(parser->feature));
-
-	list_initialize(&(parser->stack));
-
-	parser->use_report_id = 0;
+	memset(report, 0, sizeof(usb_hid_report_t));
+	list_initialize(&report->reports);
+	list_initialize(&report->collection_paths);
+
+	report->use_report_ids = 0;
     return EOK;   
 }
 
+int usb_hid_report_append_fields(usb_hid_report_t *report, usb_hid_report_item_t *report_item)
+{
+	usb_hid_report_field_t *field;
+	int i;
+
+
+	/* find or append current collection path to the list */
+	link_t *path_it = report->collection_paths.next;
+	usb_hid_report_path_t *path = NULL;
+	while(path_it != &report->collection_paths) {
+		path = list_get_instance(path_it, usb_hid_report_path_t, link);
+		
+		if(usb_hid_report_compare_usage_path(path, report_item->usage_path, USB_HID_PATH_COMPARE_STRICT) == EOK){
+			break;
+		}			
+		path_it = path_it->next;
+	}
+	if(path_it == &report->collection_paths) {
+		path = usb_hid_report_path_clone(report_item->usage_path);			
+		list_append(&path->link, &report->collection_paths);					
+		report->collection_paths_count++;
+	}
+
+	for(i=0; i<report_item->usages_count; i++){
+		usb_log_debug("usages (%d) - %x\n", i, report_item->usages[i]);
+	}
+
+	
+	for(i=0; i<report_item->count; i++){
+
+		field = malloc(sizeof(usb_hid_report_field_t));
+		memset(field, 0, sizeof(usb_hid_report_field_t));
+		list_initialize(&field->link);
+
+		/* fill the attributes */		
+		field->collection_path = path;
+		field->logical_minimum = report_item->logical_minimum;
+		field->logical_maximum = report_item->logical_maximum;
+		field->physical_minimum = report_item->physical_minimum;
+		field->physical_maximum = report_item->physical_maximum;
+
+		field->usage_minimum = report_item->usage_minimum;
+		field->usage_maximum = report_item->usage_maximum;
+		if(report_item->extended_usage_page != 0){
+			field->usage_page = report_item->extended_usage_page;
+		}
+		else {
+			field->usage_page = report_item->usage_page;
+		}
+
+		if(report_item->usages_count > 0 && ((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0))) {
+			uint32_t usage;
+			if(report_item->type == USB_HID_REPORT_TYPE_INPUT) {
+				if(i < report_item->usages_count){
+					usage = report_item->usages[i];
+				}
+				else {
+					usage = report_item->usages[report_item->usages_count - 1];
+				}
+			}
+			else {
+				if((report_item->count - i - 1) < report_item->usages_count){
+					usage = report_item->usages[(report_item->count - i - 1)];
+				}
+				else {
+					usage = report_item->usages[report_item->usages_count - 1];
+				}
+			}
+
+						
+			if((usage & 0xFF00) != 0){
+				field->usage_page = (usage >> 16);					
+				field->usage = (usage & 0xFF);
+			}
+			else {
+				field->usage = usage;
+			}
+
+			
+		}	
+
+		if((USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) != 0) && (!((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0)))) {
+			if(report_item->type == USB_HID_REPORT_TYPE_INPUT) {
+				field->usage = report_item->usage_maximum - i;
+			}
+			else {
+				field->usage = report_item->usage_minimum + i;					
+			}
+
+		}
+		
+		field->size = report_item->size;
+		field->offset = report_item->offset + (i * report_item->size);
+		if(report_item->id != 0) {
+			field->offset += 8;
+			report->use_report_ids = 1;
+		}
+		field->item_flags = report_item->item_flags;
+
+		/* find the right report list*/
+		usb_hid_report_description_t *report_des;
+		report_des = usb_hid_report_find_description(report, report_item->id, report_item->type);
+		if(report_des == NULL){
+			report_des = malloc(sizeof(usb_hid_report_description_t));
+			memset(report_des, 0, sizeof(usb_hid_report_description_t));
+
+			report_des->type = report_item->type;
+			report_des->report_id = report_item->id;
+			list_initialize (&report_des->link);
+			list_initialize (&report_des->report_items);
+
+			list_append(&report_des->link, &report->reports);
+			report->report_count++;
+		}
+
+		/* append this field to the end of founded report list */
+		list_append (&field->link, &report_des->report_items);
+		
+		/* update the sizes */
+		report_des->bit_length += field->size;
+		report_des->item_length++;
+
+	}
+
+
+	return EOK;
+}
+
+usb_hid_report_description_t * usb_hid_report_find_description(const usb_hid_report_t *report, uint8_t report_id, usb_hid_report_type_t type)
+{
+	link_t *report_it = report->reports.next;
+	usb_hid_report_description_t *report_des = NULL;
+	
+	while(report_it != &report->reports) {
+		report_des = list_get_instance(report_it, usb_hid_report_description_t, link);
+
+		if((report_des->report_id == report_id) && (report_des->type == type)){
+			return report_des;
+		}
+		
+		report_it = report_it->next;
+	}
+
+	return NULL;
+}
 
 /** Parse HID report descriptor.
@@ -119,5 +275,5 @@
  * @return Error code.
  */
-int usb_hid_parse_report_descriptor(usb_hid_report_parser_t *parser, 
+int usb_hid_parse_report_descriptor(usb_hid_report_t *report, 
     const uint8_t *data, size_t size)
 {
@@ -130,17 +286,17 @@
 	usb_hid_report_item_t *new_report_item;	
 	usb_hid_report_path_t *usage_path;
-	usb_hid_report_path_t *tmp_usage_path;
 
 	size_t offset_input=0;
 	size_t offset_output=0;
 	size_t offset_feature=0;
-	
+
+	link_t stack;
+	list_initialize(&stack);	
 
 	/* parser structure initialization*/
-	if(usb_hid_parser_init(parser) != EOK) {
+	if(usb_hid_report_init(report) != EOK) {
 		return EINVAL;
 	}
 	
-
 	/*report item initialization*/
 	if(!(report_item=malloc(sizeof(usb_hid_report_item_t)))){
@@ -159,5 +315,5 @@
 
 			if((i+USB_HID_ITEM_SIZE(data[i]))>= size){
-				return EINVAL; // TODO ERROR CODE
+				return EINVAL;
 			}
 			
@@ -165,52 +321,34 @@
 			item_size = USB_HID_ITEM_SIZE(data[i]);
 			class = USB_HID_ITEM_TAG_CLASS(data[i]);
-
-			usb_log_debug2(
-				"i(%zu) data(%X) value(%X): TAG %d, class %u, size %u - ", i,
-			    data[i], usb_hid_report_tag_data_int32(data+i+1,item_size), 
-			    tag, class, item_size);
 			
 			ret = usb_hid_report_parse_tag(tag,class,data+i+1,
 			                               item_size,report_item, usage_path);
-			usb_log_debug2("ret: %u\n", ret);
 			switch(ret){
 				case USB_HID_NEW_REPORT_ITEM:
 					// store report item to report and create the new one
-					usb_log_debug("\nNEW REPORT ITEM: %X",ret);
-
-					// store current usage path
+					// store current collection path
 					report_item->usage_path = usage_path;
 					
-					// clone path to the new one
-					tmp_usage_path = usb_hid_report_path_clone(usage_path);
-
-					// swap
-					usage_path = tmp_usage_path;
-					tmp_usage_path = NULL;
-
 					usb_hid_report_path_set_report_id(report_item->usage_path, report_item->id);	
 					if(report_item->id != 0){
-						parser->use_report_id = 1;
+						report->use_report_ids = 1;
 					}
 					
 					switch(tag) {
 						case USB_HID_REPORT_TAG_INPUT:
+							report_item->type = USB_HID_REPORT_TYPE_INPUT;
 							report_item->offset = offset_input;
 							offset_input += report_item->count * report_item->size;
-							usb_log_debug(" - INPUT\n");
-							list_append(&(report_item->link), &(parser->input));
 							break;
 						case USB_HID_REPORT_TAG_OUTPUT:
+							report_item->type = USB_HID_REPORT_TYPE_OUTPUT;
 							report_item->offset = offset_output;
 							offset_output += report_item->count * report_item->size;
-							usb_log_debug(" - OUTPUT\n");
-								list_append(&(report_item->link), &(parser->output));
 
 							break;
 						case USB_HID_REPORT_TAG_FEATURE:
+							report_item->type = USB_HID_REPORT_TYPE_FEATURE;
 							report_item->offset = offset_feature;
 							offset_feature += report_item->count * report_item->size;
-							usb_log_debug(" - FEATURE\n");
-								list_append(&(report_item->link), &(parser->feature));
 							break;
 						default:
@@ -218,43 +356,48 @@
 						    break;
 					}
-
-					/* clone current state table to the new item */
-					if(!(new_report_item = malloc(sizeof(usb_hid_report_item_t)))) {
-						return ENOMEM;
-					}					
-					memcpy(new_report_item,report_item, sizeof(usb_hid_report_item_t));
-					link_initialize(&(new_report_item->link));
 					
+					/* 
+					 * append new fields to the report
+					 * structure 					 
+					 */
+					usb_hid_report_append_fields(report, report_item);
+
 					/* reset local items */
-					new_report_item->usage_minimum = 0;
-					new_report_item->usage_maximum = 0;
-					new_report_item->designator_index = 0;
-					new_report_item->designator_minimum = 0;
-					new_report_item->designator_maximum = 0;
-					new_report_item->string_index = 0;
-					new_report_item->string_minimum = 0;
-					new_report_item->string_maximum = 0;
-
-					/* reset usage from current usage path */
-					usb_hid_report_usage_path_t *path = list_get_instance(&usage_path->link, usb_hid_report_usage_path_t, link);
-					path->usage = 0;
-					
-					report_item = new_report_item;
-										
+					usb_hid_report_reset_local_items (report_item);
+
 					break;
+
+				case USB_HID_RESET_OFFSET:
+					offset_input = 0;
+					offset_output = 0;
+					offset_feature = 0;
+					usb_hid_report_path_set_report_id (usage_path, report_item->id);
+					break;
+
 				case USB_HID_REPORT_TAG_PUSH:
 					// push current state to stack
 					new_report_item = usb_hid_report_item_clone(report_item);
-					list_prepend (&parser->stack, &new_report_item->link);
-					
+					usb_hid_report_path_t *tmp_path = usb_hid_report_path_clone(usage_path);
+					new_report_item->usage_path = tmp_path; 
+
+					list_prepend (&new_report_item->link, &stack);
 					break;
 				case USB_HID_REPORT_TAG_POP:
 					// restore current state from stack
-					if(list_empty (&parser->stack)) {
+					if(list_empty (&stack)) {
 						return EINVAL;
 					}
+					free(report_item);
+						
+					report_item = list_get_instance(stack.next, usb_hid_report_item_t, link);
 					
-					report_item = list_get_instance(&parser->stack, usb_hid_report_item_t, link);
-					list_remove (parser->stack.next);
+					usb_hid_report_usage_path_t *tmp_usage_path;
+					tmp_usage_path = list_get_instance(report_item->usage_path->link.prev, usb_hid_report_usage_path_t, link);
+					
+					usb_hid_report_set_last_item(usage_path, tmp_usage_path->usage_page, tmp_usage_path->usage);
+
+					usb_hid_report_path_free(report_item->usage_path);
+					list_initialize(&report_item->usage_path->link);
+					list_remove (stack.next);
 					
 					break;
@@ -279,64 +422,4 @@
 }
 
-
-/**
- * Parse input report.
- *
- * @param data Data for report
- * @param size Size of report
- * @param callbacks Callbacks for report actions
- * @param arg Custom arguments
- *
- * @return Error code
- */
-int usb_hid_boot_keyboard_input_report(const uint8_t *data, size_t size,
-	const usb_hid_report_in_callbacks_t *callbacks, void *arg)
-{
-	int i;
-	usb_hid_report_item_t item;
-
-	/* fill item due to the boot protocol report descriptor */
-	// modifier keys are in the first byte
-	uint8_t modifiers = data[0];
-
-	item.offset = 2; /* second byte is reserved */
-	item.size = 8;
-	item.count = 6;
-	item.usage_minimum = 0;
-	item.usage_maximum = 255;
-	item.logical_minimum = 0;
-	item.logical_maximum = 255;
-
-	if (size != 8) {
-		return -1; //ERANGE;
-	}
-
-	uint8_t keys[6];
-	for (i = 0; i < item.count; i++) {
-		keys[i] = data[i + item.offset];
-	}
-
-	callbacks->keyboard(keys, 6, modifiers, arg);
-	return EOK;
-}
-
-/**
- * Makes output report for keyboard boot protocol
- *
- * @param leds
- * @param output Output report data buffer
- * @param size Size of the output buffer
- * @return Error code
- */
-int usb_hid_boot_keyboard_output_report(uint8_t leds, uint8_t *data, size_t size)
-{
-	if(size != 1){
-		return -1;
-	}
-
-	/* used only first five bits, others are only padding*/
-	*data = leds;
-	return EOK;
-}
 
 /**
@@ -401,13 +484,11 @@
 			
 		case USB_HID_REPORT_TAG_COLLECTION:
-			usb_hid_report_path_append_item(usage_path, 0, 0);
-						
+			// TODO usage_path->flags = *data;
+			usb_hid_report_path_append_item(usage_path, report_item->usage_page, report_item->usages[report_item->usages_count-1]);						
+			usb_hid_report_reset_local_items (report_item);
 			return USB_HID_NO_ACTION;
 			break;
 			
 		case USB_HID_REPORT_TAG_END_COLLECTION:
-			// TODO
-			// znici posledni uroven ve vsech usage paths
-			// otazka jestli nema nicit dve, respektive novou posledni vynulovat?
 			usb_hid_report_remove_last_item(usage_path);
 			return USB_HID_NO_ACTION;
@@ -436,37 +517,41 @@
 	{
 		case USB_HID_REPORT_TAG_USAGE_PAGE:
-			// zmeni to jenom v poslednim poli aktualni usage path
-			usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_GLOBAL,
-				usb_hid_report_tag_data_int32(data,item_size));
+			report_item->usage_page = usb_hid_report_tag_data_uint32(data, item_size);
 			break;
 		case USB_HID_REPORT_TAG_LOGICAL_MINIMUM:
-			report_item->logical_minimum = usb_hid_report_tag_data_int32(data,item_size);
+			report_item->logical_minimum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8);
 			break;
 		case USB_HID_REPORT_TAG_LOGICAL_MAXIMUM:
-			report_item->logical_maximum = usb_hid_report_tag_data_int32(data,item_size);
+			report_item->logical_maximum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8);
 			break;
 		case USB_HID_REPORT_TAG_PHYSICAL_MINIMUM:
-			report_item->physical_minimum = usb_hid_report_tag_data_int32(data,item_size);
+			report_item->physical_minimum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8);
 			break;			
 		case USB_HID_REPORT_TAG_PHYSICAL_MAXIMUM:
-			report_item->physical_maximum = usb_hid_report_tag_data_int32(data,item_size);
+			report_item->physical_maximum = USB_HID_UINT32_TO_INT32(usb_hid_report_tag_data_uint32(data,item_size), item_size * 8);
+
 			break;
 		case USB_HID_REPORT_TAG_UNIT_EXPONENT:
-			report_item->unit_exponent = usb_hid_report_tag_data_int32(data,item_size);
+			report_item->unit_exponent = usb_hid_report_tag_data_uint32(data,item_size);
 			break;
 		case USB_HID_REPORT_TAG_UNIT:
-			report_item->unit = usb_hid_report_tag_data_int32(data,item_size);
+			report_item->unit = usb_hid_report_tag_data_uint32(data,item_size);
 			break;
 		case USB_HID_REPORT_TAG_REPORT_SIZE:
-			report_item->size = usb_hid_report_tag_data_int32(data,item_size);
+			report_item->size = usb_hid_report_tag_data_uint32(data,item_size);
 			break;
 		case USB_HID_REPORT_TAG_REPORT_COUNT:
-			report_item->count = usb_hid_report_tag_data_int32(data,item_size);
+			report_item->count = usb_hid_report_tag_data_uint32(data,item_size);
 			break;
 		case USB_HID_REPORT_TAG_REPORT_ID:
-			report_item->id = usb_hid_report_tag_data_int32(data,item_size);
+			report_item->id = usb_hid_report_tag_data_uint32(data,item_size);
+			return USB_HID_RESET_OFFSET;
 			break;
 		case USB_HID_REPORT_TAG_PUSH:
 		case USB_HID_REPORT_TAG_POP:
+			/* 
+			 * stack operations are done in top level parsing
+			 * function
+			 */
 			return tag;
 			break;
@@ -475,5 +560,5 @@
 			return USB_HID_NO_ACTION;
 	}
-	
+
 	return EOK;
 }
@@ -494,33 +579,49 @@
 	{
 		case USB_HID_REPORT_TAG_USAGE:
-			usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_LOCAL,
-				usb_hid_report_tag_data_int32(data,item_size));
+			report_item->usages[report_item->usages_count] = usb_hid_report_tag_data_uint32(data,item_size);
+			report_item->usages_count++;
 			break;
 		case USB_HID_REPORT_TAG_USAGE_MINIMUM:
-			report_item->usage_minimum = usb_hid_report_tag_data_int32(data,item_size);
+			if (item_size == 3) {
+				// usage extended usages
+				report_item->extended_usage_page = (usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16; 
+				report_item->usage_minimum = usb_hid_report_tag_data_uint32(data,item_size) & 0xFF;
+			}
+			else {
+				report_item->usage_minimum = usb_hid_report_tag_data_uint32(data,item_size);
+			}
 			break;
 		case USB_HID_REPORT_TAG_USAGE_MAXIMUM:
-			report_item->usage_maximum = usb_hid_report_tag_data_int32(data,item_size);
+			if (item_size == 3) {
+				// usage extended usages
+				report_item->extended_usage_page = (usb_hid_report_tag_data_uint32(data,item_size) & 0xFF00) >> 16; 
+				report_item->usage_maximum = usb_hid_report_tag_data_uint32(data,item_size) & 0xFF;
+			}
+			else {
+				report_item->usage_maximum = usb_hid_report_tag_data_uint32(data,item_size);
+			}
 			break;
 		case USB_HID_REPORT_TAG_DESIGNATOR_INDEX:
-			report_item->designator_index = usb_hid_report_tag_data_int32(data,item_size);
+			report_item->designator_index = usb_hid_report_tag_data_uint32(data,item_size);
 			break;
 		case USB_HID_REPORT_TAG_DESIGNATOR_MINIMUM:
-			report_item->designator_minimum = usb_hid_report_tag_data_int32(data,item_size);
+			report_item->designator_minimum = usb_hid_report_tag_data_uint32(data,item_size);
 			break;
 		case USB_HID_REPORT_TAG_DESIGNATOR_MAXIMUM:
-			report_item->designator_maximum = usb_hid_report_tag_data_int32(data,item_size);
+			report_item->designator_maximum = usb_hid_report_tag_data_uint32(data,item_size);
 			break;
 		case USB_HID_REPORT_TAG_STRING_INDEX:
-			report_item->string_index = usb_hid_report_tag_data_int32(data,item_size);
+			report_item->string_index = usb_hid_report_tag_data_uint32(data,item_size);
 			break;
 		case USB_HID_REPORT_TAG_STRING_MINIMUM:
-			report_item->string_minimum = usb_hid_report_tag_data_int32(data,item_size);
+			report_item->string_minimum = usb_hid_report_tag_data_uint32(data,item_size);
 			break;
 		case USB_HID_REPORT_TAG_STRING_MAXIMUM:
-			report_item->string_maximum = usb_hid_report_tag_data_int32(data,item_size);
+			report_item->string_maximum = usb_hid_report_tag_data_uint32(data,item_size);
 			break;			
 		case USB_HID_REPORT_TAG_DELIMITER:
-			report_item->delimiter = usb_hid_report_tag_data_int32(data,item_size);
+			//report_item->delimiter = usb_hid_report_tag_data_uint32(data,item_size);
+			//TODO: 
+			//	DELIMITER STUFF
 			break;
 		
@@ -533,5 +634,5 @@
 
 /**
- * Converts raw data to int32 (thats the maximum length of short item data)
+ * Converts raw data to uint32 (thats the maximum length of short item data)
  *
  * @param Data buffer
@@ -539,8 +640,8 @@
  * @return Converted int32 number
  */
-int32_t usb_hid_report_tag_data_int32(const uint8_t *data, size_t size)
+uint32_t usb_hid_report_tag_data_uint32(const uint8_t *data, size_t size)
 {
 	unsigned int i;
-	int32_t result;
+	uint32_t result;
 
 	result = 0;
@@ -552,6 +653,4 @@
 }
 
-
-
 /**
  * Prints content of given list of report items.
@@ -562,9 +661,8 @@
 void usb_hid_descriptor_print_list(link_t *head)
 {
-	usb_hid_report_item_t *report_item;
-	usb_hid_report_usage_path_t *path_item;
-	link_t *path;
+	usb_hid_report_field_t *report_item;
 	link_t *item;
-	
+
+
 	if(head == NULL || list_empty(head)) {
 	    usb_log_debug("\tempty\n");
@@ -574,28 +672,20 @@
 	for(item = head->next; item != head; item = item->next) {
                 
-		report_item = list_get_instance(item, usb_hid_report_item_t, link);
-
-		usb_log_debug("\tOFFSET: %zX\n", report_item->offset);
-		usb_log_debug("\tCOUNT: %X\n", report_item->count);
-		usb_log_debug("\tSIZE: %X\n", report_item->size);
-		usb_log_debug("\tCONSTANT/VAR: %X\n", USB_HID_ITEM_FLAG_CONSTANT(report_item->item_flags));
-		usb_log_debug("\tVARIABLE/ARRAY: %X\n", USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags));
-		usb_log_debug("\tUSAGE PATH:\n");
-
-		path = report_item->usage_path->link.next;
-		while(path != &report_item->usage_path->link)	{
-			path_item = list_get_instance(path, usb_hid_report_usage_path_t, link);
-			usb_log_debug("\t\tUSAGE PAGE: %X, USAGE: %X\n", path_item->usage_page, path_item->usage);
-			path = path->next;
-		}
-				
-		usb_log_debug("\tLOGMIN: %X\n", report_item->logical_minimum);
-		usb_log_debug("\tLOGMAX: %X\n", report_item->logical_maximum);		
-		usb_log_debug("\tPHYMIN: %X\n", report_item->physical_minimum);		
-		usb_log_debug("\tPHYMAX: %X\n", report_item->physical_maximum);				
-		usb_log_debug("\tUSAGEMIN: %X\n", report_item->usage_minimum);
-		usb_log_debug("\tUSAGEMAX: %X\n", report_item->usage_maximum);
-		
-		usb_log_debug("\n");		
+		report_item = list_get_instance(item, usb_hid_report_field_t, link);
+
+		usb_log_debug("\t\tOFFSET: %X\n", report_item->offset);
+		usb_log_debug("\t\tSIZE: %X\n", report_item->size);				
+		usb_log_debug("\t\tLOGMIN: %d\n", report_item->logical_minimum);
+		usb_log_debug("\t\tLOGMAX: %d\n", report_item->logical_maximum);		
+		usb_log_debug("\t\tPHYMIN: %d\n", report_item->physical_minimum);		
+		usb_log_debug("\t\tPHYMAX: %d\n", report_item->physical_maximum);				
+		usb_log_debug("\t\ttUSAGEMIN: %X\n", report_item->usage_minimum);
+		usb_log_debug("\t\tUSAGEMAX: %X\n", report_item->usage_maximum);
+
+		usb_log_debug("\t\tVALUE: %X\n", report_item->value);
+		usb_log_debug("\t\ttUSAGE: %X\n", report_item->usage);
+		usb_log_debug("\t\tUSAGE PAGE: %X\n", report_item->usage_page);
+						
+//		usb_log_debug("\n");		
 
 	}
@@ -609,19 +699,31 @@
  * @return void
  */
-void usb_hid_descriptor_print(usb_hid_report_parser_t *parser)
-{
-	if(parser == NULL) {
+void usb_hid_descriptor_print(usb_hid_report_t *report)
+{
+	if(report == NULL) {
 		return;
 	}
-	
-	usb_log_debug("INPUT:\n");
-	usb_hid_descriptor_print_list(&parser->input);
-	
-	usb_log_debug("OUTPUT: \n");
-	usb_hid_descriptor_print_list(&parser->output);
-	
-	usb_log_debug("FEATURE:\n");	
-	usb_hid_descriptor_print_list(&parser->feature);
-
+
+	link_t *report_it = report->reports.next;
+	usb_hid_report_description_t *report_des;
+
+	while(report_it != &report->reports) {
+		report_des = list_get_instance(report_it, usb_hid_report_description_t, link);
+		usb_log_debug("Report ID: %d\n", report_des->report_id);
+		usb_log_debug("\tType: %d\n", report_des->type);
+		usb_log_debug("\tLength: %d\n", report_des->bit_length);		
+		usb_log_debug("\tItems: %d\n", report_des->item_length);		
+
+		usb_hid_descriptor_print_list(&report_des->report_items);
+
+
+		link_t *path_it = report->collection_paths.next;
+		while(path_it != &report->collection_paths) {
+			usb_hid_print_usage_path (list_get_instance(path_it, usb_hid_report_path_t, link));
+			path_it = path_it->next;
+		}
+		
+		report_it = report_it->next;
+	}
 }
 
@@ -667,16 +769,34 @@
  * @return void
  */
-void usb_hid_free_report_parser(usb_hid_report_parser_t *parser)
-{
-	if(parser == NULL){
+void usb_hid_free_report(usb_hid_report_t *report)
+{
+	if(report == NULL){
 		return;
 	}
 
-	parser->use_report_id = 0;
-
-	usb_hid_free_report_list(&parser->input);
-	usb_hid_free_report_list(&parser->output);
-	usb_hid_free_report_list(&parser->feature);
-
+	// free collection paths
+	usb_hid_report_path_t *path;
+	while(!list_empty(&report->collection_paths)) {
+		path = list_get_instance(report->collection_paths.next, usb_hid_report_path_t, link);
+		usb_hid_report_path_free(path);		
+	}
+	
+	// free report items
+	usb_hid_report_description_t *report_des;
+	usb_hid_report_field_t *field;
+	while(!list_empty(&report->reports)) {
+		report_des = list_get_instance(report->reports.next, usb_hid_report_description_t, link);
+		list_remove(&report_des->link);
+		
+		while(!list_empty(&report_des->report_items)) {
+			field = list_get_instance(report_des->report_items.next, usb_hid_report_field_t, link);
+			list_remove(&field->link);
+
+			free(field);
+		}
+		
+		free(report_des);
+	}
+	
 	return;
 }
@@ -688,69 +808,51 @@
  * @param parser Opaque HID report parser structure.
  * @param data Data for the report.
- * @param callbacks Callbacks for report actions.
- * @param arg Custom argument (passed through to the callbacks).
  * @return Error code.
  */ 
-int usb_hid_parse_report(const usb_hid_report_parser_t *parser,  
-    const uint8_t *data, size_t size,
-    usb_hid_report_path_t *path, int flags,
-    const usb_hid_report_in_callbacks_t *callbacks, void *arg)
+int usb_hid_parse_report(const usb_hid_report_t *report,  
+    const uint8_t *data, size_t size, uint8_t *report_id)
 {
 	link_t *list_item;
-	usb_hid_report_item_t *item;
-	uint8_t *keys;
-	uint8_t item_value;
-	size_t key_count=0;
-	size_t i=0;
-	size_t j=0;
-	uint8_t report_id = 0;
-
-	if(parser == NULL) {
+	usb_hid_report_field_t *item;
+
+	usb_hid_report_description_t *report_des;
+	usb_hid_report_type_t type = USB_HID_REPORT_TYPE_INPUT;
+
+	if(report == NULL) {
 		return EINVAL;
 	}
-	
-	/* get the size of result array */
-	key_count = usb_hid_report_input_length(parser, path, flags);
-
-	if(!(keys = malloc(sizeof(uint8_t) * key_count))){
-		return ENOMEM;
-	}
-
-	if(parser->use_report_id != 0) {
-		report_id = data[0];
-		usb_hid_report_path_set_report_id(path, report_id);
-	}
+
+	if(report->use_report_ids != 0) {
+		*report_id = data[0];
+	}	
+	else {
+		*report_id = 0;
+	}
+
+
+	report_des = usb_hid_report_find_description(report, *report_id, type);
 
 	/* read data */
-	list_item = parser->input.next;	   
-	while(list_item != &(parser->input)) {
-
-		item = list_get_instance(list_item, usb_hid_report_item_t, link);
-
-		if(!USB_HID_ITEM_FLAG_CONSTANT(item->item_flags) && 
-		   (usb_hid_report_compare_usage_path(item->usage_path, path, flags) == EOK)) {
-			for(j=0; j<(size_t)(item->count); j++) {
-				if((USB_HID_ITEM_FLAG_VARIABLE(item->item_flags) == 0) ||
-				   ((item->usage_minimum == 0) && (item->usage_maximum == 0))) {
-					// variable item
-					keys[i++] = usb_hid_translate_data(item, data,j);
-				}
-				else {
-					// bitmapa
-					if((item_value = usb_hid_translate_data(item, data, j)) != 0) {
-						keys[i++] = (item->count - 1 - j) + item->usage_minimum;
-					}
-					else {
-						keys[i++] = 0;
-					}
-				}
-			}
+	list_item = report_des->report_items.next;	   
+	while(list_item != &(report_des->report_items)) {
+
+		item = list_get_instance(list_item, usb_hid_report_field_t, link);
+
+		if(USB_HID_ITEM_FLAG_CONSTANT(item->item_flags) == 0) {
+			
+			if(USB_HID_ITEM_FLAG_VARIABLE(item->item_flags) == 0) {
+
+				// array
+				item->value = usb_hid_translate_data(item, data);
+			    item->usage = (item->value - item->physical_minimum) + item->usage_minimum;
+			}
+			else {
+				// variable item
+				item->value = usb_hid_translate_data(item, data);				
+			}				
 		}
 		list_item = list_item->next;
 	}
-
-	callbacks->keyboard(keys, key_count, report_id, arg);
 	   
-	free(keys);	
 	return EOK;
 	
@@ -758,5 +860,5 @@
 
 /**
- * Translate data from the report as specified in report descriptor
+ * Translate data from the report as specified in report descriptor item
  *
  * @param item Report descriptor item with definition of translation
@@ -765,5 +867,5 @@
  * @return Translated data
  */
-int usb_hid_translate_data(usb_hid_report_item_t *item, const uint8_t *data, size_t j)
+int usb_hid_translate_data(usb_hid_report_field_t *item, const uint8_t *data)
 {
 	int resolution;
@@ -771,17 +873,18 @@
 	int part_size;
 	
-	int32_t value;
+	int32_t value=0;
 	int32_t mask;
 	const uint8_t *foo;
 
-	// now only common numbers llowed
+	// now only shot tags are allowed
 	if(item->size > 32) {
 		return 0;
 	}
 
-	if((item->physical_minimum == 0) && (item->physical_maximum == 0)) {
+	if((item->physical_minimum == 0) && (item->physical_maximum == 0)){
 		item->physical_minimum = item->logical_minimum;
-		item->physical_maximum = item->logical_maximum;		
-	}
+		item->physical_maximum = item->logical_maximum;			
+	}
+	
 
 	if(item->physical_maximum == item->physical_minimum){
@@ -794,37 +897,29 @@
 	}
 
-	offset = item->offset + (j * item->size);
-	if(item->id != 0) {
-		offset += 8;
-		usb_log_debug("MOVED OFFSET BY 1Byte, REPORT_ID(%d)\n", item->id);
-	}
-	
+	offset = item->offset;
 	// FIXME
-	if((offset/8) != ((offset+item->size)/8)) {
-		usb_log_debug2("offset %d\n", offset);
+	if((size_t)(offset/8) != (size_t)((offset+item->size-1)/8)) {
 		
 		part_size = ((offset+item->size)%8);
-		usb_log_debug2("part size %d\n",part_size);
-
-		// the higher one
-		foo = data+(offset/8);
-		mask =  ((1 << (item->size-part_size))-1);
-		value = (*foo & mask) << part_size;
-
-		usb_log_debug2("hfoo %x\n", *foo);
-		usb_log_debug2("hmaska %x\n",  mask);
-		usb_log_debug2("hval %d\n", value);		
-
-		// the lower one
-		foo = data+((offset+item->size)/8);
-		mask =  ((1 << part_size)-1) << (8-part_size);
-		value += ((*foo & mask) >> (8-part_size));
-
-		usb_log_debug2("lfoo %x\n", *foo);
-		usb_log_debug2("lmaska %x\n",  mask);
-		usb_log_debug2("lval %d\n", ((*foo & mask) >> (8-(item->size-part_size))));		
-		usb_log_debug2("val %d\n", value);
-		
-		
+
+		size_t i=0;
+		for(i=(size_t)(offset/8); i<=(size_t)(offset+item->size-1)/8; i++){
+			if(i == (size_t)(offset/8)) {
+				// the higher one
+				foo = data + i;
+				mask =  ((1 << (item->size-part_size))-1);
+				value = (*foo & mask) << part_size;
+			}
+			else if(i == ((offset+item->size-1)/8)){
+				// the lower one
+				foo = data + i;
+				mask =  ((1 << part_size)-1) << (8-part_size);
+				value += ((*foo & mask) >> (8-part_size));
+			}
+			else {
+				value = value << 8;
+				value += *(data + 1);
+			}
+		}
 	}
 	else {		
@@ -832,13 +927,9 @@
 		mask =  ((1 << item->size)-1) << (8-((offset%8)+item->size));
 		value = (*foo & mask) >> (8-((offset%8)+item->size));
-
-		usb_log_debug2("offset %d\n", offset);
-	
-		usb_log_debug2("foo %x\n", *foo);
-		usb_log_debug2("maska %x\n",  mask);
-		usb_log_debug2("val %d\n", value);				
-	}
-
-	usb_log_debug2("---\n\n"); 
+	}
+
+	if((item->logical_minimum < 0) || (item->logical_maximum < 0)){
+		value = USB_HID_UINT32_TO_INT32(value, item->size);
+	}
 
 	return (int)(((value - item->logical_minimum) / resolution) + item->physical_minimum);
@@ -847,43 +938,56 @@
 
 /**
- *
- *
- * @param parser
- * @param path
- * @param flags
- * @return
- */
-size_t usb_hid_report_input_length(const usb_hid_report_parser_t *parser,
+ * Returns number of items in input report which are accessible by given usage path
+ *
+ * @param parser Opaque report descriptor structure
+ * @param path Usage path specification
+ * @param flags Usage path comparison flags
+ * @return Number of items in input report
+ */
+size_t usb_hid_report_input_length(const usb_hid_report_t *report,
 	usb_hid_report_path_t *path, int flags)
 {	
+	
 	size_t ret = 0;
-	link_t *item;
-	usb_hid_report_item_t *report_item;
-
-	if(parser == NULL) {
+
+	if(report == NULL) {
 		return 0;
 	}
-	
-	item = parser->input.next;
-	while(&parser->input != item) {
-		report_item = list_get_instance(item, usb_hid_report_item_t, link);
-		if(!USB_HID_ITEM_FLAG_CONSTANT(report_item->item_flags) &&
-		   (usb_hid_report_compare_usage_path(report_item->usage_path, path, flags) == EOK)) {
-			ret += report_item->count;
-		}
-
-		item = item->next;
-	} 
+
+	usb_hid_report_description_t *report_des;
+	report_des = usb_hid_report_find_description (report, path->report_id, USB_HID_REPORT_TYPE_INPUT);
+	if(report_des == NULL) {
+		return 0;
+	}
+
+	link_t *field_it = report_des->report_items.next;
+	usb_hid_report_field_t *field;
+	while(field_it != &report_des->report_items) {
+
+		field = list_get_instance(field_it, usb_hid_report_field_t, link);
+		if(USB_HID_ITEM_FLAG_CONSTANT(field->item_flags) == 0) {
+			
+			usb_hid_report_path_append_item (field->collection_path, field->usage_page, field->usage);
+			if(usb_hid_report_compare_usage_path (field->collection_path, path, flags) == EOK) {
+				ret++;
+			}
+			usb_hid_report_remove_last_item (field->collection_path);
+		}
+		
+		field_it = field_it->next;
+	}
 
 	return ret;
-}
-
-
-/**
- * 
- * @param usage_path
- * @param usage_page
- * @param usage
- * @return
+	}
+
+
+/**
+ * Appends one item (couple of usage_path and usage) into the usage path
+ * structure
+ *
+ * @param usage_path Usage path structure
+ * @param usage_page Usage page constant
+ * @param usage Usage constant
+ * @return Error code
  */
 int usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path, 
@@ -899,8 +1003,7 @@
 	item->usage = usage;
 	item->usage_page = usage_page;
-	
-	usb_log_debug("Appending usage %d, usage page %d\n", usage, usage_page);
-	
-	list_append (&usage_path->link, &item->link);
+	item->flags = 0;
+	
+	list_append (&item->link, &usage_path->head);
 	usage_path->depth++;
 	return EOK;
@@ -908,7 +1011,7 @@
 
 /**
- *
- * @param usage_path
- * @return
+ * Removes last item from the usage path structure
+ * @param usage_path 
+ * @return void
  */
 void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path)
@@ -916,7 +1019,7 @@
 	usb_hid_report_usage_path_t *item;
 	
-	if(!list_empty(&usage_path->link)){
-		item = list_get_instance(usage_path->link.prev, usb_hid_report_usage_path_t, link);		
-		list_remove(usage_path->link.prev);
+	if(!list_empty(&usage_path->head)){
+		item = list_get_instance(usage_path->head.prev, usb_hid_report_usage_path_t, link);		
+		list_remove(usage_path->head.prev);
 		usage_path->depth--;
 		free(item);
@@ -925,7 +1028,8 @@
 
 /**
+ * Nulls last item of the usage path structure.
  *
  * @param usage_path
- * @return
+ * @return void
  */
 void usb_hid_report_null_last_item(usb_hid_report_path_t *usage_path)
@@ -933,6 +1037,6 @@
 	usb_hid_report_usage_path_t *item;
 	
-	if(!list_empty(&usage_path->link)){	
-		item = list_get_instance(usage_path->link.prev, usb_hid_report_usage_path_t, link);
+	if(!list_empty(&usage_path->head)){	
+		item = list_get_instance(usage_path->head.prev, usb_hid_report_usage_path_t, link);
 		memset(item, 0, sizeof(usb_hid_report_usage_path_t));
 	}
@@ -940,9 +1044,11 @@
 
 /**
- *
- * @param usage_path
- * @param tag
- * @param data
- * @return
+ * Modifies last item of usage path structure by given usage page or usage
+ *
+ * @param usage_path Opaque usage path structure
+ * @param tag Class of currently processed tag (Usage page tag falls into Global
+ * class but Usage tag into the Local)
+ * @param data Value of the processed tag
+ * @return void
  */
 void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, int32_t tag, int32_t data)
@@ -950,6 +1056,6 @@
 	usb_hid_report_usage_path_t *item;
 	
-	if(!list_empty(&usage_path->link)){	
-		item = list_get_instance(usage_path->link.prev, usb_hid_report_usage_path_t, link);
+	if(!list_empty(&usage_path->head)){	
+		item = list_get_instance(usage_path->head.prev, usb_hid_report_usage_path_t, link);
 
 		switch(tag) {
@@ -965,11 +1071,32 @@
 }
 
-/**
- * 
- *
- * @param report_path
- * @param path
- * @param flags
- * @return
+
+void usb_hid_print_usage_path(usb_hid_report_path_t *path)
+{
+	usb_log_debug("USAGE_PATH FOR RId(%d):\n", path->report_id);
+	usb_log_debug("\tLENGTH: %d\n", path->depth);
+
+	link_t *item = path->head.next;
+	usb_hid_report_usage_path_t *path_item;
+	while(item != &path->head) {
+
+		path_item = list_get_instance(item, usb_hid_report_usage_path_t, link);
+		usb_log_debug("\tUSAGE_PAGE: %X\n", path_item->usage_page);
+		usb_log_debug("\tUSAGE: %X\n", path_item->usage);
+		usb_log_debug("\tFLAGS: %d\n", path_item->flags);		
+		
+		item = item->next;
+	}
+}
+
+/**
+ * Compares two usage paths structures
+ *
+ * If USB_HID_PATH_COMPARE_COLLECTION_ONLY flag is given, the last item in report_path structure is forgotten
+ *
+ * @param report_path usage path structure to compare
+ * @param path usage patrh structure to compare
+ * @param flags Flags determining the mode of comparison
+ * @return EOK if both paths are identical, non zero number otherwise
  */
 int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path, 
@@ -1005,8 +1132,8 @@
 				}
 
-				report_link = report_path->link.next;
-				path_link = path->link.next;
+				report_link = report_path->head.next;
+				path_link = path->head.next;
 			
-				while((report_link != &report_path->link) && (path_link != &path->link)) {
+				while((report_link != &report_path->head) && (path_link != &path->head)) {
 					report_item = list_get_instance(report_link, usb_hid_report_usage_path_t, link);
 					path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, link);		
@@ -1022,5 +1149,6 @@
 				}
 
-				if((report_link == &report_path->link) && (path_link == &path->link)) {
+				if(((report_link == &report_path->head) && (path_link == &path->head)) || 
+				   (((flags & USB_HID_PATH_COMPARE_COLLECTION_ONLY) != 0) && (path_link = &path->head) && (report_link == report_path->head.prev))) {
 					return EOK;
 				}
@@ -1032,12 +1160,18 @@
 		/* compare with only the end of path*/
 		case USB_HID_PATH_COMPARE_END:
-				report_link = report_path->link.prev;
-				path_link = path->link.prev;
-
-				if(list_empty(&path->link)){
+
+				if((flags & USB_HID_PATH_COMPARE_COLLECTION_ONLY) != 0) {
+					report_link = report_path->head.prev->prev;
+				}
+				else {
+					report_link = report_path->head.prev;
+				}
+				path_link = path->head.prev;
+
+				if(list_empty(&path->head)){
 					return EOK;
 				}
 			
-				while((report_link != &report_path->link) && (path_link != &path->link)) {
+				while((report_link != &report_path->head) && (path_link != &path->head)) {
 					report_item = list_get_instance(report_link, usb_hid_report_usage_path_t, link);
 					path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, link);		
@@ -1053,5 +1187,5 @@
 				}
 
-				if(path_link == &path->link) {
+				if(path_link == &path->head) {
 					return EOK;
 				}
@@ -1072,6 +1206,7 @@
 
 /**
- *
- * @return
+ * Allocates and initializes new usage path structure.
+ *
+ * @return Initialized usage path structure
  */
 usb_hid_report_path_t *usb_hid_report_path(void)
@@ -1079,5 +1214,5 @@
 	usb_hid_report_path_t *path;
 	path = malloc(sizeof(usb_hid_report_path_t));
-	if(!path){
+	if(path == NULL){
 		return NULL;
 	}
@@ -1086,4 +1221,5 @@
 		path->report_id = 0;
 		list_initialize(&path->link);
+		list_initialize(&path->head);
 		return path;
 	}
@@ -1091,13 +1227,17 @@
 
 /**
- *
- * @param path
+ * Releases given usage path structure.
+ *
+ * @param path usage path structure to release
  * @return void
  */
 void usb_hid_report_path_free(usb_hid_report_path_t *path)
 {
-	while(!list_empty(&path->link)){
+	while(!list_empty(&path->head)){
 		usb_hid_report_remove_last_item(path);
 	}
+
+	list_remove(&path->link);
+	free(path);
 }
 
@@ -1106,11 +1246,12 @@
  * Clone content of given usage path to the new one
  *
- * @param usage_path
- * @return
+ * @param usage_path Usage path structure to clone
+ * @return New copy of given usage path structure
  */
 usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path)
 {
+	link_t *path_link;
 	usb_hid_report_usage_path_t *path_item;
-	link_t *path_link;
+	usb_hid_report_usage_path_t *new_path_item;
 	usb_hid_report_path_t *new_usage_path = usb_hid_report_path ();
 
@@ -1118,13 +1259,26 @@
 		return NULL;
 	}
-	
-	if(list_empty(&usage_path->link)){
+
+	new_usage_path->report_id = usage_path->report_id;
+	
+	if(list_empty(&usage_path->head)){
 		return new_usage_path;
 	}
 
-	path_link = usage_path->link.next;
-	while(path_link != &usage_path->link) {
+	path_link = usage_path->head.next;
+	while(path_link != &usage_path->head) {
 		path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, link);
-		usb_hid_report_path_append_item (new_usage_path, path_item->usage_page, path_item->usage);
+		new_path_item = malloc(sizeof(usb_hid_report_usage_path_t));
+		if(new_path_item == NULL) {
+			return NULL;
+		}
+		
+		list_initialize (&new_path_item->link);		
+		new_path_item->usage_page = path_item->usage_page;
+		new_path_item->usage = path_item->usage;		
+		new_path_item->flags = path_item->flags;		
+		
+		list_append(&new_path_item->link, &new_usage_path->head);
+		new_usage_path->depth++;
 
 		path_link = path_link->next;
@@ -1137,35 +1291,39 @@
 /*** OUTPUT API **/
 
-/** Allocates output report buffer
- *
- * @param parser
- * @param size
- * @return
- */
-uint8_t *usb_hid_report_output(usb_hid_report_parser_t *parser, size_t *size)
-{
-	if(parser == NULL) {
+/** 
+ * Allocates output report buffer for output report
+ *
+ * @param parser Report parsed structure
+ * @param size Size of returned buffer
+ * @param report_id Report id of created output report
+ * @return Returns allocated output buffer for specified output
+ */
+uint8_t *usb_hid_report_output(usb_hid_report_t *report, size_t *size, uint8_t report_id)
+{
+	if(report == NULL) {
 		*size = 0;
 		return NULL;
 	}
-	
-	// read the last output report item
-	usb_hid_report_item_t *last;
-	link_t *link;
-
-	link = parser->output.prev;
-	if(link != &parser->output) {
-		last = list_get_instance(link, usb_hid_report_item_t, link);
-		*size = (last->offset + (last->size * last->count)) / 8;
-
-		uint8_t *buffer = malloc(sizeof(uint8_t) * (*size));
-		memset(buffer, 0, sizeof(uint8_t) * (*size));
-		usb_log_debug("output buffer: %s\n", usb_debug_str_buffer(buffer, *size, 0));
-
-		return buffer;
+
+	link_t *report_it = report->reports.next;
+	usb_hid_report_description_t *report_des = NULL;
+	while(report_it != &report->reports) {
+		report_des = list_get_instance(report_it, usb_hid_report_description_t, link);
+		if((report_des->report_id == report_id) && (report_des->type == USB_HID_REPORT_TYPE_OUTPUT)){
+			break;
+		}
+
+		report_it = report_it->next;
+	}
+
+	if(report_des == NULL){
+		*size = 0;
+		return NULL;
 	}
 	else {
-		*size = 0;		
-		return NULL;
+		*size = (report_des->bit_length + (8 - 1))/8;
+		uint8_t *ret = malloc((*size) * sizeof(uint8_t));
+		memset(ret, 0, (*size) * sizeof(uint8_t));
+		return ret;
 	}
 }
@@ -1175,5 +1333,5 @@
  *
  * @param output Output report buffer
- * @return
+ * @return void
  */
 void usb_hid_report_output_free(uint8_t *output)
@@ -1187,30 +1345,39 @@
 /** Returns size of output for given usage path 
  *
- * @param parser
- * @param path
- * @param flags
- * @return
- */
-size_t usb_hid_report_output_size(usb_hid_report_parser_t *parser,
+ * @param parser Opaque report parser structure
+ * @param path Usage path specified which items will be thought for the output
+ * @param flags Flags of usage path structure comparison
+ * @return Number of items matching the given usage path
+ */
+size_t usb_hid_report_output_size(usb_hid_report_t *report,
                                   usb_hid_report_path_t *path, int flags)
 {
-	size_t ret = 0;
-	link_t *item;
-	usb_hid_report_item_t *report_item;
-
-	if(parser == NULL) {
+	size_t ret = 0;	
+	usb_hid_report_description_t *report_des;
+
+	if(report == NULL) {
 		return 0;
 	}
 
-	item = parser->output.next;
-	while(&parser->output != item) {
-		report_item = list_get_instance(item, usb_hid_report_item_t, link);
-		if(!USB_HID_ITEM_FLAG_CONSTANT(report_item->item_flags) &&
-		   (usb_hid_report_compare_usage_path(report_item->usage_path, path, flags) == EOK)) {
-			ret += report_item->count;
-		}
-
-		item = item->next;
-	} 
+	report_des = usb_hid_report_find_description (report, path->report_id, USB_HID_REPORT_TYPE_OUTPUT);
+	if(report_des == NULL){
+		return 0;
+	}
+	
+	link_t *field_it = report_des->report_items.next;
+	usb_hid_report_field_t *field;
+	while(field_it != &report_des->report_items) {
+
+		field = list_get_instance(field_it, usb_hid_report_field_t, link);
+		if(USB_HID_ITEM_FLAG_CONSTANT(field->item_flags) == 0){
+			usb_hid_report_path_append_item (field->collection_path, field->usage_page, field->usage);
+			if(usb_hid_report_compare_usage_path (field->collection_path, path, flags) == EOK) {
+				ret++;
+			}
+			usb_hid_report_remove_last_item (field->collection_path);
+		}
+		
+		field_it = field_it->next;
+	}
 
 	return ret;
@@ -1218,65 +1385,55 @@
 }
 
-/** Updates the output report buffer by translated given data 
- *
- * @param parser
- * @param path
- * @param flags
- * @param buffer
- * @param size
- * @param data
- * @param data_size
- * @return
- */
-int usb_hid_report_output_translate(usb_hid_report_parser_t *parser,
-                                    usb_hid_report_path_t *path, int flags,
-                                    uint8_t *buffer, size_t size,
-                                    int32_t *data, size_t data_size)
-{
-	usb_hid_report_item_t *report_item;
+/** Makes the output report buffer for data given in the report structure
+ *
+ * @param parser Opaque report parser structure
+ * @param path Usage path specifing which parts of output will be set
+ * @param flags Usage path structure comparison flags
+ * @param buffer Output buffer
+ * @param size Size of output buffer
+ * @return Error code
+ */
+int usb_hid_report_output_translate(usb_hid_report_t *report, uint8_t report_id,
+                                    uint8_t *buffer, size_t size)
+{
 	link_t *item;	
-	size_t idx=0;
-	int i=0;
 	int32_t value=0;
 	int offset;
 	int length;
 	int32_t tmp_value;
-	size_t offset_prefix = 0;
-	
-	if(parser == NULL) {
+	
+	if(report == NULL) {
 		return EINVAL;
 	}
 
-	if(parser->use_report_id != 0) {
-		buffer[0] = path->report_id;
-		offset_prefix = 8;
+	if(report->use_report_ids != 0) {
+		buffer[0] = report_id;		
 	}
 
 	usb_log_debug("OUTPUT BUFFER: %s\n", usb_debug_str_buffer(buffer,size, 0));
-	usb_log_debug("OUTPUT DATA[0]: %d, DATA[1]: %d, DATA[2]: %d\n", data[0], data[1], data[2]);
-
-	item = parser->output.next;	
-	while(item != &parser->output) {
-		report_item = list_get_instance(item, usb_hid_report_item_t, link);
-
-		for(i=0; i<report_item->count; i++) {
-
-			if(idx >= data_size) {
-				break;
-			}
-
-			if((USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0) ||
-				((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0))) {
+	
+	usb_hid_report_description_t *report_des;
+	report_des = usb_hid_report_find_description (report, report_id, USB_HID_REPORT_TYPE_OUTPUT);
+	if(report_des == NULL){
+		return EINVAL;
+	}
+
+	usb_hid_report_field_t *report_item;	
+	item = report_des->report_items.next;	
+	while(item != &report_des->report_items) {
+		report_item = list_get_instance(item, usb_hid_report_field_t, link);
+
+			if(USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0) {
 					
-//				// variable item
-				value = usb_hid_translate_data_reverse(report_item, data[idx++]);
-				offset = report_item->offset + (i * report_item->size) + offset_prefix;
+				// array
+				value = usb_hid_translate_data_reverse(report_item, report_item->value);
+				offset = report_item->offset;
 				length = report_item->size;
 			}
 			else {
-				//bitmap
-				value += usb_hid_translate_data_reverse(report_item, data[idx++]);
-				offset = report_item->offset + offset_prefix;
-				length = report_item->size * report_item->count;
+				// variable item
+				value  = usb_hid_translate_data_reverse(report_item, report_item->value);
+				offset = report_item->offset;
+				length = report_item->size;
 			}
 
@@ -1297,28 +1454,36 @@
 			}
 			else {
-				// je to ve dvou!! FIXME: melo by to umet delsi jak 2
-
-				// konec prvniho -- dolni x bitu
-				tmp_value = value;
-				tmp_value = tmp_value & ((1 << (8-(offset%8)))-1);				
-				tmp_value = tmp_value << (offset%8);
-
+				int i = 0;
 				uint8_t mask = 0;
-				mask = ~(((1 << (8-(offset%8)))-1) << (offset%8));
-				buffer[offset/8] = (buffer[offset/8] & mask) | tmp_value;
-
-				// a ted druhej -- hornich length-x bitu
-				value = value >> (8 - (offset % 8));
-				value = value & ((1 << (length - (8 - (offset % 8)))) - 1);
+				for(i = (offset/8); i <= ((offset+length-1)/8); i++) {
+					if(i == (offset/8)) {
+						tmp_value = value;
+						tmp_value = tmp_value & ((1 << (8-(offset%8)))-1);				
+						tmp_value = tmp_value << (offset%8);
+	
+						mask = ~(((1 << (8-(offset%8)))-1) << (offset%8));
+						buffer[i] = (buffer[i] & mask) | tmp_value;			
+					}
+					else if (i == ((offset + length -1)/8)) {
+						
+						value = value >> (length - ((offset + length) % 8));
+						value = value & ((1 << (length - ((offset + length) % 8))) - 1);
 				
-				mask = ((1 << (length - (8 - (offset % 8)))) - 1);
-				buffer[(offset+length-1)/8] = (buffer[(offset+length-1)/8] & mask) | value;
-			}
-
-		}
-
+						mask = (1 << (length - ((offset + length) % 8))) - 1;
+						buffer[i] = (buffer[i] & mask) | value;
+					}
+					else {
+						buffer[i] = value & (0xFF << i);
+					}
+				}
+			}
+
+
+		// reset value
+		report_item->value = 0;
+		
 		item = item->next;
 	}
-
+	
 	usb_log_debug("OUTPUT BUFFER: %s\n", usb_debug_str_buffer(buffer,size, 0));
 
@@ -1327,10 +1492,10 @@
 
 /**
- *
- * @param item
- * @param value
- * @return
- */
-int32_t usb_hid_translate_data_reverse(usb_hid_report_item_t *item, int value)
+ * Translate given data for putting them into the outoput report
+ * @param item Report item structure
+ * @param value Value to translate
+ * @return ranslated value
+ */
+uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item, int value)
 {
 	int ret=0;
@@ -1341,12 +1506,13 @@
 	}
 
+	if((item->physical_minimum == 0) && (item->physical_maximum == 0)){
+		item->physical_minimum = item->logical_minimum;
+		item->physical_maximum = item->logical_maximum;			
+	}
+	
+
 	if((USB_HID_ITEM_FLAG_VARIABLE(item->item_flags) == 0)) {
 
 		// variable item
-		if((item->physical_minimum == 0) && (item->physical_maximum == 0)) {
-			item->physical_minimum = item->logical_minimum;
-			item->physical_maximum = item->logical_maximum;
-		}
-
 		if(item->physical_maximum == item->physical_minimum){
 		    resolution = 1;
@@ -1371,9 +1537,17 @@
 	}
 
-
-	return ret;
-}
-
-
+	if((item->logical_minimum < 0) || (item->logical_maximum < 0)){
+		return USB_HID_INT32_TO_UINT32(ret, item->size);
+	}
+	return (int32_t)ret;
+}
+
+/**
+ * Sets report id in usage path structure
+ *
+ * @param path Usage path structure
+ * @param report_id Report id to set
+ * @return Error code
+ */
 int usb_hid_report_path_set_report_id(usb_hid_report_path_t *path, uint8_t report_id)
 {
@@ -1383,4 +1557,59 @@
 
 	path->report_id = report_id;
+	return EOK;
+}
+
+/**
+ *
+ *
+ *
+ *
+ *
+ */
+int usb_hid_report_output_set_data(usb_hid_report_t *report, 
+                                   usb_hid_report_path_t *path, int flags, 
+                                  int *data, size_t data_size)
+{
+	size_t data_idx = 0;
+	if(report == NULL){
+		return EINVAL;
+	}
+
+	usb_hid_report_description_t *report_des;
+	report_des = usb_hid_report_find_description (report, path->report_id, 
+	                                              USB_HID_REPORT_TYPE_OUTPUT);
+	if(report_des == NULL){
+		return EINVAL;
+	}
+
+	usb_hid_report_field_t *field;
+	link_t *field_it = report_des->report_items.next;	
+	while(field_it != &report_des->report_items){
+
+		field = list_get_instance(field_it, usb_hid_report_field_t, link);		
+		if(USB_HID_ITEM_FLAG_CONSTANT(field->item_flags) == 0) {
+			usb_hid_report_path_append_item (field->collection_path, field->usage_page, field->usage);
+			if(usb_hid_report_compare_usage_path (field->collection_path, path, 
+		                                      flags) == EOK) {
+				if(data_idx < data_size) {
+					if((data[data_idx] >= field->physical_minimum) && (data[data_idx] >= field->physical_minimum)) {
+						field->value = data[data_idx];
+					}
+					else {
+						return ERANGE;
+					}
+
+					data_idx++;
+				}
+				else {
+					field->value = 0;
+				}
+			}
+			usb_hid_report_remove_last_item (field->collection_path);
+		}
+		
+		field_it = field_it->next;
+	}
+
 	return EOK;
 }
@@ -1400,4 +1629,89 @@
 }
 
+
+usb_hid_report_field_t *usb_hid_report_get_sibling(usb_hid_report_t *report, 
+							usb_hid_report_field_t *field, 
+                            usb_hid_report_path_t *path, int flags, 
+                            usb_hid_report_type_t type)
+{
+	usb_hid_report_description_t *report_des = usb_hid_report_find_description (report, path->report_id, type);
+	link_t *field_it;
+	
+	if(report_des == NULL){
+		return NULL;
+	}
+
+	if(field == NULL){
+		// vezmu prvni co mathuje podle path!!
+		field_it = report_des->report_items.next;
+	}
+	else {
+		field_it = field->link.next;
+	}
+
+	while(field_it != &report_des->report_items) {
+		field = list_get_instance(field_it, usb_hid_report_field_t, link);
+
+		if(USB_HID_ITEM_FLAG_CONSTANT(field->item_flags) == 0) {
+			usb_hid_report_path_append_item (field->collection_path, field->usage_page, field->usage);
+			if(usb_hid_report_compare_usage_path (field->collection_path, path, flags) == EOK){
+				usb_hid_report_remove_last_item (field->collection_path);
+				return field;
+			}
+			usb_hid_report_remove_last_item (field->collection_path);
+		}
+		field_it = field_it->next;
+	}
+
+	return NULL;
+}
+
+uint8_t usb_hid_report_get_report_id(usb_hid_report_t *report, uint8_t report_id, usb_hid_report_type_t type)
+{
+	if(report == NULL){
+		return 0;
+	}
+
+	usb_hid_report_description_t *report_des;
+	link_t *report_it;
+	
+	if(report_id == 0) {
+		report_it = usb_hid_report_find_description (report, report_id, type)->link.next;		
+	}
+	else {
+		report_it = report->reports.next;
+	}
+
+	while(report_it != &report->reports) {
+		report_des = list_get_instance(report_it, usb_hid_report_description_t, link);
+		if(report_des->type == type){
+			return report_des->report_id;
+		}
+	}
+
+	return 0;
+}
+
+void usb_hid_report_reset_local_items(usb_hid_report_item_t *report_item)
+{
+	if(report_item == NULL)	{
+		return;
+	}
+	
+	report_item->usages_count = 0;
+	memset(report_item->usages, 0, USB_HID_MAX_USAGES);
+	
+	report_item->extended_usage_page = 0;
+	report_item->usage_minimum = 0;
+	report_item->usage_maximum = 0;
+	report_item->designator_index = 0;
+	report_item->designator_minimum = 0;
+	report_item->designator_maximum = 0;
+	report_item->string_index = 0;
+	report_item->string_minimum = 0;
+	report_item->string_maximum = 0;
+
+	return;
+}
 /**
  * @}
Index: uspace/lib/usb/src/hidreport.c
===================================================================
--- uspace/lib/usb/src/hidreport.c	(revision 564a2b33fa6a9365cde0a9228b5722048647e566)
+++ uspace/lib/usb/src/hidreport.c	(revision 308a5d52410eedc0ee1ce72952d26a931def9c82)
@@ -164,7 +164,7 @@
 
 int usb_hid_process_report_descriptor(usb_device_t *dev, 
-    usb_hid_report_parser_t *parser)
+    usb_hid_report_t *report)
 {
-	if (dev == NULL || parser == NULL) {
+	if (dev == NULL || report == NULL) {
 		usb_log_error("Failed to process Report descriptor: wrong "
 		    "parameters given.\n");
@@ -189,5 +189,5 @@
 	assert(report_desc != NULL);
 	
-	rc = usb_hid_parse_report_descriptor(parser, report_desc, report_size);
+	rc = usb_hid_parse_report_descriptor(report, report_desc, report_size);
 	if (rc != EOK) {
 		usb_log_error("Problem parsing Report descriptor: %s.\n",
@@ -197,5 +197,5 @@
 	}
 	
-	usb_hid_descriptor_print(parser);
+	usb_hid_descriptor_print(report);
 	free(report_desc);
 	
