USBPacket *usb_ep_find_packet_by_id(USBDevice *dev, int pid, int ep, uint64_t id) { struct USBEndpoint *uep = usb_ep_get(dev, pid, ep); USBPacket *p; while ((p = QTAILQ_FIRST(&uep->queue)) != NULL) { if (p->id == id) { return p; } } return NULL; }
/* Hand over a packet to a device for processing. Return value USB_RET_ASYNC indicates the processing isn't finished yet, the driver will call usb_packet_complete() when done processing it. */ int usb_handle_packet(USBDevice *dev, USBPacket *p) { int ret; assert(p->owner == NULL); ret = dev->info->handle_packet(dev, p); if (ret == USB_RET_ASYNC) { if (p->owner == NULL) { p->owner = usb_ep_get(dev, p->pid, p->devep); } else { /* We'll end up here when usb_handle_packet is called * recursively due to a hub being in the chain. Nothing * to do. Leave p->owner pointing to the device, not the * hub. */; } } return ret; }
void usb_ep_set_max_packet_size(USBDevice *dev, int pid, int ep, uint16_t raw) { struct USBEndpoint *uep = usb_ep_get(dev, pid, ep); int size, microframes; size = raw & 0x7ff; switch ((raw >> 11) & 3) { case 1: microframes = 2; break; case 2: microframes = 3; break; default: microframes = 1; break; } uep->max_packet_size = size * microframes; }
void usb_ep_set_pipeline(USBDevice *dev, int pid, int ep, bool enabled) { struct USBEndpoint *uep = usb_ep_get(dev, pid, ep); uep->pipeline = enabled; }
int usb_ep_get_max_packet_size(USBDevice *dev, int pid, int ep) { struct USBEndpoint *uep = usb_ep_get(dev, pid, ep); return uep->max_packet_size; }
void usb_ep_set_ifnum(USBDevice *dev, int pid, int ep, uint8_t ifnum) { struct USBEndpoint *uep = usb_ep_get(dev, pid, ep); uep->ifnum = ifnum; }
uint8_t usb_ep_get_ifnum(USBDevice *dev, int pid, int ep) { struct USBEndpoint *uep = usb_ep_get(dev, pid, ep); return uep->ifnum; }
void usb_ep_set_type(USBDevice *dev, int pid, int ep, uint8_t type) { struct USBEndpoint *uep = usb_ep_get(dev, pid, ep); uep->type = type; }
uint8_t usb_ep_get_type(USBDevice *dev, int pid, int ep) { struct USBEndpoint *uep = usb_ep_get(dev, pid, ep); return uep->type; }