ReactOS  0.4.12-dev-708-g95ed44e
usb_device.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Universal Serial Bus Bulk Driver Library
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: lib/drivers/libusb/usb_device.cpp
5  * PURPOSE: USB Common Driver Library.
6  * PROGRAMMERS:
7  * Michael Martin (michael.martin@reactos.org)
8  * Johannes Anderwald (johannes.anderwald@reactos.org)
9  */
10 
11 #include "libusb.h"
12 
13 #define NDEBUG
14 #include <debug.h>
15 
16 class CUSBDevice : public IUSBDevice
17 {
18 public:
20 
22  {
24  return m_Ref;
25  }
27  {
29 
30  if (!m_Ref)
31  {
32  delete this;
33  return 0;
34  }
35  return m_Ref;
36  }
37 
38  // IUSBDevice interface functions
40  virtual BOOLEAN IsHub();
41  virtual NTSTATUS GetParent(PVOID * Parent);
42  virtual UCHAR GetDeviceAddress();
43  virtual ULONG GetPort();
44  virtual USB_DEVICE_SPEED GetSpeed();
45  virtual USB_DEVICE_TYPE GetType();
46  virtual ULONG GetState();
47  virtual void SetDeviceHandleData(PVOID Data);
50  virtual UCHAR GetConfigurationValue();
51  virtual NTSTATUS SubmitIrp(PIRP Irp);
57  virtual NTSTATUS AbortPipe(IN PUSB_ENDPOINT_DESCRIPTOR EndpointDescriptor);
58  virtual UCHAR GetMaxPacketSize();
59 
60 
61  // local function
62  virtual NTSTATUS CommitIrp(PIRP Irp);
64  virtual NTSTATUS CreateConfigurationDescriptor(UCHAR ConfigurationIndex);
67  virtual VOID DumpConfigurationDescriptor(PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor);
69  virtual NTSTATUS BuildInterfaceDescriptor(IN ULONG ConfigurationIndex, IN PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor, OUT PUSBD_INTERFACE_INFORMATION InterfaceInfo, OUT PUSB_INTERFACE *OutUsbInterface);
70 
71 
72  // constructor / destructor
73  CUSBDevice(IUnknown *OuterUnknown){}
74  virtual ~CUSBDevice(){}
75 
76 protected:
91 
93 };
94 
95 //----------------------------------------------------------------------------------------
99  IN REFIID refiid,
100  OUT PVOID* Output)
101 {
102  return STATUS_UNSUCCESSFUL;
103 }
104 
105 //----------------------------------------------------------------------------------------
106 NTSTATUS
108  IN PHUBCONTROLLER HubController,
110  IN PVOID Parent,
111  IN ULONG Port,
113 {
115 
116  //
117  // initialize members
118  //
119  m_HubController = HubController;
120  m_Device = Device;
121  m_Parent = Parent;
122  m_Port = Port;
124  m_USBType = m_Device->GetUSBType();
125 
126  //
127  // initialize device lock
128  //
130 
131  //
132  // no device address has been set yet
133  //
134  m_DeviceAddress = 0;
135 
136  //
137  // get usb request queue
138  //
139  Status = m_Device->GetUSBQueue(&m_Queue);
140  if (!NT_SUCCESS(Status))
141  {
142  //
143  // failed to get usb queue
144  //
145  DPRINT1("[%s] GetUsbQueue failed with %x\n", m_USBType, Status);
146  return Status;
147  }
148 
149  //
150  // get dma manager
151  //
152  Status = m_Device->GetDMA(&m_DmaManager);
153  if (!NT_SUCCESS(Status))
154  {
155  //
156  // failed to get dma manager
157  //
158  DPRINT1("[%s] GetDMA failed with %x\n", m_USBType, Status);
159  return Status;
160  }
161 
162  //
163  // sanity check
164  //
166 
167  //
168  // get device descriptor
169  //
171  if (!NT_SUCCESS(Status))
172  {
173  //
174  // failed to get device descriptor
175  //
176  DPRINT1("[%s] Failed to get device descriptor with %x\n", m_USBType, Status);
177  return Status;
178  }
179 
180  //
181  // done
182  //
183  return Status;
184 }
185 
186 //----------------------------------------------------------------------------------------
187 BOOLEAN
189 {
190  //
191  // USB Standard Device Class see http://www.usb.org/developers/defined_class/#BaseClass09h
192  // for details
193  //
195 }
196 
197 //----------------------------------------------------------------------------------------
198 NTSTATUS
200  PVOID * Parent)
201 {
202  //
203  // returns parent
204  //
205  *Parent = m_Parent;
206 
207  //
208  // done
209  //
210  return STATUS_SUCCESS;
211 }
212 
213 //----------------------------------------------------------------------------------------
214 UCHAR
216 {
217  //
218  // get device address
219  //
220  return m_DeviceAddress;
221 }
222 
223 //----------------------------------------------------------------------------------------
224 ULONG
226 {
227  //
228  // get port to which this device is connected to
229  //
230  return m_Port;
231 }
232 
233 //----------------------------------------------------------------------------------------
236 {
238  {
239  //
240  // low speed device
241  //
242  return UsbLowSpeed;
243  }
245  {
246  //
247  // high speed device
248  //
249  return UsbHighSpeed;
250  }
251 
252  //
253  // default to full speed
254  //
255  return UsbFullSpeed;
256 }
257 
258 //----------------------------------------------------------------------------------------
261 {
262  //
263  // device is encoded into bcdUSB
264  //
265  if (m_DeviceDescriptor.bcdUSB == 0x110)
266  {
267  //
268  // USB 1.1 device
269  //
270  return Usb11Device;
271  }
272  else if (m_DeviceDescriptor.bcdUSB == 0x200)
273  {
274  //
275  // USB 2.0 device
276  //
277  return Usb20Device;
278  }
279 
280  DPRINT1("[%s] GetType Unknown bcdUSB Type %x\n", m_USBType, m_DeviceDescriptor.bcdUSB);
281  //PC_ASSERT(FALSE);
282 
283  return Usb11Device;
284 }
285 
286 //----------------------------------------------------------------------------------------
287 ULONG
289 {
291  return FALSE;
292 }
293 
294 //----------------------------------------------------------------------------------------
295 void
297  PVOID Data)
298 {
299  //
300  // set device data, for debugging issues
301  //
302  m_Data = Data;
303 }
304 
305 //----------------------------------------------------------------------------------------
306 NTSTATUS
309 {
312  UCHAR Index;
313 
314  DPRINT1("[%s] SetDeviceAddress> Address %x\n", m_USBType, DeviceAddress);
315 
317  if (!CtrlSetup)
319 
320  // zero request
321  RtlZeroMemory(CtrlSetup, sizeof(USB_DEFAULT_PIPE_SETUP_PACKET));
322 
323  // initialize request
324  CtrlSetup->bRequest = USB_REQUEST_SET_ADDRESS;
325  CtrlSetup->wValue.W = DeviceAddress;
326 
327  // set device address
328  Status = CommitSetupPacket(CtrlSetup, NULL, 0, NULL);
329 
330  // free setup packet
331  ExFreePoolWithTag(CtrlSetup, TAG_USBLIB);
332 
333  // check for success
334  if (!NT_SUCCESS(Status))
335  {
336  // failed to set device address
337  DPRINT1("[%s] SetDeviceAddress> failed to set device address with %lx Address %x\n", m_USBType, Status, DeviceAddress);
338  return Status;
339  }
340 
341  // lets have a short nap
343 
344  // store new device address
346 
347  // fetch device descriptor
349  if (!NT_SUCCESS(Status))
350  {
351  DPRINT1("[%s] SetDeviceAddress failed to retrieve device descriptor with device address set Error %lx\n", m_USBType, Status);
352  // return error status
353  return Status;
354  }
355 
356  // check for invalid device descriptor
360  {
361  // failed to retrieve device descriptor
362  DPRINT1("[%s] SetDeviceAddress> device returned bogus device descriptor\n", m_USBType);
364 
365  // return error status
366  return STATUS_UNSUCCESSFUL;
367  }
368 
369  // dump device descriptor
371 
372  // sanity checks
374 
375  // allocate configuration descriptor
377 
378  // zero configuration descriptor
380 
381  // retrieve the configuration descriptors
383  {
384  // retrieve configuration descriptors from device
386  if (!NT_SUCCESS(Status))
387  {
388  DPRINT1("[%s] SetDeviceAddress> failed to retrieve configuration %lu\n", m_USBType, Index);
389  break;
390  }
391  }
392 
393  //
394  // done
395  //
396  return Status;
397 
398 }
399 
400 //----------------------------------------------------------------------------------------
401 void
404 {
406 }
407 
408 //----------------------------------------------------------------------------------------
409 UCHAR
411 {
412  //
413  // return configuration index
414  //
415  return m_ConfigurationIndex;
416 }
417 
418 //----------------------------------------------------------------------------------------
419 NTSTATUS
421  PIRP Irp)
422 {
425 
426  if (!m_Queue || !m_DmaManager)
427  {
428  //
429  // no queue, wtf?
430  //
431  DPRINT1("[%s] CommitIrp> no queue / dma !!!\n", m_USBType);
432  return STATUS_UNSUCCESSFUL;
433  }
434 
435  //
436  // build usb request
437  //
438  Status = m_Queue->CreateUSBRequest(&Request);
439  if (!NT_SUCCESS(Status))
440  {
441  //
442  // failed to build request
443  //
444  DPRINT1("[%s] CommitIrp> CreateUSBRequest failed with %lx\n", m_USBType, Status);
445  return Status;
446  }
447 
448  //
449  // initialize request
450  //
451  Status = Request->InitializeWithIrp(m_DmaManager, PUSBDEVICE(this), Irp);
452 
453  //
454  // mark irp as pending
455  //
457 
458  //
459  // now add the request
460  //
461  Status = m_Queue->AddUSBRequest(Request);
462  if (!NT_SUCCESS(Status))
463  {
464  //
465  // failed to add request
466  //
467  DPRINT1("[%s] failed add request to queue with %lx\n", m_USBType, Status);
468  Request->Release();
469  return Status;
470  }
471 
472  //
473  // done
474  //
475  return STATUS_PENDING;
476 }
477 
478 //----------------------------------------------------------------------------------------
479 NTSTATUS
481  PIRP Irp)
482 {
483  KIRQL OldLevel;
485 
486  //
487  // acquire device lock
488  //
489  KeAcquireSpinLock(&m_Lock, &OldLevel);
490 
491  //
492  // commit urb
493  //
494  Status = CommitIrp(Irp);
495 
496  //
497  // release lock
498  //
499  KeReleaseSpinLock(&m_Lock, OldLevel);
500 
501  return Status;
502 }
503 
504 //----------------------------------------------------------------------------------------
505 NTSTATUS
508  IN OPTIONAL PUSB_ENDPOINT EndpointDescriptor,
510  IN OUT PMDL Mdl)
511 {
514 
515  if (!m_Queue)
516  {
517  //
518  // no queue, wtf?
519  //
520  DPRINT1("[%s] CommitSetupPacket> no queue!!!\n", m_USBType);
521  return STATUS_UNSUCCESSFUL;
522  }
523 
524  //
525  // build usb request
526  //
527  Status = m_Queue->CreateUSBRequest(&Request);
528  if (!NT_SUCCESS(Status))
529  {
530  //
531  // failed to build request
532  //
533  DPRINT1("[%s] CommitSetupPacket> CreateUSBRequest failed with %x\n", m_USBType, Status);
534  return Status;
535  }
536 
537  //
538  // initialize request
539  //
540  Status = Request->InitializeWithSetupPacket(m_DmaManager, Packet, PUSBDEVICE(this), EndpointDescriptor, BufferLength, Mdl);
541  if (!NT_SUCCESS(Status))
542  {
543  //
544  // failed to initialize request
545  //
546  DPRINT1("[%s] CommitSetupPacket failed to initialize usb request with %x\n", m_USBType, Status);
547  Request->Release();
548  return Status;
549  }
550 
551  //
552  // now add the request
553  //
554  Status = m_Queue->AddUSBRequest(Request);
555  if (!NT_SUCCESS(Status))
556  {
557  //
558  // failed to add request
559  //
560  DPRINT1("[%s] CommitSetupPacket> failed add request to queue with %x\n", m_USBType, Status);
561  Request->Release();
562  return Status;
563  }
564 
565  //
566  // get the result code when the operation has been finished
567  //
568  Request->GetResultStatus(&Status, NULL);
569 
570  //
571  // release request
572  //
573  Request->Release();
574 
575  //
576  // done
577  //
578  return Status;
579 }
580 
581 //----------------------------------------------------------------------------------------
582 NTSTATUS
584 {
586  PMDL Mdl;
588  PVOID Buffer;
589 
590  //
591  // zero descriptor
592  //
594  RtlZeroMemory(&CtrlSetup, sizeof(USB_DEFAULT_PIPE_SETUP_PACKET));
595 
596  //
597  // setup request
598  //
601  CtrlSetup.wLength = sizeof(USB_DEVICE_DESCRIPTOR);
602  CtrlSetup.bmRequestType.B = 0x80;
603 
604  //
605  // allocate buffer
606  //
608  if (!Buffer)
609  {
610  //
611  // failed to allocate
612  //
614  }
615 
616  //
617  // zero buffer
618  //
620 
621  //
622  // allocate mdl describing the device descriptor
623  //
625  if (!Mdl)
626  {
627  //
628  // failed to allocate mdl
629  //
631  }
632 
633  //
634  // build mdl for non paged pool
635  //
637 
638  //
639  // commit setup packet
640  //
641  Status = CommitSetupPacket(&CtrlSetup, NULL, sizeof(USB_DEVICE_DESCRIPTOR), Mdl);
642 
643  //
644  // now free the mdl
645  //
646  IoFreeMdl(Mdl);
647 
648  if (NT_SUCCESS(Status))
649  {
650  //
651  // copy device descriptor
652  //
654  }
655 
656  //
657  // free buffer
658  //
660 
661  //
662  // done
663  //
664  return Status;
665 
666 }
667 
668 //----------------------------------------------------------------------------------------
669 NTSTATUS
671  IN UCHAR ConfigurationIndex,
673  IN PVOID Buffer)
674 {
677  PMDL Mdl;
678 
679 
680  //
681  // now build MDL describing the buffer
682  //
684  if (!Mdl)
685  {
686  //
687  // failed to allocate mdl
688  //
690  }
691 
692  //
693  // build mdl for non paged pool
694  //
696 
697 
698  //
699  // build setup packet
700  //
701  CtrlSetup.bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
702  CtrlSetup.bmRequestType.Type = BMREQUEST_STANDARD;
703  CtrlSetup.bmRequestType.Reserved = 0;
704  CtrlSetup.bmRequestType.Dir = BMREQUEST_DEVICE_TO_HOST;
706  CtrlSetup.wValue.LowByte = ConfigurationIndex;
708  CtrlSetup.wIndex.W = 0;
709  CtrlSetup.wLength = BufferSize;
710 
711  //
712  // commit packet
713  //
714  Status = CommitSetupPacket(&CtrlSetup, NULL, BufferSize, Mdl);
715 
716  //
717  // free mdl
718  //
719  IoFreeMdl(Mdl);
720 
721  //
722  // done
723  //
724  return Status;
725 }
726 
727 //----------------------------------------------------------------------------------------
728 NTSTATUS
730  UCHAR Index)
731 {
733  PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor;
734 
735  //
736  // sanity checks
737  //
739 
740  //
741  // first allocate a buffer which should be enough to store all different interfaces and endpoints
742  //
744  if (!ConfigurationDescriptor)
745  {
746  //
747  // failed to allocate buffer
748  //
750  }
751 
752  //
753  // get partial configuration descriptor
754  //
755  Status = GetConfigurationDescriptor(Index, sizeof(USB_CONFIGURATION_DESCRIPTOR), ConfigurationDescriptor);
756  if (!NT_SUCCESS(Status))
757  {
758  //
759  // failed to get partial configuration descriptor
760  //
761  DPRINT1("[%s] Failed to get partial configuration descriptor Status %x Index %x\n", m_USBType, Status, Index);
762  ExFreePoolWithTag(ConfigurationDescriptor, TAG_USBLIB);
763  return Status;
764  }
765 
766  //
767  // now get full descriptor
768  //
769  Status = GetConfigurationDescriptor(Index, ConfigurationDescriptor->wTotalLength, ConfigurationDescriptor);
770  if (!NT_SUCCESS(Status))
771  {
772  //
773  // failed to get full configuration descriptor
774  //
775  DPRINT1("[%s] Failed to get full configuration descriptor Status %x Index %x\n", m_USBType, Status, Index);
776  ExFreePoolWithTag(ConfigurationDescriptor, TAG_USBLIB);
777  return Status;
778  }
779 
780  //
781  // informal debug print
782  //
783  DumpConfigurationDescriptor(ConfigurationDescriptor);
784 
785  //
786  // sanity check
787  //
788  PC_ASSERT(ConfigurationDescriptor->bLength == sizeof(USB_CONFIGURATION_DESCRIPTOR));
789  PC_ASSERT(ConfigurationDescriptor->wTotalLength <= PAGE_SIZE);
790  PC_ASSERT(ConfigurationDescriptor->bNumInterfaces);
791 
792  //
793  // request is complete, initialize configuration descriptor
794  //
795  m_ConfigurationDescriptors[Index].ConfigurationDescriptor = ConfigurationDescriptor;
797 
798  //
799  // done
800  //
801  return Status;
802 }
803 //----------------------------------------------------------------------------------------
804 VOID
808  OUT PULONG OutBufferLength)
809 {
810  ULONG Length;
811 
812  // sanity check
815  ASSERT(OutBufferLength);
816 
817  // reset copied length
818  *OutBufferLength = 0;
819 
820  // FIXME: support multiple configurations
822 
823  // copy configuration descriptor
824  Length = min(m_ConfigurationDescriptors[0].ConfigurationDescriptor->wTotalLength, BufferLength);
826  *OutBufferLength = Length;
827 }
828 
829 //----------------------------------------------------------------------------------------
830 ULONG
832 {
833  //
834  // FIXME: support multiple configurations
835  //
837 
839 }
840 //----------------------------------------------------------------------------------------
841 VOID
843 {
844  DPRINT1("Dumping Device Descriptor %p\n", DeviceDescriptor);
845  DPRINT1("bLength %x\n", DeviceDescriptor->bLength);
846  DPRINT1("bDescriptorType %x\n", DeviceDescriptor->bDescriptorType);
847  DPRINT1("bcdUSB %x\n", DeviceDescriptor->bcdUSB);
848  DPRINT1("bDeviceClass %x\n", DeviceDescriptor->bDeviceClass);
849  DPRINT1("bDeviceSubClass %x\n", DeviceDescriptor->bDeviceSubClass);
850  DPRINT1("bDeviceProtocol %x\n", DeviceDescriptor->bDeviceProtocol);
851  DPRINT1("bMaxPacketSize0 %x\n", DeviceDescriptor->bMaxPacketSize0);
852  DPRINT1("idVendor %x\n", DeviceDescriptor->idVendor);
853  DPRINT1("idProduct %x\n", DeviceDescriptor->idProduct);
854  DPRINT1("bcdDevice %x\n", DeviceDescriptor->bcdDevice);
855  DPRINT1("iManufacturer %x\n", DeviceDescriptor->iManufacturer);
856  DPRINT1("iProduct %x\n", DeviceDescriptor->iProduct);
857  DPRINT1("iSerialNumber %x\n", DeviceDescriptor->iSerialNumber);
858  DPRINT1("bNumConfigurations %x\n", DeviceDescriptor->bNumConfigurations);
859 }
860 
861 //----------------------------------------------------------------------------------------
862 VOID
864 {
865  DPRINT1("Dumping ConfigurationDescriptor %p\n", ConfigurationDescriptor);
866  DPRINT1("bLength %x\n", ConfigurationDescriptor->bLength);
867  DPRINT1("bDescriptorType %x\n", ConfigurationDescriptor->bDescriptorType);
868  DPRINT1("wTotalLength %x\n", ConfigurationDescriptor->wTotalLength);
869  DPRINT1("bNumInterfaces %x\n", ConfigurationDescriptor->bNumInterfaces);
870  DPRINT1("bConfigurationValue %x\n", ConfigurationDescriptor->bConfigurationValue);
871  DPRINT1("iConfiguration %x\n", ConfigurationDescriptor->iConfiguration);
872  DPRINT1("bmAttributes %x\n", ConfigurationDescriptor->bmAttributes);
873  DPRINT1("MaxPower %x\n", ConfigurationDescriptor->MaxPower);
874 }
875 //----------------------------------------------------------------------------------------
876 NTSTATUS
880  OUT PVOID Buffer)
881 {
883  PMDL Mdl = NULL;
884 
885  if (BufferLength)
886  {
887  //
888  // allocate mdl
889  //
891  if (!Mdl)
892  {
893  //
894  // no memory
895  //
897  }
898 
899  //
900  // HACK HACK HACK: assume the buffer is build from non paged pool
901  //
903  }
904 
905  //
906  // commit setup packet
907  //
908  Status = CommitSetupPacket(SetupPacket, NULL, BufferLength, Mdl);
909 
910  if (Mdl != NULL)
911  {
912  //
913  // free mdl
914  //
915  IoFreeMdl(Mdl);
916  }
917 
918  //
919  // done
920  //
921  return Status;
922 }
923 //----------------------------------------------------------------------------------------
924 NTSTATUS
926  IN ULONG ConfigurationIndex,
927  IN PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor,
928  OUT PUSBD_INTERFACE_INFORMATION InterfaceInfo,
929  OUT PUSB_INTERFACE *OutUsbInterface)
930 {
931  PUSB_INTERFACE UsbInterface;
932  PUSB_ENDPOINT_DESCRIPTOR EndpointDescriptor;
933  ULONG PipeIndex;
934 
935  // allocate interface handle
936  UsbInterface = (PUSB_INTERFACE)ExAllocatePool(NonPagedPool, sizeof(USB_INTERFACE) + (InterfaceDescriptor->bNumEndpoints - 1) * sizeof(USB_ENDPOINT));
937  if (!UsbInterface)
938  {
939  // failed to allocate memory
941  }
942 
943  // zero descriptor
944  RtlZeroMemory(UsbInterface, sizeof(USB_INTERFACE) + (InterfaceDescriptor->bNumEndpoints - 1) * sizeof(USB_ENDPOINT));
945 
946  // store handle
947  InterfaceInfo->InterfaceHandle = (USBD_INTERFACE_HANDLE)UsbInterface;
948  InterfaceInfo->Class = InterfaceDescriptor->bInterfaceClass;
949  InterfaceInfo->SubClass = InterfaceDescriptor->bInterfaceSubClass;
950  InterfaceInfo->Protocol = InterfaceDescriptor->bInterfaceProtocol;
951  InterfaceInfo->Reserved = 0;
952 
953 
954  // init interface handle
955  UsbInterface->InterfaceDescriptor = InterfaceDescriptor;
956  InsertTailList(&m_ConfigurationDescriptors[ConfigurationIndex].InterfaceList, &UsbInterface->ListEntry);
957 
958  // grab first endpoint descriptor
959  EndpointDescriptor = (PUSB_ENDPOINT_DESCRIPTOR) (InterfaceDescriptor + 1);
960 
961  // now copy all endpoint information
962  for(PipeIndex = 0; PipeIndex < InterfaceDescriptor->bNumEndpoints; PipeIndex++)
963  {
964  while(EndpointDescriptor->bDescriptorType != USB_ENDPOINT_DESCRIPTOR_TYPE)
965  {
966  // skip intermediate descriptors
967  if (EndpointDescriptor->bLength == 0 || EndpointDescriptor->bDescriptorType == USB_INTERFACE_DESCRIPTOR_TYPE)
968  {
969  // bogus configuration descriptor
970  DPRINT1("[%s] Bogus descriptor found in InterfaceNumber %x Alternate %x EndpointIndex %x bLength %x bDescriptorType %x\n", m_USBType, InterfaceDescriptor->bInterfaceNumber, InterfaceDescriptor->bAlternateSetting, PipeIndex,
971  EndpointDescriptor->bLength, EndpointDescriptor->bDescriptorType);
972 
973  // failed
974  return STATUS_UNSUCCESSFUL;
975  }
976 
977  // move to next descriptor
978  EndpointDescriptor = (PUSB_ENDPOINT_DESCRIPTOR)((ULONG_PTR)EndpointDescriptor + EndpointDescriptor->bLength);
979  }
980 
981  // store in interface info
982  RtlCopyMemory(&UsbInterface->EndPoints[PipeIndex].EndPointDescriptor, EndpointDescriptor, sizeof(USB_ENDPOINT_DESCRIPTOR));
983 
984  DPRINT("Configuration Descriptor %p Length %lu\n", m_ConfigurationDescriptors[ConfigurationIndex].ConfigurationDescriptor, m_ConfigurationDescriptors[ConfigurationIndex].ConfigurationDescriptor->wTotalLength);
985  DPRINT("EndpointDescriptor %p DescriptorType %x bLength %x\n", EndpointDescriptor, EndpointDescriptor->bDescriptorType, EndpointDescriptor->bLength);
986  DPRINT("EndpointDescriptorHandle %p bAddress %x bmAttributes %x\n",&UsbInterface->EndPoints[PipeIndex], UsbInterface->EndPoints[PipeIndex].EndPointDescriptor.bEndpointAddress,
987  UsbInterface->EndPoints[PipeIndex].EndPointDescriptor.bmAttributes);
988 
989  // copy pipe info
990  InterfaceInfo->Pipes[PipeIndex].MaximumPacketSize = UsbInterface->EndPoints[PipeIndex].EndPointDescriptor.wMaxPacketSize;
991  InterfaceInfo->Pipes[PipeIndex].EndpointAddress = UsbInterface->EndPoints[PipeIndex].EndPointDescriptor.bEndpointAddress;
992  InterfaceInfo->Pipes[PipeIndex].Interval = UsbInterface->EndPoints[PipeIndex].EndPointDescriptor.bInterval;
993  InterfaceInfo->Pipes[PipeIndex].PipeType = (USBD_PIPE_TYPE)UsbInterface->EndPoints[PipeIndex].EndPointDescriptor.bmAttributes;
994  InterfaceInfo->Pipes[PipeIndex].PipeHandle = (PVOID)&UsbInterface->EndPoints[PipeIndex];
995 
996  // move to next descriptor
997  EndpointDescriptor = (PUSB_ENDPOINT_DESCRIPTOR)((ULONG_PTR)EndpointDescriptor + EndpointDescriptor->bLength);
998  }
999 
1000  if (OutUsbInterface)
1001  {
1002  // output result
1003  *OutUsbInterface = UsbInterface;
1004  }
1005  return STATUS_SUCCESS;
1006 
1007 }
1008 
1009 
1010 //----------------------------------------------------------------------------------------
1011 NTSTATUS
1013  IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
1014  IN PUSBD_INTERFACE_INFORMATION InterfaceInfo,
1016 {
1017  ULONG InterfaceIndex;
1019  NTSTATUS Status;
1020  UCHAR bConfigurationValue = 0;
1021  ULONG ConfigurationIndex = 0, Index;
1022  UCHAR Found = FALSE;
1023  PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
1024  PUSB_INTERFACE UsbInterface;
1026 
1027  if (ConfigurationDescriptor)
1028  {
1029  // find configuration index
1031  {
1032  if (m_ConfigurationDescriptors[Index].ConfigurationDescriptor->bConfigurationValue == ConfigurationDescriptor->bConfigurationValue)
1033  {
1034  // found configuration index
1035  ConfigurationIndex = Index;
1036  Found = TRUE;
1037  }
1038  }
1039 
1040  if (!Found)
1041  {
1042  DPRINT1("[%s] invalid configuration value %u\n", m_USBType, ConfigurationDescriptor->bConfigurationValue);
1043  return STATUS_INVALID_PARAMETER;
1044  }
1045 
1046  // sanity check
1047  ASSERT(ConfigurationDescriptor->bNumInterfaces <= m_ConfigurationDescriptors[ConfigurationIndex].ConfigurationDescriptor->bNumInterfaces);
1048 
1049  // get configuration value
1050  bConfigurationValue = ConfigurationDescriptor->bConfigurationValue;
1051  }
1052 
1053  // now build setup packet
1054  RtlZeroMemory(&CtrlSetup, sizeof(USB_DEFAULT_PIPE_SETUP_PACKET));
1056  CtrlSetup.wValue.W = bConfigurationValue;
1057 
1058  // select configuration
1059  Status = CommitSetupPacket(&CtrlSetup, NULL, 0, NULL);
1060 
1061  if (!ConfigurationDescriptor)
1062  {
1063  // unconfigure request
1064  DPRINT1("[%s] SelectConfiguration Unconfigure Request Status %lx\n", m_USBType, Status);
1066  return Status;
1067  }
1068 
1069  // informal debug print
1070  DPRINT("[%s] SelectConfiguration New Configuration %x Old Configuration %x Result %lx\n", m_USBType, ConfigurationIndex, m_ConfigurationIndex, Status);
1071  if (!NT_SUCCESS(Status))
1072  {
1073  //
1074  // failed
1075  //
1076  return Status;
1077  }
1078 
1079  // destroy old interface info
1081  {
1082  // remove entry
1084 
1085  // get interface info
1086  UsbInterface = (PUSB_INTERFACE)CONTAINING_RECORD(Entry, USB_INTERFACE, ListEntry);
1087 
1088  // free interface info
1089  ExFreePool(UsbInterface);
1090  }
1091 
1092  // sanity check
1094 
1095  // store new configuration device index
1096  m_ConfigurationIndex = ConfigurationIndex;
1097 
1098  // store configuration handle
1099  *ConfigurationHandle = &m_ConfigurationDescriptors[ConfigurationIndex];
1100 
1101  // copy interface info and pipe info
1102  for(InterfaceIndex = 0; InterfaceIndex < ConfigurationDescriptor->bNumInterfaces; InterfaceIndex++)
1103  {
1104  // interface info checks
1105  ASSERT(InterfaceInfo->Length != 0);
1106 
1107 #ifdef _MSC_VER
1108  PC_ASSERT(InterfaceInfo->Length == FIELD_OFFSET(USBD_INTERFACE_INFORMATION, Pipes[InterfaceInfo->NumberOfPipes]));
1109 #endif
1110 
1111  // find interface descriptor
1112  InterfaceDescriptor = USBD_ParseConfigurationDescriptor(m_ConfigurationDescriptors[ConfigurationIndex].ConfigurationDescriptor, InterfaceInfo->InterfaceNumber, InterfaceInfo->AlternateSetting);
1113 
1114  // sanity checks
1115  ASSERT(InterfaceDescriptor != NULL);
1116 
1117  // check if the number of pipes have been properly set
1118  ASSERT(InterfaceInfo->NumberOfPipes == InterfaceDescriptor->bNumEndpoints);
1119 
1120  // copy interface info
1121  Status = BuildInterfaceDescriptor(ConfigurationIndex, InterfaceDescriptor, InterfaceInfo, NULL);
1122  if (!NT_SUCCESS(Status))
1123  {
1124  // failed
1125  DPRINT1("[%s] Failed to copy interface descriptor Index %lu InterfaceDescriptor %p InterfaceInfo %p\n", m_USBType, ConfigurationIndex, InterfaceDescriptor, InterfaceInfo);
1126  break;
1127  }
1128 
1129  // move offset
1130  InterfaceInfo = (PUSBD_INTERFACE_INFORMATION)((PUCHAR)InterfaceInfo + InterfaceInfo->Length);
1131  }
1132 
1133  //
1134  // done
1135  //
1136  return Status;
1137 }
1138 
1139 //----------------------------------------------------------------------------------------
1140 NTSTATUS
1143  IN OUT PUSBD_INTERFACE_INFORMATION InterfaceInfo)
1144 {
1145  ULONG PipeIndex;
1147  NTSTATUS Status;
1148  ULONG Index, ConfigurationIndex = 0, Found = FALSE;
1149  PUSB_INTERFACE UsbInterface;
1151  PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
1152 
1153  // check if handle is valid
1155  {
1157  {
1158  // found configuration index
1159  ConfigurationIndex = Index;
1160  Found = TRUE;
1161  }
1162  }
1163 
1164  if (!Found)
1165  {
1166  // invalid handle passed
1167  DPRINT1("[%s] Invalid configuration handle passed %p\n", m_USBType, ConfigurationHandle);
1168  return STATUS_INVALID_PARAMETER;
1169  }
1170 
1171  // initialize setup packet
1172  RtlZeroMemory(&CtrlSetup, sizeof(USB_DEFAULT_PIPE_SETUP_PACKET));
1173  CtrlSetup.bRequest = USB_REQUEST_SET_INTERFACE;
1174  CtrlSetup.wValue.W = InterfaceInfo->AlternateSetting;
1175  CtrlSetup.wIndex.W = InterfaceInfo->InterfaceNumber;
1176  CtrlSetup.bmRequestType.B = 0x01;
1177 
1178  // issue request
1179  Status = CommitSetupPacket(&CtrlSetup, NULL, 0, NULL);
1180 
1181  // informal debug print
1182  DPRINT1("[%s] SelectInterface AlternateSetting %x InterfaceNumber %x Status %lx\n", m_USBType, InterfaceInfo->AlternateSetting, InterfaceInfo->InterfaceNumber, Status);
1183 #if 0
1184  if (!NT_SUCCESS(Status))
1185  {
1186  // failed to select interface
1187  return Status;
1188  }
1189 #endif
1190 
1192 
1193  // find interface
1194  Found = FALSE;
1195  Entry = m_ConfigurationDescriptors[ConfigurationIndex].InterfaceList.Flink;
1196  while (Entry != &m_ConfigurationDescriptors[ConfigurationIndex].InterfaceList)
1197  {
1198  // grab interface descriptor
1199  UsbInterface = (PUSB_INTERFACE)CONTAINING_RECORD(Entry, USB_INTERFACE, ListEntry);
1200  if (UsbInterface->InterfaceDescriptor->bAlternateSetting == InterfaceInfo->AlternateSetting &&
1201  UsbInterface->InterfaceDescriptor->bInterfaceNumber == InterfaceInfo->InterfaceNumber)
1202  {
1203  // found interface
1204  Found = TRUE;
1205  break;
1206  }
1207 
1208  // next entry
1209  Entry = Entry->Flink;
1210  }
1211 
1212  if (!Found)
1213  {
1214  // find interface descriptor
1215  InterfaceDescriptor = USBD_ParseConfigurationDescriptor(m_ConfigurationDescriptors[ConfigurationIndex].ConfigurationDescriptor, InterfaceInfo->InterfaceNumber, InterfaceInfo->AlternateSetting);
1216  if (!InterfaceDescriptor)
1217  {
1218  DPRINT1("[%s] No such interface Alternate %x InterfaceNumber %x\n", m_USBType, InterfaceInfo->AlternateSetting, InterfaceInfo->InterfaceNumber);
1219  return STATUS_UNSUCCESSFUL;
1220  }
1221 
1222  // build interface descriptor
1223  Status = BuildInterfaceDescriptor(ConfigurationIndex, InterfaceDescriptor, InterfaceInfo, &UsbInterface);
1224  if (!NT_SUCCESS(Status))
1225  {
1226  // failed
1227  DPRINT1("[%s] Failed to build interface descriptor Status %x\n", m_USBType, Status);
1228  return Status;
1229  }
1230  }
1231 
1232  // assert on pipe length mismatch
1233  DPRINT1("NumberOfPipes %lu Endpoints %lu Length %lu\n", InterfaceInfo->NumberOfPipes, UsbInterface->InterfaceDescriptor->bNumEndpoints, InterfaceInfo->Length);
1234 
1235  // sanity check
1236  ASSERT(GET_USBD_INTERFACE_SIZE(UsbInterface->InterfaceDescriptor->bNumEndpoints) == InterfaceInfo->Length);
1237 
1238  // store number of pipes
1239  InterfaceInfo->NumberOfPipes = UsbInterface->InterfaceDescriptor->bNumEndpoints;
1240 
1241  // copy pipe handles
1242  for (PipeIndex = 0; PipeIndex < UsbInterface->InterfaceDescriptor->bNumEndpoints; PipeIndex++)
1243  {
1244  // copy pipe handle
1245  DPRINT1("PipeIndex %lu\n", PipeIndex);
1246  DPRINT1("EndpointAddress %x\n", InterfaceInfo->Pipes[PipeIndex].EndpointAddress);
1247  DPRINT1("Interval %c\n", InterfaceInfo->Pipes[PipeIndex].Interval);
1248  DPRINT1("MaximumPacketSize %hu\n", InterfaceInfo->Pipes[PipeIndex].MaximumPacketSize);
1249  DPRINT1("MaximumTransferSize %lu\n", InterfaceInfo->Pipes[PipeIndex].MaximumTransferSize);
1250  DPRINT1("PipeFlags %lu\n", InterfaceInfo->Pipes[PipeIndex].PipeFlags);
1251  DPRINT1("PipeType %d\n", InterfaceInfo->Pipes[PipeIndex].PipeType);
1252  DPRINT1("UsbEndPoint %x\n", InterfaceInfo->Pipes[PipeIndex].EndpointAddress);
1253 
1254  // sanity checks
1255  ASSERT(InterfaceInfo->Pipes[PipeIndex].EndpointAddress == UsbInterface->EndPoints[PipeIndex].EndPointDescriptor.bEndpointAddress);
1256  ASSERT(InterfaceInfo->Pipes[PipeIndex].Interval == UsbInterface->EndPoints[PipeIndex].EndPointDescriptor.bInterval);
1257 
1258  // store pipe handle
1259  InterfaceInfo->Pipes[PipeIndex].PipeHandle = &UsbInterface->EndPoints[PipeIndex];
1260 
1261  // data toggle is reset on select interface requests
1262  UsbInterface->EndPoints[PipeIndex].DataToggle = FALSE;
1263  }
1264 
1265  //
1266  // done
1267  //
1268  return Status;
1269 }
1270 
1271 NTSTATUS
1273  IN PUSB_ENDPOINT_DESCRIPTOR EndpointDescriptor)
1274 {
1275  //
1276  // let it handle usb queue
1277  //
1278  ASSERT(m_Queue);
1280 
1281  //
1282  // done
1283  //
1284  return m_Queue->AbortDevicePipe(m_DeviceAddress, EndpointDescriptor);
1285 }
1286 
1287 UCHAR
1289 {
1291 }
1292 
1293 
1294 //----------------------------------------------------------------------------------------
1295 NTSTATUS
1296 NTAPI
1298  PUSBDEVICE *OutDevice)
1299 {
1300  CUSBDevice * This;
1301 
1302  //
1303  // allocate controller
1304  //
1306  if (!This)
1307  {
1308  //
1309  // failed to allocate
1310  //
1312  }
1313 
1314  //
1315  // add reference count
1316  //
1317  This->AddRef();
1318 
1319  //
1320  // return result
1321  //
1322  *OutDevice = (PUSBDEVICE)This;
1323 
1324  //
1325  // done
1326  //
1327  return STATUS_SUCCESS;
1328 }
1329 
#define USB_PORT_STATUS_LOW_SPEED
Definition: usb200.h:157
enum _USB_DEVICE_TYPE USB_DEVICE_TYPE
struct _USB_DEVICE_DESCRIPTOR USB_DEVICE_DESCRIPTOR
CPPORT Port[4]
Definition: headless.c:34
#define IN
Definition: typedefs.h:38
#define REFIID
Definition: guiddef.h:113
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_Inout_ PUSB_DEVICE_HANDLE _Out_writes_bytes_to_ DeviceDescriptorBufferLength PUCHAR _Inout_ PULONG _Out_writes_bytes_to_ ConfigDescriptorBufferLength PUCHAR ConfigDescriptorBuffer
Definition: hubbusif.h:151
PHUBCONTROLLER m_HubController
Definition: usb_device.cpp:78
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define PC_ASSERT(exp)
Definition: usbehci.h:17
IUSBHardwareDevice * PUSBHARDWAREDEVICE
_In_ PIRP _In_ PDEVICE_OBJECT Device
Definition: fatprocs.h:2020
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1530
struct _Entry Entry
Definition: kefuncs.h:640
_In_ BOOLEAN Release
Definition: classpnp.h:929
#define USB_REQUEST_SET_ADDRESS
Definition: usb100.h:81
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define USB_REQUEST_SET_INTERFACE
Definition: usb100.h:87
unsigned char * PUCHAR
Definition: retypes.h:3
union _USB_DEFAULT_PIPE_SETUP_PACKET::_wIndex wIndex
_In_ PUSBD_INTERFACE_LIST_ENTRY InterfaceList
Definition: usbdlib.h:168
USB_ENDPOINT_DESCRIPTOR EndPointDescriptor
VOID NTAPI MmBuildMdlForNonPagedPool(IN PMDL Mdl)
Definition: mdlsup.c:428
KSPIN_LOCK m_Lock
Definition: usb_device.cpp:85
LONG NTSTATUS
Definition: precomp.h:26
struct _USBD_INTERFACE_INFORMATION * PUSBD_INTERFACE_INFORMATION
struct USB_CONFIGURATION * PUSB_CONFIGURATION
virtual NTSTATUS CommitIrp(PIRP Irp)
Definition: usb_device.cpp:420
virtual NTSTATUS Initialize(IN PHUBCONTROLLER HubController, IN PUSBHARDWAREDEVICE Device, IN PVOID Parent, IN ULONG Port, IN ULONG PortStatus)
Definition: usb_device.cpp:107
virtual UCHAR GetMaxPacketSize()
virtual ULONG GetConfigurationDescriptorsLength()
Definition: usb_device.cpp:831
STDMETHODIMP_(ULONG) AddRef()
Definition: usb_device.cpp:21
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER void *Data ACPI_OBJECT_HANDLER void **Data ACPI_STRING ACPI_OBJECT_LIST ACPI_BUFFER *ReturnObjectBuffer ACPI_DEVICE_INFO **ReturnBuffer ACPI_HANDLE Parent
Definition: acpixf.h:716
#define InsertTailList(ListHead, Entry)
PUSB_INTERFACE_DESCRIPTOR NTAPI USBD_ParseConfigurationDescriptor(PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, UCHAR InterfaceNumber, UCHAR AlternateSetting)
Definition: usbd.c:604
virtual NTSTATUS AbortPipe(IN PUSB_ENDPOINT_DESCRIPTOR EndpointDescriptor)
#define USB_PORT_STATUS_HIGH_SPEED
Definition: usb200.h:158
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
enum _USBD_PIPE_TYPE USBD_PIPE_TYPE
PUSB_CONFIGURATION m_ConfigurationDescriptors
Definition: usb_device.cpp:92
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG_PTR
Definition: typedefs.h:63
virtual ULONG GetPort()
Definition: usb_device.cpp:225
struct _USB_CONFIGURATION_DESCRIPTOR * PUSB_CONFIGURATION_DESCRIPTOR
virtual void SetDeviceHandleData(PVOID Data)
Definition: usb_device.cpp:296
_In_ NDIS_HANDLE _In_ PNDIS_REQUEST Request
Definition: ndis.h:5155
UCHAR KIRQL
Definition: env_spec_w32.h:591
IUSBDevice * PUSBDEVICE
virtual VOID GetConfigurationDescriptors(IN PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptorBuffer, IN ULONG BufferLength, OUT PULONG OutBufferLength)
Definition: usb_device.cpp:805
LIST_ENTRY InterfaceList
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define USB_DEVICE_DESCRIPTOR_TYPE
Definition: usb100.h:49
_In_ PUSB_DEVICE_HANDLE _Out_ PUSHORT DeviceAddress
Definition: hubbusif.h:359
long LONG
Definition: pedump.c:60
PVOID m_Parent
Definition: usb_device.cpp:80
_In_ ULONG BufferLength
Definition: usbdlib.h:225
#define BMREQUEST_DEVICE_TO_HOST
Definition: usb100.h:32
#define USB_CONFIGURATION_DESCRIPTOR_TYPE
Definition: usb100.h:50
#define STDMETHODIMP
Definition: basetyps.h:43
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
UCHAR m_DeviceAddress
Definition: usb_device.cpp:82
unsigned char BOOLEAN
#define USB_INTERFACE_DESCRIPTOR_TYPE
Definition: usb100.h:52
UCHAR m_ConfigurationIndex
Definition: usb_device.cpp:84
smooth NULL
Definition: ftsmooth.c:416
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
void DPRINT(...)
Definition: polytest.cpp:61
virtual NTSTATUS SubmitSetupPacket(IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket, OUT ULONG BufferLength, OUT PVOID Buffer)
Definition: usb_device.cpp:877
Definition: bufpool.h:45
USB_ENDPOINT EndPoints[1]
virtual UCHAR GetConfigurationValue()
Definition: usb_device.cpp:410
return Found
Definition: dirsup.c:1270
const char * LPCSTR
Definition: xmlstorage.h:183
virtual VOID DumpDeviceDescriptor(PUSB_DEVICE_DESCRIPTOR DeviceDescriptor)
Definition: usb_device.cpp:842
struct _USB_ENDPOINT_DESCRIPTOR * PUSB_ENDPOINT_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
virtual NTSTATUS CommitSetupPacket(PUSB_DEFAULT_PIPE_SETUP_PACKET Packet, IN OPTIONAL PUSB_ENDPOINT EndpointDescriptor, IN ULONG BufferLength, IN OUT PMDL Mdl)
Definition: usb_device.cpp:506
virtual BOOLEAN IsHub()
Definition: usb_device.cpp:188
enum _USB_DEVICE_SPEED USB_DEVICE_SPEED
#define USB_REQUEST_SET_CONFIGURATION
Definition: usb100.h:85
#define TAG_USBLIB
Definition: libusb.h:70
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
IN PVOID IN PVOID IN USHORT IN USHORT IN PINTERFACE Interface
Definition: pci.h:359
const KSDEVICE_DESCRIPTOR DeviceDescriptor
Definition: splitter.c:257
UCHAR bNumConfigurations
Definition: usb100.h:124
STDMETHODIMP QueryInterface(REFIID InterfaceId, PVOID *Interface)
Definition: usb_device.cpp:98
virtual USB_DEVICE_SPEED GetSpeed()
Definition: usb_device.cpp:235
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define STATUS_PENDING
Definition: ntstatus.h:82
virtual UCHAR GetDeviceAddress()
Definition: usb_device.cpp:215
virtual NTSTATUS GetParent(PVOID *Parent)
Definition: usb_device.cpp:199
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
static const UCHAR Index[8]
Definition: usbohci.c:18
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
#define BufferSize
Definition: classpnp.h:419
nsrefcnt Release()
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
virtual NTSTATUS SelectInterface(IN USBD_CONFIGURATION_HANDLE ConfigurationHandle, IN OUT PUSBD_INTERFACE_INFORMATION Interface)
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
ULONG m_Port
Definition: usb_device.cpp:81
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define USB_REQUEST_GET_DESCRIPTOR
Definition: usb100.h:82
PUSBHARDWAREDEVICE m_Device
Definition: usb_device.cpp:79
#define GET_USBD_INTERFACE_SIZE(numEndpoints)
Definition: usbdlib.h:108
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_HANDLE ConfigurationHandle
Definition: ndis.h:3926
unsigned char UCHAR
Definition: xmlstorage.h:181
virtual ULONG GetState()
Definition: usb_device.cpp:288
#define InterlockedDecrement
Definition: armddk.h:52
virtual NTSTATUS CreateDeviceDescriptor()
Definition: usb_device.cpp:583
LPCSTR m_USBType
Definition: usb_device.cpp:90
Definition: arc.h:85
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
CUSBDevice(IUnknown *OuterUnknown)
Definition: usb_device.cpp:73
#define USB_ENDPOINT_DESCRIPTOR_TYPE
Definition: usb100.h:53
virtual NTSTATUS SubmitIrp(PIRP Irp)
Definition: usb_device.cpp:480
#define PAGE_SIZE
Definition: env_spec_w32.h:49
Definition: typedefs.h:117
PVOID m_Data
Definition: usb_device.cpp:83
_Outptr_ PUSB_DEVICE_HANDLE _In_ PUSB_DEVICE_HANDLE _In_ USHORT PortStatus
Definition: hubbusif.h:40
LIST_ENTRY ListEntry
ULONG m_PortStatus
Definition: usb_device.cpp:87
Status
Definition: gdiplustypes.h:24
#define BMREQUEST_STANDARD
Definition: usb100.h:34
NTSTATUS NTAPI CreateUSBDevice(PUSBDEVICE *OutDevice)
PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
PDMAMEMORYMANAGER m_DmaManager
Definition: usb_device.cpp:89
STDMETHODIMP_(ULONG) Release()
Definition: usb_device.cpp:26
virtual NTSTATUS BuildInterfaceDescriptor(IN ULONG ConfigurationIndex, IN PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor, OUT PUSBD_INTERFACE_INFORMATION InterfaceInfo, OUT PUSB_INTERFACE *OutUsbInterface)
Definition: usb_device.cpp:925
#define InterlockedIncrement
Definition: armddk.h:53
IUSBQueue * PUSBQUEUE
unsigned short USHORT
Definition: pedump.c:61
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
IUSBRequest * PUSBREQUEST
ULONG KSPIN_LOCK
Definition: env_spec_w32.h:72
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
struct _USB_INTERFACE * PUSB_INTERFACE
unsigned int * PULONG
Definition: retypes.h:1
#define min(a, b)
Definition: monoChain.cc:55
IDMAMemoryManager * PDMAMEMORYMANAGER
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
static ULONG WINAPI AddRef(IStream *iface)
Definition: clist.c:90
struct _USB_DEFAULT_PIPE_SETUP_PACKET * PUSB_DEFAULT_PIPE_SETUP_PACKET
PUSBQUEUE m_Queue
Definition: usb_device.cpp:88
#define DPRINT1
Definition: precomp.h:8
USB_DEVICE_DESCRIPTOR m_DeviceDescriptor
Definition: usb_device.cpp:86
union _USB_DEFAULT_PIPE_SETUP_PACKET::_wValue wValue
#define OUT
Definition: typedefs.h:39
virtual NTSTATUS CreateConfigurationDescriptor(UCHAR ConfigurationIndex)
Definition: usb_device.cpp:729
unsigned int ULONG
Definition: retypes.h:1
virtual NTSTATUS GetConfigurationDescriptor(UCHAR ConfigurationIndex, USHORT BufferSize, PVOID Buffer)
Definition: usb_device.cpp:670
#define UNIMPLEMENTED
Definition: debug.h:114
IHubController * PHUBCONTROLLER
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
virtual ~CUSBDevice()
Definition: usb_device.cpp:74
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
virtual VOID DumpConfigurationDescriptor(PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor)
Definition: usb_device.cpp:863
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
PVOID USBD_INTERFACE_HANDLE
Definition: usb.h:231
return STATUS_SUCCESS
Definition: btrfs.c:2725
BM_REQUEST_TYPE bmRequestType
Definition: usb200.h:72
IoMarkIrpPending(Irp)
virtual NTSTATUS SetDeviceAddress(UCHAR DeviceAddress)
Definition: usb_device.cpp:307
#define BMREQUEST_TO_DEVICE
Definition: usb100.h:38
VOID NTAPI KeStallExecutionProcessor(IN ULONG MicroSeconds)
Definition: ntoskrnl.c:99
base of all file and directory entries
Definition: entries.h:82
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
virtual NTSTATUS SelectConfiguration(IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, IN PUSBD_INTERFACE_INFORMATION Interface, OUT USBD_CONFIGURATION_HANDLE *ConfigurationHandle)
virtual void GetDeviceDescriptor(PUSB_DEVICE_DESCRIPTOR DeviceDescriptor)
Definition: usb_device.cpp:402
PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor
virtual USB_DEVICE_TYPE GetType()
Definition: usb_device.cpp:260
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68