[NDISUIO]
[reactos.git] / drivers / network / ndisuio / createclose.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS NDIS User I/O driver
4 * FILE: createclose.c
5 * PURPOSE: IRP_MJ_CREATE and IRP_MJ_CLOSE handling
6 * PROGRAMMERS: Cameron Gutman (cameron.gutman@reactos.org)
7 */
8
9 #include "ndisuio.h"
10
11 #define NDEBUG
12 #include <debug.h>
13
14 NTSTATUS
15 NTAPI
16 NduDispatchCreate(PDEVICE_OBJECT DeviceObject,
17 PIRP Irp)
18 {
19 PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
20
21 ASSERT(DeviceObject == GlobalDeviceObject);
22
23 /* This is associated with an adapter during IOCTL_NDISUIO_OPEN_(WRITE_)DEVICE */
24 IrpSp->FileObject->FsContext = NULL;
25 IrpSp->FileObject->FsContext2 = NULL;
26
27 /* Completed successfully */
28 Irp->IoStatus.Status = STATUS_SUCCESS;
29 Irp->IoStatus.Information = FILE_OPENED;
30 IoCompleteRequest(Irp, IO_NO_INCREMENT);
31
32 /* Return success */
33 return STATUS_SUCCESS;
34 }
35
36 NTSTATUS
37 NTAPI
38 NduDispatchClose(PDEVICE_OBJECT DeviceObject,
39 PIRP Irp)
40 {
41 PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
42 PNDISUIO_ADAPTER_CONTEXT AdapterContext = IrpSp->FileObject->FsContext;
43 PNDISUIO_OPEN_ENTRY OpenEntry = IrpSp->FileObject->FsContext2;
44
45 ASSERT(DeviceObject == GlobalDeviceObject);
46
47 /* Check if this handle was ever associated with an adapter */
48 if (AdapterContext != NULL)
49 {
50 ASSERT(OpenEntry != NULL);
51
52 /* Call the our helper */
53 DereferenceAdapterContextWithOpenEntry(AdapterContext, OpenEntry);
54 }
55
56 /* Completed */
57 Irp->IoStatus.Status = STATUS_SUCCESS;
58 Irp->IoStatus.Information = 0;
59 IoCompleteRequest(Irp, IO_NO_INCREMENT);
60
61 /* Return success */
62 return STATUS_SUCCESS;
63 }