2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: drivers/net/afd/afd/context.c
5 * PURPOSE: Ancillary functions driver
6 * PROGRAMMER: Art Yerkes (ayerkes@speakeasy.net)
13 AfdGetContext( PDEVICE_OBJECT DeviceObject
, PIRP Irp
,
14 PIO_STACK_LOCATION IrpSp
) {
15 NTSTATUS Status
= STATUS_INVALID_PARAMETER
;
16 PFILE_OBJECT FileObject
= IrpSp
->FileObject
;
17 PAFD_FCB FCB
= FileObject
->FsContext
;
18 UINT ContextSize
= IrpSp
->Parameters
.DeviceIoControl
.OutputBufferLength
;
20 if( !SocketAcquireStateLock( FCB
) ) return LostSocket( Irp
);
22 if( FCB
->ContextSize
< ContextSize
) ContextSize
= FCB
->ContextSize
;
25 RtlCopyMemory( Irp
->UserBuffer
,
28 Status
= STATUS_SUCCESS
;
31 AFD_DbgPrint(MID_TRACE
,("Returning %x\n", Status
));
33 return UnlockAndMaybeComplete( FCB
, Status
, Irp
, ContextSize
);
37 AfdGetContextSize( PDEVICE_OBJECT DeviceObject
, PIRP Irp
,
38 PIO_STACK_LOCATION IrpSp
)
40 PFILE_OBJECT FileObject
= IrpSp
->FileObject
;
41 PAFD_FCB FCB
= FileObject
->FsContext
;
43 if( !SocketAcquireStateLock( FCB
) ) return LostSocket( Irp
);
45 if (IrpSp
->Parameters
.DeviceIoControl
.OutputBufferLength
< sizeof(ULONG
))
47 AFD_DbgPrint(MIN_TRACE
,("Buffer too small\n"));
48 return UnlockAndMaybeComplete(FCB
, STATUS_BUFFER_TOO_SMALL
, Irp
, sizeof(ULONG
));
51 RtlCopyMemory(Irp
->UserBuffer
,
55 return UnlockAndMaybeComplete(FCB
, STATUS_SUCCESS
, Irp
, sizeof(ULONG
));
59 AfdSetContext( PDEVICE_OBJECT DeviceObject
, PIRP Irp
,
60 PIO_STACK_LOCATION IrpSp
) {
61 PFILE_OBJECT FileObject
= IrpSp
->FileObject
;
62 PAFD_FCB FCB
= FileObject
->FsContext
;
63 PVOID Context
= LockRequest(Irp
, IrpSp
);
65 if( !SocketAcquireStateLock( FCB
) ) return LostSocket( Irp
);
68 return UnlockAndMaybeComplete(FCB
, STATUS_NO_MEMORY
, Irp
, 0);
71 ExFreePool( FCB
->Context
);
75 FCB
->Context
= ExAllocatePool( PagedPool
,
76 IrpSp
->Parameters
.DeviceIoControl
.InputBufferLength
);
78 if( !FCB
->Context
) return UnlockAndMaybeComplete( FCB
, STATUS_NO_MEMORY
, Irp
, 0 );
80 FCB
->ContextSize
= IrpSp
->Parameters
.DeviceIoControl
.InputBufferLength
;
82 RtlCopyMemory( FCB
->Context
,
86 return UnlockAndMaybeComplete( FCB
, STATUS_SUCCESS
, Irp
, 0 );