2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS NDIS User I/O driver
5 * PURPOSE: Driver entry point and protocol initialization
6 * PROGRAMMERS: Cameron Gutman (cameron.gutman@reactos.org)
14 PDEVICE_OBJECT GlobalDeviceObject
;
15 NDIS_HANDLE GlobalProtocolHandle
;
16 KSPIN_LOCK GlobalAdapterListLock
;
17 LIST_ENTRY GlobalAdapterList
;
18 NDIS_HANDLE GlobalPacketPoolHandle
;
19 NDIS_HANDLE GlobalBufferPoolHandle
;
21 NDIS_STRING ProtocolName
= RTL_CONSTANT_STRING(L
"NDISUIO");
23 VOID NTAPI
NduUnload(PDRIVER_OBJECT DriverObject
)
25 DPRINT1("NDISUIO: Unloaded\n");
30 DriverEntry(PDRIVER_OBJECT DriverObject
,
31 PUNICODE_STRING RegistryPath
)
34 NDIS_PROTOCOL_CHARACTERISTICS Chars
;
35 UNICODE_STRING NtDeviceName
= RTL_CONSTANT_STRING(NDISUIO_DEVICE_NAME_NT
);
36 UNICODE_STRING DosDeviceName
= RTL_CONSTANT_STRING(NDISUIO_DEVICE_NAME_DOS
);
38 /* Setup dispatch functions */
39 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = NduDispatchCreate
;
40 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = NduDispatchClose
;
41 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = NduDispatchDeviceControl
;
42 DriverObject
->MajorFunction
[IRP_MJ_READ
] = NduDispatchRead
;
43 DriverObject
->MajorFunction
[IRP_MJ_WRITE
] = NduDispatchWrite
;
44 DriverObject
->DriverUnload
= NduUnload
;
46 /* Setup global state */
47 InitializeListHead(&GlobalAdapterList
);
48 KeInitializeSpinLock(&GlobalAdapterListLock
);
50 /* Create the NDISUIO device object */
51 Status
= IoCreateDevice(DriverObject
,
54 FILE_DEVICE_SECURE_OPEN
,
58 if (!NT_SUCCESS(Status
))
60 DPRINT1("Failed to create device object with status 0x%x\n", Status
);
64 /* Create a symbolic link into the DOS devices namespace */
65 Status
= IoCreateSymbolicLink(&DosDeviceName
, &NtDeviceName
);
66 if (!NT_SUCCESS(Status
))
68 DPRINT1("Failed to create symbolic link with status 0x%x\n", Status
);
69 IoDeleteDevice(GlobalDeviceObject
);
73 /* Create the buffer pool */
74 NdisAllocateBufferPool(&Status
,
75 &GlobalBufferPoolHandle
,
77 if (Status
!= NDIS_STATUS_SUCCESS
)
79 DPRINT1("Failed to allocate buffer pool with status 0x%x\n", Status
);
80 IoDeleteSymbolicLink(&DosDeviceName
);
81 IoDeleteDevice(GlobalDeviceObject
);
85 /* Create the packet pool */
86 NdisAllocatePacketPool(&Status
,
87 &GlobalPacketPoolHandle
,
90 if (Status
!= NDIS_STATUS_SUCCESS
)
92 DPRINT1("Failed to allocate packet pool with status 0x%x\n", Status
);
93 NdisFreeBufferPool(GlobalBufferPoolHandle
);
94 IoDeleteSymbolicLink(&DosDeviceName
);
95 IoDeleteDevice(GlobalDeviceObject
);
99 /* Register the protocol with NDIS */
100 RtlZeroMemory(&Chars
, sizeof(Chars
));
101 Chars
.MajorNdisVersion
= NDIS_MAJOR_VERSION
;
102 Chars
.MinorNdisVersion
= NDIS_MINOR_VERSION
;
103 Chars
.OpenAdapterCompleteHandler
= NduOpenAdapterComplete
;
104 Chars
.CloseAdapterCompleteHandler
= NduCloseAdapterComplete
;
105 Chars
.SendCompleteHandler
= NduSendComplete
;
106 Chars
.TransferDataCompleteHandler
= NduTransferDataComplete
;
107 Chars
.ResetCompleteHandler
= NduResetComplete
;
108 Chars
.RequestCompleteHandler
= NduRequestComplete
;
109 Chars
.ReceiveHandler
= NduReceive
;
110 Chars
.ReceiveCompleteHandler
= NduReceiveComplete
;
111 Chars
.StatusHandler
= NduStatus
;
112 Chars
.StatusCompleteHandler
= NduStatusComplete
;
113 Chars
.Name
= ProtocolName
;
114 Chars
.BindAdapterHandler
= NduBindAdapter
;
115 Chars
.UnbindAdapterHandler
= NduUnbindAdapter
;
117 NdisRegisterProtocol(&Status
,
118 &GlobalProtocolHandle
,
121 if (Status
!= NDIS_STATUS_SUCCESS
)
123 DPRINT1("Failed to register protocol with status 0x%x\n", Status
);
124 NdisFreePacketPool(GlobalPacketPoolHandle
);
125 NdisFreeBufferPool(GlobalBufferPoolHandle
);
126 IoDeleteSymbolicLink(&DosDeviceName
);
127 IoDeleteDevice(GlobalDeviceObject
);
131 DPRINT1("NDISUIO: Loaded\n");
133 return STATUS_SUCCESS
;