Deleted Added
sdiff udiff text old ( 195957 ) new ( 199055 )
full compact
1/* $FreeBSD: head/lib/libusb/libusb10_desc.c 195957 2009-07-30 00:11:41Z alfred $ */
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.

--- 20 unchanged lines hidden (view full) ---

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/* 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;

--- 63 unchanged lines hidden (view full) ---

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;
117 nextra = pconf->extra.len;
118
119 for (i = 0; i < nif; i++) {
120
121 pinf = pconf->interface + i;
122 nextra += pinf->extra.len;
123 nep += pinf->num_endpoints;
124 k = pinf->num_endpoints;
125 pend = pinf->endpoints;
126 while (k--) {
127 nextra += pend->extra.len;
128 pend++;
129 }
130
131 j = pinf->num_altsetting;
132 nalt += pinf->num_altsetting;
133 pinf = pinf->altsetting;
134 while (j--) {
135 nextra += pinf->extra.len;
136 nep += pinf->num_endpoints;
137 k = pinf->num_endpoints;
138 pend = pinf->endpoints;
139 while (k--) {
140 nextra += 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
153 pconfd = malloc(nextra);
154
155 if (pconfd == NULL) {
156 free(pconf);
157 return (LIBUSB_ERROR_NO_MEM);
158 }
159 /* make sure memory is clean */
160 memset(pconfd, 0, nextra);
161
162 pconfd->interface = (libusb_interface *) (pconfd +
163 sizeof(libusb_config_descriptor));
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;

--- 4 unchanged lines hidden (view full) ---

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);
184 pextra += 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;

--- 23 unchanged lines hidden (view full) ---

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);
224 pextra += 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);
241 pextra += pend->extra.len;
242 }
243 }
244 }
245 }
246
247 free(pconf);
248
249 *config = pconfd;

--- 49 unchanged lines hidden (view full) ---

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}