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