ReactOS  0.4.14-dev-98-gb0d4763
bind.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS kernel
4  * FILE: drivers/net/afd/afd/bind.c
5  * PURPOSE: Ancillary functions driver
6  * PROGRAMMER: Art Yerkes (ayerkes@speakeasy.net)
7  * UPDATE HISTORY:
8  * 20040708 Created
9  */
10 
11 #include "afd.h"
12 
15 
16  AFD_DbgPrint(MID_TRACE,("Called (AF %u)\n",
17  FCB->LocalAddress->Address[0].AddressType));
18 
19  if( !FCB->TdiDeviceName.Length || !FCB->TdiDeviceName.Buffer ) {
20  AFD_DbgPrint(MIN_TRACE,("Null Device\n"));
21  return STATUS_NO_SUCH_DEVICE;
22  }
23  if( !FCB->LocalAddress ) {
24  AFD_DbgPrint(MIN_TRACE,("No local address\n"));
26  }
27 
28  Status = TdiOpenAddressFile(&FCB->TdiDeviceName,
29  FCB->LocalAddress,
30  ShareType,
31  &FCB->AddressFile.Handle,
32  &FCB->AddressFile.Object );
33  if (!NT_SUCCESS(Status))
34  return Status;
35 
37  {
38  if (!FCB->Recv.Size)
39  {
40  Status = TdiQueryMaxDatagramLength(FCB->AddressFile.Object,
41  &FCB->Recv.Size);
42  }
43 
44  if (NT_SUCCESS(Status) && !FCB->Recv.Window)
45  {
46  FCB->Recv.Window = ExAllocatePoolWithTag(PagedPool,
47  FCB->Recv.Size,
49 
50  if (!FCB->Recv.Window)
52  }
53 
54  if (NT_SUCCESS(Status) && FCB->Recv.Content < FCB->Recv.Size)
55  {
56  Status = TdiReceiveDatagram(&FCB->ReceiveIrp.InFlightRequest,
57  FCB->AddressFile.Object,
58  0,
59  FCB->Recv.Window,
60  FCB->Recv.Size,
61  FCB->AddressFrom,
63  FCB);
64 
65  /* We don't want to wait for this read to complete. */
67  }
68  }
69 
70  AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
71 
72  return Status;
73 }
74 
80  PAFD_FCB FCB = FileObject->FsContext;
81  PAFD_BIND_DATA BindReq;
82  HANDLE UserHandle = NULL;
83 
85 
86  AFD_DbgPrint(MID_TRACE,("Called\n"));
87 
88  if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
89  if( !(BindReq = LockRequest( Irp, IrpSp, FALSE, NULL )) )
91  Irp, 0 );
92 
93  if (FCB->LocalAddress)
94  {
96  }
97 
98  FCB->LocalAddress = TaCopyTransportAddress( &BindReq->Address );
99 
100  if( FCB->LocalAddress )
101  Status = TdiBuildConnectionInfo( &FCB->AddressFrom,
102  FCB->LocalAddress );
103 
104  if( NT_SUCCESS(Status) )
105  Status = WarmSocketForBind( FCB, BindReq->ShareType );
106  AFD_DbgPrint(MID_TRACE,("FCB->Flags %x\n", FCB->Flags));
107 
108  if (NT_SUCCESS(Status))
109  {
110  Status = ObOpenObjectByPointer(FCB->AddressFile.Object,
111  0,
112  NULL,
115  Irp->RequestorMode,
116  &UserHandle);
117  if (NT_SUCCESS(Status))
118  FCB->State = SOCKET_STATE_BOUND;
119  }
120 
121  /* MSAFD relies on us returning the address file handle in the IOSB */
123  (ULONG_PTR)UserHandle);
124 }
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
#define MID_TRACE
Definition: debug.h:15
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
Definition: cdstruc.h:908
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
PVOID LockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Output, KPROCESSOR_MODE *LockMode)
Definition: lock.c:24
LONG NTSTATUS
Definition: precomp.h:26
#define TAG_AFD_TRANSPORT_ADDRESS
Definition: afd.h:39
NTSTATUS WarmSocketForBind(PAFD_FCB FCB, ULONG ShareType)
Definition: bind.c:13
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
NTSTATUS NTAPI UnlockAndMaybeComplete(PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
Definition: lock.c:375
NTSTATUS NTAPI ObOpenObjectByPointer(IN PVOID Object, IN ULONG HandleAttributes, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PHANDLE Handle)
Definition: obhandle.c:2739
uint32_t ULONG_PTR
Definition: typedefs.h:63
NTSTATUS TdiOpenAddressFile(PUNICODE_STRING DeviceName, PTRANSPORT_ADDRESS Name, ULONG ShareType, PHANDLE AddressHandle, PFILE_OBJECT *AddressObject)
Definition: tdi.c:170
#define AFD_ENDPOINT_CONNECTIONLESS
Definition: shared.h:153
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define TAG_AFD_DATA_BUFFER
Definition: afd.h:38
Definition: afd.h:161
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136
* PFILE_OBJECT
Definition: iotypes.h:1955
NTSTATUS TdiBuildConnectionInfo(PTDI_CONNECTION_INFORMATION *ConnectionInfo, PTRANSPORT_ADDRESS Address)
Definition: tdiconn.c:237
ULONG Flags
Definition: ntfs.h:532
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTSTATUS TdiQueryMaxDatagramLength(PFILE_OBJECT FileObject, PUINT MaxDatagramLength)
Definition: tdi.c:226
IO_COMPLETION_ROUTINE PacketSocketRecvComplete
Definition: afd.h:312
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
NTSTATUS TdiReceiveDatagram(PIRP *Irp, PFILE_OBJECT TransportObject, USHORT Flags, PCHAR Buffer, UINT BufferLength, PTDI_CONNECTION_INFORMATION Addr, PIO_COMPLETION_ROUTINE CompletionRoutine, PVOID CompletionContext)
Definition: tdi.c:1058
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
NTSTATUS LostSocket(PIRP Irp)
Definition: lock.c:387
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
ULONG ShareType
Definition: shared.h:39
#define SOCKET_STATE_BOUND
Definition: afd.h:74
unsigned int ULONG
Definition: retypes.h:1
PTRANSPORT_ADDRESS TaCopyTransportAddress(PTRANSPORT_ADDRESS OtherAddress)
Definition: tdiconn.c:80
#define MIN_TRACE
Definition: debug.h:14
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2966
NTSTATUS NTAPI AfdBindSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: bind.c:76
TRANSPORT_ADDRESS Address
Definition: shared.h:40