1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
/*++
Copyright (c) 1990-2000 Microsoft Corporation All Rights Reserved
Module Name:
fakemodem.h
Abstract:
Header file for the toaster driver modules.
Environment:
Kernel mode
--*/
#if !defined(_FAKEMODEM_H_)
#define _FAKEMODEM_H_
#include <NTDDK.h>
#include <wdf.h>
#include <ntddser.h>
#include <initguid.h>
#define NTSTRSAFE_LIB
#include <ntstrsafe.h>
#include <ntintsafe.h>
#ifdef DEFINE_GUID
DEFINE_GUID(GUID_DEVINTERFACE_MODEM,0x2c7089aa, 0x2e0e,0x11d1,0xb1, 0x14, 0x00, 0xc0, 0x4f, 0xc2, 0xaa, 0xe4);
#endif //DEFINE_GUID
#define OBJECT_DIRECTORY L"\\DosDevices\\"
#define READ_BUFFER_SIZE 128
#define COMMAND_MATCH_STATE_IDLE 0
#define COMMAND_MATCH_STATE_GOT_A 1
#define COMMAND_MATCH_STATE_GOT_T 2
//
// This defines the bit used to control whether the device is sending
// a break. When this bit is set the device is sending a space (logic 0).
//
// Most protocols will assume that this is a hangup.
#define SERIAL_LCR_BREAK 0x40
//
// These defines are used to define the line control register
//
#define SERIAL_5_DATA ((UCHAR)0x00)
#define SERIAL_6_DATA ((UCHAR)0x01)
#define SERIAL_7_DATA ((UCHAR)0x02)
#define SERIAL_8_DATA ((UCHAR)0x03)
#define SERIAL_DATA_MASK ((UCHAR)0x03)
#define SERIAL_1_STOP ((UCHAR)0x00)
#define SERIAL_1_5_STOP ((UCHAR)0x04) // Only valid for 5 data bits
#define SERIAL_2_STOP ((UCHAR)0x04) // Not valid for 5 data bits
#define SERIAL_STOP_MASK ((UCHAR)0x04)
#define SERIAL_NONE_PARITY ((UCHAR)0x00)
#define SERIAL_ODD_PARITY ((UCHAR)0x08)
#define SERIAL_EVEN_PARITY ((UCHAR)0x18)
#define SERIAL_MARK_PARITY ((UCHAR)0x28)
#define SERIAL_SPACE_PARITY ((UCHAR)0x38)
#define SERIAL_PARITY_MASK ((UCHAR)0x38)
#define REG_VALUE_CREATED_FLAG 0x1
//
// The device extension for the device object
//
typedef struct _FM_DEVICE_DATA
{
UNICODE_STRING PdoName; //save this so that we can use it to delete the registry value later
WDFQUEUE FmReadQueue; // Staging area for pending Read requests
WDFQUEUE FmMaskWaitQueue;
ULONG CurrentMask;
SERIAL_TIMEOUTS CurrentTimeouts;
ULONG ReadBufferBegin;
ULONG ReadBufferEnd;
ULONG BytesInReadBuffer;
UCHAR CommandMatchState;
BOOLEAN ConnectCommand;
BOOLEAN IgnoreNextChar;
BOOLEAN CapsQueried;
ULONG ModemStatus;
BOOLEAN CurrentlyConnected;
BOOLEAN ConnectionStateChanged;
UCHAR ReadBuffer[READ_BUFFER_SIZE];
ULONG BaudRate;
UCHAR LineControl;
UCHAR ValidDataMask;
UCHAR Flags;
} FM_DEVICE_DATA, *PFM_DEVICE_DATA;
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(FM_DEVICE_DATA, FmDeviceDataGet)
#define FM_COM_PORT_STRING_LENGTH 80
DRIVER_INITIALIZE DriverEntry;
EVT_WDF_DRIVER_DEVICE_ADD FmEvtDeviceAdd;
EVT_WDF_DEVICE_CONTEXT_CLEANUP FmDeviceCleanup;
EVT_WDF_IO_QUEUE_IO_READ FmEvtIoRead;
EVT_WDF_IO_QUEUE_IO_WRITE FmEvtIoWrite;
EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL FmEvtIoDeviceControl;
NTSTATUS
FmCreateDosDevicesSymbolicLink(
WDFDEVICE Device,
PFM_DEVICE_DATA FmDeviceData
);
VOID
ProcessConnectionStateChange(
IN PFM_DEVICE_DATA FmDeviceData
);
VOID
ProcessWriteBytes(
PFM_DEVICE_DATA FmDeviceData,
PUCHAR Characters,
ULONG Length
);
VOID
PutCharInReadBuffer(
PFM_DEVICE_DATA FmDeviceData,
UCHAR Character
);
VOID
ProcessReadBuffer(
IN PFM_DEVICE_DATA FmDeviceData,
IN PUCHAR SystemBuffer,
IN ULONG Length,
OUT PULONG ByesToMove
);
#endif // _FAKEMODEM_H
|