Author Topic: bmRequestType confirmation.  (Read 12210 times)

gi

  • Member
  • ***
  • Posts: 27
bmRequestType confirmation.
« on: June 21, 2011, 05:03:59 am »
Hi Jan,
I just want to confirm, which of these two are correct.
From example given by manufacturer and from example given by Tsuneo.

Manufacturer's example:
Code: [Select]
//From example given by manufacturer
switch(SETUP.bmRequestType)         // Determine if recipient was device,
   {                          // interface, or EP
      case OUT_DEVICE:  //<--------Defined below as 0x80, is this supposed to be IN_DEVICE? Bit 7 = 1 which is an IN, from USB 2.0         specification Table 9-2 p.248
         if (SETUP.wIndex.c[MSB] || SETUP.wIndex.c[LSB])
         {
            Force_Stall ();            // Send stall if request is invalid
         }
         else ...
Code: [Select]
// Define bmRequestType bitmaps
#define  IN_DEVICE               0x00  // Request made to device,
                                       // direction is IN
#define  OUT_DEVICE              0x80  // Request made to device,
                                       // direction is OUT
#define  IN_INTERFACE            0x01  // Request made to interface,
                                       // direction is IN
#define  OUT_INTERFACE           0x81  // Request made to interface,
                                       // direction is OUT
#define  IN_ENDPOINT             0x02  // Request made to endpoint,
                                       // direction is IN
#define  OUT_ENDPOINT            0x82  // Request made to endpoint,
                                       // direction is OUT

Tsuneo's Example:
Code: [Select]
//From example given by Tsuneo - Keil_USB_HID_Composite
switch( Setup.bmRequestType )
{
case IN_DEVICE: //<-------Defined below as 0x80, which is an IN, from USB Specification 2.0
if ( Setup.wIndex.i == 0 ) // Valid when wIndex equals to zero
{
// send 0x00, indicating bus power and no remote wake-up supported
DataPtr = (BYTE*)&ZERO_PACKET;
setup_handled = TRUE;
}
break;

case IN_INTERFACE: // See if recipient was interface
// Valid if device is configured and existing interface index
if ( (USB_State == DEV_CONFIGURED) && (Setup.wIndex.i < DSC_NUM_INTERFACE) )
{
// Status packet always returns 0x00
DataPtr = (BYTE*)&ZERO_PACKET;
setup_handled = TRUE;
}
break;

case IN_ENDPOINT: // See if recipient was an endpoint
// Make sure device is configured and index msb = 0x00
if ((USB_State == DEV_CONFIGURED) && (Setup.wIndex.c[MSB] == 0) )
{

Code: [Select]
// Device Request Direction (bmRequestType bit7)
#define DRD_MASK 0x80 // Mask for device request direction
#define DRD_OUT 0x00 // OUT: host to device
#define DRD_IN 0x80 // IN: device to host

// Device Request Type (bmRequestType bit6-5)
#define DRT_MASK 0x60 // Mask for device request type
#define DRT_STD 0x00 // Standard device request
#define DRT_CLASS 0x20 // Class specific request
#define DRT_VENDOR 0x40 // Vendor specific request

// Device Request Recipient (bmRequestType bit4-0)
#define DRR_MASK 0x1F // Mask for device request recipient
#define DRR_DEVICE 0x00 // Device
#define DRR_INTERFACE 0x01 // Interface
#define DRR_ENDPOINT 0x02 // Endpoint

// Define bmRequestType bitmaps
#define OUT_DEVICE (DRD_OUT | DRT_STD | DRR_DEVICE) // Request made to device,
#define IN_DEVICE (DRD_IN  | DRT_STD | DRR_DEVICE) // Request made to device,
#define OUT_INTERFACE (DRD_OUT | DRT_STD | DRR_INTERFACE) // Request made to interface,
#define IN_INTERFACE (DRD_IN  | DRT_STD | DRR_INTERFACE) // Request made to interface,
#define OUT_ENDPOINT (DRD_OUT | DRT_STD | DRR_ENDPOINT) // Request made to endpoint,
#define IN_ENDPOINT (DRD_IN  | DRT_STD | DRR_ENDPOINT) // Request made to endpoint,

I have a feeling that the example given by the manufacturer contains some typo error, the value is correct but the name is misleading.
Is my thought correct?

thanks
gi

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: bmRequestType confirmation.
« Reply #1 on: June 21, 2011, 11:13:18 am »
Is there a specific line or lines that you are questioning?

Jan

gi

  • Member
  • ***
  • Posts: 27
Re: bmRequestType confirmation.
« Reply #2 on: June 21, 2011, 08:40:25 pm »
Yes, I'm sorry.

This line:
Code: [Select]
case OUT_DEVICE:  //<--------Defined below as 0x80, is this supposed to be IN_DEVICE? Bit 7 = 1 which is an IN, from USB 2.0 specification Table 9-2 p.248

That line is part of Get_Status() standard function.

I believed it is IN_DEVICE not OUT_DEVICE although the value(0x80) is correct but the name is misleading and I am confused. Get_Status function returns the statuses of Device | Endpoint | Interface, which means the data direction is from Device to Host = IN and not OUT.
Am I correct?

thanks
gi


Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: bmRequestType confirmation.
« Reply #3 on: June 21, 2011, 10:50:14 pm »
You are correct!

Jan

gi

  • Member
  • ***
  • Posts: 27
Re: bmRequestType confirmation.
« Reply #4 on: June 21, 2011, 11:06:57 pm »
Thanks Jan, I'm learning now ;)