⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usbdcore_ep0.c

📁 u-boot-1.1.6 源码包
💻 C
📖 第 1 页 / 共 2 页
字号:
								 bNumEndpoint);							return -1;						}						/* copy descriptor for this endpoint */						copy_config (urb, endpoint_descriptor,							     sizeof (struct usb_endpoint_descriptor),							     max);					}				}			}			dbg_ep0 (3, "lengths: %d %d",				 le16_to_cpu (configuration_descriptor->wTotalLength),				 urb->actual_length);		}		break;	case USB_DESCRIPTOR_TYPE_STRING:		{			struct usb_string_descriptor *string_descriptor;			if (!(string_descriptor = usbd_get_string (index))) {				return -1;			}			/*dbg_ep0(3, "string_descriptor: %p", string_descriptor); */			copy_config (urb, string_descriptor, string_descriptor->bLength, max);		}		break;	case USB_DESCRIPTOR_TYPE_INTERFACE:		return -1;	case USB_DESCRIPTOR_TYPE_ENDPOINT:		return -1;	case USB_DESCRIPTOR_TYPE_HID:		{			return -1;	/* unsupported at this time */#if 0			int bNumInterface =				le16_to_cpu (urb->device_request.wIndex);			int bAlternateSetting = 0;			int class = 0;			struct usb_class_descriptor *class_descriptor;			if (!(class_descriptor =			      usbd_device_class_descriptor_index (device,								  port, 0,								  bNumInterface,								  bAlternateSetting,								  class))			    || class_descriptor->descriptor.hid.bDescriptorType != USB_DT_HID) {				dbg_ep0 (3, "[%d] interface is not HID",					 bNumInterface);				return -1;			}			/* copy descriptor for this class */			copy_config (urb, class_descriptor,				     class_descriptor->descriptor.hid.bLength,				     max);#endif		}		break;	case USB_DESCRIPTOR_TYPE_REPORT:		{			return -1;	/* unsupported at this time */#if 0			int bNumInterface =				le16_to_cpu (urb->device_request.wIndex);			int bAlternateSetting = 0;			int class = 0;			struct usb_class_report_descriptor *report_descriptor;			if (!(report_descriptor =			      usbd_device_class_report_descriptor_index			      (device, port, 0, bNumInterface,			       bAlternateSetting, class))			    || report_descriptor->bDescriptorType !=			    USB_DT_REPORT) {				dbg_ep0 (3, "[%d] descriptor is not REPORT",					 bNumInterface);				return -1;			}			/* copy report descriptor for this class */			/*copy_config(urb, &report_descriptor->bData[0], report_descriptor->wLength, max); */			if (max - urb->actual_length > 0) {				int length =					MIN (report_descriptor->wLength,					     max - urb->actual_length);				memcpy (urb->buffer + urb->actual_length,					&report_descriptor->bData[0], length);				urb->actual_length += length;			}#endif		}		break;	default:		return -1;	}	dbg_ep0 (1, "urb: buffer: %p buffer_length: %2d actual_length: %2d packet size: %2d",		 urb->buffer, urb->buffer_length, urb->actual_length,		 device->bus->endpoint_array[0].tx_packetSize);/*    if ((urb->actual_length < max) && !(urb->actual_length % device->bus->endpoint_array[0].tx_packetSize)) {	dbg_ep0(0, "adding null byte");	urb->buffer[urb->actual_length++] = 0;	dbg_ep0(0, "urb: buffer_length: %2d actual_length: %2d packet size: %2d",		urb->buffer_length, urb->actual_length device->bus->endpoint_array[0].tx_packetSize);    }*/	return 0;}/** * ep0_recv_setup - called to indicate URB has been received * @urb: pointer to struct urb * * Check if this is a setup packet, process the device request, put results * back into the urb and return zero or non-zero to indicate success (DATA) * or failure (STALL). * */int ep0_recv_setup (struct urb *urb){	/*struct usb_device_request *request = urb->buffer; */	/*struct usb_device_instance *device = urb->device; */	struct usb_device_request *request;	struct usb_device_instance *device;	int address;	dbg_ep0 (0, "entering ep0_recv_setup()");	if (!urb || !urb->device) {		dbg_ep0 (3, "invalid URB %p", urb);		return -1;	}	request = &urb->device_request;	device = urb->device;	dbg_ep0 (3, "urb: %p device: %p", urb, urb->device);	/*dbg_ep0(2, "-       -       -       -       -       -       -       -       -       -"); */	dbg_ep0 (2,		 "bmRequestType:%02x bRequest:%02x wValue:%04x wIndex:%04x wLength:%04x %s",		 request->bmRequestType, request->bRequest,		 le16_to_cpu (request->wValue), le16_to_cpu (request->wIndex),		 le16_to_cpu (request->wLength),		 USBD_DEVICE_REQUESTS (request->bRequest));	/* handle USB Standard Request (c.f. USB Spec table 9-2) */	if ((request->bmRequestType & USB_REQ_TYPE_MASK) != 0) {		dbg_ep0 (1, "non standard request: %x",			 request->bmRequestType & USB_REQ_TYPE_MASK);		return -1;	/* Stall here */	}	switch (device->device_state) {	case STATE_CREATED:	case STATE_ATTACHED:	case STATE_POWERED:		/* It actually is important to allow requests in these states,		 * Windows will request descriptors before assigning an		 * address to the client.		 */		/*dbg_ep0 (1, "request %s not allowed in this state: %s", */		/*                USBD_DEVICE_REQUESTS(request->bRequest), */		/*                usbd_device_states[device->device_state]); */		/*return -1; */		break;	case STATE_INIT:	case STATE_DEFAULT:		switch (request->bRequest) {		case USB_REQ_GET_STATUS:		case USB_REQ_GET_INTERFACE:		case USB_REQ_SYNCH_FRAME:	/* XXX should never see this (?) */		case USB_REQ_CLEAR_FEATURE:		case USB_REQ_SET_FEATURE:		case USB_REQ_SET_DESCRIPTOR:			/* case USB_REQ_SET_CONFIGURATION: */		case USB_REQ_SET_INTERFACE:			dbg_ep0 (1,				 "request %s not allowed in DEFAULT state: %s",				 USBD_DEVICE_REQUESTS (request->bRequest),				 usbd_device_states[device->device_state]);			return -1;		case USB_REQ_SET_CONFIGURATION:		case USB_REQ_SET_ADDRESS:		case USB_REQ_GET_DESCRIPTOR:		case USB_REQ_GET_CONFIGURATION:			break;		}	case STATE_ADDRESSED:	case STATE_CONFIGURED:		break;	case STATE_UNKNOWN:		dbg_ep0 (1, "request %s not allowed in UNKNOWN state: %s",			 USBD_DEVICE_REQUESTS (request->bRequest),			 usbd_device_states[device->device_state]);		return -1;	}	/* handle all requests that return data (direction bit set on bm RequestType) */	if ((request->bmRequestType & USB_REQ_DIRECTION_MASK)) {		dbg_ep0 (3, "Device-to-Host");		switch (request->bRequest) {		case USB_REQ_GET_STATUS:			return ep0_get_status (device, urb, request->wIndex,					       request->bmRequestType &					       USB_REQ_RECIPIENT_MASK);		case USB_REQ_GET_DESCRIPTOR:			return ep0_get_descriptor (device, urb,						   le16_to_cpu (request->wLength),						   le16_to_cpu (request->wValue) >> 8,						   le16_to_cpu (request->wValue) & 0xff);		case USB_REQ_GET_CONFIGURATION:			return ep0_get_one (device, urb,					    device->configuration);		case USB_REQ_GET_INTERFACE:			return ep0_get_one (device, urb, device->alternate);		case USB_REQ_SYNCH_FRAME:	/* XXX should never see this (?) */			return -1;		case USB_REQ_CLEAR_FEATURE:		case USB_REQ_SET_FEATURE:		case USB_REQ_SET_ADDRESS:		case USB_REQ_SET_DESCRIPTOR:		case USB_REQ_SET_CONFIGURATION:		case USB_REQ_SET_INTERFACE:			return -1;		}	}	/* handle the requests that do not return data */	else {		/*dbg_ep0(3, "Host-to-Device"); */		switch (request->bRequest) {		case USB_REQ_CLEAR_FEATURE:		case USB_REQ_SET_FEATURE:			dbg_ep0 (0, "Host-to-Device");			switch (request->				bmRequestType & USB_REQ_RECIPIENT_MASK) {			case USB_REQ_RECIPIENT_DEVICE:				/* XXX DEVICE_REMOTE_WAKEUP or TEST_MODE would be added here */				/* XXX fall through for now as we do not support either */			case USB_REQ_RECIPIENT_INTERFACE:			case USB_REQ_RECIPIENT_OTHER:				dbg_ep0 (0, "request %s not",					 USBD_DEVICE_REQUESTS (request->bRequest));			default:				return -1;			case USB_REQ_RECIPIENT_ENDPOINT:				dbg_ep0 (0, "ENDPOINT: %x", le16_to_cpu (request->wValue));				if (le16_to_cpu (request->wValue) == USB_ENDPOINT_HALT) {					/*return usbd_device_feature (device, le16_to_cpu (request->wIndex), */					/*                    request->bRequest == USB_REQ_SET_FEATURE); */					/* NEED TO IMPLEMENT THIS!!! */					return -1;				} else {					dbg_ep0 (1, "request %s bad wValue: %04x",						 USBD_DEVICE_REQUESTS						 (request->bRequest),						 le16_to_cpu (request->wValue));					return -1;				}			}		case USB_REQ_SET_ADDRESS:			/* check if this is a re-address, reset first if it is (this shouldn't be possible) */			if (device->device_state != STATE_DEFAULT) {				dbg_ep0 (1, "set_address: %02x state: %s",					 le16_to_cpu (request->wValue),					 usbd_device_states[device->device_state]);				return -1;			}			address = le16_to_cpu (request->wValue);			if ((address & 0x7f) != address) {				dbg_ep0 (1, "invalid address %04x %04x",					 address, address & 0x7f);				return -1;			}			device->address = address;			/*dbg_ep0(2, "address: %d %d %d", */			/*        request->wValue, le16_to_cpu(request->wValue), device->address); */			serial_printf ("DEVICE_ADDRESS_ASSIGNED.. event?\n");			return 0;		case USB_REQ_SET_DESCRIPTOR:	/* XXX should we support this? */			dbg_ep0 (0, "set descriptor: NOT SUPPORTED");			return -1;		case USB_REQ_SET_CONFIGURATION:			/* c.f. 9.4.7 - the top half of wValue is reserved */			/* */			if ((device->configuration =			     le16_to_cpu (request->wValue) & 0x7f) != 0) {				/* c.f. 9.4.7 - zero is the default or addressed state, in our case this */				/* is the same is configuration zero */				device->configuration = 0;	/* TBR - ?????? */			}			/* reset interface and alternate settings */			device->interface = device->alternate = 0;			/*dbg_ep0(2, "set configuration: %d", device->configuration); */			/*serial_printf("DEVICE_CONFIGURED.. event?\n"); */			return 0;		case USB_REQ_SET_INTERFACE:			device->interface = le16_to_cpu (request->wIndex);			device->alternate = le16_to_cpu (request->wValue);			/*dbg_ep0(2, "set interface: %d alternate: %d", device->interface, device->alternate); */			serial_printf ("DEVICE_SET_INTERFACE.. event?\n");			return 0;		case USB_REQ_GET_STATUS:		case USB_REQ_GET_DESCRIPTOR:		case USB_REQ_GET_CONFIGURATION:		case USB_REQ_GET_INTERFACE:		case USB_REQ_SYNCH_FRAME:	/* XXX should never see this (?) */			return -1;		}	}	return -1;}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -