14#define IO_METHOD_FROM_CTL_CODE(ctlCode) (ctlCode&0x00000003)
30 *BufferIn = *BufferOut =
Irp->AssociatedIrp.SystemBuffer;
34 *BufferIn =
Irp->AssociatedIrp.SystemBuffer;
39 *BufferOut =
Irp->UserBuffer;
69 TRACE_(SERIAL,
"SerialSetBaudRate(COM%lu, %lu Bauds)\n", DeviceExtension->ComPort, BaudRate);
83 DeviceExtension->BaudRate = BaudRate;
99 TRACE_(SERIAL,
"SerialSetLineControl(COM%lu, Settings { %lu %lu %lu })\n",
100 DeviceExtension->ComPort, NewSettings->StopBits, NewSettings->Parity, NewSettings->WordLength);
103 switch (NewSettings->WordLength)
112 if (NewSettings->WordLength < 5 || NewSettings->WordLength > 8)
115 switch (NewSettings->Parity)
125 switch (NewSettings->StopBits)
131 if (NewSettings->WordLength != 5)
136 if (NewSettings->WordLength < 6 || NewSettings->WordLength > 8)
145 ComPortBase =
ULongToPtr(DeviceExtension->BaseAddress);
156 DeviceExtension->SerialLineControl = *NewSettings;
205 pCommProp->PacketVersion = 2;
207 pCommProp->MaxTxQueue = pCommProp->CurrentTxQueue = DeviceExtension->OutputBuffer.Length - 1;
208 pCommProp->MaxRxQueue = pCommProp->CurrentRxQueue = DeviceExtension->InputBuffer.Length - 1;
222 if (DeviceExtension->UartType >=
Uart16450)
226 if (DeviceExtension->UartType >=
Uart16550)
235 pCommProp->ProvSpec2 = 0;
250 pSerialStatus->Errors = 0;
251 if (DeviceExtension->BreakInterruptErrorCount)
253 if (DeviceExtension->SerialPerfStats.FrameErrorCount)
255 if (DeviceExtension->SerialPerfStats.SerialOverrunErrorCount)
257 if (DeviceExtension->SerialPerfStats.BufferOverrunErrorCount)
259 if (DeviceExtension->SerialPerfStats.ParityErrorCount)
262 pSerialStatus->HoldReasons = 0;
265 pSerialStatus->AmountInInQueue = (DeviceExtension->InputBuffer.WritePosition + DeviceExtension->InputBuffer.Length
266 - DeviceExtension->InputBuffer.ReadPosition) % DeviceExtension->InputBuffer.Length;
270 pSerialStatus->AmountInOutQueue = (DeviceExtension->OutputBuffer.WritePosition + DeviceExtension->OutputBuffer.Length
271 - DeviceExtension->OutputBuffer.ReadPosition) % DeviceExtension->OutputBuffer.Length;
274 pSerialStatus->EofReceived =
FALSE;
275 pSerialStatus->WaitForImmediate =
FALSE;
288 ULONG LengthIn, LengthOut;
290 PVOID BufferIn, BufferOut;
294 TRACE_(SERIAL,
"IRP_MJ_DEVICE_CONTROL dispatch\n");
297 LengthIn =
Stack->Parameters.DeviceIoControl.InputBufferLength;
298 LengthOut =
Stack->Parameters.DeviceIoControl.OutputBufferLength;
310 TRACE_(SERIAL,
"IOCTL_SERIAL_CLEAR_STATS\n");
320 TRACE_(SERIAL,
"IOCTL_SERIAL_CLR_DTR\n");
326 DeviceExtension->
MCR &= ~SR_MCR_DTR;
334 TRACE_(SERIAL,
"IOCTL_SERIAL_CLR_RTS\n");
340 DeviceExtension->
MCR &= ~SR_MCR_RTS;
350 TRACE_(SERIAL,
"IOCTL_SERIAL_CONFIG_SIZE\n");
351 if (LengthOut !=
sizeof(
ULONG) || BufferOut ==
NULL)
355 pConfigSize = (
PULONG)BufferOut;
364 TRACE_(SERIAL,
"IOCTL_SERIAL_GET_BAUD_RATE\n");
367 else if (BufferOut ==
NULL)
381 ERR_(SERIAL,
"IOCTL_SERIAL_GET_CHARS not implemented.\n");
384 else if (BufferOut ==
NULL)
402 TRACE_(SERIAL,
"IOCTL_SERIAL_GET_COMMSTATUS\n");
405 else if (BufferOut ==
NULL)
417 TRACE_(SERIAL,
"IOCTL_SERIAL_GET_DTRRTS\n");
418 if (LengthOut !=
sizeof(
ULONG) || BufferOut ==
NULL)
422 pDtrRts = (
PULONG)BufferOut;
437 ERR_(SERIAL,
"IOCTL_SERIAL_GET_HANDFLOW not implemented.\n");
440 else if (BufferOut ==
NULL)
456 TRACE_(SERIAL,
"IOCTL_SERIAL_GET_LINE_CONTROL\n");
459 else if (BufferOut ==
NULL)
472 TRACE_(SERIAL,
"IOCTL_SERIAL_GET_MODEM_CONTROL\n");
473 if (LengthOut !=
sizeof(
ULONG) || BufferOut ==
NULL)
478 *pMCR = DeviceExtension->
MCR;
487 TRACE_(SERIAL,
"IOCTL_SERIAL_GET_MODEMSTATUS\n");
488 if (LengthOut !=
sizeof(
ULONG) || BufferOut ==
NULL)
493 *pMSR = DeviceExtension->
MSR;
501 TRACE_(SERIAL,
"IOCTL_SERIAL_GET_PROPERTIES\n");
504 else if (BufferOut ==
NULL)
515 TRACE_(SERIAL,
"IOCTL_SERIAL_GET_STATS\n");
518 else if (BufferOut ==
NULL)
531 TRACE_(SERIAL,
"IOCTL_SERIAL_GET_TIMEOUTS\n");
545 TRACE_(SERIAL,
"IOCTL_SERIAL_GET_WAIT_MASK\n");
546 if (LengthOut !=
sizeof(
ULONG) || BufferOut ==
NULL)
550 pWaitMask = (
PULONG)BufferOut;
551 *pWaitMask = DeviceExtension->
WaitMask;
560 ERR_(SERIAL,
"IOCTL_SERIAL_IMMEDIATE_CHAR not implemented.\n");
567 ERR_(SERIAL,
"IOCTL_SERIAL_LSRMST_INSERT not implemented.\n");
574 TRACE_(SERIAL,
"IOCTL_SERIAL_PURGE\n");
577 if (LengthIn !=
sizeof(
ULONG) || BufferIn ==
NULL)
624 ERR_(SERIAL,
"IOCTL_SERIAL_RESET_DEVICE not implemented.\n");
631 TRACE_(SERIAL,
"IOCTL_SERIAL_SET_BAUD_RATE\n");
632 if (LengthIn !=
sizeof(
ULONG) || BufferIn ==
NULL)
636 pNewBaudRate = (
PULONG)BufferIn;
644 ERR_(SERIAL,
"IOCTL_SERIAL_SET_BREAK_OFF not implemented.\n");
651 ERR_(SERIAL,
"IOCTL_SERIAL_SET_BREAK_ON not implemented.\n");
658 ERR_(SERIAL,
"IOCTL_SERIAL_SET_CHARS not implemented.\n");
666 TRACE_(SERIAL,
"IOCTL_SERIAL_SET_DTR\n");
683 TRACE_(SERIAL,
"IOCTL_SERIAL_SET_FIFO_CONTROL\n");
684 if (LengthIn !=
sizeof(
ULONG) || BufferIn ==
NULL)
700 ERR_(SERIAL,
"IOCTL_SERIAL_SET_HANDFLOW not implemented.\n");
706 TRACE_(SERIAL,
"IOCTL_SERIAL_SET_LINE_CONTROL\n");
709 else if (BufferIn ==
NULL)
718 TRACE_(SERIAL,
"IOCTL_SERIAL_SET_MODEM_CONTROL\n");
719 if (LengthIn !=
sizeof(
ULONG) || BufferIn ==
NULL)
727 DeviceExtension->
MCR = (
UCHAR)(*pMCR & 0xff);
738 else if (BufferIn ==
NULL)
764 TRACE_(SERIAL,
"IOCTL_SERIAL_SET_RTS\n");
781 TRACE_(SERIAL,
"IOCTL_SERIAL_SET_TIMEOUTS\n");
794 TRACE_(SERIAL,
"IOCTL_SERIAL_SET_WAIT_MASK\n");
796 if (LengthIn !=
sizeof(
ULONG) || BufferIn ==
NULL)
800 WARN_(SERIAL,
"An IRP is already currently processed\n");
805 DeviceExtension->
WaitMask = *pWaitMask;
813 ERR_(SERIAL,
"IOCTL_SERIAL_SET_XOFF not implemented.\n");
820 ERR_(SERIAL,
"IOCTL_SERIAL_SET_XON not implemented.\n");
827 TRACE_(SERIAL,
"IOCTL_SERIAL_WAIT_ON_MASK\n");
829 if (LengthOut !=
sizeof(
ULONG) || BufferOut ==
NULL)
841 if (WaitingIrp !=
NULL)
844 WARN_(SERIAL,
"Unable to pend a second IRP for IOCTL_SERIAL_WAIT_ON_MASK\n");
845 Irp->IoStatus.Information = 0;
856 ERR_(SERIAL,
"IOCTL_SERIAL_XOFF_COUNTER not implemented.\n");
863 TRACE_(SERIAL,
"Unknown IOCTL code 0x%x\n",
Stack->Parameters.DeviceIoControl.IoControlCode);
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
NTSTATUS IncreaseCircularBufferSize(IN PCIRCULAR_BUFFER pBuffer, IN ULONG NewBufferSize)
#define NT_SUCCESS(StatCode)
DRIVER_DISPATCH SerialDeviceControl
#define COMMPROP_INITIALIZED
#define SR_FCR_CLEAR_RCVR
#define SR_FCR_CLEAR_XMIT
struct _SERIAL_DEVICE_EXTENSION * PSERIAL_DEVICE_EXTENSION
#define KeReleaseSpinLock(sl, irql)
#define KeAcquireSpinLock(sl, irql)
#define InterlockedCompareExchangePointer
#define SERIAL_PURGE_TXCLEAR
#define SERIAL_PURGE_RXCLEAR
#define METHOD_OUT_DIRECT
#define IOCTL_SERIAL_SET_CHARS
#define SERIAL_BAUD_134_5
#define IOCTL_SERIAL_SET_LINE_CONTROL
#define SERIAL_ERROR_QUEUEOVERRUN
struct _SERIAL_CHARS * PSERIAL_CHARS
#define IOCTL_SERIAL_XOFF_COUNTER
#define IOCTL_SERIAL_SET_TIMEOUTS
struct _SERIAL_QUEUE_SIZE * PSERIAL_QUEUE_SIZE
#define SERIAL_PCF_TOTALTIMEOUTS
struct _SERIAL_COMMPROP SERIAL_COMMPROP
#define IOCTL_SERIAL_WAIT_ON_MASK
#define IOCTL_SERIAL_SET_MODEM_CONTROL
#define IOCTL_SERIAL_IMMEDIATE_CHAR
#define IOCTL_SERIAL_GET_DTRRTS
#define SERIAL_BAUD_14400
#define SERIAL_SP_DATABITS
#define IOCTL_SERIAL_SET_XOFF
#define IOCTL_SERIAL_GET_CHARS
#define SERIAL_SP_STOPBITS
#define SERIAL_BAUD_38400
struct _SERIAL_HANDFLOW * PSERIAL_HANDFLOW
struct _SERIALPERF_STATS SERIALPERF_STATS
#define SERIAL_PARITY_MARK
struct _SERIAL_BAUD_RATE SERIAL_BAUD_RATE
struct _SERIAL_CHARS SERIAL_CHARS
#define IOCTL_SERIAL_SET_WAIT_MASK
#define IOCTL_SERIAL_SET_QUEUE_SIZE
#define SERIAL_ERROR_BREAK
#define SERIAL_PCF_SPECIALCHARS
#define SERIAL_PCF_DTRDSR
#define SERIAL_SP_HANDSHAKING
#define IOCTL_SERIAL_RESET_DEVICE
struct _SERIAL_BAUD_RATE * PSERIAL_BAUD_RATE
#define SERIAL_DATABITS_5
struct _SERIAL_HANDFLOW SERIAL_HANDFLOW
#define IOCTL_SERIAL_GET_BAUD_RATE
#define IOCTL_SERIAL_GET_COMMSTATUS
#define SERIAL_PCF_XONXOFF
#define SERIAL_STOPBITS_15
#define IOCTL_SERIAL_SET_FIFO_CONTROL
#define IOCTL_SERIAL_GET_WAIT_MASK
#define IOCTL_SERIAL_SET_BREAK_OFF
#define IOCTL_SERIAL_CONFIG_SIZE
#define IOCTL_SERIAL_GET_MODEM_CONTROL
#define SERIAL_PCF_PARITY_CHECK
#define IOCTL_SERIAL_GET_TIMEOUTS
#define IOCTL_SERIAL_SET_XON
#define SERIAL_PARITY_ODD
#define IOCTL_SERIAL_GET_STATS
#define IOCTL_SERIAL_CLR_DTR
#define SERIAL_BAUD_19200
#define SERIAL_PCF_SETXCHAR
struct _SERIAL_LINE_CONTROL * PSERIAL_LINE_CONTROL
#define IOCTL_SERIAL_SET_BAUD_RATE
#define IOCTL_SERIAL_GET_PROPERTIES
#define IOCTL_SERIAL_LSRMST_INSERT
#define SERIAL_ERROR_FRAMING
#define SERIAL_PARITY_EVEN
#define SERIAL_PCF_INTTIMEOUTS
#define SERIAL_ERROR_PARITY
#define IOCTL_SERIAL_CLR_RTS
#define SERIAL_ERROR_OVERRUN
#define IOCTL_SERIAL_GET_MODEMSTATUS
#define IOCTL_SERIAL_CLEAR_STATS
#define IOCTL_SERIAL_GET_LINE_CONTROL
struct _SERIAL_STATUS SERIAL_STATUS
#define SERIAL_PARITY_NONE
#define IOCTL_SERIAL_SET_DTR
struct _SERIAL_TIMEOUTS * PSERIAL_TIMEOUTS
#define SERIAL_PARITY_SPACE
struct _SERIAL_LINE_CONTROL SERIAL_LINE_CONTROL
#define IOCTL_SERIAL_SET_BREAK_ON
#define SERIAL_BAUD_115200
#define IOCTL_SERIAL_GET_HANDFLOW
#define SERIAL_STOPBITS_10
#define SERIAL_DATABITS_6
#define SERIAL_DATABITS_8
#define SERIAL_PCF_RTSCTS
#define SERIAL_SP_PARITY_CHECK
#define IOCTL_SERIAL_SET_RTS
#define SERIAL_BAUD_57600
#define SERIAL_DATABITS_7
#define IOCTL_SERIAL_SET_HANDFLOW
#define IOCTL_SERIAL_PURGE
#define SERIAL_STOPBITS_20
#define SERIAL_SP_SERIALCOMM
#define IoSkipCurrentIrpStackLocation(Irp)
#define IoCompleteRequest
BOOLEAN NTAPI KeSynchronizeExecution(IN OUT PKINTERRUPT Interrupt, IN PKSYNCHRONIZE_ROUTINE SynchronizeRoutine, IN PVOID SynchronizeContext OPTIONAL)
#define STATUS_NOT_IMPLEMENTED
#define READ_PORT_UCHAR(p)
#define WRITE_PORT_UCHAR(p, d)
static NTSTATUS SerialGetCommProp(OUT PSERIAL_COMMPROP pCommProp, IN PSERIAL_DEVICE_EXTENSION DeviceExtension)
#define IO_METHOD_FROM_CTL_CODE(ctlCode)
static BOOLEAN NTAPI SerialGetPerfStats(IN PVOID SynchronizeContext)
static VOID SerialGetUserBuffers(IN PIRP Irp, IN ULONG IoControlCode, OUT PVOID *BufferIn, OUT PVOID *BufferOut)
static NTSTATUS SerialGetCommStatus(OUT PSERIAL_STATUS pSerialStatus, IN PSERIAL_DEVICE_EXTENSION DeviceExtension)
NTSTATUS NTAPI SerialSetBaudRate(IN PSERIAL_DEVICE_EXTENSION DeviceExtension, IN ULONG NewBaudRate)
static BOOLEAN NTAPI SerialClearPerfStats(IN PVOID SynchronizeContext)
NTSTATUS NTAPI SerialSetLineControl(IN PSERIAL_DEVICE_EXTENSION DeviceExtension, IN PSERIAL_LINE_CONTROL NewSettings)
#define STATUS_BUFFER_TOO_SMALL
PDEVICE_OBJECT DeviceObject
struct _IO_STACK_LOCATION::@1575::@1576 DeviceIoControl
union _IO_STACK_LOCATION::@1575 Parameters
SERIAL_LINE_CONTROL SerialLineControl
PDEVICE_OBJECT LowerDevice
KSPIN_LOCK OutputBufferLock
KSPIN_LOCK InputBufferLock
IO_REMOVE_LOCK RemoveLock
ULONG BreakInterruptErrorCount
CIRCULAR_BUFFER InputBuffer
CIRCULAR_BUFFER OutputBuffer
SERIALPERF_STATS SerialPerfStats
SERIAL_TIMEOUTS SerialTimeOuts
#define RtlCopyMemory(Destination, Source, Length)
#define RtlZeroMemory(Destination, Length)
#define STATUS_INVALID_PARAMETER
_In_ PDEVICE_OBJECT DeviceObject
_In_ WDFREQUEST _In_ size_t _In_ size_t _In_ ULONG IoControlCode
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
_In_ WDFREQUEST _In_ NTSTATUS _In_ ULONG_PTR Information
#define IoAcquireRemoveLock(RemoveLock, Tag)
#define IoReleaseRemoveLock(_RemoveLock, _Tag)
_In_ PKSYNCHRONIZE_ROUTINE _In_opt_ __drv_aliasesMem PVOID SynchronizeContext
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)