/* see flow chart in the usbmassbulk_10.pdf doc (page 15) Returned values: <0 Low-level USBD error. 0 = Command completed successfully. 1 = Command failed. 2 = Phase error. */ static int usb_bulk_manage_status(mass_dev* dev, unsigned int tag) { int ret; csw_packet csw; //XPRINTF("USBHDFSD: usb_bulk_manage_status 1 ...\n"); ret = usb_bulk_status(dev, &csw, tag); /* Attempt to read CSW from bulk in endpoint */ if (ret != USB_RC_OK) { /* STALL bulk in -OR- Bulk error */ usb_bulk_clear_halt(dev, USB_BLK_EP_IN); /* clear the stall condition for bulk in */ XPRINTF("USBHDFSD: usb_bulk_manage_status error %d ...\n", ret); ret = usb_bulk_status(dev, &csw, tag); /* Attempt to read CSW from bulk in endpoint */ } /* CSW not valid or stalled or phase error */ if (ret != USB_RC_OK || csw.signature != CSW_TAG || csw.tag != tag || csw.status == 2) { printf("USBHDFSD: usb_bulk_manage_status call reset recovery ...\n"); usb_bulk_reset(dev, 3); /* Perform reset recovery */ } return((ret == USB_RC_OK && csw.signature == CSW_TAG && csw.tag == tag) ? csw.status : -1); }
/* see flow chart in the usbmassbulk_10.pdf doc (page 15) */ int usb_bulk_manage_status(mass_dev* dev, int tag) { int ret; csw_packet csw; //XPRINTF("USBHDFSD: usb_bulk_manage_status 1 ...\n"); ret = usb_bulk_status(dev, &csw, tag); /* Attempt to read CSW from bulk in endpoint */ if (ret < 0) { /* STALL bulk in -OR- Bulk error */ usb_bulk_clear_halt(dev, 0); /* clear the stall condition for bulk in */ XPRINTF("USBHDFSD: usb_bulk_manage_status stall ...\n"); ret = usb_bulk_status(dev, &csw, tag); /* Attempt to read CSW from bulk in endpoint */ } /* CSW not valid or stalled or phase error */ if (csw.signature != CSW_TAG || csw.tag != tag || ret == 2) { printf("USBHDFSD: usb_bulk_manage_status call reset recovery ...\n"); usb_bulk_reset(dev, 3); /* Perform reset recovery */ } return ret; }