Changeset cdc1aa1 in mainline
- Timestamp:
- 2010-12-10T09:50:58Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7964475, bf2063e9
- Parents:
- 040068c (diff), 99ea659c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/usbinfo/dump.c
r040068c rcdc1aa1 47 47 48 48 #define INDENT " " 49 #define BYTES_PER_LINE 12 49 50 50 51 #define BCD_INT(a) (((unsigned int)(a)) / 256) … … 53 54 #define BCD_FMT "%x.%x" 54 55 #define BCD_ARGS(a) BCD_INT((a)), BCD_FRAC((a)) 56 57 void dump_buffer(const char *msg, const uint8_t *buffer, size_t length) 58 { 59 printf("%s\n", msg); 60 61 size_t i; 62 for (i = 0; i < length; i++) { 63 printf(" 0x%02X", buffer[i]); 64 if (((i > 0) && (((i+1) % BYTES_PER_LINE) == 0)) 65 || (i + 1 == length)) { 66 printf("\n"); 67 } 68 } 69 } 55 70 56 71 void dump_standard_device_descriptor(usb_standard_device_descriptor_t *d) … … 75 90 } 76 91 92 void dump_standard_configuration_descriptor( 93 int index, usb_standard_configuration_descriptor_t *d) 94 { 95 bool self_powered = d->attributes & 64; 96 bool remote_wakeup = d->attributes & 32; 97 98 printf("Standard configuration descriptor #%d\n", index); 99 printf(INDENT "bLength = %d\n", d->length); 100 printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type); 101 printf(INDENT "wTotalLength = %d\n", d->total_length); 102 printf(INDENT "bNumInterfaces = %d\n", d->interface_count); 103 printf(INDENT "bConfigurationValue = %d\n", d->configuration_number); 104 printf(INDENT "iConfiguration = %d\n", d->str_configuration); 105 printf(INDENT "bmAttributes = %d [%s%s%s]\n", d->attributes, 106 self_powered ? "self-powered" : "", 107 (self_powered & remote_wakeup) ? ", " : "", 108 remote_wakeup ? "remote-wakeup" : ""); 109 printf(INDENT "MaxPower = %d (%dmA)\n", d->max_power, 110 2 * d->max_power); 111 // printf(INDENT " = %d\n", d->); 112 } 113 114 77 115 /** @} 78 116 */ -
uspace/app/usbinfo/main.c
r040068c rcdc1aa1 44 44 #include "usbinfo.h" 45 45 46 #define DEFAULT_HOST_CONTROLLER_PATH "/virt/usbhc" 47 46 48 static void print_usage(char *app_name) 47 49 { 48 50 printf(NAME ": query USB devices for descriptors\n\n"); 49 51 printf("Usage: %s /path/to/hc usb-address\n where\n", app_name); 50 printf(" /path/to/hc Devman path to USB host controller\n"); 52 printf(" /path/to/hc Devman path to USB host controller " \ 53 "(use `-' for\n"); 54 printf(" default HC at `%s').\n", 55 DEFAULT_HOST_CONTROLLER_PATH); 51 56 printf(" usb-address USB address of device to be queried\n"); 52 57 printf("\n"); … … 68 73 } 69 74 70 int main(int argc, char * 75 int main(int argc, char *argv[]) 71 76 { 72 77 if (argc != 3) { … … 81 86 * Connect to given host controller driver. 82 87 */ 88 if (str_cmp(hc_path, "-") == 0) { 89 hc_path = (char *) DEFAULT_HOST_CONTROLLER_PATH; 90 } 83 91 int hc_phone = connect_to_hc(hc_path); 84 92 if (hc_phone < 0) { … … 107 115 */ 108 116 usb_standard_device_descriptor_t device_descriptor; 109 usb_dprintf( "usbinfo", 1,117 usb_dprintf(NAME, 1, 110 118 "usb_drv_req_get_device_descriptor(%d, %d, %p)\n", 111 119 hc_phone, (int) address, &device_descriptor); … … 121 129 dump_standard_device_descriptor(&device_descriptor); 122 130 131 /* 132 * Get first configuration descriptor and dump it. 133 */ 134 usb_standard_configuration_descriptor_t config_descriptor; 135 int config_index = 0; 136 usb_dprintf(NAME, 1, 137 "usb_drv_req_get_bare_configuration_descriptor(%d, %d, %d, %p)\n", 138 hc_phone, (int) address, config_index, &config_descriptor); 139 140 rc = usb_drv_req_get_bare_configuration_descriptor(hc_phone, address, 141 config_index, &config_descriptor ); 142 if (rc != EOK) { 143 fprintf(stderr, 144 NAME ": failed to fetch standard configuration descriptor: %s.\n", 145 str_error(rc)); 146 return rc; 147 } 148 dump_standard_configuration_descriptor(config_index, 149 &config_descriptor); 150 151 void *full_config_descriptor = malloc(config_descriptor.total_length); 152 usb_dprintf(NAME, 1, 153 "usb_drv_req_get_full_configuration_descriptor(%d, %d, %d, %p, %zu)\n", 154 hc_phone, (int) address, config_index, 155 full_config_descriptor, config_descriptor.total_length); 156 157 rc = usb_drv_req_get_full_configuration_descriptor(hc_phone, address, 158 config_index, 159 full_config_descriptor, config_descriptor.total_length, NULL); 160 if (rc != EOK) { 161 fprintf(stderr, 162 NAME ": failed to fetch full configuration descriptor: %s.\n", 163 str_error(rc)); 164 return rc; 165 } 166 dump_buffer("Full configuration descriptor:", 167 full_config_descriptor, config_descriptor.total_length); 123 168 124 169 return EOK; -
uspace/app/usbinfo/usbinfo.h
r040068c rcdc1aa1 43 43 #define NAME "usbinfo" 44 44 45 void dump_buffer(const char *, const uint8_t *, size_t); 45 46 void dump_standard_device_descriptor(usb_standard_device_descriptor_t *); 47 void dump_standard_configuration_descriptor(int, 48 usb_standard_configuration_descriptor_t *); 46 49 47 50 #endif -
uspace/lib/usb/include/usb/devreq.h
r040068c rcdc1aa1 38 38 #include <ipc/ipc.h> 39 39 #include <async.h> 40 #include <usb/usb.h> 41 #include <usb/descriptor.h> 40 42 41 43 /** Standard device request. */ … … 83 85 } __attribute__ ((packed)) usb_device_request_setup_packet_t; 84 86 87 int usb_drv_req_set_address(int, usb_address_t, usb_address_t); 88 int usb_drv_req_get_device_descriptor(int, usb_address_t, 89 usb_standard_device_descriptor_t *); 90 int usb_drv_req_get_bare_configuration_descriptor(int, usb_address_t, int, 91 usb_standard_configuration_descriptor_t *); 92 int usb_drv_req_get_full_configuration_descriptor(int, usb_address_t, int, 93 void *, size_t, size_t *); 94 95 85 96 #endif 86 97 /** -
uspace/lib/usb/include/usb/usbdrv.h
r040068c rcdc1aa1 72 72 int usb_drv_psync_control_write_status(int, usb_target_t); 73 73 74 int usb_drv_psync_control_write(int, usb_target_t, 75 void *, size_t, void *, size_t); 76 74 77 75 78 int usb_drv_async_control_read_setup(int, usb_target_t, … … 84 87 int usb_drv_psync_control_read_status(int, usb_target_t); 85 88 89 int usb_drv_psync_control_read(int, usb_target_t, 90 void *, size_t, void *, size_t, size_t *); 91 92 86 93 87 94 int usb_drv_async_wait_for(usb_handle_t); 88 95 89 90 int usb_drv_req_set_address(int, usb_address_t, usb_address_t);91 int usb_drv_req_get_device_descriptor(int, usb_address_t,92 usb_standard_device_descriptor_t *);93 96 94 97 #endif -
uspace/lib/usb/src/drvpsync.c
r040068c rcdc1aa1 100 100 101 101 102 /** Perform complete control write transaction over USB. 103 * 104 * The DATA stage is performed only when @p data is not NULL and 105 * @p data_size is greater than zero. 106 * 107 * @param phone Open phone to host controller. 108 * @param target Target device and endpoint. 109 * @param setup_packet Setup packet data. 110 * @param setup_packet_size Size of the setup packet. 111 * @param data Data to be sent. 112 * @param data_size Size of the @p data buffer. 113 * @return Error code. 114 */ 115 int usb_drv_psync_control_write(int phone, usb_target_t target, 116 void *setup_packet, size_t setup_packet_size, 117 void *data, size_t data_size) 118 { 119 int rc; 120 121 rc = usb_drv_psync_control_write_setup(phone, target, 122 setup_packet, setup_packet_size); 123 if (rc != EOK) { 124 return rc; 125 } 126 127 if ((data != NULL) && (data_size > 0)) { 128 rc = usb_drv_psync_control_write_data(phone, target, 129 data, data_size); 130 if (rc != EOK) { 131 return rc; 132 } 133 } 134 135 rc = usb_drv_psync_control_write_status(phone, target); 136 137 return rc; 138 } 139 102 140 103 141 int usb_drv_psync_control_read_setup(int phone, usb_target_t target, … … 137 175 } 138 176 177 178 /** Perform complete control read transaction over USB. 179 * 180 * @param phone Open phone to host controller. 181 * @param target Target device and endpoint. 182 * @param setup_packet Setup packet data. 183 * @param setup_packet_size Size of the setup packet. 184 * @param data Storage for read data. 185 * @param data_size Size of the @p data buffer. 186 * @param actual_data_size Storage for number of actually transferred data from 187 * device. 188 * @return Error code. 189 */ 190 int usb_drv_psync_control_read(int phone, usb_target_t target, 191 void *setup_packet, size_t setup_packet_size, 192 void *data, size_t data_size, size_t *actual_data_size) 193 { 194 int rc; 195 196 rc = usb_drv_psync_control_read_setup(phone, target, 197 setup_packet, setup_packet_size); 198 if (rc != EOK) { 199 return rc; 200 } 201 202 rc = usb_drv_psync_control_read_data(phone, target, 203 data, data_size, actual_data_size); 204 if (rc != EOK) { 205 return rc; 206 } 207 208 rc = usb_drv_psync_control_read_status(phone, target); 209 210 return rc; 211 } 212 213 214 215 139 216 /** 140 217 * @} -
uspace/lib/usb/src/usbdrvreq.c
r040068c rcdc1aa1 67 67 setup_packet.value = new_address; 68 68 69 usb_handle_t handle; 70 int rc; 71 72 /* Start the control write transfer. */ 73 rc = usb_drv_async_control_write_setup(phone, target, 74 &setup_packet, sizeof(setup_packet), &handle); 75 if (rc != EOK) { 76 return rc; 77 } 78 rc = usb_drv_async_wait_for(handle); 79 if (rc != EOK) { 80 return rc; 81 } 82 83 /* Finish the control write transfer. */ 84 rc = usb_drv_async_control_write_status(phone, target, &handle); 85 if (rc != EOK) { 86 return rc; 87 } 88 rc = usb_drv_async_wait_for(handle); 89 if (rc != EOK) { 90 return rc; 91 } 92 93 return EOK; 69 int rc = usb_drv_psync_control_write(phone, target, 70 &setup_packet, sizeof(setup_packet), NULL, 0); 71 72 return rc; 94 73 } 95 74 … … 125 104 setup_packet.value_low = 0; 126 105 127 usb_handle_t handle; 128 int rc; 129 130 /* Start the control read transfer. */ 131 rc = usb_drv_async_control_read_setup(phone, target, 132 &setup_packet, sizeof(usb_device_request_setup_packet_t), &handle); 106 /* Prepare local descriptor. */ 107 size_t actually_transferred = 0; 108 usb_standard_device_descriptor_t descriptor_tmp; 109 110 /* Perform the control read transaction. */ 111 int rc = usb_drv_psync_control_read(phone, target, 112 &setup_packet, sizeof(setup_packet), 113 &descriptor_tmp, sizeof(descriptor_tmp), &actually_transferred); 114 133 115 if (rc != EOK) { 134 116 return rc; 135 117 } 136 rc = usb_drv_async_wait_for(handle); 118 119 /* Verify that all data has been transferred. */ 120 if (actually_transferred < sizeof(descriptor_tmp)) { 121 return ELIMIT; 122 } 123 124 /* Everything is okay, copy the descriptor. */ 125 memcpy(descriptor, &descriptor_tmp, 126 sizeof(descriptor_tmp)); 127 128 return EOK; 129 } 130 131 132 /** Retrieve configuration descriptor of connected USB device. 133 * 134 * The function does not retrieve additional data binded with configuration 135 * descriptor (such as its interface and endpoint descriptors) - use 136 * usb_drv_req_get_full_configuration_descriptor() instead. 137 * 138 * @param[in] phone Open phone to HC driver. 139 * @param[in] address Device USB address. 140 * @param[in] index Configuration descriptor index. 141 * @param[out] descriptor Storage for the configuration descriptor. 142 * @return Error code. 143 * @retval EBADMEM @p descriptor is NULL. 144 */ 145 int usb_drv_req_get_bare_configuration_descriptor(int phone, 146 usb_address_t address, int index, 147 usb_standard_configuration_descriptor_t *descriptor) 148 { 149 if (descriptor == NULL) { 150 return EBADMEM; 151 } 152 153 /* Prepare the target. */ 154 usb_target_t target = { 155 .address = address, 156 .endpoint = 0 157 }; 158 159 /* Prepare the setup packet. */ 160 usb_device_request_setup_packet_t setup_packet = { 161 .request_type = 128, 162 .request = USB_DEVREQ_GET_DESCRIPTOR, 163 .index = 0, 164 .length = sizeof(usb_standard_device_descriptor_t) 165 }; 166 setup_packet.value_high = USB_DESCTYPE_CONFIGURATION; 167 setup_packet.value_low = index; 168 169 /* Prepare local descriptor. */ 170 size_t actually_transferred = 0; 171 usb_standard_configuration_descriptor_t descriptor_tmp; 172 173 /* Perform the control read transaction. */ 174 int rc = usb_drv_psync_control_read(phone, target, 175 &setup_packet, sizeof(setup_packet), 176 &descriptor_tmp, sizeof(descriptor_tmp), &actually_transferred); 177 137 178 if (rc != EOK) { 138 179 return rc; 139 180 } 140 181 141 /* Retrieve the descriptor. */ 142 size_t actually_transferred = 0; 143 usb_standard_device_descriptor_t descriptor_tmp; 144 rc = usb_drv_async_control_read_data(phone, target, 145 &descriptor_tmp, sizeof(usb_standard_device_descriptor_t), 146 &actually_transferred, &handle); 147 if (rc != EOK) { 148 return rc; 149 } 150 rc = usb_drv_async_wait_for(handle); 151 if (rc != EOK) { 152 return rc; 153 } 154 155 /* Finish the control read transfer. */ 156 rc = usb_drv_async_control_read_status(phone, target, &handle); 157 if (rc != EOK) { 158 return rc; 159 } 160 rc = usb_drv_async_wait_for(handle); 161 if (rc != EOK) { 162 return rc; 163 } 164 165 if (actually_transferred < sizeof(usb_standard_device_descriptor_t)) { 182 /* Verify that all data has been transferred. */ 183 if (actually_transferred < sizeof(descriptor_tmp)) { 166 184 return ELIMIT; 167 185 } 168 186 169 /* 170 * Everything is okay, copy the descriptor. 171 */ 187 /* Everything is okay, copy the descriptor. */ 172 188 memcpy(descriptor, &descriptor_tmp, 173 sizeof( usb_standard_device_descriptor_t));189 sizeof(descriptor_tmp)); 174 190 175 191 return EOK; 176 192 } 177 193 194 /** Retrieve full configuration descriptor of connected USB device. 195 * 196 * @warning The @p buffer might be touched (i.e. its contents changed) 197 * even when error occurres. 198 * 199 * @param[in] phone Open phone to HC driver. 200 * @param[in] address Device USB address. 201 * @param[in] index Configuration descriptor index. 202 * @param[out] buffer Buffer for the whole configuration descriptor. 203 * @param[in] buffer_size Size of the prepared @p buffer. 204 * @param[out] actual_buffer_size Bytes actually transfered. 205 * @return Error code. 206 * @retval EBADMEM @p descriptor is NULL. 207 */ 208 int usb_drv_req_get_full_configuration_descriptor(int phone, 209 usb_address_t address, int index, 210 void *buffer, size_t buffer_size, size_t *actual_buffer_size) 211 { 212 if (buffer == NULL) { 213 return EBADMEM; 214 } 215 216 /* Prepare the target. */ 217 usb_target_t target = { 218 .address = address, 219 .endpoint = 0 220 }; 221 222 /* Prepare the setup packet. */ 223 usb_device_request_setup_packet_t setup_packet = { 224 .request_type = 128, 225 .request = USB_DEVREQ_GET_DESCRIPTOR, 226 .index = 0, 227 .length = sizeof(usb_standard_device_descriptor_t) 228 }; 229 setup_packet.value_high = USB_DESCTYPE_CONFIGURATION; 230 setup_packet.value_low = index; 231 232 /* Perform the control read transaction. */ 233 int rc = usb_drv_psync_control_read(phone, target, 234 &setup_packet, sizeof(setup_packet), 235 buffer, buffer_size, actual_buffer_size); 236 237 return rc; 238 } 178 239 179 240
Note:
See TracChangeset
for help on using the changeset viewer.