1ed6d949aSAndrew Thompson /*- 24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3718cf2ccSPedro F. Giffuni * 4ed6d949aSAndrew Thompson * Copyright (c) 2009 Andrew Thompson 5ed6d949aSAndrew Thompson * 6ed6d949aSAndrew Thompson * Redistribution and use in source and binary forms, with or without 7ed6d949aSAndrew Thompson * modification, are permitted provided that the following conditions 8ed6d949aSAndrew Thompson * are met: 9ed6d949aSAndrew Thompson * 1. Redistributions of source code must retain the above copyright 10ed6d949aSAndrew Thompson * notice, this list of conditions and the following disclaimer. 11ed6d949aSAndrew Thompson * 2. Redistributions in binary form must reproduce the above copyright 12ed6d949aSAndrew Thompson * notice, this list of conditions and the following disclaimer in the 13ed6d949aSAndrew Thompson * documentation and/or other materials provided with the distribution. 14ed6d949aSAndrew Thompson * 15ed6d949aSAndrew Thompson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16ed6d949aSAndrew Thompson * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17ed6d949aSAndrew Thompson * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18ed6d949aSAndrew Thompson * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19ed6d949aSAndrew Thompson * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20ed6d949aSAndrew Thompson * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21ed6d949aSAndrew Thompson * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22ed6d949aSAndrew Thompson * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23ed6d949aSAndrew Thompson * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24ed6d949aSAndrew Thompson * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25ed6d949aSAndrew Thompson */ 26ed6d949aSAndrew Thompson #ifndef _USB_USBDI_UTIL_H_ 27ed6d949aSAndrew Thompson #define _USB_USBDI_UTIL_H_ 28ed6d949aSAndrew Thompson 29ed6d949aSAndrew Thompson struct cv; 30ed6d949aSAndrew Thompson 31ed6d949aSAndrew Thompson /* structures */ 32ed6d949aSAndrew Thompson 33ed6d949aSAndrew Thompson struct usb_idesc_parse_state { 34ed6d949aSAndrew Thompson struct usb_descriptor *desc; 35ed6d949aSAndrew Thompson uint8_t iface_index; /* current interface index */ 36ed6d949aSAndrew Thompson uint8_t iface_no_last; 37ed6d949aSAndrew Thompson uint8_t iface_index_alt; /* current alternate setting */ 38ed6d949aSAndrew Thompson }; 39ed6d949aSAndrew Thompson 40ed6d949aSAndrew Thompson /* prototypes */ 41ed6d949aSAndrew Thompson 42ed6d949aSAndrew Thompson usb_error_t usbd_do_request_proc(struct usb_device *udev, struct usb_process *pproc, 43ed6d949aSAndrew Thompson struct usb_device_request *req, void *data, uint16_t flags, 44ed6d949aSAndrew Thompson uint16_t *actlen, usb_timeout_t timeout); 45ed6d949aSAndrew Thompson 46ed6d949aSAndrew Thompson struct usb_descriptor *usb_desc_foreach(struct usb_config_descriptor *cd, 47ed6d949aSAndrew Thompson struct usb_descriptor *desc); 48ed6d949aSAndrew Thompson struct usb_interface_descriptor *usb_idesc_foreach( 49ed6d949aSAndrew Thompson struct usb_config_descriptor *cd, 50ed6d949aSAndrew Thompson struct usb_idesc_parse_state *ps); 51ed6d949aSAndrew Thompson struct usb_endpoint_descriptor *usb_edesc_foreach( 52ed6d949aSAndrew Thompson struct usb_config_descriptor *cd, 53ed6d949aSAndrew Thompson struct usb_endpoint_descriptor *ped); 54963169b4SHans Petter Selasky struct usb_endpoint_ss_comp_descriptor *usb_ed_comp_foreach( 55963169b4SHans Petter Selasky struct usb_config_descriptor *cd, 56963169b4SHans Petter Selasky struct usb_endpoint_ss_comp_descriptor *ped); 57ed6d949aSAndrew Thompson uint8_t usbd_get_no_descriptors(struct usb_config_descriptor *cd, 58ed6d949aSAndrew Thompson uint8_t type); 59ed6d949aSAndrew Thompson uint8_t usbd_get_no_alts(struct usb_config_descriptor *cd, 60ed6d949aSAndrew Thompson struct usb_interface_descriptor *id); 61ed6d949aSAndrew Thompson 62ed6d949aSAndrew Thompson usb_error_t usbd_req_get_report(struct usb_device *udev, struct mtx *mtx, 63ed6d949aSAndrew Thompson void *data, uint16_t len, uint8_t iface_index, uint8_t type, 64ed6d949aSAndrew Thompson uint8_t id); 65ed6d949aSAndrew Thompson usb_error_t usbd_req_get_report_descriptor(struct usb_device *udev, 66ed6d949aSAndrew Thompson struct mtx *mtx, void *d, uint16_t size, 67ed6d949aSAndrew Thompson uint8_t iface_index); 68ed6d949aSAndrew Thompson usb_error_t usbd_req_get_string_any(struct usb_device *udev, struct mtx *mtx, 69ed6d949aSAndrew Thompson char *buf, uint16_t len, uint8_t string_index); 70ed6d949aSAndrew Thompson usb_error_t usbd_req_get_string_desc(struct usb_device *udev, struct mtx *mtx, 71ed6d949aSAndrew Thompson void *sdesc, uint16_t max_len, uint16_t lang_id, 72ed6d949aSAndrew Thompson uint8_t string_index); 73ed6d949aSAndrew Thompson usb_error_t usbd_req_set_config(struct usb_device *udev, struct mtx *mtx, 74ed6d949aSAndrew Thompson uint8_t conf); 75ed6d949aSAndrew Thompson usb_error_t usbd_req_set_alt_interface_no(struct usb_device *udev, 76ed6d949aSAndrew Thompson struct mtx *mtx, uint8_t iface_index, uint8_t alt_no); 77ed6d949aSAndrew Thompson usb_error_t usbd_req_set_idle(struct usb_device *udev, struct mtx *mtx, 78ed6d949aSAndrew Thompson uint8_t iface_index, uint8_t duration, uint8_t id); 79ed6d949aSAndrew Thompson usb_error_t usbd_req_set_protocol(struct usb_device *udev, struct mtx *mtx, 80ed6d949aSAndrew Thompson uint8_t iface_index, uint16_t report); 81ed6d949aSAndrew Thompson usb_error_t usbd_req_set_report(struct usb_device *udev, struct mtx *mtx, 82ed6d949aSAndrew Thompson void *data, uint16_t len, uint8_t iface_index, 83ed6d949aSAndrew Thompson uint8_t type, uint8_t id); 84ae538d85SAndrew Thompson 85ae538d85SAndrew Thompson /* The following functions will not return NULL strings. */ 86ae538d85SAndrew Thompson 87ae538d85SAndrew Thompson const char *usb_get_manufacturer(struct usb_device *); 88ae538d85SAndrew Thompson const char *usb_get_product(struct usb_device *); 89ae538d85SAndrew Thompson const char *usb_get_serial(struct usb_device *); 90ae538d85SAndrew Thompson 91ed6d949aSAndrew Thompson #endif /* _USB_USBDI_UTIL_H_ */ 92