Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbmid/usbmid.c

    r87a3df7f r58563585  
    3535 * Helper functions.
    3636 */
     37
    3738#include <errno.h>
    3839#include <str_error.h>
    3940#include <stdlib.h>
    4041#include <usb_iface.h>
    41 #include <usb/ddfiface.h>
    4242#include <usb/dev/pipes.h>
    4343#include <usb/classes/classes.h>
     
    4545#include "usbmid.h"
    4646
    47 /** Callback for DDF USB interface. */
    48 static int usb_iface_get_interface_impl(ddf_fun_t *fun, int *iface_no)
     47/** Get USB device handle by calling the parent usb_device_t.
     48 *
     49 * @param[in] fun Device function the operation is running on.
     50 * @param[out] handle Device handle.
     51 * @return Error code.
     52 */
     53static int usb_iface_device_handle(ddf_fun_t *fun, devman_handle_t *handle)
     54{
     55        assert(fun);
     56        assert(handle);
     57        usb_device_t *usb_dev = usb_device_get(ddf_fun_get_dev(fun));
     58        *handle = usb_device_get_devman_handle(usb_dev);
     59        return EOK;
     60}
     61
     62/** Callback for DDF USB get interface. */
     63static int usb_iface_iface_no(ddf_fun_t *fun, int *iface_no)
    4964{
    5065        usbmid_interface_t *iface = ddf_fun_data_get(fun);
    5166        assert(iface);
    5267
    53         if (iface_no != NULL) {
     68        if (iface_no)
    5469                *iface_no = iface->interface_no;
    55         }
    5670
    5771        return EOK;
    5872}
    5973
    60 /** DDF interface of the child - interface function. */
     74/** DDF interface of the child - USB functions. */
    6175static usb_iface_t child_usb_iface = {
    62         .get_hc_handle = usb_iface_get_hc_handle_device_impl,
    63         .get_my_address = usb_iface_get_my_address_forward_impl,
    64         .get_my_interface = usb_iface_get_interface_impl,
     76        .get_my_device_handle = usb_iface_device_handle,
     77        .get_my_interface = usb_iface_iface_no,
    6578};
    6679
     
    7891                return ret;
    7992        }
    80         /* NOTE: usbmid->interface points somewhere, but we did not
    81          * allocate that space, so don't touch */
    8293        ddf_fun_destroy(mid_iface->fun);
    83         /* NOTE: mid_iface is invalid at this point, it was assigned to
    84          * mid_iface->fun->driver_data and freed in ddf_fun_destroy */
    8594        return EOK;
    8695}
     
    95104 */
    96105int usbmid_spawn_interface_child(usb_device_t *parent,
    97     usbmid_interface_t *iface,
     106    usbmid_interface_t **iface_ret,
    98107    const usb_standard_device_descriptor_t *device_descriptor,
    99108    const usb_standard_interface_descriptor_t *interface_descriptor)
    100109{
     110        ddf_fun_t *child = NULL;
    101111        char *child_name = NULL;
    102112        int rc;
     
    110120            usb_str_class(interface_descriptor->interface_class),
    111121            interface_descriptor->interface_number);
    112         if (rc < 0)
     122        if (rc < 0) {
    113123                return ENOMEM;
     124        }
    114125
    115         rc = ddf_fun_set_name(iface->fun, child_name);
     126        /* Create the device. */
     127        child = usb_device_ddf_fun_create(parent, fun_inner, child_name);
    116128        free(child_name);
    117         if (rc != EOK)
     129        if (child == NULL) {
    118130                return ENOMEM;
     131        }
    119132
    120133        match_id_list_t match_ids;
     
    123136        rc = usb_device_create_match_ids_from_interface(device_descriptor,
    124137            interface_descriptor, &match_ids);
    125         if (rc != EOK)
     138        if (rc != EOK) {
     139                ddf_fun_destroy(child);
    126140                return rc;
     141        }
    127142
    128143        list_foreach(match_ids.ids, link, match_id_t, match_id) {
    129                 rc = ddf_fun_add_match_id(iface->fun, match_id->id, match_id->score);
     144                rc = ddf_fun_add_match_id(child, match_id->id, match_id->score);
    130145                if (rc != EOK) {
    131146                        clean_match_ids(&match_ids);
     147                        ddf_fun_destroy(child);
    132148                        return rc;
    133149                }
    134150        }
    135151        clean_match_ids(&match_ids);
     152        ddf_fun_set_ops(child, &child_device_ops);
    136153
    137         ddf_fun_set_ops(iface->fun, &child_device_ops);
     154        usbmid_interface_t *iface = ddf_fun_data_alloc(child, sizeof(*iface));
    138155
    139         rc = ddf_fun_bind(iface->fun);
    140         if (rc != EOK)
     156        iface->fun = child;
     157        iface->interface_no = interface_descriptor->interface_number;
     158        link_initialize(&iface->link);
     159
     160        rc = ddf_fun_bind(child);
     161        if (rc != EOK) {
     162                /* This takes care of match_id deallocation as well. */
     163                ddf_fun_destroy(child);
    141164                return rc;
     165        }
     166        *iface_ret = iface;
    142167
    143168        return EOK;
Note: See TracChangeset for help on using the changeset viewer.