/** @file
Manage Usb Descriptor List
Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "UsbBus.h"
/**
Free the interface setting descriptor.
@param Setting The descriptor to free.
**/
)
{
//
// Each interface setting may have several endpoints, free them first.
//
}
}
//
// Only call FreePool() if NumEndpoints > 0.
//
}
}
}
/**
Free a configuration descriptor with its interface
descriptors. It may be initialized partially.
@param Config The configuration descriptor to free.
**/
)
{
//
// A configuration may have several interfaces, free the interface
//
continue;
}
//
// Each interface may have several settings, free the settings
//
}
}
}
}
}
/**
Free a device descriptor with its configurations.
@param DevDesc The device descriptor.
**/
)
{
}
}
}
}
/**
Create a descriptor.
@param DescBuf The buffer of raw descriptor.
@param Len The length of the raw descriptor buffer.
@param Type The type of descriptor to create.
@param Consumed Number of bytes consumed.
@return Created descriptor or NULL.
**/
VOID *
)
{
DescLen = 0;
CtrlLen = 0;
*Consumed = 0;
switch (Type) {
case USB_DESC_TYPE_DEVICE:
DescLen = sizeof (EFI_USB_DEVICE_DESCRIPTOR);
CtrlLen = sizeof (USB_DEVICE_DESC);
break;
case USB_DESC_TYPE_CONFIG:
DescLen = sizeof (EFI_USB_CONFIG_DESCRIPTOR);
CtrlLen = sizeof (USB_CONFIG_DESC);
break;
case USB_DESC_TYPE_INTERFACE:
DescLen = sizeof (EFI_USB_INTERFACE_DESCRIPTOR);
CtrlLen = sizeof (USB_INTERFACE_SETTING);
break;
case USB_DESC_TYPE_ENDPOINT:
DescLen = sizeof (EFI_USB_ENDPOINT_DESCRIPTOR);
CtrlLen = sizeof (USB_ENDPOINT_DESC);
break;
}
//
// All the descriptor has a common LTV (Length, Type, Value)
// format. Skip the descriptor that isn't of this Type
//
Offset = 0;
}
return NULL;
}
return NULL;
}
return Desc;
}
/**
Parse an interface descriptor and its endpoints.
@param DescBuf The buffer of raw descriptor.
@param Len The length of the raw descriptor buffer.
@param Consumed The number of raw descriptor consumed.
@return The create interface setting or NULL if failed.
**/
)
{
*Consumed = 0;
return NULL;
}
//
// Create an array to hold the interface's endpoints
//
if (NumEp == 0) {
goto ON_EXIT;
}
goto ON_ERROR;
}
//
// Create the endpoints for this interface
//
DEBUG (( EFI_D_ERROR, "UsbParseInterfaceDesc: failed to create endpoint(index %d)\n", (UINT32)Index));
goto ON_ERROR;
}
}
return Setting;
return NULL;
}
/**
Parse the configuration descriptor and its interfaces.
@param DescBuf The buffer of raw descriptor.
@param Len The length of the raw descriptor buffer.
@return The created configuration descriptor.
**/
)
{
return NULL;
}
//
// Initialize an array of setting for the configuration's interfaces.
//
goto ON_ERROR;
}
goto ON_ERROR;
}
}
//
// If a configuration has several interfaces, these interfaces are
// numbered from zero to n. If a interface has several settings,
// these settings are also number from zero to m. The interface
// setting must be organized as |interface 0, setting 0|interface 0
// setting 1|interface 1, setting 0|interface 2, setting 0|. Check
// USB2.0 spec, page 267.
//
//
// Make allowances for devices that return extra data at the
// end of their config descriptors
//
while (Len >= sizeof (EFI_USB_INTERFACE_DESCRIPTOR)) {
goto ON_ERROR;
goto ON_ERROR;
}
//
// Insert the descriptor to the corresponding set.
//
goto ON_ERROR;
}
}
return Config;
return NULL;
}
/**
USB standard control transfer support routine. This
function is used by USB device. It is possible that
the device's interfaces are still waiting to be
enumerated.
@param UsbDev The usb device.
@param Direction The direction of data transfer.
@param Type Standard / class specific / vendor specific.
@param Target The receiving target.
@param Request Which request.
@param Value The wValue parameter of the request.
@param Index The wIndex parameter of the request.
@param Buf The buffer to receive data into / transmit from.
@param Length The length of the buffer.
@retval EFI_SUCCESS The control request is executed.
@retval EFI_DEVICE_ERROR Failed to execute the control transfer.
**/
)
{
&DevReq,
Buf,
&Len,
&UsbDev->Translator,
);
return Status;
}
/**
Get the standard descriptors.
@param UsbDev The USB device to read descriptor from.
@param DescType The type of descriptor to read.
@param DescIndex The index of descriptor to read.
@param LangId Language ID, only used to get string, otherwise set
it to 0.
@param Buf The buffer to hold the descriptor read.
@param Length The length of the buffer.
@retval EFI_SUCCESS The descriptor is read OK.
@retval Others Failed to retrieve the descriptor.
**/
)
{
Status = UsbCtrlRequest (
Buf,
);
return Status;
}
/**
Return the max packet size for endpoint zero. This function
is the first function called to get descriptors during bus
enumeration.
@param UsbDev The usb device.
@retval EFI_SUCCESS The max packet size of endpoint zero is retrieved.
@retval EFI_DEVICE_ERROR Failed to retrieve it.
**/
)
{
//
// Get the first 8 bytes of the device descriptor which contains
// max packet size for endpoint 0, which is at least 8.
//
return EFI_SUCCESS;
}
return EFI_SUCCESS;
}
}
return EFI_DEVICE_ERROR;
}
/**
Get the device descriptor for the device.
@param UsbDev The Usb device to retrieve descriptor from.
@retval EFI_SUCCESS The device descriptor is returned.
@retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
**/
)
{
return EFI_OUT_OF_RESOURCES;
}
Status = UsbCtrlGetDesc (
0,
0,
sizeof (EFI_USB_DEVICE_DESCRIPTOR)
);
} else {
}
return Status;
}
/**
Retrieve the indexed string for the language. It requires two
steps to get a string, first to get the string's length. Then
the string itself.
@param UsbDev The usb device.
@param Index The index the string to retrieve.
@param LangId Language ID.
@return The created string descriptor or NULL.
**/
)
{
//
// First get two bytes which contains the string length.
//
return NULL;
}
return NULL;
}
Status = UsbCtrlGetDesc (
Buf,
);
return NULL;
}
return (EFI_USB_STRING_DESCRIPTOR *) Buf;
}
/**
Build the language ID table for string descriptors.
@param UsbDev The Usb device.
@retval EFI_UNSUPPORTED This device doesn't support string table.
**/
)
{
//
// The string of language ID zero returns the supported languages
//
return EFI_UNSUPPORTED;
}
goto ON_EXIT;
}
Point++;
}
return Status;
}
/**
Retrieve the indexed configure for the device. USB device
returns the configuration together with the interfaces for
this configuration. Configuration descriptor is also of
variable length.
@param UsbDev The Usb interface.
@param Index The index of the configuration.
@return The created configuration descriptor.
**/
)
{
//
// First get four bytes which contains the total length
// for this configuration.
//
return NULL;
}
return NULL;
}
return NULL;
}
return Buf;
}
/**
Build the whole array of descriptors. This function must
be called after UsbGetMaxPacketSize0 returns the max packet
size correctly for endpoint 0.
@param UsbDev The Usb device.
@retval EFI_SUCCESS The descriptor table is build.
@retval EFI_OUT_OF_RESOURCES Failed to allocate resource for the descriptor.
**/
)
{
//
// Get the device descriptor, then allocate the configure
// descriptor pointer array to hold configurations.
//
return Status;
}
return EFI_OUT_OF_RESOURCES;
}
//
// Read each configurations, then parse them
//
//
// If we can get the default descriptor, it is likely that the
// device is still operational.
//
if (Index == 0) {
return EFI_DEVICE_ERROR;
}
break;
}
if (ConfigDesc == NULL) {
//
// If we can get the default descriptor, it is likely that the
// device is still operational.
//
if (Index == 0) {
return EFI_DEVICE_ERROR;
}
break;
}
}
//
// Don't return error even this function failed because
// it is possible for the device to not support strings.
//
}
return EFI_SUCCESS;
}
/**
Set the device's address.
@param UsbDev The device to set address to.
@param Address The address to set.
@retval EFI_SUCCESS The device is set to the address.
@retval Others Failed to set the device address.
**/
)
{
Status = UsbCtrlRequest (
0,
NULL,
0
);
return Status;
}
/**
Set the device's configuration. This function changes
the device's internal state. UsbSelectConfig changes
the Usb bus's internal state.
@param UsbDev The USB device to set configure to.
@param ConfigIndex The configure index to set.
@retval EFI_SUCCESS The device is configured now.
@retval Others Failed to set the device configure.
**/
)
{
Status = UsbCtrlRequest (
0,
NULL,
0
);
return Status;
}
/**
Usb UsbIo interface to clear the feature. This is should
only be used by HUB which is considered a device driver
on top of the UsbIo interface.
@param UsbIo The UsbIo interface.
@param Feature The feature to clear.
@param Index The wIndex parameter.
@retval EFI_SUCCESS The device feature is cleared.
@retval Others Failed to clear the feature.
**/
)
{
&DevReq,
NULL,
0,
);
return Status;
}