ISoftUSBEndpointEvents::OnSetupTransfer Method

The OnSetupTransfer event enables the device simulator to respond directly to a request. This event is fired for control endpoints when the setup phase transaction for a device request is received from the host.

Syntax

HRESULT OnSetupTransfer(
  [in]   BYTE DataToggle,
  [in]   BYTE *pbDataBuffer,
  [in]   ULONG cbDataBuffer,
  [out]  BYTE *pbStatus
);

Parameters

  • DataToggle [in]
    The data toggle value for the transaction.

  • pbDataBuffer [in]
    The data buffer that contains the data for the transaction.

  • cbDataBuffer [in]
    The size of the data buffer that *pbDataBuffer specifies.

  • pbStatus [out]
    The status of the transaction, which is returned to the host controller.

Return Value

OnSetupTransfer returns an HRESULT value.

Remarks

The following C++ code example shows how to handle a setup request from the host controller.

STDMETHODIMP CLoopBackDevice::OnSetupTransfer(BYTE DataToggle, BYTE *pbDataBuffer,
                               ULONG cbDataBuffer, BYTE *pbStatus)
{
    HRESULT hr        = S_OK;
    USBSETUPREQUEST      *pUSBRequest = NULL;
    BYTE        bNewAddress = 0;

    if (NULL == pbDataBuffer || NULL == pbStatus)
    {
            hr = E_POINTER;
            goto Exit;
     }

     // Validate that the buffer is only 8 bytes long (the standard size of
    // a setup request)
    if (8 != cbDataBuffer)
    {
         hr = E_INVALIDARG;
         goto Exit;
    }

     // Cast the data buffer to a setup request
     pUSBRequest = reinterpret_cast<USBSETUPREQUEST*>(pbDataBuffer);

     // The device handles only SET_ADDRESS requests, and this request is not of that type
     // Fail the request
     if (SET_ADDRESS != pUSBRequest->bRequest)
     {
          hr = E_NOTIMPLE;
          goto Exit;
      }

      // Handle the setup request
       // Only addresses that are less than 128 are valid
      if(128 < pUSBRequest->sSetupValue)
     {
      bNewAddress = (BYTE)pUSBRequest->sSetupValue;
      m_piUSBDevice->put_Address(bNewAddress);
      }
      else
      {
            hr = E_INVALIDARG;
            goto Exit;
      }
 
    // ACK the status because the data was successfully sent to the IN endpoint
    *pbStatus = USB_ACK;

Exit:
    if (FAILED(hr))
    {
        *pbStatus = USB_STALL;
    }
    return hr;
}

Requirements

Header

SoftUSBif.h

See Also

ISoftUSBEndpointEvents

 

 

Send comments about this topic to Microsoft

Build date: 9/21/2010