[02ccfcd] | 1 | /*
|
---|
| 2 | * Copyright (c) 2010 Vojtech Horky
|
---|
| 3 | * 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 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
[160b75e] | 29 | /** @addtogroup libusbdev
|
---|
[02ccfcd] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
[a6add7a] | 33 | * Functions for recognition of attached devices.
|
---|
[02ccfcd] | 34 | */
|
---|
[17aca1c] | 35 | #include <sys/types.h>
|
---|
[eb1a2f4] | 36 | #include <fibril_synch.h>
|
---|
[59c163c] | 37 | #include <usb/debug.h>
|
---|
| 38 | #include <usb/dev/hub.h>
|
---|
[7d521e24] | 39 | #include <usb/dev/pipes.h>
|
---|
| 40 | #include <usb/dev/recognise.h>
|
---|
[357a302] | 41 | #include <usb/ddfiface.h>
|
---|
[7d521e24] | 42 | #include <usb/dev/request.h>
|
---|
[02ccfcd] | 43 | #include <usb/classes/classes.h>
|
---|
| 44 | #include <stdio.h>
|
---|
| 45 | #include <errno.h>
|
---|
[eb1a2f4] | 46 | #include <assert.h>
|
---|
[02ccfcd] | 47 |
|
---|
[a6add7a] | 48 | /** Index to append after device name for uniqueness. */
|
---|
[4e8e1f5] | 49 | static size_t device_name_index = 0;
|
---|
[a6add7a] | 50 | /** Mutex guard for device_name_index. */
|
---|
[4e8e1f5] | 51 | static FIBRIL_MUTEX_INITIALIZE(device_name_index_mutex);
|
---|
| 52 |
|
---|
[a6add7a] | 53 | /** DDF operations of child devices. */
|
---|
[eea3e39] | 54 | static ddf_dev_ops_t child_ops = {
|
---|
[357a302] | 55 | .interfaces[USB_DEV_IFACE] = &usb_iface_hub_child_impl
|
---|
[71ed4849] | 56 | };
|
---|
[02ccfcd] | 57 |
|
---|
[a6add7a] | 58 | /** Get integer part from BCD coded number. */
|
---|
[02ccfcd] | 59 | #define BCD_INT(a) (((unsigned int)(a)) / 256)
|
---|
[a6add7a] | 60 | /** Get fraction part from BCD coded number (as an integer, no less). */
|
---|
[02ccfcd] | 61 | #define BCD_FRAC(a) (((unsigned int)(a)) % 256)
|
---|
| 62 |
|
---|
[a6add7a] | 63 | /** Format for BCD coded number to be used in printf. */
|
---|
[02ccfcd] | 64 | #define BCD_FMT "%x.%x"
|
---|
[a6add7a] | 65 | /** Arguments to printf for BCD coded number. */
|
---|
[02ccfcd] | 66 | #define BCD_ARGS(a) BCD_INT((a)), BCD_FRAC((a))
|
---|
| 67 |
|
---|
| 68 | /** Add formatted match id.
|
---|
| 69 | *
|
---|
| 70 | * @param matches List of match ids where to add to.
|
---|
| 71 | * @param score Score of the match.
|
---|
| 72 | * @param format Printf-like format
|
---|
| 73 | * @return Error code.
|
---|
| 74 | */
|
---|
| 75 | static int usb_add_match_id(match_id_list_t *matches, int score,
|
---|
[37e4025] | 76 | const char *match_str)
|
---|
[02ccfcd] | 77 | {
|
---|
[37e4025] | 78 | assert(matches);
|
---|
[02ccfcd] | 79 |
|
---|
[37e4025] | 80 | match_id_t *match_id = create_match_id();
|
---|
[02ccfcd] | 81 | if (match_id == NULL) {
|
---|
[37e4025] | 82 | return ENOMEM;
|
---|
[02ccfcd] | 83 | }
|
---|
| 84 |
|
---|
| 85 | match_id->id = match_str;
|
---|
| 86 | match_id->score = score;
|
---|
| 87 | add_match_id(matches, match_id);
|
---|
| 88 |
|
---|
| 89 | return EOK;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
[a6add7a] | 92 | /** Add match id to list or return with error code.
|
---|
| 93 | *
|
---|
| 94 | * @param match_ids List of match ids.
|
---|
| 95 | * @param score Match id score.
|
---|
| 96 | * @param format Format of the matching string
|
---|
| 97 | * @param ... Arguments for the format.
|
---|
| 98 | */
|
---|
[6e6dc7d] | 99 | #define ADD_MATCHID_OR_RETURN(match_ids, score, format, ...) \
|
---|
| 100 | do { \
|
---|
[37e4025] | 101 | char *str = NULL; \
|
---|
| 102 | int __rc = asprintf(&str, format, ##__VA_ARGS__); \
|
---|
| 103 | if (__rc > 0) { \
|
---|
| 104 | __rc = usb_add_match_id((match_ids), (score), str); \
|
---|
| 105 | } \
|
---|
[6e6dc7d] | 106 | if (__rc != EOK) { \
|
---|
[37e4025] | 107 | free(str); \
|
---|
[6e6dc7d] | 108 | return __rc; \
|
---|
| 109 | } \
|
---|
| 110 | } while (0)
|
---|
| 111 |
|
---|
[540e2d2] | 112 | /** Create device match ids based on its interface.
|
---|
| 113 | *
|
---|
[bc1c6fb] | 114 | * @param[in] desc_device Device descriptor.
|
---|
| 115 | * @param[in] desc_interface Interface descriptor.
|
---|
[540e2d2] | 116 | * @param[out] matches Initialized list of match ids.
|
---|
| 117 | * @return Error code (the two mentioned are not the only ones).
|
---|
| 118 | * @retval EINVAL Invalid input parameters (expects non NULL pointers).
|
---|
[bc1c6fb] | 119 | * @retval ENOENT Device class is not "use interface".
|
---|
[540e2d2] | 120 | */
|
---|
| 121 | int usb_device_create_match_ids_from_interface(
|
---|
[51f0e410] | 122 | const usb_standard_device_descriptor_t *desc_device,
|
---|
| 123 | const usb_standard_interface_descriptor_t *desc_interface,
|
---|
[540e2d2] | 124 | match_id_list_t *matches)
|
---|
| 125 | {
|
---|
[37e4025] | 126 | if (desc_interface == NULL || matches == NULL) {
|
---|
[540e2d2] | 127 | return EINVAL;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
[51f0e410] | 130 | if (desc_interface->interface_class == USB_CLASS_USE_INTERFACE) {
|
---|
[540e2d2] | 131 | return ENOENT;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
[51f0e410] | 134 | const char *classname = usb_str_class(desc_interface->interface_class);
|
---|
[540e2d2] | 135 | assert(classname != NULL);
|
---|
| 136 |
|
---|
[51f0e410] | 137 | #define IFACE_PROTOCOL_FMT "interface&class=%s&subclass=0x%02x&protocol=0x%02x"
|
---|
| 138 | #define IFACE_PROTOCOL_ARGS classname, desc_interface->interface_subclass, \
|
---|
| 139 | desc_interface->interface_protocol
|
---|
| 140 |
|
---|
| 141 | #define IFACE_SUBCLASS_FMT "interface&class=%s&subclass=0x%02x"
|
---|
| 142 | #define IFACE_SUBCLASS_ARGS classname, desc_interface->interface_subclass
|
---|
| 143 |
|
---|
| 144 | #define IFACE_CLASS_FMT "interface&class=%s"
|
---|
| 145 | #define IFACE_CLASS_ARGS classname
|
---|
| 146 |
|
---|
| 147 | #define VENDOR_RELEASE_FMT "vendor=0x%04x&product=0x%04x&release=" BCD_FMT
|
---|
| 148 | #define VENDOR_RELEASE_ARGS desc_device->vendor_id, desc_device->product_id, \
|
---|
| 149 | BCD_ARGS(desc_device->device_version)
|
---|
| 150 |
|
---|
| 151 | #define VENDOR_PRODUCT_FMT "vendor=0x%04x&product=0x%04x"
|
---|
| 152 | #define VENDOR_PRODUCT_ARGS desc_device->vendor_id, desc_device->product_id
|
---|
| 153 |
|
---|
| 154 | #define VENDOR_ONLY_FMT "vendor=0x%04x"
|
---|
| 155 | #define VENDOR_ONLY_ARGS desc_device->vendor_id
|
---|
| 156 |
|
---|
| 157 | /*
|
---|
| 158 | * If the vendor is specified, create match ids with vendor with
|
---|
| 159 | * higher score.
|
---|
| 160 | * Then the same ones without the vendor part.
|
---|
| 161 | */
|
---|
| 162 | if ((desc_device != NULL) && (desc_device->vendor_id != 0)) {
|
---|
| 163 | /* First, interface matches with device release number. */
|
---|
| 164 | ADD_MATCHID_OR_RETURN(matches, 250,
|
---|
| 165 | "usb&" VENDOR_RELEASE_FMT "&" IFACE_PROTOCOL_FMT,
|
---|
| 166 | VENDOR_RELEASE_ARGS, IFACE_PROTOCOL_ARGS);
|
---|
| 167 | ADD_MATCHID_OR_RETURN(matches, 240,
|
---|
| 168 | "usb&" VENDOR_RELEASE_FMT "&" IFACE_SUBCLASS_FMT,
|
---|
| 169 | VENDOR_RELEASE_ARGS, IFACE_SUBCLASS_ARGS);
|
---|
| 170 | ADD_MATCHID_OR_RETURN(matches, 230,
|
---|
| 171 | "usb&" VENDOR_RELEASE_FMT "&" IFACE_CLASS_FMT,
|
---|
| 172 | VENDOR_RELEASE_ARGS, IFACE_CLASS_ARGS);
|
---|
| 173 |
|
---|
| 174 | /* Next, interface matches without release number. */
|
---|
| 175 | ADD_MATCHID_OR_RETURN(matches, 220,
|
---|
| 176 | "usb&" VENDOR_PRODUCT_FMT "&" IFACE_PROTOCOL_FMT,
|
---|
| 177 | VENDOR_PRODUCT_ARGS, IFACE_PROTOCOL_ARGS);
|
---|
| 178 | ADD_MATCHID_OR_RETURN(matches, 210,
|
---|
| 179 | "usb&" VENDOR_PRODUCT_FMT "&" IFACE_SUBCLASS_FMT,
|
---|
| 180 | VENDOR_PRODUCT_ARGS, IFACE_SUBCLASS_ARGS);
|
---|
| 181 | ADD_MATCHID_OR_RETURN(matches, 200,
|
---|
| 182 | "usb&" VENDOR_PRODUCT_FMT "&" IFACE_CLASS_FMT,
|
---|
| 183 | VENDOR_PRODUCT_ARGS, IFACE_CLASS_ARGS);
|
---|
| 184 |
|
---|
| 185 | /* Finally, interface matches with only vendor. */
|
---|
| 186 | ADD_MATCHID_OR_RETURN(matches, 190,
|
---|
| 187 | "usb&" VENDOR_ONLY_FMT "&" IFACE_PROTOCOL_FMT,
|
---|
| 188 | VENDOR_ONLY_ARGS, IFACE_PROTOCOL_ARGS);
|
---|
| 189 | ADD_MATCHID_OR_RETURN(matches, 180,
|
---|
| 190 | "usb&" VENDOR_ONLY_FMT "&" IFACE_SUBCLASS_FMT,
|
---|
| 191 | VENDOR_ONLY_ARGS, IFACE_SUBCLASS_ARGS);
|
---|
| 192 | ADD_MATCHID_OR_RETURN(matches, 170,
|
---|
| 193 | "usb&" VENDOR_ONLY_FMT "&" IFACE_CLASS_FMT,
|
---|
| 194 | VENDOR_ONLY_ARGS, IFACE_CLASS_ARGS);
|
---|
| 195 | }
|
---|
| 196 |
|
---|
| 197 | /* Now, the same but without any vendor specification. */
|
---|
| 198 | ADD_MATCHID_OR_RETURN(matches, 160,
|
---|
| 199 | "usb&" IFACE_PROTOCOL_FMT,
|
---|
| 200 | IFACE_PROTOCOL_ARGS);
|
---|
| 201 | ADD_MATCHID_OR_RETURN(matches, 150,
|
---|
| 202 | "usb&" IFACE_SUBCLASS_FMT,
|
---|
| 203 | IFACE_SUBCLASS_ARGS);
|
---|
| 204 | ADD_MATCHID_OR_RETURN(matches, 140,
|
---|
| 205 | "usb&" IFACE_CLASS_FMT,
|
---|
| 206 | IFACE_CLASS_ARGS);
|
---|
| 207 |
|
---|
| 208 | #undef IFACE_PROTOCOL_FMT
|
---|
| 209 | #undef IFACE_PROTOCOL_ARGS
|
---|
| 210 | #undef IFACE_SUBCLASS_FMT
|
---|
| 211 | #undef IFACE_SUBCLASS_ARGS
|
---|
| 212 | #undef IFACE_CLASS_FMT
|
---|
| 213 | #undef IFACE_CLASS_ARGS
|
---|
| 214 | #undef VENDOR_RELEASE_FMT
|
---|
| 215 | #undef VENDOR_RELEASE_ARGS
|
---|
| 216 | #undef VENDOR_PRODUCT_FMT
|
---|
| 217 | #undef VENDOR_PRODUCT_ARGS
|
---|
| 218 | #undef VENDOR_ONLY_FMT
|
---|
| 219 | #undef VENDOR_ONLY_ARGS
|
---|
[540e2d2] | 220 |
|
---|
[2211125e] | 221 | /* As a last resort, try fallback driver. */
|
---|
| 222 | ADD_MATCHID_OR_RETURN(matches, 10, "usb&interface&fallback");
|
---|
| 223 |
|
---|
[6e6dc7d] | 224 | return EOK;
|
---|
[540e2d2] | 225 | }
|
---|
| 226 |
|
---|
[692c0d3e] | 227 | /** Create DDF match ids from USB device descriptor.
|
---|
| 228 | *
|
---|
| 229 | * @param matches List of match ids to extend.
|
---|
| 230 | * @param device_descriptor Device descriptor returned by given device.
|
---|
| 231 | * @return Error code.
|
---|
| 232 | */
|
---|
[0f21c0c] | 233 | int usb_device_create_match_ids_from_device_descriptor(
|
---|
| 234 | const usb_standard_device_descriptor_t *device_descriptor,
|
---|
| 235 | match_id_list_t *matches)
|
---|
[692c0d3e] | 236 | {
|
---|
| 237 | /*
|
---|
| 238 | * Unless the vendor id is 0, the pair idVendor-idProduct
|
---|
| 239 | * quite uniquely describes the device.
|
---|
| 240 | */
|
---|
| 241 | if (device_descriptor->vendor_id != 0) {
|
---|
| 242 | /* First, with release number. */
|
---|
[6e6dc7d] | 243 | ADD_MATCHID_OR_RETURN(matches, 100,
|
---|
[345ea18] | 244 | "usb&vendor=0x%04x&product=0x%04x&release=" BCD_FMT,
|
---|
[692c0d3e] | 245 | (int) device_descriptor->vendor_id,
|
---|
| 246 | (int) device_descriptor->product_id,
|
---|
| 247 | BCD_ARGS(device_descriptor->device_version));
|
---|
| 248 |
|
---|
| 249 | /* Next, without release number. */
|
---|
[6e6dc7d] | 250 | ADD_MATCHID_OR_RETURN(matches, 90,
|
---|
[345ea18] | 251 | "usb&vendor=0x%04x&product=0x%04x",
|
---|
[692c0d3e] | 252 | (int) device_descriptor->vendor_id,
|
---|
| 253 | (int) device_descriptor->product_id);
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 | /*
|
---|
| 257 | * If the device class points to interface we skip adding
|
---|
[3ae93a8] | 258 | * class directly but we add a multi interface device.
|
---|
[692c0d3e] | 259 | */
|
---|
| 260 | if (device_descriptor->device_class != USB_CLASS_USE_INTERFACE) {
|
---|
[6e6dc7d] | 261 | ADD_MATCHID_OR_RETURN(matches, 50, "usb&class=%s",
|
---|
[692c0d3e] | 262 | usb_str_class(device_descriptor->device_class));
|
---|
[3ae93a8] | 263 | } else {
|
---|
[6e6dc7d] | 264 | ADD_MATCHID_OR_RETURN(matches, 50, "usb&mid");
|
---|
[692c0d3e] | 265 | }
|
---|
| 266 |
|
---|
[93855d4] | 267 | /* As a last resort, try fallback driver. */
|
---|
| 268 | ADD_MATCHID_OR_RETURN(matches, 10, "usb&fallback");
|
---|
| 269 |
|
---|
[692c0d3e] | 270 | return EOK;
|
---|
| 271 | }
|
---|
| 272 |
|
---|
[a66225f3] | 273 |
|
---|
[02ccfcd] | 274 | /** Create match ids describing attached device.
|
---|
| 275 | *
|
---|
| 276 | * @warning The list of match ids @p matches may change even when
|
---|
| 277 | * function exits with error.
|
---|
| 278 | *
|
---|
[4e8e1f5] | 279 | * @param ctrl_pipe Control pipe to given device (session must be already
|
---|
| 280 | * started).
|
---|
[02ccfcd] | 281 | * @param matches Initialized list of match ids.
|
---|
| 282 | * @return Error code.
|
---|
| 283 | */
|
---|
[a372663] | 284 | int usb_device_create_match_ids(usb_pipe_t *ctrl_pipe,
|
---|
[4e8e1f5] | 285 | match_id_list_t *matches)
|
---|
[02ccfcd] | 286 | {
|
---|
[2179cf95] | 287 | assert(ctrl_pipe);
|
---|
[02ccfcd] | 288 | int rc;
|
---|
[692c0d3e] | 289 | /*
|
---|
| 290 | * Retrieve device descriptor and add matches from it.
|
---|
| 291 | */
|
---|
[02ccfcd] | 292 | usb_standard_device_descriptor_t device_descriptor;
|
---|
| 293 |
|
---|
[4e8e1f5] | 294 | rc = usb_request_get_device_descriptor(ctrl_pipe, &device_descriptor);
|
---|
[02ccfcd] | 295 | if (rc != EOK) {
|
---|
| 296 | return rc;
|
---|
| 297 | }
|
---|
[4e8e1f5] | 298 |
|
---|
[0f21c0c] | 299 | rc = usb_device_create_match_ids_from_device_descriptor(
|
---|
| 300 | &device_descriptor, matches);
|
---|
[692c0d3e] | 301 | if (rc != EOK) {
|
---|
| 302 | return rc;
|
---|
[a66225f3] | 303 | }
|
---|
[4e8e1f5] | 304 |
|
---|
[02ccfcd] | 305 | return EOK;
|
---|
| 306 | }
|
---|
| 307 |
|
---|
| 308 | /** Probe for device kind and register it in devman.
|
---|
| 309 | *
|
---|
[2179cf95] | 310 | * @param[in] ctrl_pipe Control pipe to the device.
|
---|
[4e8e1f5] | 311 | * @param[in] parent Parent device.
|
---|
[eea3e39] | 312 | * @param[in] dev_ops Child device ops. Default child_ops will be used if NULL.
|
---|
[bc1c6fb] | 313 | * @param[in] dev_data Arbitrary pointer to be stored in the child
|
---|
| 314 | * as @c driver_data.
|
---|
| 315 | * @param[out] child_fun Storage where pointer to allocated child function
|
---|
| 316 | * will be written.
|
---|
[02ccfcd] | 317 | * @return Error code.
|
---|
| 318 | */
|
---|
[2179cf95] | 319 | int usb_device_register_child_in_devman(usb_pipe_t *ctrl_pipe,
|
---|
| 320 | ddf_dev_t *parent, ddf_dev_ops_t *dev_ops, void *dev_data,
|
---|
| 321 | ddf_fun_t **child_fun)
|
---|
[02ccfcd] | 322 | {
|
---|
[2179cf95] | 323 | if (child_fun == NULL || ctrl_pipe == NULL)
|
---|
[ae754e5f] | 324 | return EINVAL;
|
---|
| 325 |
|
---|
[59c163c] | 326 | if (!dev_ops && dev_data) {
|
---|
| 327 | usb_log_warning("Using standard fun ops with arbitrary "
|
---|
| 328 | "driver data. This does not have to work.\n");
|
---|
| 329 | }
|
---|
| 330 |
|
---|
[38648f0] | 331 | fibril_mutex_lock(&device_name_index_mutex);
|
---|
[2179cf95] | 332 | const size_t this_device_name_index = device_name_index++;
|
---|
[38648f0] | 333 | fibril_mutex_unlock(&device_name_index_mutex);
|
---|
| 334 |
|
---|
[eb1a2f4] | 335 | ddf_fun_t *child = NULL;
|
---|
[7ed5b576] | 336 | int rc;
|
---|
| 337 |
|
---|
| 338 | /*
|
---|
[b207803] | 339 | * TODO: Once the device driver framework support persistent
|
---|
| 340 | * naming etc., something more descriptive could be created.
|
---|
[7ed5b576] | 341 | */
|
---|
[2179cf95] | 342 | char child_name[12]; /* The format is: "usbAB_aXYZ", length 11 */
|
---|
| 343 | rc = snprintf(child_name, sizeof(child_name),
|
---|
| 344 | "usb%02zu_a%d", this_device_name_index, ctrl_pipe->wire->address);
|
---|
[7ed5b576] | 345 | if (rc < 0) {
|
---|
| 346 | goto failure;
|
---|
| 347 | }
|
---|
[eb1a2f4] | 348 |
|
---|
| 349 | child = ddf_fun_create(parent, fun_inner, child_name);
|
---|
| 350 | if (child == NULL) {
|
---|
| 351 | rc = ENOMEM;
|
---|
| 352 | goto failure;
|
---|
| 353 | }
|
---|
| 354 |
|
---|
| 355 | if (dev_ops != NULL) {
|
---|
| 356 | child->ops = dev_ops;
|
---|
| 357 | } else {
|
---|
| 358 | child->ops = &child_ops;
|
---|
| 359 | }
|
---|
| 360 |
|
---|
| 361 | child->driver_data = dev_data;
|
---|
[59c163c] | 362 | /* Store the attached device in fun driver data if there is no
|
---|
| 363 | * other data */
|
---|
| 364 | if (!dev_data) {
|
---|
| 365 | usb_hub_attached_device_t *new_device = ddf_fun_data_alloc(
|
---|
| 366 | child, sizeof(usb_hub_attached_device_t));
|
---|
| 367 | if (!new_device) {
|
---|
| 368 | rc = ENOMEM;
|
---|
| 369 | goto failure;
|
---|
| 370 | }
|
---|
[2179cf95] | 371 | new_device->address = ctrl_pipe->wire->address;
|
---|
[59c163c] | 372 | new_device->fun = child;
|
---|
| 373 | }
|
---|
| 374 |
|
---|
[4e8e1f5] | 375 |
|
---|
[2179cf95] | 376 | rc = usb_device_create_match_ids(ctrl_pipe, &child->match_ids);
|
---|
[4e8e1f5] | 377 | if (rc != EOK) {
|
---|
| 378 | goto failure;
|
---|
| 379 | }
|
---|
| 380 |
|
---|
[eb1a2f4] | 381 | rc = ddf_fun_bind(child);
|
---|
[7ed5b576] | 382 | if (rc != EOK) {
|
---|
| 383 | goto failure;
|
---|
| 384 | }
|
---|
| 385 |
|
---|
[ae754e5f] | 386 | *child_fun = child;
|
---|
[7ed5b576] | 387 | return EOK;
|
---|
| 388 |
|
---|
| 389 | failure:
|
---|
| 390 | if (child != NULL) {
|
---|
[59c163c] | 391 | /* We know nothing about the data if it came from outside. */
|
---|
| 392 | if (dev_data) {
|
---|
| 393 | child->driver_data = NULL;
|
---|
| 394 | }
|
---|
[7ed5b576] | 395 | /* This takes care of match_id deallocation as well. */
|
---|
[eb1a2f4] | 396 | ddf_fun_destroy(child);
|
---|
[7ed5b576] | 397 | }
|
---|
| 398 |
|
---|
| 399 | return rc;
|
---|
[02ccfcd] | 400 | }
|
---|
[7ed5b576] | 401 |
|
---|
[02ccfcd] | 402 |
|
---|
| 403 | /**
|
---|
| 404 | * @}
|
---|
| 405 | */
|
---|