[DELAYIMP] Fix 2 Clang-Cl warnings about __pfnDliNotifyHook2Default and __pfnDliFailu...
[reactos.git] / sdk / lib / drivers / libusb / misc.cpp
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/misc.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 //
17 // driver verifier
18 //
19 IO_COMPLETION_ROUTINE SyncForwardIrpCompletionRoutine;
20
21 NTSTATUS
22 NTAPI
23 SyncForwardIrpCompletionRoutine(
24 PDEVICE_OBJECT DeviceObject,
25 PIRP Irp,
26 PVOID Context)
27 {
28 if (Irp->PendingReturned)
29 {
30 KeSetEvent((PKEVENT)Context, IO_NO_INCREMENT, FALSE);
31 }
32 return STATUS_MORE_PROCESSING_REQUIRED;
33 }
34
35 NTSTATUS
36 NTAPI
37 SyncForwardIrp(PDEVICE_OBJECT DeviceObject, PIRP Irp)
38 {
39 KEVENT Event;
40 NTSTATUS Status;
41
42 //
43 // initialize event
44 //
45 KeInitializeEvent(&Event, NotificationEvent, FALSE);
46
47 //
48 // copy irp stack location
49 //
50 IoCopyCurrentIrpStackLocationToNext(Irp);
51
52 //
53 // set completion routine
54 //
55 IoSetCompletionRoutine(Irp, SyncForwardIrpCompletionRoutine, &Event, TRUE, TRUE, TRUE);
56
57
58 //
59 // call driver
60 //
61 Status = IoCallDriver(DeviceObject, Irp);
62
63
64 //
65 // check if pending
66 //
67 if (Status == STATUS_PENDING)
68 {
69 //
70 // wait for the request to finish
71 //
72 KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
73
74 //
75 // copy status code
76 //
77 Status = Irp->IoStatus.Status;
78 }
79
80 //
81 // done
82 //
83 return Status;
84 }
85
86 NTSTATUS
87 NTAPI
88 GetBusInterface(
89 PDEVICE_OBJECT DeviceObject,
90 PBUS_INTERFACE_STANDARD busInterface)
91 {
92 KEVENT Event;
93 NTSTATUS Status;
94 PIRP Irp;
95 IO_STATUS_BLOCK IoStatus;
96 PIO_STACK_LOCATION Stack;
97
98 if ((!DeviceObject) || (!busInterface))
99 return STATUS_UNSUCCESSFUL;
100
101 KeInitializeEvent(&Event, NotificationEvent, FALSE);
102
103 Irp = IoBuildSynchronousFsdRequest(IRP_MJ_PNP,
104 DeviceObject,
105 NULL,
106 0,
107 NULL,
108 &Event,
109 &IoStatus);
110
111 if (Irp == NULL)
112 {
113 return STATUS_INSUFFICIENT_RESOURCES;
114 }
115
116 Stack=IoGetNextIrpStackLocation(Irp);
117 Stack->MajorFunction = IRP_MJ_PNP;
118 Stack->MinorFunction = IRP_MN_QUERY_INTERFACE;
119 Stack->Parameters.QueryInterface.Size = sizeof(BUS_INTERFACE_STANDARD);
120 Stack->Parameters.QueryInterface.InterfaceType = (LPGUID)&GUID_BUS_INTERFACE_STANDARD;
121 Stack->Parameters.QueryInterface.Version = 1;
122 Stack->Parameters.QueryInterface.Interface = (PINTERFACE)busInterface;
123 Stack->Parameters.QueryInterface.InterfaceSpecificData = NULL;
124 Irp->IoStatus.Status=STATUS_NOT_SUPPORTED ;
125
126 Status=IoCallDriver(DeviceObject, Irp);
127
128 if (Status == STATUS_PENDING)
129 {
130 KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
131
132 Status=IoStatus.Status;
133 }
134
135 return Status;
136 }
137