464bbf3513b265ae0b33b40a8b09564d80b0b9ae
[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
17 #endif /* DBG */
18
19
20 NTSTATUS
21 STDCALL
22 AfdFileSystemControl(
23 PDEVICE_OBJECT DeviceObject,
24 PIRP Irp)
25 {
26 UNIMPLEMENTED
27
28 Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
29 Irp->IoStatus.Information = 0;
30 return STATUS_UNSUCCESSFUL;
31 }
32
33
34 NTSTATUS
35 STDCALL
36 AfdDispatch(
37 PDEVICE_OBJECT DeviceObject,
38 PIRP Irp)
39 /*
40 * FUNCTION: IOCTL dispatch routine
41 * ARGUMENTS:
42 * DeviceObject = Pointer to a device object for this driver
43 * Irp = Pointer to a I/O request packet
44 * RETURNS:
45 * Status of the operation
46 */
47 {
48 NTSTATUS Status;
49 PIO_STACK_LOCATION IrpSp;
50
51 IrpSp = IoGetCurrentIrpStackLocation(Irp);
52
53 AFD_DbgPrint(MAX_TRACE, ("Called. DeviceObject is at (0x%X), IRP is at (0x%X), IrpSp->FileObject (0x%X).\n",
54 DeviceObject, Irp, IrpSp->FileObject));
55
56 Irp->IoStatus.Information = 0;
57
58 switch (IrpSp->Parameters.DeviceIoControl.IoControlCode) {
59 case IOCTL_AFD_BIND:
60 Status = AfdDispBind(Irp, IrpSp);
61 break;
62
63 case IOCTL_AFD_LISTEN:
64 Status = AfdDispListen(Irp, IrpSp);
65 break;
66
67 case IOCTL_AFD_SENDTO:
68 Status = AfdDispSendTo(Irp, IrpSp);
69 break;
70
71 case IOCTL_AFD_RECVFROM:
72 Status = AfdDispRecvFrom(Irp, IrpSp);
73 break;
74
75 default:
76 AFD_DbgPrint(MIN_TRACE, ("Unknown IOCTL (0x%X).\n",
77 IrpSp->Parameters.DeviceIoControl.IoControlCode));
78 Status = STATUS_NOT_IMPLEMENTED;
79 break;
80 }
81
82 if (Status != STATUS_PENDING) {
83 Irp->IoStatus.Status = Status;
84 IoCompleteRequest(Irp, IO_NETWORK_INCREMENT);
85 }
86
87 AFD_DbgPrint(MAX_TRACE, ("Leaving. Status (0x%X).\n", Status));
88
89 return Status;
90 }
91
92
93 VOID AfdUnload(
94 PDRIVER_OBJECT DriverObject)
95 /*
96 * FUNCTION: Unloads the driver
97 * ARGUMENTS:
98 * DriverObject = Pointer to driver object created by the system
99 */
100 {
101 DbgPrint("Unloading Ancillary Function Driver\n");
102 }
103
104
105 NTSTATUS
106 STDCALL
107 DriverEntry(
108 PDRIVER_OBJECT DriverObject,
109 PUNICODE_STRING RegistryPath)
110 /*
111 * FUNCTION: Called by the system to initialize the driver
112 * ARGUMENTS:
113 * DriverObject = object describing this driver
114 * RegistryPath = path to our configuration entries
115 * RETURNS:
116 * Status of operation
117 */
118 {
119 PDEVICE_EXTENSION DeviceExt;
120 PDEVICE_OBJECT DeviceObject;
121 UNICODE_STRING DeviceName;
122 NTSTATUS Status;
123
124 DbgPrint("Ancillary Function Driver\n");
125
126 RtlInitUnicodeString(&DeviceName, L"\\Device\\Afd");
127 Status = IoCreateDevice(DriverObject,
128 sizeof(DEVICE_EXTENSION),
129 &DeviceName,
130 FILE_DEVICE_NAMED_PIPE,
131 0,
132 FALSE,
133 &DeviceObject);
134 if (!NT_SUCCESS(Status)) {
135 AFD_DbgPrint(MIN_TRACE, ("Could not create device (0x%X).\n", Status));
136 return Status;
137 }
138
139 DeviceObject->Flags |= DO_DIRECT_IO;
140
141 DeviceExt = DeviceObject->DeviceExtension;
142 KeInitializeSpinLock(&DeviceExt->FCBListLock);
143 InitializeListHead(&DeviceExt->FCBListHead);
144
145 DriverObject->MajorFunction[IRP_MJ_CREATE] = AfdCreate;
146 DriverObject->MajorFunction[IRP_MJ_CLOSE] = AfdClose;
147 DriverObject->MajorFunction[IRP_MJ_READ] = AfdRead;
148 DriverObject->MajorFunction[IRP_MJ_WRITE] = AfdWrite;
149 DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = AfdFileSystemControl;
150 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = AfdDispatch;
151 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = AfdClose;
152
153 DriverObject->DriverUnload = (PDRIVER_UNLOAD)AfdUnload;
154
155 return STATUS_SUCCESS;
156 }
157
158 /* EOF */