Changes in / [2e1d5d70:0e45e7f] in mainline
- Location:
- uspace
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/usbinfo/info.c
r2e1d5d70 r0e45e7f 42 42 #include <usb/classes/classes.h> 43 43 #include <usb/classes/hid.h> 44 #include <usb/classes/hub.h> 44 45 #include "usbinfo.h" 45 46 … … 119 120 usb_standard_configuration_descriptor_t *descriptor) 120 121 { 121 printf("%sConfiguration #%d (%zu interfaces )\n", prefix,122 printf("%sConfiguration #%d (%zu interfaces, total %zuB)\n", prefix, 122 123 (int) descriptor->configuration_number, 123 (size_t) descriptor->interface_count); 124 (size_t) descriptor->interface_count, 125 (size_t) descriptor->total_length); 124 126 } 125 127 … … 156 158 } 157 159 158 159 static void dump_descriptor_tree_brief_callback(uint8_t *descriptor, 160 static void dump_descriptor_tree_brief_hub(const char *prefix, 161 usb_hub_descriptor_header_t *descriptor) 162 { 163 printf("%shub (%d ports)\n", prefix, 164 (int) descriptor->port_count); 165 } 166 167 168 static void dump_descriptor_tree_callback(uint8_t *descriptor, 160 169 size_t depth, void *arg) 161 170 { … … 174 183 if (descr_size >= sizeof(descriptor_type)) { \ 175 184 callback(indent, (descriptor_type *) descriptor); \ 185 if (arg != NULL) { \ 186 usb_dump_standard_descriptor(stdout, \ 187 get_indent(depth +2), "\n", \ 188 descriptor, descr_size); \ 189 } \ 176 190 } else { \ 177 191 descr_type = -1; \ … … 194 208 usb_standard_hid_descriptor_t, 195 209 dump_descriptor_tree_brief_hid); 210 /* 211 * Probably useless, hub descriptor shall not be part of 212 * configuration descriptor. 213 */ 214 _BRANCH(USB_DESCTYPE_HUB, 215 usb_hub_descriptor_header_t, 216 dump_descriptor_tree_brief_hub); 196 217 197 218 default: … … 206 227 void dump_descriptor_tree_brief(usbinfo_device_t *dev) 207 228 { 208 dump_descriptor_tree_ brief_callback((uint8_t *)&dev->device_descriptor,229 dump_descriptor_tree_callback((uint8_t *)&dev->device_descriptor, 209 230 (size_t) -1, NULL); 210 231 usb_dp_walk_simple(dev->full_configuration_descriptor, 211 232 dev->full_configuration_descriptor_size, 212 233 usb_dp_standard_descriptor_nesting, 213 dump_descriptor_tree_ brief_callback,234 dump_descriptor_tree_callback, 214 235 NULL); 215 236 } 237 238 void dump_descriptor_tree_full(usbinfo_device_t *dev) 239 { 240 dump_descriptor_tree_callback((uint8_t *)&dev->device_descriptor, 241 (size_t) -1, dev); 242 usb_dp_walk_simple(dev->full_configuration_descriptor, 243 dev->full_configuration_descriptor_size, 244 usb_dp_standard_descriptor_nesting, 245 dump_descriptor_tree_callback, 246 dev); 247 } 248 216 249 217 250 void dump_strings(usbinfo_device_t *dev) -
uspace/app/usbinfo/main.c
r2e1d5d70 r0e45e7f 134 134 _OPTION("-m --match-ids", "Print match ids generated for the device."); 135 135 _OPTION("-t --descriptor-tree", "Print descriptor tree."); 136 _OPTION("-T --descriptor-tree-full", "Print detailed descriptor tree"); 136 137 _OPTION("-s --strings", "Try to print all string descriptors."); 137 138 … … 149 150 {"match-ids", no_argument, NULL, 'm'}, 150 151 {"descriptor-tree", no_argument, NULL, 't'}, 152 {"descriptor-tree-full", no_argument, NULL, 'T'}, 151 153 {"strings", no_argument, NULL, 's'}, 152 154 {0, 0, NULL, 0} 153 155 }; 154 static const char *short_options = "himt s";156 static const char *short_options = "himtTs"; 155 157 156 158 static usbinfo_action_t actions[] = { … … 168 170 .opt = 't', 169 171 .action = dump_descriptor_tree_brief, 172 .active = false 173 }, 174 { 175 .opt = 'T', 176 .action = dump_descriptor_tree_full, 170 177 .active = false 171 178 }, -
uspace/app/usbinfo/usbinfo.h
r2e1d5d70 r0e45e7f 82 82 void dump_device_match_ids(usbinfo_device_t *); 83 83 void dump_descriptor_tree_brief(usbinfo_device_t *); 84 void dump_descriptor_tree_full(usbinfo_device_t *); 84 85 void dump_strings(usbinfo_device_t *); 85 86 -
uspace/lib/usb/include/usb/classes/hub.h
r2e1d5d70 r0e45e7f 60 60 } usb_hub_class_feature_t; 61 61 62 /** Header of standard hub descriptor without the "variadic" part. */ 63 typedef struct { 64 /** Descriptor length. */ 65 uint8_t length; 66 /** Descriptor type (0x29). */ 67 uint8_t descriptor_type; 68 /** Number of downstream ports. */ 69 uint8_t port_count; 70 /** Characteristics bitmask. */ 71 uint16_t characteristics; 72 /** Time from power-on to stabilization of current on the port. */ 73 uint8_t power_good_time; 74 /** Maximum current requirements in mA. */ 75 uint8_t max_current; 76 } __attribute__ ((packed)) usb_hub_descriptor_header_t; 62 77 63 78 /** -
uspace/lib/usb/include/usb/request.h
r2e1d5d70 r0e45e7f 94 94 uint16_t, uint16_t, void *, size_t, size_t *); 95 95 96 int usb_request_get_status(usb_endpoint_pipe_t *, usb_request_recipient_t, 97 uint16_t, uint16_t *); 98 int usb_request_clear_feature(usb_endpoint_pipe_t *, usb_request_type_t, 99 usb_request_recipient_t, uint16_t, uint16_t); 100 int usb_request_set_feature(usb_endpoint_pipe_t *, usb_request_type_t, 101 usb_request_recipient_t, uint16_t, uint16_t); 96 102 int usb_request_set_address(usb_endpoint_pipe_t *, usb_address_t); 97 103 int usb_request_get_descriptor(usb_endpoint_pipe_t *, usb_request_type_t, … … 108 114 int usb_request_get_full_configuration_descriptor_alloc(usb_endpoint_pipe_t *, 109 115 int, void **, size_t *); 116 int usb_request_set_descriptor(usb_endpoint_pipe_t *, usb_request_type_t, 117 usb_request_recipient_t, uint8_t, uint8_t, uint16_t, void *, size_t); 118 int usb_request_get_configuration(usb_endpoint_pipe_t *, uint8_t *); 110 119 int usb_request_set_configuration(usb_endpoint_pipe_t *, uint8_t); 120 int usb_request_get_interface(usb_endpoint_pipe_t *, uint8_t, uint8_t *); 121 int usb_request_set_interface(usb_endpoint_pipe_t *, uint8_t, uint8_t); 111 122 112 123 int usb_request_get_supported_languages(usb_endpoint_pipe_t *, -
uspace/lib/usb/src/request.c
r2e1d5d70 r0e45e7f 157 157 } 158 158 159 /** Retrieve status of a USB device. 160 * 161 * @param[in] pipe Control endpoint pipe (session must be already started). 162 * @param[in] index Recipient index (in native endianness). 163 * @param[in] recipient Recipient of the GET_STATUS request. 164 * @param[out] status Recipient status (in native endianness). 165 * @return Error code. 166 */ 167 int usb_request_get_status(usb_endpoint_pipe_t *pipe, 168 usb_request_recipient_t recipient, uint16_t index, 169 uint16_t *status) 170 { 171 if ((recipient == USB_REQUEST_RECIPIENT_DEVICE) && (index != 0)) { 172 return EINVAL; 173 } 174 175 if (status == NULL) { 176 return EBADMEM; 177 } 178 179 uint16_t status_usb_endianess; 180 size_t data_transfered_size; 181 int rc = usb_control_request_get(pipe, USB_REQUEST_TYPE_STANDARD, 182 recipient, USB_DEVREQ_GET_STATUS, 0, uint16_host2usb(index), 183 &status_usb_endianess, 2, &data_transfered_size); 184 if (rc != EOK) { 185 return rc; 186 } 187 if (data_transfered_size != 2) { 188 return ELIMIT; 189 } 190 191 *status = uint16_usb2host(status_usb_endianess); 192 193 return EOK; 194 } 195 196 /** Clear or disable specific device feature. 197 * 198 * @param[in] pipe Control endpoint pipe (session must be already started). 199 * @param[in] request_type Request type (standard/class/vendor). 200 * @param[in] recipient Recipient of the CLEAR_FEATURE request. 201 * @param[in] feature_selector Feature selector (in native endianness). 202 * @param[in] index Recipient index (in native endianness). 203 * @return Error code. 204 */ 205 int usb_request_clear_feature(usb_endpoint_pipe_t *pipe, 206 usb_request_type_t request_type, usb_request_recipient_t recipient, 207 uint16_t feature_selector, uint16_t index) 208 { 209 if (request_type == USB_REQUEST_TYPE_STANDARD) { 210 if ((recipient == USB_REQUEST_RECIPIENT_DEVICE) 211 && (index != 0)) { 212 return EINVAL; 213 } 214 } 215 216 int rc = usb_control_request_set(pipe, request_type, recipient, 217 USB_DEVREQ_CLEAR_FEATURE, 218 uint16_host2usb(feature_selector), uint16_host2usb(index), 219 NULL, 0); 220 221 return rc; 222 } 223 224 /** Set or enable specific device feature. 225 * 226 * @param[in] pipe Control endpoint pipe (session must be already started). 227 * @param[in] request_type Request type (standard/class/vendor). 228 * @param[in] recipient Recipient of the SET_FEATURE request. 229 * @param[in] feature_selector Feature selector (in native endianness). 230 * @param[in] index Recipient index (in native endianness). 231 * @return Error code. 232 */ 233 int usb_request_set_feature(usb_endpoint_pipe_t *pipe, 234 usb_request_type_t request_type, usb_request_recipient_t recipient, 235 uint16_t feature_selector, uint16_t index) 236 { 237 if (request_type == USB_REQUEST_TYPE_STANDARD) { 238 if ((recipient == USB_REQUEST_RECIPIENT_DEVICE) 239 && (index != 0)) { 240 return EINVAL; 241 } 242 } 243 244 int rc = usb_control_request_set(pipe, request_type, recipient, 245 USB_DEVREQ_SET_FEATURE, 246 uint16_host2usb(feature_selector), uint16_host2usb(index), 247 NULL, 0); 248 249 return rc; 250 } 251 159 252 /** Change address of connected device. 160 253 * This function automatically updates the backing connection to point to … … 473 566 } 474 567 568 /** Update existing or add new USB descriptor to a USB device. 569 * 570 * @param[in] pipe Control endpoint pipe (session must be already started). 571 * @param[in] request_type Request type (standard/class/vendor). 572 * @param[in] recipient Request recipient (device/interface/endpoint). 573 * @param[in] descriptor_type Descriptor type (device/configuration/HID/...). 574 * @param[in] descriptor_index Descriptor index. 575 * @param[in] language Language index (in native endianness). 576 * @param[in] buffer Buffer with the new descriptor (in USB endianness). 577 * @param[in] size Size of the @p buffer in bytes (in native endianness). 578 * @return Error code. 579 */ 580 int usb_request_set_descriptor(usb_endpoint_pipe_t *pipe, 581 usb_request_type_t request_type, usb_request_recipient_t recipient, 582 uint8_t descriptor_type, uint8_t descriptor_index, 583 uint16_t language, 584 void *buffer, size_t size) 585 { 586 if (buffer == NULL) { 587 return EBADMEM; 588 } 589 if (size == 0) { 590 return EINVAL; 591 } 592 593 /* FIXME: proper endianness. */ 594 uint16_t wValue = descriptor_index | (descriptor_type << 8); 595 596 return usb_control_request_set(pipe, 597 request_type, recipient, 598 USB_DEVREQ_SET_DESCRIPTOR, 599 wValue, language, 600 buffer, size); 601 } 602 603 /** Get current configuration value of USB device. 604 * 605 * @param[in] pipe Control endpoint pipe (session must be already started). 606 * @param[out] configuration_value Current configuration value. 607 * @return Error code. 608 */ 609 int usb_request_get_configuration(usb_endpoint_pipe_t *pipe, 610 uint8_t *configuration_value) 611 { 612 uint8_t value; 613 size_t actual_size; 614 615 int rc = usb_control_request_get(pipe, 616 USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE, 617 USB_DEVREQ_GET_CONFIGURATION, 618 0, 0, 619 &value, 1, &actual_size); 620 621 if (rc != EOK) { 622 return rc; 623 } 624 if (actual_size != 1) { 625 return ELIMIT; 626 } 627 628 if (configuration_value != NULL) { 629 *configuration_value = value; 630 } 631 632 return EOK; 633 } 634 475 635 /** Set configuration of USB device. 476 636 * … … 488 648 USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE, 489 649 USB_DEVREQ_SET_CONFIGURATION, config_value, 0, 650 NULL, 0); 651 } 652 653 /** Get selected alternate setting for USB interface. 654 * 655 * @param[in] pipe Control endpoint pipe (session must be already started). 656 * @param[in] interface_index Interface index. 657 * @param[out] alternate_setting Alternate setting for the interface. 658 * @return Error code. 659 */ 660 int usb_request_get_interface(usb_endpoint_pipe_t *pipe, 661 uint8_t interface_index, uint8_t *alternate_setting) 662 { 663 uint8_t value; 664 size_t actual_size; 665 666 int rc = usb_control_request_get(pipe, 667 USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_INTERFACE, 668 USB_DEVREQ_GET_INTERFACE, 669 0, uint16_host2usb((uint16_t) interface_index), 670 &value, 1, &actual_size); 671 672 if (rc != EOK) { 673 return rc; 674 } 675 if (actual_size != 1) { 676 return ELIMIT; 677 } 678 679 if (alternate_setting != NULL) { 680 *alternate_setting = value; 681 } 682 683 return EOK; 684 } 685 686 /** Select alternate setting for USB interface. 687 * 688 * @param[in] pipe Control endpoint pipe (session must be already started). 689 * @param[in] interface_index Interface index. 690 * @param[in] alternate_setting Alternate setting to select. 691 * @return Error code. 692 */ 693 int usb_request_set_interface(usb_endpoint_pipe_t *pipe, 694 uint8_t interface_index, uint8_t alternate_setting) 695 { 696 return usb_control_request_set(pipe, 697 USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_INTERFACE, 698 USB_DEVREQ_SET_INTERFACE, 699 uint16_host2usb((uint16_t) alternate_setting), 700 uint16_host2usb((uint16_t) interface_index), 490 701 NULL, 0); 491 702 }
Note:
See TracChangeset
for help on using the changeset viewer.