More work on winsock stack (ping is now working)
[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 default:
85 AFD_DbgPrint(MIN_TRACE, ("Unknown IOCTL (0x%X).\n",
86 IrpSp->Parameters.DeviceIoControl.IoControlCode));
87 Status = STATUS_NOT_IMPLEMENTED;
88 break;
89 }
90
91 if (Status != STATUS_PENDING) {
92 Irp->IoStatus.Status = Status;
93 IoCompleteRequest(Irp, IO_NETWORK_INCREMENT);
94 }
95
96 AFD_DbgPrint(MAX_TRACE, ("Leaving. Status (0x%X).\n", Status));
97
98 return Status;
99 }
100
101
102 VOID AfdUnload(
103 PDRIVER_OBJECT DriverObject)
104 /*
105 * FUNCTION: Unloads the driver
106 * ARGUMENTS:
107 * DriverObject = Pointer to driver object created by the system
108 */
109 {
110 DbgPrint("Unloading Ancillary Function Driver\n");
111 }
112
113
114 NTSTATUS
115 STDCALL
116 DriverEntry(
117 PDRIVER_OBJECT DriverObject,
118 PUNICODE_STRING RegistryPath)
119 /*
120 * FUNCTION: Called by the system to initialize the driver
121 * ARGUMENTS:
122 * DriverObject = object describing this driver
123 * RegistryPath = path to our configuration entries
124 * RETURNS:
125 * Status of operation
126 */
127 {
128 PDEVICE_EXTENSION DeviceExt;
129 PDEVICE_OBJECT DeviceObject;
130 UNICODE_STRING DeviceName;
131 NTSTATUS Status;
132
133 DbgPrint("Ancillary Function Driver\n");
134
135 RtlInitUnicodeString(&DeviceName, L"\\Device\\Afd");
136 Status = IoCreateDevice(DriverObject,
137 sizeof(DEVICE_EXTENSION),
138 &DeviceName,
139 FILE_DEVICE_NAMED_PIPE,
140 0,
141 FALSE,
142 &DeviceObject);
143 if (!NT_SUCCESS(Status)) {
144 AFD_DbgPrint(MIN_TRACE, ("Could not create device (0x%X).\n", Status));
145 return Status;
146 }
147
148 DeviceObject->Flags |= DO_DIRECT_IO;
149
150 DeviceExt = DeviceObject->DeviceExtension;
151 KeInitializeSpinLock(&DeviceExt->FCBListLock);
152 InitializeListHead(&DeviceExt->FCBListHead);
153
154 DriverObject->MajorFunction[IRP_MJ_CREATE] = AfdCreate;
155 DriverObject->MajorFunction[IRP_MJ_CLOSE] = AfdClose;
156 DriverObject->MajorFunction[IRP_MJ_READ] = AfdRead;
157 DriverObject->MajorFunction[IRP_MJ_WRITE] = AfdWrite;
158 DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = AfdFileSystemControl;
159 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = AfdDispatch;
160 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = AfdClose;
161
162 DriverObject->DriverUnload = (PDRIVER_UNLOAD)AfdUnload;
163
164 /* ExInitializeNPagedLookasideList(
165 &BufferLookasideList,
166 NULL,
167 NULL,
168 0,
169 sizeof(AFD_BUFFER),
170 TAG('A', 'F', 'D', 'B'),
171 0);*/
172
173 /* ExInitializeNPagedLookasideList(
174 &ReadRequestLookasideList,
175 NULL,
176 NULL,
177 0,
178 sizeof(AFD_READ_REQUEST),
179 TAG('A', 'F', 'D', 'R'),
180 0);*/
181
182
183 return STATUS_SUCCESS;
184 }
185
186 /* EOF */