845272b5212512cb4e60779dccd44f17fa8466be
[reactos.git] / reactos / drivers / net / afd / afd / afd.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Ancillary Function Driver
4 * FILE: afd/afd.c
5 * PURPOSE: MSAFD kernel mode module
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 * REVISIONS:
8 * CSH 01/09-2000 Created
9 */
10 #include <afd.h>
11
12 #ifdef DBG
13
14 /* See debug.h for debug/trace constants */
15 DWORD DebugTraceLevel = MIN_TRACE;
16 //DWORD DebugTraceLevel = DEBUG_ULTRA;
17
18 #endif /* DBG */
19
20
21 NPAGED_LOOKASIDE_LIST BufferLookasideList;
22 NPAGED_LOOKASIDE_LIST ReadRequestLookasideList;
23
24
25 NTSTATUS
26 STDCALL
27 AfdFileSystemControl(
28 PDEVICE_OBJECT DeviceObject,
29 PIRP Irp)
30 {
31 UNIMPLEMENTED
32
33 Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
34 Irp->IoStatus.Information = 0;
35 return STATUS_UNSUCCESSFUL;
36 }
37
38
39 NTSTATUS
40 STDCALL
41 AfdDispatch(
42 PDEVICE_OBJECT DeviceObject,
43 PIRP Irp)
44 /*
45 * FUNCTION: IOCTL dispatch routine
46 * ARGUMENTS:
47 * DeviceObject = Pointer to a device object for this driver
48 * Irp = Pointer to a I/O request packet
49 * RETURNS:
50 * Status of the operation
51 */
52 {
53 NTSTATUS Status;
54 PIO_STACK_LOCATION IrpSp;
55
56 IrpSp = IoGetCurrentIrpStackLocation(Irp);
57
58 AFD_DbgPrint(MAX_TRACE, ("Called. DeviceObject is at (0x%X), IRP is at (0x%X), IrpSp->FileObject (0x%X).\n",
59 DeviceObject, Irp, IrpSp->FileObject));
60
61 Irp->IoStatus.Information = 0;
62
63 switch (IrpSp->Parameters.DeviceIoControl.IoControlCode) {
64 case IOCTL_AFD_BIND:
65 Status = AfdDispBind(Irp, IrpSp);
66 break;
67
68 case IOCTL_AFD_LISTEN:
69 Status = AfdDispListen(Irp, IrpSp);
70 break;
71
72 case IOCTL_AFD_SENDTO:
73 Status = AfdDispSendTo(Irp, IrpSp);
74 break;
75
76 case IOCTL_AFD_RECVFROM:
77 Status = AfdDispRecvFrom(Irp, IrpSp);
78 break;
79
80 case IOCTL_AFD_SELECT:
81 Status = AfdDispSelect(Irp, IrpSp);
82 break;
83
84 case IOCTL_AFD_EVENTSELECT:
85 Status = AfdDispEventSelect(Irp, IrpSp);
86 break;
87
88 case IOCTL_AFD_ENUMNETWORKEVENTS:
89 Status = AfdDispEnumNetworkEvents(Irp, IrpSp);
90 break;
91
92 case IOCTL_AFD_RECV:
93 Status = AfdDispRecv(Irp, IrpSp);
94 break;
95
96 case IOCTL_AFD_SEND:
97 Status = AfdDispSend(Irp, IrpSp);
98 break;
99
100 case IOCTL_AFD_CONNECT:
101 Status = AfdDispConnect(Irp, IrpSp);
102 break;
103
104 default:
105 AFD_DbgPrint(MIN_TRACE, ("Unknown IOCTL (0x%X).\n",
106 IrpSp->Parameters.DeviceIoControl.IoControlCode));
107 Status = STATUS_NOT_IMPLEMENTED;
108 break;
109 }
110
111 if (Status != STATUS_PENDING) {
112 Irp->IoStatus.Status = Status;
113 IoCompleteRequest(Irp, IO_NETWORK_INCREMENT);
114 }
115
116 AFD_DbgPrint(MAX_TRACE, ("Leaving. Status (0x%X).\n", Status));
117
118 return Status;
119 }
120
121
122 VOID AfdUnload(
123 PDRIVER_OBJECT DriverObject)
124 /*
125 * FUNCTION: Unloads the driver
126 * ARGUMENTS:
127 * DriverObject = Pointer to driver object created by the system
128 */
129 {
130 }
131
132
133 NTSTATUS
134 STDCALL
135 DriverEntry(
136 PDRIVER_OBJECT DriverObject,
137 PUNICODE_STRING RegistryPath)
138 /*
139 * FUNCTION: Called by the system to initialize the driver
140 * ARGUMENTS:
141 * DriverObject = object describing this driver
142 * RegistryPath = path to our configuration entries
143 * RETURNS:
144 * Status of operation
145 */
146 {
147 PDEVICE_EXTENSION DeviceExt;
148 PDEVICE_OBJECT DeviceObject;
149 UNICODE_STRING DeviceName = UNICODE_STRING_INITIALIZER(L"\\Device\\Afd");
150 NTSTATUS Status;
151
152 Status = IoCreateDevice(DriverObject,
153 sizeof(DEVICE_EXTENSION),
154 &DeviceName,
155 FILE_DEVICE_NAMED_PIPE,
156 0,
157 FALSE,
158 &DeviceObject);
159 if (!NT_SUCCESS(Status)) {
160 AFD_DbgPrint(MIN_TRACE, ("Could not create device (0x%X).\n", Status));
161 return Status;
162 }
163
164 DeviceObject->Flags |= DO_DIRECT_IO;
165
166 DeviceExt = DeviceObject->DeviceExtension;
167 KeInitializeSpinLock(&DeviceExt->FCBListLock);
168 InitializeListHead(&DeviceExt->FCBListHead);
169
170 DriverObject->MajorFunction[IRP_MJ_CREATE] = AfdCreate;
171 DriverObject->MajorFunction[IRP_MJ_CLOSE] = AfdClose;
172 DriverObject->MajorFunction[IRP_MJ_READ] = AfdRead;
173 DriverObject->MajorFunction[IRP_MJ_WRITE] = AfdWrite;
174 DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = AfdFileSystemControl;
175 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = AfdDispatch;
176 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = AfdClose;
177
178 DriverObject->DriverUnload = (PDRIVER_UNLOAD)AfdUnload;
179
180 /* ExInitializeNPagedLookasideList(
181 &BufferLookasideList,
182 NULL,
183 NULL,
184 0,
185 sizeof(AFD_BUFFER),
186 TAG('A', 'F', 'D', 'B'),
187 0);*/
188
189 /* ExInitializeNPagedLookasideList(
190 &ReadRequestLookasideList,
191 NULL,
192 NULL,
193 0,
194 sizeof(AFD_READ_REQUEST),
195 TAG('A', 'F', 'D', 'R'),
196 0);*/
197
198
199 return STATUS_SUCCESS;
200 }
201
202 /* EOF */