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
TaCopyTransportAddressInPlace( PTRANSPORT_ADDRESS Target
,
75 PTRANSPORT_ADDRESS Source
) {
76 UINT AddrLen
= TaLengthOfTransportAddress( Source
);
77 RtlCopyMemory( Target
, Source
, AddrLen
);
80 PTRANSPORT_ADDRESS
TaCopyTransportAddress( PTRANSPORT_ADDRESS OtherAddress
) {
84 AddrLen
= TaLengthOfTransportAddress( OtherAddress
);
88 A
= ExAllocatePool( NonPagedPool
, AddrLen
);
91 TaCopyTransportAddressInPlace( A
, OtherAddress
);
96 NTSTATUS
TdiBuildNullTransportAddressInPlace(PTRANSPORT_ADDRESS A
, UINT AddressType
)
98 A
->TAAddressCount
= 1;
100 A
->Address
[0].AddressLength
= TdiAddressSizeFromType(AddressType
);
101 if (!A
->Address
[0].AddressLength
)
102 return STATUS_INVALID_PARAMETER
;
104 A
->Address
[0].AddressType
= AddressType
;
106 RtlZeroMemory(A
->Address
[0].Address
, A
->Address
[0].AddressLength
);
108 return STATUS_SUCCESS
;
111 PTRANSPORT_ADDRESS
TaBuildNullTransportAddress(UINT AddressType
)
114 PTRANSPORT_ADDRESS A
;
116 AddrLen
= TaLengthOfTransportAddressByType(AddressType
);
120 A
= ExAllocatePool(NonPagedPool
, AddrLen
);
124 if (TdiBuildNullTransportAddressInPlace(A
, AddressType
) != STATUS_SUCCESS
)
134 NTSTATUS TdiBuildNullConnectionInfoInPlace
135 ( PTDI_CONNECTION_INFORMATION ConnInfo
,
138 * FUNCTION: Builds a NULL TDI connection information structure
140 * ConnectionInfo = Address of buffer to place connection information
141 * Type = TDI style address type (TDI_ADDRESS_TYPE_XXX).
143 * Status of operation
146 ULONG TdiAddressSize
;
147 PTRANSPORT_ADDRESS TransportAddress
;
149 TdiAddressSize
= TaLengthOfTransportAddressByType(Type
);
152 AFD_DbgPrint(MIN_TRACE
,("Invalid parameter\n"));
153 return STATUS_INVALID_PARAMETER
;
156 RtlZeroMemory(ConnInfo
,
157 sizeof(TDI_CONNECTION_INFORMATION
) +
160 ConnInfo
->OptionsLength
= sizeof(ULONG
);
161 ConnInfo
->RemoteAddressLength
= TdiAddressSize
;
162 ConnInfo
->RemoteAddress
= TransportAddress
=
163 (PTRANSPORT_ADDRESS
)&ConnInfo
[1];
165 return TdiBuildNullTransportAddressInPlace(TransportAddress
, Type
);
168 NTSTATUS TdiBuildNullConnectionInfo
169 ( PTDI_CONNECTION_INFORMATION
*ConnectionInfo
,
172 * FUNCTION: Builds a NULL TDI connection information structure
174 * ConnectionInfo = Address of buffer pointer to allocate connection
176 * Type = TDI style address type (TDI_ADDRESS_TYPE_XXX).
178 * Status of operation
181 PTDI_CONNECTION_INFORMATION ConnInfo
;
182 ULONG TdiAddressSize
;
185 TdiAddressSize
= TaLengthOfTransportAddressByType(Type
);
186 if (!TdiAddressSize
) {
187 AFD_DbgPrint(MIN_TRACE
,("Invalid parameter\n"));
188 *ConnectionInfo
= NULL
;
189 return STATUS_INVALID_PARAMETER
;
192 ConnInfo
= (PTDI_CONNECTION_INFORMATION
)
193 ExAllocatePool(NonPagedPool
,
194 sizeof(TDI_CONNECTION_INFORMATION
) +
197 *ConnectionInfo
= NULL
;
198 return STATUS_INSUFFICIENT_RESOURCES
;
201 Status
= TdiBuildNullConnectionInfoInPlace( ConnInfo
, Type
);
203 if (!NT_SUCCESS(Status
))
205 ExFreePool( ConnInfo
);
209 *ConnectionInfo
= ConnInfo
;
216 TdiBuildConnectionInfoInPlace
217 ( PTDI_CONNECTION_INFORMATION ConnectionInfo
,
218 PTRANSPORT_ADDRESS Address
) {
219 NTSTATUS Status
= STATUS_SUCCESS
;
222 RtlCopyMemory( ConnectionInfo
->RemoteAddress
,
224 ConnectionInfo
->RemoteAddressLength
);
225 } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
) {
226 Status
= _SEH2_GetExceptionCode();
234 TdiBuildConnectionInfo
235 ( PTDI_CONNECTION_INFORMATION
*ConnectionInfo
,
236 PTRANSPORT_ADDRESS Address
) {
237 NTSTATUS Status
= TdiBuildNullConnectionInfo
238 ( ConnectionInfo
, Address
->Address
[0].AddressType
);
240 if( NT_SUCCESS(Status
) )
241 TdiBuildConnectionInfoInPlace( *ConnectionInfo
, Address
);