1/* $FreeBSD: head/lib/libusb/libusb10_desc.c 195957 2009-07-30 00:11:41Z alfred $ */
| 1/* $FreeBSD: head/lib/libusb/libusb10_desc.c 199055 2009-11-08 20:03:52Z thompsa $ */
|
2/*- 3 * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <stdlib.h> 28#include <stdio.h> 29#include <pthread.h> 30#include <sys/queue.h> 31 32#include "libusb20.h" 33#include "libusb20_desc.h" 34#include "libusb20_int.h" 35#include "libusb.h" 36#include "libusb10.h" 37
| 2/*- 3 * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <stdlib.h> 28#include <stdio.h> 29#include <pthread.h> 30#include <sys/queue.h> 31 32#include "libusb20.h" 33#include "libusb20_desc.h" 34#include "libusb20_int.h" 35#include "libusb.h" 36#include "libusb10.h" 37
|
| 38#define N_ALIGN(n) (-((-(n)) & (-8UL))) 39
|
38/* USB descriptors */ 39 40int 41libusb_get_device_descriptor(libusb_device *dev, 42 struct libusb_device_descriptor *desc) 43{ 44 struct LIBUSB20_DEVICE_DESC_DECODED *pdesc; 45 struct libusb20_device *pdev; 46 47 if ((dev == NULL) || (desc == NULL)) 48 return (LIBUSB_ERROR_INVALID_PARAM); 49 50 pdev = dev->os_priv; 51 pdesc = libusb20_dev_get_device_desc(pdev); 52 53 desc->bLength = pdesc->bLength; 54 desc->bDescriptorType = pdesc->bDescriptorType; 55 desc->bcdUSB = pdesc->bcdUSB; 56 desc->bDeviceClass = pdesc->bDeviceClass; 57 desc->bDeviceSubClass = pdesc->bDeviceSubClass; 58 desc->bDeviceProtocol = pdesc->bDeviceProtocol; 59 desc->bMaxPacketSize0 = pdesc->bMaxPacketSize0; 60 desc->idVendor = pdesc->idVendor; 61 desc->idProduct = pdesc->idProduct; 62 desc->bcdDevice = pdesc->bcdDevice; 63 desc->iManufacturer = pdesc->iManufacturer; 64 desc->iProduct = pdesc->iProduct; 65 desc->iSerialNumber = pdesc->iSerialNumber; 66 desc->bNumConfigurations = pdesc->bNumConfigurations; 67 68 return (0); 69} 70 71int 72libusb_get_active_config_descriptor(libusb_device *dev, 73 struct libusb_config_descriptor **config) 74{ 75 struct libusb20_device *pdev; 76 uint8_t config_index; 77 78 pdev = dev->os_priv; 79 config_index = libusb20_dev_get_config_index(pdev); 80 81 return (libusb_get_config_descriptor(dev, config_index, config)); 82} 83 84int 85libusb_get_config_descriptor(libusb_device *dev, uint8_t config_index, 86 struct libusb_config_descriptor **config) 87{ 88 struct libusb20_device *pdev; 89 struct libusb20_config *pconf; 90 struct libusb20_interface *pinf; 91 struct libusb20_endpoint *pend; 92 struct libusb_config_descriptor *pconfd; 93 struct libusb_interface_descriptor *ifd; 94 struct libusb_endpoint_descriptor *endd; 95 uint8_t *pextra; 96 uint16_t nextra; 97 uint8_t nif; 98 uint8_t nep; 99 uint8_t nalt; 100 uint8_t i; 101 uint8_t j; 102 uint8_t k; 103 104 if (dev == NULL || config == NULL) 105 return (LIBUSB_ERROR_INVALID_PARAM); 106 107 *config = NULL; 108 109 pdev = dev->os_priv; 110 pconf = libusb20_dev_alloc_config(pdev, config_index); 111 112 if (pconf == NULL) 113 return (LIBUSB_ERROR_NOT_FOUND); 114 115 nalt = nif = pconf->num_interface; 116 nep = 0;
| 40/* USB descriptors */ 41 42int 43libusb_get_device_descriptor(libusb_device *dev, 44 struct libusb_device_descriptor *desc) 45{ 46 struct LIBUSB20_DEVICE_DESC_DECODED *pdesc; 47 struct libusb20_device *pdev; 48 49 if ((dev == NULL) || (desc == NULL)) 50 return (LIBUSB_ERROR_INVALID_PARAM); 51 52 pdev = dev->os_priv; 53 pdesc = libusb20_dev_get_device_desc(pdev); 54 55 desc->bLength = pdesc->bLength; 56 desc->bDescriptorType = pdesc->bDescriptorType; 57 desc->bcdUSB = pdesc->bcdUSB; 58 desc->bDeviceClass = pdesc->bDeviceClass; 59 desc->bDeviceSubClass = pdesc->bDeviceSubClass; 60 desc->bDeviceProtocol = pdesc->bDeviceProtocol; 61 desc->bMaxPacketSize0 = pdesc->bMaxPacketSize0; 62 desc->idVendor = pdesc->idVendor; 63 desc->idProduct = pdesc->idProduct; 64 desc->bcdDevice = pdesc->bcdDevice; 65 desc->iManufacturer = pdesc->iManufacturer; 66 desc->iProduct = pdesc->iProduct; 67 desc->iSerialNumber = pdesc->iSerialNumber; 68 desc->bNumConfigurations = pdesc->bNumConfigurations; 69 70 return (0); 71} 72 73int 74libusb_get_active_config_descriptor(libusb_device *dev, 75 struct libusb_config_descriptor **config) 76{ 77 struct libusb20_device *pdev; 78 uint8_t config_index; 79 80 pdev = dev->os_priv; 81 config_index = libusb20_dev_get_config_index(pdev); 82 83 return (libusb_get_config_descriptor(dev, config_index, config)); 84} 85 86int 87libusb_get_config_descriptor(libusb_device *dev, uint8_t config_index, 88 struct libusb_config_descriptor **config) 89{ 90 struct libusb20_device *pdev; 91 struct libusb20_config *pconf; 92 struct libusb20_interface *pinf; 93 struct libusb20_endpoint *pend; 94 struct libusb_config_descriptor *pconfd; 95 struct libusb_interface_descriptor *ifd; 96 struct libusb_endpoint_descriptor *endd; 97 uint8_t *pextra; 98 uint16_t nextra; 99 uint8_t nif; 100 uint8_t nep; 101 uint8_t nalt; 102 uint8_t i; 103 uint8_t j; 104 uint8_t k; 105 106 if (dev == NULL || config == NULL) 107 return (LIBUSB_ERROR_INVALID_PARAM); 108 109 *config = NULL; 110 111 pdev = dev->os_priv; 112 pconf = libusb20_dev_alloc_config(pdev, config_index); 113 114 if (pconf == NULL) 115 return (LIBUSB_ERROR_NOT_FOUND); 116 117 nalt = nif = pconf->num_interface; 118 nep = 0;
|
117 nextra = pconf->extra.len;
| 119 nextra = N_ALIGN(pconf->extra.len);
|
118 119 for (i = 0; i < nif; i++) { 120 121 pinf = pconf->interface + i;
| 120 121 for (i = 0; i < nif; i++) { 122 123 pinf = pconf->interface + i;
|
122 nextra += pinf->extra.len;
| 124 nextra += N_ALIGN(pinf->extra.len);
|
123 nep += pinf->num_endpoints; 124 k = pinf->num_endpoints; 125 pend = pinf->endpoints; 126 while (k--) {
| 125 nep += pinf->num_endpoints; 126 k = pinf->num_endpoints; 127 pend = pinf->endpoints; 128 while (k--) {
|
127 nextra += pend->extra.len;
| 129 nextra += N_ALIGN(pend->extra.len);
|
128 pend++; 129 } 130 131 j = pinf->num_altsetting; 132 nalt += pinf->num_altsetting; 133 pinf = pinf->altsetting; 134 while (j--) {
| 130 pend++; 131 } 132 133 j = pinf->num_altsetting; 134 nalt += pinf->num_altsetting; 135 pinf = pinf->altsetting; 136 while (j--) {
|
135 nextra += pinf->extra.len;
| 137 nextra += N_ALIGN(pinf->extra.len);
|
136 nep += pinf->num_endpoints; 137 k = pinf->num_endpoints; 138 pend = pinf->endpoints; 139 while (k--) {
| 138 nep += pinf->num_endpoints; 139 k = pinf->num_endpoints; 140 pend = pinf->endpoints; 141 while (k--) {
|
140 nextra += pend->extra.len;
| 142 nextra += N_ALIGN(pend->extra.len);
|
141 pend++; 142 } 143 pinf++; 144 } 145 } 146 147 nextra = nextra + 148 (1 * sizeof(libusb_config_descriptor)) + 149 (nif * sizeof(libusb_interface)) + 150 (nalt * sizeof(libusb_interface_descriptor)) + 151 (nep * sizeof(libusb_endpoint_descriptor)); 152
| 143 pend++; 144 } 145 pinf++; 146 } 147 } 148 149 nextra = nextra + 150 (1 * sizeof(libusb_config_descriptor)) + 151 (nif * sizeof(libusb_interface)) + 152 (nalt * sizeof(libusb_interface_descriptor)) + 153 (nep * sizeof(libusb_endpoint_descriptor)); 154
|
| 155 nextra = N_ALIGN(nextra); 156
|
153 pconfd = malloc(nextra); 154 155 if (pconfd == NULL) { 156 free(pconf); 157 return (LIBUSB_ERROR_NO_MEM); 158 }
| 157 pconfd = malloc(nextra); 158 159 if (pconfd == NULL) { 160 free(pconf); 161 return (LIBUSB_ERROR_NO_MEM); 162 }
|
159 /* make sure memory is clean */
| 163 /* make sure memory is initialised */
|
160 memset(pconfd, 0, nextra); 161
| 164 memset(pconfd, 0, nextra); 165
|
162 pconfd->interface = (libusb_interface *) (pconfd + 163 sizeof(libusb_config_descriptor));
| 166 pconfd->interface = (libusb_interface *) (pconfd + 1);
|
164 165 ifd = (libusb_interface_descriptor *) (pconfd->interface + nif); 166 endd = (libusb_endpoint_descriptor *) (ifd + nalt); 167 pextra = (uint8_t *)(endd + nep); 168 169 /* fill in config descriptor */ 170 171 pconfd->bLength = pconf->desc.bLength; 172 pconfd->bDescriptorType = pconf->desc.bDescriptorType; 173 pconfd->wTotalLength = pconf->desc.wTotalLength; 174 pconfd->bNumInterfaces = pconf->desc.bNumInterfaces; 175 pconfd->bConfigurationValue = pconf->desc.bConfigurationValue; 176 pconfd->iConfiguration = pconf->desc.iConfiguration; 177 pconfd->bmAttributes = pconf->desc.bmAttributes; 178 pconfd->MaxPower = pconf->desc.bMaxPower; 179 180 if (pconf->extra.len != 0) { 181 pconfd->extra_length = pconf->extra.len; 182 pconfd->extra = pextra; 183 memcpy(pextra, pconf->extra.ptr, pconfd->extra_length);
| 167 168 ifd = (libusb_interface_descriptor *) (pconfd->interface + nif); 169 endd = (libusb_endpoint_descriptor *) (ifd + nalt); 170 pextra = (uint8_t *)(endd + nep); 171 172 /* fill in config descriptor */ 173 174 pconfd->bLength = pconf->desc.bLength; 175 pconfd->bDescriptorType = pconf->desc.bDescriptorType; 176 pconfd->wTotalLength = pconf->desc.wTotalLength; 177 pconfd->bNumInterfaces = pconf->desc.bNumInterfaces; 178 pconfd->bConfigurationValue = pconf->desc.bConfigurationValue; 179 pconfd->iConfiguration = pconf->desc.iConfiguration; 180 pconfd->bmAttributes = pconf->desc.bmAttributes; 181 pconfd->MaxPower = pconf->desc.bMaxPower; 182 183 if (pconf->extra.len != 0) { 184 pconfd->extra_length = pconf->extra.len; 185 pconfd->extra = pextra; 186 memcpy(pextra, pconf->extra.ptr, pconfd->extra_length);
|
184 pextra += pconfd->extra_length;
| 187 pextra += N_ALIGN(pconfd->extra_length);
|
185 } 186 /* setup all interface and endpoint pointers */ 187 188 for (i = 0; i < nif; i++) { 189 190 pconfd->interface[i].altsetting = ifd; 191 ifd->endpoint = endd; 192 endd += pconf->interface[i].num_endpoints; 193 ifd++; 194 195 for (j = 0; j < pconf->interface[i].num_altsetting; j++) { 196 ifd->endpoint = endd; 197 endd += pconf->interface[i].altsetting[j].num_endpoints; 198 ifd++; 199 } 200 } 201 202 /* fill in all interface and endpoint data */ 203 204 for (i = 0; i < nif; i++) { 205 pinf = &pconf->interface[i]; 206 pconfd->interface[i].num_altsetting = pinf->num_altsetting + 1; 207 for (j = 0; j < pconfd->interface[i].num_altsetting; j++) { 208 if (j != 0) 209 pinf = &pconf->interface[i].altsetting[j - 1]; 210 ifd = &pconfd->interface[i].altsetting[j]; 211 ifd->bLength = pinf->desc.bLength; 212 ifd->bDescriptorType = pinf->desc.bDescriptorType; 213 ifd->bInterfaceNumber = pinf->desc.bInterfaceNumber; 214 ifd->bAlternateSetting = pinf->desc.bAlternateSetting; 215 ifd->bNumEndpoints = pinf->desc.bNumEndpoints; 216 ifd->bInterfaceClass = pinf->desc.bInterfaceClass; 217 ifd->bInterfaceSubClass = pinf->desc.bInterfaceSubClass; 218 ifd->bInterfaceProtocol = pinf->desc.bInterfaceProtocol; 219 ifd->iInterface = pinf->desc.iInterface; 220 if (pinf->extra.len != 0) { 221 ifd->extra_length = pinf->extra.len; 222 ifd->extra = pextra; 223 memcpy(pextra, pinf->extra.ptr, pinf->extra.len);
| 188 } 189 /* setup all interface and endpoint pointers */ 190 191 for (i = 0; i < nif; i++) { 192 193 pconfd->interface[i].altsetting = ifd; 194 ifd->endpoint = endd; 195 endd += pconf->interface[i].num_endpoints; 196 ifd++; 197 198 for (j = 0; j < pconf->interface[i].num_altsetting; j++) { 199 ifd->endpoint = endd; 200 endd += pconf->interface[i].altsetting[j].num_endpoints; 201 ifd++; 202 } 203 } 204 205 /* fill in all interface and endpoint data */ 206 207 for (i = 0; i < nif; i++) { 208 pinf = &pconf->interface[i]; 209 pconfd->interface[i].num_altsetting = pinf->num_altsetting + 1; 210 for (j = 0; j < pconfd->interface[i].num_altsetting; j++) { 211 if (j != 0) 212 pinf = &pconf->interface[i].altsetting[j - 1]; 213 ifd = &pconfd->interface[i].altsetting[j]; 214 ifd->bLength = pinf->desc.bLength; 215 ifd->bDescriptorType = pinf->desc.bDescriptorType; 216 ifd->bInterfaceNumber = pinf->desc.bInterfaceNumber; 217 ifd->bAlternateSetting = pinf->desc.bAlternateSetting; 218 ifd->bNumEndpoints = pinf->desc.bNumEndpoints; 219 ifd->bInterfaceClass = pinf->desc.bInterfaceClass; 220 ifd->bInterfaceSubClass = pinf->desc.bInterfaceSubClass; 221 ifd->bInterfaceProtocol = pinf->desc.bInterfaceProtocol; 222 ifd->iInterface = pinf->desc.iInterface; 223 if (pinf->extra.len != 0) { 224 ifd->extra_length = pinf->extra.len; 225 ifd->extra = pextra; 226 memcpy(pextra, pinf->extra.ptr, pinf->extra.len);
|
224 pextra += pinf->extra.len;
| 227 pextra += N_ALIGN(pinf->extra.len);
|
225 } 226 for (k = 0; k < pinf->num_endpoints; k++) { 227 pend = &pinf->endpoints[k]; 228 endd = &ifd->endpoint[k]; 229 endd->bLength = pend->desc.bLength; 230 endd->bDescriptorType = pend->desc.bDescriptorType; 231 endd->bEndpointAddress = pend->desc.bEndpointAddress; 232 endd->bmAttributes = pend->desc.bmAttributes; 233 endd->wMaxPacketSize = pend->desc.wMaxPacketSize; 234 endd->bInterval = pend->desc.bInterval; 235 endd->bRefresh = pend->desc.bRefresh; 236 endd->bSynchAddress = pend->desc.bSynchAddress; 237 if (pend->extra.len != 0) { 238 endd->extra_length = pend->extra.len; 239 endd->extra = pextra; 240 memcpy(pextra, pend->extra.ptr, pend->extra.len);
| 228 } 229 for (k = 0; k < pinf->num_endpoints; k++) { 230 pend = &pinf->endpoints[k]; 231 endd = &ifd->endpoint[k]; 232 endd->bLength = pend->desc.bLength; 233 endd->bDescriptorType = pend->desc.bDescriptorType; 234 endd->bEndpointAddress = pend->desc.bEndpointAddress; 235 endd->bmAttributes = pend->desc.bmAttributes; 236 endd->wMaxPacketSize = pend->desc.wMaxPacketSize; 237 endd->bInterval = pend->desc.bInterval; 238 endd->bRefresh = pend->desc.bRefresh; 239 endd->bSynchAddress = pend->desc.bSynchAddress; 240 if (pend->extra.len != 0) { 241 endd->extra_length = pend->extra.len; 242 endd->extra = pextra; 243 memcpy(pextra, pend->extra.ptr, pend->extra.len);
|
241 pextra += pend->extra.len;
| 244 pextra += N_ALIGN(pend->extra.len);
|
242 } 243 } 244 } 245 } 246 247 free(pconf); 248 249 *config = pconfd; 250 251 return (0); /* success */ 252} 253 254int 255libusb_get_config_descriptor_by_value(libusb_device *dev, 256 uint8_t bConfigurationValue, struct libusb_config_descriptor **config) 257{ 258 struct LIBUSB20_DEVICE_DESC_DECODED *pdesc; 259 struct libusb20_device *pdev; 260 int i; 261 int err; 262 263 if (dev == NULL || config == NULL) 264 return (LIBUSB_ERROR_INVALID_PARAM); 265 266 pdev = dev->os_priv; 267 pdesc = libusb20_dev_get_device_desc(pdev); 268 269 for (i = 0; i < pdesc->bNumConfigurations; i++) { 270 err = libusb_get_config_descriptor(dev, i, config); 271 if (err) 272 return (err); 273 274 if ((*config)->bConfigurationValue == bConfigurationValue) 275 return (0); /* success */ 276 277 libusb_free_config_descriptor(*config); 278 } 279 280 *config = NULL; 281 282 return (LIBUSB_ERROR_NOT_FOUND); 283} 284 285void 286libusb_free_config_descriptor(struct libusb_config_descriptor *config) 287{ 288 free(config); 289} 290 291int 292libusb_get_string_descriptor_ascii(libusb_device_handle *pdev, 293 uint8_t desc_index, unsigned char *data, int length) 294{ 295 if (pdev == NULL || data == NULL || length < 1) 296 return (LIBUSB20_ERROR_INVALID_PARAM); 297 298 /* put some default data into the destination buffer */ 299 data[0] = 0; 300 301 if (libusb20_dev_req_string_simple_sync(pdev, desc_index, 302 data, length) == 0) 303 return (strlen(data)); 304 305 return (LIBUSB_ERROR_OTHER); 306}
| 245 } 246 } 247 } 248 } 249 250 free(pconf); 251 252 *config = pconfd; 253 254 return (0); /* success */ 255} 256 257int 258libusb_get_config_descriptor_by_value(libusb_device *dev, 259 uint8_t bConfigurationValue, struct libusb_config_descriptor **config) 260{ 261 struct LIBUSB20_DEVICE_DESC_DECODED *pdesc; 262 struct libusb20_device *pdev; 263 int i; 264 int err; 265 266 if (dev == NULL || config == NULL) 267 return (LIBUSB_ERROR_INVALID_PARAM); 268 269 pdev = dev->os_priv; 270 pdesc = libusb20_dev_get_device_desc(pdev); 271 272 for (i = 0; i < pdesc->bNumConfigurations; i++) { 273 err = libusb_get_config_descriptor(dev, i, config); 274 if (err) 275 return (err); 276 277 if ((*config)->bConfigurationValue == bConfigurationValue) 278 return (0); /* success */ 279 280 libusb_free_config_descriptor(*config); 281 } 282 283 *config = NULL; 284 285 return (LIBUSB_ERROR_NOT_FOUND); 286} 287 288void 289libusb_free_config_descriptor(struct libusb_config_descriptor *config) 290{ 291 free(config); 292} 293 294int 295libusb_get_string_descriptor_ascii(libusb_device_handle *pdev, 296 uint8_t desc_index, unsigned char *data, int length) 297{ 298 if (pdev == NULL || data == NULL || length < 1) 299 return (LIBUSB20_ERROR_INVALID_PARAM); 300 301 /* put some default data into the destination buffer */ 302 data[0] = 0; 303 304 if (libusb20_dev_req_string_simple_sync(pdev, desc_index, 305 data, length) == 0) 306 return (strlen(data)); 307 308 return (LIBUSB_ERROR_OTHER); 309}
|
| 310 311int 312libusb_get_descriptor(libusb_device_handle * devh, uint8_t desc_type, 313 uint8_t desc_index, uint8_t *data, int length) 314{ 315 return (libusb_control_transfer(devh, LIBUSB_ENDPOINT_IN, 316 LIBUSB_REQUEST_GET_DESCRIPTOR, (desc_type << 8) | desc_index, 0, data, 317 length, 1000)); 318}
|
| |