ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

tdiconn.c
Go to the documentation of this file.
00001 /* $Id: tdiconn.c 56389 2012-04-22 13:11:54Z tfaber $
00002  * COPYRIGHT:        See COPYING in the top level directory
00003  * PROJECT:          ReactOS kernel
00004  * FILE:             drivers/net/afd/afd/tdiconn.c
00005  * PURPOSE:          Ancillary functions driver
00006  * PROGRAMMER:       Art Yerkes (ayerkes@speakeasy.net)
00007  * UPDATE HISTORY:
00008  * 20040708 Created
00009  */
00010 #include <afd.h>
00011 
00012 UINT TdiAddressSizeFromType( UINT AddressType ) {
00013     switch( AddressType ) {
00014     case TDI_ADDRESS_TYPE_IP:
00015         return TDI_ADDRESS_LENGTH_IP;
00016     case TDI_ADDRESS_TYPE_APPLETALK:
00017         return TDI_ADDRESS_LENGTH_APPLETALK;
00018     case TDI_ADDRESS_TYPE_NETBIOS:
00019         return TDI_ADDRESS_LENGTH_NETBIOS;
00020     /* case TDI_ADDRESS_TYPE_NS: */
00021     case TDI_ADDRESS_TYPE_IPX:
00022         return TDI_ADDRESS_LENGTH_IPX;
00023     case TDI_ADDRESS_TYPE_VNS:
00024         return TDI_ADDRESS_LENGTH_VNS;
00025     default:
00026         DbgPrint("TdiAddressSizeFromType - invalid type: %x\n", AddressType);
00027         return 0;
00028     }
00029 }
00030 
00031 UINT TaLengthOfAddress( PTA_ADDRESS Addr )
00032 {
00033     UINT AddrLen = Addr->AddressLength;
00034 
00035     if (!AddrLen)
00036         return 0;
00037 
00038     AddrLen += 2 * sizeof( USHORT );
00039 
00040     AFD_DbgPrint(MID_TRACE,("AddrLen %x\n", AddrLen));
00041 
00042     return AddrLen;
00043 }
00044 
00045 UINT TaLengthOfTransportAddress( PTRANSPORT_ADDRESS Addr )
00046 {
00047     UINT AddrLen = TaLengthOfAddress(&Addr->Address[0]);
00048 
00049     if (!AddrLen)
00050         return 0;
00051 
00052     AddrLen += sizeof(ULONG);
00053 
00054     AFD_DbgPrint(MID_TRACE,("AddrLen %x\n", AddrLen));
00055 
00056     return AddrLen;
00057 }
00058 
00059 UINT TaLengthOfTransportAddressByType(UINT AddressType)
00060 {
00061     UINT AddrLen = TdiAddressSizeFromType(AddressType);
00062 
00063     if (!AddrLen)
00064         return 0;
00065 
00066     AddrLen += sizeof(ULONG) + 2 * sizeof(USHORT);
00067 
00068     AFD_DbgPrint(MID_TRACE,("AddrLen %x\n", AddrLen));
00069 
00070     return AddrLen;
00071 }
00072 
00073 VOID TaCopyAddressInPlace( PTA_ADDRESS Target,
00074                            PTA_ADDRESS Source ) {
00075     UINT AddrLen = TaLengthOfAddress( Source );
00076     RtlCopyMemory( Target, Source, AddrLen );
00077 }
00078 
00079 PTA_ADDRESS TaCopyAddress( PTA_ADDRESS Source ) {
00080     UINT AddrLen = TaLengthOfAddress( Source );
00081     PVOID Buffer;
00082     if (!AddrLen)
00083         return NULL;
00084 
00085     Buffer = ExAllocatePool( NonPagedPool, AddrLen );
00086 
00087     if (Buffer)
00088        RtlCopyMemory( Buffer, Source, AddrLen );
00089 
00090     return Buffer;
00091 }
00092 
00093 VOID TaCopyTransportAddressInPlace( PTRANSPORT_ADDRESS Target,
00094                                     PTRANSPORT_ADDRESS Source ) {
00095     UINT AddrLen = TaLengthOfTransportAddress( Source );
00096     RtlCopyMemory( Target, Source, AddrLen );
00097 }
00098 
00099 PTRANSPORT_ADDRESS TaCopyTransportAddress( PTRANSPORT_ADDRESS OtherAddress ) {
00100     UINT AddrLen;
00101     PTRANSPORT_ADDRESS A;
00102 
00103     AddrLen = TaLengthOfTransportAddress( OtherAddress );
00104     if (!AddrLen)
00105         return NULL;
00106 
00107     A = ExAllocatePool( NonPagedPool, AddrLen );
00108 
00109     if( A )
00110         TaCopyTransportAddressInPlace( A, OtherAddress );
00111 
00112     return A;
00113 }
00114 
00115 NTSTATUS TdiBuildNullTransportAddressInPlace(PTRANSPORT_ADDRESS A, UINT AddressType)
00116 {
00117     A->TAAddressCount = 1;
00118 
00119     A->Address[0].AddressLength = TdiAddressSizeFromType(AddressType);
00120     if (!A->Address[0].AddressLength)
00121         return STATUS_INVALID_PARAMETER;
00122 
00123     A->Address[0].AddressType = AddressType;
00124 
00125     RtlZeroMemory(A->Address[0].Address, A->Address[0].AddressLength);
00126 
00127     return STATUS_SUCCESS;
00128 }
00129 
00130 PTRANSPORT_ADDRESS TaBuildNullTransportAddress(UINT AddressType)
00131 {
00132     UINT AddrLen;
00133     PTRANSPORT_ADDRESS A;
00134 
00135     AddrLen = TaLengthOfTransportAddressByType(AddressType);
00136     if (!AddrLen)
00137         return NULL;
00138 
00139     A = ExAllocatePool(NonPagedPool, AddrLen);
00140 
00141     if (A)
00142     {
00143         if (TdiBuildNullTransportAddressInPlace(A, AddressType) != STATUS_SUCCESS)
00144         {
00145             ExFreePool(A);
00146             return NULL;
00147         }
00148     }
00149 
00150     return A;
00151 }
00152 
00153 NTSTATUS TdiBuildNullConnectionInfoInPlace
00154 ( PTDI_CONNECTION_INFORMATION ConnInfo,
00155   ULONG Type )
00156 /*
00157  * FUNCTION: Builds a NULL TDI connection information structure
00158  * ARGUMENTS:
00159  *     ConnectionInfo = Address of buffer to place connection information
00160  *     Type           = TDI style address type (TDI_ADDRESS_TYPE_XXX).
00161  * RETURNS:
00162  *     Status of operation
00163  */
00164 {
00165     ULONG TdiAddressSize;
00166     PTRANSPORT_ADDRESS TransportAddress;
00167 
00168     TdiAddressSize = TaLengthOfTransportAddressByType(Type);
00169     if (!TdiAddressSize)
00170     {
00171         AFD_DbgPrint(MIN_TRACE,("Invalid parameter\n"));
00172         return STATUS_INVALID_PARAMETER;
00173     }
00174 
00175     RtlZeroMemory(ConnInfo,
00176                   sizeof(TDI_CONNECTION_INFORMATION) +
00177                   TdiAddressSize);
00178 
00179     ConnInfo->OptionsLength = sizeof(ULONG);
00180     ConnInfo->RemoteAddressLength = TdiAddressSize;
00181     ConnInfo->RemoteAddress = TransportAddress =
00182         (PTRANSPORT_ADDRESS)&ConnInfo[1];
00183 
00184     return TdiBuildNullTransportAddressInPlace(TransportAddress, Type);
00185 }
00186 
00187 NTSTATUS TdiBuildNullConnectionInfo
00188 ( PTDI_CONNECTION_INFORMATION *ConnectionInfo,
00189   ULONG Type )
00190 /*
00191  * FUNCTION: Builds a NULL TDI connection information structure
00192  * ARGUMENTS:
00193  *     ConnectionInfo = Address of buffer pointer to allocate connection
00194  *                      information in
00195  *     Type           = TDI style address type (TDI_ADDRESS_TYPE_XXX).
00196  * RETURNS:
00197  *     Status of operation
00198  */
00199 {
00200     PTDI_CONNECTION_INFORMATION ConnInfo;
00201     ULONG TdiAddressSize;
00202     NTSTATUS Status;
00203 
00204     TdiAddressSize = TaLengthOfTransportAddressByType(Type);
00205     if (!TdiAddressSize) {
00206         AFD_DbgPrint(MIN_TRACE,("Invalid parameter\n"));
00207         *ConnectionInfo = NULL;
00208         return STATUS_INVALID_PARAMETER;
00209     }
00210 
00211     ConnInfo = (PTDI_CONNECTION_INFORMATION)
00212         ExAllocatePool(NonPagedPool,
00213                        sizeof(TDI_CONNECTION_INFORMATION) +
00214                        TdiAddressSize);
00215     if (!ConnInfo) {
00216         *ConnectionInfo = NULL;
00217         return STATUS_INSUFFICIENT_RESOURCES;
00218     }
00219 
00220     Status = TdiBuildNullConnectionInfoInPlace( ConnInfo, Type );
00221 
00222     if (!NT_SUCCESS(Status))
00223     {
00224         ExFreePool( ConnInfo );
00225         ConnInfo = NULL;
00226     }
00227 
00228     *ConnectionInfo = ConnInfo;
00229 
00230     return Status;
00231 }
00232 
00233 
00234 NTSTATUS
00235 TdiBuildConnectionInfoInPlace
00236 ( PTDI_CONNECTION_INFORMATION ConnectionInfo,
00237   PTRANSPORT_ADDRESS Address ) {
00238     NTSTATUS Status = STATUS_SUCCESS;
00239 
00240     _SEH2_TRY {
00241         RtlCopyMemory( ConnectionInfo->RemoteAddress,
00242                        Address,
00243                        ConnectionInfo->RemoteAddressLength );
00244     } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
00245         Status = _SEH2_GetExceptionCode();
00246     } _SEH2_END;
00247 
00248     return Status;
00249 }
00250 
00251 
00252 NTSTATUS
00253 TdiBuildConnectionInfo
00254 ( PTDI_CONNECTION_INFORMATION *ConnectionInfo,
00255   PTRANSPORT_ADDRESS Address ) {
00256     NTSTATUS Status = TdiBuildNullConnectionInfo
00257         ( ConnectionInfo, Address->Address[0].AddressType );
00258 
00259     if( NT_SUCCESS(Status) )
00260         TdiBuildConnectionInfoInPlace( *ConnectionInfo, Address );
00261 
00262     return Status;
00263 }
00264 

Generated on Sun May 27 2012 04:28:02 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.