Example #1
0
int mass_stor_disconnect(int devId) {
	mass_dev* dev;
	dev = mass_stor_findDevice(devId, 0);

	printf("USBHDFSD: disconnect: devId=%i\n", devId);

	if (dev == NULL)
	{
		printf("USBHDFSD: Error - disconnect: no device storage!\n");
		return 0;
	}

	if (dev->status & USBMASS_DEV_STAT_CONN)
	{
		mass_stor_release(dev);
		part_disconnect(dev);
		scache_kill(dev->cache);
		dev->cache = NULL;
		dev->devId = -1;

		DeleteSema(dev->ioSema);

		if(dev->callback != NULL) dev->callback(USBMASS_DEV_EV_DISCONN);
	}

	return 0;
}
Example #2
0
int mass_stor_configureNextDevice(void)
{
	int i;

	XPRINTF("USBHDFSD: configuring devices... \n");

	for (i = 0; i < NUM_DEVICES; ++i)
	{
		mass_dev *dev = &g_mass_device[i];
		if (dev->devId != -1 && (dev->status & USBMASS_DEV_STAT_CONN) && !(dev->status & USBMASS_DEV_STAT_CONF))
		{
			int ret;
			usb_set_configuration(dev, dev->configId);
			usb_set_interface(dev, dev->interfaceNumber, dev->interfaceAlt);
			dev->status |= USBMASS_DEV_STAT_CONF;

			ret = mass_stor_warmup(dev);
			if (ret < 0)
			{
				printf("USBHDFSD: Error - failed to warmup device %d\n", dev->devId);
				mass_stor_release(dev);
				continue;
			}

			dev->cache = scache_init(dev, dev->sectorSize); // modified by Hermes
			if (dev->cache == NULL) {
				printf("USBHDFSD: Error - scache_init failed \n" );
				continue;
			}

			return part_connect(dev) >= 0;
		}
	}
	return 0;
}
int mass_stor_configureNextDevice()
{
	int i;

    // give the USB driver some time to detect the device
    //i = 10000;
    //while (wait_for_connect && (--i > 0))
        //DelayThread(100);
    //wait_for_connect = 0;

	XPRINTF("USBHDFSD: configuring devices... \n");

    for (i = 0; i < NUM_DEVICES; ++i)
    {
        mass_dev *dev = &g_mass_device[i];
        if (dev->devId != -1 && (dev->status & DEVICE_DETECTED) && !(dev->status & DEVICE_CONFIGURED))
        {
            int ret;
            usb_set_configuration(dev, dev->configId);
            usb_set_interface(dev, dev->interfaceNumber, dev->interfaceAlt);
            dev->status |= DEVICE_CONFIGURED;

            ret = mass_stor_warmup(dev);
            if (ret < 0)
            {
                printf("USBHDFSD: Error - failed to warmup device %d\n", dev->devId);
                mass_stor_release(dev);
                continue;
            }

            dev->cache = scache_init(dev, dev->sectorSize); // modified by Hermes
            if (dev->cache == NULL) {
                printf("USBHDFSD: Error - scache_init failed \n" );
                continue;
            }

            return part_connect(dev) >= 0;
        }
    }
    return 0;
}
int mass_stor_disconnect(int devId) {
	mass_dev* dev;
	dev = mass_stor_findDevice(devId, 0);

	printf("USBHDFSD: disconnect: devId=%i\n", devId);

    if (dev == NULL)
    {
        printf("USBHDFSD: Error - disconnect: no device storage!\n");
        return 0;
    }
    
	if ((dev->status & DEVICE_DETECTED) && devId == dev->devId)
	{
		mass_stor_release(dev);
		part_disconnect(dev);
		scache_kill(dev->cache);
		dev->cache = NULL;
		dev->devId = -1;
	}
	return 0;
}
Example #5
0
int mass_stor_connect(int devId)
{
	int i;
	int epCount;
	UsbDeviceDescriptor *device;
	UsbConfigDescriptor *config;
	UsbInterfaceDescriptor *interface;
	UsbEndpointDescriptor *endpoint;
	iop_sema_t SemaData;
	mass_dev* dev;

	printf("USBHDFSD: connect: devId=%i\n", devId);
	dev = mass_stor_findDevice(devId, 1);

	if (dev == NULL) {
		printf("USBHDFSD: Error - unable to allocate space!\n");
		return 1;
	}

	/* only one mass device allowed */
	if (dev->devId != -1) {
		printf("USBHDFSD: Error - only one mass storage device allowed !\n");
		return 1;
	}

	dev->status = 0;
	dev->sectorSize = 0;

	dev->bulkEpI = -1;
	dev->bulkEpO = -1;

	/* open the config endpoint */
	dev->controlEp = UsbOpenEndpoint(devId, NULL);

	device = (UsbDeviceDescriptor*)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_DEVICE);

	config = (UsbConfigDescriptor*)UsbGetDeviceStaticDescriptor(devId, device, USB_DT_CONFIG);

	interface = (UsbInterfaceDescriptor *) ((char *) config + config->bLength); /* Get first interface */

	// store interface numbers
	dev->interfaceNumber = interface->bInterfaceNumber;
	dev->interfaceAlt    = interface->bAlternateSetting;

	epCount = interface->bNumEndpoints;
	endpoint = (UsbEndpointDescriptor*)UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_ENDPOINT);
	usb_bulk_probeEndpoint(devId, dev, endpoint);

	for (i = 1; i < epCount; i++)
	{
		endpoint = (UsbEndpointDescriptor*) ((char *) endpoint + endpoint->bLength);
		usb_bulk_probeEndpoint(devId, dev, endpoint);
	}

	// Bail out if we do NOT have enough bulk endpoints.
	if (dev->bulkEpI < 0 || dev->bulkEpO < 0) {
		mass_stor_release(dev);
		printf("USBHDFSD: Error - connect failed: not enough bulk endpoints! \n");
		return -1;
	}

	SemaData.initial = 0;
	SemaData.max = 1;
	SemaData.option = 0;
	SemaData.attr = 0;
	if((dev->ioSema = CreateSema(&SemaData)) <0){
		printf("USBHDFSD: Failed to allocate I/O semaphore.\n");
		return -1;
	}

	/*store current configuration id - can't call set_configuration here */
	dev->devId = devId;
	dev->configId = config->bConfigurationValue;
	dev->status = USBMASS_DEV_STAT_CONN;
	XPRINTF("USBHDFSD: connect ok: epI=%i, epO=%i \n", dev->bulkEpI, dev->bulkEpO);

	if(dev->callback != NULL) dev->callback(USBMASS_DEV_EV_CONN);

	return 0;
}