ReactOS  0.4.15-dev-509-g96a357b
serenum.h File Reference
#include <ntifs.h>
#include <ntddser.h>
Include dependency graph for serenum.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _COMMON_DEVICE_EXTENSION
 
struct  _FDO_DEVICE_EXTENSION
 
struct  _PDO_DEVICE_EXTENSION
 

Macros

#define SERENUM_TAG   'ereS'
 
#define FLAG_ENUMERATION_DONE   0x01
 

Typedefs

typedef struct _COMMON_DEVICE_EXTENSION COMMON_DEVICE_EXTENSION
 
typedef struct _COMMON_DEVICE_EXTENSIONPCOMMON_DEVICE_EXTENSION
 
typedef struct _FDO_DEVICE_EXTENSION FDO_DEVICE_EXTENSION
 
typedef struct _FDO_DEVICE_EXTENSIONPFDO_DEVICE_EXTENSION
 
typedef struct _PDO_DEVICE_EXTENSION PDO_DEVICE_EXTENSION
 
typedef struct _PDO_DEVICE_EXTENSIONPPDO_DEVICE_EXTENSION
 

Enumerations

enum  SERENUM_DEVICE_STATE {
  dsStopped, dsStarted, dsPaused, dsRemoved,
  dsSurpriseRemoved
}
 

Functions

NTSTATUS SerenumDetectPnpDevice (IN PDEVICE_OBJECT DeviceObject, IN PDEVICE_OBJECT LowerDevice)
 
NTSTATUS SerenumDetectLegacyDevice (IN PDEVICE_OBJECT DeviceObject, IN PDEVICE_OBJECT LowerDevice)
 
NTSTATUS SerenumFdoPnp (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS SerenumInitMultiSzString (OUT PUNICODE_STRING Destination,...)
 
NTSTATUS ForwardIrpAndWait (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI ForwardIrpToLowerDeviceAndForget (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI ForwardIrpToAttachedFdoAndForget (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI ForwardIrpAndForget (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS DuplicateUnicodeString (IN ULONG Flags, IN PCUNICODE_STRING SourceString, OUT PUNICODE_STRING DestinationString)
 
NTSTATUS SerenumPdoPnp (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI DriverEntry (IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegPath)
 

Variables

DRIVER_ADD_DEVICE SerenumAddDevice
 

Macro Definition Documentation

◆ FLAG_ENUMERATION_DONE

#define FLAG_ENUMERATION_DONE   0x01

Definition at line 61 of file serenum.h.

◆ SERENUM_TAG

#define SERENUM_TAG   'ereS'

Definition at line 58 of file serenum.h.

Typedef Documentation

◆ COMMON_DEVICE_EXTENSION

◆ FDO_DEVICE_EXTENSION

◆ PCOMMON_DEVICE_EXTENSION

◆ PDO_DEVICE_EXTENSION

◆ PFDO_DEVICE_EXTENSION

◆ PPDO_DEVICE_EXTENSION

Enumeration Type Documentation

◆ SERENUM_DEVICE_STATE

Enumerator
dsStopped 
dsStarted 
dsPaused 
dsRemoved 
dsSurpriseRemoved 

Definition at line 16 of file serenum.h.

17 {
18  dsStopped,
19  dsStarted,
20  dsPaused,
21  dsRemoved,
SERENUM_DEVICE_STATE
Definition: serenum.h:16

Function Documentation

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( IN PDRIVER_OBJECT  DriverObject,
IN PUNICODE_STRING  RegPath 
)

Definition at line 367 of file beep.c.

369 {
370  PDEVICE_EXTENSION DeviceExtension;
372  UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\Beep");
374 
376 
377  /* Create the device */
379  sizeof(DEVICE_EXTENSION),
380  &DeviceName,
382  0,
383  FALSE,
384  &DeviceObject);
385  if (!NT_SUCCESS(Status)) return Status;
386 
387  /* Make it use buffered I/O */
389 
390  /* Setup the Driver Object */
397 
398  /* Set up device extension */
399  DeviceExtension = DeviceObject->DeviceExtension;
400  DeviceExtension->ReferenceCount = 0;
401  DeviceExtension->TimerActive = FALSE;
403  KeInitializeTimer(&DeviceExtension->Timer);
404  ExInitializeFastMutex(&DeviceExtension->Mutex);
405 
406  /* Page the entire driver */
408  return STATUS_SUCCESS;
409 }
DRIVER_DISPATCH BeepClose
Definition: beep.c:78
FORCEINLINE VOID IoInitializeDpcRequest(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIO_DPC_ROUTINE DpcRoutine)
Definition: iofuncs.h:2792
DRIVER_STARTIO BeepStartIo
Definition: beep.c:295
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
LONG NTSTATUS
Definition: precomp.h:26
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define FILE_DEVICE_BEEP
Definition: winioctl.h:106
DRIVER_DISPATCH BeepDeviceControl
Definition: beep.c:206
NTSTATUS NTAPI DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
Definition: beep.c:367
PVOID DeviceExtension
Definition: env_spec_w32.h:418
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
DRIVER_DISPATCH BeepCreate
Definition: beep.c:52
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
PVOID NTAPI MmPageEntireDriver(IN PVOID AddressWithinSection)
Definition: sysldr.c:3370
IO_DPC_ROUTINE * PIO_DPC_ROUTINE
Definition: iotypes.h:2494
VOID NTAPI BeepDPC(IN PKDPC Dpc, IN PDEVICE_OBJECT DeviceObject, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: beep.c:34
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
static const WCHAR L[]
Definition: oid.c:1250
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2182
DRIVER_DISPATCH BeepCleanup
Definition: beep.c:145
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
FAST_MUTEX Mutex
Definition: beep.c:24
DRIVER_UNLOAD BeepUnload
Definition: beep.c:268
#define IRP_MJ_CLEANUP
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2183
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:28
PDRIVER_STARTIO DriverStartIo
Definition: iotypes.h:2181
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

◆ DuplicateUnicodeString()

NTSTATUS DuplicateUnicodeString ( IN ULONG  Flags,
IN PCUNICODE_STRING  SourceString,
OUT PUNICODE_STRING  DestinationString 
)

Definition at line 72 of file misc.c.

76 {
81  {
83  }
84 
85 
86  if ((SourceString->Length == 0)
89  {
93  }
94  else
95  {
96  USHORT DestMaxLength = SourceString->Length;
97 
99  DestMaxLength += sizeof(UNICODE_NULL);
100 
102  if (DestinationString->Buffer == NULL)
103  return STATUS_NO_MEMORY;
104 
107  DestinationString->MaximumLength = DestMaxLength;
108 
111  }
112 
113  return STATUS_SUCCESS;
114 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
unsigned short Length
Definition: sprintf.c:451
#define I8042PRT_TAG
Definition: i8042prt.h:12
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
void * Buffer
Definition: sprintf.c:453
#define UNICODE_NULL
_Out_ _Inout_ POEM_STRING DestinationString
Definition: rtlfuncs.h:1868
smooth NULL
Definition: ftsmooth.c:416
#define RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
Definition: isapnp.h:82
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_Out_ _Inout_ POEM_STRING _In_ PCUNICODE_STRING SourceString
Definition: rtlfuncs.h:1868
#define RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING
Definition: isapnp.h:83
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
return STATUS_SUCCESS
Definition: btrfs.c:3014
unsigned short MaximumLength
Definition: sprintf.c:452

◆ ForwardIrpAndForget()

NTSTATUS NTAPI ForwardIrpAndForget ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 59 of file misc.c.

62 {
64 
65  ASSERT(LowerDevice);
66 
68  return IoCallDriver(LowerDevice, Irp);
69 }
_In_ PIRP Irp
Definition: csq.h:116
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
PVOID DeviceExtension
Definition: env_spec_w32.h:418
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421

◆ ForwardIrpAndWait()

NTSTATUS ForwardIrpAndWait ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 32 of file fdo.c.

35 {
36  KEVENT Event;
39  ASSERT(LowerDevice);
40 
43 
45 
46  Status = IoCallDriver(LowerDevice, Irp);
47  if (Status == STATUS_PENDING)
48  {
50  if (NT_SUCCESS(Status))
51  Status = Irp->IoStatus.Status;
52  }
53 
54  return Status;
55 }
#define TRUE
Definition: types.h:120
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
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
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:498
FORCEINLINE VOID IoCopyCurrentIrpStackLocationToNext(_Inout_ PIRP Irp)
Definition: iofuncs.h:2820
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:437
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static IO_COMPLETION_ROUTINE ForwardIrpAndWaitCompletion
Definition: fdo.c:17
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218

◆ ForwardIrpToAttachedFdoAndForget()

NTSTATUS NTAPI ForwardIrpToAttachedFdoAndForget ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 152 of file misc.c.

155 {
156  PPDO_DEVICE_EXTENSION DeviceExtension;
157  PDEVICE_OBJECT Fdo;
158 
160  ASSERT(!DeviceExtension->Common.IsFDO);
161 
162  Fdo = DeviceExtension->AttachedFdo;
163  ASSERT(Fdo);
164  TRACE_(SERENUM, "Calling attached Fdo 0x%p\n", Fdo);
166  return IoCallDriver(Fdo, Irp);
167 }
_In_ PIRP Irp
Definition: csq.h:116
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
PVOID DeviceExtension
Definition: env_spec_w32.h:418
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:56
#define TRACE_(x)
Definition: compat.h:66
PDEVICE_OBJECT AttachedFdo
Definition: parport.h:59
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421

Referenced by IrpStub(), and SerenumPdoPnp().

◆ ForwardIrpToLowerDeviceAndForget()

NTSTATUS NTAPI ForwardIrpToLowerDeviceAndForget ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 134 of file misc.c.

137 {
138  PFDO_DEVICE_EXTENSION DeviceExtension;
139  PDEVICE_OBJECT LowerDevice;
140 
142  ASSERT(DeviceExtension->Common.IsFDO);
143 
144  LowerDevice = DeviceExtension->LowerDevice;
145  ASSERT(LowerDevice);
146  TRACE_(SERENUM, "Calling lower device 0x%p\n", LowerDevice);
148  return IoCallDriver(LowerDevice, Irp);
149 }
_In_ PIRP Irp
Definition: csq.h:116
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define TRACE_(x)
Definition: compat.h:66
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:81
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
PDEVICE_OBJECT LowerDevice
Definition: i8042prt.h:130

Referenced by IrpStub().

◆ SerenumDetectLegacyDevice()

NTSTATUS SerenumDetectLegacyDevice ( IN PDEVICE_OBJECT  DeviceObject,
IN PDEVICE_OBJECT  LowerDevice 
)

Definition at line 444 of file detect.c.

447 {
448  HANDLE Handle = NULL;
449  ULONG Fcr, Mcr;
450  ULONG BaudRate;
451  ULONG Command;
452  SERIAL_TIMEOUTS Timeouts;
454  ULONG i, Count = 0;
455  UCHAR Buffer[16];
457  UNICODE_STRING DeviceId;
459  UNICODE_STRING HardwareIds;
460  UNICODE_STRING CompatibleIds;
462 
463  TRACE_(SERENUM, "SerenumDetectLegacyDevice(DeviceObject %p, LowerDevice %p)\n",
464  DeviceObject,
465  LowerDevice);
466 
467  RtlZeroMemory(Buffer, sizeof(Buffer));
468 
469  /* Open port */
471  LowerDevice,
473  NULL,
474  0,
475  NULL,
476  KernelMode,
477  &Handle);
478  if (!NT_SUCCESS(Status)) return Status;
479 
480  /* Reset UART */
481  TRACE_(SERENUM, "Reset UART\n");
482  Mcr = 0; /* MCR: DTR/RTS/OUT2 off */
484  &Mcr, sizeof(Mcr), NULL, NULL);
485  if (!NT_SUCCESS(Status)) goto ByeBye;
486 
487  /* Set communications parameters */
488  TRACE_(SERENUM, "Set communications parameters\n");
489  /* DLAB off */
490  Fcr = 0;
492  &Fcr, sizeof(Fcr), NULL, NULL);
493  if (!NT_SUCCESS(Status)) goto ByeBye;
494  /* Set serial port speed */
495  BaudRate = 1200;
497  &BaudRate, sizeof(BaudRate), NULL, NULL);
498  if (!NT_SUCCESS(Status)) goto ByeBye;
499  /* Set LCR */
500  LCR.WordLength = 7;
501  LCR.Parity = NO_PARITY;
502  LCR.StopBits = STOP_BITS_2;
504  &LCR, sizeof(LCR), NULL, NULL);
505  if (!NT_SUCCESS(Status)) goto ByeBye;
506 
507  /* Flush receive buffer */
508  TRACE_(SERENUM, "Flush receive buffer\n");
511  &Command, sizeof(Command), NULL, NULL);
512  if (!NT_SUCCESS(Status)) goto ByeBye;
513  /* Wait 100 ms */
514  Wait(100);
515 
516  /* Enable DTR/RTS */
517  TRACE_(SERENUM, "Enable DTR/RTS\n");
519  NULL, 0, NULL, NULL);
520  if (!NT_SUCCESS(Status)) goto ByeBye;
522  NULL, 0, NULL, NULL);
523  if (!NT_SUCCESS(Status)) goto ByeBye;
524 
525  /* Set timeout to 500 microseconds */
526  TRACE_(SERENUM, "Set timeout to 500 microseconds\n");
527  Timeouts.ReadIntervalTimeout = 100;
528  Timeouts.ReadTotalTimeoutMultiplier = 0;
529  Timeouts.ReadTotalTimeoutConstant = 500;
532  &Timeouts, sizeof(Timeouts), NULL, NULL);
533  if (!NT_SUCCESS(Status)) goto ByeBye;
534 
535  /* Fill the read buffer */
536  TRACE_(SERENUM, "Fill the read buffer\n");
537  Status = ReadBytes(LowerDevice, Buffer, sizeof(Buffer)/sizeof(Buffer[0]), (PVOID)&Count);
538  if (!NT_SUCCESS(Status)) goto ByeBye;
539 
540  RtlInitUnicodeString(&DeviceId, L"Serenum\\Mouse");
541  RtlInitUnicodeString(&InstanceId, L"0000"); /* FIXME */
542  for (i = 0; i < Count; i++)
543  {
544  if (Buffer[i] == 'B')
545  {
546  /* Sign for Microsoft Ballpoint */
547  /* Hardware id: *PNP0F09
548  * Compatible id: *PNP0F0F, SERIAL_MOUSE
549  */
550  RtlInitUnicodeString(&DeviceDescription, L"Microsoft Ballpoint device");
551  SerenumInitMultiSzString(&HardwareIds, "*PNP0F09", NULL);
552  SerenumInitMultiSzString(&CompatibleIds, "*PNP0F0F", "SERIAL_MOUSE", NULL);
554  &DeviceDescription, &DeviceId, &InstanceId, &HardwareIds, &CompatibleIds);
555  RtlFreeUnicodeString(&HardwareIds);
556  RtlFreeUnicodeString(&CompatibleIds);
557  goto ByeBye;
558  }
559  else if (Buffer[i] == 'M')
560  {
561  /* Sign for Microsoft Mouse protocol followed by button specifier */
562  if (i == sizeof(Buffer) - 1)
563  {
564  /* Overflow Error */
566  goto ByeBye;
567  }
568  switch (Buffer[i + 1])
569  {
570  case '3':
571  /* Hardware id: *PNP0F08
572  * Compatible id: SERIAL_MOUSE
573  */
574  RtlInitUnicodeString(&DeviceDescription, L"Microsoft Mouse with 3-buttons");
575  SerenumInitMultiSzString(&HardwareIds, "*PNP0F08", NULL);
576  SerenumInitMultiSzString(&CompatibleIds, "SERIAL_MOUSE", NULL);
577  break;
578  default:
579  /* Hardware id: *PNP0F01
580  * Compatible id: SERIAL_MOUSE
581  */
582  RtlInitUnicodeString(&DeviceDescription, L"Microsoft Mouse with 2-buttons or Microsoft Wheel Mouse");
583  SerenumInitMultiSzString(&HardwareIds, "*PNP0F01", NULL);
584  SerenumInitMultiSzString(&CompatibleIds, "SERIAL_MOUSE", NULL);
585  break;
586  }
588  &DeviceDescription, &DeviceId, &InstanceId, &HardwareIds, &CompatibleIds);
589  RtlFreeUnicodeString(&HardwareIds);
590  RtlFreeUnicodeString(&CompatibleIds);
591  goto ByeBye;
592  }
593  }
594 
596 
597 ByeBye:
598  /* Close port */
599  if (Handle)
600  ZwClose(Handle);
601  return Status;
602 }
#define SERIAL_PURGE_RXCLEAR
Definition: serial.c:96
static NTSTATUS Wait(IN ULONG milliseconds)
Definition: detect.c:210
#define IOCTL_SERIAL_SET_BAUD_RATE
Definition: ntddser.h:82
ULONG WriteTotalTimeoutConstant
Definition: ntddser.h:307
#define IOCTL_SERIAL_SET_FIFO_CONTROL
Definition: ntddser.h:92
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSTATUS SerenumInitMultiSzString(OUT PUNICODE_STRING Destination,...)
Definition: misc.c:20
ULONG ReadTotalTimeoutConstant
Definition: ntddser.h:305
LONG NTSTATUS
Definition: precomp.h:26
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1173
Definition: shell.h:41
NTSTATUS NTAPI ObOpenObjectByPointer(IN PVOID Object, IN ULONG HandleAttributes, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PHANDLE Handle)
Definition: obhandle.c:2739
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define IOCTL_SERIAL_SET_LINE_CONTROL
Definition: ntddser.h:96
#define IOCTL_SERIAL_SET_DTR
Definition: ntddser.h:90
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Must_inspect_result_ _In_opt_ PVOID _In_opt_ PVOID InstanceId
Definition: fsrtlfuncs.h:907
ULONG ReadTotalTimeoutMultiplier
Definition: ntddser.h:304
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
static NTSTATUS ReportDetectedDevice(IN PDEVICE_OBJECT DeviceObject, IN PUNICODE_STRING DeviceDescription, IN PUNICODE_STRING DeviceId, IN PUNICODE_STRING InstanceId, IN PUNICODE_STRING HardwareIds, IN PUNICODE_STRING CompatibleIds)
Definition: detect.c:102
static NTSTATUS ReadBytes(IN PDEVICE_OBJECT LowerDevice, OUT PUCHAR Buffer, IN ULONG BufferSize, OUT PULONG_PTR FilledBytes)
Definition: detect.c:65
#define STATUS_DEVICE_NOT_CONNECTED
Definition: udferr_usr.h:160
#define TRACE_(x)
Definition: compat.h:66
_Must_inspect_result_ _In_ PDEVICE_DESCRIPTION DeviceDescription
Definition: iofuncs.h:1015
_In_ HANDLE Handle
Definition: extypes.h:390
ULONG WriteTotalTimeoutMultiplier
Definition: ntddser.h:306
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct Command Command
ULONG ReadIntervalTimeout
Definition: ntddser.h:303
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define LCR
Definition: serial_port.h:65
#define STOP_BITS_2
Definition: serial.c:87
unsigned char UCHAR
Definition: xmlstorage.h:181
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
#define NO_PARITY
Definition: serial.c:89
#define IOCTL_SERIAL_SET_MODEM_CONTROL
Definition: ntddser.h:98
static NTSTATUS DeviceIoControl(IN PDEVICE_OBJECT DeviceObject, IN ULONG CtlCode, IN PVOID InputBuffer OPTIONAL, IN ULONG_PTR InputBufferSize, IN OUT PVOID OutputBuffer OPTIONAL, IN OUT PULONG_PTR OutputBufferSize)
Definition: detect.c:17
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define IOCTL_SERIAL_SET_RTS
Definition: ntddser.h:102
#define IOCTL_SERIAL_SET_TIMEOUTS
Definition: ntddser.h:104

Referenced by SerenumFdoQueryBusRelations().

◆ SerenumDetectPnpDevice()

NTSTATUS SerenumDetectPnpDevice ( IN PDEVICE_OBJECT  DeviceObject,
IN PDEVICE_OBJECT  LowerDevice 
)

Definition at line 223 of file detect.c.

226 {
227  HANDLE Handle = NULL;
228  UCHAR Buffer[256];
229  ULONG BaudRate;
230  ULONG_PTR TotalBytesReceived = 0;
231  ULONG_PTR Size;
232  ULONG Msr, Purge;
233  ULONG i;
234  BOOLEAN BufferContainsBeginId = FALSE;
235  BOOLEAN BufferContainsEndId = FALSE;
237  SERIAL_TIMEOUTS Timeouts;
238  SERIALPERF_STATS PerfStats;
240 
241  /* Open port */
243  LowerDevice,
245  NULL,
246  0,
247  NULL,
248  KernelMode,
249  &Handle);
250  if (!NT_SUCCESS(Status)) goto ByeBye;
251 
252  /* 1. COM port initialization, check for device enumerate */
253  TRACE_(SERENUM, "COM port initialization, check for device enumerate\n");
255  NULL, 0, NULL, NULL);
256  if (!NT_SUCCESS(Status)) goto ByeBye;
258  NULL, 0, NULL, NULL);
259  if (!NT_SUCCESS(Status)) goto ByeBye;
260  Wait(200);
261  Size = sizeof(Msr);
263  NULL, 0, &Msr, &Size);
264  if (!NT_SUCCESS(Status)) goto ByeBye;
265  if ((Msr & SERIAL_DSR_STATE) == 0) goto DisconnectIdle;
266 
267  /* 2. COM port setup, 1st phase */
268  TRACE_(SERENUM, "COM port setup, 1st phase\n");
269  BaudRate = 1200;
271  &BaudRate, sizeof(BaudRate), NULL, 0);
272  if (!NT_SUCCESS(Status)) goto ByeBye;
273  Lcr.WordLength = 7;
274  Lcr.Parity = NO_PARITY;
275  Lcr.StopBits = STOP_BIT_1;
277  &Lcr, sizeof(Lcr), NULL, NULL);
278  if (!NT_SUCCESS(Status)) goto ByeBye;
280  NULL, 0, NULL, NULL);
281  if (!NT_SUCCESS(Status)) goto ByeBye;
283  NULL, 0, NULL, NULL);
284  if (!NT_SUCCESS(Status)) goto ByeBye;
285  Wait(200);
287  NULL, 0, NULL, NULL);
288  if (!NT_SUCCESS(Status)) goto ByeBye;
289  Wait(200);
290 
291  /* 3. Wait for response, 1st phase */
292  TRACE_(SERENUM, "Wait for response, 1st phase\n");
294  NULL, 0, NULL, NULL);
295  if (!NT_SUCCESS(Status)) goto ByeBye;
296  Timeouts.ReadIntervalTimeout = 0;
297  Timeouts.ReadTotalTimeoutMultiplier = 0;
298  Timeouts.ReadTotalTimeoutConstant = 200;
301  &Timeouts, sizeof(Timeouts), NULL, NULL);
302  if (!NT_SUCCESS(Status)) goto ByeBye;
303  Status = ReadBytes(LowerDevice, Buffer, sizeof(Buffer), &Size);
304  if (!NT_SUCCESS(Status)) goto ByeBye;
305  if (Size != 0) goto CollectPnpComDeviceId;
306 
307  /* 4. COM port setup, 2nd phase */
308  TRACE_(SERENUM, "COM port setup, 2nd phase\n");
310  NULL, 0, NULL, NULL);
311  if (!NT_SUCCESS(Status)) goto ByeBye;
313  NULL, 0, NULL, NULL);
314  if (!NT_SUCCESS(Status)) goto ByeBye;
317  &Purge, sizeof(ULONG), NULL, NULL);
318  if (!NT_SUCCESS(Status)) goto ByeBye;
319  Wait(200);
320 
321  /* 5. Wait for response, 2nd phase */
322  TRACE_(SERENUM, "Wait for response, 2nd phase\n");
324  NULL, 0, NULL, NULL);
325  if (!NT_SUCCESS(Status)) goto ByeBye;
327  NULL, 0, NULL, NULL);
328  if (!NT_SUCCESS(Status)) goto ByeBye;
329  Status = ReadBytes(LowerDevice, Buffer, 1, &TotalBytesReceived);
330  if (!NT_SUCCESS(Status)) goto ByeBye;
331  if (TotalBytesReceived != 0) goto CollectPnpComDeviceId;
332  Size = sizeof(Msr);
334  NULL, 0, &Msr, &Size);
335  if (!NT_SUCCESS(Status)) goto ByeBye;
336  if ((Msr & SERIAL_DSR_STATE) == 0) goto VerifyDisconnect; else goto ConnectIdle;
337 
338  /* 6. Collect PnP COM device ID */
339 CollectPnpComDeviceId:
340  TRACE_(SERENUM, "Collect PnP COM device ID\n");
341  Timeouts.ReadIntervalTimeout = 200;
342  Timeouts.ReadTotalTimeoutMultiplier = 0;
343  Timeouts.ReadTotalTimeoutConstant = 2200;
345  &Timeouts, sizeof(Timeouts), NULL, NULL);
346  if (!NT_SUCCESS(Status)) goto ByeBye;
347  Status = ReadBytes(LowerDevice, &Buffer[TotalBytesReceived], sizeof(Buffer) - TotalBytesReceived, &Size);
348  if (!NT_SUCCESS(Status)) goto ByeBye;
349  TotalBytesReceived += Size;
350  Size = sizeof(PerfStats);
352  NULL, 0, &PerfStats, &Size);
353  if (!NT_SUCCESS(Status)) goto ByeBye;
354  if (PerfStats.FrameErrorCount + PerfStats.ParityErrorCount != 0) goto ConnectIdle;
355  for (i = 0; i < TotalBytesReceived; i++)
356  {
357  if (Buffer[i] == BEGIN_ID) BufferContainsBeginId = TRUE;
358  if (Buffer[i] == END_ID) BufferContainsEndId = TRUE;
359  }
360  if (TotalBytesReceived == 1 || BufferContainsEndId)
361  {
362  if (IsValidPnpIdString(Buffer, TotalBytesReceived))
363  {
364  Status = ReportDetectedPnpDevice(Buffer, TotalBytesReceived);
365  goto ByeBye;
366  }
367  goto ConnectIdle;
368  }
369  if (!BufferContainsBeginId) goto ConnectIdle;
370  if (!BufferContainsEndId) goto ConnectIdle;
371  Size = sizeof(Msr);
373  NULL, 0, &Msr, &Size);
374  if (!NT_SUCCESS(Status)) goto ByeBye;
375  if ((Msr & SERIAL_DSR_STATE) == 0) goto VerifyDisconnect;
376 
377  /* 7. Verify disconnect */
378 VerifyDisconnect:
379  TRACE_(SERENUM, "Verify disconnect\n");
381  NULL, 0, NULL, NULL);
382  if (!NT_SUCCESS(Status)) goto ByeBye;
384  NULL, 0, NULL, NULL);
385  if (!NT_SUCCESS(Status)) goto ByeBye;
386  Wait(5000);
387  goto DisconnectIdle;
388 
389  /* 8. Connect idle */
390 ConnectIdle:
391  TRACE_(SERENUM, "Connect idle\n");
393  NULL, 0, NULL, NULL);
394  if (!NT_SUCCESS(Status)) goto ByeBye;
396  NULL, 0, NULL, NULL);
397  if (!NT_SUCCESS(Status)) goto ByeBye;
398  BaudRate = 300;
400  &BaudRate, sizeof(BaudRate), NULL, NULL);
401  if (!NT_SUCCESS(Status)) goto ByeBye;
402  Lcr.WordLength = 7;
403  Lcr.Parity = NO_PARITY;
404  Lcr.StopBits = STOP_BIT_1;
406  &Lcr, sizeof(Lcr), NULL, NULL);
407  if (!NT_SUCCESS(Status)) goto ByeBye;
408  if (TotalBytesReceived == 0)
410  else
412  goto ByeBye;
413 
414  /* 9. Disconnect idle */
415 DisconnectIdle:
416  TRACE_(SERENUM, "Disconnect idle\n");
417  /* FIXME: report to OS device removal, if it was present */
419  NULL, 0, NULL, NULL);
420  if (!NT_SUCCESS(Status)) goto ByeBye;
422  NULL, 0, NULL, NULL);
423  if (!NT_SUCCESS(Status)) goto ByeBye;
424  BaudRate = 300;
426  &BaudRate, sizeof(BaudRate), NULL, NULL);
427  if (!NT_SUCCESS(Status)) goto ByeBye;
428  Lcr.WordLength = 7;
429  Lcr.Parity = NO_PARITY;
430  Lcr.StopBits = STOP_BIT_1;
432  &Lcr, sizeof(Lcr), NULL, NULL);
433  if (!NT_SUCCESS(Status)) goto ByeBye;
435 
436 ByeBye:
437  /* Close port */
438  if (Handle)
439  ZwClose(Handle);
440  return Status;
441 }
#define SERIAL_PURGE_RXCLEAR
Definition: serial.c:96
#define TRUE
Definition: types.h:120
#define STOP_BIT_1
Definition: ntddser.h:215
static BOOLEAN IsValidPnpIdString(IN PUCHAR Buffer, IN ULONG BufferLength)
Definition: detect.c:176
static NTSTATUS Wait(IN ULONG milliseconds)
Definition: detect.c:210
#define IOCTL_SERIAL_SET_BAUD_RATE
Definition: ntddser.h:82
ULONG WriteTotalTimeoutConstant
Definition: ntddser.h:307
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
ULONG ReadTotalTimeoutConstant
Definition: ntddser.h:305
LONG NTSTATUS
Definition: precomp.h:26
#define IOCTL_SERIAL_CLR_RTS
Definition: ntddser.h:46
#define SERIAL_DSR_STATE
Definition: ntddser.h:430
NTSTATUS NTAPI ObOpenObjectByPointer(IN PVOID Object, IN ULONG HandleAttributes, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PHANDLE Handle)
Definition: obhandle.c:2739
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define IOCTL_SERIAL_SET_LINE_CONTROL
Definition: ntddser.h:96
uint32_t ULONG_PTR
Definition: typedefs.h:64
#define IOCTL_SERIAL_SET_DTR
Definition: ntddser.h:90
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define IOCTL_SERIAL_GET_MODEMSTATUS
Definition: ntddser.h:64
#define IOCTL_SERIAL_PURGE
Definition: ntddser.h:78
#define BEGIN_ID
Definition: detect.c:206
unsigned char BOOLEAN
ULONG ReadTotalTimeoutMultiplier
Definition: ntddser.h:304
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define END_ID
Definition: detect.c:207
static NTSTATUS ReadBytes(IN PDEVICE_OBJECT LowerDevice, OUT PUCHAR Buffer, IN ULONG BufferSize, OUT PULONG_PTR FilledBytes)
Definition: detect.c:65
#define STATUS_DEVICE_NOT_CONNECTED
Definition: udferr_usr.h:160
#define TRACE_(x)
Definition: compat.h:66
_In_ HANDLE Handle
Definition: extypes.h:390
ULONG WriteTotalTimeoutMultiplier
Definition: ntddser.h:306
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG ReadIntervalTimeout
Definition: ntddser.h:303
unsigned char UCHAR
Definition: xmlstorage.h:181
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define IOCTL_SERIAL_GET_STATS
Definition: ntddser.h:68
Status
Definition: gdiplustypes.h:24
#define SERIAL_PURGE_RXABORT
Definition: serial.c:94
#define NO_PARITY
Definition: serial.c:89
#define IOCTL_SERIAL_CLR_DTR
Definition: ntddser.h:44
ULONG FrameErrorCount
Definition: ntddser.h:296
static NTSTATUS DeviceIoControl(IN PDEVICE_OBJECT DeviceObject, IN ULONG CtlCode, IN PVOID InputBuffer OPTIONAL, IN ULONG_PTR InputBufferSize, IN OUT PVOID OutputBuffer OPTIONAL, IN OUT PULONG_PTR OutputBufferSize)
Definition: detect.c:17
unsigned int ULONG
Definition: retypes.h:1
#define IOCTL_SERIAL_SET_RTS
Definition: ntddser.h:102
static NTSTATUS ReportDetectedPnpDevice(IN PUCHAR Buffer, IN ULONG BufferLength)
Definition: detect.c:191
ULONG ParityErrorCount
Definition: ntddser.h:299
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define IOCTL_SERIAL_SET_TIMEOUTS
Definition: ntddser.h:104

Referenced by SerenumFdoQueryBusRelations().

◆ SerenumFdoPnp()

NTSTATUS SerenumFdoPnp ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 152 of file fdo.c.

155 {
157  PIO_STACK_LOCATION Stack;
160 
162  MinorFunction = Stack->MinorFunction;
163 
164  switch (MinorFunction)
165  {
166  /* FIXME: do all these minor functions
167  IRP_MN_QUERY_REMOVE_DEVICE 0x1
168  IRP_MN_REMOVE_DEVICE 0x2
169  IRP_MN_CANCEL_REMOVE_DEVICE 0x3
170  IRP_MN_STOP_DEVICE 0x4
171  IRP_MN_QUERY_STOP_DEVICE 0x5
172  IRP_MN_CANCEL_STOP_DEVICE 0x6
173  IRP_MN_QUERY_DEVICE_RELATIONS / RemovalRelations (optional) 0x7
174  IRP_MN_QUERY_INTERFACE (optional) 0x8
175  IRP_MN_QUERY_CAPABILITIES (optional) 0x9
176  IRP_MN_QUERY_PNP_DEVICE_STATE (optional) 0x14
177  IRP_MN_DEVICE_USAGE_NOTIFICATION (required or optional) 0x16
178  IRP_MN_SURPRISE_REMOVAL 0x17
179  */
180  case IRP_MN_START_DEVICE: /* 0x0 */
181  {
182  TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_START_DEVICE\n");
183  /* Call lower driver */
185  if (NT_SUCCESS(Status))
187  break;
188  }
189  case IRP_MN_QUERY_DEVICE_RELATIONS: /* 0x7 */
190  {
191  switch (Stack->Parameters.QueryDeviceRelations.Type)
192  {
193  case BusRelations:
194  {
195  PDEVICE_RELATIONS DeviceRelations = NULL;
196  TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / BusRelations\n");
197  Status = SerenumFdoQueryBusRelations(DeviceObject, &DeviceRelations);
198  Information = (ULONG_PTR)DeviceRelations;
199  break;
200  }
201  default:
202  TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / Unknown type 0x%lx\n",
203  Stack->Parameters.QueryDeviceRelations.Type);
205  }
206  break;
207  }
209  {
210  TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n");
212  }
213  default:
214  {
215  TRACE_(SERENUM, "IRP_MJ_PNP / unknown minor function 0x%lx\n", MinorFunction);
217  }
218  }
219 
220  Irp->IoStatus.Information = Information;
221  Irp->IoStatus.Status = Status;
223  return Status;
224 }
NTSTATUS NTAPI ForwardIrpAndForget(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fdo.c:66
NTSTATUS NTAPI ForwardIrpAndWait(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fdo.c:32
_In_ PIRP Irp
Definition: csq.h:116
#define IRP_MN_FILTER_RESOURCE_REQUIREMENTS
LONG NTSTATUS
Definition: precomp.h:26
uint32_t ULONG_PTR
Definition: typedefs.h:64
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
#define TRACE_(x)
Definition: compat.h:66
static NTSTATUS SerenumFdoQueryBusRelations(IN PDEVICE_OBJECT DeviceObject, OUT PDEVICE_RELATIONS *pDeviceRelations)
Definition: fdo.c:102
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IRP_MN_START_DEVICE
_In_ UCHAR MinorFunction
Definition: pofuncs.h:42
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define IRP_MN_QUERY_DEVICE_RELATIONS
static NTSTATUS NTAPI SerenumFdoStartDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fdo.c:77
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:568
#define ULONG_PTR
Definition: config.h:101
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2774
Iosb Information
Definition: create.c:4353

Referenced by SerenumPnp().

◆ SerenumInitMultiSzString()

NTSTATUS SerenumInitMultiSzString ( OUT PUNICODE_STRING  Destination,
  ... 
)

Definition at line 20 of file misc.c.

23 {
24  va_list args;
25  PCSZ Source;
28  ULONG DestinationSize = 0;
30 
32 
33  /* Calculate length needed for destination unicode string */
35  Source = va_arg(args, PCSZ);
36  while (Source != NULL)
37  {
39  DestinationSize += RtlAnsiStringToUnicodeSize(&AnsiString)
40  + sizeof(WCHAR) /* final NULL */;
41  Source = va_arg(args, PCSZ);
42  }
43  va_end(args);
44  if (DestinationSize == 0)
45  {
47  return STATUS_SUCCESS;
48  }
49 
50  /* Initialize destination string */
51  DestinationSize += sizeof(WCHAR); // final NULL
53  if (!Destination->Buffer)
55  Destination->Length = 0;
56  Destination->MaximumLength = (USHORT)DestinationSize;
57 
58  /* Copy arguments to destination string */
59  /* Use a temporary unicode string, which buffer is shared with
60  * destination string, to copy arguments */
62  UnicodeString.MaximumLength = Destination->MaximumLength;
65  Source = va_arg(args, PCSZ);
66  while (Source != NULL)
67  {
70  if (!NT_SUCCESS(Status))
71  {
73  break;
74  }
75  Destination->Length += UnicodeString.Length + sizeof(WCHAR);
76  UnicodeString.MaximumLength -= UnicodeString.Length + sizeof(WCHAR);
77  UnicodeString.Buffer += UnicodeString.Length / sizeof(WCHAR) + 1;
78  UnicodeString.Length = 0;
79  Source = va_arg(args, PCSZ);
80  }
81  va_end(args);
82  if (NT_SUCCESS(Status))
83  {
84  /* Finish multi-sz string */
85  Destination->Buffer[Destination->Length / sizeof(WCHAR)] = L'\0';
86  Destination->Length += sizeof(WCHAR);
87  }
88  return Status;
89 }
CONST char * PCSZ
Definition: umtypes.h:125
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
*BytesInUnicodeString PWCH UnicodeString
Definition: rtlfuncs.h:1979
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint16_t * PWSTR
Definition: typedefs.h:55
LONG NTSTATUS
Definition: precomp.h:26
#define SERENUM_TAG
Definition: serenum.h:58
Definition: match.c:390
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define va_end(ap)
Definition: acmsvcex.h:90
NTSYSAPI DWORD WINAPI RtlAnsiStringToUnicodeSize(const STRING *)
smooth NULL
Definition: ftsmooth.c:416
char * va_list
Definition: acmsvcex.h:78
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:2937
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
#define va_arg(ap, T)
Definition: acmsvcex.h:89
unsigned short USHORT
Definition: pedump.c:61
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
#define va_start(ap, A)
Definition: acmsvcex.h:91
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define args
Definition: format.c:66

Referenced by SerenumDetectLegacyDevice().

◆ SerenumPdoPnp()

NTSTATUS SerenumPdoPnp ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 109 of file pdo.c.

112 {
114  PIO_STACK_LOCATION Stack;
117 
119  MinorFunction = Stack->MinorFunction;
120 
121  switch (MinorFunction)
122  {
123  /* FIXME: do all these minor functions
124  IRP_MN_QUERY_REMOVE_DEVICE 0x1
125  IRP_MN_REMOVE_DEVICE 0x2
126  IRP_MN_CANCEL_REMOVE_DEVICE 0x3
127  IRP_MN_STOP_DEVICE 0x4
128  IRP_MN_QUERY_STOP_DEVICE 0x5
129  IRP_MN_CANCEL_STOP_DEVICE 0x6
130  IRP_MN_QUERY_DEVICE_RELATIONS / EjectionRelations (optional) 0x7
131  IRP_MN_QUERY_INTERFACE (required or optional) 0x8
132  IRP_MN_READ_CONFIG (required or optional) 0xf
133  IRP_MN_WRITE_CONFIG (required or optional) 0x10
134  IRP_MN_EJECT (required or optional) 0x11
135  IRP_MN_SET_LOCK (required or optional) 0x12
136  IRP_MN_QUERY_ID / BusQueryDeviceID 0x13
137  IRP_MN_QUERY_ID / BusQueryCompatibleIDs (optional) 0x13
138  IRP_MN_QUERY_ID / BusQueryInstanceID (optional) 0x13
139  IRP_MN_QUERY_PNP_DEVICE_STATE (optional) 0x14
140  IRP_MN_DEVICE_USAGE_NOTIFICATION (required or optional) 0x16
141  IRP_MN_SURPRISE_REMOVAL 0x17
142  */
143  case IRP_MN_START_DEVICE: /* 0x0 */
144  {
145  TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_START_DEVICE\n");
147  break;
148  }
149  case IRP_MN_QUERY_DEVICE_RELATIONS: /* 0x7 */
150  {
151  switch (Stack->Parameters.QueryDeviceRelations.Type)
152  {
153  case RemovalRelations:
154  {
156  }
158  {
159  PDEVICE_RELATIONS DeviceRelations = NULL;
160  TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / TargetDeviceRelation\n");
162  Information = (ULONG_PTR)DeviceRelations;
163  break;
164  }
165  default:
166  {
167  WARN_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / Unknown type 0x%lx\n",
168  Stack->Parameters.QueryDeviceRelations.Type);
169  ASSERT(FALSE);
171  break;
172  }
173  }
174  break;
175  }
176  case IRP_MN_QUERY_CAPABILITIES: /* 0x9 */
177  {
179  ULONG i;
180  TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_CAPABILITIES\n");
181 
182  DeviceCapabilities = (PDEVICE_CAPABILITIES)Stack->Parameters.DeviceCapabilities.Capabilities;
183  /* FIXME: capabilities can change with connected device */
184  DeviceCapabilities->LockSupported = FALSE;
185  DeviceCapabilities->EjectSupported = FALSE;
186  DeviceCapabilities->Removable = TRUE;
187  DeviceCapabilities->DockDevice = FALSE;
188  DeviceCapabilities->UniqueID = FALSE;
189  DeviceCapabilities->SilentInstall = FALSE;
190  DeviceCapabilities->RawDeviceOK = TRUE;
191  DeviceCapabilities->SurpriseRemovalOK = TRUE;
192  DeviceCapabilities->HardwareDisabled = FALSE; /* FIXME */
193  //DeviceCapabilities->NoDisplayInUI = FALSE; /* FIXME */
194  DeviceCapabilities->DeviceState[0] = PowerDeviceD0; /* FIXME */
195  for (i = 0; i < PowerSystemMaximum; i++)
196  DeviceCapabilities->DeviceState[i] = PowerDeviceD3; /* FIXME */
197  //DeviceCapabilities->DeviceWake = PowerDeviceUndefined; /* FIXME */
198  DeviceCapabilities->D1Latency = 0; /* FIXME */
199  DeviceCapabilities->D2Latency = 0; /* FIXME */
200  DeviceCapabilities->D3Latency = 0; /* FIXME */
202  break;
203  }
204  case IRP_MN_QUERY_RESOURCES: /* 0xa */
205  {
206  TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_RESOURCES\n");
207  /* Serial devices don't need resources, except the ones of
208  * the serial port. This PDO is the serial device PDO, so
209  * report no resource by not changing Information and
210  * Status
211  */
212  Information = Irp->IoStatus.Information;
213  Status = Irp->IoStatus.Status;
214  break;
215  }
216  case IRP_MN_QUERY_RESOURCE_REQUIREMENTS: /* 0xb */
217  {
218  TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_RESOURCE_REQUIREMENTS\n");
219  /* Serial devices don't need resources, except the ones of
220  * the serial port. This PDO is the serial device PDO, so
221  * report no resource by not changing Information and
222  * Status
223  */
224  Information = Irp->IoStatus.Information;
225  Status = Irp->IoStatus.Status;
226  break;
227  }
228  case IRP_MN_QUERY_DEVICE_TEXT: /* 0xc */
229  {
230  switch (Stack->Parameters.QueryDeviceText.DeviceTextType)
231  {
233  {
236  TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_TEXT / DeviceTextDescription\n");
237 
238  Source = &((PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->DeviceDescription;
240  if (!Description)
242  else
243  {
244  RtlCopyMemory(Description, Source->Buffer, Source->Length);
245  Description[Source->Length / sizeof(WCHAR)] = L'\0';
248  }
249  break;
250  }
252  {
253  /* We don't have any text location to report,
254  * and this query is optional, so ignore it.
255  */
256  Information = Irp->IoStatus.Information;
257  Status = Irp->IoStatus.Status;
258  break;
259  }
260  default:
261  {
262  WARN_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_TEXT / unknown type 0x%lx\n",
263  Stack->Parameters.QueryDeviceText.DeviceTextType);
264  ASSERT(FALSE);
266  }
267  }
268  break;
269  }
271  {
273  }
274  case IRP_MN_QUERY_ID: /* 0x13 */
275  {
277  break;
278  }
279  case IRP_MN_QUERY_BUS_INFORMATION: /* 0x15 */
280  {
281  PPNP_BUS_INFORMATION BusInfo;
282  TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_BUS_INFORMATION\n");
283 
285  if (!BusInfo)
287  else
288  {
289  memcpy(
290  &BusInfo->BusTypeGuid,
291  &GUID_DEVINTERFACE_SERENUM_BUS_ENUMERATOR,
292  sizeof(BusInfo->BusTypeGuid));
293  BusInfo->LegacyBusType = PNPBus;
294  /* We're the only serial bus enumerator on the computer */
295  BusInfo->BusNumber = 0;
296  Information = (ULONG_PTR)BusInfo;
298  }
299  break;
300  }
301  default:
302  {
303  /* We can't forward request to the lower driver, because
304  * we are a Pdo, so we don't have lower driver... */
305  WARN_(SERENUM, "IRP_MJ_PNP / unknown minor function 0x%lx\n", MinorFunction);
306  ASSERT(FALSE);
307  Information = Irp->IoStatus.Information;
308  Status = Irp->IoStatus.Status;
309  }
310  }
311 
312  Irp->IoStatus.Information = Information;
313  Irp->IoStatus.Status = Status;
315  return Status;
316 }
#define TRUE
Definition: types.h:120
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
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
_In_ PIRP Irp
Definition: csq.h:116
#define IRP_MN_FILTER_RESOURCE_REQUIREMENTS
uint16_t * PWSTR
Definition: typedefs.h:55
static NTSTATUS SerenumPdoStartDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: pdo.c:15
#define IRP_MN_QUERY_RESOURCE_REQUIREMENTS
LONG NTSTATUS
Definition: precomp.h:26
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
static const WCHAR Description[]
Definition: oid.c:1266
#define SERENUM_TAG
Definition: serenum.h:58
uint32_t ULONG_PTR
Definition: typedefs.h:64
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static NTSTATUS SerenumPdoQueryId(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, OUT ULONG_PTR *Information)
Definition: pdo.c:29
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
struct _PNP_BUS_INFORMATION * PPNP_BUS_INFORMATION
#define IoCompleteRequest
Definition: irp.c:1240
#define DeviceCapabilities
Definition: wingdi.h:4448
#define TRACE_(x)
Definition: compat.h:66
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define IRP_MN_START_DEVICE
#define for
Definition: utility.h:88
static NTSTATUS SerenumPdoQueryDeviceRelations(IN PDEVICE_OBJECT DeviceObject, OUT PDEVICE_RELATIONS *pDeviceRelations)
Definition: pdo.c:83
NTSTATUS NTAPI ForwardIrpToAttachedFdoAndForget(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: misc.c:152
#define IRP_MN_QUERY_DEVICE_TEXT
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define IRP_MN_QUERY_BUS_INFORMATION
static const WCHAR L[]
Definition: oid.c:1250
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
_In_ UCHAR MinorFunction
Definition: pofuncs.h:42
* PDEVICE_CAPABILITIES
Definition: iotypes.h:930
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:568
#define ULONG_PTR
Definition: config.h:101
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2774
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define WARN_(ch,...)
Definition: debug.h:157
INTERFACE_TYPE LegacyBusType
Definition: cmtypes.h:365
Iosb Information
Definition: create.c:4353
#define IRP_MN_QUERY_CAPABILITIES

Referenced by SerenumPnp().

Variable Documentation

◆ SerenumAddDevice

DRIVER_ADD_DEVICE SerenumAddDevice

Definition at line 77 of file serenum.h.

Referenced by DriverEntry().