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)
13 UINT
TdiAddressSizeFromType( UINT AddressType
) {
14 switch( AddressType
) {
15 case TDI_ADDRESS_TYPE_IP
:
16 return TDI_ADDRESS_LENGTH_IP
;
17 case TDI_ADDRESS_TYPE_APPLETALK
:
18 return TDI_ADDRESS_LENGTH_APPLETALK
;
19 case TDI_ADDRESS_TYPE_NETBIOS
:
20 return TDI_ADDRESS_LENGTH_NETBIOS
;
21 /* case TDI_ADDRESS_TYPE_NS: */
22 case TDI_ADDRESS_TYPE_IPX
:
23 return TDI_ADDRESS_LENGTH_IPX
;
24 case TDI_ADDRESS_TYPE_VNS
:
25 return TDI_ADDRESS_LENGTH_VNS
;
27 DbgPrint("TdiAddressSizeFromType - invalid type: %x\n", AddressType
);
32 UINT
TaLengthOfAddress( PTA_ADDRESS Addr
)
34 UINT AddrLen
= Addr
->AddressLength
;
39 AddrLen
+= 2 * sizeof( USHORT
);
41 AFD_DbgPrint(MID_TRACE
,("AddrLen %x\n", AddrLen
));
46 UINT
TaLengthOfTransportAddress( PTRANSPORT_ADDRESS Addr
)
48 UINT AddrLen
= TaLengthOfAddress(&Addr
->Address
[0]);
53 AddrLen
+= sizeof(ULONG
);
55 AFD_DbgPrint(MID_TRACE
,("AddrLen %x\n", AddrLen
));
60 UINT
TaLengthOfTransportAddressByType(UINT AddressType
)
62 UINT AddrLen
= TdiAddressSizeFromType(AddressType
);
67 AddrLen
+= sizeof(ULONG
) + 2 * sizeof(USHORT
);
69 AFD_DbgPrint(MID_TRACE
,("AddrLen %x\n", AddrLen
));
74 VOID
TaCopyAddressInPlace( PTA_ADDRESS Target
,
75 PTA_ADDRESS Source
) {
76 UINT AddrLen
= TaLengthOfAddress( Source
);
77 RtlCopyMemory( Target
, Source
, AddrLen
);
80 PTA_ADDRESS
TaCopyAddress( PTA_ADDRESS Source
) {
81 UINT AddrLen
= TaLengthOfAddress( Source
);
86 Buffer
= ExAllocatePool( NonPagedPool
, AddrLen
);
89 RtlCopyMemory( Buffer
, Source
, AddrLen
);
94 VOID
TaCopyTransportAddressInPlace( PTRANSPORT_ADDRESS Target
,
95 PTRANSPORT_ADDRESS Source
) {
96 UINT AddrLen
= TaLengthOfTransportAddress( Source
);
97 RtlCopyMemory( Target
, Source
, AddrLen
);
100 PTRANSPORT_ADDRESS
TaCopyTransportAddress( PTRANSPORT_ADDRESS OtherAddress
) {
102 PTRANSPORT_ADDRESS A
;
104 AddrLen
= TaLengthOfTransportAddress( OtherAddress
);
108 A
= ExAllocatePool( NonPagedPool
, AddrLen
);
111 TaCopyTransportAddressInPlace( A
, OtherAddress
);
116 NTSTATUS
TdiBuildNullTransportAddressInPlace(PTRANSPORT_ADDRESS A
, UINT AddressType
)
118 A
->TAAddressCount
= 1;
120 A
->Address
[0].AddressLength
= TdiAddressSizeFromType(AddressType
);
121 if (!A
->Address
[0].AddressLength
)
122 return STATUS_INVALID_PARAMETER
;
124 A
->Address
[0].AddressType
= AddressType
;
126 RtlZeroMemory(A
->Address
[0].Address
, A
->Address
[0].AddressLength
);
128 return STATUS_SUCCESS
;
131 PTRANSPORT_ADDRESS
TaBuildNullTransportAddress(UINT AddressType
)
134 PTRANSPORT_ADDRESS A
;
136 AddrLen
= TaLengthOfTransportAddressByType(AddressType
);
140 A
= ExAllocatePool(NonPagedPool
, AddrLen
);
144 if (TdiBuildNullTransportAddressInPlace(A
, AddressType
) != STATUS_SUCCESS
)
154 NTSTATUS TdiBuildNullConnectionInfoInPlace
155 ( PTDI_CONNECTION_INFORMATION ConnInfo
,
158 * FUNCTION: Builds a NULL TDI connection information structure
160 * ConnectionInfo = Address of buffer to place connection information
161 * Type = TDI style address type (TDI_ADDRESS_TYPE_XXX).
163 * Status of operation
166 ULONG TdiAddressSize
;
167 PTRANSPORT_ADDRESS TransportAddress
;
169 TdiAddressSize
= TaLengthOfTransportAddressByType(Type
);
172 AFD_DbgPrint(MIN_TRACE
,("Invalid parameter\n"));
173 return STATUS_INVALID_PARAMETER
;
176 RtlZeroMemory(ConnInfo
,
177 sizeof(TDI_CONNECTION_INFORMATION
) +
180 ConnInfo
->OptionsLength
= sizeof(ULONG
);
181 ConnInfo
->RemoteAddressLength
= TdiAddressSize
;
182 ConnInfo
->RemoteAddress
= TransportAddress
=
183 (PTRANSPORT_ADDRESS
)&ConnInfo
[1];
185 return TdiBuildNullTransportAddressInPlace(TransportAddress
, Type
);
188 NTSTATUS TdiBuildNullConnectionInfo
189 ( PTDI_CONNECTION_INFORMATION
*ConnectionInfo
,
192 * FUNCTION: Builds a NULL TDI connection information structure
194 * ConnectionInfo = Address of buffer pointer to allocate connection
196 * Type = TDI style address type (TDI_ADDRESS_TYPE_XXX).
198 * Status of operation
201 PTDI_CONNECTION_INFORMATION ConnInfo
;
202 ULONG TdiAddressSize
;
205 TdiAddressSize
= TaLengthOfTransportAddressByType(Type
);
206 if (!TdiAddressSize
) {
207 AFD_DbgPrint(MIN_TRACE
,("Invalid parameter\n"));
208 *ConnectionInfo
= NULL
;
209 return STATUS_INVALID_PARAMETER
;
212 ConnInfo
= (PTDI_CONNECTION_INFORMATION
)
213 ExAllocatePool(NonPagedPool
,
214 sizeof(TDI_CONNECTION_INFORMATION
) +
217 *ConnectionInfo
= NULL
;
218 return STATUS_INSUFFICIENT_RESOURCES
;
221 Status
= TdiBuildNullConnectionInfoInPlace( ConnInfo
, Type
);
223 if (!NT_SUCCESS(Status
))
225 ExFreePool( ConnInfo
);
229 *ConnectionInfo
= ConnInfo
;
236 TdiBuildConnectionInfoInPlace
237 ( PTDI_CONNECTION_INFORMATION ConnectionInfo
,
238 PTRANSPORT_ADDRESS Address
) {
239 NTSTATUS Status
= STATUS_SUCCESS
;
242 RtlCopyMemory( ConnectionInfo
->RemoteAddress
,
244 ConnectionInfo
->RemoteAddressLength
);
245 } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
) {
246 Status
= _SEH2_GetExceptionCode();
254 TdiBuildConnectionInfo
255 ( PTDI_CONNECTION_INFORMATION
*ConnectionInfo
,
256 PTRANSPORT_ADDRESS Address
) {
257 NTSTATUS Status
= TdiBuildNullConnectionInfo
258 ( ConnectionInfo
, Address
->Address
[0].AddressType
);
260 if( NT_SUCCESS(Status
) )
261 TdiBuildConnectionInfoInPlace( *ConnectionInfo
, Address
);