Changes in uspace/drv/vhc/connhost.c [284c629:76daaf9f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/vhc/connhost.c
r284c629 r76daaf9f 27 27 */ 28 28 29 /** @addtogroup drvusbvhc29 /** @addtogroup usb 30 30 * @{ 31 31 */ … … 41 41 #include "conn.h" 42 42 #include "hc.h" 43 44 43 45 44 typedef struct { … … 48 47 usbhc_iface_transfer_in_callback_t in_callback; 49 48 device_t *dev; 50 size_t reported_size;51 49 void *arg; 52 50 } transfer_info_t; 53 51 54 typedef struct {55 usb_direction_t direction;56 usb_target_t target;57 usbhc_iface_transfer_out_callback_t out_callback;58 usbhc_iface_transfer_in_callback_t in_callback;59 device_t *dev;60 void *arg;61 void *data_buffer;62 size_t data_buffer_size;63 } control_transfer_info_t;64 65 52 static void universal_callback(void *buffer, size_t size, 66 53 usb_transaction_outcome_t outcome, void *arg) 67 54 { 68 55 transfer_info_t *transfer = (transfer_info_t *) arg; 69 70 if (transfer->reported_size != (size_t) -1) {71 size = transfer->reported_size;72 }73 56 74 57 switch (transfer->direction) { … … 101 84 transfer->arg = arg; 102 85 transfer->dev = dev; 103 transfer->reported_size = (size_t) -1;104 105 return transfer;106 }107 108 static void control_abort_prematurely(control_transfer_info_t *transfer,109 size_t size, usb_transaction_outcome_t outcome)110 {111 switch (transfer->direction) {112 case USB_DIRECTION_IN:113 transfer->in_callback(transfer->dev,114 outcome, size,115 transfer->arg);116 break;117 case USB_DIRECTION_OUT:118 transfer->out_callback(transfer->dev,119 outcome,120 transfer->arg);121 break;122 default:123 assert(false && "unreachable");124 break;125 }126 }127 128 static void control_callback_two(void *buffer, size_t size,129 usb_transaction_outcome_t outcome, void *arg)130 {131 control_transfer_info_t *ctrl_transfer = (control_transfer_info_t *) arg;132 133 if (outcome != USB_OUTCOME_OK) {134 control_abort_prematurely(ctrl_transfer, outcome, size);135 free(ctrl_transfer);136 return;137 }138 139 transfer_info_t *transfer = create_transfer_info(ctrl_transfer->dev,140 ctrl_transfer->direction, ctrl_transfer->arg);141 transfer->out_callback = ctrl_transfer->out_callback;142 transfer->in_callback = ctrl_transfer->in_callback;143 transfer->reported_size = size;144 145 switch (ctrl_transfer->direction) {146 case USB_DIRECTION_IN:147 hc_add_transaction_to_device(false, ctrl_transfer->target,148 USB_TRANSFER_CONTROL,149 NULL, 0,150 universal_callback, transfer);151 break;152 case USB_DIRECTION_OUT:153 hc_add_transaction_from_device(ctrl_transfer->target,154 USB_TRANSFER_CONTROL,155 NULL, 0,156 universal_callback, transfer);157 break;158 default:159 assert(false && "unreachable");160 break;161 }162 163 free(ctrl_transfer);164 }165 166 static void control_callback_one(void *buffer, size_t size,167 usb_transaction_outcome_t outcome, void *arg)168 {169 control_transfer_info_t *transfer = (control_transfer_info_t *) arg;170 171 if (outcome != USB_OUTCOME_OK) {172 control_abort_prematurely(transfer, outcome, size);173 free(transfer);174 return;175 }176 177 switch (transfer->direction) {178 case USB_DIRECTION_IN:179 hc_add_transaction_from_device(transfer->target,180 USB_TRANSFER_CONTROL,181 transfer->data_buffer, transfer->data_buffer_size,182 control_callback_two, transfer);183 break;184 case USB_DIRECTION_OUT:185 hc_add_transaction_to_device(false, transfer->target,186 USB_TRANSFER_CONTROL,187 transfer->data_buffer, transfer->data_buffer_size,188 control_callback_two, transfer);189 break;190 default:191 assert(false && "unreachable");192 break;193 }194 }195 196 static control_transfer_info_t *create_control_transfer_info(device_t *dev,197 usb_direction_t direction, usb_target_t target,198 void *data_buffer, size_t data_buffer_size,199 void *arg)200 {201 control_transfer_info_t *transfer202 = malloc(sizeof(control_transfer_info_t));203 204 transfer->direction = direction;205 transfer->target = target;206 transfer->in_callback = NULL;207 transfer->out_callback = NULL;208 transfer->arg = arg;209 transfer->dev = dev;210 transfer->data_buffer = data_buffer;211 transfer->data_buffer_size = data_buffer_size;212 86 213 87 return transfer; … … 319 193 } 320 194 321 static int control_write(device_t *dev, usb_target_t target,322 void *setup_packet, size_t setup_packet_size,323 void *data, size_t data_size,324 usbhc_iface_transfer_out_callback_t callback, void *arg)325 {326 control_transfer_info_t *transfer327 = create_control_transfer_info(dev, USB_DIRECTION_OUT, target,328 data, data_size, arg);329 transfer->out_callback = callback;330 331 hc_add_transaction_to_device(true, target, USB_TRANSFER_CONTROL,332 setup_packet, setup_packet_size,333 control_callback_one, transfer);334 335 return EOK;336 }337 338 195 static int control_read_setup(device_t *dev, usb_target_t target, 339 196 void *data, size_t size, … … 360 217 NULL, 0, 361 218 callback, arg); 362 }363 364 static int control_read(device_t *dev, usb_target_t target,365 void *setup_packet, size_t setup_packet_size,366 void *data, size_t data_size,367 usbhc_iface_transfer_in_callback_t callback, void *arg)368 {369 control_transfer_info_t *transfer370 = create_control_transfer_info(dev, USB_DIRECTION_IN, target,371 data, data_size, arg);372 transfer->in_callback = callback;373 374 hc_add_transaction_to_device(true, target, USB_TRANSFER_CONTROL,375 setup_packet, setup_packet_size,376 control_callback_one, transfer);377 378 return EOK;379 219 } 380 220 … … 450 290 .control_write_status = control_write_status, 451 291 452 .control_write = control_write,453 454 292 .control_read_setup = control_read_setup, 455 293 .control_read_data = control_read_data, 456 .control_read_status = control_read_status, 457 458 .control_read = control_read 294 .control_read_status = control_read_status 459 295 }; 460 296
Note:
See TracChangeset
for help on using the changeset viewer.