Changes in uspace/drv/bus/usb/usbmid/explore.c [58563585:56fd7cf] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbmid/explore.c
r58563585 r56fd7cf 34 34 * Exploration of available interfaces in the USB device. 35 35 */ 36 37 36 #include <errno.h> 38 37 #include <str_error.h> … … 41 40 #include <usb/dev/request.h> 42 41 #include <usb/dev/dp.h> 42 #include <usb/ddfiface.h> 43 43 #include "usbmid.h" 44 45 /** Operations of the device itself. */ 46 static ddf_dev_ops_t mid_device_ops = { 47 .interfaces[USB_DEV_IFACE] = &usb_iface_hub_impl 48 }; 44 49 45 50 /** Tell whether given interface is already in the list. … … 51 56 static bool interface_in_list(const list_t *list, int interface_no) 52 57 { 53 list_foreach(*list, link, const usbmid_interface_t, iface) { 58 list_foreach(*list, l) { 59 usbmid_interface_t *iface = usbmid_interface_from_link(l); 54 60 if (iface->interface_no == interface_no) { 55 61 return true; … … 66 72 * @param list List where to add the interfaces. 67 73 */ 68 static intcreate_interfaces(const uint8_t *config_descriptor,69 size_t config_descriptor_size, list_t *list , usb_device_t *usb_dev)74 static void create_interfaces(const uint8_t *config_descriptor, 75 size_t config_descriptor_size, list_t *list) 70 76 { 71 assert(config_descriptor);72 assert(usb_dev);73 74 77 const usb_dp_parser_data_t data = { 75 78 .data = config_descriptor, … … 87 90 /* Walk all descriptors nested in the current configuration decriptor; 88 91 * i.e. all interface descriptors. */ 89 for (; 92 for (;interface_ptr != NULL; 90 93 interface_ptr = usb_dp_get_sibling_descriptor( 91 94 &parser, &data, config_descriptor, interface_ptr)) … … 104 107 continue; 105 108 } 106 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) { 109 usbmid_interface_t *iface = malloc(sizeof(usbmid_interface_t)); 110 if (iface == NULL) { 116 111 //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 } 125 return EOK; 112 break; 113 } 114 115 link_initialize(&iface->link); 116 iface->fun = NULL; 117 iface->interface_no = interface->interface_number; 118 iface->interface = interface; 119 120 list_append(&iface->link, list); 121 } 126 122 } 127 123 … … 134 130 * @return Whether to accept this device from devman. 135 131 */ 136 intusbmid_explore_device(usb_device_t *dev)132 bool usbmid_explore_device(usb_device_t *dev) 137 133 { 138 assert(dev);139 const unsigned dev_class = 140 usb_device_descriptors(dev)->device.device_class;134 int rc; 135 136 unsigned dev_class = dev->descriptors.device.device_class; 141 137 if (dev_class != USB_CLASS_USE_INTERFACE) { 142 138 usb_log_warning( … … 144 140 dev_class, usb_str_class(dev_class), 145 141 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; 142 usb_log_error("Not multi interface device, refusing.\n"); 143 return false; 144 } 145 146 /* Shortcuts to save on typing ;-). */ 147 const void *config_descriptor_raw = dev->descriptors.configuration; 148 size_t config_descriptor_size = dev->descriptors.configuration_size; 155 149 const usb_standard_configuration_descriptor_t *config_descriptor = 156 150 config_descriptor_raw; 157 151 158 152 /* Select the first configuration */ 159 int rc = usb_request_set_configuration(usb_device_get_default_pipe(dev),153 rc = usb_request_set_configuration(&dev->ctrl_pipe, 160 154 config_descriptor->configuration_number); 161 155 if (rc != EOK) { 162 156 usb_log_error("Failed to set device configuration: %s.\n", 163 157 str_error(rc)); 164 return rc;165 } 166 158 return false; 159 } 160 167 161 /* Create driver soft-state. */ 168 162 usb_mid_t *usb_mid = usb_device_data_alloc(dev, sizeof(usb_mid_t)); 169 163 if (!usb_mid) { 170 164 usb_log_error("Failed to create USB MID structure.\n"); 171 return ENOMEM;165 return false; 172 166 } 173 167 174 168 /* Create control function. */ 175 usb_mid->ctl_fun = usb_device_ddf_fun_create(dev, fun_exposed, "ctl");169 usb_mid->ctl_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, "ctl"); 176 170 if (usb_mid->ctl_fun == NULL) { 177 171 usb_log_error("Failed to create control function.\n"); 178 return ENOMEM; 179 } 172 return false; 173 } 174 ddf_fun_set_ops(usb_mid->ctl_fun, &mid_device_ops); 180 175 181 176 /* Bind control function. */ … … 185 180 str_error(rc)); 186 181 ddf_fun_destroy(usb_mid->ctl_fun); 187 return rc; 188 } 182 return false; 183 } 184 189 185 190 186 /* Create interface children. */ 191 187 list_initialize(&usb_mid->interface_list); 192 188 create_interfaces(config_descriptor_raw, config_descriptor_size, 193 &usb_mid->interface_list, dev); 194 195 return EOK; 189 &usb_mid->interface_list); 190 191 /* Start child function for every interface. */ 192 list_foreach(usb_mid->interface_list, link) { 193 usbmid_interface_t *iface = usbmid_interface_from_link(link); 194 195 usb_log_info("Creating child for interface %d (%s).\n", 196 iface->interface_no, 197 usb_str_class(iface->interface->interface_class)); 198 199 rc = usbmid_spawn_interface_child(dev, iface, 200 &dev->descriptors.device, iface->interface); 201 if (rc != EOK) { 202 usb_log_error("Failed to create interface child: %s.\n", 203 str_error(rc)); 204 } 205 } 206 207 return true; 196 208 } 197 209
Note:
See TracChangeset
for help on using the changeset viewer.