📄 usbdcore.c
字号:
/* * (C) Copyright 2003 * Gerry Hamel, geh@ti.com, Texas Instruments * * Based on * linux/drivers/usbd/usbd.c.c - USB Device Core Layer * * Copyright (c) 2000, 2001, 2002 Lineo * Copyright (c) 2001 Hewlett Packard * * By: * Stuart Lynne <sl@lineo.com>, * Tom Rushworth <tbr@lineo.com>, * Bruce Balden <balden@lineo.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */#include <malloc.h>#include "usbdcore.h"#define MAX_INTERFACES 2int maxstrings = 20;/* Global variables ************************************************************************** */struct usb_string_descriptor **usb_strings;int usb_devices;extern struct usb_function_driver ep0_driver;int registered_functions;int registered_devices;char *usbd_device_events[] = { "DEVICE_UNKNOWN", "DEVICE_INIT", "DEVICE_CREATE", "DEVICE_HUB_CONFIGURED", "DEVICE_RESET", "DEVICE_ADDRESS_ASSIGNED", "DEVICE_CONFIGURED", "DEVICE_SET_INTERFACE", "DEVICE_SET_FEATURE", "DEVICE_CLEAR_FEATURE", "DEVICE_DE_CONFIGURED", "DEVICE_BUS_INACTIVE", "DEVICE_BUS_ACTIVITY", "DEVICE_POWER_INTERRUPTION", "DEVICE_HUB_RESET", "DEVICE_DESTROY", "DEVICE_FUNCTION_PRIVATE",};char *usbd_device_states[] = { "STATE_INIT", "STATE_CREATED", "STATE_ATTACHED", "STATE_POWERED", "STATE_DEFAULT", "STATE_ADDRESSED", "STATE_CONFIGURED", "STATE_UNKNOWN",};char *usbd_device_requests[] = { "GET STATUS", /* 0 */ "CLEAR FEATURE", /* 1 */ "RESERVED", /* 2 */ "SET FEATURE", /* 3 */ "RESERVED", /* 4 */ "SET ADDRESS", /* 5 */ "GET DESCRIPTOR", /* 6 */ "SET DESCRIPTOR", /* 7 */ "GET CONFIGURATION", /* 8 */ "SET CONFIGURATION", /* 9 */ "GET INTERFACE", /* 10 */ "SET INTERFACE", /* 11 */ "SYNC FRAME", /* 12 */};char *usbd_device_descriptors[] = { "UNKNOWN", /* 0 */ "DEVICE", /* 1 */ "CONFIG", /* 2 */ "STRING", /* 3 */ "INTERFACE", /* 4 */ "ENDPOINT", /* 5 */ "DEVICE QUALIFIER", /* 6 */ "OTHER SPEED", /* 7 */ "INTERFACE POWER", /* 8 */};char *usbd_device_status[] = { "USBD_OPENING", "USBD_OK", "USBD_SUSPENDED", "USBD_CLOSING",};/* Descriptor support functions ************************************************************** *//** * usbd_get_string - find and return a string descriptor * @index: string index to return * * Find an indexed string and return a pointer to a it. */struct usb_string_descriptor *usbd_get_string (__u8 index){ if (index >= maxstrings) { return NULL; } return usb_strings[index];}/* Access to device descriptor functions ***************************************************** *//* * * usbd_device_configuration_instance - find a configuration instance for this device * @device: * @configuration: index to configuration, 0 - N-1 * * Get specifed device configuration. Index should be bConfigurationValue-1. */static struct usb_configuration_instance *usbd_device_configuration_instance (struct usb_device_instance *device, unsigned int port, unsigned int configuration){ /* XXX */ configuration = configuration ? configuration - 1 : 0; if (configuration >= device->configurations) { return NULL; } return device->configuration_instance_array + configuration;}/* * * usbd_device_interface_instance * @device: * @configuration: index to configuration, 0 - N-1 * @interface: index to interface * * Return the specified interface descriptor for the specified device. */struct usb_interface_instance *usbd_device_interface_instance (struct usb_device_instance *device, int port, int configuration, int interface){ struct usb_configuration_instance *configuration_instance; if ((configuration_instance = usbd_device_configuration_instance (device, port, configuration)) == NULL) { return NULL; } if (interface >= configuration_instance->interfaces) { return NULL; } return configuration_instance->interface_instance_array + interface;}/* * * usbd_device_alternate_descriptor_list * @device: * @configuration: index to configuration, 0 - N-1 * @interface: index to interface * @alternate: alternate setting * * Return the specified alternate descriptor for the specified device. */struct usb_alternate_instance *usbd_device_alternate_instance (struct usb_device_instance *device, int port, int configuration, int interface, int alternate){ struct usb_interface_instance *interface_instance; if ((interface_instance = usbd_device_interface_instance (device, port, configuration, interface)) == NULL) { return NULL; } if (alternate >= interface_instance->alternates) { return NULL; } return interface_instance->alternates_instance_array + alternate;}/* * * usbd_device_device_descriptor * @device: which device * @configuration: index to configuration, 0 - N-1 * @port: which port * * Return the specified configuration descriptor for the specified device. */struct usb_device_descriptor *usbd_device_device_descriptor (struct usb_device_instance *device, int port){ return (device->device_descriptor);}/** * usbd_device_configuration_descriptor * @device: which device * @port: which port * @configuration: index to configuration, 0 - N-1 * * Return the specified configuration descriptor for the specified device. */struct usb_configuration_descriptor *usbd_device_configuration_descriptor (struct usb_device_instance *device, int port, int configuration){ struct usb_configuration_instance *configuration_instance; if (!(configuration_instance = usbd_device_configuration_instance (device, port, configuration))) { return NULL; } return (configuration_instance->configuration_descriptor);}/** * usbd_device_interface_descriptor * @device: which device * @port: which port * @configuration: index to configuration, 0 - N-1 * @interface: index to interface * @alternate: alternate setting * * Return the specified interface descriptor for the specified device. */struct usb_interface_descriptor *usbd_device_interface_descriptor (struct usb_device_instance *device, int port, int configuration, int interface, int alternate){ struct usb_interface_instance *interface_instance; if (!(interface_instance = usbd_device_interface_instance (device, port, configuration, interface))) { return NULL; } if ((alternate < 0) || (alternate >= interface_instance->alternates)) { return NULL; } return (interface_instance->alternates_instance_array[alternate].interface_descriptor);}/** * usbd_device_endpoint_descriptor_index * @device: which device * @port: which port * @configuration: index to configuration, 0 - N-1 * @interface: index to interface * @alternate: index setting * @index: which index * * Return the specified endpoint descriptor for the specified device. */struct usb_endpoint_descriptor *usbd_device_endpoint_descriptor_index (struct usb_device_instance *device, int port, int configuration, int interface, int alternate, int index){ struct usb_alternate_instance *alternate_instance; if (!(alternate_instance = usbd_device_alternate_instance (device, port, configuration, interface, alternate))) { return NULL; } if (index >= alternate_instance->endpoints) { return NULL; } return *(alternate_instance->endpoints_descriptor_array + index);}/** * usbd_device_endpoint_transfersize * @device: which device * @port: which port * @configuration: index to configuration, 0 - N-1 * @interface: index to interface * @index: which index * * Return the specified endpoint transfer size; */int usbd_device_endpoint_transfersize (struct usb_device_instance *device, int port, int configuration, int interface, int alternate, int index){ struct usb_alternate_instance *alternate_instance; if (!(alternate_instance = usbd_device_alternate_instance (device, port, configuration, interface, alternate))) { return 0; } if (index >= alternate_instance->endpoints) { return 0; } return *(alternate_instance->endpoint_transfersize_array + index);}/** * usbd_device_endpoint_descriptor * @device: which device * @port: which port * @configuration: index to configuration, 0 - N-1 * @interface: index to interface * @alternate: alternate setting * @endpoint: which endpoint * * Return the specified endpoint descriptor for the specified device. */struct usb_endpoint_descriptor *usbd_device_endpoint_descriptor (struct usb_device_instance *device, int port, int configuration, int interface, int alternate, int endpoint){ struct usb_endpoint_descriptor *endpoint_descriptor; int i; for (i = 0; !(endpoint_descriptor = usbd_device_endpoint_descriptor_index (device, port, configuration, interface, alternate, i)); i++) { if (endpoint_descriptor->bEndpointAddress == endpoint) { return endpoint_descriptor; } } return NULL;}/** * usbd_endpoint_halted * @device: point to struct usb_device_instance * @endpoint: endpoint to check * * Return non-zero if endpoint is halted. */int usbd_endpoint_halted (struct usb_device_instance *device, int endpoint)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -