1194677Sthompsa/*- 2194677Sthompsa * Copyright (c) 2009 Andrew Thompson 3194677Sthompsa * 4194677Sthompsa * Redistribution and use in source and binary forms, with or without 5194677Sthompsa * modification, are permitted provided that the following conditions 6194677Sthompsa * are met: 7194677Sthompsa * 1. Redistributions of source code must retain the above copyright 8194677Sthompsa * notice, this list of conditions and the following disclaimer. 9194677Sthompsa * 2. Redistributions in binary form must reproduce the above copyright 10194677Sthompsa * notice, this list of conditions and the following disclaimer in the 11194677Sthompsa * documentation and/or other materials provided with the distribution. 12194677Sthompsa * 13194677Sthompsa * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14194677Sthompsa * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15194677Sthompsa * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16194677Sthompsa * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17194677Sthompsa * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18194677Sthompsa * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19194677Sthompsa * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20194677Sthompsa * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21194677Sthompsa * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22194677Sthompsa * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23194677Sthompsa * 24194677Sthompsa * $FreeBSD$ 25194677Sthompsa */ 26194677Sthompsa#ifndef _USB_USBDI_UTIL_H_ 27194677Sthompsa#define _USB_USBDI_UTIL_H_ 28194677Sthompsa 29194677Sthompsastruct cv; 30194677Sthompsa 31194677Sthompsa/* structures */ 32194677Sthompsa 33194677Sthompsastruct usb_idesc_parse_state { 34194677Sthompsa struct usb_descriptor *desc; 35194677Sthompsa uint8_t iface_index; /* current interface index */ 36194677Sthompsa uint8_t iface_no_last; 37194677Sthompsa uint8_t iface_index_alt; /* current alternate setting */ 38194677Sthompsa}; 39194677Sthompsa 40194677Sthompsa/* prototypes */ 41194677Sthompsa 42194677Sthompsausb_error_t usbd_do_request_proc(struct usb_device *udev, struct usb_process *pproc, 43194677Sthompsa struct usb_device_request *req, void *data, uint16_t flags, 44194677Sthompsa uint16_t *actlen, usb_timeout_t timeout); 45194677Sthompsa 46194677Sthompsastruct usb_descriptor *usb_desc_foreach(struct usb_config_descriptor *cd, 47194677Sthompsa struct usb_descriptor *desc); 48194677Sthompsastruct usb_interface_descriptor *usb_idesc_foreach( 49194677Sthompsa struct usb_config_descriptor *cd, 50194677Sthompsa struct usb_idesc_parse_state *ps); 51194677Sthompsastruct usb_endpoint_descriptor *usb_edesc_foreach( 52194677Sthompsa struct usb_config_descriptor *cd, 53194677Sthompsa struct usb_endpoint_descriptor *ped); 54213435Shselaskystruct usb_endpoint_ss_comp_descriptor *usb_ed_comp_foreach( 55213435Shselasky struct usb_config_descriptor *cd, 56213435Shselasky struct usb_endpoint_ss_comp_descriptor *ped); 57194677Sthompsauint8_t usbd_get_no_descriptors(struct usb_config_descriptor *cd, 58194677Sthompsa uint8_t type); 59194677Sthompsauint8_t usbd_get_no_alts(struct usb_config_descriptor *cd, 60194677Sthompsa struct usb_interface_descriptor *id); 61194677Sthompsa 62194677Sthompsausb_error_t usbd_req_get_report(struct usb_device *udev, struct mtx *mtx, 63194677Sthompsa void *data, uint16_t len, uint8_t iface_index, uint8_t type, 64194677Sthompsa uint8_t id); 65194677Sthompsausb_error_t usbd_req_get_report_descriptor(struct usb_device *udev, 66194677Sthompsa struct mtx *mtx, void *d, uint16_t size, 67194677Sthompsa uint8_t iface_index); 68194677Sthompsausb_error_t usbd_req_get_string_any(struct usb_device *udev, struct mtx *mtx, 69194677Sthompsa char *buf, uint16_t len, uint8_t string_index); 70194677Sthompsausb_error_t usbd_req_get_string_desc(struct usb_device *udev, struct mtx *mtx, 71194677Sthompsa void *sdesc, uint16_t max_len, uint16_t lang_id, 72194677Sthompsa uint8_t string_index); 73194677Sthompsausb_error_t usbd_req_set_config(struct usb_device *udev, struct mtx *mtx, 74194677Sthompsa uint8_t conf); 75194677Sthompsausb_error_t usbd_req_set_alt_interface_no(struct usb_device *udev, 76194677Sthompsa struct mtx *mtx, uint8_t iface_index, uint8_t alt_no); 77194677Sthompsausb_error_t usbd_req_set_idle(struct usb_device *udev, struct mtx *mtx, 78194677Sthompsa uint8_t iface_index, uint8_t duration, uint8_t id); 79194677Sthompsausb_error_t usbd_req_set_protocol(struct usb_device *udev, struct mtx *mtx, 80194677Sthompsa uint8_t iface_index, uint16_t report); 81194677Sthompsausb_error_t usbd_req_set_report(struct usb_device *udev, struct mtx *mtx, 82194677Sthompsa void *data, uint16_t len, uint8_t iface_index, 83194677Sthompsa uint8_t type, uint8_t id); 84212136Sthompsa 85212136Sthompsa/* The following functions will not return NULL strings. */ 86212136Sthompsa 87212136Sthompsaconst char *usb_get_manufacturer(struct usb_device *); 88212136Sthompsaconst char *usb_get_product(struct usb_device *); 89212136Sthompsaconst char *usb_get_serial(struct usb_device *); 90212136Sthompsa 91194677Sthompsa#endif /* _USB_USBDI_UTIL_H_ */ 92