Move drivers to the right location
[reactos.git] / reactos / drivers / usb / usbhub / pdo.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: USB hub driver
4 * FILE: drivers/usb/cromwell/hub/pdo.c
5 * PURPOSE: IRP_MJ_PNP operations for PDOs
6 *
7 * PROGRAMMERS: Hervé Poussineau (hpoussin@reactos.com)
8 */
9
10 #define NDEBUG
11 #include <stdio.h>
12 #include "usbhub.h"
13
14 #define IO_METHOD_FROM_CTL_CODE(ctlCode) (ctlCode&0x00000003)
15
16 NTSTATUS
17 UsbhubDeviceControlPdo(
18 IN PDEVICE_OBJECT DeviceObject,
19 IN PIRP Irp)
20 {
21 PIO_STACK_LOCATION Stack;
22 ULONG_PTR Information = 0;
23 NTSTATUS Status;
24
25 DPRINT("Usbhub: UsbhubDeviceControlPdo() called\n");
26
27 Stack = IoGetCurrentIrpStackLocation(Irp);
28 Status = Irp->IoStatus.Status;
29
30 switch (Stack->Parameters.DeviceIoControl.IoControlCode)
31 {
32 default:
33 {
34 DPRINT1("Usbhub: Unknown IOCTL code 0x%lx\n", Stack->Parameters.DeviceIoControl.IoControlCode);
35 Information = Irp->IoStatus.Information;
36 Status = Irp->IoStatus.Status;
37 }
38 }
39
40 Irp->IoStatus.Information = Information;
41 Irp->IoStatus.Status = Status;
42 IoCompleteRequest(Irp, IO_NO_INCREMENT);
43 return Status;
44 }
45
46 static NTSTATUS
47 UsbhubPdoStartDevice(
48 IN PDEVICE_OBJECT DeviceObject,
49 IN PIRP Irp)
50 {
51 PHUB_DEVICE_EXTENSION DeviceExtension;
52 NTSTATUS Status;
53
54 DeviceExtension = (PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
55 DbgBreakPoint();
56
57 /* Register and activate device interface */
58 Status = IoRegisterDeviceInterface(
59 DeviceObject,
60 DeviceExtension->dev->descriptor.bDeviceClass == USB_CLASS_HUB ?
61 &GUID_DEVINTERFACE_USB_HUB :
62 &GUID_DEVINTERFACE_USB_DEVICE,
63 NULL, /* Reference string */
64 &DeviceExtension->SymbolicLinkName);
65 if (!NT_SUCCESS(Status))
66 {
67 DPRINT("Usbhub: IoRegisterDeviceInterface() failed with status 0x%08lx\n", Status);
68 return Status;
69 }
70
71 Status = IoSetDeviceInterfaceState(&DeviceExtension->SymbolicLinkName, TRUE);
72 if (!NT_SUCCESS(Status))
73 {
74 DPRINT("Usbhub: IoSetDeviceInterfaceState() failed with status 0x%08lx\n", Status);
75 return Status;
76 }
77
78 return STATUS_SUCCESS;
79 }
80
81 static NTSTATUS
82 UsbhubPdoQueryId(
83 IN PDEVICE_OBJECT DeviceObject,
84 IN PIRP Irp,
85 OUT ULONG_PTR* Information)
86 {
87 PHUB_DEVICE_EXTENSION DeviceExtension;
88 ULONG IdType;
89 PUNICODE_STRING SourceString;
90 UNICODE_STRING String;
91 NTSTATUS Status;
92
93 IdType = IoGetCurrentIrpStackLocation(Irp)->Parameters.QueryId.IdType;
94 DeviceExtension = (PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
95 RtlInitUnicodeString(&String, NULL);
96
97 switch (IdType)
98 {
99 case BusQueryDeviceID:
100 {
101 DPRINT("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryDeviceID\n");
102 SourceString = &DeviceExtension->DeviceId;
103 break;
104 }
105 case BusQueryHardwareIDs:
106 {
107 DPRINT("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryHardwareIDs\n");
108 SourceString = &DeviceExtension->HardwareIds;
109 break;
110 }
111 case BusQueryCompatibleIDs:
112 {
113 DPRINT("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryCompatibleIDs\n");
114 SourceString = &DeviceExtension->CompatibleIds;
115 break;
116 }
117 case BusQueryInstanceID:
118 {
119 DPRINT("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryInstanceID\n");
120 SourceString = &DeviceExtension->InstanceId;
121 break;
122 }
123 default:
124 DPRINT1("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_ID / unknown query id type 0x%lx\n", IdType);
125 return STATUS_NOT_SUPPORTED;
126 }
127
128 Status = UsbhubDuplicateUnicodeString(
129 &String,
130 SourceString,
131 PagedPool);
132 *Information = (ULONG_PTR)String.Buffer;
133 return Status;
134 }
135
136 NTSTATUS STDCALL
137 UsbhubPnpPdo(
138 IN PDEVICE_OBJECT DeviceObject,
139 IN PIRP Irp)
140 {
141 ULONG MinorFunction;
142 PIO_STACK_LOCATION Stack;
143 ULONG_PTR Information = 0;
144 NTSTATUS Status;
145
146 Stack = IoGetCurrentIrpStackLocation(Irp);
147 MinorFunction = Stack->MinorFunction;
148
149 switch (MinorFunction)
150 {
151 case IRP_MN_START_DEVICE: /* 0x0 */
152 {
153 DPRINT("Usbhub: IRP_MJ_PNP / IRP_MN_START_DEVICE\n");
154 Status = UsbhubPdoStartDevice(DeviceObject, Irp);
155 break;
156 }
157 case IRP_MN_QUERY_ID: /* 0x13 */
158 {
159 Status = UsbhubPdoQueryId(DeviceObject, Irp, &Information);
160 break;
161 }
162 default:
163 {
164 /* We can't forward request to the lower driver, because
165 * we are a Pdo, so we don't have lower driver...
166 */
167 DPRINT1("Usbhub: IRP_MJ_PNP / unknown minor function 0x%lx\n", MinorFunction);
168 Information = Irp->IoStatus.Information;
169 Status = Irp->IoStatus.Status;
170 }
171 }
172
173 Irp->IoStatus.Information = Information;
174 Irp->IoStatus.Status = Status;
175 IoCompleteRequest(Irp, IO_NO_INCREMENT);
176 return Status;
177 }
178