void usb_rx_request_write_call(struct usb_manager_binding *binding, uint8_t *request, size_t req_length, uint8_t *data, size_t data_length) { USB_DEBUG_TR_ENTER; USB_DEBUG_IDC("received usb_rx_request_call() of %i bytes\n", data_length); struct usb_device_request *req = (struct usb_device_request *) request; /* check if we have received the correct amount of data */ if ((req_length != sizeof(struct usb_device_request)) || (req->wLength != data_length)) { USB_DEBUG_IDC("ERROR in usb_rx_request_call(): received too less data" " to full fill the request:\n " "request length: expected %i bytes, was %i\n" "data length: expected %i, was %i\n", sizeof(struct usb_device_request), req_length, req->wLength, data_length); usb_request_send_error(USB_ERR_INVAL, binding, usb_tx_request_write_response); } /* execute request and prepare reply */ struct usb_request_state *st = malloc(sizeof(struct usb_request_state)); if (st == NULL) { USB_DEBUG_IDC("WARNING: usb_rx_request_write_call(): out of memory\b"); usb_request_send_error(USB_ERR_NOMEM, binding, usb_tx_request_write_response); return; } /* fill in the struct */ st->bind = binding; st->req = req; /* write requests have no data to return */ st->data_length = data_length; st->data = data; st->callback = usb_tx_request_write_response; struct usb_device *device = (struct usb_device *) binding->st; usb_handle_request(device, 0, req, st, st->data, &st->data_length); }
static void usb_tx_request_generic_cb(void *a) { USB_DEBUG_IDC("rusb_tx_request_generic_cb(): successful transmitted\n"); struct usb_request_state *st = (struct usb_request_state *) a; free_request_state(st); }
void usb_rx_transfer_state_call(struct usb_manager_binding *bind, uint32_t tid) { struct usb_tstate_state *st = malloc(sizeof(struct usb_tstate_state)); if (st == NULL) { USB_DEBUG_IDC("WARNING: Cannot reply, out of memory!\n"); return; } st->bind = bind; usb_tx_transfer_state_response(st); }
void usb_rx_request_read_call(struct usb_manager_binding *binding, uint8_t *request, size_t req_length) { USB_DEBUG_TR_ENTER; USB_DEBUG_IDC("received usb_rx_request_read_call()\n"); // check if we have received the correct amount of data if (req_length != sizeof(struct usb_device_request)) { USB_DEBUG_IDC("received too less data to fullfill the request:\n " "request length: expected %i bytes, was %i\n", sizeof(struct usb_device_request), req_length); usb_request_send_error(USB_ERR_INVAL, binding, usb_tx_request_read_response); } /* * execute request and prepare reply */ struct usb_request_state *st = malloc(sizeof(struct usb_request_state)); struct usb_device *device = (struct usb_device *) binding->st; struct usb_device_request *req = (struct usb_device_request *) request; st->req = req; st->bind = binding; st->data_length = 0; if (req->wLength > 0) { st->data = malloc(req->wLength); } else { /* XXX: Just allocating some memory, note this may not be enough */ st->data = malloc(1024); req->wLength = 1024; // setting the maximum data length } st->callback = usb_tx_request_read_response; usb_handle_request(device, 0, req, st, st->data, &st->data_length); }
static void usb_tx_transfer_stop_response(void *a) { errval_t err; struct usb_tstop_state *st = (struct usb_tstop_state *) a; USB_DEBUG_IDC("usb_tx_transfer_stop_response()\n"); struct event_closure txcont = MKCONT(usb_tx_transfer_generic_cb, st); err = usb_manager_transfer_stop_response__tx(st->bind, txcont, (uint32_t) st->error); USB_TX_TRANSER_ERR(usb_tx_transfer_stop_response); }
static void usb_tx_request_read_response(void *a) { errval_t err; struct usb_request_state *st = (struct usb_request_state *) a; USB_DEBUG_IDC("send usb_tx_request_read_response()\n"); struct event_closure txcont = MKCONT(usb_tx_request_generic_cb, st); err = usb_manager_request_read_response__tx(st->bind, txcont, st->data, st->data_length, (uint32_t) st->error); USB_TX_REQUEST_ERR(usb_tx_request_read_response); }
void usb_rx_transfer_start_call(struct usb_manager_binding *bind, uint32_t tid) { USB_DEBUG_IDC("usb_rx_transfer_start_call()\n"); struct usb_tstart_state *st = malloc(sizeof(struct usb_tstart_state)); if (st == NULL) { debug_printf("WARNING: Cannot reply, out of memory!\n"); } st->bind = bind; struct usb_device *dev = (struct usb_device *) (bind->st); assert(dev != NULL); struct usb_xfer *xfer = dev->xfers; while (xfer) { if (xfer->xfer_id == tid) { break; } xfer = xfer->device_xfers_next; } if (xfer == NULL) { USB_DEBUG("no xfer!\n"); st->error = USB_ERR_BAD_CONTEXT; usb_tx_transfer_start_response(st); } usb_transfer_start(xfer); st->error = xfer->error; usb_tx_transfer_start_response(st); }
void usb_rx_transfer_setup_call(struct usb_manager_binding *bind, uint8_t type, usb_manager_setup_param_t params) { struct usb_tsetup_state *st = malloc(sizeof(struct usb_tsetup_state)); if (st == NULL) { debug_printf("WARNING: Cannot reply, out of memory!\n"); return; } struct usb_xfer_config setup; st->bind = bind; struct usb_xfer *xfer; struct usb_device *dev = (struct usb_device *) bind->st; memcpy(&setup, ¶ms, sizeof(params)); if (dev == NULL) { st->tid = 0; st->error = USB_ERR_BAD_CONTEXT; usb_tx_transfer_setup_response(st); return; } setup.xfer_done_cb = &usb_transfer_complete_notify; switch ((usb_type_t) type) { case USB_TYPE_BULK: USB_DEBUG_IDC("received usb_rx_transfer_setup_call [bulk type]\n"); /* TODO: Handle transfer setup */ setup.usb_type = USB_TYPE_BULK; st->error = USB_ERR_OK; xfer->usb_manager_binding = st->bind; xfer->usb_driver_binding = dev->usb_driver_binding; st->tid = 123; break; case USB_TYPE_CTRL: USB_DEBUG_IDC("received usb_rx_transfer_setup_call [ctrl type]\n"); /* TODO: Handle transfer setup */ setup.usb_type = USB_TYPE_CTRL; st->error = USB_ERR_OK; xfer->usb_manager_binding = st->bind; xfer->usb_driver_binding = dev->usb_driver_binding; st->tid = 234; break; case USB_TYPE_ISOC: USB_DEBUG_IDC("received usb_rx_transfer_setup_call [isoc type]\n"); /* TODO: Handle transfer setup */ setup.usb_type = USB_TYPE_ISOC; st->error = USB_ERR_OK; xfer->usb_manager_binding = st->bind; xfer->usb_driver_binding = dev->usb_driver_binding; st->tid = 345; break; case USB_TYPE_INTR: USB_DEBUG_IDC("received usb_rx_transfer_setup_call [intr type]\n"); /* TODO: Handle transfer setup */ setup.usb_type = USB_TYPE_INTR; st->error = usb_transfer_setup(dev, params.iface, &xfer, &setup); xfer->usb_manager_binding = st->bind; xfer->usb_driver_binding = dev->usb_driver_binding; st->tid = xfer->xfer_id; break; default: USB_DEBUG("received usb_rx_transfer_setup_call [invalid type]\n"); st->error = USB_ERR_INVAL; break; } usb_tx_transfer_setup_response(st); }