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)
12 UINT
TdiAddressSizeFromType( UINT AddressType
) {
13 switch( AddressType
) {
14 case TDI_ADDRESS_TYPE_IP
:
15 return TDI_ADDRESS_LENGTH_IP
;
16 case TDI_ADDRESS_TYPE_APPLETALK
:
17 return TDI_ADDRESS_LENGTH_APPLETALK
;
18 case TDI_ADDRESS_TYPE_NETBIOS
:
19 return TDI_ADDRESS_LENGTH_NETBIOS
;
20 /* case TDI_ADDRESS_TYPE_NS: */
21 case TDI_ADDRESS_TYPE_IPX
:
22 return TDI_ADDRESS_LENGTH_IPX
;
23 case TDI_ADDRESS_TYPE_VNS
:
24 return TDI_ADDRESS_LENGTH_VNS
;
26 DbgPrint("TdiAddressSizeFromType - invalid type: %x\n", AddressType
);
31 UINT
TaLengthOfAddress( PTA_ADDRESS Addr
)
33 UINT AddrLen
= Addr
->AddressLength
;
38 AddrLen
+= 2 * sizeof( USHORT
);
40 AFD_DbgPrint(MID_TRACE
,("AddrLen %x\n", AddrLen
));
45 UINT
TaLengthOfTransportAddress( PTRANSPORT_ADDRESS Addr
)
47 UINT AddrLen
= TaLengthOfAddress(&Addr
->Address
[0]);
52 AddrLen
+= sizeof(ULONG
);
54 AFD_DbgPrint(MID_TRACE
,("AddrLen %x\n", AddrLen
));
59 UINT
TaLengthOfTransportAddressByType(UINT AddressType
)
61 UINT AddrLen
= TdiAddressSizeFromType(AddressType
);
66 AddrLen
+= sizeof(ULONG
) + 2 * sizeof(USHORT
);
68 AFD_DbgPrint(MID_TRACE
,("AddrLen %x\n", AddrLen
));
73 VOID
TaCopyAddressInPlace( PTA_ADDRESS Target
,
74 PTA_ADDRESS Source
) {
75 UINT AddrLen
= TaLengthOfAddress( Source
);
76 RtlCopyMemory( Target
, Source
, AddrLen
);
79 PTA_ADDRESS
TaCopyAddress( PTA_ADDRESS Source
) {
80 UINT AddrLen
= TaLengthOfAddress( Source
);
85 Buffer
= ExAllocatePool( NonPagedPool
, AddrLen
);
88 RtlCopyMemory( Buffer
, Source
, AddrLen
);
93 VOID
TaCopyTransportAddressInPlace( PTRANSPORT_ADDRESS Target
,
94 PTRANSPORT_ADDRESS Source
) {
95 UINT AddrLen
= TaLengthOfTransportAddress( Source
);
96 RtlCopyMemory( Target
, Source
, AddrLen
);
99 PTRANSPORT_ADDRESS
TaCopyTransportAddress( PTRANSPORT_ADDRESS OtherAddress
) {
101 PTRANSPORT_ADDRESS A
;
103 AddrLen
= TaLengthOfTransportAddress( OtherAddress
);
107 A
= ExAllocatePool( NonPagedPool
, AddrLen
);
110 TaCopyTransportAddressInPlace( A
, OtherAddress
);
115 NTSTATUS
TdiBuildNullTransportAddressInPlace(PTRANSPORT_ADDRESS A
, UINT AddressType
)
117 A
->TAAddressCount
= 1;
119 A
->Address
[0].AddressLength
= TdiAddressSizeFromType(AddressType
);
120 if (!A
->Address
[0].AddressLength
)
121 return STATUS_INVALID_PARAMETER
;
123 A
->Address
[0].AddressType
= AddressType
;
125 RtlZeroMemory(A
->Address
[0].Address
, A
->Address
[0].AddressLength
);
127 return STATUS_SUCCESS
;
130 PTRANSPORT_ADDRESS
TaBuildNullTransportAddress(UINT AddressType
)
133 PTRANSPORT_ADDRESS A
;
135 AddrLen
= TaLengthOfTransportAddressByType(AddressType
);
139 A
= ExAllocatePool(NonPagedPool
, AddrLen
);
143 if (TdiBuildNullTransportAddressInPlace(A
, AddressType
) != STATUS_SUCCESS
)
153 NTSTATUS TdiBuildNullConnectionInfoInPlace
154 ( PTDI_CONNECTION_INFORMATION ConnInfo
,
157 * FUNCTION: Builds a NULL TDI connection information structure
159 * ConnectionInfo = Address of buffer to place connection information
160 * Type = TDI style address type (TDI_ADDRESS_TYPE_XXX).
162 * Status of operation
165 ULONG TdiAddressSize
;
166 PTRANSPORT_ADDRESS TransportAddress
;
168 TdiAddressSize
= TaLengthOfTransportAddressByType(Type
);
171 AFD_DbgPrint(MIN_TRACE
,("Invalid parameter\n"));
172 return STATUS_INVALID_PARAMETER
;
175 RtlZeroMemory(ConnInfo
,
176 sizeof(TDI_CONNECTION_INFORMATION
) +
179 ConnInfo
->OptionsLength
= sizeof(ULONG
);
180 ConnInfo
->RemoteAddressLength
= TdiAddressSize
;
181 ConnInfo
->RemoteAddress
= TransportAddress
=
182 (PTRANSPORT_ADDRESS
)&ConnInfo
[1];
184 return TdiBuildNullTransportAddressInPlace(TransportAddress
, Type
);
187 NTSTATUS TdiBuildNullConnectionInfo
188 ( PTDI_CONNECTION_INFORMATION
*ConnectionInfo
,
191 * FUNCTION: Builds a NULL TDI connection information structure
193 * ConnectionInfo = Address of buffer pointer to allocate connection
195 * Type = TDI style address type (TDI_ADDRESS_TYPE_XXX).
197 * Status of operation
200 PTDI_CONNECTION_INFORMATION ConnInfo
;
201 ULONG TdiAddressSize
;
204 TdiAddressSize
= TaLengthOfTransportAddressByType(Type
);
205 if (!TdiAddressSize
) {
206 AFD_DbgPrint(MIN_TRACE
,("Invalid parameter\n"));
207 *ConnectionInfo
= NULL
;
208 return STATUS_INVALID_PARAMETER
;
211 ConnInfo
= (PTDI_CONNECTION_INFORMATION
)
212 ExAllocatePool(NonPagedPool
,
213 sizeof(TDI_CONNECTION_INFORMATION
) +
216 *ConnectionInfo
= NULL
;
217 return STATUS_INSUFFICIENT_RESOURCES
;
220 Status
= TdiBuildNullConnectionInfoInPlace( ConnInfo
, Type
);
222 if (!NT_SUCCESS(Status
))
224 ExFreePool( ConnInfo
);
228 *ConnectionInfo
= ConnInfo
;
235 TdiBuildConnectionInfoInPlace
236 ( PTDI_CONNECTION_INFORMATION ConnectionInfo
,
237 PTRANSPORT_ADDRESS Address
) {
238 NTSTATUS Status
= STATUS_SUCCESS
;
241 RtlCopyMemory( ConnectionInfo
->RemoteAddress
,
243 ConnectionInfo
->RemoteAddressLength
);
244 } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
) {
245 Status
= _SEH2_GetExceptionCode();
253 TdiBuildConnectionInfo
254 ( PTDI_CONNECTION_INFORMATION
*ConnectionInfo
,
255 PTRANSPORT_ADDRESS Address
) {
256 NTSTATUS Status
= TdiBuildNullConnectionInfo
257 ( ConnectionInfo
, Address
->Address
[0].AddressType
);
259 if( NT_SUCCESS(Status
) )
260 TdiBuildConnectionInfoInPlace( *ConnectionInfo
, Address
);