Reactos
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 */
18IO_COMPLETION_ROUTINE SyncForwardIrpCompletionRoutine;
19
20NTSTATUS
21NTAPI
22USBSTOR_SyncForwardIrpCompletionRoutine(
23 PDEVICE_OBJECT DeviceObject,
24 PIRP Irp,
25 PVOID Context)
26{
27 if (Irp->PendingReturned)
28 {
29 KeSetEvent((PKEVENT)Context, IO_NO_INCREMENT, FALSE);
30 }
31 return STATUS_MORE_PROCESSING_REQUIRED;
32}
33
34NTSTATUS
35USBCCGP_SyncUrbRequest(
36 IN PDEVICE_OBJECT DeviceObject,
37 OUT PURB UrbRequest)
38{
39 PIRP Irp;
40 PIO_STACK_LOCATION IoStack;
41 KEVENT Event;
42 NTSTATUS Status;
43
44 /* Allocate irp */
45 Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
46 if (!Irp)
47 {
48 /* No memory */
49 return STATUS_INSUFFICIENT_RESOURCES;
50 }
51
52 /* Initialize event */
53 KeInitializeEvent(&Event, NotificationEvent, FALSE);
54
55 /* Get next stack location */
56 IoStack = IoGetNextIrpStackLocation(Irp);
57
58 /* Initialize stack location */
59 IoStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
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 */
66 IoSetCompletionRoutine(Irp,
67 USBSTOR_SyncForwardIrpCompletionRoutine,
68 &Event,
69 TRUE,
70 TRUE,
71 TRUE);
72
73 /* Call driver */
74 Status = IoCallDriver(DeviceObject, Irp);
75
76 /* Check if request is pending */
77 if (Status == STATUS_PENDING)
78 {
79 /* Wait for completion */
80 KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
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
93PVOID
94AllocateItem(
95 IN POOL_TYPE PoolType,
96 IN ULONG ItemSize)
97{
98 /* Allocate, zero and return item */
99 return ExAllocatePoolZero(PoolType, ItemSize, USBCCPG_TAG);
100}
101
102VOID
103FreeItem(
104 IN PVOID Item)
105{
106 /* Free item */
107 ExFreePoolWithTag(Item, USBCCPG_TAG);
108}
109
110VOID
111DumpFunctionDescriptor(
112 IN PUSBC_FUNCTION_DESCRIPTOR FunctionDescriptor,
113 IN ULONG FunctionDescriptorCount)
114{
115 ULONG Index, SubIndex;
116
117 DPRINT("FunctionCount %lu\n", FunctionDescriptorCount);
118 for (Index = 0; Index < FunctionDescriptorCount; Index++)
119 {
120 DPRINT("Function %lu\n", Index);
121 DPRINT("FunctionNumber %lu\n", FunctionDescriptor[Index].FunctionNumber);
122 DPRINT("HardwareId %S\n", FunctionDescriptor[Index].HardwareId.Buffer);
123 DPRINT("CompatibleId %S\n", FunctionDescriptor[Index].CompatibleId.Buffer);
124 DPRINT("FunctionDescription %wZ\n", &FunctionDescriptor[Index].FunctionDescription);
125 DPRINT("NumInterfaces %lu\n", FunctionDescriptor[Index].NumberOfInterfaces);
126
127 for(SubIndex = 0; SubIndex < FunctionDescriptor[Index].NumberOfInterfaces; SubIndex++)
128 {
129 DPRINT(" Index %lu Interface %p\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]);
130 DPRINT(" Index %lu Interface InterfaceNumber %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceNumber);
131 DPRINT(" Index %lu Interface Alternate %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bAlternateSetting );
132 DPRINT(" Index %lu bLength %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bLength);
133 DPRINT(" Index %lu bDescriptorType %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bDescriptorType);
134 DPRINT(" Index %lu bInterfaceNumber %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceNumber);
135 DPRINT(" Index %lu bAlternateSetting %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bAlternateSetting);
136 DPRINT(" Index %lu bNumEndpoints %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bNumEndpoints);
137 DPRINT(" Index %lu bInterfaceClass %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceClass);
138 DPRINT(" Index %lu bInterfaceSubClass %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceSubClass);
139 DPRINT(" Index %lu bInterfaceProtocol %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceProtocol);
140 DPRINT(" Index %lu iInterface %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->iInterface);
141 }
142 }
143}