Changes in uspace/drv/bus/usb/usbmid/explore.c [9f583151:5203e256] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbmid/explore.c
r9f583151 r5203e256 57 57 { 58 58 list_foreach(*list, l) { 59 usbmid_interface_t *iface = usbmid_interface_from_link(l); 59 usbmid_interface_t *iface 60 = list_get_instance(l, usbmid_interface_t, link); 60 61 if (iface->interface_no == interface_no) { 61 62 return true; … … 72 73 * @param list List where to add the interfaces. 73 74 */ 74 static void create_interfaces( constuint8_t *config_descriptor,75 static void create_interfaces(uint8_t *config_descriptor, 75 76 size_t config_descriptor_size, list_t *list) 76 77 { 77 constusb_dp_parser_data_t data = {78 usb_dp_parser_data_t data = { 78 79 .data = config_descriptor, 79 80 .size = config_descriptor_size, … … 81 82 }; 82 83 83 static constusb_dp_parser_t parser = {84 usb_dp_parser_t parser = { 84 85 .nesting = usb_dp_standard_descriptor_nesting 85 86 }; 86 87 87 const uint8_t *interface_ptr = 88 usb_dp_get_nested_descriptor(&parser, &data, config_descriptor); 89 90 /* Walk all descriptors nested in the current configuration decriptor; 91 * i.e. all interface descriptors. */ 92 for (;interface_ptr != NULL; 93 interface_ptr = usb_dp_get_sibling_descriptor( 94 &parser, &data, config_descriptor, interface_ptr)) 95 { 96 /* The second byte is DESCTYPE byte in all desriptors. */ 97 if (interface_ptr[1] != USB_DESCTYPE_INTERFACE) 98 continue; 99 100 const usb_standard_interface_descriptor_t *interface 88 uint8_t *interface_ptr = usb_dp_get_nested_descriptor(&parser, &data, 89 data.data); 90 if (interface_ptr == NULL) { 91 return; 92 } 93 94 do { 95 if (interface_ptr[1] != USB_DESCTYPE_INTERFACE) { 96 goto next_descriptor; 97 } 98 99 usb_standard_interface_descriptor_t *interface 101 100 = (usb_standard_interface_descriptor_t *) interface_ptr; 102 101 103 102 /* Skip alternate interfaces. */ 104 if (interface_in_list(list, interface->interface_number)) { 105 /* TODO: add the alternatives and create match ids 106 * for them. */ 107 continue; 108 } 109 usbmid_interface_t *iface = malloc(sizeof(usbmid_interface_t)); 110 if (iface == NULL) { 111 //TODO: Do something about that failure. 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 } 103 if (!interface_in_list(list, interface->interface_number)) { 104 usbmid_interface_t *iface 105 = malloc(sizeof(usbmid_interface_t)); 106 if (iface == NULL) { 107 break; 108 } 109 link_initialize(&iface->link); 110 iface->fun = NULL; 111 iface->interface_no = interface->interface_number; 112 iface->interface = interface; 113 114 list_append(&iface->link, list); 115 } 116 117 /* TODO: add the alternatives and create match ids from them 118 * as well. 119 */ 120 121 next_descriptor: 122 interface_ptr = usb_dp_get_sibling_descriptor(&parser, &data, 123 data.data, interface_ptr); 124 125 } while (interface_ptr != NULL); 126 122 127 } 123 128 … … 134 139 int rc; 135 140 136 unsigneddev_class = dev->descriptors.device.device_class;141 int dev_class = dev->descriptors.device.device_class; 137 142 if (dev_class != USB_CLASS_USE_INTERFACE) { 138 143 usb_log_warning( 139 "Device class: %u (%s), but expected class %u.\n", 140 dev_class, usb_str_class(dev_class), 141 USB_CLASS_USE_INTERFACE); 144 "Device class: %d (%s), but expected class 0.\n", 145 dev_class, usb_str_class(dev_class)); 142 146 usb_log_error("Not multi interface device, refusing.\n"); 143 147 return false; 144 148 } 145 149 146 /* Short cuts to save on typing ;-). */147 const void*config_descriptor_raw = dev->descriptors.configuration;150 /* Short cuts to save on typing ;-). */ 151 uint8_t *config_descriptor_raw = dev->descriptors.configuration; 148 152 size_t config_descriptor_size = dev->descriptors.configuration_size; 149 constusb_standard_configuration_descriptor_t *config_descriptor =150 config_descriptor_raw;153 usb_standard_configuration_descriptor_t *config_descriptor = 154 (usb_standard_configuration_descriptor_t *) config_descriptor_raw; 151 155 152 156 /* Select the first configuration */ … … 159 163 } 160 164 161 /* Create driver soft-state. */ 162 usb_mid_t *usb_mid = usb_device_data_alloc(dev, sizeof(usb_mid_t)); 163 if (!usb_mid) { 164 usb_log_error("Failed to create USB MID structure.\n"); 165 return false; 166 } 167 168 /* Create control function. */ 169 usb_mid->ctl_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, "ctl"); 170 if (usb_mid->ctl_fun == NULL) { 165 /* Create control function */ 166 ddf_fun_t *ctl_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, "ctl"); 167 if (ctl_fun == NULL) { 171 168 usb_log_error("Failed to create control function.\n"); 172 169 return false; 173 170 } 174 usb_mid->ctl_fun->ops = &mid_device_ops; 175 176 /* Bind control function. */ 177 rc = ddf_fun_bind( usb_mid->ctl_fun);171 172 ctl_fun->ops = &mid_device_ops; 173 174 rc = ddf_fun_bind(ctl_fun); 178 175 if (rc != EOK) { 179 176 usb_log_error("Failed to bind control function: %s.\n", 180 177 str_error(rc)); 181 ddf_fun_destroy(usb_mid->ctl_fun); 182 return false; 183 } 184 178 return false; 179 } 185 180 186 181 /* Create interface children. */ 187 list_initialize(&usb_mid->interface_list); 182 list_t interface_list; 183 list_initialize(&interface_list); 188 184 create_interfaces(config_descriptor_raw, config_descriptor_size, 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);185 &interface_list); 186 187 list_foreach(interface_list, link) { 188 usbmid_interface_t *iface = list_get_instance(link, 189 usbmid_interface_t, link); 194 190 195 191 usb_log_info("Creating child for interface %d (%s).\n", 196 iface->interface_no,192 (int) iface->interface_no, 197 193 usb_str_class(iface->interface->interface_class)); 198 194
Note:
See TracChangeset
for help on using the changeset viewer.