Example #1
0
static int usb_bulk_command(mass_dev* dev, cbw_packet* packet ) {
	int ret;
	usb_callback_data cb_data;

	if(dev->status & USBMASS_DEV_STAT_ERR){
		printf("USBHDFSD: Rejecting I/O to offline device %d.\n", dev->devId);
		return -1;
	}

	cb_data.semh = dev->ioSema;

	ret =  UsbBulkTransfer(
		dev->bulkEpO,		//bulk output pipe
		packet,			//data ptr
		31,	//data length
		usb_callback,
		(void*)&cb_data
	);

	if (ret == USB_RC_OK) {
		WaitSema(cb_data.semh);
		ret = cb_data.returnCode;
	}
	if (ret != USB_RC_OK) {
		XPRINTF("USBHDFSD: Error - sending bulk command %d. Calling reset recovery.\n", ret);
		usb_bulk_reset(dev, 3);
	}

	return ret;
}
Example #2
0
static int usb_bulk_status(mass_dev* dev, csw_packet* csw, unsigned int tag) {
	int ret;
	usb_callback_data cb_data;

	cb_data.semh = dev->ioSema;

	csw->signature = CSW_TAG;
	csw->tag = tag;
	csw->dataResidue = 0;
	csw->status = 0;

	ret = UsbBulkTransfer(
		dev->bulkEpI,		//bulk input pipe
		csw,			//data ptr
		13,	//data length
		usb_callback,
		(void*)&cb_data
        );

	if (ret == USB_RC_OK) {
		WaitSema(cb_data.semh);
		ret = cb_data.returnCode;

#ifdef DEBUG
		if (cb_data.returnSize != 13)
			printf("USBHDFSD: bulk csw.status returnSize: %i != 13\n", cb_data.returnSize);
		if (csw->dataResidue != 0)
			printf("USBHDFSD: bulk csw.status residue: %i\n", csw->dataResidue);
		XPRINTF("USBHDFSD: bulk csw result: %d, csw.status: %i\n", ret, csw->status);
#endif
	}

	return ret;
}
void usb_bulk_command(mass_dev* dev, cbw_packet* packet ) {
	int ret;
	iop_sema_t s;
	usb_callback_data cb_data;

	s.initial = 0;
	s.max = 1;
	s.option = 0;
	s.attr = 0;
	cb_data.semh = CreateSema(&s);

	ret =  UsbBulkTransfer(
		dev->bulkEpO,		//bulk output pipe
		packet,			//data ptr
		31,			//data length
		usb_callback,
		(void*)&cb_data
	);
    
	if (ret != USB_RC_OK) {
		printf("USBHDFSD: Error - sending bulk command %d\n", ret);
	} else {
		WaitSema(cb_data.semh);
	}
	DeleteSema(cb_data.semh);
}
Example #4
0
static int usb_bulk_transfer(mass_dev* dev, int direction, void* buffer, unsigned int transferSize) {
	int ret;
	unsigned char* buf = (unsigned char*) buffer;
	int blockSize = transferSize;
	int offset = 0, pipe;
	usb_callback_data cb_data;

	cb_data.semh = dev->ioSema;

	pipe = (direction==USB_BLK_EP_IN) ? dev->bulkEpI : dev->bulkEpO;
	while (transferSize > 0) {
		if (transferSize < blockSize) {
			blockSize = transferSize;
		}

		ret = UsbBulkTransfer(
			pipe,			//bulk pipe epI(Read)  epO(Write)
			(buf + offset),		//data ptr
			blockSize,		//data length
			usb_callback,
			(void*)&cb_data
			);
		if (ret != USB_RC_OK) {
			cb_data.returnCode = ret;
			break;
		} else {
			WaitSema(cb_data.semh);
			//XPRINTF("USBHDFSD: retCode=%i retSize=%i \n", cb_data.returnCode, cb_data.returnSize);
			if (cb_data.returnCode != USB_RC_OK) {
				break;
			}
			offset += cb_data.returnSize;
			transferSize-= cb_data.returnSize;
		}
	}

	if(cb_data.returnCode != USB_RC_OK){
		XPRINTF("USBHDFSD: Error - bulk data transfer %d. Clearing HALT state.\n", cb_data.returnCode);
		usb_bulk_clear_halt(dev, direction);
	}

	return cb_data.returnCode;
}
int usb_bulk_transfer(int pipe, void* buffer, int transferSize) {
	int ret;
	char* buf = (char*) buffer;
	int blockSize = transferSize;
	int offset = 0;
	iop_sema_t s;
	usb_callback_data cb_data;

	s.initial = 0;
	s.max = 1;
	s.option = 0;
	s.attr = 0;
	cb_data.semh = CreateSema(&s);

	while (transferSize > 0) {
		if (transferSize < blockSize) {
			blockSize = transferSize;
		}

		ret = UsbBulkTransfer(
			pipe,		//bulk pipe epI(Read)  epO(Write)
			(buf + offset),		//data ptr
			blockSize,		//data length
			usb_callback,
			(void*)&cb_data
            );
		if (ret != USB_RC_OK) {
			printf("USBHDFSD: Error - sending bulk data transfer %d\n", ret);
			cb_data.returnCode = -1;
			break;
		} else {
			WaitSema(cb_data.semh);
			//XPRINTF("USBHDFSD: retCode=%i retSize=%i \n", cb_data.returnCode, cb_data.returnSize);
			if (cb_data.returnCode > 0) {
				break;
			}
			offset += cb_data.returnSize;
			transferSize-= cb_data.returnSize;
		}
	}
	DeleteSema(cb_data.semh);
	return cb_data.returnCode;
}
int usb_bulk_status(mass_dev* dev, csw_packet* csw, int tag) {
	int ret;
	iop_sema_t s;
	usb_callback_data cb_data;

	s.initial = 0;
	s.max = 1;
	s.option = 0;
	s.attr = 0;
	cb_data.semh = CreateSema(&s);

	csw->signature = CSW_TAG;
	csw->tag = tag;
	csw->dataResidue = 0;
	csw->status = 0;

	ret = UsbBulkTransfer(
		dev->bulkEpI,		//bulk input pipe
		csw,			//data ptr
		13,			//data length
		usb_callback,
		(void*)&cb_data
        );

	if (ret != USB_RC_OK) {
		printf("USBHDFSD: Error - sending bulk status %d\n", ret);
		DeleteSema(cb_data.semh);
		return -1;
	} else {
		WaitSema(cb_data.semh);
    	DeleteSema(cb_data.semh);
        if (cb_data.returnSize != 13)
            printf("USBHDFSD: bulk csw.status returnSize: %i\n", cb_data.returnSize);
        if (csw->dataResidue != 0)
            printf("USBHDFSD: bulk csw.status residue: %i\n", csw->dataResidue);
    	XPRINTF("USBHDFSD: bulk csw.status: %i\n", csw->status);
    	return csw->status;
	}
}