These functions makes USB driver's code simpler when dealing with endpoints
by avoiding them from accessing the endpoint's descriptor structure directly
when they only need to know the endpoint's transfer type and/or
direction.

Please, read each functions' documentation in order to know how to use
them.

Signed-off-by: Luiz Fernando N. Capitulino <[EMAIL PROTECTED]>
---
 drivers/usb/core/usb.c |  142 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/usb.h    |   14 +++++
 2 files changed, 156 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 184c246..224e325 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -675,6 +675,136 @@ int usb_get_current_frame_number(struct 
        return dev->bus->op->get_frame_number (dev);
 }
 
+/*
+ * usb_endpoint_dir_in - check whether the endpoint has IN direction
+ * @epd: endpoint to be checked
+ *
+ * Returns positive if the endpoint has IN direction, and zero else
+ */
+int usb_endpoint_dir_in(struct usb_endpoint_descriptor *epd)
+{
+       return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN);
+}
+
+/*
+ * usb_endpoint_dir_out - check whether the endpoint has OUT direction
+ * @epd: endpoint to be checked
+ *
+ * Returns positive if the endpoint has OUT direction, and zero else
+ */
+int usb_endpoint_dir_out(struct usb_endpoint_descriptor *epd)
+{
+       return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
+}
+
+/*
+ * usb_endpoint_xfer_bulk - check whether the endpoint has bulk transfer type
+ * @epd: endpoint to be checked
+ *
+ * Returns positive if the endpoint has bulk transfer type, and zero else
+ */
+int usb_endpoint_xfer_bulk(struct usb_endpoint_descriptor *epd)
+{
+       return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == 
USB_ENDPOINT_XFER_BULK);
+}
+
+/*
+ * usb_endpoint_xfer_int - check whether the endpoint has interrupt transfer
+ * type
+ * @epd: endpoint to be checked
+ *
+ * Returns positive if the endpoint has interrupt transfer type, and zero else
+ */
+int usb_endpoint_xfer_int(struct usb_endpoint_descriptor *epd)
+{
+       return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == 
USB_ENDPOINT_XFER_INT);
+}
+
+/*
+ * usb_endpoint_xfer_isoc - check whether the endpoint has isochronous transfer
+ * type
+ * @epd: endpoint to be checked
+ *
+ * Returns positive if the endpoint has isochronous transfer type, and zero
+ * else
+ */
+int usb_endpoint_xfer_isoc(struct usb_endpoint_descriptor *epd)
+{
+       return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == 
USB_ENDPOINT_XFER_ISOC);
+}
+
+/*
+ * usb_endpoint_is_bulk_in - check whether the endpoint has bulk transfer
+ * type and IN direction
+ * @epd: endpoint to be checked
+ *
+ * Returns positive if the endpoint is bulk IN, and zero else
+ */
+int usb_endpoint_is_bulk_in(struct usb_endpoint_descriptor *epd)
+{
+       return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_in(epd));
+}
+
+/*
+ * usb_endpoint_is_bulk_out - check whether the endpoint has bulk transfer
+ * type and OUT direction
+ * @epd: endpoint to be checked
+ *
+ * Returns positive if the endpoint is bulk OUT, and zero else
+ */
+int usb_endpoint_is_bulk_out(struct usb_endpoint_descriptor *epd)
+{
+       return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_out(epd));
+}
+
+/*
+ * usb_endpoint_is_int_in - check whether the endpoint has interrupt transfer
+ * type and IN direction
+ * @epd: endpoint to be checked
+ *
+ * Returns positive if the endpoint is interrupt IN, and zero else
+ */
+int usb_endpoint_is_int_in(struct usb_endpoint_descriptor *epd)
+{
+       return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd));
+}
+
+/*
+ * usb_endpoint_is_int_out - check whether the endpoint has interrupt transfer
+ * type and OUT direction
+ * @epd: endpoint to be checked
+ *
+ * Returns positive if the endpoint is interrupt OUT, and zero else
+ */
+int usb_endpoint_is_int_out(struct usb_endpoint_descriptor *epd)
+{
+       return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_out(epd));
+}
+
+/*
+ * usb_endpoint_is_isoc_in - check whether the endpoint has isochronous
+ * transfer type and IN direction
+ * @epd: endpoint to be checked
+ *
+ * Returns positive if the endpoint is isochronous IN, and zero else
+ */
+int usb_endpoint_is_isoc_in(struct usb_endpoint_descriptor *epd)
+{
+       return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_in(epd));
+}
+
+/*
+ * usb_endpoint_is_isoc_out - check whether the endpoint has isochronous
+ * transfer type and OUT direction
+ * @epd: endpoint to be checked
+ *
+ * Returns positive if the endpoint is isochronous OUT, and zero else
+ */
+int usb_endpoint_is_isoc_out(struct usb_endpoint_descriptor *epd)
+{
+       return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_out(epd));
+}
+
 /*-------------------------------------------------------------------*/
 /*
  * __usb_get_extra_descriptor() finds a descriptor of specific type in the
@@ -1215,6 +1345,18 @@ EXPORT_SYMBOL(__usb_get_extra_descriptor
 EXPORT_SYMBOL(usb_find_device);
 EXPORT_SYMBOL(usb_get_current_frame_number);
 
+EXPORT_SYMBOL(usb_endpoint_dir_in);
+EXPORT_SYMBOL(usb_endpoint_dir_out);
+EXPORT_SYMBOL(usb_endpoint_xfer_bulk);
+EXPORT_SYMBOL(usb_endpoint_xfer_int);
+EXPORT_SYMBOL(usb_endpoint_xfer_isoc);
+EXPORT_SYMBOL(usb_endpoint_is_bulk_in);
+EXPORT_SYMBOL(usb_endpoint_is_bulk_out);
+EXPORT_SYMBOL(usb_endpoint_is_int_in);
+EXPORT_SYMBOL(usb_endpoint_is_int_out);
+EXPORT_SYMBOL(usb_endpoint_is_isoc_in);
+EXPORT_SYMBOL(usb_endpoint_is_isoc_out);
+
 EXPORT_SYMBOL (usb_buffer_alloc);
 EXPORT_SYMBOL (usb_buffer_free);
 
diff --git a/include/linux/usb.h b/include/linux/usb.h
index d2bd0c8..e0b8116 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -464,6 +464,20 @@ static inline int usb_make_path (struct 
 
 /*-------------------------------------------------------------------------*/
 
+extern int usb_endpoint_dir_in(struct usb_endpoint_descriptor *epd);
+extern int usb_endpoint_dir_out(struct usb_endpoint_descriptor *epd);
+extern int usb_endpoint_xfer_bulk(struct usb_endpoint_descriptor *epd);
+extern int usb_endpoint_xfer_int(struct usb_endpoint_descriptor *epd);
+extern int usb_endpoint_xfer_isoc(struct usb_endpoint_descriptor *epd);
+extern int usb_endpoint_is_bulk_in(struct usb_endpoint_descriptor *epd);
+extern int usb_endpoint_is_bulk_out(struct usb_endpoint_descriptor *epd);
+extern int usb_endpoint_is_int_in(struct usb_endpoint_descriptor *epd);
+extern int usb_endpoint_is_int_out(struct usb_endpoint_descriptor *epd);
+extern int usb_endpoint_is_isoc_in(struct usb_endpoint_descriptor *epd);
+extern int usb_endpoint_is_isoc_out(struct usb_endpoint_descriptor *epd);
+
+/*-------------------------------------------------------------------------*/
+
 #define USB_DEVICE_ID_MATCH_DEVICE \
                (USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT)
 #define USB_DEVICE_ID_MATCH_DEV_RANGE \
-- 
1.4.1.1


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to