- Update AFD's shared header
[reactos.git] / reactos / drivers / network / afd / afd / context.c
1 /* $Id$
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)
7 * UPDATE HISTORY:
8 * 20040708 Created
9 */
10 #include "afd.h"
11 #include "tdi_proto.h"
12 #include "tdiconn.h"
13 #include "debug.h"
14
15 NTSTATUS NTAPI
16 AfdGetContext( PDEVICE_OBJECT DeviceObject, PIRP Irp,
17 PIO_STACK_LOCATION IrpSp ) {
18 NTSTATUS Status = STATUS_INVALID_PARAMETER;
19 PFILE_OBJECT FileObject = IrpSp->FileObject;
20 PAFD_FCB FCB = FileObject->FsContext;
21 UINT ContextSize = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
22
23 if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
24
25 if( FCB->ContextSize < ContextSize ) ContextSize = FCB->ContextSize;
26
27 if( FCB->Context ) {
28 RtlCopyMemory( Irp->UserBuffer,
29 FCB->Context,
30 ContextSize );
31 Status = STATUS_SUCCESS;
32 }
33
34 AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
35
36 return UnlockAndMaybeComplete( FCB, Status, Irp, ContextSize );
37 }
38
39 NTSTATUS NTAPI
40 AfdGetContextSize( PDEVICE_OBJECT DeviceObject, PIRP Irp,
41 PIO_STACK_LOCATION IrpSp )
42 {
43 PFILE_OBJECT FileObject = IrpSp->FileObject;
44 PAFD_FCB FCB = FileObject->FsContext;
45
46 if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
47
48 if (IrpSp->Parameters.DeviceIoControl.OutputBufferLength < sizeof(ULONG))
49 return UnlockAndMaybeComplete(FCB, STATUS_BUFFER_TOO_SMALL, Irp, sizeof(ULONG));
50
51 RtlCopyMemory(Irp->UserBuffer,
52 &FCB->ContextSize,
53 sizeof(ULONG));
54
55 return UnlockAndMaybeComplete(FCB, STATUS_SUCCESS, Irp, sizeof(ULONG));
56 }
57
58 NTSTATUS NTAPI
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
64 if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
65
66 if( FCB->Context ) {
67 ExFreePool( FCB->Context );
68 FCB->ContextSize = 0;
69 }
70
71 FCB->Context = ExAllocatePool( PagedPool,
72 IrpSp->Parameters.DeviceIoControl.InputBufferLength );
73
74 if( !FCB->Context ) return UnlockAndMaybeComplete( FCB, STATUS_NO_MEMORY, Irp, 0 );
75
76 FCB->ContextSize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
77
78 RtlCopyMemory( FCB->Context,
79 IrpSp->Parameters.DeviceIoControl.Type3InputBuffer,
80 FCB->ContextSize );
81
82 return UnlockAndMaybeComplete( FCB, STATUS_SUCCESS, Irp, 0 );
83 }