source: mainline/uspace/lib/usbdev/src/devdrv.c@ 4c86c7c

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 4c86c7c was 4c86c7c, checked in by Jan Vesely <jano.vesely@…>, 12 years ago

libusbdev: Close bus_session after every other thing is down.

  • Property mode set to 100644
File size: 16.7 KB
RevLine 
[6105fc0]1/*
2 * Copyright (c) 2011 Vojtech Horky
[4291215]3 * Copyright (c) 2011 Jan Vesely
[6105fc0]4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
[160b75e]29/** @addtogroup libusbdev
[6105fc0]30 * @{
31 */
32/** @file
33 * USB device driver framework.
34 */
[87619045]35
36#include <usb_iface.h>
37#include <usb/dev/device.h>
[7d521e24]38#include <usb/dev/request.h>
[6105fc0]39#include <usb/debug.h>
[1a38701]40#include <usb/dev.h>
[6105fc0]41#include <errno.h>
[69334af]42#include <str_error.h>
[6105fc0]43#include <assert.h>
44
[fd9b3a67]45/** USB device structure. */
46typedef struct usb_device {
47 /** Connection to USB hc, used by wire and arbitrary requests. */
48 usb_hc_connection_t hc_conn;
49 /** Connection backing the pipes.
50 * Typically, you will not need to use this attribute at all.
51 */
52 usb_device_connection_t wire;
53 /** The default control pipe. */
54 usb_pipe_t ctrl_pipe;
55
56 /** Other endpoint pipes.
57 * This is an array of other endpoint pipes in the same order as
58 * in usb_driver_t.
59 */
60 usb_endpoint_mapping_t *pipes;
61 /** Number of other endpoint pipes. */
62 size_t pipes_count;
63 /** Current interface.
64 * Usually, drivers operate on single interface only.
65 * This item contains the value of the interface or -1 for any.
66 */
67 int interface_no;
68 /** Alternative interfaces. */
69 usb_alternate_interfaces_t alternate_interfaces;
70 /** Some useful descriptors for USB device. */
[e2dfa86]71 usb_device_descriptors_t descriptors;
[fd9b3a67]72 /** Generic DDF device backing this one. DO NOT TOUCH! */
73 ddf_dev_t *ddf_dev;
74 /** Custom driver data.
75 * Do not use the entry in generic device, that is already used
76 * by the framework.
77 */
78 void *driver_data;
79
80 usb_dev_session_t *bus_session;
81} usb_device_t;
82
[69334af]83/** Count number of pipes the driver expects.
84 *
85 * @param drv USB driver.
86 * @return Number of pipes (excluding default control pipe).
87 */
[b06d35a]88static inline size_t count_pipes(const usb_endpoint_description_t **endpoints)
[6105fc0]89{
[ab27e01]90 size_t count;
[64e3dad]91 for (count = 0; endpoints != NULL && endpoints[count] != NULL; ++count);
[6105fc0]92 return count;
93}
[a76b01b4]94
[0b4e7ca]95/** Change interface setting of a device.
96 * This function selects new alternate setting of an interface by issuing
97 * proper USB command to the device and also creates new USB pipes
98 * under @c dev->pipes.
99 *
100 * @warning This function is intended for drivers working at interface level.
101 * For drivers controlling the whole device, you need to change interface
102 * manually using usb_request_set_interface() and creating new pipes
103 * with usb_pipe_initialize_from_configuration().
104 *
[3f2af64]105 * @warning This is a wrapper function that does several operations that
106 * can fail and that cannot be rollbacked easily. That means that a failure
107 * during the SET_INTERFACE request would result in having a device with
108 * no pipes at all (except the default control one). That is because the old
109 * pipes needs to be unregistered at HC first and the new ones could not
110 * be created.
111 *
[0b4e7ca]112 * @param dev USB device.
113 * @param alternate_setting Alternate setting to choose.
114 * @param endpoints New endpoint descriptions.
115 * @return Error code.
116 */
[f4138ac]117int usb_device_select_interface(usb_device_t *usb_dev,
118 uint8_t alternate_setting, const usb_endpoint_description_t **endpoints)
[0b4e7ca]119{
[f4138ac]120 assert(usb_dev);
121
122 if (usb_dev->interface_no < 0) {
[0b4e7ca]123 return EINVAL;
124 }
125
126 /* Change the interface itself. */
[f4138ac]127 int rc = usb_request_set_interface(&usb_dev->ctrl_pipe,
128 usb_dev->interface_no, alternate_setting);
[0b4e7ca]129 if (rc != EOK) {
130 return rc;
131 }
132
[f4138ac]133 /* Change current alternative */
134 usb_dev->alternate_interfaces.current = alternate_setting;
135
136 /* Destroy existing pipes. */
137 usb_device_destroy_pipes(usb_dev);
138
[0b4e7ca]139 /* Create new pipes. */
[b06d35a]140 rc = usb_device_create_pipes(usb_dev, endpoints);
[c1b1944]141
142 return rc;
143}
144
145/** Retrieve basic descriptors from the device.
146 *
[4fa0a384]147 * @param[in] ctrl_pipe Control endpoint pipe.
[c1b1944]148 * @param[out] descriptors Where to store the descriptors.
149 * @return Error code.
150 */
[945d66c]151static int usb_device_retrieve_descriptors(usb_device_t *usb_dev)
[c1b1944]152{
[945d66c]153 assert(usb_dev);
[e2dfa86]154 assert(usb_dev->descriptors.full_config == NULL);
[c1b1944]155
[4fa0a384]156 /* It is worth to start a long transfer. */
[945d66c]157 usb_pipe_start_long_transfer(&usb_dev->ctrl_pipe);
[4fa0a384]158
[c1b1944]159 /* Get the device descriptor. */
[945d66c]160 int rc = usb_request_get_device_descriptor(&usb_dev->ctrl_pipe,
161 &usb_dev->descriptors.device);
[c1b1944]162 if (rc != EOK) {
[4fa0a384]163 goto leave;
[c1b1944]164 }
165
166 /* Get the full configuration descriptor. */
167 rc = usb_request_get_full_configuration_descriptor_alloc(
[945d66c]168 &usb_dev->ctrl_pipe, 0,
[0eb2a0f]169 &usb_dev->descriptors.full_config,
[e2dfa86]170 &usb_dev->descriptors.full_config_size);
[c1b1944]171
[4fa0a384]172leave:
[945d66c]173 usb_pipe_end_long_transfer(&usb_dev->ctrl_pipe);
[4fa0a384]174
175 return rc;
[c1b1944]176}
177
[7fc260ff]178/** Cleanup structure initialized via usb_device_retrieve_descriptors.
179 *
180 * @param[in] descriptors Where to store the descriptors.
181 */
[945d66c]182static void usb_device_release_descriptors(usb_device_t *usb_dev)
[7fc260ff]183{
[945d66c]184 assert(usb_dev);
[e2dfa86]185 free(usb_dev->descriptors.full_config);
186 usb_dev->descriptors.full_config = NULL;
187 usb_dev->descriptors.full_config_size = 0;
[7fc260ff]188}
189
[c1b1944]190/** Create pipes for a device.
191 *
192 * This is more or less a wrapper that does following actions:
193 * - allocate and initialize pipes
194 * - map endpoints to the pipes based on the descriptions
195 * - registers endpoints with the host controller
196 *
197 * @param[in] wire Initialized backing connection to the host controller.
198 * @param[in] endpoints Endpoints description, NULL terminated.
199 * @param[in] config_descr Configuration descriptor of active configuration.
200 * @param[in] config_descr_size Size of @p config_descr in bytes.
201 * @param[in] interface_no Interface to map from.
202 * @param[in] interface_setting Interface setting (default is usually 0).
203 * @param[out] pipes_ptr Where to store array of created pipes
204 * (not NULL terminated).
205 * @param[out] pipes_count_ptr Where to store number of pipes
[ab27e01]206 * (set to NULL if you wish to ignore the count).
[c1b1944]207 * @return Error code.
208 */
[b06d35a]209int usb_device_create_pipes(usb_device_t *usb_dev,
210 const usb_endpoint_description_t **endpoints)
[c1b1944]211{
[b06d35a]212 assert(usb_dev);
[e2dfa86]213 assert(usb_dev->descriptors.full_config);
[b06d35a]214 assert(usb_dev->pipes == NULL);
215 assert(usb_dev->pipes_count == 0);
[c1b1944]216
[b06d35a]217 size_t pipe_count = count_pipes(endpoints);
[c1b1944]218 if (pipe_count == 0) {
219 return EOK;
220 }
221
[b06d35a]222 usb_endpoint_mapping_t *pipes =
223 calloc(pipe_count, sizeof(usb_endpoint_mapping_t));
[c1b1944]224 if (pipes == NULL) {
225 return ENOMEM;
226 }
227
[441633f]228 /* Now initialize. */
[b06d35a]229 for (size_t i = 0; i < pipe_count; i++) {
[c1b1944]230 pipes[i].description = endpoints[i];
[b06d35a]231 pipes[i].interface_no = usb_dev->interface_no;
232 pipes[i].interface_setting =
233 usb_dev->alternate_interfaces.current;
[c1b1944]234 }
235
236 /* Find the mapping from configuration descriptor. */
[b06d35a]237 int rc = usb_pipe_initialize_from_configuration(pipes, pipe_count,
[e2dfa86]238 usb_dev->descriptors.full_config,
[8582076]239 usb_dev->descriptors.full_config_size, &usb_dev->wire,
240 usb_dev->bus_session);
[c1b1944]241 if (rc != EOK) {
[441633f]242 free(pipes);
243 return rc;
[c1b1944]244 }
245
[441633f]246 /* Register created pipes. */
[b06d35a]247 for (size_t i = 0; i < pipe_count; i++) {
[c1b1944]248 if (pipes[i].present) {
[b77931d]249 rc = usb_pipe_register(&pipes[i].pipe,
[bd575647]250 pipes[i].descriptor->poll_interval);
[c1b1944]251 if (rc != EOK) {
252 goto rollback_unregister_endpoints;
253 }
254 }
255 }
256
[b06d35a]257 usb_dev->pipes = pipes;
258 usb_dev->pipes_count = pipe_count;
[c1b1944]259
260 return EOK;
261
262 /*
263 * Jump here if something went wrong after endpoints have
264 * been registered.
265 * This is also the target when the registration of
266 * endpoints fails.
267 */
268rollback_unregister_endpoints:
[b06d35a]269 for (size_t i = 0; i < pipe_count; i++) {
[c1b1944]270 if (pipes[i].present) {
[bd575647]271 usb_pipe_unregister(&pipes[i].pipe);
[c1b1944]272 }
273 }
274
275 free(pipes);
[0b4e7ca]276 return rc;
277}
[159b91f4]278
[c1b1944]279/** Destroy pipes previously created by usb_device_create_pipes.
280 *
[2dc5a9f]281 * @param[in] usb_dev USB device.
[c1b1944]282 */
[2dc5a9f]283void usb_device_destroy_pipes(usb_device_t *usb_dev)
[c1b1944]284{
[2dc5a9f]285 assert(usb_dev);
286 assert(usb_dev->pipes || usb_dev->pipes_count == 0);
[c1b1944]287 /* Destroy the pipes. */
[2dc5a9f]288 for (size_t i = 0; i < usb_dev->pipes_count; ++i) {
[8a01a0b]289 usb_log_debug2("Unregistering pipe %zu: %spresent.\n",
[2dc5a9f]290 i, usb_dev->pipes[i].present ? "" : "not ");
291 if (usb_dev->pipes[i].present)
292 usb_pipe_unregister(&usb_dev->pipes[i].pipe);
[c1b1944]293 }
[2dc5a9f]294 free(usb_dev->pipes);
295 usb_dev->pipes = NULL;
296 usb_dev->pipes_count = 0;
[c1b1944]297}
298
[0f4bff8]299usb_pipe_t *usb_device_get_default_pipe(usb_device_t *usb_dev)
300{
301 assert(usb_dev);
302 return &usb_dev->ctrl_pipe;
303}
304
[a6a5b25]305usb_endpoint_mapping_t *usb_device_get_mapped_ep_desc(usb_device_t *usb_dev,
306 const usb_endpoint_description_t *desc)
307{
308 assert(usb_dev);
309 for (unsigned i = 0; i < usb_dev->pipes_count; ++i) {
310 if (usb_dev->pipes[i].description == desc)
311 return &usb_dev->pipes[i];
312 }
313 return NULL;
314}
315
316usb_endpoint_mapping_t * usb_device_get_mapped_ep(
317 usb_device_t *usb_dev, usb_endpoint_t ep)
318{
319 assert(usb_dev);
320 for (unsigned i = 0; i < usb_dev->pipes_count; ++i) {
321 if (usb_dev->pipes[i].pipe.endpoint_no == ep)
322 return &usb_dev->pipes[i];
323 }
324 return NULL;
325}
326
[8e10ef4]327int usb_device_get_iface_number(usb_device_t *usb_dev)
328{
329 assert(usb_dev);
330 return usb_dev->interface_no;
331}
332
[e2dfa86]333const usb_device_descriptors_t *usb_device_descriptors(usb_device_t *usb_dev)
[945d66c]334{
335 assert(usb_dev);
[e2dfa86]336 return &usb_dev->descriptors;
[945d66c]337}
338
[8e10ef4]339const usb_alternate_interfaces_t * usb_device_get_alternative_ifaces(
340 usb_device_t *usb_dev)
341{
342 assert(usb_dev);
343 return &usb_dev->alternate_interfaces;
344}
345
[35bc430]346static int usb_dev_get_info(usb_device_t *usb_dev, devman_handle_t *handle,
347 usb_address_t *address, int *iface_no)
348{
349 assert(usb_dev);
350
351 int ret = EOK;
352 async_exch_t *exch = async_exchange_begin(usb_dev->bus_session);
353 if (!exch)
354 ret = ENOMEM;
355
356 if (ret == EOK && address)
357 ret = usb_get_my_address(exch, address);
358
359 if (ret == EOK && handle)
360 ret = usb_get_hc_handle(exch, handle);
361
362 if (ret == EOK && iface_no) {
363 ret = usb_get_my_interface(exch, iface_no);
364 if (ret == ENOTSUP) {
365 ret = EOK;
366 *iface_no = -1;
367 }
368 }
369
370 async_exchange_end(exch);
371 return ret;
372}
373
[7363fc1]374/** Clean instance of a USB device.
375 *
376 * @param dev Device to be de-initialized.
377 *
378 * Does not free/destroy supplied pointer.
379 */
380static void usb_device_fini(usb_device_t *usb_dev)
381{
382 if (usb_dev) {
383 /* Destroy existing pipes. */
384 usb_device_destroy_pipes(usb_dev);
385 /* Ignore errors and hope for the best. */
386 usb_hc_connection_deinitialize(&usb_dev->hc_conn);
387 usb_alternate_interfaces_deinit(&usb_dev->alternate_interfaces);
388 usb_device_release_descriptors(usb_dev);
389 free(usb_dev->driver_data);
390 usb_dev->driver_data = NULL;
[4c86c7c]391 usb_dev_disconnect(usb_dev->bus_session);
392 usb_dev->bus_session = NULL;
[7363fc1]393 }
394}
395
[7d9cd62]396/** Initialize new instance of USB device.
[6ee6e6f]397 *
[7d9cd62]398 * @param[in] usb_dev Pointer to the new device.
[6ee6e6f]399 * @param[in] ddf_dev Generic DDF device backing the USB one.
400 * @param[in] endpoints NULL terminated array of endpoints (NULL for none).
401 * @param[out] errstr_ptr Where to store description of context
402 * (in case error occurs).
403 * @return Error code.
404 */
[fd9b3a67]405static int usb_device_init(usb_device_t *usb_dev, ddf_dev_t *ddf_dev,
[7363fc1]406 const usb_endpoint_description_t **endpoints, const char **errstr_ptr,
407 devman_handle_t handle)
[6ee6e6f]408{
[7d9cd62]409 assert(usb_dev != NULL);
[7363fc1]410 assert(errstr_ptr);
[6ee6e6f]411
[7fc260ff]412 *errstr_ptr = NULL;
413
[7d9cd62]414 usb_dev->ddf_dev = ddf_dev;
415 usb_dev->driver_data = NULL;
[e2dfa86]416 usb_dev->descriptors.full_config = NULL;
417 usb_dev->descriptors.full_config_size = 0;
[7d9cd62]418 usb_dev->pipes_count = 0;
419 usb_dev->pipes = NULL;
[6ee6e6f]420
[7363fc1]421 if (ddf_dev)
422 usb_dev->bus_session = usb_dev_connect_to_self(ddf_dev);
423 else
424 usb_dev->bus_session = usb_dev_connect(handle);
425
[c8c758d]426 if (!usb_dev->bus_session) {
427 *errstr_ptr = "device bus session create";
428 return ENOMEM;
429 }
430
[c24c157d]431 /* Get assigned params */
432 devman_handle_t hc_handle;
433 usb_address_t address;
434
[35bc430]435 int rc = usb_dev_get_info(usb_dev,
[c24c157d]436 &hc_handle, &address, &usb_dev->interface_no);
437 if (rc != EOK) {
[7363fc1]438 usb_dev_disconnect(usb_dev->bus_session);
[c24c157d]439 *errstr_ptr = "device parameters retrieval";
440 return rc;
441 }
442
[c0fdc0e]443 /* Initialize hc connection. */
[c24c157d]444 usb_hc_connection_initialize(&usb_dev->hc_conn, hc_handle);
[c0fdc0e]445
[3f2af64]446 /* Initialize backing wire and control pipe. */
[c24c157d]447 rc = usb_device_connection_initialize(
[bd575647]448 &usb_dev->wire, &usb_dev->hc_conn, address);
[3f2af64]449 if (rc != EOK) {
[7363fc1]450 usb_dev_disconnect(usb_dev->bus_session);
[7fc260ff]451 *errstr_ptr = "device connection initialization";
452 return rc;
453 }
454
455 /* This pipe was registered by the hub driver,
456 * during device initialization. */
[c0fdc0e]457 rc = usb_pipe_initialize_default_control(
[8582076]458 &usb_dev->ctrl_pipe, &usb_dev->wire, usb_dev->bus_session);
[7fc260ff]459 if (rc != EOK) {
[7363fc1]460 usb_dev_disconnect(usb_dev->bus_session);
[7fc260ff]461 *errstr_ptr = "default control pipe initialization";
[3f2af64]462 return rc;
463 }
464
[6e3c005]465 /* Open hc connection for pipe registration. */
[c0fdc0e]466 rc = usb_hc_connection_open(&usb_dev->hc_conn);
467 if (rc != EOK) {
[7363fc1]468 usb_dev_disconnect(usb_dev->bus_session);
[c0fdc0e]469 *errstr_ptr = "hc connection open";
470 return rc;
471 }
472
[3f2af64]473 /* Retrieve standard descriptors. */
[945d66c]474 rc = usb_device_retrieve_descriptors(usb_dev);
[6ee6e6f]475 if (rc != EOK) {
[3f2af64]476 *errstr_ptr = "descriptor retrieval";
[c0fdc0e]477 usb_hc_connection_close(&usb_dev->hc_conn);
[7363fc1]478 usb_dev_disconnect(usb_dev->bus_session);
[6ee6e6f]479 return rc;
480 }
481
[7fc260ff]482 /* Create alternate interfaces. We will silently ignore failure.
483 * We might either control one interface or an entire device,
484 * it makes no sense to speak about alternate interfaces when
485 * controlling a device. */
[ab27e01]486 rc = usb_alternate_interfaces_init(&usb_dev->alternate_interfaces,
[e2dfa86]487 usb_dev->descriptors.full_config,
488 usb_dev->descriptors.full_config_size, usb_dev->interface_no);
[6ee6e6f]489
[7363fc1]490 if (endpoints) {
491 /* Create and register other pipes than default control (EP 0)*/
492 rc = usb_device_create_pipes(usb_dev, endpoints);
493 if (rc != EOK) {
494 usb_hc_connection_close(&usb_dev->hc_conn);
495 usb_device_fini(usb_dev);
496 *errstr_ptr = "pipes initialization";
497 return rc;
498 }
[6ee6e6f]499 }
500
[c0fdc0e]501 usb_hc_connection_close(&usb_dev->hc_conn);
[6ee6e6f]502 return EOK;
503}
504
[fd9b3a67]505int usb_device_create_ddf(ddf_dev_t *ddf_dev,
506 const usb_endpoint_description_t **desc, const char **err)
507{
508 assert(ddf_dev);
509 assert(err);
[7363fc1]510 usb_device_t *usb_dev =
511 ddf_dev_data_alloc(ddf_dev, sizeof(usb_device_t));
512 if (usb_dev == NULL) {
[fd9b3a67]513 *err = "DDF data alloc";
514 return ENOMEM;
515 }
[7363fc1]516 return usb_device_init(usb_dev, ddf_dev, desc, err, 0);
[fd9b3a67]517}
518
519void usb_device_destroy_ddf(ddf_dev_t *ddf_dev)
520{
521 assert(ddf_dev);
[7363fc1]522 usb_device_t *usb_dev = ddf_dev_data_get(ddf_dev);
523 assert(usb_dev);
524 usb_device_fini(usb_dev);
[fd9b3a67]525 return;
526}
527
[7363fc1]528usb_device_t * usb_device_create(devman_handle_t handle)
529{
530 usb_device_t *usb_dev = malloc(sizeof(usb_device_t));
531 if (!usb_dev)
532 return NULL;
533 const char* dummy = NULL;
534 const int ret = usb_device_init(usb_dev, NULL, NULL, &dummy, handle);
535 if (ret != EOK) {
536 free(usb_dev);
537 usb_dev = NULL;
538 }
539 return usb_dev;
540}
541
542void usb_device_destroy(usb_device_t *usb_dev)
543{
544 if (usb_dev) {
545 usb_device_fini(usb_dev);
546 free(usb_dev);
547 }
548}
549
[f6b2a76b]550const char *usb_device_get_name(usb_device_t *usb_dev)
551{
552 assert(usb_dev);
[35bc430]553 if (usb_dev->ddf_dev)
554 return ddf_dev_get_name(usb_dev->ddf_dev);
555 return NULL;
[f6b2a76b]556}
557
[bb512b2d]558ddf_fun_t *usb_device_ddf_fun_create(usb_device_t *usb_dev, fun_type_t ftype,
559 const char* name)
560{
561 assert(usb_dev);
562 if (usb_dev->ddf_dev)
563 return ddf_fun_create(usb_dev->ddf_dev, ftype, name);
564 return NULL;
565}
566
[0f4bff8]567async_exch_t * usb_device_bus_exchange_begin(usb_device_t *usb_dev)
568{
569 assert(usb_dev);
570 return async_exchange_begin(usb_dev->bus_session);
571}
572
573void usb_device_bus_exchange_end(async_exch_t *exch)
574{
575 async_exchange_end(exch);
576}
577
[6e3c005]578/** Allocate driver specific data.
579 * @param usb_dev usb_device structure.
580 * @param size requested data size.
581 * @return Pointer to the newly allocated space, NULL on failure.
582 */
[065064e6]583void * usb_device_data_alloc(usb_device_t *usb_dev, size_t size)
584{
585 assert(usb_dev);
586 assert(usb_dev->driver_data == NULL);
587 return usb_dev->driver_data = calloc(1, size);
[70452dd4]588
589}
590
[0f4bff8]591void * usb_device_data_get(usb_device_t *usb_dev)
592{
593 assert(usb_dev);
594 return usb_dev->driver_data;
595}
[4ca778b]596
597usb_address_t usb_device_address(usb_device_t *usb_dev)
598{
599 assert(usb_dev);
600 return usb_dev->wire.address;
601}
602
603devman_handle_t usb_device_hc_handle(usb_device_t *usb_dev)
604{
605 assert(usb_dev);
606 return usb_dev->hc_conn.hc_handle;
607}
[6105fc0]608/**
609 * @}
610 */
Note: See TracBrowser for help on using the repository browser.