2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: drivers/net/afd/afd/tdiconn.c
5 * PURPOSE: Ancillary functions driver
6 * PROGRAMMER: Art Yerkes (ayerkes@speakeasy.net)
14 UINT
TdiAddressSizeFromType( UINT AddressType
) {
15 switch( AddressType
) {
17 return sizeof(TA_IP_ADDRESS
);
19 AFD_DbgPrint(MID_TRACE
,("TdiAddressSizeFromType - invalid type: %x\n", AddressType
));
25 UINT
TaLengthOfAddress( PTA_ADDRESS Addr
) {
26 UINT AddrLen
= 2 * sizeof( USHORT
) + Addr
->AddressLength
;
27 AFD_DbgPrint(MID_TRACE
,("AddrLen %x\n", AddrLen
));
31 UINT
TaLengthOfTransportAddress( PTRANSPORT_ADDRESS Addr
) {
32 UINT AddrLen
= 2 * sizeof( ULONG
) + Addr
->Address
[0].AddressLength
;
33 AFD_DbgPrint(MID_TRACE
,("AddrLen %x\n", AddrLen
));
37 VOID
TaCopyAddressInPlace( PTA_ADDRESS Target
,
38 PTA_ADDRESS Source
) {
39 UINT AddrLen
= TaLengthOfAddress( Source
);
40 RtlCopyMemory( Target
, Source
, AddrLen
);
43 PTA_ADDRESS
TaCopyAddress( PTA_ADDRESS Source
) {
44 UINT AddrLen
= TaLengthOfAddress( Source
);
45 PVOID Buffer
= ExAllocatePool( NonPagedPool
, AddrLen
);
46 RtlCopyMemory( Buffer
, Source
, AddrLen
);
50 VOID
TaCopyTransportAddressInPlace( PTRANSPORT_ADDRESS Target
,
51 PTRANSPORT_ADDRESS Source
) {
52 UINT AddrLen
= TaLengthOfTransportAddress( Source
);
53 RtlCopyMemory( Target
, Source
, AddrLen
);
56 PTRANSPORT_ADDRESS
TaCopyTransportAddress( PTRANSPORT_ADDRESS OtherAddress
) {
60 ASSERT(OtherAddress
->TAAddressCount
== 1);
61 AddrLen
= TaLengthOfTransportAddress( OtherAddress
);
62 A
= ExAllocatePool( NonPagedPool
, AddrLen
);
65 TaCopyTransportAddressInPlace( A
, OtherAddress
);
70 NTSTATUS TdiBuildNullConnectionInfoInPlace
71 ( PTDI_CONNECTION_INFORMATION ConnInfo
,
74 * FUNCTION: Builds a NULL TDI connection information structure
76 * ConnectionInfo = Address of buffer to place connection information
77 * Type = TDI style address type (TDI_ADDRESS_TYPE_XXX).
83 PTRANSPORT_ADDRESS TransportAddress
;
85 TdiAddressSize
= TdiAddressSizeFromType(Type
);
87 RtlZeroMemory(ConnInfo
,
88 sizeof(TDI_CONNECTION_INFORMATION
) +
91 ConnInfo
->OptionsLength
= sizeof(ULONG
);
92 ConnInfo
->RemoteAddressLength
= TdiAddressSize
;
93 ConnInfo
->RemoteAddress
= TransportAddress
=
94 (PTRANSPORT_ADDRESS
)&ConnInfo
[1];
95 TransportAddress
->TAAddressCount
= 1;
96 TransportAddress
->Address
[0].AddressType
= Type
;
98 return STATUS_SUCCESS
;
101 NTSTATUS TdiBuildNullConnectionInfo
102 ( PTDI_CONNECTION_INFORMATION
*ConnectionInfo
,
105 * FUNCTION: Builds a NULL TDI connection information structure
107 * ConnectionInfo = Address of buffer pointer to allocate connection
109 * Type = TDI style address type (TDI_ADDRESS_TYPE_XXX).
111 * Status of operation
114 PTDI_CONNECTION_INFORMATION ConnInfo
;
115 ULONG TdiAddressSize
;
118 TdiAddressSize
= TdiAddressSizeFromType(Type
);
120 ConnInfo
= (PTDI_CONNECTION_INFORMATION
)
121 ExAllocatePool(NonPagedPool
,
122 sizeof(TDI_CONNECTION_INFORMATION
) +
125 return STATUS_INSUFFICIENT_RESOURCES
;
127 Status
= TdiBuildNullConnectionInfoInPlace( ConnInfo
, Type
);
129 if (!NT_SUCCESS(Status
))
130 ExFreePool( ConnInfo
);
132 *ConnectionInfo
= ConnInfo
;
134 ConnInfo
->RemoteAddress
= (PTA_ADDRESS
)&ConnInfo
[1];
135 ConnInfo
->RemoteAddressLength
= TdiAddressSize
;
142 TdiBuildConnectionInfoInPlace
143 ( PTDI_CONNECTION_INFORMATION ConnectionInfo
,
144 PTRANSPORT_ADDRESS Address
) {
145 NTSTATUS Status
= STATUS_SUCCESS
;
147 RtlCopyMemory( ConnectionInfo
->RemoteAddress
,
149 ConnectionInfo
->RemoteAddressLength
);
156 TdiBuildConnectionInfo
157 ( PTDI_CONNECTION_INFORMATION
*ConnectionInfo
,
158 PTRANSPORT_ADDRESS Address
) {
159 NTSTATUS Status
= TdiBuildNullConnectionInfo
160 ( ConnectionInfo
, Address
->Address
[0].AddressType
);
162 if( NT_SUCCESS(Status
) )
163 TdiBuildConnectionInfoInPlace( *ConnectionInfo
, Address
);
169 TdiBuildConnectionInfoPair
170 ( PTDI_CONNECTION_INFO_PAIR ConnectionInfo
,
171 PTRANSPORT_ADDRESS From
, PTRANSPORT_ADDRESS To
)
173 * FUNCTION: Fill a TDI_CONNECTION_INFO_PAIR struct will the two addresses
176 * ConnectionInfo: The pair
177 * From: The from address
180 * Status of the operation
185 ULONG TdiAddressSize
;
187 /* FIXME: Get from socket information */
188 TdiAddressSize
= TdiAddressSizeFromType(From
->Address
[0].AddressType
);
189 SizeOfEntry
= TdiAddressSize
+ sizeof(TDI_CONNECTION_INFORMATION
);
191 LayoutFrame
= (PCHAR
)ExAllocatePool(NonPagedPool
, 2 * SizeOfEntry
);
194 AFD_DbgPrint(MIN_TRACE
, ("Insufficient resources.\n"));
195 return STATUS_INSUFFICIENT_RESOURCES
;
198 RtlZeroMemory( LayoutFrame
, 2 * SizeOfEntry
);
200 PTDI_CONNECTION_INFORMATION
201 FromTdiConn
= (PTDI_CONNECTION_INFORMATION
)LayoutFrame
,
202 ToTdiConn
= (PTDI_CONNECTION_INFORMATION
)LayoutFrame
+ SizeOfEntry
;
205 TdiBuildConnectionInfoInPlace( FromTdiConn
, From
);
207 TdiBuildNullConnectionInfoInPlace( FromTdiConn
,
208 From
->Address
[0].AddressType
);
211 TdiBuildConnectionInfoInPlace( ToTdiConn
, To
);
213 return STATUS_SUCCESS
;
216 PTA_ADDRESS
TdiGetRemoteAddress( PTDI_CONNECTION_INFORMATION TdiConn
)
218 * Convenience function that rounds out the abstraction of
219 * the TDI_CONNECTION_INFORMATION struct.
222 return TdiConn
->RemoteAddress
;