ReactOS  0.4.15-dev-1374-g8d3e80e
main.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS NDIS User I/O driver
4  * FILE: main.c
5  * PURPOSE: Driver entry point and protocol initialization
6  * PROGRAMMERS: Cameron Gutman (cameron.gutman@reactos.org)
7  */
8 
9 #include "ndisuio.h"
10 
11 #define NDEBUG
12 #include <debug.h>
13 
18 
20 
22 {
23  DPRINT("NDISUIO: Unloaded\n");
24 }
25 
27 NTAPI
30 {
35 
36  /* Setup dispatch functions */
38  DriverObject->MajorFunction[IRP_MJ_CLOSE] = NduDispatchClose;
40  DriverObject->MajorFunction[IRP_MJ_READ] = NduDispatchRead;
41  DriverObject->MajorFunction[IRP_MJ_WRITE] = NduDispatchWrite;
42  DriverObject->DriverUnload = NduUnload;
43 
44  /* Setup global state */
47 
48  /* Create the NDISUIO device object */
50  0,
51  &NtDeviceName,
53  0,
54  FALSE,
56  if (!NT_SUCCESS(Status))
57  {
58  DPRINT1("Failed to create device object with status 0x%x\n", Status);
59  return Status;
60  }
61 
62  /* Create a symbolic link into the DOS devices namespace */
63  Status = IoCreateSymbolicLink(&DosDeviceName, &NtDeviceName);
64  if (!NT_SUCCESS(Status))
65  {
66  DPRINT1("Failed to create symbolic link with status 0x%x\n", Status);
68  return Status;
69  }
70 
71  /* Register the protocol with NDIS */
72  RtlZeroMemory(&Chars, sizeof(Chars));
82  Chars.ReceiveHandler = NduReceive;
84  Chars.StatusHandler = NduStatus;
86  Chars.Name = ProtocolName;
89 
92  &Chars,
93  sizeof(Chars));
95  {
96  DPRINT1("Failed to register protocol with status 0x%x\n", Status);
99  return Status;
100  }
101 
102  DPRINT("NDISUIO: Loaded\n");
103 
104  return STATUS_SUCCESS;
105 }
#define NDIS_MAJOR_VERSION
Definition: ndisuio.h:78
NDIS_STATUS NTAPI NduNetPnPEvent(NDIS_HANDLE ProtocolBindingContext, PNET_PNP_EVENT NetPnPEvent)
Definition: protocol.c:45
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define NDISUIO_DEVICE_NAME_DOS
Definition: nuiouser.h:6
NTSTATUS NTAPI NduDispatchCreate(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: createclose.c:16
REQUEST_COMPLETE_HANDLER RequestCompleteHandler
Definition: ndis.h:1887
VOID EXPORT NdisRegisterProtocol(OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE NdisProtocolHandle, IN PNDIS_PROTOCOL_CHARACTERISTICS ProtocolCharacteristics, IN UINT CharacteristicsLength)
Definition: protocol.c:1115
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI NduCloseAdapterComplete(NDIS_HANDLE ProtocolBindingContext, NDIS_STATUS Status)
Definition: protocol.c:31
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:213
VOID NTAPI NduUnbindAdapter(PNDIS_STATUS Status, NDIS_HANDLE ProtocolBindingContext, NDIS_HANDLE UnbindContext)
Definition: protocol.c:550
UNBIND_HANDLER UnbindAdapterHandler
Definition: ndis.h:1898
CLOSE_ADAPTER_COMPLETE_HANDLER CloseAdapterCompleteHandler
Definition: ndis.h:1877
VOID NTAPI NduReceiveComplete(NDIS_HANDLE ProtocolBindingContext)
Definition: protocol.c:275
NTSTATUS NTAPI NduDispatchClose(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: createclose.c:40
RECEIVE_COMPLETE_HANDLER ReceiveCompleteHandler
Definition: ndis.h:1892
STATUS_HANDLER StatusHandler
Definition: ndis.h:1893
NTSTATUS NTAPI NduDispatchWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: readwrite.c:158
int NDIS_STATUS
Definition: ntddndis.h:471
VOID NTAPI NduSendComplete(NDIS_HANDLE ProtocolBindingContext, PNDIS_PACKET Packet, NDIS_STATUS Status)
Definition: protocol.c:106
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
VOID NTAPI NduResetComplete(NDIS_HANDLE ProtocolBindingContext, NDIS_STATUS Status)
Definition: protocol.c:137
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
VOID NTAPI NduStatusComplete(NDIS_HANDLE ProtocolBindingContext)
Definition: protocol.c:292
BIND_HANDLER BindAdapterHandler
Definition: ndis.h:1897
void DPRINT(...)
Definition: polytest.cpp:61
KSPIN_LOCK GlobalAdapterListLock
Definition: main.c:16
RESET_COMPLETE_HANDLER ResetCompleteHandler
Definition: ndis.h:1886
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
OPEN_ADAPTER_COMPLETE_HANDLER OpenAdapterCompleteHandler
Definition: ndis.h:1876
#define NDISUIO_DEVICE_NAME_NT
Definition: nuiouser.h:5
VOID NTAPI NduOpenAdapterComplete(NDIS_HANDLE ProtocolBindingContext, NDIS_STATUS Status, NDIS_STATUS OpenStatus)
Definition: protocol.c:16
Status
Definition: gdiplustypes.h:24
VOID NTAPI NduBindAdapter(PNDIS_STATUS Status, NDIS_HANDLE BindContext, PNDIS_STRING DeviceName, PVOID SystemSpecific1, PVOID SystemSpecific2)
Definition: protocol.c:538
TRANSFER_DATA_COMPLETE_HANDLER TransferDataCompleteHandler
Definition: ndis.h:1883
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID NTAPI NduRequestComplete(NDIS_HANDLE ProtocolBindingContext, PNDIS_REQUEST NdisRequest, NDIS_STATUS Status)
Definition: protocol.c:151
STATUS_COMPLETE_HANDLER StatusCompleteHandler
Definition: ndis.h:1894
NTSTATUS NTAPI NduDispatchDeviceControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: ioctl.c:469
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
static char DosDeviceName[DEVICE_SIZE]
Definition: lsdd.c:26
PDEVICE_OBJECT GlobalDeviceObject
Definition: main.c:14
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
static const WCHAR L[]
Definition: oid.c:1250
NTSTATUS NTAPI NduDispatchRead(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: readwrite.c:42
RECEIVE_HANDLER ReceiveHandler
Definition: ndis.h:1889
Definition: typedefs.h:119
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
SEND_COMPLETE_HANDLER SendCompleteHandler
Definition: ndis.h:1879
NTSTATUS NTAPI DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
Definition: main.c:690
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
ULONG KSPIN_LOCK
Definition: env_spec_w32.h:72
LIST_ENTRY GlobalAdapterList
Definition: main.c:17
#define DPRINT1
Definition: precomp.h:8
#define IRP_MJ_READ
Definition: rdpdr.c:46
VOID NTAPI NduStatus(NDIS_HANDLE ProtocolBindingContext, NDIS_STATUS GeneralStatus, PVOID StatusBuffer, UINT StatusBufferSize)
Definition: protocol.c:282
VOID NTAPI NduUnload(PDRIVER_OBJECT DriverObject)
Definition: main.c:21
#define NDIS_MINOR_VERSION
Definition: ndisuio.h:79
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
#define STATUS_SUCCESS
Definition: shellext.h:65
NDIS_STRING ProtocolName
Definition: main.c:19
NDIS_HANDLE GlobalProtocolHandle
Definition: main.c:15
NDIS_STATUS NTAPI NduReceive(NDIS_HANDLE ProtocolBindingContext, NDIS_HANDLE MacReceiveContext, PVOID HeaderBuffer, UINT HeaderBufferSize, PVOID LookAheadBuffer, UINT LookaheadBufferSize, UINT PacketSize)
Definition: protocol.c:166
PNP_EVENT_HANDLER PnPEventHandler
Definition: ndis.h:1899
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
VOID NTAPI NduTransferDataComplete(NDIS_HANDLE ProtocolBindingContext, PNDIS_PACKET Packet, NDIS_STATUS Status, UINT BytesTransferred)
Definition: protocol.c:121