ReactOS  0.4.15-dev-5122-g72bdbdd
misc.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Universal Serial Bus Bulk Enhanced Host Controller Interface
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: drivers/usb/usbccgp/misc.c
5  * PURPOSE: USB device driver.
6  * PROGRAMMERS:
7  * Michael Martin (michael.martin@reactos.org)
8  * Johannes Anderwald (johannes.anderwald@reactos.org)
9  * Cameron Gutman
10  */
11 
12 #include "usbccgp.h"
13 
14 #define NDEBUG
15 #include <debug.h>
16 
17 /* Driver verifier */
18 IO_COMPLETION_ROUTINE SyncForwardIrpCompletionRoutine;
19 
21 NTAPI
24  PIRP Irp,
25  PVOID Context)
26 {
27  if (Irp->PendingReturned)
28  {
30  }
32 }
33 
37  OUT PURB UrbRequest)
38 {
39  PIRP Irp;
40  PIO_STACK_LOCATION IoStack;
41  KEVENT Event;
43 
44  /* Allocate irp */
45  Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
46  if (!Irp)
47  {
48  /* No memory */
50  }
51 
52  /* Initialize event */
54 
55  /* Get next stack location */
56  IoStack = IoGetNextIrpStackLocation(Irp);
57 
58  /* Initialize stack location */
60  IoStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB;
61  IoStack->Parameters.Others.Argument1 = (PVOID)UrbRequest;
62  IoStack->Parameters.DeviceIoControl.InputBufferLength = UrbRequest->UrbHeader.Length;
63  Irp->IoStatus.Status = STATUS_SUCCESS;
64 
65  /* Setup completion routine */
68  &Event,
69  TRUE,
70  TRUE,
71  TRUE);
72 
73  /* Call driver */
75 
76  /* Check if request is pending */
77  if (Status == STATUS_PENDING)
78  {
79  /* Wait for completion */
81 
82  /* Update status */
83  Status = Irp->IoStatus.Status;
84  }
85 
86  /* Free irp */
87  IoFreeIrp(Irp);
88 
89  /* Done */
90  return Status;
91 }
92 
93 PVOID
97 {
98  /* Allocate item */
100 
101  if (Item)
102  {
103  /* Zero item */
105  }
106 
107  /* Return element */
108  return Item;
109 }
110 
111 VOID
113  IN PVOID Item)
114 {
115  /* Free item */
117 }
118 
119 VOID
121  IN PUSBC_FUNCTION_DESCRIPTOR FunctionDescriptor,
122  IN ULONG FunctionDescriptorCount)
123 {
124  ULONG Index, SubIndex;
125 
126 
127  DPRINT("FunctionCount %lu\n", FunctionDescriptorCount);
128  for (Index = 0; Index < FunctionDescriptorCount; Index++)
129  {
130  DPRINT("Function %lu\n", Index);
131  DPRINT("FunctionNumber %lu\n", FunctionDescriptor[Index].FunctionNumber);
132  DPRINT("HardwareId %S\n", FunctionDescriptor[Index].HardwareId.Buffer);
133  DPRINT("CompatibleId %S\n", FunctionDescriptor[Index].CompatibleId.Buffer);
134  DPRINT("FunctionDescription %wZ\n", &FunctionDescriptor[Index].FunctionDescription);
135  DPRINT("NumInterfaces %lu\n", FunctionDescriptor[Index].NumberOfInterfaces);
136 
137  for(SubIndex = 0; SubIndex < FunctionDescriptor[Index].NumberOfInterfaces; SubIndex++)
138  {
139  DPRINT(" Index %lu Interface %p\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]);
140  DPRINT(" Index %lu Interface InterfaceNumber %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceNumber);
141  DPRINT(" Index %lu Interface Alternate %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bAlternateSetting );
142  DPRINT(" Index %lu bLength %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bLength);
143  DPRINT(" Index %lu bDescriptorType %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bDescriptorType);
144  DPRINT(" Index %lu bInterfaceNumber %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceNumber);
145  DPRINT(" Index %lu bAlternateSetting %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bAlternateSetting);
146  DPRINT(" Index %lu bNumEndpoints %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bNumEndpoints);
147  DPRINT(" Index %lu bInterfaceClass %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceClass);
148  DPRINT(" Index %lu bInterfaceSubClass %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceSubClass);
149  DPRINT(" Index %lu bInterfaceProtocol %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceProtocol);
150  DPRINT(" Index %lu iInterface %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->iInterface);
151  }
152  }
153 }
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
#define IN
Definition: typedefs.h:39
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define IOCTL_INTERNAL_USB_SUBMIT_URB
Definition: usbioctl.h:32
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:498
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:467
NTSTATUS NTAPI USBSTOR_SyncForwardIrpCompletionRoutine(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
Definition: misc.c:22
Status
Definition: gdiplustypes.h:24
#define STATUS_PENDING
Definition: ntstatus.h:82
INT POOL_TYPE
Definition: typedefs.h:78
_In_ WDFCOLLECTION _In_ ULONG Index
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
IO_COMPLETION_ROUTINE SyncForwardIrpCompletionRoutine
Definition: misc.c:18
static UCHAR ItemSize[4]
Definition: parser.c:16
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
VOID DumpFunctionDescriptor(IN PUSBC_FUNCTION_DESCRIPTOR FunctionDescriptor, IN ULONG FunctionDescriptorCount)
Definition: misc.c:120
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
Definition: usb.h:529
NTSTATUS USBCCGP_SyncUrbRequest(IN PDEVICE_OBJECT DeviceObject, OUT PURB UrbRequest)
Definition: misc.c:35
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
_In_ WDFCOLLECTION _In_ WDFOBJECT Item
#define USBCCPG_TAG
Definition: usbccgp.h:39
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
#define OUT
Definition: typedefs.h:40
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE PoolType
Definition: wdfdevice.h:3810
static PVOID
Definition: misc.c:50
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099