- Main Page
- Classes
- Files
- Related Pages

- File List
- File Members

# usbstdreq.c File Reference

`#include "type.h"`
`#include "usbdebug.h"`
`#include "usbstruct.h"`
`#include "usbapi.h"`

Include dependency graph for usbstdreq.c:

## Defines

#define | MAX_DESC_HANDLERS 4
#define | DESC_bLength 0
#define | DESC_bDescriptorType 1
#define | CONF_DESC_wTotalLength 2
#define | CONF_DESC_bConfigurationValue 5
#define | CONF_DESC_bmAttributes 7
#define | INTF_DESC_bAlternateSetting 3
#define | ENDP_DESC_bEndpointAddress 2
#define | ENDP_DESC_wMaxPacketSize 4

## Functions

void | USBRegisterDescriptors (const U8 *pabDescriptors)
BOOL | USBGetDescriptor (U16 wTypeIndex, U16 wLangID, int *piLen, U8 **ppbData)
BOOL | USBHandleStandardRequest (TSetupPacket *pSetup, int *piLen, U8 **ppbData)
void | USBRegisterCustomReqHandler (TFnHandleRequest *pfnHandler)

## Detailed Description

Standard request handler.

This modules handles the 'chapter 9' processing, specifically the standard device requests in table 9-3 from the universal serial bus specification revision 2.0

Specific types of devices may specify additional requests (for example HID devices add a GET_DESCRIPTOR request for interfaces), but they will not be part of this module.

Todo:
  some requests have to return a request error if device not configured:

  GET_INTERFACE, GET_STATUS, SET_INTERFACE, SYNCH_FRAME

  this applies to the following if endpoint != 0:

  SET_FEATURE, GET_FEATURE

## Define Documentation

#define CONF_DESC_bConfigurationValue 5

configuration value offset

#define CONF_DESC_bmAttributes 7

configuration characteristics

#define CONF_DESC_wTotalLength 2

total length offset

#define DESC_bDescriptorType 1

descriptor type offset

#define DESC_bLength 0

length offset

#define ENDP_DESC_bEndpointAddress 2

endpoint address offset

#define ENDP_DESC_wMaxPacketSize 4

maximum packet size offset

#define INTF_DESC_bAlternateSetting 3

alternate setting offset

#define MAX_DESC_HANDLERS 4

device, interface, endpoint, other

## Function Documentation

BOOL USBGetDescriptor | ( | U16 | wTypeIndex,
|  | U16 | wLangID,
|  | int * | piLen,
|  | U8 ** | ppbData |
| ) |  |  |

Parses the list of installed USB descriptors and attempts to find the specified USB descriptor.

Parameters:

  `[in]` | wTypeIndex | Type and index of the descriptor
  `[in]` | wLangID | Language ID of the descriptor (currently unused)
  `[out]` | *piLen | Descriptor length
  `[out]` | *ppbData | Descriptor data

Returns:
  TRUE if the descriptor was found, FALSE otherwise

BOOL USBHandleStandardRequest | ( | TSetupPacket * | pSetup,
|  | int * | piLen,
|  | U8 ** | ppbData |
| ) |  |  |

Default handler for standard ('chapter 9') requests

If a custom request handler was installed, this handler is called first.

Parameters:

  `[in]` | pSetup | The setup packet
  `[in,out]` | *piLen | Pointer to data length
  `[in]` | ppbData | Data buffer.

Returns:
  TRUE if the request was handled successfully

void USBRegisterCustomReqHandler | ( | TFnHandleRequest * | pfnHandler | ) |

Registers a callback for custom device requests

In USBHandleStandardRequest, the custom request handler gets a first chance at handling the request before it is handed over to the 'chapter 9' request handler.

This can be used for example in HID devices, where a REQ_GET_DESCRIPTOR request is sent to an interface, which is not covered by the 'chapter 9' specification.

Parameters:

  `[in]` | pfnHandler | Callback function pointer

void USBRegisterDescriptors | ( | const U8 * | pabDescriptors | ) |

Registers a pointer to a descriptor block containing all descriptors for the device.

Parameters:

  `[in]` | pabDescriptors | The descriptor byte array