示例#1
0
/*
** Process the request for the right type
** @params self, env, request (for standard_request)
** @return t_bool success -> TRUE, failure -> FALSE
*/
t_bool			cd_process_request(t_cd *self, t_env_manager *env,
					   char *request)
{
  if (self->request_type == PREVIOUS)
    return (previous_dir(self, env));
  else if (self->request_type == EMPTY)
    return (home_dir(self, env));
  else
    return (standard_request(self, env, request));
}
// This function is run inside the thread created in init
// It will respond to standard USB requests
// some of the requests are forwarded to the flash drive when appropriate
void usbslaveboms_setup(usbSlaveBoms_context *ctx)
{
	usbslave_ioctl_cb_t iocb; // this is a structure used by underlying VOS driver
	usb_deviceRequest_t *devReq; // this struct is defined in usb.h and is used to store the 9 byte setup request
	unsigned char bmRequestType; // The request type is defined by USB standard
	unsigned char state = UNATTACHED;  // assume unattached at the start

	// This will wait till the flash drive is enumed so we don't
	// start responding to commands right away
	vos_wait_semaphore(&ctx->enumed);
	vos_signal_semaphore(&ctx->enumed);

	vos_wait_semaphore(&setupDoneSemaphore); // wait for setup to complete
	vos_signal_semaphore(&setupDoneSemaphore); // reset semaphore for next guy

	while (1)
	{
		switch (state)
		{
		case UNATTACHED:

			if (!ctx->attached)
				vos_delay_msecs(100); // this delay is to avoid a tight loop
			else
			{
				state = ATTACHED;
			}

			break;

		case ATTACHED:

			if (!ctx->attached) // check to see if we somehow became unattached
			{
				state = UNATTACHED;
				break;
			}

			// we now make a blocking call requesting the 9 byte setup
			// packet on the control endpoint
			iocb.ioctl_code = VOS_IOCTL_USBSLAVE_WAIT_SETUP_RCVD;
			iocb.request.setup_or_bulk_transfer.buffer = ctx->setup_buffer;
			iocb.request.setup_or_bulk_transfer.size = 9;
			vos_dev_ioctl(ctx->handle, &iocb);

			// decode the raw data by pointing to our structure
			devReq = (usb_deviceRequest_t *) ctx->setup_buffer;
			// valid types here are standard, class, and vendor
			// BOMS devices do not have vendor specific calls
			// even if they did, we wouldn't support them.
			bmRequestType = devReq->bmRequestType & (USB_BMREQUESTTYPE_STANDARD | USB_BMREQUESTTYPE_CLASS);

			// we only need to handle standard and class requests for BOMS
			if (bmRequestType == USB_BMREQUESTTYPE_STANDARD)
			{
				standard_request(ctx); // standard request that all USB devices support
			}
			else if (bmRequestType == USB_BMREQUESTTYPE_CLASS)
			{
				class_request(ctx); // the request is specific to this device class (only 2 in our case)
			}

			break;

		default:
			asm {HALT}; // if we somehow got here the fecal matter has hit the turbine
			break;
		}
	}

	return;
}