Index: .bzrignore
===================================================================
--- .bzrignore	(revision 30db06c97ea02cfb2f8063707068ae167fc12f82)
+++ .bzrignore	(revision c081780ef0a9adfc657f2215a4c71ee184cfd775)
@@ -89,4 +89,5 @@
 ./uspace/drv/usbhid/usbhid
 ./uspace/drv/usbmid/usbmid
+./uspace/drv/usbmouse/usbmouse
 ./uspace/drv/vhc/vhc
 ./uspace/srv/bd/ata_bd/ata_bd
Index: boot/arch/amd64/Makefile.inc
===================================================================
--- boot/arch/amd64/Makefile.inc	(revision 30db06c97ea02cfb2f8063707068ae167fc12f82)
+++ boot/arch/amd64/Makefile.inc	(revision c081780ef0a9adfc657f2215a4c71ee184cfd775)
@@ -48,4 +48,5 @@
 	usbhid \
 	usbmid \
+	usbmouse \
 	vhc
 
Index: uspace/Makefile
===================================================================
--- uspace/Makefile	(revision 30db06c97ea02cfb2f8063707068ae167fc12f82)
+++ uspace/Makefile	(revision c081780ef0a9adfc657f2215a4c71ee184cfd775)
@@ -122,4 +122,5 @@
 		drv/usbhub \
 		drv/usbmid \
+		drv/usbmouse \
 		drv/vhc
 endif
@@ -138,4 +139,5 @@
 		drv/usbhub \
 		drv/usbmid \
+		drv/usbmouse \
 		drv/vhc
 endif
Index: uspace/doc/doxygroups.h
===================================================================
--- uspace/doc/doxygroups.h	(revision 30db06c97ea02cfb2f8063707068ae167fc12f82)
+++ uspace/doc/doxygroups.h	(revision c081780ef0a9adfc657f2215a4c71ee184cfd775)
@@ -245,4 +245,10 @@
 
 	/**
+	 * @defgroup drvusbmouse USB mouse driver
+	 * @ingroup usb
+	 * @brief USB driver for mouse with boot protocol.
+	 */
+
+	/**
 	 * @defgroup drvusbuhci UHCI driver
 	 * @ingroup usb
Index: uspace/drv/usbmouse/Makefile
===================================================================
--- uspace/drv/usbmouse/Makefile	(revision c081780ef0a9adfc657f2215a4c71ee184cfd775)
+++ uspace/drv/usbmouse/Makefile	(revision c081780ef0a9adfc657f2215a4c71ee184cfd775)
@@ -0,0 +1,40 @@
+#
+# Copyright (c) 2011 Vojtech Horky
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+USPACE_PREFIX = ../..
+LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBUSB_PREFIX)/libusb.a
+EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBUSB_PREFIX)/include -I.
+
+BINARY = usbmouse
+
+SOURCES = \
+	init.c \
+	main.c \
+	mouse.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/drv/usbmouse/init.c
===================================================================
--- uspace/drv/usbmouse/init.c	(revision c081780ef0a9adfc657f2215a4c71ee184cfd775)
+++ uspace/drv/usbmouse/init.c	(revision c081780ef0a9adfc657f2215a4c71ee184cfd775)
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2011 Vojtech Horky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup drvusbmouse
+ * @{
+ */
+/**
+ * @file
+ * Initialization routines for USB mouse driver.
+ */
+#include "mouse.h"
+#include <usb/debug.h>
+#include <usb/classes/hid.h>
+#include <usb/request.h>
+#include <errno.h>
+
+#if 0
+/** Mouse polling endpoint description for boot protocol subclass. */
+static usb_endpoint_description_t poll_endpoint_description = {
+	.transfer_type = USB_TRANSFER_INTERRUPT,
+	.direction = USB_DIRECTION_IN,
+	.interface_class = USB_CLASS_HID,
+	.interface_subclass = USB_HID_SUBCLASS_BOOT,
+	.interface_protocol = USB_HID_PROTOCOL_MOUSE,
+	.flags = 0
+};
+#endif
+
+
+int usb_mouse_create(ddf_dev_t *dev)
+{
+	usb_mouse_t *mouse = malloc(sizeof(usb_mouse_t));
+	if (mouse == NULL) {
+		return ENOMEM;
+	}
+	mouse->device = dev;
+
+	int rc;
+
+	/* Initialize the backing connection. */
+	rc = usb_device_connection_initialize_from_device(&mouse->wire, dev);
+	if (rc != EOK) {
+		goto leave;
+	}
+
+	/* Initialize the default control pipe. */
+	rc = usb_endpoint_pipe_initialize_default_control(&mouse->ctrl_pipe,
+	    &mouse->wire);
+	if (rc != EOK) {
+		goto leave;
+	}
+
+	/* FIXME: initialize to the proper endpoint. */
+	rc = usb_endpoint_pipe_initialize(&mouse->poll_pipe, &mouse->wire,
+	    1, USB_TRANSFER_INTERRUPT, 8, USB_DIRECTION_IN);
+	if (rc != EOK) {
+		goto leave;
+	}
+
+	/* Create DDF function. */
+	mouse->mouse_fun = ddf_fun_create(dev, fun_exposed, "mouse");
+	if (mouse->mouse_fun == NULL) {
+		rc = ENOMEM;
+		goto leave;
+	}
+	rc = ddf_fun_bind(mouse->mouse_fun);
+	if (rc != EOK) {
+		goto leave;
+	}
+
+	/* Everything allright. */
+	dev->driver_data = mouse;
+
+	return EOK;
+
+leave:
+	free(mouse);
+
+	return rc;
+}
+
+/**
+ * @}
+ */
Index: uspace/drv/usbmouse/main.c
===================================================================
--- uspace/drv/usbmouse/main.c	(revision c081780ef0a9adfc657f2215a4c71ee184cfd775)
+++ uspace/drv/usbmouse/main.c	(revision c081780ef0a9adfc657f2215a4c71ee184cfd775)
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2011 Vojtech Horky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup drvusbmouse
+ * @{
+ */
+/**
+ * @file
+ * Main routines of USB boot protocol mouse driver.
+ */
+#include "mouse.h"
+#include <usb/debug.h>
+#include <errno.h>
+#include <str_error.h>
+
+static int usbmouse_add_device(ddf_dev_t *dev)
+{
+	usb_log_info("Detected USB mouse to control.\n");
+
+	int rc = usb_mouse_create(dev);
+	if (rc != EOK) {
+		usb_log_error("Failed to initialize device driver: %s.\n",
+		    str_error(rc));
+		return rc;
+	}
+
+	fid_t poll_fibril = fibril_create(usb_mouse_polling_fibril, dev);
+	if (poll_fibril == 0) {
+		usb_log_error("Failed to initialize polling fibril.\n");
+		/* FIXME: free allocated resources. */
+		return ENOMEM;
+	}
+
+	fibril_add_ready(poll_fibril);
+
+	return EOK;
+}
+
+static driver_ops_t mouse_driver_ops = {
+	.add_device = usbmouse_add_device,
+};
+
+static driver_t mouse_driver = {
+	.name = NAME,
+	.driver_ops = &mouse_driver_ops
+};
+
+int main(int argc, char *argv[])
+{
+	usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME);
+
+	return ddf_driver_main(&mouse_driver);
+}
+
+/**
+ * @}
+ */
Index: uspace/drv/usbmouse/mouse.c
===================================================================
--- uspace/drv/usbmouse/mouse.c	(revision c081780ef0a9adfc657f2215a4c71ee184cfd775)
+++ uspace/drv/usbmouse/mouse.c	(revision c081780ef0a9adfc657f2215a4c71ee184cfd775)
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2011 Vojtech Horky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup drvusbmouse
+ * @{
+ */
+/**
+ * @file
+ * Actual handling of USB mouse protocol.
+ */
+#include "mouse.h"
+#include <usb/debug.h>
+#include <errno.h>
+
+int usb_mouse_polling_fibril(void *arg)
+{
+	assert(arg != NULL);
+	ddf_dev_t *dev = (ddf_dev_t *) arg;
+	usb_mouse_t *mouse = (usb_mouse_t *) dev->driver_data;
+
+	assert(mouse);
+
+	while (true) {
+		async_usleep(10 * 1000);
+
+		uint8_t buffer[8];
+		size_t actual_size;
+
+		/* FIXME: check for errors. */
+		usb_endpoint_pipe_start_session(&mouse->poll_pipe);
+
+		usb_endpoint_pipe_read(&mouse->poll_pipe, buffer, 8, &actual_size);
+
+		usb_endpoint_pipe_end_session(&mouse->poll_pipe);
+
+		uint8_t butt = buffer[0];
+		char str_buttons[4] = {
+			butt & 1 ? '#' : '.',
+			butt & 2 ? '#' : '.',
+			butt & 4 ? '#' : '.',
+			0
+		};
+
+		int shift_x = ((int) buffer[1]) - 127;
+		int shift_y = ((int) buffer[2]) - 127;
+		int wheel = ((int) buffer[3]) - 127;
+
+		if (buffer[1] == 0) {
+			shift_x = 0;
+		}
+		if (buffer[2] == 0) {
+			shift_y = 0;
+		}
+		if (buffer[3] == 0) {
+			wheel = 0;
+		}
+
+		usb_log_debug("buttons=%s  dX=%+3d  dY=%+3d  wheel=%+3d\n",
+		   str_buttons, shift_x, shift_y, wheel);
+	}
+
+	return EOK;
+}
+
+
+/**
+ * @}
+ */
Index: uspace/drv/usbmouse/mouse.h
===================================================================
--- uspace/drv/usbmouse/mouse.h	(revision c081780ef0a9adfc657f2215a4c71ee184cfd775)
+++ uspace/drv/usbmouse/mouse.h	(revision c081780ef0a9adfc657f2215a4c71ee184cfd775)
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2011 Vojtech Horky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup drvusbmouse
+ * @{
+ */
+/**
+ * @file
+ * Common definitions for USB mouse driver.
+ */
+#ifndef USBMOUSE_MOUSE_H_
+#define USBMOUSE_MOUSE_H_
+
+#include <ddf/driver.h>
+#include <usb/pipes.h>
+
+#define NAME "usbmouse"
+
+typedef struct {
+	ddf_dev_t *device;
+	ddf_fun_t *mouse_fun;
+	usb_device_connection_t wire;
+	usb_endpoint_pipe_t ctrl_pipe;
+	usb_endpoint_pipe_t poll_pipe;
+} usb_mouse_t;
+
+int usb_mouse_create(ddf_dev_t *);
+
+int usb_mouse_polling_fibril(void *);
+
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/usbmouse/usbmouse.ma
===================================================================
--- uspace/drv/usbmouse/usbmouse.ma	(revision c081780ef0a9adfc657f2215a4c71ee184cfd775)
+++ uspace/drv/usbmouse/usbmouse.ma	(revision c081780ef0a9adfc657f2215a4c71ee184cfd775)
@@ -0,0 +1,1 @@
+100 usb&interface&class=HID&subclass=0x01&protocol=0x02
