ReactOS  0.4.14-dev-337-gf981a68
CUSBRequest Class Reference
Inheritance diagram for CUSBRequest:
Collaboration diagram for CUSBRequest:

Public Member Functions

STDMETHODIMP QueryInterface (REFIID InterfaceId, PVOID *Interface)
 
 STDMETHODIMP_ (ULONG) AddRef()
 
 STDMETHODIMP_ (ULONG) Release()
 
IMP_IUSBREQUEST IMP_IEHCIREQUEST ULONG InternalGetTransferType ()
 
UCHAR InternalGetPidDirection ()
 
NTSTATUS BuildControlTransferQueueHead (PQUEUE_HEAD *OutHead)
 
NTSTATUS BuildBulkInterruptTransferQueueHead (PQUEUE_HEAD *OutHead)
 
NTSTATUS STDMETHODCALLTYPE CreateDescriptor (PQUEUE_TRANSFER_DESCRIPTOR *OutDescriptor)
 
NTSTATUS CreateQueueHead (PQUEUE_HEAD *OutQueueHead)
 
UCHAR STDMETHODCALLTYPE GetDeviceAddress ()
 
NTSTATUS BuildSetupPacket ()
 
NTSTATUS BuildSetupPacketFromURB ()
 
ULONG InternalCalculateTransferLength ()
 
NTSTATUS STDMETHODCALLTYPE BuildTransferDescriptorChain (IN PQUEUE_HEAD QueueHead, IN PVOID TransferBuffer, IN ULONG TransferBufferLength, IN UCHAR PidCode, IN UCHAR InitialDataToggle, OUT PQUEUE_TRANSFER_DESCRIPTOR *OutFirstDescriptor, OUT PQUEUE_TRANSFER_DESCRIPTOR *OutLastDescriptor, OUT PUCHAR OutDataToggle, OUT PULONG OutTransferBufferOffset)
 
VOID STDMETHODCALLTYPE InitDescriptor (IN PQUEUE_TRANSFER_DESCRIPTOR CurrentDescriptor, IN PVOID TransferBuffer, IN ULONG TransferBufferLength, IN UCHAR PidCode, IN UCHAR DataToggle, OUT PULONG OutDescriptorLength)
 
VOID DumpQueueHead (IN PQUEUE_HEAD QueueHead)
 
 CUSBRequest (IUnknown *OuterUnknown)
 
virtual ~CUSBRequest ()
 
STDMETHODIMP QueryInterface (REFIID InterfaceId, PVOID *Interface)
 
 STDMETHODIMP_ (ULONG) AddRef()
 
 STDMETHODIMP_ (ULONG) Release()
 
IMP_IUSBREQUEST IMP_IOHCIREQUEST ULONG InternalGetTransferType ()
 
UCHAR InternalGetPidDirection ()
 
UCHAR STDMETHODCALLTYPE GetDeviceAddress ()
 
NTSTATUS BuildSetupPacket ()
 
NTSTATUS BuildSetupPacketFromURB ()
 
NTSTATUS BuildControlTransferDescriptor (POHCI_ENDPOINT_DESCRIPTOR *OutEndpointDescriptor)
 
NTSTATUS BuildBulkInterruptEndpoint (POHCI_ENDPOINT_DESCRIPTOR *OutEndpointDescriptor)
 
NTSTATUS BuildIsochronousEndpoint (POHCI_ENDPOINT_DESCRIPTOR *OutEndpointDescriptor)
 
NTSTATUS CreateGeneralTransferDescriptor (POHCI_GENERAL_TD *OutDescriptor, ULONG BufferSize)
 
VOID FreeDescriptor (POHCI_GENERAL_TD Descriptor)
 
NTSTATUS AllocateEndpointDescriptor (OUT POHCI_ENDPOINT_DESCRIPTOR *OutDescriptor)
 
NTSTATUS CreateIsochronousTransferDescriptor (OUT POHCI_ISO_TD *OutDescriptor, ULONG FrameCount)
 
UCHAR GetEndpointAddress ()
 
USHORT GetMaxPacketSize ()
 
VOID CheckError (struct _OHCI_ENDPOINT_DESCRIPTOR *OutDescriptor)
 
VOID DumpEndpointDescriptor (struct _OHCI_ENDPOINT_DESCRIPTOR *Descriptor)
 
NTSTATUS BuildTransferDescriptorChain (IN PVOID TransferBuffer, IN ULONG TransferBufferLength, IN UCHAR PidCode, OUT POHCI_GENERAL_TD *OutFirstDescriptor, OUT POHCI_GENERAL_TD *OutLastDescriptor, OUT PULONG OutTransferBufferOffset)
 
VOID InitDescriptor (IN POHCI_GENERAL_TD CurrentDescriptor, IN PVOID TransferBuffer, IN ULONG TransferBufferLength, IN UCHAR PidCode)
 
 CUSBRequest (IUnknown *OuterUnknown)
 
virtual ~CUSBRequest ()
 
STDMETHODIMP QueryInterface (REFIID InterfaceId, PVOID *Interface)
 
 STDMETHODIMP_ (ULONG) AddRef()
 
 STDMETHODIMP_ (ULONG) Release()
 
IMP_IUSBREQUEST IMP_IUHCIREQUEST ULONG InternalGetTransferType ()
 
UCHAR InternalGetPidDirection ()
 
UCHAR GetDeviceAddress ()
 
NTSTATUS BuildSetupPacket ()
 
NTSTATUS BuildSetupPacketFromURB ()
 
UCHAR GetEndpointAddress ()
 
USHORT GetMaxPacketSize ()
 
NTSTATUS CreateDescriptor (PUHCI_TRANSFER_DESCRIPTOR *OutDescriptor, IN UCHAR PidCode, ULONG BufferLength)
 
NTSTATUS BuildControlTransferDescriptor (IN PUHCI_QUEUE_HEAD *OutQueueHead)
 
NTSTATUS BuildBulkInterruptTransferDescriptor (IN PUHCI_QUEUE_HEAD *OutQueueHead)
 
NTSTATUS BuildQueueHead (OUT PUHCI_QUEUE_HEAD *OutQueueHead)
 
VOID FreeDescriptor (IN PUHCI_TRANSFER_DESCRIPTOR Descriptor)
 
NTSTATUS BuildTransferDescriptorChain (IN PVOID TransferBuffer, IN ULONG TransferBufferLength, IN UCHAR PidCode, IN UCHAR InitialDataToggle, OUT PUHCI_TRANSFER_DESCRIPTOR *OutFirstDescriptor, OUT PUHCI_TRANSFER_DESCRIPTOR *OutLastDescriptor, OUT PULONG OutTransferBufferOffset, OUT PUCHAR OutDataToggle)
 
 CUSBRequest (IUnknown *OuterUnknown)
 
virtual ~CUSBRequest ()
 

Protected Attributes

LONG m_Ref
 
PDMAMEMORYMANAGER m_DmaManager
 
PIRP m_Irp
 
ULONG m_TransferBufferLength
 
ULONG m_TransferBufferLengthCompleted
 
ULONG m_TotalBytesTransferred
 
PMDL m_TransferBufferMDL
 
PUSB_DEFAULT_PIPE_SETUP_PACKET m_SetupPacket
 
PKEVENT m_CompletionEvent
 
UCHAR m_DeviceAddress
 
PUSB_ENDPOINT m_EndpointDescriptor
 
PQUEUE_HEAD m_QueueHead
 
PUSB_DEFAULT_PIPE_SETUP_PACKET m_DescriptorPacket
 
PHYSICAL_ADDRESS m_DescriptorSetupPacket
 
NTSTATUS m_NtStatusCode
 
ULONG m_UrbStatusCode
 
PVOID m_Base
 
USB_DEVICE_SPEED m_Speed
 
USB_DEVICE_SPEED m_DeviceSpeed
 
PURB m_Urb
 

Detailed Description

Definition at line 16 of file usb_request.cpp.

Constructor & Destructor Documentation

◆ CUSBRequest() [1/3]

CUSBRequest::CUSBRequest ( IUnknown OuterUnknown)

Definition at line 141 of file usb_request.cpp.

141  :
143 {
144  UNREFERENCED_PARAMETER(OuterUnknown);
145 }
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
PKEVENT m_CompletionEvent
smooth NULL
Definition: ftsmooth.c:416

◆ ~CUSBRequest() [1/3]

CUSBRequest::~CUSBRequest ( )
virtual

Definition at line 148 of file usb_request.cpp.

149 {
150  if (m_CompletionEvent != NULL)
151  {
153  }
154 }
PKEVENT m_CompletionEvent
smooth NULL
Definition: ftsmooth.c:416
#define TAG_USBEHCI
Definition: usbehci.h:12
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

◆ CUSBRequest() [2/3]

CUSBRequest::CUSBRequest ( IUnknown OuterUnknown)

◆ ~CUSBRequest() [2/3]

virtual CUSBRequest::~CUSBRequest ( )
virtual

◆ CUSBRequest() [3/3]

CUSBRequest::CUSBRequest ( IUnknown OuterUnknown)

◆ ~CUSBRequest() [3/3]

virtual CUSBRequest::~CUSBRequest ( )
virtual

Member Function Documentation

◆ AllocateEndpointDescriptor()

NTSTATUS CUSBRequest::AllocateEndpointDescriptor ( OUT POHCI_ENDPOINT_DESCRIPTOR OutDescriptor)

Definition at line 968 of file usb_request.cpp.

970 {
972  PHYSICAL_ADDRESS DescriptorAddress;
974 
975  //
976  // allocate descriptor
977  //
978  Status = m_DmaManager->Allocate(sizeof(OHCI_ENDPOINT_DESCRIPTOR), (PVOID*)&Descriptor, &DescriptorAddress);
979  if (!NT_SUCCESS(Status))
980  {
981  //
982  // failed to allocate descriptor
983  //
984  return Status;
985  }
986 
987  //
988  // initialize descriptor
989  //
991 
992  //
993  // append device address and endpoint number
994  //
998 
999  DPRINT("Flags %x DeviceAddress %x EndpointAddress %x PacketSize %lu\n", Descriptor->Flags, GetDeviceAddress(), GetEndpointAddress(), GetMaxPacketSize());
1000 
1001  //
1002  // is there an endpoint descriptor
1003  //
1005  {
1006  //
1007  // check direction
1008  //
1010  {
1011  //
1012  // direction out
1013  //
1015  }
1016  else
1017  {
1018  //
1019  // direction in
1020  //
1022  }
1023  }
1024  else
1025  {
1026  //
1027  // get it from transfer descriptor
1028  //
1030  }
1031 
1032  //
1033  // set type
1034  //
1035  if (m_DeviceSpeed == UsbFullSpeed)
1036  {
1037  //
1038  // device is full speed
1039  //
1041  }
1042  else if (m_DeviceSpeed == UsbLowSpeed)
1043  {
1044  //
1045  // device is full speed
1046  //
1048  }
1049  else
1050  {
1051  //
1052  // error
1053  //
1054  ASSERT(FALSE);
1055  }
1056 
1057  Descriptor->HeadPhysicalDescriptor = 0;
1058  Descriptor->NextPhysicalEndpoint = 0;
1059  Descriptor->TailPhysicalDescriptor = 0;
1060  Descriptor->PhysicalAddress.QuadPart = DescriptorAddress.QuadPart;
1061 
1062  //
1063  // store result
1064  //
1065  *OutDescriptor = Descriptor;
1066 
1067  //
1068  // done
1069  //
1070  return STATUS_SUCCESS;
1071 }
PUSB_ENDPOINT m_EndpointDescriptor
#define OHCI_ENDPOINT_DIRECTION_IN
Definition: hardware.h:239
USB_ENDPOINT_DESCRIPTOR EndPointDescriptor
LONG NTSTATUS
Definition: precomp.h:26
#define OHCI_ENDPOINT_DIRECTION_DESCRIPTOR
Definition: hardware.h:245
UCHAR STDMETHODCALLTYPE GetDeviceAddress()
#define OHCI_ENDPOINT_DIRECTION_OUT
Definition: hardware.h:238
USB_DEVICE_SPEED m_DeviceSpeed
void DPRINT(...)
Definition: polytest.cpp:61
PDMAMEMORYMANAGER m_DmaManager
Definition: usb_request.cpp:68
#define OHCI_ENDPOINT_SET_MAX_PACKET_SIZE(s)
Definition: hardware.h:235
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define OHCI_ENDPOINT_SKIP
Definition: hardware.h:229
#define OHCI_ENDPOINT_LOW_SPEED
Definition: hardware.h:236
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
UCHAR GetEndpointAddress()
#define OHCI_ENDPOINT_SET_DEVICE_ADDRESS(s)
Definition: hardware.h:230
#define OHCI_ENDPOINT_SET_ENDPOINT_NUMBER(s)
Definition: hardware.h:233
#define USB_ENDPOINT_DIRECTION_OUT(x)
Definition: usb100.h:75
#define OHCI_ENDPOINT_FULL_SPEED
Definition: hardware.h:237
USHORT GetMaxPacketSize()
return STATUS_SUCCESS
Definition: btrfs.c:2938
LONGLONG QuadPart
Definition: typedefs.h:112
_In_ PSTORAGE_PROPERTY_ID _Outptr_ PSTORAGE_DESCRIPTOR_HEADER * Descriptor
Definition: classpnp.h:966

Referenced by BuildBulkInterruptEndpoint(), BuildControlTransferDescriptor(), and BuildIsochronousEndpoint().

◆ BuildBulkInterruptEndpoint()

NTSTATUS CUSBRequest::BuildBulkInterruptEndpoint ( POHCI_ENDPOINT_DESCRIPTOR OutEndpointDescriptor)

Definition at line 1245 of file usb_request.cpp.

1247 {
1248  POHCI_GENERAL_TD FirstDescriptor, LastDescriptor;
1249  POHCI_ENDPOINT_DESCRIPTOR EndpointDescriptor;
1250  NTSTATUS Status;
1251  PVOID Base;
1252  ULONG ChainDescriptorLength;
1253 
1254  //
1255  // sanity check
1256  //
1258 
1259  //
1260  // allocate endpoint descriptor
1261  //
1262  Status = AllocateEndpointDescriptor(&EndpointDescriptor);
1263  if (!NT_SUCCESS(Status))
1264  {
1265  //
1266  // failed to create setup descriptor
1267  //
1268  return Status;
1269  }
1270 
1272 
1273  if (m_Base == NULL)
1274  {
1275  //
1276  // get buffer
1277  //
1279  }
1280 
1281  //
1282  // Increase the size of last transfer, 0 in case this is the first
1283  //
1285 
1286  //
1287  // sanity checks
1288  //
1290  ASSERT(Base);
1291 
1292  //
1293  // use 2 * PAGE_SIZE at max for each new request
1294  //
1296  DPRINT("m_TransferBufferLength %lu m_TransferBufferLengthCompleted %lu DataToggle %x\n", m_TransferBufferLength, m_TransferBufferLengthCompleted, m_EndpointDescriptor->DataToggle);
1297 
1298  //
1299  // build bulk transfer descriptor chain
1300  //
1302  MaxTransferLength,
1304  &FirstDescriptor,
1305  &LastDescriptor,
1306  &ChainDescriptorLength);
1307  if (!NT_SUCCESS(Status))
1308  {
1309  //
1310  // failed to build transfer descriptor chain
1311  //
1312  m_DmaManager->Release(EndpointDescriptor, sizeof(OHCI_ENDPOINT_DESCRIPTOR));
1313  return Status;
1314  }
1315 
1316  //
1317  // move to next offset
1318  //
1319  m_TransferBufferLengthCompleted += ChainDescriptorLength;
1320 
1321  //
1322  // first descriptor has no carry bit
1323  //
1324  FirstDescriptor->Flags &= ~OHCI_TD_TOGGLE_CARRY;
1325 
1326  //
1327  // apply data toggle
1328  //
1330 
1331  //
1332  // clear interrupt mask for last transfer descriptor
1333  //
1334  LastDescriptor->Flags &= ~OHCI_TD_INTERRUPT_MASK;
1335 
1336 
1337  //
1338  // fire interrupt as soon transfer is finished
1339  //
1341 
1342  //
1343  // now link descriptor to endpoint
1344  //
1345  EndpointDescriptor->HeadPhysicalDescriptor = FirstDescriptor->PhysicalAddress.LowPart;
1346  EndpointDescriptor->TailPhysicalDescriptor = (FirstDescriptor == LastDescriptor ? 0 : LastDescriptor->PhysicalAddress.LowPart);
1347  EndpointDescriptor->HeadLogicalDescriptor = FirstDescriptor;
1348 
1349  //
1350  // dump descriptor list
1351  //
1352  //DumpEndpointDescriptor(EndpointDescriptor);
1353 
1354  //
1355  // store result
1356  //
1357  *OutEndpointDescriptor = EndpointDescriptor;
1358 
1359  //
1360  // done
1361  //
1362  return STATUS_SUCCESS;
1363 }
ULONG m_TransferBufferLength
Definition: usb_request.cpp:78
PUSB_ENDPOINT m_EndpointDescriptor
ULONG m_TransferBufferLengthCompleted
Definition: usb_request.cpp:83
NTSTATUS STDMETHODCALLTYPE BuildTransferDescriptorChain(IN PQUEUE_HEAD QueueHead, IN PVOID TransferBuffer, IN ULONG TransferBufferLength, IN UCHAR PidCode, IN UCHAR InitialDataToggle, OUT PQUEUE_TRANSFER_DESCRIPTOR *OutFirstDescriptor, OUT PQUEUE_TRANSFER_DESCRIPTOR *OutLastDescriptor, OUT PUCHAR OutDataToggle, OUT PULONG OutTransferBufferOffset)
LONG NTSTATUS
Definition: precomp.h:26
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2343
#define OHCI_TD_SET_DELAY_INTERRUPT(x)
Definition: hardware.h:281
#define OHCI_TD_INTERRUPT_IMMEDIATE
Definition: hardware.h:292
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)
uint32_t ULONG_PTR
Definition: typedefs.h:63
PHYSICAL_ADDRESS PhysicalAddress
Definition: hardware.h:268
#define OHCI_TD_INTERRUPT_MASK
Definition: hardware.h:282
smooth NULL
Definition: ftsmooth.c:416
UCHAR InternalGetPidDirection()
void DPRINT(...)
Definition: polytest.cpp:61
void * PVOID
Definition: retypes.h:9
PDMAMEMORYMANAGER m_DmaManager
Definition: usb_request.cpp:68
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define OHCI_TD_TOGGLE_1
Definition: hardware.h:285
ULONG LowPart
Definition: typedefs.h:104
#define PAGE_SIZE
Definition: env_spec_w32.h:49
PMDL m_TransferBufferMDL
Definition: usb_request.cpp:93
Status
Definition: gdiplustypes.h:24
#define OHCI_TD_TOGGLE_CARRY
Definition: hardware.h:283
#define min(a, b)
Definition: monoChain.cc:55
#define OHCI_TD_TOGGLE_0
Definition: hardware.h:284
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2938
NTSTATUS AllocateEndpointDescriptor(OUT POHCI_ENDPOINT_DESCRIPTOR *OutDescriptor)

◆ BuildBulkInterruptTransferDescriptor()

NTSTATUS CUSBRequest::BuildBulkInterruptTransferDescriptor ( IN PUHCI_QUEUE_HEAD OutQueueHead)

Definition at line 1010 of file usb_request.cpp.

1012 {
1013  NTSTATUS Status;
1014  PUHCI_QUEUE_HEAD QueueHead;
1015  PUHCI_TRANSFER_DESCRIPTOR FirstDescriptor, LastDescriptor;
1016  ULONG ChainDescriptorLength;
1018  PVOID Buffer;
1019  ULONG BufferSize;
1020 
1021  // create queue head
1022  Status = BuildQueueHead(&QueueHead);
1023  if (!NT_SUCCESS(Status))
1024  {
1025  // failed to allocate queue head
1026  DPRINT1("[UHCI] Failed to create queue head\n");
1027  return Status;
1028  }
1029 
1030  // get direction
1032 
1033  if (!m_Base)
1034  {
1035  // get buffer base
1037 
1038  // sanity check
1039  ASSERT(m_Base != NULL);
1040  }
1041 
1042  // get new buffer offset
1044 
1045  // FIXME determine buffer limit
1047 
1048  // create descriptor chain
1050  BufferSize,
1053  &FirstDescriptor,
1054  &LastDescriptor,
1055  &ChainDescriptorLength,
1056  NULL);
1057  if (!NT_SUCCESS(Status))
1058  {
1059  //
1060  // failed to allocate descriptor
1061  //
1062  DPRINT1("[UHCI] Failed to create descriptor chain\n");
1063  m_DmaManager->Release(QueueHead, sizeof(UHCI_QUEUE_HEAD));
1064  return Status;
1065  }
1066 
1067  // adjust buffer offset
1068  m_TransferBufferLengthCompleted += ChainDescriptorLength;
1069 
1070  // fire interrupt when the last descriptor is complete
1071  LastDescriptor->Status |= TD_CONTROL_IOC;
1072  LastDescriptor->LinkPhysical = TD_TERMINATE;
1073  LastDescriptor->NextLogicalDescriptor = NULL;
1074 
1075  // link queue head with first data descriptor descriptor
1076  QueueHead->NextElementDescriptor = (PVOID)FirstDescriptor;
1077  QueueHead->ElementPhysical = FirstDescriptor->PhysicalAddress;
1078 
1079  // store result
1080  *OutQueueHead = QueueHead;
1081  return STATUS_SUCCESS;
1082 }
ULONG m_TransferBufferLength
Definition: usb_request.cpp:78
PUSB_ENDPOINT m_EndpointDescriptor
ULONG m_TransferBufferLengthCompleted
Definition: usb_request.cpp:83
NTSTATUS STDMETHODCALLTYPE BuildTransferDescriptorChain(IN PQUEUE_HEAD QueueHead, IN PVOID TransferBuffer, IN ULONG TransferBufferLength, IN UCHAR PidCode, IN UCHAR InitialDataToggle, OUT PQUEUE_TRANSFER_DESCRIPTOR *OutFirstDescriptor, OUT PQUEUE_TRANSFER_DESCRIPTOR *OutLastDescriptor, OUT PUCHAR OutDataToggle, OUT PULONG OutTransferBufferOffset)
#define MmGetMdlVirtualAddress(_Mdl)
#define TD_TERMINATE
Definition: hardware.h:137
#define TD_CONTROL_IOC
Definition: hardware.h:109
LONG NTSTATUS
Definition: precomp.h:26
ULONG ElementPhysical
Definition: hardware.h:171
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define TD_TOKEN_IN
Definition: hardware.h:130
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
UCHAR InternalGetPidDirection()
Definition: bufpool.h:45
PVOID NextElementDescriptor
Definition: hardware.h:177
void * PVOID
Definition: retypes.h:9
PDMAMEMORYMANAGER m_DmaManager
Definition: usb_request.cpp:68
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_Inout_ PSIZE_T _In_opt_ PMDLX _In_ MM_ROTATE_DIRECTION Direction
Definition: mmfuncs.h:773
#define BufferSize
Definition: classpnp.h:419
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define PAGE_SIZE
Definition: env_spec_w32.h:49
PMDL m_TransferBufferMDL
Definition: usb_request.cpp:93
#define TD_TOKEN_OUT
Definition: hardware.h:131
Status
Definition: gdiplustypes.h:24
#define min(a, b)
Definition: monoChain.cc:55
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS BuildQueueHead(OUT PUHCI_QUEUE_HEAD *OutQueueHead)
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2938

◆ BuildBulkInterruptTransferQueueHead()

NTSTATUS CUSBRequest::BuildBulkInterruptTransferQueueHead ( PQUEUE_HEAD OutHead)

Definition at line 1118 of file usb_request.cpp.

1120 {
1121  NTSTATUS Status;
1122  PQUEUE_HEAD QueueHead;
1123  PVOID Base;
1124  ULONG ChainDescriptorLength;
1125  PQUEUE_TRANSFER_DESCRIPTOR FirstDescriptor, LastDescriptor;
1126 
1127  //
1128  // Allocate the queue head
1129  //
1130  Status = CreateQueueHead(&QueueHead);
1131  if (!NT_SUCCESS(Status))
1132  {
1133  //
1134  // failed to allocate queue head
1135  //
1136  DPRINT1("[EHCI] Failed to create queue head\n");
1137  return Status;
1138  }
1139 
1140  //
1141  // sanity checks
1142  //
1143  PC_ASSERT(QueueHead);
1145 
1146  if (!m_Base)
1147  {
1148  //
1149  // get virtual base of mdl
1150  //
1152  }
1153 
1154  //
1155  // Increase the size of last transfer, 0 in case this is the first
1156  //
1158 
1160  PC_ASSERT(Base);
1161 
1162  //
1163  // sanity check
1164  //
1166 
1167  //
1168  // use 4 * PAGE_SIZE at max for each new request
1169  //
1171 
1172  //
1173  // build bulk transfer descriptor chain
1174  //
1176  Base,
1177  MaxTransferLength,
1180  &FirstDescriptor,
1181  &LastDescriptor,
1183  &ChainDescriptorLength);
1184  if (!NT_SUCCESS(Status))
1185  {
1186  //
1187  // failed to build transfer descriptor chain
1188  //
1189  DPRINT1("[EHCI] Failed to create descriptor chain\n");
1190  m_DmaManager->Release(QueueHead, sizeof(QUEUE_HEAD));
1191  return Status;
1192  }
1193 
1194  //
1195  // move to next offset
1196  //
1197  m_TransferBufferLengthCompleted += ChainDescriptorLength;
1198 
1199  //
1200  // init queue head
1201  //
1205  QueueHead->NextPointer = FirstDescriptor->PhysicalAddr;
1206  QueueHead->CurrentLinkPointer = FirstDescriptor->PhysicalAddr;
1208 
1212  ASSERT(QueueHead->NextPointer);
1213 
1214  //
1215  // interrupt on last descriptor
1216  //
1217  LastDescriptor->Token.Bits.InterruptOnComplete = TRUE;
1218 
1219  //
1220  // store result
1221  //
1222  *OutHead = QueueHead;
1223 
1224  //
1225  // dump status
1226  //
1227  //DumpQueueHead(QueueHead);
1228 
1229  //
1230  // done
1231  //
1232  return STATUS_SUCCESS;
1233 }
ULONG m_TransferBufferLength
Definition: usb_request.cpp:78
PUSB_ENDPOINT m_EndpointDescriptor
ULONG m_TransferBufferLengthCompleted
Definition: usb_request.cpp:83
ULONG AlternateNextPointer
Definition: hardware.h:208
#define TRUE
Definition: types.h:120
#define PC_ASSERT(exp)
Definition: usbehci.h:17
NTSTATUS STDMETHODCALLTYPE BuildTransferDescriptorChain(IN PQUEUE_HEAD QueueHead, IN PVOID TransferBuffer, IN ULONG TransferBufferLength, IN UCHAR PidCode, IN UCHAR InitialDataToggle, OUT PQUEUE_TRANSFER_DESCRIPTOR *OutFirstDescriptor, OUT PQUEUE_TRANSFER_DESCRIPTOR *OutLastDescriptor, OUT PUCHAR OutDataToggle, OUT PULONG OutTransferBufferOffset)
ULONG NextPointer
Definition: hardware.h:206
END_POINT_CHARACTERISTICS EndPointCharacteristics
Definition: hardware.h:201
USB_ENDPOINT_DESCRIPTOR EndPointDescriptor
LONG NTSTATUS
Definition: precomp.h:26
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2343
UCHAR STDMETHODCALLTYPE GetDeviceAddress()
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)
uint32_t ULONG_PTR
Definition: typedefs.h:63
ULONG InterruptOnComplete
Definition: hardware.h:129
UCHAR InternalGetPidDirection()
void * PVOID
Definition: retypes.h:9
PDMAMEMORYMANAGER m_DmaManager
Definition: usb_request.cpp:68
union _QUEUE_TRANSFER_DESCRIPTOR::@1300 Token
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
NTSTATUS CreateQueueHead(PQUEUE_HEAD *OutQueueHead)
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define TERMINATE_POINTER
Definition: hardware.h:87
PMDL m_TransferBufferMDL
Definition: usb_request.cpp:93
Status
Definition: gdiplustypes.h:24
#define min(a, b)
Definition: monoChain.cc:55
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2938
ULONG CurrentLinkPointer
Definition: hardware.h:204
QETD_TOKEN_BITS Bits
Definition: hardware.h:144

◆ BuildControlTransferDescriptor() [1/2]

NTSTATUS CUSBRequest::BuildControlTransferDescriptor ( POHCI_ENDPOINT_DESCRIPTOR OutEndpointDescriptor)

Definition at line 1396 of file usb_request.cpp.

1398 {
1399  POHCI_GENERAL_TD SetupDescriptor, StatusDescriptor, DataDescriptor = NULL, LastDescriptor;
1400  POHCI_ENDPOINT_DESCRIPTOR EndpointDescriptor;
1401  NTSTATUS Status;
1402 
1403  //
1404  // allocate endpoint descriptor
1405  //
1406  Status = AllocateEndpointDescriptor(&EndpointDescriptor);
1407  if (!NT_SUCCESS(Status))
1408  {
1409  //
1410  // failed to create setup descriptor
1411  //
1412  return Status;
1413  }
1414 
1415  //
1416  // first allocate setup descriptor
1417  //
1419  if (!NT_SUCCESS(Status))
1420  {
1421  //
1422  // failed to create setup descriptor
1423  //
1424  m_DmaManager->Release(EndpointDescriptor, sizeof(OHCI_ENDPOINT_DESCRIPTOR));
1425  return Status;
1426  }
1427 
1428  //
1429  // now create the status descriptor
1430  //
1431  Status = CreateGeneralTransferDescriptor(&StatusDescriptor, 0);
1432  if (!NT_SUCCESS(Status))
1433  {
1434  //
1435  // failed to create status descriptor
1436  //
1437  FreeDescriptor(SetupDescriptor);
1438  m_DmaManager->Release(EndpointDescriptor, sizeof(OHCI_ENDPOINT_DESCRIPTOR));
1439  return Status;
1440  }
1441 
1442  //
1443  // finally create the last descriptor
1444  //
1445  Status = CreateGeneralTransferDescriptor(&LastDescriptor, 0);
1446  if (!NT_SUCCESS(Status))
1447  {
1448  //
1449  // failed to create status descriptor
1450  //
1451  FreeDescriptor(SetupDescriptor);
1452  FreeDescriptor(StatusDescriptor);
1453  m_DmaManager->Release(EndpointDescriptor, sizeof(OHCI_ENDPOINT_DESCRIPTOR));
1454  return Status;
1455  }
1456 
1457  //
1458  // initialize setup descriptor
1459  //
1461 
1462  //
1463  // initialize status descriptor
1464  //
1466 
1467  if (m_SetupPacket)
1468  {
1469  //
1470  // copy setup packet
1471  //
1473  }
1474  else
1475  {
1476  //
1477  // generate setup packet from urb
1478  //
1479  ASSERT(FALSE);
1480  }
1481 
1483  {
1484  //
1485  // FIXME: support more than one data descriptor
1486  //
1488 
1489  //
1490  // now create the data descriptor
1491  //
1492  Status = CreateGeneralTransferDescriptor(&DataDescriptor, 0);
1493  if (!NT_SUCCESS(Status))
1494  {
1495  //
1496  // failed to create status descriptor
1497  //
1498  m_DmaManager->Release(EndpointDescriptor, sizeof(OHCI_ENDPOINT_DESCRIPTOR));
1499  FreeDescriptor(SetupDescriptor);
1500  FreeDescriptor(StatusDescriptor);
1501  return Status;
1502  }
1503 
1504  //
1505  // initialize data descriptor
1506  //
1508 
1509  //
1510  // setup pid direction
1511  //
1513 
1514  //
1515  // use short packets
1516  //
1517  DataDescriptor->Flags |= OHCI_TD_BUFFER_ROUNDING;
1518 
1519  //
1520  // store physical address of buffer
1521  //
1523  DataDescriptor->LastPhysicalByteAddress = DataDescriptor->BufferPhysical + m_TransferBufferLength - 1;
1524 
1525  //
1526  // flip status pid direction
1527  //
1529 
1530  //
1531  // link setup descriptor to data descriptor
1532  //
1533  SetupDescriptor->NextPhysicalDescriptor = DataDescriptor->PhysicalAddress.LowPart;
1534  SetupDescriptor->NextLogicalDescriptor = DataDescriptor;
1535 
1536  //
1537  // link data descriptor to status descriptor
1538  // FIXME: check if there are more data descriptors
1539  //
1540  DataDescriptor->NextPhysicalDescriptor = StatusDescriptor->PhysicalAddress.LowPart;
1541  DataDescriptor->NextLogicalDescriptor = StatusDescriptor;
1542 
1543  //
1544  // link status descriptor to last descriptor
1545  //
1546  StatusDescriptor->NextPhysicalDescriptor = LastDescriptor->PhysicalAddress.LowPart;
1547  StatusDescriptor->NextLogicalDescriptor = LastDescriptor;
1548  }
1549  else
1550  {
1551  //
1552  // status descriptor is always in
1553  //
1554  StatusDescriptor->Flags |= OHCI_TD_DIRECTION_PID_IN;
1555 
1556  //
1557  // link setup descriptor to status descriptor
1558  //
1559  SetupDescriptor->NextPhysicalDescriptor = StatusDescriptor->PhysicalAddress.LowPart;
1560  SetupDescriptor->NextLogicalDescriptor = StatusDescriptor;
1561  //
1562  // link status descriptor to last descriptor
1563  //
1564  StatusDescriptor->NextPhysicalDescriptor = LastDescriptor->PhysicalAddress.LowPart;
1565  StatusDescriptor->NextLogicalDescriptor = LastDescriptor;
1566  }
1567 
1568  //
1569  // now link descriptor to endpoint
1570  //
1571  EndpointDescriptor->HeadPhysicalDescriptor = SetupDescriptor->PhysicalAddress.LowPart;
1572  EndpointDescriptor->TailPhysicalDescriptor = LastDescriptor->PhysicalAddress.LowPart;
1573  EndpointDescriptor->HeadLogicalDescriptor = SetupDescriptor;
1574 
1575  //
1576  // store result
1577  //
1578  *OutEndpointDescriptor = EndpointDescriptor;
1579 
1580  //
1581  // dump descriptor
1582  //
1583  //DumpEndpointDescriptor(EndpointDescriptor);
1584 
1585  //
1586  // done
1587  //
1588  return STATUS_SUCCESS;
1589 }
ULONG m_TransferBufferLength
Definition: usb_request.cpp:78
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
PVOID BufferLogical
Definition: hardware.h:271
#define OHCI_TD_DIRECTION_PID_SETUP
Definition: hardware.h:277
PVOID NextLogicalDescriptor
Definition: hardware.h:269
#define MmGetMdlVirtualAddress(_Mdl)
LONG NTSTATUS
Definition: precomp.h:26
#define OHCI_TD_SET_DELAY_INTERRUPT(x)
Definition: hardware.h:281
#define OHCI_TD_INTERRUPT_IMMEDIATE
Definition: hardware.h:292
PHYSICAL_ADDRESS PhysicalAddress
Definition: hardware.h:268
#define OHCI_TD_DIRECTION_PID_IN
Definition: hardware.h:279
#define OHCI_TD_SET_CONDITION_CODE(x)
Definition: hardware.h:289
smooth NULL
Definition: ftsmooth.c:416
UCHAR InternalGetPidDirection()
#define OHCI_TD_INTERRUPT_NONE
Definition: hardware.h:293
PDMAMEMORYMANAGER m_DmaManager
Definition: usb_request.cpp:68
ULONG BufferPhysical
Definition: hardware.h:264
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID FreeDescriptor(POHCI_GENERAL_TD Descriptor)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
PUSB_DEFAULT_PIPE_SETUP_PACKET m_SetupPacket
Definition: usb_request.cpp:98
#define OHCI_TD_TOGGLE_1
Definition: hardware.h:285
ULONG LowPart
Definition: typedefs.h:104
PMDL m_TransferBufferMDL
Definition: usb_request.cpp:93
Status
Definition: gdiplustypes.h:24
#define OHCI_TD_DIRECTION_PID_OUT
Definition: hardware.h:278
#define OHCI_TD_TOGGLE_CARRY
Definition: hardware.h:283
ULONG LastPhysicalByteAddress
Definition: hardware.h:266
#define OHCI_TD_TOGGLE_0
Definition: hardware.h:284
#define OHCI_TD_CONDITION_NOT_ACCESSED
Definition: hardware.h:307
#define OHCI_TD_BUFFER_ROUNDING
Definition: hardware.h:275
PHYSICAL_ADDRESS NTAPI MmGetPhysicalAddress(IN PVOID Address)
Definition: stubs.c:682
NTSTATUS CreateGeneralTransferDescriptor(POHCI_GENERAL_TD *OutDescriptor, ULONG BufferSize)
ULONG NextPhysicalDescriptor
Definition: hardware.h:265
return STATUS_SUCCESS
Definition: btrfs.c:2938
NTSTATUS AllocateEndpointDescriptor(OUT POHCI_ENDPOINT_DESCRIPTOR *OutDescriptor)

◆ BuildControlTransferDescriptor() [2/2]

NTSTATUS CUSBRequest::BuildControlTransferDescriptor ( IN PUHCI_QUEUE_HEAD OutQueueHead)

Definition at line 1086 of file usb_request.cpp.

1088 {
1089  PUHCI_TRANSFER_DESCRIPTOR SetupDescriptor, StatusDescriptor, FirstDescriptor, LastDescriptor;
1090  PUHCI_QUEUE_HEAD QueueHead;
1092  NTSTATUS Status;
1093  ULONG ChainDescriptorLength;
1094 
1095  //
1096  // create queue head
1097  //
1098  Status = BuildQueueHead(&QueueHead);
1099  if (!NT_SUCCESS(Status))
1100  {
1101  //
1102  // failed to allocate queue head
1103  //
1104  DPRINT1("[UHCI] Failed to create queue head\n");
1105  return Status;
1106  }
1107 
1108  //
1109  // get direction
1110  //
1112 
1113  //
1114  // build setup descriptor
1115  //
1116  Status = CreateDescriptor(&SetupDescriptor,
1119  if (!NT_SUCCESS(Status))
1120  {
1121  //
1122  // failed to allocate descriptor
1123  //
1124  DPRINT1("[UHCI] Failed to create setup descriptor\n");
1125  m_DmaManager->Release(QueueHead, sizeof(UHCI_QUEUE_HEAD));
1126  return Status;
1127  }
1128 
1129  //
1130  // build status descriptor
1131  //
1132  Status = CreateDescriptor(&StatusDescriptor,
1134  0);
1135  if (!NT_SUCCESS(Status))
1136  {
1137  //
1138  // failed to allocate descriptor
1139  //
1140  DPRINT1("[UHCI] Failed to create status descriptor\n");
1141  FreeDescriptor(SetupDescriptor);
1142  m_DmaManager->Release(QueueHead, sizeof(UHCI_QUEUE_HEAD));
1143  return Status;
1144  }
1145 
1146  if (m_SetupPacket)
1147  {
1148  //
1149  // copy setup packet
1150  //
1152  }
1153  else
1154  {
1155  //
1156  // generate setup packet from urb
1157  //
1158  ASSERT(FALSE);
1159  }
1160 
1161  //
1162  // init status descriptor
1163  //
1164  StatusDescriptor->Status |= TD_CONTROL_IOC;
1165  StatusDescriptor->Token |= TD_TOKEN_DATA1;
1166  StatusDescriptor->LinkPhysical = TD_TERMINATE;
1167  StatusDescriptor->NextLogicalDescriptor = NULL;
1168 
1170  {
1171  //
1172  // create descriptor chain
1173  //
1177  TRUE,
1178  &FirstDescriptor,
1179  &LastDescriptor,
1180  &ChainDescriptorLength,
1181  NULL);
1182  if (!NT_SUCCESS(Status))
1183  {
1184  //
1185  // failed to allocate descriptor
1186  //
1187  DPRINT1("[UHCI] Failed to create descriptor chain\n");
1188  FreeDescriptor(SetupDescriptor);
1189  FreeDescriptor(StatusDescriptor);
1190  m_DmaManager->Release(QueueHead, sizeof(UHCI_QUEUE_HEAD));
1191  return Status;
1192  }
1193 
1194  //
1195  // link setup descriptor to first data descriptor
1196  //
1197  SetupDescriptor->LinkPhysical = FirstDescriptor->PhysicalAddress | TD_DEPTH_FIRST;
1198  SetupDescriptor->NextLogicalDescriptor = (PVOID)FirstDescriptor;
1199 
1200  //
1201  // link last data descriptor to status descriptor
1202  //
1203  LastDescriptor->LinkPhysical = StatusDescriptor->PhysicalAddress | TD_DEPTH_FIRST;
1204  LastDescriptor->NextLogicalDescriptor = (PVOID)StatusDescriptor;
1205  }
1206  else
1207  {
1208  //
1209  // directly link setup to status descriptor
1210  //
1211  SetupDescriptor->LinkPhysical = StatusDescriptor->PhysicalAddress | TD_DEPTH_FIRST;
1212  SetupDescriptor->NextLogicalDescriptor = (PVOID)StatusDescriptor;
1213  }
1214 
1215  //
1216  // link queue head with setup descriptor
1217  //
1218  QueueHead->NextElementDescriptor = (PVOID)SetupDescriptor;
1219  QueueHead->ElementPhysical = SetupDescriptor->PhysicalAddress;
1220 
1221  //
1222  // store result
1223  //
1224  *OutQueueHead = QueueHead;
1225  return STATUS_SUCCESS;
1226 }
ULONG m_TransferBufferLength
Definition: usb_request.cpp:78
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define TD_TOKEN_DATA1
Definition: hardware.h:127
NTSTATUS STDMETHODCALLTYPE BuildTransferDescriptorChain(IN PQUEUE_HEAD QueueHead, IN PVOID TransferBuffer, IN ULONG TransferBufferLength, IN UCHAR PidCode, IN UCHAR InitialDataToggle, OUT PQUEUE_TRANSFER_DESCRIPTOR *OutFirstDescriptor, OUT PQUEUE_TRANSFER_DESCRIPTOR *OutLastDescriptor, OUT PUCHAR OutDataToggle, OUT PULONG OutTransferBufferOffset)
#define MmGetMdlVirtualAddress(_Mdl)
#define TD_TERMINATE
Definition: hardware.h:137
#define TD_CONTROL_IOC
Definition: hardware.h:109
LONG NTSTATUS
Definition: precomp.h:26
ULONG ElementPhysical
Definition: hardware.h:171
#define TD_TOKEN_IN
Definition: hardware.h:130
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
UCHAR InternalGetPidDirection()
PVOID NextElementDescriptor
Definition: hardware.h:177
void * PVOID
Definition: retypes.h:9
PDMAMEMORYMANAGER m_DmaManager
Definition: usb_request.cpp:68
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_Inout_ PSIZE_T _In_opt_ PMDLX _In_ MM_ROTATE_DIRECTION Direction
Definition: mmfuncs.h:773
NTSTATUS STDMETHODCALLTYPE CreateDescriptor(PQUEUE_TRANSFER_DESCRIPTOR *OutDescriptor)
VOID FreeDescriptor(POHCI_GENERAL_TD Descriptor)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
PUSB_DEFAULT_PIPE_SETUP_PACKET m_SetupPacket
Definition: usb_request.cpp:98
PMDL m_TransferBufferMDL
Definition: usb_request.cpp:93
#define TD_TOKEN_OUT
Definition: hardware.h:131
Status
Definition: gdiplustypes.h:24
#define TD_DEPTH_FIRST
Definition: hardware.h:136
#define DPRINT1
Definition: precomp.h:8
#define TD_TOKEN_SETUP
Definition: hardware.h:129
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS BuildQueueHead(OUT PUHCI_QUEUE_HEAD *OutQueueHead)
return STATUS_SUCCESS
Definition: btrfs.c:2938

◆ BuildControlTransferQueueHead()

NTSTATUS CUSBRequest::BuildControlTransferQueueHead ( PQUEUE_HEAD OutHead)

Definition at line 845 of file usb_request.cpp.

847 {
849  ULONG DescriptorChainLength;
850  PQUEUE_HEAD QueueHead;
851  PQUEUE_TRANSFER_DESCRIPTOR SetupDescriptor, StatusDescriptor, FirstDescriptor, LastDescriptor;
852 
853  //
854  // first allocate the queue head
855  //
856  Status = CreateQueueHead(&QueueHead);
857  if (!NT_SUCCESS(Status))
858  {
859  //
860  // failed to allocate queue head
861  //
862  DPRINT1("[EHCI] Failed to create queue head\n");
863  return Status;
864  }
865 
866  //
867  // sanity check
868  //
869  PC_ASSERT(QueueHead);
870 
871  //
872  // create setup packet
873  //
875  if (!NT_SUCCESS(Status))
876  {
877  // failed to create setup packet
878  DPRINT1("[EHCI] Failed to create setup packet\n");
879 
880  // release queue head
881  m_DmaManager->Release(QueueHead, sizeof(QUEUE_HEAD));
882  return Status;
883  }
884 
885  //
886  // create setup descriptor
887  //
888  Status = CreateDescriptor(&SetupDescriptor);
889  if (!NT_SUCCESS(Status))
890  {
891  // failed to create setup transfer descriptor
892  DPRINT1("[EHCI] Failed to create setup descriptor\n");
893 
894  if (m_DescriptorPacket)
895  {
896  // release packet descriptor
898  }
899 
900  // release queue head
901  m_DmaManager->Release(QueueHead, sizeof(QUEUE_HEAD));
902  return Status;
903  }
904 
905  //
906  // create status descriptor
907  //
908  Status = CreateDescriptor(&StatusDescriptor);
909  if (!NT_SUCCESS(Status))
910  {
911  // failed to create status transfer descriptor
912  DPRINT1("[EHCI] Failed to create status descriptor\n");
913 
914  // release setup transfer descriptor
915  m_DmaManager->Release(SetupDescriptor, sizeof(QUEUE_TRANSFER_DESCRIPTOR));
916 
917  if (m_DescriptorPacket)
918  {
919  // release packet descriptor
921  }
922 
923  // release queue head
924  m_DmaManager->Release(QueueHead, sizeof(QUEUE_HEAD));
925  return Status;
926  }
927 
928  //
929  // now initialize the queue head
930  //
932 
934 
935  //
936  // init setup descriptor
937  //
938  SetupDescriptor->Token.Bits.PIDCode = PID_CODE_SETUP_TOKEN;
940  SetupDescriptor->Token.Bits.DataToggle = FALSE;
941  SetupDescriptor->BufferPointer[0] = m_DescriptorSetupPacket.LowPart;
943  InsertTailList(&QueueHead->TransferDescriptorListHead, &SetupDescriptor->DescriptorEntry);
944 
945 
946  //
947  // init status descriptor
948  //
949  StatusDescriptor->Token.Bits.TotalBytesToTransfer = 0;
950  StatusDescriptor->Token.Bits.DataToggle = TRUE;
951  StatusDescriptor->Token.Bits.InterruptOnComplete = TRUE;
952 
953  //
954  // is there data
955  //
957  {
962  TRUE,
963  &FirstDescriptor,
964  &LastDescriptor,
965  NULL,
966  &DescriptorChainLength);
967  if (!NT_SUCCESS(Status))
968  {
969  // failed to create descriptor chain
970  DPRINT1("[EHCI] Failed to create descriptor chain\n");
971 
972  // release status transfer descriptor
973  m_DmaManager->Release(StatusDescriptor, sizeof(QUEUE_TRANSFER_DESCRIPTOR));
974 
975  // release setup transfer descriptor
976  m_DmaManager->Release(SetupDescriptor, sizeof(QUEUE_TRANSFER_DESCRIPTOR));
977 
978  if (m_DescriptorPacket)
979  {
980  // release packet descriptor
982  }
983 
984  // release queue head
985  m_DmaManager->Release(QueueHead, sizeof(QUEUE_HEAD));
986  return Status;
987  }
988 
989  if (m_TransferBufferLength != DescriptorChainLength)
990  {
991  DPRINT1("DescriptorChainLength %x\n", DescriptorChainLength);
992  DPRINT1("m_TransferBufferLength %x\n", m_TransferBufferLength);
993  ASSERT(FALSE);
994  }
995 
996  //
997  // now link the descriptors
998  //
999  SetupDescriptor->NextPointer = FirstDescriptor->PhysicalAddr;
1000  SetupDescriptor->AlternateNextPointer = FirstDescriptor->PhysicalAddr;
1001  LastDescriptor->NextPointer = StatusDescriptor->PhysicalAddr;
1002  LastDescriptor->AlternateNextPointer = StatusDescriptor->PhysicalAddr;
1003 
1004 
1005  //
1006  // pid code is flipped for ops with data stage
1007  //
1008  StatusDescriptor->Token.Bits.PIDCode = !InternalGetPidDirection();
1009  }
1010  else
1011  {
1012  //
1013  // direct link
1014  //
1015  SetupDescriptor->NextPointer = StatusDescriptor->PhysicalAddr;
1016  SetupDescriptor->AlternateNextPointer = StatusDescriptor->PhysicalAddr;
1017 
1018  //
1019  // retrieve result of operation
1020  //
1021  StatusDescriptor->Token.Bits.PIDCode = PID_CODE_IN_TOKEN;
1022  }
1023 
1024  //
1025  // insert status descriptor
1026  //
1027  InsertTailList(&QueueHead->TransferDescriptorListHead, &StatusDescriptor->DescriptorEntry);
1028 
1029 
1030  //
1031  // link transfer descriptors to queue head
1032  //
1033  QueueHead->NextPointer = SetupDescriptor->PhysicalAddr;
1034 
1035  //
1036  // store result
1037  //
1038  *OutHead = QueueHead;
1039 
1040  //
1041  // displays the current request
1042  //
1043  //DumpQueueHead(QueueHead);
1044 
1045  DPRINT("BuildControlTransferQueueHead done\n");
1046  //
1047  // done
1048  //
1049  return STATUS_SUCCESS;
1050 }
ULONG m_TransferBufferLength
Definition: usb_request.cpp:78
PUSB_ENDPOINT m_EndpointDescriptor
#define PID_CODE_IN_TOKEN
Definition: hardware.h:97
#define TRUE
Definition: types.h:120
#define PC_ASSERT(exp)
Definition: usbehci.h:17
NTSTATUS STDMETHODCALLTYPE BuildTransferDescriptorChain(IN PQUEUE_HEAD QueueHead, IN PVOID TransferBuffer, IN ULONG TransferBufferLength, IN UCHAR PidCode, IN UCHAR InitialDataToggle, OUT PQUEUE_TRANSFER_DESCRIPTOR *OutFirstDescriptor, OUT PQUEUE_TRANSFER_DESCRIPTOR *OutLastDescriptor, OUT PUCHAR OutDataToggle, OUT PULONG OutTransferBufferOffset)
#define MmGetMdlVirtualAddress(_Mdl)
ULONG NextPointer
Definition: hardware.h:206
END_POINT_CHARACTERISTICS EndPointCharacteristics
Definition: hardware.h:201
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS BuildSetupPacket()
UCHAR STDMETHODCALLTYPE GetDeviceAddress()
#define InsertTailList(ListHead, Entry)
LIST_ENTRY DescriptorEntry
Definition: hardware.h:152
ULONG InterruptOnComplete
Definition: hardware.h:129
PHYSICAL_ADDRESS m_DescriptorSetupPacket
smooth NULL
Definition: ftsmooth.c:416
UCHAR InternalGetPidDirection()
void DPRINT(...)
Definition: polytest.cpp:61
PDMAMEMORYMANAGER m_DmaManager
Definition: usb_request.cpp:68
LIST_ENTRY TransferDescriptorListHead
Definition: hardware.h:221
PUSB_DEFAULT_PIPE_SETUP_PACKET m_DescriptorPacket
ULONG ExtendedBufferPointer[5]
Definition: hardware.h:148
ULONG TotalBytesToTransfer
Definition: hardware.h:130
union _QUEUE_TRANSFER_DESCRIPTOR::@1300 Token
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS STDMETHODCALLTYPE CreateDescriptor(PQUEUE_TRANSFER_DESCRIPTOR *OutDescriptor)
struct _USB_DEFAULT_PIPE_SETUP_PACKET USB_DEFAULT_PIPE_SETUP_PACKET
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
NTSTATUS CreateQueueHead(PQUEUE_HEAD *OutQueueHead)
#define PID_CODE_SETUP_TOKEN
Definition: hardware.h:98
ULONG LowPart
Definition: typedefs.h:104
ULONG DataToggle
Definition: hardware.h:131
PMDL m_TransferBufferMDL
Definition: usb_request.cpp:93
Status
Definition: gdiplustypes.h:24
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2938
QETD_TOKEN_BITS Bits
Definition: hardware.h:144

◆ BuildIsochronousEndpoint()

NTSTATUS CUSBRequest::BuildIsochronousEndpoint ( POHCI_ENDPOINT_DESCRIPTOR OutEndpointDescriptor)

Definition at line 708 of file usb_request.cpp.

710 {
711  POHCI_ISO_TD FirstDescriptor = NULL, PreviousDescriptor = NULL, CurrentDescriptor = NULL;
712  POHCI_ENDPOINT_DESCRIPTOR EndpointDescriptor;
713  ULONG Index = 0, SubIndex, NumberOfPackets, PageOffset, Page;
715  PVOID Buffer;
716  PIO_STACK_LOCATION IoStack;
717  PURB Urb;
719 
720  //
721  // get current irp stack location
722  //
724 
725  //
726  // sanity check
727  //
729  PC_ASSERT(IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_INTERNAL_USB_SUBMIT_URB);
730  PC_ASSERT(IoStack->Parameters.Others.Argument1 != 0);
731 
732  //
733  // get urb
734  //
735  Urb = (PURB)IoStack->Parameters.Others.Argument1;
736  ASSERT(Urb);
737 
738  //
739  // allocate endpoint descriptor
740  //
741  Status = AllocateEndpointDescriptor(&EndpointDescriptor);
742  if (!NT_SUCCESS(Status))
743  {
744  //
745  // failed to create setup descriptor
746  //
747  ASSERT(FALSE);
748  return Status;
749  }
750 
751  //
752  // get buffer
753  //
755  ASSERT(Buffer);
756 
757  //
758  // FIXME: support requests which spans several pages
759  //
761 
764 
765 
766  while(Index < Urb->UrbIsochronousTransfer.NumberOfPackets)
767  {
768  //
769  // get number of packets remaining
770  //
772  //
773  // allocate iso descriptor
774  //
776  if (!NT_SUCCESS(Status))
777  {
778  //
779  // FIXME: cleanup
780  // failed to allocate descriptor
781  //
782  ASSERT(FALSE);
783  return Status;
784  }
785 
786  //
787  // get physical page (HACK)
788  //
789  *(volatile char *)Buffer;
791 
792  //
793  // get page offset
794  //
795  PageOffset = BYTE_OFFSET(Page);
796 
797  //
798  // initialize descriptor
799  //
800  CurrentDescriptor->BufferPhysical = Page - PageOffset;
801 
802  for(SubIndex = 0; SubIndex < NumberOfPackets; SubIndex++)
803  {
804  //
805  // store buffer offset
806  //
807  CurrentDescriptor->Offset[SubIndex] = Urb->UrbIsochronousTransfer.IsoPacket[Index+SubIndex].Offset + PageOffset;
808  DPRINT("Index %lu PacketOffset %lu FinalOffset %lu\n", SubIndex+Index, Urb->UrbIsochronousTransfer.IsoPacket[Index+SubIndex].Offset, CurrentDescriptor->Offset[SubIndex]);
809  }
810 
811  //
812  // increment packet offset
813  //
815 
816  //
817  // check if this is the last descriptor
818  //
819  if (Index == Urb->UrbIsochronousTransfer.NumberOfPackets)
820  {
821  //
822  // end of transfer
823  //
824  CurrentDescriptor->LastPhysicalByteAddress = CurrentDescriptor->BufferPhysical + PageOffset + m_TransferBufferLength - 1;
825  }
826  else
827  {
828  //
829  // use start address of next packet - 1
830  //
831  CurrentDescriptor->LastPhysicalByteAddress = CurrentDescriptor->BufferPhysical + PageOffset + Urb->UrbIsochronousTransfer.IsoPacket[Index].Offset - 1;
832  }
833 
834  //
835  // is there a previous descriptor
836  //
837  if (PreviousDescriptor)
838  {
839  //
840  // link descriptors
841  //
842  PreviousDescriptor->NextLogicalDescriptor = CurrentDescriptor;
843  PreviousDescriptor->NextPhysicalDescriptor = CurrentDescriptor->PhysicalAddress.LowPart;
844  }
845  else
846  {
847  //
848  // first descriptor
849  //
850  FirstDescriptor = CurrentDescriptor;
851  }
852 
853  //
854  // store as previous descriptor
855  //
856  PreviousDescriptor = CurrentDescriptor;
857  DPRINT("Current Descriptor %p Logical %lx StartAddress %x EndAddress %x\n", CurrentDescriptor, CurrentDescriptor->PhysicalAddress.LowPart, CurrentDescriptor->BufferPhysical, CurrentDescriptor->LastPhysicalByteAddress);
858 
859  //
860  // fire interrupt as soon transfer is finished
861  //
862  CurrentDescriptor->Flags |= OHCI_TD_SET_DELAY_INTERRUPT(OHCI_TD_INTERRUPT_IMMEDIATE);
863  }
864 
865  //
866  // clear interrupt mask for last transfer descriptor
867  //
868  CurrentDescriptor->Flags &= ~OHCI_TD_INTERRUPT_MASK;
869 
870  //
871  // fire interrupt as soon transfer is finished
872  //
873  CurrentDescriptor->Flags |= OHCI_TD_SET_DELAY_INTERRUPT(OHCI_TD_INTERRUPT_IMMEDIATE);
874 
875  //
876  // set isochronous type
877  //
878  EndpointDescriptor->Flags |= OHCI_ENDPOINT_ISOCHRONOUS_FORMAT;
879 
880  //
881  // now link descriptor to endpoint
882  //
883  EndpointDescriptor->HeadPhysicalDescriptor = FirstDescriptor->PhysicalAddress.LowPart;
884  EndpointDescriptor->TailPhysicalDescriptor = CurrentDescriptor->PhysicalAddress.LowPart;
885  EndpointDescriptor->HeadLogicalDescriptor = FirstDescriptor;
886 
887  //
888  // store result
889  //
890  *OutEndpointDescriptor = EndpointDescriptor;
891 
892  //
893  // done
894  //
895  return STATUS_SUCCESS;
896 }
_In_ PPNDIS_PACKET _In_ UINT NumberOfPackets
Definition: ndis.h:5120
ULONG m_TransferBufferLength
Definition: usb_request.cpp:78
#define OHCI_ITD_NOFFSET
Definition: hardware.h:313
#define PC_ASSERT(exp)
Definition: usbehci.h:17
#define IOCTL_INTERNAL_USB_SUBMIT_URB
Definition: usbioctl.h:32
#define MmGetMdlVirtualAddress(_Mdl)
NTSTATUS CreateIsochronousTransferDescriptor(OUT POHCI_ISO_TD *OutDescriptor, ULONG FrameCount)
LONG NTSTATUS
Definition: precomp.h:26
#define OHCI_TD_SET_DELAY_INTERRUPT(x)
Definition: hardware.h:281
#define OHCI_TD_INTERRUPT_IMMEDIATE
Definition: hardware.h:292
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)
#define OHCI_TD_INTERRUPT_MASK
Definition: hardware.h:282
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
PDMAMEMORYMANAGER m_DmaManager
Definition: usb_request.cpp:68
#define ADDRESS_AND_SIZE_TO_SPAN_PAGES(_Va, _Size)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const UCHAR Index[8]
Definition: usbohci.c:18
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
ULONG LowPart
Definition: typedefs.h:104
struct _URB * PURB
PMDL m_TransferBufferMDL
Definition: usb_request.cpp:93
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
struct _URB_ISOCH_TRANSFER UrbIsochronousTransfer
Definition: usb.h:544
Definition: usb.h:529
#define OHCI_ENDPOINT_ISOCHRONOUS_FORMAT
Definition: hardware.h:241
#define MmGetMdlByteCount(_Mdl)
#define min(a, b)
Definition: monoChain.cc:55
unsigned int ULONG
Definition: retypes.h:1
PHYSICAL_ADDRESS NTAPI MmGetPhysicalAddress(IN PVOID Address)
Definition: stubs.c:682
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2938
PHYSICAL_ADDRESS PhysicalAddress
Definition: hardware.h:326
#define BYTE_OFFSET(Va)
NTSTATUS AllocateEndpointDescriptor(OUT POHCI_ENDPOINT_DESCRIPTOR *OutDescriptor)

◆ BuildQueueHead()

NTSTATUS CUSBRequest::BuildQueueHead ( OUT PUHCI_QUEUE_HEAD OutQueueHead)

Definition at line 958 of file usb_request.cpp.

960 {
961  PUHCI_QUEUE_HEAD QueueHead;
964 
965  //
966  // allocate queue head
967  //
968  Status = m_DmaManager->Allocate(sizeof(UHCI_QUEUE_HEAD), (PVOID*)&QueueHead, &Address);
969  if (!NT_SUCCESS(Status))
970  {
971  //
972  // failed to allocate queue head
973  //
974  DPRINT1("[UHCI] Failed to create queue head\n");
975  return Status;
976  }
977 
978  //
979  // store address
980  //
981  QueueHead->PhysicalAddress = Address.LowPart;
982  QueueHead->ElementPhysical = Address.LowPart;
983 
984  //
985  // store result
986  //
987  *OutQueueHead = QueueHead;
988  return STATUS_SUCCESS;
989 }
LONG NTSTATUS
Definition: precomp.h:26
static WCHAR Address[46]
Definition: ping.c:68
PDMAMEMORYMANAGER m_DmaManager
Definition: usb_request.cpp:68
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
#define DPRINT1
Definition: precomp.h:8
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by BuildBulkInterruptTransferDescriptor(), and BuildControlTransferDescriptor().

◆ BuildSetupPacket() [1/3]

NTSTATUS CUSBRequest::BuildSetupPacket ( )

◆ BuildSetupPacket() [2/3]

NTSTATUS CUSBRequest::BuildSetupPacket ( )

◆ BuildSetupPacket() [3/3]

NTSTATUS CUSBRequest::BuildSetupPacket ( )

Definition at line 1402 of file usb_request.cpp.

1403 {
1404  NTSTATUS Status;
1405 
1406  //
1407  // allocate common buffer setup packet
1408  //
1410  if (!NT_SUCCESS(Status))
1411  {
1412  //
1413  // no memory
1414  //
1415  return Status;
1416  }
1417 
1418  if (m_SetupPacket)
1419  {
1420  //
1421  // copy setup packet
1422  //
1424  }
1425  else
1426  {
1427  //
1428  // build setup packet from urb
1429  //
1431  }
1432 
1433  //
1434  // done
1435  //
1436  return Status;
1437 }
NTSTATUS BuildSetupPacketFromURB()
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
LONG NTSTATUS
Definition: precomp.h:26
PHYSICAL_ADDRESS m_DescriptorSetupPacket
PDMAMEMORYMANAGER m_DmaManager
Definition: usb_request.cpp:68
PUSB_DEFAULT_PIPE_SETUP_PACKET m_DescriptorPacket
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PUSB_DEFAULT_PIPE_SETUP_PACKET m_SetupPacket
Definition: usb_request.cpp:98
Status
Definition: gdiplustypes.h:24

Referenced by BuildControlTransferQueueHead().

◆ BuildSetupPacketFromURB() [1/3]

NTSTATUS CUSBRequest::BuildSetupPacketFromURB ( )

◆ BuildSetupPacketFromURB() [2/3]

NTSTATUS CUSBRequest::BuildSetupPacketFromURB ( )

◆ BuildSetupPacketFromURB() [3/3]

NTSTATUS CUSBRequest::BuildSetupPacketFromURB ( )

Definition at line 1441 of file usb_request.cpp.

1442 {
1443  PIO_STACK_LOCATION IoStack;
1444  PURB Urb;
1446 
1447  //
1448  // sanity checks
1449  //
1450  PC_ASSERT(m_Irp);
1452 
1453  //
1454  // get stack location
1455  //
1457 
1458  //
1459  // get urb
1460  //
1461  Urb = (PURB)IoStack->Parameters.Others.Argument1;
1462 
1463  //
1464  // zero descriptor packet
1465  //
1467 
1468 
1469  switch (Urb->UrbHeader.Function)
1470  {
1471  /* CLEAR FEATURE */
1475  UNIMPLEMENTED;
1476  break;
1477 
1478  /* GET CONFIG */
1483  break;
1484 
1485  /* GET DESCRIPTOR */
1491  m_DescriptorPacket->wLength = (USHORT)Urb->UrbControlDescriptorRequest.TransferBufferLength;
1493  break;
1494 
1495  /* GET INTERFACE */
1501  break;
1502 
1503  /* GET STATUS */
1506  ASSERT(Urb->UrbControlGetStatusRequest.Index == 0);
1510  break;
1511 
1514  ASSERT(Urb->UrbControlGetStatusRequest.Index != 0);
1518  break;
1519 
1522  ASSERT(Urb->UrbControlGetStatusRequest.Index != 0);
1526  break;
1527 
1528  /* SET ADDRESS */
1529 
1530  /* SET CONFIG */
1533  m_DescriptorPacket->wValue.W = Urb->UrbSelectConfiguration.ConfigurationDescriptor->bConfigurationValue;
1537  break;
1538 
1539  /* SET DESCRIPTOR */
1543  UNIMPLEMENTED;
1544  break;
1545 
1546  /* SET FEATURE */
1549  ASSERT(Urb->UrbControlGetStatusRequest.Index == 0);
1552  break;
1553 
1556  ASSERT(Urb->UrbControlGetStatusRequest.Index == 0);
1559  break;
1560 
1563  ASSERT(Urb->UrbControlGetStatusRequest.Index == 0);
1566  break;
1567 
1568  /* SET INTERFACE*/
1571  m_DescriptorPacket->wValue.W = Urb->UrbSelectInterface.Interface.AlternateSetting;
1572  m_DescriptorPacket->wIndex.W = Urb->UrbSelectInterface.Interface.InterfaceNumber;
1575  break;
1576 
1577  /* SYNC FRAME */
1579  UNIMPLEMENTED;
1580  break;
1581  default:
1582  UNIMPLEMENTED;
1583  break;
1584  }
1585 
1586  return Status;
1587 }
#define PC_ASSERT(exp)
Definition: usbehci.h:17
#define URB_FUNCTION_CLEAR_FEATURE_TO_INTERFACE
Definition: usb.h:103
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define USB_REQUEST_SET_INTERFACE
Definition: usb100.h:87
union _USB_DEFAULT_PIPE_SETUP_PACKET::_wIndex wIndex
LONG NTSTATUS
Definition: precomp.h:26
#define USB_REQUEST_GET_CONFIGURATION
Definition: usb100.h:84
#define URB_FUNCTION_CLEAR_FEATURE_TO_ENDPOINT
Definition: usb.h:104
#define URB_FUNCTION_GET_INTERFACE
Definition: usb.h:125
#define URB_FUNCTION_SET_FEATURE_TO_ENDPOINT
Definition: usb.h:101
#define URB_FUNCTION_SET_DESCRIPTOR_TO_INTERFACE
Definition: usb.h:127
#define URB_FUNCTION_SET_FEATURE_TO_DEVICE
Definition: usb.h:99
#define URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL
Definition: usb.h:116
#define URB_FUNCTION_GET_STATUS_FROM_INTERFACE
Definition: usb.h:106
#define USB_REQUEST_SET_CONFIGURATION
Definition: usb100.h:85
PUSB_DEFAULT_PIPE_SETUP_PACKET m_DescriptorPacket
struct _URB_HEADER UrbHeader
Definition: usb.h:531
#define URB_FUNCTION_GET_STATUS_FROM_ENDPOINT
Definition: usb.h:107
#define URB_FUNCTION_GET_CONFIGURATION
Definition: usb.h:124
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define USB_REQUEST_GET_DESCRIPTOR
Definition: usb100.h:82
#define URB_FUNCTION_SELECT_CONFIGURATION
Definition: usb.h:86
#define URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE
Definition: usb.h:97
#define URB_FUNCTION_SELECT_INTERFACE
Definition: usb.h:87
struct _URB * PURB
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
struct _URB_SELECT_CONFIGURATION UrbSelectConfiguration
Definition: usb.h:533
#define USB_REQUEST_GET_STATUS
Definition: usb100.h:78
#define URB_FUNCTION_SET_FEATURE_TO_INTERFACE
Definition: usb.h:100
Definition: usb.h:529
unsigned short USHORT
Definition: pedump.c:61
#define URB_FUNCTION_SET_DESCRIPTOR_TO_ENDPOINT
Definition: usb.h:123
#define USB_REQUEST_SET_FEATURE
Definition: usb100.h:80
#define URB_FUNCTION_GET_STATUS_FROM_DEVICE
Definition: usb.h:105
union _USB_DEFAULT_PIPE_SETUP_PACKET::_wValue wValue
#define URB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE
Definition: usb.h:98
#define UNIMPLEMENTED
Definition: debug.h:114
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
struct _URB_CONTROL_DESCRIPTOR_REQUEST UrbControlDescriptorRequest
Definition: usb.h:545
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
#define URB_FUNCTION_CLEAR_FEATURE_TO_DEVICE
Definition: usb.h:102
BM_REQUEST_TYPE bmRequestType
Definition: usb200.h:72
struct _URB_CONTROL_GET_STATUS_REQUEST UrbControlGetStatusRequest
Definition: usb.h:546
struct _URB_SELECT_INTERFACE UrbSelectInterface
Definition: usb.h:532

Referenced by BuildSetupPacket().

◆ BuildTransferDescriptorChain() [1/3]

NTSTATUS STDMETHODCALLTYPE CUSBRequest::BuildTransferDescriptorChain ( IN PQUEUE_HEAD  QueueHead,
IN PVOID  TransferBuffer,
IN ULONG  TransferBufferLength,
IN UCHAR  PidCode,
IN UCHAR  InitialDataToggle,
OUT PQUEUE_TRANSFER_DESCRIPTOR OutFirstDescriptor,
OUT PQUEUE_TRANSFER_DESCRIPTOR OutLastDescriptor,
OUT PUCHAR  OutDataToggle,
OUT PULONG  OutTransferBufferOffset 
)

Definition at line 698 of file usb_request.cpp.

708 {
709  PQUEUE_TRANSFER_DESCRIPTOR FirstDescriptor = NULL, CurrentDescriptor, LastDescriptor = NULL;
711  ULONG DescriptorLength, TransferBufferOffset = 0;
712  ULONG MaxPacketSize = 0, TransferSize;
713 
714  //
715  // is there an endpoint descriptor
716  //
718  {
719  //
720  // use endpoint packet size
721  //
723  }
724 
725  do
726  {
727  //
728  // allocate transfer descriptor
729  //
730  Status = CreateDescriptor(&CurrentDescriptor);
731  if (!NT_SUCCESS(Status))
732  {
733  //
734  // failed to allocate transfer descriptor
735  //
737  }
738 
739  if (MaxPacketSize)
740  {
741  //
742  // transfer size is minimum available buffer or endpoint size
743  //
744  TransferSize = min(TransferBufferLength - TransferBufferOffset, MaxPacketSize);
745  }
746  else
747  {
748  //
749  // use available buffer
750  //
751  TransferSize = TransferBufferLength - TransferBufferOffset;
752  }
753 
754  //
755  // now init the descriptor
756  //
757  InitDescriptor(CurrentDescriptor,
758  (PVOID)((ULONG_PTR)TransferBuffer + TransferBufferOffset),
759  TransferSize,
760  PidCode,
761  InitialDataToggle,
762  &DescriptorLength);
763 
764  //
765  // insert into queue head
766  //
767  InsertTailList(&QueueHead->TransferDescriptorListHead, &CurrentDescriptor->DescriptorEntry);
768 
769  //
770  // adjust offset
771  //
772  TransferBufferOffset += DescriptorLength;
773 
774  if (LastDescriptor)
775  {
776  //
777  // link to current descriptor
778  //
779  LastDescriptor->NextPointer = CurrentDescriptor->PhysicalAddr;
780  LastDescriptor = CurrentDescriptor;
781  }
782  else
783  {
784  //
785  // first descriptor in chain
786  //
787  LastDescriptor = FirstDescriptor = CurrentDescriptor;
788  }
789 
790  //
791  // flip data toggle
792  //
793  InitialDataToggle = !InitialDataToggle;
794 
795  if(TransferBufferLength == TransferBufferOffset)
796  {
797  //
798  // end reached
799  //
800  break;
801  }
802 
803  }while(TRUE);
804 
805  if (OutFirstDescriptor)
806  {
807  //
808  // store first descriptor
809  //
810  *OutFirstDescriptor = FirstDescriptor;
811  }
812 
813  if (OutLastDescriptor)
814  {
815  //
816  // store last descriptor
817  //
818  *OutLastDescriptor = CurrentDescriptor;
819  }
820 
821  if (OutDataToggle)
822  {
823  //
824  // store result data toggle
825  //
826  *OutDataToggle = InitialDataToggle;
827  }
828 
829  if (OutTransferBufferOffset)
830  {
831  //
832  // store offset
833  //
834  *OutTransferBufferOffset = TransferBufferOffset;
835  }
836 
837  //
838  // done
839  //
840  return STATUS_SUCCESS;
841 }
PUSB_ENDPOINT m_EndpointDescriptor
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
VOID STDMETHODCALLTYPE InitDescriptor(IN PQUEUE_TRANSFER_DESCRIPTOR CurrentDescriptor, IN PVOID TransferBuffer, IN ULONG TransferBufferLength, IN UCHAR PidCode, IN UCHAR DataToggle, OUT PULONG OutDescriptorLength)
USB_ENDPOINT_DESCRIPTOR EndPointDescriptor
LONG NTSTATUS
Definition: precomp.h:26
#define InsertTailList(ListHead, Entry)
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS STDMETHODCALLTYPE CreateDescriptor(PQUEUE_TRANSFER_DESCRIPTOR *OutDescriptor)
Status
Definition: gdiplustypes.h:24
#define min(a, b)
Definition: monoChain.cc:55
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by BuildBulkInterruptEndpoint(), BuildBulkInterruptTransferDescriptor(), BuildBulkInterruptTransferQueueHead(), BuildControlTransferDescriptor(), and BuildControlTransferQueueHead().

◆ BuildTransferDescriptorChain() [2/3]

NTSTATUS CUSBRequest::BuildTransferDescriptorChain ( IN PVOID  TransferBuffer,
IN ULONG  TransferBufferLength,
IN UCHAR  PidCode,
IN UCHAR  InitialDataToggle,
OUT PUHCI_TRANSFER_DESCRIPTOR OutFirstDescriptor,
OUT PUHCI_TRANSFER_DESCRIPTOR OutLastDescriptor,
OUT PULONG  OutTransferBufferOffset,
OUT PUCHAR  OutDataToggle 
)

Definition at line 807 of file usb_request.cpp.

816 {
817  PUHCI_TRANSFER_DESCRIPTOR FirstDescriptor = NULL, CurrentDescriptor, LastDescriptor = NULL;
818  ULONG TransferBufferOffset = 0;
820  ULONG MaxPacketSize, CurrentBufferSize;
821 
822  //
823  // FIXME FIXME FIXME FIXME FIXME
824  //
825  if (GetDeviceSpeed() == UsbLowSpeed)
826  {
827  //
828  // low speed use max 8 bytes
829  //
830  MaxPacketSize = 8;
831  }
832  else
833  {
835  {
836  //
837  // use endpoint size
838  //
840  }
841  else
842  {
843  //
844  // use max 64 bytes
845  //
846  MaxPacketSize = 64;
847  }
848  }
849 
850  do
851  {
852  //
853  // determine current packet size
854  //
855  CurrentBufferSize = min(MaxPacketSize, TransferBufferLength - TransferBufferOffset);
856 
857  //
858  // allocate descriptor
859  //
860  Status = CreateDescriptor(&CurrentDescriptor, PidCode, CurrentBufferSize);
861  if (!NT_SUCCESS(Status))
862  {
863  //
864  // failed to allocate queue head
865  //
866  DPRINT1("[UHCI] Failed to create descriptor\n");
867  ASSERT(FALSE);
868  return Status;
869  }
870 
871  if (PidCode == TD_TOKEN_OUT)
872  {
873  //
874  // copy buffer
875  //
876  RtlCopyMemory(CurrentDescriptor->BufferLogical, (PVOID)((ULONG_PTR)TransferBuffer + TransferBufferOffset), CurrentBufferSize);
877  }
878  else
879  {
880  //
881  // store user buffer
882  //
883  CurrentDescriptor->UserBuffer = (PVOID)((ULONG_PTR)TransferBuffer + TransferBufferOffset);
884  }
885 
886  if (!FirstDescriptor)
887  {
888  //
889  // first descriptor
890  //
891  FirstDescriptor = CurrentDescriptor;
892  }
893  else
894  {
895  //
896  // link descriptor
897  //
898  LastDescriptor->LinkPhysical = CurrentDescriptor->PhysicalAddress | TD_DEPTH_FIRST;
899  LastDescriptor->NextLogicalDescriptor = (PVOID)CurrentDescriptor;
900  }
901 
902  if (InitialDataToggle)
903  {
904  //
905  // apply data toggle
906  //
907  CurrentDescriptor->Token |= TD_TOKEN_DATA1;
908  }
909 
910  //
911  // re-run
912  //
913  LastDescriptor = CurrentDescriptor;
914  TransferBufferOffset += CurrentBufferSize;
915  InitialDataToggle = !InitialDataToggle;
916 
917  }while(TransferBufferOffset < TransferBufferLength);
918 
919  if (OutTransferBufferOffset)
920  {
921  //
922  // store transfer buffer length
923  //
924  *OutTransferBufferOffset = TransferBufferOffset;
925  }
926 
927  if (OutFirstDescriptor)
928  {
929  //
930  // store first descriptor
931  //
932  *OutFirstDescriptor = FirstDescriptor;
933  }
934 
935  if (OutLastDescriptor)
936  {
937  //
938  // store last descriptor
939  //
940  *OutLastDescriptor = CurrentDescriptor;
941  }
942 
943  if (OutDataToggle)
944  {
945  //
946  // store data toggle
947  //
948  *OutDataToggle = InitialDataToggle;
949  }
950 
951  //
952  // done
953  //
954  return STATUS_SUCCESS;
955 }
PUSB_ENDPOINT m_EndpointDescriptor
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define TD_TOKEN_DATA1
Definition: hardware.h:127
USB_ENDPOINT_DESCRIPTOR EndPointDescriptor
LONG NTSTATUS
Definition: precomp.h:26
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS STDMETHODCALLTYPE CreateDescriptor(PQUEUE_TRANSFER_DESCRIPTOR *OutDescriptor)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define TD_TOKEN_OUT
Definition: hardware.h:131
Status
Definition: gdiplustypes.h:24
#define TD_DEPTH_FIRST
Definition: hardware.h:136
#define min(a, b)
Definition: monoChain.cc:55
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2938

◆ BuildTransferDescriptorChain() [3/3]

NTSTATUS CUSBRequest::BuildTransferDescriptorChain ( IN PVOID  TransferBuffer,
IN ULONG  TransferBufferLength,
IN UCHAR  PidCode,
OUT POHCI_GENERAL_TD OutFirstDescriptor,
OUT POHCI_GENERAL_TD OutLastDescriptor,
OUT PULONG  OutTransferBufferOffset 
)

Definition at line 1113 of file usb_request.cpp.

1120 {
1121  POHCI_GENERAL_TD FirstDescriptor = NULL, CurrentDescriptor, LastDescriptor = NULL;
1122  NTSTATUS Status;
1123  ULONG MaxLengthInPage, TransferBufferOffset = 0;
1124  ULONG MaxPacketSize = 0, TransferSize, CurrentSize;
1125 
1126  //
1127  // for now use one page as maximum size
1128  //
1129  MaxPacketSize = PAGE_SIZE;
1130 
1131  do
1132  {
1133  //
1134  // allocate transfer descriptor
1135  //
1136  Status = CreateGeneralTransferDescriptor(&CurrentDescriptor, 0);
1137  if (!NT_SUCCESS(Status))
1138  {
1139  //
1140  // failed to allocate transfer descriptor
1141  //
1143  }
1144 
1145  if (MaxPacketSize)
1146  {
1147  //
1148  // transfer size is minimum available buffer or endpoint size
1149  //
1150  TransferSize = min(TransferBufferLength - TransferBufferOffset, MaxPacketSize);
1151  }
1152  else
1153  {
1154  //
1155  // use available buffer
1156  //
1157  TransferSize = TransferBufferLength - TransferBufferOffset;
1158  }
1159 
1160  //
1161  // get page offset
1162  //
1163  MaxLengthInPage = PAGE_SIZE - BYTE_OFFSET(TransferBuffer);
1164 
1165  //
1166  // get minimum from current page size
1167  //
1168  CurrentSize = min(TransferSize, MaxLengthInPage);
1169  ASSERT(CurrentSize);
1170 
1171  //
1172  // now init the descriptor
1173  //
1174  InitDescriptor(CurrentDescriptor,
1175  (PVOID)((ULONG_PTR)TransferBuffer + TransferBufferOffset),
1176  CurrentSize,
1177  PidDirection);
1178 
1179  //
1180  // adjust offset
1181  //
1182  TransferBufferOffset += CurrentSize;
1183 
1184  //
1185  // is there a previous descriptor
1186  //
1187  if (LastDescriptor)
1188  {
1189  //
1190  // link descriptors
1191  //
1192  LastDescriptor->NextLogicalDescriptor = (PVOID)CurrentDescriptor;
1193  LastDescriptor->NextPhysicalDescriptor = CurrentDescriptor->PhysicalAddress.LowPart;
1194  }
1195  else
1196  {
1197  //
1198  // it is the first descriptor
1199  //
1200  FirstDescriptor = CurrentDescriptor;
1201  }
1202 
1203  if(TransferBufferLength == TransferBufferOffset)
1204  {
1205  //
1206  // end reached
1207  //
1208  break;
1209  }
1210 
1211  }while(TRUE);
1212 
1213  if (OutFirstDescriptor)
1214  {
1215  //
1216  // store first descriptor
1217  //
1218  *OutFirstDescriptor = FirstDescriptor;
1219  }
1220 
1221  if (OutLastDescriptor)
1222  {
1223  //
1224  // store last descriptor
1225  //
1226  *OutLastDescriptor = CurrentDescriptor;
1227  }
1228 
1229  if (OutTransferBufferOffset)
1230  {
1231  //
1232  // store offset
1233  //
1234  *OutTransferBufferOffset = TransferBufferOffset;
1235  }
1236 
1237  //
1238  // done
1239  //
1240  return STATUS_SUCCESS;
1241 }
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
VOID STDMETHODCALLTYPE InitDescriptor(IN PQUEUE_TRANSFER_DESCRIPTOR CurrentDescriptor, IN PVOID TransferBuffer, IN ULONG TransferBufferLength, IN UCHAR PidCode, IN UCHAR DataToggle, OUT PULONG OutDescriptorLength)
LONG NTSTATUS
Definition: precomp.h:26
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define PAGE_SIZE
Definition: env_spec_w32.h:49
Status
Definition: gdiplustypes.h:24
#define min(a, b)
Definition: monoChain.cc:55
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS CreateGeneralTransferDescriptor(POHCI_GENERAL_TD *OutDescriptor, ULONG BufferSize)
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define BYTE_OFFSET(Va)

◆ CheckError()

VOID CUSBRequest::CheckError ( struct _OHCI_ENDPOINT_DESCRIPTOR OutDescriptor)

Definition at line 1789 of file usb_request.cpp.

1791 {
1792  POHCI_GENERAL_TD TransferDescriptor;
1793  ULONG ConditionCode;
1794  PURB Urb;
1795  PIO_STACK_LOCATION IoStack;
1796 
1797 
1798  //
1799  // set status code
1800  //
1803 
1804 
1805  if (OutDescriptor->Flags & OHCI_ENDPOINT_ISOCHRONOUS_FORMAT)
1806  {
1807  //
1808  // FIXME: handle isochronous support
1809  //
1810  ASSERT(FALSE);
1811  }
1812  else
1813  {
1814  //
1815  // get first general transfer descriptor
1816  //
1817  TransferDescriptor = (POHCI_GENERAL_TD)OutDescriptor->HeadLogicalDescriptor;
1818 
1820  {
1821  //
1822  // update data toggle
1823  //
1825  }
1826 
1827  while(TransferDescriptor)
1828  {
1829  //
1830  // get condition code
1831  //
1832  ConditionCode = OHCI_TD_GET_CONDITION_CODE(TransferDescriptor->Flags);
1833  if (ConditionCode != OHCI_TD_CONDITION_NO_ERROR)
1834  {
1835  //
1836  // FIXME status code
1837  //
1839 
1840  switch(ConditionCode)
1841  {
1843  DPRINT1("OHCI_TD_CONDITION_CRC_ERROR detected in TransferDescriptor TransferDescriptor %p\n", TransferDescriptor);
1845  break;
1847  DPRINT1("OHCI_TD_CONDITION_BIT_STUFFING detected in TransferDescriptor TransferDescriptor %p\n", TransferDescriptor);
1849  break;
1851  DPRINT1("OHCI_TD_CONDITION_TOGGLE_MISMATCH detected in TransferDescriptor TransferDescriptor %p\n", TransferDescriptor);
1853  break;
1855  DPRINT1("OHCI_TD_CONDITION_STALL detected in TransferDescriptor TransferDescriptor %p\n", TransferDescriptor);
1857  break;
1859  DPRINT1("OHCI_TD_CONDITION_NO_RESPONSE detected in TransferDescriptor TransferDescriptor %p\n", TransferDescriptor);
1861  break;
1863  DPRINT1("OHCI_TD_CONDITION_PID_CHECK_FAILURE detected in TransferDescriptor TransferDescriptor %p\n", TransferDescriptor);
1865  break;
1867  DPRINT1("OHCI_TD_CONDITION_UNEXPECTED_PID detected in TransferDescriptor TransferDescriptor %p\n", TransferDescriptor);
1869  break;
1871  DPRINT1("OHCI_TD_CONDITION_DATA_OVERRUN detected in TransferDescriptor TransferDescriptor %p\n", TransferDescriptor);
1873  break;
1875  if (m_Irp)
1876  {
1877  //
1878  // get current irp stack location
1879  //
1881 
1882  //
1883  // get urb
1884  //
1885  Urb = (PURB)IoStack->Parameters.Others.Argument1;
1886 
1887  if(Urb->UrbBulkOrInterruptTransfer.TransferFlags & USBD_SHORT_TRANSFER_OK)
1888  {
1889  //
1890  // short packets are ok
1891  //
1894  break;
1895  }
1896  }
1897  DPRINT1("OHCI_TD_CONDITION_DATA_UNDERRUN detected in TransferDescriptor TransferDescriptor %p\n", TransferDescriptor);
1899  break;
1901  DPRINT1("OHCI_TD_CONDITION_BUFFER_OVERRUN detected in TransferDescriptor TransferDescriptor %p\n", TransferDescriptor);
1903  break;
1905  DPRINT1("OHCI_TD_CONDITION_BUFFER_UNDERRUN detected in TransferDescriptor TransferDescriptor %p\n", TransferDescriptor);
1907  break;
1908  }
1909  }
1910 
1911  //
1912  // get next
1913  //
1914  TransferDescriptor = (POHCI_GENERAL_TD)TransferDescriptor->NextLogicalDescriptor;
1915  }
1916  }
1917 }
PUSB_ENDPOINT m_EndpointDescriptor
#define OHCI_TD_CONDITION_BUFFER_OVERRUN
Definition: hardware.h:305
#define USBD_STATUS_PID_CHECK_FAILURE
Definition: usb.h:177
PVOID NextLogicalDescriptor
Definition: hardware.h:269
#define USBD_STATUS_DATA_UNDERRUN
Definition: usb.h:180
#define OHCI_TD_CONDITION_DATA_UNDERRUN
Definition: hardware.h:304
struct OHCI_GENERAL_TD * POHCI_GENERAL_TD
#define USBD_STATUS_CRC
Definition: usb.h:172
#define OHCI_TD_CONDITION_TOGGLE_MISMATCH
Definition: hardware.h:298
#define OHCI_TD_CONDITION_NO_ERROR
Definition: hardware.h:295
smooth NULL
Definition: ftsmooth.c:416
#define USBD_STATUS_BUFFER_UNDERRUN
Definition: usb.h:184
#define USBD_STATUS_DATA_TOGGLE_MISMATCH
Definition: usb.h:174
#define USBD_STATUS_BUFFER_OVERRUN
Definition: usb.h:183
#define OHCI_TD_CONDITION_STALL
Definition: hardware.h:299
struct _URB_HEADER UrbHeader
Definition: usb.h:531
#define OHCI_TD_GET_CONDITION_CODE(x)
Definition: hardware.h:288
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define OHCI_TD_CONDITION_CRC_ERROR
Definition: hardware.h:296
#define OHCI_TD_CONDITION_DATA_OVERRUN
Definition: hardware.h:303
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define USBD_STATUS_SUCCESS
Definition: usb.h:170
#define OHCI_TD_CONDITION_BIT_STUFFING
Definition: hardware.h:297
#define USBD_STATUS_STALL_PID
Definition: usb.h:175
struct _URB * PURB
#define USBD_STATUS_DEV_NOT_RESPONDING
Definition: usb.h:176
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define USBD_SHORT_TRANSFER_OK
Definition: usb.h:154
#define OHCI_TD_CONDITION_BUFFER_UNDERRUN
Definition: hardware.h:306
#define USBD_STATUS_UNEXPECTED_PID
Definition: usb.h:178
Definition: usb.h:529
#define OHCI_ENDPOINT_ISOCHRONOUS_FORMAT
Definition: hardware.h:241
#define OHCI_ENDPOINT_TOGGLE_CARRY
Definition: hardware.h:244
#define DPRINT1
Definition: precomp.h:8
NTSTATUS m_NtStatusCode
#define OHCI_TD_CONDITION_PID_CHECK_FAILURE
Definition: hardware.h:301
struct _URB_BULK_OR_INTERRUPT_TRANSFER UrbBulkOrInterruptTransfer
Definition: usb.h:543
unsigned int ULONG
Definition: retypes.h:1
#define USBD_STATUS_DATA_OVERRUN
Definition: usb.h:179
#define OHCI_TD_CONDITION_UNEXPECTED_PID
Definition: hardware.h:302
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938
ULONG m_UrbStatusCode
#define OHCI_TD_CONDITION_NO_RESPONSE
Definition: hardware.h:300
#define URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER
Definition: usb.h:95
#define USBD_STATUS_BTSTUFF
Definition: usb.h:173

◆ CreateDescriptor() [1/2]

NTSTATUS STDMETHODCALLTYPE CUSBRequest::CreateDescriptor ( PQUEUE_TRANSFER_DESCRIPTOR OutDescriptor)

Definition at line 1238 of file usb_request.cpp.

1240 {
1242  NTSTATUS Status;
1243  PHYSICAL_ADDRESS TransferDescriptorPhysicalAddress;
1244 
1245  //
1246  // allocate descriptor
1247  //
1248  Status = m_DmaManager->Allocate(sizeof(QUEUE_TRANSFER_DESCRIPTOR), (PVOID*)&Descriptor, &TransferDescriptorPhysicalAddress);
1249  if (!NT_SUCCESS(Status))
1250  {
1251  //
1252  // failed to allocate transfer descriptor
1253  //
1255  }
1256 
1257  //
1258  // initialize transfer descriptor
1259  //
1260  Descriptor->NextPointer = TERMINATE_POINTER;
1261  Descriptor->AlternateNextPointer = TERMINATE_POINTER;
1262  Descriptor->Token.Bits.DataToggle = TRUE;
1263  Descriptor->Token.Bits.ErrorCounter = 0x03;
1264  Descriptor->Token.Bits.Active = TRUE;
1265  Descriptor->PhysicalAddr = TransferDescriptorPhysicalAddress.LowPart;
1266 
1267  //
1268  // store result
1269  //
1270  *OutDescriptor = Descriptor;
1271 
1272  //
1273  // done
1274  //
1275  return Status;
1276 }
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG NTSTATUS
Definition: precomp.h:26
PDMAMEMORYMANAGER m_DmaManager
Definition: usb_request.cpp:68
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG LowPart
Definition: typedefs.h:104
#define TERMINATE_POINTER
Definition: hardware.h:87
Status
Definition: gdiplustypes.h:24
_In_ PSTORAGE_PROPERTY_ID _Outptr_ PSTORAGE_DESCRIPTOR_HEADER * Descriptor
Definition: classpnp.h:966

Referenced by BuildControlTransferDescriptor(), BuildControlTransferQueueHead(), and BuildTransferDescriptorChain().

◆ CreateDescriptor() [2/2]

NTSTATUS CUSBRequest::CreateDescriptor ( PUHCI_TRANSFER_DESCRIPTOR OutDescriptor,
IN UCHAR  PidCode,
ULONG  BufferLength 
)

◆ CreateGeneralTransferDescriptor()

NTSTATUS CUSBRequest::CreateGeneralTransferDescriptor ( POHCI_GENERAL_TD OutDescriptor,
ULONG  BufferSize 
)

Definition at line 900 of file usb_request.cpp.

903 {
905  PHYSICAL_ADDRESS DescriptorAddress;
907 
908  //
909  // allocate transfer descriptor
910  //
911  Status = m_DmaManager->Allocate(sizeof(OHCI_GENERAL_TD), (PVOID*)&Descriptor, &DescriptorAddress);
912  if (!NT_SUCCESS(Status))
913  {
914  //
915  // no memory
916  //
917  return Status;
918  }
919 
920  //
921  // initialize descriptor, hardware part
922  //
923  Descriptor->Flags = 0;
924  Descriptor->BufferPhysical = 0;
925  Descriptor->NextPhysicalDescriptor = 0;
926  Descriptor->LastPhysicalByteAddress = 0;
927 
928  //
929  // software part
930  //
931  Descriptor->PhysicalAddress.QuadPart = DescriptorAddress.QuadPart;
932  Descriptor->BufferSize = BufferSize;
933 
934  if (BufferSize > 0)
935  {
936  //
937  // allocate buffer from dma
938  //
939  Status = m_DmaManager->Allocate(BufferSize, &Descriptor->BufferLogical, &DescriptorAddress);
940  if (!NT_SUCCESS(Status))
941  {
942  //
943  // no memory
944  //
945  m_DmaManager->Release(Descriptor, sizeof(OHCI_GENERAL_TD));
946  return Status;
947  }
948 
949  //
950  // set physical address of buffer
951  //
952  Descriptor->BufferPhysical = DescriptorAddress.LowPart;
953  Descriptor->LastPhysicalByteAddress = Descriptor->BufferPhysical + BufferSize - 1;
954  }
955 
956  //
957  // store result
958  //
959  *OutDescriptor = Descriptor;
960 
961  //
962  // done
963  //
964  return STATUS_SUCCESS;
965 }
LONG NTSTATUS
Definition: precomp.h:26
PDMAMEMORYMANAGER m_DmaManager
Definition: usb_request.cpp:68
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define BufferSize
Definition: classpnp.h:419
ULONG LowPart
Definition: typedefs.h:104
Status
Definition: gdiplustypes.h:24
return STATUS_SUCCESS
Definition: btrfs.c:2938
LONGLONG QuadPart
Definition: typedefs.h:112
_In_ PSTORAGE_PROPERTY_ID _Outptr_ PSTORAGE_DESCRIPTOR_HEADER * Descriptor
Definition: classpnp.h:966

Referenced by BuildControlTransferDescriptor(), and BuildTransferDescriptorChain().

◆ CreateIsochronousTransferDescriptor()

NTSTATUS CUSBRequest::CreateIsochronousTransferDescriptor ( OUT POHCI_ISO_TD OutDescriptor,
ULONG  FrameCount 
)

Definition at line 662 of file usb_request.cpp.

665 {
667  PHYSICAL_ADDRESS DescriptorAddress;
669 
670  //
671  // allocate transfer descriptor
672  //
673  Status = m_DmaManager->Allocate(sizeof(OHCI_ISO_TD), (PVOID*)&Descriptor, &DescriptorAddress);
674  if (!NT_SUCCESS(Status))
675  {
676  //
677  // no memory
678  //
679  return Status;
680  }
681 
682  //
683  // initialize descriptor, hardware part
684  //
685  Descriptor->Flags = OHCI_ITD_SET_FRAME_COUNT(FrameCount) | OHCI_ITD_SET_DELAY_INTERRUPT(OHCI_TD_INTERRUPT_NONE);// | OHCI_TD_SET_CONDITION_CODE(OHCI_TD_CONDITION_NOT_ACCESSED);
686  Descriptor->BufferPhysical = 0;
687  Descriptor->NextPhysicalDescriptor = 0;
688  Descriptor->LastPhysicalByteAddress = 0;
689 
690  //
691  // software part
692  //
693  Descriptor->PhysicalAddress.QuadPart = DescriptorAddress.QuadPart;
694  Descriptor->NextLogicalDescriptor = 0;
695 
696  //
697  // store result
698  //
699  *OutDescriptor = Descriptor;
700 
701  //
702  // done
703  //
704  return STATUS_SUCCESS;
705 }
LONG NTSTATUS
Definition: precomp.h:26
#define OHCI_TD_INTERRUPT_NONE
Definition: hardware.h:293
PDMAMEMORYMANAGER m_DmaManager
Definition: usb_request.cpp:68
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define OHCI_ITD_SET_FRAME_COUNT(x)
Definition: hardware.h:345
#define OHCI_ITD_SET_DELAY_INTERRUPT(x)
Definition: hardware.h:342
Status
Definition: gdiplustypes.h:24
return STATUS_SUCCESS
Definition: btrfs.c:2938
LONGLONG QuadPart
Definition: typedefs.h:112
_In_ PSTORAGE_PROPERTY_ID _Outptr_ PSTORAGE_DESCRIPTOR_HEADER * Descriptor
Definition: classpnp.h:966

Referenced by BuildIsochronousEndpoint().

◆ CreateQueueHead()

NTSTATUS CUSBRequest::CreateQueueHead ( PQUEUE_HEAD OutQueueHead)

Definition at line 1280 of file usb_request.cpp.

1282 {
1283  PQUEUE_HEAD QueueHead;
1284  PHYSICAL_ADDRESS QueueHeadPhysicalAddress;
1285  NTSTATUS Status;
1286 
1287  //
1288  // allocate queue head
1289  //
1290  Status = m_DmaManager->Allocate(sizeof(QUEUE_HEAD), (PVOID*)&QueueHead, &QueueHeadPhysicalAddress);
1291  if (!NT_SUCCESS(Status))
1292  {
1293  //
1294  // failed to allocate queue head
1295  //
1297  }
1298 
1299  //
1300  // initialize queue head
1301  //
1302  QueueHead->HorizontalLinkPointer = TERMINATE_POINTER;
1303  QueueHead->AlternateNextPointer = TERMINATE_POINTER;
1304  QueueHead->NextPointer = TERMINATE_POINTER;
1305  InitializeListHead(&QueueHead->TransferDescriptorListHead);
1306 
1307  //
1308  // 1 for non high speed, 0 for high speed device
1309  //
1310  QueueHead->EndPointCharacteristics.ControlEndPointFlag = 0;
1311  QueueHead->EndPointCharacteristics.HeadOfReclamation = FALSE;
1312  QueueHead->EndPointCharacteristics.MaximumPacketLength = 64;
1313 
1314  //
1315  // Set NakCountReload to max value possible
1316  //
1317  QueueHead->EndPointCharacteristics.NakCountReload = 0x3;
1318 
1319  //
1320  // Get the Initial Data Toggle from the QEDT
1321  //
1322  QueueHead->EndPointCharacteristics.QEDTDataToggleControl = TRUE;
1323 
1324  //
1325  // FIXME: check if High Speed Device
1326  //
1327  QueueHead->EndPointCharacteristics.EndPointSpeed = QH_ENDPOINT_HIGHSPEED;
1328  QueueHead->EndPointCapabilities.NumberOfTransactionPerFrame = 0x01;
1329  QueueHead->Token.DWord = 0;
1330  QueueHead->Token.Bits.InterruptOnComplete = FALSE;
1331 
1332  //
1333  // store address
1334  //
1335  QueueHead->PhysicalAddr = QueueHeadPhysicalAddress.LowPart;
1336 
1337  //
1338  // output queue head
1339  //
1340  *OutQueueHead = QueueHead;
1341 
1342  //
1343  // done
1344  //
1345  return STATUS_SUCCESS;
1346 }
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG NTSTATUS
Definition: precomp.h:26
#define QH_ENDPOINT_HIGHSPEED
Definition: hardware.h:163
PDMAMEMORYMANAGER m_DmaManager
Definition: usb_request.cpp:68
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG LowPart
Definition: typedefs.h:104
#define TERMINATE_POINTER
Definition: hardware.h:87
Status
Definition: gdiplustypes.h:24
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by BuildBulkInterruptTransferQueueHead(), and BuildControlTransferQueueHead().

◆ DumpEndpointDescriptor()

VOID CUSBRequest::DumpEndpointDescriptor ( struct _OHCI_ENDPOINT_DESCRIPTOR Descriptor)

Definition at line 1366 of file usb_request.cpp.

1368 {
1369  ULONG Count = 0;
1370  POHCI_GENERAL_TD GeneralDescriptor;
1371 
1372  DPRINT1("EndpointDescriptor %p Addr %x\n", Descriptor, Descriptor->PhysicalAddress.LowPart);
1373  DPRINT1("EndpointDescriptor HeadPhysicalDescriptor %x HeadLogicalDescriptor %p\n", Descriptor->HeadPhysicalDescriptor, Descriptor->HeadLogicalDescriptor);
1374  DPRINT1("EndpointDescriptor TailPhysicalDescriptor %x\n", Descriptor->TailPhysicalDescriptor);
1375  DPRINT1("EndpointDescriptor NextDescriptor %p\n", Descriptor->NextDescriptor);
1376  DPRINT1("EndpointDescriptor NextPhysicalEndpoint %x\n", Descriptor->NextPhysicalEndpoint);
1377  DPRINT1("EndpointDescriptor Flags %x\n", Descriptor->Flags);
1378 
1379 
1380  GeneralDescriptor = (POHCI_GENERAL_TD)Descriptor->HeadLogicalDescriptor;
1381  while(GeneralDescriptor)
1382  {
1383  DPRINT1("Descriptor %lu Address %p Addr %x\n", Count, GeneralDescriptor, GeneralDescriptor->PhysicalAddress);
1384  DPRINT1("Descriptor %lu BufferLogical %p BufferPhysical %x\n", Count, GeneralDescriptor->BufferLogical, GeneralDescriptor->BufferPhysical);
1385  DPRINT1("Descriptor %lu BufferSize %lu\n", Count, GeneralDescriptor->BufferSize);
1386  DPRINT1("Descriptor %lu LastPhysicalByteAddress %x\n", Count, GeneralDescriptor->LastPhysicalByteAddress);
1387  DPRINT1("Descriptor %lu Flags %x\n", Count, GeneralDescriptor->Flags);
1388  DPRINT1("Descriptor %lu NextLogicalDescriptor %p NextPhysicalDescriptor %x\n", Count, GeneralDescriptor->NextLogicalDescriptor, GeneralDescriptor->NextPhysicalDescriptor);
1389 
1390  Count++;
1391  GeneralDescriptor = (POHCI_GENERAL_TD)GeneralDescriptor->NextLogicalDescriptor;
1392  }
1393 }
PVOID BufferLogical
Definition: hardware.h:271
PVOID NextLogicalDescriptor
Definition: hardware.h:269
ULONG BufferSize
Definition: hardware.h:270
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
struct OHCI_GENERAL_TD * POHCI_GENERAL_TD
PHYSICAL_ADDRESS PhysicalAddress
Definition: hardware.h:268
ULONG BufferPhysical
Definition: hardware.h:264
ULONG LastPhysicalByteAddress
Definition: hardware.h:266
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
ULONG NextPhysicalDescriptor
Definition: hardware.h:265
_In_ PSTORAGE_PROPERTY_ID _Outptr_ PSTORAGE_DESCRIPTOR_HEADER * Descriptor
Definition: classpnp.h:966

◆ DumpQueueHead()

VOID CUSBRequest::DumpQueueHead ( IN PQUEUE_HEAD  QueueHead)

Definition at line 1053 of file usb_request.cpp.

1055 {
1058  ULONG Index = 0;
1059 
1060  DPRINT1("QueueHead %p Addr %x\n", QueueHead, QueueHead->PhysicalAddr);
1061  DPRINT1("QueueHead AlternateNextPointer %x\n", QueueHead->AlternateNextPointer);
1062  DPRINT1("QueueHead NextPointer %x\n", QueueHead->NextPointer);
1063 
1064  DPRINT1("QueueHead HubAddr %x\n", QueueHead->EndPointCharacteristics.ControlEndPointFlag);
1065  DPRINT1("QueueHead DeviceAddress %x\n", QueueHead->EndPointCharacteristics.DeviceAddress);
1066  DPRINT1("QueueHead EndPointNumber %x\n", QueueHead->EndPointCharacteristics.EndPointNumber);
1067  DPRINT1("QueueHead EndPointSpeed %x\n", QueueHead->EndPointCharacteristics.EndPointSpeed);
1068  DPRINT1("QueueHead HeadOfReclamation %x\n", QueueHead->EndPointCharacteristics.HeadOfReclamation);
1069  DPRINT1("QueueHead InactiveOnNextTransaction %x\n", QueueHead->EndPointCharacteristics.InactiveOnNextTransaction);
1070  DPRINT1("QueueHead MaximumPacketLength %x\n", QueueHead->EndPointCharacteristics.MaximumPacketLength);
1071  DPRINT1("QueueHead NakCountReload %x\n", QueueHead->EndPointCharacteristics.NakCountReload);
1072  DPRINT1("QueueHead QEDTDataToggleControl %x\n", QueueHead->EndPointCharacteristics.QEDTDataToggleControl);
1073  DPRINT1("QueueHead HubAddr %x\n", QueueHead->EndPointCapabilities.HubAddr);
1074  DPRINT1("QueueHead InterruptScheduleMask %x\n", QueueHead->EndPointCapabilities.InterruptScheduleMask);
1075  DPRINT1("QueueHead NumberOfTransactionPerFrame %x\n", QueueHead->EndPointCapabilities.NumberOfTransactionPerFrame);
1076  DPRINT1("QueueHead PortNumber %x\n", QueueHead->EndPointCapabilities.PortNumber);
1077  DPRINT1("QueueHead SplitCompletionMask %x\n", QueueHead->EndPointCapabilities.SplitCompletionMask);
1078 
1079  Entry = QueueHead->TransferDescriptorListHead.Flink;
1080  while(Entry != &QueueHead->TransferDescriptorListHead)
1081  {
1082  //
1083  // get transfer descriptor
1084  //
1086 
1087  DPRINT1("TransferDescriptor %lu Addr %x\n", Index, Descriptor->PhysicalAddr);
1088  DPRINT1("TransferDescriptor %lu Next %x\n", Index, Descriptor->NextPointer);
1089  DPRINT1("TransferDescriptor %lu AlternateNextPointer %x\n", Index, Descriptor->AlternateNextPointer);
1090  DPRINT1("TransferDescriptor %lu Active %lu\n", Index, Descriptor->Token.Bits.Active);
1091  DPRINT1("TransferDescriptor %lu BabbleDetected %lu\n", Index, Descriptor->Token.Bits.BabbleDetected);
1092  DPRINT1("TransferDescriptor %lu CurrentPage %lu\n", Index, Descriptor->Token.Bits.CurrentPage);
1093  DPRINT1("TransferDescriptor %lu DataBufferError %lu\n", Index, Descriptor->Token.Bits.DataBufferError);
1094  DPRINT1("TransferDescriptor %lu DataToggle %lu\n", Index, Descriptor->Token.Bits.DataToggle);
1095  DPRINT1("TransferDescriptor %lu ErrorCounter %lu\n", Index, Descriptor->Token.Bits.ErrorCounter);
1096  DPRINT1("TransferDescriptor %lu Halted %lu\n", Index, Descriptor->Token.Bits.Halted);
1097  DPRINT1("TransferDescriptor %lu InterruptOnComplete %x\n", Index, Descriptor->Token.Bits.InterruptOnComplete);
1098  DPRINT1("TransferDescriptor %lu MissedMicroFrame %lu\n", Index, Descriptor->Token.Bits.MissedMicroFrame);
1099  DPRINT1("TransferDescriptor %lu PIDCode %lu\n", Index, Descriptor->Token.Bits.PIDCode);
1100  DPRINT1("TransferDescriptor %lu PingState %lu\n", Index, Descriptor->Token.Bits.PingState);
1101  DPRINT1("TransferDescriptor %lu SplitTransactionState %lu\n", Index, Descriptor->Token.Bits.SplitTransactionState);
1102  DPRINT1("TransferDescriptor %lu TotalBytesToTransfer %lu\n", Index, Descriptor->Token.Bits.TotalBytesToTransfer);
1103  DPRINT1("TransferDescriptor %lu TransactionError %lu\n", Index, Descriptor->Token.Bits.TransactionError);
1104 
1105  DPRINT1("TransferDescriptor %lu Buffer Pointer 0 %x\n", Index, Descriptor->BufferPointer[0]);
1106  DPRINT1("TransferDescriptor %lu Buffer Pointer 1 %x\n", Index, Descriptor->BufferPointer[1]);
1107  DPRINT1("TransferDescriptor %lu Buffer Pointer 2 %x\n", Index, Descriptor->BufferPointer[2]);
1108  DPRINT1("TransferDescriptor %lu Buffer Pointer 3 %x\n", Index, Descriptor->BufferPointer[3]);
1109  DPRINT1("TransferDescriptor %lu Buffer Pointer 4 %x\n", Index, Descriptor->BufferPointer[4]);
1110  Entry = Entry->Flink;
1111  Index++;
1112  }
1113 }
struct _Entry Entry
Definition: kefuncs.h:640
struct _QUEUE_TRANSFER_DESCRIPTOR * PQUEUE_TRANSFER_DESCRIPTOR
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
static const UCHAR Index[8]
Definition: usbohci.c:18
Definition: typedefs.h:117
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
base of all file and directory entries
Definition: entries.h:82
_In_ PSTORAGE_PROPERTY_ID _Outptr_ PSTORAGE_DESCRIPTOR_HEADER * Descriptor
Definition: classpnp.h:966

◆ FreeDescriptor() [1/2]

VOID CUSBRequest::FreeDescriptor ( POHCI_GENERAL_TD  Descriptor)

Definition at line 642 of file usb_request.cpp.

644 {
645  if (Descriptor->BufferSize)
646  {
647  //
648  // free buffer
649  //
650  m_DmaManager->Release(Descriptor->BufferLogical, Descriptor->BufferSize);
651  }
652 
653  //
654  // release descriptor
655  //
656  m_DmaManager->Release(Descriptor, sizeof(OHCI_GENERAL_TD));
657 
658 }
PDMAMEMORYMANAGER m_DmaManager
Definition: usb_request.cpp:68
_In_ PSTORAGE_PROPERTY_ID _Outptr_ PSTORAGE_DESCRIPTOR_HEADER * Descriptor
Definition: classpnp.h:966

Referenced by BuildControlTransferDescriptor().

◆ FreeDescriptor() [2/2]

VOID CUSBRequest::FreeDescriptor ( IN PUHCI_TRANSFER_DESCRIPTOR  Descriptor)

Definition at line 992 of file usb_request.cpp.

994 {
995  if (Descriptor->BufferLogical)
996  {
997  //
998  // free buffer
999  //
1000  m_DmaManager->Release(Descriptor->BufferLogical, Descriptor->BufferSize);
1001  }
1002 
1003  //
1004  // free descriptors
1005  //
1007 }
PDMAMEMORYMANAGER m_DmaManager
Definition: usb_request.cpp:68
_In_ PSTORAGE_PROPERTY_ID _Outptr_ PSTORAGE_DESCRIPTOR_HEADER * Descriptor
Definition: classpnp.h:966

◆ GetDeviceAddress() [1/3]

UCHAR CUSBRequest::GetDeviceAddress ( )

◆ GetDeviceAddress() [2/3]

UCHAR STDMETHODCALLTYPE CUSBRequest::GetDeviceAddress ( )

◆ GetDeviceAddress() [3/3]

UCHAR CUSBRequest::GetDeviceAddress ( )

Definition at line 1351 of file usb_request.cpp.

1352 {
1353  PIO_STACK_LOCATION IoStack;
1354  PURB Urb;
1355  PUSBDEVICE UsbDevice;
1356 
1357  //
1358  // check if there is an irp provided
1359  //
1360  if (!m_Irp)
1361  {
1362  //
1363  // used provided address
1364  //
1365  return m_DeviceAddress;
1366  }
1367 
1368  //
1369  // get current stack location
1370  //
1372 
1373  //
1374  // get contained urb
1375  //
1376  Urb = (PURB)IoStack->Parameters.Others.Argument1;
1377 
1378  //
1379  // check if there is a pipe handle provided
1380  //
1381  if (Urb->UrbHeader.UsbdDeviceHandle)
1382  {
1383  //
1384  // there is a device handle provided
1385  //
1386  UsbDevice = (PUSBDEVICE)Urb->UrbHeader.UsbdDeviceHandle;
1387 
1388  //
1389  // return device address
1390  //
1391  return UsbDevice->GetDeviceAddress();
1392  }
1393 
1394  //
1395  // no device handle provided, it is the host root bus
1396  //
1397  return 0;
1398 }
IUSBDevice * PUSBDEVICE
struct _URB_HEADER UrbHeader
Definition: usb.h:531
if(!(yy_init))
Definition: macro.lex.yy.c:714
struct _URB * PURB
UCHAR m_DeviceAddress
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
Definition: usb.h:529
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772

Referenced by AllocateEndpointDescriptor(), BuildBulkInterruptTransferQueueHead(), and BuildControlTransferQueueHead().

◆ GetEndpointAddress() [1/2]

UCHAR CUSBRequest::GetEndpointAddress ( )

◆ GetEndpointAddress() [2/2]

UCHAR CUSBRequest::GetEndpointAddress ( )

Definition at line 518 of file usb_request.cpp.

519 {
521  {
522  //
523  // control request
524  //
525  return 0;
526  }
527 
528  ASSERT(m_Irp);
530 
531  //
532  // endpoint number is between 1-15
533  //
535 }
PUSB_ENDPOINT m_EndpointDescriptor
USB_ENDPOINT_DESCRIPTOR EndPointDescriptor
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)

Referenced by AllocateEndpointDescriptor().

◆ GetMaxPacketSize() [1/2]

USHORT CUSBRequest::GetMaxPacketSize ( )

◆ GetMaxPacketSize() [2/2]

USHORT CUSBRequest::GetMaxPacketSize ( )

Definition at line 474 of file usb_request.cpp.

475 {
477  {
478  if (m_DeviceSpeed == UsbLowSpeed)
479  {
480  //
481  // control pipes use 8 bytes packets
482  //
483  return 8;
484  }
485  else
486  {
487  //
488  // must be full speed
489  //
491  return 64;
492  }
493  }
494 
495  ASSERT(m_Irp);
497 
498  //
499  // return max packet size
500  //
502 }
PUSB_ENDPOINT m_EndpointDescriptor
USB_ENDPOINT_DESCRIPTOR EndPointDescriptor
USB_DEVICE_SPEED m_DeviceSpeed
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)

Referenced by AllocateEndpointDescriptor().

◆ InitDescriptor() [1/2]

VOID STDMETHODCALLTYPE CUSBRequest::InitDescriptor ( IN PQUEUE_TRANSFER_DESCRIPTOR  CurrentDescriptor,
IN PVOID  TransferBuffer,
IN ULONG  TransferBufferLength,
IN UCHAR  PidCode,
IN UCHAR  DataToggle,
OUT PULONG  OutDescriptorLength 
)

Definition at line 588 of file usb_request.cpp.

595 {
596  ULONG Index, Length = 0, PageOffset, BufferLength;
598 
599  //
600  // init transfer descriptor
601  //
602  CurrentDescriptor->Token.Bits.PIDCode = PidCode;
603  CurrentDescriptor->Token.Bits.TotalBytesToTransfer = 0;
604  CurrentDescriptor->Token.Bits.DataToggle = DataToggle;
605 
606  //
607  // sanity check
608  //
609  ASSERT(TransferBufferLength);
610 
611  //
612  // store buffers
613  //
614  Index = 0;
615  do
616  {
617  //
618  // get address (HACK)
619  //
620  *(volatile char *)TransferBuffer;
621  Address = MmGetPhysicalAddress(TransferBuffer);
622 
623  //
624  // use physical address
625  //
626  CurrentDescriptor->BufferPointer[Index] = Address.LowPart;
627  CurrentDescriptor->ExtendedBufferPointer[Index] = Address.HighPart;
628 
629  //
630  // Get the offset from page size
631  //
632  PageOffset = BYTE_OFFSET(CurrentDescriptor->BufferPointer[Index]);
633  if (PageOffset != 0)
634  {
635  //
636  // move to next page
637  //
638  TransferBuffer = (PVOID)ROUND_TO_PAGES(TransferBuffer);
639  }
640  else
641  {
642  //
643  // move to next page
644  //
645  TransferBuffer = (PVOID)((ULONG_PTR)TransferBuffer + PAGE_SIZE);
646  }
647 
648  //
649  // calculate buffer length
650  //
651  BufferLength = min(TransferBufferLength, PAGE_SIZE - PageOffset);
652 
653  //
654  // increment transfer bytes
655  //
656  CurrentDescriptor->Token.Bits.TotalBytesToTransfer += BufferLength;
657  CurrentDescriptor->TotalBytesToTransfer += BufferLength;
658  Length += BufferLength;
659  DPRINT("Index %lu TransferBufferLength %lu PageOffset %x BufferLength %lu Buffer Phy %p TransferBuffer %p\n", Index, TransferBufferLength, PageOffset, BufferLength, CurrentDescriptor->BufferPointer[Index], TransferBuffer);
660 
661  //
662  // decrement available byte count
663  //
664  TransferBufferLength -= BufferLength;
665  if (TransferBufferLength == 0)
666  {
667  //
668  // end reached
669  //
670  break;
671  }
672 
673  //
674  // sanity check
675  //
676  if (Index > 1)
677  {
678  //
679  // no equal buffers
680  //
681  ASSERT(CurrentDescriptor->BufferPointer[Index] != CurrentDescriptor->BufferPointer[Index-1]);
682  }
683 
684  //
685  // next descriptor index
686  //
687  Index++;
688  }while(Index < 5);
689 
690  //
691  // store result
692  //
693  *OutDescriptorLength = Length;
694 }
uint32_t ULONG_PTR
Definition: typedefs.h:63
_In_ ULONG BufferLength
Definition: usbdlib.h:225
static WCHAR Address[46]
Definition: ping.c:68
void DPRINT(...)
Definition: polytest.cpp:61
void * PVOID
Definition: retypes.h:9
static const UCHAR Index[8]
Definition: usbohci.c:18
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define ROUND_TO_PAGES(Size)
#define min(a, b)
Definition: monoChain.cc:55
unsigned int ULONG
Definition: retypes.h:1
PHYSICAL_ADDRESS NTAPI MmGetPhysicalAddress(IN PVOID Address)
Definition: stubs.c:682
#define BYTE_OFFSET(Va)

Referenced by BuildTransferDescriptorChain().

◆ InitDescriptor() [2/2]

VOID CUSBRequest::InitDescriptor ( IN POHCI_GENERAL_TD  CurrentDescriptor,
IN PVOID  TransferBuffer,
IN ULONG  TransferBufferLength,
IN UCHAR  PidCode 
)

Definition at line 1074 of file usb_request.cpp.

1079 {
1080  ULONG Direction;
1081 
1082  if (PidDirection)
1083  {
1084  //
1085  // input direction
1086  //
1088  }
1089  else
1090  {
1091  //
1092  // output direction
1093  //
1095  }
1096 
1097 
1098  //
1099  // initialize descriptor
1100  //
1102 
1103  //
1104  // store physical address of buffer
1105  //
1106  CurrentDescriptor->BufferPhysical = MmGetPhysicalAddress(TransferBuffer).LowPart;
1107  CurrentDescriptor->LastPhysicalByteAddress = CurrentDescriptor->BufferPhysical + TransferBufferLength - 1;
1108 
1109  DPRINT("CurrentDescriptor %p Addr %x TransferBufferLength %lu\n", CurrentDescriptor, CurrentDescriptor->PhysicalAddress.LowPart, TransferBufferLength);
1110 }
#define OHCI_TD_SET_DELAY_INTERRUPT(x)
Definition: hardware.h:281
#define OHCI_TD_DIRECTION_PID_IN
Definition: hardware.h:279
#define OHCI_TD_SET_CONDITION_CODE(x)
Definition: hardware.h:289
void DPRINT(...)
Definition: polytest.cpp:61
#define OHCI_TD_INTERRUPT_NONE
Definition: hardware.h:293
_Inout_ PSIZE_T _In_opt_ PMDLX _In_ MM_ROTATE_DIRECTION Direction
Definition: mmfuncs.h:773
ULONG LowPart
Definition: typedefs.h:104
#define OHCI_TD_DIRECTION_PID_OUT
Definition: hardware.h:278
#define OHCI_TD_TOGGLE_CARRY
Definition: hardware.h:283
#define OHCI_TD_CONDITION_NOT_ACCESSED
Definition: hardware.h:307
#define OHCI_TD_BUFFER_ROUNDING
Definition: hardware.h:275
unsigned int ULONG
Definition: retypes.h:1
PHYSICAL_ADDRESS NTAPI MmGetPhysicalAddress(IN PVOID Address)
Definition: stubs.c:682

◆ InternalCalculateTransferLength()

ULONG CUSBRequest::InternalCalculateTransferLength ( )

Definition at line 1774 of file usb_request.cpp.

1775 {
1776  if (!m_Irp)
1777  {
1778  //
1779  // FIXME: get length for control request
1780  //
1781  return m_TransferBufferLength;
1782  }
1783 
1784  //
1785  // sanity check
1786  //
1789  {
1790  //
1791  // bulk in request
1792  // HACK: Properly determine transfer length
1793  //
1794  return m_TransferBufferLength;//m_TotalBytesTransferred;
1795  }
1796 
1797  //
1798  // bulk out transfer
1799  //
1800  return m_TransferBufferLength;
1801 }
ULONG m_TransferBufferLength
Definition: usb_request.cpp:78
PUSB_ENDPOINT m_EndpointDescriptor
#define USB_ENDPOINT_DIRECTION_IN(x)
Definition: usb100.h:76
USB_ENDPOINT_DESCRIPTOR EndPointDescriptor
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)

◆ InternalGetPidDirection() [1/3]

UCHAR CUSBRequest::InternalGetPidDirection ( )

◆ InternalGetPidDirection() [2/3]

UCHAR CUSBRequest::InternalGetPidDirection ( )

◆ InternalGetPidDirection() [3/3]

UCHAR CUSBRequest::InternalGetPidDirection ( )

Definition at line 567 of file usb_request.cpp.

568 {
570  {
571  //
572  // end point direction is highest bit in bEndpointAddress
573  //
575  }
576  else
577  {
578  //
579  // request arrives on the control pipe, extract direction from setup packet
580  //
582  return (m_DescriptorPacket->bmRequestType.B >> 7);
583  }
584 }
PUSB_ENDPOINT m_EndpointDescriptor
USB_ENDPOINT_DESCRIPTOR EndPointDescriptor
#define USB_ENDPOINT_DIRECTION_MASK
Definition: usb100.h:73
PUSB_DEFAULT_PIPE_SETUP_PACKET m_DescriptorPacket
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BM_REQUEST_TYPE bmRequestType
Definition: usb200.h:72

Referenced by BuildBulkInterruptEndpoint(), BuildBulkInterruptTransferDescriptor(), BuildBulkInterruptTransferQueueHead(), BuildControlTransferDescriptor(), and BuildControlTransferQueueHead().

◆ InternalGetTransferType() [1/3]

IMP_IUSBREQUEST IMP_IOHCIREQUEST ULONG CUSBRequest::InternalGetTransferType ( )

◆ InternalGetTransferType() [2/3]

IMP_IUSBREQUEST IMP_IUHCIREQUEST ULONG CUSBRequest::InternalGetTransferType ( )

◆ InternalGetTransferType() [3/3]

ULONG CUSBRequest::InternalGetTransferType ( )

Definition at line 535 of file usb_request.cpp.

536 {
537  ULONG TransferType;
538 
539  //
540  // check if an irp is provided
541  //
542  if (m_Irp)
543  {
545 
546  //
547  // end point is defined in the low byte of bmAttributes
548  //
550  }
551  else
552  {
553  //
554  // initialized with setup packet, must be a control transfer
555  //
556  TransferType = USB_ENDPOINT_TYPE_CONTROL;
558  }
559 
560  //
561  // done
562  //
563  return TransferType;
564 }
PUSB_ENDPOINT m_EndpointDescriptor
USB_ENDPOINT_DESCRIPTOR EndPointDescriptor
#define USB_ENDPOINT_TYPE_CONTROL
Definition: usb100.h:62
smooth NULL
Definition: ftsmooth.c:416
#define USB_ENDPOINT_TYPE_MASK
Definition: usb100.h:61
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned int ULONG
Definition: retypes.h:1

◆ QueryInterface() [1/3]

STDMETHODIMP CUSBRequest::QueryInterface ( REFIID  InterfaceId,
PVOID Interface 
)

◆ QueryInterface() [2/3]

STDMETHODIMP CUSBRequest::QueryInterface ( REFIID  InterfaceId,
PVOID Interface 
)

◆ QueryInterface() [3/3]

STDMETHODIMP CUSBRequest::QueryInterface ( REFIID  InterfaceId,
PVOID Interface 
)

◆ STDMETHODIMP_() [1/6]

CUSBRequest::STDMETHODIMP_ ( ULONG  )
inline

Definition at line 21 of file usb_request.cpp.

22  {
24  return m_Ref;
25  }
#define InterlockedIncrement
Definition: armddk.h:53

◆ STDMETHODIMP_() [2/6]

CUSBRequest::STDMETHODIMP_ ( ULONG  )
inline

Definition at line 21 of file usb_request.cpp.

22  {
24  return m_Ref;
25  }
#define InterlockedIncrement
Definition: armddk.h:53

◆ STDMETHODIMP_() [3/6]

CUSBRequest::STDMETHODIMP_ ( ULONG  )
inline

Definition at line 21 of file usb_request.cpp.

22  {
24  return m_Ref;
25  }
#define InterlockedIncrement
Definition: armddk.h:53

◆ STDMETHODIMP_() [4/6]

CUSBRequest::STDMETHODIMP_ ( ULONG  )
inline

Definition at line 26 of file usb_request.cpp.

27  {
29 
30  if (!m_Ref)
31  {
32  delete this;
33  return 0;
34  }
35  return m_Ref;
36  }
#define InterlockedDecrement
Definition: armddk.h:52

◆ STDMETHODIMP_() [5/6]

CUSBRequest::STDMETHODIMP_ ( ULONG  )
inline

Definition at line 26 of file usb_request.cpp.

27  {
29 
30  if (!m_Ref)
31  {
32  delete this;
33  return 0;
34  }
35  return m_Ref;
36  }
#define InterlockedDecrement
Definition: armddk.h:52

◆ STDMETHODIMP_() [6/6]

CUSBRequest::STDMETHODIMP_ ( ULONG  )
inline

Definition at line 26 of file usb_request.cpp.

27  {
29 
30  if (!m_Ref)
31  {
32  delete this;
33  return 0;
34  }
35  return m_Ref;
36  }
#define InterlockedDecrement
Definition: armddk.h:52

Member Data Documentation

◆ m_Base

PVOID CUSBRequest::m_Base
protected

◆ m_CompletionEvent

PKEVENT CUSBRequest::m_CompletionEvent
protected

Definition at line 103 of file usb_request.cpp.

Referenced by ~CUSBRequest().

◆ m_DescriptorPacket

PUSB_DEFAULT_PIPE_SETUP_PACKET CUSBRequest::m_DescriptorPacket
protected

◆ m_DescriptorSetupPacket

PHYSICAL_ADDRESS CUSBRequest::m_DescriptorSetupPacket
protected

Definition at line 124 of file usb_request.cpp.

Referenced by BuildControlTransferQueueHead(), and BuildSetupPacket().

◆ m_DeviceAddress

UCHAR CUSBRequest::m_DeviceAddress
protected

Definition at line 108 of file usb_request.cpp.

Referenced by GetDeviceAddress().

◆ m_DeviceSpeed

USB_DEVICE_SPEED CUSBRequest::m_DeviceSpeed
protected

Definition at line 134 of file usb_request.cpp.

Referenced by AllocateEndpointDescriptor(), and GetMaxPacketSize().

◆ m_DmaManager

◆ m_EndpointDescriptor

◆ m_Irp

◆ m_NtStatusCode

NTSTATUS CUSBRequest::m_NtStatusCode
protected

Definition at line 129 of file usb_request.cpp.

Referenced by CheckError().

◆ m_QueueHead

PQUEUE_HEAD CUSBRequest::m_QueueHead
protected

Definition at line 118 of file usb_request.cpp.

◆ m_Ref

LONG CUSBRequest::m_Ref
protected

Definition at line 63 of file usb_request.cpp.

Referenced by STDMETHODIMP_().

◆ m_SetupPacket

PUSB_DEFAULT_PIPE_SETUP_PACKET CUSBRequest::m_SetupPacket
protected

Definition at line 98 of file usb_request.cpp.

Referenced by BuildControlTransferDescriptor(), and BuildSetupPacket().

◆ m_Speed

USB_DEVICE_SPEED CUSBRequest::m_Speed
protected

Definition at line 136 of file usb_request.cpp.

◆ m_TotalBytesTransferred

ULONG CUSBRequest::m_TotalBytesTransferred
protected

Definition at line 88 of file usb_request.cpp.

◆ m_TransferBufferLength

◆ m_TransferBufferLengthCompleted

ULONG CUSBRequest::m_TransferBufferLengthCompleted
protected

◆ m_TransferBufferMDL

◆ m_Urb

PURB CUSBRequest::m_Urb
protected

Definition at line 139 of file usb_request.cpp.

◆ m_UrbStatusCode

ULONG CUSBRequest::m_UrbStatusCode
protected

Definition at line 130 of file usb_request.cpp.

Referenced by CheckError().


The documentation for this class was generated from the following file: