Index: uspace/lib/usbvirt/src/stdreq.c
===================================================================
--- uspace/lib/usbvirt/src/stdreq.c	(revision 0eddb76bcbabe8f448e8a6f610dcc98ec480bed4)
+++ uspace/lib/usbvirt/src/stdreq.c	(revision 84439d7c2ebefbea307e636b8e8316fb8f84e090)
@@ -41,4 +41,6 @@
 
 
+typedef int (*usbvirt_stdreq_handler_t)(usbvirt_device_t *,
+usb_device_request_setup_packet_t *, uint8_t *);
 
 /*
@@ -51,7 +53,9 @@
 /** GET_DESCRIPTOR handler. */
 static int handle_get_descriptor(usbvirt_device_t *device,
-    uint8_t type, uint8_t index, uint16_t language,
-    uint16_t length)
-{
+    usb_device_request_setup_packet_t *setup_packet, uint8_t *extra_data)
+{
+	uint8_t type = setup_packet->value_high;
+	uint8_t index = setup_packet->value_low;
+
 	/* 
 	 * Standard device descriptor.
@@ -110,7 +114,10 @@
 /** SET_ADDRESS handler. */
 static int handle_set_address(usbvirt_device_t *device,
-    uint16_t new_address,
-    uint16_t zero1, uint16_t zero2)
-{
+    usb_device_request_setup_packet_t *setup_packet, uint8_t *extra_data)
+{
+	uint16_t new_address = setup_packet->value;
+	uint16_t zero1 = setup_packet->index;
+	uint16_t zero2 = setup_packet->length;
+
 	if ((zero1 != 0) || (zero2 != 0)) {
 		return EINVAL;
@@ -128,7 +135,10 @@
 /** SET_CONFIGURATION handler. */
 static int handle_set_configuration(usbvirt_device_t *device,
-    uint16_t configuration_value,
-    uint16_t zero1, uint16_t zero2)
-{
+    usb_device_request_setup_packet_t *setup_packet, uint8_t *extra_data)
+{
+	uint16_t configuration_value = setup_packet->value;
+	uint16_t zero1 = setup_packet->index;
+	uint16_t zero2 = setup_packet->length;
+
 	if ((zero1 != 0) || (zero2 != 0)) {
 		return EINVAL;
@@ -167,43 +177,41 @@
 }
 
-#define HANDLE_REQUEST(request, data, type, dev, user_callback, default_handler) \
-	do { \
-		if ((request)->request == (type)) { \
-			int _rc = EFORWARD; \
-			if (((dev)->ops) && ((dev)->ops->standard_request_ops) \
-			    && ((dev)->ops->standard_request_ops->user_callback)) { \
-				_rc = (dev)->ops->standard_request_ops->\
-				    user_callback(dev, request, data); \
-			} \
-			if (_rc == EFORWARD) { \
-				default_handler; \
-			} \
-			return _rc; \
-		} \
-	} while (false)
+static usbvirt_stdreq_handler_t local_handlers[USB_DEVREQ_LAST_STD] = {
+	[USB_DEVREQ_GET_DESCRIPTOR] = handle_get_descriptor,
+	[USB_DEVREQ_SET_ADDRESS] = handle_set_address,
+	[USB_DEVREQ_SET_CONFIGURATION] = handle_set_configuration
+};
 
 /** Handle standard device request. */
 int handle_std_request(usbvirt_device_t *device,
-    usb_device_request_setup_packet_t *request, uint8_t *data)
-{
+    usb_device_request_setup_packet_t *request_packet, uint8_t *data)
+{
+	int request = request_packet->request;
+
 	device->lib_debug(device, 3, USBVIRT_DEBUGTAG_CONTROL_PIPE_ZERO,
-	    "handling standard request %d", request->request);
-	
-	HANDLE_REQUEST(request, data, USB_DEVREQ_GET_DESCRIPTOR,
-	    device, on_get_descriptor,
-	    handle_get_descriptor(device, request->value_high, request->value_low,
-	        request->index, request->length));
-	
-	HANDLE_REQUEST(request, data, USB_DEVREQ_SET_ADDRESS,
-	    device, on_set_address,
-	    handle_set_address(device, request->value,
-	        request->index, request->length));
-	
-	HANDLE_REQUEST(request, data, USB_DEVREQ_SET_CONFIGURATION,
-	    device, on_set_configuration,
-	    handle_set_configuration(device, request->value,
-	        request->index, request->length));
-	
-	return ENOTSUP;
+	    "handling standard request %d", request);
+
+	if (request >= USB_DEVREQ_LAST_STD) {
+		return ENOTSUP;
+	}
+	
+	int rc = EFORWARD;
+	if ((device->ops)
+	    && (device->ops->on_standard_request[request])) {
+		rc = device->ops->on_standard_request[request](device,
+		    request_packet, data);
+	}
+
+	if (rc == EFORWARD) {
+		if (local_handlers[request]) {
+			rc = local_handlers[request](device,
+			    request_packet, data);
+		} else {
+			rc = ENOTSUP;
+		}
+	}
+
+	assert(rc != EFORWARD);
+	return rc;
 }
 
