Changes in uspace/lib/usb/src/usbdrvreq.c [f995350:eac610e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/src/usbdrvreq.c
rf995350 reac610e 34 34 */ 35 35 #include <usb/usbdrv.h> 36 #include <usb/devreq.h>37 36 #include <errno.h> 38 37 … … 95 94 } 96 95 96 /** Retrieve device descriptor of connected USB device. 97 * 98 * @param[in] phone Open phone to HC driver. 99 * @param[in] address Device USB address. 100 * @param[out] descriptor Storage for the device descriptor. 101 * @return Error code. 102 * @retval EBADMEM @p descriptor is NULL. 103 */ 104 int usb_drv_req_get_device_descriptor(int phone, usb_address_t address, 105 usb_standard_device_descriptor_t *descriptor) 106 { 107 if (descriptor == NULL) { 108 return EBADMEM; 109 } 110 111 /* Prepare the target. */ 112 usb_target_t target = { 113 .address = address, 114 .endpoint = 0 115 }; 116 117 /* Prepare the setup packet. */ 118 usb_device_request_setup_packet_t setup_packet = { 119 .request_type = 128, 120 .request = USB_DEVREQ_GET_DESCRIPTOR, 121 .index = 0, 122 .length = sizeof(usb_standard_device_descriptor_t) 123 }; 124 setup_packet.value_high = USB_DESCTYPE_DEVICE; 125 setup_packet.value_low = 0; 126 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); 133 if (rc != EOK) { 134 return rc; 135 } 136 rc = usb_drv_async_wait_for(handle); 137 if (rc != EOK) { 138 return rc; 139 } 140 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)) { 166 return ELIMIT; 167 } 168 169 /* 170 * Everything is okay, copy the descriptor. 171 */ 172 memcpy(descriptor, &descriptor_tmp, 173 sizeof(usb_standard_device_descriptor_t)); 174 175 return EOK; 176 } 177 178 179 97 180 /** 98 181 * @}
Note:
See TracChangeset
for help on using the changeset viewer.