ReactOS  0.4.14-dev-999-g61c8d34
pdo.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS ISA PnP Bus driver
3  * FILE: pdo.c
4  * PURPOSE: PDO-specific code
5  * PROGRAMMERS: Cameron Gutman (cameron.gutman@reactos.org)
6  */
7 
8 #include <isapnp.h>
9 
10 #define NDEBUG
11 #include <debug.h>
12 
14 NTAPI
17  IN PIRP Irp,
19 {
20  PDEVICE_RELATIONS DeviceRelations;
21 
22  if (IrpSp->Parameters.QueryDeviceRelations.Type != TargetDeviceRelation)
23  return Irp->IoStatus.Status;
24 
25  DeviceRelations = ExAllocatePool(PagedPool, sizeof(*DeviceRelations));
26  if (!DeviceRelations)
28 
29  DeviceRelations->Count = 1;
30  DeviceRelations->Objects[0] = LogDev->Common.Self;
31  ObReferenceObject(LogDev->Common.Self);
32 
33  Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
34 
35  return STATUS_SUCCESS;
36 }
37 
39 NTAPI
42  IN PIRP Irp,
44 {
46 
47  DeviceCapabilities = IrpSp->Parameters.DeviceCapabilities.Capabilities;
48  if (DeviceCapabilities->Version != 1)
49  return STATUS_UNSUCCESSFUL;
50 
51  DeviceCapabilities->UniqueID = LogDev->SerialNumber != 0xffffffff;
52  DeviceCapabilities->Address = LogDev->CSN;
53 
54  return STATUS_SUCCESS;
55 }
56 
58 NTAPI
61  IN PIRP Irp,
63 {
64  WCHAR Temp[256];
65  PWCHAR Buffer, End;
66  ULONG Length;
68 
69  switch (IrpSp->Parameters.QueryId.IdType)
70  {
71  case BusQueryDeviceID:
72  {
73  DPRINT("IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryDeviceID\n");
74  Status = RtlStringCbPrintfExW(Temp, sizeof(Temp),
75  &End,
76  NULL, 0,
77  L"ISAPNP\\%3S%04X",
78  LogDev->VendorId,
79  LogDev->ProdId);
80  if (!NT_SUCCESS(Status))
81  return Status;
82  Length = End - Temp;
83  Temp[Length++] = UNICODE_NULL;
84  break;
85  }
86 
88  DPRINT("IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryHardwareIDs\n");
89  Status = RtlStringCbPrintfExW(Temp, sizeof(Temp),
90  &End,
91  NULL, 0,
92  L"ISAPNP\\%3S%04X",
93  LogDev->VendorId,
94  LogDev->ProdId);
95  if (!NT_SUCCESS(Status))
96  return Status;
97  Length = End - Temp;
98  Temp[Length++] = UNICODE_NULL;
99  Status = RtlStringCbPrintfExW(Temp + Length, sizeof(Temp) - Length,
100  &End,
101  NULL, 0,
102  L"*%3S%04X",
103  LogDev->VendorId,
104  LogDev->ProdId);
105  if (!NT_SUCCESS(Status))
106  return Status;
107  Length = End - Temp;
108  Temp[Length++] = UNICODE_NULL;
109  Temp[Length++] = UNICODE_NULL;
110  break;
111 
112  case BusQueryInstanceID:
113  DPRINT("IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryInstanceID\n");
114  Status = RtlStringCbPrintfExW(Temp, sizeof(Temp),
115  &End,
116  NULL, 0,
117  L"%u",
118  LogDev->SerialNumber);
119  if (!NT_SUCCESS(Status))
120  return Status;
121  Length = End - Temp;
122  Temp[Length++] = UNICODE_NULL;
123  break;
124 
125  default:
126  DPRINT1("IRP_MJ_PNP / IRP_MN_QUERY_ID / unknown query id type 0x%lx\n",
127  IrpSp->Parameters.QueryId.IdType);
128  return Irp->IoStatus.Status;
129  }
130 
132  if (!Buffer)
133  return STATUS_NO_MEMORY;
134 
135  RtlCopyMemory(Buffer, Temp, Length * sizeof(WCHAR));
136  Irp->IoStatus.Information = (ULONG_PTR)Buffer;
137  return STATUS_SUCCESS;
138 }
139 
140 NTSTATUS
141 NTAPI
143  IN PISAPNP_LOGICAL_DEVICE LogDev,
144  IN PIRP Irp,
146 {
147  NTSTATUS Status = Irp->IoStatus.Status;
148 
149  switch (IrpSp->MinorFunction)
150  {
151  case IRP_MN_START_DEVICE:
152  Status = IsaHwActivateDevice(LogDev);
153 
154  if (NT_SUCCESS(Status))
155  LogDev->Common.State = dsStarted;
156  break;
157 
158  case IRP_MN_STOP_DEVICE:
159  Status = IsaHwDeactivateDevice(LogDev);
160 
161  if (NT_SUCCESS(Status))
162  LogDev->Common.State = dsStopped;
163  break;
164 
167  break;
168 
171  break;
172 
174  DPRINT1("IRP_MN_QUERY_RESOURCES is UNIMPLEMENTED!\n");
175  break;
176 
178  DPRINT1("IRP_MN_QUERY_RESOURCE_REQUIREMENTS is UNIMPLEMENTED!\n");
179  break;
180 
181  case IRP_MN_QUERY_ID:
182  Status = IsaPdoQueryId(LogDev, Irp, IrpSp);
183  break;
184 
185  default:
186  DPRINT1("Unknown PnP code: %x\n", IrpSp->MinorFunction);
187  break;
188  }
189 
190  Irp->IoStatus.Status = Status;
192 
193  return Status;
194 }
NTSTATUS NTAPI IsaPdoQueryId(IN PISAPNP_LOGICAL_DEVICE LogDev, IN PIRP Irp, IN PIO_STACK_LOCATION IrpSp)
Definition: pdo.c:59
#define IN
Definition: typedefs.h:39
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define IRP_MN_QUERY_RESOURCES
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define IRP_MN_QUERY_ID
_In_ PIRP Irp
Definition: csq.h:116
#define IRP_MN_QUERY_RESOURCE_REQUIREMENTS
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2055
LONG NTSTATUS
Definition: precomp.h:26
NTSTRSAFEVAPI RtlStringCbPrintfExW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _Outptr_opt_result_bytebuffer_(*pcbRemaining) NTSTRSAFE_PWSTR *ppszDestEnd, _Out_opt_ size_t *pcbRemaining, _In_ STRSAFE_DWORD dwFlags, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1335
uint16_t * PWCHAR
Definition: typedefs.h:55
NTSTATUS NTAPI IsaPdoQueryCapabilities(IN PISAPNP_LOGICAL_DEVICE LogDev, IN PIRP Irp, IN PIO_STACK_LOCATION IrpSp)
Definition: pdo.c:40
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define UNICODE_NULL
NTSTATUS NTAPI IsaPdoQueryDeviceRelations(IN PISAPNP_LOGICAL_DEVICE LogDev, IN PIRP Irp, IN PIO_STACK_LOCATION IrpSp)
Definition: pdo.c:15
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
#define DeviceCapabilities
Definition: wingdi.h:4448
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
#define IRP_MN_STOP_DEVICE
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IRP_MN_START_DEVICE
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
NTSTATUS NTAPI IsaPdoPnp(IN PISAPNP_LOGICAL_DEVICE LogDev, IN PIRP Irp, IN PIO_STACK_LOCATION IrpSp)
Definition: pdo.c:142
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
static const WCHAR L[]
Definition: oid.c:1250
NTSTATUS NTAPI IsaHwActivateDevice(IN PISAPNP_LOGICAL_DEVICE LogicalDevice)
Definition: hardware.c:557
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
* PDEVICE_CAPABILITIES
Definition: iotypes.h:928
Status
Definition: gdiplustypes.h:24
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define IRP_MN_QUERY_DEVICE_RELATIONS
NTSTATUS NTAPI IsaHwDeactivateDevice(IN PISAPNP_LOGICAL_DEVICE LogicalDevice)
Definition: hardware.c:568
#define DPRINT1
Definition: precomp.h:8
#define ObReferenceObject
Definition: obfuncs.h:204
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define ULONG_PTR
Definition: config.h:101
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define IRP_MN_QUERY_CAPABILITIES