Changes in uspace/drv/bus/usb/usbmid/explore.c [58563585:87a3df7f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbmid/explore.c
r58563585 r87a3df7f 34 34 * Exploration of available interfaces in the USB device. 35 35 */ 36 36 #include <ddf/driver.h> 37 37 #include <errno.h> 38 38 #include <str_error.h> … … 41 41 #include <usb/dev/request.h> 42 42 #include <usb/dev/dp.h> 43 #include <usb/ddfiface.h> 43 44 #include "usbmid.h" 45 46 /** Operations of the device itself. */ 47 static ddf_dev_ops_t mid_device_ops = { 48 .interfaces[USB_DEV_IFACE] = &usb_iface_hub_impl 49 }; 44 50 45 51 /** Tell whether given interface is already in the list. … … 51 57 static bool interface_in_list(const list_t *list, int interface_no) 52 58 { 53 list_foreach(*list, link, constusbmid_interface_t, iface) {59 list_foreach(*list, link, usbmid_interface_t, iface) { 54 60 if (iface->interface_no == interface_no) { 55 61 return true; … … 65 71 * @param config_descriptor_size Size of configuration descriptor in bytes. 66 72 * @param list List where to add the interfaces. 67 */ 68 static int create_interfaces(const uint8_t *config_descriptor, 69 size_t config_descriptor_size, list_t *list, usb_device_t *usb_dev) 73 * @return EOK on success, ENOMEM if out of memory. 74 */ 75 static int create_interfaces(usb_mid_t *mid, const uint8_t *config_descriptor, 76 size_t config_descriptor_size) 70 77 { 71 assert(config_descriptor);72 assert(usb_dev);73 74 78 const usb_dp_parser_data_t data = { 75 79 .data = config_descriptor, … … 87 91 /* Walk all descriptors nested in the current configuration decriptor; 88 92 * i.e. all interface descriptors. */ 89 for (; 93 for (;interface_ptr != NULL; 90 94 interface_ptr = usb_dp_get_sibling_descriptor( 91 95 &parser, &data, config_descriptor, interface_ptr)) … … 99 103 100 104 /* Skip alternate interfaces. */ 101 if (interface_in_list(list, interface->interface_number)) { 105 if (interface_in_list(&mid->interface_list, 106 interface->interface_number)) { 102 107 /* TODO: add the alternatives and create match ids 103 108 * for them. */ … … 105 110 } 106 111 107 108 usb_log_info("Creating child for interface %d (%s).\n",109 interface->interface_number,110 usb_str_class(interface->interface_class));111 112 usbmid_interface_t *iface = NULL;113 const int rc = usbmid_spawn_interface_child(usb_dev, &iface,114 &usb_device_descriptors(usb_dev)->device, interface);115 if (rc != EOK) {116 //TODO: Do something about that failure. 117 usb_log_error("Failed to create interface child for "118 "%d (%s): %s.\n", interface->interface_number,119 usb_str_class(interface->interface_class),120 str_error(rc));121 } else { 122 list_append(&iface->link,list);123 124 } 112 /* Create the function */ 113 ddf_fun_t *fun = ddf_fun_create(mid->dev, fun_inner, NULL); 114 if (fun == NULL) 115 goto error; 116 117 usbmid_interface_t *iface = ddf_fun_data_alloc(fun, 118 sizeof(usbmid_interface_t)); 119 if (iface == NULL) 120 goto error; 121 122 link_initialize(&iface->link); 123 iface->fun = fun; 124 iface->interface_no = interface->interface_number; 125 iface->interface = interface; 126 127 list_append(&iface->link, &mid->interface_list); 128 } 129 125 130 return EOK; 131 error: 132 while (!list_empty(&mid->interface_list)) { 133 link_t *link = list_first(&mid->interface_list); 134 usbmid_interface_t *iface = list_get_instance(link, 135 usbmid_interface_t, link); 136 137 ddf_fun_destroy(iface->fun); 138 } 139 140 return ENOMEM; 126 141 } 127 142 … … 134 149 * @return Whether to accept this device from devman. 135 150 */ 136 intusbmid_explore_device(usb_device_t *dev)151 bool usbmid_explore_device(usb_device_t *dev) 137 152 { 138 assert(dev);139 const unsigned dev_class = 140 usb_device_descriptors(dev)->device.device_class;153 int rc; 154 155 unsigned dev_class = dev->descriptors.device.device_class; 141 156 if (dev_class != USB_CLASS_USE_INTERFACE) { 142 157 usb_log_warning( … … 144 159 dev_class, usb_str_class(dev_class), 145 160 USB_CLASS_USE_INTERFACE); 146 usb_log_error("Not a multi-interface device, refusing.\n"); 147 return ENOTSUP; 148 } 149 150 /* Get coonfiguration descriptor. */ 151 const size_t config_descriptor_size = 152 usb_device_descriptors(dev)->full_config_size; 153 const void *config_descriptor_raw = 154 usb_device_descriptors(dev)->full_config; 161 usb_log_error("Not multi interface device, refusing.\n"); 162 return false; 163 } 164 165 /* Shortcuts to save on typing ;-). */ 166 const void *config_descriptor_raw = dev->descriptors.configuration; 167 size_t config_descriptor_size = dev->descriptors.configuration_size; 155 168 const usb_standard_configuration_descriptor_t *config_descriptor = 156 169 config_descriptor_raw; 157 170 158 171 /* Select the first configuration */ 159 int rc = usb_request_set_configuration(usb_device_get_default_pipe(dev),172 rc = usb_request_set_configuration(&dev->ctrl_pipe, 160 173 config_descriptor->configuration_number); 161 174 if (rc != EOK) { 162 175 usb_log_error("Failed to set device configuration: %s.\n", 163 176 str_error(rc)); 164 return rc;165 } 166 177 return false; 178 } 179 167 180 /* Create driver soft-state. */ 168 181 usb_mid_t *usb_mid = usb_device_data_alloc(dev, sizeof(usb_mid_t)); 169 182 if (!usb_mid) { 170 183 usb_log_error("Failed to create USB MID structure.\n"); 171 return ENOMEM; 172 } 184 return false; 185 } 186 187 usb_mid->dev = dev->ddf_dev; 173 188 174 189 /* Create control function. */ 175 usb_mid->ctl_fun = usb_device_ddf_fun_create(dev, fun_exposed, "ctl");190 usb_mid->ctl_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, "ctl"); 176 191 if (usb_mid->ctl_fun == NULL) { 177 192 usb_log_error("Failed to create control function.\n"); 178 return ENOMEM; 179 } 193 return false; 194 } 195 ddf_fun_set_ops(usb_mid->ctl_fun, &mid_device_ops); 180 196 181 197 /* Bind control function. */ … … 185 201 str_error(rc)); 186 202 ddf_fun_destroy(usb_mid->ctl_fun); 187 return rc;203 return false; 188 204 } 189 205 190 206 /* Create interface children. */ 191 207 list_initialize(&usb_mid->interface_list); 192 create_interfaces(config_descriptor_raw, config_descriptor_size, 193 &usb_mid->interface_list, dev); 194 195 return EOK; 208 create_interfaces(usb_mid, config_descriptor_raw, config_descriptor_size); 209 210 /* Start child function for every interface. */ 211 list_foreach(usb_mid->interface_list, link, usbmid_interface_t, iface) { 212 usb_log_info("Creating child for interface %d (%s).\n", 213 iface->interface_no, 214 usb_str_class(iface->interface->interface_class)); 215 216 rc = usbmid_spawn_interface_child(dev, iface, 217 &dev->descriptors.device, iface->interface); 218 if (rc != EOK) { 219 usb_log_error("Failed to create interface child: %s.\n", 220 str_error(rc)); 221 } 222 } 223 224 return true; 196 225 } 197 226
Note:
See TracChangeset
for help on using the changeset viewer.