Index: uspace/lib/usbdev/src/devpoll.c
===================================================================
--- uspace/lib/usbdev/src/devpoll.c	(revision f6b2a76b0bcfe02adf5d21778437749ac56bc83f)
+++ uspace/lib/usbdev/src/devpoll.c	(revision 8b68bdfef6c3f6dfcee87b4f33a9f87f225f827d)
@@ -51,6 +51,6 @@
 	/** USB device to poll. */
 	usb_device_t *dev;
-	/** Device pipe to use for polling. */
-	size_t pipe_index;
+	/** Device enpoint mapping to use for polling. */
+	usb_endpoint_mapping_t *polling_mapping;
 	/** Size of the recieved data. */
 	size_t request_size;
@@ -72,10 +72,9 @@
 	const usb_device_auto_polling_t *params = &data->auto_polling;
 
-	usb_pipe_t *pipe
-	    = &data->dev->pipes[data->pipe_index].pipe;
+	usb_pipe_t *pipe = &data->polling_mapping->pipe;
 
 	if (params->debug > 0) {
 		const usb_endpoint_mapping_t *mapping
-		    = &data->dev->pipes[data->pipe_index];
+		    = data->polling_mapping;
 		usb_log_debug("Poll%p: started polling of `%s' - " \
 		    "interface %d (%s,%d,%d), %zuB/%zu.\n",
@@ -117,5 +116,6 @@
 			 */
 			usb_request_clear_endpoint_halt(
-			    &data->dev->ctrl_pipe, pipe->endpoint_no);
+			    usb_device_get_default_pipe(data->dev),
+			    pipe->endpoint_no);
 		}
 
@@ -175,8 +175,9 @@
 }
 
+
 /** Start automatic device polling over interrupt in pipe.
  *
- * @warning It is up to the callback to produce delays between individual
- * requests.
+ * The polling settings is copied thus it is okay to destroy the structure
+ * after this function returns.
  *
  * @warning There is no guarantee when the request to the device
@@ -185,7 +186,101 @@
  *
  * @param dev Device to be periodically polled.
+ * @param epm Endpoint mapping to use.
+ * @param polling Polling settings.
+ * @param request_size How many bytes to ask for in each request.
+ * @param arg Custom argument (passed as is to the callbacks).
+ * @return Error code.
+ * @retval EOK New fibril polling the device was already started.
+ */
+static int usb_device_auto_polling_internal(usb_device_t *dev,
+    usb_endpoint_mapping_t *epm, const usb_device_auto_polling_t *polling,
+    size_t request_size)
+{
+	if ((dev == NULL) || (polling == NULL) || (polling->on_data == NULL)) {
+		return EBADMEM;
+	}
+
+	if (request_size == 0)
+		return EINVAL;
+
+	if (!epm || (epm->pipe.transfer_type != USB_TRANSFER_INTERRUPT) ||
+	    (epm->pipe.direction != USB_DIRECTION_IN))
+		return EINVAL;
+
+
+	polling_data_t *polling_data = malloc(sizeof(polling_data_t));
+	if (polling_data == NULL) {
+		return ENOMEM;
+	}
+
+	/* Fill-in the data. */
+	polling_data->buffer = malloc(sizeof(request_size));
+	if (polling_data->buffer == NULL) {
+		free(polling_data);
+		return ENOMEM;
+	}
+	polling_data->request_size = request_size;
+	polling_data->dev = dev;
+	polling_data->polling_mapping = epm;
+
+	/* Copy provided settings. */
+	polling_data->auto_polling = *polling;
+
+	/* Negative value means use descriptor provided value. */
+	if (polling->delay < 0) {
+		polling_data->auto_polling.delay =
+		    epm->descriptor->poll_interval;
+	}
+
+	fid_t fibril = fibril_create(polling_fibril, polling_data);
+	if (fibril == 0) {
+		free(polling_data->buffer);
+		free(polling_data);
+		return ENOMEM;
+	}
+	fibril_add_ready(fibril);
+
+	/* Fibril launched. That fibril will free the allocated data. */
+
+	return EOK;
+}
+/** Start automatic device polling over interrupt in pipe.
+ *
+ * The polling settings is copied thus it is okay to destroy the structure
+ * after this function returns.
+ *
+ * @warning There is no guarantee when the request to the device
+ * will be sent for the first time (it is possible that this
+ * first request would be executed prior to return from this function).
+ *
+ * @param dev Device to be periodically polled.
  * @param pipe_index Index of the endpoint pipe used for polling.
+ * @param polling Polling settings.
+ * @param req_size How many bytes to ask for in each request.
+ * @param arg Custom argument (passed as is to the callbacks).
+ * @return Error code.
+ * @retval EOK New fibril polling the device was already started.
+ */
+int usb_device_auto_polling(usb_device_t *usb_dev, usb_endpoint_t ep,
+    const usb_device_auto_polling_t *polling, size_t req_size)
+{
+	usb_endpoint_mapping_t *epm = usb_device_get_mapped_ep(usb_dev, ep);
+	return usb_device_auto_polling_internal(usb_dev, epm, polling, req_size);
+}
+
+/** Start automatic device polling over interrupt in pipe.
+ *
+ * @warning It is up to the callback to produce delays between individual
+ * requests.
+ *
+ * @warning There is no guarantee when the request to the device
+ * will be sent for the first time (it is possible that this
+ * first request would be executed prior to return from this function).
+ *
+ * @param dev Device to be periodically polled.
+ * @param ep Endpoint  used for polling.
  * @param callback Callback when data are available.
  * @param request_size How many bytes to ask for in each request.
+ * @param delay NUmber of ms to wait between queries, -1 to use descriptor val.
  * @param terminated_callback Callback when polling is terminated.
  * @param arg Custom argument (passed as is to the callbacks).
@@ -193,5 +288,5 @@
  * @retval EOK New fibril polling the device was already started.
  */
-int usb_device_auto_poll(usb_device_t *dev, size_t pipe_index,
+int usb_device_auto_poll(usb_device_t *dev, usb_endpoint_t ep,
     usb_polling_callback_t callback, size_t request_size, int delay,
     usb_polling_terminted_callback_t terminated_callback, void *arg)
@@ -208,76 +303,38 @@
 	};
 
-	return usb_device_auto_polling(dev, pipe_index, &auto_polling,
-	   request_size);
-}
-
-/** Start automatic device polling over interrupt in pipe.
- *
- * The polling settings is copied thus it is okay to destroy the structure
- * after this function returns.
- *
- * @warning There is no guarantee when the request to the device
- * will be sent for the first time (it is possible that this
- * first request would be executed prior to return from this function).
- *
- * @param dev Device to be periodically polled.
- * @param pipe_index Index of the endpoint pipe used for polling.
- * @param polling Polling settings.
- * @param request_size How many bytes to ask for in each request.
- * @param arg Custom argument (passed as is to the callbacks).
- * @return Error code.
- * @retval EOK New fibril polling the device was already started.
- */
-int usb_device_auto_polling(usb_device_t *dev, size_t pipe_index,
-    const usb_device_auto_polling_t *polling,
-    size_t request_size)
-{
-	if ((dev == NULL) || (polling == NULL) || (polling->on_data == NULL)) {
-		return EBADMEM;
-	}
-
-	if (pipe_index >= dev->pipes_count || request_size == 0) {
-		return EINVAL;
-	}
-	if ((dev->pipes[pipe_index].pipe.transfer_type != USB_TRANSFER_INTERRUPT)
-	    || (dev->pipes[pipe_index].pipe.direction != USB_DIRECTION_IN)) {
-		return EINVAL;
-	}
-
-	polling_data_t *polling_data = malloc(sizeof(polling_data_t));
-	if (polling_data == NULL) {
-		return ENOMEM;
-	}
-
-	/* Fill-in the data. */
-	polling_data->buffer = malloc(sizeof(request_size));
-	if (polling_data->buffer == NULL) {
-		free(polling_data);
-		return ENOMEM;
-	}
-	polling_data->request_size = request_size;
-	polling_data->dev = dev;
-	polling_data->pipe_index = pipe_index;
-
-	/* Copy provided settings. */
-	polling_data->auto_polling = *polling;
-
-	/* Negative value means use descriptor provided value. */
-	if (polling->delay < 0) {
-		polling_data->auto_polling.delay =
-		    (int) dev->pipes[pipe_index].descriptor->poll_interval;
-	}
-
-	fid_t fibril = fibril_create(polling_fibril, polling_data);
-	if (fibril == 0) {
-		free(polling_data->buffer);
-		free(polling_data);
-		return ENOMEM;
-	}
-	fibril_add_ready(fibril);
-
-	/* Fibril launched. That fibril will free the allocated data. */
-
-	return EOK;
+	usb_endpoint_mapping_t *epm = usb_device_get_mapped_ep(dev, ep);
+	return usb_device_auto_polling_internal(
+	    dev, epm, &auto_polling, request_size);
+}
+
+int usb_device_auto_polling_desc(usb_device_t *usb_dev,
+    const usb_endpoint_description_t *desc,
+    const usb_device_auto_polling_t *polling, size_t req_size)
+{
+	usb_endpoint_mapping_t *epm =
+	    usb_device_get_mapped_ep_desc(usb_dev, desc);
+	return usb_device_auto_polling_internal(usb_dev, epm, polling, req_size);
+}
+
+int usb_device_auto_poll_desc(usb_device_t * usb_dev,
+    const usb_endpoint_description_t *desc, usb_polling_callback_t callback,
+    size_t req_size, int delay,
+    usb_polling_terminted_callback_t terminated_callback, void *arg)
+{
+	const usb_device_auto_polling_t auto_polling = {
+		.debug = 1,
+		.auto_clear_halt = true,
+		.delay = delay,
+		.max_failures = MAX_FAILED_ATTEMPTS,
+		.on_data = callback,
+		.on_polling_end = terminated_callback,
+		.on_error = NULL,
+		.arg = arg,
+	};
+
+	usb_endpoint_mapping_t *epm =
+	    usb_device_get_mapped_ep_desc(usb_dev, desc);
+	return usb_device_auto_polling_internal(
+	    usb_dev, epm, &auto_polling, req_size);
 }
 
